diff --git a/include/nuttx/net/netstats.h b/include/nuttx/net/netstats.h index e5d96bf95f2..a624360dc75 100644 --- a/include/nuttx/net/netstats.h +++ b/include/nuttx/net/netstats.h @@ -50,9 +50,6 @@ #include -#ifdef CONFIG_NET_PKT -# include -#endif #ifdef CONFIG_NET_TCP # include #endif diff --git a/include/nuttx/net/pkt.h b/include/nuttx/net/pkt.h index 55e04db5158..2c3515eb0b8 100644 --- a/include/nuttx/net/pkt.h +++ b/include/nuttx/net/pkt.h @@ -46,32 +46,12 @@ #include -#include -#include - #include /**************************************************************************** * Public Type Definitions ****************************************************************************/ -/* Representation of a uIP packet socket connection */ - -struct devif_callback_s; /* Forward reference */ - -struct pkt_conn_s -{ - dq_entry_t node; /* Supports a double linked list */ - uint8_t lmac[6]; /* The local Ethernet address in network byte order */ - uint8_t ifindex; - uint16_t proto; - uint8_t crefs; /* Reference counts on this instance */ - - /* Defines the list of packet callbacks */ - - struct devif_callback_s *list; -}; - /**************************************************************************** * Public Data ****************************************************************************/ @@ -79,25 +59,12 @@ struct pkt_conn_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 +/* This function provides the interface between Ethernet device drivers and + * packet socket logic. All frames that are received should be provided to + * pkt_input() prior to other routing. */ -FAR struct pkt_conn_s *pkt_alloc(void); - -/* Free a connection structure that is no longer in use. This should - * be done by the implementation of close() - */ - -void pkt_free(FAR struct pkt_conn_s *conn); -void pkt_poll(FAR struct net_driver_s *dev, FAR struct pkt_conn_s *conn); +struct net_driver_s; /* Forward reference */ int pkt_input(FAR struct net_driver_s *dev); #endif /* __INCLUDE_NUTTX_NET_PKT_H */ diff --git a/net/pkt/pkt.h b/net/pkt/pkt.h index dee1fecbf33..61fd45387bb 100644 --- a/net/pkt/pkt.h +++ b/net/pkt/pkt.h @@ -59,6 +59,23 @@ * Public Type Definitions ****************************************************************************/ +/* Representation of a uIP packet socket connection */ + +struct devif_callback_s; /* Forward reference */ + +struct pkt_conn_s +{ + dq_entry_t node; /* Supports a double linked list */ + uint8_t lmac[6]; /* The local Ethernet address in network byte order */ + uint8_t ifindex; + uint16_t proto; + uint8_t crefs; /* Reference counts on this instance */ + + /* Defines the list of packet callbacks */ + + struct devif_callback_s *list; +}; + /**************************************************************************** * Public Data ****************************************************************************/ @@ -76,24 +93,127 @@ extern "C" ****************************************************************************/ struct eth_hdr_s; /* Forward reference */ -struct pkt_conn_s; /* Forward refernce */ /* Defined in pkt_conn.c ****************************************************/ +/**************************************************************************** + * Name: pkt_initialize() + * + * Description: + * Initialize the packet socket connection structures. Called once and + * only from the UIP layer. + * + ****************************************************************************/ void pkt_initialize(void); + +/**************************************************************************** + * Name: pkt_palloc() + * + * Description: + * Allocate a new, uninitialized packet socket connection structure. This + * is normally something done by the implementation of the socket() API + * + ****************************************************************************/ + FAR struct pkt_conn_s *pkt_alloc(void); + +/**************************************************************************** + * Name: pkt_free() + * + * Description: + * Free a packet socket connection structure that is no longer in use. + * This should be done by the implementation of close(). + * + ****************************************************************************/ + void pkt_free(FAR struct pkt_conn_s *conn); + +/**************************************************************************** + * Name: pkt_active() + * + * Description: + * Find a connection structure that is the appropriate + * connection to be used with the provided Ethernet header + * + * Assumptions: + * This function is called from UIP logic at interrupt level + * + ****************************************************************************/ + struct pkt_conn_s *pkt_active(FAR struct eth_hdr_s *buf); + +/**************************************************************************** + * Name: pkt_nextconn() + * + * Description: + * Traverse the list of allocated packet connections + * + * Assumptions: + * This function is called from UIP logic at interrupt level (or with + * interrupts disabled). + * + ****************************************************************************/ + struct pkt_conn_s *pkt_nextconn(FAR struct pkt_conn_s *conn); /* Defined in pkt_callback.c ************************************************/ +/**************************************************************************** + * Function: pkt_callback + * + * Description: + * Inform the application holding the packet 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 pkt_callback(FAR struct net_driver_s *dev, FAR struct pkt_conn_s *conn, uint16_t flags); /* Defined in pkt_input.c ***************************************************/ +/**************************************************************************** + * Name: pkt_input + * + * Description: + * Handle incoming packet input + * + * Parameters: + * dev - The device driver structure containing the received 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 recv in place to catch the packet yet. + * + * Assumptions: + * Called from the interrupt level or with interrupts disabled. + * + ****************************************************************************/ + +/* pkt_input() is prototyped in include/nuttx/net/pkt.h */ /* Defined in pkt_poll.c ****************************************************/ +/**************************************************************************** + * Name: pkt_poll + * + * Description: + * Poll a packet "connection" structure for availability of TX data + * + * Parameters: + * dev - The device driver structure to use in the send operation + * conn - The packet "connection" to poll for TX data + * + * Return: + * None + * + * Assumptions: + * Called from the interrupt level or with interrupts disabled. + * + ****************************************************************************/ void pkt_poll(FAR struct net_driver_s *dev, FAR struct pkt_conn_s *conn); @@ -158,7 +278,6 @@ struct socket; ssize_t psock_pkt_send(FAR struct socket *psock, FAR const void *buf, size_t len); - #undef EXTERN #ifdef __cplusplus } diff --git a/net/pkt/pkt_callback.c b/net/pkt/pkt_callback.c index dcc9e2c597e..443cc8accca 100644 --- a/net/pkt/pkt_callback.c +++ b/net/pkt/pkt_callback.c @@ -45,7 +45,6 @@ #include #include -#include #include "devif/devif.h" #include "pkt/pkt.h" diff --git a/net/pkt/pkt_conn.c b/net/pkt/pkt_conn.c index 471de1d3b48..50a71c0c841 100644 --- a/net/pkt/pkt_conn.c +++ b/net/pkt/pkt_conn.c @@ -54,7 +54,6 @@ #include #include #include -#include #include "devif/devif.h" #include "pkt/pkt.h" @@ -139,7 +138,8 @@ void pkt_initialize(void) * Name: pkt_palloc() * * Description: - * Alloc a new, uninitialized packet socket connection structure. + * Allocate a new, uninitialized packet socket connection structure. This + * is normally something done by the implementation of the socket() API * ****************************************************************************/ diff --git a/net/pkt/pkt_poll.c b/net/pkt/pkt_poll.c index 4701456be6d..130ca5a9408 100644 --- a/net/pkt/pkt_poll.c +++ b/net/pkt/pkt_poll.c @@ -50,7 +50,6 @@ #include #include #include -#include #include "devif/devif.h" #include "pkt/pkt.h" diff --git a/net/pkt/pkt_send.c b/net/pkt/pkt_send.c index 1d3f94f7fd4..5e548fcef8d 100644 --- a/net/pkt/pkt_send.c +++ b/net/pkt/pkt_send.c @@ -56,7 +56,6 @@ #include #include #include -#include #include "netdev/netdev.h" #include "devif/devif.h" diff --git a/net/socket/bind.c b/net/socket/bind.c index f399d3c991a..2a6739dd50b 100644 --- a/net/socket/bind.c +++ b/net/socket/bind.c @@ -51,12 +51,12 @@ #include #include -#include #include "socket/socket.h" #include "netdev/netdev.h" #include "tcp/tcp.h" #include "udp/udp.h" +#include "pkt/pkt.h" /**************************************************************************** * Private Functions diff --git a/net/socket/net_close.c b/net/socket/net_close.c index 503dbab156a..0fe973c0e13 100644 --- a/net/socket/net_close.c +++ b/net/socket/net_close.c @@ -52,7 +52,6 @@ #include #include #include -#include #ifdef CONFIG_NET_SOLINGER # include diff --git a/net/socket/recvfrom.c b/net/socket/recvfrom.c index fbf03f9c7bf..388281a289d 100644 --- a/net/socket/recvfrom.c +++ b/net/socket/recvfrom.c @@ -61,7 +61,6 @@ #include #include #include -#include #include "netdev/netdev.h" #include "devif/devif.h" @@ -70,7 +69,6 @@ #include "pkt/pkt.h" #include "socket/socket.h" - /**************************************************************************** * Definitions ****************************************************************************/ diff --git a/net/socket/socket.c b/net/socket/socket.c index 2c7e7a0719f..f9af58fd183 100644 --- a/net/socket/socket.c +++ b/net/socket/socket.c @@ -47,7 +47,6 @@ #include #include -#include #include "socket/socket.h" #include "tcp/tcp.h"