blob: 1411129def7a812e0ce2f40e171f77fa19dfde31 [file] [log] [blame]
Neels Hofmeyr17518fe2017-06-20 04:35:06 +02001/*! \file card_fs_sim.c
2 * classic SIM card specific structures/routines. */
Harald Weltead418632012-09-10 10:49:59 +02003/*
Harald Weltebb5f3c72014-05-04 13:59:41 +02004 * (C) 2012-2014 by Harald Welte <laforge@gnumonks.org>
Harald Weltead418632012-09-10 10:49:59 +02005 *
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 */
Harald Welted54c2ee2012-01-17 18:25:50 +010023
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"
32
Harald Weltebb5f3c72014-05-04 13:59:41 +020033/* 3GPP TS 51.011 / Chapter 9.4 */
Harald Welted54c2ee2012-01-17 18:25:50 +010034static const struct osim_card_sw ts11_11_sw[] = {
35 {
36 0x9000, 0xffff, SW_TYPE_STR, SW_CLS_OK,
37 .u.str = "Normal ending of the command",
38 }, {
39 0x9100, 0xff00, SW_TYPE_STR, SW_CLS_OK,
40 .u.str = "Normal ending of the command - proactive command from SIM pending",
41 }, {
42 0x9e00, 0xff00, SW_TYPE_STR, SW_CLS_OK,
43 .u.str = "Normal ending of the command - response data for SIM data download",
44 }, {
45 0x9f00, 0xff00, SW_TYPE_STR, SW_CLS_OK,
46 .u.str = "Normal ending of the command - response data available",
47 }, {
48 0x9300, 0xffff, SW_TYPE_STR, SW_CLS_POSTP,
49 .u.str = "SIM Application Toolkit is busy, command cannot be executed at present",
50 }, {
51 0x9200, 0xfff0, SW_TYPE_STR, SW_CLS_WARN,
52 .u.str = "Memory management - Command successful but after using an internal updat retry X times",
53 }, {
54 0x9240, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
55 .u.str = "Memory management - Memory problem",
56 }, {
57 0x9400, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
58 .u.str = "Referencing management - no EF selected",
59 }, {
60 0x9402, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
61 .u.str = "Referencing management - out of range (invalid address)",
62 }, {
63 0x9404, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
64 .u.str = "Referencing management - file ID not found / pattern not found",
65 }, {
Harald Weltebb5f3c72014-05-04 13:59:41 +020066 0x9408, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
67 .u.str = "Referencing management - file is inconsistent with the command",
68 }, {
Harald Welted54c2ee2012-01-17 18:25:50 +010069 0x9802, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
70 .u.str = "Security management - no CHV initialized",
71 }, {
72 0x9804, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
73 .u.str = "Security management - access condition not fulfilled",
74 }, {
75 0x9808, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
76 .u.str = "Security management - in contradiction with CHV status",
77 }, {
78 0x9810, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
79 .u.str = "Security management - in contradiction with invalidation status",
80 }, {
81 0x9840, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
82 .u.str = "Security management - unsuccessful CHV verification, no attempt left",
83 }, {
84 0x9850, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
85 .u.str = "Security management - increase cannot be performed, max value reached",
86 }, {
87 0x6700, 0xff00, SW_TYPE_STR, SW_CLS_ERROR,
88 .u.str = "Application independent - incorrect parameter P3",
89 }, {
90 0x6b00, 0xff00, SW_TYPE_STR, SW_CLS_ERROR,
91 .u.str = "Application independent - incorrect parameter P1 or P2",
92 }, {
93 0x6d00, 0xff00, SW_TYPE_STR, SW_CLS_ERROR,
94 .u.str = "Application independent - unknown instruction code",
95 }, {
96 0x6e00, 0xff00, SW_TYPE_STR, SW_CLS_ERROR,
97 .u.str = "Application independent - wrong instruction class",
98 }, {
99 0x6f00, 0xff00, SW_TYPE_STR, SW_CLS_ERROR,
100 .u.str = "Application independent - technical problem with no diagnostic given",
101 },
102 OSIM_CARD_SW_LAST
103};
104
105static const struct osim_card_sw *sim_card_sws[] = {
106 ts11_11_sw,
107 NULL
108};
109
110static int iccid_decode(struct osim_decoded_data *dd,
111 const struct osim_file_desc *desc,
112 int len, uint8_t *data)
113{
114 struct osim_decoded_element *elem;
115
116 elem = element_alloc(dd, "ICCID", ELEM_T_BCD, ELEM_REPR_DEC);
117 elem->length = len;
118 elem->u.buf = talloc_memdup(elem, data, len);
119
120 return 0;
121}
122
123static int elp_decode(struct osim_decoded_data *dd,
124 const struct osim_file_desc *desc,
125 int len, uint8_t *data)
126{
127 int i, num_lp = len / 2;
128
129 for (i = 0; i < num_lp; i++) {
130 uint8_t *cur = data + i*2;
131 struct osim_decoded_element *elem;
132 elem = element_alloc(dd, "Language Code", ELEM_T_STRING, ELEM_REPR_NONE);
133 elem->u.buf = (uint8_t *) talloc_strndup(elem, (const char *) cur, 2);
134 }
135
136 return 0;
137}
138
Harald Welted54c2ee2012-01-17 18:25:50 +0100139/* 10.3.1 */
140int gsm_lp_decode(struct osim_decoded_data *dd,
141 const struct osim_file_desc *desc,
142 int len, uint8_t *data)
143{
144 int i;
145
146 for (i = 0; i < len; i++) {
147 struct osim_decoded_element *elem;
148 elem = element_alloc(dd, "Language Code", ELEM_T_UINT8, ELEM_REPR_DEC);
149 elem->u.u8 = data[i];
150 }
151
152 return 0;
153}
154
155/* 10.3.2 */
156int gsm_imsi_decode(struct osim_decoded_data *dd,
157 const struct osim_file_desc *desc,
158 int len, uint8_t *data)
159{
160 struct osim_decoded_element *elem;
161
162 if (len < 2)
163 return -EINVAL;
164
165 elem = element_alloc(dd, "IMSI", ELEM_T_BCD, ELEM_REPR_DEC);
166 elem->length = data[0];
167 elem->u.buf = talloc_memdup(elem, data+1, len-1);
168
169 return 0;
170}
171
172/* 10.3.3 */
173static int gsm_kc_decode(struct osim_decoded_data *dd,
174 const struct osim_file_desc *desc,
175 int len, uint8_t *data)
176{
177 struct osim_decoded_element *kc, *cksn;
178
179 if (len < 9)
180 return -EINVAL;
181
182 kc = element_alloc(dd, "Kc", ELEM_T_BYTES, ELEM_REPR_HEX);
183 kc->u.buf = talloc_memdup(kc, data, 8);
184 cksn = element_alloc(dd, "CKSN", ELEM_T_UINT8, ELEM_REPR_DEC);
185 cksn->u.u8 = data[8];
186
187 return 0;
188}
189
190/* 10.3.4 */
191static int gsm_plmnsel_decode(struct osim_decoded_data *dd,
192 const struct osim_file_desc *desc,
193 int len, uint8_t *data)
194{
195 int i, n_plmn = len / 3;
196
197 if (n_plmn < 1)
198 return -EINVAL;
199
200 for (i = 0; i < n_plmn; i++) {
201 uint8_t *cur = data + 3*i;
202 struct osim_decoded_element *elem, *mcc, *mnc;
203 uint8_t ra_buf[6];
204 struct gprs_ra_id ra_id;
205
206 memset(ra_buf, 0, sizeof(ra_buf));
207 memcpy(ra_buf, cur, 3);
208 gsm48_parse_ra(&ra_id, ra_buf);
209
210 elem = element_alloc(dd, "PLMN", ELEM_T_GROUP, ELEM_REPR_NONE);
211
212 mcc = element_alloc_sub(elem, "MCC", ELEM_T_UINT16, ELEM_REPR_DEC);
213 mcc->u.u16 = ra_id.mcc;
214
215 mnc = element_alloc_sub(elem, "MNC", ELEM_T_UINT16, ELEM_REPR_DEC);
216 mnc->u.u16 = ra_id.mnc;
217 }
218
219 return 0;
220}
221
222/* 10.3.5 */
223int gsm_hpplmn_decode(struct osim_decoded_data *dd,
224 const struct osim_file_desc *desc,
225 int len, uint8_t *data)
226{
227 struct osim_decoded_element *elem;
228
229 elem = element_alloc(dd, "Time interval", ELEM_T_UINT8, ELEM_REPR_DEC);
230 elem->u.u8 = *data;
231
232 return 0;
233}
234
Harald Weltebb5f3c72014-05-04 13:59:41 +0200235/* Chapter 10.1. Contents of the EFs at the MF level */
Harald Welted54c2ee2012-01-17 18:25:50 +0100236static const struct osim_file_desc sim_ef_in_mf[] = {
Harald Weltebb5f3c72014-05-04 13:59:41 +0200237 EF_TRANSP(0x2FE2, SFI_NONE, "EF.ICCID", 0, 10, 10,
Harald Welted54c2ee2012-01-17 18:25:50 +0100238 "ICC Identification", &iccid_decode, NULL),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200239 EF_TRANSP(0x2F05, SFI_NONE, "EF.PL", F_OPTIONAL, 2, 20,
240 "Preferred language", &elp_decode, NULL),
Harald Welted54c2ee2012-01-17 18:25:50 +0100241};
242
Harald Weltebb5f3c72014-05-04 13:59:41 +0200243/* Chapter 10.3.x Contents of files at the GSM application level */
Harald Welte6729a972014-10-26 19:04:56 +0100244static const struct osim_file_desc sim_ef_in_gsm[] = {
Harald Weltebb5f3c72014-05-04 13:59:41 +0200245 EF_TRANSP(0x6F05, SFI_NONE, "EF.LP", 0, 1, 16,
Harald Welted54c2ee2012-01-17 18:25:50 +0100246 "Language preference", &gsm_lp_decode, NULL),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200247 EF_TRANSP(0x6F07, SFI_NONE, "EF.IMSI", 0, 9, 9,
Harald Welted54c2ee2012-01-17 18:25:50 +0100248 "IMSI", &gsm_imsi_decode, NULL),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200249 EF_TRANSP(0x6F20, SFI_NONE, "EF.Kc", 0, 9, 9,
Harald Welted54c2ee2012-01-17 18:25:50 +0100250 "Ciphering key Kc", &gsm_kc_decode, NULL),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200251 EF_TRANSP(0x6F30, SFI_NONE, "EF.PLMNsel", F_OPTIONAL, 24, 72,
Harald Welted54c2ee2012-01-17 18:25:50 +0100252 "PLMN selector", &gsm_plmnsel_decode, NULL),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200253 EF_TRANSP(0x6F31, SFI_NONE, "EF.HPPLMN", 0, 1, 1,
Harald Welted54c2ee2012-01-17 18:25:50 +0100254 "Higher Priority PLMN search period", &gsm_hpplmn_decode, NULL),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200255 EF_TRANSP_N(0x6F37, SFI_NONE, "EF.ACMmax", F_OPTIONAL, 3, 3,
Harald Welted54c2ee2012-01-17 18:25:50 +0100256 "ACM maximum value"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200257 EF_TRANSP_N(0x6F38, SFI_NONE, "EF.SST", 0, 2, 16,
Harald Welted54c2ee2012-01-17 18:25:50 +0100258 "SIM service table"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200259 EF_CYCLIC_N(0x6F39, SFI_NONE, "EF.ACM", F_OPTIONAL, 3, 3,
Harald Welted54c2ee2012-01-17 18:25:50 +0100260 "Accumulated call meter"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200261 EF_TRANSP_N(0x6F3E, SFI_NONE, "EF.GID1", F_OPTIONAL, 1, 8,
Harald Welted54c2ee2012-01-17 18:25:50 +0100262 "Group Identifier Level 1"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200263 EF_TRANSP_N(0x6F3F, SFI_NONE, "EF.GID2", F_OPTIONAL, 1, 8,
Harald Welted54c2ee2012-01-17 18:25:50 +0100264 "Group Identifier Level 2"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200265 EF_TRANSP_N(0x6F46, SFI_NONE, "EF.SPN", F_OPTIONAL, 17, 17,
Harald Welted54c2ee2012-01-17 18:25:50 +0100266 "Service Provider Name"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200267 EF_TRANSP_N(0x6F41, SFI_NONE, "EF.PUCT", F_OPTIONAL, 5, 5,
Harald Welted54c2ee2012-01-17 18:25:50 +0100268 "Price per unit and currency table"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200269 EF_TRANSP_N(0x6F45, SFI_NONE, "EF.CBMI", F_OPTIONAL, 2, 32,
Harald Welted54c2ee2012-01-17 18:25:50 +0100270 "Cell broadcast massage identifier selection"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200271 EF_TRANSP_N(0x6F74, SFI_NONE, "EF.BCCH", 0, 16, 16,
Harald Welted54c2ee2012-01-17 18:25:50 +0100272 "Broadcast control channels"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200273 EF_TRANSP_N(0x6F78, SFI_NONE, "EF.ACC", 0, 2, 2,
Harald Welted54c2ee2012-01-17 18:25:50 +0100274 "Access control class"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200275 EF_TRANSP_N(0x6F7B, SFI_NONE, "EF.FPLMN", 0, 12, 12,
Harald Welted54c2ee2012-01-17 18:25:50 +0100276 "Forbidden PLMNs"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200277 EF_TRANSP_N(0x6F7E, SFI_NONE, "EF.LOCI", 0, 11, 11,
Harald Welted54c2ee2012-01-17 18:25:50 +0100278 "Location information"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200279 EF_TRANSP_N(0x6FAD, SFI_NONE, "EF.AD", 0, 3, 8,
Harald Welted54c2ee2012-01-17 18:25:50 +0100280 "Administrative data"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200281 EF_TRANSP_N(0x6FAE, SFI_NONE, "EF.Phase", 0, 1, 1,
Harald Welted54c2ee2012-01-17 18:25:50 +0100282 "Phase identification"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200283 EF_TRANSP_N(0x6FB1, SFI_NONE, "EF.VGCS", F_OPTIONAL, 4, 80,
Harald Welted54c2ee2012-01-17 18:25:50 +0100284 "Voice Group Call Service"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200285 EF_TRANSP_N(0x6FB2, SFI_NONE, "EF.VGCSS", F_OPTIONAL, 7, 7,
Harald Welted54c2ee2012-01-17 18:25:50 +0100286 "Voice Group Call Service Status"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200287 EF_TRANSP_N(0x6FB3, SFI_NONE, "EF.VBS", F_OPTIONAL, 4, 80,
Harald Welted54c2ee2012-01-17 18:25:50 +0100288 "Voice Broadcast Service"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200289 EF_TRANSP_N(0x6FB4, SFI_NONE, "EF.VBSS", F_OPTIONAL, 7, 7,
Harald Welted54c2ee2012-01-17 18:25:50 +0100290 "Voice Broadcast Service Status"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200291 EF_TRANSP_N(0x6FB5, SFI_NONE, "EF.eMLPP", F_OPTIONAL, 2, 2,
Harald Welted54c2ee2012-01-17 18:25:50 +0100292 "enhanced Mult Level Pre-emption and Priority"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200293 EF_TRANSP_N(0x6FB6, SFI_NONE, "EF.AAeM", F_OPTIONAL, 1, 1,
Harald Welted54c2ee2012-01-17 18:25:50 +0100294 "Automatic Answer for eMLPP Service"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200295 EF_TRANSP_N(0x6F48, SFI_NONE, "EF.CBMID", F_OPTIONAL, 2, 32,
Harald Welted54c2ee2012-01-17 18:25:50 +0100296 "Cell Broadcast Message Identifier for Data Download"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200297 EF_TRANSP_N(0x6FB7, SFI_NONE, "EF.ECC", F_OPTIONAL, 3, 15,
Harald Welted54c2ee2012-01-17 18:25:50 +0100298 "Emergency Call Code"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200299 EF_TRANSP_N(0x6F50, SFI_NONE, "EF.CBMIR", F_OPTIONAL, 4, 64,
Harald Welted54c2ee2012-01-17 18:25:50 +0100300 "Cell broadcast message identifier range selection"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200301 EF_TRANSP_N(0x6F2C, SFI_NONE, "EF.DCK", F_OPTIONAL, 16, 16,
Harald Welted54c2ee2012-01-17 18:25:50 +0100302 "De-personalization Control Keys"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200303 EF_TRANSP_N(0x6F32, SFI_NONE, "EF.CNL", F_OPTIONAL, 6, 60,
Harald Welted54c2ee2012-01-17 18:25:50 +0100304 "Co-operative Network List"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200305 EF_LIN_FIX_N(0x6F51, SFI_NONE, "EF.NIA", F_OPTIONAL, 1, 17,
Harald Welted54c2ee2012-01-17 18:25:50 +0100306 "Network's Indication of Alerting"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200307 EF_TRANSP_N(0x6F52, SFI_NONE, "EF.KcGPRS", F_OPTIONAL, 9, 9,
Harald Welted54c2ee2012-01-17 18:25:50 +0100308 "GPRS Ciphering key KcGPRS"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200309 EF_TRANSP_N(0x6F53, SFI_NONE, "EF.LOCIGPRS", F_OPTIONAL, 14, 14,
Harald Welted54c2ee2012-01-17 18:25:50 +0100310 "GPRS location information"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200311 EF_TRANSP_N(0x6F54, SFI_NONE, "EF.SUME", F_OPTIONAL, 1, 64,
Harald Welted54c2ee2012-01-17 18:25:50 +0100312 "SetUpMenu Elements"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200313 EF_TRANSP_N(0x6F60, SFI_NONE, "EF.PLMNwAcT", F_OPTIONAL, 40, 80,
Harald Welted54c2ee2012-01-17 18:25:50 +0100314 "User controlled PLMN Selector with Access Technology"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200315 EF_TRANSP_N(0x6F61, SFI_NONE, "EF.OPLMNwAcT", F_OPTIONAL, 40, 80,
Harald Welted54c2ee2012-01-17 18:25:50 +0100316 "Operator controlled PLMN Selector with Access Technology"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200317 EF_TRANSP_N(0x6F62, SFI_NONE, "EF.HPLMNwAcT", F_OPTIONAL, 5, 20,
Harald Welted54c2ee2012-01-17 18:25:50 +0100318 "HPLMN Selector with Access Technology"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200319 EF_TRANSP_N(0x6F63, SFI_NONE, "EF.CPBCCH", F_OPTIONAL, 2, 20,
Harald Welted54c2ee2012-01-17 18:25:50 +0100320 "CPBCCH Information"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200321 EF_TRANSP_N(0x6F64, SFI_NONE, "EF.InvScan", F_OPTIONAL, 1, 1,
Harald Welted54c2ee2012-01-17 18:25:50 +0100322 "Investigation Scan"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200323 EF_LIN_FIX_N(0x6FC5, SFI_NONE, "EF.PNN", F_OPTIONAL, 3, 20,
324 "PLMN Network Name"),
325 EF_LIN_FIX_N(0x6FC6, SFI_NONE, "EF.OPL", F_OPTIONAL, 8, 8,
326 "PLMN Operator PLMN List"),
327 EF_LIN_FIX_N(0x6FC7, SFI_NONE, "EF.MBDN", F_OPTIONAL, 14, 30,
328 "Mailbox Dialling Number"),
329 EF_LIN_FIX_N(0x6FC9, SFI_NONE, "EF.MBI", F_OPTIONAL, 4, 4,
330 "Maibox Identifier"),
331 EF_LIN_FIX_N(0x6FCA, SFI_NONE, "EF.MWIS", F_OPTIONAL, 5, 5,
332 "Message Waiting Indication Status"),
333 EF_LIN_FIX_N(0x6FCB, SFI_NONE, "EF.CFIS", F_OPTIONAL, 16, 16,
334 "Call Forwarding Indication Status"),
335 EF_LIN_FIX_N(0x6FC8, SFI_NONE, "EF.EXT6", F_OPTIONAL, 13, 13,
336 "Extension6 (MBDN)"),
337 EF_LIN_FIX_N(0x6FCC, SFI_NONE, "EF.EXT7", F_OPTIONAL, 13, 13,
338 "Extension7 (CFIS)"),
339 EF_TRANSP_N(0x6FCD, SFI_NONE, "EF.SPDI", F_OPTIONAL, 1, 32,
340 "Extension7 (CFIS)"),
341 EF_LIN_FIX_N(0x6FCE, SFI_NONE, "EF.MMSN", F_OPTIONAL, 4, 32,
342 "MMS Notification"),
343 EF_LIN_FIX_N(0x6FCF, SFI_NONE, "EF.EXT8", F_OPTIONAL, 2, 18,
344 "Extension8 (MMSN)"),
345 EF_TRANSP_N(0x6FD0, SFI_NONE, "EF.MMSICP", F_OPTIONAL, 1, 64,
346 "MMS Issuer Connectivity Parameters"),
347 EF_LIN_FIX_N(0x6FD1, SFI_NONE, "EF.MMSUP", F_OPTIONAL, 1, 64,
348 "MMS User Preferences"),
349 EF_TRANSP_N(0x6FD2, SFI_NONE, "EF.MMSUCP", F_OPTIONAL, 1, 64,
350 "MMS User Connectivity Parameters"),
351};
Harald Weltebb5f3c72014-05-04 13:59:41 +0200352
353/* 10.4.1 Contents of the files at the SoLSA level */
354static const struct osim_file_desc sim_ef_in_solsa[] = {
355 EF_TRANSP_N(0x4F30, SFI_NONE, "EF.SAI", F_OPTIONAL, 1, 32,
356 "SoLSA Access Indicator"),
357 EF_LIN_FIX_N(0x4F31, SFI_NONE, "EF.SLL", F_OPTIONAL, 1, 32,
358 "SoLSA LSA List"),
359 /* LSA Descriptor files */
Harald Welted54c2ee2012-01-17 18:25:50 +0100360};
361
Harald Weltebb5f3c72014-05-04 13:59:41 +0200362/* 10.4.2 Contents of files at the MExE level */
363static const struct osim_file_desc sim_ef_in_mexe[] = {
364 EF_TRANSP_N(0x4F40, SFI_NONE, "EF.MExE-ST", F_OPTIONAL, 1, 8,
365 "MExE Service table"),
366 EF_LIN_FIX_N(0x4F41, SFI_NONE, "EF.ORPK", F_OPTIONAL, 11, 32,
367 "Operator Root Public Key"),
368 EF_LIN_FIX_N(0x4F42, SFI_NONE, "EF.ARPK", F_OPTIONAL, 11, 32,
369 "Administrator Root Public Key"),
370 EF_LIN_FIX_N(0x4F43, SFI_NONE, "EF.TRPK", F_OPTIONAL, 11, 32,
371 "Third Party Root Public Key"),
372};
373
374/* 10.5 Contents of files at the telecom level */
Harald Welte6729a972014-10-26 19:04:56 +0100375static const struct osim_file_desc sim_ef_in_telecom[] = {
Harald Weltebb5f3c72014-05-04 13:59:41 +0200376 EF_LIN_FIX_N(0x6F3A, SFI_NONE, "EF.ADN", F_OPTIONAL, 14, 30,
Harald Welted54c2ee2012-01-17 18:25:50 +0100377 "Abbreviated dialling numbers"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200378 EF_LIN_FIX_N(0x6F3B, SFI_NONE, "EF.FDN", F_OPTIONAL, 14, 30,
Harald Welted54c2ee2012-01-17 18:25:50 +0100379 "Fixed dialling numbers"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200380 EF_LIN_FIX_N(0x6F3C, SFI_NONE, "EF.SMS", F_OPTIONAL, 176, 176,
Harald Welted54c2ee2012-01-17 18:25:50 +0100381 "Short messages"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200382 EF_LIN_FIX_N(0x6F3D, SFI_NONE, "EF.CCP", F_OPTIONAL, 14, 14,
Harald Welted54c2ee2012-01-17 18:25:50 +0100383 "Capability configuration parameters"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200384 EF_LIN_FIX_N(0x6F4F, SFI_NONE, "EF.ECCP", F_OPTIONAL, 15, 15,
Harald Welted54c2ee2012-01-17 18:25:50 +0100385 "Extended Capability configuration parameters"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200386 EF_LIN_FIX_N(0x6F40, SFI_NONE, "EF.MSISDN", F_OPTIONAL, 14, 30,
Harald Welted54c2ee2012-01-17 18:25:50 +0100387 "MSISDN"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200388 EF_LIN_FIX_N(0x6F42, SFI_NONE, "EF.SMSP", F_OPTIONAL, 28, 44,
Harald Welted54c2ee2012-01-17 18:25:50 +0100389 "Short message service parameters"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200390 EF_TRANSP_N(0x6F43, SFI_NONE, "EF.SMSS", F_OPTIONAL, 2, 3,
Harald Welted54c2ee2012-01-17 18:25:50 +0100391 "SMS Status"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200392 EF_CYCLIC_N(0x6F44, SFI_NONE, "EF.LND", F_OPTIONAL, 14, 30,
Harald Welted54c2ee2012-01-17 18:25:50 +0100393 "Last number dialled"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200394 EF_LIN_FIX_N(0x6F49, SFI_NONE, "EF.SDN", F_OPTIONAL, 14, 30,
395 "Service Dialling Numbers"),
396 EF_LIN_FIX_N(0x6F4A, SFI_NONE, "EF.EXT1", F_OPTIONAL, 13, 13,
397 "Extension 1 (ADN/SSC, MSISDN, LND)"),
398 EF_LIN_FIX_N(0x6F4B, SFI_NONE, "EF.EXT2", F_OPTIONAL, 13, 13,
399 "Extension 2 (FDN/SSC)"),
400 EF_LIN_FIX_N(0x6F4C, SFI_NONE, "EF.EXT3", F_OPTIONAL, 13, 13,
401 "Extension 3 (SDN)"),
402 EF_LIN_FIX_N(0x6F4D, SFI_NONE, "EF.BDN", F_OPTIONAL, 15, 31,
Harald Welted54c2ee2012-01-17 18:25:50 +0100403 "Barred dialling numbers"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200404 EF_LIN_FIX_N(0x6F4E, SFI_NONE, "EF.EXT4", F_OPTIONAL, 13, 13,
405 "Extension 4 (BDN/SSC)"),
406 EF_LIN_FIX_N(0x6F47, SFI_NONE, "EF.SMSR", F_OPTIONAL, 30, 30,
Harald Welted54c2ee2012-01-17 18:25:50 +0100407 "Short message status reports"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200408 EF_LIN_FIX_N(0x6F58, SFI_NONE, "EF.CMI", F_OPTIONAL, 1, 17,
Harald Welted54c2ee2012-01-17 18:25:50 +0100409 "Comparison Method Information"),
410};
411
Harald Weltebb5f3c72014-05-04 13:59:41 +0200412/* 10.6.1 Contents of files at the telecom graphics level */
413const struct osim_file_desc sim_ef_in_graphics[] = {
414 EF_LIN_FIX_N(0x4F20, SFI_NONE, "EF.IMG", F_OPTIONAL, 11, 38,
Harald Welted54c2ee2012-01-17 18:25:50 +0100415 "Image"),
416};
417
Harald Welte6729a972014-10-26 19:04:56 +0100418int osim_int_cprof_add_gsm(struct osim_file_desc *mf)
Harald Welted54c2ee2012-01-17 18:25:50 +0100419{
Harald Welte6729a972014-10-26 19:04:56 +0100420 struct osim_file_desc *gsm;
Harald Welted54c2ee2012-01-17 18:25:50 +0100421
Harald Welted54c2ee2012-01-17 18:25:50 +0100422 gsm = add_df_with_ef(mf, 0x7F20, "DF.GSM", sim_ef_in_gsm,
423 ARRAY_SIZE(sim_ef_in_gsm));
Harald Weltebb5f3c72014-05-04 13:59:41 +0200424 /* Chapter 10.2: DFs at the GSM Application Level */
Harald Welted54c2ee2012-01-17 18:25:50 +0100425 add_df_with_ef(gsm, 0x5F30, "DF.IRIDIUM", NULL, 0);
Harald Weltebb5f3c72014-05-04 13:59:41 +0200426 add_df_with_ef(gsm, 0x5F31, "DF.GLOBALSTAR", NULL, 0);
Harald Welted54c2ee2012-01-17 18:25:50 +0100427 add_df_with_ef(gsm, 0x5F32, "DF.ICO", NULL, 0);
428 add_df_with_ef(gsm, 0x5F33, "DF.ACeS", NULL, 0);
Harald Weltebb5f3c72014-05-04 13:59:41 +0200429 add_df_with_ef(gsm, 0x5F3C, "DF.MExE", sim_ef_in_mexe,
430 ARRAY_SIZE(sim_ef_in_mexe));
431 add_df_with_ef(gsm, 0x5F40, "DF.EIA/TIA-533", NULL, 0);
Harald Welted54c2ee2012-01-17 18:25:50 +0100432 add_df_with_ef(gsm, 0x5F60, "DF.CTS", NULL, 0);
Harald Weltebb5f3c72014-05-04 13:59:41 +0200433 add_df_with_ef(gsm, 0x5F70, "DF.SoLSA", sim_ef_in_solsa,
434 ARRAY_SIZE(sim_ef_in_solsa));
435
Harald Welte6729a972014-10-26 19:04:56 +0100436 return 0;
437}
438
439int osim_int_cprof_add_telecom(struct osim_file_desc *mf)
440{
441 struct osim_file_desc *tc;
442
Harald Welted54c2ee2012-01-17 18:25:50 +0100443 tc = add_df_with_ef(mf, 0x7F10, "DF.TELECOM", sim_ef_in_telecom,
444 ARRAY_SIZE(sim_ef_in_telecom));
445 add_df_with_ef(tc, 0x5F50, "DF.GRAPHICS", sim_ef_in_graphics,
446 ARRAY_SIZE(sim_ef_in_graphics));
Harald Weltebb5f3c72014-05-04 13:59:41 +0200447 add_df_with_ef(mf, 0x7F22, "DF.IS-41", NULL, 0);
448 add_df_with_ef(mf, 0x7F23, "DF.FP-CTS", NULL, 0); /* TS 11.19 */
Harald Welted54c2ee2012-01-17 18:25:50 +0100449
Harald Welte6729a972014-10-26 19:04:56 +0100450 return 0;
451}
452
453struct osim_card_profile *osim_cprof_sim(void *ctx)
454{
455 struct osim_card_profile *cprof;
456 struct osim_file_desc *mf;
457 int rc;
458
459 cprof = talloc_zero(ctx, struct osim_card_profile);
460 cprof->name = "GSM SIM";
461 cprof->sws = sim_card_sws;
462
463 mf = alloc_df(cprof, 0x3f00, "MF");
464
465 cprof->mf = mf;
466
467 /* According to Figure 8 */
468 add_filedesc(mf, sim_ef_in_mf, ARRAY_SIZE(sim_ef_in_mf));
469
470 rc = osim_int_cprof_add_gsm(mf);
471 rc |= osim_int_cprof_add_telecom(mf);
472 if (rc != 0) {
473 talloc_free(cprof);
474 return NULL;
475 }
476
Harald Welted54c2ee2012-01-17 18:25:50 +0100477 return cprof;
478}