comparison src/g23m-gprs/sndcp/sndcp_sdas.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 : sndcp_sdas.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 is part of the entity SNDCP and implements all
18 | functions to handles the incoming process internal signals as
19 | described in the SDL-documentation (SD-statemachine)
20 +-----------------------------------------------------------------------------
21 */
22
23
24 #define ENTITY_SNDCP
25
26 /*==== INCLUDES =============================================================*/
27
28 #include "typedefs.h" /* to get Condat data types */
29 #include "vsi.h" /* to get a lot of macros */
30 #include "macdef.h"
31 #include "gsm.h" /* to get a lot of macros */
32 #include "prim.h" /* to get the definitions of used SAP and directions */
33
34 #include "dti.h"
35 #include "sndcp.h" /* to get the global entity definitions */
36 #include "sndcp_f.h" /* to get the functions to access the global arrays*/
37
38 #include "sndcp_sdaf.h" /* to get the internal functions of this service */
39 #include "sndcp_nds.h" /* to get signals to nd service */
40
41
42 /*==== CONST ================================================================*/
43
44 /*==== LOCAL VARS ===========================================================*/
45
46 /*==== PRIVATE FUNCTIONS ====================================================*/
47
48 /*==== PUBLIC FUNCTIONS =====================================================*/
49
50 /*
51 +------------------------------------------------------------------------------
52 | Function : sig_cia_sda_cia_decomp_ind
53 +------------------------------------------------------------------------------
54 | Description : Handles the internal signal SIG_CIA_SDA_CIA_DECOMP_IND
55 |
56 | Parameters : cia_decomp_ind, p_id
57 |
58 +------------------------------------------------------------------------------
59 */
60 GLOBAL void sig_cia_sda_cia_decomp_ind (T_CIA_DECOMP_IND* cia_decomp_ind, UBYTE p_id)
61 {
62 UBYTE sapi_index = 0;
63 UBYTE sapi = 0;
64 UBYTE nsapi= cia_decomp_ind->pdu_ref.ref_nsapi;
65 BOOL rec = FALSE;
66 T_SN_DATA_IND* sn_data_ind = NULL;
67
68 TRACE_ISIG( "sig_cia_sda_cia_decomp_ind" );
69
70 /*
71 * set service instance according to sapi in primitive
72 */
73 sndcp_get_nsapi_sapi(cia_decomp_ind->pdu_ref.ref_nsapi, &sapi);
74 sndcp_get_sapi_index(sapi, &sapi_index);
75 sndcp_data->sda = & sndcp_data->sda_base[sapi_index];
76
77
78 switch( sndcp_get_nsapi_rec_state(nsapi) )
79 {
80 case SDA_RECEIVE_FIRST_SEGMENT:
81 case SDA_RECEIVE_SUBSEQUENT_SEGMENT:
82 case SDA_ESTABLISH_REQUESTED:
83 {
84
85 MALLOC(sn_data_ind, sizeof(T_SN_DATA_IND));
86
87 #ifdef _SNDCP_DTI_2_
88 sn_data_ind->desc_list2.first = cia_decomp_ind->desc_list2.first;
89 sn_data_ind->desc_list2.list_len = cia_decomp_ind->desc_list2.list_len;
90 #endif /*_SNDCP_DTI_2_*/
91
92 #ifdef SNDCP_TRACE_ALL
93
94 sndcp_data->cia.cia_decomp_ind_number[nsapi] --;
95 TRACE_EVENT_P1("number of cia_decomp_ind: % d",
96 sndcp_data->cia.cia_decomp_ind_number[nsapi]);
97 #endif /* SNDCP_TRACE_ALL */
98
99 sn_data_ind->nsapi = nsapi;
100 sn_data_ind->p_id = p_id;
101 sda_is_nsapi_rec(nsapi, &rec);
102 if (rec) {
103 sda_set_nsapi_rec(nsapi, FALSE);
104 sig_sda_nd_data_ind(nsapi,
105 sn_data_ind,
106 (UBYTE)cia_decomp_ind->pdu_ref.ref_npdu_num);
107 sda_get_data_if_nec(sapi);
108 } else {
109 if (sndcp_data->sda->cur_sn_data_ind[nsapi] NEQ NULL)
110 {
111 #ifndef NTRACE
112 #ifdef SNDCP_TRACE_ALL
113 TRACE_EVENT_P1("Discard cur_sn.. in %s", sndcp_data->sda->state_name);
114 #endif /* SNDCP_TRACE_ALL */
115 #endif /* NTRACE */
116 sda_delete_cur_sn_data_ind(nsapi);
117 }
118 sndcp_data->sda->cur_sn_data_ind[nsapi] = sn_data_ind;
119 sndcp_data->sda->uncomp_npdu_num =
120 (UBYTE)cia_decomp_ind->pdu_ref.ref_npdu_num;
121 sndcp_set_nsapi_rec_state(nsapi, SDA_WAIT_NSAPI);
122 sda_get_data_if_nec ( sapi );
123 }
124 }
125 MFREE(cia_decomp_ind);
126 break;
127 default:
128 TRACE_ERROR( "SIG_CIA_SDA_CIA_DECOMP_IND unexpected" );
129 MFREE_PRIM(cia_decomp_ind);
130 break;
131 }
132 } /* sig_cia_sda_cia_decomp_ind() */
133
134
135
136 /*
137 +------------------------------------------------------------------------------
138 | Function : sig_mg_sda_delete_npdus
139 +------------------------------------------------------------------------------
140 | Description : Handles the internal signal SIG_MG_SD_DELETE_NPDUS
141 |
142 | Parameters : affected NSAPI, SAPI
143 | Pre : If the affected SAPI no longer uses acknowledged LLC operation
144 | mode, no LL_GETDATA_REQ shall be sent. So sndcp_sapi_state_ra
145 | must already be set to MG_REL_PENDING before this functon is
146 | called (if that sub state is desired).
147 |
148 +------------------------------------------------------------------------------
149 */
150 GLOBAL void sig_mg_sda_delete_npdus (UBYTE nsapi,
151 UBYTE sapi)
152 {
153 UBYTE sapi_index = 0;
154
155 TRACE_ISIG( "sig_mg_sda_delete_npdus" );
156
157 /*
158 * set service instance according to sapi in primitive
159 */
160 sndcp_get_sapi_index(sapi, &sapi_index);
161 sndcp_data->sda = & sndcp_data->sda_base[sapi_index];
162
163 switch( sndcp_get_nsapi_rec_state(nsapi) )
164 {
165 case SDA_ESTABLISH_REQUESTED:
166 case SDA_RECEIVE_FIRST_SEGMENT:
167 case SDA_RECEIVE_SUBSEQUENT_SEGMENT:
168 if (sndcp_data->sda->cur_sn_data_ind[nsapi] != NULL) {
169 sda_delete_cur_sn_data_ind(nsapi);
170 sndcp_set_nsapi_rec_state(nsapi, SDA_RECEIVE_FIRST_SEGMENT);
171 } else {
172 sndcp_set_nsapi_rec_state(nsapi, SDA_RECEIVE_FIRST_SEGMENT);
173 }
174 break;
175 case SDA_WAIT_NSAPI:
176 if (sndcp_data->sda->cur_sn_data_ind[nsapi] != NULL) {
177 USHORT sapi_state = MG_IDLE;
178
179 sda_delete_cur_sn_data_ind(nsapi);
180 /*
181 * Does it make sense to request another acknowlegded segment or is
182 * the whole SAPI now using only unacknowledged mode?
183 */
184 sndcp_get_sapi_state(sapi, &sapi_state);
185 if ((sapi_state & MG_REL) == 0) {
186 sda_get_data_if_nec(sapi);
187 }
188 sndcp_set_nsapi_rec_state(nsapi, SDA_RECEIVE_FIRST_SEGMENT);
189 }
190 break;
191 default:
192 TRACE_ERROR( "SIG_MG_SDA_DELETE_NPDUS unexpected" );
193 break;
194 }
195 } /* sig_mg_sda_delete_npdus() */
196
197
198 /*
199 +------------------------------------------------------------------------------
200 | Function : sig_mg_sda_end_est
201 +------------------------------------------------------------------------------
202 | Description : Handles the signal PD_SD_END_EST
203 |
204 | Parameters : affected sapi, success
205 |
206 +------------------------------------------------------------------------------
207 */
208 GLOBAL void sig_mg_sda_end_est (UBYTE sapi, BOOL success)
209 {
210 UBYTE sapi_index = 0;
211 UBYTE nsapi = 0;
212
213 TRACE_FUNCTION( "sig_pda_sda_est_cnf" );
214
215 /*
216 * set service instance according to sapi in primitive
217 */
218 sndcp_get_sapi_index(sapi, &sapi_index);
219 sndcp_data->sda = & sndcp_data->sda_base[sapi_index];
220
221 /*
222 * Send LL_GETDATA_REQ.
223 */
224 if (success){
225 sndcp_data->sda->llc_may_send = FALSE;
226 sda_get_data_if_nec(sapi);
227 }
228 /*
229 * All nsapis at this sapi that use ack mode, enter
230 * SDA_ESTABLISH_REQUESTED state.
231 */
232 for (nsapi = 0; nsapi < SNDCP_NUMBER_OF_NSAPIS; nsapi ++) {
233 UBYTE local_sapi = 0;
234 BOOL used = FALSE;
235
236 sndcp_is_nsapi_used(nsapi, &used);
237 if (!used) {
238 continue;
239 }
240 sndcp_get_nsapi_sapi(nsapi, &local_sapi);
241 if (local_sapi == sapi) {
242 switch( sndcp_get_nsapi_rec_state(nsapi) )
243 {
244 case SDA_ESTABLISH_REQUESTED:
245 case SDA_RECEIVE_FIRST_SEGMENT:
246 case SDA_RECEIVE_SUBSEQUENT_SEGMENT:
247 case SDA_WAIT_NSAPI:
248 case SDA_ACK_DISCARD:
249 sndcp_set_nsapi_rec_state(nsapi, SDA_RECEIVE_FIRST_SEGMENT);
250 break;
251 default:
252 TRACE_EVENT( "SIG_MG_SDA_END_EST unexpected for this NSAPI" );
253 break;
254 }
255 }
256 } /* for all nsapis */
257
258
259 } /* sig_mg_sda_end_est() */
260
261
262 /*
263 +------------------------------------------------------------------------------
264 | Function : sig_mg_sda_getdata
265 +------------------------------------------------------------------------------
266 | Description : Handles the internal signal SIG_MG_SD_GETDATA
267 |
268 | Parameters : sapi
269 |
270 +------------------------------------------------------------------------------
271 */
272 GLOBAL void sig_mg_sda_getdata (UBYTE sapi, UBYTE nsapi)
273 {
274 UBYTE sapi_index = 0;
275
276 TRACE_ISIG( "sig_mg_sda_getdata" );
277
278 /*
279 * set service instance according to sapi in primitive
280 */
281 sndcp_get_sapi_index(sapi, &sapi_index);
282 sndcp_data->sda = & sndcp_data->sda_base[sapi_index];
283
284 switch( GET_STATE(SDA) )
285 {
286 case SDA_DEFAULT:
287 sda_get_data_if_nec(sapi);
288 sndcp_set_nsapi_rec_state(nsapi, SDA_RECEIVE_FIRST_SEGMENT);
289 break;
290 default:
291 TRACE_ERROR( "SIG_MG_SDA_GETDATA unexpected" );
292 break;
293 }
294 } /* sig_mg_sda_getdata() */
295
296
297 /*
298 +------------------------------------------------------------------------------
299 | Function : sig_cia_sda_getdata
300 +------------------------------------------------------------------------------
301 | Description : Handles the internal signal SIG_CIA_SDA_GETDATA
302 |
303 | Parameters : sapi
304 |
305 +------------------------------------------------------------------------------
306 */
307 GLOBAL void sig_cia_sda_getdata (UBYTE sapi, UBYTE nsapi)
308 {
309
310 TRACE_ISIG( "sig_cia_sda_getdata" );
311
312 switch( sndcp_get_nsapi_rec_state(nsapi) )
313 {
314 case SDA_RECEIVE_FIRST_SEGMENT:
315 case SDA_RECEIVE_SUBSEQUENT_SEGMENT:
316 case SDA_WAIT_NSAPI:
317 sda_get_data_if_nec(sapi);
318 break;
319 default:
320 TRACE_ERROR( "SIG_CIA_SDA_GETDATA unexpected" );
321 break;
322 }
323 } /* sig_cia_sda_getdata() */
324
325
326 /*
327 +------------------------------------------------------------------------------
328 | Function : sig_nd_sda_getdata_req
329 +------------------------------------------------------------------------------
330 | Description : Handles the internal signal SIG_ND_SDA_GETDATA_REQ
331 |
332 | Parameters : affected sapi, affected nsapi
333 |
334 +------------------------------------------------------------------------------
335 */
336 GLOBAL void sig_nd_sda_getdata_req (UBYTE sapi,
337 UBYTE nsapi)
338 {
339 UBYTE sapi_index = 0;
340
341 TRACE_ISIG( "sig_nd_sda_getdata_req" );
342
343 /*
344 * set service instance according to sapi in primitive
345 */
346 sndcp_get_sapi_index(sapi, &sapi_index);
347 sndcp_data->sda = & sndcp_data->sda_base[sapi_index];
348
349 switch( sndcp_get_nsapi_rec_state(nsapi) )
350 {
351 case SDA_RECEIVE_FIRST_SEGMENT:
352 case SDA_RECEIVE_SUBSEQUENT_SEGMENT:
353 sda_set_nsapi_rec(nsapi, TRUE);
354 break;
355 case SDA_WAIT_NSAPI:
356 if (sndcp_data->sda->cur_sn_data_ind[nsapi] != NULL) {
357 /*
358 * Send the just reassembled N-PDU (must be present because of state!).
359 */
360 sndcp_set_nsapi_rec_state(nsapi, SDA_RECEIVE_FIRST_SEGMENT);
361 sig_sda_nd_data_ind(nsapi,
362 sndcp_data->sda->cur_sn_data_ind[nsapi],
363 sndcp_data->sda->uncomp_npdu_num);
364 sndcp_data->sda->cur_sn_data_ind[nsapi] = NULL;
365 sda_get_data_if_nec(sapi);
366 } else {
367 /*
368 * Set the receptive for the given nsapi.
369 */
370 sda_set_nsapi_rec(nsapi, TRUE);
371 }
372 break;
373 default:
374 TRACE_ERROR( "SIG_ND_SDA_GETDATA_REQ unexpected" );
375 break;
376 }
377 } /* sig_nd_sda_getdata_req() */
378
379 /*
380 +------------------------------------------------------------------------------
381 | Function : sig_mg_sda_start_est
382 +------------------------------------------------------------------------------
383 | Description : Handles the signal PD_SD_START_EST
384 |
385 | Parameters : affected sapi
386 |
387 +------------------------------------------------------------------------------
388 */
389 GLOBAL void sig_mg_sda_start_est (UBYTE sapi)
390 {
391 UBYTE nsapi = 0;
392
393 TRACE_FUNCTION( "sig_pda_sda_start_est" );
394
395 /*
396 * All nsapis at this sapi that use ack mode, enter
397 * SDA_ESTABLISH_REQUESTED state.
398 */
399 for (nsapi = 0; nsapi < SNDCP_NUMBER_OF_NSAPIS; nsapi ++) {
400 UBYTE sapi_help = 0;
401 BOOL used = FALSE;
402
403 sndcp_is_nsapi_used(nsapi, &used);
404 if (!used) {
405 continue;
406 }
407 sndcp_get_nsapi_sapi(nsapi, &sapi_help);
408 if (sapi_help == sapi) {
409 switch( sndcp_get_nsapi_rec_state(nsapi) )
410 {
411 case SDA_ESTABLISH_REQUESTED:
412 case SDA_RECEIVE_FIRST_SEGMENT:
413 case SDA_RECEIVE_SUBSEQUENT_SEGMENT:
414 case SDA_WAIT_NSAPI:
415 sndcp_set_nsapi_rec_state(nsapi, SDA_ESTABLISH_REQUESTED);
416 break;
417 default:
418 TRACE_EVENT( "SIG_MG_SDA_START_EST unexpected for this NSAPI" );
419 break;
420 }
421 }
422 } /* for all nsapis */
423
424 } /* sig_mg_sda_start_est() */
425
426
427 /*
428 +------------------------------------------------------------------------------
429 | Function : sig_pd_sda_data_ind
430 +------------------------------------------------------------------------------
431 | Description : Handles the signal PD_SD_DATA_IND
432 |
433 | Parameters : *ll_data_ind - Ptr to primitive payload
434 |
435 +------------------------------------------------------------------------------
436 */
437 GLOBAL void sig_pda_sda_data_ind ( T_LL_DATA_IND *ll_data_ind )
438 {
439 UBYTE sapi_index = 0;
440 BOOL valid = FALSE;
441 UBYTE nsapi = 0;
442 UBYTE sapi = 0;
443
444 TRACE_FUNCTION( "sig_pda_sda_data_ind" );
445
446 /*
447 * set service instance according to sapi in primitive
448 */
449 sndcp_get_sapi_index(ll_data_ind->sapi, &sapi_index);
450 sndcp_data->sda = & sndcp_data->sda_base[sapi_index];
451 sda_get_nsapi(ll_data_ind, &nsapi);
452
453 /*
454 * LLC has now "used up" it's pending LL_GETDATA_REQ and will have
455 * to wait for the next one.
456 */
457 sndcp_data->sda->llc_may_send = FALSE;
458 sapi = ll_data_ind->sapi;
459
460 switch( sndcp_get_nsapi_rec_state(nsapi) )
461 {
462 case SDA_ESTABLISH_REQUESTED:
463 /*
464 * Just discard the segment. Next segment will be requested after
465 * confirmation of establishment.
466 */
467 PFREE(ll_data_ind);
468 ll_data_ind = NULL;
469 break;
470
471 case SDA_RECEIVE_FIRST_SEGMENT:
472 /*
473 * Invalid segments are discarded without error notification
474 */
475 sda_is_seg_valid(ll_data_ind, &valid);
476 if (!valid) {
477 PFREE(ll_data_ind);
478 sda_get_data_if_nec(sapi);
479 return;
480 }
481 if (sda_f_bit(ll_data_ind)) {
482 if (sda_m_bit(ll_data_ind)) {
483 sda_ac_f_f1_m1(ll_data_ind);
484 } else {
485 sda_ac_f_f1_m0(ll_data_ind);
486 }
487 } else {
488 sda_ac_f_f0(ll_data_ind);
489 }
490
491 break;
492
493 case SDA_RECEIVE_SUBSEQUENT_SEGMENT:
494 /*
495 * Invalid segments are discarded without error notification
496 */
497 sda_is_seg_valid(ll_data_ind, &valid);
498 if (!valid) {
499 PFREE(ll_data_ind);
500 sda_get_data_if_nec(sapi);
501 return;
502 }
503 if (sda_f_bit(ll_data_ind)) {
504 if (sda_m_bit(ll_data_ind)) {
505 sda_ac_s_f1_m1(ll_data_ind);
506 } else {
507 sda_ac_s_f1_m0(ll_data_ind);
508 }
509 } else {
510 if (sda_m_bit(ll_data_ind)) {
511 sda_ac_s_f0_m1(ll_data_ind);
512 } else {
513 sda_ac_s_f0_m0(ll_data_ind);
514 }
515 }
516
517 break;
518
519 case SDA_WAIT_NSAPI:
520 if (ll_data_ind != NULL)
521 {
522 PFREE(ll_data_ind);
523 }
524 sda_get_data_if_nec(sapi);
525 break;
526
527 case SDA_ACK_DISCARD:
528 /*
529 * In this state we will discard every downlink segment till we receive.
530 * the last segment.
531 * Once we receive the last segment, we will move to the state
532 * SDA_RECEIVE_FIRST_SEGMENT.
533 */
534 TRACE_EVENT( "SDA_ACK_DISCARD state,Discard Segments ..." );
535 sndcp_data->cur_segment_number[nsapi] ++;
536 if (!sda_m_bit(ll_data_ind))
537 {
538 TRACE_EVENT( "Received the last Segment in SDA_ACK_DISCARD state " );
539 sndcp_data->cur_segment_number[nsapi] = 0;
540 sndcp_set_nsapi_rec_state(nsapi, SDA_RECEIVE_FIRST_SEGMENT);
541 }
542 PFREE(ll_data_ind);
543 sda_get_data_if_nec(sapi);
544 break;
545
546 default:
547 TRACE_ERROR( "SIG_PDA_SDA_DATA_IND unexpected" );
548 /*
549 * The primitive LL_DATA_IND is unexpected or the
550 * NSAPI value is wrong. Discard the prim and send a FC prim.
551 */
552 if (ll_data_ind != NULL)
553 {
554 PFREE(ll_data_ind);
555 }
556 sda_get_data_if_nec(sapi);
557 break;
558 }
559
560 } /* sig_pda_sda_data_ind() */
561
562
563 /*
564 +------------------------------------------------------------------------------
565 | Function : sig_mg_sda_reset_ind
566 +------------------------------------------------------------------------------
567 | Description : Handles the internal signal SIG_MG_SDA_RESET_IND
568 |
569 | Parameters : affected sapi
570 |
571 +------------------------------------------------------------------------------
572 */
573 GLOBAL void sig_mg_sda_reset_ind (UBYTE nsapi)
574 {
575
576 TRACE_ISIG( "sig_mg_sda_reset_ind" );
577
578 switch( sndcp_get_nsapi_rec_state(nsapi) )
579 {
580 case SDA_ESTABLISH_REQUESTED:
581 case SDA_RECEIVE_FIRST_SEGMENT:
582 case SDA_RECEIVE_SUBSEQUENT_SEGMENT:
583 case SDA_WAIT_NSAPI:
584 case SDA_ACK_DISCARD:
585 /*
586 * Similar to sd.
587 */
588 sndcp_data->cur_dcomp[nsapi] = 0;
589 sndcp_data->cur_pcomp[nsapi] = 0;
590 break;
591 default:
592 TRACE_ERROR( "SIG_MG_SDA_RESET_IND unexpected" );
593 break;
594 }
595 } /* sig_mg_sda_reset_ind() */
596