comparison src/g23m-gprs/gmm/gmm_em.c @ 183:219afcfc6250

src/g23m-gprs: initial import from TCS3.2/LoCosto
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 13 Oct 2016 04:24:13 +0000
parents
children
comparison
equal deleted inserted replaced
182:f02d0a0e1849 183:219afcfc6250
1
2
3 /*
4 +-----------------------------------------------------------------------------
5 | Project :
6 | Modul :
7 +-----------------------------------------------------------------------------
8 | Copyright 2002 Texas Instruments Berlin, AG
9 | All rights reserved.
10 |
11 | This file is confidential and a trade secret of Texas
12 | Instruments Berlin, AG
13 | The receipt of or possession of this file does not convey
14 | any rights to reproduce or disclose its contents or to
15 | manufacture, use, or sell anything it may describe, in
16 | whole, or in part, without the specific written consent of
17 | Texas Instruments Berlin, AG.
18 +-----------------------------------------------------------------------------
19 | Purpose : This Module defines the engineering mode (EM) device driver for the
20 | G23 protocol stack. This driver is used to control all engineering
21 | mode related functions.
22 +-----------------------------------------------------------------------------
23 */
24
25 #ifndef GMM_EM_C
26 #define GMM_EM_C
27
28 #define ENTITY_GMM
29
30 /*--------- INCLUDES -----*/
31
32
33 #include "typedefs.h" /* to get Condat data types */
34 #include "vsi.h" /* to get a lot of macros */
35 #include "macdef.h"
36 #include "gprs.h"
37 #include "gsm.h" /* to get a lot of macros */
38 #include "custom.h" /* to get EM for Simulation Stack compiled*/
39 #include "prim.h" /* to get the definitions of used SAP and directions */
40 #include "gmm.h" /* to get the global entity definitions */
41
42 #include <string.h> /* to get memcpy , memset*/
43
44 #include "gmm_em.h" /*to get EM spezific definitions*/
45
46 #ifdef FF_EM_MODE
47 GLOBAL UBYTE em_gmm_event_buffer[EM_GMM_BUFFER_SIZE];
48 GLOBAL UBYTE em_gmm_buffer_write;
49
50 /* Event tracing flags for EM */
51 GLOBAL BOOL gmm_v[EM_MAX_GMM_EVENTS];
52
53 static UBYTE em_gmm_trace_occured;
54
55
56 /*----------Transfer Functions from and to GRR/GRLC -------*/
57 /*This functions handle Engineering Mode Primitives that are sent from ACI
58 to GRR or GRLC (and the other way around). Because they cannot be sent directly,
59 they have to be passed through GMM
60 */
61 /*
62 +------------------------------------------------------------------------------
63 | Function : em_gmm_sc_gprs_info_req
64 +------------------------------------------------------------------------------
65 | Description : The function em_gmm_sc_gprs_info_req() is used to forward a
66 | request from ACI to GRR.
67 |
68 | Parameters : EM_SC_GPRS_INFO_REQ
69 |
70 +------------------------------------------------------------------------------
71 */
72 GLOBAL void em_gmm_sc_gprs_info_req ( T_EM_SC_GPRS_INFO_REQ *em_sc_gprs_info_req)
73 {
74 GMM_TRACE_FUNCTION( "em_gmm_sc_gprs_info_req" );
75 /* NO PFREE */
76 PSEND ( hCommGRR, em_sc_gprs_info_req );
77
78 } /* em_gmm_sc_gprs_info_req () */
79
80 /*
81 +------------------------------------------------------------------------------
82 | Function : check_write_index
83 +------------------------------------------------------------------------------
84 | Description : Checks the write index inside the buffer. No reset when
85 | buffer is full.
86 |
87 | Parameters : Number of bytes to be stored in buffer
88 |
89 | Return : TRUE/FALSE
90 |
91 +------------------------------------------------------------------------------
92 */
93 GLOBAL UBYTE check_write_index (UBYTE n)
94 {
95 TRACE_FUNCTION ("gmm_check_write_index()");
96
97 if (em_gmm_buffer_write + n < EM_GMM_BUFFER_SIZE)
98 {
99 /*
100 * ACI is informed about the first event trace,
101 * used for later data processing.
102 */
103 if (em_gmm_trace_occured EQ 0)
104 {
105 PALLOC(data, EM_DATA_IND);
106 data->entity = EM_GMM;
107 PSENDX(MMI, data);
108 em_gmm_trace_occured++;
109 }
110 return TRUE;
111 }
112 else
113 return FALSE;
114 }
115
116 /*+------------------------------------------------------------------------------
117 | Function : em_init_gmm_event_trace
118 +------------------------------------------------------------------------------
119 | Description : Initialize the event tracing flags for GMM
120 |
121 | Parameters : void
122 |
123 | Return : void
124 |
125 +------------------------------------------------------------------------------
126 */
127 GLOBAL void em_init_gmm_event_trace(void)
128 {
129 UBYTE i;
130
131 TRACE_FUNCTION ("em_init_gmm_event_trace()");
132
133 for (i = 0; i < EM_MAX_GMM_EVENTS; i++)
134 gmm_v[i] = 0;
135
136 em_gmm_buffer_write = 0;
137 }
138
139 /*
140 +------------------------------------------------------------------------------
141 | Function : em_gmm_event_req
142 +------------------------------------------------------------------------------
143 | Description : Set the event tracing flags according the bitmask
144 |
145 | Parameters : Primitive - Bitmask
146 |
147 | Return :
148 |
149 +------------------------------------------------------------------------------
150 */
151
152 GLOBAL void em_gmm_event_req (T_EM_GMM_EVENT_REQ *em_gmm_event_req)
153 {
154 UBYTE i;
155
156 TRACE_FUNCTION ("em_gmm_event_req()");
157
158 /*
159 * The event tracing flags are set according the bitmask. mm_v[i] are
160 * the flags belonging to the event number described in 8443.601
161 */
162 for(i = 1; i < EM_MAX_GMM_EVENTS; i++)
163 gmm_v[i] = ((em_gmm_event_req->bitmask_gmm & (0x01<<(i-1))) > 0) ? TRUE : FALSE;
164
165 /*
166 * A new event trace is generated therefore the flag is reset.
167 */
168 em_gmm_trace_occured = 0;
169
170 PFREE(em_gmm_event_req);
171 }
172
173 /*
174 +------------------------------------------------------------------------------
175 | Function : em_write_buffer_4
176 +------------------------------------------------------------------------------
177 | Description : Perform buffer check and store corresponding data in it.
178 |
179 | Parameters : Event number, data identity type (UBYTE), data value (UBYTE)
180 |
181 | Return : TRUE/FALSE
182 |
183 | Pupose : Used for storing states
184 +------------------------------------------------------------------------------
185 */
186
187 GLOBAL UBYTE em_write_buffer_4 (UBYTE event_no, UBYTE value1, UBYTE value2)
188 {
189 TRACE_FUNCTION ("gmm_em_write_buffer_4()");
190
191 if (check_write_index(4))
192 {
193 em_gmm_event_buffer[em_gmm_buffer_write++] = event_no; /* Tag: Event number */
194 em_gmm_event_buffer[em_gmm_buffer_write++] = 2; /* Length */
195 em_gmm_event_buffer[em_gmm_buffer_write++] = value1;
196 em_gmm_event_buffer[em_gmm_buffer_write++] = value2;
197 return FALSE; /* Data is stored inside buffer, reset flag */
198 }/* check write index*/
199 else
200 return TRUE; /* No more space inside buffer, serve flag next time */
201 }
202 /*
203 +------------------------------------------------------------------------------
204 | Function : em_gmm_sc_gprs_info_cnf
205 +------------------------------------------------------------------------------
206 | Description : The function em_gmm_sc_gprs_info_cnf() is used to forward a
207 | confirm from GRR to ACI.
208 |
209 | Parameters : EM_SC_GPRS_INFO_CN
210 |
211 +------------------------------------------------------------------------------
212 */
213 GLOBAL void em_gmm_sc_gprs_info_cnf ( T_EM_SC_GPRS_INFO_CNF *em_sc_gprs_info_cnf)
214 {
215 GMM_TRACE_FUNCTION( "em_gmm_sc_gprs_info_cnf" );
216 /* NO PFREE */
217 PSEND ( hCommMMI, em_sc_gprs_info_cnf );
218
219 } /* em_gmm_sc_gprs_info_cnf () */
220
221
222
223
224 /*
225 +------------------------------------------------------------------------------
226 | Function : em_gmm_grlc_info_req
227 +------------------------------------------------------------------------------
228 | Description : The function em_gmm_grlc_info_req() is used to forward a
229 | request from ACI to GRLC.
230 |
231 | Parameters : EM_GRLC_INFO_REQ
232 |
233 +------------------------------------------------------------------------------
234 */
235 GLOBAL void em_gmm_grlc_info_req ( T_EM_GRLC_INFO_REQ *em_grlc_info_req)
236 {
237 GMM_TRACE_FUNCTION( "em_gmm_grlc_info_req" );
238 /* NO PFREE */
239 PSEND ( hCommGRLC, em_grlc_info_req);
240
241 } /* em_gmm_grlc_info_req () */
242
243
244 GLOBAL void em_gmm_throughput_info_req ( T_EM_THROUGHPUT_INFO_REQ *em_throughput_info_req)
245 {
246 GMM_TRACE_FUNCTION( "em_gmm_throughput_info_req" );
247 /* NO PFREE */
248 PSEND ( hCommGRLC, em_throughput_info_req);
249
250 } /* em_gmm_throughput_info_req () */
251
252 GLOBAL void em_gmm_throughput_info_cnf ( T_EM_THROUGHPUT_INFO_CNF *em_throughput_info_cnf)
253 {
254 GMM_TRACE_FUNCTION( "em_gmm_throughput_info_cnf" );
255 /* NO PFREE */
256 PSEND ( hCommMMI, em_throughput_info_cnf );
257
258 } /* em_gmm_throughput_info_cnf () */
259
260 GLOBAL void em_gmm_grr_event_req ( T_EM_GRR_EVENT_REQ *em_grr_event_req)
261 {
262 GMM_TRACE_FUNCTION( "em_gmm_grr_event_req" );
263 /* NO PFREE */
264 PSEND ( hCommGRR, em_grr_event_req);
265
266 } /* em_gmm_grr_event_req () */
267
268 GLOBAL void em_gmm_grlc_event_req ( T_EM_GRLC_EVENT_REQ *em_grlc_event_req)
269 {
270 GMM_TRACE_FUNCTION( "em_gmm_grlc_event_req" );
271 /* NO PFREE */
272 PSEND ( hCommGRLC, em_grlc_event_req);
273
274 } /* em_gmm_grlc_event_req () */
275
276 GLOBAL void em_gmm_data_ind ( T_EM_DATA_IND *em_data_ind)
277 {
278 GMM_TRACE_FUNCTION( "em_gmm_data_ind" );
279 /* NO PFREE */
280 PSEND ( hCommMMI, em_data_ind);
281
282 } /* em_gmm_data_ind () */
283
284 /*
285 +------------------------------------------------------------------------------
286 | Function : em_gmm_grlc_info_cnf
287 +------------------------------------------------------------------------------
288 | Description : The function em_gmm_grlc_info_cnf() is used to forward a
289 | confirm from GRLC to ACI.
290 |
291 | Parameters : EM_GRLC_INFO_CNF
292 |
293 +------------------------------------------------------------------------------
294 */
295 GLOBAL void em_gmm_grlc_info_cnf ( T_EM_GRLC_INFO_CNF *em_grlc_info_cnf)
296 {
297 GMM_TRACE_FUNCTION( "em_gmm_grlc_info_cnf" );
298 /* NO PFREE */
299 PSEND ( hCommMMI, em_grlc_info_cnf );
300
301 } /* em_gmm_grlc_info_cnf () */
302
303
304
305 /*----------------- GMM - Data - Function ---------------*/
306 /*
307 +------------------------------------------------------------------------------
308 | Function : em_gmm_pco_trace_req
309 +------------------------------------------------------------------------------
310 | Description : The function em_gmm_pco_trace_req() is used to trace EM - GMM
311 | relevant data at the PCO. If necessary the Request is forwarded
312 | to GRR or/and GRLC.
313 |
314 | Parameters : EM_PCO_TRACE_REQ
315 |
316 +------------------------------------------------------------------------------
317 */
318 GLOBAL void em_gmm_pco_trace_req ( T_EM_PCO_TRACE_REQ *em_pco_trace_req)
319 {
320 GMM_TRACE_FUNCTION( "em_gmm_pco_trace_req" );
321
322 /*check if GMM data is requested*/
323 if(em_pco_trace_req->pco_bitmap & EM_PCO_GMM_INFO)
324 {
325 TRACE_EVENT_EM_P8("EM_GMM_INFO_REQ: ready_st:%d tlli:%u ptmsi:%u ptmsi_sig:%u ready_tim:%u ciph_alg:%d periodic_tim:%u ciph_on:%d",
326 GET_STATE(RDY),
327 gmm_data->tlli.current,
328 gmm_data->ptmsi.current,
329 gmm_data->ptmsi_signature.value,
330 gmm_data->rdy.t3314_val,
331 gmm_data->kern.auth_cap.ciphering_algorithm,
332 gmm_data->rdy.t3312_val,
333 gmm_data->cipher);
334
335
336 TRACE_EVENT_EM_P2("EM_GMM_INFO_REQ: t3312_deactive:%u t3312_val_sec:%d",
337 gmm_data->rdy.t3312_deactivated,
338 gmm_data->rdy.t3312_val/SEC);
339 }
340
341 /*check if a forward to GRR is necessary*/
342 if(em_pco_trace_req->pco_bitmap & EM_PCO_GPRS_INFO)
343 {
344 /*copy the request and send it to GRR*/
345 PALLOC (em_pco_trace_req_grr, EM_PCO_TRACE_REQ);
346 memcpy (em_pco_trace_req_grr, em_pco_trace_req, sizeof (T_EM_PCO_TRACE_REQ));
347
348 /* NO PFREE */
349 PSEND ( hCommGRR, em_pco_trace_req_grr );
350 }
351
352 /*check if a forward to GRLC is necessary*/
353 if(em_pco_trace_req->pco_bitmap & EM_PCO_GRLC_INFO)
354 {
355 /*send original request, because it is no longer needed in GMM*/
356 /* NO PFREE */
357 PSEND ( hCommGRLC, em_pco_trace_req);
358 }
359 else
360 {
361 PFREE(em_pco_trace_req);
362 }
363
364 }/*em_gmm_pco_trace_req*/
365
366 /*
367 +------------------------------------------------------------------------------
368 | Function : em_gmm_info_req
369 +------------------------------------------------------------------------------
370 | Description : The function em_gmm_info_req() is used to provide EM - GMM
371 | relevant data and send it back to ACI.
372 |
373 | Parameters : EM_GMM_INFO_REQ
374 |
375 +------------------------------------------------------------------------------
376 */
377 GLOBAL void em_gmm_info_req ( T_EM_GMM_INFO_REQ *em_gmm_info_req)
378 {
379 PALLOC (em_gmm_info_cnf, EM_GMM_INFO_CNF);
380
381 GMM_TRACE_FUNCTION( "em_gmm_info_req" );
382 PFREE(em_gmm_info_req);
383
384 memset (em_gmm_info_cnf, 0, sizeof (T_EM_GMM_INFO_CNF));
385
386 em_gmm_info_cnf->ready_state = GET_STATE(RDY);
387 em_gmm_info_cnf->tlli = gmm_data->tlli.current;
388 em_gmm_info_cnf->ptmsi = gmm_data->ptmsi.current;
389 em_gmm_info_cnf->ptmsi_sig = gmm_data->ptmsi_signature.value;
390 em_gmm_info_cnf->ready_timer = gmm_data->rdy.t3314_val;
391 em_gmm_info_cnf->ciphering_algorithm = gmm_data->kern.auth_cap.ciphering_algorithm;
392 em_gmm_info_cnf->t3312.t3312_deactivated = gmm_data->rdy.t3312_deactivated;
393 em_gmm_info_cnf->t3312.t3312_val = gmm_data->rdy.t3312_val/SEC;
394
395
396
397
398 /* NO PFREE */
399 PSEND ( hCommMMI, em_gmm_info_cnf);
400
401 } /* em_gmm_info_req () */
402
403 /*
404 +------------------------------------------------------------------------------
405 | Function : em_gmm_map_state
406 +------------------------------------------------------------------------------
407 | Description : The function em_gmm_map_state maps the GMM state used within the
408 GMM entity to state and substate values required by the EM entity
409 |
410 | Parameters : void
411 |
412 +------------------------------------------------------------------------------
413 */
414 GLOBAL void em_gmm_map_state ( UBYTE state, UBYTE *main_state, UBYTE *sub_state)
415 {
416 switch(state)
417 {
418 case KERN_GMM_NULL_NO_IMSI:
419 case KERN_GMM_NULL_IMSI:
420 case KERN_GMM_NULL_NO_IMSI_LIMITED_SERVICE_REQ:
421 case KERN_GMM_NULL_IMSI_LIMITED_SERVICE_REQ:
422 case KERN_GMM_NULL_PLMN_SEARCH:
423 *main_state = GMM_EM_NULL_STATE;
424 *sub_state = GMM_EM_POWER_OFF_SUBSTATE;
425 break;
426
427 case KERN_GMM_DEREG_INITIATED:
428 *main_state = GMM_EM_DEREG_INIT_STATE;
429 *sub_state = GMM_EM_NORMAL_SRVC_SUBSTATE;
430 break;
431
432 case KERN_GMM_DEREG_ATTEMPTING_TO_ATTACH:
433 *main_state = GMM_EM_DEREG_STATE;
434 *sub_state = GMM_EM_ATTEMPT_TO_ATT_SUBSTATE;
435 break;
436
437 case KERN_GMM_DEREG_NO_CELL_AVAILABLE:
438 *main_state = GMM_EM_DEREG_STATE;
439 *sub_state = GMM_EM_NO_CELL_SUBSTATE;
440 break;
441
442 case KERN_GMM_DEREG_LIMITED_SERVICE:
443 case KERN_GMM_DEREG_NO_IMSI:
444 case KERN_GMM_DEREG_PLMN_SEARCH:
445 *main_state = GMM_EM_DEREG_STATE;
446 *sub_state = GMM_EM_ATT_NEEDED_SUBSTATE;
447 break;
448
449 case KERN_GMM_DEREG_SUSPENDED:
450 case KERN_GMM_DEREG_SUSPENDING:
451 case KERN_GMM_DEREG_RESUMING:
452 *main_state = GMM_EM_DEREG_STATE;
453 *sub_state = GMM_EM_SUSPENDED_SUBSTATE;
454 break;
455
456 case KERN_GMM_REG_INITIATED:
457 *main_state = GMM_EM_REG_INIT_STATE;
458 *sub_state = GMM_EM_NORMAL_SRVC_SUBSTATE;
459 break;
460
461 case KERN_GMM_REG_NO_CELL_AVAILABLE:
462 *main_state = GMM_EM_REG_STATE;
463 *sub_state = GMM_EM_NO_CELL_SUBSTATE;
464 break;
465
466 case KERN_GMM_REG_LIMITED_SERVICE:
467 *main_state = GMM_EM_REG_STATE;
468 *sub_state = GMM_EM_UPDATE_NEEDED_SUBSTATE;
469 break;
470
471 case KERN_GMM_REG_ATTEMPTING_TO_UPDATE_MM:
472 *main_state = GMM_EM_REG_STATE;
473 *sub_state = GMM_EM_ATTEMPT_TO_UPDATE_MM_SUBSTATE;
474 break;
475
476 case KERN_GMM_REG_ATTEMPTING_TO_UPDATE:
477 *main_state = GMM_EM_REG_STATE;
478 *sub_state = GMM_EM_ATTEMPT_TO_UPDATE_SUBSTATE;
479 break;
480
481 case KERN_GMM_REG_RESUMING:
482 case KERN_GMM_REG_SUSPENDED:
483 case KERN_GMM_REG_SUSPENDING:
484 *main_state = GMM_EM_REG_STATE;
485 *sub_state = GMM_EM_SUSPENDED_SUBSTATE;
486 break;
487
488 case KERN_GMM_REG_NORMAL_SERVICE:
489 case KERN_GMM_REG_TEST_MODE:
490 *main_state = GMM_EM_REG_STATE;
491 *sub_state = GMM_EM_NORMAL_SRVC_SUBSTATE;
492 break;
493
494 case KERN_GMM_RAU_INITIATED:
495 case KERN_GMM_RAU_WAIT_FOR_NPDU_LIST:
496 *main_state = GMM_EM_RAU_INIT_STATE;
497 *sub_state = GMM_EM_NORMAL_SRVC_SUBSTATE;
498 break;
499
500 case KERN_GMM_REG_IMSI_DETACH_INITIATED:
501 *main_state = GMM_EM_REG_STATE;
502 *sub_state = GMM_EM_IMSI_DETACH_INIT_SUBSTATE;
503 break;
504
505 case KERN_GMM_REG_TEST_MODE_NO_IMSI:
506 *main_state = GMM_EM_REG_STATE;
507 *sub_state = GMM_EM_POWER_OFF_SUBSTATE;
508 break;
509
510 default:
511 TRACE_ERROR ("Unknown state passed to function");
512 break;
513 }
514 return;
515 }
516
517
518 #endif /* FF_EM_MODE */
519
520 #endif /*GMM_EM_C */