blob: f07a2370290a4f4f3858ac03ab39f440b6358572 [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 *
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 */
Harald Welted54c2ee2012-01-17 18:25:50 +010021
22#include <errno.h>
23#include <string.h>
24
25#include <osmocom/sim/sim.h>
26#include <osmocom/core/talloc.h>
27#include <osmocom/gsm/gsm48.h>
28
29#include "sim_int.h"
30
Harald Weltebb5f3c72014-05-04 13:59:41 +020031/* 3GPP TS 51.011 / Chapter 9.4 */
Harald Welted54c2ee2012-01-17 18:25:50 +010032static const struct osim_card_sw ts11_11_sw[] = {
33 {
34 0x9000, 0xffff, SW_TYPE_STR, SW_CLS_OK,
35 .u.str = "Normal ending of the command",
36 }, {
37 0x9100, 0xff00, SW_TYPE_STR, SW_CLS_OK,
38 .u.str = "Normal ending of the command - proactive command from SIM pending",
39 }, {
40 0x9e00, 0xff00, SW_TYPE_STR, SW_CLS_OK,
41 .u.str = "Normal ending of the command - response data for SIM data download",
42 }, {
43 0x9f00, 0xff00, SW_TYPE_STR, SW_CLS_OK,
44 .u.str = "Normal ending of the command - response data available",
45 }, {
46 0x9300, 0xffff, SW_TYPE_STR, SW_CLS_POSTP,
47 .u.str = "SIM Application Toolkit is busy, command cannot be executed at present",
48 }, {
49 0x9200, 0xfff0, SW_TYPE_STR, SW_CLS_WARN,
Thorsten Alteholz5a9dbf82018-04-08 19:13:25 +020050 .u.str = "Memory management - Command successful but after using an internal update retry X times",
Harald Welted54c2ee2012-01-17 18:25:50 +010051 }, {
52 0x9240, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
53 .u.str = "Memory management - Memory problem",
54 }, {
55 0x9400, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
56 .u.str = "Referencing management - no EF selected",
57 }, {
58 0x9402, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
59 .u.str = "Referencing management - out of range (invalid address)",
60 }, {
61 0x9404, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
62 .u.str = "Referencing management - file ID not found / pattern not found",
63 }, {
Harald Weltebb5f3c72014-05-04 13:59:41 +020064 0x9408, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
65 .u.str = "Referencing management - file is inconsistent with the command",
66 }, {
Harald Welted54c2ee2012-01-17 18:25:50 +010067 0x9802, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
68 .u.str = "Security management - no CHV initialized",
69 }, {
70 0x9804, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
71 .u.str = "Security management - access condition not fulfilled",
72 }, {
73 0x9808, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
74 .u.str = "Security management - in contradiction with CHV status",
75 }, {
76 0x9810, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
77 .u.str = "Security management - in contradiction with invalidation status",
78 }, {
79 0x9840, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
80 .u.str = "Security management - unsuccessful CHV verification, no attempt left",
81 }, {
82 0x9850, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
83 .u.str = "Security management - increase cannot be performed, max value reached",
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 *sim_card_sws[] = {
104 ts11_11_sw,
105 NULL
106};
107
108static int iccid_decode(struct osim_decoded_data *dd,
109 const struct osim_file_desc *desc,
110 int len, uint8_t *data)
111{
112 struct osim_decoded_element *elem;
113
114 elem = element_alloc(dd, "ICCID", ELEM_T_BCD, ELEM_REPR_DEC);
115 elem->length = len;
116 elem->u.buf = talloc_memdup(elem, data, len);
117
118 return 0;
119}
120
121static int elp_decode(struct osim_decoded_data *dd,
122 const struct osim_file_desc *desc,
123 int len, uint8_t *data)
124{
125 int i, num_lp = len / 2;
126
127 for (i = 0; i < num_lp; i++) {
128 uint8_t *cur = data + i*2;
129 struct osim_decoded_element *elem;
130 elem = element_alloc(dd, "Language Code", ELEM_T_STRING, ELEM_REPR_NONE);
131 elem->u.buf = (uint8_t *) talloc_strndup(elem, (const char *) cur, 2);
132 }
133
134 return 0;
135}
136
Harald Welted54c2ee2012-01-17 18:25:50 +0100137/* 10.3.1 */
138int gsm_lp_decode(struct osim_decoded_data *dd,
139 const struct osim_file_desc *desc,
140 int len, uint8_t *data)
141{
142 int i;
143
144 for (i = 0; i < len; i++) {
145 struct osim_decoded_element *elem;
146 elem = element_alloc(dd, "Language Code", ELEM_T_UINT8, ELEM_REPR_DEC);
147 elem->u.u8 = data[i];
148 }
149
150 return 0;
151}
152
153/* 10.3.2 */
154int gsm_imsi_decode(struct osim_decoded_data *dd,
155 const struct osim_file_desc *desc,
156 int len, uint8_t *data)
157{
158 struct osim_decoded_element *elem;
159
160 if (len < 2)
161 return -EINVAL;
162
163 elem = element_alloc(dd, "IMSI", ELEM_T_BCD, ELEM_REPR_DEC);
164 elem->length = data[0];
165 elem->u.buf = talloc_memdup(elem, data+1, len-1);
166
167 return 0;
168}
169
170/* 10.3.3 */
171static int gsm_kc_decode(struct osim_decoded_data *dd,
172 const struct osim_file_desc *desc,
173 int len, uint8_t *data)
174{
175 struct osim_decoded_element *kc, *cksn;
176
177 if (len < 9)
178 return -EINVAL;
179
180 kc = element_alloc(dd, "Kc", ELEM_T_BYTES, ELEM_REPR_HEX);
181 kc->u.buf = talloc_memdup(kc, data, 8);
182 cksn = element_alloc(dd, "CKSN", ELEM_T_UINT8, ELEM_REPR_DEC);
183 cksn->u.u8 = data[8];
184
185 return 0;
186}
187
188/* 10.3.4 */
189static int gsm_plmnsel_decode(struct osim_decoded_data *dd,
190 const struct osim_file_desc *desc,
191 int len, uint8_t *data)
192{
193 int i, n_plmn = len / 3;
194
195 if (n_plmn < 1)
196 return -EINVAL;
197
198 for (i = 0; i < n_plmn; i++) {
199 uint8_t *cur = data + 3*i;
200 struct osim_decoded_element *elem, *mcc, *mnc;
201 uint8_t ra_buf[6];
202 struct gprs_ra_id ra_id;
203
204 memset(ra_buf, 0, sizeof(ra_buf));
205 memcpy(ra_buf, cur, 3);
206 gsm48_parse_ra(&ra_id, ra_buf);
207
208 elem = element_alloc(dd, "PLMN", ELEM_T_GROUP, ELEM_REPR_NONE);
209
210 mcc = element_alloc_sub(elem, "MCC", ELEM_T_UINT16, ELEM_REPR_DEC);
211 mcc->u.u16 = ra_id.mcc;
212
213 mnc = element_alloc_sub(elem, "MNC", ELEM_T_UINT16, ELEM_REPR_DEC);
214 mnc->u.u16 = ra_id.mnc;
Neels Hofmeyrc4fce142018-02-20 13:47:08 +0100215 /* TODO: what about ra_id.mnc_3_digits? */
Harald Welted54c2ee2012-01-17 18:25:50 +0100216 }
217
218 return 0;
219}
220
221/* 10.3.5 */
222int gsm_hpplmn_decode(struct osim_decoded_data *dd,
223 const struct osim_file_desc *desc,
224 int len, uint8_t *data)
225{
226 struct osim_decoded_element *elem;
227
228 elem = element_alloc(dd, "Time interval", ELEM_T_UINT8, ELEM_REPR_DEC);
229 elem->u.u8 = *data;
230
231 return 0;
232}
233
Harald Weltebb5f3c72014-05-04 13:59:41 +0200234/* Chapter 10.1. Contents of the EFs at the MF level */
Harald Welted54c2ee2012-01-17 18:25:50 +0100235static const struct osim_file_desc sim_ef_in_mf[] = {
Harald Weltebb5f3c72014-05-04 13:59:41 +0200236 EF_TRANSP(0x2FE2, SFI_NONE, "EF.ICCID", 0, 10, 10,
Harald Welted54c2ee2012-01-17 18:25:50 +0100237 "ICC Identification", &iccid_decode, NULL),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200238 EF_TRANSP(0x2F05, SFI_NONE, "EF.PL", F_OPTIONAL, 2, 20,
239 "Preferred language", &elp_decode, NULL),
Harald Welted54c2ee2012-01-17 18:25:50 +0100240};
241
Harald Weltebb5f3c72014-05-04 13:59:41 +0200242/* Chapter 10.3.x Contents of files at the GSM application level */
Harald Welte6729a972014-10-26 19:04:56 +0100243static const struct osim_file_desc sim_ef_in_gsm[] = {
Harald Weltebb5f3c72014-05-04 13:59:41 +0200244 EF_TRANSP(0x6F05, SFI_NONE, "EF.LP", 0, 1, 16,
Harald Welted54c2ee2012-01-17 18:25:50 +0100245 "Language preference", &gsm_lp_decode, NULL),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200246 EF_TRANSP(0x6F07, SFI_NONE, "EF.IMSI", 0, 9, 9,
Harald Welted54c2ee2012-01-17 18:25:50 +0100247 "IMSI", &gsm_imsi_decode, NULL),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200248 EF_TRANSP(0x6F20, SFI_NONE, "EF.Kc", 0, 9, 9,
Harald Welted54c2ee2012-01-17 18:25:50 +0100249 "Ciphering key Kc", &gsm_kc_decode, NULL),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200250 EF_TRANSP(0x6F30, SFI_NONE, "EF.PLMNsel", F_OPTIONAL, 24, 72,
Harald Welted54c2ee2012-01-17 18:25:50 +0100251 "PLMN selector", &gsm_plmnsel_decode, NULL),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200252 EF_TRANSP(0x6F31, SFI_NONE, "EF.HPPLMN", 0, 1, 1,
Harald Welted54c2ee2012-01-17 18:25:50 +0100253 "Higher Priority PLMN search period", &gsm_hpplmn_decode, NULL),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200254 EF_TRANSP_N(0x6F37, SFI_NONE, "EF.ACMmax", F_OPTIONAL, 3, 3,
Harald Welted54c2ee2012-01-17 18:25:50 +0100255 "ACM maximum value"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200256 EF_TRANSP_N(0x6F38, SFI_NONE, "EF.SST", 0, 2, 16,
Harald Welted54c2ee2012-01-17 18:25:50 +0100257 "SIM service table"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200258 EF_CYCLIC_N(0x6F39, SFI_NONE, "EF.ACM", F_OPTIONAL, 3, 3,
Harald Welted54c2ee2012-01-17 18:25:50 +0100259 "Accumulated call meter"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200260 EF_TRANSP_N(0x6F3E, SFI_NONE, "EF.GID1", F_OPTIONAL, 1, 8,
Harald Welted54c2ee2012-01-17 18:25:50 +0100261 "Group Identifier Level 1"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200262 EF_TRANSP_N(0x6F3F, SFI_NONE, "EF.GID2", F_OPTIONAL, 1, 8,
Harald Welted54c2ee2012-01-17 18:25:50 +0100263 "Group Identifier Level 2"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200264 EF_TRANSP_N(0x6F46, SFI_NONE, "EF.SPN", F_OPTIONAL, 17, 17,
Harald Welted54c2ee2012-01-17 18:25:50 +0100265 "Service Provider Name"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200266 EF_TRANSP_N(0x6F41, SFI_NONE, "EF.PUCT", F_OPTIONAL, 5, 5,
Harald Welted54c2ee2012-01-17 18:25:50 +0100267 "Price per unit and currency table"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200268 EF_TRANSP_N(0x6F45, SFI_NONE, "EF.CBMI", F_OPTIONAL, 2, 32,
Harald Welted54c2ee2012-01-17 18:25:50 +0100269 "Cell broadcast massage identifier selection"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200270 EF_TRANSP_N(0x6F74, SFI_NONE, "EF.BCCH", 0, 16, 16,
Harald Welted54c2ee2012-01-17 18:25:50 +0100271 "Broadcast control channels"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200272 EF_TRANSP_N(0x6F78, SFI_NONE, "EF.ACC", 0, 2, 2,
Harald Welted54c2ee2012-01-17 18:25:50 +0100273 "Access control class"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200274 EF_TRANSP_N(0x6F7B, SFI_NONE, "EF.FPLMN", 0, 12, 12,
Harald Welted54c2ee2012-01-17 18:25:50 +0100275 "Forbidden PLMNs"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200276 EF_TRANSP_N(0x6F7E, SFI_NONE, "EF.LOCI", 0, 11, 11,
Harald Welted54c2ee2012-01-17 18:25:50 +0100277 "Location information"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200278 EF_TRANSP_N(0x6FAD, SFI_NONE, "EF.AD", 0, 3, 8,
Harald Welted54c2ee2012-01-17 18:25:50 +0100279 "Administrative data"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200280 EF_TRANSP_N(0x6FAE, SFI_NONE, "EF.Phase", 0, 1, 1,
Harald Welted54c2ee2012-01-17 18:25:50 +0100281 "Phase identification"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200282 EF_TRANSP_N(0x6FB1, SFI_NONE, "EF.VGCS", F_OPTIONAL, 4, 80,
Harald Welted54c2ee2012-01-17 18:25:50 +0100283 "Voice Group Call Service"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200284 EF_TRANSP_N(0x6FB2, SFI_NONE, "EF.VGCSS", F_OPTIONAL, 7, 7,
Harald Welted54c2ee2012-01-17 18:25:50 +0100285 "Voice Group Call Service Status"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200286 EF_TRANSP_N(0x6FB3, SFI_NONE, "EF.VBS", F_OPTIONAL, 4, 80,
Harald Welted54c2ee2012-01-17 18:25:50 +0100287 "Voice Broadcast Service"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200288 EF_TRANSP_N(0x6FB4, SFI_NONE, "EF.VBSS", F_OPTIONAL, 7, 7,
Harald Welted54c2ee2012-01-17 18:25:50 +0100289 "Voice Broadcast Service Status"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200290 EF_TRANSP_N(0x6FB5, SFI_NONE, "EF.eMLPP", F_OPTIONAL, 2, 2,
Harald Welted54c2ee2012-01-17 18:25:50 +0100291 "enhanced Mult Level Pre-emption and Priority"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200292 EF_TRANSP_N(0x6FB6, SFI_NONE, "EF.AAeM", F_OPTIONAL, 1, 1,
Harald Welted54c2ee2012-01-17 18:25:50 +0100293 "Automatic Answer for eMLPP Service"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200294 EF_TRANSP_N(0x6F48, SFI_NONE, "EF.CBMID", F_OPTIONAL, 2, 32,
Harald Welted54c2ee2012-01-17 18:25:50 +0100295 "Cell Broadcast Message Identifier for Data Download"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200296 EF_TRANSP_N(0x6FB7, SFI_NONE, "EF.ECC", F_OPTIONAL, 3, 15,
Harald Welted54c2ee2012-01-17 18:25:50 +0100297 "Emergency Call Code"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200298 EF_TRANSP_N(0x6F50, SFI_NONE, "EF.CBMIR", F_OPTIONAL, 4, 64,
Harald Welted54c2ee2012-01-17 18:25:50 +0100299 "Cell broadcast message identifier range selection"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200300 EF_TRANSP_N(0x6F2C, SFI_NONE, "EF.DCK", F_OPTIONAL, 16, 16,
Harald Welted54c2ee2012-01-17 18:25:50 +0100301 "De-personalization Control Keys"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200302 EF_TRANSP_N(0x6F32, SFI_NONE, "EF.CNL", F_OPTIONAL, 6, 60,
Harald Welted54c2ee2012-01-17 18:25:50 +0100303 "Co-operative Network List"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200304 EF_LIN_FIX_N(0x6F51, SFI_NONE, "EF.NIA", F_OPTIONAL, 1, 17,
Harald Welted54c2ee2012-01-17 18:25:50 +0100305 "Network's Indication of Alerting"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200306 EF_TRANSP_N(0x6F52, SFI_NONE, "EF.KcGPRS", F_OPTIONAL, 9, 9,
Harald Welted54c2ee2012-01-17 18:25:50 +0100307 "GPRS Ciphering key KcGPRS"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200308 EF_TRANSP_N(0x6F53, SFI_NONE, "EF.LOCIGPRS", F_OPTIONAL, 14, 14,
Harald Welted54c2ee2012-01-17 18:25:50 +0100309 "GPRS location information"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200310 EF_TRANSP_N(0x6F54, SFI_NONE, "EF.SUME", F_OPTIONAL, 1, 64,
Harald Welted54c2ee2012-01-17 18:25:50 +0100311 "SetUpMenu Elements"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200312 EF_TRANSP_N(0x6F60, SFI_NONE, "EF.PLMNwAcT", F_OPTIONAL, 40, 80,
Harald Welted54c2ee2012-01-17 18:25:50 +0100313 "User controlled PLMN Selector with Access Technology"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200314 EF_TRANSP_N(0x6F61, SFI_NONE, "EF.OPLMNwAcT", F_OPTIONAL, 40, 80,
Harald Welted54c2ee2012-01-17 18:25:50 +0100315 "Operator controlled PLMN Selector with Access Technology"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200316 EF_TRANSP_N(0x6F62, SFI_NONE, "EF.HPLMNwAcT", F_OPTIONAL, 5, 20,
Harald Welted54c2ee2012-01-17 18:25:50 +0100317 "HPLMN Selector with Access Technology"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200318 EF_TRANSP_N(0x6F63, SFI_NONE, "EF.CPBCCH", F_OPTIONAL, 2, 20,
Harald Welted54c2ee2012-01-17 18:25:50 +0100319 "CPBCCH Information"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200320 EF_TRANSP_N(0x6F64, SFI_NONE, "EF.InvScan", F_OPTIONAL, 1, 1,
Harald Welted54c2ee2012-01-17 18:25:50 +0100321 "Investigation Scan"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200322 EF_LIN_FIX_N(0x6FC5, SFI_NONE, "EF.PNN", F_OPTIONAL, 3, 20,
323 "PLMN Network Name"),
324 EF_LIN_FIX_N(0x6FC6, SFI_NONE, "EF.OPL", F_OPTIONAL, 8, 8,
325 "PLMN Operator PLMN List"),
326 EF_LIN_FIX_N(0x6FC7, SFI_NONE, "EF.MBDN", F_OPTIONAL, 14, 30,
327 "Mailbox Dialling Number"),
328 EF_LIN_FIX_N(0x6FC9, SFI_NONE, "EF.MBI", F_OPTIONAL, 4, 4,
329 "Maibox Identifier"),
330 EF_LIN_FIX_N(0x6FCA, SFI_NONE, "EF.MWIS", F_OPTIONAL, 5, 5,
331 "Message Waiting Indication Status"),
332 EF_LIN_FIX_N(0x6FCB, SFI_NONE, "EF.CFIS", F_OPTIONAL, 16, 16,
333 "Call Forwarding Indication Status"),
334 EF_LIN_FIX_N(0x6FC8, SFI_NONE, "EF.EXT6", F_OPTIONAL, 13, 13,
335 "Extension6 (MBDN)"),
336 EF_LIN_FIX_N(0x6FCC, SFI_NONE, "EF.EXT7", F_OPTIONAL, 13, 13,
337 "Extension7 (CFIS)"),
338 EF_TRANSP_N(0x6FCD, SFI_NONE, "EF.SPDI", F_OPTIONAL, 1, 32,
339 "Extension7 (CFIS)"),
340 EF_LIN_FIX_N(0x6FCE, SFI_NONE, "EF.MMSN", F_OPTIONAL, 4, 32,
341 "MMS Notification"),
342 EF_LIN_FIX_N(0x6FCF, SFI_NONE, "EF.EXT8", F_OPTIONAL, 2, 18,
343 "Extension8 (MMSN)"),
344 EF_TRANSP_N(0x6FD0, SFI_NONE, "EF.MMSICP", F_OPTIONAL, 1, 64,
345 "MMS Issuer Connectivity Parameters"),
346 EF_LIN_FIX_N(0x6FD1, SFI_NONE, "EF.MMSUP", F_OPTIONAL, 1, 64,
347 "MMS User Preferences"),
348 EF_TRANSP_N(0x6FD2, SFI_NONE, "EF.MMSUCP", F_OPTIONAL, 1, 64,
349 "MMS User Connectivity Parameters"),
350};
Harald Weltebb5f3c72014-05-04 13:59:41 +0200351
352/* 10.4.1 Contents of the files at the SoLSA level */
353static const struct osim_file_desc sim_ef_in_solsa[] = {
354 EF_TRANSP_N(0x4F30, SFI_NONE, "EF.SAI", F_OPTIONAL, 1, 32,
355 "SoLSA Access Indicator"),
356 EF_LIN_FIX_N(0x4F31, SFI_NONE, "EF.SLL", F_OPTIONAL, 1, 32,
357 "SoLSA LSA List"),
358 /* LSA Descriptor files */
Harald Welted54c2ee2012-01-17 18:25:50 +0100359};
360
Harald Weltebb5f3c72014-05-04 13:59:41 +0200361/* 10.4.2 Contents of files at the MExE level */
362static const struct osim_file_desc sim_ef_in_mexe[] = {
363 EF_TRANSP_N(0x4F40, SFI_NONE, "EF.MExE-ST", F_OPTIONAL, 1, 8,
364 "MExE Service table"),
365 EF_LIN_FIX_N(0x4F41, SFI_NONE, "EF.ORPK", F_OPTIONAL, 11, 32,
366 "Operator Root Public Key"),
367 EF_LIN_FIX_N(0x4F42, SFI_NONE, "EF.ARPK", F_OPTIONAL, 11, 32,
368 "Administrator Root Public Key"),
369 EF_LIN_FIX_N(0x4F43, SFI_NONE, "EF.TRPK", F_OPTIONAL, 11, 32,
370 "Third Party Root Public Key"),
371};
372
373/* 10.5 Contents of files at the telecom level */
Harald Welte6729a972014-10-26 19:04:56 +0100374static const struct osim_file_desc sim_ef_in_telecom[] = {
Harald Weltebb5f3c72014-05-04 13:59:41 +0200375 EF_LIN_FIX_N(0x6F3A, SFI_NONE, "EF.ADN", F_OPTIONAL, 14, 30,
Harald Welted54c2ee2012-01-17 18:25:50 +0100376 "Abbreviated dialling numbers"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200377 EF_LIN_FIX_N(0x6F3B, SFI_NONE, "EF.FDN", F_OPTIONAL, 14, 30,
Harald Welted54c2ee2012-01-17 18:25:50 +0100378 "Fixed dialling numbers"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200379 EF_LIN_FIX_N(0x6F3C, SFI_NONE, "EF.SMS", F_OPTIONAL, 176, 176,
Harald Welted54c2ee2012-01-17 18:25:50 +0100380 "Short messages"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200381 EF_LIN_FIX_N(0x6F3D, SFI_NONE, "EF.CCP", F_OPTIONAL, 14, 14,
Harald Welted54c2ee2012-01-17 18:25:50 +0100382 "Capability configuration parameters"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200383 EF_LIN_FIX_N(0x6F4F, SFI_NONE, "EF.ECCP", F_OPTIONAL, 15, 15,
Harald Welted54c2ee2012-01-17 18:25:50 +0100384 "Extended Capability configuration parameters"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200385 EF_LIN_FIX_N(0x6F40, SFI_NONE, "EF.MSISDN", F_OPTIONAL, 14, 30,
Harald Welted54c2ee2012-01-17 18:25:50 +0100386 "MSISDN"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200387 EF_LIN_FIX_N(0x6F42, SFI_NONE, "EF.SMSP", F_OPTIONAL, 28, 44,
Harald Welted54c2ee2012-01-17 18:25:50 +0100388 "Short message service parameters"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200389 EF_TRANSP_N(0x6F43, SFI_NONE, "EF.SMSS", F_OPTIONAL, 2, 3,
Harald Welted54c2ee2012-01-17 18:25:50 +0100390 "SMS Status"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200391 EF_CYCLIC_N(0x6F44, SFI_NONE, "EF.LND", F_OPTIONAL, 14, 30,
Harald Welted54c2ee2012-01-17 18:25:50 +0100392 "Last number dialled"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200393 EF_LIN_FIX_N(0x6F49, SFI_NONE, "EF.SDN", F_OPTIONAL, 14, 30,
394 "Service Dialling Numbers"),
395 EF_LIN_FIX_N(0x6F4A, SFI_NONE, "EF.EXT1", F_OPTIONAL, 13, 13,
396 "Extension 1 (ADN/SSC, MSISDN, LND)"),
397 EF_LIN_FIX_N(0x6F4B, SFI_NONE, "EF.EXT2", F_OPTIONAL, 13, 13,
398 "Extension 2 (FDN/SSC)"),
399 EF_LIN_FIX_N(0x6F4C, SFI_NONE, "EF.EXT3", F_OPTIONAL, 13, 13,
400 "Extension 3 (SDN)"),
401 EF_LIN_FIX_N(0x6F4D, SFI_NONE, "EF.BDN", F_OPTIONAL, 15, 31,
Harald Welted54c2ee2012-01-17 18:25:50 +0100402 "Barred dialling numbers"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200403 EF_LIN_FIX_N(0x6F4E, SFI_NONE, "EF.EXT4", F_OPTIONAL, 13, 13,
404 "Extension 4 (BDN/SSC)"),
405 EF_LIN_FIX_N(0x6F47, SFI_NONE, "EF.SMSR", F_OPTIONAL, 30, 30,
Harald Welted54c2ee2012-01-17 18:25:50 +0100406 "Short message status reports"),
Harald Weltebb5f3c72014-05-04 13:59:41 +0200407 EF_LIN_FIX_N(0x6F58, SFI_NONE, "EF.CMI", F_OPTIONAL, 1, 17,
Harald Welted54c2ee2012-01-17 18:25:50 +0100408 "Comparison Method Information"),
409};
410
Harald Weltebb5f3c72014-05-04 13:59:41 +0200411/* 10.6.1 Contents of files at the telecom graphics level */
412const struct osim_file_desc sim_ef_in_graphics[] = {
413 EF_LIN_FIX_N(0x4F20, SFI_NONE, "EF.IMG", F_OPTIONAL, 11, 38,
Harald Welted54c2ee2012-01-17 18:25:50 +0100414 "Image"),
415};
416
Harald Welte6729a972014-10-26 19:04:56 +0100417int osim_int_cprof_add_gsm(struct osim_file_desc *mf)
Harald Welted54c2ee2012-01-17 18:25:50 +0100418{
Harald Welte6729a972014-10-26 19:04:56 +0100419 struct osim_file_desc *gsm;
Harald Welted54c2ee2012-01-17 18:25:50 +0100420
Harald Welted54c2ee2012-01-17 18:25:50 +0100421 gsm = add_df_with_ef(mf, 0x7F20, "DF.GSM", sim_ef_in_gsm,
422 ARRAY_SIZE(sim_ef_in_gsm));
Harald Weltebb5f3c72014-05-04 13:59:41 +0200423 /* Chapter 10.2: DFs at the GSM Application Level */
Harald Welted54c2ee2012-01-17 18:25:50 +0100424 add_df_with_ef(gsm, 0x5F30, "DF.IRIDIUM", NULL, 0);
Harald Weltebb5f3c72014-05-04 13:59:41 +0200425 add_df_with_ef(gsm, 0x5F31, "DF.GLOBALSTAR", NULL, 0);
Harald Welted54c2ee2012-01-17 18:25:50 +0100426 add_df_with_ef(gsm, 0x5F32, "DF.ICO", NULL, 0);
427 add_df_with_ef(gsm, 0x5F33, "DF.ACeS", NULL, 0);
Harald Weltebb5f3c72014-05-04 13:59:41 +0200428 add_df_with_ef(gsm, 0x5F3C, "DF.MExE", sim_ef_in_mexe,
429 ARRAY_SIZE(sim_ef_in_mexe));
Harald Welte2d284df2020-03-21 16:23:58 +0100430 add_df_with_ef(gsm, 0x5F40, "DF.EIA-TIA-533", NULL, 0);
Harald Welted54c2ee2012-01-17 18:25:50 +0100431 add_df_with_ef(gsm, 0x5F60, "DF.CTS", NULL, 0);
Harald Weltebb5f3c72014-05-04 13:59:41 +0200432 add_df_with_ef(gsm, 0x5F70, "DF.SoLSA", sim_ef_in_solsa,
433 ARRAY_SIZE(sim_ef_in_solsa));
434
Harald Welte6729a972014-10-26 19:04:56 +0100435 return 0;
436}
437
438int osim_int_cprof_add_telecom(struct osim_file_desc *mf)
439{
440 struct osim_file_desc *tc;
441
Harald Welted54c2ee2012-01-17 18:25:50 +0100442 tc = add_df_with_ef(mf, 0x7F10, "DF.TELECOM", sim_ef_in_telecom,
443 ARRAY_SIZE(sim_ef_in_telecom));
444 add_df_with_ef(tc, 0x5F50, "DF.GRAPHICS", sim_ef_in_graphics,
445 ARRAY_SIZE(sim_ef_in_graphics));
Harald Weltebb5f3c72014-05-04 13:59:41 +0200446 add_df_with_ef(mf, 0x7F22, "DF.IS-41", NULL, 0);
447 add_df_with_ef(mf, 0x7F23, "DF.FP-CTS", NULL, 0); /* TS 11.19 */
Harald Welted54c2ee2012-01-17 18:25:50 +0100448
Harald Welte6729a972014-10-26 19:04:56 +0100449 return 0;
450}
451
452struct osim_card_profile *osim_cprof_sim(void *ctx)
453{
454 struct osim_card_profile *cprof;
455 struct osim_file_desc *mf;
456 int rc;
457
458 cprof = talloc_zero(ctx, struct osim_card_profile);
459 cprof->name = "GSM SIM";
460 cprof->sws = sim_card_sws;
461
462 mf = alloc_df(cprof, 0x3f00, "MF");
463
464 cprof->mf = mf;
465
466 /* According to Figure 8 */
467 add_filedesc(mf, sim_ef_in_mf, ARRAY_SIZE(sim_ef_in_mf));
468
469 rc = osim_int_cprof_add_gsm(mf);
470 rc |= osim_int_cprof_add_telecom(mf);
471 if (rc != 0) {
472 talloc_free(cprof);
473 return NULL;
474 }
475
Harald Welted54c2ee2012-01-17 18:25:50 +0100476 return cprof;
477}