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