comparison gsm-fw/g23m-gsm/sim/sim_gprs.c @ 673:2f7df7a314f8

gsm-fw/g23m-gsm subtree: initial import from LoCosto source
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 28 Sep 2014 23:20:04 +0000
parents
children
comparison
equal deleted inserted replaced
672:0dc6f9e8e980 673:2f7df7a314f8
1 /*
2 +-----------------------------------------------------------------------------
3 | Project : GSM-F&D (8411)
4 | Modul : SIM_GPRS
5 +-----------------------------------------------------------------------------
6 | Copyright 2002 Texas Instruments Berlin, AG
7 | All rights reserved.
8 |
9 | This file is confidential and a trade secret of Texas
10 | Instruments Berlin, AG
11 | The receipt of or possession of this file does not convey
12 | any rights to reproduce or disclose its contents or to
13 | manufacture, use, or sell anything it may describe, in
14 | whole, or in part, without the specific written consent of
15 | Texas Instruments Berlin, AG.
16 +-----------------------------------------------------------------------------
17 | Purpose : This modul defines the GPRS Upgrade.
18 +-----------------------------------------------------------------------------
19 */
20
21 #ifndef SIM_GPRS_C
22 #define SIM_GPRS_C
23
24 #define ENTITY_SIM
25
26 /*==== INCLUDES ===================================================*/
27
28 #include <string.h>
29 #include "typedefs.h"
30 #include "pcm.h"
31 #include "pconst.cdg"
32 #include "message.h"
33 #include "ccdapi.h"
34 #include "vsi.h"
35 #include "custom.h"
36 #include "gsm.h"
37 #include "cnf_sim.h"
38 #include "mon_sim.h"
39 #include "prim.h"
40 #include "pei.h"
41 #include "tok.h"
42 #include "sim.h"
43
44 /*==== EXPORT =====================================================*/
45
46 /*==== PRIVAT =====================================================*/
47
48 /*==== TYPES ======================================================*/
49
50 /*==== CONSTANTS ==================================================*/
51
52 /*==== VARIABLES ==================================================*/
53
54 /*==== FUNCTIONS ==================================================*/
55
56 /*
57 +--------------------------------------------------------------------+
58 | PROJECT : GSM-PS (8419) MODULE : SIM_GPRS |
59 | STATE : code ROUTINE : gprs_check_pcm_data |
60 +--------------------------------------------------------------------+
61
62 PURPOSE : Checks the validation of GPRS data stored in PCM.
63
64 */
65
66 GLOBAL BOOL gprs_check_pcm_data (T_imsi_field *sim_imsi)
67 {
68 EF_IMSIGPRS imsi;
69 UBYTE version;
70
71
72 return pcm_ReadFile((UBYTE *)EF_IMSIGPRS_ID, SIZE_EF_IMSIGPRS,
73 (UBYTE *)&imsi, &version) EQ PCM_OK
74 AND
75 (sim_imsi->c_field EQ imsi.len)
76 AND
77 !memcmp(imsi.IMSI, sim_imsi->field, sim_imsi->c_field);
78 }
79 /*
80 +--------------------------------------------------------------------+
81 | PROJECT : GSM-PS (8419) MODULE : SIM_GPRS |
82 | STATE : code ROUTINE : gprs_gmm_insert_ind |
83 +--------------------------------------------------------------------+
84
85 PURPOSE : Collects the initial data for GMM.
86
87 */
88
89 GLOBAL void gprs_gmm_insert_ind (T_SIM_MM_INSERT_IND * sim_mm_insert_ind)
90 {
91 UBYTE kc_n[MAX_KC_N];
92 int i;
93 /*
94 * Read Parameters for GPRS mobility management
95 */
96 PALLOC (sim_gmm_insert_ind, SIM_GMM_INSERT_IND);
97
98 TRACE_FUNCTION ("gprs_sim_gmm_insert_ind()");
99
100 /*
101 * administrative data
102 */
103 sim_gmm_insert_ind->op_mode = sim_mm_insert_ind->ad[0];
104
105 /*
106 * IMSI
107 */
108 memcpy (&sim_gmm_insert_ind->imsi_field, &sim_mm_insert_ind->imsi_field,
109 sizeof (T_imsi_field));
110 /*
111 * Location Information
112 */
113 memcpy (&sim_gmm_insert_ind->loc_info, &sim_mm_insert_ind->loc_info,
114 sizeof (T_loc_info));
115 /*
116 * access control classes
117 */
118 memcpy (&sim_gmm_insert_ind->acc_ctrl, &sim_mm_insert_ind->acc_ctrl,
119 sizeof (T_acc_ctrl));
120 /*
121 * phase
122 */
123 sim_gmm_insert_ind->phase = sim_data.sim_phase;
124
125 if (SIM_IS_FLAG_SET (SERVICE_38_SUPPORT))
126 {
127 /*
128 * SIM card supports GPRS
129 *
130 * Read GPRS Location Information
131 */
132 TRACE_EVENT ("SIM supports GPRS");
133
134 if (FKT_Select (SIM_LOCGPRS, FALSE, NULL, NULL, 0) EQ SIM_NO_ERROR)
135 {
136 sim_gmm_insert_ind->gprs_loc_info.c_loc = MAX_LOCIGPRS;
137 if (FKT_ReadBinary ((UBYTE *)&sim_gmm_insert_ind->gprs_loc_info.loc,
138 0, MAX_LOCIGPRS) NEQ SIM_NO_ERROR)
139 {
140 PFREE (sim_gmm_insert_ind);
141 return;
142 }
143 }
144 /*
145 * Read GPRS KC
146 */
147 if (FKT_Select (SIM_KCGPRS, FALSE, NULL, NULL, 0) EQ SIM_NO_ERROR)
148 {
149 if (FKT_ReadBinary ((UBYTE *)kc_n, 0, MAX_KC_N) NEQ
150 SIM_NO_ERROR)
151 {
152 PFREE (sim_gmm_insert_ind);
153 return;
154 }
155 else
156 {
157 sim_gmm_insert_ind->kc_n.c_kc = MAX_KC_N;
158 /*
159 * Store KC in opposite order
160 */
161 for (i = 0; i < MAX_KC; i++)
162 sim_gmm_insert_ind->kc_n.kc[(MAX_KC-1)-i] = kc_n[i];
163 /*
164 * Store cipher key sequence number
165 */
166 sim_gmm_insert_ind->kc_n.kc[MAX_KC] = kc_n[MAX_KC];
167 }
168 }
169 }
170 else
171 {
172 /*
173 * Use PCM instead
174 */
175 TRACE_EVENT ("SIM does not support GPRS");
176
177 /*
178 * Only use ME data, when it is marked with IMSI
179 * Note : No storage of the changed IMSI here!
180 */
181 if (gprs_check_pcm_data (&sim_mm_insert_ind->imsi_field))
182 {
183 UBYTE version;
184 /*
185 * then read the fields
186 */
187 pcm_ReadFile((UBYTE *) EF_LOCGPRS_ID,SIZE_EF_LOCGPRS,
188 (UBYTE *) &sim_gmm_insert_ind->gprs_loc_info.loc, &version);
189 sim_gmm_insert_ind->gprs_loc_info.c_loc = MAX_LOCIGPRS;
190 pcm_ReadFile((UBYTE *) EF_KCGPRS_ID,SIZE_EF_KCGPRS,
191 (UBYTE *) &sim_gmm_insert_ind->kc_n, &version);
192 }
193 else
194 {
195 /*
196 * reading of IMSI failed, set values to defaults
197 */
198 memset (&sim_gmm_insert_ind->gprs_loc_info.loc, 0xFF, MAX_LOCIGPRS);
199 sim_gmm_insert_ind->gprs_loc_info.loc[11] = 0xFE;
200 sim_gmm_insert_ind->gprs_loc_info.c_loc = 0;
201 memset (&sim_gmm_insert_ind->kc_n, 0xFF, 9);
202 }
203 }
204
205 /*
206 * send information to GPRS mobility management
207 */
208 PSENDX (GMM, sim_gmm_insert_ind);
209 }
210
211 /*
212 +--------------------------------------------------------------------+
213 | PROJECT : GSM-PS (6302) MODULE : SIM_GPRS |
214 | STATE : code ROUTINE : gprs_gmm_update_req |
215 +--------------------------------------------------------------------+
216
217 PURPOSE : Process of the primitive SIM_GMM_UPDATE_REQ.
218
219 */
220
221 GLOBAL void gprs_sim_gmm_update_req (T_SIM_GMM_UPDATE_REQ * sim_gmm_update_req)
222 {
223 int i;
224 T_kc_n kc_n;
225
226 TRACE_FUNCTION ("gprs_sim_gmm_update_req()");
227
228 /*
229 * prepare kc and cksn for storing
230 */
231 kc_n.c_kc = MAX_KC_N;
232 kc_n.kc[MAX_KC] = sim_gmm_update_req->cksn;
233 for (i = 0; i < MAX_KC; i++)
234 kc_n.kc[(MAX_KC-1)-i] = sim_gmm_update_req->kc[i];
235
236 /*
237 * SIM with GPRS service activated?
238 */
239 if (SIM_IS_FLAG_SET (SERVICE_38_SUPPORT))
240 {
241 /*
242 * check location information
243 */
244 if (sim_gmm_update_req->gprs_loc_info.c_loc > 0)
245 {
246 if (FKT_Select (SIM_LOCGPRS, FALSE, NULL, NULL, 0) EQ SIM_NO_ERROR)
247 FKT_UpdateBinary (sim_gmm_update_req->gprs_loc_info.loc,
248 MAX_LOCIGPRS, 0);
249 }
250 /*
251 * store kc and cksn
252 */
253 if (FKT_Select (SIM_KCGPRS, FALSE, NULL, NULL, 0) EQ SIM_NO_ERROR)
254 {
255 FKT_UpdateBinary (kc_n.kc, kc_n.c_kc, 0);
256 }
257 }
258 else
259 {
260 /*
261 * SIM with no GPRS service: store in ME memory
262 */
263 T_imsi_field sim_imsi;
264
265 if (FKT_Select (SIM_IMSI, FALSE, NULL, NULL, 0) EQ SIM_NO_ERROR AND
266 FKT_ReadBinary ((UBYTE *)&sim_imsi, 0, MAX_IMSI)
267 EQ SIM_NO_ERROR)
268 {
269 /*
270 * Compare IMSI on SIM with IMSI in ME memory
271 */
272 if (!gprs_check_pcm_data (&sim_imsi))
273 {
274 /*
275 * Check GPRS attach status of current IMSI (from SIM)
276 */
277 if (sim_gmm_update_req->att_status)
278 /*
279 * Update IMSI in ME memory, when attached
280 */
281 pcm_WriteFile((UBYTE *)EF_IMSIGPRS_ID, SIZE_EF_IMSIGPRS,
282 (UBYTE *)&sim_imsi);
283 else
284 {
285 /*
286 * do not update GPRS data
287 */
288 PFREE (sim_gmm_update_req);
289 return;
290 }
291 }
292 /*
293 * Update GPRS data in ME memory
294 */
295 if (sim_gmm_update_req->gprs_loc_info.c_loc > 0)
296 {
297 pcm_WriteFile((UBYTE *)EF_LOCGPRS_ID,SIZE_EF_LOCGPRS,
298 (UBYTE *)&sim_gmm_update_req->gprs_loc_info.loc);
299 }
300 pcm_WriteFile((UBYTE *)EF_KCGPRS_ID,SIZE_EF_KCGPRS,
301 (UBYTE *)kc_n.kc);
302 }
303 }
304 PFREE (sim_gmm_update_req);
305 }
306
307 #endif