esp_netif_private.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #ifndef _ESP_NETIF_PRIVATE_H_
  14. #define _ESP_NETIF_PRIVATE_H_
  15. #define ESP_NETIF_CALL_CHECK(info, api_call, ret) \
  16. do{\
  17. esp_err_t __err = (api_call);\
  18. if ((ret) != __err) {\
  19. ESP_LOGE(TAG, "%s %d %s ret=0x%X", __FUNCTION__, __LINE__, (info), __err);\
  20. return;\
  21. }\
  22. } while(0)
  23. /**
  24. * @brief Cause the TCP/IP stack to start the ESP-NETIF instance interface
  25. *
  26. * @param[in] esp_netif Handle to esp-netif instance
  27. *
  28. * @return
  29. * - ESP_OK
  30. * - ESP_ERR_ESP_NETIF_INVALID_PARAMS
  31. * - ESP_ERR_NO_MEM
  32. */
  33. esp_err_t esp_netif_start(esp_netif_t *esp_netif);
  34. /**
  35. * @brief Cause the TCP/IP stack to stop a network interface defined as ESP-NETIF instance
  36. *
  37. * Causes TCP/IP stack to clean up this interface. This includes stopping the DHCP server or client, if they are started.
  38. *
  39. * @note To stop an interface from application code, the media driver-specific API (esp_wifi_stop() or esp_eth_stop())
  40. * shall be called, the driver layer will then send a stop event and the event handler should call this API.
  41. *
  42. * @param[in] esp_netif Handle to esp-netif instance
  43. *
  44. * @return
  45. * - ESP_OK
  46. * - ESP_ERR_ESP_NETIF_INVALID_PARAMS
  47. * - ESP_ERR_ESP_NETIF_IF_NOT_READY
  48. */
  49. esp_err_t esp_netif_stop(esp_netif_t *esp_netif);
  50. /**
  51. * @brief Cause the TCP/IP stack to bring up an interface
  52. * This function is called automatically by default called from event handlers/actions
  53. *
  54. * @note This function is not normally used with Wi-Fi AP interface. If the AP interface is started, it is up.
  55. *
  56. * @param[in] esp_netif Handle to esp-netif instance
  57. *
  58. * @return
  59. * - ESP_OK
  60. * - ESP_ERR_ESP_NETIF_IF_NOT_READY
  61. */
  62. esp_err_t esp_netif_up(esp_netif_t *esp_netif);
  63. /**
  64. * @brief Cause the TCP/IP stack to shutdown an interface
  65. * This function is called automatically by default called from event handlers/actions
  66. *
  67. * @note This function is not normally used with Wi-Fi AP interface. If the AP interface is stopped, it is down.
  68. *
  69. * @param[in] esp_netif Handle to esp-netif instance
  70. *
  71. * @return
  72. * - ESP_OK
  73. * - ESP_ERR_ESP_NETIF_INVALID_PARAMS - parameter error
  74. */
  75. esp_err_t esp_netif_down(esp_netif_t *esp_netif);
  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. * @brief Adds created interface to the list of netifs
  85. *
  86. * @param[in] esp_netif Handle to esp-netif instance
  87. *
  88. * @return
  89. * - ESP_OK -- Success
  90. * - ESP_ERR_NO_MEM -- Cannot be added due to memory allocation failure
  91. */
  92. esp_err_t esp_netif_add_to_list(esp_netif_t* netif);
  93. /**
  94. * @brief Removes interface to be destroyed from the list of netifs
  95. *
  96. * @param[in] esp_netif Handle to esp-netif instance
  97. *
  98. * @return
  99. * - ESP_OK -- Success
  100. * - ESP_ERR_NOT_FOUND -- This netif was not found in the netif list
  101. */
  102. esp_err_t esp_netif_remove_from_list(esp_netif_t* netif);
  103. /**
  104. * @brief Iterates over list of interfaces without list locking. Returns first netif if NULL given as parameter
  105. *
  106. * Used for bulk search loops to avoid locking and unlocking every iteration. esp_netif_list_lock and esp_netif_list_unlock
  107. * must be used to guard the search loop
  108. *
  109. * @param[in] esp_netif Handle to esp-netif instance
  110. *
  111. * @return First netif from the list if supplied parameter is NULL, next one otherwise
  112. */
  113. esp_netif_t* esp_netif_next_unsafe(esp_netif_t* netif);
  114. /**
  115. * @brief Locking network interface list. Use only in connection with esp_netif_next_unsafe
  116. *
  117. * @return ESP_OK on success, specific mutex error if failed to lock
  118. */
  119. esp_err_t esp_netif_list_lock(void);
  120. /**
  121. * @brief Unlocking network interface list. Use only in connection with esp_netif_next_unsafe
  122. *
  123. */
  124. void esp_netif_list_unlock(void);
  125. /**
  126. * @brief Iterates over list of registered interfaces to check if supplied netif is listed
  127. *
  128. * @param esp_netif network interface to check
  129. *
  130. * @return true if supplied interface is listed
  131. */
  132. bool esp_netif_is_netif_listed(esp_netif_t *esp_netif);
  133. #endif //_ESP_NETIF_PRIVATE_H_