diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2009-03-08 14:42:36 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2009-03-08 14:42:36 +0000 |
commit | 7507485356f2bdf02f95194438c4fafc7aa7db13 (patch) | |
tree | bdcafaeda3addd9f5c24f43aa692c3cb0d29f7e5 /nuttx/net/uip | |
parent | 99c28e14199f709222988dbb7e8c589b48a94206 (diff) | |
download | px4-nuttx-7507485356f2bdf02f95194438c4fafc7aa7db13.tar.gz px4-nuttx-7507485356f2bdf02f95194438c4fafc7aa7db13.tar.bz2 px4-nuttx-7507485356f2bdf02f95194438c4fafc7aa7db13.zip |
Changes to work around bug in ZDS compiler
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1575 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/net/uip')
-rw-r--r-- | nuttx/net/uip/uip_chksum.c | 12 | ||||
-rw-r--r-- | nuttx/net/uip/uip_icmpinput.c | 76 | ||||
-rw-r--r-- | nuttx/net/uip/uip_icmpping.c | 17 | ||||
-rw-r--r-- | nuttx/net/uip/uip_icmppoll.c | 4 | ||||
-rw-r--r-- | nuttx/net/uip/uip_icmpsend.c | 60 | ||||
-rw-r--r-- | nuttx/net/uip/uip_input.c | 67 | ||||
-rw-r--r-- | nuttx/net/uip/uip_tcpappsend.c | 4 | ||||
-rw-r--r-- | nuttx/net/uip/uip_tcpinput.c | 57 | ||||
-rw-r--r-- | nuttx/net/uip/uip_tcpreadahead.c | 2 | ||||
-rw-r--r-- | nuttx/net/uip/uip_tcpsend.c | 140 | ||||
-rw-r--r-- | nuttx/net/uip/uip_udpinput.c | 7 | ||||
-rw-r--r-- | nuttx/net/uip/uip_udpsend.c | 70 |
12 files changed, 270 insertions, 246 deletions
diff --git a/nuttx/net/uip/uip_chksum.c b/nuttx/net/uip/uip_chksum.c index 474dae576..defb5b479 100644 --- a/nuttx/net/uip/uip_chksum.c +++ b/nuttx/net/uip/uip_chksum.c @@ -1,7 +1,7 @@ /**************************************************************************** * net/uip/uip_chksum.c * - * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * @@ -105,13 +105,14 @@ static uint16 chksum(uint16 sum, const uint8 *data, uint16 len) static uint16 upper_layer_chksum(struct uip_driver_s *dev, uint8 proto) { + struct uip_ip_hdr *pbuf = BUF; uint16 upper_layer_len; uint16 sum; #ifdef CONFIG_NET_IPv6 - upper_layer_len = (((uint16)(BUF->len[0]) << 8) + BUF->len[1]); + upper_layer_len = (((uint16)(pbuf->len[0]) << 8) + pbuf->len[1]); #else /* CONFIG_NET_IPv6 */ - upper_layer_len = (((uint16)(BUF->len[0]) << 8) + BUF->len[1]) - UIP_IPH_LEN; + upper_layer_len = (((uint16)(pbuf->len[0]) << 8) + pbuf->len[1]) - UIP_IPH_LEN; #endif /* CONFIG_NET_IPv6 */ /* First sum pseudoheader. */ @@ -122,7 +123,7 @@ static uint16 upper_layer_chksum(struct uip_driver_s *dev, uint8 proto) /* Sum IP source and destination addresses. */ - sum = chksum(sum, (uint8 *)&BUF->srcipaddr, 2 * sizeof(uip_ipaddr_t)); + sum = chksum(sum, (uint8 *)&pbuf->srcipaddr, 2 * sizeof(uip_ipaddr_t)); /* Sum TCP header and data. */ @@ -231,7 +232,8 @@ uint16 uip_udpchksum(struct uip_driver_s *dev) #if defined(CONFIG_NET_ICMP) && defined(CONFIG_NET_ICMP_PING) uint16 uip_icmpchksum(struct uip_driver_s *dev) { - return uip_chksum((uint16*)&ICMPBUF->type, dev->d_sndlen); + struct uip_icmpip_hdr *picmp = ICMPBUF; + return uip_chksum((uint16*)&picmp->type, dev->d_sndlen); } #endif diff --git a/nuttx/net/uip/uip_icmpinput.c b/nuttx/net/uip/uip_icmpinput.c index f515bc7fb..52352c700 100644 --- a/nuttx/net/uip/uip_icmpinput.c +++ b/nuttx/net/uip/uip_icmpinput.c @@ -2,7 +2,7 @@ * net/uip/uip_icmpinput.c * Handling incoming ICMP/ICMP6 input * - * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009 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: @@ -103,6 +103,8 @@ struct uip_callback_s *g_echocallback = NULL; void uip_icmpinput(struct uip_driver_s *dev) { + struct uip_icmpip_hdr *picmp = ICMPBUF; + #ifdef CONFIG_NET_STATISTICS uip_stat.icmp.recv++; #endif @@ -115,7 +117,7 @@ void uip_icmpinput(struct uip_driver_s *dev) * we return the packet. */ - if (ICMPBUF->type == ICMP_ECHO_REQUEST) + if (picmp->type == ICMP_ECHO_REQUEST) { /* If we are configured to use ping IP address assignment, we use * the destination IP address of this ping packet and assign it to @@ -125,28 +127,28 @@ void uip_icmpinput(struct uip_driver_s *dev) #ifdef CONFIG_NET_PINGADDRCONF if (dev->d_ipaddr == 0) { - dev->d_ipaddr = ICMPBUF->destipaddr; + dev->d_ipaddr = picmp->destipaddr; } #endif - ICMPBUF->type = ICMP_ECHO_REPLY; + picmp->type = ICMP_ECHO_REPLY; - if (ICMPBUF->icmpchksum >= HTONS(0xffff - (ICMP_ECHO_REPLY << 8))) + if (picmp->icmpchksum >= HTONS(0xffff - (ICMP_ECHO_REPLY << 8))) { - ICMPBUF->icmpchksum += HTONS(ICMP_ECHO_REPLY << 8) + 1; + picmp->icmpchksum += HTONS(ICMP_ECHO_REPLY << 8) + 1; } else { - ICMPBUF->icmpchksum += HTONS(ICMP_ECHO_REPLY << 8); + picmp->icmpchksum += HTONS(ICMP_ECHO_REPLY << 8); } /* Swap IP addresses. */ - uiphdr_ipaddr_copy(ICMPBUF->destipaddr, ICMPBUF->srcipaddr); - uiphdr_ipaddr_copy(ICMPBUF->srcipaddr, &dev->d_ipaddr); + uiphdr_ipaddr_copy(picmp->destipaddr, picmp->srcipaddr); + uiphdr_ipaddr_copy(picmp->srcipaddr, &dev->d_ipaddr); nvdbg("Outgoing ICMP packet length: %d (%d)\n", - dev->d_len, (ICMPBUF->len[0] << 8) | ICMPBUF->len[1]); + dev->d_len, (picmp->len[0] << 8) | picmp->len[1]); #ifdef CONFIG_NET_STATISTICS uip_stat.icmp.sent++; @@ -159,9 +161,9 @@ void uip_icmpinput(struct uip_driver_s *dev) */ #ifdef CONFIG_NET_ICMP_PING - else if (ICMPBUF->type == ICMP_ECHO_REPLY && g_echocallback) + else if (picmp->type == ICMP_ECHO_REPLY && g_echocallback) { - (void)uip_callbackexecute(dev, ICMPBUF, UIP_ECHOREPLY, g_echocallback); + (void)uip_callbackexecute(dev, picmp, UIP_ECHOREPLY, g_echocallback); } #endif @@ -169,7 +171,7 @@ void uip_icmpinput(struct uip_driver_s *dev) else { - ndbg("Unknown ICMP cmd: %d\n", ICMPBUF->type); + ndbg("Unknown ICMP cmd: %d\n", picmp->type); goto typeerr; } @@ -188,52 +190,52 @@ typeerr: * a neighbor advertisement message back. */ - if (ICMPBUF->type == ICMP6_NEIGHBOR_SOLICITATION) + if (picmp->type == ICMP6_NEIGHBOR_SOLICITATION) { - if (uip_ipaddr_cmp(ICMPBUF->icmp6data, dev->d_ipaddr)) + if (uip_ipaddr_cmp(picmp->icmp6data, dev->d_ipaddr)) { - if (ICMPBUF->options[0] == ICMP6_OPTION_SOURCE_LINK_ADDRESS) + if (picmp->options[0] == ICMP6_OPTION_SOURCE_LINK_ADDRESS) { /* Save the sender's address in our neighbor list. */ - uiphdr_neighbor_add(ICMPBUF->srcipaddr, &(ICMPBUF->options[2])); + uiphdr_neighbor_add(picmp->srcipaddr, &(picmp->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. */ + picmp->type = ICMP6_NEIGHBOR_ADVERTISEMENT; + picmp->flags = ICMP6_FLAG_S; /* Solicited flag. */ - ICMPBUF->reserved1 = ICMPBUF->reserved2 = ICMPBUF->reserved3 = 0; + picmp->reserved1 = picmp->reserved2 = picmp->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); + uiphdr_ipaddr_copy(picmp->destipaddr, picmp->srcipaddr); + uiphdr_ipaddr_copy(picmp->srcipaddr, &dev->d_ipaddr); + picmp->options[0] = ICMP6_OPTION_TARGET_LINK_ADDRESS; + picmp->options[1] = 1; /* Options length, 1 = 8 bytes. */ + memcpy(&(picmp->options[2]), &dev->d_mac, IFHWADDRLEN); + picmp->icmpchksum = 0; + picmp->icmpchksum = ~uip_icmp6chksum(dev); } else { goto drop; } } - else if (ICMPBUF->type == ICMP6_ECHO_REQUEST) + else if (picmp->type == ICMP6_ECHO_REQUEST) { /* 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; + picmp->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); + uiphdr_ipaddr_copy(picmp->destipaddr, picmp->srcipaddr); + uiphdr_ipaddr_copy(picmp->srcipaddr, &dev->d_ipaddr); + picmp->icmpchksum = 0; + picmp->icmpchksum = ~uip_icmp6chksum(dev); } /* If an ICMP echo reply is received then there should also be @@ -241,7 +243,7 @@ typeerr: */ #ifdef CONFIG_NET_ICMP_PING - else if (ICMPBUF->type == ICMP6_ECHO_REPLY && g_echocallback) + else if (picmp->type == ICMP6_ECHO_REPLY && g_echocallback) { uint16 flags = UIP_ECHOREPLY; @@ -249,7 +251,7 @@ typeerr: { /* Dispatch the ECHO reply to the waiting thread */ - flags = uip_callbackexecute(dev, ICMPBUF, flags, g_echocallback); + flags = uip_callbackexecute(dev, picmp, flags, g_echocallback); } /* If the ECHO reply was not handled, then drop the packet */ @@ -265,12 +267,12 @@ typeerr: else { - ndbg("Unknown ICMP6 cmd: %d\n", ICMPBUF->type); + ndbg("Unknown ICMP6 cmd: %d\n", picmp->type); goto typeerr; } nvdbg("Outgoing ICMP6 packet length: %d (%d)\n", - dev->d_len, (ICMPBUF->len[0] << 8) | ICMPBUF->len[1]); + dev->d_len, (picmp->len[0] << 8) | picmp->len[1]); #ifdef CONFIG_NET_STATISTICS uip_stat.icmp.sent++; diff --git a/nuttx/net/uip/uip_icmpping.c b/nuttx/net/uip/uip_icmpping.c index 44c056be4..6c2c57c91 100644 --- a/nuttx/net/uip/uip_icmpping.c +++ b/nuttx/net/uip/uip_icmpping.c @@ -1,7 +1,7 @@ /**************************************************************************** * net/uip/uip_icmpping.c * - * Copyright (C) 2008 Gregory Nutt. All rights reserved. + * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * Redistribution and use in source and binary forms, with or without @@ -149,6 +149,7 @@ static uint16 ping_interrupt(struct uip_driver_s *dev, void *conn, void *pvprivate, uint16 flags) { struct icmp_ping_s *pstate = (struct icmp_ping_s *)pvprivate; + ubyte *ptr; int failcode = -ETIMEDOUT; int i; @@ -212,24 +213,26 @@ static uint16 ping_interrupt(struct uip_driver_s *dev, void *conn, (flags & UIP_NEWDATA) == 0 && /* No incoming data */ !pstate->png_sent) /* Request not sent */ { + struct uip_icmpip_hdr *picmp = ICMPBUF; + /* We can send the ECHO request now. * * Format the ICMP ECHO request packet */ - ICMPBUF->type = ICMP_ECHO_REQUEST; - ICMPBUF->icode = 0; + picmp->type = ICMP_ECHO_REQUEST; + picmp->icode = 0; #ifndef CONFIG_NET_IPv6 - ICMPBUF->id = htons(pstate->png_id); - ICMPBUF->seqno = htons(pstate->png_seqno); + picmp->id = htons(pstate->png_id); + picmp->seqno = htons(pstate->png_seqno); #else # error "IPv6 ECHO Request not implemented" #endif /* Add some easily verifiable data */ - for (i = 0; i < pstate->png_datlen; i++) + for (i = 0, ptr = ICMPDAT; i < pstate->png_datlen; i++) { - ICMPDAT[i] = i; + *ptr++ = i; } /* Send the ICMP echo request. Note that d_sndlen is set to diff --git a/nuttx/net/uip/uip_icmppoll.c b/nuttx/net/uip/uip_icmppoll.c index 6a61c73ed..a910b6068 100644 --- a/nuttx/net/uip/uip_icmppoll.c +++ b/nuttx/net/uip/uip_icmppoll.c @@ -1,7 +1,7 @@ /**************************************************************************** * net/uip/uip_icmppoll.c * - * Copyright (C) 2008 Gregory Nutt. All rights reserved. + * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * Redistribution and use in source and binary forms, with or without @@ -53,8 +53,6 @@ * Definitions ****************************************************************************/ -#define ICMPBUF ((struct uip_icmpip_hdr *)&dev->d_buf[UIP_LLH_LEN]) - /**************************************************************************** * Public Variables ****************************************************************************/ diff --git a/nuttx/net/uip/uip_icmpsend.c b/nuttx/net/uip/uip_icmpsend.c index 8e68441f2..6acbf3176 100644 --- a/nuttx/net/uip/uip_icmpsend.c +++ b/nuttx/net/uip/uip_icmpsend.c @@ -1,7 +1,7 @@ /**************************************************************************** * net/uip/uip_icmsend.c * - * Copyright (C) 2008 Gregory Nutt. All rights reserved. + * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * Redistribution and use in source and binary forms, with or without @@ -90,6 +90,8 @@ void uip_icmpsend(struct uip_driver_s *dev, uip_ipaddr_t *destaddr) { + struct uip_icmpip_hdr *picmp = ICMPBUF; + if (dev->d_sndlen > 0) { /* The total length to send is the size of the application data plus @@ -110,52 +112,52 @@ void uip_icmpsend(struct uip_driver_s *dev, uip_ipaddr_t *destaddr) #ifdef CONFIG_NET_IPv6 - ICMPBUF->vtc = 0x60; - ICMPBUF->tcf = 0x00; - ICMPBUF->flow = 0x00; - ICMPBUF->len[0] = (dev->d_sndlen >> 8); - ICMPBUF->len[1] = (dev->d_sndlen & 0xff); - ICMPBUF->nexthdr = UIP_PROTO_ICMP; - ICMPBUF->hoplimit = UIP_TTL; + picmp->vtc = 0x60; + picmp->tcf = 0x00; + picmp->flow = 0x00; + picmp->len[0] = (dev->d_sndlen >> 8); + picmp->len[1] = (dev->d_sndlen & 0xff); + picmp->nexthdr = UIP_PROTO_ICMP; + picmp->hoplimit = UIP_TTL; - uip_ipaddr_copy(ICMPBUF->srcipaddr, &dev->d_ipaddr); - uip_ipaddr_copy(ICMPBUF->destipaddr, destaddr); + uip_ipaddr_copy(picmp->srcipaddr, &dev->d_ipaddr); + uip_ipaddr_copy(picmp->destipaddr, destaddr); #else /* CONFIG_NET_IPv6 */ - ICMPBUF->vhl = 0x45; - ICMPBUF->tos = 0; - ICMPBUF->len[0] = (dev->d_len >> 8); - ICMPBUF->len[1] = (dev->d_len & 0xff); + picmp->vhl = 0x45; + picmp->tos = 0; + picmp->len[0] = (dev->d_len >> 8); + picmp->len[1] = (dev->d_len & 0xff); ++g_ipid; - ICMPBUF->ipid[0] = g_ipid >> 8; - ICMPBUF->ipid[1] = g_ipid & 0xff; - ICMPBUF->ipoffset[0] = UIP_TCPFLAG_DONTFRAG >> 8; - ICMPBUF->ipoffset[1] = UIP_TCPFLAG_DONTFRAG & 0xff; - ICMPBUF->ttl = UIP_TTL; - ICMPBUF->proto = UIP_PROTO_ICMP; + picmp->ipid[0] = g_ipid >> 8; + picmp->ipid[1] = g_ipid & 0xff; + picmp->ipoffset[0] = UIP_TCPFLAG_DONTFRAG >> 8; + picmp->ipoffset[1] = UIP_TCPFLAG_DONTFRAG & 0xff; + picmp->ttl = UIP_TTL; + picmp->proto = UIP_PROTO_ICMP; - uiphdr_ipaddr_copy(ICMPBUF->srcipaddr, &dev->d_ipaddr); - uiphdr_ipaddr_copy(ICMPBUF->destipaddr, destaddr); + uiphdr_ipaddr_copy(picmp->srcipaddr, &dev->d_ipaddr); + uiphdr_ipaddr_copy(picmp->destipaddr, destaddr); /* Calculate IP checksum. */ - ICMPBUF->ipchksum = 0; - ICMPBUF->ipchksum = ~(uip_ipchksum(dev)); + picmp->ipchksum = 0; + picmp->ipchksum = ~(uip_ipchksum(dev)); #endif /* CONFIG_NET_IPv6 */ /* Calculate the ICMP checksum. */ - ICMPBUF->icmpchksum = 0; - ICMPBUF->icmpchksum = ~(uip_icmpchksum(dev)); - if (ICMPBUF->icmpchksum == 0) + picmp->icmpchksum = 0; + picmp->icmpchksum = ~(uip_icmpchksum(dev)); + if (picmp->icmpchksum == 0) { - ICMPBUF->icmpchksum = 0xffff; + picmp->icmpchksum = 0xffff; } nvdbg("Outgoing ICMP packet length: %d (%d)\n", - dev->d_len, (ICMPBUF->len[0] << 8) | ICMPBUF->len[1]); + dev->d_len, (picmp->len[0] << 8) | picmp->len[1]); #ifdef CONFIG_NET_STATISTICS uip_stat.icmp.sent++; diff --git a/nuttx/net/uip/uip_input.c b/nuttx/net/uip/uip_input.c index 640103b87..fe5302644 100644 --- a/nuttx/net/uip/uip_input.c +++ b/nuttx/net/uip/uip_input.c @@ -2,7 +2,7 @@ * net/uip/uip_input.c * The uIP TCP/IP stack code. * - * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009 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: @@ -144,7 +144,10 @@ static uint8 uip_reassflags; #if UIP_REASSEMBLY && !defined(CONFIG_NET_IPv6) static uint8 uip_reass(void) { - uint16 offset, len; + struct uip_ip_hdr *pbuf = BUF; + struct uip_ip_hdr *pfbuf = FBUF; + uint16 offset; + uint16 len; uint16 i; /* If uip_reasstmr is zero, no packet is present in the buffer, so we @@ -154,7 +157,7 @@ static uint8 uip_reass(void) if (!uip_reasstmr) { - memcpy(uip_reassbuf, &BUF->vhl, UIP_IPH_LEN); + memcpy(uip_reassbuf, &pbuf->vhl, UIP_IPH_LEN); uip_reasstmr = UIP_REASS_MAXAGE; uip_reassflags = 0; @@ -167,12 +170,12 @@ static uint8 uip_reass(void) * fragment into the buffer. */ - if (uiphdr_addr_cmp(BUF->srcipaddr, FBUF->srcipaddr) && - uiphdr_addr_cmp(BUF->destipaddr == FBUF->destipaddr) && - BUF->g_ipid[0] == FBUF->g_ipid[0] && BUF->g_ipid[1] == FBUF->g_ipid[1]) + if (uiphdr_addr_cmp(pbuf->srcipaddr, pfbuf->srcipaddr) && + uiphdr_addr_cmp(pbuf->destipaddr == pfbuf->destipaddr) && + pbuf->g_ipid[0] == pfbuf->g_ipid[0] && pbuf->g_ipid[1] == pfbuf->g_ipid[1]) { - len = (BUF->len[0] << 8) + BUF->len[1] - (BUF->vhl & 0x0f) * 4; - offset = (((BUF->ipoffset[0] & 0x3f) << 8) + BUF->ipoffset[1]) * 8; + len = (pbuf->len[0] << 8) + pbuf->len[1] - (pbuf->vhl & 0x0f) * 4; + offset = (((pbuf->ipoffset[0] & 0x3f) << 8) + pbuf->ipoffset[1]) * 8; /* If the offset or the offset + fragment length overflows the * reassembly buffer, we discard the entire packet. @@ -186,7 +189,7 @@ static uint8 uip_reass(void) /* Copy the fragment into the reassembly buffer, at the right offset. */ - memcpy(&uip_reassbuf[UIP_IPH_LEN + offset], (char *)BUF + (int)((BUF->vhl & 0x0f) * 4), len); + memcpy(&uip_reassbuf[UIP_IPH_LEN + offset], (char *)pbuf + (int)((pbuf->vhl & 0x0f) * 4), len); /* Update the bitmap. */ @@ -218,7 +221,7 @@ static uint8 uip_reass(void) * we have received the final fragment. */ - if ((BUF->ipoffset[0] & IP_MF) == 0) + if ((pbuf->ipoffset[0] & IP_MF) == 0) { uip_reassflags |= UIP_REASS_FLAG_LASTFRAG; uip_reasslen = offset + len; @@ -258,17 +261,17 @@ static uint8 uip_reass(void) */ uip_reasstmr = 0; - memcpy(BUF, FBUF, uip_reasslen); + memcpy(pbuf, pfbuf, uip_reasslen); /* Pretend to be a "normal" (i.e., not fragmented) IP packet from * now on. */ - BUF->ipoffset[0] = BUF->ipoffset[1] = 0; - BUF->len[0] = uip_reasslen >> 8; - BUF->len[1] = uip_reasslen & 0xff; - BUF->ipchksum = 0; - BUF->ipchksum = ~(uip_ipchksum(dev)); + pbuf->ipoffset[0] = pbuf->ipoffset[1] = 0; + pbuf->len[0] = uip_reasslen >> 8; + pbuf->len[1] = uip_reasslen & 0xff; + pbuf->ipchksum = 0; + pbuf->ipchksum = ~(uip_ipchksum(dev)); return uip_reasslen; } @@ -294,6 +297,8 @@ nullreturn: void uip_input(struct uip_driver_s *dev) { + struct uip_ip_hdr *pbuf = BUF; + /* This is where the input processing starts. */ #ifdef CONFIG_NET_STATISTICS @@ -305,7 +310,7 @@ void uip_input(struct uip_driver_s *dev) #ifdef CONFIG_NET_IPv6 /* Check validity of the IP header. */ - if ((BUF->vtc & 0xf0) != 0x60) + if ((pbuf->vtc & 0xf0) != 0x60) { /* IP version and header length. */ @@ -313,13 +318,13 @@ void uip_input(struct uip_driver_s *dev) uip_stat.ip.drop++; uip_stat.ip.vhlerr++; #endif - ndbg("Invalid IPv6 version: %d\n", BUF->vtc >> 4); + ndbg("Invalid IPv6 version: %d\n", pbuf->vtc >> 4); goto drop; } #else /* CONFIG_NET_IPv6 */ /* Check validity of the IP header. */ - if (BUF->vhl != 0x45) + if (pbuf->vhl != 0x45) { /* IP version and header length. */ @@ -327,7 +332,7 @@ void uip_input(struct uip_driver_s *dev) uip_stat.ip.drop++; uip_stat.ip.vhlerr++; #endif - ndbg("Invalid IP version or header length: %02x\n", BUF->vhl); + ndbg("Invalid IP version or header length: %02x\n", pbuf->vhl); goto drop; } #endif /* CONFIG_NET_IPv6 */ @@ -339,9 +344,9 @@ void uip_input(struct uip_driver_s *dev) * we set d_len to the correct value. */ - if ((BUF->len[0] << 8) + BUF->len[1] <= dev->d_len) + if ((pbuf->len[0] << 8) + pbuf->len[1] <= dev->d_len) { - dev->d_len = (BUF->len[0] << 8) + BUF->len[1]; + dev->d_len = (pbuf->len[0] << 8) + pbuf->len[1]; #ifdef CONFIG_NET_IPv6 /* The length reported in the IPv6 header is the length of the * payload that follows the header. However, uIP uses the d_len @@ -363,7 +368,7 @@ void uip_input(struct uip_driver_s *dev) #ifndef CONFIG_NET_IPv6 /* Check the fragment flag. */ - if ((BUF->ipoffset[0] & 0x3f) != 0 || BUF->ipoffset[1] != 0) + if ((pbuf->ipoffset[0] & 0x3f) != 0 || pbuf->ipoffset[1] != 0) { #if UIP_REASSEMBLY dev->d_len = uip_reass(); @@ -389,11 +394,11 @@ void uip_input(struct uip_driver_s *dev) */ #if defined(CONFIG_NET_BROADCAST) && defined(CONFIG_NET_UDP) - if (BUF->proto == UIP_PROTO_UDP && + if (pbuf->proto == UIP_PROTO_UDP && #ifndef CONFIG_NET_IPv6 - uip_ipaddr_cmp(uip_ip4addr_conv(BUF->destipaddr), g_alloneaddr)) + uip_ipaddr_cmp(uip_ip4addr_conv(pbuf->destipaddr), g_alloneaddr)) #else - uip_ipaddr_cmp(BUF->destipaddr, g_alloneaddr)) + uip_ipaddr_cmp(pbuf->destipaddr, g_alloneaddr)) #endif { uip_udpinput(dev); @@ -416,7 +421,7 @@ void uip_input(struct uip_driver_s *dev) */ #if defined(CONFIG_NET_PINGADDRCONF) && !defined(CONFIG_NET_IPv6) - if (BUF->proto == UIP_PROTO_ICMP) + if (pbuf->proto == UIP_PROTO_ICMP) { ndbg("Possible ping config packet received\n"); uip_icmpinput(dev); @@ -436,7 +441,7 @@ void uip_input(struct uip_driver_s *dev) { /* Check if the packet is destined for our IP address. */ #ifndef CONFIG_NET_IPv6 - if (!uip_ipaddr_cmp(uip_ip4addr_conv(BUF->destipaddr), dev->d_ipaddr)) + if (!uip_ipaddr_cmp(uip_ip4addr_conv(pbuf->destipaddr), dev->d_ipaddr)) { #ifdef CONFIG_NET_STATISTICS uip_stat.ip.drop++; @@ -451,8 +456,8 @@ void uip_input(struct uip_driver_s *dev) * multicast packets that are sent to the ff02::/16 addresses. */ - if (!uip_ipaddr_cmp(BUF->destipaddr, dev->d_ipaddr) && - BUF->destipaddr & HTONL(0xffff0000) != HTONL(0xff020000)) + if (!uip_ipaddr_cmp(pbuf->destipaddr, dev->d_ipaddr) && + pbuf->destipaddr & HTONL(0xffff0000) != HTONL(0xff020000)) { #ifdef CONFIG_NET_STATISTICS uip_stat.ip.drop++; @@ -480,7 +485,7 @@ void uip_input(struct uip_driver_s *dev) * according to the protocol. */ - switch (BUF->proto) + switch (pbuf->proto) { #ifdef CONFIG_NET_TCP case UIP_PROTO_TCP: /* TCP input */ diff --git a/nuttx/net/uip/uip_tcpappsend.c b/nuttx/net/uip/uip_tcpappsend.c index 1d6bb7a67..786ea7081 100644 --- a/nuttx/net/uip/uip_tcpappsend.c +++ b/nuttx/net/uip/uip_tcpappsend.c @@ -1,7 +1,7 @@ /**************************************************************************** * net/uip/uip_tcpappsend.c * - * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009 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: @@ -57,8 +57,6 @@ * Definitions ****************************************************************************/ -#define BUF ((struct uip_tcpip_hdr *)&dev->d_buf[UIP_LLH_LEN]) - /**************************************************************************** * Public Variables ****************************************************************************/ diff --git a/nuttx/net/uip/uip_tcpinput.c b/nuttx/net/uip/uip_tcpinput.c index cab58e48d..362229d74 100644 --- a/nuttx/net/uip/uip_tcpinput.c +++ b/nuttx/net/uip/uip_tcpinput.c @@ -2,7 +2,7 @@ * net/uip/uip_tcpinput.c * Handling incoming TCP input * - * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009 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: @@ -97,6 +97,7 @@ void uip_tcpinput(struct uip_driver_s *dev) { struct uip_conn *conn = NULL; + struct uip_tcpip_hdr *pbuf = BUF; uint16 tmp16; uint16 flags; uint8 opt; @@ -127,7 +128,7 @@ void uip_tcpinput(struct uip_driver_s *dev) /* Demultiplex this segment. First check any active connections. */ - conn = uip_tcpactive(BUF); + conn = uip_tcpactive(pbuf); if (conn) { goto found; @@ -139,13 +140,13 @@ void uip_tcpinput(struct uip_driver_s *dev) * it is an old packet and we send a RST. */ - if ((BUF->flags & TCP_CTL) == TCP_SYN) + if ((pbuf->flags & TCP_CTL) == TCP_SYN) { /* This is a SYN packet for a connection. Find the connection * listening on this port. */ - tmp16 = BUF->destport; + tmp16 = pbuf->destport; if (uip_islistener(tmp16)) { /* We matched the incoming packet with a connection in LISTEN. @@ -157,7 +158,7 @@ void uip_tcpinput(struct uip_driver_s *dev) * user application to accept it. */ - conn = uip_tcpaccept(BUF); + conn = uip_tcpaccept(pbuf); if (conn) { /* The connection structure was successfully allocated. Now see @@ -193,9 +194,9 @@ void uip_tcpinput(struct uip_driver_s *dev) /* Parse the TCP MSS option, if present. */ - if ((BUF->tcpoffset & 0xf0) > 0x50) + if ((pbuf->tcpoffset & 0xf0) > 0x50) { - for (i = 0; i < ((BUF->tcpoffset >> 4) - 5) << 2 ;) + for (i = 0; i < ((pbuf->tcpoffset >> 4) - 5) << 2 ;) { opt = dev->d_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + i]; if (opt == TCP_OPT_END) @@ -256,7 +257,7 @@ void uip_tcpinput(struct uip_driver_s *dev) /* We do not send resets in response to resets. */ - if (BUF->flags & TCP_RST) + if (pbuf->flags & TCP_RST) { goto drop; } @@ -277,7 +278,7 @@ found: * before we accept the reset. */ - if (BUF->flags & TCP_RST) + if (pbuf->flags & TCP_RST) { conn->tcpstateflags = UIP_CLOSED; ndbg("RESET - TCP state: UIP_CLOSED\n"); @@ -290,7 +291,7 @@ found: * any data to us. */ - len = (BUF->tcpoffset >> 4) << 2; + len = (pbuf->tcpoffset >> 4) << 2; /* d_len will contain the length of the actual TCP data. This is * calculated by subtracting the length of the TCP header (in @@ -305,10 +306,10 @@ found: */ if (!(((conn->tcpstateflags & UIP_TS_MASK) == UIP_SYN_SENT) && - ((BUF->flags & TCP_CTL) == (TCP_SYN | TCP_ACK)))) + ((pbuf->flags & TCP_CTL) == (TCP_SYN | TCP_ACK)))) { - if ((dev->d_len > 0 || ((BUF->flags & (TCP_SYN | TCP_FIN)) != 0)) && - memcmp(BUF->seqno, conn->rcv_nxt, 4) != 0) + if ((dev->d_len > 0 || ((pbuf->flags & (TCP_SYN | TCP_FIN)) != 0)) && + memcmp(pbuf->seqno, conn->rcv_nxt, 4) != 0) { uip_tcpsend(dev, conn, TCP_ACK, UIP_IPTCPH_LEN); return; @@ -321,14 +322,14 @@ found: * retransmission timer. */ - if ((BUF->flags & TCP_ACK) && uip_outstanding(conn)) + if ((pbuf->flags & TCP_ACK) && uip_outstanding(conn)) { /* Temporary variables. */ uint8 acc32[4]; uip_add32(conn->snd_nxt, conn->len, acc32); - if (memcmp(BUF->ackno, acc32, 4) == 0) + if (memcmp(pbuf->ackno, acc32, 4) == 0) { /* Update sequence number. */ @@ -414,13 +415,13 @@ found: * state. */ - if ((flags & UIP_ACKDATA) && (BUF->flags & TCP_CTL) == (TCP_SYN | TCP_ACK)) + if ((flags & UIP_ACKDATA) && (pbuf->flags & TCP_CTL) == (TCP_SYN | TCP_ACK)) { /* Parse the TCP MSS option, if present. */ - if ((BUF->tcpoffset & 0xf0) > 0x50) + if ((pbuf->tcpoffset & 0xf0) > 0x50) { - for (i = 0; i < ((BUF->tcpoffset >> 4) - 5) << 2 ;) + for (i = 0; i < ((pbuf->tcpoffset >> 4) - 5) << 2 ;) { opt = dev->d_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN + i]; if (opt == TCP_OPT_END) @@ -471,7 +472,7 @@ found: } conn->tcpstateflags = UIP_ESTABLISHED; - memcpy(conn->rcv_nxt, BUF->seqno, 4); + memcpy(conn->rcv_nxt, pbuf->seqno, 4); nvdbg("TCP state: UIP_ESTABLISHED\n"); uip_incr32(conn->rcv_nxt, 1); @@ -494,7 +495,7 @@ found: /* We do not send resets in response to resets. */ - if (BUF->flags & TCP_RST) + if (pbuf->flags & TCP_RST) { goto drop; } @@ -514,7 +515,7 @@ found: * sequence numbers will be screwed up. */ - if (BUF->flags & TCP_FIN && !(conn->tcpstateflags & UIP_STOPPED)) + if (pbuf->flags & TCP_FIN && !(conn->tcpstateflags & UIP_STOPPED)) { if (uip_outstanding(conn)) { @@ -544,10 +545,10 @@ found: * data that we must pass to the application. */ - if ((BUF->flags & TCP_URG) != 0) + if ((pbuf->flags & TCP_URG) != 0) { #ifdef CONFIG_NET_TCPURGDATA - dev->d_urglen = (BUF->urgp[0] << 8) | BUF->urgp[1]; + dev->d_urglen = (pbuf->urgp[0] << 8) | pbuf->urgp[1]; if (dev->d_urglen > dev->d_len) { /* There is more urgent data in the next segment to come. */ @@ -565,9 +566,9 @@ found: dev->d_urglen = 0; #else /* CONFIG_NET_TCPURGDATA */ dev->d_appdata = - ((uint8*)dev->d_appdata) + ((BUF->urgp[0] << 8) | BUF->urgp[1]); + ((uint8*)dev->d_appdata) + ((pbuf->urgp[0] << 8) | pbuf->urgp[1]); dev->d_len -= - (BUF->urgp[0] << 8) | BUF->urgp[1]; + (pbuf->urgp[0] << 8) | pbuf->urgp[1]; #endif /* CONFIG_NET_TCPURGDATA */ } @@ -597,7 +598,7 @@ found: * "persistent timer" and uses the retransmission mechanim. */ - tmp16 = ((uint16)BUF->wnd[0] << 8) + (uint16)BUF->wnd[1]; + tmp16 = ((uint16)pbuf->wnd[0] << 8) + (uint16)pbuf->wnd[1]; if (tmp16 > conn->initialmss || tmp16 == 0) { tmp16 = conn->initialmss; @@ -655,7 +656,7 @@ found: { uip_incr32(conn->rcv_nxt, dev->d_len); } - if (BUF->flags & TCP_FIN) + if (pbuf->flags & TCP_FIN) { if (flags & UIP_ACKDATA) { @@ -696,7 +697,7 @@ found: uip_incr32(conn->rcv_nxt, dev->d_len); } - if (BUF->flags & TCP_FIN) + if (pbuf->flags & TCP_FIN) { conn->tcpstateflags = UIP_TIME_WAIT; conn->timer = 0; diff --git a/nuttx/net/uip/uip_tcpreadahead.c b/nuttx/net/uip/uip_tcpreadahead.c index b94edc2f7..fc37423fc 100644 --- a/nuttx/net/uip/uip_tcpreadahead.c +++ b/nuttx/net/uip/uip_tcpreadahead.c @@ -1,7 +1,7 @@ /**************************************************************************** * net/uip/uip_tcpreadahead.c * - * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * Redistribution and use in source and binary forms, with or without diff --git a/nuttx/net/uip/uip_tcpsend.c b/nuttx/net/uip/uip_tcpsend.c index d7e48f1f7..a5bb1d715 100644 --- a/nuttx/net/uip/uip_tcpsend.c +++ b/nuttx/net/uip/uip_tcpsend.c @@ -1,7 +1,7 @@ /**************************************************************************** * net/uip/uip_tcpsend.c * - * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009 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: @@ -92,7 +92,9 @@ static void uip_tcpsendcomplete(struct uip_driver_s *dev) { - BUF->ttl = UIP_TTL; + struct uip_tcpip_hdr *pbuf = BUF; + + pbuf->ttl = UIP_TTL; #ifdef CONFIG_NET_IPv6 @@ -100,48 +102,48 @@ static void uip_tcpsendcomplete(struct uip_driver_s *dev) * length. */ - BUF->len[0] = ((dev->d_len - UIP_IPH_LEN) >> 8); - BUF->len[1] = ((dev->d_len - UIP_IPH_LEN) & 0xff); + pbuf->len[0] = ((dev->d_len - UIP_IPH_LEN) >> 8); + pbuf->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); + pbuf->len[0] = (dev->d_len >> 8); + pbuf->len[1] = (dev->d_len & 0xff); #endif /* CONFIG_NET_IPv6 */ - BUF->urgp[0] = BUF->urgp[1] = 0; + pbuf->urgp[0] = pbuf->urgp[1] = 0; /* Calculate TCP checksum. */ - BUF->tcpchksum = 0; - BUF->tcpchksum = ~(uip_tcpchksum(dev)); + pbuf->tcpchksum = 0; + pbuf->tcpchksum = ~(uip_tcpchksum(dev)); #ifdef CONFIG_NET_IPv6 - BUF->vtc = 0x60; - BUF->tcf = 0x00; - BUF->flow = 0x00; + pbuf->vtc = 0x60; + pbuf->tcf = 0x00; + pbuf->flow = 0x00; #else /* CONFIG_NET_IPv6 */ - BUF->vhl = 0x45; - BUF->tos = 0; - BUF->ipoffset[0] = 0; - BUF->ipoffset[1] = 0; + pbuf->vhl = 0x45; + pbuf->tos = 0; + pbuf->ipoffset[0] = 0; + pbuf->ipoffset[1] = 0; ++g_ipid; - BUF->ipid[0] = g_ipid >> 8; - BUF->ipid[1] = g_ipid & 0xff; + pbuf->ipid[0] = g_ipid >> 8; + pbuf->ipid[1] = g_ipid & 0xff; /* Calculate IP checksum. */ - BUF->ipchksum = 0; - BUF->ipchksum = ~(uip_ipchksum(dev)); + pbuf->ipchksum = 0; + pbuf->ipchksum = ~(uip_ipchksum(dev)); #endif /* CONFIG_NET_IPv6 */ nvdbg("Outgoing TCP packet length: %d (%d)\n", - dev->d_len, (BUF->len[0] << 8) | BUF->len[1]); + dev->d_len, (pbuf->len[0] << 8) | pbuf->len[1]); #ifdef CONFIG_NET_STATISTICS uip_stat.tcp.sent++; @@ -171,15 +173,17 @@ static void uip_tcpsendcomplete(struct uip_driver_s *dev) static void uip_tcpsendcommon(struct uip_driver_s *dev, struct uip_conn *conn) { - memcpy(BUF->ackno, conn->rcv_nxt, 4); - memcpy(BUF->seqno, conn->snd_nxt, 4); + struct uip_tcpip_hdr *pbuf = BUF; + + memcpy(pbuf->ackno, conn->rcv_nxt, 4); + memcpy(pbuf->seqno, conn->snd_nxt, 4); - BUF->proto = UIP_PROTO_TCP; - BUF->srcport = conn->lport; - BUF->destport = conn->rport; + pbuf->proto = UIP_PROTO_TCP; + pbuf->srcport = conn->lport; + pbuf->destport = conn->rport; - uiphdr_ipaddr_copy(BUF->srcipaddr, &dev->d_ipaddr); - uiphdr_ipaddr_copy(BUF->destipaddr, &conn->ripaddr); + uiphdr_ipaddr_copy(pbuf->srcipaddr, &dev->d_ipaddr); + uiphdr_ipaddr_copy(pbuf->destipaddr, &conn->ripaddr); if (conn->tcpstateflags & UIP_STOPPED) { @@ -187,13 +191,13 @@ static void uip_tcpsendcommon(struct uip_driver_s *dev, struct uip_conn *conn) * window so that the remote host will stop sending data. */ - BUF->wnd[0] = 0; - BUF->wnd[1] = 0; + pbuf->wnd[0] = 0; + pbuf->wnd[1] = 0; } else { - BUF->wnd[0] = ((CONFIG_NET_RECEIVE_WINDOW) >> 8); - BUF->wnd[1] = ((CONFIG_NET_RECEIVE_WINDOW) & 0xff); + pbuf->wnd[0] = ((CONFIG_NET_RECEIVE_WINDOW) >> 8); + pbuf->wnd[1] = ((CONFIG_NET_RECEIVE_WINDOW) & 0xff); } /* Finish the IP portion of the message, calculate checksums and send @@ -230,9 +234,11 @@ static void uip_tcpsendcommon(struct uip_driver_s *dev, struct uip_conn *conn) void uip_tcpsend(struct uip_driver_s *dev, struct uip_conn *conn, uint16 flags, uint16 len) { - BUF->flags = flags; + struct uip_tcpip_hdr *pbuf = BUF; + + pbuf->flags = flags; dev->d_len = len; - BUF->tcpoffset = (UIP_TCPH_LEN / 4) << 4; + pbuf->tcpoffset = (UIP_TCPH_LEN / 4) << 4; uip_tcpsendcommon(dev, conn); } @@ -255,6 +261,8 @@ void uip_tcpsend(struct uip_driver_s *dev, struct uip_conn *conn, uint16 flags, void uip_tcpreset(struct uip_driver_s *dev) { + struct uip_tcpip_hdr *pbuf = BUF; + uint16 tmp16; uint8 seqbyte; @@ -262,54 +270,54 @@ void uip_tcpreset(struct uip_driver_s *dev) uip_stat.tcp.rst++; #endif - BUF->flags = TCP_RST | TCP_ACK; - dev->d_len = UIP_IPTCPH_LEN; - BUF->tcpoffset = 5 << 4; + pbuf->flags = TCP_RST | TCP_ACK; + dev->d_len = UIP_IPTCPH_LEN; + pbuf->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 = pbuf->seqno[3]; + pbuf->seqno[3] = pbuf->ackno[3]; + pbuf->ackno[3] = seqbyte; - seqbyte = BUF->seqno[2]; - BUF->seqno[2] = BUF->ackno[2]; - BUF->ackno[2] = seqbyte; + seqbyte = pbuf->seqno[2]; + pbuf->seqno[2] = pbuf->ackno[2]; + pbuf->ackno[2] = seqbyte; - seqbyte = BUF->seqno[1]; - BUF->seqno[1] = BUF->ackno[1]; - BUF->ackno[1] = seqbyte; + seqbyte = pbuf->seqno[1]; + pbuf->seqno[1] = pbuf->ackno[1]; + pbuf->ackno[1] = seqbyte; - seqbyte = BUF->seqno[0]; - BUF->seqno[0] = BUF->ackno[0]; - BUF->ackno[0] = seqbyte; + seqbyte = pbuf->seqno[0]; + pbuf->seqno[0] = pbuf->ackno[0]; + pbuf->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 (++(pbuf->ackno[3]) == 0) { - if (++(BUF->ackno[2]) == 0) + if (++(pbuf->ackno[2]) == 0) { - if (++(BUF->ackno[1]) == 0) + if (++(pbuf->ackno[1]) == 0) { - ++(BUF->ackno[0]); + ++(pbuf->ackno[0]); } } } /* Swap port numbers. */ - tmp16 = BUF->srcport; - BUF->srcport = BUF->destport; - BUF->destport = tmp16; + tmp16 = pbuf->srcport; + pbuf->srcport = pbuf->destport; + pbuf->destport = tmp16; /* Swap IP addresses. */ - uiphdr_ipaddr_copy(BUF->destipaddr, BUF->srcipaddr); - uiphdr_ipaddr_copy(BUF->srcipaddr, &dev->d_ipaddr); + uiphdr_ipaddr_copy(pbuf->destipaddr, pbuf->srcipaddr); + uiphdr_ipaddr_copy(pbuf->srcipaddr, &dev->d_ipaddr); /* And send out the RST packet */ @@ -337,18 +345,20 @@ void uip_tcpreset(struct uip_driver_s *dev) void uip_tcpack(struct uip_driver_s *dev, struct uip_conn *conn, uint8 ack) { + struct uip_tcpip_hdr *pbuf = BUF; + /* Save the ACK bits */ - BUF->flags = ack; + pbuf->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; + pbuf->optdata[0] = TCP_OPT_MSS; + pbuf->optdata[1] = TCP_OPT_MSS_LEN; + pbuf->optdata[2] = (UIP_TCP_MSS) / 256; + pbuf->optdata[3] = (UIP_TCP_MSS) & 255; + dev->d_len = UIP_IPTCPH_LEN + TCP_OPT_MSS_LEN; + pbuf->tcpoffset = ((UIP_TCPH_LEN + TCP_OPT_MSS_LEN) / 4) << 4; /* Complete the common portions of the TCP message */ diff --git a/nuttx/net/uip/uip_udpinput.c b/nuttx/net/uip/uip_udpinput.c index b9003cd86..7df58bd9f 100644 --- a/nuttx/net/uip/uip_udpinput.c +++ b/nuttx/net/uip/uip_udpinput.c @@ -2,7 +2,7 @@ * net/uip/uip_udpinput.c * Handling incoming UDP input * - * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009 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: @@ -96,6 +96,7 @@ void uip_udpinput(struct uip_driver_s *dev) { struct uip_udp_conn *conn; + struct uip_udpip_hdr *pbuf = UDPBUF; /* UDP processing is really just a hack. We don't do anything to the UDP/IP * headers, but let the UDP application do all the hard work. If the @@ -105,7 +106,7 @@ void uip_udpinput(struct uip_driver_s *dev) dev->d_len -= UIP_IPUDPH_LEN; #ifdef CONFIG_NET_UDP_CHECKSUMS dev->d_appdata = &dev->d_buf[UIP_LLH_LEN + UIP_IPUDPH_LEN]; - if (UDPBUF->udpchksum != 0 && uip_udpchksum(dev) != 0xffff) + if (pudpbuf->udpchksum != 0 && uip_udpchksum(dev) != 0xffff) { #ifdef CONFIG_NET_STATISTICS uip_stat.udp.drop++; @@ -119,7 +120,7 @@ void uip_udpinput(struct uip_driver_s *dev) { /* Demultiplex this UDP packet between the UDP "connections". */ - conn = uip_udpactive(UDPBUF); + conn = uip_udpactive(pudpbuf); if (conn) { /* Setup for the application callback */ diff --git a/nuttx/net/uip/uip_udpsend.c b/nuttx/net/uip/uip_udpsend.c index 9e6a95a38..af02a3069 100644 --- a/nuttx/net/uip/uip_udpsend.c +++ b/nuttx/net/uip/uip_udpsend.c @@ -1,7 +1,7 @@ /**************************************************************************** * net/uip/uip_udpsend.c * - * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009 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: @@ -57,7 +57,7 @@ * Definitions ****************************************************************************/ -#define UDPBUF ((struct uip_udpip_hdr *)&dev->d_buf[UIP_LLH_LEN]) +#define UDPBUF ((struct uip_udpip_hdr *)&dev->d_buf[UIP_LLH_LEN]) /**************************************************************************** * Public Variables @@ -95,6 +95,8 @@ void uip_udpsend(struct uip_driver_s *dev, struct uip_udp_conn *conn) { + struct uip_udpip_hdr *pudpbuf = UDPBUF; + if (dev->d_sndlen > 0) { /* The total lenth to send is the size of the application data plus @@ -109,62 +111,62 @@ void uip_udpsend(struct uip_driver_s *dev, struct uip_udp_conn *conn) #ifdef CONFIG_NET_IPv6 - UDPBUF->vtc = 0x60; - UDPBUF->tcf = 0x00; - UDPBUF->flow = 0x00; - UDPBUF->len[0] = (dev->d_sndlen >> 8); - UDPBUF->len[1] = (dev->d_sndlen & 0xff); - UDPBUF->nexthdr = UIP_PROTO_UDP; - UDPBUF->hoplimit = conn->ttl; + pudpbuf->vtc = 0x60; + pudpbuf->tcf = 0x00; + pudpbuf->flow = 0x00; + pudpbuf->len[0] = (dev->d_sndlen >> 8); + pudpbuf->len[1] = (dev->d_sndlen & 0xff); + pudpbuf->nexthdr = UIP_PROTO_UDP; + pudpbuf->hoplimit = conn->ttl; - uip_ipaddr_copy(UDPBUF->srcipaddr, &dev->d_ipaddr); - uip_ipaddr_copy(UDPBUF->destipaddr, &conn->ripaddr); + uip_ipaddr_copy(pudpbuf->srcipaddr, &dev->d_ipaddr); + uip_ipaddr_copy(pudpbuf->destipaddr, &conn->ripaddr); #else /* CONFIG_NET_IPv6 */ - UDPBUF->vhl = 0x45; - UDPBUF->tos = 0; - UDPBUF->len[0] = (dev->d_len >> 8); - UDPBUF->len[1] = (dev->d_len & 0xff); + pudpbuf->vhl = 0x45; + pudpbuf->tos = 0; + pudpbuf->len[0] = (dev->d_len >> 8); + pudpbuf->len[1] = (dev->d_len & 0xff); ++g_ipid; - UDPBUF->ipid[0] = g_ipid >> 8; - UDPBUF->ipid[1] = g_ipid & 0xff; - UDPBUF->ipoffset[0] = 0; - UDPBUF->ipoffset[1] = 0; - UDPBUF->ttl = conn->ttl; - UDPBUF->proto = UIP_PROTO_UDP; + pudpbuf->ipid[0] = g_ipid >> 8; + pudpbuf->ipid[1] = g_ipid & 0xff; + pudpbuf->ipoffset[0] = 0; + pudpbuf->ipoffset[1] = 0; + pudpbuf->ttl = conn->ttl; + pudpbuf->proto = UIP_PROTO_UDP; - uiphdr_ipaddr_copy(UDPBUF->srcipaddr, &dev->d_ipaddr); - uiphdr_ipaddr_copy(UDPBUF->destipaddr, &conn->ripaddr); + uiphdr_ipaddr_copy(pudpbuf->srcipaddr, &dev->d_ipaddr); + uiphdr_ipaddr_copy(pudpbuf->destipaddr, &conn->ripaddr); /* Calculate IP checksum. */ - UDPBUF->ipchksum = 0; - UDPBUF->ipchksum = ~(uip_ipchksum(dev)); + pudpbuf->ipchksum = 0; + pudpbuf->ipchksum = ~(uip_ipchksum(dev)); #endif /* CONFIG_NET_IPv6 */ /* Initialize the UDP header */ - UDPBUF->srcport = conn->lport; - UDPBUF->destport = conn->rport; - UDPBUF->udplen = HTONS(dev->d_sndlen + UIP_UDPH_LEN); + pudpbuf->srcport = conn->lport; + pudpbuf->destport = conn->rport; + pudpbuf->udplen = HTONS(dev->d_sndlen + UIP_UDPH_LEN); #ifdef CONFIG_NET_UDP_CHECKSUMS /* Calculate UDP checksum. */ - UDPBUF->udpchksum = 0; - UDPBUF->udpchksum = ~(uip_udpchksum(dev)); - if (UDPBUF->udpchksum == 0) + pudpbuf->udpchksum = 0; + pudpbuf->udpchksum = ~(uip_udpchksum(dev)); + if (pudpbuf->udpchksum == 0) { - UDPBUF->udpchksum = 0xffff; + pudpbuf->udpchksum = 0xffff; } #else - UDPBUF->udpchksum = 0; + pudpbuf->udpchksum = 0; #endif nvdbg("Outgoing UDP packet length: %d (%d)\n", - dev->d_len, (UDPBUF->len[0] << 8) | UDPBUF->len[1]); + dev->d_len, (pudpbuf->len[0] << 8) | pudpbuf->len[1]); #ifdef CONFIG_NET_STATISTICS uip_stat.udp.sent++; |