Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


Loading

FreeRTOS +TCP/+UDP - how to send raw ethernet packets?

Posted by papstdfrisco on January 26, 2018

Hi All,

I'm looking to send raw Ethernet packets Under Linux something in the vein of:

// Open our raw socket if ((mfd = socket(AFPACKET, SOCKRAW, IPPROTORAW)) == -1) { LogErr(VB_CHANNELOUT, "Error creating raw socket: %sn", strerror(errno)); return 0; }

if (sendto(mfd, mbuffer0101, mbuffer0101len, 0, (struct sockaddr*)&msockaddr, sizeof(struct sockaddrll)) < 0) { LogErr(VBCHANNELOUT, "Error sending 0x0101 packet: %sn", strerror(errno)); return 0; }

where mbuffer is: //////////////////////////// // Setup 0x0101 packet data mbuffer0101len = sizeof(struct etherheader) + 98; mbuffer0101 = (char *)calloc(mbuffer0101len, 1); if (!mbuffer0101) { LogErr(VBCHANNELOUT, "Error allocating mbuffer_0101n"); return 0; }

memset(m_buffer_0101, 0, m_buffer_0101_len);
SetHostMACs(m_buffer_0101);
m_eh = (struct ether_header *)m_buffer_0101;
m_eh->ether_type = htons(0x0101);

m_sock_addr.sll_ifindex = m_if_idx.ifr_ifindex;
m_sock_addr.sll_halen = ETH_ALEN;
memcpy(m_sock_addr.sll_addr, m_eh->ether_dhost, 6);

 Essentially a src & dest mac addr and a protocal type and the data....

I have not been able to determine if this is possible with FreeRTOS +TCP/+UDP or any setup therein.

Hopefully someone here will know either how to do this or if I'm barking up the wrong tree.

Thanks,
Matt

FreeRTOS +TCP/+UDP - how to send raw ethernet packets?

Posted by rtel on January 26, 2018

The user documentation only describes the interface to the TCP/IP stack, rather than directly to the Ethernet. There are a few function intended for use by people who are porting the TCP stack to a different platform though, and it is possible, with a bit of fiddling, you may be able to do what you want with those: https://www.freertos.org/FreeRTOS-Plus/FreeRTOSPlusTCP/Networkinterfacefunctions.html


FreeRTOS +TCP/+UDP - how to send raw ethernet packets?

Posted by papstdfrisco on January 26, 2018

Thanks for the quick response. However, I don't see how this will help me. It appears to still call the same stack functions and I don't see the stuff there that will handle the raw packets. Now it's clear that I may not understand what's going on, but that's why I'm asking. I have found neither AFPACKET (which I understand is a Linux term) nor SOCKRAW in the code anywhere - or anything that looks like it will setup things like those will.

So, is there another way to get from point a to b?

Thanks, Matt


FreeRTOS +TCP/+UDP - how to send raw ethernet packets?

Posted by papstdfrisco on January 26, 2018

So I see this: xDomain Must be set to FREERTOSAFINET. [no other choices}

xType Set to FREERTOSSOCKSTREAM to create a TCP socket.
Set to FREERTOSSOCKDGRAM to create a UDP socket. No other values are valid. [no other choices -> SOCKRAW]

xProtocol Set to FREERTOSIPPROTOTCP to create a TCP socket. Set to FREERTOSIPPROTOUDP to create a UDP socket. No other values are valid. [no other choices -> IPPROTORAW]

So I doubtfull that the stuff exists to do the raw packets.

So this begs the question: how likely is it for this functionality to be added?


FreeRTOS +TCP/+UDP - how to send raw ethernet packets?

Posted by heinbali01 on January 27, 2018

You are right, there is no support yet for exchanging RAW Ethernet packets. Just curiosity: why would you like to have that feature? What type of packets do you actually want to send? When you send RAW packets, you probably also want to receive responses in a RAW way, or not? It shouldn't be too difficult to add both sending and reception of RAW packets.


[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]


Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Careers

FreeRTOS and other careers at AWS.


Latest News

FreeRTOS kernel V10.0.1 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner