FreeCalypso > hg > fc-magnetite
comparison src/g23m-fad/tcpip/tcpip_dti.c @ 174:90eb61ecd093
src/g23m-fad: initial import from TCS3.2/LoCosto
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 12 Oct 2016 05:40:46 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
173:bf64d785238a | 174:90eb61ecd093 |
---|---|
1 /* | |
2 +------------------------------------------------------------------------------ | |
3 | File: tcpip_dti.c | |
4 +------------------------------------------------------------------------------ | |
5 | Copyright 2003 Texas Instruments Berlin, AG | |
6 | All rights reserved. | |
7 | | |
8 | This file is confidential and a trade secret of Texas | |
9 | Instruments Berlin, AG | |
10 | The receipt of or possession of this file does not convey | |
11 | any rights to reproduce or disclose its contents or to | |
12 | manufacture, use, or sell anything it may describe, in | |
13 | whole, or in part, without the specific written consent of | |
14 | Texas Instruments Berlin, AG. | |
15 +----------------------------------------------------------------------------- | |
16 | Purpose : GPF-based TCP/IP's glue layer towards DTI. | |
17 +----------------------------------------------------------------------------- | |
18 */ | |
19 | |
20 | |
21 #define TCPIP_DTI_C | |
22 | |
23 #define ENTITY_TCPIP | |
24 | |
25 /*==== INCLUDES =============================================================*/ | |
26 | |
27 #include <string.h> /* String functions, e. g. strncpy(). */ | |
28 | |
29 #include "typedefs.h" /* Condat data types */ | |
30 #include "vsi.h" /* a lot of macros */ | |
31 #include "custom.h" | |
32 #include "gsm.h" /* a lot of macros */ | |
33 #include "prim.h" /* definitions of used SAP and directions */ | |
34 #include "pei.h" /* PEI interface */ | |
35 #include "tools.h" /* common tools */ | |
36 #include "dti.h" /* DTI library definitions. */ | |
37 #include "tcpip.h" /* global entity definitions */ | |
38 #include "macdef.h" /* PFREE_DESC2() */ | |
39 | |
40 /* RNET includes | |
41 */ | |
42 #include "rv_general.h" | |
43 #include "rnet_api.h" | |
44 #include "rnet_rt_env.h" | |
45 #include "rnet_message.h" | |
46 #include "rnet_rt_i.h" | |
47 | |
48 | |
49 /*==== Local data ===========================================================*/ | |
50 | |
51 | |
52 | |
53 | |
54 /*==== Local utility functions ==============================================*/ | |
55 | |
56 | |
57 | |
58 /*==== Specific event handler functions =====================================*/ | |
59 | |
60 | |
61 /** Handle the respective DTI primitive. These functions simply forward the | |
62 * DTI primitive to the appropriate DTI library function, but with the | |
63 * entity's dti_handle as additional argument. | |
64 * | |
65 * @param dti_* Pointer to the primitive. | |
66 */ | |
67 | |
68 void tcpip_dti_ready_ind(T_DTI2_READY_IND *dti_ready_ind) | |
69 { | |
70 dti_dti_ready_ind(tcpip_data->dti_handle, dti_ready_ind) ; } | |
71 | |
72 void tcpip_dti_data_req(T_DTI2_DATA_REQ *dti_data_req) | |
73 { | |
74 dti_dti_data_req(tcpip_data->dti_handle, dti_data_req) ; } | |
75 | |
76 void tcpip_dti_data_ind(T_DTI2_DATA_IND *dti_data_ind) | |
77 { | |
78 dti_dti_data_ind(tcpip_data->dti_handle, dti_data_ind) ; } | |
79 | |
80 void tcpip_dti_getdata_req(T_DTI2_GETDATA_REQ *dti_getdata_req) | |
81 { | |
82 dti_dti_getdata_req(tcpip_data->dti_handle, dti_getdata_req) ; } | |
83 | |
84 #if defined(_SIMULATION_) | |
85 void tcpip_dti_data_test_ind(T_DTI2_DATA_TEST_IND *dti_data_test_ind) | |
86 { dti_dti_data_test_ind(tcpip_data->dti_handle, dti_data_test_ind) ; } | |
87 | |
88 void tcpip_dti_data_test_req(T_DTI2_DATA_TEST_REQ *dti_data_test_req) | |
89 { dti_dti_data_test_req(tcpip_data->dti_handle, dti_data_test_req) ; } | |
90 #endif /* _SIMULATION_ */ | |
91 | |
92 void tcpip_dti_connect_req(T_DTI2_CONNECT_REQ *dti_connect_req ) | |
93 { | |
94 dti_dti_connect_req(tcpip_data->dti_handle, dti_connect_req) ; } | |
95 | |
96 void tcpip_dti_disconnect_ind(T_DTI2_DISCONNECT_IND *dti_disconnect_ind) | |
97 { | |
98 dti_dti_disconnect_ind(tcpip_data->dti_handle, dti_disconnect_ind) ; } | |
99 | |
100 void tcpip_dti_connect_cnf(T_DTI2_CONNECT_CNF *dti_connect_cnf) | |
101 { | |
102 dti_dti_connect_cnf(tcpip_data->dti_handle, dti_connect_cnf) ; } | |
103 | |
104 void tcpip_dti_connect_ind(T_DTI2_CONNECT_IND *dti_connect_ind) | |
105 { | |
106 dti_dti_connect_ind(tcpip_data->dti_handle, dti_connect_ind) ; } | |
107 | |
108 void tcpip_dti_connect_res(T_DTI2_CONNECT_RES *dti_connect_res) | |
109 { | |
110 dti_dti_connect_res(tcpip_data->dti_handle, dti_connect_res) ; } | |
111 | |
112 void tcpip_dti_disconnect_req(T_DTI2_DISCONNECT_REQ *dti_disconnect_req) | |
113 { | |
114 dti_dti_disconnect_req(tcpip_data->dti_handle, dti_disconnect_req) ; } | |
115 | |
116 | |
117 | |
118 | |
119 /*==== Callback functions ===================================================*/ | |
120 | |
121 | |
122 /** Handle a "DTI connection opened" indication; send a DTI confirmation to | |
123 * the ACI. | |
124 * | |
125 * @param interfac To lower layer or to higher layer. | |
126 * @param channel Number of connection to other layer. | |
127 */ | |
128 static void tcpip_dti_connection_opened_ind(U8 interfac, U8 channel) | |
129 { | |
130 TRACE_FUNCTION("tcpip_dti_connection_opened_ind()") ; | |
131 | |
132 | |
133 switch (interfac) | |
134 { | |
135 case TCPIP_DTI_TO_LOWER_LAYER: | |
136 dti_start(tcpip_data->dti_handle, 0, interfac, channel) ; | |
137 tcpip_dti_cnf(TCPIP_CONNECT_DTI, tcpip_data->ll[channel].link_id) ; | |
138 break ; | |
139 case TCPIP_DTI_TO_HIGHER_LAYER: | |
140 TRACE_ERROR("dti_connection_opened_ind: DTI to UL not yet implemented") ; | |
141 break ; | |
142 default: | |
143 TRACE_ERROR("DTI connection opened: unknown interface") ; | |
144 break ; | |
145 } | |
146 } | |
147 | |
148 | |
149 /** Handle a "DTI connection closed" indication; send a DTI confirmation to | |
150 * the ACI and mark the connection as dead. | |
151 * | |
152 * @param interfac To lower layer or to higher layer. | |
153 * @param channel Number of connection to other layer. | |
154 */ | |
155 static void tcpip_dti_connection_closed_ind(U8 interfac, U8 channel) | |
156 { | |
157 TRACE_FUNCTION("tcpip_dti_connection_closed_ind()") ; | |
158 | |
159 | |
160 switch (interfac) | |
161 { | |
162 case TCPIP_DTI_TO_LOWER_LAYER: | |
163 tcpip_dti_cnf(TCPIP_DISCONNECT_DTI, tcpip_data->ll[channel].link_id) ; | |
164 tcpip_data->ll[channel].link_id = 0 ; | |
165 break ; | |
166 case TCPIP_DTI_TO_HIGHER_LAYER: | |
167 TRACE_ERROR("dti_connection_closed_ind: DTI to UL not yet implemented") ; | |
168 break ; | |
169 default: | |
170 TRACE_ERROR("DTI connection opened: unknown interface") ; | |
171 break ; | |
172 } | |
173 } | |
174 | |
175 | |
176 /** Handle an incoming DTI data indication primitive from the lower layer; | |
177 * relay data to the IP input function. | |
178 * | |
179 * @param dti_data_ind Pointer to the primitive. | |
180 */ | |
181 static void tcpip_ll_dti_data_ind(T_DTI2_DATA_IND *dti_data_ind) | |
182 { | |
183 NGbuf *bufp ; | |
184 T_desc2 *ddesc ; /* DTI2 data descriptor. */ | |
185 int n_copied ; /* Number of bytes already copied. */ | |
186 | |
187 TRACE_FUNCTION("tcpip_ll_dti_data_ind()") ; | |
188 if (dti_data_ind->desc_list2.list_len <= TCPIP_DEFAULT_MTU_SIZE) | |
189 { | |
190 ngBufAlloc(bufp) ; /* This is macro that assigns to bufp. */ | |
191 if (bufp) /* If we got a buffer... */ | |
192 { | |
193 bufp->buf_datalen = dti_data_ind->desc_list2.list_len ; | |
194 bufp->buf_next = NULL ; | |
195 bufp->buf_iov = NULL ; | |
196 bufp->buf_iovcnt = 0 ; | |
197 bufp->buf_flags = NG_PROTO_IP ; | |
198 bufp->buf_datap = ((NGubyte *) bufp) + ngBufDataOffset; | |
199 | |
200 /* Copy data to buffer. */ | |
201 for (ddesc = (T_desc2 *) dti_data_ind->desc_list2.first, n_copied = 0; | |
202 ddesc NEQ NULL; | |
203 ddesc = (T_desc2 *) ddesc->next) | |
204 { | |
205 memcpy(bufp->buf_datap + n_copied, | |
206 ddesc->buffer + ddesc->offset, | |
207 ddesc->len) ; | |
208 n_copied += ddesc->len ; | |
209 } | |
210 /* Finally, send to IP. */ | |
211 ngIfGenInput(&rnet_rt_env_ctrl_blk_p->ifnet_dti.dti_ifnet, bufp, 1) ; | |
212 } | |
213 else | |
214 { | |
215 TRACE_ERROR("ngBufAlloc() failed for incoming from DTI") ; | |
216 } | |
217 } | |
218 else | |
219 { | |
220 /* Packet too big -> drop it. */ | |
221 TRACE_ERROR("incoming IP packet > MTU size") ; | |
222 } | |
223 | |
224 /* TRACE_EVENT("PFREE_DESC2(dti_data_ind) ...") ; */ | |
225 PFREE_DESC2(dti_data_ind) ; | |
226 /* TRACE_EVENT("...Done") ; */ | |
227 } | |
228 | |
229 | |
230 /** Handle an incoming DTI data indication primitive from the higher layer; | |
231 * relay data to the socket send function. | |
232 * | |
233 * @param dti_data_ind Pointer to the primitive. | |
234 */ | |
235 static void tcpip_hl_dti_data_ind(T_DTI2_DATA_IND *dti_data_ind) | |
236 { | |
237 TRACE_FUNCTION("tcpip_hl_dti_data_ind()") ; | |
238 | |
239 | |
240 /* This will be implemented later for SAT class E over TCP/IP. */ | |
241 TRACE_ERROR("DTI_DATA_IND: DTI to higher layer not yet implemented") ; | |
242 PFREE(dti_data_ind) ; | |
243 } | |
244 | |
245 | |
246 /** Act on DTI's indication that the lower-layer send buffer is full. | |
247 * | |
248 * @param channel Channel identifier. | |
249 */ | |
250 static void tcpip_ll_dti_buffer_full_ind(U8 channel) | |
251 { | |
252 TRACE_FUNCTION("tcpip_ll_dti_buffer_full_ind()") ; | |
253 | |
254 /* Make a note of this; don't send any data from TCP/IP if this is set. */ | |
255 TRACE_EVENT("switch flow control towards lower layer to xoff") ; | |
256 rnet_rt_env_ctrl_blk_p->ifnet_dti.dti_ifnet.if_flags |= NG_IFF_OACTIVE ; | |
257 tcpip_data->ll[channel].flowstat_ul = TCPIP_FLOWCTL_XOFF ; | |
258 } | |
259 | |
260 | |
261 /** Act on DTI's indication that the higher-layer send buffer is full. | |
262 * | |
263 * @param channel Channel identifier. | |
264 */ | |
265 static void tcpip_hl_dti_buffer_full_ind(U8 channel) | |
266 { | |
267 TRACE_FUNCTION("tcpip_hl_dti_buffer_full_ind()") ; | |
268 | |
269 | |
270 /* This will be implemented later for SAT class E over TCP/IP. */ | |
271 TRACE_ERROR("DTI buffer full: DTI to higher layer not yet implemented") ; | |
272 } | |
273 | |
274 | |
275 /** Act on DTI's indication that the lower-layer send buffer is ready for | |
276 * sending again. | |
277 * | |
278 * @param channel Channel identifier. | |
279 */ | |
280 static void tcpip_ll_dti_buffer_ready_ind(U8 channel) | |
281 { | |
282 TRACE_FUNCTION("tcpip_ll_dti_buffer_ready_ind()") ; | |
283 | |
284 | |
285 /* Note this; enable fetching data from TCP/IP again. */ | |
286 TRACE_EVENT("switch flow control towards lower layer to xon") ; | |
287 rnet_rt_env_ctrl_blk_p->ifnet_dti.dti_ifnet.if_flags &= ~NG_IFF_OACTIVE; | |
288 tcpip_data->ll[channel].flowstat_ul = TCPIP_FLOWCTL_XON ; | |
289 } | |
290 | |
291 | |
292 /** Act on DTI's indication that the higher-layer send buffer is ready for | |
293 * sending again. | |
294 * | |
295 * @param channel Channel identifier. | |
296 */ | |
297 static void tcpip_hl_dti_buffer_ready_ind(U8 channel) | |
298 { | |
299 TRACE_FUNCTION("tcpip_hl_dti_buffer_ready_ind()") ; | |
300 | |
301 | |
302 /* This will be implemented later for SAT class E over TCP/IP. */ | |
303 TRACE_ERROR("DTI buffer ready: DTI to higher layer not yet implemented") ; | |
304 } | |
305 | |
306 | |
307 /** Central DTI callback dispatcher function according to dti.h. | |
308 * | |
309 * @param instance Instance number (unused in TCPIP). | |
310 * @param interfac Interface number (higher or lower layer). | |
311 * @param channel Channel number (to be used for lower layer in the | |
312 * future). | |
313 * @param reason Code for the event to be handled. | |
314 * @param dti_data_ind Data primitive if present. | |
315 */ | |
316 void tcpip_dti_callback(U8 instance, U8 interfac, U8 channel, U8 reason, | |
317 T_DTI2_DATA_IND *dti_data_ind) | |
318 { | |
319 TRACE_FUNCTION("tcpip_dti_callback()") ; | |
320 | |
321 | |
322 /* We don't use the instance parameter at all, so it is not passed to the | |
323 * final handler functions. */ | |
324 | |
325 switch (reason) | |
326 { | |
327 case DTI_REASON_CONNECTION_OPENED: /* DTI connect */ | |
328 tcpip_dti_connection_opened_ind(interfac, channel) ; | |
329 break; | |
330 case DTI_REASON_CONNECTION_CLOSED: /* DTI disconnect */ | |
331 tcpip_dti_connection_closed_ind(interfac, channel) ; | |
332 break; | |
333 case DTI_REASON_DATA_RECEIVED: | |
334 ((interfac EQ TCPIP_DTI_TO_LOWER_LAYER) | |
335 ? tcpip_ll_dti_data_ind : tcpip_hl_dti_data_ind)(dti_data_ind); | |
336 break; | |
337 case DTI_REASON_TX_BUFFER_FULL: | |
338 ((interfac EQ TCPIP_DTI_TO_LOWER_LAYER) | |
339 ? tcpip_ll_dti_buffer_full_ind | |
340 : tcpip_hl_dti_buffer_full_ind)(channel) ; | |
341 break; | |
342 case DTI_REASON_TX_BUFFER_READY: | |
343 ((interfac EQ TCPIP_DTI_TO_LOWER_LAYER) | |
344 ? tcpip_ll_dti_buffer_ready_ind | |
345 : tcpip_hl_dti_buffer_ready_ind)(channel) ; | |
346 break; | |
347 default: | |
348 TRACE_ERROR("bogus DTI reason code"); | |
349 break; | |
350 } /* end switch */ | |
351 } /* tcpip_dti_callback() */ | |
352 | |
353 | |
354 | |
355 /*==== Service functions ====================================================*/ | |
356 | |
357 | |
358 /** Send the data buffer with the specified length to the lower layer. The | |
359 * data buffer will be freed by the caller. | |
360 * | |
361 * @param data Pointer to the data. | |
362 * @param length Length of the data. | |
363 */ | |
364 void tcpip_dti_send_data_ll(U8 *data, U16 length) | |
365 { | |
366 T_desc2 *ddesc ; /* Pointer to DTI descriptor. */ | |
367 | |
368 TRACE_FUNCTION("tcpip_dti_send_data_ll()") ; | |
369 | |
370 { | |
371 PALLOC(dind, DTI2_DATA_IND) ; | |
372 MALLOC(ddesc, sizeof(T_desc2) - 1 + length) ; | |
373 | |
374 dind->desc_list2.list_len = length ; | |
375 dind->desc_list2.first = (U32) ddesc ; | |
376 ddesc->next = NULL ; | |
377 ddesc->offset = 0 ; | |
378 ddesc->len = length ; | |
379 ddesc->size = length ; | |
380 memcpy((U8 *) ddesc->buffer, data, length) ; | |
381 | |
382 dind->parameters.st_lines.st_line_sa = DTI_SA_ON; | |
383 dind->parameters.st_lines.st_line_sb = DTI_SB_ON; | |
384 dind->parameters.st_lines.st_flow = DTI_FLOW_ON; | |
385 dind->parameters.st_lines.st_break_len = DTI_BREAK_OFF; | |
386 | |
387 dind->link_id = 0; | |
388 dind->parameters.p_id = DTI_PID_IP; | |
389 | |
390 | |
391 #if 0 /* Keep these traces in mind, but not in the code right now. */ | |
392 /* tlu: content send to SNDCP */ | |
393 TRACE_EVENT_P1("!!!!content (tlu) data send to SNDCP (%d bytes)", length); | |
394 for (i=0; i<length; i++) | |
395 { | |
396 TRACE_EVENT_P1("cont: %02X", data[i]); | |
397 } | |
398 #endif /* 0 */ | |
399 | |
400 dti_send_data(tcpip_data->dti_handle, 0, | |
401 TCPIP_DTI_TO_LOWER_LAYER, 0, dind) ; | |
402 } | |
403 } | |
404 | |
405 | |
406 | |
407 /*==== Primitive sender functions ===========================================*/ | |
408 | |
409 | |
410 | |
411 /*==== Primitive handler functions ==========================================*/ | |
412 | |
413 | |
414 /* EOF */ |