comparison src/g23m-gprs/grlc/grlc_rus.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 signal handler functions for service
18 | RU of entity GRLC.
19 +-----------------------------------------------------------------------------
20 */
21
22 #ifndef GRLC_RUS_C
23 #define GRLC_RUS_C
24 #endif
25
26 #define ENTITY_GRLC
27
28 /*==== INCLUDES =============================================================*/
29
30 #include <stdio.h>
31 #include "typedefs.h" /* to get Condat data types */
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 "cnf_grlc.h" /* to get cnf-definitions */
38 #include "mon_grlc.h" /* to get mon-definitions */
39 #include "prim.h" /* to get the definitions of used SAP and directions */
40 #include "message.h"
41 #include "grlc.h" /* to get the global entity definitions */
42 #include "grlc_f.h"
43 #include "grlc_tms.h"
44 #include "grlc_ruf.h"
45 #include <string.h>
46
47
48 /*==== CONST ================================================================*/
49 /*#ifdef TRACE_ERROR
50 #undef TRACE_ERROR
51 #define TRACE_ERROR(x)
52 #endif
53 #ifdef TRACE_FUNCTION
54 #undef TRACE_FUNCTION
55 #define TRACE_FUNCTION(x)
56 #endif
57 #ifdef TRACE_ISIG
58 #undef TRACE_ISIG
59 #define TRACE_ISIG(x)
60 #endif*/
61 /*==== LOCAL VARS ===========================================================*/
62
63 /*==== PRIVATE FUNCTIONS ====================================================*/
64
65 /*==== PUBLIC FUNCTIONS =====================================================*/
66
67
68
69 /*
70 +------------------------------------------------------------------------------
71 | Function : sig_tm_ru_assign
72 +------------------------------------------------------------------------------
73 | Description : Handles the internal signal SIG_TM_RU_ASSIGN
74 |
75 | Parameters : dummy - description of parameter dummy
76 |
77 +------------------------------------------------------------------------------
78 */
79 GLOBAL void sig_tm_ru_assign ( void)
80 {
81 TRACE_ISIG( "sig_tm_ru_assign" );
82
83 switch( GET_STATE( RU ) )
84 {
85 case RU_WAIT_FOR_FIRST_CALL_ACK:
86 case RU_WAIT_FOR_FIRST_CALL_UACK:
87 /*
88 * reorg l1 one
89 */
90 {
91 grlc_data->ru.write_pos_index -= grlc_data->ru.nts_max;
92 }
93 TRACE_EVENT_P3("UL REASSIG during tbf starting time is running:%ld ul_tfi=%d st_fn_tfi=%d"
94 ,grlc_data->ul_tbf_start_time
95 ,grlc_data->ul_tfi
96 ,grlc_data->start_fn_ul_tfi);
97
98 /*lint -fallthrough*/
99
100 case RU_NULL:
101 if(grlc_data->ul_tfi EQ 0xFF)
102 grlc_data->ul_tfi = grlc_data->start_fn_ul_tfi;
103
104 switch( grlc_data->uplink_tbf.rlc_mode )
105 {
106 case CGRLC_RLC_MODE_ACK:
107 SET_STATE(RU,RU_WAIT_FOR_FIRST_CALL_ACK);
108 ru_tbf_init();
109 /*
110 * sending the first block of the tbf
111 */
112 grlc_data->ru.N3104 = 0;
113
114 while( grlc_data->ru.nts AND
115 tm_get_num_ctrl_blck( ) NEQ 0 )
116 { /*
117 * next uplink block is a control block,
118 * check if countdown procedure is statred or not
119 */
120 ru_send_control_block( );
121 }
122 while(grlc_data->ru.nts AND grlc_data->ru.sdu_len)
123 {
124 ru_new_data();
125 }
126 while(grlc_data->ru.nts)
127 {
128 ru_ret_bsn();
129 }
130 break;
131 case CGRLC_RLC_MODE_UACK:
132 SET_STATE(RU,RU_WAIT_FOR_FIRST_CALL_UACK);
133 ru_tbf_init();
134 while( grlc_data->ru.nts AND
135 tm_get_num_ctrl_blck( ) NEQ 0 )
136 { /*
137 * next uplink block is a control block,
138 * check if countdown procedure is statred or not
139 */
140 ru_send_control_block( );
141 }
142 while(grlc_data->ru.nts AND grlc_data->ru.sdu_len)
143 {
144 ru_new_data();
145 }
146 if(grlc_data->ru.cv EQ 0)
147 {
148 while( grlc_data->ru.nts
149 AND (grlc_data->ru.count_cv_0 < 4) )
150 {
151 UBYTE bsn;
152 bsn = grlc_data->ru.vs - 1;
153 bsn &= 0x7F;
154 ru_send_mac_data_req(bsn);
155 grlc_data->ru.count_cv_0++;
156 }
157 }
158 break;
159 default:
160 TRACE_ERROR( "unknown RLC MODE for UL" );
161 break;
162 }
163 break;
164 case RU_ACK:
165 case RU_REL_ACK:
166 case RU_UACK:
167 case RU_REL_UACK:
168 /*
169 * store new params, modification at reaching starting time
170 */
171 grlc_data->ru.next_tbf_params = grlc_data->uplink_tbf;
172 grlc_data->ru.v_next_tbf_params = TRUE;
173 break;
174 default:
175 TRACE_ERROR( "SIG_TM_RU_ASSIGN unexpected" );
176 break;
177 }
178 } /* sig_tm_ru_assign() */
179
180 /*
181 +------------------------------------------------------------------------------
182 | Function : sig_tm_ru_abrel
183 +------------------------------------------------------------------------------
184 | Description : Handles the internal signal SIG_TM_RU_ABREL
185 |
186 | Parameters : dummy - description of parameter dummy
187 |
188 +------------------------------------------------------------------------------
189 */
190 GLOBAL void sig_tm_ru_abrel (ULONG fn,BOOL poll_i)
191 {
192 TRACE_ISIG( "sig_tm_ru_abrel" );
193
194 /*
195 * stop all uplink timers
196 */
197 vsi_t_stop(GRLC_handle,T3164);
198 vsi_t_stop(GRLC_handle,T3166);
199 vsi_t_stop(GRLC_handle,T3180);
200 vsi_t_stop(GRLC_handle,T3182);
201 vsi_t_stop(GRLC_handle,T3184);/*timer for FA, used in simulation test*/
202 vsi_t_stop(GRLC_handle,T3188);/*timer for FA, used in simulation test*/
203
204 if (grlc_data->prim_start_tbf < PRIM_QUEUE_SIZE_TOTAL)
205 {
206 grlc_data->prim_queue[grlc_data->prim_start_tbf].rlc_status = FALSE;
207 grlc_data->prim_queue[grlc_data->prim_start_tbf].cv_status = FALSE;
208 grlc_data->prim_queue[grlc_data->prim_start_tbf].last_bsn = 0xFF;
209 }
210 if(!poll_i)
211 {
212 /*
213 * abnormal release: abort TBF
214 */
215 grlc_data->tbf_ctrl[grlc_data->ul_index].end_fn = grlc_data->ul_fn;
216 grlc_data->tbf_ctrl[grlc_data->ul_index].vs_vr = grlc_data->ru.vs;
217 grlc_data->tbf_ctrl[grlc_data->ul_index].va_vq = grlc_data->ru.va;
218 grlc_data->tbf_ctrl[grlc_data->ul_index].cnt_ts = grlc_data->ru.cnt_ts;
219 grlc_trace_tbf_par ( grlc_data->ul_index );
220 SET_STATE(RU,RU_NULL);
221 }
222 else
223 {
224 SET_STATE(RU,RU_NET_REL);
225 grlc_data->ru.poll_fn = fn;
226 TRACE_EVENT_P2("UL:RU_NET_REL p.tbf rel c_fn=%ld poll_fn=%d",grlc_data->dl_fn,grlc_data->ru.poll_fn);
227 }
228
229 } /* sig_tm_ru_abrel() */
230
231
232
233 /*
234 +------------------------------------------------------------------------------
235 | Function : sig_tm_ru_queue_status
236 +------------------------------------------------------------------------------
237 | Description : Handles the internal signal SIG_TM_RU_QUEUE_STATUS
238 |
239 | Parameters : dummy - description of parameter dummy
240 |
241 +------------------------------------------------------------------------------
242 */
243 GLOBAL void sig_tm_ru_queue_status ( void)
244 {
245 TRACE_ISIG( "sig_tm_ru_queue_status" );
246
247 switch( GET_STATE( RU ) )
248 {
249 case RU_WAIT_FOR_FIRST_CALL_ACK:
250 case RU_WAIT_FOR_FIRST_CALL_UACK:
251 case RU_ACK:
252 case RU_UACK:
253 grlc_data->ru.rlc_octet_cnt = ru_recalc_rlc_oct_cnt();
254 break;
255 default:
256 /*
257 * nothing to do
258 */
259 break;
260 }
261 } /* sig_tm_ru_queue_status() */
262
263
264
265
266 /*
267 +------------------------------------------------------------------------------
268 | Function : sig_gff_ru_ul_ack
269 +------------------------------------------------------------------------------
270 | Description : Handles the Signal SIG_GFF_RU_UL_ACK
271 |
272 | Parameters : fn - current frame number
273 | tn - current timeslot number
274 | rrbp - rrbp parameter indicated in mac header
275 | sp - sp parameter indicated in mac header
276 |
277 +------------------------------------------------------------------------------
278 */
279
280 GLOBAL void sig_gff_ru_ul_ack (ULONG fn , UBYTE tn, UBYTE rrbp, UBYTE sp)
281 {
282 MCAST(d_ul_ack,D_GRLC_UL_ACK);
283
284 TRACE_ISIG( "sig_gff_ru_ul_ack" );
285
286 #ifdef REL99
287 /* Handling abnormal case
288 * 8.7 While a TBF is in progress, if a mobile station receives a
289 * PACKET UPLINK ASSIGNMENT, PACKET UPLINK ACK/NACK or PACKET TIMESLOT RECONFIGURE
290 * message with message escape bit indicating EGPRS (resp. GPRS) contents whereas
291 * the current TBF mode is GPRS (resp. EGPRS), the mobile station shall ignore the
292 * message.
293 */
294 if(d_ul_ack->egprs_flag)
295 {
296 TRACE_ERROR( "EGPRS UL ACK/NACK received" );
297 return;
298 }
299 #endif
300
301 grlc_data->tbf_ctrl[grlc_data->ul_index].ack_cnt++;
302
303
304 if(grlc_data->uplink_tbf.mac_mode EQ CGRLC_MAC_MODE_FA)
305 {
306 vsi_t_stop(GRLC_handle,T3184);
307 if(!d_ul_ack->gprs_ul_ack_nack_info.ack_nack_des.f_ack_ind)
308 {
309 vsi_t_start(GRLC_handle,T3184,T3184_VALUE);
310 TRACE_EVENT("sig_gff_ru_ul_ack: T3184 started for FA");
311 }
312 sig_ru_tm_repeat_alloc();
313 }
314
315 switch( GET_STATE( RU ) )
316 {
317 case RU_ACK :
318 if(ru_contention_resolution())
319 {
320 SET_STATE(RU,RU_NULL);
321 return;
322 }
323 ru_update_vb();
324 grlc_data->ru.va = ru_calc_va();
325 ru_delete_prims(grlc_data->ru.va);
326 ru_handle_stall_ind();
327 break;
328 case RU_REL_ACK :
329 /*
330 * For proper release of ul tbf
331 */
332 vsi_t_stop(GRLC_handle,T3182);
333 if(ru_contention_resolution())
334 {
335 SET_STATE(RU,RU_NULL);
336 return;
337 }
338 if(sp)
339 {
340 grlc_data->ru.poll_fn = grlc_calc_new_poll_pos(fn,rrbp);
341 grlc_data->ru.poll_tn = tn;
342 }
343 if( !(d_ul_ack->gprs_ul_ack_nack_info.ack_nack_des.f_ack_ind) )
344 {
345 ru_update_vb();
346 grlc_data->ru.va = ru_calc_va();
347 ru_delete_prims(grlc_data->ru.va);
348 ru_handle_stall_ind();
349 }
350 else if(d_ul_ack->gprs_ul_ack_nack_info.ack_nack_des.f_ack_ind AND
351 grlc_data->ru.cv EQ 0)
352 {
353 SET_STATE(RU,RU_SEND_PCA);
354 ru_delete_prims(grlc_data->ru.vs);
355 grlc_data->ru.va = grlc_data->ru.vs;
356 grlc_data->ru.nr_nacked_blks = 0;
357 grlc_data->tbf_ctrl[grlc_data->ul_index].fbi = 1;
358 grlc_data->ru.reorg_l1_needed = TRUE; /* delete blocks, dummies will be placed */
359 if(!sp)
360 {
361 SET_STATE(RU,RU_NULL);
362 TRACE_EVENT("FAI = 1 received but no poll");
363 vsi_t_stop(GRLC_handle,T3180);
364 sig_ru_tm_error_ra();
365 }
366 #if defined REL99 AND defined TI_PS_FF_TBF_EST_PACCH
367 else
368 { /* network wishes to re-estab tbf on pacch */
369 if(d_ul_ack->gprs_ul_ack_nack_info.release_99_str_d_ul_ack.tbf_est EQ 1 AND
370 grlc_data->prim_start_tbf NEQ END_OF_LIST AND /*UL data is present*/
371 grlc_data->tbf_type NEQ TBF_TYPE_CONC /* No DL TBF */
372 )
373 {
374 grlc_data->ru.tbf_re_est = TRUE;
375 grlc_data->next_poll_array[grlc_data->poll_start_tbf].poll_type[tn] = CGRLC_POLL_RE_ASS;
376 }
377
378 }
379 #endif
380 }
381 else
382 {
383 /*
384 * if the mobile station has not started or has not completed the countdown procedure
385 * and it receives a Packet Uplink Ack/Nack with the Final Ack Indicator set,
386 * it shall perform an abnormal release with random access.
387 */
388 SET_STATE(RU,RU_NULL);
389 TRACE_ERROR( "FBI set, but cv > 0" );
390 sig_ru_tm_error_ra();
391 }
392 break;
393 case RU_UACK:
394 grlc_data->ru.va = grlc_data->ru.vs;
395 ru_handle_stall_ind();
396 break;
397 case RU_REL_UACK:
398 /*
399 * For proper release of ul tbf
400 */
401 vsi_t_stop(GRLC_handle,T3182);
402 grlc_data->ru.va = grlc_data->ru.vs;
403 ru_handle_stall_ind();
404 if(sp)
405 {
406 grlc_data->ru.poll_fn = grlc_calc_new_poll_pos(fn,rrbp);
407 grlc_data->ru.poll_tn = tn;
408 if( d_ul_ack->gprs_ul_ack_nack_info.ack_nack_des.f_ack_ind)
409 {
410 SET_STATE(RU,RU_SEND_PCA);
411 ru_delete_prims(grlc_data->ru.vs);
412
413 #if defined REL99 AND defined TI_PS_FF_TBF_EST_PACCH
414 if(d_ul_ack->gprs_ul_ack_nack_info.release_99_str_d_ul_ack.tbf_est EQ 1 AND
415 grlc_data->prim_start_tbf NEQ END_OF_LIST AND /*UL data is present*/
416 grlc_data->tbf_type NEQ TBF_TYPE_CONC /* No DL TBF */
417 )
418 {
419 grlc_data->ru.tbf_re_est = TRUE;
420 grlc_data->next_poll_array[grlc_data->poll_start_tbf].poll_type[tn] = CGRLC_POLL_RE_ASS;
421 }
422 #endif
423 }
424 }
425 /*
426 * this part is a workaround to pass GCF 14.16.1
427 * R&S is not setting the sp bit in final ack
428 */
429 else if( d_ul_ack->gprs_ul_ack_nack_info.ack_nack_des.f_ack_ind AND
430 (grlc_data->ru.cv EQ 0) AND
431 (grlc_data->testmode.mode EQ CGRLC_TEST_RANDOM))
432 {
433 TRACE_EVENT("SP bit not set in PULACK, FBI BIT SET --> PERFORM IMMEDIATE RELEASE DURING TMA");
434 sig_ru_tm_error_ra();
435 }
436 else if( d_ul_ack->gprs_ul_ack_nack_info.ack_nack_des.f_ack_ind AND
437 (grlc_data->testmode.mode EQ CGRLC_TEST_RANDOM))
438 {
439 TRACE_EVENT_P3("SP=0,FBI=1,CV=%d-> rlc_oct=%ld,sdu_l=%ld"
440 ,grlc_data->ru.cv
441 ,grlc_data->ru.rlc_octet_cnt
442 ,grlc_data->ru.sdu_len);
443 }
444 break;
445 case RU_SEND_PCA :
446 if(sp)
447 {
448 grlc_data->ru.poll_fn = grlc_calc_new_poll_pos(fn,rrbp);
449 grlc_data->ru.poll_tn = tn;
450 TRACE_EVENT_P1("NEW RU POLL FN AT =%ld ",grlc_data->ru.poll_fn);
451
452 #if defined REL99 AND defined TI_PS_FF_TBF_EST_PACCH
453 /*
454 * tbf re-establishment on pacch
455 */
456 if( d_ul_ack->gprs_ul_ack_nack_info.release_99_str_d_ul_ack.tbf_est EQ 1 AND /* network wishes to re-estab tbf on pacch */
457 grlc_data->prim_start_tbf NEQ END_OF_LIST AND /* ul data is present*/
458 grlc_data->tbf_type NEQ TBF_TYPE_CONC /* no dl tbf */
459 )
460 {
461 grlc_data->ru.tbf_re_est = TRUE;
462 grlc_data->next_poll_array[grlc_data->poll_start_tbf].poll_type[tn] = CGRLC_POLL_RE_ASS;
463 }
464 #endif
465 }
466 break;
467 default:
468 TRACE_ERROR( "SIG_GFF_RU_UL_ACK unexpected" );
469 break;
470 }
471 if(grlc_data->ru.cs_type NEQ (T_CODING_SCHEME)d_ul_ack->gprs_ul_ack_nack_info.chan_coding_cmd)
472 {
473 TRACE_EVENT_P7("ul ack:CS changed from %d to %d, ssn=%d, va=%d, vs=%d, neg_acked_blks=%d, fbi=%d ",
474 grlc_data->ru.cs_type,
475 d_ul_ack->gprs_ul_ack_nack_info.chan_coding_cmd,
476 d_ul_ack->gprs_ul_ack_nack_info.ack_nack_des.ssn,
477 grlc_data->ru.va,
478 grlc_data->ru.vs,
479 grlc_data->ru.nr_nacked_blks,
480 d_ul_ack->gprs_ul_ack_nack_info.ack_nack_des.f_ack_ind);
481 grlc_data->ru.cs_type = (T_CODING_SCHEME)d_ul_ack->gprs_ul_ack_nack_info.chan_coding_cmd;
482 ru_change_of_cs(grlc_data->ru.cs_type);
483 }
484 else if(grlc_data->ru.nr_nacked_blks OR d_ul_ack->gprs_ul_ack_nack_info.ack_nack_des.f_ack_ind)
485 {
486 ULONG rbb=0,i,dummy;
487 for(i=0; i<d_ul_ack->gprs_ul_ack_nack_info.ack_nack_des.ssn;i++)
488 {
489 dummy = (USHORT)d_ul_ack->gprs_ul_ack_nack_info.ack_nack_des.rbb[WIN_SIZE-1-i];
490 rbb += dummy <<i;
491 if(i EQ 31)
492 break;
493 }
494 TRACE_EVENT_P8("ul ack fn=%ld :ssn=%d,va=%d,vs=%d,neg_acked_blks=%d,fbi=%d,rbb=%lx,cnt_ts=%d",
495 fn,
496 d_ul_ack->gprs_ul_ack_nack_info.ack_nack_des.ssn,
497 grlc_data->ru.va,
498 grlc_data->ru.vs,
499 grlc_data->ru.nr_nacked_blks,
500 d_ul_ack->gprs_ul_ack_nack_info.ack_nack_des.f_ack_ind,
501 rbb,
502 grlc_data->ru.cnt_ts);
503 }
504 grlc_data->ru.bsn_ret = grlc_data->ru.va;
505
506
507
508 } /* sig_gff_ru_ul_ack() */
509
510
511 /*
512 +------------------------------------------------------------------------------
513 | Function : sig_gff_ru_mac_ready_ind
514 +------------------------------------------------------------------------------
515 | Description : Handles the Signal SIG_GFF_RU_MAC_READY_IND
516 |
517 | Parameters : *ptr_mac_ready_ind_i - Ptr to primitive MAC_READY_IND
518 |
519 +------------------------------------------------------------------------------
520 */
521 GLOBAL void sig_gff_ru_mac_ready_ind ( T_MAC_READY_IND * mac_ul_ready_ind)
522 {
523 UBYTE bsn=0xFF;
524 BOOL release_tbf=FALSE;
525 UBYTE rd_state=GET_STATE( RD );
526 UBYTE ctrl_blk_active_idx;
527 BOOL realloc_prr_allowed = FALSE;
528
529 TRACE_ISIG( "sig_gff_ru_mac_ready_ind" );
530
531
532 #if defined (_SIMULATION_)
533 TRACE_EVENT_P1("fn = %ld",mac_ul_ready_ind->fn );
534 TRACE_EVENT_P9("wpi=%d sent=%ld\n current.cnt=%d,bsn[0]=%d,bsn[1]=%d,bsn[2]=%d,bsn[3]=%d,nts=%d,nts_max=%d",
535 grlc_data->ru.write_pos_index,
536 mac_ul_ready_ind->rlc_blocks_sent,
537 grlc_data->ru.pl_retrans_current.cnt,
538 grlc_data->ru.pl_retrans_current.blk[0],
539 grlc_data->ru.pl_retrans_current.blk[1],
540 grlc_data->ru.pl_retrans_current.blk[2],
541 grlc_data->ru.pl_retrans_current.blk[3],
542 grlc_data->ru.nts,
543 grlc_data->ru.nts_max);
544 #endif /* defined (_SIMULATION_) */
545
546 ru_switch_ul_buffer (mac_ul_ready_ind->rlc_blocks_sent);
547 ru_check_pl_ret(mac_ul_ready_ind->rlc_blocks_sent);
548 if(grlc_data->ru.v_next_tbf_params AND
549 grlc_check_if_tbf_start_is_elapsed ( grlc_data->ul_tbf_start_time, ((mac_ul_ready_ind->fn+5)%FN_MAX)))
550 {
551 ru_handle_tbf_start_in_ptm( mac_ul_ready_ind->rlc_blocks_sent);
552 ru_cgrlc_st_time_ind();
553 }
554 grlc_handle_poll_pos (mac_ul_ready_ind->fn);
555 ru_handle_nts (mac_ul_ready_ind->rlc_blocks_sent);
556
557 switch( GET_STATE( RU ) )
558 {
559 case RU_WAIT_FOR_FIRST_CALL_ACK:
560 if( !grlc_data->ru.v_next_tbf_params AND
561 !grlc_check_if_tbf_start_is_elapsed ( grlc_data->ul_tbf_start_time, ((mac_ul_ready_ind->fn+5)%FN_MAX)))
562 {
563 TRACE_EVENT_P2("WAIT FOR UL STARTING TIME, DL IS RUNNING st=%ld c_fn=%ld",grlc_data->ul_tbf_start_time
564 ,mac_ul_ready_ind->fn);
565 grlc_send_rem_poll_pos(mac_ul_ready_ind->fn);
566 return;
567 }
568 if(grlc_data->ru.first_usf)
569 {
570 /*
571 * Tbf starting time is reached, start T3164
572 */
573 vsi_t_start(GRLC_handle,T3164,T3164_VALUE);
574 }
575 SET_STATE(RU,RU_ACK);
576 grlc_data->tbf_ctrl[grlc_data->ul_index].start_fn = mac_ul_ready_ind->fn;
577 if(!grlc_data->ru.cd_active AND
578 (grlc_data->ru.tbc <= grlc_data->uplink_tbf.bs_cv_max))
579 {
580 grlc_data->ru.cd_active = TRUE;
581 ru_set_prim_queue(grlc_data->ru.cd_active);
582 }
583 ru_cgrlc_st_time_ind();
584 TRACE_EVENT_P9 ("UL first call:fn=%ld (%ld) tfi=%d ul_mask=%x st_fn=%ld pdu_cnt=%d,PST=%d,PSF=%d ta=%d",
585 mac_ul_ready_ind->fn,
586 mac_ul_ready_ind->fn%42432,
587 grlc_data->ul_tfi,
588 grlc_data->ul_tn_mask,
589 grlc_data->ul_tbf_start_time,
590 grlc_data->grlc_data_req_cnt,
591 grlc_data->prim_start_tbf,
592 grlc_data->prim_start_free,
593 grlc_data->ta_value);
594
595 /*lint -fallthrough*/
596
597 case RU_ACK :
598 /*
599 * Handling of counter N3104
600 */
601 if(ru_handle_n3104())
602 {
603 SET_STATE(RU,RU_NULL);
604 TRACE_ERROR( "counter N3104 reaches its maximum, contention resolution has failed" );
605 TRACE_EVENT_P7("va=%d,vs=%d,cnt_ts=%d,fn=%d n3104_max=%d,n3104=%d,bs_cv_max=%d",
606 grlc_data->ru.va,
607 grlc_data->ru.vs,
608 grlc_data->ru.cnt_ts,
609 mac_ul_ready_ind->fn,
610 grlc_data->ru.N3104_MAX,
611 grlc_data->ru.N3104,
612 grlc_data->uplink_tbf.bs_cv_max);
613 sig_ru_tm_error_ra();
614 return;
615 }
616 /*
617 * IS THERE A CONTROL BLOCK TO SEND ?
618 */
619 while( grlc_data->ru.nts AND
620 !grlc_data->ru.cd_active AND
621 tm_get_num_ctrl_blck( ) NEQ 0 )
622 { /*
623 * next uplink block is a control block,
624 * check if countdown procedure is statred or not
625 */
626 ru_send_control_block( );
627 }
628
629 /*
630 * IS RETRANSMISSION NEEDED ?
631 */
632 while(grlc_data->ru.nts)
633 {
634 ctrl_blk_active_idx = ru_peek_for_ctrl_blk();
635 if ((ctrl_blk_active_idx EQ 0xFF) OR
636 realloc_prr_allowed EQ TRUE) /*No control block , form data block*/
637 {
638 while( (grlc_data->ru.vb[grlc_data->ru.bsn_ret & WIN_MOD] EQ VB_NACKED) AND
639 grlc_data->ru.nts)
640 {
641 ru_ret_bsn();
642 }
643
644 while(grlc_data->ru.nts)
645 {
646 /*
647 * IS THERE A STALL CONDITION ?
648 */
649 if(grlc_data->ru.vs EQ ((grlc_data->ru.va + WIN_SIZE) & 0x7F))
650 {
651 ru_stall_ind();
652 }
653 /*
654 * IS THERE MORE DATA ?
655 */
656 else if(grlc_data->ru.sdu_len)
657 {
658 ru_new_data();
659 }
660 else
661 {
662 break;
663 }
664 }
665 realloc_prr_allowed = FALSE;
666 break;
667 }
668 else
669 {
670
671 TRACE_EVENT_P1("reallocation of llc pdu (index)=%d",ctrl_blk_active_idx);
672
673 /* if already one PRR in L1 Buffer , replace it with new PRR */
674 if (grlc_data->ru.pl_retrans_current.blk[0]
675 EQ (BLK_INDEX_TM + OFFSET_CTRL_BLOCK_IDX))
676 {
677 grlc_data->ru.write_pos_index--;
678 grlc_data->ru.pl_retrans_current.cnt--;
679 grlc_data->ru.nts++;
680 TRACE_EVENT("prr in l1 buffer queue,replace with new prr");
681 }
682 sig_ru_tm_end_of_pdu(ctrl_blk_active_idx);
683 ru_send_control_block();
684 realloc_prr_allowed = TRUE;
685 }
686 }
687 if( grlc_data->ru.cv EQ 0)
688 {
689 SET_STATE(RU,RU_REL_ACK);
690 grlc_data->ru.bsn_ret = grlc_data->ru.va;
691 }
692 while(grlc_data->ru.nts)
693 {
694 ru_ret_bsn();
695 }
696 grlc_send_rem_poll_pos (mac_ul_ready_ind->fn);
697 break;
698 case RU_REL_ACK :
699 /*
700 * All blocks are sent, wait for the last ack.
701 * If uplink resources are available retransmit window
702 */
703 if(ru_handle_n3104())
704 {
705 SET_STATE(RU,RU_NULL);
706 TRACE_ERROR( "counter N3104 reaches its maximum, contention resolution has failed" );
707 sig_ru_tm_error_ra();
708 grlc_data->ru.nts = 0; /*to avoid transmitting of data*/
709 return;
710 }
711
712 /*
713 * IS THERE A CONTROL BLOCK TO SEND ?
714 */
715 while( grlc_data->ru.nts AND
716 tm_get_num_ctrl_blck( ) NEQ 0 AND
717 ru_ctrl_blk_selection_allowed())
718 {
719 /*
720 * next uplink block is a control block,
721 */
722 TRACE_EVENT("Ctrl blk selected in RU_REL_ACK");
723 ru_send_control_block( );
724 }
725 while(grlc_data->ru.nts)
726 {
727 ctrl_blk_active_idx = ru_peek_for_ctrl_blk();
728 if ((ctrl_blk_active_idx EQ 0xFF) OR
729 realloc_prr_allowed EQ TRUE) /*No control block , form data block*/
730 {
731 while(grlc_data->ru.nts AND (grlc_data->ru.va NEQ grlc_data->ru.vs))
732 {
733 ru_ret_bsn();
734 }
735
736 while(grlc_data->ru.nts)
737 {
738 TRACE_EVENT_P3("ALL BLKS ACKED, wait for fbi in PUAN wpi=%d t3182=%d t3180=%d"
739 ,grlc_data->ru.write_pos_index
740 ,grlc_t_status( T3182 )
741 ,grlc_t_status( T3180 ));
742 ru_send_ul_dummy_block();
743 }
744 realloc_prr_allowed = FALSE;
745 break;
746 }
747 else
748 {
749
750 TRACE_EVENT_P1("reallocation of llc pdu (index)=%d",ctrl_blk_active_idx);
751
752 /* if already one PRR in L1 Buffer , replace it with new PRR */
753 if (grlc_data->ru.pl_retrans_current.blk[0]
754 EQ (BLK_INDEX_TM + OFFSET_CTRL_BLOCK_IDX))
755 {
756 grlc_data->ru.write_pos_index--;
757 grlc_data->ru.pl_retrans_current.cnt--;
758 grlc_data->ru.nts++;
759 TRACE_EVENT("prr in l1 buffer queue,replace with new prr");
760 }
761 sig_ru_tm_end_of_pdu(ctrl_blk_active_idx);
762 ru_send_control_block();
763 realloc_prr_allowed = TRUE;
764 }
765 }
766 grlc_send_rem_poll_pos (mac_ul_ready_ind->fn);
767 break;
768 case RU_SEND_PCA:
769 while(grlc_data->ru.nts)
770 {
771 ru_send_ul_dummy_block();
772 }
773 #ifdef _TARGET_
774 if( grlc_check_dist(mac_ul_ready_ind->fn,grlc_data->ru.poll_fn,100) )
775 {
776 if ((mac_ul_ready_ind->fn NEQ grlc_data->ru.poll_fn) AND
777 (mac_ul_ready_ind->last_poll_resp EQ 0))
778 {
779 release_tbf = TRUE;
780 /*TRACE_EVENT_P2("REL TBF:fn =%ld new ru_poll_fn=%ld",
781 mac_ul_ready_ind->fn,
782 grlc_data->ru.poll_fn);*/
783
784 }
785 else if(mac_ul_ready_ind->last_poll_resp)
786 {
787 grlc_data->ru.poll_fn +=104;
788 grlc_data->ru.poll_fn %= FN_MAX;
789 TRACE_ERROR("UL GAP: UL TBF NOT RELEASED +104");
790 TRACE_EVENT_P3("fn =%ld new ru_poll_fn=%ld poll_staus=%d",
791 mac_ul_ready_ind->fn,
792 grlc_data->ru.poll_fn,
793 mac_ul_ready_ind->last_poll_resp);
794 }
795 if(grlc_data->missed_poll_fn EQ grlc_data->ru.poll_fn)
796 {
797 release_tbf = FALSE;
798 grlc_data->ru.poll_fn +=104;
799 grlc_data->ru.poll_fn %= FN_MAX;
800 TRACE_ERROR("DL GAP: UL TBF NOT RELEASED +104");
801 TRACE_EVENT_P3("fn =%ld missed poll=%ld new ru_poll_fn=%ld",
802 mac_ul_ready_ind->fn,
803 grlc_data->missed_poll_fn,
804 grlc_data->ru.poll_fn);
805 }
806
807 }
808 #endif
809 #ifdef _SIMULATION_
810 if(mac_ul_ready_ind->fn EQ grlc_data->ru.poll_fn)
811 release_tbf = TRUE;
812 #endif
813 grlc_send_rem_poll_pos (mac_ul_ready_ind->fn);
814 if(release_tbf)
815 {
816 vsi_t_stop(GRLC_handle,T3182);
817 vsi_t_stop(GRLC_handle,T3180);
818 if ( grlc_data->poll_start_tbf NEQ 0xFF AND
819 (!grlc_check_if_tbf_start_is_elapsed(grlc_data->dl_tbf_start_time,grlc_data->next_poll_array[grlc_data->
820 poll_start_tbf].fn) AND
821 (rd_state EQ RD_WAIT_FOR_STARTING_TIME_ACK OR
822 rd_state EQ RD_WAIT_FOR_STARTING_TIME_UACK)) )
823 {
824 grlc_data->ru.poll_fn = grlc_data->next_poll_array[grlc_data->poll_start_tbf].fn;
825 TRACE_EVENT_P2("UL DELAYED WHILE WAITING STARTING TIME DL poll_fn=%ld c_fn=%ld",grlc_data->next_poll_array[grlc_data->poll_start_tbf].fn
826 ,mac_ul_ready_ind->fn);
827 }
828 else
829 {
830 SET_STATE(RU,RU_NULL);
831 grlc_data->tbf_ctrl[grlc_data->ul_index].end_fn = grlc_data->ul_fn;
832 grlc_data->tbf_ctrl[grlc_data->ul_index].vs_vr = grlc_data->ru.vs;
833 grlc_data->tbf_ctrl[grlc_data->ul_index].va_vq = grlc_data->ru.va;
834 grlc_data->tbf_ctrl[grlc_data->ul_index].cnt_ts = grlc_data->ru.cnt_ts;
835 grlc_trace_tbf_par ( grlc_data->ul_index );
836
837 #if defined REL99 AND defined TI_PS_FF_TBF_EST_PACCH
838 if(grlc_data->ru.tbf_re_est)
839 {
840 /*
841 * signal tm to start timer 3168,re-establish tbf on pacch as poll sent succesfully
842 */
843 sig_ru_tm_ul_re_est_tbf();
844 }
845 else
846 #endif
847 {
848 sig_ru_tm_end_of_tbf();
849 }
850 }
851 }
852 break;
853
854 case RU_WAIT_FOR_FIRST_CALL_UACK:
855 if( !grlc_data->ru.v_next_tbf_params AND
856 !grlc_check_if_tbf_start_is_elapsed ( grlc_data->ul_tbf_start_time, ((mac_ul_ready_ind->fn+5)%FN_MAX)))
857 {
858 TRACE_EVENT_P2("UACK MODE WAIT FOR UL STARTING TIME, DL IS RUNNING st=%ld c_fn=%ld",grlc_data->ul_tbf_start_time
859 ,mac_ul_ready_ind->fn);
860 grlc_send_rem_poll_pos(mac_ul_ready_ind->fn);
861 return;
862 }
863 if(grlc_data->ru.first_usf)
864 {
865 /*
866 * Tbf starting time is reached, start T3164
867 */
868 vsi_t_start(GRLC_handle,T3164,T3164_VALUE);
869 }
870 grlc_data->tbf_ctrl[grlc_data->ul_index].start_fn = mac_ul_ready_ind->fn;
871 SET_STATE(RU,RU_UACK);
872 if(!grlc_data->ru.cd_active AND
873 (grlc_data->ru.tbc <= grlc_data->uplink_tbf.bs_cv_max))
874 {
875 grlc_data->ru.cd_active = TRUE;
876 ru_set_prim_queue(grlc_data->ru.cd_active);
877 }
878 ru_cgrlc_st_time_ind();
879 TRACE_EVENT_P9 ("UL first call:fn=%ld (%ld) tfi=%d ul_mask=%x st_fn=%ld pdu_cnt=%d,PST=%d,PSF=%d ta=%d UACK_MODE",
880 mac_ul_ready_ind->fn,
881 mac_ul_ready_ind->fn%42432,
882 grlc_data->ul_tfi,
883 grlc_data->ul_tn_mask,
884 grlc_data->ul_tbf_start_time,
885 grlc_data->grlc_data_req_cnt,
886 grlc_data->prim_start_tbf,
887 grlc_data->prim_start_free,
888 grlc_data->ta_value);
889 /*lint -fallthrough*/
890
891 case RU_UACK :
892 ru_del_prim_in_uack_mode ( mac_ul_ready_ind->rlc_blocks_sent);
893 if(grlc_data->ru.last_bsn EQ LAST_BSN_STALL_CONDITION)
894 { /*in uack mode is transmission at stall condition of data not allowed*/
895 grlc_data->ru.nts = 0;
896 }
897 else if (grlc_data->ru.last_bsn EQ LAST_BSN_RESUME_UACK_MODE_AFTER_SI)
898 { /* data transmission allowed after stall indication in rlc unackgnowledged mode*/
899 grlc_data->ru.nts = grlc_data->ru.nts_max;
900 grlc_data->ru.last_bsn = LAST_BSN_NOT_BULIT;
901 TRACE_EVENT(" STALL IND ELIMINATED IN RLC UACK");
902 }
903 /*
904 * IS THERE A CONTROL BLOCK TO SEND ?
905 */
906 while( grlc_data->ru.nts AND
907 !grlc_data->ru.cd_active AND
908 tm_get_num_ctrl_blck( ) NEQ 0 )
909 {
910 ru_send_control_block( );
911 }
912 /*
913 * IS THERE MORE DATA ?
914 */
915 while(grlc_data->ru.nts)
916 {
917 ctrl_blk_active_idx = ru_peek_for_ctrl_blk();
918 if ((ctrl_blk_active_idx EQ 0xFF) OR
919 realloc_prr_allowed EQ TRUE) /*No control block , form data block*/
920 {
921 while( grlc_data->ru.nts AND
922 grlc_data->ru.sdu_len )
923 {
924 ru_new_data();
925 }
926 if (grlc_test_mode_active())
927 {
928 /*
929 * to prevent stall indication in Testmode A/B
930 */
931 grlc_data->ru.va = grlc_data->ru.vs;
932 }
933
934 while( grlc_data->ru.nts
935 AND (grlc_data->ru.count_cv_0 < 4) )
936 {
937 bsn = (grlc_data->ru.vs - 1) % 128;
938 ru_send_mac_data_req(bsn);
939 grlc_data->ru.count_cv_0++;
940 }
941 while(grlc_data->ru.nts)
942 {
943 ru_send_ul_dummy_block();
944 }
945 realloc_prr_allowed = FALSE;
946 break;
947 }
948 else
949 {
950
951 TRACE_EVENT_P1("reallocation of llc pdu (index)=%d",ctrl_blk_active_idx);
952
953 /* if already one PRR in L1 Buffer , replace it with new PRR */
954 if (grlc_data->ru.pl_retrans_current.blk[0]
955 EQ (BLK_INDEX_TM + OFFSET_CTRL_BLOCK_IDX))
956 {
957 grlc_data->ru.write_pos_index--;
958 grlc_data->ru.pl_retrans_current.cnt--;
959 grlc_data->ru.nts++;
960 TRACE_EVENT("prr in l1 buffer queue,replace with new prr");
961 }
962 sig_ru_tm_end_of_pdu(ctrl_blk_active_idx);
963 ru_send_control_block();
964 realloc_prr_allowed = TRUE;
965 }
966 }
967
968 if(grlc_data->ru.cv EQ 0)
969 {
970 SET_STATE(RU,RU_REL_UACK);
971 }
972 grlc_send_rem_poll_pos (mac_ul_ready_ind->fn);
973 break;
974 case RU_REL_UACK:
975 ru_del_prim_in_uack_mode ( mac_ul_ready_ind->rlc_blocks_sent);
976
977 /*
978 * IS THERE A CONTROL BLOCK TO SEND ?
979 */
980 while( grlc_data->ru.nts AND
981 tm_get_num_ctrl_blck( ) NEQ 0 AND
982 ru_ctrl_blk_selection_allowed())
983 {
984 /*
985 * next uplink block is a control block,
986 */
987 TRACE_EVENT("Ctrl blk selected in RU_REL_UACK");
988 ru_send_control_block( );
989 }
990 while(grlc_data->ru.nts)
991 {
992 ctrl_blk_active_idx = ru_peek_for_ctrl_blk();
993 if ((ctrl_blk_active_idx EQ 0xFF) OR
994 realloc_prr_allowed EQ TRUE) /*No control block , form data block*/
995 {
996 while( grlc_data->ru.nts AND
997 (grlc_data->ru.count_cv_0 < 4) )
998 {
999 bsn = (grlc_data->ru.vs - 1) % 128;
1000 ru_send_mac_data_req(bsn);
1001 grlc_data->ru.count_cv_0++;
1002 }
1003 while(grlc_data->ru.nts)
1004 {
1005 ru_send_ul_dummy_block();
1006 }
1007 realloc_prr_allowed = FALSE;
1008 break;
1009 }
1010 else
1011 {
1012
1013 TRACE_EVENT_P1("reallocation of llc pdu (index)=%d",ctrl_blk_active_idx);
1014
1015 /* if already one PRR in L1 Buffer , replace it with new PRR */
1016 if (grlc_data->ru.pl_retrans_current.blk[0]
1017 EQ (BLK_INDEX_TM + OFFSET_CTRL_BLOCK_IDX))
1018 {
1019 grlc_data->ru.write_pos_index--;
1020 grlc_data->ru.pl_retrans_current.cnt--;
1021 grlc_data->ru.nts++;
1022 TRACE_EVENT("prr in l1 buffer queue,replace with new prr");
1023 }
1024 sig_ru_tm_end_of_pdu(ctrl_blk_active_idx);
1025 ru_send_control_block();
1026 realloc_prr_allowed = TRUE;
1027 }
1028 }
1029 grlc_send_rem_poll_pos (mac_ul_ready_ind->fn);
1030 break;
1031 case RU_NET_REL:
1032 /*
1033 * send packet control acknowledgement and abort TBF
1034 */
1035 grlc_send_rem_poll_pos(mac_ul_ready_ind->fn);
1036 if(grlc_data->ru.release_tbf)
1037 {
1038 SET_STATE(RU,RU_NULL);
1039 grlc_data->ru.release_tbf = FALSE;
1040 TRACE_EVENT_P2("poll sent after packet tbf release(UL): current_fn=%ld rel_fn=%ld",
1041 mac_ul_ready_ind->fn,
1042 grlc_data->ru.poll_fn);
1043 vsi_t_stop(GRLC_handle,T3180);
1044 vsi_t_stop(GRLC_handle,T3182);
1045 grlc_data->tbf_ctrl[grlc_data->ul_index].end_fn = grlc_data->ul_fn;
1046 grlc_data->tbf_ctrl[grlc_data->ul_index].vs_vr = grlc_data->ru.vs;
1047 grlc_data->tbf_ctrl[grlc_data->ul_index].va_vq = grlc_data->ru.va;
1048 grlc_data->tbf_ctrl[grlc_data->ul_index].cnt_ts = grlc_data->ru.cnt_ts;
1049 grlc_trace_tbf_par ( grlc_data->ul_index );
1050 sig_ru_tm_end_of_tbf();
1051 }
1052 if(grlc_check_if_tbf_start_is_elapsed ( grlc_data->ru.poll_fn, mac_ul_ready_ind->fn))
1053 {
1054 grlc_data->ru.release_tbf = TRUE;
1055 TRACE_EVENT_P2("wait for poll confirm after packet tbf release(UL) current_fn=%ld rel_fn=%ld",
1056 mac_ul_ready_ind->fn,
1057 grlc_data->ru.poll_fn);
1058 }
1059 break;
1060 default:
1061 TRACE_ERROR( "MAC_UL_READY_IND unexpected" );
1062 break;
1063 }
1064
1065 if(grlc_data->uplink_tbf.mac_mode EQ CGRLC_MAC_MODE_FA AND
1066 grlc_data->uplink_tbf.fa_manag.current_alloc.alloc_end_fn EQ mac_ul_ready_ind->fn)
1067 {
1068 sig_ru_tm_end_of_fix_alloc();
1069 }
1070
1071
1072
1073 } /* sig_gff_ru_mac_ready_ind() */
1074
1075
1076
1077 /*
1078 +------------------------------------------------------------------------------
1079 | Function : sig_tm_ru_reset_poll_array
1080 +------------------------------------------------------------------------------
1081 | Description : Handles the Signal SIG_TM_RU_RESET_POLL_ARRAY.
1082 |
1083 | Parameters :
1084 |
1085 +------------------------------------------------------------------------------
1086 */
1087
1088 GLOBAL void sig_tm_ru_reset_poll_array()
1089 {
1090 UBYTE i,j;
1091 /*
1092 * handle not_transmitted control blocks
1093 */
1094 for (i=0;i<NEXT_POLL_ARRAY_SIZE;i++)
1095 {
1096 /*
1097 * set free list
1098 */
1099 grlc_data->next_poll_array[i].next = i+1;
1100 grlc_data->next_poll_array[i].fn = 0xFFFFFFFF;
1101 grlc_data->next_poll_array[i].cnt = 0;
1102 for(j=0; j< POLL_TYPE_ARRAY_SIZE; j++)
1103 {
1104 grlc_data->next_poll_array[i].poll_type[j] = CGRLC_POLL_NONE;
1105 }
1106 }
1107 /*
1108 * last free entry points to 0xff
1109 */
1110 grlc_data->next_poll_array[NEXT_POLL_ARRAY_SIZE-1].next = 0xFF;
1111 /*
1112 * indicates invalid paramters
1113 */
1114 grlc_data->poll_start_free = 0;
1115 grlc_data->poll_start_tbf = 0xFF;
1116 }
1117
1118