comparison src/g23m-gsm/alr3/alr_gprs.c @ 2:e636eadcad21

src/g23m-gsm: TCS3.2 version of alr renamed to alr3
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 15 Jul 2018 04:42:00 +0000
parents src/g23m-gsm/alr/alr_gprs.c@d393cd9bb723
children
comparison
equal deleted inserted replaced
1:d393cd9bb723 2:e636eadcad21
1 /*
2 +-----------------------------------------------------------------------------
3 | Project : GSM-PS
4 | Modul : ALR_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 module implements the necessary funtionality
18 | for switching to and from GPRS mode and also
19 | the handling if determining if GPRS is supported
20 | by the cell.
21 +-----------------------------------------------------------------------------
22 */
23 #ifndef ALR_GPRS_C
24 #define ALR_GPRS_C
25
26
27 #define ENTITY_PL
28
29 /*==== INCLUDES ===================================================*/
30 #include <string.h>
31 #include <stdlib.h>
32 #include <ctype.h>
33 #include "typedefs.h"
34 #include "pconst.cdg"
35 #include "mconst.cdg"
36 #include "message.h"
37 #include "ccdapi.h"
38 #include "vsi.h"
39 #include "custom.h"
40 #include "gsm.h"
41 #include "prim.h"
42 #include "cnf_alr.h"
43 #include "mon_alr.h"
44 #include "pei.h"
45 #include "tok.h"
46 #include "pcm.h"
47 #include "alr_gprs.h"
48 #define TRACING
49 #include "alr.h"
50 #define TRACING
51
52 #define TRACING
53
54 #if defined (TRACING)
55 #define ALR_TRACE_GPRS(a) ALR_TRACE(a)
56 #else
57 #define ALR_TRACE_GPRS(a)
58 #endif
59
60 LOCAL BOOL gprs_read_si13 (UBYTE si13_position);
61 LOCAL void gprs_alr_nc_enter_ptm (void);
62 LOCAL void gprs_alr_tb_meas_ind (T_TB_MEAS_IND* report);
63
64 LOCAL const T_FUNC tb_table[] = {
65 MAK_FUNC_0( gprs_alr_tb_meas_ind, TB_MEAS_IND ) /* 0 */
66 };
67
68 #define ONLY_BCC 7
69 static UBYTE gprs_support = 0;
70
71 /*
72 +--------------------------------------------------------------------+
73 | PROJECT : GSM-PS (6103) MODULE : ALR_GPRS |
74 | STATE : code ROUTINE : gprs_alr_get_table |
75 +--------------------------------------------------------------------+
76
77 PURPOSE :
78
79 */
80 void gprs_alr_get_table(const T_FUNC **tab, USHORT *n)
81 {
82 *tab = tb_table;
83 *n = TAB_SIZE (tb_table);
84 }
85
86 /*
87 +--------------------------------------------------------------------+
88 | PROJECT : GSM-PS (6103) MODULE : ALR_GPRS |
89 | STATE : code ROUTINE : gprs_alr_mon_ctrl_req |
90 +--------------------------------------------------------------------+
91
92 PURPOSE :
93
94 */
95 /*
96 * required for TESTMODE A/B
97 */
98 EXTERN UBYTE grlc_test_mode_active(void);
99 void gprs_alr_mon_ctrl_req(T_MPH_MON_CTRL_REQ* ctrl_req)
100 {
101 GET_INSTANCE_DATA;
102 ALR_TRACE_GPRS("mon_ctrl_req");
103
104 switch(GET_STATE(STATE_MA))
105 {
106 case MA_CELL_SELECTION:
107 switch(ctrl_req->action)
108 {
109 case START_MON_EBCCH:
110 if(ctrl_req->si_to_read EQ UPDATE_SI13)
111 {
112 PALLOC(req, MPHC_SCELL_EBCCH_REQ);
113 req->schedule_array_size = 1;
114 req->schedule_array[0].modulus = 8;
115 req->schedule_array[0].relative_position = 0;
116
117 ma_scell_ebcch_req(req);
118 }
119 break;
120 default:
121 break;
122 }
123 break;
124 case MA_CELL_RESELECTION:
125 switch(ctrl_req->action)
126 {
127 case START_MON_EBCCH:
128 /*for SI13 reading control*/
129 if(ctrl_req->si_to_read EQ UPDATE_SI13)
130 {
131 PALLOC(req, MPHC_SCELL_EBCCH_REQ);
132 req->schedule_array_size = 1;
133 req->schedule_array[0].modulus = 8;
134 req->schedule_array[0].relative_position = 0;
135
136 ma_scell_ebcch_req(req);
137 }
138 break;
139 default:
140 break;
141 }
142 break;
143 case MA_IDLE:
144 switch(ctrl_req->action)
145 {
146 case START_MON_EBCCH:
147 /*for SI13 reading control*/
148 if(ctrl_req->si_to_read EQ UPDATE_SI13)
149 {
150 PALLOC(req, MPHC_SCELL_EBCCH_REQ);
151 req->schedule_array_size = 1;
152 req->schedule_array[0].modulus = 8;
153 req->schedule_array[0].relative_position = 0;
154
155 ma_scell_ebcch_req(req);
156 }
157 break;
158 case START_MON_NBCCH:
159 {
160 USHORT si_mask = 0;
161 UBYTE tc = 0; /* refer to GSM Spec 05.02, clause 6.3.1.3 Mapping of BCCH data */
162 UBYTE i,k;
163
164 switch(ctrl_req->si_to_read)
165 {
166 case UPDATE_SI13:
167 gprs_read_si13(SI13_ON_NBCCH);
168 break;
169
170 case UPDATE_SI13_GSM:
171 {
172 PALLOC(scell_bcch_req, MPHC_SCELL_NBCCH_REQ);
173
174 scell_bcch_req->schedule_array_size = 1;
175 scell_bcch_req->schedule_array[0].modulus = 8;
176 scell_bcch_req->schedule_array[0].relative_position = 4;
177 ma_scell_nbcch_req(scell_bcch_req);
178 }
179 break;
180
181 case UNSPECIFIED_SI:
182 case COMPLETE_SI:
183 ma_clean_sys_buffer (IND_ALL_IDLE_SI);
184 ma_scell_full_nbcch();
185 break;
186
187 case UPDATE_SI1:
188 si_mask = IND_SI_1;
189 tc = (1<<0);
190 break;
191 case UPDATE_SI2_SI2BIS_OR_SI2TER:
192 si_mask = IND_SI_2 | IND_SI_2BIS | IND_SI_2TER;
193 tc = (1<<1) | (1<<4) | (1<<5);
194 #if defined (REL99) AND defined (TI_PS_FF_EMR)
195 /*This update indication is for SI-2quater also, so we need
196 to configure it after SI-2/2bis/2ter are received*/
197 alr_data->nc_data.si2_count = 1;
198 /*check whether we have valid 2bis info */
199 if (alr_data->ma_data.sys_info_2bis[1] EQ D_SYS_INFO_2BIS)
200 alr_data->nc_data.si2_count++;
201 /*check whether we have valid 2ter info */
202 if (alr_data->ma_data.sys_info_2ter[1] EQ D_SYS_INFO_2TER)
203 alr_data->nc_data.si2_count++;
204 #endif
205 break;
206 case UPDATE_SI3_SI4_SI7_OR_SI8:
207 si_mask = IND_SI_3 | IND_SI_4;
208 tc = (1<<2) | (1<<3) | (1<<6) | (1<<7);
209 break;
210 case UPDATE_SI9:
211 break;
212 }
213
214 if ( si_mask )
215 {
216 PALLOC(scell_bcch_req, MPHC_SCELL_NBCCH_REQ);
217 k = 0;
218 scell_bcch_req->schedule_array_size = k;
219 for ( i = 0; i < 8; i++ )
220 {
221 if ( (tc & (1 << i)) != 0 )
222 {
223 scell_bcch_req->schedule_array[k].modulus = 8;
224 scell_bcch_req->schedule_array[k].relative_position = i;
225 k++;
226 scell_bcch_req->schedule_array_size = k;
227 }
228 }
229 ma_clean_sys_buffer ( si_mask );
230 ma_scell_nbcch_req ( scell_bcch_req );
231 }
232 }
233 break;
234 case STOP_MON_CCCH:
235 /* PBCCH is present, stop all activities */
236 /*ma_stop_active_procs(STOP_PCH_READING | STOP_MEASUREMENTS);*/
237 pch_stop();
238 /*alr_data->gprs_data.pbcch = 1;*/
239 break;
240 case START_MON_CCCH:
241 if(alr_data->gprs_data.pbcch EQ TRUE)
242 {
243 pch_configure (NULL, PGM_NORMAL);
244 pch_save_pgm(PGM_NORMAL); /* reset saved pgm to REORG_CS */
245 pch_start_ccch_req();
246 }
247 break;
248
249 case LEAVING_PIM_PBCCH:
250 /* we are about to enter PAM or PTM */
251 if(alr_data->gprs_data.pbcch EQ TRUE)
252 {
253 TRACE_EVENT("leave pim");
254 alr_data->gprs_data.pim = FALSE;
255 pch_stop();
256 cb_stop();
257 nc_suspend();
258 }
259 else
260 {
261 TRACE_EVENT("huch pim");
262 }
263 break;
264 case LEAVING_PAM_PBCCH:
265 /* we are about to enter PTM or PIM */
266 if(alr_data->gprs_data.pbcch EQ TRUE)
267 {
268 /* do nothing, nothing should be active */
269 alr_data->gprs_data.pim = FALSE;
270 TRACE_EVENT("leave pam");
271 }
272 else
273 {
274 TRACE_EVENT("huch pam");
275 }
276 break;
277 case LEAVING_PTM_PBCCH:
278 /* we are about to enter PIM */
279 if(alr_data->gprs_data.pbcch EQ TRUE)
280 {
281 TRACE_EVENT("leave ptm");
282 alr_data->gprs_data.pim = FALSE;
283 pch_stop();
284 nc_suspend();
285 alr_data->gprs_data.ptm = FALSE;
286 }
287 else
288 {
289 TRACE_EVENT("huch ptm");
290 }
291 break;
292 case ENTER_PTM_PBCCH:
293 if(alr_data->gprs_data.pbcch EQ TRUE)
294 {
295 alr_data->gprs_data.ptm = TRUE;
296 alr_data->gprs_data.pim = FALSE;
297 nc_start_pbcch();
298 }
299 break;
300 case ENTER_PIM_PBCCH:
301 if(alr_data->gprs_data.pbcch EQ TRUE)
302 {
303 alr_data->gprs_data.pim = TRUE;
304 alr_data->gprs_data.ptm = FALSE;
305 nc_start_pbcch();
306 cb_start();
307 }
308 break;
309 case ENTER_PTM_BCCH:
310 /*
311 * convert counters and set NC process to IDLE
312 */
313 alr_data->gprs_data.pim = FALSE;
314 gprs_alr_nc_enter_ptm();
315 break;
316 default:
317 break;
318 }
319 break;
320 case MA_PTM:
321 switch(ctrl_req->action)
322 {
323 case START_MON_EBCCH:
324 /*for SI13 reading control*/
325 if(ctrl_req->si_to_read EQ UPDATE_SI13)
326 {
327 PALLOC(req, MPHC_SCELL_EBCCH_REQ);
328 req->schedule_array_size = 1;
329 req->schedule_array[0].modulus = 8;
330 req->schedule_array[0].relative_position = 0;
331
332 ma_scell_ebcch_req(req);
333 }
334 break;
335 case START_MON_NBCCH:
336 gprs_read_si13(SI13_ON_NBCCH);
337 break;
338 case START_MON_CCCH:
339 pch_configure (NULL, PGM_NORMAL);
340 if(alr_data->gprs_data.pbcch EQ TRUE)
341 pch_save_pgm(PGM_NORMAL); /* reset saved pgm to REORG_CS */
342 else
343 {
344 pch_save_pgm(PGM_REORG_CS); /* reset saved pgm to REORG_CS */
345 alr_data->pch_data.last_start_ccch_req.bs_pa_mfrms = NOT_PRESENT_8BIT;
346 }
347
348 pch_start_ccch_req();
349 break;
350 /*
351 * This case is necessary to stop ccch monitoring in MA_PTM
352 * This is required for Testmode A/B
353 */
354 case STOP_MON_CCCH:
355 if(grlc_test_mode_active())
356 {
357 ma_stop_active_procs(STOP_PCH_READING | STOP_MEASUREMENTS);
358 TRACE_EVENT("STOP_MON_CCCH: TESTMODE A/B is running !!!!");
359 }
360 break;
361 case ENTER_PTM_BCCH:
362 /*
363 * convert counters and set NC process to IDLE
364 */
365 gprs_alr_nc_enter_ptm();
366 break;
367 default:
368 break;
369 }
370 break;
371
372 case MA_CON_EST:
373 switch(ctrl_req->action)
374 {
375 case ENTER_PTM_BCCH:
376 /*
377 * convert counters and set NC process to IDLE
378 */
379 gprs_alr_nc_enter_ptm();
380 break;
381 default:
382 break;
383 }
384 break;
385 default:
386 break;
387 }
388 PFREE (ctrl_req);
389
390 }
391 /*
392 +--------------------------------------------------------------------+
393 | PROJECT : GSM-PS (6103) MODULE : ALR_GPRS |
394 | STATE : code ROUTINE : gprs_alr_check_packet_paging
395 +--------------------------------------------------------------------+
396
397 PURPOSE :
398
399 */
400
401 #define P1_REST_OCTET_LEN 5
402 #define GSM408_SPARE_PADDING 0x2b
403
404 /*lint -e749 (Info -- local enumeration constant not referenced) */
405 enum t_p1_ie { NLN = 0,
406 PRIO1,
407 PRIO2,
408 GRCI,
409 PPI1,
410 PPI2
411 };
412 /*lint +e749 (Info -- local enumeration constant not referenced) */
413
414 #define NEXT_BIT(bit_pos,byte_pos) if( (bit_pos >>=1) == 0 ) { bit_pos=0x80; byte_pos++;}
415
416 LOCAL enum t_p1_ie p1_ie;
417 LOCAL UBYTE element_size[PPI2+1] = {
418 3,
419 3,
420 3,
421 0,
422 1,
423 1
424 };
425
426
427
428 BOOL gprs_alr_check_packet_paging(UBYTE* frame, UBYTE which)
429 {
430 UBYTE byte_pos = 0;
431 UBYTE bit = 0x80;
432 UBYTE *frame_ptr = frame;
433
434 ALR_TRACE_GPRS("check packet paging");
435 /* point after Mobile Identity 1 */
436 frame = frame + 4 + frame[4] + 1;
437 /* check if Mobile Identity 2 is present */
438 if (frame[0] EQ 0x17)
439 /* skip Mobile Identity 2 */
440 /* rest octets = start of mob 2 + len of mob 2 + TL */
441 frame= frame + frame[1] + 2;
442
443 if( frame - frame_ptr >= MAX_L2_FRAME_SIZE )
444 return FALSE;
445
446 /* decode packet paging */
447 for(p1_ie = NLN; p1_ie < PPI2+1;p1_ie++)
448 {
449 if((frame[byte_pos] & bit) EQ
450 (GSM408_SPARE_PADDING & bit))
451 {
452 /* L:
453 * - element is not used
454 * - check next bit for next element
455 */
456 if(p1_ie NEQ (which+GRCI))
457 {
458 NEXT_BIT(bit,byte_pos);/*lint!e720 (Info -- Boolean test of assignment) */
459 }
460 else
461 {
462 ALR_TRACE_GPRS("no packet");
463 return FALSE;
464 }
465 }
466 else
467 {
468 /* H:
469 * - element is used
470 * - skip the bits used by this element
471 * except PPIx
472 */
473 ALR_TRACE_GPRS("element used");
474 if(p1_ie NEQ (which+GRCI))
475 {
476 UBYTE i;
477 for(i=element_size[p1_ie]+1; i > 0; i--)
478 {
479 NEXT_BIT(bit,byte_pos);/*lint!e720 (Info -- Boolean test of assignment) */
480 }
481 }
482 else
483 {
484 ALR_TRACE_GPRS("packet paging");
485 return TRUE;
486 }
487 }
488 }
489 return FALSE;
490 }
491
492 /*
493 +--------------------------------------------------------------------+
494 | PROJECT : GSM-PS (6103) MODULE : ALR_GPRS |
495 | STATE : code ROUTINE : gprs_alr_check_packet_paging_2
496 +--------------------------------------------------------------------+
497
498 PURPOSE :
499
500 */
501
502 /*lint -e749 (Info -- local enumeration constant not referenced) */
503 enum t_p2_ie {
504 p2CN3 = 0,
505 p2NLN,
506 p2PRIO1,
507 p2PRIO2,
508 p2PRIO3,
509 p2PPI3
510 };
511 /*lint -e749 (Info -- local enumeration constant not referenced) */
512
513 LOCAL enum t_p2_ie p2_ie;
514 LOCAL UBYTE p2_element_size[p2PPI3+1] = {
515 2,
516 3,
517 3,
518 3,
519 3,
520 1
521 };
522
523 BOOL gprs_alr_check_packet_paging_2(UBYTE* frame, UBYTE which)
524 {
525 UBYTE byte_pos = 0;
526 UBYTE bit = 0x80;
527
528 if(which NEQ 3) return FALSE;
529 ALR_TRACE_GPRS("check packet paging 2");
530 frame += frame[13]+14;
531 /* decode packet paging */
532 for(p2_ie = p2CN3; p2_ie < p2PPI3+1;p2_ie++)
533 {
534 if((frame[byte_pos] & bit) EQ
535 (GSM408_SPARE_PADDING & bit))
536 {
537 /* L:
538 * - element is not used
539 * - check next bit for next element
540 */
541 if(p2_ie NEQ p2PPI3)
542 {
543 NEXT_BIT(bit,byte_pos);/*lint!e720 (Info -- Boolean test of assignment) */
544 }
545 else
546 {
547 ALR_TRACE_GPRS("no packet");
548 return FALSE;
549 }
550 }
551 else
552 {
553 /* H:
554 * - element is used
555 * - skip the bits used by this element
556 * except PPIx
557 */
558 ALR_TRACE_GPRS("element used");
559 if(p2_ie NEQ p2PPI3)
560 {
561 UBYTE i;
562 for(i=p2_element_size[p2_ie]+1; i > 0; i--)
563 {
564 NEXT_BIT(bit,byte_pos);/*lint!e720 (Info -- Boolean test of assignment) */
565 }
566 }
567 else
568 {
569 ALR_TRACE_GPRS("packet paging");
570 return TRUE;
571 }
572 }
573 }
574 return FALSE;
575 }
576
577 /*
578 +--------------------------------------------------------------------+
579 | PROJECT : GSM-PS (6103) MODULE : ALR_GPRS |
580 | STATE : code ROUTINE : gprs_alr_store_ptmsi |
581 +--------------------------------------------------------------------+
582
583 PURPOSE :
584
585 */
586 void gprs_alr_store_ptmsi(UBYTE indic, ULONG tmsi)
587 {
588 GET_INSTANCE_DATA;
589 alr_data->gprs_data.v_ptmsi = indic;
590 alr_data->gprs_data.ptmsi = tmsi;
591 TRACE_EVENT_P2("v: %d ptmsi: %x", indic, tmsi);
592 }
593
594 /*
595 +--------------------------------------------------------------------+
596 | PROJECT : GSM-PS (6103) MODULE : ALR_GPRS |
597 | STATE : code ROUTINE : gprs_alr_store_ptmsi |
598 +--------------------------------------------------------------------+
599
600 PURPOSE : Store the candidate PTMSI
601
602 */
603 void gprs_alr_store_ptmsi2(UBYTE indic2, ULONG tmsi2)
604 {
605 GET_INSTANCE_DATA;
606 alr_data->gprs_data.v_ptmsi2 = indic2;
607 alr_data->gprs_data.ptmsi2 = tmsi2;
608 TRACE_EVENT_P2("v: %d ptmsi: %x", indic2, tmsi2);
609 }
610
611 /*
612 +--------------------------------------------------------------------+
613 | PROJECT : GSM-PS (6103) MODULE : ALR_GPRS |
614 | STATE : code ROUTINE : gprs_alr_check_ptmsi |
615 +--------------------------------------------------------------------+
616
617 PURPOSE :
618
619 */
620 BOOL gprs_alr_check_ptmsi(ULONG ptmsi_pag)
621 {
622 GET_INSTANCE_DATA;
623
624 if((alr_data->gprs_data.v_ptmsi AND
625 alr_data->gprs_data.ptmsi EQ ptmsi_pag) OR
626 (alr_data->gprs_data.v_ptmsi2 AND
627 alr_data->gprs_data.ptmsi2 EQ ptmsi_pag))
628 {
629 ALR_TRACE_GPRS("ptmsi match");
630 ma_pch_paging_ind (ID_PTMSI, CN_PACKET);
631 return TRUE;
632 }
633
634 return FALSE;
635 }
636
637 /*
638 +--------------------------------------------------------------------+
639 | PROJECT : GSM-PS (6103) MODULE : ALR_GPRS |
640 | STATE : code ROUTINE : gprs_alr_check_downlink_assign
641 +--------------------------------------------------------------------+
642
643 PURPOSE :
644
645 */
646 void gprs_alr_check_downlink_assign(T_MPHC_DATA_IND* data_ind)
647 {
648 /* check dl bit */
649 if(data_ind->l2_frame.content[3] & 0x20) {
650 ma_send_unitdata (data_ind);
651 }
652 }
653
654 /*
655 +--------------------------------------------------------------------+
656 | PROJECT : GSM-PS (6103) MODULE : ALR_GPRS |
657 | STATE : code ROUTINE : gprs_read_si13 |
658 +--------------------------------------------------------------------+
659
660 PURPOSE :
661
662 */
663 BOOL gprs_check_read_si13_only(void)
664 {
665 if(gprs_support)
666 return FALSE;
667 else
668 return TRUE;
669 }
670
671 LOCAL BOOL gprs_read_si13(UBYTE si13_position)
672 {
673 ALR_TRACE_GPRS("read si13");
674
675 if(gprs_support AND
676 si13_position EQ SI13_ON_NBCCH)
677 {
678 PALLOC(scell_bcch_req, MPHC_SCELL_NBCCH_REQ);
679 /*
680 * we want to read SI13 on TC=4 which has to be send at least
681 * on every 4th consecutive occurence of TC=4
682 */
683 scell_bcch_req->schedule_array_size = 1;
684 scell_bcch_req->schedule_array[0].modulus = 8;
685 scell_bcch_req->schedule_array[0].relative_position = 4;
686 ma_scell_nbcch_req(scell_bcch_req);
687 return FALSE;
688 }
689 else return TRUE;
690 }
691
692 /*
693 +--------------------------------------------------------------------+
694 | PROJECT : GSM-PS (6103) MODULE : ALR_GPRS |
695 | STATE : code ROUTINE : gprs_stop |
696 +--------------------------------------------------------------------+
697
698 PURPOSE :
699
700 */
701 void gprs_alr_init(void)
702 {
703 GET_INSTANCE_DATA;
704 ALR_TRACE_GPRS("gprs_alr_init");
705 alr_data->gprs_data.ign_pgm = FALSE;
706 alr_data->gprs_data.pbcch = FALSE;
707 alr_data->gprs_data.ptm = FALSE;
708 alr_data->gprs_data.check_bsic = FALSE;
709 alr_data->gprs_data.sync_only = FALSE;
710 alr_data->gprs_data.pcco_active= FALSE;
711 alr_data->nc_sync_with_grr = FALSE;
712 gprs_support = FALSE;
713 }
714
715 /*
716 +--------------------------------------------------------------------+
717 | PROJECT : GSM-PS (6103) MODULE : ALR_GPRS |
718 | STATE : code ROUTINE : gprs_alr_tb_meas_ind |
719 +--------------------------------------------------------------------+
720
721 PURPOSE :
722
723 */
724 LOCAL void gprs_alr_tb_meas_ind (T_TB_MEAS_IND *report)
725 {
726 GET_INSTANCE_DATA;
727 ALR_TRACE_GPRS("tb_meas_ind");
728 switch(GET_STATE(STATE_MA))
729 {
730 case MA_PTM:
731 /*Measurement Report in Packet Transfer Mode*/
732 {
733 USHORT temp;
734 USHORT index;
735 UBYTE diff;
736 UBYTE i,j,lim;
737 T_NC* pcell;
738
739 if(report->tb_meas_result[0].arfcn EQ NOT_PRESENT_16BIT)
740 {
741 lim = alr_data->nc_data.c_ba_arfcn;
742 }
743 else
744 {
745 lim = 0;
746 while( report ->tb_meas_result[lim].arfcn NEQ NOT_PRESENT_16BIT AND lim < TB_BA_LIST_SIZE )
747 {
748 lim++;
749 }
750 }
751
752 /*
753 * reduce the time for next sync
754 * Decrement the 10sec timer counter variable by 2
755 */
756 alr_data->nc_data.c_ncsync_tim = alr_data->nc_data.c_ncsync_tim-2;
757 if ((signed char)( alr_data->nc_data.c_ncsync_tim) < 0)
758 alr_data->nc_data.c_ncsync_tim = 0;
759
760 if( alr_data->nc_data.c_ncsync_tim==0 )
761 {
762 /* 10 sec have elapsed. Perform all requisite tasks */
763 nc_ncsync_tim_expiry();
764 }
765
766 for (pcell=&alr_data->nc_data.cell[0],i = 0; i < lim; i++,pcell++)
767 {
768 if(lim EQ alr_data->nc_data.c_ba_arfcn)
769 {
770 index = i;
771 }
772 else
773 {
774 /* For all cells look if it is in BA(BCCH) */
775 switch(index = nc_get_index(ARFCN_TO_G23(report->tb_meas_result[i].arfcn)))
776 {
777 case LAST_BSIC_REQ:
778 case NOT_PRESENT_16BIT:
779 continue;
780 default:
781 break;
782 }
783 }
784 /*
785 * the ncell is in the list
786 * so store the rxlev values
787 */
788 if(report->tb_meas_result[0].arfcn NEQ NOT_PRESENT_16BIT)
789 {
790 for(j=0;j<lim;j++)
791 {
792 if(pcell->ba_arfcn EQ ARFCN_TO_G23(report->tb_meas_result[j].arfcn))
793 {
794 if (alr_data->nc_data.cell[index].c_rxlev EQ NOT_PRESENT_8BIT)
795 {
796 /*
797 * if it is a new cell, build an average from the first value
798 * to speed up fb sb read
799 */
800 if ((signed short) (report->tb_meas_result[j].rxlev) < 0)
801 {
802 report->tb_meas_result[j].rxlev = 0;
803 }
804
805 alr_data->nc_data.cell[index].rxlev[0] = report->tb_meas_result[j].rxlev / report->tb_meas_result[j].num_meas;
806 alr_data->nc_data.cell[index].rxlev[1] = report->tb_meas_result[j].rxlev / report->tb_meas_result[j].num_meas;
807 alr_data->nc_data.cell[index].rxlev[2] = report->tb_meas_result[j].rxlev / report->tb_meas_result[j].num_meas;
808 alr_data->nc_data.cell[index].rxlev[3] = report->tb_meas_result[j].rxlev / report->tb_meas_result[j].num_meas;
809 alr_data->nc_data.cell[index].rxlev[4] = report->tb_meas_result[j].rxlev / report->tb_meas_result[j].num_meas;
810 alr_data->nc_data.cell[index].c_rxlev = 0;
811 }
812 else
813 {
814 if ((signed short) (report->tb_meas_result[j].rxlev) < 0)
815 report->tb_meas_result[j].rxlev = 0;
816
817 alr_data->nc_data.cell[index].rxlev[alr_data->nc_data.cell[index].c_rxlev++] =
818 report->tb_meas_result[j].rxlev / report->tb_meas_result[j].num_meas;
819
820 if (alr_data->nc_data.cell[index].c_rxlev >= 5)
821 alr_data->nc_data.cell[index].c_rxlev = 0;
822 }
823 #ifdef GPRS
824 /*
825 * store the results seperately for averaging when NC=1 or NC=2
826 */
827 if(alr_data->nwctrl_meas_active)
828 {
829 pcell->nc_rxlev += (report->tb_meas_result[j].rxlev / report->tb_meas_result[j].num_meas);
830 pcell->c_nc_rxlev++;
831
832 TRACE_EVENT_P3("%d %d rx: %d ",i, alr_data->nc_data.cell[i].ba_arfcn,
833 report->tb_meas_result[j].rxlev / report->tb_meas_result[j].num_meas);
834 }
835 #endif
836 break;
837 }
838 }
839 }
840 else
841 {
842 if (alr_data->nc_data.cell[index].c_rxlev EQ NOT_PRESENT_8BIT)
843 {
844 /*
845 * if it is a new cell, build an average from the first value
846 * to speed up fb sb read
847 */
848 if ((signed short) (report->tb_meas_result[i].rxlev) < 0)
849 {
850 report->tb_meas_result[i].rxlev = 0;
851 }
852
853 alr_data->nc_data.cell[index].rxlev[0] = report->tb_meas_result[i].rxlev / report->tb_meas_result[i].num_meas;
854 alr_data->nc_data.cell[index].rxlev[1] = report->tb_meas_result[i].rxlev / report->tb_meas_result[i].num_meas;
855 alr_data->nc_data.cell[index].rxlev[2] = report->tb_meas_result[i].rxlev / report->tb_meas_result[i].num_meas;
856 alr_data->nc_data.cell[index].rxlev[3] = report->tb_meas_result[i].rxlev / report->tb_meas_result[i].num_meas;
857 alr_data->nc_data.cell[index].rxlev[4] = report->tb_meas_result[i].rxlev / report->tb_meas_result[i].num_meas;
858 alr_data->nc_data.cell[index].c_rxlev = 0;
859 }
860 else
861 {
862 if ((signed short) (report->tb_meas_result[i].rxlev) < 0)
863 report->tb_meas_result[i].rxlev = 0;
864
865 alr_data->nc_data.cell[index].rxlev[alr_data->nc_data.cell[index].c_rxlev++] =
866 report->tb_meas_result[i].rxlev / report->tb_meas_result[i].num_meas;
867
868 if (alr_data->nc_data.cell[index].c_rxlev >= 5)
869 alr_data->nc_data.cell[index].c_rxlev = 0;
870 }
871 /*
872 * store the results seperately for averaging when NC=1 or NC=2
873 */
874 #ifdef GPRS
875 if(alr_data->nwctrl_meas_active)
876 {
877 if(report->tb_meas_result[0].arfcn NEQ NOT_PRESENT_16BIT)
878 {
879 for(j=0;j<lim;j++)
880 {
881 if(pcell->ba_arfcn EQ ARFCN_TO_G23(report->tb_meas_result[j].arfcn))
882 {
883 pcell->nc_rxlev += (report->tb_meas_result[j].rxlev / report->tb_meas_result[j].num_meas);
884 pcell->c_nc_rxlev++;
885
886 TRACE_EVENT_P3("%d %d rx: %d ",i, alr_data->nc_data.cell[i].ba_arfcn,
887 report->tb_meas_result[j].rxlev / report->tb_meas_result[j].num_meas);
888 break;
889 }
890 }
891 }
892 else
893 {
894
895 pcell->nc_rxlev += (report->tb_meas_result[i].rxlev / report->tb_meas_result[i].num_meas);
896 pcell->c_nc_rxlev++;
897
898 TRACE_EVENT_P3("%d %d rx: %d ",i, alr_data->nc_data.cell[i].ba_arfcn,
899 report->tb_meas_result[i].rxlev / report->tb_meas_result[i].num_meas);
900 }
901 }
902 #endif
903 }
904
905 temp = (USHORT)(alr_data->nc_data.cell[index].rxlev[0] +
906 alr_data->nc_data.cell[index].rxlev[1] +
907 alr_data->nc_data.cell[index].rxlev[2] +
908 alr_data->nc_data.cell[index].rxlev[3] +
909 alr_data->nc_data.cell[index].rxlev[4]);
910
911 alr_data->nc_data.cell[index].rxlev_average = (UBYTE)(temp / 5);
912
913
914 switch (alr_data->nc_data.cell[index].status)
915 {
916 case INACTIVE:
917 nc_set_status (index, IDLE);
918 break;
919 case EXCLUDED:
920 diff = (UBYTE)(alr_data->nc_data.cell[index].rxlev_average -
921 alr_data->nc_data.cell[index].last_rxlev);
922
923 if (diff < 128 AND diff >= 6)
924 {
925 /* result is positive and more than 6 dBm */
926 nc_set_status (index, IDLE);
927 }
928 break;
929 default:
930 break;
931 }
932
933 } /* for all */
934 PFREE(report);
935
936 nc_check_activity();
937 }
938 break;
939 default:
940 PFREE(report);
941 break;
942 }
943 }
944
945
946 /*
947 +--------------------------------------------------------------------+
948 | PROJECT : GSM-PS (6103) MODULE : ALR_GPRS |
949 | STATE : code ROUTINE : gprs_alr_nc_enter_ptm |
950 +--------------------------------------------------------------------+
951
952 PURPOSE : After the Packet Access Phase we enter Packet Transfer
953 Mode and have to do Measurements and Cell Reselection like
954 in Idle Mode.
955 */
956
957 LOCAL void gprs_alr_nc_enter_ptm (void)
958 {
959 GET_INSTANCE_DATA;
960 nc_resume(); /* set NC_STATE to IDLE */
961
962 alr_data->nc_data.c_reports = (alr_data->nc_data.c_reports*10)/alr_data->nc_data.max_reports;
963 alr_data->nc_data.max_reports = 10;
964 alr_data->nc_data.cell[LAST_BSIC_REQ].status = INACTIVE;
965
966 TRACE_EVENT_P2("glob reps: %d max_report: %d", alr_data->nc_data.c_reports, alr_data->nc_data.max_reports);
967 }
968
969 /*
970 +--------------------------------------------------------------------+
971 | PROJECT : GSM-PS (6103) MODULE : ALR_GPRS |
972 | STATE : code ROUTINE : gprs_check_page_mode |
973 +--------------------------------------------------------------------+
974
975 PURPOSE : Do not change the page mode configuration in L1
976 if ing_pgm is set. ie. we have to stay in REORG.
977
978 */
979 void gprs_check_page_mode(T_MPHC_DATA_IND* data_ind)
980 {
981 GET_INSTANCE_DATA;
982 if(alr_data->gprs_data.ign_pgm EQ TRUE)
983 {
984 pch_check_page_mode_cr(data_ind);
985 }
986 else
987 {
988 pch_check_page_mode(data_ind);
989 }
990 }
991
992 /*
993 +--------------------------------------------------------------------+
994 | PROJECT : GSM-PS (6103) MODULE : ALR_GPRS |
995 | STATE : code ROUTINE : gprs_alr_is_supported |
996 +--------------------------------------------------------------------+
997
998 PURPOSE : This function returns whether GPRS is supported in
999 the cell.
1000
1001 */
1002 GLOBAL BOOL gprs_alr_is_supported( void )
1003 {
1004 return( gprs_support EQ TRUE );
1005 }
1006
1007 void set_gprs_support( UBYTE support )
1008 {
1009 gprs_support = support;
1010 }
1011
1012 #endif /* ALR_GPRS_C */
1013
1014