summaryrefslogtreecommitdiffstats
path: root/src/simutil.h
blob: 16b210b64584b5c7270613dd26585672adc0e504 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
/*
 *
 *  oFono - Open Source Telephony
 *
 *  Copyright (C) 2008-2010  Intel Corporation. All rights reserved.
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License version 2 as
 *  published by the Free Software Foundation.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */

#define SIM_EFSPN_DC_HOME_PLMN_BIT 0x1
#define SIM_EFSPN_DC_ROAMING_SPN_BIT 0x2

enum sim_fileid {
	SIM_EFPL_FILEID =			0x2F05,
	SIM_EF_ICCID_FILEID =			0x2FE2,
	SIM_MF_FILEID =				0x3F00,
	SIM_EFIMG_FILEID =			0x4F20,
	SIM_EFPSC_FILEID =			0x4F22,
	SIM_EFCC_FILEID =			0x4F23,
	SIM_EFPUID_FILEID =			0x4F24,
	SIM_EFPBR_FILEID =			0x4F30,
	SIM_DFPHONEBOOK_FILEID =		0x5F3A,
	SIM_DFMULTIMEDIA_FILEID =		0x5F3B,
	SIM_EFLI_FILEID =			0x6F05,
	SIM_EFARR_FILEID =			0x6F06,
	SIM_EFIMSI_FILEID =			0x6F07,
	SIM_EF_CPHS_MWIS_FILEID =		0x6F11,
	SIM_EF_CPHS_CFF_FILEID =		0x6F13,
	SIM_EF_CPHS_CSP_FILEID =		0x6F15,
	SIM_EF_CPHS_INFORMATION_FILEID =	0x6F16,
	SIM_EF_CPHS_MBDN_FILEID =		0x6F17,
	SIM_EFUST_FILEID =			0x6F38,
	SIM_EFSST_FILEID =			0x6F38, /* same as EFust */
	SIM_EFADN_FILEID =			0x6F3A,
	SIM_EFMSISDN_FILEID =			0x6F40,
	SIM_EFSMSP_FILEID =			0x6F42,
	SIM_EFCBMI_FILEID =			0x6F45,
	SIM_EFSPN_FILEID =			0x6F46,
	SIM_EFCBMID_FILEID =			0x6F48,
	SIM_EFSDN_FILEID =			0x6F49,
	SIM_EFEXT1_FILEID =			0x6F4A,
	SIM_EFBDN_FILEID =			0x6F4D,
	SIM_EFCBMIR_FILEID =			0x6F50,
	SIM_EFEST_FILEID =			0x6F56,
	SIM_EFAD_FILEID =			0x6FAD,
	SIM_EFPHASE_FILEID =			0x6FAE,
	SIM_EFECC_FILEID =			0x6FB7,
	SIM_EFPNN_FILEID =			0x6FC5,
	SIM_EFOPL_FILEID =			0x6FC6,
	SIM_EFMBDN_FILEID =			0x6FC7,
	SIM_EFMBI_FILEID =			0x6FC9,
	SIM_EFMWIS_FILEID =			0x6FCA,
	SIM_EFCFIS_FILEID =			0x6FCB,
	SIM_EFSPDI_FILEID =			0x6FCD,
	SIM_DFTELECOM_FILEID =			0x7F10,
	SIM_DFGSM_FILEID =			0x7F20,
};

/* 51.011 Section 9.3 */
enum sim_file_access {
	SIM_FILE_ACCESS_ALWAYS =	0,
	SIM_FILE_ACCESS_CHV1 =		1,
	SIM_FILE_ACCESS_CHV2 =		2,
	SIM_FILE_ACCESS_RESERVED =	3,
	SIM_FILE_ACCESS_ADM =		4,
	SIM_FILE_ACCESS_NEVER =		15,
};

/* 51.011 Section 9.3 */
enum sim_file_status {
	SIM_FILE_STATUS_VALID =			0x01,
	SIM_FILE_STATUS_RW_WHEN_INVALID =	0x04,
};

/* 131.102 Section 4.2.8 */
enum sim_ust_service {
	SIM_UST_SERVICE_LOCAL_PHONE_BOOK =		0,
	SIM_UST_SERVICE_FDN =				1,
	SIM_UST_SERVICE_EXT_2 =				2,
	SIM_UST_SERVICE_SDN =				3,
	SIM_UST_SERVICE_EXT_3 =				4,
	SIM_UST_SERVICE_BDN =				5,
	SIM_UST_SERVICE_EXT_4 =				6,
	SIM_UST_SERVICE_OCI_OCT =			7,
	SIM_UST_SERVICE_ICI_ICT =			8,
	SIM_UST_SERVICE_SMS =				9,
	SIM_UST_SERVICE_SMSR =				10,
	SIM_UST_SERVICE_SMSP =				11,
	SIM_UST_SERVICE_AOC =				12,
	SIM_UST_SERVICE_CCP2 =				13,
	SIM_UST_SERVICE_CBS_ID =			14,
	SIM_UST_SERVICE_CBS_ID_RANGE =			15,
	SIM_UST_SERVICE_GROUP_ID_LEVEL_1 =		16,
	SIM_UST_SERVICE_GROUP_ID_LEVEL_2 =		17,
	SIM_UST_SERVICE_PROVIDER_NAME =			18,
	SIM_UST_SERVICE_USER_PLMN =			19,
	SIM_UST_SERVICE_MSISDN =			20,
	SIM_UST_SERVICE_IMG =				21,
	SIM_UST_SERVICE_SOLSA =				22,
	SIM_UST_SERVICE_PRECEDENCE_PREEMPTION =		23,
	SIM_UST_SERVICE_EMLPP =				24,
	SIM_UST_SERVICE_GSM_ACCESS =			26,
	SIM_UST_SERVICE_DATA_DOWNLOAD_SMS_PP =		27,
	SIM_UST_SERVICE_DATA_DOWNLOAD_SMS_CB =		28,
	SIM_UST_SERVICE_CALL_CONTROL_USIM =		29,
	SIM_UST_SERVICE_MO_SMS_USIM =			30,
	SIM_UST_SERVICE_RUN_AT_COMMAND =		31,
	SIM_UST_SERVICE_ENABLED_SERVICE_TABLE =		33,
	SIM_UST_SERVICE_ACL =				34,
	SIM_UST_SERVICE_DEPERSONALISATION_CTRL_KEY =	35,
	SIM_UST_SERVICE_NETWORK_LIST =			36,
	SIM_UST_SERVICE_GSM_SECURITY_CONTEXT =		37,
	SIM_UST_SERVICE_CPBCCH =			38,
	SIM_UST_SERVICE_INVESTIGATION_SCAN =		39,
	SIM_UST_SERVICE_MEXE =				40,
	SIM_UST_SERVICE_OPERATOR_PLMN =			41,
	SIM_UST_SERVICE_HPLMN =				42,
	SIM_UST_SERVICE_EXT_5 =				43,
	SIM_UST_SERVICE_PLMN_NETWORK_NAME =		44,
	SIM_UST_SERVICE_OPERATOR_PLMN_LIST =		45,
	SIM_UST_SERVICE_MAILBOX_DIALLING_NUMBERS =	46,
	SIM_UST_SERVICE_MWIS =				47,
	SIM_UST_SERVICE_CFIS =				48,
	SIM_UST_SERVICE_PROVIDER_DISPLAY_INFO =		50,
	SIM_UST_SERVICE_MMS =				51,
	SIM_UST_SERVICE_EXT_8 =				52,
	SIM_UST_SERVICE_CALL_CONTROL_GPRS_USIM =	53,
	SIM_UST_SERVICE_MMS_USER_CONN_PARAM =		54,
	SIM_UST_SERVICE_NIA =				55,
	SIM_UST_SERVICE_EFVGCS_EFVGCSS =		56,
	SIM_UST_SERVICE_EFVBS_EFVBSS =			57,
	SIM_UST_SERVICE_PSEUDONYM =			58,
	SIM_UST_SERVICE_USER_PLMN_I_WLAN =		59,
	SIM_UST_SERVICE_OPERATOR_PLMN_I_WLAN =		60,
	SIM_UST_SERVICE_USER_WSID =			61,
	SIM_UST_SERVICE_OPERATOR_WSID =			62,
	SIM_UST_SERVICE_VGCS_SECURITY =			63,
	SIM_UST_SERVICE_VBS_SECURITY =			64,
	SIM_UST_SERVICE_WLAN_REAUTH_ID =		65,
	SIM_UST_SERVICE_MMS_STORAGE =			66,
	SIM_UST_SERVICE_GBA =				67,
	SIM_UST_SERVICE_MBMS_SECURITY =			68,
	SIM_UST_SERVICE_USSD_APPLICATION_MODE =		69,
	SIM_UST_SERVICE_EQUIVALENT_HPLMN =		70,
	SIM_UST_SERVICE_ADDITIONAL_TERMINAL_PROFILE =	71,
	SIM_UST_SERVICE_EQUIVALENT_HPLMN_IND =		72,
	SIM_UST_SERVICE_LAST_RPLMN_IND =		73,
	SIM_UST_SERVICE_OMA_BCAST_SC_PROFILE =		74,
	SIM_UST_SERVICE_BGA_LOCAL_KEY =			75,
	SIM_UST_SERVICE_TERMINAL_APPLICATIONS =		76,
	SIM_UST_SERVICE_PROVIDER_NAME_ICON =		77,
	SIM_UST_SERVICE_PLMN_NETWORK_NAME_ICON =	78,
	SIM_UST_SERVICE_CONN_PARAM_USIM_IP =		79,
	SIM_UST_SERVICE_HOME_I_WLAN_ID_LIST =		80,
	SIM_UST_SERVICE_I_WLAN_EQUIVALENT_HPLMN_IND =	81,
	SIM_UST_SERVICE_I_WLAN_HPLMN_PRIORITY_IND =	82,
	SIM_UST_SERVICE_I_WLAN_LAST_PLMN =		83,
	SIM_UST_SERVICE_EPS_INFO =			84,
	SIM_UST_SERVICE_CSG_IND =			85,
	SIM_UST_SERVICE_CALL_CONTROL_EPS_PDN_USIM =	86,
	SIM_UST_SERVICE_HPLMN_DIRECT_ACCESS =		87,
	SIM_UST_SERVICE_ECALL_DATA =			88,
	SIM_UST_SERVICE_OPERATOR_CSG =			89
};

/* 131.102 Section 4.2.47 */
enum sim_est_service {
	SIM_EST_SERVICE_FDN =		0,
	SIM_EST_SERVICE_BDN =		1,
	SIM_EST_SERVICE_ACL =		2
};

/* 51.011 Section 10.3.7 */
enum sim_sst_service {
	SIM_SST_SERVICE_CHV1_DISABLE =			0,
	SIM_SST_SERVICE_ADN =				1,
	SIM_SST_SERVICE_FDN =				2,
	SIM_SST_SERVICE_SMS =				3,
	SIM_SST_SERVICE_AOC =				4,
	SIM_SST_SERVICE_CCP =				5,
	SIM_SST_SERVICE_PLMN_SELECTOR =			6,
	SIM_SST_SERVICE_MSISDN =			8,
	SIM_SST_SERVICE_EXT_1 =				9,
	SIM_SST_SERVICE_EXT_2 =				10,
	SIM_SST_SERVICE_SMSP =				11,
	SIM_SST_SERVICE_LND =				12,
	SIM_SST_SERVICE_CBS_ID =			13,
	SIM_SST_SERVICE_GROUP_ID_LEVEL_1 =		14,
	SIM_SST_SERVICE_GROUP_ID_LEVEL_2 =		15,
	SIM_SST_SERVICE_PROVIDER_NAME =			16,
	SIM_SST_SERVICE_SDN =				17,
	SIM_SST_SERVICE_EXT_3 =				18,
	SIM_SST_SERVICE_EFVGCS_EFVGCSS =		20,
	SIM_SST_SERVICE_EFVBS_EFVBSS =			21,
	SIM_SST_SERVICE_PRECEDENCE_PREEMPTION =		22,
	SIM_SST_SERVICE_EMLPP =				23,
	SIM_SST_SERVICE_DATA_DOWNLOAD_SMS_CB =		24,
	SIM_SST_SERVICE_DATA_DOWNLOAD_SMS_PP =		25,
	SIM_SST_SERVICE_MENU_SELECTION =		26,
	SIM_SST_SERVICE_CALL_CONTROL =			27,
	SIM_SST_SERVICE_PROACTIVE_SIM =			28,
	SIM_SST_SERVICE_CBS_ID_RANGE =			29,
	SIM_SST_SERVICE_BDN =				30,
	SIM_SST_SERVICE_EXT_4 =				31,
	SIM_SST_SERVICE_DEPERSONALISATION_CTRL_KEY =	32,
	SIM_SST_SERVICE_NETWORK_LIST =			33,
	SIM_SST_SERVICE_SMSR =				34,
	SIM_SST_SERVICE_NIA =				35,
	SIM_SST_SERVICE_MO_SMS_SIM =			36,
	SIM_SST_SERVICE_GPRS =				37,
	SIM_SST_SERVICE_IMG =				38,
	SIM_SST_SERVICE_SOLSA =				39,
	SIM_SST_SERVICE_USSD_CALL_CONTROL =		40,
	SIM_SST_SERVICE_RUN_AT_COMMAND =		41,
	SIM_SST_SERVICE_USER_PLMN =			42,
	SIM_SST_SERVICE_OPERATOR_PLMN =			43,
	SIM_SST_SERVICE_HPLMN =				44,
	SIM_SST_SERVICE_CPBCCH =			45,
	SIM_SST_SERVICE_INVESTIGATION_SCAN =		46,
	SIM_SST_SERVICE_EXT_CCP =			47,
	SIM_SST_SERVICE_MEXE =				48,
	SIM_SST_SERVICE_RPLMN =				49,
	SIM_SST_SERVICE_PLMN_NETWORK_NAME =		50,
	SIM_SST_SERVICE_OPERATOR_PLMN_LIST =		51,
	SIM_SST_SERVICE_MAILBOX_DIALLING_NUMBERS =	52,
	SIM_SST_SERVICE_MWIS =				53,
	SIM_SST_SERVICE_CFIS =				54,
	SIM_SST_SERVICE_PROVIDER_DISPLAY_INFO =		55
};

/* CPHS 4.2, Section B4.7 CSP Service Group Codes */
enum sim_csp_entry {
	SIM_CSP_ENTRY_CALL_OFFERING =		0x01,
	SIM_CSP_ENTRY_CALL_RESTRICTION =	0x02,
	SIM_CSP_ENTRY_OTHER_SUPP_SERVICES =	0x03,
	SIM_CSP_ENTRY_CALL_COMPLETION =		0x04,
	SIM_CSP_ENTRY_TELESERVICES =		0x05,
	SIM_CSP_ENTRY_CPHS_TELESERVICES =	0x06,
	SIM_CSP_ENTRY_CPHS_FEATURES =		0x07,
	SIM_CSP_ENTRY_NUMBER_IDENTIFICATION =	0x08,
	SIM_CSP_ENTRY_PHASE_2GPLUS_SERVICES =	0x09,
	SIM_CSP_ENTRY_VALUE_ADDED_SERVICES =	0xC0,
	SIM_CSP_ENTRY_INFORMATION_NUMBERS =	0xD5,
};

enum ber_tlv_data_type {
	BER_TLV_DATA_TYPE_UNIVERSAL =		0,
	BER_TLV_DATA_TYPE_APPLICATION =		1,
	BER_TLV_DATA_TYPE_CONTEXT_SPECIFIC =	2,
	BER_TLV_DATA_TYPE_PRIVATE =		3,
};

enum ber_tlv_data_encoding_type {
	BER_TLV_DATA_ENCODING_TYPE_PRIMITIVE =		0,
	BER_TLV_DATA_ENCODING_TYPE_CONSTRUCTED =	1,
};

struct sim_eons_operator_info {
	char *longname;
	gboolean long_ci;
	char *shortname;
	gboolean short_ci;
	char *info;
};

struct sim_ef_info {
	unsigned short id;
	unsigned short parent;
	unsigned char file_type;
	unsigned char size;
	enum sim_file_access perm_read;
	enum sim_file_access perm_update;
};

struct sim_app_record {
	unsigned char aid[16];
	int aid_len;
	char *label;
};

struct simple_tlv_iter {
	unsigned int max;
	unsigned int pos;
	const unsigned char *pdu;
	unsigned char tag;
	unsigned short len;
	const unsigned char *data;
};

struct comprehension_tlv_iter {
	unsigned int max;
	unsigned int pos;
	const unsigned char *pdu;
	unsigned short tag;
	gboolean cr;
	unsigned int len;
	const unsigned char *data;
};

struct ber_tlv_iter {
	unsigned int max;
	unsigned int pos;
	const unsigned char *pdu;
	unsigned int tag;
	enum ber_tlv_data_type class;
	enum ber_tlv_data_encoding_type encoding;
	unsigned int len;
	const unsigned char *data;
};

struct ber_tlv_builder {
	unsigned int max;
	unsigned int pos;
	unsigned char *pdu;
	struct ber_tlv_builder *parent;

	unsigned int tag;
	enum ber_tlv_data_type class;
	enum ber_tlv_data_encoding_type encoding;
	unsigned int len;
};

struct comprehension_tlv_builder {
	unsigned int max;
	unsigned int pos;
	unsigned char *pdu;
	unsigned int len;
	struct ber_tlv_builder *parent;
};

void simple_tlv_iter_init(struct simple_tlv_iter *iter,
				const unsigned char *pdu, unsigned int len);
gboolean simple_tlv_iter_next(struct simple_tlv_iter *iter);
unsigned char simple_tlv_iter_get_tag(struct simple_tlv_iter *iter);
unsigned short simple_tlv_iter_get_length(struct simple_tlv_iter *iter);
const unsigned char *simple_tlv_iter_get_data(struct simple_tlv_iter *iter);

void comprehension_tlv_iter_init(struct comprehension_tlv_iter *iter,
					const unsigned char *pdu,
					unsigned int len);
gboolean comprehension_tlv_iter_next(struct comprehension_tlv_iter *iter);
unsigned short comprehension_tlv_iter_get_tag(struct comprehension_tlv_iter *i);
gboolean comprehension_tlv_get_cr(struct comprehension_tlv_iter *iter);
unsigned int comprehension_tlv_iter_get_length(
					struct comprehension_tlv_iter *iter);
const unsigned char *comprehension_tlv_iter_get_data(
					struct comprehension_tlv_iter *iter);

void comprehension_tlv_iter_copy(struct comprehension_tlv_iter *from,
					struct comprehension_tlv_iter *to);

gboolean comprehension_tlv_builder_init(
				struct comprehension_tlv_builder *builder,
				unsigned char *pdu, unsigned int size);
gboolean comprehension_tlv_builder_next(
				struct comprehension_tlv_builder *builder,
				gboolean cr, unsigned short tag);
gboolean comprehension_tlv_builder_set_length(
				struct comprehension_tlv_builder *builder,
				unsigned int len);
unsigned char *comprehension_tlv_builder_get_data(
				struct comprehension_tlv_builder *builder);

void ber_tlv_iter_init(struct ber_tlv_iter *iter, const unsigned char *pdu,
			unsigned int len);
/*
 * Returns the tag value of the TLV.  Note that the tag value can be either
 * short (0-30) or long
 */
unsigned int ber_tlv_iter_get_tag(struct ber_tlv_iter *iter);

enum ber_tlv_data_type ber_tlv_iter_get_class(struct ber_tlv_iter *iter);
enum ber_tlv_data_encoding_type ber_tlv_iter_get_encoding(
						struct ber_tlv_iter *iter);

/*
 * This will return the short tag along with class and encoding information.
 * This is more convenient to use for TLV contents of SIM Elementary Files
 * and SIM toolkit since these elements only use short tags.  In case of an
 * error (e.g. not a short tag) a zero is returned.  According to ISO 7816,
 * a tag value of '00' is invalid.
 */
unsigned char ber_tlv_iter_get_short_tag(struct ber_tlv_iter *iter);
unsigned int ber_tlv_iter_get_length(struct ber_tlv_iter *iter);

const unsigned char *ber_tlv_iter_get_data(struct ber_tlv_iter *iter);

gboolean ber_tlv_iter_next(struct ber_tlv_iter *iter);
void ber_tlv_iter_recurse(struct ber_tlv_iter *iter,
				struct ber_tlv_iter *recurse);
void ber_tlv_iter_recurse_simple(struct ber_tlv_iter *iter,
					struct simple_tlv_iter *container);
void ber_tlv_iter_recurse_comprehension(struct ber_tlv_iter *iter,
					struct comprehension_tlv_iter *recurse);

gboolean ber_tlv_builder_init(struct ber_tlv_builder *builder,
				unsigned char *pdu, unsigned int size);
gboolean ber_tlv_builder_next(struct ber_tlv_builder *builder,
				enum ber_tlv_data_type class,
				enum ber_tlv_data_encoding_type encoding,
				unsigned int new_tag);
gboolean ber_tlv_builder_set_length(struct ber_tlv_builder *builder,
					unsigned int len);
unsigned char *ber_tlv_builder_get_data(struct ber_tlv_builder *builder);
gboolean ber_tlv_builder_recurse(struct ber_tlv_builder *builder,
					struct ber_tlv_builder *recurse);
gboolean ber_tlv_builder_recurse_comprehension(struct ber_tlv_builder *builder,
				struct comprehension_tlv_builder *recurse);
void ber_tlv_builder_optimize(struct ber_tlv_builder *builder,
				unsigned char **pdu, unsigned int *len);

struct sim_eons *sim_eons_new(int pnn_records);
void sim_eons_add_pnn_record(struct sim_eons *eons, int record,
				const guint8 *tlv, int length);
gboolean sim_eons_pnn_is_empty(struct sim_eons *eons);
void sim_eons_add_opl_record(struct sim_eons *eons,
				const guint8 *contents, int length);
void sim_eons_optimize(struct sim_eons *eons);
const struct sim_eons_operator_info *sim_eons_lookup_with_lac(
						struct sim_eons *eons,
						const char *mcc,
						const char *mnc,
						guint16 lac);
const struct sim_eons_operator_info *sim_eons_lookup(struct sim_eons *eons,
						const char *mcc,
						const char *mnc);
void sim_eons_free(struct sim_eons *eons);

void sim_parse_mcc_mnc(const guint8 *bcd, char *mcc, char *mnc);
void sim_encode_mcc_mnc(guint8 *out, const char *mcc, const char *mnc);
struct sim_spdi *sim_spdi_new(const guint8 *tlv, int length);
gboolean sim_spdi_lookup(struct sim_spdi *spdi,
				const char *mcc, const char *mnc);
void sim_spdi_free(struct sim_spdi *spdi);

static inline enum sim_file_access file_access_condition_decode(int bcd)
{
	if (bcd >= 4 && bcd <= 14)
		return SIM_FILE_ACCESS_ADM;
	return bcd;
}

void sim_extract_bcd_number(const unsigned char *buf, int len, char *out);
void sim_encode_bcd_number(const char *number, unsigned char *out);

gboolean sim_adn_parse(const unsigned char *data, int length,
			struct ofono_phone_number *ph, char **identifier);
void sim_adn_build(unsigned char *data, int length,
			const struct ofono_phone_number *ph,
			const char *identifier);

struct sim_ef_info *sim_ef_db_lookup(unsigned short efid);

gboolean sim_parse_3g_get_response(const unsigned char *data, int len,
					int *file_len, int *record_len,
					int *structure, unsigned char *access,
					unsigned short *efid);

gboolean sim_parse_2g_get_response(const unsigned char *response, int len,
					int *file_len, int *record_len,
					int *structure, unsigned char *access,
					unsigned char *file_status);

gboolean sim_ust_is_available(unsigned char *service_ust, unsigned char len,
						enum sim_ust_service index);
gboolean sim_est_is_active(unsigned char *service_est, unsigned char len,
						enum sim_est_service index);
gboolean sim_sst_is_available(unsigned char *service_sst, unsigned char len,
						enum sim_sst_service index);
gboolean sim_sst_is_active(unsigned char *service_sst, unsigned char len,
						enum sim_sst_service index);

GSList *sim_parse_app_template_entries(const unsigned char *buffer, int len);