84 #include "rpl/rpl-private.h"
93 #define DEBUG DEBUG_NONE
99 #define UIP_LOG(m) uip_log(m)
104 #if UIP_STATISTICS == 1
116 #if UIP_CONF_LL_802154
156 #define FBUF ((struct uip_tcpip_hdr *)&uip_reassbuf[0])
157 #define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
158 #define UIP_ICMP_BUF ((struct uip_icmp_hdr *)&uip_buf[uip_l2_l3_hdr_len])
159 #define UIP_UDP_BUF ((struct uip_udp_hdr *)&uip_buf[UIP_LLH_LEN + UIP_IPH_LEN])
160 #define UIP_TCP_BUF ((struct uip_tcp_hdr *)&uip_buf[UIP_LLH_LEN + UIP_IPH_LEN])
161 #define UIP_EXT_BUF ((struct uip_ext_hdr *)&uip_buf[uip_l2_l3_hdr_len])
162 #define UIP_ROUTING_BUF ((struct uip_routing_hdr *)&uip_buf[uip_l2_l3_hdr_len])
163 #define UIP_FRAG_BUF ((struct uip_frag_hdr *)&uip_buf[uip_l2_l3_hdr_len])
164 #define UIP_HBHO_BUF ((struct uip_hbho_hdr *)&uip_buf[uip_l2_l3_hdr_len])
165 #define UIP_DESTO_BUF ((struct uip_desto_hdr *)&uip_buf[uip_l2_l3_hdr_len])
166 #define UIP_EXT_HDR_OPT_BUF ((struct uip_ext_hdr_opt *)&uip_buf[uip_l2_l3_hdr_len + uip_ext_opt_offset])
167 #define UIP_EXT_HDR_OPT_PADN_BUF ((struct uip_ext_hdr_opt_padn *)&uip_buf[uip_l2_l3_hdr_len + uip_ext_opt_offset])
168 #if UIP_CONF_IPV6_RPL
169 #define UIP_EXT_HDR_OPT_RPL_BUF ((struct uip_ext_hdr_opt_rpl *)&uip_buf[uip_l2_l3_hdr_len + uip_ext_opt_offset])
171 #define UIP_ICMP6_ERROR_BUF ((struct uip_icmp6_error *)&uip_buf[uip_l2_l3_icmp_hdr_len])
178 #ifndef UIP_CONF_EXTERNAL_BUFFER
190 uint16_t uip_urglen, uip_surglen;
211 #if UIP_ACTIVE_OPEN || UIP_UDP
213 static uint16_t lastport;
233 #define TCP_OPT_END 0
234 #define TCP_OPT_NOOP 1
235 #define TCP_OPT_MSS 2
237 #define TCP_OPT_MSS_LEN 4
251 static uint8_t iss[4];
287 void uip_add32(uint8_t *op32, uint16_t op16);
294 uip_acc32[1] = op32[1];
295 uip_acc32[0] = op32[0];
297 if(uip_acc32[2] < (op16 >> 8)) {
299 if(uip_acc32[1] == 0) {
305 if(uip_acc32[3] < (op16 & 0xff)) {
307 if(uip_acc32[2] == 0) {
309 if(uip_acc32[1] == 0) {
318 #if ! UIP_ARCH_CHKSUM
321 chksum(uint16_t sum,
const uint8_t *data, uint16_t len)
324 const uint8_t *dataptr;
325 const uint8_t *last_byte;
328 last_byte = data + len - 1;
330 while(dataptr < last_byte) {
331 t = (dataptr[0] << 8) + dataptr[1];
339 if(dataptr == last_byte) {
340 t = (dataptr[0] << 8) + 0;
354 return uip_htons(chksum(0, (uint8_t *)data, len));
357 #ifndef UIP_ARCH_IPCHKSUM
364 PRINTF(
"uip_ipchksum: sum 0x%04x\n", sum);
365 return (sum == 0) ? 0xffff :
uip_htons(sum);
370 upper_layer_chksum(uint8_t proto)
381 volatile uint16_t upper_layer_len;
386 PRINTF(
"Upper layer checksum len: %d from: %d\n", upper_layer_len,
391 sum = upper_layer_len + proto;
393 sum = chksum(sum, (uint8_t *)&
UIP_IP_BUF->srcipaddr, 2 *
sizeof(uip_ipaddr_t));
399 return (sum == 0) ? 0xffff :
uip_htons(sum);
405 return upper_layer_chksum(UIP_PROTO_ICMP6);
413 return upper_layer_chksum(UIP_PROTO_TCP);
417 #if UIP_UDP && UIP_UDP_CHECKSUMS
421 return upper_layer_chksum(UIP_PROTO_UDP);
437 uip_listenports[c] = 0;
444 #if UIP_ACTIVE_OPEN || UIP_UDP
450 uip_udp_conns[c].
lport = 0;
454 #if UIP_CONF_IPV6_MULTICAST
459 #if UIP_TCP && UIP_ACTIVE_OPEN
463 register struct uip_conn *conn, *cconn;
470 if(lastport >= 32000) {
477 conn = &uip_conns[c];
486 cconn = &uip_conns[c];
536 PRINTF(
"Cutting ext-header before processing (extlen: %d, uiplen: %d)\n",
539 PRINTF(
"ERROR: uip_len too short compared to ext len\n");
543 memmove(((uint8_t *)UIP_TCP_BUF), (uint8_t *)UIP_TCP_BUF +
uip_ext_len,
556 struct uip_udp_conn *
560 register struct uip_udp_conn *conn;
566 if(lastport >= 32000) {
578 if(uip_udp_conns[c].
lport == 0) {
579 conn = &uip_udp_conns[c];
590 if(ripaddr ==
NULL) {
591 memset(&conn->
ripaddr, 0,
sizeof(uip_ipaddr_t));
607 if(uip_listenports[c] == port) {
608 uip_listenports[c] = 0;
619 if(uip_listenports[c] == 0) {
620 uip_listenports[c] = port;
628 #if UIP_CONF_IPV6_REASSEMBLY
629 #define UIP_REASS_BUFSIZE (UIP_BUFSIZE - UIP_LLH_LEN)
631 static uint8_t uip_reassbuf[UIP_REASS_BUFSIZE];
633 static uint8_t uip_reassbitmap[UIP_REASS_BUFSIZE / (8 * 8)];
636 static const uint8_t bitmap_bits[8] = {0xff, 0x7f, 0x3f, 0x1f,
637 0x0f, 0x07, 0x03, 0x01};
638 static uint16_t uip_reasslen;
639 static uint8_t uip_reassflags;
641 #define UIP_REASS_FLAG_LASTFRAG 0x01
642 #define UIP_REASS_FLAG_FIRSTFRAG 0x02
643 #define UIP_REASS_FLAG_ERROR_MSG 0x04
657 uint8_t uip_reass_on;
659 static uint32_t uip_id;
674 if(uip_reass_on == 0) {
675 PRINTF(
"Starting reassembly\n");
681 uip_id = UIP_FRAG_BUF->id;
683 memset(uip_reassbitmap, 0,
sizeof(uip_reassbitmap));
690 if(uip_ipaddr_cmp(&FBUF->srcipaddr, &
UIP_IP_BUF->srcipaddr) &&
691 uip_ipaddr_cmp(&FBUF->destipaddr, &
UIP_IP_BUF->destipaddr) &&
692 UIP_FRAG_BUF->id == uip_id) {
694 offset = (uip_ntohs(UIP_FRAG_BUF->offsetresmore) & 0xfff8);
696 PRINTF(
"len %d\n", len);
697 PRINTF(
"offset %d\n", offset);
699 uip_reassflags |= UIP_REASS_FLAG_FIRSTFRAG;
708 PRINT6ADDR(&FBUF->srcipaddr);
710 PRINT6ADDR(&FBUF->destipaddr);
717 if(offset > UIP_REASS_BUFSIZE ||
718 offset + len > UIP_REASS_BUFSIZE) {
726 if((uip_ntohs(UIP_FRAG_BUF->offsetresmore) & IP_MF) == 0) {
727 uip_reassflags |= UIP_REASS_FLAG_LASTFRAG;
729 uip_reasslen = offset + len;
730 PRINTF(
"LAST FRAGMENT reasslen %d\n", uip_reasslen);
738 uip_reassflags |= UIP_REASS_FLAG_ERROR_MSG;
749 memcpy((uint8_t *)FBUF + UIP_IPH_LEN +
uip_ext_len + offset,
750 (uint8_t *)UIP_FRAG_BUF + UIP_FRAGH_LEN, len);
753 if(offset >> 6 == (offset + len) >> 6) {
754 uip_reassbitmap[offset >> 6] |=
755 bitmap_bits[(offset >> 3) & 7] &
756 ~bitmap_bits[((offset + len) >> 3) & 7];
761 uip_reassbitmap[offset >> 6] |= bitmap_bits[(offset >> 3) & 7];
763 for(i = (1 + (offset >> 6)); i < ((offset + len) >> 6); ++i) {
764 uip_reassbitmap[i] = 0xff;
766 uip_reassbitmap[(offset + len) >> 6] |=
767 ~bitmap_bits[((offset + len) >> 3) & 7];
774 if(uip_reassflags & UIP_REASS_FLAG_LASTFRAG) {
777 for(i = 0; i < (uip_reasslen >> 6); ++i) {
778 if(uip_reassbitmap[i] != 0xff) {
784 if(uip_reassbitmap[uip_reasslen >> 6] !=
785 (uint8_t)~bitmap_bits[(uip_reasslen >> 3) & 7]) {
796 UIP_IP_BUF->len[0] = ((uip_reasslen - UIP_IPH_LEN) >> 8);
797 UIP_IP_BUF->len[1] = ((uip_reasslen - UIP_IPH_LEN) & 0xff);
798 PRINTF(
"REASSEMBLED PAQUET %d (%d)\n", uip_reasslen,
805 PRINTF(
"Already reassembling another paquet\n");
818 if(uip_reassflags & UIP_REASS_FLAG_FIRSTFRAG){
819 PRINTF(
"FRAG INTERRUPTED TOO LATE\n");
844 uip_add_rcv_nxt(uint16_t n)
868 switch(UIP_EXT_HDR_OPT_BUF->type) {
875 PRINTF(
"Processing PAD1 option\n");
878 case UIP_EXT_HDR_OPT_PADN:
879 PRINTF(
"Processing PADN option\n");
882 case UIP_EXT_HDR_OPT_RPL:
891 #if UIP_CONF_IPV6_RPL
892 PRINTF(
"Processing RPL option\n");
894 PRINTF(
"RPL Option Error: Dropping Packet\n");
914 PRINTF(
"MSB %x\n", UIP_EXT_HDR_OPT_BUF->type);
915 switch(UIP_EXT_HDR_OPT_BUF->type & 0xC0) {
946 register struct uip_conn *uip_connr =
uip_conn;
949 if(flag == UIP_UDP_SEND_CONN) {
957 if(flag == UIP_POLL_REQUEST) {
959 if((uip_connr->
tcpstateflags & UIP_TS_MASK) == UIP_ESTABLISHED &&
960 !uip_outstanding(uip_connr)) {
961 uip_flags = UIP_POLL;
965 }
else if((uip_connr->
tcpstateflags & UIP_TS_MASK) == UIP_SYN_SENT) {
967 UIP_TCP_BUF->flags = 0;
974 }
else if(flag == UIP_TIMER) {
997 ++(uip_connr->
timer);
1007 if(uip_outstanding(uip_connr)) {
1008 if(uip_connr->
timer-- == 0) {
1020 uip_flags = UIP_TIMEDOUT;
1024 UIP_TCP_BUF->flags = TCP_RST | TCP_ACK;
1025 goto tcp_send_nodata;
1032 ++(uip_connr->
nrtx);
1046 goto tcp_send_synack;
1051 UIP_TCP_BUF->flags = 0;
1055 case UIP_ESTABLISHED:
1062 uip_flags = UIP_REXMIT;
1066 case UIP_FIN_WAIT_1:
1070 goto tcp_send_finack;
1073 }
else if((uip_connr->
tcpstateflags & UIP_TS_MASK) == UIP_ESTABLISHED) {
1078 uip_flags = UIP_POLL;
1087 if(flag == UIP_UDP_TIMER) {
1088 if(uip_udp_conn->
lport != 0) {
1092 uip_flags = UIP_POLL;
1111 UIP_LOG(
"ipv6: invalid version.");
1137 UIP_LOG(
"ip: packet shorter than reported in IP header.");
1141 PRINTF(
"IPv6 packet received from ");
1149 PRINTF(
"Dropping packet, src is mcast\n");
1163 #if UIP_CONF_IPV6_CHECKS
1173 PRINTF(
"Dropping packet after extension header processing\n");
1177 PRINTF(
"Sending error message after extension header processing\n");
1195 #if UIP_CONF_IPV6_MULTICAST
1197 if(UIP_MCAST6.
in() == UIP_MCAST6_ACCEPT) {
1208 if(!uip_ds6_is_my_addr(&
UIP_IP_BUF->destipaddr) &&
1209 !uip_ds6_is_my_maddr(&
UIP_IP_BUF->destipaddr)) {
1231 #if UIP_CONF_IPV6_RPL
1232 if(!rpl_update_header()) {
1234 PRINTF(
"RPL header update error\n");
1240 PRINTF(
"Forwarding packet to ");
1250 (!uip_ds6_is_addr_onlink((&
UIP_IP_BUF->destipaddr)))) {
1251 PRINTF(
"LL source address with off link destination, dropping\n");
1256 PRINTF(
"Dropping packet, not for me and link local or multicast\n");
1262 if(!uip_ds6_is_my_addr(&
UIP_IP_BUF->destipaddr) &&
1263 !uip_ds6_is_my_maddr(&
UIP_IP_BUF->destipaddr) &&
1265 PRINTF(
"Dropping packet, not for me\n");
1279 #if UIP_CONF_IPV6_MULTICAST
1295 case UIP_PROTO_ICMP6:
1299 PRINTF(
"Processing hbh header\n");
1301 #if UIP_CONF_IPV6_CHECKS
1324 case UIP_PROTO_DESTO:
1325 #if UIP_CONF_IPV6_CHECKS
1327 PRINTF(
"Processing desto header\n");
1353 case UIP_PROTO_ROUTING:
1354 #if UIP_CONF_IPV6_CHECKS
1370 PRINTF(
"Processing Routing header\n");
1371 if(UIP_ROUTING_BUF->seg_left > 0) {
1372 #if UIP_CONF_IPV6_RPL && RPL_WITH_NON_STORING
1373 if(rpl_process_srh_header()) {
1379 UIP_LOG(
"ip6: unrecognized routing type");
1385 case UIP_PROTO_FRAG:
1387 #if UIP_CONF_IPV6_REASSEMBLY
1388 PRINTF(
"Processing frag header\n");
1393 if(uip_reassflags & UIP_REASS_FLAG_ERROR_MSG){
1399 PRINTF(
"Processing reassembled packet\n");
1407 UIP_LOG(
"ip: fragment dropped.");
1410 case UIP_PROTO_NONE:
1424 UIP_LOG(
"ip6: unrecognized header");
1432 #if UIP_CONF_IPV6_CHECKS
1437 UIP_LOG(
"icmpv6: bad checksum.");
1438 PRINTF(
"icmpv6: bad checksum.\n");
1463 PRINTF(
"Unknown ICMPv6 message type/code %d\n",
UIP_ICMP_BUF->type);
1466 UIP_LOG(
"icmp6: unknown ICMPv6 message.");
1485 PRINTF(
"Receiving UDP packet\n");
1491 #if UIP_UDP_CHECKSUMS
1497 if(UIP_UDP_BUF->udpchksum != 0 &&
uip_udpchksum() != 0xffff) {
1500 PRINTF(
"udp: bad checksum 0x%04x 0x%04x\n", UIP_UDP_BUF->udpchksum,
1507 if(UIP_UDP_BUF->destport == 0) {
1508 PRINTF(
"udp: zero port.\n");
1513 for(uip_udp_conn = &uip_udp_conns[0];
1523 if(uip_udp_conn->
lport != 0 &&
1524 UIP_UDP_BUF->destport == uip_udp_conn->
lport &&
1525 (uip_udp_conn->
rport == 0 ||
1526 UIP_UDP_BUF->srcport == uip_udp_conn->
rport) &&
1532 PRINTF(
"udp: no matching connection found\n");
1539 PRINTF(
"In udp_found\n");
1545 uip_flags = UIP_NEWDATA;
1551 PRINTF(
"In udp_send\n");
1556 uip_len = uip_slen + UIP_IPUDPH_LEN;
1566 UIP_UDP_BUF->udplen =
UIP_HTONS(uip_slen + UIP_UDPH_LEN);
1567 UIP_UDP_BUF->udpchksum = 0;
1569 UIP_UDP_BUF->srcport = uip_udp_conn->
lport;
1570 UIP_UDP_BUF->destport = uip_udp_conn->
rport;
1577 #if UIP_UDP_CHECKSUMS
1580 if(UIP_UDP_BUF->udpchksum == 0) {
1581 UIP_UDP_BUF->udpchksum = 0xffff;
1585 #if UIP_CONF_IPV6_RPL
1586 rpl_insert_header();
1601 PRINTF(
"Receiving TCP packet\n");
1608 PRINTF(
"tcp: bad checksum 0x%04x 0x%04x\n", UIP_TCP_BUF->tcpchksum,
1614 if(UIP_TCP_BUF->destport == 0 || UIP_TCP_BUF->srcport == 0) {
1615 PRINTF(
"tcp: zero port.");
1621 for(uip_connr = &uip_conns[0]; uip_connr <= &uip_conns[UIP_CONNS - 1];
1624 UIP_TCP_BUF->destport == uip_connr->
lport &&
1625 UIP_TCP_BUF->srcport == uip_connr->
rport &&
1635 if((UIP_TCP_BUF->flags & TCP_CTL) != TCP_SYN) {
1639 tmp16 = UIP_TCP_BUF->destport;
1642 if(tmp16 == uip_listenports[c]) {
1651 PRINTF(
"In reset\n");
1653 if(UIP_TCP_BUF->flags & TCP_RST) {
1659 UIP_TCP_BUF->flags = TCP_RST | TCP_ACK;
1661 UIP_TCP_BUF->tcpoffset = 5 << 4;
1664 c = UIP_TCP_BUF->seqno[3];
1665 UIP_TCP_BUF->seqno[3] = UIP_TCP_BUF->ackno[3];
1666 UIP_TCP_BUF->ackno[3] = c;
1668 c = UIP_TCP_BUF->seqno[2];
1669 UIP_TCP_BUF->seqno[2] = UIP_TCP_BUF->ackno[2];
1670 UIP_TCP_BUF->ackno[2] = c;
1672 c = UIP_TCP_BUF->seqno[1];
1673 UIP_TCP_BUF->seqno[1] = UIP_TCP_BUF->ackno[1];
1674 UIP_TCP_BUF->ackno[1] = c;
1676 c = UIP_TCP_BUF->seqno[0];
1677 UIP_TCP_BUF->seqno[0] = UIP_TCP_BUF->ackno[0];
1678 UIP_TCP_BUF->ackno[0] = c;
1683 if(++UIP_TCP_BUF->ackno[3] == 0) {
1684 if(++UIP_TCP_BUF->ackno[2] == 0) {
1685 if(++UIP_TCP_BUF->ackno[1] == 0) {
1686 ++UIP_TCP_BUF->ackno[0];
1692 tmp16 = UIP_TCP_BUF->srcport;
1693 UIP_TCP_BUF->srcport = UIP_TCP_BUF->destport;
1694 UIP_TCP_BUF->destport = tmp16;
1700 goto tcp_send_noconn;
1706 PRINTF(
"In found listen\n");
1716 uip_connr = &uip_conns[c];
1720 if(uip_connr == 0 ||
1722 uip_connr = &uip_conns[c];
1727 if(uip_connr == 0) {
1732 UIP_LOG(
"tcp: found no unused connections.");
1735 uip_conn = uip_connr;
1741 uip_connr->
nrtx = 0;
1742 uip_connr->
lport = UIP_TCP_BUF->destport;
1743 uip_connr->
rport = UIP_TCP_BUF->srcport;
1747 uip_connr->
snd_nxt[0] = iss[0];
1748 uip_connr->
snd_nxt[1] = iss[1];
1749 uip_connr->
snd_nxt[2] = iss[2];
1750 uip_connr->
snd_nxt[3] = iss[3];
1754 uip_connr->
rcv_nxt[0] = UIP_TCP_BUF->seqno[0];
1755 uip_connr->
rcv_nxt[1] = UIP_TCP_BUF->seqno[1];
1756 uip_connr->
rcv_nxt[2] = UIP_TCP_BUF->seqno[2];
1757 uip_connr->
rcv_nxt[3] = UIP_TCP_BUF->seqno[3];
1761 if((UIP_TCP_BUF->tcpoffset & 0xf0) > 0x50) {
1762 for(c = 0; c < ((UIP_TCP_BUF->tcpoffset >> 4) - 5) << 2 ;) {
1764 if(opt == TCP_OPT_END) {
1767 }
else if(opt == TCP_OPT_NOOP) {
1770 }
else if(opt == TCP_OPT_MSS &&
1796 UIP_TCP_BUF->flags = TCP_ACK;
1799 UIP_TCP_BUF->flags |= TCP_SYN;
1802 UIP_TCP_BUF->flags = TCP_SYN | TCP_ACK;
1807 UIP_TCP_BUF->optdata[0] = TCP_OPT_MSS;
1808 UIP_TCP_BUF->optdata[1] = TCP_OPT_MSS_LEN;
1811 uip_len = UIP_IPTCPH_LEN + TCP_OPT_MSS_LEN;
1812 UIP_TCP_BUF->tcpoffset = ((UIP_TCPH_LEN + TCP_OPT_MSS_LEN) / 4) << 4;
1817 PRINTF(
"In found\n");
1818 uip_conn = uip_connr;
1824 if(UIP_TCP_BUF->flags & TCP_RST) {
1826 UIP_LOG(
"tcp: got reset, aborting connection.");
1827 uip_flags = UIP_ABORT;
1833 c = (UIP_TCP_BUF->tcpoffset >> 4) << 2;
1844 if(!((((uip_connr->
tcpstateflags & UIP_TS_MASK) == UIP_SYN_SENT) &&
1845 ((UIP_TCP_BUF->flags & TCP_CTL) == (TCP_SYN | TCP_ACK))) ||
1846 (((uip_connr->
tcpstateflags & UIP_TS_MASK) == UIP_SYN_RCVD) &&
1847 ((UIP_TCP_BUF->flags & TCP_CTL) == TCP_SYN)))) {
1848 if((
uip_len > 0 || ((UIP_TCP_BUF->flags & (TCP_SYN | TCP_FIN)) != 0)) &&
1849 (UIP_TCP_BUF->seqno[0] != uip_connr->
rcv_nxt[0] ||
1850 UIP_TCP_BUF->seqno[1] != uip_connr->
rcv_nxt[1] ||
1851 UIP_TCP_BUF->seqno[2] != uip_connr->
rcv_nxt[2] ||
1852 UIP_TCP_BUF->seqno[3] != uip_connr->
rcv_nxt[3])) {
1854 if((UIP_TCP_BUF->flags & TCP_SYN)) {
1855 if((uip_connr->
tcpstateflags & UIP_TS_MASK) == UIP_SYN_RCVD) {
1856 goto tcp_send_synack;
1857 }
else if((uip_connr->
tcpstateflags & UIP_TS_MASK) == UIP_SYN_SENT) {
1869 if((UIP_TCP_BUF->flags & TCP_ACK) && uip_outstanding(uip_connr)) {
1872 if(UIP_TCP_BUF->ackno[0] ==
uip_acc32[0] &&
1873 UIP_TCP_BUF->ackno[1] ==
uip_acc32[1] &&
1874 UIP_TCP_BUF->ackno[2] ==
uip_acc32[2] &&
1875 UIP_TCP_BUF->ackno[3] ==
uip_acc32[3]) {
1883 if(uip_connr->
nrtx == 0) {
1885 m = uip_connr->
rto - uip_connr->
timer;
1887 m = m - (uip_connr->
sa >> 3);
1892 m = m - (uip_connr->
sv >> 2);
1894 uip_connr->
rto = (uip_connr->
sa >> 3) + uip_connr->
sv;
1898 uip_flags = UIP_ACKDATA;
1919 if(uip_flags & UIP_ACKDATA) {
1921 uip_flags = UIP_CONNECTED;
1924 uip_flags |= UIP_NEWDATA;
1932 if((UIP_TCP_BUF->flags & TCP_CTL) == TCP_SYN) {
1933 goto tcp_send_synack;
1942 if((uip_flags & UIP_ACKDATA) &&
1943 (UIP_TCP_BUF->flags & TCP_CTL) == (TCP_SYN | TCP_ACK)) {
1946 if((UIP_TCP_BUF->tcpoffset & 0xf0) > 0x50) {
1947 for(c = 0; c < ((UIP_TCP_BUF->tcpoffset >> 4) - 5) << 2 ;) {
1949 if(opt == TCP_OPT_END) {
1952 }
else if(opt == TCP_OPT_NOOP) {
1955 }
else if(opt == TCP_OPT_MSS &&
1978 uip_connr->
rcv_nxt[0] = UIP_TCP_BUF->seqno[0];
1979 uip_connr->
rcv_nxt[1] = UIP_TCP_BUF->seqno[1];
1980 uip_connr->
rcv_nxt[2] = UIP_TCP_BUF->seqno[2];
1981 uip_connr->
rcv_nxt[3] = UIP_TCP_BUF->seqno[3];
1983 uip_flags = UIP_CONNECTED | UIP_NEWDATA;
1991 uip_flags = UIP_ABORT;
1998 case UIP_ESTABLISHED:
2010 if(UIP_TCP_BUF->flags & TCP_FIN && !(uip_connr->
tcpstateflags & UIP_STOPPED)) {
2011 if(uip_outstanding(uip_connr)) {
2015 uip_flags |= UIP_CLOSE;
2017 uip_flags |= UIP_NEWDATA;
2022 uip_connr->
nrtx = 0;
2024 UIP_TCP_BUF->flags = TCP_FIN | TCP_ACK;
2025 goto tcp_send_nodata;
2030 if((UIP_TCP_BUF->flags & TCP_URG) != 0) {
2032 uip_urglen = (UIP_TCP_BUF->urgp[0] << 8) | UIP_TCP_BUF->urgp[1];
2037 uip_add_rcv_nxt(uip_urglen);
2045 uip_len -= (UIP_TCP_BUF->urgp[0] << 8) | UIP_TCP_BUF->urgp[1];
2055 uip_flags |= UIP_NEWDATA;
2071 tmp16 = ((uint16_t)UIP_TCP_BUF->wnd[0] << 8) + (uint16_t)UIP_TCP_BUF->wnd[1];
2076 uip_connr->
mss = tmp16;
2094 if(uip_flags & (UIP_NEWDATA | UIP_ACKDATA)) {
2100 if(uip_flags & UIP_ABORT) {
2103 UIP_TCP_BUF->flags = TCP_RST | TCP_ACK;
2104 goto tcp_send_nodata;
2107 if(uip_flags & UIP_CLOSE) {
2111 uip_connr->
nrtx = 0;
2112 UIP_TCP_BUF->flags = TCP_FIN | TCP_ACK;
2113 goto tcp_send_nodata;
2121 if((uip_flags & UIP_ACKDATA) != 0) {
2128 if(uip_connr->
len == 0) {
2133 if(uip_slen > uip_connr->
mss) {
2134 uip_slen = uip_connr->
mss;
2139 uip_connr->
len = uip_slen;
2145 uip_slen = uip_connr->
len;
2148 uip_connr->
nrtx = 0;
2154 if(uip_slen > 0 && uip_connr->
len > 0) {
2158 UIP_TCP_BUF->flags = TCP_ACK | TCP_PSH;
2160 goto tcp_send_noopts;
2164 if(uip_flags & UIP_NEWDATA) {
2166 UIP_TCP_BUF->flags = TCP_ACK;
2167 goto tcp_send_noopts;
2174 if(uip_flags & UIP_ACKDATA) {
2176 uip_flags = UIP_CLOSE;
2181 case UIP_FIN_WAIT_1:
2188 if(UIP_TCP_BUF->flags & TCP_FIN) {
2189 if(uip_flags & UIP_ACKDATA) {
2191 uip_connr->
timer = 0;
2197 uip_flags = UIP_CLOSE;
2200 }
else if(uip_flags & UIP_ACKDATA) {
2210 case UIP_FIN_WAIT_2:
2214 if(UIP_TCP_BUF->flags & TCP_FIN) {
2216 uip_connr->
timer = 0;
2218 uip_flags = UIP_CLOSE;
2231 if(uip_flags & UIP_ACKDATA) {
2233 uip_connr->
timer = 0;
2241 UIP_TCP_BUF->flags = TCP_ACK;
2247 UIP_TCP_BUF->tcpoffset = (UIP_TCPH_LEN / 4) << 4;
2254 PRINTF(
"In tcp_send\n");
2256 UIP_TCP_BUF->ackno[0] = uip_connr->
rcv_nxt[0];
2257 UIP_TCP_BUF->ackno[1] = uip_connr->
rcv_nxt[1];
2258 UIP_TCP_BUF->ackno[2] = uip_connr->
rcv_nxt[2];
2259 UIP_TCP_BUF->ackno[3] = uip_connr->
rcv_nxt[3];
2261 UIP_TCP_BUF->seqno[0] = uip_connr->
snd_nxt[0];
2262 UIP_TCP_BUF->seqno[1] = uip_connr->
snd_nxt[1];
2263 UIP_TCP_BUF->seqno[2] = uip_connr->
snd_nxt[2];
2264 UIP_TCP_BUF->seqno[3] = uip_connr->
snd_nxt[3];
2266 UIP_TCP_BUF->srcport = uip_connr->
lport;
2267 UIP_TCP_BUF->destport = uip_connr->
rport;
2271 PRINTF(
"Sending TCP packet to ");
2280 UIP_TCP_BUF->wnd[0] = UIP_TCP_BUF->wnd[1] = 0;
2293 UIP_TCP_BUF->urgp[0] = UIP_TCP_BUF->urgp[1] = 0;
2296 UIP_TCP_BUF->tcpchksum = 0;
2308 PRINTF(
"Sending packet with length %d (%d)\n",
uip_len,
2330 uip_htonl(uint32_t val)
2332 return UIP_HTONL(val);
2340 if(uip_sappdata !=
NULL) {
2342 (
int)((
char *)uip_sappdata -
2349 if(data != uip_sappdata) {
2350 if(uip_sappdata ==
NULL) {
2354 memcpy(uip_sappdata, (data), uip_slen);
void uip_log(char *msg)
Print out a uIP log message.
Header file for IPv6 Neighbor discovery (RFC 4861)
#define UIP_EXT_HDR_OPT_PAD1
Destination and Hop By Hop extension headers option types.
#define UIP_REASS_MAXAGE
The maximum time an IP fragment should wait in the reassembly buffer before it is dropped...
#define ICMP6_TIME_EXCEED_TRANSIT
ttl==0 in transit
uint16_t initialmss
Initial maximum segment size for the connection.
#define UIP_MAXRTX
The maximum number of times a segment should be retransmitted before the connection should be aborted...
uint8_t sa
Retransmission time-out calculation state variable.
uint8_t tcpstateflags
TCP state and flags.
The structure holding the TCP/IP statistics that are gathered if UIP_STATISTICS is set to 1...
struct uip_udp_conn * uip_udp_conn
The current UDP connection.
#define ICMP6_PARAMPROB_HEADER
erroneous header field
uint16_t uip_ipchksum(void)
Calculate the IP header checksum of the packet header in uip_buf.
uip_ipaddr_t ripaddr
The IP address of the remote peer.
Representation of a uIP TCP connection.
#define UIP_EXT_HDR_BITMAP_HBHO
Bitmaps for extension header processing.
Configuration options for uIP.
Header file for IPv6-related data structures.
uint8_t(* in)(void)
Process an incoming multicast datagram and determine whether it should be delivered up the stack or n...
#define UIP_CONNS
The maximum number of simultaneously open TCP connections.
#define UIP_HTONS(n)
Convert 16-bit quantity from host byte order to network byte order.
uint8_t uip_acc32[4]
4-byte array used for the 32-bit sequence number calculations.
Default definitions of C compiler quirk work-arounds.
void uip_send(const void *data, int len)
Send data on the current connection.
void etimer_set(struct etimer *et, clock_time_t interval)
Set an event timer.
Representation of a uIP UDP connection.
struct uip_conn * uip_conn
Pointer to the current TCP connection.
#define UIP_LLH_LEN
The link level header length.
uint16_t uip_icmp6chksum(void)
Calculate the ICMP checksum of the packet in uip_buf.
uint8_t uip_ext_bitmap
bitmap we use to record which IPv6 headers we have already seen
#define uip_is_addr_unspecified(a)
Is IPv6 address a the unspecified address a is of type uip_ipaddr_t.
#define uip_buf
Macro to access uip_aligned_buf as an array of bytes.
#define ICMP6_DST_UNREACH
dest unreachable
#define uip_ipaddr_copy(dest, src)
Copy an IP address from one place to another.
uint8_t rcv_nxt[4]
The sequence number that we expect to receive next.
uint8_t snd_nxt[4]
The sequence number that was last sent by us.
uip_ipaddr_t ripaddr
The IP address of the remote host.
static uint8_t ext_hdr_options_process(void)
Process the options in Destination and Hop By Hop extension headers.
#define UIP_IP_BUF
Pointer to IP header.
#define UIP_STAT(s)
The uIP TCP/IP statistics.
#define uip_is_addr_mcast_routable(a)
is address a routable multicast address.
uint8_t uip_ext_opt_offset
length of the header options read
#define ICMP6_DST_UNREACH_NOPORT
port unreachable
uint8_t ttl
Default time-to-live.
#define uip_is_addr_mcast(a)
is address a multicast address, see RFC 3513 a is of type uip_ipaddr_t*
void uip_reass_over(void)
Abandon the reassembly of the current packet.
void etimer_stop(struct etimer *et)
Stop a pending event timer.
uint8_t uip_ext_len
length of the extension headers read.
#define UIP_MAXSYNRTX
The maximum number of times a SYN segment should be retransmitted before a connection request should ...
void uip_ds6_select_src(uip_ipaddr_t *src, uip_ipaddr_t *dst)
Source address selection, see RFC 3484.
uint8_t * uip_next_hdr
Type of the next header in IPv6 header or extension headers.
uint16_t uip_tcpchksum(void)
Calculate the TCP checksum of the packet in uip_buf and uip_appdata.
uip_buf_t uip_aligned_buf
Packet buffer for incoming and outgoing packets.
This header file contains configuration directives for uIPv6 multicast support.
void uip_listen(uint16_t port)
Start listening to the specified port.
struct uip_udp_conn * uip_udp_new(const uip_ipaddr_t *ripaddr, uint16_t rport)
Set up a new UDP connection.
#define ICMP6_TIME_EXCEED_REASSEMBLY
ttl==0 in reass
#define NULL
The null pointer.
void uip_add32(uint8_t *op32, uint16_t op16)
Carry out a 32-bit addition.
Header file for ICMPv6 message and error handing (RFC 4443)
uint16_t rport
The local remote TCP port, in network byte order.
uint8_t nrtx
The number of retransmissions for the last segment sent.
uint16_t lport
The local TCP port, in network byte order.
uint8_t rto
Retransmission time-out.
#define UIP_APPCALL
The name of the application function that uIP should call in response to TCP/IP events.
#define UIP_ICMP_BUF
Pointer to ICMP header.
#define CLOCK_SECOND
A second, measured in system clock time.
#define ICMP6_PARAM_PROB
ip6 header bad
#define UIP_UDP_CONNS
The maximum amount of concurrent UDP connections.
Header file for the uIP TCP/IP stack.
uint16_t rport
The remote port number in network byte order.
uint8_t timer
The retransmission timer.
#define UIP_PROTO_HBHO
extension headers types
#define UIP_RECEIVE_WINDOW
The size of the advertised receiver's window.
#define ICMP6_DST_UNREACH_NOTNEIGHBOR
not a neighbor(obsolete)
struct uip_conn * uip_connect(const uip_ipaddr_t *ripaddr, uint16_t port)
Connect to a remote host using TCP.
struct etimer uip_reass_timer
Timer for reassembly.
uint16_t uip_udpchksum(void)
Calculate the UDP checksum of the packet in uip_buf and uip_appdata.
uint16_t len
Length of the data that was previously sent.
#define ICMP6_TIME_EXCEEDED
time exceeded
void uip_icmp6_init()
Initialise the uIP ICMPv6 core.
uint16_t lport
The local port number in network byte order.
#define UIP_TIME_WAIT_TIMEOUT
How long a connection should stay in the TIME_WAIT state.
uint8_t sv
Retransmission time-out calculation state variable.
A set of debugging macros for the IP stack
uint16_t uip_htons(uint16_t val)
Convert a 16-bit quantity from host byte order to network byte order.
struct uip_icmp6_conn uip_icmp6_conns
single possible icmpv6 "connection"
#define UIP_TCP_MSS
The TCP maximum segment size.
void uip_ds6_init(void)
Initialize data structures.
void uip_icmp6_error_output(uint8_t type, uint8_t code, uint32_t param)
Send an icmpv6 error message.
uint16_t uip_len
The length of the packet in the uip_buf buffer.
#define uip_is_addr_loopback(a)
Is IPv6 address a the unspecified address a is of type uip_ipaddr_t.
uint16_t mss
Current maximum segment size for the connection.
#define uip_is_addr_linklocal(a)
is addr (a) a link local unicast address, see RFC3513 i.e.
uip_ds6_netif_t uip_ds6_if
The single interface.
#define ICMP6_PARAMPROB_OPTION
unrecognized option
#define UIP_LISTENPORTS
The maximum number of simultaneously listening TCP ports.
void * uip_appdata
Pointer to the application data in the packet buffer.
uint8_t uip_icmp6_input(uint8_t type, uint8_t icode)
Handle an incoming ICMPv6 message.
#define ICMP6_PARAMPROB_NEXTHEADER
unrecognized next header
#define UIP_BUFSIZE
The size of the uIP packet buffer.
void uip_init(void)
uIP initialization function.
#define UIP_LINK_MTU
The maximum transmission unit at the IP Layer.
#define ICMP6_PACKET_TOO_BIG
packet too big
void uip_nd6_init()
Initialise the uIP ND core.
uint16_t uip_chksum(uint16_t *data, uint16_t len)
Calculate the Internet checksum over a buffer.
#define UIP_RTO
The initial retransmission timeout counted in timer pulses.
void(* init)(void)
Initialize the multicast engine.
uip_lladdr_t uip_lladdr
Host L2 address.
void uip_process(uint8_t flag)
process the options within a hop by hop or destination option header
void uip_unlisten(uint16_t port)
Stop listening to the specified port.