1 /*
2  * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef _ESP_NETIF_PRIVATE_H_
8 #define _ESP_NETIF_PRIVATE_H_
9 
10 #define ESP_NETIF_CALL_CHECK(info, api_call, ret) \
11 do{\
12     esp_err_t __err = (api_call);\
13     if ((ret) != __err) {\
14         ESP_LOGE(TAG, "%s %d %s ret=0x%X", __FUNCTION__, __LINE__, (info), __err);\
15         return;\
16     }\
17 } while(0)
18 
19 /**
20  * @brief  Cause the TCP/IP stack to start the ESP-NETIF instance interface
21  *
22  * @param[in]  esp_netif Handle to esp-netif instance
23  *
24  * @return
25  *         - ESP_OK
26  *         - ESP_ERR_ESP_NETIF_INVALID_PARAMS
27  *         - ESP_ERR_NO_MEM
28  */
29 esp_err_t esp_netif_start(esp_netif_t *esp_netif);
30 
31 /**
32  * @brief  Cause the TCP/IP stack to stop a network interface defined as ESP-NETIF instance
33  *
34  * Causes TCP/IP stack to clean up this interface. This includes stopping the DHCP server or client, if they are started.
35  *
36  * @note To stop an interface from application code, the media driver-specific API (esp_wifi_stop() or esp_eth_stop())
37  * shall be called, the driver layer will then send a stop event and the event handler should call this API.
38  *
39  * @param[in]  esp_netif Handle to esp-netif instance
40  *
41  * @return
42  *         - ESP_OK
43  *         - ESP_ERR_ESP_NETIF_INVALID_PARAMS
44  *         - ESP_ERR_ESP_NETIF_IF_NOT_READY
45  */
46 esp_err_t esp_netif_stop(esp_netif_t *esp_netif);
47 
48 /**
49  * @brief  Cause the TCP/IP stack to bring up an interface
50  * This function is called automatically by default called from event handlers/actions
51  *
52  * @note This function is not normally used with Wi-Fi AP interface. If the AP interface is started, it is up.
53  *
54  * @param[in]  esp_netif Handle to esp-netif instance
55  *
56  * @return
57  *         - ESP_OK
58  *         - ESP_ERR_ESP_NETIF_IF_NOT_READY
59  */
60 esp_err_t esp_netif_up(esp_netif_t *esp_netif);
61 
62 /**
63  * @brief Cause the TCP/IP stack to shutdown an interface
64  * This function is called automatically by default called from event handlers/actions
65  *
66  * @note This function is not normally used with Wi-Fi AP interface. If the AP interface is stopped, it is down.
67  *
68  * @param[in]  esp_netif Handle to esp-netif instance
69  *
70  * @return
71  *         - ESP_OK
72  *         - ESP_ERR_ESP_NETIF_INVALID_PARAMS - parameter error
73  */
74 esp_err_t esp_netif_down(esp_netif_t *esp_netif);
75 
76 /**
77  * @brief Returns true if underlying TCP/IP stack finds the ip_info as valid static address
78  *
79  * @param[in] ip_info
80  * @return true if address assumed to be valid static IP address
81  */
82 bool esp_netif_is_valid_static_ip(esp_netif_ip_info_t *ip_info);
83 
84 /**
85  * @brief Adds created interface to the list of netifs
86  *
87  * @param[in]  esp_netif Handle to esp-netif instance
88  *
89  * @return
90  *         - ESP_OK -- Success
91  *         - ESP_ERR_NO_MEM -- Cannot be added due to memory allocation failure
92  */
93 esp_err_t esp_netif_add_to_list(esp_netif_t* netif);
94 
95 /**
96  * @brief Removes interface to be destroyed from the list of netifs
97  *
98  * @param[in]  esp_netif Handle to esp-netif instance
99  *
100  * @return
101  *         - ESP_OK -- Success
102  *         - ESP_ERR_NOT_FOUND -- This netif was not found in the netif list
103  */
104 esp_err_t esp_netif_remove_from_list(esp_netif_t* netif);
105 
106 /**
107  * @brief Iterates over list of interfaces without list locking. Returns first netif if NULL given as parameter
108  *
109  * Used for bulk search loops to avoid locking and unlocking every iteration. esp_netif_list_lock and esp_netif_list_unlock
110  * must be used to guard the search loop
111  *
112  * @param[in]  esp_netif Handle to esp-netif instance
113  *
114  * @return First netif from the list if supplied parameter is NULL, next one otherwise
115  */
116 esp_netif_t* esp_netif_next_unsafe(esp_netif_t* netif);
117 
118 /**
119  * @brief Locking network interface list. Use only in connection with esp_netif_next_unsafe
120  *
121  * @return ESP_OK on success, specific mutex error if failed to lock
122  */
123 esp_err_t esp_netif_list_lock(void);
124 
125 /**
126  * @brief Unlocking network interface list. Use only in connection with esp_netif_next_unsafe
127  *
128  */
129 void esp_netif_list_unlock(void);
130 
131 /**
132  * @brief Iterates over list of registered interfaces to check if supplied netif is listed
133  *
134  * @param esp_netif network interface to check
135  *
136  * @return true if supplied interface is listed
137  */
138 bool esp_netif_is_netif_listed(esp_netif_t *esp_netif);
139 
140 /**
141  * @brief  Cause the TCP/IP stack to add an IPv6 address to the interface
142  *
143  * @param[in]  esp_netif Handle to esp-netif instance
144  * @param[in]  addr      The address to be added
145  *
146  * @return
147  *         - ESP_OK
148  *         - ESP_ERR_ESP_NETIF_INVALID_PARAMS
149  *         - ESP_ERR_ESP_NETIF_IP6_ADDR_FAILED
150  *         - ESP_ERR_NO_MEM
151  */
152 esp_err_t esp_netif_add_ip6_address(esp_netif_t *esp_netif, const ip_event_add_ip6_t *addr);
153 
154 /**
155  * @brief  Cause the TCP/IP stack to remove an IPv6 address from the interface
156  *
157  * @param[in]  esp_netif Handle to esp-netif instance
158  * @param[in]  addr      The address to be removed
159  *
160  * @return
161  *         - ESP_OK
162  *         - ESP_ERR_ESP_NETIF_INVALID_PARAMS
163  *         - ESP_ERR_ESP_NETIF_IP6_ADDR_FAILED
164  *         - ESP_ERR_NO_MEM
165  */
166 esp_err_t esp_netif_remove_ip6_address(esp_netif_t *esp_netif, const esp_ip6_addr_t *addr);
167 
168 #endif //_ESP_NETIF_PRIVATE_H_
169