comparison src/g23m-fad/tcpip/tcpip_pei.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 | File: tcpip_pei.c
4 +------------------------------------------------------------------------------
5 | Copyright 2002 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 : This module implements the PEI interface
17 | for the entity TCPIP.
18 +-----------------------------------------------------------------------------
19 */
20
21 #define TCPIP_PEI_C
22
23 #define ENTITY_TCPIP
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 "custom.h"
30 #include "gsm.h" /* to get a lot of macros */
31 #include "prim.h" /* to get the definitions of used SAP and directions */
32 #include "pei.h" /* to get PEI interface */
33 #include "tools.h" /* to get common tools */
34 #include "dti.h" /* For DTI library definitions. */
35 #include "tcpip.h" /* to get the global entity definitions */
36 #define RNET_CFG_REAL_TRANSPORT
37 #include "rnet_api.h"
38 #include "rnet_rt_env.h"
39 #include "rv_general.h"
40 #include "rnet_rt_i.h"
41 #include <ngip/if.h>
42 #include "string.h"
43 #include "stdio.h"
44
45 T_RNET_DESC *desc;
46
47 /*==== CONSTS ================================================================*/
48
49 #define TCPIP_STACK_SIZE 2048
50 #define TCPIP_QUEUE_SIZE 15
51 #define TCPIP_PRIORITY 80
52 #define TCPIP_NUM_TIMER 1
53
54 #define PRIM_OFFSET_DTI2 0x50 /* We must subtract this from the DTI2
55 * opcodes. No, I don't know why. And, to be
56 * honest, I do not really care. */
57
58 /*==== TYPES =================================================================*/
59
60 /*==== LOCALS ================================================================*/
61
62 static BOOL first_access = TRUE;
63
64 static const T_FUNC tcpip_table[] =
65 {
66 MAK_FUNC_0(tcpip_initialize_req, TCPIP_INITIALIZE_REQ),
67 MAK_FUNC_0(tcpip_shutdown_req, TCPIP_SHUTDOWN_REQ),
68 MAK_FUNC_0(tcpip_ifconfig_req, TCPIP_IFCONFIG_REQ),
69 MAK_FUNC_0(tcpip_dti_req, TCPIP_DTI_REQ),
70 MAK_FUNC_0(tcpip_create_req, TCPIP_CREATE_REQ),
71 MAK_FUNC_0(tcpip_close_req, TCPIP_CLOSE_REQ),
72 MAK_FUNC_0(tcpip_bind_req, TCPIP_BIND_REQ),
73 MAK_FUNC_0(tcpip_listen_req, TCPIP_LISTEN_REQ),
74 MAK_FUNC_0(tcpip_connect_req, TCPIP_CONNECT_REQ),
75 MAK_FUNC_0(tcpip_data_req, TCPIP_DATA_REQ),
76 MAK_FUNC_0(tcpip_data_res, TCPIP_DATA_RES),
77 MAK_FUNC_0(tcpip_sockname_req, TCPIP_SOCKNAME_REQ),
78 MAK_FUNC_0(tcpip_peername_req, TCPIP_PEERNAME_REQ),
79 MAK_FUNC_0(tcpip_hostinfo_req, TCPIP_HOSTINFO_REQ),
80 MAK_FUNC_0(tcpip_mtu_size_req, TCPIP_MTU_SIZE_REQ),
81 MAK_FUNC_0(tcpip_internal_ind, TCPIP_INTERNAL_IND)
82 } ;
83
84 static const T_FUNC dti_dl_table[] =
85 {
86 MAK_FUNC_0(tcpip_dti_connect_ind , DTI2_CONNECT_IND ),
87 MAK_FUNC_0(tcpip_dti_connect_cnf , DTI2_CONNECT_CNF ),
88 MAK_FUNC_0(tcpip_dti_disconnect_ind , DTI2_DISCONNECT_IND) ,
89 MAK_FUNC_0(tcpip_dti_ready_ind , DTI2_READY_IND ),
90 MAK_FUNC_0(tcpip_dti_data_ind , DTI2_DATA_IND )
91 #if defined (_SIMULATION_)
92 ,
93 MAK_FUNC_S(tcpip_dti_data_test_ind , DTI2_DATA_TEST_IND )
94 #endif
95 } ;
96
97
98 static const T_FUNC dti_ul_table[] =
99 {
100 MAK_FUNC_0(tcpip_dti_connect_req , DTI2_CONNECT_REQ ),
101 MAK_FUNC_0(tcpip_dti_connect_res , DTI2_CONNECT_RES ),
102 MAK_FUNC_0(tcpip_dti_disconnect_req, DTI2_DISCONNECT_REQ) ,
103 MAK_FUNC_0(tcpip_dti_getdata_req , DTI2_GETDATA_REQ ),
104 MAK_FUNC_0(tcpip_dti_data_req , DTI2_DATA_REQ )
105
106 #if defined (_SIMULATION_)
107 ,
108 MAK_FUNC_S(tcpip_dti_data_test_req , DTI2_DATA_TEST_REQ )
109 #endif
110 } ;
111
112
113 /*==== PRIVATE FUNCTIONS ====================================================*/
114
115 /*
116 +------------------------------------------------------------------------------
117 | Function : primitive_not_supported
118 +------------------------------------------------------------------------------
119 | Description : This function handles unsupported primitives.
120 |
121 | Parameters : data - not used
122 |
123 | Return : void
124 +------------------------------------------------------------------------------
125 */
126 static void primitive_not_supported (void *data)
127 {
128 TRACE_FUNCTION ("primitive_not_supported");
129
130 PFREE (data);
131 }
132
133 /*
134 +------------------------------------------------------------------------------
135 | Function : pei_primitive
136 +------------------------------------------------------------------------------
137 | Description : Process protocol specific primitive.
138 |
139 | Parameters : prim - pointer to the received primitive
140 |
141 | Return : PEI_OK - function succeeded
142 | PEI_ERROR - function failed
143 +-----------------------------------------------------------------------------*/
144 static short pei_primitive (void * ptr)
145 {
146 T_PRIM *prim = (T_PRIM*)ptr;
147
148 TRACE_FUNCTION ("pei_primitive");
149
150 if (prim NEQ NULL)
151 {
152 unsigned long opc = prim->custom.opc;
153 unsigned short n;
154 const T_FUNC *table;
155
156 PTRACE_IN (opc);
157
158 switch (SAP_NR(opc))
159 {
160 case SAP_NR(TCPIP_UL):
161 table = tcpip_table;
162 n = TAB_SIZE (tcpip_table);
163 break;
164 case SAP_NR(DTI2_UL): /* defined in prim.h */
165 table = dti_ul_table;
166 n = TAB_SIZE (dti_ul_table);
167 opc -= PRIM_OFFSET_DTI2 ; /* Don't ask. */
168 break;
169 case SAP_NR(DTI2_DL): /* defined in prim.h */
170 table = dti_dl_table;
171 n = TAB_SIZE (dti_dl_table);
172 opc -= PRIM_OFFSET_DTI2 ; /* Don't ask here either. */
173 break;
174 default:
175 table = NULL;
176 n = 0;
177 break;
178 }
179
180 if (table NEQ NULL)
181 {
182 if (PRIM_NR(opc) < n)
183 {
184 table += PRIM_NR(opc) ;
185 #ifdef PALLOC_TRANSITION
186 P_SDU(prim) = table->soff ? (T_sdu*) (((char*)&prim->data) + table->soff) : 0;
187 #ifndef NO_COPY_ROUTING
188 P_LEN(prim) = table->size + sizeof (T_PRIM_HEADER);
189 #endif /* NO_COPY_ROUTING */
190 #endif /* PALLOC_TRANSITION */
191 JUMP (table->func) (P2D(prim));
192 }
193 else
194 {
195 primitive_not_supported (P2D(prim));
196 }
197 return PEI_OK;
198 }
199
200 /*
201 * primitive is not a GSM primitive - forward it to the environment
202 */
203 if (opc & SYS_MASK)
204 vsi_c_primitive (VSI_CALLER prim);
205 else
206 {
207 PFREE (P2D(prim));
208 return PEI_ERROR;
209 }
210 }
211 return PEI_OK;
212 }
213
214 /*
215 +------------------------------------------------------------------------------
216 | Function : pei_init
217 +------------------------------------------------------------------------------
218 | Description : Initialize Protocol Stack Entity
219 |
220 | Parameters : handle - task handle
221 |
222 | Return : PEI_OK - entity initialised
223 | PEI_ERROR - entity not (yet) initialised
224 +------------------------------------------------------------------------------
225 */
226 static short pei_init (T_HANDLE handle)
227 {
228 TRACE_FUNCTION ("pei_init");
229
230 /* Initialize entity handle */
231 tcpip_handle = handle;
232
233 /*
234 * Open communication channels
235 */
236 if (hCommMMI < VSI_OK)
237 {
238 if ((hCommMMI = vsi_c_open (tcpip_handle, ACI_NAME)) < VSI_OK)
239 {
240 return PEI_ERROR;
241 }
242 }
243
244 if (hCommTCPIP < VSI_OK)
245 {
246 if ((hCommTCPIP = vsi_c_open (tcpip_handle, TCPIP_NAME)) < VSI_OK)
247 {
248 return PEI_ERROR;
249 }
250 }
251
252 /*
253 * Initialize global pointer tcpip_data. This is required to access all
254 * entity data.
255 */
256 tcpip_data = &tcpip_data_base;
257
258 tcpip_data->dti_handle = dti_init(TCPIP_MAX_DTI_LINKS, tcpip_handle,
259 DTI_DEFAULT_OPTIONS, tcpip_dti_callback) ;
260 return (PEI_OK);
261 }
262
263 /*
264 +------------------------------------------------------------------------------
265 | Function : pei_timeout
266 +------------------------------------------------------------------------------
267 | Description : Process timeout.
268 |
269 | Parameters : index - timer index
270 |
271 | Return : PEI_OK - timeout processed
272 | PEI_ERROR - timeout not processed
273 +------------------------------------------------------------------------------
274 */
275 static short pei_timeout (unsigned short index)
276 {
277 /* TRACE_FUNCTION ("pei_timeout"); */
278
279 /* Process timeout */
280 switch (index)
281 {
282 case RNET_RT_NGIP_TIMER:
283 /* Call of timeout routine */
284 rnet_rt_handle_timer(NULL) ;
285 break;
286 default:
287 TRACE_ERROR("Unknown Timeout");
288 return PEI_ERROR;
289 }
290
291 return PEI_OK;
292 }
293
294
295 /*
296 +------------------------------------------------------------------------------
297 | Function : pei_exit
298 +------------------------------------------------------------------------------
299 | Description : Close Resources and terminate.
300 |
301 | Parameters : -
302 |
303 | Return : PEI_OK - exit sucessful
304 +------------------------------------------------------------------------------
305 */
306 static short pei_exit (void)
307 {
308 TRACE_FUNCTION ("pei_exit");
309
310 tcpip_do_shutdown() ;
311 if (tcpip_data->dti_handle NEQ NULL)
312 {
313 dti_deinit(tcpip_data->dti_handle) ;
314 tcpip_data->dti_handle = NULL ;
315 }
316
317 /* Close communication channels */
318 vsi_c_close (tcpip_handle,hCommMMI);
319 hCommMMI = VSI_ERROR;
320 vsi_c_close (tcpip_handle,hCommTCPIP);
321 hCommTCPIP = VSI_ERROR;
322
323
324 return PEI_OK;
325 }
326
327 /*
328 +------------------------------------------------------------------------------
329 | Function : pei_config
330 +------------------------------------------------------------------------------
331 | Description : Dynamic Configuration.
332 |
333 | Parameters : in_string - configuration string
334 |
335 | Return : PEI_OK - sucessful
336 | PEI_ERROR - not successful
337 +------------------------------------------------------------------------------
338 */
339
340
341 static short pei_config (char *in_string)
342 {
343 TRACE_FUNCTION ("pei_config");
344 TRACE_FUNCTION (in_string);
345
346 if (!strcmp (in_string, "TCPIP_INITIALIZE_REQ") )
347 {
348 tcpip_initialize_req(NULL) ;
349 }
350 else if (!strcmp (in_string, "TCPIP_SHUTDOWN_REQ") )
351 {
352 tcpip_shutdown_req(NULL) ;
353 }
354 else if (!strcmp (in_string, "TCPIP_CREATE_REQ") )
355 {
356 T_RV_RETURN_PATH return_path = { 0, 0 } ;
357 rnet_new(RNET_IPPROTO_TCP, &desc, return_path);
358 }
359 else if (!strcmp (in_string, "TCPIP_BIND_REQ") )
360 {
361 rnet_bind(desc, RNET_IP_ADDR_ANY, 32000);
362 }
363 else if (!strcmp (in_string, "TCPIP_CONNECT_REQ") )
364 {
365 rnet_connect(desc, RNET_IP_ADDR_ANY, 32000);
366 }
367 else if (!strcmp (in_string, "TCPIP_LISTEN_REQ") )
368 {
369 rnet_listen(desc);
370 }
371 else if (!strcmp (in_string, "TCPIP_CLOSE_REQ") )
372 {
373 rnet_close(desc);
374 }
375 else if (!strncmp(in_string, "dns ", 4))
376 {
377 U8 *addrbyte ;
378 int o1, o2, o3, o4 ;
379
380 if (sscanf(in_string + 4, "%d.%d.%d.%d", &o1, &o2, &o3, &o4) != 4)
381 {
382 TRACE_EVENT("cannot parse argument as an IP address") ;
383 return PEI_OK ;
384 }
385 addrbyte = (U8 *) &tcpip_data->config_dns_address ;
386 addrbyte[0] = (U8) o1 ;
387 addrbyte[1] = (U8) o2 ;
388 addrbyte[2] = (U8) o3 ;
389 addrbyte[3] = (U8) o4 ;
390 TRACE_EVENT("DNS address saved") ;
391 }
392 /*
393 * further dynamic configuration
394 */
395 return PEI_OK;
396 }
397
398
399 /*==== PUBLIC FUNCTIONS =====================================================*/
400
401 /*
402 +------------------------------------------------------------------------------
403 | Function : pei_create
404 +------------------------------------------------------------------------------
405 | Description : Create the Protocol Stack Entity.
406 |
407 | Parameters : info - Pointer to the structure of entity parameters
408 |
409 | Return : PEI_OK - entity created successfully
410 |
411 +------------------------------------------------------------------------------
412 */
413 short tcpip_pei_create (T_PEI_INFO **info)
414 {
415 static T_PEI_INFO pei_info =
416 {
417 "TCP", /* name */
418 { /* pei-table */
419 pei_init,
420 pei_exit,
421 pei_primitive,
422 pei_timeout,
423 NULL, /* pei_signal */
424 NULL, /* pei_run */
425 pei_config,
426 NULL /* pei_monitor */
427 },
428 TCPIP_STACK_SIZE, /* stack size */
429 TCPIP_QUEUE_SIZE, /* queue entries */
430 TCPIP_PRIORITY, /* priority (1->low, 255->high) */
431 TCPIP_NUM_TIMER, /* number of timers */
432 COPY_BY_REF|PASSIVE_BODY /* flags: bit 0 active(0) body/passive(1) */
433 }; /* bit 1 com by copy(0)/reference(1) */
434
435 TRACE_FUNCTION ("pei_create()");
436
437 /* Close Resources if open */
438 if (first_access) {
439 first_access = FALSE;
440 }
441 else {
442 pei_exit ();
443 }
444
445 /* Export startup configuration data */
446 *info = &pei_info;
447
448 return PEI_OK;
449 }
450
451 /*==== END OF FILE ==========================================================*/
452