Neels Hofmeyr | 17518fe | 2017-06-20 04:35:06 +0200 | [diff] [blame] | 1 | /*! \file card_fs_tetra.c |
| 2 | * TETRA SIM card specific structures/routines. */ |
Harald Welte | e8dd2bd | 2014-05-04 13:42:38 +0200 | [diff] [blame] | 3 | /* |
| 4 | * (C) 2014 by Harald Welte <laforge@gnumonks.org> |
| 5 | * |
| 6 | * All Rights Reserved |
| 7 | * |
Harald Welte | e08da97 | 2017-11-13 01:00:26 +0900 | [diff] [blame] | 8 | * SPDX-License-Identifier: GPL-2.0+ |
| 9 | * |
Harald Welte | e8dd2bd | 2014-05-04 13:42:38 +0200 | [diff] [blame] | 10 | * 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 Welte | e8dd2bd | 2014-05-04 13:42:38 +0200 | [diff] [blame] | 20 | */ |
| 21 | |
| 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" |
Harald Welte | aad7e06 | 2014-05-04 16:31:24 +0200 | [diff] [blame] | 30 | #include "gsm_int.h" |
Harald Welte | e8dd2bd | 2014-05-04 13:42:38 +0200 | [diff] [blame] | 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, |
Thorsten Alteholz | 5a9dbf8 | 2018-04-08 19:13:25 +0200 | [diff] [blame] | 45 | .u.str = "Memory management - Command successful but after using an internal update retry X times", |
Harald Welte | e8dd2bd | 2014-05-04 13:42:38 +0200 | [diff] [blame] | 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[] = { |
Harald Welte | aad7e06 | 2014-05-04 16:31:24 +0200 | [diff] [blame] | 102 | tsim_sw, |
Harald Welte | e8dd2bd | 2014-05-04 13:42:38 +0200 | [diff] [blame] | 103 | NULL |
| 104 | }; |
| 105 | |
| 106 | /* Chapter 10.2.x */ |
| 107 | static const struct osim_file_desc sim_ef_in_mf[] = { |
Harald Welte | aad7e06 | 2014-05-04 16:31:24 +0200 | [diff] [blame] | 108 | EF_TRANSP_N(0x2FE2, SFI_NONE, "EF.ICCID", 0, 10, 10, |
| 109 | "ICC Identification"), |
| 110 | EF_TRANSP_N(0x2F00, SFI_NONE, "EF.DIR", F_OPTIONAL, 8, 54, |
| 111 | "Application directory"), |
| 112 | EF_TRANSP_N(0x2F05, SFI_NONE, "EF.LP", 0, 2, 32, |
| 113 | "Language preference"), |
Harald Welte | e8dd2bd | 2014-05-04 13:42:38 +0200 | [diff] [blame] | 114 | }; |
| 115 | |
| 116 | //////////////////////////// |
| 117 | |
| 118 | /* Chapter 10.3.x */ |
| 119 | static const struct osim_file_desc sim_ef_in_tetra[] = { |
Harald Welte | aad7e06 | 2014-05-04 16:31:24 +0200 | [diff] [blame] | 120 | EF_TRANSP_N(0x6F01, SFI_NONE, "EF.SST", 0, 4, 8, |
Harald Welte | e8dd2bd | 2014-05-04 13:42:38 +0200 | [diff] [blame] | 121 | "SIM service table"), |
Harald Welte | aad7e06 | 2014-05-04 16:31:24 +0200 | [diff] [blame] | 122 | EF_TRANSP_N(0x6F02, SFI_NONE, "EF.ITSI", 0, 6, 6, |
| 123 | "ITSI"), |
| 124 | EF_TRANSP_N(0x6F03, SFI_NONE, "EF.ITSIDIS", 0, 1, 1, |
| 125 | "ITSI Disable"), |
| 126 | EF_TRANSP_N(0x6F05, SFI_NONE, "EF.SCT", 0, 4, 4, |
| 127 | "Subscriber Class Table"), |
| 128 | EF_TRANSP_N(0x6F06, SFI_NONE, "EF.PHASE", 0, 1, 1, |
| 129 | "Phase identification"), |
| 130 | EF_KEY_N(0x6F07, SFI_NONE, "EF.CCK", F_OPTIONAL, 12, 12, |
| 131 | "Common Cipher Key"), |
| 132 | EF_TRANSP_N(0x6F08, SFI_NONE, "EF.CCKLOC", F_OPTIONAL, 31, 31, |
| 133 | "CCK location areas"), |
| 134 | EF_KEY_N(0x6F09, SFI_NONE, "EF.SCK", F_OPTIONAL, 12, 12, |
| 135 | "Static Cipher Keys"), |
Harald Welte | e8dd2bd | 2014-05-04 13:42:38 +0200 | [diff] [blame] | 136 | /* X+4 for each record, suggested 1 to 10 */ |
Harald Welte | aad7e06 | 2014-05-04 16:31:24 +0200 | [diff] [blame] | 137 | EF_LIN_FIX_N(0x6F0A, SFI_NONE, "EF.GSSIS", 0, 5, 21, |
| 138 | "Static Cipher Keys"), |
Harald Welte | e8dd2bd | 2014-05-04 13:42:38 +0200 | [diff] [blame] | 139 | /* 2 for each record, one for each recod in GSSIS */ |
Harald Welte | aad7e06 | 2014-05-04 16:31:24 +0200 | [diff] [blame] | 140 | EF_LIN_FIX_N(0x6F0B, SFI_NONE, "EF.GRDS", 0, 2, 2, |
| 141 | "Group related data for static GSSIS"), |
| 142 | EF_LIN_FIX_N(0x6F0C, SFI_NONE, "EF.GSSID", 0, 5, 21, |
| 143 | "Dynamic GSSIs"), |
Harald Welte | e8dd2bd | 2014-05-04 13:42:38 +0200 | [diff] [blame] | 144 | /* 2 for each record, one for each recod in GSSID */ |
Harald Welte | aad7e06 | 2014-05-04 16:31:24 +0200 | [diff] [blame] | 145 | EF_LIN_FIX_N(0x6F0D, SFI_NONE, "EF.GRDD", 0, 2, 2, |
| 146 | "Dynamic GSSIs"), |
| 147 | EF_LIN_FIX_N(0x6F0E, SFI_NONE, "EF.GCK", F_OPTIONAL, 12, 12, |
| 148 | "Group Cipher Keys"), |
| 149 | EF_KEY_N(0x6F0F, SFI_NONE, "EF.MGCK", F_OPTIONAL, 12, 12, |
| 150 | "Modified Group Cipher Keys"), |
| 151 | EF_TRANSP_N(0x6F10, SFI_NONE, "EF.GINFO", 0, 9, 9, |
| 152 | "User's group information"), |
| 153 | EF_TRANSP_N(0x6F11, SFI_NONE, "EF.SEC", 0, 1, 1, |
| 154 | "Security settings"), |
| 155 | EF_CYCLIC_N(0x6F12, SFI_NONE, "EF.FORBID", 0, 3, 3, |
| 156 | "Security settings"), |
| 157 | EF_CYCLIC_N(0x6F13, SFI_NONE, "EF.PREF", F_OPTIONAL, 3, 3, |
| 158 | "Preferred networks"), |
| 159 | EF_TRANSP_N(0x6F14, SFI_NONE, "EF.SPN", F_OPTIONAL, 17, 17, |
| 160 | "Service Provider Name"), |
| 161 | EF_TRANSP_N(0x6F15, SFI_NONE, "EF.LOCI", F_OPTIONAL, 7, 7, |
| 162 | "Location Information"), |
| 163 | EF_TRANSP_N(0x6F16, SFI_NONE, "EF.DNWRK", 0, 3, 3, |
| 164 | "Broadcast network information"), |
| 165 | EF_LIN_FIX_N(0x6F17, SFI_NONE, "EF.NWT", 0, 5, 5, |
| 166 | "Network table"), |
| 167 | EF_LIN_FIX_N(0x6F18, SFI_NONE, "EF.GWT", F_OPTIONAL, 13, 13, |
| 168 | "Gateway table"), |
| 169 | EF_LIN_FIX_N(0x6F19, SFI_NONE, "EF.CMT", F_OPTIONAL, 5, 20, |
| 170 | "Call Modifier Table"), |
| 171 | EF_LIN_FIX_N(0x6F1A, SFI_NONE, "EF.ADNGWT", F_OPTIONAL, 13, 28, |
| 172 | "Abbreviated Dialling Number with Gateways"), |
| 173 | EF_LIN_FIX_N(0x6F1C, SFI_NONE, "EF.ADNTETRA", F_OPTIONAL, 9, 23, |
| 174 | "Abbreviated dialling numbers for TETRA network"), |
| 175 | EF_LIN_FIX_N(0x6F1D, SFI_NONE, "EF.EXTA", F_OPTIONAL, 20, 20, |
| 176 | "Extension A"), |
| 177 | EF_LIN_FIX_N(0x6F1E, SFI_NONE, "EF.FDNGWT", F_OPTIONAL, 13, 28, |
| 178 | "Fixed dialling numbers with Gateways"), |
| 179 | EF_LIN_FIX_N(0x6F1F, SFI_NONE, "EF.GWTEXT2", F_OPTIONAL, 13, 13, |
| 180 | "Gateway Extension2"), |
| 181 | EF_LIN_FIX_N(0x6F20, SFI_NONE, "EF.FDNTETRA", F_OPTIONAL, 9, 25, |
| 182 | "Fixed dialling numbers for TETRA network"), |
| 183 | EF_LIN_FIX_N(0x6F21, SFI_NONE, "EF.EXTB", F_OPTIONAL, 20, 20, |
| 184 | "Extension B"), |
| 185 | EF_LIN_FIX_N(0x6F22, SFI_NONE, "EF.LNDGWT", F_OPTIONAL, 13, 28, |
| 186 | "Last number dialled with Gateways"), |
| 187 | EF_CYCLIC_N(0x6F23, SFI_NONE, "EF.LNDTETRA", F_OPTIONAL, 9, 23, |
| 188 | "Last numbers dialled for TETRA network"), |
| 189 | EF_LIN_FIX_N(0x6F24, SFI_NONE, "EF.SDNGWT", F_OPTIONAL, 13, 28, |
| 190 | "Service Dialling Numbers with gateway"), |
| 191 | EF_LIN_FIX_N(0x6F25, SFI_NONE, "EF.GWTEXT3", F_OPTIONAL, 13, 13, |
| 192 | "Gateway Extension3"), |
| 193 | EF_LIN_FIX_N(0x6F26, SFI_NONE, "EF.SDNTETRA", F_OPTIONAL, 8, 22, |
| 194 | "Service Dialling Nubers for TETRA network"), |
| 195 | EF_LIN_FIX_N(0x6F27, SFI_NONE, "EF.STXT", F_OPTIONAL, 5, 18, |
| 196 | "Status message texts"), |
| 197 | EF_LIN_FIX_N(0x6F28, SFI_NONE, "EF.MSGTXT", F_OPTIONAL, 5, 18, |
| 198 | "SDS-1 message texts"), |
| 199 | EF_LIN_FIX_N(0x6F29, SFI_NONE, "EF.SDS123", F_OPTIONAL, 46, 46, |
| 200 | "Status and SDS type 1, 2 and 3 message storage"), |
| 201 | EF_LIN_FIX_N(0x6F2A, SFI_NONE, "EF.SDS4", F_OPTIONAL, 255, 255, |
| 202 | "Status and SDS type 4 message storage"), |
| 203 | EF_LIN_FIX_N(0x6F2B, SFI_NONE, "EF.MSGEXT", F_OPTIONAL, 16, 16, |
| 204 | "Message Extension"), |
| 205 | EF_LIN_FIX_N(0x6F2C, SFI_NONE, "EF.EADDR", 0, 17, 17, |
Ruben Undheim | 029f5a1 | 2015-09-16 19:02:35 +0200 | [diff] [blame] | 206 | "Emergency addresses"), |
Harald Welte | aad7e06 | 2014-05-04 16:31:24 +0200 | [diff] [blame] | 207 | EF_TRANSP_N(0x6F2D, SFI_NONE, "EF.EINFO", 0, 2, 2, |
| 208 | "Emergency call information"), |
| 209 | EF_LIN_FIX_N(0x6F2E, SFI_NONE, "EF.DMOCh", F_OPTIONAL, 4, 4, |
| 210 | "DMO channel information"), |
| 211 | EF_TRANSP_N(0x6F2F, SFI_NONE, "EF.MSCh", F_OPTIONAL, 1, 16, |
| 212 | "MS allocation of DMO channels"), |
| 213 | EF_TRANSP_N(0x6F30, SFI_NONE, "EF.KH", F_OPTIONAL, 6, 6, |
| 214 | "List of Key Holders"), |
| 215 | EF_LIN_FIX_N(0x6F31, SFI_NONE, "EF.REPGATE", F_OPTIONAL, 2, 2, |
| 216 | "DMO repeater and gateway list"), |
| 217 | EF_TRANSP_N(0x6F32, SFI_NONE, "EF.AD", F_OPTIONAL, 2, 2, |
| 218 | "Administrative Data"), |
| 219 | EF_TRANSP_N(0x6F33, SFI_NONE, "EF.PREF_LA", F_OPTIONAL, 2, 2, |
| 220 | "Preferred location areas"), |
| 221 | EF_CYCLIC_N(0x6F34, SFI_NONE, "EF.LNDComp", F_OPTIONAL, 3, 3, |
| 222 | "Composite LND file"), |
| 223 | EF_TRANSP_N(0x6F35, SFI_NONE, "EF.DFLTSTSTGGT", F_OPTIONAL, 16, 16, |
| 224 | "Status Default Target"), |
| 225 | EF_TRANSP_N(0x6F36, SFI_NONE, "EF.SDSMEM_STATUS", F_OPTIONAL, 7, 7, |
| 226 | "SDS Memory Status"), |
| 227 | EF_TRANSP_N(0x6F37, SFI_NONE, "EF.WELCOME", F_OPTIONAL, 32, 32, |
| 228 | "Welcome Message"), |
| 229 | EF_LIN_FIX_N(0x6F38, SFI_NONE, "EF.SDSR", F_OPTIONAL, 2, 2, |
| 230 | "SDS delivery report"), |
| 231 | EF_LIN_FIX_N(0x6F39, SFI_NONE, "EF.SDSP", F_OPTIONAL, 20, 35, |
| 232 | "SDS parameters"), |
| 233 | EF_TRANSP_N(0x6F46, SFI_NONE, "EF.DIALSC", 0, 5, 5, |
| 234 | "Dialling schemes for TETRA network"), |
| 235 | EF_TRANSP_N(0x6F3E, SFI_NONE, "EF.APN", F_OPTIONAL, 65, 65, |
| 236 | "APN table"), |
| 237 | EF_LIN_FIX_N(0x6FC0, SFI_NONE, "EF.PNI", F_OPTIONAL, 14, 14, |
| 238 | "Private Number Information"), |
Harald Welte | e8dd2bd | 2014-05-04 13:42:38 +0200 | [diff] [blame] | 239 | }; |
| 240 | |
Harald Welte | aad7e06 | 2014-05-04 16:31:24 +0200 | [diff] [blame] | 241 | struct osim_card_profile *osim_cprof_tsim(void *ctx) |
Harald Welte | e8dd2bd | 2014-05-04 13:42:38 +0200 | [diff] [blame] | 242 | { |
| 243 | struct osim_card_profile *cprof; |
Harald Welte | 6729a97 | 2014-10-26 19:04:56 +0100 | [diff] [blame] | 244 | struct osim_file_desc *mf; |
| 245 | int rc; |
Harald Welte | e8dd2bd | 2014-05-04 13:42:38 +0200 | [diff] [blame] | 246 | |
| 247 | cprof = talloc_zero(ctx, struct osim_card_profile); |
Harald Welte | aad7e06 | 2014-05-04 16:31:24 +0200 | [diff] [blame] | 248 | cprof->name = "TETRA SIM"; |
| 249 | cprof->sws = tsim_card_sws; |
Harald Welte | e8dd2bd | 2014-05-04 13:42:38 +0200 | [diff] [blame] | 250 | |
| 251 | mf = alloc_df(cprof, 0x3f00, "MF"); |
| 252 | |
| 253 | cprof->mf = mf; |
| 254 | |
| 255 | add_filedesc(mf, sim_ef_in_mf, ARRAY_SIZE(sim_ef_in_mf)); |
Harald Welte | aad7e06 | 2014-05-04 16:31:24 +0200 | [diff] [blame] | 256 | add_df_with_ef(mf, 0x7F20, "DF.TETRA", sim_ef_in_tetra, |
| 257 | ARRAY_SIZE(sim_ef_in_tetra)); |
| 258 | |
Harald Welte | 6729a97 | 2014-10-26 19:04:56 +0100 | [diff] [blame] | 259 | rc = osim_int_cprof_add_telecom(mf); |
| 260 | if (rc != 0) { |
| 261 | talloc_free(cprof); |
| 262 | return NULL; |
| 263 | } |
Harald Welte | e8dd2bd | 2014-05-04 13:42:38 +0200 | [diff] [blame] | 264 | |
| 265 | return cprof; |
| 266 | } |