comparison src/g23m-gprs/grlc/grlc_gfff.c @ 183:219afcfc6250

src/g23m-gprs: initial import from TCS3.2/LoCosto
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 13 Oct 2016 04:24:13 +0000
parents
children
comparison
equal deleted inserted replaced
182:f02d0a0e1849 183:219afcfc6250
1 /*
2 +-----------------------------------------------------------------------------
3 | Project : GPRS (8441)
4 | Modul : GRLC
5 +-----------------------------------------------------------------------------
6 | Copyright 2002 Texas Instruments Berlin, AG
7 | All rights reserved.
8 |
9 | This file is confidential and a trade secret of Texas
10 | Instruments Berlin, AG
11 | The receipt of or possession of this file does not convey
12 | any rights to reproduce or disclose its contents or to
13 | manufacture, use, or sell anything it may describe, in
14 | whole, or in part, without the specific written consent of
15 | Texas Instruments Berlin, AG.
16 +-----------------------------------------------------------------------------
17 | Purpose : This module implements local functions for service GFF of
18 | entity GRLC.
19 +-----------------------------------------------------------------------------
20 */
21
22 #ifndef GRLC_GFFF_C
23 #define GRLC_GFFF_C
24 #endif
25
26 #define ENTITY_GRLC
27
28 /*==== INCLUDES =============================================================*/
29 #include <string.h>
30 #include "typedefs.h" /* to get Condat data types */
31 #include <stdio.h>
32 #include "vsi.h" /* to get a lot of macros */
33 #include "macdef.h"
34 #include "gprs.h"
35 #include "gsm.h" /* to get a lot of macros */
36 #include "ccdapi.h" /* to get CCD API */
37 #include "prim.h" /* to get the definitions of used SAP and directions */
38 #include "message.h"
39 #include "grlc.h"
40 #include "grlc_f.h"
41 #include "grlc_tms.h"
42 #include "grlc_rus.h"
43 #include "grlc_rds.h"
44 #include "grlc_gfff.h"
45 #include "cl_rlcmac.h"
46
47 /*==== CONST ================================================================*/
48
49 #define D_DL_DUMMY_c 0x25
50
51 /*==== LOCAL VARS ===========================================================*/
52
53 /*==== PRIVATE FUNCTIONS ====================================================*/
54
55 /*==== PUBLIC FUNCTIONS =====================================================*/
56
57 /*
58 +------------------------------------------------------------------------------
59 | Function : gff_init
60 +------------------------------------------------------------------------------
61 | Description : The function gff_init() ....
62 |
63 | Parameters : dummy - description of parameter dummy
64 |
65 +------------------------------------------------------------------------------
66 */
67 GLOBAL void gff_init ( void )
68 {
69 TRACE_FUNCTION( "gff_init" );
70
71 grlc_data->gff.rlc_status = RLC_STATUS_NULL;
72 grlc_data->ul_tfi = 0xFF;
73 grlc_data->dl_tfi = 0xFF;
74
75 grlc_data->next_poll_fn = 1;
76 grlc_data->ul_poll_pos_index = 0xFF;
77 grlc_data->nr_of_crc_errors = 0xFFFF;
78 grlc_data->ta_value = 0xFF;
79
80 INIT_STATE(GFF,GFF_DEACTIVE);
81 } /* gff_init() */
82
83
84
85 /*
86 +------------------------------------------------------------------------------
87 | Function : gff_tbf_init
88 +------------------------------------------------------------------------------
89 | Description : The function gff_tbf_init() ....
90 |
91 | Parameters : dummy - description of parameter dummy
92 |
93 +------------------------------------------------------------------------------
94 */
95 GLOBAL void gff_tbf_init ( void )
96 {
97 TRACE_FUNCTION( "gff_tbf_init" );
98
99 /*
100 * set segmented control block array
101 */
102 grlc_data->ul_poll_pos_index = 0;
103 grlc_data->nr_of_crc_errors = 0;
104
105
106 #if defined (_TARGET_)
107 {
108 UBYTE i;
109 /* target debugging*/
110
111 grlc_data->last_dl_fn = 1;
112
113 for (i=0; i < CALL_ERROR_NR_OF_ST_FN;i++)
114 {
115 grlc_data->ul_fn_store[i] = 0;
116 grlc_data->ul_fn_errors[i] = 0;
117 grlc_data->dl_fn_store[i] = 0;
118 grlc_data->dl_fn_errors[i] = 0;
119 }
120 grlc_data->ul_cnt_syn = 0; /*for target, count calls in rlc uplink*/
121 grlc_data->ul_cnt_asyn = 0; /*for target, count calls in gffp mac_ready_ind*/
122 grlc_data->dl_cnt_syn = 0; /*for target, count calls in rlc downlink*/
123 grlc_data->dl_cnt_asyn = 0; /*for target, count calls in gffp mac_data_ind*/
124 grlc_data->ul_call_errors = 0; /*for target, count calls in rlc uplink during grlc is active*/
125 grlc_data->dl_call_errors = 0; /*for target, count calls in rlc downlink during grlc is active*/
126 }
127 #endif /* defined (_TARGET_) */
128
129 } /* gff_tbf_init() */
130
131
132
133 /*
134 +------------------------------------------------------------------------------
135 | Function : gff_send_ctrl_block
136 +------------------------------------------------------------------------------
137 | Description : The function gff_send_ctrl_block() ....
138 |
139 | Parameters : dummy - description of parameter dummy
140 |
141 +------------------------------------------------------------------------------
142 */
143 GLOBAL void gff_send_ctrl_block (ULONG fn_i, UBYTE tn_i, UBYTE * ptr_ctrl_block_i )
144 {
145 PALLOC(cgrlc_data_ind,CGRLC_DATA_IND); /*T_CGRLC_DATA_IND*/
146
147 TRACE_FUNCTION( "gff_send_ctrl_block" );
148
149 cgrlc_data_ind->fn = fn_i;
150 cgrlc_data_ind->tn = tn_i;
151
152 memcpy( cgrlc_data_ind->data_array,
153 ptr_ctrl_block_i,
154 CGRLC_MAX_CTRL_MSG_SIZE );
155
156 PSEND(hCommGRR,cgrlc_data_ind);
157
158 }/* gff_send_ctrl_block() */
159
160
161
162
163 /*
164 +------------------------------------------------------------------------------
165 | Function : gff_analyse_dl_data
166 +------------------------------------------------------------------------------
167 | Description : The function gff_analyse_dl_data() .... It returns whether
168 | the downlink block was intended for that MS or not.
169 |
170 | Parameters : dummy - description of parameter dummy
171 |
172 +------------------------------------------------------------------------------
173 */
174 GLOBAL BOOL gff_analyse_dl_data (ULONG fn_i, T_dl_data * ptr_dl_data_i )
175 {
176
177 BOOL tfi_correct = FALSE;
178 UBYTE payload,rrbp,sp,tfi,*ptr_blk;
179
180 TRACE_FUNCTION( "gff_analyse_dl_data" );
181
182 /*
183 * Layer 1 buffer
184 * B1 B0 --> ptr_dl_data_i->dl_block[0]
185 * B3 B2
186 *
187 * B0 is the mac header
188 */
189
190
191 ptr_blk = (UBYTE *) (&ptr_dl_data_i->dl_block[0]);
192
193
194 payload = (ptr_blk[0] & 0xC0) >> 6;
195 rrbp = (ptr_blk[0] & 0x30) >> 4;
196 sp = (ptr_blk[0] & 0x08) >> 3;
197
198
199 /*
200 * In Test mode B,if there is CRC error on the payload data the MS will,
201 * where required by the USF, transmit the decoded payload data. The block
202 * transmitted will be a valid uplink block format.
203 */
204 if(((ptr_dl_data_i->block_status & 0x0100) NEQ 0x0000) AND ((grlc_data->testmode.mode EQ CGRLC_LOOP)))
205 {
206 UBYTE bsn,e_bit;
207
208 bsn = (ptr_blk[2] & 0xFE)>>1;
209 e_bit = (ptr_blk[2] & 0x01);
210
211 TRACE_EVENT(" Bad CRC - In Testmode B ");
212
213 sig_gff_rd_data( fn_i,
214 (UBYTE)ptr_dl_data_i->tn,
215 ptr_dl_data_i->block_status,
216 rrbp,
217 sp,
218 bsn,
219 0,
220 e_bit,
221 ptr_blk);
222 }
223 else
224 {
225 if(payload EQ RLC_DATA_BLOCK)
226 {
227 UBYTE bsn,fbi,e_bit;
228
229 tfi = (ptr_blk[1] & 0x3E) >> 1;
230 bsn = (ptr_blk[2] & 0xFE)>>1;
231 fbi = (ptr_blk[1] & 0x01);
232 e_bit = (ptr_blk[2] & 0x01);
233 ptr_blk = (UBYTE *) (&ptr_blk[3]);
234
235 if((tfi EQ grlc_data->dl_tfi) AND
236 ((0x80>>ptr_dl_data_i->tn) & grlc_data->dl_tn_mask))
237 {
238 tfi_correct = TRUE;
239 if(sp)
240 {
241 grlc_save_poll_pos ( fn_i,(UBYTE)ptr_dl_data_i->tn,rrbp, CGRLC_POLL_DATA, 3);
242 }
243 sig_gff_rd_data( fn_i,
244 (UBYTE)ptr_dl_data_i->tn,
245 ptr_dl_data_i->block_status,
246 rrbp,
247 sp,
248 bsn,
249 fbi,
250 e_bit,
251 ptr_blk);
252 #ifdef _TARGET_
253
254 TRACE_BINDUMP( hCommGRLC, TC_USER6,
255 "D_DATA_BLOCK including MAC header", &ptr_dl_data_i->dl_block[0],53);
256 #endif /* _TARGET_ */
257
258 }
259 else
260 {
261 TRACE_EVENT_P6("wrong tfi in data block ad.tfi=%d dl_tfi=%d bsn=%d || tn=%d->mask=%x tn_mask=%x"
262 ,tfi
263 ,grlc_data->dl_tfi
264 ,bsn
265 ,ptr_dl_data_i->tn
266 ,(0x80>>ptr_dl_data_i->tn)
267 ,grlc_data->dl_tn_mask);
268 }
269
270
271 }
272 else
273 {
274 /*
275 * any rlc control message received.
276 * check if it is a packet uplink ack/nack and if it is adressed to MS
277 */
278 ULONG tc_user = TC_USER4;
279 UBYTE trace_msg_type = D_MSG_TYPE_UNKNOWN_c;
280
281 UBYTE msg_type=0,i=0;
282
283 if( payload EQ CTRL_BLK_NO_OPT )
284 {
285 msg_type = trace_msg_type = ptr_blk[1]>>2;
286 i = 2; /* Byte position of tfi in puan */
287 }
288 else if( payload EQ CTRL_BLK_OPT )
289 {
290 if( !(ptr_blk[1] & 0x01) ) /* no tfi octet present: ac = 0 */
291 {
292 if( !(ptr_blk[1] & 0x80) ) /* not segmented : rbsn = 0 */
293 {
294 if( (ptr_blk[1] & 0x02) ) /* not segmented : fs = 1 */
295 {
296 msg_type = trace_msg_type = ptr_blk[2]>>2;
297 i = 3; /* Byte position of tfi in puan */
298 }
299 else /* segmented : fs = 0 */
300 {
301 trace_msg_type = ptr_blk[2]>>2;
302 }
303 }
304 else /* segmented : rbsn = 1 */
305 {
306 trace_msg_type = D_MSG_TYPE_2ND_SEGMENT_c;
307 }
308 }
309 else /* tfi octet present : ac = 1 */
310 {
311 if( !(ptr_blk[1] & 0x80) ) /* not segmented : rbsn = 0 */
312 {
313 if( (ptr_blk[1] & 0x02) ) /* not segmented : fs = 1 */
314 {
315 msg_type = trace_msg_type = ptr_blk[3]>>2;
316 i = 4; /* Byte position of tfi in puan */
317 }
318 else /* segmented : fs = 0 */
319 {
320 trace_msg_type = ptr_blk[3]>>2;
321 }
322 }
323 else /* segmented : rbsn = 1 */
324 {
325 trace_msg_type = D_MSG_TYPE_2ND_SEGMENT_c;
326 }
327 }
328 }
329
330 /*
331 * send control message to GRR
332 */
333 if(msg_type NEQ D_DL_DUMMY_c ) /* No Dummy blocks sent to GRR , to primitive load between GRR and GRLC*/
334 {
335 gff_send_ctrl_block(fn_i, (UBYTE)ptr_dl_data_i->tn,ptr_blk);
336 }
337
338 if( trace_msg_type EQ D_DL_DUMMY_c )
339 {
340 tc_user = TC_USER5;
341 }
342
343 TRACE_BINDUMP( hCommGRLC, tc_user,
344 cl_rlcmac_get_msg_name( trace_msg_type, RLC_MAC_ROUTE_DL ),
345 ptr_blk, MAX_L2_FRAME_SIZE ); /*lint !e569*/
346
347 if(msg_type EQ D_GRLC_UL_ACK_c)
348 {
349 /*
350 * tfi check for packet uplink ack nack
351 */
352 if(i EQ 4 AND /* tfi in header present */
353 !(ptr_blk[2] & 0x01) AND /* D=0 packet uplink tfi add. */
354 (((ptr_blk[2]) & 0x3E)>>1) EQ grlc_data->ul_tfi) /* header tfi addressed to MS */
355 {
356 tfi = ((ptr_blk[2]) & 0x3E)>>1;
357 }
358 else
359 {
360 tfi = ((ptr_blk[i]) & 0x3E)>>1; /* Take tfi from airmessage*/
361 }
362
363 if((grlc_data->ul_tfi EQ tfi) AND
364 ((0x80>>ptr_dl_data_i->tn) & grlc_data->ul_tn_mask))
365 {
366 T_MSGBUF msg;
367 UBYTE data[22];
368
369 memset(data,0xEE,22);
370
371 msg.l_buf = (23 - i + 1) * 8;
372 msg.o_buf = 0;
373 msg.buf[0] = data[0];
374
375 memcpy(msg.buf, &(ptr_blk[i-1]), (msg.l_buf)/8);
376
377
378 if(sp)
379 {
380 grlc_save_poll_pos ( fn_i,(UBYTE)ptr_dl_data_i->tn,rrbp, CGRLC_POLL_UACK, 3);
381 }
382 grlc_decode_grlc (&msg);
383 sig_gff_ru_ul_ack ( fn_i,(UBYTE)ptr_dl_data_i->tn,rrbp,sp);
384 }
385 }
386 }
387 }
388
389
390 return( tfi_correct );
391 } /* gff_analyse_dl_data() */
392
393
394 /*
395 +------------------------------------------------------------------------------
396 | Function : gff_handle_continious_ta
397 +------------------------------------------------------------------------------
398 | Description : store the new ta value, and pass it to L1
399 |
400 | Parameters :
401 |
402 +------------------------------------------------------------------------------
403 */
404 GLOBAL void gff_handle_continious_ta ( void )
405 {
406
407 TRACE_FUNCTION( "gff_handle_continious_ta" );
408
409
410 if(grlc_data->func.mac_ready_ind.ta_value NEQ 0xFF)
411 {
412 /*
413 * valid TA in L1
414 */
415 if(grlc_data->ta_value NEQ grlc_data->func.mac_ready_ind.ta_value )
416 {
417 PALLOC(cgrlc_ta_value_ind,CGRLC_TA_VALUE_IND);
418
419 /*
420 * Current TA in GRLC differs from the TA in L1: store in GRLC
421 */
422 grlc_data->ta_value = grlc_data->func.mac_ready_ind.ta_value;
423 cgrlc_ta_value_ind->ta_value = grlc_data->ta_value;
424 PSEND(hCommGRR,cgrlc_ta_value_ind);
425 }
426 }
427
428 } /* gff_handle_continious_ta */
429
430 /*
431 +------------------------------------------------------------------------------
432 | Function : gff_clip_rxlev
433 +------------------------------------------------------------------------------
434 | Description : This function is used to clip received signal level values.
435 |
436 | Parameters : clipp - pointer to clipped received signal level values
437 | rxlev - pointer to received signal level values
438 | number - number of received signal level values
439 |
440 +------------------------------------------------------------------------------
441 */
442 GLOBAL void gff_clip_rxlev ( UBYTE *clipp, UBYTE *rxlev, UBYTE number )
443 {
444 UBYTE i; /* used for counting */
445
446 TRACE_FUNCTION( "gff_clip_rxlev" );
447
448 for( i = 0; i < number; i++ )
449 {
450 if( (signed char)( rxlev[i] ) < MAC_RXLEV_MIN AND
451 rxlev[i] NEQ MAC_RXLEV_NONE )
452 {
453 clipp[i] = MAC_RXLEV_MIN;
454 }
455 else if ( (signed char)( rxlev[i] ) > MAC_RXLEV_MAX )
456 {
457 clipp[i] = MAC_RXLEV_MAX;
458 }
459 else if( rxlev[i] EQ MAC_RXLEV_NONE )
460 {
461 clipp[i] = MAC_RXLEV_NONE;
462 }
463 else
464 {
465 clipp[i] = rxlev[i];
466 }
467 }
468 } /* gff_clip_rxlev() */