comparison src/g23m-fad/tcpip/rnet/rnet_rt/rnet_rt_env.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 * @file rnet_rt_env.c
3 *
4 * Coding of the Riviera RNET Generic Functions,
5 *
6 * @author Jose Yp-Tcha (j-yp-tcha@ti.com)
7 * @version 0.1
8 */
9
10 /*
11 * $Id: rnet_rt_env.c,v 1.5 2002/10/30 15:23:34 rf Exp $
12 * $Name: ti_20021030 $
13 *
14 * History:
15 *
16 * Date Author Modification
17 * -------------------------------------------------------------------
18 * 3/19/2002 Jose Yp-Tcha (j-yp-tcha@ti.com) Create.
19 * 3/29/2002 Regis Feneon NexGenIP configuration
20 * 5/6/2002 Regis Feneon ATP driver support
21 * 10/28/2002 Regis Feneon added tests for RNET_RT_ETH_SUPPORT
22 *
23 * (C) Copyright 2002 by TI, All Rights Reserved
24 */
25
26 #include "rnet_cfg.h"
27 #ifdef RNET_CFG_REAL_TRANSPORT
28
29 #ifdef _WINDOWS
30 #include "windows.h"
31 #include "rnet_rt_ngwinnet_i.h"
32 #endif
33
34 #include "rnet_rt_i.h"
35 #include "rnet_rt_env.h"
36
37 #include "rvm_priorities.h"
38 #include "rnet_trace_i.h"
39
40 #ifdef _WINDOWS
41 #define BUF_HEADER_SIZE 16
42 #else
43 #define BUF_HEADER_SIZE 0
44 #endif
45 #define BUF_DATA_SIZE 1500
46
47
48 /* Buffer for TCPIP internal memory menagement */
49 static T_RNET_RT_ENV_CTRL_BLK rnet_data_buf;
50 static unsigned char tcpip_buf[RNET_RT_BUFPOOL_SIZE];
51
52
53 /**
54 * Pointer on the structure gathering all the global variables
55 * used by RNET instance.
56 */
57 T_RNET_RT_ENV_CTRL_BLK *rnet_rt_env_ctrl_blk_p;
58
59 /* Type 4, temporary */
60 T_RVM_RETURN rnet_rt_temp_core (void);
61
62 /**
63 * Called by the RV manager to learn
64 * tut requirements in terms of memory, SWEs...
65 *
66 * @param swe_info Pointer to the structure to fill
67 * containing infos related to the tut SWE.
68 *
69 * @return RVM_OK
70 */
71 T_RVM_RETURN rnet_rt_get_info(T_RVM_INFO_SWE * swe_info)
72 {
73 RNET_RT_SEND_TRACE("RNET_RT: get_info called", RV_TRACE_LEVEL_DEBUG_LOW);
74
75 /* The SWE is a Type 4 SWE */
76 swe_info->swe_type = RVM_SWE_TYPE_4;
77
78 /* Used for info */
79 memcpy(swe_info->type_info.type4.swe_name, "RNET_RT", sizeof("RNET_RT"));
80 /*
81 * This is the real way to indentify a SWE.
82 * Look in rvm_use_id_list.h and rvm_ext_use_id_list.h.
83 */
84 swe_info->type_info.type4.swe_use_id = RNET_RT_USE_ID;
85
86 /* SWE info */
87 swe_info->type_info.type4.stack_size = RNET_RT_STACK_SIZE;
88 swe_info->type_info.type4.priority = RVM_RNET_RT_TASK_PRIORITY;
89 swe_info->type_info.type4.version = BUILD_VERSION_NUMBER(0,1,0);
90
91 /* Memory bank info */
92 swe_info->type_info.type4.nb_mem_bank = 1;
93 memcpy(swe_info->type_info.type4.mem_bank[0].bank_name,
94 "RNET_RT_PRIM", sizeof("RNET_RT_PRIM"));
95 swe_info->type_info.type4.mem_bank[0].initial_params.size =
96 RNET_RT_MB_PRIM_SIZE;
97
98
99 swe_info->type_info.type4.mem_bank[0].initial_params.watermark =
100 RNET_RT_MB_PRIM_WATERMARK;
101
102 /*
103 * Linked SWE info.
104 */
105 #ifdef RNET_RT_ATP_SUPPORT
106 /* we require ATP SWE to run */
107 swe_info->type_info.type4.linked_swe_id[0] = ATP_USE_ID;
108 swe_info->type_info.type4.nb_linked_swe = 1;
109 #else
110 swe_info->type_info.type4.nb_linked_swe = 0;
111 #endif
112
113 /* Set the return path: NOT USED. */
114 swe_info->type_info.type4.return_path.callback_func = NULL;
115 swe_info->type_info.type4.return_path.addr_id = 0;
116
117 /* Generic functions */
118 swe_info->type_info.type4.set_info = rnet_rt_set_info;
119 swe_info->type_info.type4.init = rnet_rt_init;
120 /*
121 swe_info->type_info.type3.start = rnet_rt_start;
122 swe_info->type_info.type3.handle_message = rnet_rt_handle_message;
123 swe_info->type_info.type3.handle_timer = rnet_rt_handle_timer;
124 */
125 swe_info->type_info.type4.stop = rnet_rt_stop;
126 swe_info->type_info.type4.kill = rnet_rt_kill;
127
128 /* Type 4 specific generic functions */
129 swe_info->type_info.type4.core = rnet_rt_temp_core;
130 /* End of specific generic functions */
131
132 return RVM_OK;
133 }
134
135 /**
136 * Called by the RV manager to inform the tut SWE about
137 * addr_id, return path, mb_id and error function.
138 *
139 * It is called only once.
140 *
141 * @param addr_id Address ID of the TUT SWE.
142 * Used to send messages to the SWE.
143 * @param return_path Return path array of the linked SWEs.
144 * @param bk_id_table Array of memory bank ids allocated to the SWE.
145 * @param call_back_error_ft Callback function to call in case of unrecoverable error.
146 * @return RVM_MEMORY_ERR ou RVM_OK.
147 */
148 T_RVM_RETURN rnet_rt_set_info ( T_RVF_ADDR_ID addr_id,
149 T_RV_RETURN_PATH return_path[],
150 T_RVF_MB_ID bk_id_table[],
151 T_RVM_CB_FUNC call_back_error_ft)
152 {
153 /* Memory bank status (red, yellow, green). */
154
155 RNET_RT_SEND_TRACE("RNET_RT: set_info called", RV_TRACE_LEVEL_DEBUG_LOW);
156
157 /* Create instance gathering all the variable used by TUT instance */
158 rnet_rt_env_ctrl_blk_p = &rnet_data_buf;
159
160 /* Store the address ID. */
161 rnet_rt_env_ctrl_blk_p->addr_id = addr_id;
162
163 /* Store the pointer to the error function. */
164 rnet_rt_env_ctrl_blk_p->error_ft = call_back_error_ft;
165
166 /*
167 * Store the mem bank id.
168 * Memory bank ID (mb_id) can be retrieved later using rvf_get_mb_id function.
169 */
170 rnet_rt_env_ctrl_blk_p->mb_id = bk_id_table[0];
171
172 return RVM_OK;
173 }
174
175 /**
176 * Called by the RV manager to initialize the
177 * RNET SWE before creating the task and calling tut_start.
178 *
179 * @return RVM_OK
180 */
181
182 #define CFGMAX 40
183 #define CFG( opt, arg) { cfg[i].cfg_option = (opt); cfg[i++].cfg_arg = (arg); }
184
185 T_RVM_RETURN rnet_rt_init( void)
186 {
187 int i, init_err;
188 NGcfgent cfg[CFGMAX];
189 #ifdef _WINDOWS
190 /* windows specific settings */
191 NGuint ipaddr, ipnetmask, ipgateway, ipdns1, ipdns2;
192 char *winpcapdev, *domain;
193 static char tmpbuf[128], tmpbuf2[128];
194 #endif
195
196 RNET_RT_SEND_TRACE("RNET_RT: init called", RV_TRACE_LEVEL_DEBUG_LOW);
197
198 /*
199 * NexGenIP initialisation
200 */
201
202 #ifdef _WINDOWS
203 /* get windows settings */
204 if( (GetEnvironmentVariable( "RNET_RT_WIN32_IPADDR", tmpbuf, sizeof( tmpbuf)) == 0) ||
205 (ngInetATON( tmpbuf, &ipaddr) != NG_EOK)) {
206 ipaddr = 0;
207 }
208 if( (GetEnvironmentVariable( "RNET_RT_WIN32_IPNETMASK", tmpbuf, sizeof( tmpbuf)) == 0) ||
209 (ngInetATON( tmpbuf, &ipnetmask) != NG_EOK)) {
210 ipnetmask = 0;
211 }
212 if( (GetEnvironmentVariable( "RNET_RT_WIN32_IPGATEWAY", tmpbuf, sizeof( tmpbuf)) == 0) ||
213 (ngInetATON( tmpbuf, &ipgateway) != NG_EOK)) {
214 ipgateway = 0;
215 }
216 if( (GetEnvironmentVariable( "RNET_RT_WIN32_IPDNS1", tmpbuf, sizeof( tmpbuf)) == 0) ||
217 (ngInetATON( tmpbuf, &ipdns1) != NG_EOK)) {
218 ipdns1 = 0;
219 }
220 if( (GetEnvironmentVariable( "RNET_RT_WIN32_IPDNS2", tmpbuf, sizeof( tmpbuf)) == 0) ||
221 (ngInetATON( tmpbuf, &ipdns1) != NG_EOK)) {
222 ipdns2 = 0;
223 }
224 if( GetEnvironmentVariable( "RNET_RT_WIN32_WINPCAPDEV", tmpbuf, sizeof( tmpbuf)) == 0) {
225 winpcapdev = NULL;
226 }
227 else {
228 winpcapdev = tmpbuf;
229 }
230 if( GetEnvironmentVariable( "RNET_RT_WIN32_DOMAIN", tmpbuf, sizeof( tmpbuf2)) == 0) {
231 domain = NULL;
232 }
233 else {
234 domain = tmpbuf2;
235 }
236 #endif
237
238 /* allocate buffer pool */
239 rnet_rt_env_ctrl_blk_p->buf_net = &tcpip_buf;
240
241 /* initialise mutex */
242 if( rvf_initialize_mutex( &rnet_rt_env_ctrl_blk_p->mutex) != RV_OK) {
243 RNET_RT_SEND_TRACE("RNET_RT: Cannot initialize mutex ",RV_TRACE_LEVEL_ERROR);
244 return RVM_INTERNAL_ERR;
245 }
246
247 /*
248 * Configuration Table
249 */
250 i = 0;
251 /* TCP */
252 CFG( NG_CFG_PROTOADD, NG_CFG_PTR( &ngProto_TCP));
253 CFG( NG_TCPO_TCB_MAX, NG_CFG_INT( RNET_RT_SOCK_MAX));
254 CFG( NG_TCPO_TCB_TABLE, NG_CFG_PTR( (/*(rnet_data *)*/ rnet_rt_env_ctrl_blk_p)->tcbtable));
255 /* UDP */
256 CFG( NG_CFG_PROTOADD, NG_CFG_PTR( &ngProto_UDP));
257 /* IP */
258 CFG( NG_CFG_PROTOADD, NG_CFG_PTR( &ngProto_IP));
259 #ifdef _WINDOWS
260 if( ipgateway != 0) {
261 CFG( NG_IPO_ROUTE_DEFAULT, NG_CFG_LNG( ipgateway));
262 }
263 #endif
264 #ifdef RNET_RT_ETH_SUPPORT
265 /* ARP */
266 CFG( NG_CFG_PROTOADD, NG_CFG_PTR( &ngProto_ARP));
267 CFG( NG_ARPO_MAX, NG_CFG_INT( RNET_RT_ARP_MAX));
268 CFG( NG_ARPO_TABLE, NG_CFG_PTR( (/*(rnet_data *)*/ rnet_rt_env_ctrl_blk_p)->arptable));
269 CFG( NG_ARPO_EXPIRE, NG_CFG_INT( 120));
270 #endif
271 /* RESOLVER */
272 CFG( NG_CFG_PROTOADD, NG_CFG_PTR( &ngProto_RESOLV));
273 CFG( NG_RSLVO_QUERY_MAX, NG_CFG_INT( RNET_RT_RESOLV_QUERY_MAX));
274 CFG( NG_RSLVO_QUERY, NG_CFG_PTR( (/*(rnet_data *)*/ rnet_rt_env_ctrl_blk_p)->resolvquery));
275 CFG( NG_RSLVO_CACHE_MAX, NG_CFG_INT( RNET_RT_RESOLV_CACHE_MAX));
276 CFG( NG_RSLVO_CACHE_ENT, NG_CFG_PTR( (/*(rnet_data *)*/ rnet_rt_env_ctrl_blk_p)->resolvcache));
277 CFG( NG_RSLVO_TO, NG_CFG_INT( RNET_RT_RESOLV_TIMEOUT));
278 #ifdef _WINDOWS
279 if( ipdns1 != 0) {
280 CFG( NG_RSLVO_SERV1_IPADDR, NG_CFG_LNG( ipdns1));
281 }
282 if( ipdns2 != 0) {
283 CFG( NG_RSLVO_SERV2_IPADDR, NG_CFG_LNG( ipdns2));
284 }
285 if( domain != NULL) {
286 CFG( NG_RSLVO_DOMAIN, NG_CFG_PTR( domain));
287 }
288 #endif
289 #ifdef RNET_RT_LOOPBACK_SUPPORT
290 /* Loopback Interface */
291 CFG( NG_CFG_IFADD, NG_CFG_PTR( &rnet_rt_env_ctrl_blk_p->ifnet_lo));
292 CFG( NG_CFG_DRIVER, NG_CFG_PTR( &ngNetDrv_LOOPBACK));
293 CFG( NG_IFO_NAME, NG_CFG_PTR( "lo0"));
294 #endif
295 #if defined(_WINDOWS) && defined(RNET_RT_ETH_SUPPORT)
296 /* Ethernet interface */
297 CFG( NG_CFG_IFADD, NG_CFG_PTR( &rnet_rt_env_ctrl_blk_p->ifnet_eth));
298 CFG( NG_CFG_DRIVER, NG_CFG_PTR( &ngNetDrv_WIN32));
299 CFG( NG_IFO_NAME, NG_CFG_PTR( "eth0"));
300 CFG( NG_IFO_OUTQ_MAX, NG_CFG_INT( 16));
301 if( ipaddr != 0) {
302 CFG( NG_IFO_ADDR, NG_CFG_LNG( ipaddr));
303 }
304 if( ipnetmask != 0) {
305 CFG( NG_IFO_NETMASK, NG_CFG_LNG( ipnetmask));
306 }
307 if( winpcapdev != NULL) {
308 CFG( NG_IFO_DEVPTR1, NG_CFG_PTR( winpcapdev));
309 }
310 #endif
311 #ifdef RNET_RT_ATP_SUPPORT
312 /* ATP point-to-point Interface */
313 CFG( NG_CFG_IFADD, NG_CFG_PTR( &rnet_rt_env_ctrl_blk_p->ifnet_atp));
314 CFG( NG_CFG_DRIVER, NG_CFG_PTR( &rnet_rt_netdrv_atp));
315 CFG( NG_IFO_NAME, NG_CFG_PTR( "ppp0"));
316 #endif
317 #ifdef RNET_RT_DTI_SUPPORT
318 /* DTI (i. e. GMS or GPRS) point-to-point Interface */
319 CFG( NG_CFG_IFADD, NG_CFG_PTR( &rnet_rt_env_ctrl_blk_p->ifnet_dti));
320 CFG( NG_CFG_DRIVER, NG_CFG_PTR( &rnet_rt_netdrv_dti));
321 CFG( NG_IFO_NAME, NG_CFG_PTR( "gsm0"));
322 #endif
323 /* end of table */
324 CFG( NG_CFG_END, 0);
325
326 /* initialise protocols and network interfaces */
327 init_err = rnet_rt_ngip_init( rnet_rt_env_ctrl_blk_p->buf_net,
328 RNET_RT_BUFPOOL_SIZE,
329 BUF_HEADER_SIZE,
330 BUF_DATA_SIZE,
331 rnet_rt_env_ctrl_blk_p->socktable,
332 RNET_RT_SOCK_MAX,
333 cfg);
334 if( init_err != NG_EOK) {
335 RNET_RT_SEND_TRACE("RNET_RT: Cannot initialize NexGenIP stack ",RV_TRACE_LEVEL_ERROR);
336 return RVM_INTERNAL_ERR;
337 }
338
339 #ifdef RNET_RT_NGIP_DEBUG_ENABLE
340 /* set debug */
341 ngDebugModOnOff[NG_DBG_IP] = 1;
342 ngDebugModOnOff[NG_DBG_UDP] = 1;
343 ngDebugModOnOff[NG_DBG_TCP] = 1;
344 ngDebugModOnOff[NG_DBG_RESOLV] = 1;
345 #endif
346
347 return RVM_OK;
348 }
349
350 /**
351 * Called by the RV manager to start the RNET SWE,
352 *
353 * @return RVM_OK.
354 */
355 T_RVM_RETURN rnet_rt_start( void)
356 {
357
358 RNET_RT_SEND_TRACE("RNET_RT: start called", RV_TRACE_LEVEL_DEBUG_LOW);
359
360 /* arm timer */
361
362 /* It looks as if the timer runs by a factor of 10 slower in the
363 * simulation than it ought to, so we speed it up again here. Target
364 * testing must reveal if there is really a difference. */
365
366 #ifdef _SIMULATION_
367 #define MILLISECONDS_PER_SECOND 100
368 #else /* _SIMULATION_ */
369 #define MILLISECONDS_PER_SECOND 1000
370 #endif
371 rvf_start_timer( RNET_RT_NGIP_TIMER,
372 RVF_MS_TO_TICKS(MILLISECONDS_PER_SECOND/NG_TIMERHZ),
373 FALSE); // TRUE --> FALSE , set once timer for OMAPS00169870 05102008 by pinghua
374
375 /* open interfaces */
376 rvf_lock_mutex( &rnet_rt_env_ctrl_blk_p->mutex);
377 rnet_rt_ngip_start();
378 rvf_unlock_mutex( &rnet_rt_env_ctrl_blk_p->mutex);
379
380 return RVM_OK;
381 }
382
383 /**
384 * Called by the RV manager to stop the RNET SWE.
385 *
386 * @return RVM_OK
387 */
388 T_RVM_RETURN rnet_rt_stop( void)
389 {
390 /* NB: Other SWEs have not been killed yet, tut can send messages to other SWEs. */
391 RNET_RT_SEND_TRACE("RNET_RT: stop called", RV_TRACE_LEVEL_DEBUG_LOW);
392
393 /* stop protocol timer */
394 rvf_stop_timer( RNET_RT_NGIP_TIMER);
395
396 /* shutdown TCP/IP stack */
397 rvf_lock_mutex( &rnet_rt_env_ctrl_blk_p->mutex);
398 rnet_rt_ngip_stop();
399 rvf_unlock_mutex( &rnet_rt_env_ctrl_blk_p->mutex);
400
401 /* release resources */
402
403 rvf_delete_mutex( &rnet_rt_env_ctrl_blk_p->mutex);
404
405 #if 0
406 rvf_free_buf( rnet_rt_env_ctrl_blk_p->buf_net);
407 rvf_free_buf( rnet_rt_env_ctrl_blk_p);
408 #endif
409
410 rnet_rt_env_ctrl_blk_p->buf_net = NULL;
411 rnet_rt_env_ctrl_blk_p = NULL;
412
413 return RVM_OK;
414 }
415
416 /**
417 * Called by the RV manager to kill the RNET SWE,
418 * after the rnet_stop function has been called.
419 *
420 * @return RVM_OK
421 */
422 T_RVM_RETURN rnet_rt_kill( void)
423 {
424 /*
425 * DO NOT SEND MESSAGES
426 */
427
428 return RVM_OK;
429 }
430
431 /* Temporary core for RNET */
432 T_RVM_RETURN rnet_rt_temp_core (void)
433 {
434 T_RVM_RETURN error_status;
435 T_RV_HDR *msg_p ;
436 UINT16 rec_event;
437
438 RNET_TRACE_HIGH("RNET_RT: core task started");
439
440 /* start RNET */
441 rnet_rt_start();
442
443 error_status = RV_OK;
444 while (error_status == RV_OK )
445 {
446 rec_event = rvf_wait(0xffff, 0); /* Wait (infinite) for all events. */
447 if (rec_event & RVF_TASK_MBOX_0_EVT_MASK)
448 {
449 msg_p = rvf_read_mbox(0);
450 error_status = rnet_rt_handle_message(msg_p);
451 }
452 if (rec_event & RVF_TIMER_1_EVT_MASK)
453 {
454 error_status = rnet_rt_handle_timer(NULL);
455 }
456 }
457 if (error_status == RV_MEMORY_ERR ) /* If a memory error happened .. */
458 {
459 (void)(rnet_rt_env_ctrl_blk_p->error_ft("RNET", RVM_MEMORY_ERR, 0,
460 " Memory Error : the RNET primitive memory bank is RED "));
461 }
462 return RVM_OK;
463 }
464
465 #endif /* ifdef RNET_CFG_REAL_TRANSPORT */
466