comparison src/g23m-gprs/sndcp/sndcp_suaf.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_suaf.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 (SUA-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 "prim.h" /* to get the definitions of used SAP and directions */
32
33 #include "dti.h"
34
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_suaf.h" /* to get this file */
39 #include "sndcp_nus.h" /* to get signals to service nu */
40 #include "sndcp_cias.h" /* to get signals to service cia */
41
42
43 /*==== CONST ================================================================*/
44
45 /*==== LOCAL VARS ===========================================================*/
46
47 /*==== PRIVATE FUNCTIONS ====================================================*/
48
49 /*==== PUBLIC FUNCTIONS =====================================================*/
50
51 #ifdef _SNDCP_DTI_2_
52 /*
53 +------------------------------------------------------------------------------
54 | Function : sua_get_nsapi
55 +------------------------------------------------------------------------------
56 | Description : find the affected nsapi in sn-PDU.
57 |
58 | Parameters : ll_desc_req*
59 | Returns : the nsapi
60 |
61 +------------------------------------------------------------------------------
62 */
63 GLOBAL U8 sua_get_nsapi (T_LL_DESC_REQ* ll_desc_req)
64 {
65 T_desc3* desc3 = NULL;
66 U8 * sndcp_header = NULL;
67
68 /* Get the descriptor describing the memory area with the sndcp header */
69
70 desc3 = (T_desc3*)ll_desc_req->desc_list3.first;
71 sndcp_header = (U8*)desc3->buffer;
72
73 TRACE_FUNCTION( "sua_get_nsapi" );
74
75 return (*(sndcp_header + ENCODE_OFFSET_BYTE)) & 0xf;
76 } /* sua_get_nsapi() */
77 #else /* _SNDCP_DTI_2_ */
78 /*
79 +------------------------------------------------------------------------------
80 | Function : sua_get_nsapi
81 +------------------------------------------------------------------------------
82 | Description : find the affected nsapi in sn-PDU.
83 |
84 | Parameters : ll_data_req*
85 | Returns : the nsapi
86 |
87 +------------------------------------------------------------------------------
88 */
89 GLOBAL UBYTE sua_get_nsapi (T_LL_DATA_REQ* ll_data_req)
90 {
91 USHORT octet_offset = (ll_data_req->sdu.o_buf) >> 3;
92
93 TRACE_FUNCTION( "sua_get_nsapi" );
94
95 return ll_data_req->sdu.buf[octet_offset] & 0xf;
96
97 } /* sua_get_nsapi() */
98 #endif /* _SNDCP_DTI_2_ */
99 /*
100 +------------------------------------------------------------------------------
101 | Function : sua_init
102 +------------------------------------------------------------------------------
103 | Description : The function sua_init()
104 |
105 | Parameters :
106 |
107 +------------------------------------------------------------------------------
108 */
109 GLOBAL void sua_init (void)
110 {
111 TRACE_FUNCTION( "sua_init" );
112
113 /*
114 * Not initialized:
115 * Members of sn_data_q are not set to NULL.
116 * Members of npdu_number_q are not set to 0.
117 * Members of ll_desc_q are not set to NULL.
118 * Members of ll_data_q are not set to NULL.
119 */
120
121 sndcp_data->sua = & sndcp_data->sua_base[0];
122 INIT_STATE(SUA_0, SUA_LLC_NOT_RECEPTIVE);
123 #ifdef SNDCP_2to1
124 sndcp_data->sua->sapi = PS_SAPI_3;
125 #else
126 sndcp_data->sua->sapi = LL_SAPI_3;
127 #endif /*SNDCP_2to1*/
128 sndcp_data->sua = & sndcp_data->sua_base[1];
129 INIT_STATE(SUA_1, SUA_LLC_NOT_RECEPTIVE);
130 #ifdef SNDCP_2to1
131 sndcp_data->sua->sapi = PS_SAPI_5;
132 #else
133 sndcp_data->sua->sapi = LL_SAPI_5;
134 #endif /*SNDCP_2to1*/
135
136 sndcp_data->sua = & sndcp_data->sua_base[2];
137 INIT_STATE(SUA_2, SUA_LLC_NOT_RECEPTIVE);
138 #ifdef SNDCP_2to1
139 sndcp_data->sua->sapi = PS_SAPI_9;
140 #else
141 sndcp_data->sua->sapi = LL_SAPI_9;
142 #endif /*SNDCP_2to1*/
143
144 sndcp_data->sua = & sndcp_data->sua_base[3];
145 INIT_STATE(SUA_3, SUA_LLC_NOT_RECEPTIVE);
146 #ifdef SNDCP_2to1
147 sndcp_data->sua->sapi = PS_SAPI_11;
148 #else
149 sndcp_data->sua->sapi = LL_SAPI_11;
150 #endif /*SNDCP_2to1*/
151 {
152 UBYTE sapi_index = 0;
153
154 for (sapi_index = 0; sapi_index < SNDCP_NUMBER_OF_SAPIS; sapi_index++) {
155 sndcp_data->sua = & sndcp_data->sua_base[sapi_index];
156 sndcp_data->sua->n201_i = N201_I_DEFAULT;
157 sndcp_data->sua->sn_data_q_read = 0;
158 sndcp_data->sua->sn_data_q_write = 0;
159 #ifdef _SNDCP_DTI_2_
160 sndcp_data->sua->ll_desc_q_read = 0;
161 sndcp_data->sua->ll_desc_q_write = 0;
162 #else /* _SNDCP_DTI_2_ */
163 sndcp_data->sua->ll_data_q_read = 0;
164 sndcp_data->sua->ll_data_q_write = 0;
165 #endif /* _SNDCP_DTI_2_ */
166 sndcp_data->sua->first_seg_info = NULL;
167 sndcp_data->sua->cia_state = CIA_IDLE;
168
169 }
170 }
171
172 } /* sua_init() */
173
174
175
176
177 /*
178 +------------------------------------------------------------------------------
179 | Function : sua_mark_segment
180 +------------------------------------------------------------------------------
181 | Description : The function sua_mark_segment()
182 |
183 | Parameters : N-PDU number, NSAPI, LL_DESC_REQ in which the reference has to be set.
184 | Pre : The "correct" sua instance is activated and
185 | sndcp_data->sua->segment_number is the segment number of the
186 | current segment.
187 |
188 +------------------------------------------------------------------------------
189 */
190 GLOBAL void sua_mark_segment (UBYTE npdu_number,
191 UBYTE nsapi)
192 {
193 T_SEG_INFO* seg_info = NULL;
194
195 TRACE_FUNCTION( "sua_mark_segment" );
196
197 /*
198 * Add new seg_info to the list.
199 */
200 if (sndcp_data->sua->first_seg_info == NULL) {
201 MALLOC(seg_info, sizeof(T_SEG_INFO));
202 /*
203 * The list has been empty.
204 */
205 sndcp_data->sua->first_seg_info = seg_info;
206 /*
207 * First segment.
208 */
209 seg_info->number_of_segments = 1;
210 /*
211 * Reset the confirm mask.
212 */
213 seg_info->cnf_segments = 0;
214 seg_info->npdu_number = npdu_number;
215 seg_info->next = NULL;
216 seg_info->nsapi = nsapi;
217 } else {
218 /*
219 * There are already some seg_infos. Find the seg_info for the given N-PDU.
220 * number and NSAPI or create a new one.
221 */
222 /*
223 * Are N-PDU number and NSAPI different?
224 */
225 BOOL different = TRUE;
226 BOOL end = FALSE;
227 T_SEG_INFO* help = sndcp_data->sua->first_seg_info;
228
229 while(!end && different) {
230 if (nsapi == help->nsapi && npdu_number == help->npdu_number) {
231 different = FALSE;
232 } else {
233 if (help->next == NULL) {
234 end = TRUE;
235 } else {
236 help = help->next;
237 }
238 }
239 }
240 if (different) {
241 /*
242 * A seg_info with same NSAPI and N-PDU number has not been found.
243 * Create a new one.
244 */
245 MALLOC(seg_info, sizeof(T_SEG_INFO));
246 /*
247 * First segment.
248 */
249 seg_info->number_of_segments = 1;
250 /*
251 * Reset the confirm mask.
252 */
253 seg_info->cnf_segments = 0;
254 seg_info->npdu_number = npdu_number;
255 seg_info->next = NULL;
256 seg_info->nsapi = nsapi;
257 /*
258 * Add the new seg_info to the list.
259 */
260 help->next = seg_info;
261 } else {
262 /*
263 * A seg_info with same NSAPI and N-PDU number has been found.
264 * Use this one.
265 */
266 help->number_of_segments++;
267 }
268
269 }
270
271 } /* sua_mark_segment() */
272
273
274 /*
275 +------------------------------------------------------------------------------
276 | Function : sua_next_sn_data_req
277 +------------------------------------------------------------------------------
278 | Description : If queue with sn_data_req is
279 | not empty, send SIG_SUA_CIA_DATA_REQ with next prim from sn_data_req queue
280 |
281 | Parameters : sapi
282 | Pre : cia_state == CIA_IDLE
283 |
284 +------------------------------------------------------------------------------
285 */
286 GLOBAL void sua_next_sn_data_req (UBYTE sapi)
287 {
288 TRACE_FUNCTION( "sua_next_sn_data_req" );
289
290 if (sndcp_data->sua->sn_data_q_write !=
291 sndcp_data->sua->sn_data_q_read) {
292 /*
293 * Get sn_data_req from queue.
294 */
295 T_SN_DATA_REQ* sn_data_req =
296 sndcp_data->sua->sn_data_q[sndcp_data->sua->sn_data_q_read];
297 /*
298 * Get npdu_number from queue.
299 */
300 UBYTE npdu_num =
301 sndcp_data->sua->npdu_number_q[sndcp_data->sua->sn_data_q_read];
302 UBYTE nsapi = sn_data_req->nsapi;
303
304 sndcp_data->sua->sn_data_q[sndcp_data->sua->sn_data_q_read] = NULL;
305 sndcp_data->sua->sn_data_q_read =
306 (sndcp_data->sua->sn_data_q_read + 1) % SN_DATA_Q_LEN;
307
308 /*
309 * Cia is now busy. Send data.
310 */
311 sndcp_data->sua->cia_state = CIA_BUSY;
312 sig_sua_cia_cia_comp_req(sn_data_req,
313 npdu_num,
314 nsapi,
315 sapi);
316 } else if (sndcp_data->sua->cia_state == CIA_IDLE) {
317 UBYTE nsapi = 0;
318
319 for (nsapi = 0; nsapi < SNDCP_NUMBER_OF_NSAPIS; nsapi++) {
320 UBYTE used_sapi = 0;
321 BOOL used = FALSE;
322 BOOL ack = FALSE;
323
324 sndcp_is_nsapi_used(nsapi, &used);
325 if (used) {
326 sndcp_get_nsapi_sapi(nsapi, &used_sapi);
327 sndcp_get_nsapi_ack(nsapi, &ack);
328 if (used_sapi == sapi && ack) {
329 sig_sua_nu_ready_ind(nsapi);
330 }
331 }
332 }
333 }
334
335 } /* sua_next_sn_data_req() */
336