This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Help ! How to do ethernet loopback test in eCos ??


I did something similar doing the following.  It is a bit of a kludge, but
for a test it worked.

Open a socket and configure it as usual.  I use a special my_eth_drv_write()
function to write the ethernet packet, and the standard select()/recv()
calls to read the looped back reply.  This was needed to get the write to
bypass the IP stack on the way out.  You can fill out the ethernet header
any way you like, and pass along any additional data you want (IP,UDP, etc
packet, or just raw data).

void my_eth_drv_write(eth_header_t *eth_hdr, char *buf, int len)
{
	struct eth_drv_sg sg_list[2];
	int sg_len = 2;

	while (!(enet_sc->funs->can_send)(enet_sc))
		cyg_thread_sleep(1);
	sg_list[0].buf = (CYG_ADDRESS)eth_hdr;
	sg_list[0].len = ETH_HDR_SIZE;
	sg_list[1].buf = (CYG_ADDRESS)buf;
	sg_list[1].len = len;
	(enet_sc->funs->send)(enet_sc, sg_list, sg_len, len,
(CYG_ADDRWORD)0);
}

Note that it is important to pass a NULL value for the key argument in the
funs->send() call, because the generic ethernet driver uses this as the
address of the buffer allocated for the packet, and will try to free it if
it is non-NULL when the packet completes transmission.  By making it NULL,
the generic ethernet driver does nothing with the buffer upon transmission
completion, which is what you want.

The enet_sc was initialized by:
	enet_sc = NULL;
	for (cyg_netdevtab_entry_t *t = &__NETDEVTAB__[0]; t !=
&__NETDEVTAB_END__; t++)
	{
		sc = (struct eth_drv_sc *)t->device_instance;
		if (strcmp(sc->dev_name, eth0_name) == 0)
		{
			enet_sc = sc;
			break;
		}
	}

This code only ran when it was known that no other tasks were trying to use
the network.
Jay

-----Original Message-----
From: Zi Zhou [mailto:zzhou@3upsystems.com]
Sent: Wednesday, July 02, 2003 2:34 PM
To: ecos-discuss@sources.redhat.com
Subject: [ECOS] Help ! How to do ethernet loopback test in eCos ??


Hi,

I am trying to do external loopback test for one of my 2 ethernet MAC
interfaces.  So I need to generate an ethernet packet, send it out, and
compare the received packet with the one I just sent out.   I need to be
able to access the ethernet driver function. I was thinking of using
cyg_io_lookup() to find my ethernet port and call the API to write/read.
But by going through the discussion list, I realized that I can't use
these API for ethernet device. Seems I can only access ethernet device
through socket() interface. But my loopback test requires that I use
some arbitrary MAC address that's different from the real MAC address of
the port, otherwise the loopbacked ethernet packet will be dropped
because it's the same as the receive port MAC address.  Any input is
welcome and greatly appreciated !

thanks !

Zi


-- 
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss

-- 
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]