comparison g23m-gsm/alr/alr_cs.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 : GSM-PS
4 | Modul : ALR_CS
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 SDL process Cell Selection.
18 +-----------------------------------------------------------------------------
19 */
20
21 #ifndef ALR_CS_C
22 #define ALR_CS_C
23
24 #include "config.h"
25 #include "fixedconf.h"
26 #include "condat-features.h"
27
28 #define ENTITY_PL
29
30 /*==== INCLUDES ===================================================*/
31 #include <string.h>
32 #include <stdlib.h>
33 #include <limits.h>
34 #include "typedefs.h"
35 #include "vsi.h"
36 #include "custom.h"
37 #include "gsm.h"
38 #include "prim.h"
39 #include "pei.h"
40 #include "tok.h"
41
42 #include "pcm.h"
43 #ifdef GPRS
44 #include "alr_gprs.h"
45 #endif
46
47 #include "alr.h"
48 #include "alr_em.h"
49 #include "cl_list.h"
50
51 #if defined (_SIMULATION_)
52 #define TRACING
53 #endif
54
55 #if defined (TRACING)
56 #define ALR_TRACE_CS(a) ALR_TRACE(a)
57 #else
58 #define ALR_TRACE_CS(a)
59 #endif
60
61 #if defined (TRACING)
62
63 #define ALR_TRACE_CS_STD(a1) TRACE_EVENT_P1 ("std %d",a1)
64 #define ALR_TRACE_CS_BSIC_REQ(a,s) TRACE_EVENT_P2 ("BSIC REQ [%u] %d", a, s)
65 #define ALR_TRACE_CS_SYNC_VALID(a,f,t) TRACE_EVENT_P3 ("set new SC[%u],valid block fno:%d,time_al%d",a,f,t)
66
67 #else
68
69 #define ALR_TRACE_CS_STD(std)
70 #define ALR_TRACE_CS_BSIC_REQ(a,s)
71 #define ALR_TRACE_CS_SYNC_VALID(a,f,t)
72
73 #endif
74
75 /*==== EXPORT =====================================================*/
76
77 /*==== PRIVAT =====================================================*/
78
79 /*==== VARIABLES ==================================================*/
80
81 /* Power scan attempts for different search modes */
82 LOCAL const U8 power_scan_attempts[] = {
83 FULL_SEARCH_MODE_ATTEMPTS,
84 NORMAL_SEARCH_MODE_ATTEMPTS,
85 FAST_SEARCH_MODE_ATTEMPTS,
86 BLACK_LIST_SEARCH_MODE_ATTEMPTS
87 };
88
89 /* Power measurements spreading time for different search modes */
90 #if defined(_SIMULATION_)
91 LOCAL const U16 tim_powermeas_value[] = {
92 500,
93 500,
94 100,
95 100
96 };
97 #else
98 LOCAL const U16 tim_powermeas_value[] = {
99 TIM_FULL_SEARCH_POWERMEAS_VAL,
100 TIM_NORMAL_SEARCH_POWERMEAS_VAL,
101 TIM_FAST_SEARCH_POWERMEAS_VAL,
102 TIM_BLACK_LIST_SEARCH_POWERMEAS_VAL
103 };
104 #endif
105
106 LOCAL const int array_band_index[] = {
107 B_GSM_900,
108 B_E_GSM,
109 B_PCS_1900,
110 B_DCS_1800,
111 MAX_NUM_BANDS,
112 MAX_NUM_BANDS,
113 B_GSM_850
114 };
115
116 /*==== FUNCTIONS ==================================================*/
117
118 LOCAL void cs_add_and_sort_channels (void);
119 LOCAL void cs_find_inactive_carriers (T_POWER_MEAS **p_results,
120 U16 p_results_size[2],U8 *std,
121 U8 no_of_attempts, SHORT *min_rxlev);
122 #ifdef TI_PS_FF_QUAD_BAND_SUPPORT
123 LOCAL U8 cs_add_whitelist_carriers (U16 p_results_size[2], U8 *std,
124 U8 attempts,
125 SHORT *min_rxlev,
126 T_POWER_MEAS **p_results,
127 U8 no_of_carriers_per_band[4]);
128 #else
129 LOCAL U8 cs_add_whitelist_carriers (U16 p_results_size[2],
130 U8 std, U8 attempts,
131 SHORT *min_rxlev,
132 T_POWER_MEAS *presults,
133 U8 no_of_carriers_per_band[4]);
134 #endif
135 LOCAL BOOL cs_is_in_black_list (U8 region,U16 arfcn);
136 LOCAL U8 cs_restrict_max_carriers_per_band (U16 arfcn, U8 std,
137 U8 no_of_carriers_per_band[4],
138 U16 p_results_size[2], U8 min_rxlev);
139 LOCAL void cs_move_extra_carriers (U8 i_cnf, U8 extra_cnf);
140 LOCAL void cs_reorder_the_extra_carriers (U8 extra_cnf);
141 LOCAL void cs_power_array_swap_arfcn (T_POWER_ARRAY *from,
142 T_POWER_ARRAY *to);
143
144 /*
145 +--------------------------------------------------------------------+
146 | PROJECT : GSM-PS (8403) MODULE : ALR_CS |
147 | STATE : code ROUTINE : cs_init |
148 +--------------------------------------------------------------------+
149
150 PURPOSE : Initialize Cell Selection Process.
151 Set state and dynamic allocated RAM area to NULL.
152
153 */
154
155 GLOBAL void cs_init (void)
156 {
157 GET_INSTANCE_DATA;
158 TRACE_FUNCTION ("cs_init()");
159 alr_data->state[STATE_CS] = CS_NULL;
160 memset (&alr_data->cs_data, 0, sizeof (T_CS_DATA));
161 alr_data->cs_data.p_results1 = (T_POWER_MEAS*)&alr_power_meas_result1;
162 alr_data->cs_data.p_results2 = (T_POWER_MEAS*)&alr_power_meas_result2;
163 alr_data->cs_data.search_mode = SM_WIDE_MODE;
164 alr_data->cs_data.sync_fail_count = CS_SYNC_FAIL_COUNT_MAX;
165 alr_data->cs_data.bcch_fail_count = CS_BCCH_FAIL_COUNT_MAX;
166
167 if ( IS_EXT_MEAS_RUNNING ) /*alr_data->cs_data.mph_ext_meas_req NEQ NULL*/
168 {
169 PFREE ( alr_data->cs_data.mph_ext_meas_req );
170 alr_data->cs_data.mph_ext_meas_req = NULL;
171 }
172 }
173
174 /*
175 +--------------------------------------------------------------------+
176 | PROJECT : GSM-PS (8403) MODULE : ALR_CS |
177 | STATE : code ROUTINE : cs_get_next_area |
178 +--------------------------------------------------------------------+
179
180 PURPOSE : This returns the next area to scan ('next_area').
181 Also it sets 'std' and 'freq_area' - members of 'cs_data' -
182 depend on given 'freq_bands'.
183 */
184
185 LOCAL UBYTE cs_get_next_area (void)
186 {
187 GET_INSTANCE_DATA;
188 UBYTE next_area;
189
190 if ((alr_data->cs_data.freq_area&ALL_FREQ_AREA) EQ ALL_FREQ_AREA)
191 next_area =
192 (alr_data->cs_data.freq_area&NEXT_AMERICAN_AREA) ? AMERICAN_FREQ_AREA : EUROPEAN_FREQ_AREA;
193 else
194 next_area = alr_data->cs_data.freq_area;
195
196 /*
197 * In the case the members and value aren't already initialized,
198 * next_area is set to 0
199 */
200 switch (next_area)
201 {
202 default:
203 case EUROPEAN_FREQ_AREA:
204 if ((alr_data->cs_data.std12 & 0x0f) EQ 0) /* not initialized */
205 next_area = 0;
206 break;
207 case AMERICAN_FREQ_AREA:
208 if ((alr_data->cs_data.std12 >> 4) EQ 0) /* not initialized */
209 next_area = 0;
210 break;
211 case 0:
212 break;
213 }
214
215 /*
216 if (next_area)
217 {
218 TRACE_EVENT_P9 ("cs_get_next_area: fb=%02x => cs_std=%u(%u) std12=%02x area=%02x'%c%c' next=%u'%c'",
219 alr_data->cs_data.freq_bands, alr_data->cs_data.std, std,
220 alr_data->cs_data.std12, alr_data->cs_data.freq_area,
221 (alr_data->cs_data.freq_area & EUROPEAN_FREQ_AREA) ? 'E':' ',
222 (alr_data->cs_data.freq_area & AMERICAN_FREQ_AREA) ? 'A':' ',
223 next_area, next_area ? ((next_area EQ AMERICAN_FREQ_AREA) ? 'A':' E') : '?');
224 }
225 */
226 return next_area;
227 }
228
229 /*
230 +--------------------------------------------------------------------+
231 | PROJECT : GSM-PS (8403) MODULE : ALR_CS |
232 | STATE : code ROUTINE : cs_get_std_area |
233 +--------------------------------------------------------------------+
234
235 PURPOSE : This returns the frequency band 'std' depend on given
236 'freq_bands'. It also sets the suitable frequency area
237 to the value of a possible given area pointer.
238
239 This function knows only the single and dual frequency
240 band combinations. Triple or quad frequency band
241 combinations leads to return values set to 0.
242 */
243
244 LOCAL UBYTE cs_get_std_area (UBYTE freq_bands, UBYTE *p_area)
245 {
246 UBYTE cs_freq_area;
247 UBYTE cs_std;
248
249 switch (freq_bands)
250 {
251 case BAND_GSM_900:/* single band */
252 cs_freq_area = EUROPEAN_FREQ_AREA;
253 cs_std = STD_900;
254 break;
255 case BAND_DCS_1800:/* single band */
256 cs_freq_area = EUROPEAN_FREQ_AREA;
257 cs_std = STD_1800;
258 break;
259 case BAND_PCS_1900:/* single band */
260 cs_freq_area = AMERICAN_FREQ_AREA;
261 cs_std = STD_1900;
262 break;
263 case BAND_E_GSM:/* extended single band */
264 case BAND_GSM_900|BAND_E_GSM: /* extended single band */
265 cs_freq_area = EUROPEAN_FREQ_AREA;
266 cs_std = STD_EGSM;
267 break;
268 case BAND_GSM_850:/* single band */
269 cs_freq_area = AMERICAN_FREQ_AREA;
270 cs_std = STD_850;
271 break;
272 case BAND_DUAL:/* dual band */
273 cs_freq_area = EUROPEAN_FREQ_AREA;
274 cs_std = STD_DUAL;
275 break;
276 case BAND_DUAL_EXT:/* dual band */
277 cs_freq_area = EUROPEAN_FREQ_AREA;
278 cs_std = STD_DUAL_EGSM;
279 break;
280 case BAND_DUAL_US:/* dual band */
281 cs_freq_area = AMERICAN_FREQ_AREA;
282 cs_std = STD_DUAL_US;
283 break;
284 default:
285 cs_freq_area = 0;
286 cs_std = 0;
287 break;
288 }
289
290 if (p_area)
291 *p_area = cs_freq_area;
292 return cs_std;
293 }
294
295 /*
296 +--------------------------------------------------------------------+
297 | PROJECT : GSM-PS (8403) MODULE : ALR_CS |
298 | STATE : code ROUTINE : cs_set_std_area |
299 +--------------------------------------------------------------------+
300
301 PURPOSE : This returns the next area to scan ('next_area').
302 Also it sets 'std' and 'freq_area' - members of 'cs_data' -
303 depend on given 'freq_bands'.
304 This function will be executed at least once (single band) and
305 not more than twice (multiband) per power request.
306 */
307
308 LOCAL UBYTE cs_set_std_area (void)
309 {
310 GET_INSTANCE_DATA;
311 UBYTE next_area;
312 UBYTE cs_freq_bands = alr_data->cs_data.freq_bands;
313 UBYTE cs_std;
314 UBYTE cs_freq_area = alr_data->cs_data.freq_area;
315
316 /*
317 TRACE_EVENT_P1 ("cs_set_std_area(): %s call", cs_freq_area?"second":"first");
318 */
319 if (cs_freq_area & NEXT_AMERICAN_AREA)
320 /*
321 * Initializing before second measurement
322 */
323 next_area = AMERICAN_FREQ_AREA;
324 else
325 next_area = 0;
326
327 if (cs_freq_bands EQ 0)
328 {
329 TRACE_ERROR ("alr_data->cs_data.freq_bands=0 (Invalid value)!");
330 TRACE_ASSERT (cs_freq_bands EQ 0);
331 }
332
333 cs_std = cs_get_std_area(cs_freq_bands, &cs_freq_area);
334 if (cs_std EQ 0)
335 {
336 cs_freq_area = 0;
337 if (cs_freq_bands & BAND_DUAL_EXT)
338 { /* european frequency bands */
339 cs_freq_area |= EUROPEAN_FREQ_AREA;
340 if (next_area EQ 0)
341 next_area = EUROPEAN_FREQ_AREA;
342 }
343 if (cs_freq_bands & BAND_DUAL_US)
344 { /* american frequency bands */
345 cs_freq_area |= AMERICAN_FREQ_AREA;
346 if (next_area EQ 0)
347 next_area = AMERICAN_FREQ_AREA;
348 }
349
350 if (next_area EQ EUROPEAN_FREQ_AREA)
351 {
352 cs_freq_bands &= BAND_DUAL_EXT;
353 }
354 else
355 {
356 cs_freq_bands &= BAND_DUAL_US;
357 cs_freq_area |= NEXT_AMERICAN_AREA;
358 }
359 /*
360 * get the next 'std' depend on the value of 'next_area'
361 */
362 cs_std = cs_get_std_area (cs_freq_bands, NULL);
363 }
364
365 if (next_area EQ 0)
366 next_area = cs_freq_area;
367
368 alr_data->cs_data.freq_area = cs_freq_area;
369 alr_data->cs_data.std = cs_std;
370 TRACE_EVENT_P9 ("cs_set_std_area: fb=%02x => cs_std=%u(%u) std12=%02x area=%02x'%c%c' next=%u'%c'",
371 alr_data->cs_data.freq_bands, alr_data->cs_data.std, std,
372 alr_data->cs_data.std12, alr_data->cs_data.freq_area,
373 (alr_data->cs_data.freq_area & EUROPEAN_FREQ_AREA) ? 'E':' ',
374 (alr_data->cs_data.freq_area & AMERICAN_FREQ_AREA) ? 'A':' ',
375 next_area, next_area ? ((next_area EQ AMERICAN_FREQ_AREA) ? 'A':'E') : '?');
376
377 return next_area;
378 }
379
380 /*
381 +--------------------------------------------------------------------+
382 | PROJECT : GSM-PS (8403) MODULE : ALR_CS |
383 | STATE : code ROUTINE : cs_power_array_swap_arfcn|
384 +--------------------------------------------------------------------+
385
386 PURPOSE : This function swaps ARFCN and its RxLev between the
387 locations passed.
388 */
389 LOCAL void cs_power_array_swap_arfcn(T_POWER_ARRAY *ptr1,T_POWER_ARRAY *ptr2)
390 {
391 U16 temp_arfcn;
392 SHORT temp_rxlev;
393
394 temp_arfcn = ptr1->radio_freq;
395 temp_rxlev = ptr1->accum_power_result;
396
397 ptr1->radio_freq = ptr2->radio_freq;
398 ptr1->accum_power_result = ptr2->accum_power_result;
399
400 ptr2->radio_freq = temp_arfcn;
401 ptr2->accum_power_result = temp_rxlev;
402
403 }
404
405 /*
406 +--------------------------------------------------------------------+
407 | PROJECT : GSM-PS (8403) MODULE : ALR_CS |
408 | STATE : code ROUTINE : cs_prepare_power_req |
409 +--------------------------------------------------------------------+
410
411 PURPOSE : This prepares the inputs for the power request depending
412 on the frequency areas.
413
414 */
415
416 GLOBAL T_POWER_MEAS* cs_prepare_power_req (void)
417 {
418 GET_INSTANCE_DATA;
419 UBYTE next_area,region;
420 T_POWER_MEAS *power_meas;
421 T_LIST *black_list;
422
423 TRACE_FUNCTION ("cs_prepare_power_req");
424
425 /*
426 * depending on the set frequency area
427 */
428 next_area = cs_get_next_area ();
429
430 if (next_area)
431 { /* members and values are already initialized */
432 switch (next_area)
433 {
434 default:
435 case EUROPEAN_FREQ_AREA:
436 power_meas = alr_data->cs_data.p_results1;
437 alr_data->cs_data.std = alr_data->cs_data.std12&0x0f;
438 break;
439 case AMERICAN_FREQ_AREA:
440 power_meas = alr_data->cs_data.p_results2;
441 alr_data->cs_data.std = alr_data->cs_data.std12>>4;
442 break;
443 }
444
445 TRACE_EVENT_WIN_P4 ("cs_prepare_power_req: cs_std=%u(%02x) next=%u'%c'",
446 alr_data->cs_data.std, alr_data->cs_data.std12,
447 next_area, (next_area EQ AMERICAN_FREQ_AREA) ? 'A':'E');
448
449 }
450 else
451 { /* must be initialize first */
452 int i;
453 int power_array_size;
454 int radio_freq_offset = 1;
455
456 /*
457 * depending on the given frequency bands
458 */
459 next_area = cs_set_std_area ();
460 /*
461 * depending on the just set frequency standard
462 */
463 switch(alr_data->cs_data.std)
464 {
465 case STD_900:
466 power_array_size = MAX_CARRIERS_GSM900;
467 break;
468
469 case STD_EGSM:
470 power_array_size = MAX_CARRIERS_EGSM900;
471 break;
472
473 case STD_1900:
474 power_array_size = MAX_CARRIERS_PCS1900;
475 #ifdef TI_PS_FF_QUAD_BAND_SUPPORT
476 radio_freq_offset = 1024;
477 #else
478 radio_freq_offset = 512;
479 #endif
480 break;
481
482 case STD_1800:
483 power_array_size = MAX_CARRIERS_DCS1800;
484 radio_freq_offset = 512;
485 break;
486
487 case STD_DUAL:
488 power_array_size = MAX_CARRIERS_DUAL;
489 break;
490
491 case STD_DUAL_EGSM:
492 power_array_size = MAX_CARRIERS_DUAL_EGSM;
493 break;
494
495 case STD_850:
496 power_array_size = MAX_CARRIERS_GSM850;
497 radio_freq_offset = 128;
498 break;
499
500 case STD_DUAL_US:
501 power_array_size = MAX_CARRIERS_DUAL_US;
502 #ifdef TI_PS_FF_QUAD_BAND_SUPPORT
503 radio_freq_offset = 128;
504 #endif
505 break;
506
507 default:
508 power_array_size = 0;
509 break;
510 }
511
512 if (power_array_size)
513 {
514 /*
515 * fill all carriers which shall be measured into the structure
516 * to layer 1.
517 */
518 T_POWER_ARRAY *power_array;
519 USHORT size;
520
521 if ( IS_EXT_MEAS_RUNNING )
522 {
523 power_array_size = alr_data->cs_data.mph_ext_meas_req->num_of_chan;
524 }
525
526 /* depend on the next area get the right T_POWER_MEAS instance */
527 switch (next_area)
528 {
529 default:
530 case EUROPEAN_FREQ_AREA:
531 size = sizeof (T_POWER_MEAS1);
532 power_meas = alr_data->cs_data.p_results1;
533 /*
534 TRACE_EVENT_P1 ("static T_POWER_MEAS(EU): size=%u", sizeof (T_POWER_MEAS1));
535 */
536 memset (alr_data->cs_data.p_results1, 0, sizeof (T_POWER_MEAS));
537
538 /* save value of 'std' for cs_increment_c_channels() */
539 alr_data->cs_data.std12 |= alr_data->cs_data.std & 0x0f;
540 break;
541
542 case AMERICAN_FREQ_AREA:
543 size = sizeof (T_POWER_MEAS2);
544 power_meas = alr_data->cs_data.p_results2;
545 /*
546 TRACE_EVENT_P1 ("static T_POWER_MEAS(USA): size=%u", sizeof (T_POWER_MEAS2));
547 */
548 /* save value of 'std' for cs_increment_c_channels() */
549 alr_data->cs_data.std12 |= (alr_data->cs_data.std << 4);
550 break;
551 }
552
553 memset (power_meas, 0, size);
554
555 TRACE_EVENT_WIN_P8 ("cs_prepare_power_req: cs_std=%u(%u) std12=%02x rf=%u..%u (%u) next=%u'%c'",
556 alr_data->cs_data.std, std, alr_data->cs_data.std12,
557 radio_freq_offset, power_array_size+radio_freq_offset-1,
558 power_array_size,
559 next_area, (next_area EQ AMERICAN_FREQ_AREA) ? 'A':'E');
560
561 power_array = &(power_meas->power_array[0]);
562 memset (power_array, 0, sizeof (T_POWER_ARRAY) * power_array_size);
563 power_meas->power_array_size = power_array_size;
564
565 if ( IS_EXT_MEAS_RUNNING )
566 {
567 USHORT *arfcn = &alr_data->cs_data.mph_ext_meas_req->arfcn[0];
568 for ( i = 0; i < power_array_size; i++, power_array++, arfcn++ )
569 {
570 power_array->radio_freq = ARFCN_TO_L1 ( *arfcn );
571 }
572 }
573 else
574 {
575 if(alr_data->cs_data.p_power_req->search_mode NEQ BLACK_LIST_SEARCH_MODE)
576 {
577 power_array_size += radio_freq_offset;
578 #ifdef TI_PS_FF_QUAD_BAND_SUPPORT
579 if (alr_data->cs_data.std EQ STD_EGSM)
580 {
581 for (i=radio_freq_offset; i <= MAX_CARRIERS_GSM900; i++, power_array++)
582 {
583 power_array->radio_freq = (U16)i;
584 }
585 for (i=LOW_CHANNEL_EGSM; i < HIGH_CHANNEL_EGSM; i++, power_array++)
586 {
587 power_array->radio_freq = (U16)i;
588 }
589 power_array->radio_freq = 0x00;
590 power_array++;
591 }
592 else if (alr_data->cs_data.std EQ STD_DUAL)
593 {
594 for (i=radio_freq_offset; i <= MAX_CARRIERS_GSM900; i++, power_array++)
595 {
596 power_array->radio_freq = (U16)i;
597 }
598 for (i=LOW_CHANNEL_1800; i <= HIGH_CHANNEL_1800; i++, power_array++)
599 {
600 power_array->radio_freq = (U16)i;
601 }
602 }
603 else if (alr_data->cs_data.std EQ STD_DUAL_EGSM)
604 {
605 for (i=radio_freq_offset; i <= MAX_CARRIERS_GSM900; i++, power_array++)
606 {
607 power_array->radio_freq = (U16)i;
608 }
609 for (i=LOW_CHANNEL_EGSM; i < HIGH_CHANNEL_EGSM; i++, power_array++)
610 {
611 power_array->radio_freq = (U16)i;
612 }
613 for (i=LOW_CHANNEL_1800; i <= HIGH_CHANNEL_1800; i++, power_array++)
614 {
615 power_array->radio_freq = (U16)i;
616 }
617 power_array->radio_freq = 0x00;
618 power_array++;
619 }
620 else if (alr_data->cs_data.std EQ STD_DUAL_US)
621 {
622 for (i=radio_freq_offset; i <= HIGH_CHANNEL_850; i++, power_array++)
623 {
624 power_array->radio_freq = (U16)i;
625 }
626 for (i=1024; i <= 1322; i++, power_array++)
627 {
628 power_array->radio_freq = (U16)i;
629 }
630 }
631 else
632 {
633 for(i=radio_freq_offset; i < power_array_size; i++, power_array++)
634 {
635 power_array->radio_freq = (U16)i;
636 }
637 }
638 #else
639 for(i=radio_freq_offset; i < power_array_size; i++, power_array++)
640 {
641 power_array->radio_freq = (U16)i;
642 }
643 #endif
644 }
645 else
646 {
647 /* Blacklist search. Fill all Black Listed and "Grey" carriers
648 * sent by RR for L1 measurement
649 */
650 region = srv_get_region_from_std(std);
651 power_meas->power_array_size = 0;
652 #ifdef TI_PS_FF_QUAD_BAND_SUPPORT
653 if (region EQ BOTH_REGIONS)
654 {
655 int j;
656 for (j=0; j<MAX_REGIONS; j++)
657 {
658 black_list = (T_LIST*)&alr_data->cs_data.p_power_req->black_list.list[j];
659
660 for(i=CHANNEL_0;i<CHANNEL_0_INTERNAL;i++)
661 {
662 if(srv_get_channel(black_list, i))
663 {
664 power_array->radio_freq = ARFCN_TO_L1 ( i );
665
666 power_meas->power_array_size++;
667 power_array++;
668 }
669 }
670 }
671 }
672 else
673 {
674 #endif
675 black_list = (T_LIST*)&alr_data->cs_data.p_power_req->black_list.list[region];
676
677 for(i=CHANNEL_0;i<CHANNEL_0_INTERNAL;i++)
678 {
679 if(srv_get_channel(black_list, i))
680 {
681 power_array->radio_freq = ARFCN_TO_L1 ( i );
682
683 power_meas->power_array_size++;
684 power_array++;
685 }
686 }
687 #ifdef TI_PS_FF_QUAD_BAND_SUPPORT
688 }
689 #endif
690 } /* Black list search */
691 } /* !EXT_MEAS */
692 } /* power_array_size != 0 */
693 else
694 {
695 TRACE_EVENT_P6 ("cs_prepare_power_req: invalid: fb=%02x cs_std=%u area=%02x'%c%c' next='%c'",
696 alr_data->cs_data.freq_bands,
697 alr_data->cs_data.std, alr_data->cs_data.freq_area,
698 (alr_data->cs_data.freq_area & EUROPEAN_FREQ_AREA) ? 'E':' ',
699 (alr_data->cs_data.freq_area & AMERICAN_FREQ_AREA) ? 'A':' ',
700 (next_area EQ AMERICAN_FREQ_AREA) ? 'A':'E');
701 power_meas = NULL;/* invalid values */
702 }
703 }
704 return power_meas;/* do it */
705 }
706
707 /*
708 +--------------------------------------------------------------------+
709 | PROJECT : GSM-PS (8403) MODULE : ALR_CS |
710 | STATE : code ROUTINE : cs_power_req |
711 +--------------------------------------------------------------------+
712
713 PURPOSE : This starts measurement of the fieldstrength of all channels.
714
715 */
716
717 GLOBAL void cs_power_req (UBYTE pch_interrupt)
718 {
719 GET_INSTANCE_DATA;
720 /* When Power On alr_data->cs_data.std will be set to 0, which wil be changed later. This is
721 used to find out if it is a first power scan after boot up. MPHC_INIT_L1_REQ will be sent
722 only during first powerv scan. It should not be sent on subsequent power scan */
723 #ifdef TI_PS_FF_QUAD_BAND_SUPPORT
724 U8 initial_req = alr_data->cs_data.std;
725 #endif
726
727 TRACE_EVENT_P1 (" p_results1=%08x", alr_data->cs_data.p_results1);
728
729 /* Reset CS data */
730 alr_data->cs_data.std12 = 0;
731 alr_data->cs_data.freq_area = 0;
732 alr_data->cs_data.c_meas = 0;
733 alr_data->cs_data.p_results1->power_array_size = 0;
734 alr_data->cs_data.p_results2->power_array_size = 0;
735
736 cs_prepare_power_req();
737
738 if(IS_EXT_MEAS_RUNNING)
739 {
740 alr_data->cs_data.c_max_meas = power_scan_attempts[FULL_SEARCH_MODE];
741
742 alr_data->cs_data.c_tim_meas = (tim_powermeas_value[FULL_SEARCH_MODE]/
743 power_scan_attempts[FULL_SEARCH_MODE]);
744
745 }
746 else
747 {
748 T_MPH_POWER_REQ* mph_power_req = alr_data->cs_data.p_power_req;
749
750 /* CSI-LLD Section: 4.1.3.4.2.3
751 * Set the number of RF scan attempts and TIM_POWER_MEAS timer value
752 * based on the search mode
753 */
754
755 /* Set the number of RF scan attempts */
756 alr_data->cs_data.c_max_meas =
757 power_scan_attempts[mph_power_req->search_mode];
758
759 /* Set TIM_POWER_MEAS timer value */
760 alr_data->cs_data.c_tim_meas =
761 (tim_powermeas_value[mph_power_req->search_mode] /
762 power_scan_attempts[mph_power_req->search_mode]);
763
764
765 if (((alr_data->cs_data.freq_area & ALL_FREQ_AREA) EQ ALL_FREQ_AREA) AND
766 (mph_power_req->search_mode NEQ BLACK_LIST_SEARCH_MODE))
767 {
768 /* Multiply the number of field strength measurements by 2 */
769 alr_data->cs_data.c_max_meas <<= 1;
770
771 /* Reduce the TIM_POWER_MEAS value by half */
772 alr_data->cs_data.c_tim_meas >>= 1;
773 }
774
775 TRACE_EVENT_P2(" Search Type:[%u] Search Mode:[%u]",
776 mph_power_req->pch_interrupt,
777 mph_power_req->search_mode);
778 }
779
780 /* new state is dependent on necessary of the L1 configuration */
781 #ifdef TI_PS_FF_QUAD_BAND_SUPPORT
782 if (!initial_req)
783 #else
784 if ((pch_interrupt EQ PCH_INTERRUPT) OR (alr_data->cs_data.std NEQ std))
785 #endif
786 {
787 SET_STATE (STATE_CS, CS_INIT_L1);
788 }
789 else
790 {
791 SET_STATE (STATE_CS, CS_START_MEASURE);
792 }
793
794 TRACE_EVENT_P2 ("cs_power_req: c_max_meas=%u c_tim_meas=%u",
795 alr_data->cs_data.c_max_meas, alr_data->cs_data.c_tim_meas);
796
797 ma_cs_rxlev_req ();
798 }
799
800 /*
801 +--------------------------------------------------------------------+
802 | PROJECT : GSM-PS (8403) MODULE : ALR_CS |
803 | STATE : code ROUTINE : cs_bsic_req |
804 +--------------------------------------------------------------------+
805
806 PURPOSE : Request of RR to search for frequency correction
807 burst and synchron burst.
808
809 */
810
811 GLOBAL void cs_bsic_req (T_MPH_BSIC_REQ * mph_bsic_req)
812 {
813 GET_INSTANCE_DATA;
814 UBYTE cs_std;
815
816 if (mph_bsic_req)
817 {
818 ALR_TRACE_CS_BSIC_REQ(mph_bsic_req->arfcn&ARFCN_MASK, GET_STATE (STATE_CS));
819
820 ALR_EM_BSIC_REQUEST;
821
822 }
823 /*
824 * cs_bsic_req is called from several places with mph_bsic_req EQ NULL
825 */
826
827 switch (GET_STATE (STATE_CS))
828 {
829 case CS_ACTIVE_BCCH:
830 ma_stop_scell_bcch_req ();
831 /*
832 * first stop BCCH reading,
833 * then start like in idle mode if
834 * it is a valid channel number
835 */
836 /*lint -fallthrough*/
837 default:
838 if (mph_bsic_req)
839 {
840 alr_data->cs_data.arfcn = mph_bsic_req->arfcn;
841 cs_std = STD_GET_FROM_ARFCN (mph_bsic_req->arfcn);
842 #ifdef TI_PS_FF_QUAD_BAND_SUPPORT
843 alr_data->cs_data.std = cs_std;
844 #else
845 if (cs_std AND (cs_std NEQ alr_data->cs_data.std))
846 { /*
847 * When RR supplies a value of 'std' then init radio band before sync
848 */
849 TRACE_EVENT_WIN_P2("cs_bsic_req: cs_std=%u->%u",
850 alr_data->cs_data.std, cs_std);
851 alr_data->cs_data.std = cs_std;
852 ma_cs_init_l1_req(alr_data->cs_data.std);
853 SET_STATE(STATE_CS, CS_INIT_SYNC);
854 return; /* wait of MPHC_INIT_L1_CON */
855 }
856 #endif
857 }
858 /* If no value of 'std' are supplied, then start sync immediately */
859 /*lint -fallthrough*/
860 case CS_INIT_DONE:
861 #if defined(STOP_SYNC_TASK)
862 if (alr_data->cs_data.sync_active)
863 {
864 /*
865 * stop any synchronisation task
866 */
867 SET_STATE(STATE_CS, CS_STOP_SYNC);
868 ma_cs_stop_network_sync_req();
869 return;/* wait for MPHC_STOP_NETWORK_SYNC_CON */
870 }
871 /*lint -fallthrough*/
872 case CS_STOP_SYNC_DONE:
873 #endif /* STOP_SYNC */
874 /*
875 * start synchronisation
876 * to the frequency correction burst and synchron burst
877 * in layer 1.
878 */
879 TRACE_EVENT_P1 ("NETWORK_SYNC_REQ[%u]", alr_data->cs_data.arfcn&ARFCN_MASK);
880 ma_cs_network_sync_req (ARFCN_STD_TO_L1(alr_data->cs_data.arfcn, alr_data->cs_data.std));
881 SET_STATE(STATE_CS, CS_ACTIVE_SYNC);
882 break;
883 #if defined(STOP_SYNC_TASK)
884 case CS_STOP_SYNC:
885 /* do nothing, wait for MPHC_STOP_NETWORK_SYNC_CON */
886 return;
887 #endif /* STOP_SYNC */
888 }
889 }
890
891 /*
892 +--------------------------------------------------------------------+
893 | PROJECT : GSM-PS (8403) MODULE : ALR_CS |
894 | STATE : code ROUTINE : cs_rxlev_ind |
895 +--------------------------------------------------------------------+
896
897 PURPOSE : This is the response from layer 1 for
898 a measurement sample request over all channels.
899
900 */
901
902 GLOBAL void cs_rxlev_ind (T_MPHC_RXLEV_IND* rxlev_ind)
903 {
904 GET_INSTANCE_DATA;
905 #if defined(_SIMULATION_)
906 {
907 /*
908 * special handling for windows simulation. In this case predefined
909 * values are used, because the primitives are too big to be forwarded
910 * via the test interface.
911 */
912 int index = rxlev_ind->shared_ptr;
913
914 memcpy(alr_data->cs_data.p_results1,&tap_rxlev_response_european[index],
915 sizeof(T_POWER_MEAS));
916
917 memcpy(alr_data->cs_data.p_results2,&tap_rxlev_response_american[index],
918 sizeof(T_POWER_MEAS));
919 }
920 #endif /* _SIMULATION_ */
921
922 TRACE_EVENT_P3 ("cs_rxlev_ind(): cs_std=%u c_meas=%u/%u",
923 alr_data->cs_data.std, alr_data->cs_data.c_meas+1, alr_data->cs_data.c_max_meas);
924
925 if ( IS_EXT_MEAS_RUNNING AND alr_data->cs_data.ext_meas_state_pend NEQ CS_NULL )
926 {
927 TIMERSTOP(TIM_POWERMEAS);
928 SET_STATE (STATE_CS, CS_NULL);
929 nc_stop_ext_meas_ind();
930 return;
931 }
932
933 switch (GET_STATE (STATE_CS))
934 {
935 case CS_MEASURED:
936
937 /* increment the number of measurement samples */
938 alr_data->cs_data.c_meas++;
939
940 if (alr_data->cs_data.c_meas EQ alr_data->cs_data.c_max_meas)
941 {
942 /* Allocate memory for MPH_POWER_CNF */
943 PALLOC (mph_power_cnf, MPH_POWER_CNF);
944
945 if (alr_data->cs_data.p_power_cnf)
946 {
947 PFREE (alr_data->cs_data.p_power_cnf);
948 }
949
950 alr_data->cs_data.p_power_cnf = mph_power_cnf;
951
952 memset (alr_data->cs_data.p_power_cnf, 0, sizeof (T_MPH_POWER_CNF));
953
954 TIMERSTOP(TIM_POWERMEAS);
955
956 /* Sort the channels based on their RxLev */
957 cs_add_and_sort_channels ();
958
959 if(!IS_EXT_MEAS_RUNNING)
960 {
961 /* Free MPH_POWER_REQ buffer */
962 PFREE(alr_data->cs_data.p_power_req);
963
964 alr_data->cs_data.p_power_req = NULL;
965 }
966
967 /* Send fieldstrength list to RR */
968 ma_cs_power_cnf (mph_power_cnf);
969
970 /* we are done with power measurements, next comes the BCCH detection */
971 SET_STATE (STATE_CS, CS_NULL);
972
973 alr_data->cs_data.p_power_cnf = NULL;
974
975 ALR_EM_POWER_MEASUREMENT_CONFIRM;
976 }
977 else
978 if (alr_data->cs_data.c_meas < alr_data->cs_data.c_max_meas)
979 {
980 /*
981 * start next sample
982 */
983 if ((alr_data->cs_data.freq_area & ALL_FREQ_AREA) EQ ALL_FREQ_AREA)
984 { /*
985 * toggle radio_band and configure new before the next measurement
986 */
987 TRACE_EVENT_P2 ("cs_rxlev_ind(): area=%02x->%02x",
988 alr_data->cs_data.freq_area,
989 alr_data->cs_data.freq_area^NEXT_AMERICAN_AREA);
990 alr_data->cs_data.freq_area ^= NEXT_AMERICAN_AREA;
991 #ifndef TI_PS_FF_QUAD_BAND_SUPPORT
992 SET_STATE (STATE_CS, CS_INIT_L1);
993 #endif
994 }
995 #ifndef TI_PS_FF_QUAD_BAND_SUPPORT
996 else
997 { /*
998 * start new measurement without new configuration of radio_band
999 */
1000 #endif
1001 SET_STATE (STATE_CS, CS_START_MEASURE);
1002 #ifndef TI_PS_FF_QUAD_BAND_SUPPORT
1003 }
1004 #endif
1005 ma_cs_rxlev_req ();
1006 }
1007 break;
1008
1009 default:
1010 break;
1011 }
1012 }
1013
1014 /*
1015 +--------------------------------------------------------------------+
1016 | PROJECT : GSM-PS (8403) MODULE : ALR_CS |
1017 | STATE : code ROUTINE : cs_network_sync_ind |
1018 +--------------------------------------------------------------------+
1019
1020 PURPOSE : The function handles the result of a search for FCB or SCB.
1021
1022 */
1023
1024 GLOBAL void cs_network_sync_ind (T_MPHC_NETWORK_SYNC_IND* sync_ind)
1025 {
1026 GET_INSTANCE_DATA;
1027 PALLOC (mph_bsic_cnf, MPH_BSIC_CNF);
1028
1029 alr_data->cs_data.sync_active = FALSE;
1030 /*
1031 * The BCCH fail counter has to be reinitialized for every new cell.
1032 */
1033 alr_data->cs_data.bcch_fail_count = CS_BCCH_FAIL_COUNT_MAX;
1034 /*
1035 * copy arfcn, rxlev and bsic
1036 */
1037 mph_bsic_cnf->arfcn = ARFCN_STD_TO_G23(sync_ind->radio_freq, alr_data->cs_data.std);
1038 mph_bsic_cnf->arfcn = STD_ADD_TO_ARFCN(mph_bsic_cnf->arfcn, alr_data->cs_data.std);
1039 /* US_BIT should be used to differentiate an US frequency channel. */
1040 switch (alr_data->cs_data.std)
1041 {
1042 case STD_1900:
1043 case STD_850:
1044 case STD_DUAL_US:
1045 mph_bsic_cnf->arfcn |= US_BIT;
1046 break;
1047 #ifdef TI_PS_FF_QUAD_BAND_SUPPORT
1048 case STD_850_1800:
1049 case STD_850_900_1800:
1050 if ((mph_bsic_cnf->arfcn >= LOW_CHANNEL_850) && (mph_bsic_cnf->arfcn <= HIGH_CHANNEL_850))
1051 mph_bsic_cnf->arfcn |= US_BIT;
1052 break;
1053 case STD_900_1900:
1054 if ((mph_bsic_cnf->arfcn >= LOW_CHANNEL_1900) && (mph_bsic_cnf->arfcn <= HIGH_CHANNEL_1900))
1055 mph_bsic_cnf->arfcn |= US_BIT;
1056 break;
1057 case STD_850_900_1900:
1058 if (mph_bsic_cnf->arfcn >= HIGH_CHANNEL_900)
1059 mph_bsic_cnf->arfcn |= US_BIT;
1060 break;
1061 #endif
1062 default:
1063 break;
1064 }
1065
1066 /*
1067 * set bsic and result code
1068 */
1069 mph_bsic_cnf->bsic = (UBYTE)(sync_ind->bsic & 63);
1070 mph_bsic_cnf->cs = sync_ind->sb_flag ? CS_NO_ERROR : CS_NO_BCCH_AVAIL;
1071
1072 /* Implements Measure#32: Row 21 and 22 */
1073 if (sync_ind->sb_flag)
1074 {
1075 TRACE_EVENT_P3 ("network_sync_ind:[%u] rf=%u cs_std=%u OK",
1076 mph_bsic_cnf->arfcn&ARFCN_MASK,
1077 sync_ind->radio_freq, alr_data->cs_data.std);
1078 }
1079 else
1080 {
1081 TRACE_EVENT_P3 ("network_sync_ind:[%u] rf=%u cs_std=%u no BCCH avail.",
1082 mph_bsic_cnf->arfcn&ARFCN_MASK,
1083 sync_ind->radio_freq, alr_data->cs_data.std);
1084 }
1085
1086 switch (GET_STATE(STATE_CS))
1087 {
1088 /*
1089 * workarounds for crossing MPHC_STOP_NETWORK_SYNC_REQ and
1090 * MPHC_NETWORK_SYNC_IND:
1091 * It is possible to receive a MPHC_NETWORK_SYNC_IND from layer 1 at the
1092 * same time as sending a MPHC_STOP_NETWORK_SYNC_REQ. The
1093 * MPHC_STOP_NETWORK_SYNC_REQ will be ignored by the layer 1 and no
1094 * STOP_NW_SYNC_CON will be send.
1095 */
1096 case CS_STOP_SYNC:
1097 /* The state CS_STOP_SYNC was set and the MPHC_NETWORK_SYNC_REQ was
1098 * interrupted to clean the way for a new MPHC_NETWORK_SYNC_REQ. A possible
1099 * MPHC_NETWORK_SYNC_IND will be treated as MPHC_STOP_NETWORK_SYNC_CON
1100 * because the result does not matter.
1101 */
1102 SET_STATE (STATE_CS, CS_STOP_SYNC_DONE);
1103 cs_bsic_req(NULL);
1104 /*lint -fallthrough */
1105 default:
1106 /*
1107 * the synchronisation has been broken
1108 */
1109 ALR_TRACE_CS ("MPHC_NETWORK_SYNC_IND ignored");
1110 PFREE (mph_bsic_cnf);
1111 return;
1112 /* break; */
1113
1114 case CS_NW_SYNC_TIMEOUT:
1115 /*
1116 * The state CS_NW_SYNC_TIMEOUT was set and the MPHC_NETWORK_SYNC_REQ was
1117 * interrupted to limit the time for reading the BCCH. A possible
1118 * MPHC_NETWORK_SYNC_IND will be treated normal. Otherwise, no BSIC_CNF
1119 * will be sent to RR, and RR waits forever.
1120 */
1121 SET_STATE(STATE_CS, CS_ACTIVE_SYNC);
1122 /*lint -fallthrough */
1123 case CS_ACTIVE_SYNC:
1124 ma_bsic_cnf (mph_bsic_cnf);
1125 break;
1126 }
1127
1128 #ifdef GPRS
1129 if(alr_data->gprs_data.pcco_active)
1130 {
1131 USHORT index;
1132 /* store data in nc_data.cr_cell */
1133 alr_data->nc_data.cr_cell.ba_arfcn =
1134 ARFCN_TO_G23(sync_ind->radio_freq)&ARFCN_MASK;
1135 alr_data->nc_data.cr_cell.bsic = (UBYTE)(sync_ind->bsic & 63);
1136 alr_data->nc_data.cr_cell.frame_offset = sync_ind->fn_offset;
1137 alr_data->nc_data.cr_cell.time_align = sync_ind->time_alignment;
1138
1139 index = nc_get_index(alr_data->nc_data.cr_cell.ba_arfcn);
1140 if ((index NEQ NOT_PRESENT_16BIT) AND (index NEQ LAST_BSIC_REQ))
1141 {
1142 /*
1143 * update in nc_data also because this data is not valid
1144 * anymore after a network_sync_req and in some special cases
1145 * nc_start_reselect will use the data in nc_data.cell[index]
1146 */
1147 alr_data->nc_data.cell[index].bsic = (UBYTE)(sync_ind->bsic & 63);
1148 alr_data->nc_data.cell[index].frame_offset = sync_ind->fn_offset;
1149 alr_data->nc_data.cell[index].time_align = sync_ind->time_alignment;
1150 }
1151 SET_STATE(STATE_CS, CS_NULL);
1152 return;
1153 }
1154 #endif
1155 if (sync_ind->sb_flag)
1156 {
1157 if (GET_STATE (STATE_CS) EQ CS_ACTIVE_SYNC)
1158 {
1159 USHORT arfcn;
1160 PALLOC(new_scell, MPHC_NEW_SCELL_REQ);
1161
1162 arfcn = ARFCN_STD_TO_G23(sync_ind->radio_freq, alr_data->cs_data.std);
1163 ALR_TRACE_CS_SYNC_VALID(arfcn, sync_ind->fn_offset,
1164 sync_ind->time_alignment);
1165
1166 /* store data in nc_data.cr_cell */
1167 alr_data->nc_data.cr_cell.ba_arfcn =
1168 ARFCN_TO_G23(sync_ind->radio_freq)&ARFCN_MASK;
1169 alr_data->nc_data.cr_cell.bsic = sync_ind->bsic;
1170 alr_data->nc_data.cr_cell.frame_offset = 0;
1171 alr_data->nc_data.cr_cell.time_align = 0;
1172
1173 new_scell->radio_freq = sync_ind->radio_freq;
1174 new_scell->fn_offset = sync_ind->fn_offset;
1175 new_scell->time_alignment = sync_ind->time_alignment;
1176 new_scell->tsc = sync_ind->bsic;
1177
1178 ALR_EM_BSIC_CONFIRM(EM_AVAIL);
1179
1180 /* after successful sync we can use narrow band search mode for
1181 * subsequent syncs.
1182 */
1183 alr_data->cs_data.search_mode = SM_NARROW_MODE;
1184 alr_data->cs_data.sync_fail_count = CS_SYNC_FAIL_COUNT_MAX;
1185
1186 alr_data->sc_band = get_band (arfcn);
1187 ma_new_scell_req(new_scell);
1188 }
1189 }
1190 else
1191 {
1192 ALR_TRACE_CS ("INVALID BLOCK");
1193
1194 ALR_EM_BSIC_CONFIRM(EM_NOT_AVAIL);
1195 /* If there are too many failed sync attempts in a row the AFC value
1196 * in L1 might be screwed up somehow.
1197 */
1198 if(alr_data->cs_data.sync_fail_count EQ 0)
1199 {
1200 alr_data->cs_data.sync_fail_count = CS_SYNC_FAIL_COUNT_MAX;
1201 alr_data->cs_data.search_mode = SM_WIDE_MODE;
1202 }
1203 else
1204 {
1205 alr_data->cs_data.sync_fail_count -= 1;
1206 }
1207
1208 }
1209 SET_STATE(STATE_CS, CS_NULL);
1210 }
1211
1212
1213 /*
1214 +--------------------------------------------------------------------+
1215 | PROJECT : GSM-PS (8403) MODULE : ALR_CS |
1216 | STATE : code ROUTINE : cs_stop |
1217 +--------------------------------------------------------------------+
1218
1219 PURPOSE : Process signal cs_stop from SDL process
1220 Main_Control. This function stops all cell selection
1221 activities of ALR.
1222
1223 */
1224
1225 GLOBAL void cs_stop (void)
1226 {
1227 GET_INSTANCE_DATA;
1228 switch (GET_STATE (STATE_CS))
1229 {
1230 case CS_ACTIVE_MEASURE:
1231 {
1232 PALLOC (stop_req, MPHC_STOP_RXLEV_REQ);
1233 PSENDX (L1, stop_req);
1234 if ( IS_EXT_MEAS_RUNNING )
1235 {
1236 /* wait for MPHC_RXLEV_IND */
1237 alr_data->cs_data.ext_meas_state_pend = CS_ACTIVE_MEASURE;
1238 }
1239 break;
1240 }
1241 case CS_ACTIVE_SYNC:
1242 {
1243 PALLOC (stop_req, MPHC_STOP_NETWORK_SYNC_REQ);
1244 TIMERSTOP(TIM_NW_SYNC_GUARD);
1245 PSENDX (L1, stop_req);
1246 break;
1247 }
1248 case CS_ACTIVE_BCCH:
1249 /*
1250 * Stop BCCH reading
1251 */
1252 ma_stop_scell_bcch_req ();
1253 break;
1254 default:
1255 break;
1256 }
1257 SET_STATE (STATE_CS, CS_NULL);
1258 }
1259
1260 /*
1261 +--------------------------------------------------------------------+
1262 | PROJECT : GSM-PS (8403) MODULE : ALR_CS |
1263 | STATE : code ROUTINE : cs_read_scell_bcch |
1264 +--------------------------------------------------------------------+
1265
1266 PURPOSE : Process signal cs_read_scell_bcch from SDL process
1267 Main_Control. This funtion requests reading of the full
1268 serving cell BCCH.
1269
1270 */
1271 GLOBAL void cs_read_scell_bcch (void)
1272 {
1273 GET_INSTANCE_DATA;
1274 /*
1275 * send bcch req
1276 * do full normal BCCH reading(modulus=1,position=0)
1277 */
1278 SET_STATE(STATE_CS, CS_ACTIVE_BCCH);
1279 ma_scell_full_nbcch();
1280 }
1281
1282
1283 /*
1284 +--------------------------------------------------------------------+
1285 | PROJECT : GSM-PS (8403) MODULE : ALR_CS |
1286 | STATE : code ROUTINE : cs_add_and_sort_channels |
1287 +--------------------------------------------------------------------+
1288
1289 PURPOSE : Accumulate power measurements for all found channels
1290 sorted by highest fieldstrength.
1291 */
1292
1293 LOCAL void cs_add_and_sort_channels (void)
1294 {
1295 GET_INSTANCE_DATA;
1296 T_MPH_POWER_CNF* mph_power_cnf = alr_data->cs_data.p_power_cnf;
1297 T_MPH_POWER_REQ* mph_power_req = alr_data->cs_data.p_power_req;
1298 T_POWER_MEAS *p_results[MAX_REGIONS];
1299 T_POWER_ARRAY *parray, *pbig, *last;
1300 SHORT rxlev, min_rxlev[MAX_NUM_BANDS+1];
1301 /*lint -e644 (Warning -- Variable 'band_index' may not have been initialized) */
1302 UBYTE x, band_index = 0;
1303 /*lint +e644 (Warning -- Variable 'band_index' may not have been initialized) */
1304 U16 i, j, p_results_size[MAX_REGIONS], arfcn;
1305 U8 radio_band_config, std[MAX_REGIONS];
1306 U8 no_of_attempts, region, where_to_add;
1307 U8 i_cnf, extra_cnf, extra_space;
1308 U8 no_of_carriers_per_band[4] = {0, 0, 0, 0}; /* Counter for Multible frequency band in a Region
1309 * Index 0 for GSM_900,
1310 * Index 1 for DCS_1800,
1311 * Index 2 for GSM_850,
1312 * Index 3 for PCS_1900
1313 */
1314 /* Obtain data for European region */
1315 p_results[EUROPEAN_REGION] = alr_data->cs_data.p_results1;
1316 p_results_size[EUROPEAN_REGION] = alr_data->cs_data.p_results1 ?
1317 (alr_data->cs_data.p_results1->power_array_size) : 0;
1318
1319 /* Obtain data for American region */
1320 p_results[AMERICAN_REGION] = alr_data->cs_data.p_results2;
1321 p_results_size[AMERICAN_REGION] = alr_data->cs_data.p_results2 ?
1322 alr_data->cs_data.p_results2->power_array_size : 0;
1323
1324 TRACE_FUNCTION ( "cs_add_and_sort_channels()" );
1325
1326 if (!mph_power_cnf)
1327 {
1328 TRACE_EVENT ("mph_power_cnf EQ NULL");
1329 SET_STATE (STATE_CS, CS_NULL);
1330 return;
1331 }
1332
1333 i_cnf = 0;
1334 extra_cnf = MAX_CHANNELS - 1;
1335 mph_power_cnf->num_of_chan = 0;
1336
1337
1338 /* Set the minimum signal level */
1339 if ( IS_EXT_MEAS_RUNNING )
1340 {
1341 no_of_attempts = power_scan_attempts[FULL_SEARCH_MODE];
1342 for(x=0 ; x<=MAX_NUM_BANDS ; x++ )
1343 min_rxlev[x] = SHRT_MIN + 1;
1344 }
1345 else
1346 {
1347 if (!mph_power_req)
1348 {
1349 TRACE_EVENT ("mph_power_req EQ NULL");
1350 SET_STATE (STATE_CS, CS_NULL);
1351 return;
1352 }
1353
1354 no_of_attempts = power_scan_attempts[mph_power_req->search_mode];
1355 for(x=0 ; x<MAX_NUM_BANDS ; x++ )
1356 min_rxlev[x] = mph_power_req->lower_rxlevel_threshold[x] * no_of_attempts;
1357 /* If the std value cannot be retreived use the
1358 * default lower_rxlev_threshold value of 4
1359 */
1360 min_rxlev[MAX_NUM_BANDS] = LOWER_RXLEV_THRESHOLD;
1361 }
1362
1363 TRACE_EVENT_P5 ("cs_add_and_sort_channels: std12=%02x max=%u/%u a='%c%c'",
1364 alr_data->cs_data.std12,
1365 p_results_size[EUROPEAN_REGION],
1366 p_results_size[AMERICAN_REGION],
1367 (alr_data->cs_data.freq_area & EUROPEAN_FREQ_AREA) ? 'E' : ' ',
1368 (alr_data->cs_data.freq_area & AMERICAN_FREQ_AREA) ? 'A' : ' ');
1369
1370 if ((alr_data->cs_data.freq_area&ALL_FREQ_AREA) EQ ALL_FREQ_AREA)
1371 {
1372 /* use 'std' values saved by cs_prepare_power_req() */
1373 std[EUROPEAN_REGION] = alr_data->cs_data.std12&0x0f;
1374 std[AMERICAN_REGION] = alr_data->cs_data.std12>>4;
1375 }
1376 else
1377 {
1378 /* only one area */
1379 std[EUROPEAN_REGION] = std[AMERICAN_REGION] = alr_data->cs_data.std;
1380 if (alr_data->cs_data.freq_area & EUROPEAN_FREQ_AREA)
1381 p_results_size[AMERICAN_REGION] = 0;
1382 if (alr_data->cs_data.freq_area & AMERICAN_FREQ_AREA)
1383 p_results_size[EUROPEAN_REGION] = 0;
1384 }
1385
1386 if( IS_EXT_MEAS_RUNNING )
1387 {
1388 /*
1389 * According to 3GPP 05 08
1390 * Section "Range of parameter RxLev"
1391 *
1392 * The measured signal level shall be mapped to an RXLEV value between 0 and 63, as follows:
1393 * RXLEV 0 = less than -110 dBm + SCALE.
1394 * RXLEV 1 = -110 dBm + SCALE to -109 dBm + SCALE.
1395 * RXLEV 2 = -109 dBm + SCALE to -108 dBm + SCALE.
1396 * :
1397 * :
1398 * RXLEV 62 = -49 dBm + SCALE to -48 dBm + SCALE.
1399 * RXLEV 63 = greater than -48 dBm + SCALE.
1400 * where SCALE is an offset that is used only in the ENHANCED MEASUREMENT REPORT message,
1401 * otherwise it is set to 0.
1402 */
1403
1404 for(i=0; i < p_results_size[EUROPEAN_REGION]; i++)
1405 if( p_results[EUROPEAN_REGION]->power_array->accum_power_result < 0 )
1406 p_results[EUROPEAN_REGION]->power_array->accum_power_result = 0;
1407
1408 for(i=0; i < p_results_size[AMERICAN_REGION]; i++)
1409 if( p_results[AMERICAN_REGION]->power_array->accum_power_result < 0 )
1410 p_results[AMERICAN_REGION]->power_array->accum_power_result = 0;
1411 }
1412 else
1413 {
1414 /* LLD Section : 4.1.3.4.2
1415 * Find all inactive carriers and add them to MPH_POER_CNF
1416 * Also set the Rxlev of all Black Listed carriers to less than
1417 * Lower_Rxlev_Threshold
1418 */
1419
1420 TRACE_EVENT_P2("BIC->PWR array size, E:%d, A:%d",
1421 p_results_size[0], p_results_size[1]);
1422
1423 cs_find_inactive_carriers(p_results, p_results_size,
1424 std, no_of_attempts,
1425 min_rxlev);
1426
1427 TRACE_EVENT_P2("AIC->PWR array size, E:%d, A:%d",
1428 p_results_size[0], p_results_size[1]);
1429
1430 /*
1431 * If the search mode is BLACK_LIST_SEARCH_MODE no need for sorting
1432 * (based on RXLEV) the carriers (RR will look only for
1433 * inactive carrier list)
1434 */
1435 if(mph_power_req->search_mode EQ BLACK_LIST_SEARCH_MODE)
1436 {
1437 /* Allow measurement indications posting to RR */
1438 SET_STATE(STATE_NC,NC_IDLE);
1439 return;
1440 }
1441
1442 /* Put whitelist carriers at the top of power cnf list */
1443 if(mph_power_req->white_list.white_list_valid)
1444 {
1445 region = mph_power_req->white_list.region;
1446
1447 switch(mph_power_req->white_list.region)
1448 {
1449 case EUROPEAN_REGION :
1450 case AMERICAN_REGION :
1451 #ifdef TI_PS_FF_QUAD_BAND_SUPPORT
1452 case BOTH_REGIONS:
1453 i_cnf = cs_add_whitelist_carriers(p_results_size, std,
1454 no_of_attempts,
1455 min_rxlev, p_results,
1456 no_of_carriers_per_band);
1457 #else
1458 i_cnf = cs_add_whitelist_carriers(p_results_size,
1459 std[region], no_of_attempts,
1460 min_rxlev, p_results[region],
1461 no_of_carriers_per_band);
1462 #endif
1463 TRACE_EVENT_P5(
1464 "[%c]White list Area (B_GSM_EGSM:%d, B_1800:%d, B_850:%d, B_1900:%d)",
1465 (mph_power_req->white_list.region ? 'A' : 'E'),
1466 no_of_carriers_per_band[0], no_of_carriers_per_band[1],
1467 no_of_carriers_per_band[2], no_of_carriers_per_band[3]);
1468 break;
1469 default :
1470 TRACE_EVENT_P1("Invalid whitelist region:%d",region);
1471 break;
1472 }
1473 } /* white list valid */
1474 else
1475 {
1476 TRACE_EVENT("WL is absent");
1477 }
1478 } /* !ext_meas */
1479
1480 TRACE_EVENT_P3("AWL->PWR array size, E:%d A:%d i_cnf:%d",
1481 p_results_size[0], p_results_size[1],i_cnf);
1482
1483 while (i_cnf < MAX_CHANNELS)
1484 {
1485 pbig=NULL;
1486 rxlev = 0;
1487 radio_band_config = where_to_add =0x00;
1488
1489 /* Loop through both regions */
1490 for (i=0;i<MAX_REGIONS;i++)
1491 {
1492 if((p_results_size[i]) AND (p_results[i] NEQ NULL))
1493 {
1494 parray = p_results[i]->power_array;
1495
1496 for (j=0; j<p_results_size[i]; j++, parray++)
1497 {
1498 arfcn = ARFCN_STD_TO_G23(parray->radio_freq, std[i]);
1499 /*lint -e661 (Warning -- Possible access of out-of-bounds) */
1500 get_band_index_from_arfcn(arfcn, x, std[i]);
1501 if (parray->accum_power_result >= min_rxlev[x] AND parray->accum_power_result > rxlev)
1502 {
1503 pbig = parray;
1504 rxlev = parray->accum_power_result;
1505 radio_band_config = std[i];
1506 region = (U8) i;
1507 band_index = x;
1508 }
1509 /*lint +e661 (Warning -- Possible access of out-of-bounds) */
1510 }
1511 }
1512 }
1513
1514 if( pbig NEQ NULL )
1515 {
1516 arfcn = ARFCN_STD_TO_G23(pbig->radio_freq, radio_band_config);
1517 if (rxlev > (min_rxlev[band_index] -1))
1518 {
1519 /* fill mph_power_cnf */
1520 arfcn = STD_ADD_TO_ARFCN(arfcn, radio_band_config);
1521
1522 /* US_BIT should be used to differentiate an US frequency channel. */
1523 switch (radio_band_config)
1524 {
1525 case STD_1900:
1526 case STD_850:
1527 case STD_DUAL_US:
1528 arfcn |= US_BIT;
1529 break;
1530 default:
1531 break;
1532 }
1533
1534 where_to_add = cs_restrict_max_carriers_per_band(
1535 arfcn&ARFCN_MASK,
1536 radio_band_config,
1537 no_of_carriers_per_band,
1538 p_results_size, min_rxlev[band_index]);
1539
1540 if(where_to_add EQ ADD_AT_THE_TOP)
1541 {
1542 /* First 40 Strongest Cariiers */
1543 mph_power_cnf->arfcn[i_cnf] = arfcn;
1544 mph_power_cnf->rx_lev[i_cnf] = (U8)(rxlev/no_of_attempts);
1545
1546 i_cnf++;
1547 }
1548 else if(where_to_add EQ ADD_AT_THE_BOTTOM)
1549 {
1550 /* Strongest Carriers which fall between 41 to 60 */
1551 if(extra_cnf >= i_cnf)
1552 {
1553 mph_power_cnf->arfcn[extra_cnf] = arfcn;
1554 mph_power_cnf->rx_lev[extra_cnf] = (U8)(rxlev/no_of_attempts);
1555
1556 extra_cnf--;
1557 }
1558 else
1559 {
1560 TRACE_EVENT_P2("MPH_POWER_CNF crossover, i_cnf: %d extra_cnf: %d",
1561 i_cnf, extra_cnf);
1562 }
1563 }
1564
1565 /* After adding a carrier to MPH_POWER_CNF, the particular carrier will be
1566 * replaced by the Last carrier of that region. So that we could avoid
1567 * searching the already added (MPH_POWER_CNF) carrier.
1568 */
1569 if(where_to_add NEQ REACHED_THE_MAXIMUM)
1570 {
1571 last = p_results[region]->power_array + (p_results_size[region]-1);/*lint !e644 region may not have been initialized */
1572
1573 pbig->accum_power_result = min_rxlev[band_index] - 1;
1574
1575 cs_power_array_swap_arfcn(pbig, last);
1576
1577 p_results_size[region]--;
1578 }
1579 else
1580 {
1581 TRACE_EVENT_P4("RTM->PWR array size, E:%d A:%d i_cnf:%d extra_cnf:%d",
1582 p_results_size[0], p_results_size[1],i_cnf,
1583 (MAX_CHANNELS-(extra_cnf+1)));
1584 }
1585 }
1586 }
1587 else
1588 break; /* no level found higher or equal than min_rxlev -> break sort/fill */
1589
1590 }/* while (i_cnf < MAX_CHANNELS) */
1591
1592 mph_power_cnf->num_of_chan = i_cnf;
1593
1594 /* Obtain the number of extra channels(41 to 60) added to
1595 * Power cnf array
1596 */
1597 extra_cnf = MAX_CHANNELS - (extra_cnf+1);
1598
1599 /* Obtain the amount of space available for extra channels
1600 * in power_cnf array
1601 */
1602 extra_space = MAX_CHANNELS - i_cnf;
1603
1604 TRACE_EVENT_P3("After Sorting, i_cnf:%d extra_cnf:%d extra_space:%d",
1605 i_cnf,extra_cnf,(extra_space-extra_cnf));
1606
1607 if(extra_cnf AND extra_space)
1608 {
1609 /* Extra channels are present and space to fit them is also available */
1610 if(extra_space < extra_cnf)
1611 {
1612 /* Some of the extra channels(41 to 60) are overwritten
1613 * Ignore them
1614 */
1615 extra_cnf = extra_space;
1616 }
1617
1618 /* Reordering the carriers(41 to 60) from Strongest to Weakest */
1619 cs_reorder_the_extra_carriers(extra_cnf);
1620
1621 /* Move the extra carriers up in power_cnf array, in case there
1622 * is empty gap between i_cnf and extra_cnf channels
1623 */
1624 if(extra_space > extra_cnf)
1625 cs_move_extra_carriers(i_cnf, extra_cnf);
1626
1627 mph_power_cnf->num_of_chan += extra_cnf;
1628 }
1629
1630 TRACE_EVENT_P5(
1631 "No. of carriers in POWER_CNF:%d (B_GSM_EGSM:%d, B_1800:%d, B_850:%d, B_1900:%d)",
1632 mph_power_cnf->num_of_chan,
1633 no_of_carriers_per_band[0], no_of_carriers_per_band[1],
1634 no_of_carriers_per_band[2], no_of_carriers_per_band[3]);
1635 }
1636
1637
1638
1639 /*
1640 +--------------------------------------------------------------------+
1641 | PROJECT : GSM-PS (8403) MODULE : ALR_CS |
1642 | STATE : code ROUTINE : get_band |
1643 +--------------------------------------------------------------------+
1644
1645 PURPOSE : The function extracts the frequency band from the given
1646 'arfcn' parameter.
1647 */
1648
1649 GLOBAL UBYTE get_band (USHORT arfcn)
1650 {
1651 UBYTE local_std = STD_GET_FROM_ARFCN(arfcn);
1652 UBYTE sc_band;
1653
1654 if (local_std EQ 0)
1655 local_std = std;
1656
1657 switch (local_std)
1658 {
1659 case STD_900:
1660 sc_band = BAND_GSM_900;
1661 break;
1662
1663 case STD_EGSM:
1664 sc_band = BAND_E_GSM;
1665 break;
1666
1667 case STD_1800:
1668 sc_band = BAND_DCS_1800;
1669 break;
1670
1671 case STD_1900:
1672 sc_band = BAND_PCS_1900;
1673 break;
1674
1675 case STD_850:
1676 sc_band = BAND_GSM_850;
1677 break;
1678
1679 case STD_DUAL:
1680 if (arfcn >= LOW_CHANNEL_1800)
1681 sc_band = BAND_DCS_1800;
1682 else
1683 sc_band = BAND_GSM_900;
1684 break;
1685
1686 case STD_DUAL_EGSM:
1687 if (arfcn >= LOW_CHANNEL_EGSM)
1688 sc_band = BAND_E_GSM;
1689 else if (arfcn >= LOW_CHANNEL_1800)
1690 sc_band = BAND_DCS_1800;
1691 else if (arfcn EQ CHANNEL_0)
1692 sc_band = BAND_E_GSM;
1693 else
1694 sc_band = BAND_GSM_900;
1695 break;
1696
1697 case STD_DUAL_US:
1698 if (arfcn >= LOW_CHANNEL_1900)
1699 sc_band = BAND_PCS_1900;
1700 else
1701 sc_band = BAND_GSM_850;
1702 break;
1703
1704 #ifdef TI_PS_FF_QUAD_BAND_SUPPORT
1705 case STD_850_1800:
1706 if (arfcn >= LOW_CHANNEL_1800)
1707 sc_band = BAND_DCS_1800;
1708 else
1709 sc_band = BAND_GSM_850;
1710 break;
1711
1712 case STD_900_1900:
1713 if (arfcn >= LOW_CHANNEL_EGSM)
1714 sc_band = BAND_E_GSM;
1715 else if (arfcn >= LOW_CHANNEL_1900)
1716 sc_band = BAND_PCS_1900;
1717 else if (arfcn EQ CHANNEL_0)
1718 sc_band = BAND_E_GSM;
1719 else
1720 sc_band = BAND_GSM_900;
1721 break;
1722
1723 case STD_850_900_1800:
1724 if (arfcn >= LOW_CHANNEL_EGSM)
1725 sc_band = BAND_E_GSM;
1726 else if (arfcn >= LOW_CHANNEL_1800)
1727 sc_band = BAND_DCS_1800;
1728 else if (arfcn EQ CHANNEL_0)
1729 sc_band = BAND_E_GSM;
1730 else if (arfcn >= LOW_CHANNEL_850)
1731 sc_band = BAND_GSM_850;
1732 else
1733 sc_band = BAND_GSM_900;
1734 break;
1735
1736 case STD_850_900_1900:
1737 if (arfcn >= LOW_CHANNEL_EGSM)
1738 sc_band = BAND_E_GSM;
1739 else if (arfcn >= LOW_CHANNEL_1900)
1740 sc_band = BAND_PCS_1900;
1741 else if (arfcn EQ CHANNEL_0)
1742 sc_band = BAND_E_GSM;
1743 else if (arfcn >= LOW_CHANNEL_850)
1744 sc_band = BAND_GSM_850;
1745 else
1746 sc_band = BAND_GSM_900;
1747 break;
1748 #endif
1749
1750 default:
1751 sc_band = 0;
1752 break;
1753 }
1754 /* this trace causes a lot of trace load; switch on only if needed
1755 TRACE_EVENT_P2 ("[%u] sc_band=%02x", arfcn&ARFCN_MASK, sc_band);
1756 */
1757 return sc_band;
1758 }
1759
1760 /*
1761 +--------------------------------------------------------------------+
1762 | PROJECT : GSM-PS (8403) MODULE : ALR_CS |
1763 | STATE : code ROUTINE : cs_increment_bfc |
1764 +--------------------------------------------------------------------+
1765
1766 PURPOSE : The function increments the BCCH fail counter. This
1767 counter is decremented on every invalid BCCH block read
1768 during CS. It is incremented on evry valid block read on
1769 BCCH during CS. Valid means in this case that there was a
1770 SYS Info decodable in the block on the BCCH. There is a
1771 maximum value to start with and when the counter reaches
1772 0 we switch back to wide band search mode for further
1773 MPHC_NETWORK_SYNC_REQs (if any).
1774 */
1775
1776 GLOBAL void cs_increment_bfc (void)
1777 {
1778 GET_INSTANCE_DATA;
1779 alr_data->cs_data.bcch_fail_count += 1;
1780 if(alr_data->cs_data.bcch_fail_count > CS_BCCH_FAIL_COUNT_MAX)
1781 alr_data->cs_data.bcch_fail_count = CS_BCCH_FAIL_COUNT_MAX;
1782 }
1783
1784
1785 /*
1786 +--------------------------------------------------------------------+
1787 | PROJECT : GSM-PS (8403) MODULE : ALR_CS |
1788 | STATE : code ROUTINE : cs_decrement_bfc |
1789 +--------------------------------------------------------------------+
1790
1791 PURPOSE : The function decrements the BCCH fail counter. This
1792 counter is decremented on every invalid BCCH block read
1793 during CS. It is incremented on evry valid block read on
1794 BCCH during CS. Valid means in this case that there was a
1795 SYS Info decodable in the block on the BCCH. There is a
1796 maximum value to start with and when the counter reaches
1797 0 we switch back to wide band search mode for further
1798 MPHC_NETWORK_SYNC_REQs (if any).
1799 */
1800
1801 GLOBAL void cs_decrement_bfc (void)
1802 {
1803 GET_INSTANCE_DATA;
1804 if(alr_data->cs_data.bcch_fail_count < 3)
1805 {
1806 alr_data->cs_data.bcch_fail_count = 0;
1807 alr_data->cs_data.search_mode = SM_WIDE_MODE;
1808 }
1809 else
1810 alr_data->cs_data.bcch_fail_count -= 2;
1811
1812 }
1813
1814
1815 /*
1816 +--------------------------------------------------------------------+
1817 | PROJECT : GSM-PS (8403) MODULE : ALR_CS |
1818 | STATE : code ROUTINE : cs_set_wideband_sync |
1819 +--------------------------------------------------------------------+
1820
1821 PURPOSE : The function sets wide band search mode for further
1822 MPHC_NETWORK_SYNC_REQs (if any).
1823 */
1824
1825 GLOBAL void cs_set_wideband_sync (void)
1826 {
1827 GET_INSTANCE_DATA;
1828 alr_data->cs_data.search_mode = SM_WIDE_MODE;
1829 }
1830
1831 /*
1832 +--------------------------------------------------------------------+
1833 | PROJECT : GSM-PS (8403) MODULE : ALR_CS |
1834 | STATE : code ROUTINE : cs_is_in_black_list |
1835 +--------------------------------------------------------------------+
1836
1837 PURPOSE : The function checks whether the given carrier is in the
1838 Blacklist or not
1839 CSI-LLD section: 4.1.3.4.2.1
1840 */
1841
1842 LOCAL BOOL cs_is_in_black_list(U8 region,U16 arfcn)
1843 {
1844 GET_INSTANCE_DATA;
1845 BOOL ret = FALSE;
1846
1847 if((region EQ EUROPEAN_REGION) OR (region EQ AMERICAN_REGION))
1848 {
1849 if(alr_data->cs_data.p_power_req->search_mode EQ FULL_SEARCH_MODE)
1850 {
1851 return ret;
1852 }
1853
1854 ret = srv_get_channel((T_LIST*)&alr_data->cs_data.p_power_req->black_list.list[region],
1855 arfcn&ARFCN_MASK);
1856
1857 if(ret)
1858 {
1859 if(srv_get_region_from_std(alr_data->cs_data.std) == region
1860 AND nc_is_in_ba(arfcn&ARFCN_MASK))
1861 {
1862 TRACE_EVENT_P1 ("ARFCN %d found in BA and Black list", arfcn & ARFCN_MASK);
1863 ret = FALSE;
1864 }
1865 }
1866
1867 }
1868 return ret;
1869 }
1870
1871 /*
1872 +--------------------------------------------------------------------+
1873 | PROJECT : GSM-PS (8403) MODULE : ALR_CS |
1874 | STATE : code ROUTINE : cs_find_inactive_carriers |
1875 +--------------------------------------------------------------------+
1876
1877 PURPOSE : 1. Finds all inactive carriers
1878 2. Sets the RxLev of all Blacklisted carriers to less than
1879 LOWER_RXLEV_THRESHOLD
1880 CSI-LLD Section: 4.1.3.8.2.2.1
1881 CSI-LLD Section: 4.2
1882 */
1883
1884 LOCAL void cs_find_inactive_carriers (T_POWER_MEAS **p_results,
1885 U16 p_results_size[2],U8 *std,
1886 U8 no_of_attempts, SHORT *min_rxlev)
1887 {
1888 GET_INSTANCE_DATA;
1889 T_POWER_ARRAY* parray, *last;
1890 U16 j, arfcn;
1891 U8 i, x=0;
1892 T_MPH_POWER_CNF* mph_power_cnf = alr_data->cs_data.p_power_cnf;
1893
1894 TRACE_FUNCTION("cs_find_inactive_carriers ()");
1895
1896 /* Loop through both regions */
1897 for (i=0;i<MAX_REGIONS;i++)
1898 {
1899 if((p_results_size[i]) AND (p_results[i] NEQ NULL))
1900 {
1901 parray = p_results[i]->power_array;
1902
1903 for (j=0; j<p_results_size[i];)
1904 {
1905 arfcn = ARFCN_STD_TO_G23(parray->radio_freq, std[i]);
1906 /* Pointer to the Last Power array for a particular region */
1907 last = (p_results[i]->power_array + (p_results_size[i]-1));
1908 /*lint -e661 (Warning -- Possible access of out-of-bounds) */
1909 get_band_index_from_arfcn(arfcn, x, std[i]);
1910 if (parray->accum_power_result < min_rxlev[x])
1911 {
1912 /*lint +e661 (Warning -- Possible access of out-of-bounds) */
1913 /* Inactive carrier */
1914 srv_set_channel((T_LIST*)&mph_power_cnf->inactive_carrier_list.list[i],
1915 arfcn&ARFCN_MASK);
1916
1917 /* Replace inactive carrier with the last active carrier */
1918 cs_power_array_swap_arfcn(parray,last);
1919
1920 /* Decrement the power array size to exclude this carrier */
1921 p_results_size[i]--;
1922 }
1923 else if(cs_is_in_black_list(i, (U16)(arfcn&ARFCN_MASK)))
1924 {
1925 /* Carrier is black listed. No need to consider this */
1926 /*lint -e661 (Warning -- Possible access of out-of-bounds) */
1927 parray->accum_power_result = min_rxlev[x]-1;
1928 /*lint +e661 (Warning -- Possible access of out-of-bounds) */
1929 /* Replace inactive carrier with the last active carrier */
1930 cs_power_array_swap_arfcn(parray,last);
1931
1932 /* Decrement the power array size to exclude this carrier */
1933 p_results_size[i]--;
1934
1935 }
1936 else
1937 {
1938 j++, parray++;
1939 }
1940 } /* for size */
1941 } /* if size */
1942 } /* MAX_REGIONS */
1943 }
1944
1945
1946 /*
1947 +--------------------------------------------------------------------+
1948 | PROJECT : GSM-PS (8403) MODULE : ALR_CS |
1949 | STATE : code ROUTINE : cs_whitelist_handle |
1950 +--------------------------------------------------------------------+
1951
1952 PURPOSE : This function puts the White carriers at the top of the
1953 MPH_POWER_CNF list
1954 CSI-LLD 4.1.3.4.2.7
1955
1956 FreeCalypso note: when TI reworked this function for their
1957 TI_PS_FF_QUAD_BAND_SUPPORT, they broke the configuration without this
1958 feature. If one takes the version of ALR from the LoCosto source
1959 and builds it without TI_PS_FF_QUAD_BAND_SUPPORT, after passing through
1960 the C preprocessor this function will be reduced to an equivalent of
1961 return 0; followed by unreachable code.
1962
1963 Our solution: let's put the #ifdef TI_PS_FF_QUAD_BAND_SUPPORT on the
1964 outside of the function, and have two entirely separate versions.
1965 If one builds with the new feature, the version from LoCosto will be
1966 built, made more readable by removing further internal ifdefs on the
1967 same condition. The version to be built *without* TI_PS_FF_QUAD_BAND_SUPPORT
1968 has been taken from the ALR source that miraculously survived in the
1969 otherwise sanitized Leonardo semi-src.
1970
1971 */
1972
1973 #ifdef TI_PS_FF_QUAD_BAND_SUPPORT
1974 LOCAL U8 cs_add_whitelist_carriers(U16 p_results_size[2], U8 *r_std, U8 no_of_attempts,
1975 SHORT *min_rxlev, T_POWER_MEAS **presults,
1976 U8 no_of_carriers_per_band[4])
1977 {
1978 GET_INSTANCE_DATA;
1979 T_MPH_POWER_CNF* mph_power_cnf = alr_data->cs_data.p_power_cnf;
1980 T_MPH_POWER_REQ* mph_power_req = alr_data->cs_data.p_power_req;
1981 U8 i_cnf,j, where_to_add = DO_NOT_ADD;
1982 U8 region = mph_power_req->white_list.region;
1983 U16 i,arfcn, temp_arfcn;
1984 U8 temp_rxlev;
1985 UBYTE x=0;
1986 T_POWER_ARRAY *parray, *last;
1987 U8 std, start_region, no_of_regions, k;
1988
1989 TRACE_FUNCTION ("cs_add_whitelist_carriers()");
1990
1991 i_cnf = 0;
1992
1993 if (region EQ BOTH_REGIONS)
1994 {
1995 if((!(p_results_size[EUROPEAN_REGION]) OR (presults[EUROPEAN_REGION] EQ NULL)) AND
1996 (!(p_results_size[AMERICAN_REGION]) OR (presults[AMERICAN_REGION] EQ NULL)))
1997 return i_cnf;
1998 }
1999 else if(!(p_results_size[region]) OR (presults EQ NULL))
2000 {
2001 return i_cnf;
2002 }
2003
2004 /* Move the white list carriers to MPH_POWER_CNF array first */
2005 if (region EQ BOTH_REGIONS)
2006 {
2007 start_region = EUROPEAN_REGION;
2008 no_of_regions = MAX_REGIONS;
2009 }
2010 else if (region EQ EUROPEAN_REGION)
2011 {
2012 start_region = region;
2013 no_of_regions = MAX_REGIONS - 1;
2014 }
2015 else
2016 {
2017 start_region = region;
2018 no_of_regions = MAX_REGIONS;
2019 }
2020
2021 for (k=start_region; k< no_of_regions; k++)
2022 {
2023 std = r_std[k];
2024 parray = presults[k]->power_array;
2025
2026 for (i=0; (i<p_results_size[k] AND i_cnf < 32); )
2027 {
2028 /* Convert to GSM standard format from L1 format*/
2029 arfcn = ARFCN_STD_TO_G23(parray->radio_freq,std);
2030 /*lint -e661 (Warning -- Possible access of out-of-bounds) */
2031 get_band_index_from_arfcn(arfcn, x, std);
2032 if (parray->accum_power_result > (min_rxlev[x] - 1))
2033 {
2034 /*lint +e661 (Warning -- Possible access of out-of-bounds) */
2035 if(srv_get_channel((T_LIST*)&mph_power_req->white_list.list, arfcn&ARFCN_MASK))
2036 {
2037
2038 /* Channel is present in white list. Add this to top of MPH_POWER_CNF */
2039 arfcn = STD_ADD_TO_ARFCN(arfcn, std);
2040
2041 /* US_BIT should be used to differentiate an US frequency channel. */
2042 switch (std)
2043 {
2044 case STD_1900:
2045 case STD_850:
2046 case STD_DUAL_US:
2047 arfcn |= US_BIT;
2048 break;
2049 default:
2050 break;
2051 }
2052 /*lint -e661 (Warning -- Possible access of out-of-bounds) */
2053 where_to_add = cs_restrict_max_carriers_per_band(arfcn&ARFCN_MASK, std,
2054 no_of_carriers_per_band, p_results_size, min_rxlev[x]);
2055 /*lint +e661 (Warning -- Possible access of out-of-bounds) */
2056 if(where_to_add NEQ DO_NOT_ADD)
2057 {
2058 /* White list carriers are always added at the top */
2059 mph_power_cnf->arfcn[i_cnf] = arfcn;
2060 mph_power_cnf->rx_lev[i_cnf] = (U8)(parray->accum_power_result/no_of_attempts);
2061 i_cnf++;
2062 }
2063 else
2064 {
2065 TRACE_EVENT_P2("[WL] [DO_NOT_ADD] [%d] : [%c]", arfcn&ARFCN_MASK,
2066 (k ? 'A' :'E'));
2067 }
2068
2069 /* Exclude this carrier */
2070 parray->accum_power_result = min_rxlev[x]-1;
2071
2072 last = presults[k]->power_array + (p_results_size[k] - 1);
2073
2074 /* Swapping the current carrier with the last carrier */
2075 cs_power_array_swap_arfcn(parray, last);
2076
2077 /* Decrement the power array counter to exclude the above carrier */
2078 p_results_size[k]--;
2079
2080 } /* Present in White List */
2081 else
2082 {
2083 i++; parray++;
2084 }
2085 } /* Active Carrier */
2086 else
2087 {
2088 TRACE_EVENT_P2("[WL] [IA] [%d] : [%c]", parray->radio_freq,
2089 (k ? 'A' :'E'));
2090 i++; parray++;
2091 }
2092 } /* i < max */
2093 }
2094
2095 /* Assign the total Number of white list channels */
2096 mph_power_cnf->num_of_white_list_chan = i_cnf;
2097
2098 TRACE_EVENT_P1("[WL] no. of channels : %d ",mph_power_cnf->num_of_white_list_chan);
2099
2100 /*
2101 * Sort the white list carriers added to power_cnf array on the
2102 * basis of their field strength
2103 */
2104 for(i=0; i < i_cnf; i++)
2105 {
2106 for(j=i+1; j<i_cnf; j++)
2107 {
2108 if(mph_power_cnf->rx_lev[i] < mph_power_cnf->rx_lev[j])
2109 {
2110 temp_rxlev = mph_power_cnf->rx_lev[i];
2111 temp_arfcn = mph_power_cnf->arfcn[i];
2112
2113 mph_power_cnf->rx_lev[i] = mph_power_cnf->rx_lev[j];
2114 mph_power_cnf->arfcn[i] = mph_power_cnf->arfcn[j];
2115
2116 mph_power_cnf->rx_lev[j] = temp_rxlev;
2117 mph_power_cnf->arfcn[j] = temp_arfcn;
2118 }
2119 }
2120 }
2121
2122 return (i_cnf);
2123 }
2124 #else /* no TI_PS_FF_QUAD_BAND_SUPPORT */
2125
2126 /*
2127 * Version taken from the TCS211 ALR source, modified in a few places
2128 * to work with the rest of ALR which is the version from LoCosto.
2129 */
2130
2131 LOCAL U8 cs_add_whitelist_carriers(U16 p_results_size[2], U8 std, U8 no_of_attempts,
2132 SHORT *min_rxlev,
2133 T_POWER_MEAS *presults,
2134 U8 no_of_carriers_per_band[4])
2135 {
2136 GET_INSTANCE_DATA;
2137 T_MPH_POWER_CNF* mph_power_cnf = alr_data->cs_data.p_power_cnf;
2138 T_MPH_POWER_REQ* mph_power_req = alr_data->cs_data.p_power_req;
2139 U8 i_cnf,j, where_to_add = DO_NOT_ADD;
2140 U8 region = mph_power_req->white_list.region;
2141 U16 i,arfcn, temp_arfcn;
2142 U8 temp_rxlev;
2143 UBYTE x;
2144 T_POWER_ARRAY *parray, *last;
2145
2146 TRACE_FUNCTION ("cs_add_whitelist_carriers()");
2147
2148 i_cnf = 0;
2149
2150 if((p_results_size[region]) AND (presults NEQ NULL))
2151 {
2152 parray = presults->power_array;
2153 }
2154 else
2155 return i_cnf;
2156
2157 /* Move the white list carriers to MPH_POWER_CNF array first */
2158 for (i=0; (i<p_results_size[region] AND i_cnf < 32); )
2159 {
2160
2161 /* Convert to GSM standard format from L1 format*/
2162 arfcn = ARFCN_STD_TO_G23(parray->radio_freq,std);
2163 get_band_index_from_arfcn(arfcn, x, std);
2164 if (parray->accum_power_result > (min_rxlev[x] - 1))
2165 {
2166 if(srv_get_channel((T_LIST*)&mph_power_req->white_list.list, arfcn&ARFCN_MASK))
2167 {
2168
2169 /* Channel is present in white list. Add this to top of MPH_POWER_CNF */
2170 arfcn = STD_ADD_TO_ARFCN(arfcn, std);
2171
2172 /* US_BIT should be used to differentiate an US frequency channel. */
2173 switch (std)
2174 {
2175 case STD_1900:
2176 case STD_850:
2177 case STD_DUAL_US:
2178 arfcn |= US_BIT;
2179 break;
2180 default:
2181 break;
2182 }
2183
2184 where_to_add = cs_restrict_max_carriers_per_band(arfcn&ARFCN_MASK, std,
2185 no_of_carriers_per_band, p_results_size,
2186 min_rxlev[x]);
2187
2188 if(where_to_add NEQ DO_NOT_ADD)
2189 {
2190 /* White list carriers are always added at the top */
2191 mph_power_cnf->arfcn[i_cnf] = arfcn;
2192 mph_power_cnf->rx_lev[i_cnf] = (U8)(parray->accum_power_result/no_of_attempts);
2193 i_cnf++;
2194 }
2195 else
2196 {
2197 TRACE_EVENT_P2("[WL] [DO_NOT_ADD] [%d] : [%c]", arfcn&ARFCN_MASK,
2198 (region ? 'A' :'E'));
2199 }
2200
2201 /* Exclude this carrier */
2202 parray->accum_power_result = min_rxlev[x]-1;
2203
2204 last = presults->power_array + (p_results_size[region] - 1);
2205
2206 /* Swapping the current carrier with the last carrier */
2207 cs_power_array_swap_arfcn(parray, last);
2208
2209 /* Decrement the power array counter to exclude the above carrier */
2210 p_results_size[region]--;
2211
2212 } /* Present in White List */
2213 else
2214 {
2215 i++; parray++;
2216 }
2217 } /* Active Carrier */
2218 else
2219 {
2220 TRACE_EVENT_P2("[WL] [IA] [%d] : [%c]", parray->radio_freq,
2221 (region ? 'A' :'E'));
2222 i++; parray++;
2223 }
2224 } /* i < max */
2225
2226 /* Assign the total Number of white list channels */
2227 mph_power_cnf->num_of_white_list_chan = i_cnf;
2228
2229 TRACE_EVENT_P1("[WL] no. of channels : %d ",mph_power_cnf->num_of_white_list_chan);
2230
2231 /*
2232 * Sort the white list carriers added to power_cnf array on the
2233 * basis of their field strength
2234 */
2235 for(i=0; i < i_cnf; i++)
2236 {
2237 for(j=i+1; j<i_cnf; j++)
2238 {
2239 if(mph_power_cnf->rx_lev[i] < mph_power_cnf->rx_lev[j])
2240 {
2241 temp_rxlev = mph_power_cnf->rx_lev[i];
2242 temp_arfcn = mph_power_cnf->arfcn[i];
2243
2244 mph_power_cnf->rx_lev[i] = mph_power_cnf->rx_lev[j];
2245 mph_power_cnf->arfcn[i] = mph_power_cnf->arfcn[j];
2246
2247 mph_power_cnf->rx_lev[j] = temp_rxlev;
2248 mph_power_cnf->arfcn[j] = temp_arfcn;
2249 }
2250 }
2251 }
2252
2253 return (i_cnf);
2254 }
2255 #endif
2256
2257 /*
2258 +--------------------------------------------------------------------+
2259 | PROJECT : GSM-PS (8403) MODULE : ALR_CS |
2260 | STATE : code ROUTINE : |
2261 | cs_restrict_max_carriers_per_band |
2262 +--------------------------------------------------------------------+
2263 PURPOSE : This function is to handle the Multiple Frequency Bands
2264 in a Region. Will help to add the minimum(40) carriers per
2265 band on top of the power cnf and the remaining(40 to 60)
2266 carriers will be added in at the end (Below the Normal (40)
2267 carriers of all band).
2268 CSI-LLD :
2269 */
2270
2271 U8 cs_restrict_max_carriers_per_band (U16 arfcn, U8 std,
2272 U8 no_of_carriers_per_band[4], U16 p_results_size[2], UBYTE min_rxlev)
2273 {
2274 GET_INSTANCE_DATA;
2275
2276 T_POWER_MEAS *presults;
2277 T_POWER_ARRAY *parray, *last;
2278 U16 i;
2279 U8 index = 0xff,just_reached_the_maximum=FALSE;
2280 U8 region, where_to_add = DO_NOT_ADD;
2281
2282 switch(std)
2283 {
2284 case STD_900 :
2285 case STD_DUAL :
2286 case STD_EGSM :
2287 case STD_DUAL_EGSM :
2288 case STD_1800 :
2289 if(INRANGE (CHANNEL_0, arfcn, HIGH_CHANNEL_900) OR
2290 INRANGE(LOW_CHANNEL_EGSM, arfcn, HIGH_CHANNEL_EGSM))
2291 {
2292 index = 0;
2293 }
2294 else if(INRANGE (LOW_CHANNEL_1800, arfcn, HIGH_CHANNEL_1800))
2295 {
2296 index = 1;
2297 }
2298 else
2299 {
2300 TRACE_ERROR("[European]Invalid Carrier");
2301 return DO_NOT_ADD;
2302 }
2303 region = EUROPEAN_REGION;
2304 break;
2305 case STD_DUAL_US :
2306 case STD_850 :
2307 case STD_1900 :
2308 if(INRANGE (LOW_CHANNEL_850, arfcn, HIGH_CHANNEL_850))
2309 {
2310 index = 2;
2311 }
2312 else if(INRANGE (LOW_CHANNEL_1900, arfcn, HIGH_CHANNEL_1900))
2313 {
2314 index = 3;
2315 }
2316 else
2317 {
2318 TRACE_ERROR("[American]Invalid Carrier");
2319 return DO_NOT_ADD;
2320 }
2321 region = AMERICAN_REGION;
2322 break;
2323 } /* end switch */
2324
2325 if(index < 4)
2326 {
2327 if(no_of_carriers_per_band[index] < MIN_CHANNELS_PER_BAND)
2328 {
2329 /* Increment counter for corresponding band */
2330 no_of_carriers_per_band[index]++;
2331
2332 if(no_of_carriers_per_band[index] EQ MIN_CHANNELS_PER_BAND)
2333 {
2334 TRACE_EVENT_P5(
2335 "[%d]Band, 40 channels added (B_GSM_EGSM%d, B_1800:%d, B_850:%d, B_1900:%d)",
2336 index,
2337 no_of_carriers_per_band[0], no_of_carriers_per_band[1],
2338 no_of_carriers_per_band[2], no_of_carriers_per_band[3]);
2339 }
2340
2341 /* Add at the top of MPH_POWER_CNF list */
2342 where_to_add = ADD_AT_THE_TOP;
2343 }
2344 else if(no_of_carriers_per_band[index] <= MAX_CHANNELS_PER_BAND)
2345 {
2346 /* Increment counter for corresponding band */
2347 no_of_carriers_per_band[index]++;
2348
2349 /* Add at the bottom of MPH_POWER_CNF list */
2350 where_to_add = ADD_AT_THE_BOTTOM;
2351
2352 if(no_of_carriers_per_band[index] EQ (MAX_CHANNELS_PER_BAND + 1))
2353 {
2354 TRACE_EVENT_P5(
2355 "[%d]Band, 60 channels added (B_GSM_EGSM%d, B_1800:%d, B_850:%d, B_1900:%d)",
2356 index,
2357 no_of_carriers_per_band[0], no_of_carriers_per_band[1],
2358 no_of_carriers_per_band[2], no_of_carriers_per_band[3]);
2359
2360 just_reached_the_maximum = TRUE;
2361
2362 where_to_add = REACHED_THE_MAXIMUM;
2363 }
2364 }
2365 else
2366 {
2367 where_to_add = DO_NOT_ADD;
2368 }
2369 }
2370 else
2371 {
2372 TRACE_ERROR("Unknown Band Index");
2373 return DO_NOT_ADD;
2374 } /* if index < 4 */
2375
2376 /* When Max number of channels(60) are added for a particular band,
2377 * all the remaining carriers belonging to that band are excluded from
2378 * further sorting
2379 */
2380 if(just_reached_the_maximum)
2381 {
2382 BOOL exclude;
2383 U16 l3_arfcn;
2384
2385 if (region EQ AMERICAN_REGION)/*lint !e644 region may not have been initialized */
2386 { /* American band */
2387 presults = alr_data->cs_data.p_results2;
2388 }
2389 else
2390 { /* European band */
2391 presults = alr_data->cs_data.p_results1;
2392 }
2393
2394 TRACE_EVENT_P3("[%d]Index, E:%d A:%d",
2395 index, p_results_size[0], p_results_size[1]);
2396
2397 if((presults NEQ NULL) AND (p_results_size[region]))/*lint !e644 region may not have been initialized */
2398 {
2399 for(i=0, parray = presults->power_array; i < p_results_size[region];)
2400 {
2401 exclude = FALSE;
2402 l3_arfcn = ARFCN_STD_TO_G23(parray->radio_freq, std);
2403
2404 switch(index)
2405 {
2406 case 0 :
2407 if(INRANGE (LOW_CHANNEL_900, l3_arfcn, HIGH_CHANNEL_900) OR
2408 INRANGE(LOW_CHANNEL_EGSM, l3_arfcn, HIGH_CHANNEL_EGSM))
2409 {
2410 exclude = TRUE;
2411 }
2412 break;
2413 case 1:
2414 if(INRANGE (LOW_CHANNEL_1800, l3_arfcn, HIGH_CHANNEL_1800))
2415 {
2416 exclude = TRUE;
2417 }
2418 break;
2419 case 2 :
2420 if(INRANGE (LOW_CHANNEL_850, l3_arfcn, HIGH_CHANNEL_850))
2421 {
2422 exclude = TRUE;
2423 }
2424 break;
2425 case 3:
2426 if(INRANGE (LOW_CHANNEL_1900, l3_arfcn, HIGH_CHANNEL_1900))
2427 {
2428 exclude = TRUE;
2429 }
2430 break;
2431 default :
2432 break;
2433 } /* end switch */
2434
2435 if(exclude)
2436 {
2437 last = presults->power_array + (p_results_size[region] - 1); /*lint !e644 region may not have been initialized */
2438
2439 /* Exclude this carrier */
2440 parray->accum_power_result = min_rxlev-1;
2441
2442 /* Swaping the Current carrier with the last carrier */
2443 cs_power_array_swap_arfcn(parray, last);
2444
2445 /* Decrement the power array counter to exclude the above carrier */
2446 p_results_size[region]--;
2447 }
2448 else
2449 {
2450 parray++; i++;
2451 }
2452 } /* power array size */
2453 } /* end if(just_reached_the_maximum */
2454 } /* presults NEQ NULL */
2455
2456 return where_to_add;
2457 }
2458 #endif
2459
2460
2461 /*
2462 +--------------------------------------------------------------------+
2463 | PROJECT : GSM-PS (8403) MODULE : ALR_CS |
2464 | STATE : code ROUTINE : cs_reorder_the_extra_carriers |
2465 +--------------------------------------------------------------------+
2466 PURPOSE : Extra Carriers (More than 40 and below 60) are stored at
2467 the bottom of the MPH_POWER_CNF. But these are stored in
2468 ascending order (if you see from the TOP). This needs to
2469 be reordered (means Strongest carrier should go to top).
2470 */
2471
2472 LOCAL void cs_reorder_the_extra_carriers(U8 extra_cnf)
2473 {
2474 GET_INSTANCE_DATA;
2475 T_MPH_POWER_CNF* mph_power_cnf = alr_data->cs_data.p_power_cnf;
2476 U8 i,j,count,max_count,temp_rxlevel;
2477 U16 temp_arfcn;
2478
2479 TRACE_FUNCTION("cs_reorder_the_extra_carriers");
2480
2481 i = MAX_CHANNELS - 1;
2482 j = MAX_CHANNELS - extra_cnf;
2483 max_count = extra_cnf/2;
2484
2485
2486 for(count=0; count < max_count; i--, j++, count++)
2487 {
2488 temp_arfcn = mph_power_cnf->arfcn[i];
2489 temp_rxlevel = mph_power_cnf->rx_lev[i];
2490
2491 mph_power_cnf->arfcn[i] = mph_power_cnf->arfcn[j];
2492 mph_power_cnf->rx_lev[i] = mph_power_cnf->rx_lev[j];
2493
2494 mph_power_cnf->arfcn[j] = temp_arfcn;
2495 mph_power_cnf->rx_lev[j] = temp_rxlevel;
2496
2497 }
2498
2499 }
2500
2501 /*
2502 +--------------------------------------------------------------------+
2503 | PROJECT : GSM-PS (8403) MODULE : ALR_CS |
2504 | STATE : code ROUTINE : |
2505 | cs_move_extra_carriers |
2506 +--------------------------------------------------------------------+
2507 PURPOSE : Extra Carriers (More than 40 and below 60) are stored at
2508 the bottom of the MPH_POWER_CNF. These carriers needs to
2509 be rearranged below the normal (Strangest 40 Carriers)
2510 carriers
2511 */
2512
2513 LOCAL void cs_move_extra_carriers(U8 i_cnf, U8 extra_cnf)
2514 {
2515 GET_INSTANCE_DATA;
2516 T_MPH_POWER_CNF* mph_power_cnf = alr_data->cs_data.p_power_cnf;
2517
2518 /*
2519 * Add the extra carriers below Normal carrier
2520 */
2521 TRACE_FUNCTION("cs_move_extra_carriers");
2522
2523 /* Move the extra carriers below the Normal carriers */
2524 memmove (&mph_power_cnf->arfcn[i_cnf],
2525 &mph_power_cnf->arfcn[MAX_CHANNELS - extra_cnf],
2526 sizeof (mph_power_cnf->arfcn[0]) * (extra_cnf));
2527
2528 memmove (&mph_power_cnf->rx_lev[i_cnf],
2529 &mph_power_cnf->rx_lev[MAX_CHANNELS - extra_cnf],
2530 sizeof (mph_power_cnf->rx_lev[0]) * (extra_cnf));
2531
2532 }