Harald Welte | e8dd2bd | 2014-05-04 13:42:38 +0200 | [diff] [blame^] | 1 | /* 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" |
| 31 | |
| 32 | /* EN 300 812 V2.1.1 (2001-12) 9.4 */ |
| 33 | static const struct osim_card_sw tsim_sw[] = { |
| 34 | { |
| 35 | 0x9000, 0xffff, SW_TYPE_STR, SW_CLS_OK, |
| 36 | .u.str = "Normal ending of the command", |
| 37 | }, { |
| 38 | 0x9f00, 0xff00, SW_TYPE_STR, SW_CLS_OK, |
| 39 | .u.str = "Normal ending of the command - response data available", |
| 40 | }, { |
| 41 | 0x9300, 0xffff, SW_TYPE_STR, SW_CLS_POSTP, |
| 42 | .u.str = "SIM Application Toolkit is busy, command cannot be executed at present", |
| 43 | }, { |
| 44 | 0x9200, 0xfff0, SW_TYPE_STR, SW_CLS_WARN, |
| 45 | .u.str = "Memory management - Command successful but after using an internal updat retry X times", |
| 46 | }, { |
| 47 | 0x9240, 0xffff, SW_TYPE_STR, SW_CLS_ERROR, |
| 48 | .u.str = "Memory management - Memory problem", |
| 49 | }, { |
| 50 | 0x9400, 0xffff, SW_TYPE_STR, SW_CLS_ERROR, |
| 51 | .u.str = "Referencing management - no EF selected", |
| 52 | }, { |
| 53 | 0x9402, 0xffff, SW_TYPE_STR, SW_CLS_ERROR, |
| 54 | .u.str = "Referencing management - out of range (invalid address)", |
| 55 | }, { |
| 56 | 0x9404, 0xffff, SW_TYPE_STR, SW_CLS_ERROR, |
| 57 | .u.str = "Referencing management - file ID not found / pattern not found", |
| 58 | }, { |
| 59 | 0x9408, 0xffff, SW_TYPE_STR, SW_CLS_ERROR, |
| 60 | .u.str = "Referencing management - file is inconsistent with the command", |
| 61 | }, { |
| 62 | 0x9802, 0xffff, SW_TYPE_STR, SW_CLS_ERROR, |
| 63 | .u.str = "Security management - no CHV initialized", |
| 64 | }, { |
| 65 | 0x9804, 0xffff, SW_TYPE_STR, SW_CLS_ERROR, |
| 66 | .u.str = "Security management - access condition not fulfilled", |
| 67 | }, { |
| 68 | 0x9808, 0xffff, SW_TYPE_STR, SW_CLS_ERROR, |
| 69 | .u.str = "Security management - in contradiction with CHV status", |
| 70 | }, { |
| 71 | 0x9810, 0xffff, SW_TYPE_STR, SW_CLS_ERROR, |
| 72 | .u.str = "Security management - in contradiction with invalidation status", |
| 73 | }, { |
| 74 | 0x9840, 0xffff, SW_TYPE_STR, SW_CLS_ERROR, |
| 75 | .u.str = "Security management - unsuccessful CHV verification, no attempt left", |
| 76 | }, { |
| 77 | 0x9860, 0xffff, SW_TYPE_STR, SW_CLS_ERROR, |
| 78 | .u.str = "Security management - manipulation flag set", |
| 79 | }, { |
| 80 | 0x9870, 0xffff, SW_TYPE_STR, SW_CLS_ERROR, |
| 81 | .u.str = "Security management - SwMI authentication unsuccessful", |
| 82 | }, { |
| 83 | 0x6700, 0xff00, SW_TYPE_STR, SW_CLS_ERROR, |
| 84 | .u.str = "Application independent - incorrect parameter P3", |
| 85 | }, { |
| 86 | 0x6b00, 0xff00, SW_TYPE_STR, SW_CLS_ERROR, |
| 87 | .u.str = "Application independent - incorrect parameter P1 or P2", |
| 88 | }, { |
| 89 | 0x6d00, 0xff00, SW_TYPE_STR, SW_CLS_ERROR, |
| 90 | .u.str = "Application independent - unknown instruction code", |
| 91 | }, { |
| 92 | 0x6e00, 0xff00, SW_TYPE_STR, SW_CLS_ERROR, |
| 93 | .u.str = "Application independent - wrong instruction class", |
| 94 | }, { |
| 95 | 0x6f00, 0xff00, SW_TYPE_STR, SW_CLS_ERROR, |
| 96 | .u.str = "Application independent - technical problem with no diagnostic given", |
| 97 | }, |
| 98 | OSIM_CARD_SW_LAST |
| 99 | }; |
| 100 | |
| 101 | static const struct osim_card_sw *tsim_card_sws[] = { |
| 102 | tsim1_sw, |
| 103 | NULL |
| 104 | }; |
| 105 | |
| 106 | /* Chapter 10.2.x */ |
| 107 | static const struct osim_file_desc sim_ef_in_mf[] = { |
| 108 | EF_TRANSP(0x2FE2, "EF.ICCID", 0, 10, 10, |
| 109 | "ICC Identification", NULL, NULL), |
| 110 | EF_TRANSP(0x2F00, "EF.DIR", F_OPTIONAL, 8, 54, |
| 111 | "Application directory", NULL, NULL), |
| 112 | EF_TRANSP(0x2F05, "EF.LP", 0, 2, 32, |
| 113 | "Language preference", NULL, NULL), |
| 114 | }; |
| 115 | |
| 116 | //////////////////////////// |
| 117 | |
| 118 | /* Chapter 10.3.x */ |
| 119 | static const struct osim_file_desc sim_ef_in_tetra[] = { |
| 120 | EF_TRANSP_N(0x6F01, "EF.SST", 0, 4, 8, |
| 121 | "SIM service table"), |
| 122 | EF_TRANSP_N(0x6F02, "EF.ITSI", 0, 6, 6, |
| 123 | "ITSI", NULL, NULL), |
| 124 | EF_TRANSP_N(0x6F03, "EF.ITSIDIS", 0, 1, 1, |
| 125 | "ITSI Disable"); |
| 126 | EF_TRANSP_N(0x6F05, "EF.SCT", 0, 4, 4, |
| 127 | "Subscriber Class Table"); |
| 128 | EF_TRANSP_N(0x6F06, "EF.PHASE", 0, 1, 1, |
| 129 | "Phase identification"); |
| 130 | EF_KEY_N(0x6F07, "EF.CCK", F_OPTIONAL, 12, 12, |
| 131 | "Common Cipher Key"); |
| 132 | EF_TRANSP_N(0x6F08, "EF.CCKLOC", F_OPTIONAL, 31, 31, |
| 133 | "CCK location areas"); |
| 134 | EF_KEY_N(0x6F09, "EF.SCK", F_OPTIONAL, 12, 12, |
| 135 | "Static Cipher Keys"); |
| 136 | /* X+4 for each record, suggested 1 to 10 */ |
| 137 | EF_LIN_FIX_N(0x6F0A, "EF.GSSIS", 0, 5, 21, |
| 138 | "Static Cipher Keys"); |
| 139 | /* 2 for each record, one for each recod in GSSIS */ |
| 140 | EF_LIN_FIX_N(0x6F0B, "EF.GRDS", 0, 2, 2, |
| 141 | "Group related data for static GSSIS"); |
| 142 | EF_LIN_FIX_N(0x6F0C, "EF.GSSID", 0, 5, 21, |
| 143 | "Dynamic GSSIs"); |
| 144 | /* 2 for each record, one for each recod in GSSID */ |
| 145 | EF_LIN_FIX_N(0x6F0D, "EF.GRDD", 0, 2, 2, |
| 146 | "Dynamic GSSIs"); |
| 147 | EF_LIN_FIX_N(0x6F0E, "EF.GCK", F_OPTIONAL, 12, 12, |
| 148 | "Group Cipher Keys"); |
| 149 | EF_KEY_N(0x6F0F, "EF.MGCK", F_OPTIONAL, 12, 12, |
| 150 | "Modified Group Cipher Keys"); |
| 151 | EF_TRANSP_N(0x6F10, "EF.GINFO", 0, 9, 9, |
| 152 | "User's group information"); |
| 153 | EF_TRANSP_N(0x6F11, "EF.SEC", 0, 1, 1, |
| 154 | "Security settings"); |
| 155 | EF_CYCLIC_N(0x6F12, "EF.FORBID", 0, 3, 3, |
| 156 | "Security settings"); |
| 157 | EF_CYCLIC_N(0x6F13, "EF.PREF", F_OPTIONAL, 3, 3, |
| 158 | "Preferred networks"); |
| 159 | EF_TRANSP_N(0x6F14, "EF.SPN", F_OPTIONAL, 17, 17, |
| 160 | "Service Provider Name"); |
| 161 | EF_TRANSP_N(0x6F15, "EF.LOCI", F_OPTIONAL, 7, 7, |
| 162 | "Location Information"); |
| 163 | EF_TRANSP_N(0x6F16, "EF.DNWRK", 0, 3, 3, |
| 164 | "Broadcast network information"); |
| 165 | EF_LIN_FIX_N(0x6F17, "EF.NWT", 0, 5, 5, |
| 166 | "Network table"); |
| 167 | EF_LIN_FIX_N(0x6F18, "EF.GWT", F_OPTIONAL, 13, 13, |
| 168 | "Gateway table"); |
| 169 | EF_LIN_FIX_N(0x6F19, "EF.CMT", F_OPTIONAL, 5, 20, |
| 170 | "Call Modifier Table"); |
| 171 | EF_LIN_FIX_N(0x6F1A, "EF.ADNGWT", F_OPTIONAL, 13, 28, |
| 172 | "Abbreviated Dialling Number with Gateways"); |
| 173 | EF_LIN_FIX_N(0x6F1C, "EF.ADNTETRA", F_OPTIONAL, 9, 23, |
| 174 | "Abbreviated dialling numbers for TETRA network"); |
| 175 | EF_LIN_FIX_N(0x6F1D, "EF.EXTA", F_OPTIONAL, 20, 20, |
| 176 | "Extension A"); |
| 177 | EF_LIN_FIX_N(0x6F1E, "EF.FDNGWT", F_OPTIONAL, 13, 28, |
| 178 | "Fixed dialling numbers with Gateways"); |
| 179 | EF_LIN_FIX_N(0x6F1F, "EF.GWTEXT2", F_OPTIONAL, 13, 13, |
| 180 | "Gateway Extension2"); |
| 181 | EF_LIN_FIX_N(0x6F20, "EF.FDNTETRA", F_OPTIONAL, 9, 25, |
| 182 | "Fixed dialling numbers for TETRA network"); |
| 183 | EF_LIN_FIX_N(0x6F21, "EF.EXTB", F_OPTIONAL, 20, 20, |
| 184 | "Extension B"); |
| 185 | EF_LIN_FIX_N(0x6F22, "EF.LNDGWT", F_OPTIONAL, 13, 28, |
| 186 | "Last number dialled with Gateways"); |
| 187 | EF_CYCLIC_N(0x6F23, "EF.LNDTETRA", F_OPTIONAL, 9, 23, |
| 188 | "Last numbers dialled for TETRA network"); |
| 189 | EF_LIN_FIX_N(0x6F24, "EF.SDNGWT", F_OPTIONAL, 13, 28, |
| 190 | "Service Dialling Numbers with gateway"); |
| 191 | EF_LIN_FIX_N(0x6F25, "EF.GWTEXT3", F_OPTIONAL, 13, 13, |
| 192 | "Gateway Extension3"); |
| 193 | EF_LIN_FIX_N(0x6F26, "EF.SDNTETRA", F_OPTIONAL, 8, 22, |
| 194 | "Service Dialling Nubers for TETRA network"); |
| 195 | EF_LIN_FIX_N(0x6F27, "EF.STXT", F_OPTIONAL, 5, 18, |
| 196 | "Status message texts"); |
| 197 | EF_LIN_FIX_N(0x6F28, "EF.MSGTXT", F_OPTIONAL, 5, 18, |
| 198 | "SDS-1 message texts"); |
| 199 | EF_LIN_FIX_N(0x6F29, "EF.SDS123", F_OPTIONAL, 46, 46, |
| 200 | "Status and SDS type 1, 2 and 3 message storage"); |
| 201 | EF_LIN_FIX_N(0x6F2A, "EF.SDS4", F_OPTIONAL, 255, 255, |
| 202 | "Status and SDS type 4 message storage"); |
| 203 | EF_LIN_FIX_N(0x6F2B, "EF.MSGEXT", F_OPTIONAL, 16, 16, |
| 204 | "Message Extension"); |
| 205 | EF_LIN_FIX_N(0x6F2C, "EF.EADDR", 0, 17, 17, |
| 206 | "Emergency adresses"); |
| 207 | EF_TRANSP_N(0x6F2D, "EF.EINFO", 0, 2, 2, |
| 208 | "Emergency call information"); |
| 209 | EF_LIN_FIX_N(0x6F2E, "EF.DMOCh", F_OPTIONAL, 4, 4, |
| 210 | "DMO channel information"); |
| 211 | EF_TRANSP_N(0x6F2F, "EF.MSCh", F_OPTIONAL, 1, 16, |
| 212 | "MS allocation of DMO channels"); |
| 213 | EF_TRANSP_N(0x6F30, "EF.KH", F_OPTIONAL, 6, 6, |
| 214 | "List of Key Holders"); |
| 215 | EF_LIN_FIX_N(0x6F31, "EF.REPGATE", F_OPTIONAL, 2, 2, |
| 216 | "DMO repeater and gateway list"); |
| 217 | EF_TRANSP_N(0x6F32, "EF.AD", F_OPTIONAL, 2, 2, |
| 218 | "DMO repeater and gateway list"); |
| 219 | EF_TRANSP_N(0x6F33, "EF.PREF_LA", F_OPTIONAL, 2, 2, |
| 220 | "Preferred location areas"); |
| 221 | EF_CYCLIC_N(0x6F34, "EF.LNDComp", F_OPTIONAL, 3, 3, |
| 222 | "Composite LND file"); |
| 223 | EF_TRANSP_N(0x6F35, "EF.DFLTSTSTGGT", F_OPTIONAL, 16, 16, |
| 224 | "Status Default Target"); |
| 225 | EF_TRANSP_N(0x6F36, "EF.SDSMEM_STATUS", F_OPTIONAL, 7, 7, |
| 226 | "SDS Memory Status"); |
| 227 | EF_TRANSP_N(0x6F37, "EF.WELCOME", F_OPTIONAL, 32, 32, |
| 228 | "Welcome Message"); |
| 229 | EF_LIN_FIX_N(0x6F38, "EF.SDSR", F_OPTIONAL, 2, 2, |
| 230 | "SDS delivery report"); |
| 231 | EF_LIN_FIX_N(0x6F39, "EF.SDSP", F_OPTIONAL, 20, 35, |
| 232 | "SDS parameters"); |
| 233 | EF_TRANSP_N(0x6F46, "EF.DIALSC", 0, 5, 5, |
| 234 | "Dialling schemes for TETRA network"); |
| 235 | EF_TRANSP_N(0x6F3E, "EF.APN", F_OPTIONAL, 65, 65, |
| 236 | "APN table"); |
| 237 | EF_LIN_FIX_N(0x6FC0, "EF.PNI", F_OPTIONAL, 14, 14, |
| 238 | "Private Number Information"); |
| 239 | }; |
| 240 | |
| 241 | //////////////////////////// |
| 242 | |
| 243 | /* 10.5. */ |
| 244 | static const struct osim_file_desc sim_ef_in_telecom[] = { |
| 245 | EF_LIN_FIX_N(0x6F3A, "EF.ADN", F_OPTIONAL, |
| 246 | "Abbreviated dialling numbers"), |
| 247 | EF_LIN_FIX_N(0x6F3B, "EF.FDN", F_OPTIONAL, |
| 248 | "Fixed dialling numbers"), |
| 249 | EF_LIN_FIX_N(0x6F3C, "EF.SMS", F_OPTIONAL, |
| 250 | "Short messages"), |
| 251 | EF_LIN_FIX_N(0x6F3D, "EF.CCP", F_OPTIONAL, |
| 252 | "Capability configuration parameters"), |
| 253 | EF_LIN_FIX_N(0x6F4F, "EF.ECCP", F_OPTIONAL, |
| 254 | "Extended Capability configuration parameters"), |
| 255 | EF_LIN_FIX_N(0x6F40, "EF.MSISDN", F_OPTIONAL, |
| 256 | "MSISDN"), |
| 257 | EF_LIN_FIX_N(0x6F42, "EF.SMSP", F_OPTIONAL, |
| 258 | "Short message service parameters"), |
| 259 | EF_TRANSP_N(0x6F43, "EF.SMSS", F_OPTIONAL, |
| 260 | "SMS Status"), |
| 261 | EF_CYCLIC_N(0x6F44, "EF.LND", F_OPTIONAL, |
| 262 | "Last number dialled"), |
| 263 | EF_LIN_FIX_N(0x6F4A, "EF.EXT1", F_OPTIONAL, |
| 264 | "Extension 1"), |
| 265 | EF_LIN_FIX_N(0x6F4B, "EF.EXT2", F_OPTIONAL, |
| 266 | "Extension 2"), |
| 267 | EF_LIN_FIX_N(0x6F4C, "EF.EXT3", F_OPTIONAL, |
| 268 | "Extension 3"), |
| 269 | EF_LIN_FIX_N(0x6F4D, "EF.BDN", F_OPTIONAL, |
| 270 | "Barred dialling numbers"), |
| 271 | EF_LIN_FIX_N(0x6F4E, "EF.EXT4", F_OPTIONAL, |
| 272 | "Extension 4"), |
| 273 | EF_LIN_FIX_N(0x6F47, "EF.SMSR", F_OPTIONAL, |
| 274 | "Short message status reports"), |
| 275 | EF_LIN_FIX_N(0x6F58, "EF.CMI", F_OPTIONAL, |
| 276 | "Comparison Method Information"), |
| 277 | }; |
| 278 | |
| 279 | |
| 280 | /* 10.6. */ |
| 281 | static const struct osim_file_desc sim_ef_in_graphics[] = { |
| 282 | EF_LIN_FIX_N(0x4F20, "EF.IMG", F_OPTIONAL, |
| 283 | "Image"), |
| 284 | }; |
| 285 | |
| 286 | struct osim_card_profile *osim_cprof_sim(void *ctx) |
| 287 | { |
| 288 | struct osim_card_profile *cprof; |
| 289 | struct osim_file_desc *mf, *gsm, *tc; |
| 290 | |
| 291 | cprof = talloc_zero(ctx, struct osim_card_profile); |
| 292 | cprof->name = "GSM SIM"; |
| 293 | cprof->sws = sim_card_sws; |
| 294 | |
| 295 | mf = alloc_df(cprof, 0x3f00, "MF"); |
| 296 | |
| 297 | cprof->mf = mf; |
| 298 | |
| 299 | add_filedesc(mf, sim_ef_in_mf, ARRAY_SIZE(sim_ef_in_mf)); |
| 300 | gsm = add_df_with_ef(mf, 0x7F20, "DF.GSM", sim_ef_in_gsm, |
| 301 | ARRAY_SIZE(sim_ef_in_gsm)); |
| 302 | add_df_with_ef(gsm, 0x5F30, "DF.IRIDIUM", NULL, 0); |
| 303 | add_df_with_ef(gsm, 0x5F31, "DF.GLOBST", NULL, 0); |
| 304 | add_df_with_ef(gsm, 0x5F32, "DF.ICO", NULL, 0); |
| 305 | add_df_with_ef(gsm, 0x5F33, "DF.ACeS", NULL, 0); |
| 306 | add_df_with_ef(gsm, 0x5F40, "DF.ACeS", NULL, 0); |
| 307 | add_df_with_ef(gsm, 0x5F60, "DF.CTS", NULL, 0); |
| 308 | add_df_with_ef(gsm, 0x5F70, "DF.SoLSA", NULL, 0); |
| 309 | tc = add_df_with_ef(mf, 0x7F10, "DF.TELECOM", sim_ef_in_telecom, |
| 310 | ARRAY_SIZE(sim_ef_in_telecom)); |
| 311 | add_df_with_ef(tc, 0x5F50, "DF.GRAPHICS", sim_ef_in_graphics, |
| 312 | ARRAY_SIZE(sim_ef_in_graphics)); |
| 313 | |
| 314 | return cprof; |
| 315 | } |