comparison src/g23m-fad/rlp/rlp_kerp.c @ 174:90eb61ecd093

src/g23m-fad: initial import from TCS3.2/LoCosto
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 12 Oct 2016 05:40:46 +0000
parents
children
comparison
equal deleted inserted replaced
173:bf64d785238a 174:90eb61ecd093
1 /*
2 +-----------------------------------------------------------------------------
3 | Project : CSD (8411)
4 | Modul : Rlp_kerp.c
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 functions for processing
18 | of incomming primitives for the component
19 | Radio Link Protocol of the base station
20 +-----------------------------------------------------------------------------
21 */
22
23 #ifndef RLP_KERP_C
24 #define RLP_KERP_C
25 #endif
26
27 #define ENTITY_RLP
28
29 /*==== INCLUDES ===================================================*/
30
31 #include <string.h>
32 #include "typedefs.h"
33 #include "vsi.h"
34 #include "macdef.h"
35 #include "custom.h"
36 #include "gsm.h"
37 #include "cus_rlp.h"
38 #include "prim.h"
39 #include "tok.h"
40 #include "rlp.h"
41
42 /*==== CONST =======================================================*/
43
44 /*==== TYPES =======================================================*/
45
46 /*==== VAR EXPORT ==================================================*/
47
48 /*==== VAR LOCAL ===================================================*/
49
50 /*==== FUNCTIONS ===================================================*/
51
52 /*
53 +------------------------------------------------------------------------------
54 | Function : ker_rlp_attach_req
55 +------------------------------------------------------------------------------
56 | Description : Process primitive RLP_ATTACH_REQ received from L2R.
57 |
58 | Parameters : rlp_attach_req -
59 |
60 |
61 | Return : -
62 +------------------------------------------------------------------------------
63 */
64
65
66 GLOBAL void ker_rlp_attach_req
67 (
68 T_RLP_ATTACH_REQ *rlp_attach_req
69 )
70 {
71 TRACE_FUNCTION ("ker_rlp_attach_req()");
72 PACCESS (rlp_attach_req);
73
74 /*******************************/
75 /*
76 * Initialize Shared Fax/Data memory
77 */
78 memset (rlp_data, 0, sizeof (T_RLP_DATA));
79
80 ker_init ();
81 snd_init (&rlp_data->snd);
82 rcv_init ();
83
84 rlp_data->uplink_frame_trace = FALSE;
85 rlp_data->downlink_frame_trace = FALSE;
86
87 rbm_reset(&rlp_data->rbm);
88 rlp_data_magic_num = RLP_DATA_MAGIC_NUM; /* memory is initialized */
89
90 /*******************************/
91
92 switch (GET_STATE (KER))
93 {
94 case RLP_ADM_AND_DETACHED:
95 /*
96 * processing for state RLP_ADM_AND_DETACHED
97 */
98
99 rlp_data->ker.Poll_xchg = IW_IDLE;
100 rlp_data->ker.SABM_State = ISW_IDLE;
101 rlp_data->ker.T1 = GEN_TO;
102 rlp_data->ker.T_ul = (USHORT)UL_TO;
103 rlp_data->ker.BytesPerPrim = rlp_attach_req->bytes_per_prim;
104
105 ker_set_frame_size (rlp_attach_req->rate);
106
107 ker_get_frame_desc (rlp_data->ker.UI_Frame,
108 &rlp_data->ker.UI_FrameDesc);
109
110 ker_get_frame_desc (rlp_data->ker.XID_C_Frame,
111 &rlp_data->ker.XID_C_FrameDesc);
112
113 ker_get_frame_desc (rlp_data->ker.XID_R_Frame,
114 &rlp_data->ker.XID_R_FrameDesc);
115
116 ker_get_frame_desc (rlp_data->ker.TEST_R_Frame,
117 &rlp_data->ker.TEST_R_FrameDesc);
118
119 ker_get_frame_desc (rlp_data->ker.REMAP_Frame,
120 &rlp_data->ker.REMAP_FrameDesc);
121
122 rlp_data->ker.TEST_R_State = IS_IDLE;
123 rlp_data->ker.UA_State = IS_IDLE;
124 rlp_data->ker.UI_State = IS_IDLE;
125 rlp_data->ker.XID_R_State = IS_IDLE;
126
127 ker_init_xid_data(rlp_attach_req);
128
129 SET_STATE (KER, RLP_ADM_AND_ATTACHED);
130 break;
131
132 default:
133 break;
134 }
135 PFREE (rlp_attach_req);
136 }
137
138 /*
139 +------------------------------------------------------------------------------
140 | Function : ker_rlp_detach_req
141 +------------------------------------------------------------------------------
142 | Description : Process primitive RLP_DETACH_REQ received from L2R.
143 |
144 | Parameters : rlp_detach_req -
145 |
146 |
147 | Return : -
148 +------------------------------------------------------------------------------
149 */
150
151
152 GLOBAL void ker_rlp_detach_req(T_RLP_DETACH_REQ *rlp_detach_req)
153 {
154 TRACE_FUNCTION ("ker_rlp_detach_req()");
155 PACCESS (rlp_detach_req);
156
157 /*
158 * processing for any kernel state
159 */
160 rlp_data->ker.DM_State = IS_IDLE;
161 ker_deinit_link_vars ();
162 SET_STATE (KER, RLP_ADM_AND_DETACHED);
163 {
164 PPASS (rlp_detach_req, rlp_detach_cnf, RLP_DETACH_CNF);
165 PSENDX (L2R, rlp_detach_cnf);
166 }
167 rlp_data_magic_num = 0; /* memory is no more initialized */
168 }
169
170 /*
171 +------------------------------------------------------------------------------
172 | Function : ker_rlp_connect_req
173 +------------------------------------------------------------------------------
174 | Description : Process primitive RLP_CONNECT_REQ received from L2R.
175 |
176 | Parameters : rlp_connect_req -
177 |
178 |
179 | Return : -
180 +------------------------------------------------------------------------------
181 */
182
183
184 GLOBAL void ker_rlp_connect_req
185 (
186 T_RLP_CONNECT_REQ *rlp_connect_req
187 )
188 {
189 TRACE_FUNCTION ("ker_rlp_connect_req()");
190 PACCESS (rlp_connect_req);
191
192 switch (GET_STATE (KER))
193 {
194 case RLP_ADM_AND_ATTACHED:
195 /*
196 * processing for state RLP_ADM_AND_ATTACHED
197 */
198 rlp_data->ker.SABM_State = ISW_SEND;
199 rlp_data->ker.SABM_Count = 0;
200 rlp_data->ker.DM_State = IS_IDLE;
201
202 SET_STATE (KER, RLP_PENDING_CONNECT_REQ);
203 break;
204
205 default:
206 break;
207 }
208 PFREE (rlp_connect_req);
209 }
210
211 /*
212 +------------------------------------------------------------------------------
213 | Function : ker_rlp_connect_res
214 +------------------------------------------------------------------------------
215 | Description : Process primitive RLP_CONNECT_RES received from L2R.
216 |
217 | Parameters : rlp_connect_res -
218 |
219 |
220 | Return : -
221 +------------------------------------------------------------------------------
222 */
223
224
225 GLOBAL void ker_rlp_connect_res
226 (
227 T_RLP_CONNECT_RES *rlp_connect_res
228 )
229 {
230 TRACE_FUNCTION ("ker_rlp_connect_res()");
231 PACCESS (rlp_connect_res);
232
233 switch (GET_STATE (KER))
234 {
235 case RLP_PENDING_CONNECT_IND:
236 {
237 /*
238 * processing for state RLP_PENDING_CONNECT_IND
239 */
240 rlp_data->ker.ABit = rlp_connect_res->ack_flg;
241
242 switch (rlp_data->ker.ABit)
243 {
244 case RLP_NAK:
245 rlp_data->ker.DM_State = IS_SEND;
246 rlp_data->ker.DM_FBit = 1;
247 SET_STATE (KER, RLP_ADM_AND_ATTACHED);
248 break;
249
250 case RLP_ACK:
251 rlp_data->ker.UA_State = IS_SEND;
252 rlp_data->ker.UA_FBit = 1;
253 ker_init_link_vars ();
254 SET_STATE (KER, RLP_CONNECTION_ESTABLISHED);
255 break;
256 }
257 }
258 }
259 PFREE (rlp_connect_res);
260 }
261
262 /*
263 +------------------------------------------------------------------------------
264 | Function : ker_rlp_disc_req
265 +------------------------------------------------------------------------------
266 | Description : Process primitive RLP_DISC_REQ received from L2R.
267 |
268 | Parameters : rlp_disc_req -
269 |
270 |
271 | Return : -
272 +------------------------------------------------------------------------------
273 */
274
275
276 GLOBAL void ker_rlp_disc_req
277 (
278 T_RLP_DISC_REQ *rlp_disc_req
279 )
280 {
281 TRACE_FUNCTION ("ker_rlp_disc_req()");
282 PACCESS (rlp_disc_req);
283
284 switch (GET_STATE (KER))
285 {
286 case RLP_ADM_AND_DETACHED:
287 case RLP_ADM_AND_ATTACHED:
288 /*
289 * processing for state RLP_ADM_AND_DETACHED
290 */
291 break;
292
293 default:
294 /*
295 * processing for any other state
296 */
297 TIMERSTOP (TT_HANDLE);
298
299 rlp_data->ker.DISC_State = ISW_SEND;
300 rlp_data->ker.DISC_Count = 0;
301
302 switch (rlp_data->ker.Poll_xchg)
303 {
304 case IW_IDLE:
305 rlp_data->ker.DISC_PBit = 1;
306 break;
307
308 default:
309 rlp_data->ker.DISC_PBit = 0;
310 break;
311 }
312
313 ker_deinit_link_vars ();
314 rlp_data->ker.DISC_Ind = FALSE;
315
316 SET_STATE (KER, RLP_DISCONNECT_INITIATED);
317 TRACE_EVENT("#1");
318 break;
319 }
320 PFREE (rlp_disc_req);
321 }
322
323 /*
324 +------------------------------------------------------------------------------
325 | Function : ker_rlp_reset_req
326 +------------------------------------------------------------------------------
327 | Description : Process primitive RLP_RESET_REQ received from L2R.
328 |
329 | Parameters : rlp_reset_req -
330 |
331 |
332 | Return : -
333 +------------------------------------------------------------------------------
334 */
335
336
337 GLOBAL void ker_rlp_reset_req
338 (
339 T_RLP_RESET_REQ *rlp_reset_req
340 )
341 {
342 TRACE_FUNCTION ("ker_rlp_reset_req()");
343 PACCESS (rlp_reset_req);
344
345 switch (GET_STATE (KER))
346 {
347 case RLP_CONNECTION_ESTABLISHED:
348 /*
349 * processing for state RLP_CONNECTION_ESTABLISHED
350 */
351 TIMERSTOP (TT_HANDLE);
352 TIMERSTOP (TRCVR_HANDLE);
353 ker_reset_all_t_rcvs ();
354
355 rlp_data->ker.SABM_State = ISW_SEND;
356 rlp_data->ker.SABM_Count = 0;
357
358 ker_deinit_link_vars ();
359
360 SET_STATE (KER, RLP_PENDING_RESET_REQ);
361 break;
362 }
363 PFREE (rlp_reset_req);
364 }
365
366 /*
367 +------------------------------------------------------------------------------
368 | Function : ker_rlp_reset_res
369 +------------------------------------------------------------------------------
370 | Description : Process primitive RLP_RESET_RES received from L2R.
371 |
372 | Parameters : rlp_reset_res -
373 |
374 |
375 | Return : -
376 +------------------------------------------------------------------------------
377 */
378
379
380 GLOBAL void ker_rlp_reset_res
381 (
382 T_RLP_RESET_RES *rlp_reset_res
383 )
384 {
385 TRACE_FUNCTION ("ker_rlp_reset_res()");
386 PACCESS (rlp_reset_res);
387
388 switch (GET_STATE (KER))
389 {
390 case RLP_PENDING_RESET_IND:
391 /*
392 * processing for state RLP_PENDING_RESET_IND
393 */
394 rlp_data->ker.UA_State = IS_SEND;
395 rlp_data->ker.UA_FBit = 1;
396
397 ker_init_link_vars ();
398 SET_STATE (KER, RLP_CONNECTION_ESTABLISHED);
399 break;
400 }
401 PFREE (rlp_reset_res);
402 }
403
404 /*
405 +------------------------------------------------------------------------------
406 | Function : ker_rlp_data_req
407 +------------------------------------------------------------------------------
408 | Description : Process primitive RLP_ATTACH_REQ received from L2R.
409 |
410 | Parameters : rlp_data_req -
411 |
412 |
413 | Return : -
414 +------------------------------------------------------------------------------
415 */
416
417
418 GLOBAL void ker_rlp_data_req
419 (
420 T_RLP_DATA_REQ *rlp_data_req
421 )
422 {
423 TRACE_FUNCTION ("ker_rlp_data_req()");
424 PACCESS (rlp_data_req);
425
426 switch (GET_STATE (KER))
427 {
428 case RLP_CONNECTION_ESTABLISHED:
429 switch (rlp_data->ker.UL_Snd_State)
430 {
431 case IW_WAIT:
432 sbm_store_prim (rlp_data_req);
433 rlp_data->ker.UL_Snd_State = IW_IDLE;
434 return;
435 }
436 break;
437 }
438 PFREE (rlp_data_req);
439 }
440
441 /*
442 +------------------------------------------------------------------------------
443 | Function : ker_rlp_getdata_req
444 +------------------------------------------------------------------------------
445 | Description : Process primitive RLP_GETDATA_REQ received from L2R.
446 |
447 | Parameters : rlp_getdata_req -
448 |
449 |
450 | Return : -
451 +------------------------------------------------------------------------------
452 */
453
454
455 GLOBAL void ker_rlp_getdata_req
456 (
457 T_RLP_GETDATA_REQ *rlp_getdata_req
458 )
459 {
460 TRACE_FUNCTION ("ker_rlp_getdata_req()");
461 PACCESS (rlp_getdata_req);
462
463 switch (GET_STATE (KER))
464 {
465 case RLP_CONNECTION_ESTABLISHED:
466 case RLP_PENDING_REMAP_REQ:
467 case RLP_REMAP_DATA:
468 {
469 T_RLP_DATA_IND *rlp_data_ind;
470 /*
471 * processing for states RLP_CONNECTION_ESTABLISHED
472 * RLP_PENDING_REMAP_REQ:
473 * RLP_REMAP_DATA:
474 */
475
476 if (rbm_get_prim
477 (
478 &rlp_data_ind,
479 &rlp_data->ker.LRReady,
480 &rlp_data->ker.LRFull
481 ))
482 {
483 /*
484 * primitive is ready for sending to L2R
485 */
486 PSENDX (L2R, rlp_data_ind);
487 rlp_data->ker.UL_Rcv_State = IW_IDLE;
488 TIMERSTOP (TUL_RCV_HANDLE);
489 }
490 else
491 {
492 /*
493 * no primitive is ready for sending to L2R
494 */
495 TIMERSTART(TUL_RCV_HANDLE, rlp_data->ker.T_ul);
496 rlp_data->ker.UL_Rcv_State = IW_WAIT;
497 }
498 break;
499 }
500 }
501 PFREE (rlp_getdata_req);
502 }
503
504 /*
505 +------------------------------------------------------------------------------
506 | Function : ker_rlp_ui_req
507 +------------------------------------------------------------------------------
508 | Description : Process primitive RLP_UI_REQ received from L2R.
509 |
510 | Parameters : rlp_ui_req -
511 |
512 |
513 | Return :
514 +------------------------------------------------------------------------------
515 */
516
517
518 GLOBAL void ker_rlp_ui_req
519 (
520 T_RLP_UI_REQ *rlp_ui_req
521 )
522 {
523 TRACE_FUNCTION ("ker_rlp_ui_req()");
524 PACCESS (rlp_ui_req);
525
526 switch (GET_STATE (KER))
527 {
528 case RLP_ADM_AND_DETACHED:
529 /*
530 * processing for state RLP_ADM_AND_DETACHED
531 */
532 break;
533
534 default:
535 ker_copy_sdu_to_frame
536 (
537 &rlp_ui_req->sdu,
538 rlp_data->ker.UI_Frame,
539 0
540 );
541
542 rlp_data->ker.UI_State = IS_SEND;
543 rlp_data->ker.UI_PBit = 0;
544 break;
545 }
546 PFREE (rlp_ui_req);
547 }
548
549 /*
550 +------------------------------------------------------------------------------
551 | Function : ker_rlp_remap_req
552 +------------------------------------------------------------------------------
553 | Description : Process primitive RLP_REMAP_REQ received from L2R.
554 |
555 | Parameters : rlp_remap_req -
556 |
557 |
558 | Return :
559 +------------------------------------------------------------------------------
560 */
561
562
563 GLOBAL void ker_rlp_remap_req
564 (
565 T_RLP_REMAP_REQ *rlp_remap_req
566 )
567 {
568 T_FRAME_NUM vr;
569 USHORT oldFrameSize;
570
571 TRACE_FUNCTION ("ker_rlp_remap_req()");
572 PACCESS (rlp_remap_req);
573
574 switch (GET_STATE (KER))
575 {
576 case RLP_CONNECTION_ESTABLISHED:
577 /*
578 * processing for state RLP_CONNECTION_ESTABLISHED
579 */
580 rlp_data->ker.OldFrameSize = rlp_data->ker.FrameSize;
581
582 ker_set_frame_size(rlp_remap_req->rate);
583
584 if (rlp_data->ker.OldFrameSize NEQ rlp_data->ker.FrameSize)
585 {
586 ker_get_frame_desc (rlp_data->ker.UI_Frame,
587 &rlp_data->ker.UI_FrameDesc);
588
589 ker_get_frame_desc (rlp_data->ker.XID_C_Frame,
590 &rlp_data->ker.XID_C_FrameDesc);
591
592 ker_get_frame_desc (rlp_data->ker.XID_R_Frame,
593 &rlp_data->ker.XID_R_FrameDesc);
594
595 ker_get_frame_desc (rlp_data->ker.TEST_R_Frame,
596 &rlp_data->ker.TEST_R_FrameDesc);
597
598 ker_get_frame_desc (rlp_data->ker.REMAP_Frame,
599 &rlp_data->ker.REMAP_FrameDesc);
600 rlp_data->ker.Poll_xchg = IW_IDLE;
601
602 TIMERSTOP (TT_HANDLE);
603 TIMERSTOP (TRCVR_HANDLE);
604 ker_reset_all_t_rcvs ();
605 rbm_reset_all_r_states();
606 TIMERSTOP (TXID_HANDLE);
607
608 SET_STATE(KERXID_C, ISW_IDLE);
609
610 rlp_data->ker.DTX_SF = DTX_N;
611
612 vr = rbm_prepare_remap (rlp_data->ker.FrameSize);
613
614 ker_fill_remap_frame(vr);
615
616 SET_STATE (KER, RLP_PENDING_REMAP_REQ);
617 }
618 break;
619
620 case RLP_PENDING_REMAP_REQ:
621 case RLP_REMAP_DATA:
622 /*
623 * processing for state RLP_PENDING_REMAP_REQ
624 */
625 oldFrameSize = rlp_data->ker.FrameSize;
626
627 ker_set_frame_size(rlp_remap_req->rate);
628
629 if (oldFrameSize NEQ rlp_data->ker.FrameSize)
630 {
631 ker_get_frame_desc (rlp_data->ker.UI_Frame,
632 &rlp_data->ker.UI_FrameDesc);
633
634 ker_get_frame_desc (rlp_data->ker.XID_C_Frame,
635 &rlp_data->ker.XID_C_FrameDesc);
636
637 ker_get_frame_desc (rlp_data->ker.XID_R_Frame,
638 &rlp_data->ker.XID_R_FrameDesc);
639
640 ker_get_frame_desc (rlp_data->ker.TEST_R_Frame,
641 &rlp_data->ker.TEST_R_FrameDesc);
642
643 ker_get_frame_desc (rlp_data->ker.REMAP_Frame,
644 &rlp_data->ker.REMAP_FrameDesc);
645 rlp_data->ker.Poll_xchg = IW_IDLE;
646
647 TIMERSTOP (TT_HANDLE);
648
649 vr = rbm_prepare_remap (rlp_data->ker.FrameSize);
650
651 ker_fill_remap_frame(vr);
652
653 if (GET_STATE (KER) EQ RLP_REMAP_DATA)
654 {
655 SET_STATE (KER, RLP_PENDING_REMAP_REQ);
656 }
657 }
658 break;
659 }
660 PFREE (rlp_remap_req);
661 }
662
663 /*
664 +------------------------------------------------------------------------------
665 | Function : ker_rlp_remap_data_res
666 +------------------------------------------------------------------------------
667 | Description : Process primitive RLP_REMAP_DATA_RES received from L2R.
668 |
669 | Parameters : rlp_remap_data_res -
670 |
671 |
672 | Return : -
673 +------------------------------------------------------------------------------
674 */
675
676
677 GLOBAL void ker_rlp_remap_data_res
678 (
679 T_RLP_REMAP_DATA_RES *rlp_remap_data_res
680 )
681 {
682 TRACE_FUNCTION ("ker_rlp_remap_data_res()");
683 PACCESS (rlp_remap_data_res);
684
685 switch (GET_STATE (KER))
686 {
687 case RLP_REMAP_DATA:
688 /*
689 * processing for state RLP_PENDING_REMAP_REQ
690 */
691 if (!ker_send_remap_data ())
692 {
693 PALLOC (rlp_remap_cnf, RLP_REMAP_CNF);
694
695 sbm_reset_after_remap
696 (
697 rlp_data->ker.FrameSize,
698 rlp_data->ker.RemapNr
699 );
700
701 PSENDX (L2R, rlp_remap_cnf);
702 SET_STATE (KER, RLP_CONNECTION_ESTABLISHED);
703 }
704 break;
705 }
706 PFREE (rlp_remap_data_res);
707 }
708