mirror of
https://github.com/apache/nuttx.git
synced 2026-03-24 15:45:48 +08:00
Finished partitioning uip.c (now system is broken)
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@375 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
@@ -74,7 +74,9 @@ int open(const char *path, int oflags, ...)
|
||||
struct filelist *list;
|
||||
FAR struct inode *inode;
|
||||
const char *relpath = NULL;
|
||||
#ifdef CONFIG_FILE_MODE
|
||||
mode_t mode = 0666;
|
||||
#endif
|
||||
int ret;
|
||||
int fd;
|
||||
|
||||
|
||||
@@ -57,28 +57,20 @@
|
||||
* Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* The following flags are passed as an argument to the uip_interrupt()
|
||||
/* The following flags are passed as an argument to the uip_poll()
|
||||
* function. They are used to distinguish between the two cases where
|
||||
* uip_interrupt() is called. It can be called either because we have
|
||||
* uip_poll() is called. It can be called either because we have
|
||||
* incoming data that should be processed, or because the periodic
|
||||
* timer has fired. These values are never used directly, but only in
|
||||
* the macrose defined in this file.
|
||||
* timer has fired.
|
||||
*
|
||||
* UIP_DRV_RECEIVE - There is new incoming data from the driver in the d_buf
|
||||
* field of the uip_driver_s structure. The length of the
|
||||
* new data is provided in the d_len field of the
|
||||
* uip_driver_s structure.
|
||||
* UIP_DRV_TIMER - Called periodically from driver to service timeout-
|
||||
* related activities to and to get timeout-related
|
||||
* responses (e.g., reset)
|
||||
* UIP_DRV_POLL - Poll TCP for data to be transmitted
|
||||
* UIP_DRV_UDPPOLL - Poll for UDP data to be transmitted. This value is used
|
||||
* internally by the uip_poll logic.
|
||||
*/
|
||||
|
||||
#define UIP_DRV_RECEIVE 1
|
||||
#define UIP_DRV_TIMER 2
|
||||
#define UIP_DRV_POLL 3
|
||||
#define UIP_DRV_TIMER 1
|
||||
#define UIP_DRV_POLL 2
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
@@ -214,7 +206,7 @@ struct uip_driver_s
|
||||
*
|
||||
* dev->d_len = devicedriver_poll();
|
||||
* if(dev->d_len > 0) {
|
||||
* uip_input();
|
||||
* uip_input(dev);
|
||||
* if(dev->d_len > 0) {
|
||||
* devicedriver_send();
|
||||
* }
|
||||
@@ -230,7 +222,7 @@ struct uip_driver_s
|
||||
* if(dev->d_len > 0) {
|
||||
* if(BUF->type == HTONS(UIP_ETHTYPE_IP)) {
|
||||
* uip_arp_ipin();
|
||||
* uip_input();
|
||||
* uip_input(dev);
|
||||
* if(dev->d_len > 0) {
|
||||
* uip_arp_out();
|
||||
* devicedriver_send();
|
||||
@@ -243,12 +235,12 @@ struct uip_driver_s
|
||||
* }
|
||||
*/
|
||||
|
||||
#define uip_input(dev) uip_interrupt(dev, UIP_DRV_RECEIVE)
|
||||
extern void uip_input(struct uip_driver_s *dev);
|
||||
|
||||
/* Polling of connections.
|
||||
*
|
||||
* This function will traverse each active uIP connection structure and
|
||||
* perform uip_interrupt with the specified event. After each polling each
|
||||
* perform uip_input with the specified event. After each polling each
|
||||
* active uIP connection structure, this function will call the provided
|
||||
* callback function if the poll resulted in new data to be send. The poll
|
||||
* will continue until all connections have been polled or until the user-
|
||||
@@ -305,37 +297,29 @@ extern int uip_poll(struct uip_driver_s *dev, uip_poll_callback_t callback, int
|
||||
|
||||
#define uip_periodic(dev,cb) uip_poll(dev, db, UIP_DRV_TIMER);
|
||||
|
||||
/* Architecure support
|
||||
*
|
||||
* The actual uIP function which does all the work. Called from the
|
||||
* interrupt level by a device driver.
|
||||
*/
|
||||
|
||||
extern void uip_interrupt(struct uip_driver_s *dev, uint8 event);
|
||||
|
||||
/* By defining UIP_ARCH_CHKSUM, the architecture can replace the following
|
||||
* functions with hardware assisted solutions.
|
||||
*/
|
||||
|
||||
/* Carry out a 32-bit addition.
|
||||
*
|
||||
* Because not all architectures for which uIP is intended has native
|
||||
* 32-bit arithmetic, uIP uses an external C function for doing the
|
||||
* required 32-bit additions in the TCP protocol processing. This
|
||||
* function should add the two arguments and place the result in the
|
||||
* global variable uip_acc32.
|
||||
* op32 - A pointer to a 4-byte array representing a 32-bit
|
||||
* integer in network byte order (big endian). This value may not
|
||||
* be word aligned.
|
||||
*
|
||||
* Note: The 32-bit integer pointed to by the op32 parameter and the
|
||||
* result in the uip_acc32 variable are in network byte order (big
|
||||
* endian).
|
||||
* For uip_incr32, the value pointed to by op32 is modified in place
|
||||
* For uip_add32, the value pointed to by op32 is unmodified
|
||||
*
|
||||
* op16 - A 16-bit integer in host byte order.
|
||||
*
|
||||
* op32 A pointer to a 4-byte array representing a 32-bit
|
||||
* integer in network byte order (big endian).
|
||||
* sum - The location to return the result (32-bit, network byte order,
|
||||
* possibly unaligned).
|
||||
*
|
||||
* op16 A 16-bit integer in host byte order.
|
||||
* uip_add32 only.
|
||||
*/
|
||||
|
||||
extern void uip_add32(uint8 *op32, uint16 op16);
|
||||
extern void uip_add32(const uint8 *op32, uint16 op16, uint8 *sum);
|
||||
extern void uip_incr32(uint8 *op32, uint16 op16);
|
||||
|
||||
/* Calculate the Internet checksum over a buffer.
|
||||
*
|
||||
|
||||
@@ -222,55 +222,54 @@ struct uip_stats
|
||||
{
|
||||
struct
|
||||
{
|
||||
uip_stats_t drop; /* Number of dropped packets at the IP layer. */
|
||||
uip_stats_t recv; /* Number of received packets at the IP layer. */
|
||||
uip_stats_t sent; /* Number of sent packets at the IP layer. */
|
||||
uip_stats_t vhlerr; /* Number of packets dropped due to wrong
|
||||
IP version or header length. */
|
||||
uip_stats_t hblenerr; /* Number of packets dropped due to wrong
|
||||
IP length, high byte. */
|
||||
uip_stats_t lblenerr; /* Number of packets dropped due to wrong
|
||||
IP length, low byte. */
|
||||
uip_stats_t fragerr; /* Number of packets dropped since they
|
||||
were IP fragments. */
|
||||
uip_stats_t chkerr; /* Number of packets dropped due to IP
|
||||
checksum errors. */
|
||||
uip_stats_t protoerr; /* Number of packets dropped since they
|
||||
were neither ICMP, UDP nor TCP. */
|
||||
} ip; /* IP statistics. */
|
||||
uip_stats_t drop; /* Number of dropped packets at the IP layer. */
|
||||
uip_stats_t recv; /* Number of received packets at the IP layer. */
|
||||
uip_stats_t sent; /* Number of sent packets at the IP layer. */
|
||||
uip_stats_t vhlerr; /* Number of packets dropped due to wrong
|
||||
IP version or header length. */
|
||||
uip_stats_t hblenerr; /* Number of packets dropped due to wrong
|
||||
IP length, high byte. */
|
||||
uip_stats_t lblenerr; /* Number of packets dropped due to wrong
|
||||
IP length, low byte. */
|
||||
uip_stats_t fragerr; /* Number of packets dropped since they
|
||||
were IP fragments. */
|
||||
uip_stats_t chkerr; /* Number of packets dropped due to IP
|
||||
checksum errors. */
|
||||
uip_stats_t protoerr; /* Number of packets dropped since they
|
||||
were neither ICMP, UDP nor TCP. */
|
||||
} ip; /* IP statistics. */
|
||||
|
||||
struct
|
||||
{
|
||||
uip_stats_t drop; /* Number of dropped ICMP packets. */
|
||||
uip_stats_t recv; /* Number of received ICMP packets. */
|
||||
uip_stats_t sent; /* Number of sent ICMP packets. */
|
||||
uip_stats_t typeerr; /* Number of ICMP packets with a wrong type. */
|
||||
} icmp; /* ICMP statistics. */
|
||||
uip_stats_t drop; /* Number of dropped ICMP packets. */
|
||||
uip_stats_t recv; /* Number of received ICMP packets. */
|
||||
uip_stats_t sent; /* Number of sent ICMP packets. */
|
||||
uip_stats_t typeerr; /* Number of ICMP packets with a wrong type. */
|
||||
} icmp; /* ICMP statistics. */
|
||||
|
||||
struct
|
||||
|
||||
{
|
||||
uip_stats_t drop; /* Number of dropped TCP segments. */
|
||||
uip_stats_t recv; /* Number of recived TCP segments. */
|
||||
uip_stats_t sent; /* Number of sent TCP segments. */
|
||||
uip_stats_t chkerr; /* Number of TCP segments with a bad checksum. */
|
||||
uip_stats_t ackerr; /* Number of TCP segments with a bad ACK number. */
|
||||
uip_stats_t rst; /* Number of recevied TCP RST (reset) segments. */
|
||||
uip_stats_t rexmit; /* Number of retransmitted TCP segments. */
|
||||
uip_stats_t syndrop; /* Number of dropped SYNs due to too few
|
||||
connections was avaliable. */
|
||||
uip_stats_t synrst; /* Number of SYNs for closed ports,
|
||||
triggering a RST. */
|
||||
} tcp; /* TCP statistics. */
|
||||
uip_stats_t drop; /* Number of dropped TCP segments. */
|
||||
uip_stats_t recv; /* Number of recived TCP segments. */
|
||||
uip_stats_t sent; /* Number of sent TCP segments. */
|
||||
uip_stats_t chkerr; /* Number of TCP segments with a bad checksum. */
|
||||
uip_stats_t ackerr; /* Number of TCP segments with a bad ACK number. */
|
||||
uip_stats_t rst; /* Number of recevied TCP RST (reset) segments. */
|
||||
uip_stats_t rexmit; /* Number of retransmitted TCP segments. */
|
||||
uip_stats_t syndrop; /* Number of dropped SYNs due to too few
|
||||
connections was avaliable. */
|
||||
uip_stats_t synrst; /* Number of SYNs for closed ports, triggering a RST. */
|
||||
} tcp; /* TCP statistics. */
|
||||
|
||||
#ifdef CONFIG_NET_UDP
|
||||
struct
|
||||
{
|
||||
uip_stats_t drop; /* Number of dropped UDP segments. */
|
||||
uip_stats_t recv; /* Number of recived UDP segments. */
|
||||
uip_stats_t sent; /* Number of sent UDP segments. */
|
||||
uip_stats_t chkerr; /* Number of UDP segments with a bad checksum. */
|
||||
} udp; /* UDP statistics. */
|
||||
uip_stats_t drop; /* Number of dropped UDP segments. */
|
||||
uip_stats_t recv; /* Number of recived UDP segments. */
|
||||
uip_stats_t sent; /* Number of sent UDP segments. */
|
||||
uip_stats_t chkerr; /* Number of UDP segments with a bad checksum. */
|
||||
} udp; /* UDP statistics. */
|
||||
#endif /* CONFIG_NET_UDP */
|
||||
};
|
||||
|
||||
@@ -282,28 +281,29 @@ struct uip_tcpip_hdr
|
||||
|
||||
/* IPv6 Ip header. */
|
||||
|
||||
uint8 vtc;
|
||||
uint8 tcflow;
|
||||
uint16 flow;
|
||||
uint8 len[2];
|
||||
uint8 proto, ttl;
|
||||
uip_ip6addr_t srcipaddr;
|
||||
uip_ip6addr_t destipaddr;
|
||||
uint8 vtc; /* Bits 0-3: version, bits 4-7: traffic class (MS) */
|
||||
uint8 tcf; /* Bits 0-3: traffic class (LS), 4-bits: flow label (MS) */
|
||||
uint16 flow; /* 16-bit flow label (LS) */
|
||||
uint8 len[2]; /* 16-bit Payload length */
|
||||
uint8 proto; /* 8-bit Next header (same as IPv4 protocol field) */
|
||||
uint8 ttl; /* 8-bit Hop limit (like IPv4 TTL field) */
|
||||
uip_ip6addr_t srcipaddr; /* 128-bit Source address */
|
||||
uip_ip6addr_t destipaddr; /* 128-bit Destination address */
|
||||
|
||||
#else /* CONFIG_NET_IPv6 */
|
||||
|
||||
/* IPv4 IP header. */
|
||||
|
||||
uint8 vhl; /* 8-bit Version (4) and header length (5 or 6) */
|
||||
uint8 tos; /* 8-bit Type of service (e.g., 6=TCP) */
|
||||
uint8 len[2]; /* 16-bit Total length */
|
||||
uint8 ipid[2]; /* 16-bit Identification */
|
||||
uint8 ipoffset[2]; /* 16-bit IP flags + fragment offset */
|
||||
uint8 ttl; /* 8-bit Time to Live */
|
||||
uint8 proto; /* 8-bit Protocol */
|
||||
uint16 ipchksum; /* 16-bit Header checksum */
|
||||
uint16 srcipaddr[2]; /* 32-bit Source IP address */
|
||||
uint16 destipaddr[2]; /* 32-bit Destination IP address */
|
||||
uint8 vhl; /* 8-bit Version (4) and header length (5 or 6) */
|
||||
uint8 tos; /* 8-bit Type of service (e.g., 6=TCP) */
|
||||
uint8 len[2]; /* 16-bit Total length */
|
||||
uint8 ipid[2]; /* 16-bit Identification */
|
||||
uint8 ipoffset[2]; /* 16-bit IP flags + fragment offset */
|
||||
uint8 ttl; /* 8-bit Time to Live */
|
||||
uint8 proto; /* 8-bit Protocol */
|
||||
uint16 ipchksum; /* 16-bit Header checksum */
|
||||
uint16 srcipaddr[2]; /* 32-bit Source IP address */
|
||||
uint16 destipaddr[2]; /* 32-bit Destination IP address */
|
||||
|
||||
#endif /* CONFIG_NET_IPv6 */
|
||||
|
||||
@@ -327,31 +327,31 @@ struct uip_icmpip_hdr
|
||||
{
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
|
||||
/* IPv6 IP header. */
|
||||
/* IPv6 Ip header. */
|
||||
|
||||
uint8 vtc;
|
||||
uint8 tcf;
|
||||
uint16 flow;
|
||||
uint8 len[2];
|
||||
uint8 proto;
|
||||
uint8 ttl;
|
||||
uip_ip6addr_t srcipaddr;
|
||||
uip_ip6addr_t destipaddr;
|
||||
uint8 vtc; /* Bits 0-3: version, bits 4-7: traffic class (MS) */
|
||||
uint8 tcf; /* Bits 0-3: traffic class (LS), bits 4-7: flow label (MS) */
|
||||
uint16 flow; /* 16-bit flow label (LS) */
|
||||
uint8 len[2]; /* 16-bit Payload length */
|
||||
uint8 proto; /* 8-bit Next header (same as IPv4 protocol field) */
|
||||
uint8 ttl; /* 8-bit Hop limit (like IPv4 TTL field) */
|
||||
uip_ip6addr_t srcipaddr; /* 128-bit Source address */
|
||||
uip_ip6addr_t destipaddr; /* 128-bit Destination address */
|
||||
|
||||
#else /* CONFIG_NET_IPv6 */
|
||||
|
||||
/* IPv4 IP header. */
|
||||
|
||||
uint8 vhl; /* 8-bit Version (4) and header length (5 or 6) */
|
||||
uint8 tos; /* 8-bit Type of service (e.g., 6=TCP) */
|
||||
uint8 len[2]; /* 16-bit Total length */
|
||||
uint8 ipid[2]; /* 16-bit Identification */
|
||||
uint8 ipoffset[2]; /* 16-bit IP flags + fragment offset */
|
||||
uint8 ttl; /* 8-bit Time to Live */
|
||||
uint8 proto; /* 8-bit Protocol */
|
||||
uint16 ipchksum; /* 16-bit Header checksum */
|
||||
uint16 srcipaddr[2]; /* 32-bit Source IP address */
|
||||
uint16 destipaddr[2]; /* 32-bit Destination IP address */
|
||||
uint8 vhl; /* 8-bit Version (4) and header length (5 or 6) */
|
||||
uint8 tos; /* 8-bit Type of service (e.g., 6=TCP) */
|
||||
uint8 len[2]; /* 16-bit Total length */
|
||||
uint8 ipid[2]; /* 16-bit Identification */
|
||||
uint8 ipoffset[2]; /* 16-bit IP flags + fragment offset */
|
||||
uint8 ttl; /* 8-bit Time to Live */
|
||||
uint8 proto; /* 8-bit Protocol */
|
||||
uint16 ipchksum; /* 16-bit Header checksum */
|
||||
uint16 srcipaddr[2]; /* 32-bit Source IP address */
|
||||
uint16 destipaddr[2]; /* 32-bit Destination IP address */
|
||||
|
||||
#endif /* CONFIG_NET_IPv6 */
|
||||
|
||||
@@ -384,31 +384,31 @@ struct uip_udpip_hdr
|
||||
{
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
|
||||
/* IPv6 IP header. */
|
||||
/* IPv6 Ip header. */
|
||||
|
||||
uint8 vtc;
|
||||
uint8 tcf;
|
||||
uint16 flow;
|
||||
uint8 len[2];
|
||||
uint8 proto;
|
||||
uint8 ttl;
|
||||
uip_ip6addr_t srcipaddr;
|
||||
uip_ip6addr_t destipaddr;
|
||||
uint8 vtc; /* Bits 0-3: version, bits 4-7: traffic class (MS) */
|
||||
uint8 tcf; /* Bits 0-3: traffic class (LS), 4-bits: flow label (MS) */
|
||||
uint16 flow; /* 16-bit flow label (LS) */
|
||||
uint8 len[2]; /* 16-bit Payload length */
|
||||
uint8 proto; /* 8-bit Next header (same as IPv4 protocol field) */
|
||||
uint8 ttl; /* 8-bit Hop limit (like IPv4 TTL field) */
|
||||
uip_ip6addr_t srcipaddr; /* 128-bit Source address */
|
||||
uip_ip6addr_t destipaddr; /* 128-bit Destination address */
|
||||
|
||||
#else /* CONFIG_NET_IPv6 */
|
||||
|
||||
/* IPv4 header. */
|
||||
|
||||
uint8 vhl; /* 8-bit Version (4) and header length (5 or 6) */
|
||||
uint8 tos; /* 8-bit Type of service (e.g., 6=TCP) */
|
||||
uint8 len[2]; /* 16-bit Total length */
|
||||
uint8 ipid[2]; /* 16-bit Identification */
|
||||
uint8 ipoffset[2]; /* 16-bit IP flags + fragment offset */
|
||||
uint8 ttl; /* 8-bit Time to Live */
|
||||
uint8 proto; /* 8-bit Protocol */
|
||||
uint16 ipchksum; /* 16-bit Header checksum */
|
||||
uint16 srcipaddr[2]; /* 32-bit Source IP address */
|
||||
uint16 destipaddr[2]; /* 32-bit Destination IP address */
|
||||
uint8 vhl; /* 8-bit Version (4) and header length (5 or 6) */
|
||||
uint8 tos; /* 8-bit Type of service (e.g., 6=TCP) */
|
||||
uint8 len[2]; /* 16-bit Total length */
|
||||
uint8 ipid[2]; /* 16-bit Identification */
|
||||
uint8 ipoffset[2]; /* 16-bit IP flags + fragment offset */
|
||||
uint8 ttl; /* 8-bit Time to Live */
|
||||
uint8 proto; /* 8-bit Protocol */
|
||||
uint16 ipchksum; /* 16-bit Header checksum */
|
||||
uint16 srcipaddr[2]; /* 32-bit Source IP address */
|
||||
uint16 destipaddr[2]; /* 32-bit Destination IP address */
|
||||
|
||||
#endif /* CONFIG_NET_IPv6 */
|
||||
|
||||
@@ -459,10 +459,6 @@ extern uint16 uip_urglen; /* Length of (received) urgent data */
|
||||
|
||||
extern struct uip_conn *uip_conn;
|
||||
|
||||
/* 4-byte array used for the 32-bit sequence number calculations.*/
|
||||
|
||||
extern uint8 uip_acc32[4];
|
||||
|
||||
/* The current UDP connection. */
|
||||
|
||||
#ifdef CONFIG_NET_UDP
|
||||
|
||||
@@ -38,9 +38,21 @@ UIP_CSRCS =
|
||||
|
||||
ifeq ($(CONFIG_NET),y)
|
||||
|
||||
UIP_CSRCS += uip-initialize.c uip-arp.c uip.c uip-send.c uip-fw.c \
|
||||
uip-neighbor.c uip-split.c uip-tcpconn.c uip-listen.c \
|
||||
uip-poll.c uip-chksum.c
|
||||
# Common network source files
|
||||
|
||||
UIP_CSRCS += uip-initialize.c uip-setipid.c uip-arp.c uip-input.c uip-send.c \
|
||||
uip-fw.c uip-split.c uip-poll.c uip-chksum.c
|
||||
|
||||
ifeq ($(CONFIG_NET_IPv6),y)
|
||||
UIP_CSRCS += uip-neighbor.c
|
||||
endif
|
||||
|
||||
# TCP source files
|
||||
|
||||
UIP_CSRCS += uip-tcpconn.c uip-tcppoll.c uip-tcptimer.c uip-tcpsend.c \
|
||||
uip-tcpinput.c uip-tcpappsend.c uip-listen.c uip-tcpcallback.c
|
||||
|
||||
# UDP source files
|
||||
|
||||
ifeq ($(CONFIG_NET_UDP),y)
|
||||
|
||||
@@ -48,6 +60,11 @@ UIP_CSRCS += uip-udpconn.c uip-udppoll.c uip-udpsend.c uip-udpinput.c \
|
||||
uip-udpcallback.c
|
||||
|
||||
endif
|
||||
|
||||
#ICMP source files
|
||||
|
||||
UIP_CSRCS += uip-icmpinput.c
|
||||
|
||||
endif
|
||||
|
||||
|
||||
|
||||
@@ -116,12 +116,15 @@ static uint16 upper_layer_chksum(struct uip_driver_s *dev, uint8 proto)
|
||||
/* First sum pseudoheader. */
|
||||
|
||||
/* IP protocol and length fields. This addition cannot carry. */
|
||||
|
||||
sum = upper_layer_len + proto;
|
||||
|
||||
/* Sum IP source and destination addresses. */
|
||||
|
||||
sum = chksum(sum, (uint8 *)&BUF->srcipaddr, 2 * sizeof(uip_ipaddr_t));
|
||||
|
||||
/* Sum TCP header and data. */
|
||||
|
||||
sum = chksum(sum, &dev->d_buf[UIP_IPH_LEN + UIP_LLH_LEN], upper_layer_len);
|
||||
|
||||
return (sum == 0) ? 0xffff : htons(sum);
|
||||
@@ -143,35 +146,49 @@ static uint16 uip_icmp6chksum(struct uip_driver_s *dev)
|
||||
/* Calculate the Internet checksum over a buffer. */
|
||||
|
||||
#if !UIP_ARCH_ADD32
|
||||
void uip_add32(uint8 *op32, uint16 op16)
|
||||
static void uip_carry32(uint8 *sum, uint16 op16)
|
||||
{
|
||||
uip_acc32[3] = op32[3] + (op16 & 0xff);
|
||||
uip_acc32[2] = op32[2] + (op16 >> 8);
|
||||
uip_acc32[1] = op32[1];
|
||||
uip_acc32[0] = op32[0];
|
||||
|
||||
if (uip_acc32[2] < (op16 >> 8))
|
||||
if (sum[2] < (op16 >> 8))
|
||||
{
|
||||
++uip_acc32[1];
|
||||
if (uip_acc32[1] == 0)
|
||||
++sum[1];
|
||||
if (sum[1] == 0)
|
||||
{
|
||||
++uip_acc32[0];
|
||||
++sum[0];
|
||||
}
|
||||
}
|
||||
|
||||
if (uip_acc32[3] < (op16 & 0xff))
|
||||
if (sum[3] < (op16 & 0xff))
|
||||
{
|
||||
++uip_acc32[2];
|
||||
if (uip_acc32[2] == 0)
|
||||
++sum[2];
|
||||
if (sum[2] == 0)
|
||||
{
|
||||
++uip_acc32[1];
|
||||
if (uip_acc32[1] == 0)
|
||||
++sum[1];
|
||||
if (sum[1] == 0)
|
||||
{
|
||||
++uip_acc32[0];
|
||||
++sum[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void uip_add32(const uint8 *op32, uint16 op16, uint8 *sum)
|
||||
{
|
||||
/* op32 and the sum are in network order (big-endian); op16 is host order. */
|
||||
|
||||
sum[3] = op32[3] + (op16 & 0xff);
|
||||
sum[2] = op32[2] + (op16 >> 8);
|
||||
sum[1] = op32[1];
|
||||
sum[0] = op32[0];
|
||||
uip_carry32(sum, op16);
|
||||
}
|
||||
|
||||
void uip_incr32(uint8 *op32, uint16 op16)
|
||||
{
|
||||
op32[3] += (op16 & 0xff);
|
||||
op32[2] += (op16 >> 8);
|
||||
uip_carry32(op32, op16);
|
||||
}
|
||||
|
||||
#endif /* UIP_ARCH_ADD32 */
|
||||
|
||||
#if !UIP_ARCH_CHKSUM
|
||||
|
||||
243
net/uip/uip-icmpinput.c
Normal file
243
net/uip/uip-icmpinput.c
Normal file
@@ -0,0 +1,243 @@
|
||||
/****************************************************************************
|
||||
* net/uip/uip-icmpinput.c
|
||||
* Handling incoming ICMP/ICMP6 input
|
||||
*
|
||||
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* Adapted for NuttX from logic in uIP which also has a BSD-like license:
|
||||
*
|
||||
* Original author Adam Dunkels <adam@dunkels.com>
|
||||
* Copyright () 2001-2003, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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>
|
||||
#ifdef CONFIG_NET
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <net/uip/uipopt.h>
|
||||
#include <net/uip/uip.h>
|
||||
#include <net/uip/uip-arch.h>
|
||||
|
||||
#include "uip-internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define ICMPBUF ((struct uip_icmpip_hdr *)&dev->d_buf[UIP_LLH_LEN])
|
||||
|
||||
/****************************************************************************
|
||||
* Public Variables
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Variables
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: uip_icmpinput
|
||||
*
|
||||
* Description:
|
||||
* Handle incoming ICMP/ICMP6 input
|
||||
*
|
||||
* Parameters:
|
||||
* dev - The device driver structure containing the received ICMP/ICMP6
|
||||
* packet
|
||||
*
|
||||
* Return:
|
||||
* None
|
||||
*
|
||||
* Assumptions:
|
||||
* Called from the interrupt level or with interrupts disabled.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void uip_icmpinput(struct uip_driver_s *dev)
|
||||
{
|
||||
#ifdef CONFIG_NET_STATISTICS
|
||||
uip_stat.icmp.recv++;
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_NET_IPv6
|
||||
/* ICMPv4 processing code follows. */
|
||||
|
||||
/* ICMP echo (i.e., ping) processing. This is simple, we only change the
|
||||
* ICMP type from ECHO to ECHO_REPLY and adjust the ICMP checksum before
|
||||
* we return the packet.
|
||||
*/
|
||||
|
||||
if (ICMPBUF->type != ICMP_ECHO)
|
||||
{
|
||||
uip_log("icmp: not ICMP echo.");
|
||||
goto typeerr;
|
||||
}
|
||||
|
||||
/* If we are configured to use ping IP address assignment, we use
|
||||
* the destination IP address of this ping packet and assign it to
|
||||
* ourself.
|
||||
*/
|
||||
|
||||
#if UIP_PINGADDRCONF
|
||||
if (dev->d_ipaddr == 0)
|
||||
{
|
||||
dev->d_ipaddr = ICMPBUF->destipaddr;
|
||||
}
|
||||
#endif /* UIP_PINGADDRCONF */
|
||||
|
||||
ICMPBUF->type = ICMP_ECHO_REPLY;
|
||||
|
||||
if (ICMPBUF->icmpchksum >= HTONS(0xffff - (ICMP_ECHO << 8)))
|
||||
{
|
||||
ICMPBUF->icmpchksum += HTONS(ICMP_ECHO << 8) + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
ICMPBUF->icmpchksum += HTONS(ICMP_ECHO << 8);
|
||||
}
|
||||
|
||||
/* Swap IP addresses. */
|
||||
|
||||
uiphdr_ipaddr_copy(ICMPBUF->destipaddr, ICMPBUF->srcipaddr);
|
||||
uiphdr_ipaddr_copy(ICMPBUF->srcipaddr, &dev->d_ipaddr);
|
||||
|
||||
vdbg("Outgoing ICMP packet length: %d (%d)\n",
|
||||
dev->d_len, (ICMPBUF->len[0] << 8) | ICMPBUF->len[1]);
|
||||
|
||||
#ifdef CONFIG_NET_STATISTICS
|
||||
uip_stat.icmp.sent++;
|
||||
uip_stat.ip.sent++;
|
||||
#endif
|
||||
return;
|
||||
|
||||
typeerr:
|
||||
#ifdef CONFIG_NET_STATISTICS
|
||||
uip_stat.icmp.typeerr++;
|
||||
uip_stat.icmp.drop++;
|
||||
#endif
|
||||
dev->d_len = 0;
|
||||
|
||||
#else /* !CONFIG_NET_IPv6 */
|
||||
|
||||
/* If we get a neighbor solicitation for our address we should send
|
||||
* a neighbor advertisement message back.
|
||||
*/
|
||||
|
||||
if (ICMPBUF->type == ICMP6_NEIGHBOR_SOLICITATION)
|
||||
{
|
||||
if (uip_ipaddr_cmp(ICMPBUF->icmp6data, dev->d_ipaddr))
|
||||
{
|
||||
if (ICMPBUF->options[0] == ICMP6_OPTION_SOURCE_LINK_ADDRESS)
|
||||
{
|
||||
/* Save the sender's address in our neighbor list. */
|
||||
|
||||
uiphdr_neighbor_add(ICMPBUF->srcipaddr, &(ICMPBUF->options[2]));
|
||||
}
|
||||
|
||||
/* We should now send a neighbor advertisement back to where the
|
||||
* neighbor solicication came from.
|
||||
*/
|
||||
|
||||
ICMPBUF->type = ICMP6_NEIGHBOR_ADVERTISEMENT;
|
||||
ICMPBUF->flags = ICMP6_FLAG_S; /* Solicited flag. */
|
||||
|
||||
ICMPBUF->reserved1 = ICMPBUF->reserved2 = ICMPBUF->reserved3 = 0;
|
||||
|
||||
uiphdr_ipaddr_copy(ICMPBUF->destipaddr, ICMPBUF->srcipaddr);
|
||||
uiphdr_ipaddr_copy(ICMPBUF->srcipaddr, dev->d_ipaddr);
|
||||
ICMPBUF->options[0] = ICMP6_OPTION_TARGET_LINK_ADDRESS;
|
||||
ICMPBUF->options[1] = 1; /* Options length, 1 = 8 bytes. */
|
||||
memcpy(&(ICMPBUF->options[2]), &dev->d_mac, IFHWADDRLEN);
|
||||
ICMPBUF->icmpchksum = 0;
|
||||
ICMPBUF->icmpchksum = ~uip_icmp6chksum(dev);
|
||||
}
|
||||
else
|
||||
{
|
||||
goto drop;
|
||||
}
|
||||
}
|
||||
else if (ICMPBUF->type == ICMP6_ECHO)
|
||||
{
|
||||
/* ICMP echo (i.e., ping) processing. This is simple, we only
|
||||
* change the ICMP type from ECHO to ECHO_REPLY and update the
|
||||
* ICMP checksum before we return the packet.
|
||||
*/
|
||||
|
||||
ICMPBUF->type = ICMP6_ECHO_REPLY;
|
||||
|
||||
uiphdr_ipaddr_copy(ICMPBUF->destipaddr, ICMPBUF->srcipaddr);
|
||||
uiphdr_ipaddr_copy(ICMPBUF->srcipaddr, dev->d_ipaddr);
|
||||
ICMPBUF->icmpchksum = 0;
|
||||
ICMPBUF->icmpchksum = ~uip_icmp6chksum(dev);
|
||||
}
|
||||
else
|
||||
{
|
||||
uip_log("icmp: unknown ICMP6 message.");
|
||||
goto typeerr;
|
||||
}
|
||||
|
||||
vdbg("Outgoing ICMP6 packet length: %d (%d)\n",
|
||||
dev->d_len, (ICMPBUF->len[0] << 8) | ICMPBUF->len[1]);
|
||||
|
||||
#ifdef CONFIG_NET_STATISTICS
|
||||
uip_stat.icmp.sent++;
|
||||
uip_stat.ip.sent++;
|
||||
#endif
|
||||
return;
|
||||
|
||||
typeerr:
|
||||
#ifdef CONFIG_NET_STATISTICS
|
||||
uip_stat.icmp.typeerr++;
|
||||
#endif
|
||||
|
||||
drop:
|
||||
#ifdef CONFIG_NET_STATISTICS
|
||||
uip_stat.icmp.drop++;
|
||||
#endif
|
||||
dev->d_len = 0;
|
||||
|
||||
#endif /* !CONFIG_NET_IPv6 */
|
||||
}
|
||||
|
||||
#endif /* CONFIG_NET */
|
||||
@@ -57,6 +57,51 @@
|
||||
* Public Variables
|
||||
****************************************************************************/
|
||||
|
||||
#if UIP_URGDATA > 0
|
||||
void *uip_urgdata; /* urgent data (out-of-band data), if present. */
|
||||
uint16 uip_urglen; /* Length of (received) urgent data */
|
||||
#endif
|
||||
|
||||
/* The uip_flags variable is used for communication between the TCP/IP
|
||||
* stack and the application program.
|
||||
*/
|
||||
|
||||
uint8 uip_flags;
|
||||
|
||||
/* uip_conn always points to the current connection. */
|
||||
|
||||
struct uip_conn *uip_conn;
|
||||
|
||||
#ifdef CONFIG_NET_UDP
|
||||
struct uip_udp_conn *uip_udp_conn;
|
||||
#endif /* CONFIG_NET_UDP */
|
||||
|
||||
#ifdef CONFIG_NET_STATISTICS
|
||||
struct uip_stats uip_stat;
|
||||
#endif
|
||||
|
||||
/* Increasing number used for the IP ID field. */
|
||||
|
||||
uint16 g_ipid;
|
||||
|
||||
const uip_ipaddr_t all_ones_addr =
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
{0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff};
|
||||
#else /* CONFIG_NET_IPv6 */
|
||||
{0xffffffff};
|
||||
#endif /* CONFIG_NET_IPv6 */
|
||||
|
||||
const uip_ipaddr_t all_zeroes_addr =
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
{0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000};
|
||||
#else
|
||||
{0x00000000};
|
||||
#endif
|
||||
|
||||
#if UIP_REASSEMBLY && !defined(CONFIG_NET_IPv6)
|
||||
uint8 uip_reasstmr;
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Variables
|
||||
****************************************************************************/
|
||||
|
||||
509
net/uip/uip-input.c
Normal file
509
net/uip/uip-input.c
Normal file
File diff suppressed because it is too large
Load Diff
@@ -55,6 +55,37 @@
|
||||
* Public Macro Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* TCP definitions */
|
||||
|
||||
#define TCP_FIN 0x01
|
||||
#define TCP_SYN 0x02
|
||||
#define TCP_RST 0x04
|
||||
#define TCP_PSH 0x08
|
||||
#define TCP_ACK 0x10
|
||||
#define TCP_URG 0x20
|
||||
#define TCP_CTL 0x3f
|
||||
|
||||
#define TCP_OPT_END 0 /* End of TCP options list */
|
||||
#define TCP_OPT_NOOP 1 /* "No-operation" TCP option */
|
||||
#define TCP_OPT_MSS 2 /* Maximum segment size TCP option */
|
||||
|
||||
#define TCP_OPT_MSS_LEN 4 /* Length of TCP MSS option. */
|
||||
|
||||
/* ICMP/ICMP6 definitions */
|
||||
|
||||
#define ICMP_ECHO_REPLY 0
|
||||
#define ICMP_ECHO 8
|
||||
|
||||
#define ICMP6_ECHO_REPLY 129
|
||||
#define ICMP6_ECHO 128
|
||||
#define ICMP6_NEIGHBOR_SOLICITATION 135
|
||||
#define ICMP6_NEIGHBOR_ADVERTISEMENT 136
|
||||
|
||||
#define ICMP6_FLAG_S (1 << 6)
|
||||
|
||||
#define ICMP6_OPTION_SOURCE_LINK_ADDRESS 1
|
||||
#define ICMP6_OPTION_TARGET_LINK_ADDRESS 2
|
||||
|
||||
/****************************************************************************
|
||||
* Public Type Definitions
|
||||
****************************************************************************/
|
||||
@@ -70,6 +101,10 @@ extern const uip_ipaddr_t all_zeroes_addr;
|
||||
|
||||
extern uint16 g_ipid;
|
||||
|
||||
#if UIP_REASSEMBLY && !defined(CONFIG_NET_IPv6)
|
||||
extern uint8 uip_reasstmr;
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
@@ -90,12 +125,43 @@ EXTERN struct uip_conn *uip_tcplistener(uint16 portno);
|
||||
EXTERN struct uip_conn *uip_tcpaccept(struct uip_tcpip_hdr *buf);
|
||||
EXTERN void uip_tcpnextsequence(void);
|
||||
|
||||
/* Defined in uip-tcppoll.c *************************************************/
|
||||
|
||||
EXTERN void uip_tcppoll(struct uip_driver_s *dev, struct uip_conn *conn);
|
||||
|
||||
/* Defined in uip-udptimer.c ************************************************/
|
||||
|
||||
EXTERN void uip_udptimer(struct uip_driver_s *dev, struct uip_conn *conn);
|
||||
|
||||
/* Defined in uip_listen.c **************************************************/
|
||||
|
||||
EXTERN void uip_listeninit(void);
|
||||
EXTERN boolean uip_islistener(uint16 port);
|
||||
EXTERN int uip_accept(struct uip_conn *conn, uint16 portno);
|
||||
|
||||
/* Defined in uip-tcpsend.c *************************************************/
|
||||
|
||||
EXTERN void uip_tcpsend(struct uip_driver_s *dev, struct uip_conn *conn,
|
||||
uint8 flags, uint16 len);
|
||||
EXTERN void uip_tcpreset(struct uip_driver_s *dev);
|
||||
EXTERN void uip_tcpack(struct uip_driver_s *dev, struct uip_conn *conn,
|
||||
uint8 ack);
|
||||
|
||||
/* Defined in uip-tcpappsend.c **********************************************/
|
||||
|
||||
EXTERN void uip_tcpappsend(struct uip_driver_s *dev, struct uip_conn *conn,
|
||||
uint8 result);
|
||||
EXTERN void uip_tcprexmit(struct uip_driver_s *dev, struct uip_conn *conn,
|
||||
uint8 result);
|
||||
|
||||
/* Defined in uip-tcpinput.c ************************************************/
|
||||
|
||||
EXTERN void uip_tcpinput(struct uip_driver_s *dev);
|
||||
|
||||
/* Defined in uip_uipcallback.c *********************************************/
|
||||
|
||||
EXTERN void uip_tcpcallback(struct uip_driver_s *dev);
|
||||
|
||||
#ifdef CONFIG_NET_UDP
|
||||
/* Defined in uip_udpconn.c *************************************************/
|
||||
|
||||
@@ -103,7 +169,7 @@ EXTERN void uip_udpinit(void);
|
||||
EXTERN struct uip_udp_conn *uip_udpactive(struct uip_udpip_hdr *buf);
|
||||
EXTERN struct uip_udp_conn *uip_nextudpconn(struct uip_udp_conn *conn);
|
||||
|
||||
/* Defined in uip-udppool.c *************************************************/
|
||||
/* Defined in uip-udppoll.c *************************************************/
|
||||
|
||||
EXTERN void uip_udppoll(struct uip_driver_s *dev, struct uip_udp_conn *conn);
|
||||
|
||||
@@ -120,6 +186,10 @@ EXTERN void uip_udpinput(struct uip_driver_s *dev);
|
||||
EXTERN void uip_udpcallback(struct uip_driver_s *dev);
|
||||
#endif /* CONFIG_NET_UDP */
|
||||
|
||||
/* Defined in uip-icmpinput.c ***********************************************/
|
||||
|
||||
EXTERN void uip_icmpinput(struct uip_driver_s *dev);
|
||||
|
||||
/* UIP logging **************************************************************/
|
||||
|
||||
/* This function must be provided by the application if CONFIG_NET_LOGGING
|
||||
|
||||
@@ -107,7 +107,15 @@ int uip_poll(struct uip_driver_s *dev, uip_poll_callback_t callback, int event)
|
||||
while ((conn = uip_nexttcpconn(conn)))
|
||||
{
|
||||
uip_conn = conn;
|
||||
uip_interrupt(dev, event);
|
||||
if (event == UIP_DRV_POLL)
|
||||
{
|
||||
uip_tcppoll(dev, conn);
|
||||
}
|
||||
else
|
||||
{
|
||||
uip_tcptimer(dev, conn);
|
||||
}
|
||||
|
||||
if (callback(dev))
|
||||
{
|
||||
irqrestore(flags);
|
||||
|
||||
78
net/uip/uip-setipid.c
Normal file
78
net/uip/uip-setipid.c
Normal file
@@ -0,0 +1,78 @@
|
||||
/****************************************************************************
|
||||
* net/uip/uip-udpcallback.c
|
||||
*
|
||||
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
*
|
||||
* 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>
|
||||
#ifdef CONFIG_NET
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <net/uip/uip.h>
|
||||
|
||||
#include "uip-internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Function: uip_setipid
|
||||
*
|
||||
* Description:
|
||||
* This function may be used at boot time to set the initial ip_id.
|
||||
*
|
||||
* Assumptions:
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void uip_setipid(uint16 id)
|
||||
{
|
||||
g_ipid = id;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_NET */
|
||||
@@ -102,18 +102,16 @@ void uip_split_output(struct uip_driver_s *dev)
|
||||
/* dev->d_appdata += len1;*/
|
||||
memcpy(dev->d_appdata, dev->d_appdata + len1, len2);
|
||||
|
||||
uip_add32(BUF->seqno, len1);
|
||||
BUF->seqno[0] = uip_acc32[0];
|
||||
BUF->seqno[1] = uip_acc32[1];
|
||||
BUF->seqno[2] = uip_acc32[2];
|
||||
BUF->seqno[3] = uip_acc32[3];
|
||||
uip_incr32(BUF->seqno, len1);
|
||||
|
||||
/* Recalculate the TCP checksum. */
|
||||
|
||||
BUF->tcpchksum = 0;
|
||||
BUF->tcpchksum = ~(uip_tcpchksum(dev));
|
||||
|
||||
#ifndef CONFIG_NET_IPv6
|
||||
/* Recalculate the IP checksum. */
|
||||
|
||||
BUF->ipchksum = 0;
|
||||
BUF->ipchksum = ~(uip_ipchksum(dev));
|
||||
#endif /* CONFIG_NET_IPv6 */
|
||||
|
||||
225
net/uip/uip-tcpappsend.c
Normal file
225
net/uip/uip-tcpappsend.c
Normal file
@@ -0,0 +1,225 @@
|
||||
/****************************************************************************
|
||||
* net/uip/uip-tcpappsend.c
|
||||
*
|
||||
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* Adapted for NuttX from logic in uIP which also has a BSD-like license:
|
||||
*
|
||||
* Original author Adam Dunkels <adam@dunkels.com>
|
||||
* Copyright () 2001-2003, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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>
|
||||
#ifdef CONFIG_NET
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <net/uip/uipopt.h>
|
||||
#include <net/uip/uip.h>
|
||||
#include <net/uip/uip-arch.h>
|
||||
|
||||
#include "uip-internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define BUF ((struct uip_tcpip_hdr *)&dev->d_buf[UIP_LLH_LEN])
|
||||
|
||||
/****************************************************************************
|
||||
* Public Variables
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Variables
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: uip_tcpappsend
|
||||
*
|
||||
* Description:
|
||||
* Handle application response
|
||||
*
|
||||
* Parameters:
|
||||
* dev - The device driver structure to use in the send operation
|
||||
* conn - The TCP connection structure holding connection information
|
||||
* result - App result event sent
|
||||
*
|
||||
* Return:
|
||||
* None
|
||||
*
|
||||
* Assumptions:
|
||||
* Called from the interrupt level or with interrupts disabled.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void uip_tcpappsend(struct uip_driver_s *dev, struct uip_conn *conn, uint8 result)
|
||||
{
|
||||
/* Handle the result based on the application response */
|
||||
|
||||
if (result & UIP_ABORT)
|
||||
{
|
||||
dev->d_sndlen = 0;
|
||||
conn->tcpstateflags = UIP_CLOSED;
|
||||
vdbg("TCP state: UIP_CLOSED\n");
|
||||
|
||||
uip_tcpsend(dev, conn, TCP_RST | TCP_ACK, UIP_IPTCPH_LEN);
|
||||
}
|
||||
|
||||
else if (result & UIP_CLOSE)
|
||||
{
|
||||
conn->tcpstateflags = UIP_FIN_WAIT_1;
|
||||
conn->len = 1;
|
||||
conn->nrtx = 0;
|
||||
vdbg("TCP state: UIP_FIN_WAIT_1\n");
|
||||
|
||||
dev->d_sndlen = 0;
|
||||
uip_tcpsend(dev, conn, TCP_FIN | TCP_ACK, UIP_IPTCPH_LEN);
|
||||
}
|
||||
|
||||
/* If d_sndlen > 0, the application has data to be sent. */
|
||||
|
||||
else if (dev->d_sndlen > 0)
|
||||
{
|
||||
/* If the connection has acknowledged data, the contents of
|
||||
* the ->len variable should be discarded.
|
||||
*/
|
||||
|
||||
if (result & UIP_ACKDATA)
|
||||
{
|
||||
conn->len = 0;
|
||||
}
|
||||
|
||||
/* If the ->len variable is non-zero the connection has
|
||||
* already data in transit and cannot send anymore right
|
||||
* now.
|
||||
*/
|
||||
|
||||
if (conn->len == 0)
|
||||
{
|
||||
/* The application cannot send more than what is
|
||||
* allowed by the mss (the minumum of the MSS and the
|
||||
* available window).
|
||||
*/
|
||||
|
||||
if (dev->d_sndlen > conn->mss)
|
||||
{
|
||||
dev->d_sndlen = conn->mss;
|
||||
}
|
||||
|
||||
/* Remember how much data we send out now so that we
|
||||
* know when everything has been acknowledged.
|
||||
*/
|
||||
|
||||
conn->len = dev->d_sndlen;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* If the application already had unacknowledged data,
|
||||
* we make sure that the application does not send
|
||||
* (i.e., retransmit) out more than it previously sent
|
||||
* out.
|
||||
*/
|
||||
|
||||
dev->d_sndlen = conn->len;
|
||||
}
|
||||
|
||||
/* Then handle the rest of the operation just as for the rexmit case */
|
||||
|
||||
conn->nrtx = 0;
|
||||
uip_tcprexmit(dev, conn, result);
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: uip_tcprexmit
|
||||
*
|
||||
* Description:
|
||||
* Handle application retransmission
|
||||
*
|
||||
* Parameters:
|
||||
* dev - The device driver structure to use in the send operation
|
||||
* conn - The TCP connection structure holding connection information
|
||||
* result - App result event sent
|
||||
*
|
||||
* Return:
|
||||
* None
|
||||
*
|
||||
* Assumptions:
|
||||
* Called from the interrupt level or with interrupts disabled.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void uip_tcprexmit(struct uip_driver_s *dev, struct uip_conn *conn, uint8 result)
|
||||
{
|
||||
dev->d_appdata = dev->d_snddata;
|
||||
|
||||
/* If the application has data to be sent, or if the incoming packet had
|
||||
* new data in it, we must send out a packet.
|
||||
*/
|
||||
|
||||
if (dev->d_sndlen > 0 && conn->len > 0)
|
||||
{
|
||||
/* We always set the ACK flag in response packets adding the length of
|
||||
* the IP and TCP headers.
|
||||
*/
|
||||
|
||||
uip_tcpsend(dev, conn, TCP_ACK | TCP_PSH, conn->len + UIP_TCPIP_HLEN);
|
||||
}
|
||||
|
||||
/* If there is no data to send, just send out a pure ACK if there is newdata. */
|
||||
|
||||
else if (result & UIP_NEWDATA)
|
||||
{
|
||||
uip_tcpsend(dev, conn, TCP_ACK, UIP_TCPIP_HLEN);
|
||||
}
|
||||
|
||||
/* There is nothing to do -- drop the packet */
|
||||
|
||||
else
|
||||
{
|
||||
dev->d_len = 0;
|
||||
}
|
||||
}
|
||||
#endif /* CONFIG_NET */
|
||||
105
net/uip/uip-tcpcallback.c
Normal file
105
net/uip/uip-tcpcallback.c
Normal file
@@ -0,0 +1,105 @@
|
||||
/****************************************************************************
|
||||
* net/uip/uip-tcpcallback.c
|
||||
*
|
||||
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
*
|
||||
* 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>
|
||||
#ifdef CONFIG_NET
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <net/uip/uipopt.h>
|
||||
#include <net/uip/uip.h>
|
||||
#include <net/uip/uip-arch.h>
|
||||
|
||||
#include "uip-internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Function: uip_tcpcallback
|
||||
*
|
||||
* Description:
|
||||
* Inform the application holding the TCP socket of a change in state.
|
||||
*
|
||||
* Assumptions:
|
||||
* This function is called at the interrupt level with interrupts disabled.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void uip_tcpcallback(struct uip_driver_s *dev)
|
||||
{
|
||||
vdbg("uip_flags: %02x\n", uip_flags);
|
||||
|
||||
/* Some sanity checking */
|
||||
|
||||
if (uip_conn)
|
||||
{
|
||||
/* Check if there is a data callback */
|
||||
|
||||
if (uip_conn->data_event)
|
||||
{
|
||||
/* Perform the callback */
|
||||
|
||||
uip_conn->data_event(dev, uip_conn->data_private);
|
||||
}
|
||||
|
||||
/* Check if there is a connection-related event and a connection
|
||||
* callback.
|
||||
*/
|
||||
if (((uip_flags & UIP_CONN_EVENTS) != 0) && uip_conn->connection_event)
|
||||
{
|
||||
/* Perform the callback */
|
||||
|
||||
uip_conn->connection_event(uip_conn->connection_private);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* CONFIG_NET */
|
||||
753
net/uip/uip-tcpinput.c
Normal file
753
net/uip/uip-tcpinput.c
Normal file
File diff suppressed because it is too large
Load Diff
126
net/uip/uip-tcppoll.c
Normal file
126
net/uip/uip-tcppoll.c
Normal file
@@ -0,0 +1,126 @@
|
||||
/****************************************************************************
|
||||
* net/uip/uip-tcppoll.c
|
||||
* Poll for the availability of TCP TX data
|
||||
*
|
||||
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* Adapted for NuttX from logic in uIP which also has a BSD-like license:
|
||||
*
|
||||
* Original author Adam Dunkels <adam@dunkels.com>
|
||||
* Copyright () 2001-2003, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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>
|
||||
#ifdef CONFIG_NET
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <net/uip/uipopt.h>
|
||||
#include <net/uip/uip.h>
|
||||
#include <net/uip/uip-arch.h>
|
||||
|
||||
#include "uip-internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Variables
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Variables
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: uip_tcppoll
|
||||
*
|
||||
* Description:
|
||||
* Poll a TCP connection structure for availability of TX data
|
||||
*
|
||||
* Parameters:
|
||||
* dev - The device driver structure to use in the send operation
|
||||
* conn - The TCP "connection" to poll for TX data
|
||||
*
|
||||
* Return:
|
||||
* None
|
||||
*
|
||||
* Assumptions:
|
||||
* Called from the interrupt level or with interrupts disabled.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void uip_tcppoll(struct uip_driver_s *dev, struct uip_conn *conn)
|
||||
{
|
||||
/* Verify that the connection is established and if the connection has
|
||||
* oustanding (unacknowledged) sent data.
|
||||
*/
|
||||
|
||||
if ((conn->tcpstateflags & UIP_TS_MASK) == UIP_ESTABLISHED &&
|
||||
!uip_outstanding(conn))
|
||||
{
|
||||
/* Set up for the callback */
|
||||
|
||||
dev->d_snddata = &dev->d_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN];
|
||||
dev->d_appdata = &dev->d_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN];
|
||||
|
||||
/* Perfom the callback */
|
||||
|
||||
uip_flags = UIP_POLL;
|
||||
uip_tcpcallback(dev);
|
||||
|
||||
/* Handle the callback response */
|
||||
|
||||
uip_tcpappsend(dev, conn, uip_flags);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Nothing to do for this connection */
|
||||
|
||||
dev->d_len = 0;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* CONFIG_NET */
|
||||
365
net/uip/uip-tcpsend.c
Normal file
365
net/uip/uip-tcpsend.c
Normal file
@@ -0,0 +1,365 @@
|
||||
/****************************************************************************
|
||||
* net/uip/uip-tcpsend.c
|
||||
*
|
||||
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* Adapted for NuttX from logic in uIP which also has a BSD-like license:
|
||||
*
|
||||
* Original author Adam Dunkels <adam@dunkels.com>
|
||||
* Copyright () 2001-2003, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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>
|
||||
#ifdef CONFIG_NET
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <net/uip/uipopt.h>
|
||||
#include <net/uip/uip.h>
|
||||
#include <net/uip/uip-arch.h>
|
||||
|
||||
#include "uip-internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define BUF ((struct uip_tcpip_hdr *)&dev->d_buf[UIP_LLH_LEN])
|
||||
|
||||
/****************************************************************************
|
||||
* Public Variables
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Variables
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: uip_tcpsendcomplete
|
||||
*
|
||||
* Description:
|
||||
* Complete the final portions of the send operation. This function sets
|
||||
* up IP header and computes the TCP checksum
|
||||
*
|
||||
* Parameters:
|
||||
* dev - The device driver structure to use in the send operation
|
||||
*
|
||||
* Return:
|
||||
* None
|
||||
*
|
||||
* Assumptions:
|
||||
* Called from the interrupt level or with interrupts disabled.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static void uip_tcpsendcomplete(struct uip_driver_s *dev)
|
||||
{
|
||||
BUF->ttl = UIP_TTL;
|
||||
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
|
||||
/* For IPv6, the IP length field does not include the IPv6 IP header
|
||||
* length.
|
||||
*/
|
||||
|
||||
BUF->len[0] = ((dev->d_len - UIP_IPH_LEN) >> 8);
|
||||
BUF->len[1] = ((dev->d_len - UIP_IPH_LEN) & 0xff);
|
||||
|
||||
#else /* CONFIG_NET_IPv6 */
|
||||
|
||||
BUF->len[0] = (dev->d_len >> 8);
|
||||
BUF->len[1] = (dev->d_len & 0xff);
|
||||
|
||||
#endif /* CONFIG_NET_IPv6 */
|
||||
|
||||
BUF->urgp[0] = BUF->urgp[1] = 0;
|
||||
|
||||
/* Calculate TCP checksum. */
|
||||
|
||||
BUF->tcpchksum = 0;
|
||||
BUF->tcpchksum = ~(uip_tcpchksum(dev));
|
||||
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
|
||||
BUF->vtc = 0x60;
|
||||
BUF->tcf = 0x00;
|
||||
BUF->flow = 0x00;
|
||||
|
||||
#else /* CONFIG_NET_IPv6 */
|
||||
|
||||
BUF->vhl = 0x45;
|
||||
BUF->tos = 0;
|
||||
BUF->ipoffset[0] = 0;
|
||||
BUF->ipoffset[1] = 0;
|
||||
++g_ipid;
|
||||
BUF->ipid[0] = g_ipid >> 8;
|
||||
BUF->ipid[1] = g_ipid & 0xff;
|
||||
|
||||
/* Calculate IP checksum. */
|
||||
|
||||
BUF->ipchksum = 0;
|
||||
BUF->ipchksum = ~(uip_ipchksum(dev));
|
||||
|
||||
#endif /* CONFIG_NET_IPv6 */
|
||||
|
||||
vdbg("Outgoing TCP packet length: %d (%d)\n",
|
||||
dev->d_len, (BUF->len[0] << 8) | BUF->len[1]);
|
||||
|
||||
#ifdef CONFIG_NET_STATISTICS
|
||||
uip_stat.tcp.sent++;
|
||||
uip_stat.ip.sent++;
|
||||
#endif
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: uip_tcpsendcommon
|
||||
*
|
||||
* Description:
|
||||
* We're done with the input processing. We are now ready to send a reply
|
||||
* Our job is to fill in all the fields of the TCP and IP headers before
|
||||
* calculating the checksum and finally send the packet.
|
||||
*
|
||||
* Parameters:
|
||||
* dev - The device driver structure to use in the send operation
|
||||
* conn - The TCP connection structure holding connection information
|
||||
*
|
||||
* Return:
|
||||
* None
|
||||
*
|
||||
* Assumptions:
|
||||
* Called from the interrupt level or with interrupts disabled.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static void uip_tcpsendcommon(struct uip_driver_s *dev, struct uip_conn *conn)
|
||||
{
|
||||
BUF->ackno[0] = conn->rcv_nxt[0];
|
||||
BUF->ackno[1] = conn->rcv_nxt[1];
|
||||
BUF->ackno[2] = conn->rcv_nxt[2];
|
||||
BUF->ackno[3] = conn->rcv_nxt[3];
|
||||
|
||||
BUF->seqno[0] = conn->snd_nxt[0];
|
||||
BUF->seqno[1] = conn->snd_nxt[1];
|
||||
BUF->seqno[2] = conn->snd_nxt[2];
|
||||
BUF->seqno[3] = conn->snd_nxt[3];
|
||||
|
||||
BUF->proto = UIP_PROTO_TCP;
|
||||
|
||||
BUF->srcport = conn->lport;
|
||||
BUF->destport = conn->rport;
|
||||
|
||||
uiphdr_ipaddr_copy(BUF->srcipaddr, &dev->d_ipaddr);
|
||||
uiphdr_ipaddr_copy(BUF->destipaddr, &conn->ripaddr);
|
||||
|
||||
if (conn->tcpstateflags & UIP_STOPPED)
|
||||
{
|
||||
/* If the connection has issued uip_stop(), we advertise a zero
|
||||
* window so that the remote host will stop sending data.
|
||||
*/
|
||||
|
||||
BUF->wnd[0] = 0;
|
||||
BUF->wnd[1] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
BUF->wnd[0] = ((UIP_RECEIVE_WINDOW) >> 8);
|
||||
BUF->wnd[1] = ((UIP_RECEIVE_WINDOW) & 0xff);
|
||||
}
|
||||
|
||||
/* Finish the IP portion of the message, calculate checksums and send
|
||||
* the message.
|
||||
*/
|
||||
|
||||
uip_tcpsendcomplete(dev);
|
||||
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: uip_tcpsend
|
||||
*
|
||||
* Description:
|
||||
* Setup to send a TCP packet
|
||||
*
|
||||
* Parameters:
|
||||
* dev - The device driver structure to use in the send operation
|
||||
* conn - The TCP connection structure holding connection information
|
||||
* flags - flags to apply to the TCP header
|
||||
* len - length of the message
|
||||
*
|
||||
* Return:
|
||||
* None
|
||||
*
|
||||
* Assumptions:
|
||||
* Called from the interrupt level or with interrupts disabled.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void uip_tcpsend(struct uip_driver_s *dev, struct uip_conn *conn, uint8 flags, uint16 len)
|
||||
{
|
||||
BUF->flags = flags;
|
||||
dev->d_len = len;
|
||||
BUF->tcpoffset = (UIP_TCPH_LEN / 4) << 4;
|
||||
uip_tcpsendcommon(dev, conn);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: uip_tcpreset
|
||||
*
|
||||
* Description:
|
||||
* Send a TCP reset (no-data) message
|
||||
*
|
||||
* Parameters:
|
||||
* dev - The device driver structure to use in the send operation
|
||||
*
|
||||
* Return:
|
||||
* None
|
||||
*
|
||||
* Assumptions:
|
||||
* Called from the interrupt level or with interrupts disabled.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void uip_tcpreset(struct uip_driver_s *dev)
|
||||
{
|
||||
uint16 tmp16;
|
||||
uint8 seqbyte;
|
||||
|
||||
#ifdef CONFIG_NET_STATISTICS
|
||||
uip_stat.tcp.rst++;
|
||||
#endif
|
||||
|
||||
BUF->flags = TCP_RST | TCP_ACK;
|
||||
dev->d_len = UIP_IPTCPH_LEN;
|
||||
BUF->tcpoffset = 5 << 4;
|
||||
|
||||
/* Flip the seqno and ackno fields in the TCP header. */
|
||||
|
||||
seqbyte = BUF->seqno[3];
|
||||
BUF->seqno[3] = BUF->ackno[3];
|
||||
BUF->ackno[3] = seqbyte;
|
||||
|
||||
seqbyte = BUF->seqno[2];
|
||||
BUF->seqno[2] = BUF->ackno[2];
|
||||
BUF->ackno[2] = seqbyte;
|
||||
|
||||
seqbyte = BUF->seqno[1];
|
||||
BUF->seqno[1] = BUF->ackno[1];
|
||||
BUF->ackno[1] = seqbyte;
|
||||
|
||||
seqbyte = BUF->seqno[0];
|
||||
BUF->seqno[0] = BUF->ackno[0];
|
||||
BUF->ackno[0] = seqbyte;
|
||||
|
||||
/* We also have to increase the sequence number we are
|
||||
* acknowledging. If the least significant byte overflowed, we need
|
||||
* to propagate the carry to the other bytes as well.
|
||||
*/
|
||||
|
||||
if (++(BUF->ackno[3]) == 0)
|
||||
{
|
||||
if (++(BUF->ackno[2]) == 0)
|
||||
{
|
||||
if (++(BUF->ackno[1]) == 0)
|
||||
{
|
||||
++(BUF->ackno[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Swap port numbers. */
|
||||
|
||||
tmp16 = BUF->srcport;
|
||||
BUF->srcport = BUF->destport;
|
||||
BUF->destport = tmp16;
|
||||
|
||||
/* Swap IP addresses. */
|
||||
|
||||
uiphdr_ipaddr_copy(BUF->destipaddr, BUF->srcipaddr);
|
||||
uiphdr_ipaddr_copy(BUF->srcipaddr, dev->d_ipaddr);
|
||||
|
||||
/* And send out the RST packet */
|
||||
|
||||
uip_tcpsendcomplete(dev);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: uip_tcpack
|
||||
*
|
||||
* Description:
|
||||
* Send the SYN or SYNACK response.
|
||||
*
|
||||
* Parameters:
|
||||
* dev - The device driver structure to use in the send operation
|
||||
* conn - The TCP connection structure holding connection information
|
||||
* ack - The ACK response to send
|
||||
*
|
||||
* Return:
|
||||
* None
|
||||
*
|
||||
* Assumptions:
|
||||
* Called from the interrupt level or with interrupts disabled.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void uip_tcpack(struct uip_driver_s *dev, struct uip_conn *conn, uint8 ack)
|
||||
{
|
||||
/* Save the ACK bits */
|
||||
|
||||
BUF->flags = ack;
|
||||
|
||||
/* We send out the TCP Maximum Segment Size option with our ack. */
|
||||
|
||||
BUF->optdata[0] = TCP_OPT_MSS;
|
||||
BUF->optdata[1] = TCP_OPT_MSS_LEN;
|
||||
BUF->optdata[2] = (UIP_TCP_MSS) / 256;
|
||||
BUF->optdata[3] = (UIP_TCP_MSS) & 255;
|
||||
dev->d_len = UIP_IPTCPH_LEN + TCP_OPT_MSS_LEN;
|
||||
BUF->tcpoffset = ((UIP_TCPH_LEN + TCP_OPT_MSS_LEN) / 4) << 4;
|
||||
|
||||
/* Complete the common portions of the TCP message */
|
||||
|
||||
uip_tcpsendcommon(dev, conn);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_NET */
|
||||
241
net/uip/uip-tcptimer.c
Normal file
241
net/uip/uip-tcptimer.c
Normal file
@@ -0,0 +1,241 @@
|
||||
/****************************************************************************
|
||||
* net/uip/uip-tcptimer.c
|
||||
* Poll for the availability of TCP TX data
|
||||
*
|
||||
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* Adapted for NuttX from logic in uIP which also has a BSD-like license:
|
||||
*
|
||||
* Original author Adam Dunkels <adam@dunkels.com>
|
||||
* Copyright () 2001-2003, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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>
|
||||
#ifdef CONFIG_NET
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <net/uip/uipopt.h>
|
||||
#include <net/uip/uip.h>
|
||||
#include <net/uip/uip-arch.h>
|
||||
|
||||
#include "uip-internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Variables
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Variables
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: uip_tcptimer
|
||||
*
|
||||
* Description:
|
||||
* Handle a TCP timer expiration for the provided TCP connection
|
||||
*
|
||||
* Parameters:
|
||||
* dev - The device driver structure to use in the send operation
|
||||
* conn - The TCP "connection" to poll for TX data
|
||||
*
|
||||
* Return:
|
||||
* None
|
||||
*
|
||||
* Assumptions:
|
||||
* Called from the interrupt level or with interrupts disabled.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void uip_tcptimer(struct uip_driver_s *dev, struct uip_conn *conn)
|
||||
{
|
||||
dev->d_snddata = &dev->d_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN];
|
||||
dev->d_appdata = &dev->d_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN];
|
||||
|
||||
/* Increment the timer used by the reassembly logic */
|
||||
|
||||
#if UIP_REASSEMBLY
|
||||
if (uip_reasstmr != 0)
|
||||
{
|
||||
uip_reasstmr++;
|
||||
}
|
||||
#endif /* UIP_REASSEMBLY */
|
||||
|
||||
/* Increase the TCP sequence number */
|
||||
|
||||
uip_tcpnextsequence();
|
||||
|
||||
/* Reset the length variables. */
|
||||
|
||||
dev->d_len = 0;
|
||||
dev->d_sndlen = 0;
|
||||
|
||||
/* Check if the connection is in a state in which we simply wait
|
||||
* for the connection to time out. If so, we increase the
|
||||
* connection's timer and remove the connection if it times
|
||||
* out.
|
||||
*/
|
||||
|
||||
if (conn->tcpstateflags == UIP_TIME_WAIT || conn->tcpstateflags == UIP_FIN_WAIT_2)
|
||||
{
|
||||
(conn->timer)++;
|
||||
if (conn->timer == UIP_TIME_WAIT_TIMEOUT)
|
||||
{
|
||||
conn->tcpstateflags = UIP_CLOSED;
|
||||
vdbg("TCP state: UIP_CLOSED\n");
|
||||
}
|
||||
}
|
||||
else if (conn->tcpstateflags != UIP_CLOSED)
|
||||
{
|
||||
/* If the connection has outstanding data, we increase the
|
||||
* connection's timer and see if it has reached the RTO value
|
||||
* in which case we retransmit.
|
||||
*/
|
||||
|
||||
if (uip_outstanding(conn))
|
||||
{
|
||||
if (conn->timer-- == 0)
|
||||
{
|
||||
if (conn->nrtx == UIP_MAXRTX ||
|
||||
((conn->tcpstateflags == UIP_SYN_SENT ||
|
||||
conn->tcpstateflags == UIP_SYN_RCVD) &&
|
||||
conn->nrtx == UIP_MAXSYNRTX))
|
||||
{
|
||||
conn->tcpstateflags = UIP_CLOSED;
|
||||
vdbg("TCP state: UIP_CLOSED\n");
|
||||
|
||||
/* We call uip_tcpcallback() with uip_flags set to
|
||||
* UIP_TIMEDOUT to inform the application that the
|
||||
* connection has timed out.
|
||||
*/
|
||||
|
||||
uip_flags = UIP_TIMEDOUT;
|
||||
uip_tcpcallback(dev);
|
||||
|
||||
/* We also send a reset packet to the remote host. */
|
||||
|
||||
uip_tcpsend(dev, conn, TCP_RST | TCP_ACK, UIP_IPTCPH_LEN);
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* Exponential backoff. */
|
||||
|
||||
conn->timer = UIP_RTO << (conn->nrtx > 4 ? 4: conn->nrtx);
|
||||
++(conn->nrtx);
|
||||
|
||||
/* Ok, so we need to retransmit. We do this differently
|
||||
* depending on which state we are in. In ESTABLISHED, we
|
||||
* call upon the application so that it may prepare the
|
||||
* data for the retransmit. In SYN_RCVD, we resend the
|
||||
* SYNACK that we sent earlier and in LAST_ACK we have to
|
||||
* retransmit our FINACK.
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_NET_STATISTICS
|
||||
uip_stat.tcp.rexmit++;
|
||||
#endif
|
||||
switch(conn->tcpstateflags & UIP_TS_MASK)
|
||||
{
|
||||
case UIP_SYN_RCVD:
|
||||
/* In the SYN_RCVD state, we should retransmit our
|
||||
* SYNACK.
|
||||
*/
|
||||
|
||||
uip_tcpack(dev, conn, TCP_ACK | TCP_SYN);
|
||||
goto done;
|
||||
|
||||
case UIP_SYN_SENT:
|
||||
/* In the SYN_SENT state, we retransmit out SYN. */
|
||||
|
||||
uip_tcpack(dev, conn, TCP_SYN);
|
||||
goto done;
|
||||
|
||||
case UIP_ESTABLISHED:
|
||||
/* In the ESTABLISHED state, we call upon the application
|
||||
* to do the actual retransmit after which we jump into
|
||||
* the code for sending out the packet.
|
||||
*/
|
||||
|
||||
uip_flags = UIP_REXMIT;
|
||||
uip_tcpcallback(dev);
|
||||
uip_tcprexmit(dev, conn, uip_flags);
|
||||
goto done;
|
||||
|
||||
case UIP_FIN_WAIT_1:
|
||||
case UIP_CLOSING:
|
||||
case UIP_LAST_ACK:
|
||||
/* In all these states we should retransmit a FINACK. */
|
||||
|
||||
uip_tcpsend(dev, conn, TCP_FIN | TCP_ACK, UIP_IPTCPH_LEN);
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ((conn->tcpstateflags & UIP_TS_MASK) == UIP_ESTABLISHED)
|
||||
{
|
||||
/* If there was no need for a retransmission, we poll the
|
||||
* application for new data.
|
||||
*/
|
||||
|
||||
uip_flags = UIP_POLL;
|
||||
uip_tcpcallback(dev);
|
||||
uip_tcpappsend(dev, conn, uip_flags);
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
/* Nothing to be done */
|
||||
|
||||
dev->d_len = 0;
|
||||
|
||||
done:
|
||||
uip_flags = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_NET */
|
||||
@@ -1,6 +1,5 @@
|
||||
/****************************************************************************
|
||||
* net/uip/uip-udpsend.c
|
||||
* Poll for the availability of UDP TX data
|
||||
*
|
||||
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
@@ -115,8 +114,8 @@ void uip_udpsend(struct uip_driver_s *dev, struct uip_udp_conn *conn)
|
||||
UDPBUF->flow = 0x00;
|
||||
UDPBUF->len[0] = (dev->d_sndlen >> 8);
|
||||
UDPBUF->len[1] = (dev->d_sndlen & 0xff);
|
||||
UDPBUF->proto = UIP_PROTO_UDP;
|
||||
UDPBUF->ttl = conn->ttl;
|
||||
UDPBUF->nexthdr = UIP_PROTO_UDP;
|
||||
UDPBUF->hoplimit = conn->ttl;
|
||||
|
||||
uip_ipaddr_copy(UDPBUF->srcipaddr, &dev->d_ipaddr);
|
||||
uip_ipaddr_copy(UDPBUF->destipaddr, &conn->ripaddr);
|
||||
|
||||
1767
net/uip/uip.c
1767
net/uip/uip.c
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user