OpenWrt Forum Archive

Topic: Sending raw data to ethernet ports

The content of this topic has been archived on 22 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hi guys,

I was just wondering.. is it possible to send raw data to the ethernet ports of the router? kind of using one of the empty ports to communicate data in a way similar to what we do with available serial ports? To do this, raw data needs to be sent and total control over the packet's headers. I'm stuck because I need to communicate with a micro-controller at a speed higher than that given by the serial port, any insights?

Can you please explain what you mean with sending 'raw data to the ethernet ports'?

If you mean sending Ethernet frames containing whatever data (payload) you want, that's quite possible, just create and use a RAW Ethernet socket in your software. You can find more info about how to do that (including sample code) here. Another example is in the source code for EtherPuppet (see below).

If you mean controlling the signals going in and out of the port right down to the signal element level (like turning it into a superfast RS-485 port), I don't know if that's possible. Usually the hardware (and the driver) is 'wired' (sorry about the pun) to transmit and receive Ethernet frames, so that's what it will do best.

Assuming you do want to send/receive raw Ethernet frames: if you just want to do some testing first before you unleash your software onto your unsuspecting router, you could consider using EtherPuppet. EtherPuppet is a small program for Linux that will create a virtual interface (TUN/TAP) on one machine from the ethernet interface of another machine through a TCP connection. Everything seen by the real interface will be seen by the virtual one. Everything sent to the virtual interface will be emitted by the real one. More info on EtherPuppet on OpenWRT is in this thread.

This way you can hook up your microcontrollor to a free port on your router, setup EtherPuppet as 'puppet' on your router to take full control of that port, setup EtherPuppet as 'puppet master' on a PC which has network access to your router (this will even work over the Internet or wireless network), and use your microcontroller test/control software on that PC as if the microcontroller was hooked up directly to the PC's network card.

Note: if the ports on your router are bridged together, you may need to remove the port which your microcontroller is connected to from that bridge so devices connected to other ports don't get confused by the data format you use to communicate with the microcontroller.

When everything works as you want, you can cross-compile your software for your router's flavour of OpenWRT and run it on your router.

Hopefully this answers your question :-)

(Last edited by ack on 24 Feb 2011, 19:43)

Thanks for answering, yes I meant on the signal element level, which would be really cool! But great info too thanks. I suppose a simple script should be able to remove the packet's header and get right to the data on a binary level. Theoretically this would be a great alternative to using serial for output. Don't you think? I'm theorizing here, needs lots of experimentation.

With a little extra work on the other end, just use UDP sockets and youll be able to talk to it without too mant shenanigans. There's no handshaking with UDP, and you only need to add a few bytes for the UDP wrapper.

The discussion might have continued from here.