comparison src/g23m-aci/aci/psa_tcpipf.c @ 162:53929b40109c

src/g23m-aci: initial import from TCS3.2/LoCosto
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 11 Oct 2016 02:02:43 +0000
parents
children
comparison
equal deleted inserted replaced
161:4557e2a9c18e 162:53929b40109c
1 /*
2 +-----------------------------------------------------------------------------
3 | Project : WAPoverGPRS
4 | Modul : PSA_TCPIPF
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 : Functions for interfacing to TCP/IP-related entities. At
18 | the moment, these are IP(v4) and UDP. In the future, TCP and IPv6
19 | and perhaps others will follow, so we try to be as general as
20 | possible.
21 |
22 | Main exports:
23 | psaTCPIP_Activate()
24 | psaTCPIP_Configure()
25 | psaTCPIP_Deactivate()
26 |
27 | Declarations and definitions are in psa_tcpip.h.
28 +-----------------------------------------------------------------------------
29 */
30 #if defined (CO_UDP_IP) || defined (FF_GPF_TCPIP)
31
32 #ifndef PSA_TCPIPF_C
33 #define PSA_TCPIPF_C
34 #endif /* !PSA_TCPIPF_C */
35
36 #include "aci_all.h"
37 /*==== INCLUDES ===================================================*/
38 #include "dti.h" /* functionality of the dti library */
39 #include "dti_conn_mng.h"
40 #include "aci_cmh.h"
41 #include "ati_cmd.h"
42 #include "aci_cmd.h"
43 #include "aci_fd.h"
44 #include "psa.h"
45 #include "psa_tcpip.h"
46 #include "psa_cc.h"
47 #include "cmh.h"
48 #include "psa_ra.h"
49 #include "cmh_ra.h"
50 #include "cmh_l2r.h"
51
52 #include "ksd_utl.h"
53
54 #if defined (FF_SAT_E)
55 #include "cmh_cc.h"
56 #include "psa_sat.h"
57 #endif /* SAT E */
58
59 #ifdef FF_GPF_TCPIP
60 #include "dcm_utils.h"
61 #include "dcm_state.h"
62 #include "dcm_env.h"
63 #endif
64 #include "dcm_f.h"
65
66
67
68 /*==== CONSTANTS ==================================================*/
69
70 /*==== TYPES ======================================================*/
71
72
73 /*==== EXPORT =====================================================*/
74 GLOBAL void psaTCPIP_Initialize_Req(void);
75 GLOBAL void psaTCPIP_Shutdown_Req(void);
76 GLOBAL void psaTCPIP_Config (ULONG ipaddr, ULONG dns1, ULONG dns2, UBYTE dirc);
77 GLOBAL ULONG bytes2ipv4addr(UBYTE *host);
78
79 /*==== VARIABLES ==================================================*/
80
81 /*==== FUNCTIONS ==================================================*/
82
83 /* Convert an IP address in an array of 4 bytes (network order
84 * assumed) into an unsigned long value representing the same IP
85 * address, also in network order. This is purely a matter of
86 * alignment, so a simple copy will do.
87 */
88 ULONG psaTCPIP_bytes2ipv4addr(UBYTE *ip_address)
89 {
90 ULONG result;
91 UBYTE i;
92 BYTE buf[4];
93
94 for (i=0; i<4; i++)
95 {
96 utl_string2Byte ((CHAR*)(ip_address+(i*4)), 3, &buf[3-i]);
97 }
98 memcpy(&result, buf, 4);
99 return result;
100 }
101
102 GLOBAL char* wap_state_to_string(T_ACI_WAP_STATES wap_state)
103 {
104 switch(wap_state)
105 {
106 case Wap_Not_Init: return "wap-not_init";
107 #ifdef FF_GPF_TCPIP
108 case TCPIP_Initialization: return "TCPIP_Initialization";
109 case TCPIP_Initialized: return "TCPIP_Initialized";
110 case TCPIP_Activation: return "TCPIP_Activation";
111 case TCPIP_Activated: return "TCPIP_Activated";
112 #endif /*FF_GPF_TCPIP*/
113 case UDPA_Activation: return "UDPA_Activation";
114 case UDPA_Activated: return "UDPA_Activated";
115 case IPA_Activation: return "IPA_Activation";
116 case IPA_Activated: return "IPA_Activated";
117 case IPA_Configuration: return "IPA_Configuration";
118 case IPA_Configurated: return "IPA_Configurated";
119 case UDPA_Configuration: return "UDPA_Configuration";
120 case UDPA_Configurated: return "UDPA_Configurated";
121 #ifdef FF_GPF_TCPIP
122 case TCPIP_Configuration: return "TCPIP_Configuration";
123 case TCPIP_Configurated: return "TCPIP_Configurated";
124 #endif /*FF_GPF_TCPIP*/
125 case IPA_Deconfiguration: return "IPA_Deconfiguration";
126 case IPA_Deconfigurated: return "IPA_Deconfigurated";
127 case UDPA_Deconfiguration: return "UDPA_Deconfiguration";
128 case UPDA_Deconfigurated: return "UPDA_Deconfigurated";
129 #ifdef FF_GPF_TCPIP
130 case TCPIP_Deconfiguration: return "TCPIP_Deconfiguration";
131 case TCPIP_Deconfigurated: return "TCPIP_Deconfigurated";
132 case TCPIP_Deactivation: return "TCPIP_Deactivation";
133 case TCPIP_Deactivated: return "TCPIP_Deactivated";
134 #endif /*FF_GPF_TCPIP*/
135 case UDPA_Deactivation: return "UDPA_Deactivation";
136 case UDPA_Deactivated: return "UDPA_Deactivated";
137 case IPA_Deactivation: return "IPA_Deactivation";
138 case IPA_Deactivated: return "IPA_Deactivated";
139 default: return "<Unknown wap_state>";
140 }
141 }
142
143
144 /*
145 +-------------------------------------------------------------------+
146 | PROJECT : WAPoverGPRS MODULE : PSA_TCPIP |
147 | ROUTINE : psaTCPIP_Init |
148 +-------------------------------------------------------------------+
149
150 PURPOSE : Initialize the protocol stack adapter for TCP/IP.
151
152 */
153 GLOBAL void psaTCPIP_Init(void)
154 {
155 memset (&tcpipShrdPrm, 0, sizeof (T_TCPIP_SHRD_PRM));
156 wap_state = Wap_Not_Init ; /* This is redundant at the moment,
157 * but will be set only here
158 * eventually. */
159 tcpipShrdPrm.connection_type = TCPIP_CONNECTION_TYPE_UNKNOWN;
160 tcpipShrdPrm.connection_buildup = TCPIP_CONNECTION_BUILDUP_UNKNOWN;
161 }
162
163
164 /* Activate TCP/IP-related entities. See psa_tcpip.h for a detailed
165 * description.
166 */
167 void psaTCPIP_Activate(UBYTE src_id,
168 UBYTE dti_id,
169 SHORT wap_call_id,
170 UBYTE options,
171 UBYTE connection_type,
172 void (*callback_function)(T_ACI_RETURN result))
173 {
174 /* The `options' parameter is not yet used, since we have only UDP
175 * and IPv4. This will change in the future, including related
176 * changes to other parts of the ACI. (At the moment the completion
177 * of UDP activation calls IP activation directly, but this will
178 * have to be torn apart. [ni 2001-10-02]
179 */
180
181 TRACE_FUNCTION ("psaTCPIP_Activate()") ;
182
183 tcpipShrdPrm.src_id = src_id ;
184 tcpipShrdPrm.connection_type = connection_type;
185 tcpipShrdPrm.connection_buildup = TCPIP_CONNECTION_BUILDUP_UP;
186 tcpipShrdPrm.wap_call_id = wap_call_id ;
187 tcpipShrdPrm.options = options ;
188 tcpipShrdPrm.callback_function = callback_function ;
189
190 if(is_gpf_tcpip_call()) {
191 GPF_TCPIP_STATEMENT(wap_state = TCPIP_Initialization);
192 psaTCPIP_config_dispatch();
193 }
194 else {
195 wap_state = Wap_Not_Init ;
196 psaUDPIP_config_dispatch();
197 }
198 }
199
200
201 /* Configure TCP/IP-related entities.
202 */
203 void psaTCPIP_Configure(UBYTE *ip_address,
204 void *pdp_addrp,
205 UBYTE *peer_address,
206 UBYTE *dns1,
207 UBYTE *dns2,
208 short mtu,
209 void (*callback_function)(T_ACI_RETURN result))
210 {
211 TRACE_FUNCTION("psaTCPIP_Configure()") ;
212
213 if (ip_address AND pdp_addrp) {
214 TRACE_ERROR("psaTCPIP_Configure(): both ip_address and pdp_addrp non-null!") ;
215 return ;
216 }
217
218 if (!ip_address AND !pdp_addrp) {
219 TRACE_ERROR("psaTCPIP_Configure(): both ip_address and pdp_addrp null!") ;
220 return ;
221 }
222
223 if (ip_address) /* From PPP, IP over CSD. */
224 {
225 memcpy(tcpipShrdPrm.ipaddr, ip_address, 16) ;
226 }
227 #ifdef GPRS
228 else if (pdp_addrp) /* From SNDCP, IP over GPRS. */
229 {
230 memcpy(tcpipShrdPrm.ipaddr, pdp_addrp, 16/*sizeof(tcpipShrdPrm.ipaddr)*/);
231 }
232 #endif
233
234 if (peer_address) {
235 memcpy(tcpipShrdPrm.peer_addr, peer_address, 16) ;
236 }
237 if(dns1) {
238 memcpy(tcpipShrdPrm.dns1,dns1,16);
239 }
240
241 if(dns2) {
242 memcpy(tcpipShrdPrm.dns2,dns2,16);
243 }
244 tcpipShrdPrm.mtu = mtu ;
245 tcpipShrdPrm.callback_function = callback_function ;
246
247 if(is_gpf_tcpip_call()) {
248 GPF_TCPIP_STATEMENT(wap_state = TCPIP_Configuration);
249 psaTCPIP_config_dispatch();
250 }
251 else {
252 wap_state = IPA_Configuration ;
253 psaUDPIP_config_dispatch();
254 }
255 }
256
257
258 /* Deactivate TCP/IP-related entities.
259 */
260 void psaTCPIP_Deactivate(void (*callback_function)(T_ACI_RETURN result))
261 {
262 TRACE_FUNCTION("psaTCPIP_Deactivate()") ;
263 TRACE_EVENT_P1("wap_state: %d", wap_state) ;
264
265 tcpipShrdPrm.connection_buildup = TCPIP_CONNECTION_BUILDUP_DOWN;
266 tcpipShrdPrm.callback_function = callback_function ;
267
268 if(is_gpf_tcpip_call()) {
269 #ifdef FF_GPF_TCPIP
270 if ( wap_state EQ TCPIP_Configurated ) {
271 wap_state = TCPIP_Deconfiguration ;
272 }
273 #endif
274 psaTCPIP_config_dispatch() ;
275 }
276 else {
277 if ( wap_state EQ UDPA_Configurated ) {
278 wap_state = IPA_Deconfiguration ;
279 }
280 psaUDPIP_config_dispatch();
281 }
282 }
283
284
285 /********************** Dispatcher functions **********************/
286
287 /* State machine for UDP/TCP/IP activation, configuration, and
288 * deactivation. At the moment some of this is still handled elsewhere
289 * in the ACI (see comments to psaTCPIP_Configure() and
290 * psaTCPIP_Activate() above), but I plan to tear this apart and keep
291 * all control over these activities in this place, including status
292 * checks and transitions. [ni 2001-10-02]
293 */
294
295 void psaUDPIP_config_dispatch(void)
296 {
297 #ifdef CO_UDP_IP // to avoid linker errors in simulation
298
299 TRACE_FUNCTION("psaUDPIP_config_dispatch()") ;
300 TRACE_EVENT_P1("wap_state: %s", wap_state_to_string(wap_state)) ;
301 switch (wap_state)
302 {
303 /* Entry point for activation. */
304 case Wap_Not_Init:
305 cmhUDPA_Activate((T_ACI_CMD_SRC)tcpipShrdPrm.src_id, tcpipShrdPrm.wap_call_id) ;
306 break ;
307 case UDPA_Activation: /* Unused at the moment; handled elsewhere. */
308 break ;
309 case UDPA_Activated: /* Unused at the moment; handled elsewhere. */
310 break ;
311 case IPA_Activation: /* Unused at the moment; handled elsewhere. */
312 break ;
313 case IPA_Activated:
314 switch (tcpipShrdPrm.connection_buildup)
315 {
316 case TCPIP_CONNECTION_BUILDUP_UP:
317 if (tcpipShrdPrm.callback_function)
318 {
319 tcpipShrdPrm.callback_function(AT_CMPL) ;
320 }
321 break ;
322 case TCPIP_CONNECTION_BUILDUP_DOWN:
323 cmhUDPA_Deactivate(tcpipShrdPrm.src_id);
324 break;
325 default:
326 TRACE_ERROR("Unknown build up state in psaTCPIP_config_dispatch()");
327 return;
328 }
329 break;
330 /* Entry point for configuration. */
331 case IPA_Configuration:
332 switch (tcpipShrdPrm.connection_buildup)
333 {
334 case TCPIP_CONNECTION_BUILDUP_UP:
335 psaIPA_Config(psaTCPIP_bytes2ipv4addr(tcpipShrdPrm.ipaddr),
336 tcpipShrdPrm.mtu, IPA_CONN) ;
337 break;
338 case TCPIP_CONNECTION_BUILDUP_DOWN:
339 psaIPA_Config(psaTCPIP_bytes2ipv4addr(tcpipShrdPrm.ipaddr),
340 tcpipShrdPrm.mtu, IPA_DSC) ;
341 break;
342 default:
343 TRACE_ERROR("Unknown build up state in psaTCPIP_config_dispatch()");
344 return;
345 }
346 break;
347 case IPA_Configurated: /* Unused at the moment; handled elsewhere. */
348 break ;
349 case UDPA_Configuration: /* Unused at the moment; handled elsewhere. */
350 break ;
351 case UDPA_Configurated:
352 if (tcpipShrdPrm.callback_function)
353 {
354 tcpipShrdPrm.callback_function(AT_CMPL) ;
355 }
356 break ;
357
358 /* Entry point for deactivation. */
359 case IPA_Deconfiguration:
360 psaIPA_Config(0, 0, IPA_DSC) ;
361 break ;
362 case IPA_Deconfigurated: /* Unused at the moment; handled elsewhere. */
363 break ;
364 case UDPA_Deactivation: /* Unused at the moment; handled elsewhere. */
365 #if defined (FF_SAT_E)
366 /* If transport layer is UDP, reset wap_call flag
367 UDP is not busy anymore */
368 if( satShrdPrm.chnTb.chnTPL EQ UDP )
369 {
370 sAT_PercentWAP ( CMD_SRC_NONE, 0 );
371 }
372 #endif /* SAT E */
373 break ;
374 case UDPA_Deactivated: /* Unused at the moment; handled elsewhere. */
375 break ;
376 case IPA_Deactivation:
377 wap_state = IPA_Deactivated ;
378 tcpipShrdPrm.connection_type = TCPIP_CONNECTION_TYPE_UNKNOWN;
379
380 if (tcpipShrdPrm.callback_function)
381 {
382 tcpipShrdPrm.callback_function(AT_CMPL) ;
383 }
384 /*lint -fallthrough*/
385 case IPA_Deactivated:
386 wap_state = Wap_Not_Init ;
387
388 if(ccShrdPrm.wapStat EQ CC_WAP_STACK_DOWN)
389 {
390 /* WAP-dedicated variables shall be reinitialized */
391 wapId = NO_ENTRY;
392 Wap_Call = FALSE;
393
394 TRACE_EVENT ("WAP parameter reseted");
395 }
396 break ;
397
398 default:
399 TRACE_ERROR("Unknown wap state in psaTCPIP_config_dispatch()") ;
400 }
401 #else
402 ACI_ASSERT(FALSE);
403 #endif
404 }
405
406
407 /******************************************************************************/
408 void psaTCPIP_config_dispatch(void)
409 {
410 #ifdef FF_GPF_TCPIP // to avoid linker errors in simulation
411
412 TRACE_FUNCTION("psaTCPIP_config_dispatch()") ;
413 TRACE_EVENT_P1("wap_state: %s", wap_state_to_string(wap_state)) ;
414 switch (wap_state)
415 {
416 case TCPIP_Initialization :
417 switch(tcpipShrdPrm.connection_buildup)
418 {
419 case TCPIP_CONNECTION_BUILDUP_UP:
420 psaTCPIP_Initialize_Req();
421 break;
422
423 case TCPIP_CONNECTION_BUILDUP_DOWN:
424 psaTCPIP_Shutdown_Req();
425 break;
426
427 default:
428 TRACE_ERROR("Error: Unknown build_up state in psaTCPIP_config_dispatch()");
429 return;
430 }
431
432 case TCPIP_Initialized :
433 break;
434
435 case TCPIP_Activation :
436 switch(tcpipShrdPrm.connection_buildup)
437 {
438 case TCPIP_CONNECTION_BUILDUP_UP:
439 if(tcpipShrdPrm.callback_function)
440 {
441 tcpipShrdPrm.callback_function(AT_CMPL);
442 }
443 break ;
444
445 case TCPIP_CONNECTION_BUILDUP_DOWN:
446 wap_state = TCPIP_Deactivation;
447 psaTCPIP_Shutdown_Req();
448 break;
449
450 default:
451 TRACE_ERROR("Error: Unknown build up state in psaTCPIP_config_dispatch()");
452 return;
453 }
454 break;
455
456 case TCPIP_Configuration:
457 switch(tcpipShrdPrm.connection_buildup)
458 {
459 case TCPIP_CONNECTION_BUILDUP_UP:
460 psaTCPIP_Config(bytes2ipv4addr(tcpipShrdPrm.ipaddr),
461 bytes2ipv4addr(tcpipShrdPrm.dns1),
462 bytes2ipv4addr(tcpipShrdPrm.dns2),
463 TCPIP_IFCONFIG_UP);
464 break;
465 case TCPIP_CONNECTION_BUILDUP_DOWN:
466 psaTCPIP_Config(0,0,0,TCPIP_IFCONFIG_DOWN);
467 break;
468
469 default:
470 TRACE_ERROR("Error: Unknown build up state in psaTCPIP_config_dispatch()");
471 return;
472 }
473 break;
474
475 case TCPIP_Configurated:
476 if(tcpipShrdPrm.callback_function)
477 {
478 tcpipShrdPrm.callback_function(AT_CMPL) ;
479 }
480 break;
481
482 case TCPIP_Deconfiguration :
483 psaTCPIP_Config(0,0,0,TCPIP_IFCONFIG_DOWN);
484 break;
485
486 case TCPIP_Deconfigurated :
487 break;
488
489 case TCPIP_Deactivation :
490 psaTCPIP_Shutdown_Req();
491 break;
492
493 case TCPIP_Deactivated:
494 tcpipShrdPrm.connection_type = TCPIP_CONNECTION_TYPE_UNKNOWN;
495 if(tcpipShrdPrm.callback_function)
496 {
497 tcpipShrdPrm.callback_function(AT_CMPL) ;
498 }
499 wap_state = Wap_Not_Init ;
500 break ;
501
502 default:
503 TRACE_ERROR("Error: Unknown wap_state in psaTCPIP_config_dispatch()") ;
504 }
505 #else
506 ACI_ASSERT(FALSE);
507 #endif
508 }
509
510
511 /********************** Callbacks, several ***********************/
512
513 /* TCP/IP activation callback for circuit-switched data, to be called
514 * when activation is completed.
515 */
516 void psaTCPIP_act_csd_callback(T_ACI_RETURN result)
517 {
518 TRACE_FUNCTION("psaTCPIP_act_csd_callback()");
519
520 if (!psaCC_ctbIsValid (tcpipShrdPrm.wap_call_id))
521 {
522 /* Avoid to dereference NULL */
523 TRACE_ERROR ("Call table entry disappeared");
524 return;
525 }
526
527 /*
528 * activate RA connection: in case of failure clear call !
529 */
530 ccShrdPrm.datStat = DS_ACT_REQ;
531
532 if(cmhRA_Activate((T_ACI_CMD_SRC)psaCC_ctb(tcpipShrdPrm.wap_call_id)->curSrc,
533 (T_ACI_AT_CMD)psaCC_ctb(tcpipShrdPrm.wap_call_id)->curCmd,
534 tcpipShrdPrm.wap_call_id)
535 NEQ AT_EXCT)
536 {
537 TRACE_EVENT("RA ACTIVATION FAILURE -> DISC CALL");
538 ccShrdPrm.datStat = DS_IDL ;
539 psaCC_ctb(tcpipShrdPrm.wap_call_id)->nrmCs = MNCC_CAUSE_CALL_CLEAR ;
540 psaCC_ClearCall (tcpipShrdPrm.wap_call_id);
541 }
542 }
543
544
545 /* TCP/IP configuration callback for circuit-switched data, to be called
546 * when configuration is completed.
547 */
548 void psaTCPIP_conf_csd_callback(T_ACI_RETURN result)
549 {
550 TRACE_FUNCTION("psaTCPIP_conf_csd_callback()") ;
551
552 R_AT ( RAT_CONNECT, (T_ACI_CMD_SRC)tcpipShrdPrm.src_id )
553 ( AT_CMD_NONE, -1, tcpipShrdPrm.wap_call_id, FALSE );
554 if(is_gpf_tcpip_call()) {
555 #ifdef FF_GPF_TCPIP
556 T_DCM_STATUS_IND_MSG msg;
557 msg.hdr.msg_id = DCM_NEXT_CMD_READY_MSG;
558 dcm_send_message(msg, DCM_SUB_WAIT_SATDN_CNF);
559 #endif // #ifdef FF_GPF_TCPIP
560 }
561 }
562
563
564 /* TCP/IP deactivation callback for circuit-switched data, to be called
565 * when deactivation is completed.
566 */
567 void psaTCPIP_deact_csd_callback(T_ACI_RETURN result)
568 {
569 TRACE_FUNCTION("psaTCPIP_deact_csd_callback()") ;
570
571 /*
572 * deactivate L2R connection:
573 */
574 if (cmhL2R_Deactivate() NEQ AT_EXCT)
575 {
576 TRACE_EVENT("L2R DEACTIVATION FAILURE ");
577 if (psaCC_ctbIsValid (tcpipShrdPrm.wap_call_id)) /* To be sure */
578 psaCC_ctb(tcpipShrdPrm.wap_call_id)->nrmCs = MNCC_CAUSE_CALL_CLEAR;
579 psaCC_ClearCall (tcpipShrdPrm.wap_call_id); /* Changed in OMAPS00049111 */
580 }
581
582 if(is_gpf_tcpip_call())
583 {
584 #ifdef FF_GPF_TCPIP
585 {
586 T_DCM_STATUS_IND_MSG msg;
587 msg.hdr.msg_id = DCM_NEXT_CMD_READY_MSG;
588 dcm_send_message(msg, DCM_SUB_WAIT_SATH_CNF);
589 }
590 #endif /* #ifdef FF_GPF_TCPIP */
591 }
592 }
593
594 #endif /*defined(FF_WAP) OR defined(FF_GPF_TCPIP) */
595
596 /* EOF */
597