summaryrefslogtreecommitdiffstats
path: root/drivers/isimodem/uicc-util.c
blob: f04ca5aaa6b9d11e1ca9a979d97fb9f80b21ff17 (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
/*
 *
 *  oFono - Open Source Telephony
 *
 *  Copyright (C) 2011  ST-Ericsson AB.
 *  Copyright (C) 2011  Nokia Corporation and/or its subsidiary(-ies).
 *
 *  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
 *
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>

#include <glib.h>

#include <ofono/log.h>
#include <ofono/modem.h>
#include <ofono/sim.h>

#include "simutil.h"
#include "sim.h"
#include "uicc-util.h"
#include "uicc.h"
#include "debug.h"

#define USIM_APP_DEDICATED_FILE		0x7FFF

gboolean uicc_get_fileid_path(struct uicc_sim_data *sd,
				int *mf_path,
				int *df1_path,
				int *df2_path,
				unsigned char *df_len,
				int fileid)
{
	switch (fileid) {
	case SIM_EFPL_FILEID:
	case SIM_EF_ICCID_FILEID:
		*mf_path = SIM_MF_FILEID;
		*df1_path = 0x0000;
		*df2_path = 0x0000;
		*df_len = 2;
		break;
	case SIM_EFSMSP_FILEID:
	case SIM_EFSDN_FILEID:
	case SIM_EFMSISDN_FILEID:
		*mf_path = SIM_MF_FILEID;

		if (sd->app_type == UICC_APPL_TYPE_ICC_SIM)
			*df1_path = SIM_DFTELECOM_FILEID;
		else
			*df1_path = USIM_APP_DEDICATED_FILE;

		*df2_path = 0x0000;
		*df_len = 4;
		break;
	case SIM_EFLI_FILEID:
	case SIM_EFSPN_FILEID:
	case SIM_EFAD_FILEID:
	case SIM_EFPNN_FILEID:
	case SIM_EFOPL_FILEID:
	case SIM_EFMBDN_FILEID:
	case SIM_EFMBI_FILEID:
	case SIM_EFMWIS_FILEID:
	case SIM_EFSPDI_FILEID:
	case SIM_EFECC_FILEID:
	case SIM_EFCBMI_FILEID:
	case SIM_EFCBMIR_FILEID:
	case SIM_EFCBMID_FILEID:
	case SIM_EFIMSI_FILEID:
	case SIM_EFPHASE_FILEID: /*Did not find in TS 31.102 v6.21.0*/
	case SIM_EFARR_FILEID:
	case SIM_EF_CPHS_INFORMATION_FILEID: /*Found from unofficial source*/
		*mf_path = SIM_MF_FILEID;

		if (sd->app_type == UICC_APPL_TYPE_ICC_SIM)
			*df1_path = SIM_DFGSM_FILEID;
		else
			*df1_path = USIM_APP_DEDICATED_FILE;

		*df2_path = 0x0000;
		*df_len = 4;
		break;
		/* No info */
	case SIM_EF_CPHS_MBDN_FILEID:
	case SIM_EF_CPHS_MWIS_FILEID:
		DBG("======== No path info for %04X", fileid);
		return FALSE;
	case SIM_EFADN_FILEID: /* Only for SIM */
	case SIM_EFEXT1_FILEID: /* Only for SIM */
		*mf_path = SIM_MF_FILEID;
		*df1_path = SIM_DFTELECOM_FILEID;
		*df2_path = 0x0000;
		*df_len = 4;
		break;
	default:
		*mf_path = SIM_MF_FILEID;
		*df1_path = SIM_DFTELECOM_FILEID;
		*df2_path = SIM_DFPHONEBOOK_FILEID;
		*df_len = 6;
		break;
	}

	return TRUE;
}

uint8_t uicc_get_sfi(const int fileid)
{
	/* SFI list from 3GPP TS 31.102 Annex H */
	switch (fileid) {
	case SIM_EFECC_FILEID:
		return 01;
	case SIM_EFLI_FILEID:
		return 02;
	case SIM_EFAD_FILEID:
		return 03;
	case SIM_EFIMSI_FILEID:
		return 07;
	case SIM_EFCBMID_FILEID:
		return 0x0E;
	case SIM_EFPNN_FILEID:
		return 0x19;
	case SIM_EFOPL_FILEID:
		return 0x1A;
	default:
		return UICC_SFI_NOT_PRESENT;
	}
}