comparison src/g23m-fad/tcpip/tcpip_sim_utils.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_utils.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 : Utility functions for GPF-based TCP/IP
17 +-----------------------------------------------------------------------------
18 */
19
20
21 #define TCPIP_UTILS_C
22
23 #define ENTITY_TCPIP
24
25 /*==== INCLUDES =============================================================*/
26
27 #include <string.h> /* String functions, e. g. strncpy(). */
28 #include <stdio.h>
29
30 #include "typedefs.h" /* to get Condat data types */
31 #include "vsi.h" /* to get a lot of macros */
32 #include "custom.h"
33 #include "gsm.h" /* to get a lot of macros */
34 #include "prim.h" /* to get the definitions of used SAP and directions */
35 #include "pei.h" /* to get PEI interface */
36 #include "tools.h" /* to get common tools */
37 #include "dti.h" /* For DTI library definitions. */
38 #include "glob_defs.h"
39 #include "tcpip.h" /* to get the global entity definitions */
40
41 /* RNET includes
42 */
43 #include "rv_general.h"
44 #include "rnet_api.h"
45 #include "rnet_rt_env.h"
46 #include "rnet_message.h"
47 #include "rnet_rt_i.h"
48
49
50 /*==== Local prototypes =====================================================*/
51
52
53
54
55 /*==== Macros ===============================================================*/
56
57
58
59 /*==== Types ================================================================*/
60
61
62 /*==== Local data ===========================================================*/
63
64
65
66 /*==== Other public functions ===============================================*/
67
68 unsigned long tcpip_sim_fake_data(int socket, U16 len)
69 {
70 static char tmp[100000] ;
71
72 /* MALLOC(tmp, len) ; */
73 *tmp = 0 ;
74 if (len > 30)
75 {
76 sprintf(tmp, "data len 0x%0.4x for socket %-.2d\n", len, socket) ;
77 }
78 if (len > strlen(tmp))
79 {
80 memset(tmp + strlen(tmp), '0' + socket, len - strlen(tmp)) ;
81 }
82 return (unsigned long) tmp ;
83 }
84
85
86 void tcpip_dump_packet(char *title, U8 *data, U16 len)
87 {
88 static char buf[80] ;
89 int i = 0 ;
90
91 strcpy(buf, "pkt dump from ") ;
92 strcat(buf, title) ;
93 strcat(buf, "\n ") ;
94 while (len-- > 0)
95 {
96 sprintf(buf + strlen(buf), " %02x", *data++) ;
97 if (!(++i % 4))
98 {
99 if (!(i % 8))
100 {
101 TRACE_EVENT(buf) ;
102 sprintf(buf, " ") ;
103 }
104 else
105 {
106 sprintf(buf + strlen(buf), " ") ;
107 }
108 }
109 }
110 printf("%s", buf) ;
111 }
112
113 static char *inet_ntoa(U32 ipaddr)
114 {
115 static char ipaddr_string[sizeof("000.000.000.000")] ;
116 UBYTE *addrbyte_p ; /* Pointer to single address bytes. */
117
118 addrbyte_p = (UBYTE *) &ipaddr ;
119 sprintf(ipaddr_string,"%u.%u.%u.%u",
120 addrbyte_p[3], addrbyte_p[2], addrbyte_p[1], addrbyte_p[0]);
121 return ipaddr_string ;
122 }
123
124
125
126 void tcpip_if_properties(NGifnet *netp)
127 {
128 char *name ;
129 U32 value ;
130
131 ngIfGenCntl(netp, NG_CNTL_GET, NG_IFO_NAME, &name) ;
132 TRACE_EVENT_P1("Interface name %s", name) ;
133
134 ngIfGenCntl(netp, NG_CNTL_GET, NG_IFO_OUTQ_MAX, &value) ;
135 TRACE_EVENT_P1(" NG_IFO_OUTQ_MAX = %d", value) ;
136
137 ngIfGenCntl(netp, NG_CNTL_GET, NG_IFO_ADDR, &value) ;
138 TRACE_EVENT_P1(" NG_IFO_ADDR = %s", inet_ntoa(ngNTOHL(value))) ;
139
140 ngIfGenCntl(netp, NG_CNTL_GET, NG_IFO_NETMASK, &value) ;
141 TRACE_EVENT_P1(" NG_IFO_NETMASK = 0x%x", ngNTOHL(value)) ;
142
143 ngIfGenCntl(netp, NG_CNTL_GET, NG_IFO_DSTADDR, &value) ;
144 TRACE_EVENT_P1(" NG_IFO_DSTADDR = %s", inet_ntoa(ngNTOHL(value))) ;
145
146 ngIfGenCntl(netp, NG_CNTL_GET, NG_IFO_FLAGS, &value) ;
147 TRACE_EVENT_P1(" NG_IFO_FLAGS = 0x%x", value) ;
148
149 ngIfGenCntl(netp, NG_CNTL_GET, NG_IFO_DEV1, &value) ;
150 TRACE_EVENT_P1(" NG_IFO_DEV1 = 0x%x", value) ;
151
152 ngIfGenCntl(netp, NG_CNTL_GET, NG_IFO_DEV2, &value) ;
153 TRACE_EVENT_P1(" NG_IFO_DEV2 = 0x%x", value) ;
154
155 ngIfGenCntl(netp, NG_CNTL_GET, NG_IFO_DEVPTR1, &value) ;
156 TRACE_EVENT_P1(" NG_IFO_DEVPTR1 = 0x%x", value) ;
157
158 ngIfGenCntl(netp, NG_CNTL_GET, NG_IFO_DEVPTR2, &value) ;
159 TRACE_EVENT_P1(" NG_IFO_DEVPTR2 = 0x%x", value) ;
160
161 ngIfGenCntl(netp, NG_CNTL_GET, NG_IFO_PROMISC, &value) ;
162 TRACE_EVENT_P1(" NG_IFO_PROMISC = 0x%x", value) ;
163
164 ngIfGenCntl(netp, NG_CNTL_GET, NG_IFO_ALLMULTI, &value) ;
165 TRACE_EVENT_P1(" NG_IFO_ALLMULTI = 0x%x", value) ;
166
167 ngIfGenCntl(netp, NG_CNTL_GET, NG_IFO_MTU, &value) ;
168 TRACE_EVENT_P1(" NG_IFO_MTU = %d", value) ;
169 }