summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/netutils/dhcpc/dhcpc.c1
-rw-r--r--nuttx/include/nuttx/net/udp.h73
-rw-r--r--nuttx/net/socket/getsockname.c3
-rw-r--r--nuttx/net/socket/net_clone.c1
-rw-r--r--nuttx/net/socket/net_close.c1
-rw-r--r--nuttx/net/udp/udp.h193
-rw-r--r--nuttx/net/udp/udp_conn.c14
7 files changed, 202 insertions, 84 deletions
diff --git a/apps/netutils/dhcpc/dhcpc.c b/apps/netutils/dhcpc/dhcpc.c
index 879cab1f8..1b75cde9b 100644
--- a/apps/netutils/dhcpc/dhcpc.c
+++ b/apps/netutils/dhcpc/dhcpc.c
@@ -123,7 +123,6 @@ struct dhcp_msg
struct dhcpc_state_s
{
- struct udp_conn_s *ds_conn;
const void *ds_macaddr;
int ds_maclen;
int sockfd;
diff --git a/nuttx/include/nuttx/net/udp.h b/nuttx/include/nuttx/net/udp.h
index 094fc381a..3ed188cd9 100644
--- a/nuttx/include/nuttx/net/udp.h
+++ b/nuttx/include/nuttx/net/udp.h
@@ -68,26 +68,6 @@
/****************************************************************************
* Public Type Definitions
****************************************************************************/
-
-/* Representation of a uIP UDP connection */
-
-struct net_driver_s; /* Forward reference */
-struct devif_callback_s; /* Forward reference */
-
-struct udp_conn_s
-{
- dq_entry_t node; /* Supports a doubly linked list */
- net_ipaddr_t ripaddr; /* The IP address of the remote peer */
- uint16_t lport; /* The local port number in network byte order */
- uint16_t rport; /* The remote port number in network byte order */
- uint8_t ttl; /* Default time-to-live */
- uint8_t crefs; /* Reference counts on this instance */
-
- /* Defines the list of UDP callbacks */
-
- struct devif_callback_s *list;
-};
-
/* The UDP and IP headers */
struct udp_iphdr_s
@@ -152,57 +132,4 @@ struct udp_stats_s
* Public Function Prototypes
****************************************************************************/
-/* uIP application functions
- *
- * Functions used by an application running of top of uIP. This includes
- * functions for opening and closing connections, sending and receiving
- * data, etc.
- *
- * Find a free connection structure and allocate it for use. This is
- * normally something done by the implementation of the socket() API
- */
-
-FAR struct udp_conn_s *udp_alloc(void);
-
-/* Free a connection structure that is no longer in use. This should
- * be done by the implementation of close()
- */
-
-void udp_free(FAR struct udp_conn_s *conn);
-
-/* Bind a UDP connection to a local address */
-
-#ifdef CONFIG_NET_IPv6
-int udp_bind(FAR struct udp_conn_s *conn,
- FAR const struct sockaddr_in6 *addr);
-#else
-int udp_bind(FAR struct udp_conn_s *conn,
- FAR const struct sockaddr_in *addr);
-#endif
-
-/* This function sets up a new UDP connection. The function will
- * automatically allocate an unused local port for the new
- * connection. However, another port can be chosen by using the
- * udp_bind() call, after the udp_connect() function has been
- * called.
- *
- * This function is called as part of the implementation of sendto
- * and recvfrom.
- *
- * addr The address of the remote host.
- */
-
-#ifdef CONFIG_NET_IPv6
-int udp_connect(FAR struct udp_conn_s *conn,
- FAR const struct sockaddr_in6 *addr);
-#else
-int udp_connect(FAR struct udp_conn_s *conn,
- FAR const struct sockaddr_in *addr);
-#endif
-
-/* Enable/disable UDP callbacks on a connection */
-
-void udp_enable(FAR struct udp_conn_s *conn);
-void udp_disable(FAR struct udp_conn_s *conn);
-
#endif /* __INCLUDE_NUTTX_NET_UDP_H */
diff --git a/nuttx/net/socket/getsockname.c b/nuttx/net/socket/getsockname.c
index 45378f823..5b799b48c 100644
--- a/nuttx/net/socket/getsockname.c
+++ b/nuttx/net/socket/getsockname.c
@@ -50,8 +50,9 @@
#include <nuttx/net/tcp.h>
#include <nuttx/net/udp.h>
-#include "socket/socket.h"
#include "netdev/netdev.h"
+#include "udp/udp.h"
+#include "socket/socket.h"
#ifdef CONFIG_NET
diff --git a/nuttx/net/socket/net_clone.c b/nuttx/net/socket/net_clone.c
index e8bcba5ae..42deb00ed 100644
--- a/nuttx/net/socket/net_clone.c
+++ b/nuttx/net/socket/net_clone.c
@@ -49,6 +49,7 @@
#include <nuttx/net/tcp.h>
#include <nuttx/net/udp.h>
+#include "udp/udp.h"
#include "socket/socket.h"
/****************************************************************************
diff --git a/nuttx/net/socket/net_close.c b/nuttx/net/socket/net_close.c
index 0fe973c0e..68dd3544b 100644
--- a/nuttx/net/socket/net_close.c
+++ b/nuttx/net/socket/net_close.c
@@ -60,6 +60,7 @@
#include "netdev/netdev.h"
#include "devif/devif.h"
#include "tcp/tcp.h"
+#include "udp/udp.h"
#include "pkt/pkt.h"
#include "socket/socket.h"
diff --git a/nuttx/net/udp/udp.h b/nuttx/net/udp/udp.h
index 6d2c636b0..fd46eb310 100644
--- a/nuttx/net/udp/udp.h
+++ b/nuttx/net/udp/udp.h
@@ -59,6 +59,24 @@
* Public Type Definitions
****************************************************************************/
+/* Representation of a uIP UDP connection */
+
+struct devif_callback_s; /* Forward reference */
+
+struct udp_conn_s
+{
+ dq_entry_t node; /* Supports a doubly linked list */
+ net_ipaddr_t ripaddr; /* The IP address of the remote peer */
+ uint16_t lport; /* The local port number in network byte order */
+ uint16_t rport; /* The remote port number in network byte order */
+ uint8_t ttl; /* Default time-to-live */
+ uint8_t crefs; /* Reference counts on this instance */
+
+ /* Defines the list of UDP callbacks */
+
+ struct devif_callback_s *list;
+};
+
/****************************************************************************
* Public Data
****************************************************************************/
@@ -75,28 +93,197 @@ extern "C"
* Public Function Prototypes
****************************************************************************/
-/* Defined in udp_conn.c ****************************************************/
-
struct udp_iphdr_s; /* Forward reference */
-struct udp_conn_s; /* Forward reference */
+struct net_driver_s; /* Forward reference */
+
+/* Defined in udp_conn.c ****************************************************/
+/****************************************************************************
+ * Name: udp_initialize()
+ *
+ * Description:
+ * Initialize the UDP connection structures. Called once and only from
+ * the UIP layer.
+ *
+ ****************************************************************************/
void udp_initialize(void);
+
+/****************************************************************************
+ * Name: udp_alloc()
+ *
+ * Description:
+ * Allocate a new, uninitialized UDP connection structure. This is
+ * normally something done by the implementation of the socket() API
+ *
+ ****************************************************************************/
+
+FAR struct udp_conn_s *udp_alloc(void);
+
+/****************************************************************************
+ * Name: udp_free()
+ *
+ * Description:
+ * Free a UDP connection structure that is no longer in use. This should be
+ * done by the implementation of close().
+ *
+ ****************************************************************************/
+
+void udp_free(FAR struct udp_conn_s *conn);
+
+/****************************************************************************
+ * Name: udp_active()
+ *
+ * Description:
+ * Find a connection structure that is the appropriate
+ * connection to be used within the provided TCP/IP header
+ *
+ * Assumptions:
+ * This function is called from UIP logic at interrupt level
+ *
+ ****************************************************************************/
+
FAR struct udp_conn_s *udp_active(FAR struct udp_iphdr_s *buf);
+
+/****************************************************************************
+ * Name: udp_nextconn()
+ *
+ * Description:
+ * Traverse the list of allocated UDP connections
+ *
+ * Assumptions:
+ * This function is called from UIP logic at interrupt level (or with
+ * interrupts disabled).
+ *
+ ****************************************************************************/
+
FAR struct udp_conn_s *udp_nextconn(FAR struct udp_conn_s *conn);
+/****************************************************************************
+ * Name: udp_bind()
+ *
+ * Description:
+ * This function implements the UIP specific parts of the standard UDP
+ * bind() operation.
+ *
+ * Assumptions:
+ * This function is called from normal user level code.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_NET_IPv6
+int udp_bind(FAR struct udp_conn_s *conn, FAR const struct sockaddr_in6 *addr);
+#else
+int udp_bind(FAR struct udp_conn_s *conn, FAR const struct sockaddr_in *addr);
+#endif
+
+/****************************************************************************
+ * Name: udp_connect()
+ *
+ * Description:
+ * This function sets up a new UDP connection. The function will
+ * automatically allocate an unused local port for the new
+ * connection. However, another port can be chosen by using the
+ * udp_bind() call, after the udp_connect() function has been
+ * called.
+ *
+ * This function is called as part of the implementation of sendto
+ * and recvfrom.
+ *
+ * Input Parameters:
+ * conn - A reference to UDP connection structure
+ * addr - The address of the remote host.
+ *
+ * Assumptions:
+ * This function is called user code. Interrupts may be enabled.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_NET_IPv6
+int udp_connect(FAR struct udp_conn_s *conn,
+ FAR const struct sockaddr_in6 *addr);
+#else
+int udp_connect(FAR struct udp_conn_s *conn,
+ FAR const struct sockaddr_in *addr);
+#endif
+
/* Defined in udp_poll.c ****************************************************/
+/****************************************************************************
+ * Name: udp_poll
+ *
+ * Description:
+ * Poll a UDP "connection" structure for availability of TX data
+ *
+ * Parameters:
+ * dev - The device driver structure to use in the send operation
+ * conn - The UDP "connection" to poll for TX data
+ *
+ * Return:
+ * None
+ *
+ * Assumptions:
+ * Called from the interrupt level or with interrupts disabled.
+ *
+ ****************************************************************************/
void udp_poll(FAR struct net_driver_s *dev, FAR struct udp_conn_s *conn);
/* Defined in udp_send.c ****************************************************/
+/****************************************************************************
+ * Name: udp_send
+ *
+ * Description:
+ * Set-up to send a UDP packet
+ *
+ * Parameters:
+ * dev - The device driver structure to use in the send operation
+ * conn - The UDP "connection" structure holding port information
+ *
+ * Return:
+ * None
+ *
+ * Assumptions:
+ * Called from the interrupt level or with interrupts disabled.
+ *
+ ****************************************************************************/
void udp_send(FAR struct net_driver_s *dev, FAR struct udp_conn_s *conn);
/* Defined in udp_input.c ***************************************************/
+/****************************************************************************
+ * Name: udp_input
+ *
+ * Description:
+ * Handle incoming UDP input
+ *
+ * Parameters:
+ * dev - The device driver structure containing the received UDP packet
+ *
+ * Return:
+ * OK The packet has been processed and can be deleted
+ * ERROR Hold the packet and try again later. There is a listening socket
+ * but no receive in place to catch the packet yet.
+ *
+ * Assumptions:
+ * Called from the interrupt level or with interrupts disabled.
+ *
+ ****************************************************************************/
int udp_input(FAR struct net_driver_s *dev);
/* Defined in udp_callback.c ************************************************/
+/****************************************************************************
+ * Function: udp_callback
+ *
+ * Description:
+ * Inform the application holding the UDP socket of a change in state.
+ *
+ * Returned Value:
+ * OK if packet has been processed, otherwise ERROR.
+ *
+ * Assumptions:
+ * This function is called at the interrupt level with interrupts disabled.
+ *
+ ****************************************************************************/
uint16_t udp_callback(FAR struct net_driver_s *dev,
FAR struct udp_conn_s *conn, uint16_t flags);
diff --git a/nuttx/net/udp/udp_conn.c b/nuttx/net/udp/udp_conn.c
index 51c9a1fc5..ffe8cb1a8 100644
--- a/nuttx/net/udp/udp_conn.c
+++ b/nuttx/net/udp/udp_conn.c
@@ -230,7 +230,8 @@ void udp_initialize(void)
* Name: udp_alloc()
*
* Description:
- * Allocate a new, uninitialized UDP connection structure.
+ * Allocate a new, uninitialized UDP connection structure. This is
+ * normally something done by the implementation of the socket() API
*
****************************************************************************/
@@ -264,8 +265,7 @@ FAR struct udp_conn_s *udp_alloc(void)
*
* Description:
* Free a UDP connection structure that is no longer in use. This should be
- * done by the implementation of close(). udp_disable must have been
- * previously called.
+ * done by the implementation of close().
*
****************************************************************************/
@@ -423,10 +423,12 @@ int udp_bind(FAR struct udp_conn_s *conn, FAR const struct sockaddr_in *addr)
* udp_bind() call, after the udp_connect() function has been
* called.
*
- * udp_enable() must be called before the connection is made active (i.e.,
- * is eligible for callbacks.
+ * This function is called as part of the implementation of sendto
+ * and recvfrom.
*
- * addr The address of the remote host.
+ * Input Parameters:
+ * conn - A reference to UDP connection structure
+ * addr - The address of the remote host.
*
* Assumptions:
* This function is called user code. Interrupts may be enabled.