blob: 361c2e8880d831fd1c99855f6fe82c2f0c32d688 [file] [log] [blame]
Harald Welted54c2ee2012-01-17 18:25:50 +01001
2#include <errno.h>
3#include <string.h>
4
5#include <osmocom/sim/sim.h>
6#include <osmocom/core/talloc.h>
7#include <osmocom/gsm/gsm48.h>
8
9#include "sim_int.h"
10#include "gsm_int.h"
11
12/* TS 31.102 Version 7.7.0 / Chapoter 7.3 */
13const struct osim_card_sw ts31_102_sw[] = {
14 {
15 0x9862, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
16 .u.str = "Security management - Authentication error, incorrect MAC",
17 }, {
18 0x9864, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
19 .u.str = "Security management - Authentication error, security context not supported",
20 }, {
21 0x9865, 0xffff, SW_TYPE_STR, SW_CLS_ERROR,
22 .u.str = "Security management - Key freshness error",
23 },
24 OSIM_CARD_SW_LAST
25};
26
27static const struct osim_card_sw *usim_card_sws[] = {
28 ts31_102_sw,
29 ts102221_uicc_sw,
30 NULL
31};
32
33
34static int default_decode(struct osim_decoded_data *dd,
35 const struct osim_file_desc *desc,
36 int len, uint8_t *data)
37{
38 struct osim_decoded_element *elem;
39
40 elem = element_alloc(dd, "Unknown Payload", ELEM_T_BYTES, ELEM_REPR_HEX);
41 elem->u.buf = talloc_memdup(elem, data, len);
42
43 return 0;
44}
45
46/* TS 102 221 Chapter 13.1 */
47static const struct osim_file_desc uicc_ef_in_mf[] = {
48 EF_LIN_FIX_N(0x2f00, "EF.DIR", 0,
49 "Application directory"),
50 EF_TRANSP_N(0x2FE2, "EF.ICCID", 0,
51 "ICC Identification"),
52 EF_TRANSP_N(0x2F05, "EF.PL", 0,
53 "Preferred Languages"),
54 EF_LIN_FIX_N(0x2F06, "EF.ARR", F_OPTIONAL,
55 "Access Rule Reference"),
56};
57
58static const struct osim_file_desc usim_ef_in_df_gsm_access[] = {
59 EF_TRANSP_N(0x4f20, "EF.Kc", 0,
60 "Ciphering Key Kc"),
61 EF_TRANSP_N(0x4f52, "EF.KcGPRS", 0,
62 "GPRS Ciphering key KcGPRS"),
63 EF_TRANSP_N(0x4f63, "EF.CPBCCH", F_OPTIONAL,
64 "CPBCCH Information"),
65 EF_TRANSP_N(0x4f64, "EF.invSCAN", F_OPTIONAL,
66 "Investigation Scan"),
67};
68
69/* 31.102 Chapter 4.2 */
70static const struct osim_file_desc usim_ef_in_adf_usim[] = {
71 EF_TRANSP(0x6F05, "EF.LI", 0,
72 "Language Indication", &gsm_lp_decode, NULL),
73 EF_TRANSP(0x6F07, "EF.IMSI", 0,
74 "IMSI", &gsm_imsi_decode, NULL),
75 EF_TRANSP_N(0x6F08, "EF.Keys", 0,
76 "Ciphering and Integrity Keys"),
77 EF_TRANSP_N(0x6F09, "EF.KeysPS", 0,
78 "Ciphering and Integrity Keys for Packet Switched domain"),
79 EF_TRANSP_N(0x6F60, "EF.PLMNwAcT", F_OPTIONAL,
80 "User controlled PLMN Selector with Access Technology"),
81 EF_TRANSP(0x6F31, "EF.HPPLMN", 0,
82 "Higher Priority PLMN search period", &gsm_hpplmn_decode, NULL),
83 EF_TRANSP_N(0x6F37, "EF.ACMmax", F_OPTIONAL,
84 "ACM maximum value"),
85 EF_TRANSP_N(0x6F38, "EF.UST", 0,
86 "USIM Service Table"),
87 EF_CYCLIC_N(0x6F39, "EF.ACM", F_OPTIONAL,
88 "Accumulated call meter"),
89 EF_TRANSP_N(0x6F3E, "EF.GID1", F_OPTIONAL,
90 "Group Identifier Level 1"),
91 EF_TRANSP_N(0x6F3F, "EF.GID2", F_OPTIONAL,
92 "Group Identifier Level 2"),
93 EF_TRANSP_N(0x6F46, "EF.SPN", F_OPTIONAL,
94 "Service Provider Name"),
95 EF_TRANSP_N(0x6F41, "EF.PUCT", F_OPTIONAL,
96 "Price per unit and currency table"),
97 EF_TRANSP_N(0x6F45, "EF.CBMI", F_OPTIONAL,
98 "Cell broadcast massage identifier selection"),
99 EF_TRANSP_N(0x6F78, "EF.ACC", 0,
100 "Access control class"),
101 EF_TRANSP_N(0x6F7B, "EF.FPLMN", 0,
102 "Forbidden PLMNs"),
103 EF_TRANSP_N(0x6F7E, "EF.LOCI", 0,
104 "Location information"),
105 EF_TRANSP_N(0x6FAD, "EF.AD", 0,
106 "Administrative data"),
107 EF_TRANSP_N(0x6F48, "EF.CBMID", F_OPTIONAL,
108 "Cell Broadcast Message Identifier for Data Download"),
109 EF_TRANSP_N(0x6FB7, "EF.ECC", F_OPTIONAL,
110 "Emergency Call Code"),
111 EF_TRANSP_N(0x6F50, "EF.CBMIR", F_OPTIONAL,
112 "Cell broadcast message identifier range selection"),
113 EF_TRANSP_N(0x6F73, "EF.PSLOCI", 0,
114 "Pacet Switched location information"),
115 EF_LIN_FIX_N(0x6F3B, "EF.FDN", F_OPTIONAL,
116 "Fixed dialling numbers"),
117 EF_LIN_FIX_N(0x6F3C, "EF.SMS", F_OPTIONAL,
118 "Short messages"),
119 EF_LIN_FIX_N(0x6F40, "EF.MSISDN", F_OPTIONAL,
120 "MSISDN"),
121 EF_LIN_FIX_N(0x6F42, "EF.SMSP", F_OPTIONAL,
122 "Short message service parameters"),
123 EF_TRANSP_N(0x6F43, "EF.SMSS", F_OPTIONAL,
124 "SMS Status"),
125 EF_LIN_FIX_N(0x6F49, "EF.SDN", F_OPTIONAL,
126 "Service Dialling Numbers"),
127 EF_LIN_FIX_N(0x6F4B, "EF.EXT2", F_OPTIONAL,
128 "Extension 2"),
129 EF_LIN_FIX_N(0x6F4C, "EF.EXT3", F_OPTIONAL,
130 "Extension 3"),
131 EF_LIN_FIX_N(0x6F47, "EF.SMSR", F_OPTIONAL,
132 "Short message status reports"),
133 EF_CYCLIC_N(0x6F80, "EF.ICI", F_OPTIONAL,
134 "Incoming Calling Information"),
135 EF_CYCLIC_N(0x6F81, "EF.OCI", F_OPTIONAL,
136 "Outgoing Calling Information"),
137 EF_CYCLIC_N(0x6F82, "EF.ICT", F_OPTIONAL,
138 "Incoming Call Timer"),
139 EF_CYCLIC_N(0x6F83, "EF.OCT", F_OPTIONAL,
140 "Outgoing Call Timer"),
141 EF_LIN_FIX_N(0x6F4E, "EF.EXT5", F_OPTIONAL,
142 "Extension 5"),
143 EF_LIN_FIX_N(0x6F4F, "EF.CCP2", F_OPTIONAL,
144 "Capability Configuration Parameters 2"),
145 EF_TRANSP_N(0x6FB5, "EF.eMLPP", F_OPTIONAL,
146 "enhanced Multi Level Precedence and Pre-emption"),
147 EF_TRANSP_N(0x6FB6, "EF.AAeM", F_OPTIONAL,
148 "Automatic Answer for eMLPP Service"),
149 EF_TRANSP_N(0x6FC3, "EF.Hiddenkey", F_OPTIONAL,
150 "Key for hidden phone book entries"),
151 EF_LIN_FIX_N(0x6F4D, "EF.BDN", F_OPTIONAL,
152 "Barred Dialling Numbers"),
153 EF_LIN_FIX_N(0x6F4E, "EF.EXT4", F_OPTIONAL,
154 "Extension 4"),
155 EF_LIN_FIX_N(0x6F58, "EF.CMI", F_OPTIONAL,
156 "Comparison Method Information"),
157 EF_TRANSP_N(0x6F56, "EF.EST", F_OPTIONAL,
158 "Enhanced Services Table"),
159 EF_TRANSP_N(0x6F57, "EF.ACL", F_OPTIONAL,
160 "Access Point Name Control List"),
161 EF_TRANSP_N(0x6F2C, "EF.DCK", F_OPTIONAL,
162 "Depersonalisation Control Keys"),
163 EF_TRANSP_N(0x6F32, "EF.CNL", F_OPTIONAL,
164 "Co-operative Network List"),
165 EF_TRANSP_N(0x6F5B, "EF.START-HFN", 0,
166 "Initialisation values for Hyperframe number"),
167 EF_TRANSP_N(0x6F5C, "EF.THRESHOLD", 0,
168 "Maximum value of START"),
169 EF_TRANSP_N(0x6F61, "EF.OPLMNwAcT", F_OPTIONAL,
170 "Operator controlled PLMN Selector with Access Technology"),
171 EF_TRANSP_N(0x6F62, "EF.HPLMNwAcT", F_OPTIONAL,
172 "HPLMN Selector with Access Technology"),
173 EF_LIN_FIX_N(0x6F06, "EF.ARR", 0,
174 "Access Rule Reference"),
175 EF_TRANSP_N(0x6FC4, "EF.NETPAR", 0,
176 "Network Parameters"),
177 EF_LIN_FIX_N(0x6FC5, "EF.PNN", F_OPTIONAL,
178 "PLMN Network Name"),
179 EF_LIN_FIX_N(0x6FC6, "EF.OPL", F_OPTIONAL,
180 "Operator PLMN List"),
181 EF_LIN_FIX_N(0x6FC7, "EF.MBDN", F_OPTIONAL,
182 "Mailbox Dialling Numbers"),
183 EF_LIN_FIX_N(0x6FC8, "EF.EXT6", F_OPTIONAL,
184 "Extension 6"),
185 EF_LIN_FIX_N(0x6FC9, "EF.MBI", F_OPTIONAL,
186 "Mailbox Identifier"),
187 EF_LIN_FIX_N(0x6FCA, "EF.MWIS", F_OPTIONAL,
188 "Message Waiting Indication Status"),
189 EF_LIN_FIX_N(0x6FCB, "EF.CFIS", F_OPTIONAL,
190 "Call Forwarding Indication Status"),
191 EF_LIN_FIX_N(0x6FCC, "EF.EXT7", F_OPTIONAL,
192 "Extension 7"),
193 EF_TRANSP_N(0x6FCD, "EF.SPDI", F_OPTIONAL,
194 "Service Provider Display Information"),
195 EF_LIN_FIX_N(0x6FCE, "EF.MMSN", F_OPTIONAL,
196 "MMS Notification"),
197 EF_LIN_FIX_N(0x6FCF, "EF.EXT8", F_OPTIONAL,
198 "Extension 8"),
199 EF_TRANSP_N(0x6FD0, "EF.MMSICP", F_OPTIONAL,
200 "MMS Issuer Connectivity Parameters"),
201 EF_LIN_FIX_N(0x6FD1, "EF.MMSUP", F_OPTIONAL,
202 "MMS User Preferences"),
203 EF_TRANSP_N(0x6FD2, "EF.MMSUCP", F_OPTIONAL,
204 "MMS User Connectivity Parameters"),
205 EF_LIN_FIX_N(0x6FD3, "EF.NIA", F_OPTIONAL,
206 "Network's Indication of Alerting"),
207 EF_TRANSP_N(0x6FB1, "EF.VGCS", F_OPTIONAL,
208 "Voice Group Call Service"),
209 EF_TRANSP_N(0x6FB2, "EF.VGCSS", F_OPTIONAL,
210 "Voice Group Call Service Status"),
211 EF_TRANSP_N(0x6FB3, "EF.VBS", F_OPTIONAL,
212 "Voice Broadcast Service"),
213 EF_TRANSP_N(0x6FB4, "EF.VBSS", F_OPTIONAL,
214 "Voice Broadcast Service Status"),
215 EF_TRANSP_N(0x6FD4, "EF.VGCSCA", F_OPTIONAL,
216 "Voice Group Call Service Ciphering Algorithm"),
217 EF_TRANSP_N(0x6FD5, "EF.VBSCA", F_OPTIONAL,
218 "Voice Broadcast Service Ciphering Algorithm"),
219 EF_TRANSP_N(0x6FD6, "EF.GBABP", F_OPTIONAL,
220 "GBA Bootstrapping parameters"),
221 EF_LIN_FIX_N(0x6FD7, "EF.MSK", F_OPTIONAL,
222 "MBMS Serviec Key List"),
223 EF_LIN_FIX_N(0x6FD8, "EF.MUK", F_OPTIONAL,
224 "MBMS User Key"),
225 EF_LIN_FIX_N(0x6FDA, "EF.GBANL", F_OPTIONAL,
226 "GBA NAF List"),
227 EF_TRANSP_N(0x6FD9, "EF.EHPLMN", F_OPTIONAL,
228 "Equivalent HPLMN"),
229};
230
231
232
233/* 31.102 Chapter 4.4.1 */
234static const struct osim_file_desc usim_ef_in_solsa[] = {
235 EF_TRANSP_N(0x4F30, "EF.SAI", F_OPTIONAL,
236 "SoLSA Access Indicator"),
237 EF_LIN_FIX_N(0x4F31, "EF.SLL", F_OPTIONAL,
238 "SoLSA LSA List"),
239 /* LSA descriptor files 4Fxx, hard to represent here */
240};
241
242/* Annex E - TS 101 220 */
243static const uint8_t adf_usim_aid[] = { 0xA0, 0x00, 0x00, 0x00, 0x87, 0x10, 0x02 };
244
245struct osim_card_profile *osim_cprof_usim(void *ctx)
246{
247 struct osim_card_profile *cprof;
248 struct osim_file_desc *mf, *gsm, *tc, *uadf;
249
250 cprof = talloc_zero(ctx, struct osim_card_profile);
251 cprof->name = "3GPP USIM";
252 cprof->sws = usim_card_sws;
253
254 mf = alloc_df(cprof, 0x3f00, "MF");
255
256 cprof->mf = mf;
257
258 /* Core UICC Files */
259 add_filedesc(mf, uicc_ef_in_mf, ARRAY_SIZE(uicc_ef_in_mf));
260
261 /* ADF.USIM with its EF siblings */
262 uadf = add_adf_with_ef(mf, adf_usim_aid, sizeof(adf_usim_aid),
263 "ADF.USIM", usim_ef_in_adf_usim,
264 ARRAY_SIZE(usim_ef_in_adf_usim));
265
266 /* DFs under ADF.USIM */
267 add_df_with_ef(uadf, 0x5F3A, "DF.PHONEBOOK", NULL, 0);
268 add_df_with_ef(uadf, 0x5F3B, "DF.GSM-ACCESS", usim_ef_in_df_gsm_access,
269 ARRAY_SIZE(usim_ef_in_df_gsm_access));
270 add_df_with_ef(uadf, 0x5F3C, "DF.MExE", NULL, 0);
271 add_df_with_ef(uadf, 0x5F40, "DF.WLAN", NULL, 0);
272 add_df_with_ef(uadf, 0x5F70, "DF.SoLSA", usim_ef_in_solsa, ARRAY_SIZE(usim_ef_in_solsa));
273
274#if 0
275 /* DF.TELECOM as sub-directory of MF */
276 tc = add_df_with_ef(mf, 0x7F10, "DF.TELECOM", sim_ef_in_telecom,
277 ARRAY_SIZE(sim_ef_in_telecom));
278 add_df_with_ef(tc, 0x5F50, "DF.GRAPHICS", sim_ef_in_graphics,
279 ARRAY_SIZE(sim_ef_in_graphics));
280
281 /* DF.GSM for backwards compatibility */
282 gsm = add_df_with_ef(mf, 0x7F20, "DF.GSM", sim_ef_in_gsm,
283 ARRAY_SIZE(sim_ef_in_gsm));
284 /* FIXME: DF's below DF.GSM (51.011) */
285#endif
286
287 return cprof;
288}