comparison g23m-gsm/rr/rr_tim.c @ 0:75a11d740a02

initial import of gsm-fw from freecalypso-sw rev 1033:5ab737ac3ad7
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 09 Jun 2016 00:02:41 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:75a11d740a02
1 /*
2 +-----------------------------------------------------------------------------
3 | Project :
4 | Modul :
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 timer handling functions
18 | for the component DL of the mobile station
19 +-----------------------------------------------------------------------------
20 */
21
22 #ifndef RR_TIM_C
23 #define RR_TIM_C
24
25 #include "config.h"
26 #include "fixedconf.h"
27 #include "condat-features.h"
28
29 #define ENTITY_RR
30
31 /*==== INCLUDES ===================================================*/
32
33 #include <string.h>
34 #include <stdlib.h>
35 #include <stddef.h> /* offsetof */
36 #include <stdio.h> /* sprintf */
37 #include "typedefs.h"
38 #include "pcm.h"
39 #include "pconst.cdg"
40 #include "mconst.cdg"
41 #include "message.h"
42 #include "ccdapi.h"
43 #include "vsi.h"
44 #include "custom.h"
45 #include "gsm.h"
46 #include "prim.h"
47 #include "cnf_rr.h"
48 #include "tok.h"
49 #include "rr.h"
50 #ifdef TI_PS_FF_AT_P_CMD_CTREG
51 #include "cl_shrd.h"
52 #endif /* TI_PS_FF_AT_P_CMD_CTREG */
53
54 /*==== EXPORT =====================================================*/
55 /*==== PRIVAT =====================================================*/
56 #if !defined(ELEMENTS)
57 #define ELEMENTS(array) (sizeof(array)/sizeof(array[0]))
58 #endif /* !ELEMENTS */
59
60 /*==== VARIABLES ==================================================*/
61 EXTERN UBYTE test_house;
62 #ifdef TI_PS_FF_AT_P_CMD_CTREG
63 EXTERN T_TIME cast2T_Time(UBYTE tab_val);
64 #else
65 EXTERN T_TIME lim_service_mode_time[25];
66 #endif /* TI_PS_FF_AT_P_CMD_CTREG */
67 /*
68 * In the old frame variant most of the timer handling is done
69 * in RR. RR has a timer pool and holds the dependency between
70 * logical timer and timer handle.
71 *
72 * With the new frame variant this is simplified. RR uses a constant
73 * for the timer and gets back the this constant after timeout.
74 *
75 * This is the reason why most of the functions are only needed for
76 * the old frame variant.
77 */
78
79 /*==== FUNCTIONS ==================================================*/
80
81 #if defined(TIMER_TRACE)
82 static void trace_timer (USHORT index, long value)
83 {
84 GET_INSTANCE_DATA;
85 /* Implements Measure#32: Row */
86 static T_S2I_STRING const tim_names[] =
87 {
88 S2I_STRING("T3110"),
89 S2I_STRING("T3122"),
90 S2I_STRING("T3126"),
91 S2I_STRING("T_RESELECT"),
92 S2I_STRING("TREG"),
93 S2I_STRING("TABORT"),
94 S2I_STRING("T_NO_RESELECT"),
95 S2I_STRING("TIM_EXT_MEAS"),
96 #if defined FF_EOTD
97 S2I_STRING("TAPDU"),
98 #endif /* FF_EOTD */
99 S2I_STRING("TNNN"),
100 S2I_STRING("TCSVALID"),
101 S2I_STRING("T_DEDICATED_MODE"),
102 S2I_STRING("T_PLMN_SEARCH"),
103 S2I_STRING("T_FAST_CS"),
104 S2I_STRING("T_NORMAL_CS")
105 };
106 switch(value)
107 {
108 /* Implements Measure#32: Row 431, 432, 433 and 435 */
109 default:/* >0: start */
110 TRACE_TIMER_P2 ("T-Start:%s=%lu", S2I_STRING(tim_names[index]), value);
111 break;
112 case 0:/* EQ 0: stop */
113 TRACE_TIMER_P1 ("T-Stop:%s", S2I_STRING(tim_names[index]));
114 break;
115 case -1:/* -1: expire */
116 TRACE_TIMER_P1 ("T-Expired:%s ", S2I_STRING(tim_names[index]));
117 break;
118 case -2:/* -2: check */
119 if(rr_data->t_running[index])
120 {
121 TRACE_TIMER_P1 ("T-Check:%s active", S2I_STRING(tim_names[index]));
122 }
123 else
124 {
125 TRACE_TIMER_P1 ("T-Check:%s inactive", S2I_STRING(tim_names[index]));
126 }
127 break;
128 }
129 }
130 #else
131 #define trace_timer(index,value)
132 #endif /* TIMER_TRACE */
133
134 /*
135 +--------------------------------------------------------------------+
136 | PROJECT : GSM-PS (6147) MODULE : RR_TIM |
137 | STATE : code ROUTINE : tim_t3110 |
138 +--------------------------------------------------------------------+
139
140 PURPOSE : Timeout of timer T3110. Timer is started after reception
141 of channel release message and controls layer 2 disconnection.
142 It starts the configuration of idle mode, if layer 2 has
143 not signalled in time the disconnection of the layer 2 link.
144
145 */
146
147 GLOBAL void tim_t3110 (void)
148 {
149 GET_INSTANCE_DATA;
150 TRACE_FUNCTION ("tim_t3110()");
151
152 if (GET_STATE (STATE_DAT) EQ DAT_CHAN_REL)
153 {
154 /*
155 * Send STOP_DEDICATED_REQUEST to L1 and wait for confirmation
156 */
157 att_stop_dedicated();
158 }
159
160 }
161
162 /*
163 +--------------------------------------------------------------------+
164 | PROJECT : GSM-PS (6147) MODULE : RR_TIM |
165 | STATE : code ROUTINE : tim_t3122 |
166 +--------------------------------------------------------------------+
167
168 PURPOSE : Timeout of timer T3122. Started after reception of an
169 immediate assignment reject message. MM does not start
170 any new establishment during the timer is running.
171 After timeout MM is informed. New attempts from MM can
172 be started.
173
174 */
175
176 GLOBAL void tim_t3122 (void)
177 {
178 GET_INSTANCE_DATA;
179 PALLOC (sync, RR_SYNC_IND);
180
181 TRACE_FUNCTION ("tim_t3122()");
182
183 switch (GET_STATE (STATE_DAT))
184 {
185 case DAT_NULL:
186 case DAT_CELL_RESELECT:
187 case DAT_IDLE:
188 case DAT_IMM_ASS:
189 case DAT_IMM_ASS_1:
190 /*
191 * send the indication to MM that T3122 has
192 * timed-out.
193 */
194 sync->ciph = NOT_PRESENT_8BIT;
195 sync->chm.ch_mode = NOT_PRESENT_8BIT;
196 sync->synccs = SYNCCS_T3122_TIM_OUT;
197 memset(&sync->mm_info, 0, sizeof(T_mm_info));
198 sync->mm_info.valid = FALSE;
199 memset(&sync->bcch_info, 0, sizeof(T_bcch_info));
200 sync->bcch_info.v_bcch = FALSE;
201
202 PSENDX (MM, sync);
203 srv_use_stored_prim ();
204 break;
205
206 default:
207 PFREE (sync);
208 break;
209 }
210 }
211
212 /*
213 +--------------------------------------------------------------------+
214 | PROJECT : GSM-PS (6147) MODULE : RR_TIM |
215 | STATE : code ROUTINE : tim_t3126 |
216 +--------------------------------------------------------------------+
217
218 PURPOSE : Timeout of timer T3126. This timer is used for two cases.
219 1. It controls that all random bursts are send during a
220 certain time. If (why ever) layer 1 does not confirm
221 all outgoing random bursts, this timer prevents RR
222 from stucking. This functionality is not described in
223 GSM and is introduced for security reasons.
224 2. It controls the reception of an immediate assignment
225 message. This is the normal GSM functionality.
226
227 */
228
229 GLOBAL void tim_t3126 (void)
230 {
231 GET_INSTANCE_DATA;
232 TRACE_FUNCTION ("tim_t3126()");
233
234 if (GET_STATE (STATE_DAT) EQ DAT_IMM_ASS)
235 {
236 if (rr_data->ms_data.all_conf_received)
237 {
238 /*
239 * Normal GSM functionality. Control of the
240 * reception of immediate assignment messages.
241 */
242 TRACE_EVENT ("Immediate Assignment failed");
243
244 dat_send_release_ind ( RRCS_RND_ACC_FAIL );
245
246 /*
247 * Check if we have to do a cell reselection
248 * or if we can return directly to idle mode in the current
249 * cell
250 */
251 TRACE_EVENT("check rej_rec");
252 if (rr_data->imm_ass_rej_rec NEQ TRUE)
253 {
254 /*
255 * search for idle mode cell
256 * (exclude current serving cell, because
257 * the random access was unsuccessfull)
258 */
259 #ifdef GPRS
260 if(att_gprs_cell_has_pbcch())
261 {
262 /*XY: inform GRR, and don't wait for CR_RSP we will get a CR_REQ in this case */
263 att_rrgrr_cr_ind(CR_REQ_CANDIDATE);
264 rr_data->gprs_data.start_proc = START_PROC_NOTHING;
265 }
266 else
267 {
268 #endif
269
270 TRACE_EVENT_P1("rr_data->c_ncell_bcch: %x",rr_data->c_ncell_bcch);
271
272 /*There are three scenarios to be considered */
273 /*
274 * i - The first MPH_MEASUREMENT_IND has not yet arrived
275 * ii - The first MPH_MEASUREMENT_IND has arrived but not all
276 * the SIs have been received
277 * (These are managed below)
278 *
279 * iii - The first MPH_MEASUREMENT_IND has arrived and all the
280 * SIs have been received AND a reselection is pending
281 * This is managed in 'att_bcch_status_to_decoded()'
282 */
283
284 if(((rr_data->first_meas_received EQ TRUE) AND (rr_data->c_ncell_bcch EQ 0)) OR
285 /* Implements RR Clone findings #8 */
286 att_cell_barred_status_cr_no_cr (SC_INDEX)
287 OR
288 (rr_data->nc_data[SC_INDEX].c1 <= 0))
289 {
290 /*XY:n inform GRR, and wait for CR_RSP */
291 #ifdef GPRS
292 att_start_cell_reselection_gprs (CELL_RESELECTION_RACH);
293 #else
294 att_start_cell_reselection (CELL_RESELECTION_RACH);
295 #endif
296 }
297 else
298 {
299 /*
300 * continue camping on current SC until indication of ncell BCCH info
301 * after first measurement indication
302 */
303 rr_data->resel_pending = TRUE;
304 att_return_to_idle();
305 }
306 #ifdef GPRS
307 }
308 #endif
309 }
310 else
311 {
312 /*
313 * we have received an IMMEDIATE ASSIGNMENT REJECT
314 * (the random access procedure was successfull, meaning
315 * that an answer was received from the network, even
316 * if the answer was negative)
317 * In this case we go directly back to the current
318 * serving cell
319 */
320 #ifdef GPRS
321 if(att_gprs_cell_has_pbcch())
322 {
323 /*XY: inform GRR, and don't wait for CR_RSP */
324 att_rrgrr_cr_ind(CR_SUSPENDED_IDLE);
325 rr_data->gprs_data.start_proc = START_PROC_NOTHING;
326 }
327 #endif
328 att_return_to_idle();
329 }
330 }
331 else
332 {
333 /*
334 * Layer 1 has not confirmed all outgoing random bursts
335 * in time. Simulate that all confirmations have received
336 * and start second part of connection establishment
337 * with waiting for the immediate assignment.
338 */
339 TRACE_TIMER ("missing random acc cnf");
340
341 TIMERSTART (T3126, T3126_VALUE);
342 rr_data->ms_data.all_conf_received = TRUE;
343 }
344 }
345 }
346
347 /*
348 +--------------------------------------------------------------------+
349 | PROJECT : GSM-PS (6147) MODULE : RR_TIM |
350 | STATE : code ROUTINE : tim_treselect |
351 +--------------------------------------------------------------------+
352
353 PURPOSE : Timeout of timer T_RESELECT. The timer controls reception
354 of the whole BCCH during cell selection and cell reselection.
355
356 */
357
358 GLOBAL void tim_treselect (void)
359 {
360 GET_INSTANCE_DATA;
361 TRACE_FUNCTION ("tim_treselect()");
362
363 switch (GET_STATE (STATE_ATT))
364 {
365 case ATT_CS2:
366 #ifdef GPRS
367 if((rr_data->cr_data.cd.sys_info_read EQ SYS_INFO_EXCEPT_SI13) AND test_house)
368 {
369 if(rr_data->ms_data.rr_service EQ LIMITED_SERVICE)
370 {
371 /*
372 * We have found a 'potential' cell for limited service
373 */
374 rr_data->nc_data[CR_INDEX].si13_loc_ind = SI13_NOT_PRESENT;
375 SET_STATE(STATE_GPRS, GPRS_ACTIVATED);
376 att_check_bcch_carrier ();
377 return;
378 }
379 else
380 {
381 /*
382 * There is a problem with some R&S tests where SI13 is indicated
383 * in SI3/4 but there is no SI13 transmitted by the tester. RR continues
384 * to wait to for SI13 having successfully received all other SI's from L1
385 *
386 * The timeout of T_RESELECT would cause this cell to be ignored and
387 * RR would have instructed L1 to check the next BSIC.
388 * Thus, it can happen that after a failed scan of all subsequent frequencies,
389 * MM is indicated with "no cell available" i.e. we lose a GSM-only healthy cell
390 *
391 * Mark the current arfcn as being eligible for LIM service, which RR can camp
392 * onto on the next pass when looking for emergency cells.
393 */
394 if(dat_forb_lai_check (CR_INDEX))
395 {
396 att_store_plmn_in_found_list (&rr_data->nc_data[CR_INDEX].lai);
397 }
398 else
399 {
400 TRACE_EVENT ("Do not store Forbidden LAI PLMN in the found PLMN list");
401 }
402 cs_set_attributes (EMERGENCY_CELL, rr_data->nc_data[CR_INDEX].arfcn);
403 TRACE_EVENT_P1("Setting %x as EMERG", rr_data->nc_data[CR_INDEX].arfcn);
404 }
405 }
406 #endif
407
408 /*
409 * Sometimes SI 2Ter is indicated, but it is never sent
410 * With this patch the inconsistent BCCH is taken.
411 * Fix for defect OMAPS00069058: SI13 is indicated on EBCCH, but never
412 * received. The fix avoids ignoring this cell on TRESELECT timeout.
413 */
414 if ( (rr_data->cr_data.cd.sys_info_read EQ SYS_INFO_EXCEPT_2TER)
415 #ifdef GPRS
416 OR
417 (rr_data->cr_data.cd.sys_info_read EQ SYS_INFO_EXCEPT_SI13)
418 #endif
419 )
420 {
421 /*
422 * if at least the rest is available, check the
423 * BCCH carrier to camp on a cell.
424 */
425 #ifdef GPRS
426 if ( (rr_data->cr_data.cd.sys_info_read EQ SYS_INFO_EXCEPT_SI13) AND
427 (GET_STATE (STATE_GPRS) EQ GPRS_PIM_BCCH )
428 )
429 {
430 rr_data->nc_data[CR_INDEX].si13_loc_ind = SI13_NOT_PRESENT;
431 SET_STATE(STATE_GPRS, GPRS_ACTIVATED);
432 }
433 #endif
434 att_check_bcch_carrier ();
435 }
436 else
437 {
438 /*
439 * initialise the internal data for the next candidate,
440 * because the BCCH is not completely available.
441 */
442 srv_clear_list (&rr_data->cr_data.cd.ncell_list);
443 if (cs_sync_next ())
444 {
445 /*
446 * start FB/SB reading for the next channel.
447 */
448 SET_STATE (STATE_ATT, ATT_CS1);
449 #ifdef GPRS
450 if (GET_STATE (STATE_GPRS) EQ GPRS_PIM_BCCH )
451 {
452 SET_STATE(STATE_GPRS, GPRS_ACTIVATED);
453 }
454 #endif
455 rr_data->old_serving_cell = NOT_PRESENT_8BIT;
456 }
457 }
458 break;
459
460 case ATT_CS3:
461
462 if (rr_data->cr_data.cd.sys_info_read EQ SYS_INFO_EXCEPT_2TER)
463 {
464 /*
465 * if all sys infos except SI 2Ter is available, check the
466 * BCCH carrier to camp on a cell.
467 * When GPRS is activate, ATT_STATE is changed from ATT_CS3 to
468 * ATT_IDLE following reception of rrgrr_cr_req from GRR. Hence
469 * it not approprite to check for ATT_STATE for cell reselection
470 * completion. A new flag has been introduced for this purpose.
471 * This is s temporary solution, untill CQ 24632 is submitted
472 * where the SI2TER functionality will be cleaned up.
473 */
474
475 rr_data->cr_treselect_exp = FALSE;
476
477 att_check_bcch_carrier ();
478
479 if(rr_data->cr_treselect_exp)
480 {
481 TRACE_EVENT("Cell Reselection Success");
482 /* cell reselection completed */
483 return;
484 }
485 }
486
487 TRACE_EVENT ("cell reselection failed");
488
489 /*
490 * reset the paging received flag.
491 */
492 rr_data->pag_rec = FALSE;
493 srv_clear_stored_prim (MPH_PAGING_IND);
494
495 /*
496 * Indicate failed reestablishment earlier
497 */
498 if (rr_data->sc_data.selection_type EQ BACK_FROM_DEDICATED_RLF)
499 dat_code_reestablishment_fail ();
500
501 /*
502 * start a cell selection after timeout.
503 */
504 rr_data->old_serving_cell = NOT_PRESENT_8BIT;
505
506 /*XY:n don't inform GRR , but call start_cs anyway */
507
508 /* Cell Selection Improvements-LLD section:4.1.3.9
509 * Cell reselection fails due to T_RESELECT timer expiry
510 * Start Fast search
511 */
512 #ifdef GPRS
513 att_start_cell_selection_gprs (RR_ORIGINATED,FAST_SEARCH_MODE);
514 #else
515 att_start_cell_selection (RR_ORIGINATED, CS_NOT_PARALLEL ,FAST_SEARCH_MODE);
516 #endif
517
518 break;
519
520 case ATT_IDLE:
521 case ATT_CON_EST:
522 /*
523 * Parallel scanning for a channel in idle mode has failed.
524 * Initialize the data for the next channel and start
525 * FB/SB reading for this channel.
526 */
527 #ifdef GPRS
528 if( rr_data->sc_data.selection_type EQ CELL_RESELECTION_ON_GPRS_ACT)
529 {
530 /* Cell Selection Improvements-LLD section:4.1.3.9
531 * GPRS activation on current cell fails due to T_RESELECT timer
532 * expiry
533 * Start Fast search
534 */
535 att_start_cell_selection_gprs(MM_ORIGINATED,FAST_SEARCH_MODE);
536 }
537 else
538 {
539 #endif
540 srv_clear_list (&rr_data->cr_data.cd.ncell_list);
541 cs_sync_next ();
542 #ifdef GPRS
543 }
544 #endif
545 break;
546 case ATT_CS_INIT:
547 /* Boot Time Performance Enhancement:
548 * RR has not received the normal RR_ACTIVATE_REQ yet
549 * Free the stored power_cnf and move back to ATT_NULL
550 */
551 if( srv_check_stored_prim(MPH_POWER_CNF))
552 {
553 srv_clear_stored_prim(MPH_POWER_CNF);
554 }
555 SET_STATE(STATE_CELL_SEL, CS_NULL);
556 SET_STATE(STATE_ATT, ATT_NULL);
557 break;
558 }
559 }
560
561 /*
562 +--------------------------------------------------------------------+
563 | PROJECT : GSM-PS (6147) MODULE : RR_TIM |
564 | STATE : code ROUTINE : tim_plmn_search_expiry |
565 +--------------------------------------------------------------------+
566
567 PURPOSE : This timer expires to signal end on Manual cell selection.
568
569 */
570 GLOBAL void tim_plmn_search_expiry (void)
571 {
572 GET_INSTANCE_DATA;
573 if(rr_data->ms_data.req_mm_service EQ FUNC_NET_SRCH_BY_MMI)
574 {
575 /*
576 * Mark all ARFCN's as Checked !
577 * After the next MPH_BSIC_CNF & MPH_UNITDATA_IND,
578 * cs_sync_next_bsic() will return FALSE.
579 */
580 UBYTE i;
581 for ( i=0; i < rr_data->cs_data.max_arfcn; i++ )
582 {
583 rr_data->cs_data.attributes[i] |= CS_CHECK_FLAG;
584 }
585 }
586 }
587
588 /*
589 +--------------------------------------------------------------------+
590 | PROJECT : GSM-PS (6147) MODULE : RR_TIM |
591 | STATE : code ROUTINE : tim_tfast_cs |
592 +--------------------------------------------------------------------+
593
594 PURPOSE : This timer expires to signal end on Fast Search. Currently
595 this function just traces the Black Listed channels
596 CSI-LLD section:4.1.3.4.1.9
597 */
598
599 GLOBAL void tim_tfast_cs(void)
600 {
601 TRACE_FUNCTION("tim_tfast_cs()");
602
603 srv_trace_black_list();
604 srv_trace_white_list();
605 }
606
607 /*
608 +--------------------------------------------------------------------+
609 | PROJECT : GSM-PS (6147) MODULE : RR_TIM |
610 | STATE : code ROUTINE : tim_tnormal_cs |
611 +--------------------------------------------------------------------+
612
613 PURPOSE : This timer expires to signal end on Normal search.Currently
614 this function just traces the Black Listed channels
615 CSI-LLD section:4.1.3.4.1.10
616 */
617
618 GLOBAL void tim_tnormal_cs(void)
619 {
620 TRACE_FUNCTION("tim_tnormal_cs()");
621
622 srv_trace_black_list();
623 srv_trace_white_list();
624 }
625
626 /*
627 +--------------------------------------------------------------------+
628 | PROJECT : GSM-PS (6147) MODULE : RR_TIM |
629 | STATE : code ROUTINE : att_reset_registration_timer |
630 +--------------------------------------------------------------------+
631
632 PURPOSE : This function stops the registration timer early on
633 request of MMI / Keypad driver. This function can be called
634 to avoid too long periods between search attempts to come
635 back to coverage.
636
637 */
638
639 GLOBAL void tim_reset_registration_timer (void)
640 {
641 GET_INSTANCE_DATA;
642 T_TIME status = 0;
643
644 TRACE_FUNCTION ("tim_reset_registration_timer()");
645
646 /*
647 * depending on the current RR service
648 */
649 switch (rr_data->ms_data.rr_service)
650 {
651 case NO_SERVICE:
652 case LIMITED_SERVICE:
653 if (rr_data->ms_data.reg_counter >= 12)
654 {
655 /*
656 * Only if RR has searched already more then 12 times,
657 * that means there is a long period between search attempts
658 * from some minutes.
659 *
660 * Get the remaining time of the timer.
661 */
662 TIMER_STATUS (rr_handle, TREG, &status);
663 if (status)
664 {
665 /*
666 * if the timer is just running, stop the timer,
667 * reset the attempt counter and simulate timeout
668 * by starting the timer again for one second.
669 */
670 TIMERSTOP (TREG);
671 rr_data->ms_data.reg_counter = 0;
672 TIMERSTART (TREG, ONE_SEC);
673 }
674 }
675 break;
676 }
677 }
678
679 /*
680 +--------------------------------------------------------------------+
681 | PROJECT : GSM-PS (6147) MODULE : RR_TIM |
682 | STATE : code ROUTINE : tim_treg |
683 +--------------------------------------------------------------------+
684
685 PURPOSE : Timeout of timer TREG. Used by RR to recover from
686 No service to limited / full service or
687 limited service to full service or
688 full service (non-HPLMN) to full service (HPLMN)
689
690 */
691
692 GLOBAL void tim_treg (void)
693 {
694 GET_INSTANCE_DATA;
695 U8 search_mode = 0;
696 #ifdef GPRS
697 UBYTE state;
698 #endif /* GPRS */
699 #ifdef TI_PS_FF_AT_P_CMD_CTREG
700 BOOL ret;
701 UBYTE tab_val;
702 #endif /* TI_PS_FF_AT_P_CMD_CTREG */
703 TRACE_FUNCTION ("tim_treg()");
704
705 /*
706 * clear old cell identification to
707 * signal with RR_ACTIVATE_IND to MM to force
708 * location updatings.
709 */
710 att_reset_old_lai_rac();
711
712 /*
713 * due to : "Network not recovered after a manual registration failure"
714 * do nothing if measurement is running (RR is already in state ATT_CS1)
715 */
716 switch (GET_STATE (STATE_ATT))
717 {
718 case ATT_CS1:
719 case ATT_CS2:
720 break;
721
722 case ATT_CS3:
723 case ATT_DEDICATED:
724 case ATT_CON_EST:
725 /*
726 * handle the expiry event later after state change (by an
727 * additional expiry of TREG)
728 */
729 rr_data->treg_pending = TRUE;
730 break;
731 case ATT_IDLE:
732 #ifdef GPRS
733 state = GET_STATE(STATE_GPRS);
734 switch(state)
735 {
736 case GPRS_PTM_BCCH:
737 case GPRS_PAM_BCCH:
738 case GPRS_PAM_PBCCH:
739 case GPRS_PTM_PBCCH:
740 rr_data->treg_pending = TRUE;
741 break;
742 default:
743 if(GET_STATE(STATE_CELL_SEL) EQ CS_CCO)
744 rr_data->treg_pending = TRUE;
745 break;
746 }
747 if(rr_data->treg_pending)
748 {
749 att_start_registration_timer();
750 break;
751 }
752 #endif
753 /*lint -fallthrough*/
754 default:
755
756 /* Obtain the new search mode
757 * CSI-LLD : 4.1.3.4.1.5
758 */
759 search_mode = cs_get_new_search_mode();
760
761 switch (rr_data->ms_data.rr_service)
762 {
763 case NO_SERVICE:
764 /*
765 * actual there is no service. Depending on the
766 * last request from MM a limited service search
767 * or full service search is started.
768 */
769 /* XY:n inform GRR, and wait for CR_RSP */
770 #ifdef GPRS
771 att_start_cell_selection_gprs(RR_ORIGINATED,search_mode);
772 #else
773 att_start_cell_selection(RR_ORIGINATED, CS_NOT_PARALLEL,search_mode);
774 #endif
775 break;
776
777 case LIMITED_SERVICE:
778 /*
779 * actual there is limited service. Depending on the
780 * frequency area a limited service search or full service
781 * search is started.
782 */
783
784 /* Both American and European carriers are detected in
785 * this area. Perform Non-Parallel search only when the
786 * time gap between search attempts exceeds 2min
787 * CSI-LLD 4.3
788 */
789 if(rr_data->ms_data.reg_counter)
790 {
791 #ifdef TI_PS_FF_AT_P_CMD_CTREG
792 ret = cl_shrd_get_treg(RR_MOD_LIMSERVICE_TIME,
793 (UBYTE)(rr_data->ms_data.reg_counter - 1),
794 &tab_val);
795 if (!ret)
796 {
797 /* Use default on failure */
798 tab_val = lim_service_mode_time [rr_data->ms_data.reg_counter-1];
799 }
800 rr_data->ms_data.reg_time_gap += cast2T_Time(tab_val);
801 #else
802 /* Add the time gap between search attempts */
803 rr_data->ms_data.reg_time_gap +=
804 lim_service_mode_time[rr_data->ms_data.reg_counter-1];
805 #endif /* TI_PS_FF_AT_P_CMD_CTREG */
806 TRACE_EVENT_P2("[%d]reg_counter, [%d]reg_time_gap",
807 rr_data->ms_data.reg_counter,
808 rr_data->ms_data.reg_time_gap);
809 }
810
811 if((rr_data->ms_data.reg_counter < 20) AND
812 (rr_data->ms_data.reg_time_gap < rr_data->dyn_config.lim_ser_nps_delay))
813 {
814 /* Perform parallel search if delay >= 2min. This is to allow time
815 * for emergency calls
816 */
817 att_start_cell_selection(RR_ORIGINATED, CS_PARALLEL,search_mode);
818 }
819 else
820 {
821 rr_data->ms_data.reg_time_gap = 0;
822
823 /* Perform Non-Parallel search every >= 2min */
824 #ifdef GPRS
825 att_start_cell_selection_gprs(RR_ORIGINATED,search_mode);
826 #else
827 att_start_cell_selection(RR_ORIGINATED, CS_NOT_PARALLEL,search_mode);
828 #endif
829 }
830 break;
831
832 case FULL_SERVICE:
833 /*
834 * actual there is full service. Nothing to do here.
835 */
836 break;
837 }
838 break;
839 }
840 }
841
842 /*
843 +--------------------------------------------------------------------+
844 | PROJECT : GSM-PS (6147) MODULE : RR_TIM |
845 | STATE : code ROUTINE : tim_tnnn |
846 +--------------------------------------------------------------------+
847
848 PURPOSE : Timeout of timer TNNN
849
850 */
851 GLOBAL void tim_tnnn (void)
852 {
853 GET_INSTANCE_DATA;
854 int index;
855 BOOL tnnn_active = FALSE;
856
857 for (index = 0; index < (int)ELEMENTS(rr_data->nc_data); index++)
858 {
859 if (rr_data->nc_data[index].tnnn)
860 {
861 rr_data->nc_data[index].tnnn--; /* decrement all active timer counts */
862 if (rr_data->nc_data[index].tnnn)
863 tnnn_active = TRUE; /* at least one timer count active */
864 else
865 {
866 /* Implements Measure#32: Row 442 */
867 switch(index)
868 {
869 case CR_INDEX:
870 TRACE_TIMER_P1 ("T-Expiry:TNNN[CR%d]", rr_data->nc_data[index].arfcn);
871 break;
872 case SC_INDEX:
873 TRACE_TIMER_P1 ("T-Expiry:TNNN[SC%d]", rr_data->nc_data[index].arfcn);
874 break;
875 default:
876 TRACE_TIMER_P1 ("T-Expiry:TNNN[%d]", rr_data->nc_data[index].arfcn);
877 break;
878 }
879 }
880 }
881 }
882
883 if (!tnnn_active)
884 TIMERSTOP (TNNN); /* no timer count active -> stop physical timer */
885 }
886 /*
887 +--------------------------------------------------------------------+
888 | PROJECT : GSM-PS (6147) MODULE : RR_TIM |
889 | STATE : code ROUTINE : tim_tabort |
890 +--------------------------------------------------------------------+
891
892 PURPOSE : Timeout of timer TABORT
893
894 */
895 GLOBAL void tim_tabort (void)
896 {
897 GET_INSTANCE_DATA;
898 TRACE_EVENT("tim_tabort TIMEOUT");
899
900 /* Sometimes SI 2Ter is indicated but it is never sent.
901 * Wait till expiry of T_RESELECT Timer, to give more time to read SI 2Ter.
902 * Do not send RR_ABORT_IND in this special case,
903 * as this will cause MMI to show "No Network"
904 */
905 if( (rr_data->cr_data.cd.sys_info_read EQ SYS_INFO_EXCEPT_2TER) AND
906 ((GET_STATE(STATE_ATT) EQ ATT_CS2) OR (GET_STATE(STATE_ATT) EQ ATT_CS3)) )
907 {
908 TRACE_EVENT("SI2 Ter missing - wait for T_RESELECT expiry");
909 TIMERSTART (TABORT, TABORT_VALUE);
910 return;
911 }
912
913 /*If the MS is carrying out a search for a list of PLMNs, this may take */
914 /*longer than 10s and the MMI is not displaying the PLMN name */
915 /*Boot Time:If MM has initiated a power scan for quick registration
916 *do not send RR_ABORT_IND here.
917 */
918 if((rr_data->ms_data.req_mm_service NEQ FUNC_NET_SRCH_BY_MMI) AND
919 (rr_data->ms_data.req_mm_service NEQ FUNC_ST_PWR_SCAN))
920 {
921 att_code_net_lost();
922 #ifdef FF_PS_RSSI
923 RX_SetValue ( 0, RX_QUAL_UNAVAILABLE, RX_ACCE_UNAVAILABLE);
924 #else
925 RX_SetValue (0);
926 #endif
927 }
928 }
929
930 /*
931 +--------------------------------------------------------------------+
932 | PROJECT : GSM-PS MODULE : RR_TIM |
933 | STATE : code ROUTINE : check_tnnn |
934 +--------------------------------------------------------------------+
935
936 PURPOSE : Starts timer TABORT
937
938 */
939 void tstart_tabort( USHORT val )
940 {
941 GET_INSTANCE_DATA;
942 if( rr_data->net_lost )
943 {
944 if(!IS_TIMER_ACTIVE(TABORT))
945 {
946 TIMERSTART (TABORT, val);
947 }
948 }
949 }
950
951 /*
952 +--------------------------------------------------------------------+
953 | PROJECT : GSM-PS (6147) MODULE : RR_TIM |
954 | STATE : code ROUTINE : check_tnnn |
955 +--------------------------------------------------------------------+
956
957 PURPOSE : Checks to see if timer TNNN is running or not
958
959 */
960 static int check_tnnn (void)
961 {
962 GET_INSTANCE_DATA;
963 int nc;
964 int tnnn_active = FALSE;
965
966 /* check all timer counter for active state */
967 for (nc = 0; nc < (int)ELEMENTS(rr_data->nc_data); nc++)
968 {
969 if (rr_data->nc_data[nc].tnnn)
970 {
971 tnnn_active = TRUE;
972 break;
973 }
974 }
975 return tnnn_active;
976 }
977
978 /*
979 +--------------------------------------------------------------------+
980 | PROJECT : GSM-PS (6147) MODULE : RR_TIM |
981 | STATE : code ROUTINE : set_tnnn |
982 +--------------------------------------------------------------------+
983
984 PURPOSE : Sets timer TNNN
985
986 */
987 GLOBAL void set_tnnn (int index, USHORT value)
988 {
989 GET_INSTANCE_DATA;
990 /* Implements Measure#32: Row 443 */
991 switch (index)
992 {
993 case CR_INDEX:
994 TRACE_TIMER_P2 ("T-Start:TNNN[CR%d]=%d", rr_data->nc_data[index].arfcn, value);
995 break;
996 case SC_INDEX:
997 TRACE_TIMER_P2 ("T-Start:TNNN[SC%d]=%d", rr_data->nc_data[index].arfcn, value);
998 break;
999 default:
1000 TRACE_TIMER_P2 ("T-Start:TNNN[%d]=%d", rr_data->nc_data[index].arfcn, value);
1001 break;
1002 }
1003
1004 if (!check_tnnn ())
1005 {/* up to now there are no timer counter active -> start physical timer */
1006 trace_timer (TNNN, value);
1007 rr_data->t_running[TNNN] = 1;
1008
1009 /*
1010 * start physical periodically timer.
1011 */
1012 TIMER_PSTART (rr_handle, TNNN, ONE_SEC, ONE_SEC);
1013 }
1014
1015 /* set the new timer counter */
1016 rr_data->nc_data[index].tnnn = value / ONE_SEC;
1017 }
1018
1019 /*
1020 +--------------------------------------------------------------------+
1021 | PROJECT : GSM-PS (6147) MODULE : RR_TIM |
1022 | STATE : code ROUTINE : reset_tnnn |
1023 +--------------------------------------------------------------------+
1024
1025 PURPOSE : Resets timer TNNN
1026
1027 */
1028 GLOBAL void reset_tnnn (int index)
1029 {
1030 GET_INSTANCE_DATA;
1031 if (rr_data->nc_data[index].tnnn)
1032 {
1033 /* Implements Measure#32: Row 444 */
1034 switch (index)
1035 {
1036 case CR_INDEX:
1037 TRACE_TIMER_P1 ("T-Stop:TNNN[CR%d]", rr_data->nc_data[index].arfcn);
1038 break;
1039 case SC_INDEX:
1040 TRACE_TIMER_P1 ("T-Stop:TNNN[SC%d]", rr_data->nc_data[index].arfcn);
1041 break;
1042 default:
1043 TRACE_TIMER_P1 ("T-Stop:TNNN[%d]", rr_data->nc_data[index].arfcn);
1044 break;
1045 }
1046
1047 /* reset the timer counter */
1048 rr_data->nc_data[index].tnnn = 0;
1049
1050 if (IS_TIMER_ACTIVE(TNNN) AND !check_tnnn ())
1051 TIMERSTOP (TNNN);
1052 }
1053 }
1054
1055 /*
1056 +--------------------------------------------------------------------+
1057 | PROJECT : GSM-PS (6147) MODULE : RR_TIM |
1058 | STATE : code ROUTINE : is_tnnn |
1059 +--------------------------------------------------------------------+
1060
1061 PURPOSE : Returns value of timer TNNN
1062
1063 */
1064 GLOBAL int is_tnnn (int index)
1065 {
1066 GET_INSTANCE_DATA;
1067 if (rr_data->nc_data[index].tnnn)
1068 {
1069 /* Implements Measure#32: Row 446 */
1070 switch (index)
1071 {
1072 case CR_INDEX:
1073 TRACE_TIMER_P2 ("T-Check:TNNN[CR%d]=%d", rr_data->nc_data[index].arfcn,
1074 rr_data->nc_data[index].tnnn*ONE_SEC);
1075 break;
1076 case SC_INDEX:
1077 TRACE_TIMER_P2 ("T-Check:TNNN[SC%d]=%d", rr_data->nc_data[index].arfcn,
1078 rr_data->nc_data[index].tnnn*ONE_SEC);
1079 break;
1080 default:
1081 TRACE_TIMER_P2 ("T-Check:TNNN[%d]=%d", rr_data->nc_data[index].arfcn,
1082 rr_data->nc_data[index].tnnn*ONE_SEC);
1083 break;
1084 }
1085 }
1086 else
1087 {
1088 /* Implements Measure#32: Row 445 */
1089 switch (index)
1090 {
1091 case CR_INDEX:
1092 TRACE_TIMER_P1 ("T-Check:TNNN[CR%d] inactive", rr_data->nc_data[index].arfcn);
1093 break;
1094 case SC_INDEX:
1095 TRACE_TIMER_P1 ("T-Check:TNNN[SC%d] inactive", rr_data->nc_data[index].arfcn);
1096 break;
1097 default:
1098 TRACE_TIMER_P1 ("T-Check:TNNN[%d] inactive", rr_data->nc_data[index].arfcn);
1099 break;
1100 }
1101 }
1102
1103 return rr_data->nc_data[index].tnnn;
1104 }
1105
1106
1107 /*
1108 +--------------------------------------------------------------------+
1109 | PROJECT : GSM-PS (6147) MODULE : RR_TIM |
1110 | STATE : code ROUTINE : tim_ext_meas |
1111 +--------------------------------------------------------------------+
1112
1113 PURPOSE : Timeout of timer TIM_EXT_MEAS.
1114
1115 */
1116
1117 GLOBAL void tim_ext_meas (void)
1118 {
1119 TRACE_FUNCTION ("tim_ext_meas ()");
1120 dat_emo_stop ( TRUE );
1121 }
1122
1123 #if defined FF_EOTD
1124 /*
1125 +--------------------------------------------------------------------+
1126 | PROJECT : GSM-PS (6147) MODULE : RR_TIM |
1127 | STATE : code ROUTINE : tim_apdu |
1128 +--------------------------------------------------------------------+
1129
1130 PURPOSE : Timeout of timer TAPDU.
1131
1132 */
1133
1134 GLOBAL void tim_apdu (void)
1135 {
1136 GET_INSTANCE_DATA;
1137 TRACE_FUNCTION ("tim_apdu ()");
1138 rr_applic_rx_init ( &rr_data->applic_rx );
1139 }
1140 #endif /* FF_EOTD */
1141
1142 /*
1143 +--------------------------------------------------------------------+
1144 | PROJECT : GSM-PS (6147) MODULE : RR_TIM |
1145 | STATE : code ROUTINE : tim_exec_timeout |
1146 +--------------------------------------------------------------------+
1147
1148 PURPOSE : execute timeout for the new frame variant.
1149
1150 */
1151
1152 GLOBAL void tim_exec_timeout (USHORT index)
1153 {
1154 GET_INSTANCE_DATA;
1155 TRACE_FUNCTION ("tim_exec_timeout()");
1156
1157 if (index >= NUM_OF_RR_TIMERS)
1158 {
1159 #if defined(TIMER_TRACE)
1160 SYST_TRACE_P ((SYST, "tim_exec_timeout(%u)", index));
1161 #endif
1162 }
1163 else
1164 {
1165 if (index NEQ TNNN) /* TNNN timer has its own trace */
1166 {
1167 trace_timer (index, -1);
1168 rr_data->t_running[index] = 0;
1169 }
1170
1171 if (rr_data->t_expire[index])
1172 rr_data->t_expire[index] ();
1173 }
1174 }
1175
1176 /*
1177 +--------------------------------------------------------------------+
1178 | PROJECT : GSM-PS (6147) MODULE : RR_TIM |
1179 | STATE : code ROUTINE : tim_stop_timer |
1180 +--------------------------------------------------------------------+
1181
1182 PURPOSE : stop timer in the new frame variant.
1183
1184 */
1185
1186 GLOBAL void tim_stop_timer (USHORT index)
1187 {
1188 GET_INSTANCE_DATA;
1189 TRACE_FUNCTION ("tim_stop_timer()");
1190
1191 if (index >= NUM_OF_RR_TIMERS)
1192 {
1193 #if defined(TIMER_TRACE)
1194 SYST_TRACE_P ((SYST, "tim_stop_timer(%u)", index));
1195 #endif
1196 }
1197 else
1198 {
1199 trace_timer (index, 0);
1200 rr_data->t_running[index] = 0;
1201 TIMER_STOP (rr_handle, index);
1202 }
1203 }
1204
1205 /*
1206 +--------------------------------------------------------------------+
1207 | PROJECT : GSM-PS (6147) MODULE : RR_TIM |
1208 | STATE : code ROUTINE : tim_start_timer |
1209 +--------------------------------------------------------------------+
1210
1211 PURPOSE : start timer in the new frame variant.
1212
1213 */
1214
1215 GLOBAL void tim_start_timer (USHORT index, T_TIME value)
1216 {
1217 GET_INSTANCE_DATA;
1218 TRACE_FUNCTION ("tim_start_timer()");
1219
1220 if (index >= NUM_OF_RR_TIMERS)
1221 {
1222 #if defined(TIMER_TRACE)
1223 SYST_TRACE_P ((SYST, "tim_start_timer(%u)", index));
1224 #endif
1225 }
1226 else
1227 {
1228 trace_timer (index, value);
1229 rr_data->t_running[index] = 1;
1230 TIMER_START (rr_handle, index, value);
1231 }
1232 }
1233
1234 /*
1235 +--------------------------------------------------------------------+
1236 | PROJECT : GSM-PS (6147) MODULE : RR_TIM |
1237 | STATE : code ROUTINE : tim_check_timer |
1238 +--------------------------------------------------------------------+
1239
1240 PURPOSE : Checks if a specified timer is running
1241
1242 */
1243 #if defined(TIMER_TRACE)
1244 GLOBAL BOOL tim_check_timer(USHORT index)
1245 {
1246 GET_INSTANCE_DATA;
1247 TRACE_FUNCTION ("tim_check_timer()");
1248
1249 if (index >= NUM_OF_RR_TIMERS)
1250 {
1251 SYST_TRACE_P ((SYST, "tim_check_timer(%u)", index));
1252 return FALSE;
1253 }
1254 else
1255 {
1256 trace_timer (index, -2);
1257 return (rr_data->t_running[index]);
1258 }
1259 }
1260 #endif /* TIMER_TRACE */
1261 #endif /* RR_TIM_C */