lwip hooks

selfsimilar
Posts: 3
Joined: Sun Sep 12, 2021 10:18 am

lwip hooks

Postby selfsimilar » Sun Sep 12, 2021 10:35 am

Mainly based on https://github.com/espressif/esp-idf/issues/6261, I tried to implement my LWIP_HOOK_IP4_INPUT as follows:

CMakeLists.txt:

Code: Select all

FILE(GLOB_RECURSE app_sources ${CMAKE_SOURCE_DIR}/src/*)

idf_component_register(SRCS ${app_sources})
target_compile_definitions(${lwip} PRIVATE "-DESP_IDF_LWIP_HOOK_FILENAME=\"httpd/lwip_hooks.h\"")
(also tried "lwipcode" and "${COMPONENT_TARGET}" instead of "${lwip} – the latter does build but does not work as expected)

httpd/lwip_hooks.h:

Code: Select all

#pragma once

#define LWIP_HOOK_IP4_INPUT lwip_hook_ip4_input
httpd/myhook.h:

Code: Select all

#pragma once

#include "lwip/netif.h"
#include "lwip/pbuf.h"

#ifdef __cplusplus
extern "C" {
#endif

int IRAM_ATTR lwip_hook_ip4_input(struct pbuf *pbuf, struct netif *input_netif);

#ifdef __cplusplus
}
#endif
httpd/myhook.c:

Code: Select all

#include "driver/gpio.h"
#include "lwip/netif.h"
#include "lwip/pbuf.h"

int IRAM_ATTR lwip_hook_ip4_input(struct pbuf *pbuf, struct netif *input_netif) {
    gpio_set_level(GPIO_NUM_2, 1);
    return 0; // we don't consume the packet
}
What is the correct target to use in target_compile_definitions? Anything wrong with the rest of my incantation?

Running ESP-IDF 4.3.0 under platform.io.

Would be amazing to have an ESP-IDF example for using the hooks feature.

Sincerely,
Steffen

ESP_cermak
Posts: 69
Joined: Thu Nov 01, 2018 8:32 am

Re: lwip hooks

Postby ESP_cermak » Wed Sep 22, 2021 7:43 am

Hi Steffen

The ${lwip} in your Makefiles is a CMake variable which refers to lwip as a static library, IDF's component.
This is how you can initialise it:

Code: Select all

idf_component_get_property(lwip lwip COMPONENT_LiB)

Who is online

Users browsing this forum: No registered users and 116 guests