1 /*
2  * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #pragma once
8 
9 #include "esp_netif.h"
10 #include "lwip/netif.h"
11 #include "esp_netif_ppp.h"
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16 
17 #ifdef CONFIG_ESP_NETIF_RECEIVE_REPORT_ERRORS
18 typedef esp_err_t esp_netif_recv_ret_t;
19 #define ESP_NETIF_OPTIONAL_RETURN_CODE(expr) expr
20 #else
21 typedef void esp_netif_recv_ret_t;
22 #define ESP_NETIF_OPTIONAL_RETURN_CODE(expr)
23 #endif // CONFIG_ESP_NETIF_RECEIVE_REPORT_ERRORS
24 
25 typedef err_t (*init_fn_t)(struct netif*);
26 typedef esp_netif_recv_ret_t (*input_fn_t)(void *netif, void *buffer, size_t len, void *eb);
27 
28 struct esp_netif_netstack_lwip_vanilla_config {
29     init_fn_t init_fn;
30     input_fn_t input_fn;
31 };
32 
33 struct esp_netif_netstack_lwip_ppp_config {
34     input_fn_t input_fn;
35     esp_netif_ppp_config_t ppp_events;
36 };
37 
38 // LWIP netif specific network stack configuration
39 struct esp_netif_netstack_config {
40     union {
41         struct esp_netif_netstack_lwip_vanilla_config lwip;
42         struct esp_netif_netstack_lwip_ppp_config lwip_ppp;
43     };
44 };
45 
46 /**
47  * @brief   LWIP's network stack init function for Ethernet
48  * @param netif LWIP's network interface handle
49  * @return ERR_OK on success
50  */
51 err_t ethernetif_init(struct netif *netif);
52 
53 /**
54  * @brief   LWIP's network stack input packet function for Ethernet
55  * @param h LWIP's network interface handle
56  * @param buffer Input buffer pointer
57  * @param len Input buffer size
58  * @param l2_buff External buffer pointer (to be passed to custom input-buffer free)
59  */
60 esp_netif_recv_ret_t ethernetif_input(void *h, void *buffer, size_t len, void *l2_buff);
61 
62 /**
63  * @brief   LWIP's network stack init function for WiFi (AP)
64  * @param netif LWIP's network interface handle
65  * @return ERR_OK on success
66  */
67 err_t wlanif_init_ap(struct netif *netif);
68 
69 /**
70  * @brief   LWIP's network stack init function for WiFi (Station)
71  * @param netif LWIP's network interface handle
72  * @return ERR_OK on success
73  */
74 err_t wlanif_init_sta(struct netif *netif);
75 
76 /**
77  * @brief   LWIP's network stack init function for WiFi Aware interface (NAN)
78  * @param netif LWIP's network interface handle
79  * @return ERR_OK on success
80  */
81 err_t wlanif_init_nan(struct netif *netif);
82 
83 /**
84  * @brief   LWIP's network stack input packet function for WiFi (both STA/AP)
85  * @param h LWIP's network interface handle
86  * @param buffer Input buffer pointer
87  * @param len Input buffer size
88  * @param l2_buff External buffer pointer (to be passed to custom input-buffer free)
89  */
90 esp_netif_recv_ret_t wlanif_input(void *h, void *buffer, size_t len, void* l2_buff);
91 
92 #ifdef __cplusplus
93 }
94 #endif
95