2014-05-30 21:32:10 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* net/icmp/icmp_ping.c
|
|
|
|
*
|
2016-11-03 19:17:02 +01:00
|
|
|
* Copyright (C) 2008-2012, 2014-2016 Gregory Nutt. All rights reserved.
|
2014-05-30 21:32:10 +02:00
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
|
|
|
* used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
#if defined(CONFIG_NET) && defined(CONFIG_NET_ICMP) && \
|
2014-08-07 20:35:24 +02:00
|
|
|
defined(CONFIG_NET_ICMP_PING)
|
2014-05-30 21:32:10 +02:00
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <semaphore.h>
|
|
|
|
#include <debug.h>
|
|
|
|
|
2015-05-29 23:16:11 +02:00
|
|
|
#include <netinet/in.h>
|
2014-05-30 21:32:10 +02:00
|
|
|
#include <net/if.h>
|
2014-07-05 03:13:08 +02:00
|
|
|
|
2014-05-30 21:32:10 +02:00
|
|
|
#include <nuttx/clock.h>
|
2016-11-04 00:48:36 +01:00
|
|
|
#include <nuttx/semaphore.h>
|
2014-06-24 16:53:28 +02:00
|
|
|
#include <nuttx/net/netconfig.h>
|
2014-07-05 00:38:51 +02:00
|
|
|
#include <nuttx/net/net.h>
|
2014-06-24 17:28:44 +02:00
|
|
|
#include <nuttx/net/netdev.h>
|
2014-07-05 03:13:08 +02:00
|
|
|
#include <nuttx/net/ip.h>
|
2014-06-26 17:32:39 +02:00
|
|
|
#include <nuttx/net/icmp.h>
|
2014-05-30 21:32:10 +02:00
|
|
|
|
2014-06-27 17:56:45 +02:00
|
|
|
#include "netdev/netdev.h"
|
2014-06-29 02:07:02 +02:00
|
|
|
#include "devif/devif.h"
|
2014-08-19 00:22:14 +02:00
|
|
|
#include "arp/arp.h"
|
2014-06-25 17:12:47 +02:00
|
|
|
#include "icmp/icmp.h"
|
|
|
|
|
2014-05-30 21:32:10 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2014-11-15 20:13:23 +01:00
|
|
|
#define ICMPBUF ((struct icmp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
|
|
|
|
#define ICMPDAT (&dev->d_buf[NET_LL_HDRLEN(dev) + sizeof(struct icmp_iphdr_s)])
|
2014-05-30 21:32:10 +02:00
|
|
|
|
|
|
|
/* Allocate a new ICMP data callback */
|
|
|
|
|
2015-06-03 16:11:57 +02:00
|
|
|
#define icmp_callback_alloc(dev) devif_callback_alloc(dev, &(dev)->d_conncb)
|
|
|
|
#define icmp_callback_free(dev,cb) devif_dev_callback_free(dev, cb)
|
2014-05-30 21:32:10 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
struct icmp_ping_s
|
|
|
|
{
|
2014-06-29 20:59:34 +02:00
|
|
|
FAR struct devif_callback_s *png_cb; /* Reference to callback instance */
|
2014-05-30 21:32:10 +02:00
|
|
|
|
2015-01-15 19:19:44 +01:00
|
|
|
sem_t png_sem; /* Use to manage the wait for the response */
|
2016-01-21 18:54:26 +01:00
|
|
|
systime_t png_time; /* Start time for determining timeouts */
|
|
|
|
systime_t png_ticks; /* System clock ticks to wait */
|
2015-01-15 19:19:44 +01:00
|
|
|
int png_result; /* 0: success; <0:negated errno on fail */
|
|
|
|
in_addr_t png_addr; /* The peer to be ping'ed */
|
|
|
|
uint16_t png_id; /* Used to match requests with replies */
|
2015-05-27 17:26:00 +02:00
|
|
|
uint16_t png_seqno; /* IN: seqno to send; OUT: seqno received */
|
2015-01-15 19:19:44 +01:00
|
|
|
uint16_t png_datlen; /* The length of data to send in the ECHO request */
|
|
|
|
bool png_sent; /* true... the PING request has been sent */
|
2014-05-30 21:32:10 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: ping_timeout
|
2014-05-30 21:32:10 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Check for send timeout.
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* pstate - Ping state structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* TRUE:timeout FALSE:no timeout
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* Running at the interrupt level
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2014-06-25 17:12:47 +02:00
|
|
|
static inline int ping_timeout(FAR struct icmp_ping_s *pstate)
|
2014-05-30 21:32:10 +02:00
|
|
|
{
|
2016-01-21 18:54:26 +01:00
|
|
|
systime_t elapsed = clock_systimer() - pstate->png_time;
|
2014-05-30 21:32:10 +02:00
|
|
|
if (elapsed >= pstate->png_ticks)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: ping_interrupt
|
2014-05-30 21:32:10 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This function is called from the interrupt level to perform the actual
|
2014-07-07 01:22:02 +02:00
|
|
|
* ECHO request and/or ECHO reply actions when polled by the lower, device
|
|
|
|
* interfacing layer.
|
2014-05-30 21:32:10 +02:00
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* dev The structure of the network driver that caused the interrupt
|
|
|
|
* conn The received packet, cast to void *
|
|
|
|
* pvpriv An instance of struct icmp_ping_s cast to void*
|
|
|
|
* flags Set of events describing why the callback was invoked
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Modified value of the input flags
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* Running at the interrupt level
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2014-06-28 00:48:12 +02:00
|
|
|
static uint16_t ping_interrupt(FAR struct net_driver_s *dev, FAR void *conn,
|
2014-06-25 17:12:47 +02:00
|
|
|
FAR void *pvpriv, uint16_t flags)
|
2014-05-30 21:32:10 +02:00
|
|
|
{
|
2014-06-25 17:12:47 +02:00
|
|
|
FAR struct icmp_ping_s *pstate = (struct icmp_ping_s *)pvpriv;
|
|
|
|
FAR uint8_t *ptr;
|
2014-05-30 21:32:10 +02:00
|
|
|
int i;
|
|
|
|
|
2016-06-20 19:59:15 +02:00
|
|
|
ninfo("flags: %04x\n", flags);
|
2015-05-27 19:39:44 +02:00
|
|
|
|
2014-05-30 21:32:10 +02:00
|
|
|
if (pstate)
|
|
|
|
{
|
2015-05-27 19:39:44 +02:00
|
|
|
/* Check if the network is still up */
|
2015-05-27 17:26:00 +02:00
|
|
|
|
|
|
|
if ((flags & NETDEV_DOWN) != 0)
|
|
|
|
{
|
2016-06-20 19:59:15 +02:00
|
|
|
nerr("ERROR: Interface is down\n");
|
2015-05-27 17:26:00 +02:00
|
|
|
pstate->png_result = -ENETUNREACH;
|
|
|
|
goto end_wait;
|
|
|
|
}
|
|
|
|
|
2014-05-30 21:32:10 +02:00
|
|
|
/* Check if this is a ICMP ECHO reply. If so, return the sequence
|
|
|
|
* number to the caller. NOTE: We may not even have sent the
|
|
|
|
* requested ECHO request; this could have been the delayed ECHO
|
|
|
|
* response from a previous ping.
|
|
|
|
*/
|
|
|
|
|
2015-05-27 17:26:00 +02:00
|
|
|
else if ((flags & ICMP_ECHOREPLY) != 0 && conn != NULL)
|
2014-05-30 21:32:10 +02:00
|
|
|
{
|
2014-06-25 17:12:47 +02:00
|
|
|
FAR struct icmp_iphdr_s *icmp = (FAR struct icmp_iphdr_s *)conn;
|
|
|
|
|
2016-06-20 19:59:15 +02:00
|
|
|
ninfo("ECHO reply: id=%d seqno=%d\n",
|
|
|
|
ntohs(icmp->id), ntohs(icmp->seqno));
|
2014-05-30 21:32:10 +02:00
|
|
|
|
|
|
|
if (ntohs(icmp->id) == pstate->png_id)
|
|
|
|
{
|
|
|
|
/* Consume the ECHOREPLY */
|
|
|
|
|
2014-07-07 01:22:02 +02:00
|
|
|
flags &= ~ICMP_ECHOREPLY;
|
2014-05-30 21:32:10 +02:00
|
|
|
dev->d_len = 0;
|
|
|
|
|
|
|
|
/* Return the result to the caller */
|
|
|
|
|
|
|
|
pstate->png_result = OK;
|
|
|
|
pstate->png_seqno = ntohs(icmp->seqno);
|
|
|
|
goto end_wait;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check:
|
|
|
|
* If the outgoing packet is available (it may have been claimed
|
|
|
|
* by a sendto interrupt serving a different thread)
|
|
|
|
* -OR-
|
|
|
|
* If the output buffer currently contains unprocessed incoming
|
|
|
|
* data.
|
|
|
|
* -OR-
|
|
|
|
* If we have already sent the ECHO request
|
|
|
|
*
|
|
|
|
* In the first two cases, we will just have to wait for the next
|
|
|
|
* polling cycle.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (dev->d_sndlen <= 0 && /* Packet available */
|
2014-07-07 01:22:02 +02:00
|
|
|
(flags & ICMP_NEWDATA) == 0 && /* No incoming data */
|
2014-05-30 21:32:10 +02:00
|
|
|
!pstate->png_sent) /* Request not sent */
|
|
|
|
{
|
2014-06-25 17:12:47 +02:00
|
|
|
FAR struct icmp_iphdr_s *picmp = ICMPBUF;
|
2014-05-30 21:32:10 +02:00
|
|
|
|
|
|
|
/* We can send the ECHO request now.
|
|
|
|
*
|
|
|
|
* Format the ICMP ECHO request packet
|
|
|
|
*/
|
|
|
|
|
|
|
|
picmp->type = ICMP_ECHO_REQUEST;
|
|
|
|
picmp->icode = 0;
|
|
|
|
picmp->id = htons(pstate->png_id);
|
|
|
|
picmp->seqno = htons(pstate->png_seqno);
|
2015-01-14 21:47:40 +01:00
|
|
|
|
2014-05-30 21:32:10 +02:00
|
|
|
/* Add some easily verifiable data */
|
|
|
|
|
|
|
|
for (i = 0, ptr = ICMPDAT; i < pstate->png_datlen; i++)
|
|
|
|
{
|
|
|
|
*ptr++ = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Send the ICMP echo request. Note that d_sndlen is set to
|
|
|
|
* the size of the ICMP payload and does not include the size
|
|
|
|
* of the ICMP header.
|
|
|
|
*/
|
|
|
|
|
2016-06-20 19:59:15 +02:00
|
|
|
ninfo("Send ECHO request: seqno=%d\n", pstate->png_seqno);
|
2014-05-30 21:32:10 +02:00
|
|
|
|
|
|
|
dev->d_sndlen = pstate->png_datlen + 4;
|
2014-06-25 17:12:47 +02:00
|
|
|
icmp_send(dev, &pstate->png_addr);
|
2015-01-24 14:29:43 +01:00
|
|
|
|
2014-05-30 21:32:10 +02:00
|
|
|
pstate->png_sent = true;
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if the selected timeout has elapsed */
|
|
|
|
|
|
|
|
if (ping_timeout(pstate))
|
|
|
|
{
|
|
|
|
int failcode;
|
|
|
|
|
|
|
|
/* Check if this device is on the same network as the destination
|
|
|
|
* device.
|
|
|
|
*/
|
|
|
|
|
2015-01-15 19:19:44 +01:00
|
|
|
if (!net_ipv4addr_maskcmp(pstate->png_addr, dev->d_ipaddr, dev->d_netmask))
|
2014-05-30 21:32:10 +02:00
|
|
|
{
|
|
|
|
/* Destination address was not on the local network served by this
|
|
|
|
* device. If a timeout occurs, then the most likely reason is
|
|
|
|
* that the destination address is not reachable.
|
|
|
|
*/
|
|
|
|
|
2016-06-20 19:59:15 +02:00
|
|
|
nerr("ERROR:Not reachable\n");
|
2014-05-30 21:32:10 +02:00
|
|
|
failcode = -ENETUNREACH;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-06-20 19:59:15 +02:00
|
|
|
nerr("ERROR:Ping timeout\n");
|
2014-05-30 21:32:10 +02:00
|
|
|
failcode = -ETIMEDOUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Report the failure */
|
|
|
|
|
|
|
|
pstate->png_result = failcode;
|
|
|
|
goto end_wait;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Continue waiting */
|
|
|
|
}
|
|
|
|
|
|
|
|
return flags;
|
|
|
|
|
|
|
|
end_wait:
|
2016-06-20 19:59:15 +02:00
|
|
|
ninfo("Resuming\n");
|
2014-05-30 21:32:10 +02:00
|
|
|
|
|
|
|
/* Do not allow any further callbacks */
|
|
|
|
|
|
|
|
pstate->png_cb->flags = 0;
|
|
|
|
pstate->png_cb->priv = NULL;
|
|
|
|
pstate->png_cb->event = NULL;
|
|
|
|
|
|
|
|
/* Wake up the waiting thread */
|
|
|
|
|
|
|
|
sem_post(&pstate->png_sem);
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2014-07-01 02:15:59 +02:00
|
|
|
* Name: imcp_ping
|
2014-05-30 21:32:10 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Send a ECHO request and wait for the ECHO response
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* addr - The IP address of the peer to send the ICMP ECHO request to
|
|
|
|
* in network order.
|
|
|
|
* id - The ID to use in the ICMP ECHO request. This number should be
|
|
|
|
* unique; only ECHO responses with this matching ID will be
|
|
|
|
* processed (host order)
|
|
|
|
* seqno - The sequence number used in the ICMP ECHO request. NOT used
|
|
|
|
* to match responses (host order)
|
|
|
|
* dsecs - Wait up to this many deci-seconds for the ECHO response to be
|
|
|
|
* returned (host order).
|
|
|
|
*
|
|
|
|
* Return:
|
|
|
|
* seqno of received ICMP ECHO with matching ID (may be different
|
|
|
|
* from the seqno argument (may be a delayed response from an earlier
|
|
|
|
* ping with the same ID). Or a negated errno on any failure.
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* Called from the user level with interrupts enabled.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-01-15 19:19:44 +01:00
|
|
|
int icmp_ping(in_addr_t addr, uint16_t id, uint16_t seqno, uint16_t datalen,
|
|
|
|
int dsecs)
|
2014-05-30 21:32:10 +02:00
|
|
|
{
|
2015-05-27 19:39:44 +02:00
|
|
|
FAR struct net_driver_s *dev;
|
2014-05-30 21:32:10 +02:00
|
|
|
struct icmp_ping_s state;
|
2014-08-19 00:22:14 +02:00
|
|
|
#ifdef CONFIG_NET_ARP_SEND
|
|
|
|
int ret;
|
2015-05-27 17:26:00 +02:00
|
|
|
#endif
|
2015-10-04 23:28:54 +02:00
|
|
|
|
2015-05-27 17:26:00 +02:00
|
|
|
/* Get the device that will be used to route this ICMP ECHO request */
|
|
|
|
|
2015-05-27 19:39:44 +02:00
|
|
|
#ifdef CONFIG_NETDEV_MULTINIC
|
2015-05-29 23:16:11 +02:00
|
|
|
dev = netdev_findby_ipv4addr(INADDR_ANY, addr);
|
2015-05-27 19:39:44 +02:00
|
|
|
#else
|
|
|
|
dev = netdev_findby_ipv4addr(addr);
|
|
|
|
#endif
|
2015-05-27 17:26:00 +02:00
|
|
|
if (dev == 0)
|
|
|
|
{
|
2016-06-11 23:50:49 +02:00
|
|
|
nerr("ERROR: Not reachable\n");
|
2015-05-27 17:26:00 +02:00
|
|
|
return -ENETUNREACH;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_ARP_SEND
|
2014-08-19 00:22:14 +02:00
|
|
|
/* Make sure that the IP address mapping is in the ARP table */
|
|
|
|
|
|
|
|
ret = arp_send(addr);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
2016-06-11 23:50:49 +02:00
|
|
|
nerr("ERROR: Not reachable\n");
|
2014-08-19 00:22:14 +02:00
|
|
|
return -ENETUNREACH;
|
|
|
|
}
|
|
|
|
#endif
|
2014-05-30 21:32:10 +02:00
|
|
|
|
|
|
|
/* Initialize the state structure */
|
|
|
|
|
2016-11-03 19:17:02 +01:00
|
|
|
/* This semaphore is used for signaling and, hence, should not have
|
|
|
|
* priority inheritance enabled.
|
|
|
|
*/
|
|
|
|
|
2014-05-30 21:32:10 +02:00
|
|
|
sem_init(&state.png_sem, 0, 0);
|
2016-11-03 19:17:02 +01:00
|
|
|
sem_setprotocol(&state.png_sem, SEM_PRIO_NONE);
|
|
|
|
|
2014-05-30 21:32:10 +02:00
|
|
|
state.png_ticks = DSEC2TICK(dsecs); /* System ticks to wait */
|
|
|
|
state.png_result = -ENOMEM; /* Assume allocation failure */
|
|
|
|
state.png_addr = addr; /* Address of the peer to be ping'ed */
|
|
|
|
state.png_id = id; /* The ID to use in the ECHO request */
|
2015-01-23 21:06:08 +01:00
|
|
|
state.png_seqno = seqno; /* The seqno to use in the ECHO request */
|
2014-05-30 21:32:10 +02:00
|
|
|
state.png_datlen = datalen; /* The length of data to send in the ECHO request */
|
|
|
|
state.png_sent = false; /* ECHO request not yet sent */
|
|
|
|
|
2016-12-03 23:28:19 +01:00
|
|
|
net_lock();
|
2014-05-30 21:32:10 +02:00
|
|
|
state.png_time = clock_systimer();
|
|
|
|
|
|
|
|
/* Set up the callback */
|
|
|
|
|
2015-05-27 19:39:44 +02:00
|
|
|
state.png_cb = icmp_callback_alloc(dev);
|
2014-05-30 21:32:10 +02:00
|
|
|
if (state.png_cb)
|
|
|
|
{
|
2015-05-27 17:26:00 +02:00
|
|
|
state.png_cb->flags = (ICMP_POLL | ICMP_ECHOREPLY | NETDEV_DOWN);
|
2015-10-08 23:10:04 +02:00
|
|
|
state.png_cb->priv = (FAR void *)&state;
|
2014-05-30 21:32:10 +02:00
|
|
|
state.png_cb->event = ping_interrupt;
|
|
|
|
state.png_result = -EINTR; /* Assume sem-wait interrupted by signal */
|
|
|
|
|
|
|
|
/* Notify the device driver of the availability of TX data */
|
|
|
|
|
2015-05-27 19:39:44 +02:00
|
|
|
netdev_txnotify_dev(dev);
|
2014-05-30 21:32:10 +02:00
|
|
|
|
|
|
|
/* Wait for either the full round trip transfer to complete or
|
2014-06-26 22:23:21 +02:00
|
|
|
* for timeout to occur. (1) net_lockedwait will also terminate if a
|
2014-05-30 21:32:10 +02:00
|
|
|
* signal is received, (2) interrupts may be disabled! They will
|
|
|
|
* be re-enabled while the task sleeps and automatically
|
|
|
|
* re-enabled when the task restarts.
|
|
|
|
*/
|
|
|
|
|
2016-06-20 19:59:15 +02:00
|
|
|
ninfo("Start time: 0x%08x seqno: %d\n", state.png_time, seqno);
|
2014-06-26 22:23:21 +02:00
|
|
|
net_lockedwait(&state.png_sem);
|
2014-05-30 21:32:10 +02:00
|
|
|
|
2015-05-27 19:39:44 +02:00
|
|
|
icmp_callback_free(dev, state.png_cb);
|
2014-05-30 21:32:10 +02:00
|
|
|
}
|
|
|
|
|
2016-12-03 23:28:19 +01:00
|
|
|
net_unlock();
|
2014-05-30 21:32:10 +02:00
|
|
|
|
|
|
|
/* Return the negated error number in the event of a failure, or the
|
|
|
|
* sequence number of the ECHO reply on success.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!state.png_result)
|
|
|
|
{
|
2016-06-20 19:59:15 +02:00
|
|
|
ninfo("Return seqno=%d\n", state.png_seqno);
|
2014-05-30 21:32:10 +02:00
|
|
|
return (int)state.png_seqno;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-06-20 19:59:15 +02:00
|
|
|
nerr("ERROR: Return error=%d\n", -state.png_result);
|
2014-05-30 21:32:10 +02:00
|
|
|
return state.png_result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_NET_ICMP && CONFIG_NET_ICMP_PING ... */
|