diff --git a/components/lwip/apps/ping/esp_ping.c b/components/lwip/apps/ping/esp_ping.c index cae4c866b..75b669412 100644 --- a/components/lwip/apps/ping/esp_ping.c +++ b/components/lwip/apps/ping/esp_ping.c @@ -22,7 +22,9 @@ typedef struct _ping_option { uint32_t ping_count; uint32_t ping_rcv_timeout; uint32_t ping_delay; + size_t ping_data_len; uint16_t ping_id; + u8_t ping_tos; esp_ping_found_fn ping_res_fn; esp_ping_found ping_res; 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); ping_option_info->ping_delay = (*(uint32_t *)opt_val); 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: ESP_PING_CHECK_OPTLEN(opt_len, uint16_t); ping_option_info->ping_id = *(uint16_t *)opt_val; 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: ping_option_info->ping_res_fn = opt_val; 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); *(uint32_t *)opt_val = ping_option_info->ping_delay; 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: ESP_PING_CHECK_OPTLEN(opt_len, uint16_t); *(uint16_t *)opt_val = ping_option_info->ping_id; 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: ret = ESP_ERR_PING_INVALID_PARAMS; break; diff --git a/components/lwip/apps/ping/esp_ping.h b/components/lwip/apps/ping/esp_ping.h index d83c5b367..399093cbd 100644 --- a/components/lwip/apps/ping/esp_ping.h +++ b/components/lwip/apps/ping/esp_ping.h @@ -49,7 +49,9 @@ typedef enum { PING_TARGET_DELAY_TIME = 53, /**< delay time in milliseconds */ PING_TARGET_ID = 54, /**< identifier */ 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; typedef enum { diff --git a/components/lwip/apps/ping/ping.c b/components/lwip/apps/ping/ping.c index 8799832db..db6aefa00 100644 --- a/components/lwip/apps/ping/ping.c +++ b/components/lwip/apps/ping/ping.c @@ -142,7 +142,21 @@ ping_send(int s, ip_addr_t *addr) int err; struct icmp_echo_hdr *iecho; 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: expect IPv4 address", !IP_IS_V6(addr)); @@ -262,6 +276,17 @@ ping_thread(void *arg) LWIP_ASSERT("setting receive timeout failed", ret == 0); 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) { #ifdef ESP_PING if (ping_count_cur++ >= ping_count_max) {