blob: 657e55f7b12aee5de8f8ea06fdf30136bf04e22b [file] [log] [blame]
Harald Weltee8dd2bd2014-05-04 13:42:38 +02001/* TETRA SIM card specific structures/routines */
2/*
3 * (C) 2014 by Harald Welte <laforge@gnumonks.org>
4 *
5 * All Rights Reserved
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 */
22
23#include <errno.h>
24#include <string.h>
25
26#include <osmocom/sim/sim.h>
27#include <osmocom/core/talloc.h>
28#include <osmocom/gsm/gsm48.h>
29
30#include "sim_int.h"
Harald Welteaad7e062014-05-04 16:31:24 +020031#include "gsm_int.h"
Harald Weltee8dd2bd2014-05-04 13:42:38 +020032
33/* EN 300 812 V2.1.1 (2001-12) 9.4 */
34static const struct osim_card_sw tsim_sw[] = {
35 {
36 0x9000, 0xffff, SW_TYPE_STR, SW_CLS_OK,
37 .u.str = "Normal ending of the command",
38 }, {
39 0x9f00, 0xff00, SW_TYPE_STR, SW_CLS_OK,
40 .u.str = "Normal ending of the command - response data available",
41 }, {
42 0x9300, 0xffff, SW_TYPE_STR, SW_CLS_POSTP,
43 .u.str = "SIM Application Toolkit is busy, command cannot be executed at present",
44 }, {
45 0x9200, 0xfff0, SW_TYPE_STR, SW_CLS_WARN,
46 .u.str = "Memory management - Command successful but after using an internal updat retry X times",
47 }, {
48 0x9240, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
49 .u.str = "Memory management - Memory problem",
50 }, {
51 0x9400, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
52 .u.str = "Referencing management - no EF selected",
53 }, {
54 0x9402, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
55 .u.str = "Referencing management - out of range (invalid address)",
56 }, {
57 0x9404, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
58 .u.str = "Referencing management - file ID not found / pattern not found",
59 }, {
60 0x9408, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
61 .u.str = "Referencing management - file is inconsistent with the command",
62 }, {
63 0x9802, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
64 .u.str = "Security management - no CHV initialized",
65 }, {
66 0x9804, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
67 .u.str = "Security management - access condition not fulfilled",
68 }, {
69 0x9808, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
70 .u.str = "Security management - in contradiction with CHV status",
71 }, {
72 0x9810, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
73 .u.str = "Security management - in contradiction with invalidation status",
74 }, {
75 0x9840, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
76 .u.str = "Security management - unsuccessful CHV verification, no attempt left",
77 }, {
78 0x9860, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
79 .u.str = "Security management - manipulation flag set",
80 }, {
81 0x9870, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
82 .u.str = "Security management - SwMI authentication unsuccessful",
83 }, {
84 0x6700, 0xff00, SW_TYPE_STR, SW_CLS_ERROR,
85 .u.str = "Application independent - incorrect parameter P3",
86 }, {
87 0x6b00, 0xff00, SW_TYPE_STR, SW_CLS_ERROR,
88 .u.str = "Application independent - incorrect parameter P1 or P2",
89 }, {
90 0x6d00, 0xff00, SW_TYPE_STR, SW_CLS_ERROR,
91 .u.str = "Application independent - unknown instruction code",
92 }, {
93 0x6e00, 0xff00, SW_TYPE_STR, SW_CLS_ERROR,
94 .u.str = "Application independent - wrong instruction class",
95 }, {
96 0x6f00, 0xff00, SW_TYPE_STR, SW_CLS_ERROR,
97 .u.str = "Application independent - technical problem with no diagnostic given",
98 },
99 OSIM_CARD_SW_LAST
100};
101
102static const struct osim_card_sw *tsim_card_sws[] = {
Harald Welteaad7e062014-05-04 16:31:24 +0200103 tsim_sw,
Harald Weltee8dd2bd2014-05-04 13:42:38 +0200104 NULL
105};
106
107/* Chapter 10.2.x */
108static const struct osim_file_desc sim_ef_in_mf[] = {
Harald Welteaad7e062014-05-04 16:31:24 +0200109 EF_TRANSP_N(0x2FE2, SFI_NONE, "EF.ICCID", 0, 10, 10,
110 "ICC Identification"),
111 EF_TRANSP_N(0x2F00, SFI_NONE, "EF.DIR", F_OPTIONAL, 8, 54,
112 "Application directory"),
113 EF_TRANSP_N(0x2F05, SFI_NONE, "EF.LP", 0, 2, 32,
114 "Language preference"),
Harald Weltee8dd2bd2014-05-04 13:42:38 +0200115};
116
117////////////////////////////
118
119/* Chapter 10.3.x */
120static const struct osim_file_desc sim_ef_in_tetra[] = {
Harald Welteaad7e062014-05-04 16:31:24 +0200121 EF_TRANSP_N(0x6F01, SFI_NONE, "EF.SST", 0, 4, 8,
Harald Weltee8dd2bd2014-05-04 13:42:38 +0200122 "SIM service table"),
Harald Welteaad7e062014-05-04 16:31:24 +0200123 EF_TRANSP_N(0x6F02, SFI_NONE, "EF.ITSI", 0, 6, 6,
124 "ITSI"),
125 EF_TRANSP_N(0x6F03, SFI_NONE, "EF.ITSIDIS", 0, 1, 1,
126 "ITSI Disable"),
127 EF_TRANSP_N(0x6F05, SFI_NONE, "EF.SCT", 0, 4, 4,
128 "Subscriber Class Table"),
129 EF_TRANSP_N(0x6F06, SFI_NONE, "EF.PHASE", 0, 1, 1,
130 "Phase identification"),
131 EF_KEY_N(0x6F07, SFI_NONE, "EF.CCK", F_OPTIONAL, 12, 12,
132 "Common Cipher Key"),
133 EF_TRANSP_N(0x6F08, SFI_NONE, "EF.CCKLOC", F_OPTIONAL, 31, 31,
134 "CCK location areas"),
135 EF_KEY_N(0x6F09, SFI_NONE, "EF.SCK", F_OPTIONAL, 12, 12,
136 "Static Cipher Keys"),
Harald Weltee8dd2bd2014-05-04 13:42:38 +0200137 /* X+4 for each record, suggested 1 to 10 */
Harald Welteaad7e062014-05-04 16:31:24 +0200138 EF_LIN_FIX_N(0x6F0A, SFI_NONE, "EF.GSSIS", 0, 5, 21,
139 "Static Cipher Keys"),
Harald Weltee8dd2bd2014-05-04 13:42:38 +0200140 /* 2 for each record, one for each recod in GSSIS */
Harald Welteaad7e062014-05-04 16:31:24 +0200141 EF_LIN_FIX_N(0x6F0B, SFI_NONE, "EF.GRDS", 0, 2, 2,
142 "Group related data for static GSSIS"),
143 EF_LIN_FIX_N(0x6F0C, SFI_NONE, "EF.GSSID", 0, 5, 21,
144 "Dynamic GSSIs"),
Harald Weltee8dd2bd2014-05-04 13:42:38 +0200145 /* 2 for each record, one for each recod in GSSID */
Harald Welteaad7e062014-05-04 16:31:24 +0200146 EF_LIN_FIX_N(0x6F0D, SFI_NONE, "EF.GRDD", 0, 2, 2,
147 "Dynamic GSSIs"),
148 EF_LIN_FIX_N(0x6F0E, SFI_NONE, "EF.GCK", F_OPTIONAL, 12, 12,
149 "Group Cipher Keys"),
150 EF_KEY_N(0x6F0F, SFI_NONE, "EF.MGCK", F_OPTIONAL, 12, 12,
151 "Modified Group Cipher Keys"),
152 EF_TRANSP_N(0x6F10, SFI_NONE, "EF.GINFO", 0, 9, 9,
153 "User's group information"),
154 EF_TRANSP_N(0x6F11, SFI_NONE, "EF.SEC", 0, 1, 1,
155 "Security settings"),
156 EF_CYCLIC_N(0x6F12, SFI_NONE, "EF.FORBID", 0, 3, 3,
157 "Security settings"),
158 EF_CYCLIC_N(0x6F13, SFI_NONE, "EF.PREF", F_OPTIONAL, 3, 3,
159 "Preferred networks"),
160 EF_TRANSP_N(0x6F14, SFI_NONE, "EF.SPN", F_OPTIONAL, 17, 17,
161 "Service Provider Name"),
162 EF_TRANSP_N(0x6F15, SFI_NONE, "EF.LOCI", F_OPTIONAL, 7, 7,
163 "Location Information"),
164 EF_TRANSP_N(0x6F16, SFI_NONE, "EF.DNWRK", 0, 3, 3,
165 "Broadcast network information"),
166 EF_LIN_FIX_N(0x6F17, SFI_NONE, "EF.NWT", 0, 5, 5,
167 "Network table"),
168 EF_LIN_FIX_N(0x6F18, SFI_NONE, "EF.GWT", F_OPTIONAL, 13, 13,
169 "Gateway table"),
170 EF_LIN_FIX_N(0x6F19, SFI_NONE, "EF.CMT", F_OPTIONAL, 5, 20,
171 "Call Modifier Table"),
172 EF_LIN_FIX_N(0x6F1A, SFI_NONE, "EF.ADNGWT", F_OPTIONAL, 13, 28,
173 "Abbreviated Dialling Number with Gateways"),
174 EF_LIN_FIX_N(0x6F1C, SFI_NONE, "EF.ADNTETRA", F_OPTIONAL, 9, 23,
175 "Abbreviated dialling numbers for TETRA network"),
176 EF_LIN_FIX_N(0x6F1D, SFI_NONE, "EF.EXTA", F_OPTIONAL, 20, 20,
177 "Extension A"),
178 EF_LIN_FIX_N(0x6F1E, SFI_NONE, "EF.FDNGWT", F_OPTIONAL, 13, 28,
179 "Fixed dialling numbers with Gateways"),
180 EF_LIN_FIX_N(0x6F1F, SFI_NONE, "EF.GWTEXT2", F_OPTIONAL, 13, 13,
181 "Gateway Extension2"),
182 EF_LIN_FIX_N(0x6F20, SFI_NONE, "EF.FDNTETRA", F_OPTIONAL, 9, 25,
183 "Fixed dialling numbers for TETRA network"),
184 EF_LIN_FIX_N(0x6F21, SFI_NONE, "EF.EXTB", F_OPTIONAL, 20, 20,
185 "Extension B"),
186 EF_LIN_FIX_N(0x6F22, SFI_NONE, "EF.LNDGWT", F_OPTIONAL, 13, 28,
187 "Last number dialled with Gateways"),
188 EF_CYCLIC_N(0x6F23, SFI_NONE, "EF.LNDTETRA", F_OPTIONAL, 9, 23,
189 "Last numbers dialled for TETRA network"),
190 EF_LIN_FIX_N(0x6F24, SFI_NONE, "EF.SDNGWT", F_OPTIONAL, 13, 28,
191 "Service Dialling Numbers with gateway"),
192 EF_LIN_FIX_N(0x6F25, SFI_NONE, "EF.GWTEXT3", F_OPTIONAL, 13, 13,
193 "Gateway Extension3"),
194 EF_LIN_FIX_N(0x6F26, SFI_NONE, "EF.SDNTETRA", F_OPTIONAL, 8, 22,
195 "Service Dialling Nubers for TETRA network"),
196 EF_LIN_FIX_N(0x6F27, SFI_NONE, "EF.STXT", F_OPTIONAL, 5, 18,
197 "Status message texts"),
198 EF_LIN_FIX_N(0x6F28, SFI_NONE, "EF.MSGTXT", F_OPTIONAL, 5, 18,
199 "SDS-1 message texts"),
200 EF_LIN_FIX_N(0x6F29, SFI_NONE, "EF.SDS123", F_OPTIONAL, 46, 46,
201 "Status and SDS type 1, 2 and 3 message storage"),
202 EF_LIN_FIX_N(0x6F2A, SFI_NONE, "EF.SDS4", F_OPTIONAL, 255, 255,
203 "Status and SDS type 4 message storage"),
204 EF_LIN_FIX_N(0x6F2B, SFI_NONE, "EF.MSGEXT", F_OPTIONAL, 16, 16,
205 "Message Extension"),
206 EF_LIN_FIX_N(0x6F2C, SFI_NONE, "EF.EADDR", 0, 17, 17,
Ruben Undheim029f5a12015-09-16 19:02:35 +0200207 "Emergency addresses"),
Harald Welteaad7e062014-05-04 16:31:24 +0200208 EF_TRANSP_N(0x6F2D, SFI_NONE, "EF.EINFO", 0, 2, 2,
209 "Emergency call information"),
210 EF_LIN_FIX_N(0x6F2E, SFI_NONE, "EF.DMOCh", F_OPTIONAL, 4, 4,
211 "DMO channel information"),
212 EF_TRANSP_N(0x6F2F, SFI_NONE, "EF.MSCh", F_OPTIONAL, 1, 16,
213 "MS allocation of DMO channels"),
214 EF_TRANSP_N(0x6F30, SFI_NONE, "EF.KH", F_OPTIONAL, 6, 6,
215 "List of Key Holders"),
216 EF_LIN_FIX_N(0x6F31, SFI_NONE, "EF.REPGATE", F_OPTIONAL, 2, 2,
217 "DMO repeater and gateway list"),
218 EF_TRANSP_N(0x6F32, SFI_NONE, "EF.AD", F_OPTIONAL, 2, 2,
219 "Administrative Data"),
220 EF_TRANSP_N(0x6F33, SFI_NONE, "EF.PREF_LA", F_OPTIONAL, 2, 2,
221 "Preferred location areas"),
222 EF_CYCLIC_N(0x6F34, SFI_NONE, "EF.LNDComp", F_OPTIONAL, 3, 3,
223 "Composite LND file"),
224 EF_TRANSP_N(0x6F35, SFI_NONE, "EF.DFLTSTSTGGT", F_OPTIONAL, 16, 16,
225 "Status Default Target"),
226 EF_TRANSP_N(0x6F36, SFI_NONE, "EF.SDSMEM_STATUS", F_OPTIONAL, 7, 7,
227 "SDS Memory Status"),
228 EF_TRANSP_N(0x6F37, SFI_NONE, "EF.WELCOME", F_OPTIONAL, 32, 32,
229 "Welcome Message"),
230 EF_LIN_FIX_N(0x6F38, SFI_NONE, "EF.SDSR", F_OPTIONAL, 2, 2,
231 "SDS delivery report"),
232 EF_LIN_FIX_N(0x6F39, SFI_NONE, "EF.SDSP", F_OPTIONAL, 20, 35,
233 "SDS parameters"),
234 EF_TRANSP_N(0x6F46, SFI_NONE, "EF.DIALSC", 0, 5, 5,
235 "Dialling schemes for TETRA network"),
236 EF_TRANSP_N(0x6F3E, SFI_NONE, "EF.APN", F_OPTIONAL, 65, 65,
237 "APN table"),
238 EF_LIN_FIX_N(0x6FC0, SFI_NONE, "EF.PNI", F_OPTIONAL, 14, 14,
239 "Private Number Information"),
Harald Weltee8dd2bd2014-05-04 13:42:38 +0200240};
241
Harald Welteaad7e062014-05-04 16:31:24 +0200242struct osim_card_profile *osim_cprof_tsim(void *ctx)
Harald Weltee8dd2bd2014-05-04 13:42:38 +0200243{
244 struct osim_card_profile *cprof;
Harald Welte6729a972014-10-26 19:04:56 +0100245 struct osim_file_desc *mf;
246 int rc;
Harald Weltee8dd2bd2014-05-04 13:42:38 +0200247
248 cprof = talloc_zero(ctx, struct osim_card_profile);
Harald Welteaad7e062014-05-04 16:31:24 +0200249 cprof->name = "TETRA SIM";
250 cprof->sws = tsim_card_sws;
Harald Weltee8dd2bd2014-05-04 13:42:38 +0200251
252 mf = alloc_df(cprof, 0x3f00, "MF");
253
254 cprof->mf = mf;
255
256 add_filedesc(mf, sim_ef_in_mf, ARRAY_SIZE(sim_ef_in_mf));
Harald Welteaad7e062014-05-04 16:31:24 +0200257 add_df_with_ef(mf, 0x7F20, "DF.TETRA", sim_ef_in_tetra,
258 ARRAY_SIZE(sim_ef_in_tetra));
259
Harald Welte6729a972014-10-26 19:04:56 +0100260 rc = osim_int_cprof_add_telecom(mf);
261 if (rc != 0) {
262 talloc_free(cprof);
263 return NULL;
264 }
Harald Weltee8dd2bd2014-05-04 13:42:38 +0200265
266 return cprof;
267}