FreeCalypso > hg > fc-tourmaline
comparison src/gpf/ccd/freq_list.c @ 0:4e78acac3d88
src/{condat,cs,gpf,nucleus}: import from Selenite
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Fri, 16 Oct 2020 06:23:26 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:4e78acac3d88 |
|---|---|
| 1 /* | |
| 2 +----------------------------------------------------------------------------- | |
| 3 | Project : CCD | |
| 4 | Modul : freq_list.c | |
| 5 +----------------------------------------------------------------------------- | |
| 6 | Copyright 2004 Texas Instruments Deutschland GmbH | |
| 7 | All rights reserved. | |
| 8 | | |
| 9 | This file is confidential and a trade secret of Texas | |
| 10 | Instruments Deutschland GmbH | |
| 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 Deutschland GmbH. | |
| 16 +----------------------------------------------------------------------------- | |
| 17 | Purpose : Definition of decoding function for FREQ_LIST type | |
| 18 +----------------------------------------------------------------------------- | |
| 19 */ | |
| 20 | |
| 21 #define FREQ_LIST_C | |
| 22 | |
| 23 /* | |
| 24 * standard definitions like GLOBAL, UCHAR, ERROR etc. | |
| 25 */ | |
| 26 #include "typedefs.h" | |
| 27 #include "header.h" | |
| 28 | |
| 29 #include "string.h" | |
| 30 | |
| 31 /* | |
| 32 * Types and functions for bit access and manipulation | |
| 33 */ | |
| 34 #include "ccd_globs.h" | |
| 35 #include "bitfun.h" | |
| 36 | |
| 37 /* | |
| 38 * Prototypes of ccd internal functions | |
| 39 */ | |
| 40 #include "ccd.h" | |
| 41 | |
| 42 /* | |
| 43 * Declaration of coder/decoder tables | |
| 44 */ | |
| 45 #include "ccdtable.h" | |
| 46 /* | |
| 47 * Function prototypes of CCD-CCDDATA interface | |
| 48 */ | |
| 49 #include "ccddata.h" | |
| 50 | |
| 51 | |
| 52 #if !(defined (CCD_TEST)) | |
| 53 #include "vsi.h" | |
| 54 #endif | |
| 55 | |
| 56 #ifndef RUN_INT_RAM | |
| 57 /* | |
| 58 * Attention: in this file all static and global functions as well as | |
| 59 * the static data are controlled by one RUN_.. clause. | |
| 60 * The static data and functions are currently only used in the decode | |
| 61 * function, whereas encoding is not yet available. | |
| 62 */ | |
| 63 static U16 first; | |
| 64 static U16 last; | |
| 65 static U16 num; | |
| 66 | |
| 67 | |
| 68 /* | |
| 69 * The W-parameter in the 256 range start from bit 7 of the | |
| 70 * information element. The following table indicate the number | |
| 71 * of W-parameters and their length in bits. A length of zero | |
| 72 * indicated the end of the table. | |
| 73 */ | |
| 74 static const T_W_PARAM param_256[10] = | |
| 75 { | |
| 76 /* | |
| 77 * length count | |
| 78 */ | |
| 79 10, 1, | |
| 80 8, 1, | |
| 81 7, 2, | |
| 82 6, 4, | |
| 83 5, 8, | |
| 84 4, 16, | |
| 85 3, 32, | |
| 86 2, 64, | |
| 87 1, 128, | |
| 88 0, 0 | |
| 89 }; | |
| 90 | |
| 91 /* | |
| 92 * The W-parameter in the 128 range start from bit 7 of the | |
| 93 * information element. The following table indicate the number | |
| 94 * of W-parameters and their length in bits. A length of zero | |
| 95 * indicated the end of the table. | |
| 96 */ | |
| 97 | |
| 98 static const T_W_PARAM param_128[9] = | |
| 99 { | |
| 100 /* | |
| 101 * length count | |
| 102 */ | |
| 103 10, 1, | |
| 104 7, 1, | |
| 105 6, 2, | |
| 106 5, 4, | |
| 107 4, 8, | |
| 108 3, 16, | |
| 109 2, 32, | |
| 110 1, 64, | |
| 111 0, 0 | |
| 112 }; | |
| 113 | |
| 114 /* | |
| 115 * Compare results of the first channel with those of the others | |
| 116 * to find the dimensions. | |
| 117 */ | |
| 118 static void completeAddInfo (U8 *BitmapInStruct) | |
| 119 { | |
| 120 *(U16*) (BitmapInStruct - 2) += num; | |
| 121 if (*(U16*) (BitmapInStruct - 6) > first) | |
| 122 *(U16*) (BitmapInStruct - 6) = first; | |
| 123 if (*(U16*) (BitmapInStruct - 4) < last) | |
| 124 *(U16*) (BitmapInStruct - 6) = last; | |
| 125 } | |
| 126 | |
| 127 static void setFirstChanNr (U8 *BitmapInStruct, short w0) | |
| 128 { | |
| 129 U16 bitposition; | |
| 130 bitposition = (w0 == 0) ? 0 : (U16)(BITOFFSET_LIST - w0); | |
| 131 BitmapInStruct[bitposition >> 3] |= ByteBitMask[bitposition & 7]; | |
| 132 first = bitposition; | |
| 133 last = bitposition; | |
| 134 num = 1; | |
| 135 } | |
| 136 /* | |
| 137 +--------------------------------------------------------------------+ | |
| 138 | PROJECT : CCD MODULE : cdc_freq_list_decode | | |
| 139 +--------------------------------------------------------------------+ | |
| 140 PURPOSE : The function creates a frequency hopping list from one of | |
| 141 the following information elements according GSM 4.08: | |
| 142 | |
| 143 cell channel description | |
| 144 frequency list | |
| 145 frequency short list | |
| 146 neighbour cell description | |
| 147 | |
| 148 The format identifier of the information element is defined as: | |
| 149 | |
| 150 FORMAT-ID, Format Identifier | |
| 151 | |
| 152 Bit Bit Bit Bit Bit format notation | |
| 153 8 7 4 3 2 | |
| 154 | |
| 155 0 0 X X X bit map 0 | |
| 156 1 0 0 X X 1024 range | |
| 157 1 0 1 0 0 512 range | |
| 158 1 0 1 0 1 256 range | |
| 159 1 0 1 1 0 128 range | |
| 160 1 0 1 1 1 variable bit map | |
| 161 | |
| 162 The space this IE takes in the C-structure is depicted in the | |
| 163 example below: | |
| 164 typedef struct | |
| 165 { | |
| 166 U16 first; | |
| 167 U16 last; | |
| 168 U16 num; | |
| 169 U8 bitmap[128]; | |
| 170 } BMP_arfcn_list; | |
| 171 | |
| 172 The member bitmap stores a list of frequencies in a range of | |
| 173 0 - 1023 (GSM), where some of the frequencies are not yet used. | |
| 174 */ | |
| 175 | |
| 176 SHORT cdc_freq_list_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) | |
| 177 { | |
| 178 U8 *FirstByte = globs->bitbuf + globs->bytepos; | |
| 179 ULONG cix_ref, num_prolog_steps, prolog_step_ref; | |
| 180 | |
| 181 #ifdef DEBUG_CCD | |
| 182 TRACE_CCD (globs, "cdc_freq_list_decode()"); | |
| 183 #ifdef CCD_SYMBOLS | |
| 184 TRACE_CCD (globs, "decoding list %s with range 1024 format", | |
| 185 ccddata_get_alias((USHORT) e_ref, 1)); | |
| 186 #else | |
| 187 TRACE_CCD (globs, "decoding list %d of range 1024 format", melem[e_ref].elemRef); | |
| 188 #endif | |
| 189 #endif | |
| 190 | |
| 191 cix_ref = melem[e_ref].calcIdxRef; | |
| 192 num_prolog_steps = calcidx[cix_ref].numPrologSteps; | |
| 193 prolog_step_ref = calcidx[cix_ref].prologStepRef; | |
| 194 | |
| 195 /* | |
| 196 * if this element have a defined Prolog | |
| 197 * we have to process it before decoding the bitstream | |
| 198 */ | |
| 199 if (num_prolog_steps) | |
| 200 { | |
| 201 ccd_performOperations (num_prolog_steps, prolog_step_ref, globs); | |
| 202 } | |
| 203 | |
| 204 globs->SeekTLVExt = FALSE; | |
| 205 globs->pstructOffs = melem[e_ref].structOffs; | |
| 206 | |
| 207 /* | |
| 208 * Bitmap 0 format | |
| 209 * only for GSM 900 or GSM 850 bands !!!! | |
| 210 * std = STD_900, STD_EGSM, STD_DUAL, STD_DUAL_EGSM, STD_850, STD_DUAL_US | |
| 211 * No check of std for being PCS 1900 or DCS 1800 is implemented. | |
| 212 */ | |
| 213 if ((*FirstByte & 0x80) == 0) | |
| 214 { | |
| 215 | |
| 216 #ifdef DEBUG_CCD | |
| 217 TRACE_CCD (globs, "bitmap 0 format"); | |
| 218 #endif | |
| 219 /* | |
| 220 * Copy only the first 16 bytes. According to section 10.5.2.1b.2 of | |
| 221 * GSM04.08, 124 bits are dedicated to ARFCN and two bits to the Format-ID. | |
| 222 * Two bits are spare. | |
| 223 */ | |
| 224 FirstByte = globs->pstruct + globs->pstructOffs; | |
| 225 /* first bit */ | |
| 226 *(U16 *) FirstByte = 896;//T_LIST_MAX_SIZE - 16; | |
| 227 /* last bit */ | |
| 228 *(U16 *) (FirstByte+2) = T_LIST_MAX_SIZE; | |
| 229 /* number of entries */ | |
| 230 *(U16 *) (FirstByte+4) = 124; | |
| 231 memcpy (FirstByte + T_LIST_MAX_SIZE - 10, //FirstByte + 6 + T_LIST_MAX_SIZE - 16, | |
| 232 globs->bitbuf + globs->bytepos, 16); | |
| 233 } | |
| 234 else | |
| 235 { | |
| 236 U16 ListLength = mvar[melem[e_ref].elemRef].bSize; | |
| 237 U8 *BitmapInStruct = globs->pstruct + globs->pstructOffs; | |
| 238 first = 0; | |
| 239 last = 0; | |
| 240 num = 0; | |
| 241 /* | |
| 242 * RANGE 128, | |
| 243 */ | |
| 244 if ((*FirstByte & 0x8E) == 0x8C) | |
| 245 { | |
| 246 /* | |
| 247 * Use dynamic memory for calculation instead of global memory or stack. | |
| 248 */ | |
| 249 short *w; | |
| 250 MALLOC (w, 129 * sizeof (U16)); | |
| 251 | |
| 252 #ifdef DEBUG_CCD | |
| 253 TRACE_CCD (globs, "range 128 format"); | |
| 254 #endif | |
| 255 | |
| 256 /* | |
| 257 * The algorithm for several ranges is the same with different | |
| 258 * tables. The W-parameter start with bit 7. Skip over offset. | |
| 259 */ | |
| 260 bf_incBitpos (7, globs); | |
| 261 cdc_decode_param (param_128, w, ListLength, globs); | |
| 262 | |
| 263 /* | |
| 264 * W[0] contains the first channel number | |
| 265 */ | |
| 266 setFirstChanNr (BitmapInStruct, w[0]); | |
| 267 | |
| 268 /* | |
| 269 * Decode and set the remaining channel number according the | |
| 270 * algorithm described in GSM 4.08. | |
| 271 */ | |
| 272 cdc_decode_frequencies (127, &w[1], w[0], FREQUENCY_LIST, globs); | |
| 273 completeAddInfo (BitmapInStruct); | |
| 274 | |
| 275 /* | |
| 276 * free the dynamic allocated memory. | |
| 277 */ | |
| 278 MFREE (w); | |
| 279 } | |
| 280 /* | |
| 281 * RANGE 256 | |
| 282 */ | |
| 283 if ((*FirstByte & 0x8E) == 0x8A) | |
| 284 { | |
| 285 /* | |
| 286 * Use dynamic memory for calculation instead of global memory or stack. | |
| 287 */ | |
| 288 short *w; | |
| 289 MALLOC (w, 257 * sizeof (U16)); | |
| 290 | |
| 291 #ifdef DEBUG_CCD | |
| 292 TRACE_CCD (globs, "range 256 format"); | |
| 293 #endif | |
| 294 | |
| 295 /* | |
| 296 * Decode the W-parameter. The W-parameter start with bit 7. | |
| 297 */ | |
| 298 bf_incBitpos (7, globs); | |
| 299 cdc_decode_param (param_256, w, ListLength, globs); | |
| 300 | |
| 301 /* | |
| 302 * W[0] contains the first channel number | |
| 303 */ | |
| 304 setFirstChanNr (BitmapInStruct, w[0]); | |
| 305 | |
| 306 /* | |
| 307 * decode and set the remaining channel number according the | |
| 308 * algorithm described in GSM 4.08. | |
| 309 */ | |
| 310 cdc_decode_frequencies (255, &w[1], w[0], FREQUENCY_LIST, globs); | |
| 311 completeAddInfo (BitmapInStruct); | |
| 312 | |
| 313 /* | |
| 314 * free the dynamic allocated memory. | |
| 315 */ | |
| 316 MFREE (w); | |
| 317 } | |
| 318 /* | |
| 319 * RANGE 512 | |
| 320 */ | |
| 321 if ((*FirstByte & 0x8E) == 0x88) | |
| 322 { | |
| 323 /* | |
| 324 * Use dynamic memory for calculation instead of global memory or stack. | |
| 325 */ | |
| 326 short *w; | |
| 327 MALLOC (w, 257 * sizeof (U16)); | |
| 328 | |
| 329 #ifdef DEBUG_CCD | |
| 330 TRACE_CCD (globs, "range 512 format"); | |
| 331 #endif | |
| 332 | |
| 333 /* | |
| 334 * the algorithm for the several ranges is the same with different | |
| 335 * tables. The W-parameter start with bit 7. Skip over offset. | |
| 336 */ | |
| 337 bf_incBitpos (7, globs); | |
| 338 cdc_decode_param (param_512, w, ListLength, globs); | |
| 339 | |
| 340 /* | |
| 341 * W[0] contains the first channel number | |
| 342 */ | |
| 343 setFirstChanNr (BitmapInStruct, w[0]); | |
| 344 | |
| 345 /* | |
| 346 * decode and set the remaining channel number according the | |
| 347 * algorithm described in GSM 4.08. | |
| 348 */ | |
| 349 cdc_decode_frequencies (511, &w[1], w[0], FREQUENCY_LIST, globs); | |
| 350 completeAddInfo (BitmapInStruct); | |
| 351 | |
| 352 /* | |
| 353 * free the dynamic allocated memory. | |
| 354 */ | |
| 355 MFREE (w); | |
| 356 } | |
| 357 | |
| 358 if ((*FirstByte & 0x88) == 0x80) | |
| 359 { | |
| 360 /* | |
| 361 * RANGE 1024 | |
| 362 * | |
| 363 * Use dynamic memory for calculation instead of global memory or stack. | |
| 364 */ | |
| 365 U8 f0; | |
| 366 U8 offset; | |
| 367 | |
| 368 short *w; | |
| 369 MALLOC (w, 257 * sizeof (U16)); | |
| 370 | |
| 371 #ifdef DEBUG_CCD | |
| 372 TRACE_CCD (globs, "range 1024 format"); | |
| 373 #endif | |
| 374 | |
| 375 /* | |
| 376 * Get the f0 indicator. It indicates whether channel 0 is part | |
| 377 * of the frequency hopping list or not. | |
| 378 */ | |
| 379 /* The following lines are equal to: | |
| 380 * ccd_decodeByte (FirstByte, (U16)(globs->byteoffs+5), 1, &f0); | |
| 381 */ | |
| 382 offset = globs->byteoffs+5; | |
| 383 if (offset < 8) | |
| 384 { | |
| 385 f0 = FirstByte[0] << offset; | |
| 386 f0 &= 0x80; | |
| 387 } | |
| 388 else | |
| 389 { | |
| 390 U16 tmpvar; | |
| 391 tmpvar = *(U16*) FirstByte; | |
| 392 tmpvar <<= offset; | |
| 393 f0 = tmpvar & 0x8000; | |
| 394 } | |
| 395 | |
| 396 /* | |
| 397 * The algorithm for the several ranges is the same with different | |
| 398 * tables. The W-parameter start with bit 6. Skip over offset. | |
| 399 */ | |
| 400 bf_incBitpos (6, globs); | |
| 401 cdc_decode_param (param_1024, w, ListLength, globs); | |
| 402 | |
| 403 /* | |
| 404 * If indicated add channel 0 to the list | |
| 405 */ | |
| 406 if (f0) | |
| 407 { | |
| 408 /* The following is equal to setFirstChanNr(0); */ | |
| 409 BitmapInStruct[0] |= 0x80; | |
| 410 num = 1; | |
| 411 } | |
| 412 | |
| 413 /* | |
| 414 * decode and set the remaining channel number according the | |
| 415 * algorithm described in GSM 4.08. | |
| 416 */ | |
| 417 cdc_decode_frequencies (1023, &w[0], 0, FREQUENCY_LIST, globs); | |
| 418 completeAddInfo (BitmapInStruct); | |
| 419 | |
| 420 /* | |
| 421 * free the dynamic allocated memory. | |
| 422 */ | |
| 423 MFREE (w); | |
| 424 } | |
| 425 /* | |
| 426 * RANGE variable | |
| 427 */ | |
| 428 if ((*FirstByte & 0x8E) == 0x8E) | |
| 429 { | |
| 430 /* | |
| 431 * The format is similar to the bitmap 0 format. The | |
| 432 * calculation starts from a base channel number svalue | |
| 433 * instead of channel number 1. | |
| 434 */ | |
| 435 U32 lvalue; | |
| 436 U16 svalue; | |
| 437 U32 i; | |
| 438 U16 bitposition; | |
| 439 | |
| 440 #ifdef DEBUG_CCD | |
| 441 TRACE_CCD (globs, "range variable format"); | |
| 442 #endif | |
| 443 | |
| 444 /* Get the first channel number. */ | |
| 445 bf_incBitpos (7, globs); | |
| 446 lvalue = bf_getBits (10, globs); | |
| 447 | |
| 448 /* Copy lvalue to svalue to set the correct channel. */ | |
| 449 svalue = (U16)lvalue; | |
| 450 setFirstChanNr (BitmapInStruct, svalue); | |
| 451 first = svalue; | |
| 452 num = 1; | |
| 453 for (i = 1; i < 112; i++) | |
| 454 { | |
| 455 /* | |
| 456 * Get the value of the next bit. | |
| 457 * If the bit is set, set channel i+svalue | |
| 458 */ | |
| 459 if (bf_readBit (globs)) | |
| 460 { | |
| 461 U16 channel = (U16)for_modulo(i+svalue, 1024); | |
| 462 | |
| 463 bitposition = (channel == 0) ? 0 : (U16)(BITOFFSET_LIST - channel); | |
| 464 BitmapInStruct[bitposition >> 3] |= ByteBitMask[bitposition & 7]; | |
| 465 last = bitposition; | |
| 466 num++; | |
| 467 } | |
| 468 } | |
| 469 completeAddInfo (BitmapInStruct); | |
| 470 } | |
| 471 } | |
| 472 | |
| 473 return 1; | |
| 474 } | |
| 475 | |
| 476 /* | |
| 477 +--------------------------------------------------------------------+ | |
| 478 | PROJECT : CCD MODULE : cdc_freq_list_encode | | |
| 479 +--------------------------------------------------------------------+ | |
| 480 | |
| 481 PURPOSE : Encoding function is not needed, since this message is | |
| 482 sent from net to MS. | |
| 483 It could be only useful for testing procedure if there | |
| 484 were an encoder function at this place. | |
| 485 This will be a future work. | |
| 486 */ | |
| 487 | |
| 488 SHORT cdc_freq_list_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs) | |
| 489 { | |
| 490 | |
| 491 #ifdef DEBUG_CCD | |
| 492 TRACE_CCD (globs, "cdc_freq_list_encode()"); | |
| 493 #endif | |
| 494 #ifdef TARGET_WIN32 | |
| 495 /* TBD */ | |
| 496 #endif | |
| 497 | |
| 498 return 1; | |
| 499 } | |
| 500 #endif /* !RUN_INT_RAM */ |
