1 // Copyright 2015-2016 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_PING_H_
16 #define ESP_PING_H_
17 
18 #include "esp_err.h"
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
24 // gen_esp_err_to_name.py: include this as "esp_ping.h" because "components/lwip/include/apps/" is in the compiler path
25 // and not "components/lwip/include"
26 
27 #define ESP_ERR_PING_BASE               0xa000
28 
29 #define ESP_ERR_PING_INVALID_PARAMS     ESP_ERR_PING_BASE + 0x01
30 #define ESP_ERR_PING_NO_MEM             ESP_ERR_PING_BASE + 0x02
31 
32 #define ESP_PING_CHECK_OPTLEN(optlen, opttype) do { if ((optlen) < sizeof(opttype)) { return ESP_ERR_PING_INVALID_PARAMS; }}while(0)
33 
34 typedef struct _ping_found {
35     uint32_t resp_time;
36     uint32_t timeout_count;
37     uint32_t send_count;
38     uint32_t recv_count;
39     uint32_t err_count;
40     uint32_t bytes;
41     uint32_t total_bytes;
42     uint32_t total_time;
43     uint32_t min_time;
44     uint32_t max_time;
45     int8_t  ping_err;
46 } esp_ping_found;
47 
48 typedef enum {
49     PING_TARGET_IP_ADDRESS          = 50,   /**< target IP address */
50     PING_TARGET_IP_ADDRESS_COUNT    = 51,   /**< target IP address total counter */
51     PING_TARGET_RCV_TIMEO           = 52,   /**< receive timeout in milliseconds */
52     PING_TARGET_DELAY_TIME          = 53,   /**< delay time in milliseconds */
53     PING_TARGET_ID                  = 54,   /**< identifier */
54     PING_TARGET_RES_FN              = 55,   /**< ping result callback function */
55     PING_TARGET_RES_RESET           = 56,   /**< ping result statistic reset */
56     PING_TARGET_DATA_LEN            = 57,   /**< ping data length*/
57     PING_TARGET_IP_TOS              = 58,    /**< ping QOS*/
58     PING_TARGET_IF_INDEX            = 59    /**< ping if index*/
59 } ping_target_id_t;
60 
61 typedef enum {
62     PING_RES_TIMEOUT = 0,
63     PING_RES_OK      = 1,
64     PING_RES_FINISH  = 2,
65 } ping_res_t;
66 
67 typedef void (* esp_ping_found_fn)(ping_target_id_t found_id, esp_ping_found *found_val);
68 
69 /**
70  * @brief  Set PING function option
71  *
72  * @param[in]  opt_id: option index, 50 for IP, 51 for COUNT, 52 for RCV TIMEOUT, 53 for DELAY TIME, 54 for ID
73  * @param[in]  opt_val: option parameter
74  * @param[in]  opt_len: option length
75  *
76  * @return
77  *      - ESP_OK
78  *      - ESP_ERR_PING_INVALID_PARAMS
79  */
80 esp_err_t esp_ping_set_target(ping_target_id_t opt_id, void *opt_val, uint32_t opt_len);
81 
82 /**
83  * @brief  Get PING function option
84  *
85  * @param[in]  opt_id: option index, 50 for IP, 51 for COUNT, 52 for RCV TIMEOUT, 53 for DELAY TIME, 54 for ID
86  * @param[in]  opt_val: option parameter
87  * @param[in]  opt_len: option length
88  *
89  * @return
90  *      - ESP_OK
91  *      - ESP_ERR_PING_INVALID_PARAMS
92  */
93 esp_err_t esp_ping_get_target(ping_target_id_t opt_id, void *opt_val, uint32_t opt_len);
94 
95 /**
96  * @brief  Get PING function result action
97  *
98  * @param[in]  res_val: ping function action, 1 for successful, 0 for fail.
99  *             res_len: response bytes
100  *             res_time: response time
101  *
102  * @return
103  *      - ESP_OK
104  *      - ESP_ERR_PING_INVALID_PARAMS
105  */
106 esp_err_t esp_ping_result(uint8_t res_val, uint16_t res_len, uint32_t res_time);
107 
108 #ifdef __cplusplus
109 }
110 #endif
111 
112 #endif /* ESP_PING_H_ */
113