comparison gsm-fw/g23m-gsm/dl/dl_dcch0.c @ 673:2f7df7a314f8

gsm-fw/g23m-gsm subtree: initial import from LoCosto source
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 28 Sep 2014 23:20:04 +0000
parents
children d6a9b9fce09e
comparison
equal deleted inserted replaced
672:0dc6f9e8e980 673:2f7df7a314f8
1 /*
2 +-----------------------------------------------------------------------------
3 | Project : GSM-PS
4 | Modul : DL_DCCH0
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 the stand alone
18 | dedicated control channel (SDCCH) and the fast dedicated
19 | control channel (FACCH) each with SAPI 0 of the component DL
20 +-----------------------------------------------------------------------------
21 */
22
23 #ifndef DL_DCCH0_C
24 #define DL_DCCH0_C
25
26 #define ENTITY_DL
27
28 /*==== INCLUDES ===================================================*/
29 #include "typedefs.h"
30 #include "string.h"
31 #include "vsi.h"
32 #include "pconst.cdg"
33 #include "custom.h"
34 #include "gsm.h"
35 #include "mon_dl.h"
36 #include "prim.h"
37 #include "pei.h"
38 #include "tok.h"
39 #include "ccdapi.h"
40 #include "dl.h"
41 #include "dl_trc.h"
42
43 /*==== EXPORT =====================================================*/
44 /*==== PRIVAT =====================================================*/
45 LOCAL void dcch0_resume_reconnect_req (T_PRIM * prim,
46 U8 ch_type);
47 /*==== VARIABLES ==================================================*/
48 /*==== FUNCTIONS ==================================================*/
49 /*
50 +--------------------------------------------------------------------+
51 | PROJECT : GSM-PS (6147) MODULE : DL_SDCCH |
52 | STATE : code ROUTINE : sdcch0_init_dl_data |
53 +--------------------------------------------------------------------+
54
55 PURPOSE : Initialisation of DCCH data (SAPI 0) for an instance.
56
57 */
58
59 GLOBAL void dcch0_init_dl_data (void)
60 {
61 GET_INSTANCE_DATA;
62 T_CCH *pcch = &dl_data->cch[C_DCCH0];
63
64 TRACE_FUNCTION ("dcch0_init_dl_data()");
65
66 memset (pcch, 0, sizeof (T_CCH));
67
68 dcch3_init_dl_data (); /*Disabling SAPI 3 connections */
69
70 com_clear_queue (PS_SAPI_0);
71 dl_data->rr_short_pd_buffer.l_buf = 0;
72
73 if (dl_data->dcch0_in_msg)
74 {
75 COM_FREE_POINTER (dl_data->dcch0_in_msg);
76 dl_data->dcch0_in_msg = NULL;
77 }
78
79 dl_data->RR_dedicated = FALSE;
80 dl_data->dcch0_ch_type = 0;
81 dl_data->dcch0_disc_request = FALSE;
82
83 #if defined(DELAYED_SABM)
84 dl_data->dcch0_sabm_delay = 0;
85 dl_data->dcch0_sabm_flag = NOT_PRESENT_8BIT;
86 #endif /* DELAYED_SABM */
87 #if defined(DELAYED_RELEASE_IND)
88 dl_data->release_ind_delay = 0;
89 dl_data->release_ind_ch_type = NOT_PRESENT_8BIT;
90 #endif /* DELAYED_RELEASE_IND */
91 set_channel_state(C_DCCH0, STATE_IDLE_DL);
92
93 sacch0_init_dl_data ();
94 }
95
96 #if defined(DELAYED_SABM)
97 GLOBAL void dcch0_delay_sabm (T_CCH *pcch)
98 {
99 GET_INSTANCE_DATA;
100 BOOL send_sabm = FALSE;
101
102 if (dl_data->dcch0_sabm_flag EQ NOT_PRESENT_8BIT)
103 {
104 if ((pcch->ch_type EQ L2_CHANNEL_FACCH_F) OR (pcch->ch_type EQ L2_CHANNEL_FACCH_H))
105 { /* start delay */
106 pcch->vtx = EMPTY_CMD; /* send dummy only */
107 dl_data->dcch0_sabm_flag = SABM_CMD;
108 dl_data->dcch0_sabm_delay = DL_FACCH_SABM_DELAY_VALUE;
109 DL_OFFLINE_TRACE (TRACE_DL_EVENT, C_DCCH0, pcch->ch_type, "delay SABM on FACCH");
110 }
111 else
112 { /* but for FACCH only */
113 send_sabm = TRUE;
114 }
115 }
116 else /* this part is called also called during uplink opportunity */
117 { /* pending delay */
118 if (dl_data->dcch0_sabm_delay > 0)
119 {
120 dl_data->dcch0_sabm_delay--;
121 DL_OFFLINE_TRACE (TRACE_DL_EVENT, C_DCCH0, pcch->ch_type, "pending delayed SABM");
122 }
123 else
124 {/* finishing delay, send SABM with the current (next) uplink opportunity */
125 #if !defined(DL_TRACE_ENABLED)
126 TRACE_EVENT ("delayed SABM");
127 #endif /* ! DL_TRACE_ENABLED*/
128 dl_data->dcch0_sabm_flag = NOT_PRESENT_8BIT;
129 send_sabm = TRUE;
130 DL_OFFLINE_TRACE (TRACE_DL_EVENT, C_DCCH0, pcch->ch_type, "send delayed SABM");
131 }
132 }
133
134 if (send_sabm)
135 {
136 pcch->vtx = SABM_CMD;
137 pcch->time_flag = TRUE;
138 pcch->rc = 0;
139 set_channel_state (C_DCCH0, STATE_CONTENTION_RESOLUTION);
140 }
141 }
142
143
144 #endif /* DELAYED_SABM */
145
146 /*
147 +--------------------------------------------------------------------+
148 | PROJECT : GSM-PS (6147) MODULE : DL_SDCCH |
149 | STATE : code ROUTINE : sdcch0_establish_req |
150 +--------------------------------------------------------------------+
151
152 PURPOSE : Establish Request for SDCCH SAPI 0.
153
154 */
155
156 GLOBAL void dcch0_establish_req (T_DL_ESTABLISH_REQ * est_req)
157 {
158 GET_INSTANCE_DATA;
159 T_CCH *pcch = &dl_data->cch[C_DCCH0];
160
161 TRACE_FUNCTION ("sdcch0_establish_req()");
162
163 DL_OFFLINE_TRACE (TRACE_DL_EVENT, C_DCCH0, est_req->ch_type, "est req");
164
165 dl_data->dcch0_ch_type = pcch->ch_type = est_req->ch_type;
166 TRACE_EVENT_WIN_P1 ("set dcch0_ch_type=%s", CH_TYPE_NAME[dl_data->dcch0_ch_type]);
167
168 dl_data->dcch0_unserved = com_queue_awaiting_transmission (PS_SAPI_0) ?
169 DL_UNSERVED : DL_ALL_DONE;
170 switch (dl_data->state[C_DCCH0])
171 {
172 case STATE_IDLE_DL:
173 /*
174 * initialize sacch buffer
175 */
176 dl_data->sacch_act_buffer = meas_report_no_nc;
177 dl_data->sacch_last_buffer= meas_report_no_nc;
178
179 com_clear_queue (PS_SAPI_0);
180 pcch->contention_resolution = TRUE;
181 dl_data->dcch0_queue.switch_buffer = (T_DL_DATA_REQ*)est_req;
182 dl_data->dcch0_disc_request = FALSE;
183 #if defined(DELAYED_SABM)
184 dcch0_delay_sabm(pcch);
185 #else /* DELAYED_SABM */
186 pcch->vtx = SABM_CMD;
187 pcch->time_flag = TRUE;
188 pcch->rc = 0;
189 set_channel_state (C_DCCH0, STATE_CONTENTION_RESOLUTION);
190 #endif /* DELAYED_SABM */
191 TRACE_EVENT_WIN_P5 ("EST_REQ: %s SAPI=%u vtx=%s (%s#%u)", CH_TYPE_NAME[pcch->ch_type],
192 est_req->sapi, VTX_NAME[pcch->vtx],
193 __FILE10__, __LINE__);
194 #if defined(DELAYED_SABM)
195 dcch0_delay_sabm(pcch);
196 #endif /* DELAYED_SABM */
197 break;
198
199 case STATE_MULTIPLE_FRAME_ESTABLISHED:
200 case STATE_TIMER_RECOVERY:
201 if (est_req->sdu.l_buf EQ 0)
202 {
203 dcch3_init_dl_data (); /*Disabling SAPI 3 connections */
204 com_clear_queue (PS_SAPI_0);
205 pcch->T200_counter = 0;
206 pcch->contention_resolution = FALSE;
207 pcch->vtx = SABM_CMD;
208 pcch->time_flag = TRUE;
209 pcch->rc = 0;
210 set_channel_state (C_DCCH0, STATE_CONTENTION_RESOLUTION);
211 TRACE_EVENT_WIN_P5 ("EST_REQ: %s SAPI=%u vtx=%s (%s#%u)", CH_TYPE_NAME[pcch->ch_type],
212 est_req->sapi, VTX_NAME[pcch->vtx],
213 __FILE10__, __LINE__);
214 }
215 else
216 {
217 dcch0_mdl_release_req ();
218 }
219 COM_FREE_POINTER (est_req);
220 break;
221
222 default:
223 COM_FREE_POINTER (est_req);
224 dcch0_mdl_release_req ();
225 break;
226 }
227 }
228
229 /*
230 +--------------------------------------------------------------------+
231 | PROJECT : GSM-PS (6147) MODULE : DL_SDCCH |
232 | STATE : code ROUTINE : sdcch0_resume_req |
233 +--------------------------------------------------------------------+
234
235 PURPOSE : Resume Request for SDCCH (SAPI 0).
236
237 */
238
239 GLOBAL void dcch0_resume_req (T_DL_RESUME_REQ * resume_req)
240 {
241
242 TRACE_FUNCTION ("dcch0_resume_req()");
243
244 DL_OFFLINE_TRACE (TRACE_DL_EVENT, C_DCCH0, resume_req->ch_type, "resume req");
245
246 dcch0_resume_reconnect_req( (T_PRIM *)D2P(resume_req), resume_req->ch_type);
247 }
248
249 /*
250 +--------------------------------------------------------------------+
251 | PROJECT : GSM-PS (6147) MODULE : DL_SDCCH |
252 | STATE : code ROUTINE : sdcch0_reconnect_req |
253 +--------------------------------------------------------------------+
254
255 PURPOSE : Reconnect Request for SDCCH (SAPI 0).
256
257 */
258
259 GLOBAL void dcch0_reconnect_req (T_DL_RECONNECT_REQ * reconnect_req)
260 {
261
262 TRACE_FUNCTION ("dcch0_reconnect_req()");
263
264 DL_OFFLINE_TRACE (TRACE_DL_EVENT, C_DCCH0, reconnect_req->ch_type, "reconn req");
265
266 dcch0_resume_reconnect_req( (T_PRIM *)D2P (reconnect_req),reconnect_req->ch_type);
267 }
268
269 /*
270 +--------------------------------------------------------------------+
271 | PROJECT : GSM-PS (6147) MODULE : DL_SDCCH |
272 | STATE : code ROUTINE : dcch0_res_recon_req |
273 +--------------------------------------------------------------------+
274
275 PURPOSE : This function processes Resume Request and Reconnect Request
276 for SDCCH (SAPI 0).
277
278 */
279 LOCAL void dcch0_resume_reconnect_req (T_PRIM * prim,
280 U8 ch_type)
281 {
282 GET_INSTANCE_DATA;
283 TRACE_FUNCTION ("dcch0_resume_reconnect_req()");
284
285 switch (dl_data->state[C_DCCH0])
286 {
287 case STATE_SUSPENDED:
288 case STATE_IDLE_DL:
289 {
290 T_CCH *pcch = &dl_data->cch[C_DCCH0];
291
292 dl_data->dcch0_ch_type = pcch->ch_type = ch_type;
293
294 TRACE_EVENT_WIN_P1 ("set dcch0_ch_type=%s", CH_TYPE_NAME[dl_data->dcch0_ch_type]);
295
296 com_restore_queue(PS_SAPI_0, (T_DL_DATA_REQ*)P2D(prim));
297
298 pcch->contention_resolution = FALSE;
299
300 #if defined(DELAYED_SABM)
301 dcch0_delay_sabm(dl_data, pcch);
302 #else /* DELAYED_SABM */
303 pcch->vtx = SABM_CMD;
304 pcch->time_flag = TRUE;
305 pcch->rc = 0;
306 set_channel_state (C_DCCH0, STATE_CONTENTION_RESOLUTION);
307 #endif /* DELAYED_SABM */
308
309 if(prim->custom.opc EQ DL_RECONNECT_REQ)
310 {
311 TRACE_EVENT_WIN_P5 ("RECONN_REQ: %s SAPI=%u vtx=%s (%s#%u)", CH_TYPE_NAME[pcch->ch_type],
312 PS_SAPI_0, VTX_NAME[pcch->vtx],
313 __FILE10__, __LINE__);
314 }
315 else
316 {
317 TRACE_EVENT_WIN_P5 ("RESUME_REQ: %s SAPI=%u vtx=%s (%s#%u)", CH_TYPE_NAME[pcch->ch_type],
318 PS_SAPI_0, VTX_NAME[pcch->vtx],
319 __FILE10__, __LINE__);
320
321 /* invalid measurement report first */
322 sacch0_reset_meas ();
323 }
324 break;
325 }
326 default:
327 {
328 COM_FREE_POINTER (P2D(prim));
329 }
330 break;
331 }/* endswitch */
332 }
333
334 /*
335 +--------------------------------------------------------------------+
336 | PROJECT : GSM-PS (6147) MODULE : DL_SDCCH |
337 | STATE : code ROUTINE : sdcch0_release_req |
338 +--------------------------------------------------------------------+
339
340 PURPOSE : Release Request for SDCCH (SAPI 0).
341
342 */
343
344 GLOBAL BOOL dcch0_release_req (T_DL_RELEASE_REQ * release_req)
345 {
346 GET_INSTANCE_DATA;
347 BOOL bFree = TRUE;
348
349 TRACE_FUNCTION ("dcch0_release_req()");
350
351 if (release_req->mode EQ DL_LOCAL_END_RELEASE)
352 {
353 DL_OFFLINE_TRACE (TRACE_DL_EVENT, C_DCCH0, release_req->ch_type, "local end release req");
354 dcch0_init_dl_data ();
355 bFree = FALSE;
356 }
357 else
358 {
359 DL_OFFLINE_TRACE (TRACE_DL_EVENT, C_DCCH0, release_req->ch_type, "normal release req");
360 dl_data->cch[C_DCCH0].ch_type = release_req->ch_type;
361 switch (dl_data->state[C_DCCH0])
362 {
363 default:
364 bFree = FALSE;
365 break;
366
367 case STATE_CONTENTION_RESOLUTION:
368 case STATE_MULTIPLE_FRAME_ESTABLISHED:
369 case STATE_TIMER_RECOVERY:
370 if (!dl_data->dcch0_disc_request AND (dl_data->cch[C_DCCH0].vtx EQ RR_CMD))
371 {
372 dl_data->dcch0_disc_request = TRUE;
373 dcch3_init_dl_data (); /*Disabling SAPI 3 connections */
374 }
375 else
376 {
377 dcch3_init_dl_data (); /*Disabling SAPI 3 connections */
378 com_prepare_DISC (C_DCCH0, release_req->sapi);
379 }
380 break;
381
382 case STATE_AWAITING_RELEASE:
383 dl_data->cch[C_DCCH0].T200_counter = 0;
384 break;
385 }
386 }
387
388 if (bFree EQ FALSE)
389 {
390 PREUSE (release_req, release_cnf, DL_RELEASE_CNF);
391 release_cnf->indication =
392 com_queue_awaiting_transmission (PS_SAPI_0) ? DL_UNSERVED : DL_ALL_DONE;
393 PSENDX (RR, release_cnf);
394 dcch0_init_dl_data ();
395 }
396
397 return bFree;
398 }
399
400 /*
401 +--------------------------------------------------------------------+
402 | PROJECT : GSM-PS (6147) MODULE : DL_SDCCH |
403 | STATE : code ROUTINE : sdcch0_mdl_release_req |
404 +--------------------------------------------------------------------+
405
406 PURPOSE : Release Request from Mobility Management for SDCCH (SAPI 0).
407
408 */
409
410 GLOBAL void dcch0_mdl_release_req (void)
411 {
412 GET_INSTANCE_DATA;
413 TRACE_FUNCTION ("dcch0_mdl_release_req()");
414
415 DL_OFFLINE_TRACE (TRACE_DL_EVENT, C_DCCH0, dl_data->cch[C_DCCH0].ch_type, "mdl rel req");
416
417 switch (dl_data->state[C_DCCH0])
418 {
419 case STATE_CONTENTION_RESOLUTION:
420 case STATE_AWAITING_RELEASE:
421 drr_dl_release_cnf (dl_data->cch[C_DCCH0].ch_type, PS_SAPI_0, TRUE);
422 break;
423 case STATE_MULTIPLE_FRAME_ESTABLISHED:
424 case STATE_TIMER_RECOVERY:
425 drr_dl_release_ind (dl_data->cch[C_DCCH0].ch_type, PS_SAPI_0, NOT_PRESENT_8BIT, TRUE);
426 break;
427 default:
428 break;
429 }
430 }
431
432 /*
433 +--------------------------------------------------------------------+
434 | PROJECT : GSM-PS (6147) MODULE : DL_SDCCH |
435 | STATE : code ROUTINE : sdcch0_suspend_req |
436 +--------------------------------------------------------------------+
437
438 PURPOSE : Suspend Request for SDCCH (SAPI 0).
439
440 */
441
442 GLOBAL void dcch0_suspend_req (T_DL_SUSPEND_REQ * suspend_req)
443 {
444 GET_INSTANCE_DATA;
445 T_CCH *pcch = &dl_data->cch[C_DCCH0];
446
447 TRACE_FUNCTION ("dcch0_suspend_req()");
448
449 DL_OFFLINE_TRACE (TRACE_DL_EVENT, C_DCCH0, suspend_req->ch_type, "suspend req");
450
451 pcch->ch_type = suspend_req->ch_type;
452
453 TRACE_EVENT_WIN_P1 ("reset dcch0_ch_type=%s ->0", CH_TYPE_NAME[dl_data->dcch0_ch_type]);
454 dl_data->dcch0_ch_type = 0;
455
456 switch (dl_data->state[C_DCCH0])
457 {
458 case STATE_CONTENTION_RESOLUTION:
459 case STATE_MULTIPLE_FRAME_ESTABLISHED:
460 case STATE_TIMER_RECOVERY:
461 case STATE_AWAITING_RELEASE:
462 pcch->T200_counter = 0;
463 pcch->time_flag = FALSE;
464 pcch->contention_resolution = FALSE;
465 set_channel_state (C_DCCH0, STATE_SUSPENDED);
466 dcch3_init_dl_data (); /* Disabling SAPI 3 connections */
467
468 #if 0 /* yes, from now DL sends measurement reports also in suspended state */
469 /*
470 * no further measurement reports
471 */
472 sacch0_reset_meas (dl_data);
473 #endif /* 0|1 */
474 break;
475
476 default:
477 TRACE_EVENT ("INVALID SUSPEND STATE");
478 break;
479 }
480 COM_FREE_POINTER (suspend_req);
481
482 TRACE_EVENT_WIN_P5 ("SUSPEND_REQ: %s SAPI=%u vtx=%s (%s#%u)", CH_TYPE_NAME[pcch->ch_type],
483 PS_SAPI_0, VTX_NAME[pcch->vtx],
484 __FILE10__, __LINE__);
485 }
486
487 /*
488 +--------------------------------------------------------------------+
489 | PROJECT : GSM-PS (6147) MODULE : DL_SDCCH |
490 | STATE : code ROUTINE : dcch0_check_disc |
491 +--------------------------------------------------------------------+
492
493 PURPOSE : DISC command frame on DCCH0.
494
495 */
496
497 GLOBAL int dcch0_check_disc (int send)
498 {
499 GET_INSTANCE_DATA;
500 TRACE_FUNCTION ("dcch0_check_disc()");
501
502 if (dl_data->dcch0_disc_request AND !(dl_data->cch[C_DCCH0].vtx EQ RR_CMD))
503 {
504 dcch3_init_dl_data (); /*Disabling SAPI 3 connections */
505 com_prepare_DISC (C_DCCH0, PS_SAPI_0);
506 dl_data->dcch0_disc_request = FALSE;
507 #if defined(DELAYED_SABM)
508 dl_data->dcch0_sabm_flag = NOT_PRESENT_8BIT; /* delete pending delayed SABM */
509 #endif /* DELAYED_SABM */
510 return uplink_awaiting_release (C_DCCH0, PS_SAPI_0);
511 }
512 else
513 return send;
514 }
515
516 /*
517 +--------------------------------------------------------------------+
518 | PROJECT : GSM-PS (6147) MODULE : DL_SDCCH |
519 | STATE : code ROUTINE : dcch0_data_req |
520 +--------------------------------------------------------------------+
521
522 PURPOSE : Data Request on SDCCH (SAPI 0).
523
524 */
525
526 GLOBAL void dcch0_data_req (T_DL_DATA_REQ * data_req)
527 {
528 GET_INSTANCE_DATA;
529 TRACE_FUNCTION ("sdcch0_data_req()");
530
531 dl_data->cch[C_DCCH0].ch_type = data_req->ch_type;
532
533 switch (dl_data->state[C_DCCH0])
534 {
535 case STATE_MULTIPLE_FRAME_ESTABLISHED:
536 case STATE_TIMER_RECOVERY:
537 case STATE_SUSPENDED:
538 case STATE_CONTENTION_RESOLUTION:
539 com_store_queue (PS_SAPI_0, data_req);
540 break;
541
542 default:
543 COM_FREE_POINTER (data_req);
544 break;
545 }
546 }
547
548 #endif /* !DL_DCCH0_C */
549
550