16
16
#include " freertos/semphr.h"
17
17
#include " freertos/queue.h"
18
18
19
- #include " esp_netif .h"
20
- #include " esp_netif_types .h"
19
+ #include " esp_netif_net_stack .h"
20
+ #include " lwip/netif .h"
21
21
22
22
static TaskHandle_t s_cli_task = NULL ;
23
23
static TaskHandle_t s_console_cli_task = NULL ;
@@ -27,6 +27,9 @@ static xQueueHandle tx_queue = NULL;
27
27
static esp_openthread_platform_config_t ot_native_config;
28
28
static TaskHandle_t s_ot_task = NULL ;
29
29
static esp_netif_t *openthread_netif = NULL ;
30
+ #if CONFIG_LWIP_HOOK_IP6_INPUT_CUSTOM
31
+ static struct netif *ot_lwip_netif = NULL ;
32
+ #endif
30
33
31
34
#define OT_CLI_MAX_LINE_LENGTH 512
32
35
@@ -38,6 +41,20 @@ typedef struct {
38
41
} ot_cli_console_t ;
39
42
static ot_cli_console_t otConsole = {NULL , false , (const char *)NULL , NULL };
40
43
44
+ #if CONFIG_LWIP_HOOK_IP6_INPUT_CUSTOM
45
+ extern " C" int lwip_hook_ip6_input (struct pbuf *p, struct netif *inp) {
46
+ if (ot_lwip_netif && ot_lwip_netif == inp) {
47
+ return 0 ;
48
+ }
49
+ if (ip6_addr_isany_val (inp->ip6_addr [0 ].u_addr .ip6 )) {
50
+ // We don't have an LL address -> eat this packet here, so it won't get accepted on input netif
51
+ pbuf_free (p);
52
+ return 1 ;
53
+ }
54
+ return 0 ;
55
+ }
56
+ #endif
57
+
41
58
// process the CLI commands sent to the OpenThread stack
42
59
static void ot_cli_loop (void *context) {
43
60
String sTxString (" " );
@@ -258,6 +275,15 @@ static void ot_task_worker(void *aContext) {
258
275
// Initialize the esp_netif bindings
259
276
esp_netif_config_t cfg = ESP_NETIF_DEFAULT_OPENTHREAD ();
260
277
openthread_netif = esp_netif_new (&cfg);
278
+ #if CONFIG_LWIP_HOOK_IP6_INPUT_CUSTOM
279
+ // Get LwIP Netif
280
+ if (openthread_netif != NULL ) {
281
+ ot_lwip_netif = (struct netif *)esp_netif_get_netif_impl (openthread_netif);
282
+ if (ot_lwip_netif == NULL ) {
283
+ log_e (" Failed to get OpenThread LwIP netif" );
284
+ }
285
+ }
286
+ #endif
261
287
}
262
288
if (!err && openthread_netif == NULL ) {
263
289
log_e (" Failed to create OpenThread esp_netif" );
@@ -335,6 +361,9 @@ void OpenThreadCLI::end() {
335
361
// Clean up
336
362
esp_openthread_deinit ();
337
363
esp_openthread_netif_glue_deinit ();
364
+ #if CONFIG_LWIP_HOOK_IP6_INPUT_CUSTOM
365
+ ot_lwip_netif = NULL ;
366
+ #endif
338
367
esp_netif_destroy (openthread_netif);
339
368
esp_vfs_eventfd_unregister ();
340
369
}
0 commit comments