add ping length and QoS
This commit is contained in:
parent
222a7118a9
commit
32f3972284
3 changed files with 47 additions and 2 deletions
|
@ -22,7 +22,9 @@ typedef struct _ping_option {
|
||||||
uint32_t ping_count;
|
uint32_t ping_count;
|
||||||
uint32_t ping_rcv_timeout;
|
uint32_t ping_rcv_timeout;
|
||||||
uint32_t ping_delay;
|
uint32_t ping_delay;
|
||||||
|
size_t ping_data_len;
|
||||||
uint16_t ping_id;
|
uint16_t ping_id;
|
||||||
|
u8_t ping_tos;
|
||||||
esp_ping_found_fn ping_res_fn;
|
esp_ping_found_fn ping_res_fn;
|
||||||
esp_ping_found ping_res;
|
esp_ping_found ping_res;
|
||||||
void *ping_reserve;
|
void *ping_reserve;
|
||||||
|
@ -55,10 +57,18 @@ esp_err_t esp_ping_set_target(ping_target_id_t opt_id, void *opt_val, uint32_t o
|
||||||
ESP_PING_CHECK_OPTLEN(opt_len, uint32_t);
|
ESP_PING_CHECK_OPTLEN(opt_len, uint32_t);
|
||||||
ping_option_info->ping_delay = (*(uint32_t *)opt_val);
|
ping_option_info->ping_delay = (*(uint32_t *)opt_val);
|
||||||
break;
|
break;
|
||||||
|
case PING_TARGET_DATA_LEN:
|
||||||
|
ESP_PING_CHECK_OPTLEN(opt_len, size_t);
|
||||||
|
ping_option_info->ping_data_len = (*(size_t *)opt_val);
|
||||||
|
break;
|
||||||
case PING_TARGET_ID:
|
case PING_TARGET_ID:
|
||||||
ESP_PING_CHECK_OPTLEN(opt_len, uint16_t);
|
ESP_PING_CHECK_OPTLEN(opt_len, uint16_t);
|
||||||
ping_option_info->ping_id = *(uint16_t *)opt_val;
|
ping_option_info->ping_id = *(uint16_t *)opt_val;
|
||||||
break;
|
break;
|
||||||
|
case PING_TARGET_IP_TOS:
|
||||||
|
ESP_PING_CHECK_OPTLEN(opt_len, u8_t);
|
||||||
|
ping_option_info->ping_tos = *(u8_t *)opt_val;
|
||||||
|
break;
|
||||||
case PING_TARGET_RES_FN:
|
case PING_TARGET_RES_FN:
|
||||||
ping_option_info->ping_res_fn = opt_val;
|
ping_option_info->ping_res_fn = opt_val;
|
||||||
break;
|
break;
|
||||||
|
@ -98,10 +108,18 @@ esp_err_t esp_ping_get_target(ping_target_id_t opt_id, void *opt_val, uint32_t o
|
||||||
ESP_PING_CHECK_OPTLEN(opt_len, uint32_t);
|
ESP_PING_CHECK_OPTLEN(opt_len, uint32_t);
|
||||||
*(uint32_t *)opt_val = ping_option_info->ping_delay;
|
*(uint32_t *)opt_val = ping_option_info->ping_delay;
|
||||||
break;
|
break;
|
||||||
|
case PING_TARGET_DATA_LEN:
|
||||||
|
ESP_PING_CHECK_OPTLEN(opt_len, size_t);
|
||||||
|
*(size_t *)opt_val = ping_option_info->ping_data_len;
|
||||||
|
break;
|
||||||
case PING_TARGET_ID:
|
case PING_TARGET_ID:
|
||||||
ESP_PING_CHECK_OPTLEN(opt_len, uint16_t);
|
ESP_PING_CHECK_OPTLEN(opt_len, uint16_t);
|
||||||
*(uint16_t *)opt_val = ping_option_info->ping_id;
|
*(uint16_t *)opt_val = ping_option_info->ping_id;
|
||||||
break;
|
break;
|
||||||
|
case PING_TARGET_IP_TOS:
|
||||||
|
ESP_PING_CHECK_OPTLEN(opt_len, uint16_t);
|
||||||
|
*(uint16_t *)opt_val = ping_option_info->ping_tos;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
ret = ESP_ERR_PING_INVALID_PARAMS;
|
ret = ESP_ERR_PING_INVALID_PARAMS;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -142,7 +142,21 @@ ping_send(int s, ip_addr_t *addr)
|
||||||
int err;
|
int err;
|
||||||
struct icmp_echo_hdr *iecho;
|
struct icmp_echo_hdr *iecho;
|
||||||
struct sockaddr_in to;
|
struct sockaddr_in to;
|
||||||
size_t ping_size = sizeof(struct icmp_echo_hdr) + PING_DATA_SIZE;
|
size_t ping_size;
|
||||||
|
|
||||||
|
#ifdef ESP_PING
|
||||||
|
size_t ping_data_len = 0;
|
||||||
|
esp_ping_get_target(PING_TARGET_DATA_LEN, &ping_data_len, sizeof(ping_data_len));
|
||||||
|
|
||||||
|
if (ping_data_len > 0) {
|
||||||
|
ping_size = sizeof(struct icmp_echo_hdr) + ping_data_len;
|
||||||
|
} else {
|
||||||
|
ping_size = sizeof(struct icmp_echo_hdr) + PING_DATA_SIZE;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
ping_size = sizeof(struct icmp_echo_hdr) + PING_DATA_SIZE;
|
||||||
|
#endif
|
||||||
|
|
||||||
LWIP_ASSERT("ping_size is too big", ping_size <= 0xffff);
|
LWIP_ASSERT("ping_size is too big", ping_size <= 0xffff);
|
||||||
LWIP_ASSERT("ping: expect IPv4 address", !IP_IS_V6(addr));
|
LWIP_ASSERT("ping: expect IPv4 address", !IP_IS_V6(addr));
|
||||||
|
|
||||||
|
@ -262,6 +276,17 @@ ping_thread(void *arg)
|
||||||
LWIP_ASSERT("setting receive timeout failed", ret == 0);
|
LWIP_ASSERT("setting receive timeout failed", ret == 0);
|
||||||
LWIP_UNUSED_ARG(ret);
|
LWIP_UNUSED_ARG(ret);
|
||||||
|
|
||||||
|
#ifdef ESP_PING
|
||||||
|
int tos = 0;
|
||||||
|
esp_ping_get_target(PING_TARGET_IP_TOS, &tos, sizeof(int));
|
||||||
|
if (tos > 0) {
|
||||||
|
tos <<= 5;
|
||||||
|
ret = setsockopt(s, IPPROTO_IP, IP_TOS, &tos, sizeof(tos));
|
||||||
|
LWIP_ASSERT("setting IP_TOS failed", ret == 0);
|
||||||
|
LWIP_UNUSED_ARG(ret);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
#ifdef ESP_PING
|
#ifdef ESP_PING
|
||||||
if (ping_count_cur++ >= ping_count_max) {
|
if (ping_count_cur++ >= ping_count_max) {
|
||||||
|
|
|
@ -52,7 +52,9 @@ typedef enum {
|
||||||
PING_TARGET_DELAY_TIME = 53, /**< delay time in milliseconds */
|
PING_TARGET_DELAY_TIME = 53, /**< delay time in milliseconds */
|
||||||
PING_TARGET_ID = 54, /**< identifier */
|
PING_TARGET_ID = 54, /**< identifier */
|
||||||
PING_TARGET_RES_FN = 55, /**< ping result callback function */
|
PING_TARGET_RES_FN = 55, /**< ping result callback function */
|
||||||
PING_TARGET_RES_RESET = 56 /**< ping result statistic reset */
|
PING_TARGET_RES_RESET = 56, /**< ping result statistic reset */
|
||||||
|
PING_TARGET_DATA_LEN = 57, /**< ping data length*/
|
||||||
|
PING_TARGET_IP_TOS = 58 /**< ping QOS*/
|
||||||
} ping_target_id_t;
|
} ping_target_id_t;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
|
Loading…
Reference in a new issue