FreeCalypso > hg > fc-magnetite
comparison src/g23m-fad/tcpip/rnet/rnet_rt/rnet_rt_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: rnet_rt_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 : DTI-based GSM/GPRS network driver for RNET_RT (a.k.a. NexGenIP) | |
17 +----------------------------------------------------------------------------- | |
18 */ | |
19 | |
20 /* Derived from... */ | |
21 /** | |
22 * @file rnet_rt_atp.c | |
23 * | |
24 * Coding of the ATP point-to-point network interface for RNET_RT, | |
25 * | |
26 * @author Regis Feneon | |
27 * @version 0.1 | |
28 */ | |
29 | |
30 /* | |
31 * $Id: rnet_rt_atp.c,v 1.4 2002/12/05 10:02:19 rf Exp $ | |
32 * $Name: $ | |
33 * | |
34 * History: | |
35 * | |
36 * Date Author Modification | |
37 * -------------------------------------------------- | |
38 * 5/6/2002 Regis Feneon Create | |
39 * 6/9/2002 Regis Feneon Select default route | |
40 * on local interface address if no destination address | |
41 * 12/5/2002 Regis Feneon Flow control handling | |
42 * (C) Copyright 2002 by TI, All Rights Reserved | |
43 * | |
44 */ | |
45 | |
46 | |
47 #define RNET_RT_DTI_C | |
48 #define ENTITY_TCPIP | |
49 | |
50 #include "rnet_cfg.h" | |
51 #ifdef RNET_CFG_REAL_TRANSPORT | |
52 | |
53 #include "typedefs.h" | |
54 #include "vsi.h" | |
55 #include "dti.h" | |
56 | |
57 #include "rnet_rt_i.h" | |
58 #include "rnet_trace_i.h" | |
59 #include "rnet_rt_atp_i.h" | |
60 #include "atp_api.h" | |
61 #include "atp_messages.h" | |
62 #include "rnet_atp_info.h" | |
63 | |
64 #include "tcpip.h" | |
65 | |
66 static int tcpip_dtiOpen(NGifnet *netp) | |
67 { | |
68 TRACE_FUNCTION("tcpip_dtiOpen()") ; | |
69 | |
70 /* As the connection to the network is actually initiated by the | |
71 * TCPIP_DTI_REQ from the ACI, this function is more or less a no-op. It | |
72 * must mainly fulfil NexGenIP's formal requirements. The latter are only | |
73 * derived from the corresponding ATP interface code for the moment. | |
74 */ | |
75 | |
76 /* Interface already running? */ | |
77 if (netp->if_flags & NG_IFF_RUNNING) | |
78 { | |
79 TRACE_ERROR("tcpip_dtiOpen: interface already opened") ; | |
80 return NG_EALREADY ; | |
81 } | |
82 | |
83 netp->if_flags |= NG_IFF_RUNNING ; | |
84 | |
85 /* Use NG_IFF_OACTIVE flag for flow control. */ | |
86 netp->if_flags &= ~NG_IFF_OACTIVE ; | |
87 | |
88 return NG_EOK ; | |
89 } | |
90 | |
91 | |
92 static int tcpip_dtiClose (NGifnet *netp) | |
93 { | |
94 TRACE_FUNCTION("tcpip_dtiClose()") ; | |
95 | |
96 /* Interface should be running to be closed. */ | |
97 if (!(netp->if_flags & NG_IFF_RUNNING)) | |
98 { | |
99 TRACE_ERROR("tcpip_dtiClose: interface already closed") ; | |
100 return NG_EALREADY ; | |
101 } | |
102 | |
103 netp->if_flags &= ~NG_IFF_RUNNING ; | |
104 | |
105 return NG_EOK ; | |
106 } | |
107 | |
108 | |
109 static int tcpip_dtiOutput(NGifnet *netp, NGbuf *bufp, NGuint addr) | |
110 { | |
111 int err = NG_EOK ; | |
112 | |
113 TRACE_FUNCTION("tcpip_dtiOutput()") ; | |
114 | |
115 /* Interface must be up and running to send data. */ | |
116 if ((netp->if_flags & (NG_IFF_RUNNING|NG_IFF_UP)) | |
117 != (NG_IFF_RUNNING|NG_IFF_UP)) | |
118 { | |
119 TRACE_ERROR("tcpip_dtiOutput: interface isn't up and running") ; | |
120 err = NG_ENETDOWN ; | |
121 } | |
122 else | |
123 { | |
124 /* Send IP packet over DTI if output is on, else discard the packet. */ | |
125 if (tcpip_data->ll[0].flowstat_ul EQ TCPIP_FLOWCTL_XON) | |
126 { | |
127 tcpip_dti_send_data_ll(bufp->buf_datap, (U16) bufp->buf_datalen) ; | |
128 } | |
129 else | |
130 { | |
131 TRACE_ERROR("tcpip_dtiOutput(): DTI connection not ready or xoff") ; | |
132 err = NG_EAGAIN ; | |
133 } | |
134 } | |
135 | |
136 ngBufOutputFree(bufp) ; | |
137 return err ; | |
138 } | |
139 | |
140 | |
141 /** This function, while copied straight from the ATP support module, is | |
142 * apparently unused by the DTI support. Everything it does -- handling | |
143 * interfaces going up and down, arriving data, flow control -- is done | |
144 * elsewhere in this DTI/GPF port of RNET. It remains to be investigated if | |
145 * this is the right thing to do, so this function will be left in place for | |
146 * the moment. | |
147 */ | |
148 static int tcpip_dtiCntl( NGifnet *netp, int cmd, int opt, void *arg) | |
149 { | |
150 int ret; | |
151 NGbuf *bufp; | |
152 UINT32 rlen, left; | |
153 UINT8 tmpbuf[16]; | |
154 T_RNET_RT_ATP_CUSTOM_INFO *cinfo; | |
155 T_ATP_NO_COPY_INFO no_copy_info = { 0 }; /* not used */ | |
156 static const T_ATP_PORT_INFO info = { | |
157 DATA_CONFIG, | |
158 ATP_NO_RING_TYPE, | |
159 // old version received from NexGen and modified 5/Dec/2002 : 0, | |
160 ATP_RX_FLOW_UNMASK | ATP_TX_FLOW_UNMASK, | |
161 0 | |
162 }; | |
163 | |
164 // RNET_RT_SEND_TRACE("RNET_RT: in atpCntl",RV_TRACE_LEVEL_ERROR); | |
165 | |
166 if (opt == NG_RNETIFO_HANDLE_MSG) { | |
167 /* handle ATP messages */ | |
168 switch( ((T_RV_HDR *)arg)->msg_id) { | |
169 case ATP_OPEN_PORT_IND: | |
170 | |
171 RNET_RT_SEND_TRACE("RNET_RT: receive OPEN_PORT_IND",RV_TRACE_LEVEL_ERROR); | |
172 cinfo = (T_RNET_RT_ATP_CUSTOM_INFO *) | |
173 ((T_ATP_OPEN_PORT_IND *) arg)->custom_info_p; | |
174 /* if interface is already up, or if no associated data, | |
175 open is not accepted */ | |
176 if (((netp->if_flags & (NG_IFF_UP|NG_IFF_RUNNING)) != NG_IFF_RUNNING) || | |
177 (cinfo == NULL)) { | |
178 | |
179 atp_open_port_rsp( ((T_ATP_OPEN_PORT_IND *) arg)->initiator_id, | |
180 ((T_ATP_OPEN_PORT_IND *) arg)->initiator_port_nb, | |
181 ((T_RNET_RT_ATP_IFNET *) netp)->atp_sw_id, | |
182 ((T_RNET_RT_ATP_IFNET *) netp)->atp_port_nb, | |
183 info, | |
184 no_copy_info, | |
185 NULL, | |
186 OPEN_PORT_NOK); | |
187 } | |
188 else { | |
189 | |
190 /* send confirmation to ATP client */ | |
191 ((T_RNET_RT_ATP_IFNET *) netp)->atp_client_sw_id = | |
192 ((T_ATP_OPEN_PORT_IND *) arg)->initiator_id; | |
193 ((T_RNET_RT_ATP_IFNET *) netp)->atp_client_port_nb = | |
194 ((T_ATP_OPEN_PORT_IND *) arg)->initiator_port_nb; | |
195 | |
196 no_copy_info.packet_mode = NORMAL_PACKET; /* No L2CAP packet... */ | |
197 no_copy_info.rx_mb = no_copy_info.tx_mb = RVF_INVALID_MB_ID; | |
198 | |
199 ret = atp_open_port_rsp( ((T_ATP_OPEN_PORT_IND *) arg)->initiator_id, | |
200 ((T_ATP_OPEN_PORT_IND *) arg)->initiator_port_nb, | |
201 ((T_RNET_RT_ATP_IFNET *) netp)->atp_sw_id, | |
202 ((T_RNET_RT_ATP_IFNET *) netp)->atp_port_nb, | |
203 info, | |
204 no_copy_info, | |
205 NULL, | |
206 OPEN_PORT_OK); | |
207 if (ret == RV_OK) { | |
208 | |
209 /* interface is ready to send and receive packets */ | |
210 netp->if_flags |= NG_IFF_UP; | |
211 /* set MTU */ | |
212 netp->if_mtu = cinfo->mtu; | |
213 /* Activating the link addresses */ | |
214 ngIfGenCntl( netp, NG_CNTL_SET, NG_IFO_ADDR, &cinfo->local_addr); | |
215 ngIfGenCntl( netp, NG_CNTL_SET, NG_IFO_DSTADDR, &cinfo->dest_addr); | |
216 TRACE_EVENT_P2("tcpip_dtiCntl cinfo address local=%08x dest%08x", | |
217 cinfo->local_addr, cinfo->dest_addr); | |
218 /* set default route */ | |
219 if (cinfo->dest_addr == 0) { | |
220 | |
221 (void)(ngProto_IP.pr_cntl_f( NG_CNTL_SET, NG_IPO_ROUTE_DEFAULT, | |
222 (NGuint *) &cinfo->local_addr)); | |
223 } | |
224 else { | |
225 | |
226 (void)(ngProto_IP.pr_cntl_f( NG_CNTL_SET, NG_IPO_ROUTE_DEFAULT, | |
227 (NGuint *) &cinfo->dest_addr)); | |
228 } | |
229 /* set DNS configuration */ | |
230 (void)(ngProto_RESOLV.pr_cntl_f( NG_CNTL_SET, NG_RSLVO_SERV1_IPADDR, &cinfo->dns1)); | |
231 (void)(ngProto_RESOLV.pr_cntl_f( NG_CNTL_SET, NG_RSLVO_SERV2_IPADDR, &cinfo->dns2)); | |
232 } | |
233 } | |
234 /* release custom information buffer */ | |
235 if (cinfo != NULL) { | |
236 atp_free_buffer( cinfo); | |
237 } | |
238 | |
239 break; | |
240 case ATP_PORT_CLOSED: | |
241 RNET_RT_SEND_TRACE("RNET_RT: receive PORT_CLOSED",RV_TRACE_LEVEL_ERROR); | |
242 if ((netp->if_flags & (NG_IFF_RUNNING|NG_IFF_UP)) != | |
243 (NG_IFF_RUNNING|NG_IFF_UP)) { | |
244 /* interface already down */ | |
245 break; | |
246 } | |
247 /* set interface down */ | |
248 netp->if_flags &= ~NG_IFF_UP; | |
249 /* call ip layer */ | |
250 (void)(ngProto_IP.pr_cntl_f( NG_CNTL_SET, NG_IPO_NETDOWN, netp)); | |
251 break; | |
252 case ATP_DATA_RDY: | |
253 /* allocate buffer for receiving new packet */ | |
254 RNET_RT_SEND_TRACE("RNET_RT: receive DATA_RDY",RV_TRACE_LEVEL_ERROR); | |
255 ngBufAlloc( bufp); | |
256 if (bufp != NULL) { | |
257 /* get new data */ | |
258 bufp->buf_flags |= NG_PROTO_IP; | |
259 bufp->buf_datap = ((NGubyte *) bufp) + ngBufDataOffset; | |
260 ret = atp_get_data( ((T_RNET_RT_ATP_IFNET *) netp)->atp_sw_id, | |
261 ((T_RNET_RT_ATP_IFNET *) netp)->atp_port_nb, | |
262 (UINT8 *) bufp->buf_datap, | |
263 ngBufDataMax, | |
264 &rlen, | |
265 &left); | |
266 if ((ret != RV_OK) || (rlen == 0)) { | |
267 netp->if_ierrors++; | |
268 ngBufFree( bufp); | |
269 } | |
270 else { | |
271 // rnet_debug[0] = '\0' ; | |
272 // for(rnet_ind=0;rnet_ind<48;rnet_ind++) { | |
273 // char tmp[3] ; | |
274 // sprintf(tmp, "%.2x", bufp->buf_datap[rnet_ind]); | |
275 // strcat(rnet_debug, tmp) ; | |
276 // } | |
277 | |
278 // RNET_RT_SEND_TRACE("RNET_RT: receive content",RV_TRACE_LEVEL_ERROR); | |
279 // RNET_RT_SEND_TRACE(rnet_debug, RV_TRACE_LEVEL_ERROR); | |
280 // rvf_delay(RVF_MS_TO_TICKS(100)); | |
281 | |
282 /* get length of packet */ | |
283 bufp->buf_datalen = rlen; | |
284 /* start IP processing */ | |
285 ngIfGenInput( netp, bufp, 1); | |
286 } | |
287 } | |
288 else { | |
289 /* skip packet */ | |
290 netp->if_ierrors++; | |
291 atp_get_data( ((T_RNET_RT_ATP_IFNET *) netp)->atp_sw_id, | |
292 ((T_RNET_RT_ATP_IFNET *) netp)->atp_port_nb, | |
293 tmpbuf, | |
294 sizeof( tmpbuf), | |
295 &rlen, | |
296 &left); | |
297 } | |
298 break; | |
299 case ATP_SIGNAL_CHANGED: | |
300 /* handle flow control flags */ | |
301 RNET_RT_SEND_TRACE("RNET_RT: receive SIGNAL_CHANGED",RV_TRACE_LEVEL_ERROR); | |
302 // rvf_delay(RVF_MS_TO_TICKS(1000)); | |
303 if (((T_ATP_SIGNAL_CHANGED *) arg)->mask & ATP_TX_FLOW_UNMASK) { | |
304 if (((T_ATP_SIGNAL_CHANGED *) arg)->signal & ATP_TX_FLOW_ON) { | |
305 /* enable transimissions */ | |
306 netp->if_flags &= ~NG_IFF_OACTIVE; | |
307 } | |
308 else { | |
309 /* disable transmissions */ | |
310 netp->if_flags |= NG_IFF_OACTIVE; | |
311 } | |
312 } | |
313 break; | |
314 default: | |
315 /* unknown message */ | |
316 RNET_TRACE_MEDIUM_PARAM("RNET_RT: receive default ",((T_RV_HDR *)arg)->msg_id); | |
317 | |
318 return( NG_EINVAL); | |
319 } | |
320 return( NG_EOK); | |
321 } | |
322 else { | |
323 RNET_RT_SEND_TRACE("RNET_RT: opt not handle msg", RV_TRACE_LEVEL_ERROR); | |
324 return( ngIfGenCntl( netp, cmd, opt, arg)); | |
325 } | |
326 } | |
327 | |
328 /********************************************************************/ | |
329 /* Driver entry point */ | |
330 | |
331 const NGnetdrv rnet_rt_netdrv_dti = { | |
332 "DTI", | |
333 NG_IFT_PPP, | |
334 NG_IFF_POINTOPOINT|NG_IFF_MULTICAST, | |
335 RNET_RT_DTI_MTU, | |
336 0, | |
337 NULL, | |
338 tcpip_dtiOpen, | |
339 tcpip_dtiClose, | |
340 tcpip_dtiOutput, | |
341 NULL, | |
342 tcpip_dtiCntl | |
343 }; | |
344 | |
345 #endif /* ifdef RNET_CFG_REAL_TRANSPORT */ | |
346 |