comparison src/g23m-gprs/sndcp/sndcp_suap.c @ 1:fa8dc04885d8

src/g23m-*: import from Magnetite
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 16 Oct 2020 06:25:50 +0000
parents
children
comparison
equal deleted inserted replaced
0:4e78acac3d88 1:fa8dc04885d8
1 /*
2 +-----------------------------------------------------------------------------
3 | Project : GPRS (8441)
4 | Modul : sndcp_suap.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 (SUA-statemachine)
20 +-----------------------------------------------------------------------------
21 */
22
23 #define ENTITY_SNDCP
24
25 /*==== INCLUDES =============================================================*/
26
27 #include "typedefs.h" /* to get Condat data types */
28 #include "vsi.h" /* to get a lot of macros */
29 #include "macdef.h"
30 #include "prim.h" /* to get the definitions of used SAP and directions */
31
32 #include "dti.h"
33
34 #include "sndcp.h" /* to get the global entity definitions */
35 #include "sndcp_f.h" /* to get the functions to access the global arrays*/
36
37 #include "sndcp_suaf.h" /* to get internal functions of service sua */
38 #include "sndcp_nus.h" /* to get signal functions to service nu */
39
40
41 /*==== CONST ================================================================*/
42
43 /*==== LOCAL VARS ===========================================================*/
44
45 /*==== PRIVATE FUNCTIONS ====================================================*/
46
47 /*==== PUBLIC FUNCTIONS =====================================================*/
48
49
50
51 /*
52 +------------------------------------------------------------------------------
53 | Function : sua_ll_data_cnf
54 +------------------------------------------------------------------------------
55 | Description : Handles the primitive LL_DATA_CNF
56 |
57 | Parameters : *ll_data_cnf - Ptr to primitive payload
58 |
59 +------------------------------------------------------------------------------
60 */
61 GLOBAL void sua_ll_data_cnf ( T_LL_DATA_CNF *ll_data_cnf )
62 {
63 BOOL complete = FALSE;
64 BOOL found = FALSE;
65 T_SEG_INFO* help = NULL;
66 T_SEG_INFO* last_help = NULL;
67 UBYTE sapi_index = 0;
68 UBYTE refi = 0;
69
70 TRACE_FUNCTION( "sua_ll_data_cnf" );
71
72 /*
73 * set service instance according to sapi in primitive
74 */
75 sndcp_get_sapi_index(ll_data_cnf->sapi, &sapi_index);
76 sndcp_data->sua = & sndcp_data->sua_base[sapi_index];
77
78 TRACE_EVENT_P1("ll_data_cnf->c_reference1: %d", ll_data_cnf->c_reference1);
79
80 switch( GET_STATE( SUA ) )
81 {
82 case SUA_LLC_NOT_RECEPTIVE_SUSPEND:
83 case SUA_LLC_RECEPTIVE_SUSPEND:
84 case SUA_LLC_NOT_RECEPTIVE:
85 case SUA_LLC_RECEPTIVE:
86 for (refi = 0; refi < ll_data_cnf->c_reference1; refi++) {
87 complete = FALSE;
88 found = FALSE;
89 last_help = NULL;
90 help = sndcp_data->sua->first_seg_info;
91 if (help == NULL) {
92 /*
93 * There are no N-PDUs buffered. CNF must be wrong.
94 */
95 if (ll_data_cnf != NULL) {
96 TRACE_EVENT("There are no N-PDUs buffered. CNF must be wrong.");
97 PFREE(ll_data_cnf);
98 }
99 return;
100 }
101 while (help != NULL && !found) {
102 TRACE_EVENT_P1("ll_data_cnf->reference1[refi].ref_nsapi: %d",
103 ll_data_cnf->reference1[refi].ref_nsapi);
104 TRACE_EVENT_P1("ll_data_cnf->reference1[refi].ref_npdu_num: %d",
105 ll_data_cnf->reference1[refi].ref_npdu_num);
106 TRACE_EVENT_P1("ll_data_cnf->reference1[refi].ref_seg_num: %d",
107 ll_data_cnf->reference1[refi].ref_seg_num);
108 if (ll_data_cnf->reference1[refi].ref_nsapi == help->nsapi &&
109 ll_data_cnf->reference1[refi].ref_npdu_num == help->npdu_number)
110 {
111 TRACE_EVENT_P1("ll_data_cnf->reference1[refi].ref_seg_num: %d",
112 ll_data_cnf->reference1[refi].ref_seg_num);
113 TRACE_EVENT_P1("old help->cnf_segments: %d", help->cnf_segments);
114 help->cnf_segments +=
115 1 << ll_data_cnf->reference1[refi].ref_seg_num;
116 TRACE_EVENT_P1("new help->cnf_segments: %d", help->cnf_segments);
117 found = TRUE;
118 }
119 last_help = help;
120 help = help->next;
121 }
122 if (!found) {
123 /*
124 * No affected NPDU found.
125 */
126 if (ll_data_cnf != NULL) {
127 TRACE_EVENT("No affected NPDU found.");
128 PFREE(ll_data_cnf);
129 }
130 return;
131 }
132
133 /*
134 * If the affected N-PDU is completely confirmed, notify service nu and
135 * free last_help.
136 */
137
138 TRACE_EVENT_P1("last_help->number_of_segments: %d",
139 last_help->number_of_segments);
140 TRACE_EVENT_P1("last_help->cnf_segments: %d",
141 last_help->cnf_segments);
142
143 if (last_help->number_of_segments == SNDCP_SEGMENT_NUMBERS_ACK) {
144 if (last_help->cnf_segments ==
145 SNDCP_MAX_COMPLETE /*4294967295 == 2**32 - 1*/) {
146 complete = TRUE;
147 }
148 } else if (last_help->cnf_segments ==
149 ((ULONG)(1 << last_help->number_of_segments) - 1)) {
150 complete = TRUE;
151 }
152 if (complete) {
153 /*
154 * Notify service nu.
155 */
156 sig_sua_nu_data_cnf
157 (ll_data_cnf->reference1[refi].ref_nsapi,
158 (UBYTE)ll_data_cnf->reference1[refi].ref_npdu_num);
159 /*
160 * Free last_help.
161 */
162 help = sndcp_data->sua->first_seg_info;
163 if (help == last_help) {
164 sndcp_data->sua->first_seg_info = help->next;
165 MFREE(help);
166 help = NULL;
167 } else {
168 T_SEG_INFO* help_next = help->next;
169 while (help->next != last_help) {
170 help = help->next;
171 }
172 help_next = help->next;
173 help->next = help_next->next;
174 MFREE (help_next);
175 }
176 }
177 } /* for refi */
178 break;
179 default:
180 TRACE_ERROR( "LL_DATA_CNF unexpected" );
181 break;
182 }
183 if (ll_data_cnf != NULL) {
184 PFREE(ll_data_cnf);
185 }
186
187 } /* sua_ll_data_cnf() */
188
189
190 #ifdef _SNDCP_DTI_2_
191 /*
192 +------------------------------------------------------------------------------
193 | Function : sua_ll_ready_ind
194 +------------------------------------------------------------------------------
195 | Description : Handles the primitive LL_READY_IND
196 |
197 | Parameters : *ll_ready_ind - Ptr to primitive payload
198 |
199 +------------------------------------------------------------------------------
200 */
201 GLOBAL void sua_ll_ready_ind ( T_LL_READY_IND *ll_ready_ind )
202 {
203 U8 sapi_index = 0;
204
205 TRACE_FUNCTION( "sua_ll_ready_ind" );
206
207 /*
208 * set service instance according to sapi in primitive
209 */
210 sndcp_get_sapi_index(ll_ready_ind->sapi, &sapi_index);
211 sndcp_data->sua = & sndcp_data->sua_base[sapi_index];
212
213 switch( GET_STATE( SUA ) )
214 {
215 case SUA_LLC_NOT_RECEPTIVE_SUSPEND:
216 /*
217 * Is queue with outgoing LL_DESC_REQs empty?
218 */
219 if (sndcp_data->sua->ll_desc_q_read ==
220 sndcp_data->sua->ll_desc_q_write) {
221 if (sndcp_data->sua->cia_state == CIA_IDLE) {
222 sua_next_sn_data_req(ll_ready_ind->sapi);
223 }
224 }
225 SET_STATE(SUA, SUA_LLC_RECEPTIVE_SUSPEND);
226 break;
227 case SUA_LLC_RECEPTIVE_SUSPEND:
228 break;
229 case SUA_LLC_NOT_RECEPTIVE:
230 /*
231 * Is queue with outgoing LL_DESC_REQs empty?
232 */
233 if (sndcp_data->sua->ll_desc_q_read ==
234 sndcp_data->sua->ll_desc_q_write) {
235 SET_STATE(SUA, SUA_LLC_RECEPTIVE);
236 if (sndcp_data->sua->cia_state == CIA_IDLE) {
237 sua_next_sn_data_req(ll_ready_ind->sapi);
238 }
239 } else { /* sndcp_data->sua.ll_desc_q is not empty */
240 /*
241 * Send next ll_desc_req from queue.
242 */
243 T_LL_DESC_REQ* ll_desc_req =
244 sndcp_data->sua->ll_desc_q[sndcp_data->sua->ll_desc_q_read];
245
246 U8 ll_desc_sapi = ll_desc_req->sapi;
247 U8 ll_desc_seg_pos = ll_desc_req->seg_pos;
248 U8 ll_desc_nsapi = sua_get_nsapi(ll_desc_req);
249
250 sndcp_data->sua->ll_desc_q[sndcp_data->sua->ll_desc_q_read] = NULL;
251 sndcp_data->sua->ll_desc_q_read =
252 (sndcp_data->sua->ll_desc_q_read + 1) % SNDCP_SEGMENT_NUMBERS_ACK;
253
254 #ifdef _SIMULATION_
255 su_send_ll_data_req_test(ll_desc_req);
256 #else /* _SIMULATION_ */
257 PSEND(hCommLLC, ll_desc_req);
258 #endif /* _SIMULATION_ */
259
260 if ((ll_desc_seg_pos & SEG_POS_LAST) > 0) {
261 sig_sua_nu_ready_ind( ll_desc_nsapi );
262 sua_next_sn_data_req( ll_desc_sapi );
263 sndcp_data->sua->cia_state = CIA_IDLE;
264 }
265
266
267 } /* sndcp_data->sua.ll_desc_q is not empty */
268 break;
269 case SUA_LLC_RECEPTIVE:
270 break;
271 default:
272 TRACE_ERROR( "LL_READY_IND unexpected" );
273 break;
274 }
275 if (ll_ready_ind != NULL) {
276 PFREE (ll_ready_ind);
277 }
278
279 } /* su_ll_ready_ind() */
280 #else /* _SNDCP_DTI_2_ */
281 /*
282 +------------------------------------------------------------------------------
283 | Function : sua_ll_ready_ind
284 +------------------------------------------------------------------------------
285 | Description : Handles the primitive LL_READY_IND
286 |
287 | Parameters : *ll_ready_ind - Ptr to primitive payload
288 |
289 +------------------------------------------------------------------------------
290 */
291 GLOBAL void sua_ll_ready_ind ( T_LL_READY_IND *ll_ready_ind )
292 {
293 UBYTE sapi_index = 0;
294
295 TRACE_FUNCTION( "sua_ll_ready_ind" );
296
297 /*
298 * set service instance according to sapi in primitive
299 */
300 sndcp_get_sapi_index(ll_ready_ind->sapi, &sapi_index);
301 sndcp_data->sua = & sndcp_data->sua_base[sapi_index];
302
303 switch( GET_STATE( SUA ) )
304 {
305 case SUA_LLC_NOT_RECEPTIVE_SUSPEND:
306 /*
307 * Is queue with outgoing LL_DATA_REQs empty?
308 */
309 if (sndcp_data->sua->ll_data_q_read ==
310 sndcp_data->sua->ll_data_q_write) {
311 if (sndcp_data->sua->cia_state == CIA_IDLE) {
312 sua_next_sn_data_req(ll_ready_ind->sapi);
313 }
314 }
315 SET_STATE(SUA, SUA_LLC_RECEPTIVE_SUSPEND);
316 break;
317 case SUA_LLC_RECEPTIVE_SUSPEND:
318 break;
319 case SUA_LLC_NOT_RECEPTIVE:
320 /*
321 * Is queue with outgoing LL_DATA_REQs empty?
322 */
323 if (sndcp_data->sua->ll_data_q_read ==
324 sndcp_data->sua->ll_data_q_write) {
325 SET_STATE(SUA, SUA_LLC_RECEPTIVE);
326 if (sndcp_data->sua->cia_state == CIA_IDLE) {
327 sua_next_sn_data_req(ll_ready_ind->sapi);
328 }
329 } else { /* sndcp_data->sua.ll_data_q is not empty */
330 /*
331 * Send next ll_data_req from queue.
332 */
333 T_LL_DATA_REQ* ll_data_req =
334 sndcp_data->sua->ll_data_q[sndcp_data->sua->ll_data_q_read];
335
336 UBYTE ll_data_sapi = ll_data_req->sapi;
337 UBYTE ll_data_seg_pos = ll_data_req->seg_pos;
338 UBYTE ll_data_nsapi = sua_get_nsapi(ll_data_req);
339
340 sndcp_data->sua->ll_data_q[sndcp_data->sua->ll_data_q_read] = NULL;
341 sndcp_data->sua->ll_data_q_read =
342 (sndcp_data->sua->ll_data_q_read + 1) % SNDCP_SEGMENT_NUMBERS_ACK;
343
344 PSEND (hCommLLC, ll_data_req);
345
346 if ((ll_data_seg_pos & SEG_POS_LAST) > 0) {
347 sig_sua_nu_ready_ind( ll_data_nsapi );
348 sua_next_sn_data_req( ll_data_sapi );
349 sndcp_data->sua->cia_state = CIA_IDLE;
350 }
351
352
353 } /* sndcp_data->sua.ll_data_q is not empty */
354 break;
355 case SUA_LLC_RECEPTIVE:
356 break;
357 default:
358 TRACE_ERROR( "LL_READY_IND unexpected" );
359 break;
360 }
361 if (ll_ready_ind != NULL) {
362 PFREE (ll_ready_ind);
363 }
364
365 } /* su_ll_ready_ind() */
366 #endif /* _SNDCP_DTI_2_ */