blob: c73fc9a29fa4d2eb5574dfc09fe462a099dada00 [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 *
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 *
24 */
25
26
Harald Welted54c2ee2012-01-17 18:25:50 +010027#include <osmocom/sim/sim.h>
Harald Welte429adec2020-03-20 13:05:40 +010028#include <osmocom/core/talloc.h>
Harald Welted54c2ee2012-01-17 18:25:50 +010029#include <osmocom/gsm/tlv.h>
30
Harald Welte429adec2020-03-20 13:05:40 +010031#include "sim_int.h"
32#include "gsm_int.h"
33
Harald Welted54c2ee2012-01-17 18:25:50 +010034/* TS 102 221 V10.0.0 / 10.2.1 */
35const struct osim_card_sw ts102221_uicc_sw[] = {
36 {
37 0x9000, 0xffff, SW_TYPE_STR, SW_CLS_OK,
38 .u.str = "Normal ending of the command",
39 }, {
40 0x9100, 0xff00, SW_TYPE_STR, SW_CLS_OK,
41 .u.str = "Normal ending of the command, extra info proactive",
42 }, {
43 0x9200, 0xff00, SW_TYPE_STR, SW_CLS_OK,
44 .u.str = "Normal ending of the command, extra info regarding transfer session",
45 }, {
46 0x9300, 0xff00, SW_TYPE_STR, SW_CLS_POSTP,
47 .u.str = "SIM Application Toolkit is busy, command cannot be executed at present",
48 }, {
49 0x6200, 0xffff, SW_TYPE_STR, SW_CLS_WARN,
50 .u.str = "No information given, state of non volatile memory unchanged",
51 }, {
52 0x6281, 0xffff, SW_TYPE_STR, SW_CLS_WARN,
53 .u.str = "Part of returned data may be corrupted",
54 }, {
55 0x6282, 0xffff, SW_TYPE_STR, SW_CLS_WARN,
56 .u.str = "End of file/record reached before reading Le bytes",
57 }, {
58 0x6283, 0xffff, SW_TYPE_STR, SW_CLS_WARN,
59 .u.str = "Selected file invalidated",
60 }, {
61 0x6285, 0xffff, SW_TYPE_STR, SW_CLS_WARN,
62 .u.str = "Selected file in termination state",
63 }, {
64 0x62f1, 0xffff, SW_TYPE_STR, SW_CLS_WARN,
65 .u.str = "More data available",
66 }, {
67 0x62f2, 0xffff, SW_TYPE_STR, SW_CLS_WARN,
68 .u.str = "More data available and proactive command pending",
69 }, {
70 0x62f3, 0xffff, SW_TYPE_STR, SW_CLS_WARN,
71 .u.str = "Response data available",
72 }, {
73 0x63f1, 0xffff, SW_TYPE_STR, SW_CLS_WARN,
74 .u.str = "More data expected",
75 }, {
76 0x63c0, 0xfff0, SW_TYPE_STR, SW_CLS_WARN,
77 .u.str = "Verification falied, X retries remaining",
78 }, {
79 0x6400, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
80 .u.str = "Execution - No information given, state of non-volatile memory unchanged",
81 }, {
82 0x6500, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
83 .u.str = "Execution - No information given, state of non-volatile memory changed",
84 }, {
85 0x6581, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
86 .u.str = "Execution - Memory problem",
87 }, {
88 0x6700, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
89 .u.str = "Checking - Wrong length",
90 }, {
91 0x6700, 0xff00, SW_TYPE_STR, SW_CLS_ERROR,
92 .u.str = "Checking - Command dependent error",
93 }, {
94 0x6b00, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
95 .u.str = "Checking - Wrong parameter(s) P1-P2",
96 }, {
97 0x6d00, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
98 .u.str = "Checking - Instruction code not supported or valid",
99 }, {
100 0x6e00, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
101 .u.str = "Checking - Class not supported",
102 }, {
103 0x6f00, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
104 .u.str = "Checking - Technical problem, no precise diagnostics",
105 }, {
106 0x6f00, 0xff00, SW_TYPE_STR, SW_CLS_ERROR,
107 .u.str = "Checking - Command dependent error",
108 }, {
109 0x6800, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
110 .u.str = "Function in CLA not supported - No information given",
111 }, {
112 0x6881, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
113 .u.str = "Function in CLA not supported - Logical channel not supported",
114 }, {
115 0x6882, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
116 .u.str = "Function in CLA not supportied - Secure messaging not supported",
117 }, {
118 0x6900, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
119 .u.str = "Command not allowed - No information given",
120 }, {
121 0x6981, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
122 .u.str = "Command not allowed - Command incompatible with file structure",
123 }, {
124 0x6982, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
125 .u.str = "Command not allowed - Security status not satisfied",
126 }, {
127 0x6983, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
128 .u.str = "Command not allowed - Authentication/PIN method blocked",
129 }, {
130 0x6984, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
131 .u.str = "Command not allowed - Referenced data invalidated",
132 }, {
133 0x6985, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
134 .u.str = "Command not allowed - Conditions of use not satisfied",
135 }, {
136 0x6986, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
137 .u.str = "Command not allowed - Noe EF selected",
138 }, {
139 0x6989, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
140 .u.str = "Command not allowed - secure channel - security not satisfied",
141 }, {
142 0x6a80, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
143 .u.str = "Wrong parameters - Incorrect parameters in the data field",
144 }, {
145 0x6a81, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
146 .u.str = "Wrong parameters - Function not supported",
147 }, {
148 0x6a82, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
149 .u.str = "Wrong parameters - File not found",
150 }, {
151 0x6a83, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
152 .u.str = "Wrong parameters - Record not found",
153 }, {
154 0x6a84, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
155 .u.str = "Wrong parameters - Not enough memory space",
156 }, {
157 0x6a86, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
158 .u.str = "Wrong parameters - Incorrect parameters P1 to P2",
159 }, {
160 0x6a87, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
161 .u.str = "Wrong parameters - Lc inconsistent with P1 ot P2",
162 }, {
163 0x6a88, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
164 .u.str = "Wrong parameters - Referenced data not found",
165 }, {
166 0x9850, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
167 .u.str = "Application error - INCREASE cannot be performed, max value reached",
168 }, {
169 0x9862, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
170 .u.str = "Application error - Authentication error, application specific",
171 }, {
172 0x9863, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
173 .u.str = "Application error - Security session or association expired",
174 },
175 OSIM_CARD_SW_LAST
176};
177
Harald Welte429adec2020-03-20 13:05:40 +0100178static const struct osim_card_sw *uicc_card_sws[] = {
179 ts102221_uicc_sw,
180 NULL
181};
182
183/* TS 102 221 Chapter 13.1 */
184static const struct osim_file_desc uicc_ef_in_mf[] = {
185 EF_LIN_FIX_N(0x2f00, SFI_NONE, "EF.DIR", 0, 1, 32,
186 "Application directory"),
187 EF_TRANSP_N(0x2FE2, SFI_NONE, "EF.ICCID", 0, 10, 10,
188 "ICC Identification"),
189 EF_TRANSP_N(0x2F05, SFI_NONE, "EF.PL", 0, 2, 20,
190 "Preferred Languages"),
191 EF_LIN_FIX_N(0x2F06, SFI_NONE, "EF.ARR", F_OPTIONAL, 1, 256,
192 "Access Rule Reference"),
193};
194
Harald Welted54c2ee2012-01-17 18:25:50 +0100195const struct value_string ts102221_fcp_vals[14] = {
196 { UICC_FCP_T_FCP, "File control parameters" },
197 { UICC_FCP_T_FILE_SIZE, "File size" },
198 { UICC_FCP_T_TOT_F_SIZE, "Total size of files" },
199 { UICC_FCP_T_FILE_DESC, "File descriptor" },
200 { UICC_FCP_T_FILE_ID, "File identifier" },
201 { UICC_FCP_T_DF_NAME, "DF name" },
202 { UICC_FCP_T_SFID, "Short file identifier" },
203 { UICC_FCP_T_LIFEC_STS, "Lifecycle status integer" },
204 { UICC_FCP_T_SEC_ATTR_REFEXP, "Security attributes (Referenced/Expanded)" },
205 { UICC_FCP_T_SEC_ATTR_COMP, "Security attributes (Compact)" },
206 { UICC_FCP_T_PROPRIETARY, "Proprietary" },
207 { UICC_FCP_T_SEC_ATTR_EXP, "Security attributes (Expanded)" },
208 { UICC_FCP_T_PIN_STS_DO, "PIN Status DO" },
209 { 0, NULL }
210};
211
212/* FIXME: Ber-TLV ?? */
213const struct tlv_definition ts102221_fcp_tlv_def = {
214 .def = {
215 [UICC_FCP_T_FCP] = { TLV_TYPE_TLV },
216 [UICC_FCP_T_FILE_SIZE] = { TLV_TYPE_TLV },
217 [UICC_FCP_T_TOT_F_SIZE] = { TLV_TYPE_TLV },
218 [UICC_FCP_T_FILE_DESC] = { TLV_TYPE_TLV },
219 [UICC_FCP_T_FILE_ID] = { TLV_TYPE_TLV },
220 [UICC_FCP_T_DF_NAME] = { TLV_TYPE_TLV },
221 [UICC_FCP_T_SFID] = { TLV_TYPE_TLV },
222 [UICC_FCP_T_LIFEC_STS] = { TLV_TYPE_TLV },
223 [UICC_FCP_T_SEC_ATTR_REFEXP] = { TLV_TYPE_TLV },
224 [UICC_FCP_T_SEC_ATTR_COMP] = { TLV_TYPE_TLV },
225 [UICC_FCP_T_PROPRIETARY] = { TLV_TYPE_TLV },
226 [UICC_FCP_T_SEC_ATTR_EXP] = { TLV_TYPE_TLV },
227 [UICC_FCP_T_PIN_STS_DO] = { TLV_TYPE_TLV },
228 },
229};
230
231/* Annex E - TS 101 220 */
Pau Espin Pedrol92274452017-06-17 23:27:47 +0200232static const uint8_t __attribute__((__unused__)) adf_uicc_aid[] = { 0xA0, 0x00, 0x00, 0x00, 0x87, 0x10, 0x01 };
Harald Welte429adec2020-03-20 13:05:40 +0100233
234struct osim_card_profile *osim_cprof_uicc(void *ctx)
235{
236 struct osim_card_profile *cprof;
237 struct osim_file_desc *mf;
238 int rc;
239
240 cprof = talloc_zero(ctx, struct osim_card_profile);
241 cprof->name = "3GPP UICC";
242 cprof->sws = uicc_card_sws; // FIXME: extend later
243
244 mf = alloc_df(cprof, 0x3f00, "MF");
245
246 cprof->mf = mf;
247
248 /* Core UICC Files */
249 add_filedesc(mf, uicc_ef_in_mf, ARRAY_SIZE(uicc_ef_in_mf));
250
251 /* DF.TELECOM hierarchy as sub-directory of MF */
252 rc = osim_int_cprof_add_telecom(mf);
253 if (rc != 0) {
254 talloc_free(cprof);
255 return NULL;
256 }
257
258 return cprof;
259}