This commit is contained in:
Richard Barry 2007-06-05 09:35:13 +00:00
parent 014d7f5b8f
commit 22e434dfaf
134 changed files with 39468 additions and 39401 deletions

View file

@ -135,8 +135,14 @@ struct uip_eth_addr uip_ethaddr = {{0,0,0,0,0,0}};
#endif
#ifndef UIP_CONF_EXTERNAL_BUFFER
u8_t uip_buf[UIP_BUFSIZE + 2] ALIGN_STRUCT_END; /* The packet buffer that contains
incoming packets. */
#ifdef __ICCARM__
#pragma data_alignment=4
u8_t uip_buf[UIP_BUFSIZE + 2]; /* The packet buffer that contains incoming packets. */
#else
u8_t uip_buf[UIP_BUFSIZE + 2] ALIGN_STRUCT_END; /* The packet buffer that contains incoming packets. */
#endif
#endif /* UIP_CONF_EXTERNAL_BUFFER */
void *uip_appdata; /* The uip_appdata pointer points to
@ -251,15 +257,15 @@ uip_add32(u8_t *op32, u16_t op16)
uip_acc32[2] = op32[2] + (op16 >> 8);
uip_acc32[1] = op32[1];
uip_acc32[0] = op32[0];
if(uip_acc32[2] < (op16 >> 8)) {
++uip_acc32[1];
if(uip_acc32[1] == 0) {
++uip_acc32[0];
}
}
if(uip_acc32[3] < (op16 & 0xff)) {
++uip_acc32[2];
if(uip_acc32[2] == 0) {
@ -284,7 +290,7 @@ chksum(u16_t sum, const u8_t *data, u16_t len)
dataptr = data;
last_byte = data + len - 1;
while(dataptr < last_byte) { /* At least two more bytes */
t = (dataptr[0] << 8) + dataptr[1];
sum += t;
@ -293,7 +299,7 @@ chksum(u16_t sum, const u8_t *data, u16_t len)
}
dataptr += 2;
}
if(dataptr == last_byte) {
t = (dataptr[0] << 8) + 0;
sum += t;
@ -329,15 +335,15 @@ upper_layer_chksum(u8_t proto)
{
u16_t upper_layer_len;
u16_t sum;
#if UIP_CONF_IPV6
upper_layer_len = (((u16_t)(BUF->len[0]) << 8) + BUF->len[1]);
#else /* UIP_CONF_IPV6 */
upper_layer_len = (((u16_t)(BUF->len[0]) << 8) + BUF->len[1]) - UIP_IPH_LEN;
#endif /* UIP_CONF_IPV6 */
/* First sum pseudoheader. */
/* IP protocol and length fields. This addition cannot carry. */
sum = upper_layer_len + proto;
/* Sum IP source and destination addresses. */
@ -346,7 +352,7 @@ upper_layer_chksum(u8_t proto)
/* Sum TCP header and data. */
sum = chksum(sum, &uip_buf[UIP_IPH_LEN + UIP_LLH_LEN],
upper_layer_len);
return (sum == 0) ? 0xffff : htons(sum);
}
/*---------------------------------------------------------------------------*/
@ -355,7 +361,7 @@ u16_t
uip_icmp6chksum(void)
{
return upper_layer_chksum(UIP_PROTO_ICMP6);
}
#endif /* UIP_CONF_IPV6 */
/*---------------------------------------------------------------------------*/
@ -392,7 +398,7 @@ uip_init(void)
uip_udp_conns[c].lport = 0;
}
#endif /* UIP_UDP */
/* IPv4 initialization. */
#if UIP_FIXEDADDR == 0
@ -406,7 +412,7 @@ struct uip_conn *
uip_connect(uip_ipaddr_t *ripaddr, u16_t rport)
{
register struct uip_conn *conn, *cconn;
/* Find an unused local port. */
again:
++lastport;
@ -443,7 +449,7 @@ uip_connect(uip_ipaddr_t *ripaddr, u16_t rport)
if(conn == 0) {
return 0;
}
conn->tcpstateflags = UIP_SYN_SENT;
conn->snd_nxt[0] = iss[0];
@ -452,7 +458,7 @@ uip_connect(uip_ipaddr_t *ripaddr, u16_t rport)
conn->snd_nxt[3] = iss[3];
conn->initialmss = conn->mss = UIP_TCP_MSS;
conn->len = 1; /* TCP length of the SYN is one. */
conn->nrtx = 0;
conn->timer = 1; /* Send the SYN next time around. */
@ -462,7 +468,7 @@ uip_connect(uip_ipaddr_t *ripaddr, u16_t rport)
conn->lport = htons(lastport);
conn->rport = rport;
uip_ipaddr_copy(&conn->ripaddr, ripaddr);
return conn;
}
#endif /* UIP_ACTIVE_OPEN */
@ -472,7 +478,7 @@ struct uip_udp_conn *
uip_udp_new(uip_ipaddr_t *ripaddr, u16_t rport)
{
register struct uip_udp_conn *conn;
/* Find an unused local port. */
again:
++lastport;
@ -480,7 +486,7 @@ uip_udp_new(uip_ipaddr_t *ripaddr, u16_t rport)
if(lastport >= 32000) {
lastport = 4096;
}
for(c = 0; c < UIP_UDP_CONNS; ++c) {
if(uip_udp_conns[c].lport == htons(lastport)) {
goto again;
@ -499,7 +505,7 @@ uip_udp_new(uip_ipaddr_t *ripaddr, u16_t rport)
if(conn == 0) {
return 0;
}
conn->lport = HTONS(lastport);
conn->rport = rport;
if(ripaddr == NULL) {
@ -508,7 +514,7 @@ uip_udp_new(uip_ipaddr_t *ripaddr, u16_t rport)
uip_ipaddr_copy(&conn->ripaddr, ripaddr);
}
conn->ttl = UIP_TTL;
return conn;
}
#endif /* UIP_UDP */
@ -593,12 +599,12 @@ uip_reass(void)
memcpy(&uip_reassbuf[UIP_IPH_LEN + offset],
(char *)BUF + (int)((BUF->vhl & 0x0f) * 4),
len);
/* Update the bitmap. */
if(offset / (8 * 8) == (offset + len) / (8 * 8)) {
/* If the two endpoints are in the same byte, we only update
that byte. */
uip_reassbitmap[offset / (8 * 8)] |=
bitmap_bits[(offset / 8 ) & 7] &
~bitmap_bits[((offset + len) / 8 ) & 7];
@ -614,7 +620,7 @@ uip_reass(void)
uip_reassbitmap[(offset + len) / (8 * 8)] |=
~bitmap_bits[((offset + len) / 8 ) & 7];
}
/* If this fragment has the More Fragments flag set to zero, we
know that this is the last fragment, so we can calculate the
size of the entire packet. We also set the
@ -625,7 +631,7 @@ uip_reass(void)
uip_reassflags |= UIP_REASS_FLAG_LASTFRAG;
uip_reasslen = offset + len;
}
/* Finally, we check if we have a full packet in the buffer. We do
this by checking if we have the last fragment and if all bits
in the bitmap are set. */
@ -687,7 +693,7 @@ uip_process(u8_t flag)
goto udp_send;
}
#endif /* UIP_UDP */
uip_sappdata = uip_appdata = &uip_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN];
/* Check if we were invoked because of a poll request for a
@ -700,7 +706,7 @@ uip_process(u8_t flag)
goto appsend;
}
goto drop;
/* Check if we were invoked because of the perodic timer fireing. */
} else if(flag == UIP_TIMER) {
#if UIP_REASSEMBLY
@ -759,7 +765,7 @@ uip_process(u8_t flag)
4:
uip_connr->nrtx);
++(uip_connr->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
@ -772,14 +778,14 @@ uip_process(u8_t flag)
/* In the SYN_RCVD state, we should retransmit our
SYNACK. */
goto tcp_send_synack;
#if UIP_ACTIVE_OPEN
case UIP_SYN_SENT:
/* In the SYN_SENT state, we retransmit out SYN. */
BUF->flags = 0;
goto tcp_send_syn;
#endif /* UIP_ACTIVE_OPEN */
case UIP_ESTABLISHED:
/* In the ESTABLISHED state, we call upon the application
to do the actual retransmit after which we jump into
@ -788,13 +794,13 @@ uip_process(u8_t flag)
uip_flags = UIP_REXMIT;
UIP_APPCALL();
goto apprexmit;
case UIP_FIN_WAIT_1:
case UIP_CLOSING:
case UIP_LAST_ACK:
/* In all these states we should retransmit a FINACK. */
goto tcp_send_finack;
}
}
} else if((uip_connr->tcpstateflags & UIP_TS_MASK) == UIP_ESTABLISHED) {
@ -826,7 +832,7 @@ uip_process(u8_t flag)
UIP_STAT(++uip_stat.ip.recv);
/* Start of IP input header processing code. */
#if UIP_CONF_IPV6
/* Check validity of the IP header. */
if((BUF->vtc & 0xf0) != 0x60) { /* IP version and header length. */
@ -844,7 +850,7 @@ uip_process(u8_t flag)
goto drop;
}
#endif /* UIP_CONF_IPV6 */
/* Check the size of the packet. If the size reported to us in
uip_len is smaller the size reported in the IP header, we assume
that the packet has been corrupted in transit. If the size of
@ -914,7 +920,7 @@ uip_process(u8_t flag)
goto udp_input;
}
#endif /* UIP_BROADCAST */
/* Check if the packet is destined for our IP address. */
#if !UIP_CONF_IPV6
if(!uip_ipaddr_cmp(BUF->destipaddr, uip_hostaddr)) {
@ -1032,14 +1038,14 @@ uip_process(u8_t flag)
/* Save the sender's address in our neighbor list. */
uip_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;
uip_ipaddr_copy(ICMPBUF->destipaddr, ICMPBUF->srcipaddr);
uip_ipaddr_copy(ICMPBUF->srcipaddr, uip_hostaddr);
ICMPBUF->options[0] = ICMP6_OPTION_TARGET_LINK_ADDRESS;
@ -1048,7 +1054,7 @@ uip_process(u8_t flag)
ICMPBUF->icmpchksum = 0;
ICMPBUF->icmpchksum = ~uip_icmp6chksum();
goto send;
}
goto drop;
} else if(ICMPBUF->type == ICMP6_ECHO) {
@ -1057,12 +1063,12 @@ uip_process(u8_t flag)
ICMP checksum before we return the packet. */
ICMPBUF->type = ICMP6_ECHO_REPLY;
uip_ipaddr_copy(BUF->destipaddr, BUF->srcipaddr);
uip_ipaddr_copy(BUF->srcipaddr, uip_hostaddr);
ICMPBUF->icmpchksum = 0;
ICMPBUF->icmpchksum = ~uip_icmp6chksum();
UIP_STAT(++uip_stat.icmp.sent);
goto send;
} else {
@ -1074,7 +1080,7 @@ uip_process(u8_t flag)
}
/* End of IPv6 ICMP processing. */
#endif /* !UIP_CONF_IPV6 */
#if UIP_UDP
@ -1120,7 +1126,7 @@ uip_process(u8_t flag)
}
UIP_LOG("udp: no matching connection found");
goto drop;
udp_found:
uip_conn = NULL;
uip_flags = UIP_NEWDATA;
@ -1154,7 +1160,7 @@ uip_process(u8_t flag)
uip_ipaddr_copy(BUF->srcipaddr, uip_hostaddr);
uip_ipaddr_copy(BUF->destipaddr, uip_udp_conn->ripaddr);
uip_appdata = &uip_buf[UIP_LLH_LEN + UIP_IPTCPH_LEN];
#if UIP_UDP_CHECKSUMS
@ -1164,16 +1170,16 @@ uip_process(u8_t flag)
UDPBUF->udpchksum = 0xffff;
}
#endif /* UIP_UDP_CHECKSUMS */
goto ip_send_nolen;
#endif /* UIP_UDP */
/* TCP input processing. */
tcp_input:
UIP_STAT(++uip_stat.tcp.recv);
/* Start of TCP input header processing code. */
if(uip_tcpchksum() != 0xffff) { /* Compute and check the TCP
checksum. */
UIP_STAT(++uip_stat.tcp.drop);
@ -1181,8 +1187,8 @@ uip_process(u8_t flag)
UIP_LOG("tcp: bad checksum.");
goto drop;
}
/* Demultiplex this segment. */
/* First check any active connections. */
for(uip_connr = &uip_conns[0]; uip_connr <= &uip_conns[UIP_CONNS - 1];
@ -1202,14 +1208,14 @@ uip_process(u8_t flag)
if((BUF->flags & TCP_CTL) != TCP_SYN) {
goto reset;
}
tmp16 = BUF->destport;
/* Next, check listening connections. */
for(c = 0; c < UIP_LISTENPORTS; ++c) {
if(tmp16 == uip_listenports[c])
goto found_listen;
}
/* No matching connection found, so we send a RST packet. */
UIP_STAT(++uip_stat.tcp.synrst);
reset:
@ -1220,7 +1226,7 @@ uip_process(u8_t flag)
}
UIP_STAT(++uip_stat.tcp.rst);
BUF->flags = TCP_RST | TCP_ACK;
uip_len = UIP_IPTCPH_LEN;
BUF->tcpoffset = 5 << 4;
@ -1229,15 +1235,15 @@ uip_process(u8_t flag)
c = BUF->seqno[3];
BUF->seqno[3] = BUF->ackno[3];
BUF->ackno[3] = c;
c = BUF->seqno[2];
BUF->seqno[2] = BUF->ackno[2];
BUF->ackno[2] = c;
c = BUF->seqno[1];
BUF->seqno[1] = BUF->ackno[1];
BUF->ackno[1] = c;
c = BUF->seqno[0];
BUF->seqno[0] = BUF->ackno[0];
BUF->ackno[0] = c;
@ -1252,16 +1258,16 @@ uip_process(u8_t flag)
}
}
}
/* Swap port numbers. */
tmp16 = BUF->srcport;
BUF->srcport = BUF->destport;
BUF->destport = tmp16;
/* Swap IP addresses. */
uip_ipaddr_copy(BUF->destipaddr, BUF->srcipaddr);
uip_ipaddr_copy(BUF->srcipaddr, uip_hostaddr);
/* And send out the RST packet! */
goto tcp_send_noconn;
@ -1298,7 +1304,7 @@ uip_process(u8_t flag)
goto drop;
}
uip_conn = uip_connr;
/* Fill in the necessary fields for the new connection. */
uip_connr->rto = uip_connr->timer = UIP_RTO;
uip_connr->sa = 0;
@ -1354,19 +1360,19 @@ uip_process(u8_t flag)
}
}
}
/* Our response will be a SYNACK. */
#if UIP_ACTIVE_OPEN
tcp_send_synack:
BUF->flags = TCP_ACK;
tcp_send_syn:
BUF->flags |= TCP_SYN;
#else /* UIP_ACTIVE_OPEN */
tcp_send_synack:
BUF->flags = TCP_SYN | TCP_ACK;
#endif /* UIP_ACTIVE_OPEN */
/* We send out the TCP Maximum Segment Size option with our
SYNACK. */
BUF->optdata[0] = TCP_OPT_MSS;
@ -1455,7 +1461,7 @@ uip_process(u8_t flag)
/* Reset length of outstanding data. */
uip_connr->len = 0;
}
}
/* Do different things depending on in what state the connection is. */
@ -1543,7 +1549,7 @@ uip_process(u8_t flag)
uip_conn->tcpstateflags = UIP_CLOSED;
goto reset;
#endif /* UIP_ACTIVE_OPEN */
case UIP_ESTABLISHED:
/* In the ESTABLISHED state, we call upon the application to feed
data into the uip_buf. If the UIP_ACKDATA flag is set, the
@ -1645,7 +1651,7 @@ uip_process(u8_t flag)
UIP_APPCALL();
appsend:
if(uip_flags & UIP_ABORT) {
uip_slen = 0;
uip_connr->tcpstateflags = UIP_CLOSED;
@ -1697,7 +1703,7 @@ uip_process(u8_t flag)
uip_connr->nrtx = 0;
apprexmit:
uip_appdata = uip_sappdata;
/* 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(uip_slen > 0 && uip_connr->len > 0) {
@ -1726,7 +1732,7 @@ uip_process(u8_t flag)
UIP_APPCALL();
}
break;
case UIP_FIN_WAIT_1:
/* The application has closed the connection, but the remote host
hasn't closed its end yet. Thus we do nothing but wait for a
@ -1755,7 +1761,7 @@ uip_process(u8_t flag)
goto tcp_send_ack;
}
goto drop;
case UIP_FIN_WAIT_2:
if(uip_len > 0) {
uip_add_rcv_nxt(uip_len);
@ -1775,7 +1781,7 @@ uip_process(u8_t flag)
case UIP_TIME_WAIT:
goto tcp_send_ack;
case UIP_CLOSING:
if(uip_flags & UIP_ACKDATA) {
uip_connr->tcpstateflags = UIP_TIME_WAIT;
@ -1783,7 +1789,7 @@ uip_process(u8_t flag)
}
}
goto drop;
/* We jump here when we are ready to send the packet, and just want
to set the appropriate TCP sequence numbers in the TCP header. */
@ -1802,14 +1808,14 @@ uip_process(u8_t flag)
BUF->ackno[1] = uip_connr->rcv_nxt[1];
BUF->ackno[2] = uip_connr->rcv_nxt[2];
BUF->ackno[3] = uip_connr->rcv_nxt[3];
BUF->seqno[0] = uip_connr->snd_nxt[0];
BUF->seqno[1] = uip_connr->snd_nxt[1];
BUF->seqno[2] = uip_connr->snd_nxt[2];
BUF->seqno[3] = uip_connr->snd_nxt[3];
BUF->proto = UIP_PROTO_TCP;
BUF->srcport = uip_connr->lport;
BUF->destport = uip_connr->rport;
@ -1838,11 +1844,11 @@ uip_process(u8_t flag)
#endif /* UIP_CONF_IPV6 */
BUF->urgp[0] = BUF->urgp[1] = 0;
/* Calculate TCP checksum. */
BUF->tcpchksum = 0;
BUF->tcpchksum = ~(uip_tcpchksum());
ip_send_nolen:
#if UIP_CONF_IPV6
@ -1861,12 +1867,12 @@ uip_process(u8_t flag)
BUF->ipchksum = ~(uip_ipchksum());
DEBUG_PRINTF("uip ip_send_nolen: chkecum 0x%04x\n", uip_ipchksum());
#endif /* UIP_CONF_IPV6 */
UIP_STAT(++uip_stat.tcp.sent);
send:
DEBUG_PRINTF("Sending packet with length %d (%d)\n", uip_len,
(BUF->len[0] << 8) | BUF->len[1]);
UIP_STAT(++uip_stat.ip.sent);
/* Return and let the caller do the actual transmission. */
uip_flags = 0;

View file

@ -95,7 +95,7 @@ typedef uip_ip4addr_t uip_ipaddr_t;
uip_ipaddr(&addr, 192,168,1,2);
uip_sethostaddr(&addr);
\endcode
* \param addr A pointer to an IP address of type uip_ipaddr_t;
*
@ -419,7 +419,11 @@ void uip_setipid(u16_t id);
}
\endcode
*/
extern u8_t uip_buf[UIP_BUFSIZE+2];
#ifndef UIP_CONF_EXTERNAL_BUFFER
extern u8_t uip_buf[UIP_BUFSIZE+2];
#else
extern unsigned char *uip_buf;
#endif
/** @} */
@ -749,7 +753,7 @@ void uip_send(const void *data, int len);
\code
uip_ipaddr_t addr;
struct uip_udp_conn *c;
uip_ipaddr(&addr, 192,168,2,1);
c = uip_udp_new(&addr, HTONS(12345));
if(c != NULL) {
@ -810,7 +814,7 @@ struct uip_udp_conn *uip_udp_new(uip_ipaddr_t *ripaddr, u16_t rport);
* These functions can be used for converting between different data
* formats used by uIP.
*/
/**
* Construct an IP address from four bytes.
*
@ -822,7 +826,7 @@ struct uip_udp_conn *uip_udp_new(uip_ipaddr_t *ripaddr, u16_t rport);
\code
uip_ipaddr_t ipaddr;
struct uip_conn *c;
uip_ipaddr(&ipaddr, 192,168,1,2);
c = uip_connect(&ipaddr, HTONS(80));
\endcode
@ -1152,11 +1156,11 @@ extern u16_t uip_urglen, uip_surglen;
*/
struct uip_conn {
uip_ipaddr_t ripaddr; /**< The IP address of the remote host. */
u16_t lport; /**< The local TCP port, in network byte order. */
u16_t rport; /**< The local remote TCP port, in network byte
order. */
u8_t rcv_nxt[4]; /**< The sequence number that we expect to
receive next. */
u8_t snd_nxt[4]; /**< The sequence number that was last sent by
@ -1352,7 +1356,7 @@ void uip_process(u8_t flag);
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. */
#define UIP_DATA 1 /* Tells uIP that there is incoming
data in the uip_buf buffer. The
length of the data is stored in the
@ -1379,10 +1383,15 @@ void uip_process(u8_t flag);
#define UIP_TIME_WAIT 7
#define UIP_LAST_ACK 8
#define UIP_TS_MASK 15
#define UIP_STOPPED 16
/* The TCP and IP headers. */
#ifdef __ICCARM__
#pragma pack(1)
#endif
struct uip_tcpip_hdr {
#if UIP_CONF_IPV6
/* IPv6 header. */
@ -1405,7 +1414,7 @@ struct uip_tcpip_hdr {
u16_t srcipaddr[2],
destipaddr[2];
#endif /* UIP_CONF_IPV6 */
/* TCP header. */
u16_t srcport,
destport;
@ -1419,7 +1428,15 @@ struct uip_tcpip_hdr {
u8_t optdata[4];
} PACK_STRUCT_END;
#ifdef __ICCARM__
#pragma pack()
#endif
/* The ICMP and IP headers. */
#ifdef __ICCARM__
#pragma pack(1)
#endif
struct uip_icmpip_hdr {
#if UIP_CONF_IPV6
/* IPv6 header. */
@ -1442,7 +1459,7 @@ struct uip_icmpip_hdr {
u16_t srcipaddr[2],
destipaddr[2];
#endif /* UIP_CONF_IPV6 */
/* ICMP (echo) header. */
u8_t type, icode;
u16_t icmpchksum;
@ -1455,8 +1472,16 @@ struct uip_icmpip_hdr {
#endif /* !UIP_CONF_IPV6 */
} PACK_STRUCT_END;
#ifdef __ICCARM__
#pragma pack()
#endif
/* The UDP and IP headers. */
#ifdef __ICCARM__
#pragma pack(1)
#endif
struct uip_udpip_hdr {
#if UIP_CONF_IPV6
/* IPv6 header. */
@ -1479,7 +1504,7 @@ struct uip_udpip_hdr {
u16_t srcipaddr[2],
destipaddr[2];
#endif /* UIP_CONF_IPV6 */
/* UDP header. */
u16_t srcport,
destport;
@ -1487,6 +1512,10 @@ struct uip_udpip_hdr {
u16_t udpchksum;
} PACK_STRUCT_END;
#ifdef __ICCARM__
#pragma pack()
#endif
/**
@ -1539,10 +1568,18 @@ extern uip_ipaddr_t uip_hostaddr, uip_netmask, uip_draddr;
/**
* Representation of a 48-bit Ethernet address.
*/
#ifdef __ICCARM__
#pragma pack(1)
#endif
struct uip_eth_addr {
u8_t addr[6];
} PACK_STRUCT_END;
#ifdef __ICCARM__
#pragma pack()
#endif
/**
* Calculate the Internet checksum over a buffer.
*

View file

@ -16,7 +16,7 @@
*
* \note This ARP implementation only supports Ethernet.
*/
/**
* \file
* Implementation of the ARP Address Resolution Protocol.
@ -63,6 +63,10 @@
#include <string.h>
#ifdef __ICCARM__
#pragma pack(1)
#endif
struct arp_hdr {
struct uip_eth_hdr ethhdr;
u16_t hwtype;
@ -76,6 +80,14 @@ struct arp_hdr {
u16_t dipaddr[2];
} PACK_STRUCT_END;
#ifdef __ICCARM__
#pragma pack()
#endif
#ifdef __ICCARM__
#pragma pack(1)
#endif
struct ethip_hdr {
struct uip_eth_hdr ethhdr;
/* IP header. */
@ -91,6 +103,10 @@ struct ethip_hdr {
destipaddr[2];
} PACK_STRUCT_END;
#ifdef __ICCARM__
#pragma pack()
#endif
#define ARP_REQUEST 1
#define ARP_REPLY 2
@ -142,7 +158,7 @@ void
uip_arp_timer(void)
{
struct arp_entry *tabptr;
++arptime;
for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
tabptr = &arp_table[i];
@ -172,7 +188,7 @@ uip_arp_update(u16_t *ipaddr, struct uip_eth_addr *ethaddr)
the IP address in this ARP table entry. */
if(ipaddr[0] == tabptr->ipaddr[0] &&
ipaddr[1] == tabptr->ipaddr[1]) {
/* An old entry found, update this and return. */
memcpy(tabptr->ethaddr.addr, ethaddr->addr, 6);
tabptr->time = arptime;
@ -247,7 +263,7 @@ uip_arp_ipin(void)
return;
}
uip_arp_update(IPBUF->srcipaddr, &(IPBUF->ethhdr.src));
return;
}
#endif /* 0 */
@ -277,13 +293,13 @@ uip_arp_ipin(void)
void
uip_arp_arpin(void)
{
if(uip_len < sizeof(struct arp_hdr)) {
uip_len = 0;
return;
}
uip_len = 0;
switch(BUF->opcode) {
case HTONS(ARP_REQUEST):
/* ARP request. If it asked for our address, we send out a
@ -293,7 +309,7 @@ uip_arp_arpin(void)
table, since it is likely that we will do more communication
with this host in the future. */
uip_arp_update(BUF->sipaddr, &BUF->shwaddr);
/* The reply opcode is 2. */
BUF->opcode = HTONS(2);
@ -301,7 +317,7 @@ uip_arp_arpin(void)
memcpy(BUF->shwaddr.addr, uip_ethaddr.addr, 6);
memcpy(BUF->ethhdr.src.addr, uip_ethaddr.addr, 6);
memcpy(BUF->ethhdr.dest.addr, BUF->dhwaddr.addr, 6);
BUF->dipaddr[0] = BUF->sipaddr[0];
BUF->dipaddr[1] = BUF->sipaddr[1];
BUF->sipaddr[0] = uip_hostaddr[0];
@ -354,7 +370,7 @@ void
uip_arp_out(void)
{
struct arp_entry *tabptr;
/* Find the destination IP address in the ARP table and construct
the Ethernet header. If the destination IP addres isn't on the
local network, we use the default router's IP address instead.
@ -376,7 +392,7 @@ uip_arp_out(void)
/* Else, we use the destination IP address. */
uip_ipaddr_copy(ipaddr, IPBUF->destipaddr);
}
for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
tabptr = &arp_table[i];
if(uip_ipaddr_cmp(ipaddr, tabptr->ipaddr)) {
@ -392,7 +408,7 @@ uip_arp_out(void)
memset(BUF->dhwaddr.addr, 0x00, 6);
memcpy(BUF->ethhdr.src.addr, uip_ethaddr.addr, 6);
memcpy(BUF->shwaddr.addr, uip_ethaddr.addr, 6);
uip_ipaddr_copy(BUF->dipaddr, ipaddr);
uip_ipaddr_copy(BUF->sipaddr, uip_hostaddr);
BUF->opcode = HTONS(ARP_REQUEST); /* ARP request. */
@ -403,7 +419,7 @@ uip_arp_out(void)
BUF->ethhdr.type = HTONS(UIP_ETHTYPE_ARP);
uip_appdata = &uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN];
uip_len = sizeof(struct arp_hdr);
return;
}
@ -412,7 +428,7 @@ uip_arp_out(void)
memcpy(IPBUF->ethhdr.dest.addr, tabptr->ethaddr.addr, 6);
}
memcpy(IPBUF->ethhdr.src.addr, uip_ethaddr.addr, 6);
IPBUF->ethhdr.type = HTONS(UIP_ETHTYPE_IP);
uip_len += sizeof(struct uip_eth_hdr);

View file

@ -7,13 +7,13 @@
* \addtogroup uiparp
* @{
*/
/**
* \file
* Macros and definitions for the ARP module.
* \author Adam Dunkels <adam@dunkels.com>
*/
/*
* Copyright (c) 2001-2003, Adam Dunkels.
@ -60,12 +60,20 @@ extern struct uip_eth_addr uip_ethaddr;
/**
* The Ethernet header.
*/
#ifdef __ICCARM__
#pragma pack(1)
#endif
struct uip_eth_hdr {
struct uip_eth_addr dest;
struct uip_eth_addr src;
u16_t type;
}PACK_STRUCT_END;
#ifdef __ICCARM__
#pragma pack()
#endif
#define UIP_ETHTYPE_ARP 0x0806
#define UIP_ETHTYPE_IP 0x0800
#define UIP_ETHTYPE_IP6 0x86dd