comparison src/g23m-gprs/gmm/gmm_syncp.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 | Project : GPRS (8441)
4 | Modul : gmm_syncp.c
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 :
18 +-----------------------------------------------------------------------------
19 */
20
21 #ifndef GMM_SYNCP_C
22 #define GMM_SYNCP_C
23 #endif
24
25 #define ENTITY_GMM
26
27 /*==== INCLUDES =============================================================*/
28
29 #include "typedefs.h" /* to get Condat data types */
30 #include "vsi.h" /* to get a lot of macros */
31 #include "macdef.h"
32 #include "gprs.h"
33 #include "gsm.h" /* to get a lot of macros */
34 #include "ccdapi.h" /* to get CCD API */
35 #include "cnf_gmm.h" /* to get cnf-definitions */
36 #include "mon_gmm.h" /* to get mon-definitions */
37 #include "prim.h" /* to get the definitions of used SAP and directions */
38 #include "gmm.h" /* to get the global entity definitions */
39 #include "gmm_f.h" /* to get the gdebug print function */
40
41 #include "gmm_kerns.h" /* to get signals */
42 #include "gmm_syncf.h"
43
44
45 /*
46 +------------------------------------------------------------------------------
47 | Function : sync_tsync
48 +------------------------------------------------------------------------------
49 | Description : Handles expiry of timer TSYNC. This function is called from
50 | pei_primitive().
51 | Timeout for waiting of GMMRR_CELL_IND or MMGMM_ACTIVATE_IND
52 | or MMGMM_NREG_IND
53 | Parameters : none
54 |
55 +------------------------------------------------------------------------------
56 */
57 GLOBAL void sync_tsync (void)
58 {
59 GMM_TRACE_FUNCTION( "sync_tsync" );
60 TRACE_0_INFO("TIMEOUT TSYNC expired");
61
62 switch( GET_STATE( SYNC ) )
63 {
64 case SYNC_WAIT_FOR_GPRS:
65 SET_STATE ( SYNC, SYNC_IDLE );
66 sync_send_mm_cell_info();
67 break;
68 case SYNC_WAIT_FOR_GSM:
69 SET_STATE ( SYNC, SYNC_IDLE );
70 sync_send_cell_info();
71 break;
72 case SYNC_IDLE:
73 default:
74 TRACE_ERROR("TSYNC expired in wrong state");
75 sync_send_cell_info();
76 break;
77 }
78 GMM_RETURN;
79 } /* sync_tsync */
80
81 /*
82 +------------------------------------------------------------------------------
83 | Function : sync_gmmrr_cell_ind
84 +------------------------------------------------------------------------------
85 | Description : Handles the primitive GMMRR_CELL_IND
86 |
87 | Parameters : *gmmrr_cell_ind - Ptr to primitive payload
88 |
89 +------------------------------------------------------------------------------
90 */
91 GLOBAL void sync_gmmrr_cell_ind (T_GMMRR_CELL_IND * gmmrr_cell_ind)
92 {
93
94 #ifdef REL99
95 /*The flag value is initialized to 0(CL_SGSN_REL_98_OR_OLDER). */
96 U8 temp_sgsnr_flag = PS_SGSN_98_OLDER; /* TCS 4.0 */
97 #endif
98
99 GMM_TRACE_FUNCTION( "sync_gmmrr_cell_ind" );
100 #ifdef GMM_TCS4
101 TRACE_12_PARA("%s, %s,%x%x%x, %x%x%x, NMO: %d, lac %x, rac %x, cid %x", /* TCS 4.0 */
102 (RT_GPRS==gmmrr_cell_ind->cell_info.rt?"GPRS":"EDGE"), /* TCS 4.0 */
103 GMMRR_SERVICE_FULL == gmmrr_cell_ind->cell_info.service_state?"service":(GMMRR_SERVICE_LIMITED== gmmrr_cell_ind->cell_info.service_state?"limited service":"NO GPRS service"),
104 gmmrr_cell_ind->cell_info.cell_env.rai.plmn.mcc[0],
105 gmmrr_cell_ind->cell_info.cell_env.rai.plmn.mcc[1],
106 gmmrr_cell_ind->cell_info.cell_env.rai.plmn.mcc[2],
107 gmmrr_cell_ind->cell_info.cell_env.rai.plmn.mnc[0],
108 gmmrr_cell_ind->cell_info.cell_env.rai.plmn.mnc[1],
109 gmmrr_cell_ind->cell_info.cell_env.rai.plmn.mnc[2],
110 gmmrr_cell_ind->cell_info.net_mode+1,
111 gmmrr_cell_ind->cell_info.cell_env.rai.lac,
112 gmmrr_cell_ind->cell_info.cell_env.rai.rac,
113 gmmrr_cell_ind->cell_info.cell_env.cid);
114 #else
115 TRACE_11_PARA("%s,%x%x%x, %x%x%x, NMO: %d, lac %x, rac %x, cid %x",
116 GMMRR_SERVICE_FULL == gmmrr_cell_ind->cell_info.service_state?"service":(GMMRR_SERVICE_LIMITED== gmmrr_cell_ind->cell_info.service_state?"limited service":"NO GPRS service"),
117 gmmrr_cell_ind->cell_info.cell_env.rai.plmn.mcc[0],
118 gmmrr_cell_ind->cell_info.cell_env.rai.plmn.mcc[1],
119 gmmrr_cell_ind->cell_info.cell_env.rai.plmn.mcc[2],
120 gmmrr_cell_ind->cell_info.cell_env.rai.plmn.mnc[0],
121 gmmrr_cell_ind->cell_info.cell_env.rai.plmn.mnc[1],
122 gmmrr_cell_ind->cell_info.cell_env.rai.plmn.mnc[2],
123 gmmrr_cell_ind->cell_info.net_mode+1,
124 gmmrr_cell_ind->cell_info.cell_env.rai.lac,
125 gmmrr_cell_ind->cell_info.cell_env.rai.rac,
126 gmmrr_cell_ind->cell_info.cell_env.cid);
127 #endif
128
129 #ifdef REL99
130 /* During initialiazation sgsnr_flag should be initialized to
131 * the value 0 (CL_SGSN_REL_98_OR_OLDER)
132 */
133 /* The function getSGSNRelease is implemented by RR layer. It
134 * returns the current SGSN release flag - CL_SGSN_REL_98_OR_OLDER
135 * or CL_SGSN_REL_99_ONWARDS
136 */
137
138 temp_sgsnr_flag = cl_nwrl_get_sgsn_release(); /* TCS 4.0 */
139 TRACE_1_OUT_PARA ("SGSNR_FLAG is >>>>: %x", temp_sgsnr_flag); /* TCS 4.0 */
140 /* CL can return three values. SGSN release can be R98,
141 * R99 or unknown. In case of SGSN release unknown
142 * we assume the value R98 and proceed.
143 */
144 if(PS_SGSN_99_ONWARDS != temp_sgsnr_flag)
145 {
146 temp_sgsnr_flag = PS_SGSN_98_OLDER;
147 }
148
149 /*Store the flag in context*/
150 gmm_data->sync.sig_cell_info.sgsnr_flag = temp_sgsnr_flag; /* TCS 4.0 */
151 #endif
152
153 gmm_data->sync.grr_cell_info = gmmrr_cell_ind->cell_info;
154 PFREE (gmmrr_cell_ind);
155
156 GMM_TRACE_GMM_DATA(GMM_DEBUG_PRINT_MASK_CID);
157
158 gmm_data->sync.mm_cell_info.gprs_indicator=MMGMM_GPRS_SUPP_YES;
159 gmm_data->sync.sig_cell_info.gmmrr_cell_ind_received = TRUE;
160
161 switch( GET_STATE( SYNC ) )
162 {
163
164 case SYNC_IDLE:
165 /*
166 *
167 */
168 if ( sync_is_cid_equal () )
169 {
170 /*
171 * CELL IND in response to RESUME REQ
172 */
173 sync_send_cell_info();
174 }
175 else
176 {
177 /*
178 * Cell Info does not match, synchronize with ACTIVATE IND
179 */
180 SET_STATE ( SYNC, SYNC_WAIT_FOR_GSM );
181 /*
182 * Timer Supervision
183 */
184 TRACE_EVENT ( "Info: START: TSYNC" );
185 vsi_t_start ( GMM_handle , sync_TSYNC, TSYNC );
186 }
187 break;
188
189 case SYNC_WAIT_FOR_GPRS:
190 /*
191 * Stop Timer ACTIVATE SYNC
192 */
193 TRACE_EVENT ( "Info: STOP: TSYNC" );
194 vsi_t_stop ( GMM_handle, sync_TSYNC);
195
196 if ( sync_is_cid_equal() )
197 {
198 /*
199 * As expected
200 */
201 SET_STATE ( SYNC, SYNC_IDLE );
202 sync_send_cell_info();
203 }
204 else
205 {
206 /*
207 * Cell Info does not match, wait for ACTIVATE IND
208 */
209 SET_STATE ( SYNC, SYNC_WAIT_FOR_GSM );
210 /*
211 * Timer Supervision
212 */
213 TRACE_EVENT ( "Info: START: TSYNC" );
214 vsi_t_start ( GMM_handle , sync_TSYNC, TSYNC );
215 }
216 break;
217 case SYNC_WAIT_FOR_GSM:
218 /*
219 * CELL IND again? Should not happen; timer runs already...
220 */
221 TRACE_ERROR (" CELL_IND repeatedly received ");
222 break;
223
224 default:
225 TRACE_ERROR ("GMMRR_CELL_IND wrong SYNC state");
226 break;
227 }
228 GMM_RETURN;
229 } /* sync_gmmrr_cell_ind */
230
231 /*
232 +------------------------------------------------------------------------------
233 | Function : sync_mmgmm_activate_ind
234 +------------------------------------------------------------------------------
235 | Description : Handles the primitive MMGMM_ACTIVATE_IND
236 |
237 | Parameters : *mmgmm_activate_ind - Ptr to primitive payload
238 |
239 +------------------------------------------------------------------------------
240 */
241 GLOBAL void sync_mmgmm_activate_ind (T_MMGMM_ACTIVATE_IND *mmgmm_activate_ind)
242 {
243 GMM_TRACE_FUNCTION( "sync_mmgmm_activate_ind" );
244
245 #ifndef NTRACE
246 switch (mmgmm_activate_ind->gprs_indicator)
247 {
248 case MMGMM_GPRS_SUPP_NO:
249 TRACE_EVENT("IPar: NO GPRS Service!");
250 break;
251 case MMGMM_GPRS_SUPP_YES:
252 TRACE_EVENT("IPar: cell supports GPRS");
253 break;
254 default:
255 TRACE_ERROR("indicator is out of range");
256 break;
257 }
258
259 switch (mmgmm_activate_ind->status)
260 {
261 case MMGMM_LIMITED_SERVICE:
262
263 TRACE_EVENT("IPar: limited service");
264 break;
265 case MMGMM_FULL_SERVICE:
266 TRACE_EVENT("IPar: full service");
267 break;
268 case MMGMM_CELL_SELECTED:
269 TRACE_EVENT("IPar: cell changed");
270 break;
271 case MMGMM_WAIT_FOR_UPDATE:
272 TRACE_EVENT("IPar: LUP REQ from MM");
273 break;
274 default:
275 TRACE_ERROR("unknown MM status");
276 }
277 #endif
278
279 gmm_data->sync.mm_cell_info.cid = mmgmm_activate_ind->cid;
280 gmm_data->sync.mm_cell_info.gprs_indicator = mmgmm_activate_ind->gprs_indicator;
281 gmm_data->sync.mm_cell_info.lac = mmgmm_activate_ind->lac;
282 gmm_data->sync.mm_cell_info.plmn = mmgmm_activate_ind->plmn;
283 gmm_data->sync.mm_cell_info.status = mmgmm_activate_ind->status;
284 gmm_data->sync.sig_cell_info.mm_status = gmm_data->sync.mm_cell_info.status;
285 gmm_data->sync.mm_cell_info.t3212_val = mmgmm_activate_ind->t3212_val;
286 PFREE (mmgmm_activate_ind);
287
288 GMM_TRACE_GMM_DATA(GMM_DEBUG_PRINT_MASK_CID);
289
290 switch( GET_STATE( SYNC ) )
291 {
292 case SYNC_IDLE:
293
294 if (sync_is_cid_equal())
295 {
296 /*
297 * signal cell info
298 */
299 sync_send_cell_info();
300 }
301 else
302 {
303 /*
304 * synchronize with CELL IND
305 */
306 SET_STATE ( SYNC, SYNC_WAIT_FOR_GPRS );
307 /*
308 * Timer Supervision
309 */
310 TRACE_EVENT ( "Info: START: TSYNC" );
311 vsi_t_start ( GMM_handle , sync_TSYNC, TSYNC );
312 }
313 break;
314
315 case SYNC_WAIT_FOR_GSM:
316 /*
317 * Stop Timer CELL SYNC
318 */
319 TRACE_EVENT ( "Info: STOP: TSYNC" );
320 vsi_t_stop ( GMM_handle, sync_TSYNC);
321
322 if (sync_is_cid_equal())
323 {
324 /*
325 * As expected
326 */
327 SET_STATE ( SYNC, SYNC_IDLE );
328 sync_send_cell_info();
329 }
330 else
331 {
332 /*
333 * Cell Info does not match, wait for CELL IND
334 */
335 SET_STATE ( SYNC, SYNC_WAIT_FOR_GPRS );
336 /*
337 * Timer Supervision
338 */
339 TRACE_EVENT ( "Info: START: TSYNC" );
340 vsi_t_start ( GMM_handle , sync_TSYNC, TSYNC );
341 }
342 break;
343
344 case SYNC_WAIT_FOR_GPRS:
345 /*
346 * Again, should not happen! Timer runs already..
347 */
348 TRACE_ERROR (" ACTIVATE_IND repeatedly received ");
349 break;
350
351 default:
352 TRACE_ERROR ("MMGMM_ACTIVATE_IND wrong SYNC state");
353 break;
354 }
355 GMM_RETURN;
356 } /* sync_mmgmm_activate_ind */
357
358 /*
359 +------------------------------------------------------------------------------
360 | Function : sync_mmgmm_nreg_ind
361 +------------------------------------------------------------------------------
362 | Description : Handles the primitive MMGMM_NREG_IND
363 |
364 | Parameters : *mmgmm_nreg_ind - Ptr to primitive payload
365 |
366 +------------------------------------------------------------------------------
367 */
368 GLOBAL void sync_mmgmm_nreg_ind (T_MMGMM_NREG_IND *mmgmm_nreg_ind)
369 {
370 GMM_TRACE_FUNCTION( "sync_mmgmm_nreg_ind" );
371
372 switch( GET_STATE( SYNC ) )
373 {
374
375 case SYNC_WAIT_FOR_GSM:
376 /*
377 * NREG IND received while waiting for ACTIVATE IND
378 */
379 TRACE_EVENT ( "Info: STOP: TSYNC" );
380 vsi_t_stop ( GMM_handle , sync_TSYNC);
381 /*
382 * handle as if ACTIVATE IND received
383 */
384 SET_STATE ( SYNC, SYNC_IDLE );
385 /*
386 *
387 */
388 switch (mmgmm_nreg_ind->service) /* TCS 2.1 */
389 {
390 case NREG_NO_SERVICE: /* TCS 2.1 */
391 gmm_data->sync.mm_cell_info.lac = GMMRR_LA_INVALID;
392 gmm_data->sync.mm_cell_info.status = MMGMM_LIMITED_SERVICE;
393 gmm_data->sync.mm_cell_info.gprs_indicator=MMGMM_GPRS_SUPP_NO;
394 break;
395 case NREG_LIMITED_SERVICE:
396 gmm_data->sync.mm_cell_info.status = MMGMM_LIMITED_SERVICE;
397 /* TCS 2.1 */
398 /* TCS 2.1 */
399 break;
400 default:
401 break;
402 }
403 /*
404 * SIGNAL CELL INFO
405 */
406 sync_send_cell_info();
407 /*
408 * SIGNAL NREG IND
409 */
410 sig_sync_kern_mmgmm_nreg_ind(mmgmm_nreg_ind);
411 break;
412
413 case SYNC_IDLE:
414 /*
415 * safe information: no or limited service
416 */
417 switch (mmgmm_nreg_ind->service) /* TCS 2.1 */
418 {
419 case NREG_NO_SERVICE: /* TCS 2.1 */
420 gmm_data->sync.mm_cell_info.lac = GMMRR_LA_INVALID;
421 gmm_data->sync.mm_cell_info.status = MMGMM_LIMITED_SERVICE;
422 gmm_data->sync.mm_cell_info.gprs_indicator=MMGMM_GPRS_SUPP_NO;
423 break;
424 case NREG_LIMITED_SERVICE:
425 gmm_data->sync.mm_cell_info.status = MMGMM_LIMITED_SERVICE;
426 /* TCS 2.1 */
427 /* TCS 2.1 */
428 break;
429 default:
430 break;
431 }
432 /*
433 * synchronize
434 */
435 if (sync_is_cid_equal())
436 {
437 /*
438 * signal cell info
439 */
440 sync_send_cell_info();
441 }
442 else
443 {
444 /*
445 * synchronize with CELL IND
446 */
447 SET_STATE ( SYNC, SYNC_WAIT_FOR_GPRS );
448 /*
449 * Timer Supervision
450 */
451 TRACE_EVENT ( "Info: START: TSYNC" );
452 vsi_t_start ( GMM_handle , sync_TSYNC, TSYNC );
453 }
454 /*
455 * handle nreg ind
456 */
457 sig_sync_kern_mmgmm_nreg_ind(mmgmm_nreg_ind);
458
459 break;
460
461 case SYNC_WAIT_FOR_GPRS:
462
463 TRACE_EVENT ( "Info: STOP: TSYNC" );
464 vsi_t_stop ( GMM_handle , sync_TSYNC);
465
466 SET_STATE ( SYNC, SYNC_IDLE);
467
468 switch (mmgmm_nreg_ind->service) /* TCS 2.1 */
469 {
470 case NREG_NO_SERVICE: /* TCS 2.1 */
471 gmm_data->sync.mm_cell_info.lac = GMMRR_LA_INVALID;
472 gmm_data->sync.mm_cell_info.status = MMGMM_LIMITED_SERVICE;
473 gmm_data->sync.mm_cell_info.gprs_indicator=MMGMM_GPRS_SUPP_NO;
474 break;
475 case NREG_LIMITED_SERVICE:
476 gmm_data->sync.mm_cell_info.status = MMGMM_LIMITED_SERVICE;
477 /* TCS 2.1 */
478 /* TCS 2.1 */
479 break;
480 default:
481 break;
482 }
483
484 sig_sync_kern_mmgmm_nreg_ind(mmgmm_nreg_ind);
485 break;
486 default:
487 TRACE_ERROR ("MMGMM_NREG_IND unexpected");
488 PFREE(mmgmm_nreg_ind);
489 break;
490 }
491 GMM_RETURN;
492 } /* sync_mmgmm_nreg_ind */
493 /*
494 +------------------------------------------------------------------------------
495 | Function : sync_mmgmm_reg_rej
496 +------------------------------------------------------------------------------
497 | Description : Handles the primitive MMGMM_REG_REJ
498 |
499 | Parameters : *mmgmm_nreg_ind - Ptr to primitive payload
500 |
501 +------------------------------------------------------------------------------
502 */
503 GLOBAL void sync_mmgmm_reg_rej (T_MMGMM_REG_REJ *mmgmm_reg_rej)
504 {
505 GMM_TRACE_FUNCTION( "sync_mmgmm_reg_rej" );
506
507 switch( GET_STATE( SYNC ) )
508 {
509 case SYNC_IDLE:
510 case SYNC_WAIT_FOR_GSM:
511 case SYNC_WAIT_FOR_GPRS:
512 gmm_data->sync.mm_cell_info.status = MMGMM_LIMITED_SERVICE;
513 switch (mmgmm_reg_rej->service) /* TCS 2.1 */
514 {
515 case NREG_NO_SERVICE: /* TCS 2.1 */
516 gmm_data->sync.mm_cell_info.lac = GMMRR_LA_INVALID;
517 break;
518 case NREG_LIMITED_SERVICE:
519 /* TCS 2.1 */
520 break;
521 default:
522 break;
523 }
524 sig_sync_kern_mmgmm_reg_rej(mmgmm_reg_rej);
525 break;
526 default:
527 TRACE_ERROR ("MMGMM_REG_REJ unexpected");
528 break;
529 }
530 GMM_RETURN;
531 } /* sync_mmgmm_reg_rej */
532
533 /*
534 +------------------------------------------------------------------------------
535 | Function : sync_mmgmm_reg_cnf
536 +------------------------------------------------------------------------------
537 | Description : Handles the primitive MMGMM_REG_CNF
538 |
539 | Parameters : *mmgmm_reg_cnf - Ptr to primitive payload
540 |
541 +------------------------------------------------------------------------------
542 */
543 GLOBAL void sync_mmgmm_reg_cnf (T_MMGMM_REG_CNF *mmgmm_reg_cnf)
544 {
545 GMM_TRACE_FUNCTION( "sync_mmgmm_reg_cnf" );
546
547 switch( GET_STATE( SYNC ) )
548 {
549
550 case SYNC_IDLE:
551 case SYNC_WAIT_FOR_GSM:
552 case SYNC_WAIT_FOR_GPRS:
553
554 /* Changes for Boot Time Speedup. GMM will get MMGMM_REG_CNF with
555 * bootup_cause = PWR_SCAN_START.
556 * No need to process this as it is response to dummy request.
557 * GMM need to send GMMREG_ATTACH_CNF indicating PWR_SCAN_START
558 */
559 if (mmgmm_reg_cnf->bootup_cause EQ PWR_SCAN_START)
560 {
561 PALLOC ( gmmreg_attach_cnf, GMMREG_ATTACH_CNF );
562 gmmreg_attach_cnf->attach_type = VAL_ATTACH_TYPE___DEF;
563 gmmreg_attach_cnf->plmn = mmgmm_reg_cnf->plmn;
564 gmmreg_attach_cnf->search_running = SEARCH_RUNNING;
565 gmmreg_attach_cnf->lac = mmgmm_reg_cnf->lac;
566 gmmreg_attach_cnf->rac = gmm_data->kern.sig_cell_info.env.rai.rac;
567 gmmreg_attach_cnf->cid = mmgmm_reg_cnf->cid; // #HM#
568 gmmreg_attach_cnf->gprs_indicator = gmm_data->kern.sig_cell_info.gmm_status;
569 gmmreg_attach_cnf->bootup_cause = PWR_SCAN_START;
570 #ifdef GMM_TCS4
571 gmmreg_attach_cnf->rt = gmm_data->kern.sig_cell_info.rt; // TCS 4.0
572 #endif
573 PSEND ( hCommMMI, gmmreg_attach_cnf );
574 return;
575 }
576 gmm_data->sync.mm_cell_info.status = MMGMM_FULL_SERVICE;
577 sig_sync_kern_mmgmm_reg_cnf(mmgmm_reg_cnf);
578 break;
579
580 default:
581 TRACE_ERROR ("MMGMM_REG_CNF unexpected");
582 break;
583 }
584 GMM_RETURN;
585 } /* sync_mmgmm_nreg_ind */
586