88 #define DEBUG DEBUG_NONE
98 #define UIP_LOG(m) uip_log(m)
103 #if UIP_STATISTICS == 1
112 #if UIP_CONF_LL_802154
148 #define FBUF ((struct uip_tcpip_hdr *)&uip_reassbuf[0])
149 #define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
150 #define UIP_ICMP_BUF ((struct uip_icmp_hdr *)&uip_buf[uip_l2_l3_hdr_len])
151 #define UIP_UDP_BUF ((struct uip_udp_hdr *)&uip_buf[UIP_LLH_LEN + UIP_IPH_LEN])
152 #define UIP_TCP_BUF ((struct uip_tcp_hdr *)&uip_buf[UIP_LLH_LEN + UIP_IPH_LEN])
153 #define UIP_EXT_BUF ((struct uip_ext_hdr *)&uip_buf[uip_l2_l3_hdr_len])
154 #define UIP_ROUTING_BUF ((struct uip_routing_hdr *)&uip_buf[uip_l2_l3_hdr_len])
155 #define UIP_FRAG_BUF ((struct uip_frag_hdr *)&uip_buf[uip_l2_l3_hdr_len])
156 #define UIP_HBHO_BUF ((struct uip_hbho_hdr *)&uip_buf[uip_l2_l3_hdr_len])
157 #define UIP_DESTO_BUF ((struct uip_desto_hdr *)&uip_buf[uip_l2_l3_hdr_len])
158 #define UIP_EXT_HDR_OPT_BUF ((struct uip_ext_hdr_opt *)&uip_buf[uip_l2_l3_hdr_len + uip_ext_opt_offset])
159 #define UIP_EXT_HDR_OPT_PADN_BUF ((struct uip_ext_hdr_opt_padn *)&uip_buf[uip_l2_l3_hdr_len + uip_ext_opt_offset])
160 #if UIP_CONF_IPV6_RPL
161 #define UIP_EXT_HDR_OPT_RPL_BUF ((struct uip_ext_hdr_opt_rpl *)&uip_buf[uip_l2_l3_hdr_len + uip_ext_opt_offset])
163 #define UIP_ICMP6_ERROR_BUF ((struct uip_icmp6_error *)&uip_buf[uip_l2_l3_icmp_hdr_len])
169 #ifndef UIP_CONF_EXTERNAL_BUFFER
181 uint16_t uip_urglen, uip_surglen;
200 #if (UIP_TCP || UIP_UDP)
204 #if UIP_ACTIVE_OPEN || UIP_UDP
206 static uint16_t lastport;
225 #define TCP_OPT_END 0
226 #define TCP_OPT_NOOP 1
227 #define TCP_OPT_MSS 2
229 #define TCP_OPT_MSS_LEN 4
242 static uint8_t iss[4];
247 static uint16_t tmp16;
265 struct uip_icmp6_conn uip_icmp6_conns;
272 #if (!UIP_ARCH_ADD32 && UIP_TCP)
278 uip_acc32[1] = op32[1];
279 uip_acc32[0] = op32[0];
281 if(uip_acc32[2] < (op16 >> 8)) {
283 if(uip_acc32[1] == 0) {
289 if(uip_acc32[3] < (op16 & 0xff)) {
291 if(uip_acc32[2] == 0) {
293 if(uip_acc32[1] == 0) {
302 #if ! UIP_ARCH_CHKSUM
305 chksum(uint16_t sum,
const uint8_t *data, uint16_t len)
308 const uint8_t *dataptr;
309 const uint8_t *last_byte;
312 last_byte = data + len - 1;
314 while(dataptr < last_byte) {
315 t = (dataptr[0] << 8) + dataptr[1];
323 if(dataptr == last_byte) {
324 t = (dataptr[0] << 8) + 0;
338 return uip_htons(chksum(0, (uint8_t *)data, len));
341 #ifndef UIP_ARCH_IPCHKSUM
347 sum = chksum(0, &uip_buf[
UIP_LLH_LEN], UIP_IPH_LEN);
348 PRINTF(
"uip_ipchksum: sum 0x%04x\n", sum);
349 return (sum == 0) ? 0xffff :
uip_htons(sum);
354 upper_layer_chksum(uint8_t proto)
365 volatile uint16_t upper_layer_len;
370 PRINTF(
"Upper layer checksum len: %d from: %d\n", upper_layer_len,
375 sum = upper_layer_len + proto;
377 sum = chksum(sum, (uint8_t *)&
UIP_IP_BUF->srcipaddr, 2 *
sizeof(uip_ipaddr_t));
383 return (sum == 0) ? 0xffff :
uip_htons(sum);
389 return upper_layer_chksum(UIP_PROTO_ICMP6);
397 return upper_layer_chksum(UIP_PROTO_TCP);
401 #if UIP_UDP && UIP_UDP_CHECKSUMS
405 return upper_layer_chksum(UIP_PROTO_UDP);
420 uip_listenports[c] = 0;
423 uip_conns[c].tcpstateflags = UIP_CLOSED;
427 #if UIP_ACTIVE_OPEN || UIP_UDP
433 uip_udp_conns[c].
lport = 0;
437 #if UIP_CONF_IPV6_MULTICAST
442 #if UIP_TCP && UIP_ACTIVE_OPEN
446 register struct uip_conn *conn, *cconn;
452 if(lastport >= 32000) {
459 conn = &uip_conns[c];
468 cconn = &uip_conns[c];
518 PRINTF(
"Cutting ext-header before processing (extlen: %d, uiplen: %d)\n",
521 PRINTF(
"ERROR: uip_len too short compared to ext len\n");
526 memmove(((uint8_t *)UIP_TCP_BUF), (uint8_t *)UIP_TCP_BUF +
uip_ext_len,
539 struct uip_udp_conn *
540 uip_udp_new(
const uip_ipaddr_t *ripaddr, uint16_t rport)
542 register struct uip_udp_conn *conn;
548 if(lastport >= 32000) {
560 if(uip_udp_conns[c].
lport == 0) {
561 conn = &uip_udp_conns[c];
572 if(ripaddr ==
NULL) {
573 memset(&conn->
ripaddr, 0,
sizeof(uip_ipaddr_t));
577 conn->
ttl = uip_ds6_if.cur_hop_limit;
588 if(uip_listenports[c] == port) {
589 uip_listenports[c] = 0;
599 if(uip_listenports[c] == 0) {
600 uip_listenports[c] = port;
608 #if UIP_CONF_IPV6_REASSEMBLY
609 #define UIP_REASS_BUFSIZE (UIP_BUFSIZE - UIP_LLH_LEN)
611 static uint8_t uip_reassbuf[UIP_REASS_BUFSIZE];
613 static uint8_t uip_reassbitmap[UIP_REASS_BUFSIZE / (8 * 8)];
616 static const uint8_t bitmap_bits[8] = {0xff, 0x7f, 0x3f, 0x1f,
617 0x0f, 0x07, 0x03, 0x01};
618 static uint16_t uip_reasslen;
619 static uint8_t uip_reassflags;
621 #define UIP_REASS_FLAG_LASTFRAG 0x01
622 #define UIP_REASS_FLAG_FIRSTFRAG 0x02
623 #define UIP_REASS_FLAG_ERROR_MSG 0x04
636 struct etimer uip_reass_timer;
637 uint8_t uip_reass_on;
639 static uint32_t uip_id;
654 if(uip_reass_on == 0) {
655 PRINTF(
"Starting reassembly\n");
661 uip_id = UIP_FRAG_BUF->id;
663 memset(uip_reassbitmap, 0,
sizeof(uip_reassbitmap));
670 if(uip_ipaddr_cmp(&FBUF->srcipaddr, &
UIP_IP_BUF->srcipaddr) &&
671 uip_ipaddr_cmp(&FBUF->destipaddr, &
UIP_IP_BUF->destipaddr) &&
672 UIP_FRAG_BUF->id == uip_id) {
674 offset = (uip_ntohs(UIP_FRAG_BUF->offsetresmore) & 0xfff8);
676 PRINTF(
"len %d\n", len);
677 PRINTF(
"offset %d\n", offset);
679 uip_reassflags |= UIP_REASS_FLAG_FIRSTFRAG;
688 PRINT6ADDR(&FBUF->srcipaddr);
690 PRINT6ADDR(&FBUF->destipaddr);
697 if(offset > UIP_REASS_BUFSIZE ||
698 offset + len > UIP_REASS_BUFSIZE) {
706 if((uip_ntohs(UIP_FRAG_BUF->offsetresmore) & IP_MF) == 0) {
707 uip_reassflags |= UIP_REASS_FLAG_LASTFRAG;
709 uip_reasslen = offset + len;
710 PRINTF(
"LAST FRAGMENT reasslen %d\n", uip_reasslen);
718 uip_reassflags |= UIP_REASS_FLAG_ERROR_MSG;
729 memcpy((uint8_t *)FBUF + UIP_IPH_LEN +
uip_ext_len + offset,
730 (uint8_t *)UIP_FRAG_BUF + UIP_FRAGH_LEN, len);
733 if(offset >> 6 == (offset + len) >> 6) {
734 uip_reassbitmap[offset >> 6] |=
735 bitmap_bits[(offset >> 3) & 7] &
736 ~bitmap_bits[((offset + len) >> 3) & 7];
741 uip_reassbitmap[offset >> 6] |= bitmap_bits[(offset >> 3) & 7];
743 for(i = (1 + (offset >> 6)); i < ((offset + len) >> 6); ++i) {
744 uip_reassbitmap[i] = 0xff;
746 uip_reassbitmap[(offset + len) >> 6] |=
747 ~bitmap_bits[((offset + len) >> 3) & 7];
754 if(uip_reassflags & UIP_REASS_FLAG_LASTFRAG) {
757 for(i = 0; i < (uip_reasslen >> 6); ++i) {
758 if(uip_reassbitmap[i] != 0xff) {
764 if(uip_reassbitmap[uip_reasslen >> 6] !=
765 (uint8_t)~bitmap_bits[(uip_reasslen >> 3) & 7]) {
776 UIP_IP_BUF->len[0] = ((uip_reasslen - UIP_IPH_LEN) >> 8);
777 UIP_IP_BUF->len[1] = ((uip_reasslen - UIP_IPH_LEN) & 0xff);
778 PRINTF(
"REASSEMBLED PAQUET %d (%d)\n", uip_reasslen,
785 PRINTF(
"Already reassembling another paquet\n");
798 if(uip_reassflags & UIP_REASS_FLAG_FIRSTFRAG){
799 PRINTF(
"FRAG INTERRUPTED TOO LATE\n");
825 uip_add_rcv_nxt(uint16_t n)
828 uip_conn->
rcv_nxt[0] = uip_acc32[0];
829 uip_conn->
rcv_nxt[1] = uip_acc32[1];
830 uip_conn->
rcv_nxt[2] = uip_acc32[2];
831 uip_conn->
rcv_nxt[3] = uip_acc32[3];
840 ext_hdr_options_process(
void)
849 switch(UIP_EXT_HDR_OPT_BUF->type) {
856 PRINTF(
"Processing PAD1 option\n");
859 case UIP_EXT_HDR_OPT_PADN:
860 PRINTF(
"Processing PADN option\n");
863 case UIP_EXT_HDR_OPT_RPL:
872 #if UIP_CONF_IPV6_RPL
873 PRINTF(
"Processing RPL option\n");
875 PRINTF(
"RPL Option Error: Dropping Packet\n");
895 PRINTF(
"MSB %x\n", UIP_EXT_HDR_OPT_BUF->type);
896 switch(UIP_EXT_HDR_OPT_BUF->type & 0xC0) {
924 register struct uip_conn *uip_connr =
uip_conn;
927 if(flag == UIP_UDP_SEND_CONN) {
935 if(flag == UIP_POLL_REQUEST) {
937 if((uip_connr->
tcpstateflags & UIP_TS_MASK) == UIP_ESTABLISHED &&
938 !uip_outstanding(uip_connr)) {
939 uip_flags = UIP_POLL;
943 }
else if((uip_connr->
tcpstateflags & UIP_TS_MASK) == UIP_SYN_SENT) {
945 UIP_TCP_BUF->flags = 0;
952 }
else if(flag == UIP_TIMER) {
975 ++(uip_connr->
timer);
985 if(uip_outstanding(uip_connr)) {
986 if(uip_connr->
timer-- == 0) {
998 uip_flags = UIP_TIMEDOUT;
1002 UIP_TCP_BUF->flags = TCP_RST | TCP_ACK;
1003 goto tcp_send_nodata;
1010 ++(uip_connr->
nrtx);
1024 goto tcp_send_synack;
1029 UIP_TCP_BUF->flags = 0;
1033 case UIP_ESTABLISHED:
1040 uip_flags = UIP_REXMIT;
1044 case UIP_FIN_WAIT_1:
1048 goto tcp_send_finack;
1051 }
else if((uip_connr->
tcpstateflags & UIP_TS_MASK) == UIP_ESTABLISHED) {
1056 uip_flags = UIP_POLL;
1065 if(flag == UIP_UDP_TIMER) {
1066 if(uip_udp_conn->
lport != 0) {
1070 uip_flags = UIP_POLL;
1089 UIP_LOG(
"ipv6: invalid version.");
1115 UIP_LOG(
"ip: packet shorter than reported in IP header.");
1119 PRINTF(
"IPv6 packet received from ");
1127 PRINTF(
"Dropping packet, src is mcast\n");
1141 #if UIP_CONF_IPV6_CHECKS
1144 switch(ext_hdr_options_process()) {
1151 PRINTF(
"Dropping packet after extension header processing\n");
1155 PRINTF(
"Sending error message after extension header processing\n");
1173 #if UIP_CONF_IPV6_MULTICAST
1175 if(UIP_MCAST6.in() == UIP_MCAST6_ACCEPT) {
1186 if(!uip_ds6_is_my_addr(&
UIP_IP_BUF->destipaddr) &&
1187 !uip_ds6_is_my_maddr(&
UIP_IP_BUF->destipaddr)) {
1209 #if UIP_CONF_IPV6_RPL
1210 rpl_update_header_empty();
1214 PRINTF(
"Forwarding packet to ");
1224 (!uip_ds6_is_addr_onlink((&
UIP_IP_BUF->destipaddr)))) {
1225 PRINTF(
"LL source address with off link destination, dropping\n");
1230 PRINTF(
"Dropping packet, not for me and link local or multicast\n");
1236 if(!uip_ds6_is_my_addr(&
UIP_IP_BUF->destipaddr) &&
1237 !uip_ds6_is_my_maddr(&
UIP_IP_BUF->destipaddr) &&
1239 PRINTF(
"Dropping packet, not for me\n");
1253 #if UIP_CONF_IPV6_MULTICAST
1269 case UIP_PROTO_ICMP6:
1273 PRINTF(
"Processing hbh header\n");
1275 #if UIP_CONF_IPV6_CHECKS
1283 switch(ext_hdr_options_process()) {
1298 case UIP_PROTO_DESTO:
1299 #if UIP_CONF_IPV6_CHECKS
1301 PRINTF(
"Processing desto header\n");
1312 switch(ext_hdr_options_process()) {
1327 case UIP_PROTO_ROUTING:
1328 #if UIP_CONF_IPV6_CHECKS
1344 PRINTF(
"Processing Routing header\n");
1345 if(UIP_ROUTING_BUF->seg_left > 0) {
1348 UIP_LOG(
"ip6: unrecognized routing type");
1354 case UIP_PROTO_FRAG:
1356 #if UIP_CONF_IPV6_REASSEMBLY
1357 PRINTF(
"Processing frag header\n");
1362 if(uip_reassflags & UIP_REASS_FLAG_ERROR_MSG){
1368 PRINTF(
"Processing reassembled packet\n");
1376 UIP_LOG(
"ip: fragment dropped.");
1379 case UIP_PROTO_NONE:
1393 UIP_LOG(
"ip6: unrecognized header");
1401 #if UIP_CONF_IPV6_CHECKS
1406 UIP_LOG(
"icmpv6: bad checksum.");
1407 PRINTF(
"icmpv6: bad checksum.");
1432 PRINTF(
"Unknown ICMPv6 message type/code %d\n",
UIP_ICMP_BUF->type);
1435 UIP_LOG(
"icmp6: unknown ICMPv6 message.");
1453 PRINTF(
"Receiving UDP packet\n");
1459 #if UIP_UDP_CHECKSUMS
1467 if(UIP_UDP_BUF->udpchksum != 0 &&
uip_udpchksum() != 0xffff) {
1470 PRINTF(
"udp: bad checksum 0x%04x 0x%04x\n", UIP_UDP_BUF->udpchksum,
1479 if(UIP_UDP_BUF->destport == 0) {
1480 PRINTF(
"udp: zero port.\n");
1485 for(uip_udp_conn = &uip_udp_conns[0];
1495 if(uip_udp_conn->
lport != 0 &&
1496 UIP_UDP_BUF->destport == uip_udp_conn->
lport &&
1497 (uip_udp_conn->
rport == 0 ||
1498 UIP_UDP_BUF->srcport == uip_udp_conn->
rport) &&
1504 PRINTF(
"udp: no matching connection found\n");
1507 #if UIP_UDP_SEND_UNREACH_NOPORT
1515 PRINTF(
"In udp_found\n");
1519 uip_flags = UIP_NEWDATA;
1525 PRINTF(
"In udp_send\n");
1530 uip_len = uip_slen + UIP_IPUDPH_LEN;
1540 UIP_UDP_BUF->udplen =
UIP_HTONS(uip_slen + UIP_UDPH_LEN);
1541 UIP_UDP_BUF->udpchksum = 0;
1543 UIP_UDP_BUF->srcport = uip_udp_conn->
lport;
1544 UIP_UDP_BUF->destport = uip_udp_conn->
rport;
1551 #if UIP_UDP_CHECKSUMS
1554 if(UIP_UDP_BUF->udpchksum == 0) {
1555 UIP_UDP_BUF->udpchksum = 0xffff;
1559 #if UIP_CONF_IPV6_RPL
1560 rpl_insert_header();
1574 PRINTF(
"Receiving TCP packet\n");
1581 PRINTF(
"tcp: bad checksum 0x%04x 0x%04x\n", UIP_TCP_BUF->tcpchksum,
1587 if(UIP_TCP_BUF->destport == 0 || UIP_TCP_BUF->srcport == 0) {
1588 PRINTF(
"tcp: zero port.");
1594 for(uip_connr = &uip_conns[0]; uip_connr <= &uip_conns[UIP_CONNS - 1];
1597 UIP_TCP_BUF->destport == uip_connr->
lport &&
1598 UIP_TCP_BUF->srcport == uip_connr->
rport &&
1608 if((UIP_TCP_BUF->flags & TCP_CTL) != TCP_SYN) {
1612 tmp16 = UIP_TCP_BUF->destport;
1615 if(tmp16 == uip_listenports[c]) {
1624 PRINTF(
"In reset\n");
1626 if(UIP_TCP_BUF->flags & TCP_RST) {
1632 UIP_TCP_BUF->flags = TCP_RST | TCP_ACK;
1634 UIP_TCP_BUF->tcpoffset = 5 << 4;
1637 c = UIP_TCP_BUF->seqno[3];
1638 UIP_TCP_BUF->seqno[3] = UIP_TCP_BUF->ackno[3];
1639 UIP_TCP_BUF->ackno[3] = c;
1641 c = UIP_TCP_BUF->seqno[2];
1642 UIP_TCP_BUF->seqno[2] = UIP_TCP_BUF->ackno[2];
1643 UIP_TCP_BUF->ackno[2] = c;
1645 c = UIP_TCP_BUF->seqno[1];
1646 UIP_TCP_BUF->seqno[1] = UIP_TCP_BUF->ackno[1];
1647 UIP_TCP_BUF->ackno[1] = c;
1649 c = UIP_TCP_BUF->seqno[0];
1650 UIP_TCP_BUF->seqno[0] = UIP_TCP_BUF->ackno[0];
1651 UIP_TCP_BUF->ackno[0] = c;
1656 if(++UIP_TCP_BUF->ackno[3] == 0) {
1657 if(++UIP_TCP_BUF->ackno[2] == 0) {
1658 if(++UIP_TCP_BUF->ackno[1] == 0) {
1659 ++UIP_TCP_BUF->ackno[0];
1665 tmp16 = UIP_TCP_BUF->srcport;
1666 UIP_TCP_BUF->srcport = UIP_TCP_BUF->destport;
1667 UIP_TCP_BUF->destport = tmp16;
1673 goto tcp_send_noconn;
1679 PRINTF(
"In found listen\n");
1689 uip_connr = &uip_conns[c];
1693 if(uip_connr == 0 ||
1695 uip_connr = &uip_conns[c];
1700 if(uip_connr == 0) {
1705 UIP_LOG(
"tcp: found no unused connections.");
1708 uip_conn = uip_connr;
1714 uip_connr->
nrtx = 0;
1715 uip_connr->
lport = UIP_TCP_BUF->destport;
1716 uip_connr->
rport = UIP_TCP_BUF->srcport;
1720 uip_connr->
snd_nxt[0] = iss[0];
1721 uip_connr->
snd_nxt[1] = iss[1];
1722 uip_connr->
snd_nxt[2] = iss[2];
1723 uip_connr->
snd_nxt[3] = iss[3];
1727 uip_connr->
rcv_nxt[3] = UIP_TCP_BUF->seqno[3];
1728 uip_connr->
rcv_nxt[2] = UIP_TCP_BUF->seqno[2];
1729 uip_connr->
rcv_nxt[1] = UIP_TCP_BUF->seqno[1];
1730 uip_connr->
rcv_nxt[0] = UIP_TCP_BUF->seqno[0];
1734 if((UIP_TCP_BUF->tcpoffset & 0xf0) > 0x50) {
1735 for(c = 0; c < ((UIP_TCP_BUF->tcpoffset >> 4) - 5) << 2 ;) {
1737 if(opt == TCP_OPT_END) {
1740 }
else if(opt == TCP_OPT_NOOP) {
1743 }
else if(opt == TCP_OPT_MSS &&
1744 uip_buf[UIP_TCPIP_HLEN +
UIP_LLH_LEN + 1 + c] == TCP_OPT_MSS_LEN) {
1746 tmp16 = ((uint16_t)uip_buf[UIP_TCPIP_HLEN +
UIP_LLH_LEN + 2 + c] << 8) |
1747 (uint16_t)uip_buf[UIP_IPTCPH_LEN +
UIP_LLH_LEN + 3 + c];
1756 if(uip_buf[UIP_TCPIP_HLEN +
UIP_LLH_LEN + 1 + c] == 0) {
1761 c += uip_buf[UIP_TCPIP_HLEN +
UIP_LLH_LEN + 1 + c];
1769 UIP_TCP_BUF->flags = TCP_ACK;
1772 UIP_TCP_BUF->flags |= TCP_SYN;
1775 UIP_TCP_BUF->flags = TCP_SYN | TCP_ACK;
1780 UIP_TCP_BUF->optdata[0] = TCP_OPT_MSS;
1781 UIP_TCP_BUF->optdata[1] = TCP_OPT_MSS_LEN;
1784 uip_len = UIP_IPTCPH_LEN + TCP_OPT_MSS_LEN;
1785 UIP_TCP_BUF->tcpoffset = ((UIP_TCPH_LEN + TCP_OPT_MSS_LEN) / 4) << 4;
1790 PRINTF(
"In found\n");
1791 uip_conn = uip_connr;
1797 if(UIP_TCP_BUF->flags & TCP_RST) {
1799 UIP_LOG(
"tcp: got reset, aborting connection.");
1800 uip_flags = UIP_ABORT;
1806 c = (UIP_TCP_BUF->tcpoffset >> 4) << 2;
1817 if(!((((uip_connr->
tcpstateflags & UIP_TS_MASK) == UIP_SYN_SENT) &&
1818 ((UIP_TCP_BUF->flags & TCP_CTL) == (TCP_SYN | TCP_ACK))) ||
1819 (((uip_connr->
tcpstateflags & UIP_TS_MASK) == UIP_SYN_RCVD) &&
1820 ((UIP_TCP_BUF->flags & TCP_CTL) == TCP_SYN)))) {
1821 if((
uip_len > 0 || ((UIP_TCP_BUF->flags & (TCP_SYN | TCP_FIN)) != 0)) &&
1822 (UIP_TCP_BUF->seqno[0] != uip_connr->
rcv_nxt[0] ||
1823 UIP_TCP_BUF->seqno[1] != uip_connr->
rcv_nxt[1] ||
1824 UIP_TCP_BUF->seqno[2] != uip_connr->
rcv_nxt[2] ||
1825 UIP_TCP_BUF->seqno[3] != uip_connr->
rcv_nxt[3])) {
1827 if((UIP_TCP_BUF->flags & TCP_SYN)) {
1828 if((uip_connr->
tcpstateflags & UIP_TS_MASK) == UIP_SYN_RCVD) {
1829 goto tcp_send_synack;
1830 }
else if((uip_connr->
tcpstateflags & UIP_TS_MASK) == UIP_SYN_SENT) {
1842 if((UIP_TCP_BUF->flags & TCP_ACK) && uip_outstanding(uip_connr)) {
1845 if(UIP_TCP_BUF->ackno[0] == uip_acc32[0] &&
1846 UIP_TCP_BUF->ackno[1] == uip_acc32[1] &&
1847 UIP_TCP_BUF->ackno[2] == uip_acc32[2] &&
1848 UIP_TCP_BUF->ackno[3] == uip_acc32[3]) {
1850 uip_connr->
snd_nxt[0] = uip_acc32[0];
1851 uip_connr->
snd_nxt[1] = uip_acc32[1];
1852 uip_connr->
snd_nxt[2] = uip_acc32[2];
1853 uip_connr->
snd_nxt[3] = uip_acc32[3];
1856 if(uip_connr->
nrtx == 0) {
1858 m = uip_connr->
rto - uip_connr->
timer;
1860 m = m - (uip_connr->
sa >> 3);
1865 m = m - (uip_connr->
sv >> 2);
1867 uip_connr->
rto = (uip_connr->
sa >> 3) + uip_connr->
sv;
1871 uip_flags = UIP_ACKDATA;
1892 if(uip_flags & UIP_ACKDATA) {
1894 uip_flags = UIP_CONNECTED;
1897 uip_flags |= UIP_NEWDATA;
1905 if((UIP_TCP_BUF->flags & TCP_CTL) == TCP_SYN) {
1906 goto tcp_send_synack;
1915 if((uip_flags & UIP_ACKDATA) &&
1916 (UIP_TCP_BUF->flags & TCP_CTL) == (TCP_SYN | TCP_ACK)) {
1919 if((UIP_TCP_BUF->tcpoffset & 0xf0) > 0x50) {
1920 for(c = 0; c < ((UIP_TCP_BUF->tcpoffset >> 4) - 5) << 2 ;) {
1922 if(opt == TCP_OPT_END) {
1925 }
else if(opt == TCP_OPT_NOOP) {
1928 }
else if(opt == TCP_OPT_MSS &&
1929 uip_buf[UIP_TCPIP_HLEN +
UIP_LLH_LEN + 1 + c] == TCP_OPT_MSS_LEN) {
1931 tmp16 = (uip_buf[UIP_TCPIP_HLEN +
UIP_LLH_LEN + 2 + c] << 8) |
1941 if(uip_buf[UIP_TCPIP_HLEN +
UIP_LLH_LEN + 1 + c] == 0) {
1946 c += uip_buf[UIP_TCPIP_HLEN +
UIP_LLH_LEN + 1 + c];
1951 uip_connr->
rcv_nxt[0] = UIP_TCP_BUF->seqno[0];
1952 uip_connr->
rcv_nxt[1] = UIP_TCP_BUF->seqno[1];
1953 uip_connr->
rcv_nxt[2] = UIP_TCP_BUF->seqno[2];
1954 uip_connr->
rcv_nxt[3] = UIP_TCP_BUF->seqno[3];
1956 uip_flags = UIP_CONNECTED | UIP_NEWDATA;
1964 uip_flags = UIP_ABORT;
1971 case UIP_ESTABLISHED:
1983 if(UIP_TCP_BUF->flags & TCP_FIN && !(uip_connr->
tcpstateflags & UIP_STOPPED)) {
1984 if(uip_outstanding(uip_connr)) {
1988 uip_flags |= UIP_CLOSE;
1990 uip_flags |= UIP_NEWDATA;
1995 uip_connr->
nrtx = 0;
1997 UIP_TCP_BUF->flags = TCP_FIN | TCP_ACK;
1998 goto tcp_send_nodata;
2003 if((UIP_TCP_BUF->flags & TCP_URG) != 0) {
2005 uip_urglen = (UIP_TCP_BUF->urgp[0] << 8) | UIP_TCP_BUF->urgp[1];
2010 uip_add_rcv_nxt(uip_urglen);
2018 uip_len -= (UIP_TCP_BUF->urgp[0] << 8) | UIP_TCP_BUF->urgp[1];
2028 uip_flags |= UIP_NEWDATA;
2044 tmp16 = ((uint16_t)UIP_TCP_BUF->wnd[0] << 8) + (uint16_t)UIP_TCP_BUF->wnd[1];
2049 uip_connr->
mss = tmp16;
2067 if(uip_flags & (UIP_NEWDATA | UIP_ACKDATA)) {
2073 if(uip_flags & UIP_ABORT) {
2076 UIP_TCP_BUF->flags = TCP_RST | TCP_ACK;
2077 goto tcp_send_nodata;
2080 if(uip_flags & UIP_CLOSE) {
2084 uip_connr->
nrtx = 0;
2085 UIP_TCP_BUF->flags = TCP_FIN | TCP_ACK;
2086 goto tcp_send_nodata;
2094 if((uip_flags & UIP_ACKDATA) != 0) {
2101 if(uip_connr->
len == 0) {
2106 if(uip_slen > uip_connr->
mss) {
2107 uip_slen = uip_connr->
mss;
2112 uip_connr->
len = uip_slen;
2118 uip_slen = uip_connr->
len;
2121 uip_connr->
nrtx = 0;
2127 if(uip_slen > 0 && uip_connr->
len > 0) {
2131 UIP_TCP_BUF->flags = TCP_ACK | TCP_PSH;
2133 goto tcp_send_noopts;
2137 if(uip_flags & UIP_NEWDATA) {
2139 UIP_TCP_BUF->flags = TCP_ACK;
2140 goto tcp_send_noopts;
2147 if(uip_flags & UIP_ACKDATA) {
2149 uip_flags = UIP_CLOSE;
2154 case UIP_FIN_WAIT_1:
2161 if(UIP_TCP_BUF->flags & TCP_FIN) {
2162 if(uip_flags & UIP_ACKDATA) {
2164 uip_connr->
timer = 0;
2170 uip_flags = UIP_CLOSE;
2173 }
else if(uip_flags & UIP_ACKDATA) {
2183 case UIP_FIN_WAIT_2:
2187 if(UIP_TCP_BUF->flags & TCP_FIN) {
2189 uip_connr->
timer = 0;
2191 uip_flags = UIP_CLOSE;
2204 if(uip_flags & UIP_ACKDATA) {
2206 uip_connr->
timer = 0;
2214 UIP_TCP_BUF->flags = TCP_ACK;
2220 UIP_TCP_BUF->tcpoffset = (UIP_TCPH_LEN / 4) << 4;
2227 PRINTF(
"In tcp_send\n");
2229 UIP_TCP_BUF->ackno[0] = uip_connr->
rcv_nxt[0];
2230 UIP_TCP_BUF->ackno[1] = uip_connr->
rcv_nxt[1];
2231 UIP_TCP_BUF->ackno[2] = uip_connr->
rcv_nxt[2];
2232 UIP_TCP_BUF->ackno[3] = uip_connr->
rcv_nxt[3];
2234 UIP_TCP_BUF->seqno[0] = uip_connr->
snd_nxt[0];
2235 UIP_TCP_BUF->seqno[1] = uip_connr->
snd_nxt[1];
2236 UIP_TCP_BUF->seqno[2] = uip_connr->
snd_nxt[2];
2237 UIP_TCP_BUF->seqno[3] = uip_connr->
snd_nxt[3];
2241 UIP_TCP_BUF->srcport = uip_connr->
lport;
2242 UIP_TCP_BUF->destport = uip_connr->
rport;
2246 PRINTF(
"Sending TCP packet to ");
2255 UIP_TCP_BUF->wnd[0] = UIP_TCP_BUF->wnd[1] = 0;
2266 UIP_TCP_BUF->urgp[0] = UIP_TCP_BUF->urgp[1] = 0;
2269 UIP_TCP_BUF->tcpchksum = 0;
2281 PRINTF(
"Sending packet with length %d (%d)\n",
uip_len,
2304 uip_htonl(uint32_t val)
2306 return UIP_HTONL(val);
2313 #define MIN(a,b) ((a) < (b)? (a): (b))
2315 if(uip_sappdata !=
NULL) {
2317 (
int)((
char *)uip_sappdata -
2324 if(data != uip_sappdata) {
2325 if(uip_sappdata ==
NULL) {
2326 memcpy((
char *)&uip_buf[
UIP_LLH_LEN + UIP_TCPIP_HLEN],
2329 memcpy(uip_sappdata, (data), uip_slen);
#define UIP_CONNS
The maximum number of simultaneously open TCP connections.
uint16_t uip_udpchksum(void)
Calculate the UDP checksum of the packet in uip_buf and uip_appdata.
struct uip_udp_conn * uip_udp_conn
The current UDP connection.
uint8_t uip_acc32[4]
4-byte array used for the 32-bit sequence number calculations.
uint16_t uip_ipchksum(void)
Calculate the IP header checksum of the packet header in uip_buf.
#define UIP_LINK_MTU
The maximum transmission unit at the IP Layer.
#define ICMP6_PACKET_TOO_BIG
packet too big
uip_len
The length of the packet in the uip_buf buffer.
uint8_t sv
Retransmission time-out calculation state variable.
#define ICMP6_PARAMPROB_NEXTHEADER
unrecognized next header
#define uip_is_addr_mcast(a)
is address a multicast address, see RFC 3513 a is of type uip_ipaddr_t*
Neighbor discovery (RFC 4861)
#define uip_is_addr_link_local(a)
is addr (a) a link local unicast address, see RFC3513 i.e.
CCIF uip_lladdr_t uip_lladdr
Host L2 address.
The structure holding the TCP/IP statistics that are gathered if UIP_STATISTICS is set to 1...
This header file contains configuration directives for uIPv6 multicast support.
#define ICMP6_TIME_EXCEED_TRANSIT
ttl==0 in transit
uint16_t rport
The remote port number in network byte order.
Representation of a uIP TCP connection.
Header file for the uIP TCP/IP stack.
void uip_icmp6_error_output(uint8_t type, uint8_t code, uint32_t param)
Send an icmpv6 error message.
CCIF void uip_send(const void *data, int len)
Send data on the current connection.
Network interface and stateless autoconfiguration (RFC 4862)
#define UIP_MAXSYNRTX
The maximum number of times a SYN segment should be retransmitted before a connection request should ...
uint8_t nrtx
The number of retransmissions for the last segment sent.
uint16_t uip_chksum(uint16_t *buf, uint16_t len)
Calculate the Internet checksum over a buffer.
#define uip_is_addr_mcast_routable(a)
is address a routable multicast address.
#define UIP_RTO
The initial retransmission timeout counted in timer pulses.
CCIF uip_buf_t uip_aligned_buf
Packet buffer for incoming and outgoing packets.
uint16_t mss
Current maximum segment size for the connection.
uint16_t lport
The local TCP port, in network byte order.
#define NULL
The null pointer.
uint8_t timer
The retransmission timer.
uint16_t len
Length of the data that was previously sent.
#define UIP_MAXRTX
The maximum number of times a segment should be retransmitted before the connection should be aborted...
void uip_log(char *msg)
Print out a uIP log message.
void uip_nd6_init()
Initialise the uIP ND core.
#define uip_is_addr_loopback(a)
Is IPv6 address a the unspecified address a is of type uip_ipaddr_t.
void uip_listen(uint16_t port)
Start listening to the specified port.
uint16_t lport
The local port number in network byte order.
#define UIP_BUFSIZE
The size of the uIP packet buffer.
struct uip_conn * uip_connect(uip_ipaddr_t *ripaddr, uint16_t port)
Connect to a remote host using TCP.
#define UIP_EXT_HDR_BITMAP_HBHO
Bitmaps for extension header processing.
#define UIP_HTONS(n)
Convert 16-bit quantity from host byte order to network byte order.
#define ICMP6_TIME_EXCEED_REASSEMBLY
ttl==0 in reass
void uip_reass_over(void)
Periodic processing for a connection identified by its number.
webserver_log_file & uip_conn
Pointer to the current TCP connection.
#define UIP_TIME_WAIT_TIMEOUT
How long a connection should stay in the TIME_WAIT state.
#define ICMP6_PARAM_PROB
ip6 header bad
#define UIP_STAT(s)
The uIP TCP/IP statistics.
#define ICMP6_PARAMPROB_OPTION
unrecognized option
uip_ipaddr_t ripaddr
The IP address of the remote peer.
uint16_t uip_tcpchksum(void)
Calculate the TCP checksum of the packet in uip_buf and uip_appdata.
uint8_t uip_ext_bitmap
bitmap we use to record which IPv6 headers we have already seen
#define UIP_IP_BUF
Pointer to IP header.
void uip_unlisten(uint16_t port)
Stop listening to the specified port.
uint8_t uip_ext_opt_offset
length of the header options read
#define UIP_LLH_LEN
The link level header length.
uint16_t rport
The local remote TCP port, in network byte order.
#define uip_is_addr_unspecified(a)
Is IPv6 address a the unspecified address a is of type uip_ipaddr_t.
#define UIP_LISTENPORTS
The maximum number of simultaneously listening TCP ports.
uint16_t uip_icmp6chksum(void)
Calculate the ICMP checksum of the packet in uip_buf.
uint8_t rcv_nxt[4]
The sequence number that we expect to receive next.
Configuration options for uIP.
uint8_t * uip_next_hdr
Type of the next header in IPv6 header or extension headers.
uint8_t rto
Retransmission time-out.
#define uip_ipaddr_copy(dest, src)
Copy an IP address from one place to another.
#define ICMP6_DST_UNREACH
dest unreachable
#define ICMP6_DST_UNREACH_NOPORT
port unreachable
#define ICMP6_DST_UNREACH_NOTNEIGHBOR
not a neighbor(obsolete)
uint16_t initialmss
Initial maximum segment size for the connection.
CCIF uint16_t uip_htons(uint16_t val)
Convert a 16-bit quantity from host byte order to network byte order.
uint8_t uip_ext_len
The length of the extension headers.
void uip_init(void)
uIP initialization function.
ICMPv6 echo request and error messages (RFC 4443)
#define UIP_EXT_HDR_OPT_PAD1
Destination and Hop By Hop extension headers option types.
void uip_add32(uint8_t *op32, uint16_t op16)
Carry out a 32-bit addition.
uint8_t tcpstateflags
TCP state and flags.
void uip_ds6_select_src(uip_ipaddr_t *src, uip_ipaddr_t *dst)
Source address selection, see RFC 3484.
uint8_t sa
Retransmission time-out calculation state variable.
#define UIP_ICMP_BUF
Pointer to ICMP header.
#define UIP_REASS_MAXAGE
The maximum time an IP fragment should wait in the reassembly buffer before it is dropped...
uint8_t snd_nxt[4]
The sequence number that was last sent by us.
#define ICMP6_PARAMPROB_HEADER
erroneous header field
void etimer_stop(struct etimer *et)
Stop a pending event timer.
void etimer_set(struct etimer *et, clock_time_t interval)
Set an event timer.
void uip_process(uint8_t flag)
process the options within a hop by hop or destination option header
#define UIP_UDP_CONNS
The maximum amount of concurrent UDP connections.
struct uip_udp_conn * uip_udp_new(const uip_ipaddr_t *ripaddr, uint16_t rport)
Set up a new UDP connection.
#define ICMP6_TIME_EXCEEDED
time exceeded
#define UIP_PROTO_HBHO
extension headers types
A set of debugging macros.
uip_ipaddr_t ripaddr
The IP address of the remote host.
Representation of a uIP UDP connection.
#define UIP_APPCALL
The name of the application function that uIP should call in response to TCP/IP events.
uint8_t uip_icmp6_input(uint8_t type, uint8_t icode)
Handle an incoming ICMPv6 message.
void uip_ds6_init(void)
Initialize data structures.
void uip_icmp6_init()
Initialise the uIP ICMPv6 core.
#define UIP_RECEIVE_WINDOW
The size of the advertised receiver's window.
#define UIP_TCP_MSS
The TCP maximum segment size.
uip_appdata
Pointer to the application data in the packet buffer.
uint8_t ttl
Default time-to-live.
#define CLOCK_SECOND
A second, measured in system clock time.