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) {
dataptr = data;
last_byte = data + len - 1;
-
+
while(dataptr < last_byte) { /* At least two more bytes */
t = (dataptr[0] << 8) + dataptr[1];
sum += t;
}
dataptr += 2;
}
-
+
if(dataptr == last_byte) {
t = (dataptr[0] << 8) + 0;
sum += t;
{
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. */
/* 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);
}
/*---------------------------------------------------------------------------*/
uip_icmp6chksum(void)
{
return upper_layer_chksum(UIP_PROTO_ICMP6);
-
+
}
#endif /* UIP_CONF_IPV6 */
/*---------------------------------------------------------------------------*/
uip_udp_conns[c].lport = 0;
}
#endif /* UIP_UDP */
-
+
/* IPv4 initialization. */
#if UIP_FIXEDADDR == 0
uip_connect(uip_ipaddr_t *ripaddr, u16_t rport)
{
register struct uip_conn *conn, *cconn;
-
+
/* Find an unused local port. */
again:
++lastport;
if(conn == 0) {
return 0;
}
-
+
conn->tcpstateflags = UIP_SYN_SENT;
conn->snd_nxt[0] = iss[0];
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. */
conn->lport = htons(lastport);
conn->rport = rport;
uip_ipaddr_copy(&conn->ripaddr, ripaddr);
-
+
return conn;
}
#endif /* UIP_ACTIVE_OPEN */
uip_udp_new(const uip_ipaddr_t *ripaddr, u16_t rport)
{
register struct uip_udp_conn *conn;
-
+
/* Find an unused local port. */
again:
++lastport;
if(lastport >= 32000) {
lastport = 4096;
}
-
+
for(c = 0; c < UIP_UDP_CONNS; ++c) {
if(uip_udp_conns[c].lport == htons(lastport)) {
goto again;
if(conn == 0) {
return 0;
}
-
+
conn->lport = HTONS(lastport);
conn->rport = rport;
if(ripaddr == NULL) {
uip_ipaddr_copy(&conn->ripaddr, ripaddr);
}
conn->ttl = UIP_TTL;
-
+
return conn;
}
#endif /* UIP_UDP */
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];
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
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. */
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
goto appsend;
}
goto drop;
-
+
/* Check if we were invoked because of the periodic timer firing. */
} else if(flag == UIP_TIMER) {
#if UIP_REASSEMBLY
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
/* 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
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) {
/* If there was no need for a retransmission, we poll the
application for new data. */
- uip_len = uip_slen = 0;
+ uip_len = uip_slen = 0;
uip_flags = UIP_POLL;
UIP_APPCALL();
goto appsend;
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. */
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
#if UIP_BROADCAST
DEBUG_PRINTF("UDP IP checksum 0x%04x\n", uip_ipchksum());
if(BUF->proto == UIP_PROTO_UDP &&
- uip_ipaddr_cmp(&BUF->destipaddr, &uip_broadcast_addr)
- /*&&
- uip_ipchksum() == 0xffff*/) {
- goto udp_input;
+ uip_ipaddr_cmp(&BUF->destipaddr, &uip_broadcast_addr))
+ {
+ if (uip_ipaddr_cmp(&BUF->srcipaddr, &uip_all_zeroes_addr))
+ uip_ipaddr_copy(&BUF->srcipaddr, &uip_broadcast_addr);
+
+ 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)) {
/* 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 solicitation 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;
memcpy(&(ICMPBUF->options[2]), &uip_ethaddr, sizeof(uip_ethaddr));
ICMPBUF->icmpchksum = 0;
ICMPBUF->icmpchksum = ~uip_icmp6chksum();
-
+
goto send;
-
+
}
goto drop;
} else if(ICMPBUF->type == ICMP6_ECHO) {
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 {
}
/* End of IPv6 ICMP processing. */
-
+
#endif /* !UIP_CONF_IPV6 */
#if UIP_UDP
#else /* UIP_CONF_ICMP_DEST_UNREACH */
goto drop;
#endif /* UIP_CONF_ICMP_DEST_UNREACH */
-
+
udp_found:
uip_conn = NULL;
uip_flags = UIP_NEWDATA;
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
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);
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];
if((BUF->flags & TCP_CTL) != TCP_SYN) {
goto reset;
}
-
+
tmp16 = BUF->destport;
/* Next, check listening connections. */
for(c = 0; c < UIP_LISTENPORTS; ++c) {
goto found_listen;
}
}
-
+
/* No matching connection found, so we send a RST packet. */
UIP_STAT(++uip_stat.tcp.synrst);
}
UIP_STAT(++uip_stat.tcp.rst);
-
+
BUF->flags = TCP_RST | TCP_ACK;
uip_len = UIP_IPTCPH_LEN;
BUF->tcpoffset = 5 << 4;
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;
}
}
}
-
+
/* 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;
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;
(u16_t)uip_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN + 3 + c];
uip_connr->initialmss = uip_connr->mss =
tmp16 > UIP_TCP_MSS? UIP_TCP_MSS: tmp16;
-
+
/* And we are done processing options. */
break;
} else {
}
}
}
-
+
/* 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;
uip_connr->snd_nxt[1] = uip_acc32[1];
uip_connr->snd_nxt[2] = uip_acc32[2];
uip_connr->snd_nxt[3] = uip_acc32[3];
-
+
/* Do RTT estimation, unless we have done retransmissions. */
if(uip_connr->nrtx == 0) {
signed char m;
/* Reset length of outstanding data. */
uip_connr->len = 0;
}
-
+
}
/* Do different things depending on in what state the connection is. */
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
UIP_APPCALL();
appsend:
-
+
if(uip_flags & UIP_ABORT) {
uip_slen = 0;
uip_connr->tcpstateflags = UIP_CLOSED;
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) {
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
goto tcp_send_ack;
}
goto drop;
-
+
case UIP_FIN_WAIT_2:
if(uip_len > 0) {
uip_add_rcv_nxt(uip_len);
case UIP_TIME_WAIT:
goto tcp_send_ack;
-
+
case UIP_CLOSING:
if(uip_flags & UIP_ACKDATA) {
uip_connr->tcpstateflags = UIP_TIME_WAIT;
}
}
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. */
tcp_send_ack:
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;
#endif /* UIP_CONF_IPV6 */
BUF->urgp[0] = BUF->urgp[1] = 0;
-
+
/* Calculate TCP checksum. */
BUF->tcpchksum = 0;
BUF->tcpchksum = ~(uip_tcpchksum());
BUF->ipchksum = 0;
BUF->ipchksum = ~(uip_ipchksum());
DEBUG_PRINTF("uip ip_send_nolen: chkecum 0x%04x\n", uip_ipchksum());
-#endif /* UIP_CONF_IPV6 */
+#endif /* UIP_CONF_IPV6 */
UIP_STAT(++uip_stat.tcp.sent);
#if UIP_CONF_IPV6
send:
#endif /* UIP_CONF_IPV6 */
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;
/*---------------------------------------------------------------------------*/
/** @} */
#endif /* UIP_CONF_IPV6 */
+