Merge branch 'feature/add_ping_packet_len_and_QoS' into 'master'

ping: add length and QoS

See merge request idf/esp-idf!3379
This commit is contained in:
Jiang Jiang Jian 2018-10-19 15:29:58 +08:00
commit 129d32772e
3 changed files with 47 additions and 2 deletions

View file

@ -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;

View file

@ -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) {

View file

@ -52,7 +52,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 {