comparison src/g23m-gprs/sndcp/sndcp_nup.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_nup.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 primitives as described in
19 | the SDL-documentation (NU-statemachine)
20 +-----------------------------------------------------------------------------
21 */
22
23 /*---- HISTORY --------------------------------------------------------------*/
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 "gsm.h" /* to get a lot of macros */
33 #include "prim.h" /* to get the definitions of used SAP and directions */
34
35 #include "dti.h"
36
37 #include "sndcp.h" /* to get the global entity definitions */
38 #include "sndcp_f.h" /* to get the functions to access the global arrays*/
39
40 #include "sndcp_nuf.h" /* to get functions from nu service */
41 #include "sndcp_sus.h" /* to get internal signals to su signals */
42 #include "sndcp_suas.h" /* to get internal signals to sua signals */
43
44
45 /*==== CONST ================================================================*/
46
47 /*==== LOCAL VARS ===========================================================*/
48
49 /*==== PRIVATE FUNCTIONS ====================================================*/
50
51 /*==== PUBLIC FUNCTIONS =====================================================*/
52
53
54 /*
55 +------------------------------------------------------------------------------
56 | Function : nu_connection_state
57 +------------------------------------------------------------------------------
58 | Description : DTI connnection has been opened by calling sndcp_sig_callback
59 | with reason DTI_REASON_CONNECTION_OPENED.
60 |
61 | Parameters : UBYTE nsapi: the affected NSAPI
62 |
63 +------------------------------------------------------------------------------
64 */
65 GLOBAL void nu_connection_state (UBYTE nsapi, BOOL opened)
66 {
67 TRACE_ISIG( "nu_connection_state" );
68
69 /*
70 * set service instance according to nsapi in primitive
71 */
72 sndcp_data->nu = & sndcp_data->nu_base[nsapi];
73
74 switch( GET_STATE( NU ) )
75 {
76
77 case NU_UNACK_SU_RECEPTIVE :
78 case NU_UNACK_SU_NOT_RECEPTIVE:
79 #ifndef NCONFIG
80 case NU_SEND_UNACK_SU_RECEPTIVE:
81 case NU_SEND_UNACK_SU_NOT_RECEPTIVE:
82 #endif /* NCONFIG */
83 if (!sndcp_data->nu->connection_is_opened
84 &&
85 opened) {
86 sndcp_data->nu->connection_is_opened = TRUE;
87 #ifndef SNDCP_UPM_INCLUDED
88 if (sndcp_data->nu->sn_switch_cnf_expected) {
89 PALLOC (sn_switch_cnf, SN_SWITCH_CNF);
90 sn_switch_cnf->nsapi = nsapi;
91 sndcp_data->nu->sn_switch_cnf_expected = FALSE;
92 PSEND(hCommMMI, sn_switch_cnf);
93 }
94 #endif /*SNDCP_UPM_INCLUDED*/
95 #ifdef SNDCP_UPM_INCLUDED
96 {
97 U32 linkid = 0;
98 PALLOC (sn_dti_cnf, SN_DTI_CNF);
99 sndcp_get_nsapi_linkid(nsapi, &linkid);
100 sn_dti_cnf->dti_linkid = linkid;
101 sndcp_data->nu->sn_dti_cnf_expected = FALSE;
102 sn_dti_cnf->dti_conn = NAS_CONNECT_DTI;
103
104 PSEND(hCommMMI, sn_dti_cnf);
105 }
106 #endif
107 nu_unitready_ind_if_nec(nsapi);
108
109 } else if (!opened) {
110 sndcp_data->nu->connection_is_opened = FALSE;
111 sndcp_data->nu->sn_unitready_ind_pending = FALSE;
112 sndcp_data->nu->sn_switch_cnf_expected = FALSE;
113 }
114 break;
115 case NU_ACK_SUA_RECEPTIVE:
116 case NU_ACK_SUA_NOT_RECEPTIVE:
117 case NU_SUS_SUA_RECEPTIVE:
118 case NU_SUS_SUA_NOT_RECEPTIVE:
119 case NU_REC_SUA_NOT_RECEPTIVE:
120 #ifndef NCONFIG
121 case NU_SEND_ACK_SUA_RECEPTIVE:
122 case NU_SEND_ACK_SUA_NOT_RECEPTIVE:
123 case NU_SEND_SUS_SUA_RECEPTIVE:
124 case NU_SEND_SUS_SUA_NOT_RECEPTIVE:
125 case NU_SEND_REC_SUA_NOT_RECEPTIVE:
126 #endif /* NCONFIG */
127 if (!sndcp_data->nu->connection_is_opened
128 &&
129 opened) {
130 sndcp_data->nu->connection_is_opened = TRUE;
131 #ifdef SNDCP_UPM_INCLUDED
132 {
133 U32 linkid = 0;
134 PALLOC (sn_dti_cnf, SN_DTI_CNF);
135 sndcp_get_nsapi_linkid(nsapi, &linkid);
136 sn_dti_cnf->dti_linkid = linkid;
137 sndcp_data->nu->sn_dti_cnf_expected = FALSE;
138 sn_dti_cnf->dti_conn = NAS_CONNECT_DTI;
139
140 PSEND(hCommMMI, sn_dti_cnf);
141 }
142
143 #else
144 if (sndcp_data->nu->sn_switch_cnf_expected) {
145 PALLOC (sn_switch_cnf, SN_SWITCH_CNF);
146 sn_switch_cnf->nsapi = nsapi;
147 sndcp_data->nu->sn_switch_cnf_expected = FALSE;
148 PSEND(hCommMMI, sn_switch_cnf);
149 }
150 #endif
151 nu_ready_ind_if_nec(nsapi);
152 } else if (!opened) {
153 sndcp_data->nu->connection_is_opened = FALSE;
154 sndcp_data->nu->sn_ready_ind_pending = FALSE;
155 sndcp_data->nu->sn_switch_cnf_expected = FALSE;
156 }
157 break;
158 default:
159 TRACE_ERROR( "Function nu_connection_state unexpected" );
160 break;
161 }
162 } /* nu_connection_state() */
163
164 /*
165 +------------------------------------------------------------------------------
166 | Function : nu_sn_data_req
167 +------------------------------------------------------------------------------
168 | Description : Handles the primitive SN_DATA_REQ
169 |
170 | Parameters : *sn_data_req - Ptr to primitive payload
171 |
172 +------------------------------------------------------------------------------
173 */
174 GLOBAL void nu_sn_data_req ( T_SN_DATA_REQ *sn_data_req )
175 {
176 BOOL used = FALSE;
177 BOOL sack = FALSE;
178 UBYTE sapi = 0;
179
180 TRACE_FUNCTION( "nu_sn_data_req" );
181
182 dti_stop(sndcp_data->hDTI,
183 0,
184 #ifndef SNDCP_UPM_INCLUDED
185 SNDCP_INTERFACE_ACK,
186 #else
187 SNDCP_INTERFACE_UNACK,
188 #endif
189 sn_data_req->nsapi);
190
191 /*
192 * set service instance according to nsapi in primitive
193 */
194 sndcp_data->nu = & sndcp_data->nu_base[sn_data_req->nsapi];
195 /*
196 * User has used up his ready_ind.
197 */
198 sndcp_data->nu->sn_ready_ind_pending = FALSE;
199 /*
200 * If context is not active, discard primitive.
201 */
202 sndcp_is_nsapi_used(sn_data_req->nsapi, &used);
203 if (!used && sn_data_req != NULL) {
204 MFREE_PRIM(sn_data_req);
205 sn_data_req = NULL;
206 return;
207 }
208 if (sn_data_req == NULL) {
209 /*
210 * Should not be possible. Only included to avoid NULL pointer use.
211 */
212 return;
213 }
214
215 #ifdef SNDCP_TRACE_IP_DATAGRAM
216 if(sndcp_data->trace_ip_header || sndcp_data->trace_ip_datagram){
217 TRACE_EVENT("--------- Uplink IP datagram ---------");
218 #ifdef _SNDCP_DTI_2_
219 sndcp_trace_ip_datagram(& sn_data_req->desc_list2);
220 #else /*_SNDCP_DTI_2_*/
221 sndcp_trace_ip_datagram(& sn_data_req->desc_list);
222 #endif /*_SNDCP_DTI_2_*/
223 TRACE_EVENT("--------------------------------------");
224 } else {
225 #ifdef _SNDCP_DTI_2_
226 sndcp_default_ip_trace(& sn_data_req->desc_list2, SNDCP_UL_PACKET);
227 #else /*_SNDCP_DTI_2_*/
228 sndcp_default_ip_trace& sn_data_req->desc_list, SNDCP_UL_PACKET);
229 #endif /*_SNDCP_DTI_2_*/
230 }
231 if(sndcp_data->trace_ip_bin){
232 #ifdef _SNDCP_DTI_2_
233 sndcp_bin_trace_ip(& sn_data_req->desc_list2, SNDCP_UL_PACKET);
234 #else /*_SNDCP_DTI_2_*/
235 sndcp_bin_trace_ip(& sn_data_req->desc_list, SNDCP_UL_PACKET);
236 #endif /*_SNDCP_DTI_2_*/
237 }
238
239 #else /* SNDCP_TRACE_IP_DATAGRAM */
240
241 #ifdef SNDCP_TRACE_BUFFER
242 #ifdef _SNDCP_DTI_2_
243 TRACE_EVENT_P1("uplink at SN SAP: %d octets",
244 sn_data_req->desc_list2.list_len);
245 sndcp_trace_desc_list(& sn_data_req->desc_list2);
246 #else /*_SNDCP_DTI_2_*/
247 TRACE_EVENT_P1("uplink at SN SAP: %d octets",
248 sn_data_req->desc_list.list_len);
249 sndcp_trace_desc_list(& sn_data_req->desc_list);
250 #endif /*_SNDCP_DTI_2_*/
251 #endif /* SNDCP_TRACE_BUFFER */
252 #endif /* SNDCP_TRACE_IP_DATAGRAM */
253
254
255 switch( GET_STATE( NU ) )
256 {
257 case NU_ACK_SUA_RECEPTIVE:
258 /*
259 * Buffer the given N-PDU
260 */
261 nu_buffer_npdu(sndcp_data->nu->send_npdu_number_ack, sn_data_req);
262 /*
263 * It is not checked here if the nsapi is active anyway!
264 */
265 sndcp_get_nsapi_sapi(sndcp_data->nu->nsapi, &sapi);
266 SET_STATE(NU, NU_ACK_SUA_NOT_RECEPTIVE);
267 sndcp_data->nu->send_npdu_number_ack =
268 (U8)((sndcp_data->nu->send_npdu_number_ack + 1) % MAX_NPDU_NUMBER_ACK);
269 sndcp_get_sapi_ack(sapi, &sack);
270 if(sack){
271 sig_nu_sua_data_req(sn_data_req,
272 (U8)((sndcp_data->nu->send_npdu_number_ack - 1
273 + MAX_NPDU_NUMBER_ACK)% MAX_NPDU_NUMBER_ACK),
274 sn_data_req->nsapi,
275 sapi);
276 }
277
278
279 break;
280 case NU_UNACK_SU_NOT_RECEPTIVE:
281 case NU_UNACK_SU_RECEPTIVE:
282 nu_unitready_ind_if_nec(sn_data_req->nsapi);
283 #ifdef _SNDCP_DTI_2_
284 MFREE_PRIM(sn_data_req);
285 #else /*_SNDCP_DTI_2_*/
286 PFREE_DESC(sn_data_req);
287 #endif /*_SNDCP_DTI_2_*/
288 sn_data_req = NULL;
289 break;
290 case NU_REC_SUA_NOT_RECEPTIVE:
291 case NU_SUS_SUA_NOT_RECEPTIVE:
292 case NU_SUS_SUA_RECEPTIVE:
293 case NU_ACK_SUA_NOT_RECEPTIVE:
294
295 nu_buffer_npdu(sndcp_data->nu->send_npdu_number_ack,
296 sn_data_req);
297 sndcp_data->nu->send_npdu_number_ack =
298 (U8)((sndcp_data->nu->send_npdu_number_ack + 1) % MAX_NPDU_NUMBER_ACK);
299 break;
300 #ifndef NCONFIG
301 case NU_SEND_UNACK_SU_RECEPTIVE:
302 case NU_SEND_UNACK_SU_NOT_RECEPTIVE:
303 case NU_SEND_ACK_SUA_RECEPTIVE:
304 case NU_SEND_ACK_SUA_NOT_RECEPTIVE:
305 case NU_SEND_SUS_SUA_RECEPTIVE:
306 case NU_SEND_SUS_SUA_NOT_RECEPTIVE:
307 case NU_SEND_REC_SUA_NOT_RECEPTIVE:
308 #ifndef SNDCP_UPM_INCLUDED
309 dti_start(sndcp_data->hDTI, 0, SNDCP_INTERFACE_ACK, sn_data_req->nsapi);
310 #ifdef _SNDCP_DTI_2_
311 MFREE_PRIM(sn_data_req);
312 #else /*_SNDCP_DTI_2_*/
313 PFREE_DESC(sn_data_req);
314 #endif /*_SNDCP_DTI_2_*/
315 #else /*#ifndef SNDCP_UPM_INCLUDED*/
316 dti_start(sndcp_data->hDTI, 0, SNDCP_INTERFACE_UNACK, sn_data_req->nsapi);
317 MFREE_PRIM(sn_data_req);
318 #endif /*#ifndef SNDCP_UPM_INCLUDED*/
319
320 sn_data_req = NULL;
321 break;
322 #endif
323 default:
324 TRACE_ERROR( "SN_DATA_REQ unexpected" );
325 #ifdef _SNDCP_DTI_2_
326 MFREE_PRIM(sn_data_req);
327 #else /*_SNDCP_DTI_2_*/
328 PFREE_DESC(sn_data_req);
329 #endif /*_SNDCP_DTI_2_*/
330 sn_data_req = NULL;
331 break;
332 }
333
334 } /* nu_sn_data_req() */
335
336 /*
337 +------------------------------------------------------------------------------
338 | Function : nu_sn_unitdata_req
339 +------------------------------------------------------------------------------
340 | Description : Handles the primitive SN_UNITDATA_REQ
341 |
342 | Parameters : *sn_unitdata_req - Ptr to primitive payload
343 |
344 +------------------------------------------------------------------------------
345 */
346 GLOBAL void nu_sn_unitdata_req ( T_SN_UNITDATA_REQ *sn_unitdata_req )
347 {
348 UBYTE sapi = 0;
349 BOOL used = FALSE;
350 UBYTE nsapi = sn_unitdata_req->nsapi;
351
352
353 #ifdef FLOW_TRACE
354 sndcp_trace_flow_control(FLOW_TRACE_SNDCP, FLOW_TRACE_UP, FLOW_TRACE_TOP, FALSE);
355 #endif
356
357 TRACE_FUNCTION( "nu_sn_unitdata_req" );
358
359 dti_stop(sndcp_data->hDTI,
360 0,
361 SNDCP_INTERFACE_UNACK,
362 sn_unitdata_req->nsapi);
363
364 /*
365 * set service instance according to nsapi in primitive
366 */
367 sndcp_data->nu = & sndcp_data->nu_base[sn_unitdata_req->nsapi];
368 /*
369 * User has used up his ready_ind.
370 */
371 sndcp_data->nu->sn_unitready_ind_pending = FALSE;
372 /*
373 * If context is not active, discard primitive.
374 */
375 sndcp_is_nsapi_used(sn_unitdata_req->nsapi, &used);
376 if (!used) {
377 #ifdef _SNDCP_DTI_2_
378 MFREE_PRIM (sn_unitdata_req);
379 #else /*_SNDCP_DTI_2_*/
380 PFREE_DESC (sn_unitdata_req);
381 #endif /*_SNDCP_DTI_2_*/
382 sn_unitdata_req = NULL;
383 return;
384 }
385
386 #ifdef SNDCP_TRACE_IP_DATAGRAM
387 if(sndcp_data->trace_ip_header || sndcp_data->trace_ip_datagram){
388 TRACE_EVENT("--------- Uplink IP datagram ---------");
389 #ifdef _SNDCP_DTI_2_
390 sndcp_trace_ip_datagram(& sn_unitdata_req->desc_list2);
391 #else /*_SNDCP_DTI_2_*/
392 sndcp_trace_ip_datagram(& sn_unitdata_req->desc_list);
393 #endif /*_SNDCP_DTI_2_*/
394 TRACE_EVENT("--------------------------------------");
395 } else {
396 #ifdef _SNDCP_DTI_2_
397 sndcp_default_ip_trace(& sn_unitdata_req->desc_list2, SNDCP_UL_PACKET);
398 #else /*_SNDCP_DTI_2_*/
399 sndcp_default_ip_trace(& sn_unitdata_req->desc_list, SNDCP_UL_PACKET);
400 #endif /*_SNDCP_DTI_2_*/
401 }
402 if(sndcp_data->trace_ip_bin){
403 #ifdef _SNDCP_DTI_2_
404 sndcp_bin_trace_ip(& sn_unitdata_req->desc_list2, SNDCP_UL_PACKET);
405 #else /*_SNDCP_DTI_2_*/
406 sndcp_bin_trace_ip(& sn_unitdata_req->desc_list, SNDCP_UL_PACKET);
407 #endif /*_SNDCP_DTI_2_*/
408 }
409 #else /* SNDCP_TRACE_IP_DATAGRAM */
410
411 #ifdef SNDCP_TRACE_BUFFER
412 #ifdef _SNDCP_DTI_2_
413 TRACE_EVENT_P1("uplink at SN SAP: %d octets",
414 sn_unitdata_req->desc_list2.list_len);
415 sndcp_trace_desc_list(& sn_unitdata_req->desc_list2);
416 #else /*_SNDCP_DTI_2_*/
417 TRACE_EVENT_P1("uplink at SN SAP: %d octets",
418 sn_unitdata_req->desc_list.list_len);
419 sndcp_trace_desc_list(& sn_unitdata_req->desc_list);
420 #endif /*_SNDCP_DTI_2_*/
421 #endif /* SNDCP_TRACE_BUFFER */
422 #endif /* SNDCP_TRACE_IP_DATAGRAM */
423
424 switch( GET_STATE( NU ) )
425 {
426 case NU_ACK_SUA_NOT_RECEPTIVE:
427 case NU_ACK_SUA_RECEPTIVE:
428 if (sn_unitdata_req != NULL) {
429 #ifdef _SNDCP_DTI_2_
430 MFREE_PRIM (sn_unitdata_req);
431 #else /*_SNDCP_DTI_2_*/
432 PFREE_DESC(sn_unitdata_req);
433 #endif /*_SNDCP_DTI_2_*/
434 sn_unitdata_req = NULL;
435 }
436 nu_ready_ind_if_nec(nsapi);
437 break;
438 case NU_UNACK_SU_NOT_RECEPTIVE:
439 if (sn_unitdata_req != NULL) {
440 #ifdef _SNDCP_DTI_2_
441 MFREE_PRIM (sn_unitdata_req);
442 #else /*_SNDCP_DTI_2_*/
443 PFREE_DESC(sn_unitdata_req);
444 #endif /*_SNDCP_DTI_2_*/
445 sn_unitdata_req = NULL;
446 }
447 break;
448 case NU_UNACK_SU_RECEPTIVE:
449 /*
450 * It is not checked here if the nsapi is active anyway!
451 */
452 sndcp_get_nsapi_sapi(sndcp_data->nu->nsapi, &sapi);
453 SET_STATE(NU, NU_UNACK_SU_NOT_RECEPTIVE);
454 sndcp_data->nu->send_npdu_number_unack =
455 (sndcp_data->nu->send_npdu_number_unack + 1) % MAX_NPDU_NUMBER_UNACK;
456 sig_nu_su_unitdata_req(sn_unitdata_req,
457 (U16)((sndcp_data->nu->send_npdu_number_unack - 1
458 + MAX_NPDU_NUMBER_UNACK) % MAX_NPDU_NUMBER_UNACK),
459 sndcp_data->nu->nsapi,
460 sapi);
461
462
463 break;
464 #ifndef NCONFIG
465 case NU_SEND_UNACK_SU_RECEPTIVE:
466 case NU_SEND_UNACK_SU_NOT_RECEPTIVE:
467 case NU_SEND_ACK_SUA_RECEPTIVE:
468 case NU_SEND_ACK_SUA_NOT_RECEPTIVE:
469 case NU_SEND_SUS_SUA_RECEPTIVE:
470 case NU_SEND_SUS_SUA_NOT_RECEPTIVE:
471 case NU_SEND_REC_SUA_NOT_RECEPTIVE:
472 dti_start(sndcp_data->hDTI, 0, SNDCP_INTERFACE_UNACK, sn_unitdata_req->nsapi);
473 if (sn_unitdata_req != NULL) {
474 #ifdef _SNDCP_DTI_2_
475 MFREE_PRIM (sn_unitdata_req);
476 #else /*_SNDCP_DTI_2_*/
477 PFREE_DESC(sn_unitdata_req);
478 #endif /*_SNDCP_DTI_2_*/
479 sn_unitdata_req = NULL;
480 }
481
482 break;
483 #endif
484 default:
485 TRACE_ERROR( "SN_UNITDATA_REQ unexpected" );
486 #ifdef _SNDCP_DTI_2_
487 MFREE_PRIM (sn_unitdata_req);
488 #else /*_SNDCP_DTI_2_*/
489 PFREE_DESC(sn_unitdata_req);
490 #endif /*_SNDCP_DTI_2_*/
491
492 sn_unitdata_req = NULL;
493 break;
494 }
495
496 } /* nu_sn_unitdata_req() */
497
498