comparison src/g23m-gprs/sndcp/sndcp_sdaf.c @ 1:d393cd9bb723

src/g23m-*: initial import from Magnetite
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 15 Jul 2018 04:40:46 +0000
parents
children
comparison
equal deleted inserted replaced
0:b6a5e36de839 1:d393cd9bb723
1 /*
2 +-----------------------------------------------------------------------------
3 | Project : GPRS (8441)
4 | Modul : sndcp_sdaf.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 | procedures and functions as described in the
19 | SDL-documentation (SDA-statemachine)
20 +-----------------------------------------------------------------------------
21 */
22
23
24
25 #define ENTITY_SNDCP
26
27 /*==== INCLUDES =============================================================*/
28
29 #include "typedefs.h" /* to get Condat data types */
30 #include "vsi.h" /* to get a lot of macros */
31 #include "macdef.h"
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 functions from sda */
39 #include "sndcp_pdas.h" /* to get the signals to service pda.*/
40 #include "sndcp_mgs.h" /* to get the signals to service mg.*/
41 #include "sndcp_cias.h" /* to get the signals to service cia.*/
42
43
44
45 /*==== CONST ================================================================*/
46
47 /*==== LOCAL VARS ===========================================================*/
48
49 /*==== PRIVATE FUNCTIONS ====================================================*/
50
51 LOCAL UBYTE sda_get_dcomp (T_LL_DATA_IND* ll_data_ind);
52
53
54 /*
55 +------------------------------------------------------------------------------
56 | Function : sda_get_dcomp
57 +------------------------------------------------------------------------------
58 | Description : E X T R A convenience function, not in SDL.
59 | Returns the DCOMP value in the sdu of the given primitive.
60 |
61 | Parameters : ll_data_ind T_LL_DATA_IND*
62 |
63 +------------------------------------------------------------------------------
64 */
65 LOCAL UBYTE sda_get_dcomp (T_LL_DATA_IND* ll_data_ind)
66 {
67 return (ll_data_ind->sdu.buf[ll_data_ind->sdu.o_buf / 8 + 1] & 0xf0) >> 4 ;
68
69 } /* sda_get_dcomp() */
70
71 /*
72 +------------------------------------------------------------------------------
73 | Function : sda_get_nsapi
74 +------------------------------------------------------------------------------
75 | Description : E X T R A convenience function, not in SDL.
76 | Gets the NSAPI from the segment header.
77 |
78 | Parameters : ll_data_ind T_LL_DATA_IND*, nsapi*
79 |
80 +------------------------------------------------------------------------------
81 */
82 GLOBAL void sda_get_nsapi (T_LL_DATA_IND* ll_data_ind, UBYTE* nsapi)
83 {
84 /*
85 * The nsapi number in the sn-pdu header is the least sig half first octet.
86 */
87 UBYTE first = ll_data_ind->sdu.buf[(ll_data_ind->sdu.o_buf / 8)];
88
89 *nsapi = first & 0xf;
90 } /* sda_get_nsapi() */
91
92 /*==== PUBLIC FUNCTIONS =====================================================*/
93
94 /*
95 +------------------------------------------------------------------------------
96 | Function : sda_get_data_if_nec
97 +------------------------------------------------------------------------------
98 | Description : This function sends a SIG_SD_PD_GETDATA_REQ to the affected
99 | SAPI
100 | if necessary (service variable llc_may_send was set to FALSE)
101 | and sets llc_may_send to TRUE or does nothing (service
102 | variable llc_may_send already was set to TRUE).
103 |
104 | Parameters : FPAR IN sapi UBYTE the number of the affected SAPI
105 |
106 +------------------------------------------------------------------------------
107 */
108 GLOBAL void sda_get_data_if_nec (UBYTE sapi)
109 {
110 UBYTE sapi_index = 0;
111 USHORT state = 0;
112
113 TRACE_FUNCTION( "sda_get_data_if_nec" );
114
115 #ifdef SNDCP_TRACE_ALL
116 if (sndcp_data->sda->llc_may_send) {
117 TRACE_EVENT("llc_may_send TRUE");
118 } else {
119 TRACE_EVENT("llc_may_send FALSE");
120 }
121 #endif
122
123 /*
124 * set service instance according to sapi in signal
125 */
126 sndcp_get_sapi_index(sapi, &sapi_index);
127 sndcp_data->sda = & sndcp_data->sda_base[sapi_index];
128 sndcp_get_sapi_state(sapi, &state);
129 if (! sndcp_data->sda->llc_may_send) {
130 sig_sda_pda_getdata_req(sapi);
131 /*
132 * Mark this LLC SAPI as pending.
133 */
134 sndcp_data->sda->llc_may_send = TRUE;
135 }
136
137 } /* sd_get_data_if_nec() */
138
139
140
141 /*
142 +------------------------------------------------------------------------------
143 | Function : sda_is_seg_valid
144 +------------------------------------------------------------------------------
145 | Description : According to GSM 4.65, 6.9 unacknowledged segments for NSAPIs
146 | in acknowledged mode and vice versa and also segments for not
147 | activated NSAPIs shall be discarded without further error
148 | notification.
149 |
150 | Parameters : nsapi, sapi, BOOL ack, BOOL* valid
151 |
152 +------------------------------------------------------------------------------
153 */
154 GLOBAL void sda_is_seg_valid(T_LL_DATA_IND* ll_data_ind,
155 BOOL* valid)
156 {
157 UBYTE nsapi = 0;
158 UBYTE sapi = 0;
159 /*
160 * Is the affected NSAPI using acknowledged LLC mode?
161 */
162 BOOL ack = TRUE;
163 /*
164 * Is the NSAPI used at all?
165 */
166 BOOL used = FALSE;
167
168 TRACE_FUNCTION( "sda_is_seg_valid" );
169
170 *valid = TRUE;
171 /*
172 * Get the affected nsapi from primitive.
173 */
174 sda_get_nsapi(ll_data_ind, &nsapi);
175 /*
176 * If the NSAPI is not used, leave.
177 */
178 sndcp_is_nsapi_used(nsapi, &used);
179 if (!used) {
180 *valid = FALSE;
181 return;
182 }
183 /*
184 * To which sapi is the given nsapi mapped?
185 */
186 sndcp_get_nsapi_sapi(nsapi, &sapi);
187 /*
188 * If the sapi in the primitive is the wrong one, leave.
189 */
190 if (sapi != ll_data_ind->sapi) {
191 *valid = FALSE;
192 return;
193 }
194 /*
195 * If the nsapi normally uses unacknowledged LLC mode, leave.
196 * Note: if 'ack' is false the NSAPI is in unacknowledged
197 * mode normally and the 'sda' service is the wrong one
198 * anyway, but it was chosen because of the ack primitive.
199 */
200 sndcp_get_nsapi_ack(nsapi, &ack);
201 if (!ack) {
202 *valid = FALSE;
203 return;
204 }
205
206 } /* sd_is_seg_valid() */
207
208
209
210 /*
211 +------------------------------------------------------------------------------
212 | Function : sda_delete_cur_sn_data_ind
213 +------------------------------------------------------------------------------
214 | Description : The descriptor list in service variable cur_sn_data_ind is
215 | deleted recursively, then the primitive is freed with PFREE
216 | macro.
217 |
218 | Parameters :
219 |
220 +------------------------------------------------------------------------------
221 */
222 GLOBAL void sda_delete_cur_sn_data_ind (U8 nsapi)
223 {
224 TRACE_FUNCTION( "sda_delete_cur_sn_data_ind" );
225
226 if (sndcp_data->sda->cur_sn_data_ind[nsapi] != NULL) {
227 #ifdef _SNDCP_DTI_2_
228 MFREE_PRIM(sndcp_data->sda->cur_sn_data_ind[nsapi]);
229 #else /*_SNDCP_DTI_2_*/
230 PFREE_DESC(sndcp_data->sda->cur_sn_data_ind[nsapi]);
231 #endif /*_SNDCP_DTI_2_*/
232
233 sndcp_data->sda->cur_sn_data_ind[nsapi] = NULL;
234 }
235 } /* sda_delete_cur_sn_data_ind() */
236
237
238 /*
239 +------------------------------------------------------------------------------
240 | Function : sda_f_bit
241 +------------------------------------------------------------------------------
242 | Description : E X T R A convenience function, not in SDL.
243 | Returns TRUE if the f bit in the given sdu is set to 1, else
244 | FALSE.
245 |
246 | Parameters : ll_data_ind T_LL_DATA_IND*
247 |
248 +------------------------------------------------------------------------------
249 */
250 GLOBAL BOOL sda_f_bit (T_LL_DATA_IND* ll_data_ind)
251 {
252 UBYTE f_b = ll_data_ind->sdu.buf[ll_data_ind->sdu.o_buf / 8] & 0x40;
253
254 TRACE_FUNCTION( "sda_f_bit" );
255
256 return (f_b > 0);
257
258 } /* sda_f_bit() */
259
260
261
262 /*
263 +------------------------------------------------------------------------------
264 | Function : sda_get_pcomp
265 +------------------------------------------------------------------------------
266 | Description : E X T R A convenience function, not in SDL.
267 | Returns the PCOMP value in the sdu of the given primitive.
268 |
269 | Parameters : ll_data_ind T_LL_DATA_IND*
270 |
271 +------------------------------------------------------------------------------
272 */
273 GLOBAL UBYTE sda_get_pcomp (T_LL_DATA_IND* ll_data_ind)
274 {
275 return ll_data_ind->sdu.buf[ll_data_ind->sdu.o_buf / 8 + 1] & 0xf;
276
277 } /* sda_get_pcomp() */
278
279
280 /*
281 +------------------------------------------------------------------------------
282 | Function : sda_init
283 +------------------------------------------------------------------------------
284 | Description : Initialize the entity instance.
285 |
286 | Parameters :
287 |
288 +------------------------------------------------------------------------------
289 */
290 GLOBAL void sda_init (void)
291 {
292 TRACE_FUNCTION( "sda_init" );
293
294 sndcp_data->sda = & sndcp_data->sda_base[0];
295 INIT_STATE(SDA_0, SDA_DEFAULT);
296 #ifdef SNDCP_2to1
297 sndcp_data->sda->sapi = PS_SAPI_3;
298 #else
299 sndcp_data->sda->sapi = LL_SAPI_3;
300 #endif /*SNDCP_2to1*/
301 sndcp_data->sda = & sndcp_data->sda_base[1];
302 INIT_STATE(SDA_1, SDA_DEFAULT);
303 #ifdef SNDCP_2to1
304 sndcp_data->sda->sapi = PS_SAPI_5;
305 #else
306 sndcp_data->sda->sapi = LL_SAPI_5;
307 #endif /*SNDCP_2to1*/
308
309
310 sndcp_data->sda = & sndcp_data->sda_base[2];
311 INIT_STATE(SDA_2, SDA_DEFAULT);
312 #ifdef SNDCP_2to1
313 sndcp_data->sda->sapi = PS_SAPI_9;
314 #else
315 sndcp_data->sda->sapi = LL_SAPI_9;
316 #endif /*SNDCP_2to1*/
317
318
319 sndcp_data->sda = & sndcp_data->sda_base[3];
320 INIT_STATE(SDA_3, SDA_DEFAULT);
321 #ifdef SNDCP_2to1
322 sndcp_data->sda->sapi = PS_SAPI_11;
323 #else
324 sndcp_data->sda->sapi = LL_SAPI_11;
325 #endif /*SNDCP_2to1*/
326
327 {
328 UBYTE sapi_index = 0;
329
330 for (sapi_index = 0; sapi_index < SNDCP_NUMBER_OF_SAPIS; sapi_index++) {
331 UBYTE nsapi = 0;
332
333 sndcp_data->sda = & sndcp_data->sda_base[sapi_index];
334 for (nsapi = 0; nsapi < SNDCP_NUMBER_OF_NSAPIS; nsapi++) {
335 sda_set_nsapi_rec(nsapi, FALSE);
336 sndcp_data->sda->cur_sn_data_ind[nsapi] = NULL;
337 }
338 sndcp_data->sda->llc_may_send = FALSE;
339 sndcp_data->sda->uncomp_npdu_num = 0;
340 }
341 }
342
343
344 } /* sda_init() */
345
346 /*
347 +------------------------------------------------------------------------------
348 | Function : sda_is_nsapi_rec
349 +------------------------------------------------------------------------------
350 | Description : Returns TRUE if the given nsapi is receptive, else
351 | FALSE.
352 |
353 | Parameters : nsapi, BOOL* b
354 |
355 +------------------------------------------------------------------------------
356 */
357 GLOBAL void sda_is_nsapi_rec (UBYTE nsapi, BOOL* b)
358 {
359 *b = sndcp_data->sda->nsapi_rec_ra[nsapi];
360 #ifdef SNDCP_TRACE_ALL
361 TRACE_EVENT("is nsapi receptive?");
362 if (*b) {
363 TRACE_EVENT("TRUE");
364 } else {
365 TRACE_EVENT("FALSE");
366 }
367 #endif
368 } /* sda_is_nsapi_rec() */
369
370
371 /*
372 +------------------------------------------------------------------------------
373 | Function : sda_m_bit
374 +------------------------------------------------------------------------------
375 | Description : E X T R A convenience function, not in SDL.
376 | Returns TRUE if the m bit in the given sdu is set to 1, else
377 | FALSE.
378 |
379 | Parameters : ll_data_ind T_LL_DATA_IND*
380 |
381 +------------------------------------------------------------------------------
382 */
383 GLOBAL BOOL sda_m_bit (T_LL_DATA_IND* ll_data_ind)
384 {
385 UBYTE m_b = 0;
386
387 TRACE_FUNCTION( "sda_m_bit" );
388
389 m_b = ll_data_ind->sdu.buf[ll_data_ind->sdu.o_buf / 8] & 0x10;
390 return (m_b > 0);
391
392 } /* sda_m_bit() */
393
394
395
396 /*
397 +------------------------------------------------------------------------------
398 | Function : sda_set_nsapi_rec
399 +------------------------------------------------------------------------------
400 | Description : Sets the given nsapi_rec_ra element to the given BOOL.
401 |
402 | Parameters : nsapi, BOOL b
403 |
404 +------------------------------------------------------------------------------
405 */
406 GLOBAL void sda_set_nsapi_rec (UBYTE nsapi, BOOL b)
407 {
408 sndcp_data->sda->nsapi_rec_ra[nsapi] = b;
409 #ifdef SNDCP_TRACE_ALL
410 TRACE_EVENT("set nsapi receptive to");
411 if (b) {
412 TRACE_EVENT("TRUE");
413 } else {
414 TRACE_EVENT("FALSE");
415 }
416 #endif
417 } /* sda_set_nsapi_rec */
418
419
420 /*
421 +------------------------------------------------------------------------------
422 | Function : sda_ac_f_f0
423 +------------------------------------------------------------------------------
424 | Description : E X T R A convenience function, not in SDL.
425 | Represents the label AC_F_F0 in SDL.
426 |
427 | Parameters : ll_data_ind T_LL_DATA_IND*
428 |
429 +------------------------------------------------------------------------------
430 */
431 GLOBAL void sda_ac_f_f0 (T_LL_DATA_IND* ll_data_ind)
432 {
433 /*
434 * Get the NSAPI number from ll_data_ind.
435 */
436 UBYTE nsapi = 0;
437
438 sda_get_nsapi(ll_data_ind, &nsapi);
439 sig_sda_mg_re_est(ll_data_ind->sapi, nsapi);
440 PFREE(ll_data_ind);
441 } /* sda_ac_f_f0() */
442
443
444 /*
445 +------------------------------------------------------------------------------
446 | Function : sda_ac_f_f1_m0
447 +------------------------------------------------------------------------------
448 | Description : E X T R A convenience function, not in SDL.
449 | Represents the label AC_F_F1_M0 in SDL.
450 |
451 | Parameters : ll_data_ind T_LL_DATA_IND*
452 |
453 +------------------------------------------------------------------------------
454 */
455 GLOBAL void sda_ac_f_f1_m0 (T_LL_DATA_IND* ll_data_ind)
456 {
457 sndcp_set_ack_transfer_params(ll_data_ind);
458 sig_sda_cia_cia_decomp_req(ll_data_ind);
459 } /* sda_ac_f_f1_m0() */
460
461 /*
462 +------------------------------------------------------------------------------
463 | Function : sda_ac_f_f1_m1
464 +------------------------------------------------------------------------------
465 | Description : E X T R A convenience function, not in SDL.
466 | Represents the label AC_F_F1_M1 in SDL.
467 |
468 | Parameters : ll_data_ind T_LL_DATA_IND*
469 |
470 +------------------------------------------------------------------------------
471 */
472 GLOBAL void sda_ac_f_f1_m1 (T_LL_DATA_IND* ll_data_ind)
473 {
474 UBYTE nsapi = 0;
475
476 sda_get_nsapi(ll_data_ind, &nsapi);
477 sndcp_set_ack_transfer_params(ll_data_ind);
478 sig_sda_cia_cia_decomp_req(ll_data_ind);
479
480 sndcp_set_nsapi_rec_state(nsapi, SDA_RECEIVE_SUBSEQUENT_SEGMENT);
481
482 } /* sda_ac_f_f1_m0() */
483
484
485 /*
486 +------------------------------------------------------------------------------
487 | Function : sda_ac_s_f0_m0
488 +------------------------------------------------------------------------------
489 | Description : E X T R A convenience function, not in SDL.
490 | Represents the label UN_S_F0_M0 in SDL.
491 |
492 | Parameters : ll_data_ind T_LL_DATA_IND*
493 |
494 +------------------------------------------------------------------------------
495 */
496 GLOBAL void sda_ac_s_f0_m0 (T_LL_DATA_IND* ll_data_ind)
497 {
498 UBYTE nsapi = 0;
499
500 sda_get_nsapi(ll_data_ind, &nsapi);
501 sndcp_data->cur_seg_pos[nsapi] = SEG_POS_LAST;
502 sndcp_set_nsapi_rec_state(nsapi, SDA_RECEIVE_FIRST_SEGMENT);
503
504 sig_sda_cia_cia_decomp_req(ll_data_ind);
505 } /* sda_ac_s_f0_m0() */
506
507
508 /*
509 +------------------------------------------------------------------------------
510 | Function : sda_ac_s_f0_m1
511 +------------------------------------------------------------------------------
512 | Description : E X T R A convenience function, not in SDL.
513 | Represents the label AC_S_F0_M1 in SDL.
514 |
515 | Parameters : ll_data_ind T_LL_DATA_IND*
516 |
517 +------------------------------------------------------------------------------
518 */
519 GLOBAL void sda_ac_s_f0_m1 (T_LL_DATA_IND* ll_data_ind)
520 {
521 UBYTE nsapi = 0;
522
523 sda_get_nsapi(ll_data_ind, &nsapi);
524 sndcp_data->cur_seg_pos[nsapi] = SEG_POS_NONE;
525 sig_sda_cia_cia_decomp_req(ll_data_ind);
526
527 } /* sda_ac_s_f0_m1() */
528
529 /*
530 +------------------------------------------------------------------------------
531 | Function : sda_ac_s_f1_m1
532 +------------------------------------------------------------------------------
533 | Description : E X T R A convenience function, not in SDL.
534 | Represents the label AC_S_F1_M1 in SDL.
535 |
536 | Parameters : ll_data_ind T_LL_DATA_IND*
537 |
538 +------------------------------------------------------------------------------
539 */
540 GLOBAL void sda_ac_s_f1_m1 (T_LL_DATA_IND* ll_data_ind)
541 {
542 /*
543 * Are PCOMP and DCOMP value the same as in the first segment?
544 */
545 UBYTE prim_dcomp = 0;
546 UBYTE prim_pcomp = 0;
547 UBYTE nsapi = 0;
548
549 sda_get_nsapi(ll_data_ind, &nsapi);
550 prim_dcomp = sda_get_dcomp(ll_data_ind);
551 prim_pcomp = sda_get_pcomp(ll_data_ind);
552 if (prim_dcomp == sndcp_data->cur_dcomp[nsapi] &&
553 prim_pcomp == sndcp_data->cur_pcomp[nsapi]) {
554 sndcp_data->big_head[nsapi] = TRUE;
555 sda_ac_s_f0_m1(ll_data_ind);
556 } else {
557 sda_delete_cur_sn_data_ind(nsapi);
558 sig_sda_mg_re_est(ll_data_ind->sapi, nsapi);
559 PFREE(ll_data_ind);
560 }
561
562 } /* sda_ac_s_f1_m1() */
563
564 /*
565 +------------------------------------------------------------------------------
566 | Function : sda_ac_s_f1_m0
567 +------------------------------------------------------------------------------
568 | Description : E X T R A convenience function, not in SDL.
569 | Represents the label AC_S_F1_M1 in SDL.
570 |
571 | Parameters : ll_data_ind T_LL_DATA_IND*
572 |
573 +------------------------------------------------------------------------------
574 */
575 GLOBAL void sda_ac_s_f1_m0 (T_LL_DATA_IND* ll_data_ind)
576 {
577 /*
578 * Are PCOMP and DCOMP value the same as in the first segment?
579 */
580 UBYTE prim_dcomp = 0;
581 UBYTE prim_pcomp = 0;
582 UBYTE nsapi = 0;
583
584 sda_get_nsapi(ll_data_ind, &nsapi);
585 prim_dcomp = sda_get_dcomp(ll_data_ind);
586 prim_pcomp = sda_get_pcomp(ll_data_ind);
587 if (prim_dcomp == sndcp_data->cur_dcomp[nsapi] &&
588 prim_pcomp == sndcp_data->cur_pcomp[nsapi]) {
589 sndcp_data->big_head[nsapi] = TRUE;
590 sda_ac_s_f0_m0(ll_data_ind);
591 } else {
592 sda_delete_cur_sn_data_ind(nsapi);
593 sig_sda_mg_re_est(ll_data_ind->sapi, nsapi);
594 PFREE(ll_data_ind);
595 }
596
597 } /* sda_ac_s_f1_m0() */