You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
2.1 KiB
83 lines
2.1 KiB
3 years ago
|
/**
|
||
|
* DHCP watchdog
|
||
|
*
|
||
|
* This is a workaround for a rare case where we don't get
|
||
|
* any IP after connecting with STA. If it takes too long,
|
||
|
* try power-cycling the DHCP client. If that fails too,
|
||
|
* try cycling the WiFi stack too.
|
||
|
*
|
||
|
* This does not try to reboot, as there are valid cases when this
|
||
|
* can happen - e.g. no DHCP on the network + no static IP configured yet.
|
||
|
*
|
||
|
* The ping component is used as a dependency.
|
||
|
*/
|
||
|
|
||
|
#ifndef _DHCP_WD_H_
|
||
|
#define _DHCP_WD_H_
|
||
|
|
||
|
#include "esp_netif.h"
|
||
|
#include "esp_event.h"
|
||
|
#include "freertos/FreeRTOS.h"
|
||
|
#include "freertos/task.h"
|
||
|
|
||
|
typedef struct dhcp_wd_instance * dhcp_wd_handle_t;
|
||
|
|
||
|
/**
|
||
|
* Start the watchdog. Handle must remain valid until the task is deleted.
|
||
|
*
|
||
|
* @param[in] iface
|
||
|
* @param[out] handle - pointer to a handle variable (will be written to it)
|
||
|
* @return success
|
||
|
*/
|
||
|
esp_err_t dhcp_watchdog_start(esp_netif_t * netif, bool is_wifi, dhcp_wd_handle_t *pHandle);
|
||
|
|
||
|
/**
|
||
|
* Check if a watchdog is running
|
||
|
*
|
||
|
* @param[in] handle
|
||
|
* @return is running
|
||
|
*/
|
||
|
bool dhcp_watchdog_is_running(dhcp_wd_handle_t handle);
|
||
|
|
||
|
/**
|
||
|
* Stop the watchdog and free resources.
|
||
|
* The handle becomes invalid and is set to NULL.
|
||
|
*
|
||
|
* @param[in] handle
|
||
|
* @return success
|
||
|
*/
|
||
|
esp_err_t dhcp_watchdog_stop(dhcp_wd_handle_t *pHandle);
|
||
|
|
||
|
enum dhcp_wd_event {
|
||
|
DHCP_WD_NOTIFY_CONNECTED,
|
||
|
DHCP_WD_NOTIFY_DISCONNECTED,
|
||
|
DHCP_WD_NOTIFY_GOT_IP,
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* @brief Notify the watchdog task about a wifi state change
|
||
|
*
|
||
|
* Call this from the WiFi event handler.
|
||
|
*
|
||
|
* @param[in] handle
|
||
|
* @param[in] event - detected event
|
||
|
*/
|
||
|
esp_err_t dhcp_watchdog_notify(dhcp_wd_handle_t handle, enum dhcp_wd_event);
|
||
|
|
||
|
enum dhcp_wd_test_result {
|
||
|
DHCP_WD_RESULT_OK = 0,
|
||
|
DHCP_WD_RESULT_PING_LOST,
|
||
|
DHCP_WD_RESULT_NO_GATEWAY,
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Manually trigger a connection test by pinging the gateway.
|
||
|
* This is independent on any watchdog tasks and can be run without starting the watchdog.
|
||
|
*
|
||
|
* @param[in] iface - network interface, typically TCPIP_ADAPTER_IF_STA
|
||
|
* @return test result
|
||
|
*/
|
||
|
enum dhcp_wd_test_result dhcp_wd_test_connection(esp_netif_t *iface);
|
||
|
|
||
|
#endif //_DHCP_WD_H_
|