Checksums in UDP telegrams

386MMX
Posts: 4
Joined: Tue Oct 27, 2020 8:48 pm

Checksums in UDP telegrams

Postby 386MMX » Tue Oct 27, 2020 9:04 pm

Hi all,

while tracing UDP telegrams via Wireshark I see checksums. The telegrams are send to a ESP32 acting as an AP. My questions are:

1. Does the ESP32 automatically dismiss corrupted UDP telegrams?
2. Can I be sure, that when I read out data via recvfrom() that the checksum for this UDP telegram was at least correct ?

Thanks and regards

boarchuz
Posts: 315
Joined: Tue Aug 21, 2018 5:28 am

Re: Checksums in UDP telegrams

Postby boarchuz » Wed Oct 28, 2020 3:07 am

Enabled by default here:
https://github.com/espressif/esp-lwip/b ... pt.h#L2364

Packet checked and discarded if invalid here:
https://github.com/espressif/esp-lwip/b ... udp.c#L331

386MMX
Posts: 4
Joined: Tue Oct 27, 2020 8:48 pm

Re: Checksums in UDP telegrams

Postby 386MMX » Wed Oct 28, 2020 7:30 pm

Hi boarchuz,

ok if I get your answer correctly, you mean it should discard corrupt telegrams by default ?

Meanwhile I checked it by sending UDP telegrams with a corrupt checksums (using packETH), but it still receives it. Wireshark also marks this telegrams corrupt. Not sure, maybe I use the wrong functions? I just create and bind a socket with the functions socket(), bind() and then read from it with recvfrom(). I've got this from: https://github.com/espressif/esp-idf/bl ... p_server.c

any idea what I'm doing wrong ?

Thanks and regards

ESP_Sprite
Posts: 4106
Joined: Thu Nov 26, 2015 4:08 am

Re: Checksums in UDP telegrams

Postby ESP_Sprite » Thu Oct 29, 2020 2:05 am

Note that some network/wifi devices have the ability to calculate CRCs for packets they send themselves; unless you disable that somehow (depends on the driver) they may not even be able to send corrupted packets, even if Wireshark (running on the same pc as you send the packets) indicates they're corrupt when leaving the software layer.

386MMX
Posts: 4
Joined: Tue Oct 27, 2020 8:48 pm

Re: Checksums in UDP telegrams

Postby 386MMX » Fri Oct 30, 2020 11:02 am

yes I use Wireshark on the same machine as I send out the UDP telegrams to the ESP32. I use dumpcap -I on a linux machine for the dump and then analyse it with Wireshark. The UDP packets are generated with PackETH, which allows to generate a checksum automatically or by hand. In the raw data the corresponding checksums show up before the payload data. In the good and bad checksum case the ESP32 accepts this package.

For me it looks like the checksum check is not enabled by default:

From: https://github.com/espressif/esp-lwip/b ... pt.h#L2364

Code: Select all

#if !defined CHECKSUM_CHECK_UDP || defined __DOXYGEN__
#define CHECKSUM_CHECK_UDP              1
#endif
but this means if the name CHECKSUM_CHECK_UDP is not defined, then define it and use a 1 as value. On the top of opt.h the file lwipopts.h is included and there it is defined:

From: https://github.com/espressif/esp-idf/bl ... pts.h#L964

Code: Select all

#define CHECKSUM_CHECK_UDP              0
Thus it is disabled by default. If I change it to 1 then the ESP32 discards the corrupt telegram.

But for me chaning it in lwipopts.h is not a good way, as this is part of the framework and I want to define it in my code as this is specific to my project.

Does anyone know how I can handle this ?

Thanks and regards

boarchuz
Posts: 315
Joined: Tue Aug 21, 2018 5:28 am

Re: Checksums in UDP telegrams

Postby boarchuz » Fri Oct 30, 2020 12:39 pm

Sorry, I missed that one earlier.
You could copy and modify lwip in your project's local components folder if you want to change it without messing with your IDF directory (https://docs.espressif.com/projects/esp ... -same-name).
This looks like a useful option to expose via menuconfig.

386MMX
Posts: 4
Joined: Tue Oct 27, 2020 8:48 pm

Re: Checksums in UDP telegrams

Postby 386MMX » Sat Oct 31, 2020 3:20 pm

thanks boarchuz, your suggestion is what I was looking for :)

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 34 guests