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