trap ICMP ping

mickeypop
Posts: 11
Joined: Mon May 08, 2017 8:56 pm

trap ICMP ping

Postby mickeypop » Sat Feb 17, 2018 3:28 am

esp32/ 8266 both natively return a ping when pinged from other device.

I need to figure out how to trap the ping and respond with an LED.
I can't help but think if ping is native trapping it should be possible.

I found: #define ICMP_IRQ 15 is in Documents\Arduino\hardware\espressif\esp32\tools\sdk\include\lwip\lwip\icmp.h along with several others.

Is there some way to react to it maybe similar to:

Code: Select all

void WiFiEvent(WiFiEvent_t event)
{
  switch (event) {
    case SYSTEM_EVENT_AP_START:
      WiFi.softAPsetHostname(AP_SSID);
      break;

    case SYSTEM_EVENT_STA_START:
      WiFi.setHostname(AP_SSID);
      break;
     }
}
with Debug set to Verbose there is no log out when i ping the ESP32.

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: trap ICMP ping

Postby kolban » Mon Feb 19, 2018 5:14 am

The TCP/IP stack is a rich protocol. It commonly manifests itself at the higher levels through the API known as sockets. However, sockets is just the programming veneer on the surface. Underneath the surface there is much, much more to the protocols. For example TCP and UDP are layers on top of IP and IP the code of the story.

For example, the format of an IP (v4) packet can be found here:

https://en.wikipedia.org/wiki/IPv4#Header

Inside that packet is a byte called "Protocol". If the value of that field is "1" then the packet contains the "ICMP" protocol described here:

https://en.wikipedia.org/wiki/IPv4#Header

All of this shenanigans occurs deep below the surface of most programmer's interactions with network programming. We take the existence of the IP (and TCP/UDP) stacks for the basis.

IP is the protocol and there are a variety of ways that IP messages can be moved from one machine to another. For example, Ethernet frames or IEEE 802.11 radio. That last one is also known as WiFi. It is important to realize that WiFi deals with the "substrate" over which IP packets are transmitted/received and (as far as I know) don't care about the content on the packets themselves.

So ... looking for "hooks" into super-low-level IP packet content is unlikely to be found at the WiFi subsystems. If I had to look into how to "trap" ICMP packets, I'd do a deep study of the ESP32 implementation of the TCP/IP protocol stack which I believe is supplied in source form and is based on the "lwIP" implementation.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

mickeypop
Posts: 11
Joined: Mon May 08, 2017 8:56 pm

Re: trap ICMP ping

Postby mickeypop » Tue Feb 20, 2018 7:42 pm

As noted above; #define ICMP_IRQ 15 is in the
..\espressif\esp32\tools\sdk\include\lwip\lwip\icmp.h
but i can't seem to find any code that reacts to the ICMP_IRQ or even attach the IRQ.

If I send a PING to the esp32 it responds so clearly the IRQ is processed somewhere.

Is there any way to monitor an IRQ that is already attached elsewhere?

Stymied,

mickeypop
Posts: 11
Joined: Mon May 08, 2017 8:56 pm

Re: trap ICMP ping

Postby mickeypop » Tue Feb 20, 2018 8:27 pm

By the By;
love your book it has been immensely helpful.

I have 1 small suggestion though.

When updates to your book come out, there is no way I see to know what areas have changed, so it's a complete re-read each time.

-- An addendum page at the end of the book would be helpful here.

Just a thought...

tele_player
Posts: 90
Joined: Sun Jul 02, 2017 3:38 am

Re: trap ICMP ping

Postby tele_player » Thu Feb 22, 2018 12:10 am

mickeypop wrote:As noted above; #define ICMP_IRQ 15 is in the
..\espressif\esp32\tools\sdk\include\lwip\lwip\icmp.h
but i can't seem to find any code that reacts to the ICMP_IRQ or even attach the IRQ.

If I send a PING to the esp32 it responds so clearly the IRQ is processed somewhere.

Is there any way to monitor an IRQ that is already attached elsewhere?

Stymied,
ICMP_IRQ has nothing to do with an interrupt. There isn’t an interrupt for ICMP.

#define ICMP_IRQ 15 /* information request */

It’s an ICMP message type.

You can look at the LWIP implementation on Github.

esp-idf/components/lwip/core/ipv4/icmp.c

It seems to me that hacking in a way for an Arduino app to access the ICMP counters would be easy, once you’re set up to build everything from source.

Who is online

Users browsing this forum: No registered users and 69 guests