comparison src/g23m-fad/tcpip/rnet/rnet_rt/rnet_rt_atp.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_atp.c
3 *
4 * Coding of the ATP point-to-point network interface for RNET_RT,
5 *
6 * @author Regis Feneon
7 * @version 0.1
8 */
9
10 /*
11 * $Id: rnet_rt_atp.c,v 1.4 2002/12/05 10:02:19 rf Exp $
12 * $Name: $
13 *
14 * History:
15 *
16 * Date Author Modification
17 * --------------------------------------------------
18 * 5/6/2002 Regis Feneon Create
19 * 6/9/2002 Regis Feneon Select default route
20 * on local interface address if no destination address
21 * 12/5/2002 Regis Feneon Flow control handling
22 * (C) Copyright 2002 by TI, All Rights Reserved
23 *
24 */
25
26 #include "rnet_cfg.h"
27 #ifdef RNET_CFG_REAL_TRANSPORT
28
29 #include "rnet_rt_i.h"
30 #include "rnet_trace_i.h"
31 #include "rnet_rt_atp_i.h"
32 #include "atp_api.h"
33 #include "atp_messages.h"
34 #include "rnet_atp_info.h"
35
36 static int atpOpen( NGifnet *netp)
37 {
38 T_ATP_RET ret;
39 T_ATP_CALLBACK return_path;
40 T_ATP_ENTITY_MODE mode = { CMD_SUPPORT_OFF, TXT_MODE, COPY_ON };
41
42 /* interface already running ? */
43 if( netp->if_flags & NG_IFF_RUNNING) {
44 RNET_RT_SEND_TRACE("RNET_RT: WINNET_open: already running",RV_TRACE_LEVEL_ERROR);
45 return( NG_EALREADY);
46 }
47
48 /* register to ATP */
49 return_path.addr_id = rnet_rt_env_ctrl_blk_p->addr_id;
50 return_path.callback_func = NULL;
51
52 ret = atp_reg( (UINT8*) "RNET_RT",
53 return_path,
54 mode,
55 &((T_RNET_RT_ATP_IFNET *) netp)->atp_sw_id);
56 if( ret != RV_OK) {
57 return( NG_ENODEV);
58 }
59 /* set a local port... */
60 ((T_RNET_RT_ATP_IFNET *) netp)->atp_port_nb = 1;
61
62 netp->if_flags |= NG_IFF_RUNNING;
63
64 /* use NG_IFF_OACTIVE flag for flow control */
65 netp->if_flags &= ~NG_IFF_OACTIVE;
66
67 return( NG_EOK);
68 }
69
70 static int atpClose( NGifnet *netp)
71 {
72 /* interface should be running to be closed */
73 if( !(netp->if_flags & NG_IFF_RUNNING)) {
74 return( NG_EALREADY);
75 }
76 /* clear flags */
77 netp->if_flags &= ~NG_IFF_RUNNING;
78
79 /* deregister to ATP */
80 atp_dereg( ((T_RNET_RT_ATP_IFNET *) netp)->atp_sw_id);
81
82 return( NG_EOK);
83 }
84
85 static int atpOutput( NGifnet *netp, NGbuf *bufp, NGuint addr)
86 {
87 UINT32 wlen;
88 int err;
89
90 // RNET_RT_SEND_TRACE("RNET_RT: In atpOutput",RV_TRACE_LEVEL_ERROR);
91
92 /* point-to-point interfaces dont use destination address */
93 ((void)addr);
94
95 /* Interface must be up and running */
96 if ( (netp->if_flags & (NG_IFF_RUNNING|NG_IFF_UP)) !=
97 (NG_IFF_RUNNING|NG_IFF_UP)) {
98 err = NG_ENETDOWN;
99 }
100 else {
101 /* send IP packet to ATP if output is on... */
102 /* ...else discard the packet */
103 if( !(netp->if_flags & NG_IFF_OACTIVE)) {
104 atp_send_data( ((T_RNET_RT_ATP_IFNET *) netp)->atp_sw_id,
105 ((T_RNET_RT_ATP_IFNET *) netp)->atp_port_nb,
106 bufp->buf_datap,
107 bufp->buf_datalen,
108 &wlen);
109 }
110 err = NG_EOK;
111 }
112 /* release buffer */
113 ngBufOutputFree( bufp);
114 return( err);
115 }
116
117 static int atpCntl( NGifnet *netp, int cmd, int opt, void *arg)
118 {
119 int ret;
120 NGbuf *bufp;
121 UINT32 rlen, left;
122 UINT8 tmpbuf[16];
123 T_RNET_RT_ATP_CUSTOM_INFO *cinfo;
124 T_ATP_NO_COPY_INFO no_copy_info = { 0 }; /* not used */
125 static const T_ATP_PORT_INFO info = {
126 DATA_CONFIG,
127 ATP_NO_RING_TYPE,
128 // old version received from NexGen and modified 5/Dec/2002 : 0,
129 ATP_RX_FLOW_UNMASK | ATP_TX_FLOW_UNMASK,
130 0
131 };
132
133 // RNET_RT_SEND_TRACE("RNET_RT: in atpCntl",RV_TRACE_LEVEL_ERROR);
134
135 if( opt == NG_RNETIFO_HANDLE_MSG) {
136 /* handle ATP messages */
137 switch( ((T_RV_HDR *)arg)->msg_id) {
138 case ATP_OPEN_PORT_IND:
139
140 RNET_RT_SEND_TRACE("RNET_RT: receive OPEN_PORT_IND",RV_TRACE_LEVEL_ERROR);
141 cinfo = (T_RNET_RT_ATP_CUSTOM_INFO *)
142 ((T_ATP_OPEN_PORT_IND *) arg)->custom_info_p;
143 /* if interface is already up, or if no associated data,
144 open is not accepted */
145 if( ((netp->if_flags & (NG_IFF_UP|NG_IFF_RUNNING)) != NG_IFF_RUNNING) ||
146 (cinfo == NULL)) {
147
148 atp_open_port_rsp( ((T_ATP_OPEN_PORT_IND *) arg)->initiator_id,
149 ((T_ATP_OPEN_PORT_IND *) arg)->initiator_port_nb,
150 ((T_RNET_RT_ATP_IFNET *) netp)->atp_sw_id,
151 ((T_RNET_RT_ATP_IFNET *) netp)->atp_port_nb,
152 info,
153 no_copy_info,
154 NULL,
155 OPEN_PORT_NOK);
156 }
157 else {
158
159 /* send confirmation to ATP client */
160 ((T_RNET_RT_ATP_IFNET *) netp)->atp_client_sw_id =
161 ((T_ATP_OPEN_PORT_IND *) arg)->initiator_id;
162 ((T_RNET_RT_ATP_IFNET *) netp)->atp_client_port_nb =
163 ((T_ATP_OPEN_PORT_IND *) arg)->initiator_port_nb;
164
165 no_copy_info.packet_mode = NORMAL_PACKET; /* No L2CAP packet... */
166 no_copy_info.rx_mb = no_copy_info.tx_mb = RVF_INVALID_MB_ID;
167
168 ret = atp_open_port_rsp( ((T_ATP_OPEN_PORT_IND *) arg)->initiator_id,
169 ((T_ATP_OPEN_PORT_IND *) arg)->initiator_port_nb,
170 ((T_RNET_RT_ATP_IFNET *) netp)->atp_sw_id,
171 ((T_RNET_RT_ATP_IFNET *) netp)->atp_port_nb,
172 info,
173 no_copy_info,
174 NULL,
175 OPEN_PORT_OK);
176 if( ret == RV_OK) {
177
178 /* interface is ready to send and receive packets */
179 netp->if_flags |= NG_IFF_UP;
180 /* set MTU */
181 netp->if_mtu = cinfo->mtu;
182 /* Activating the link addresses */
183 ngIfGenCntl( netp, NG_CNTL_SET, NG_IFO_ADDR, &cinfo->local_addr);
184 ngIfGenCntl( netp, NG_CNTL_SET, NG_IFO_DSTADDR, &cinfo->dest_addr);
185 /* set default route */
186 if( cinfo->dest_addr == 0) {
187
188 (void)(ngProto_IP.pr_cntl_f( NG_CNTL_SET, NG_IPO_ROUTE_DEFAULT,
189 (NGuint *) &cinfo->local_addr));
190 }
191 else {
192
193 (void)(ngProto_IP.pr_cntl_f( NG_CNTL_SET, NG_IPO_ROUTE_DEFAULT,
194 (NGuint *) &cinfo->dest_addr));
195 }
196 /* set DNS configuration */
197 (void)(ngProto_RESOLV.pr_cntl_f( NG_CNTL_SET, NG_RSLVO_SERV1_IPADDR, &cinfo->dns1));
198 (void)(ngProto_RESOLV.pr_cntl_f( NG_CNTL_SET, NG_RSLVO_SERV2_IPADDR, &cinfo->dns2));
199 }
200 }
201 /* release custom information buffer */
202 if( cinfo != NULL) {
203 atp_free_buffer( cinfo);
204 }
205
206 break;
207 case ATP_PORT_CLOSED:
208 RNET_RT_SEND_TRACE("RNET_RT: receive PORT_CLOSED",RV_TRACE_LEVEL_ERROR);
209 if( (netp->if_flags & (NG_IFF_RUNNING|NG_IFF_UP)) !=
210 (NG_IFF_RUNNING|NG_IFF_UP)) {
211 /* interface already down */
212 break;
213 }
214 /* set interface down */
215 netp->if_flags &= ~NG_IFF_UP;
216 /* call ip layer */
217 (void)(ngProto_IP.pr_cntl_f( NG_CNTL_SET, NG_IPO_NETDOWN, netp));
218 break;
219 case ATP_DATA_RDY:
220 /* allocate buffer for receiving new packet */
221 RNET_RT_SEND_TRACE("RNET_RT: receive DATA_RDY",RV_TRACE_LEVEL_ERROR);
222 ngBufAlloc( bufp);
223 if( bufp != NULL) {
224 /* get new data */
225 bufp->buf_flags |= NG_PROTO_IP;
226 bufp->buf_datap = ((NGubyte *) bufp) + ngBufDataOffset;
227 ret = atp_get_data( ((T_RNET_RT_ATP_IFNET *) netp)->atp_sw_id,
228 ((T_RNET_RT_ATP_IFNET *) netp)->atp_port_nb,
229 (UINT8 *) bufp->buf_datap,
230 ngBufDataMax,
231 &rlen,
232 &left);
233 if( (ret != RV_OK) || (rlen == 0)) {
234 netp->if_ierrors++;
235 ngBufFree( bufp);
236 }
237 else {
238 // rnet_debug[0] = '\0' ;
239 // for(rnet_ind=0;rnet_ind<48;rnet_ind++) {
240 // char tmp[3] ;
241 // sprintf(tmp, "%.2x", bufp->buf_datap[rnet_ind]);
242 // strcat(rnet_debug, tmp) ;
243 // }
244
245 // RNET_RT_SEND_TRACE("RNET_RT: receive content",RV_TRACE_LEVEL_ERROR);
246 // RNET_RT_SEND_TRACE(rnet_debug, RV_TRACE_LEVEL_ERROR);
247 // rvf_delay(RVF_MS_TO_TICKS(100));
248
249 /* get length of packet */
250 bufp->buf_datalen = rlen;
251 /* start IP processing */
252 ngIfGenInput( netp, bufp, 1);
253 }
254 }
255 else {
256 /* skip packet */
257 netp->if_ierrors++;
258 atp_get_data( ((T_RNET_RT_ATP_IFNET *) netp)->atp_sw_id,
259 ((T_RNET_RT_ATP_IFNET *) netp)->atp_port_nb,
260 tmpbuf,
261 sizeof( tmpbuf),
262 &rlen,
263 &left);
264 }
265 break;
266 case ATP_SIGNAL_CHANGED:
267 /* handle flow control flags */
268 RNET_RT_SEND_TRACE("RNET_RT: receive SIGNAL_CHANGED",RV_TRACE_LEVEL_ERROR);
269 // rvf_delay(RVF_MS_TO_TICKS(1000));
270 if( ((T_ATP_SIGNAL_CHANGED *) arg)->mask & ATP_TX_FLOW_UNMASK) {
271 if( ((T_ATP_SIGNAL_CHANGED *) arg)->signal & ATP_TX_FLOW_ON) {
272 /* enable transimissions */
273 netp->if_flags &= ~NG_IFF_OACTIVE;
274 }
275 else {
276 /* disable transmissions */
277 netp->if_flags |= NG_IFF_OACTIVE;
278 }
279 }
280 break;
281 default:
282 /* unknown message */
283 RNET_TRACE_MEDIUM_PARAM("RNET_RT: receive default ",((T_RV_HDR *)arg)->msg_id);
284
285 return( NG_EINVAL);
286 }
287 return( NG_EOK);
288 }
289 else {
290 RNET_RT_SEND_TRACE("RNET_RT: opt not handle msg", RV_TRACE_LEVEL_ERROR);
291 return( ngIfGenCntl( netp, cmd, opt, arg));
292 }
293 }
294
295 /********************************************************************/
296 /* Driver entry point */
297
298 const NGnetdrv rnet_rt_netdrv_atp = {
299 "ATP",
300 NG_IFT_PPP,
301 NG_IFF_POINTOPOINT|NG_IFF_MULTICAST,
302 RNET_RT_ATP_MTU,
303 0,
304 NULL,
305 atpOpen,
306 atpClose,
307 atpOutput,
308 NULL,
309 atpCntl
310 };
311
312 #endif /* ifdef RNET_CFG_REAL_TRANSPORT */
313