45 #define DEBUG_PRINTF(...)
91 const uip_ipaddr_t uip_hostaddr =
92 { UIP_IPADDR0, UIP_IPADDR1, UIP_IPADDR2, UIP_IPADDR3 };
93 const uip_ipaddr_t uip_draddr =
94 { UIP_DRIPADDR0, UIP_DRIPADDR1, UIP_DRIPADDR2, UIP_DRIPADDR3 };
95 const uip_ipaddr_t uip_netmask =
96 { UIP_NETMASK0, UIP_NETMASK1, UIP_NETMASK2, UIP_NETMASK3 };
98 uip_ipaddr_t uip_hostaddr, uip_draddr, uip_netmask;
101 const uip_ipaddr_t uip_broadcast_addr =
102 #if NETSTACK_CONF_WITH_IPV6
103 { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
104 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } };
106 { { 0xff, 0xff, 0xff, 0xff } };
108 const uip_ipaddr_t uip_all_zeroes_addr = { { 0x0, } };
133 uint16_t uip_urglen, uip_surglen;
158 static uint16_t ipid;
164 static uint8_t iss[4];
167 #if UIP_ACTIVE_OPEN || UIP_UDP
168 static uint16_t lastport;
174 static uint8_t c, opt;
175 static uint16_t tmp16;
186 #define TCP_OPT_END 0
187 #define TCP_OPT_NOOP 1
188 #define TCP_OPT_MSS 2
190 #define TCP_OPT_MSS_LEN 4
192 #define ICMP_ECHO_REPLY 0
195 #define ICMP_DEST_UNREACHABLE 3
196 #define ICMP_PORT_UNREACHABLE 3
198 #define ICMP6_ECHO_REPLY 129
199 #define ICMP6_ECHO 128
200 #define ICMP6_NEIGHBOR_SOLICITATION 135
201 #define ICMP6_NEIGHBOR_ADVERTISEMENT 136
203 #define ICMP6_FLAG_S (1 << 6)
205 #define ICMP6_OPTION_SOURCE_LINK_ADDRESS 1
206 #define ICMP6_OPTION_TARGET_LINK_ADDRESS 2
210 #define BUF ((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])
211 #define FBUF ((struct uip_tcpip_hdr *)&uip_reassbuf[0])
212 #define ICMPBUF ((struct uip_icmpip_hdr *)&uip_buf[UIP_LLH_LEN])
213 #define UDPBUF ((struct uip_udpip_hdr *)&uip_buf[UIP_LLH_LEN])
216 #if UIP_STATISTICS == 1
218 #define UIP_STAT(s) s
226 #define UIP_LOG(m) uip_log(m)
237 uip_acc32[1] = op32[1];
238 uip_acc32[0] = op32[0];
240 if(uip_acc32[2] < (op16 >> 8)) {
242 if(uip_acc32[1] == 0) {
248 if(uip_acc32[3] < (op16 & 0xff)) {
250 if(uip_acc32[2] == 0) {
252 if(uip_acc32[1] == 0) {
261 #if ! UIP_ARCH_CHKSUM
264 chksum(uint16_t sum,
const uint8_t *data, uint16_t len)
267 const uint8_t *dataptr;
268 const uint8_t *last_byte;
271 last_byte = data + len - 1;
273 while(dataptr < last_byte) {
274 t = (dataptr[0] << 8) + dataptr[1];
282 if(dataptr == last_byte) {
283 t = (dataptr[0] << 8) + 0;
297 return uip_htons(chksum(0, (uint8_t *)data, len));
300 #ifndef UIP_ARCH_IPCHKSUM
307 DEBUG_PRINTF(
"uip_ipchksum: sum 0x%04x\n", sum);
308 return (sum == 0) ? 0xffff :
uip_htons(sum);
313 upper_layer_chksum(uint8_t proto)
315 uint16_t upper_layer_len;
318 #if NETSTACK_CONF_WITH_IPV6
319 upper_layer_len = (((uint16_t)(BUF->len[0]) << 8) + BUF->len[1]);
321 upper_layer_len = (((uint16_t)(BUF->len[0]) << 8) + BUF->len[1]) - UIP_IPH_LEN;
327 sum = upper_layer_len + proto;
329 sum = chksum(sum, (uint8_t *)&BUF->srcipaddr, 2 *
sizeof(uip_ipaddr_t));
335 return (sum == 0) ? 0xffff :
uip_htons(sum);
338 #if NETSTACK_CONF_WITH_IPV6
342 return upper_layer_chksum(UIP_PROTO_ICMP6);
350 return upper_layer_chksum(UIP_PROTO_TCP);
353 #if UIP_UDP_CHECKSUMS
357 return upper_layer_chksum(UIP_PROTO_UDP);
366 uip_listenports[c] = 0;
371 #if UIP_ACTIVE_OPEN || UIP_UDP
377 uip_udp_conns[c].
lport = 0;
383 #if UIP_FIXEDADDR == 0
393 register struct uip_conn *conn, *cconn;
399 if(lastport >= 32000) {
406 conn = &uip_conns[c];
415 cconn = &uip_conns[c];
461 struct uip_udp_conn *
464 register struct uip_udp_conn *conn;
470 if(lastport >= 32000) {
483 if(uip_udp_conns[c].
lport == 0) {
484 conn = &uip_udp_conns[c];
495 if(ripaddr ==
NULL) {
496 memset(&conn->
ripaddr, 0,
sizeof(uip_ipaddr_t));
510 if(uip_listenports[c] == port) {
511 uip_listenports[c] = 0;
521 if(uip_listenports[c] == 0) {
522 uip_listenports[c] = port;
530 #if UIP_REASSEMBLY && !NETSTACK_CONF_WITH_IPV6
531 #define UIP_REASS_BUFSIZE (UIP_BUFSIZE - UIP_LLH_LEN)
532 static uint8_t uip_reassbuf[UIP_REASS_BUFSIZE];
533 static uint8_t uip_reassbitmap[UIP_REASS_BUFSIZE / (8 * 8)];
534 static const uint8_t bitmap_bits[8] = {0xff, 0x7f, 0x3f, 0x1f,
535 0x0f, 0x07, 0x03, 0x01};
536 static uint16_t uip_reasslen;
537 static uint8_t uip_reassflags;
538 #define UIP_REASS_FLAG_LASTFRAG 0x01
539 static uint8_t uip_reasstmr;
546 uint16_t offset, len;
552 if(uip_reasstmr == 0) {
553 memcpy(uip_reassbuf, &BUF->vhl, UIP_IPH_LEN);
557 memset(uip_reassbitmap, 0,
sizeof(uip_reassbitmap));
563 if(BUF->srcipaddr[0] == FBUF->srcipaddr[0] &&
564 BUF->srcipaddr[1] == FBUF->srcipaddr[1] &&
565 BUF->destipaddr[0] == FBUF->destipaddr[0] &&
566 BUF->destipaddr[1] == FBUF->destipaddr[1] &&
567 BUF->ipid[0] == FBUF->ipid[0] &&
568 BUF->ipid[1] == FBUF->ipid[1]) {
570 len = (BUF->len[0] << 8) + BUF->len[1] - (BUF->vhl & 0x0f) * 4;
571 offset = (((BUF->ipoffset[0] & 0x3f) << 8) + BUF->ipoffset[1]) * 8;
575 if(offset > UIP_REASS_BUFSIZE ||
576 offset + len > UIP_REASS_BUFSIZE) {
583 memcpy(&uip_reassbuf[UIP_IPH_LEN + offset],
584 (
char *)BUF + (
int)((BUF->vhl & 0x0f) * 4),
588 if(offset / (8 * 8) == (offset + len) / (8 * 8)) {
592 uip_reassbitmap[offset / (8 * 8)] |=
593 bitmap_bits[(offset / 8 ) & 7] &
594 ~bitmap_bits[((offset + len) / 8 ) & 7];
599 uip_reassbitmap[offset / (8 * 8)] |=
600 bitmap_bits[(offset / 8 ) & 7];
601 for(i = 1 + offset / (8 * 8); i < (offset + len) / (8 * 8); ++i) {
602 uip_reassbitmap[i] = 0xff;
604 uip_reassbitmap[(offset + len) / (8 * 8)] |=
605 ~bitmap_bits[((offset + len) / 8 ) & 7];
614 if((BUF->ipoffset[0] & IP_MF) == 0) {
615 uip_reassflags |= UIP_REASS_FLAG_LASTFRAG;
616 uip_reasslen = offset + len;
622 if(uip_reassflags & UIP_REASS_FLAG_LASTFRAG) {
625 for(i = 0; i < uip_reasslen / (8 * 8) - 1; ++i) {
626 if(uip_reassbitmap[i] != 0xff) {
632 if(uip_reassbitmap[uip_reasslen / (8 * 8)] !=
633 (uint8_t)~bitmap_bits[uip_reasslen / 8 & 7]) {
641 memcpy(BUF, FBUF, uip_reasslen);
645 BUF->ipoffset[0] = BUF->ipoffset[1] = 0;
646 BUF->len[0] = uip_reasslen >> 8;
647 BUF->len[1] = uip_reasslen & 0xff;
661 uip_add_rcv_nxt(uint16_t n)
673 register struct uip_conn *uip_connr =
uip_conn;
676 if(flag == UIP_UDP_SEND_CONN) {
685 if(flag == UIP_POLL_REQUEST) {
686 if((uip_connr->
tcpstateflags & UIP_TS_MASK) == UIP_ESTABLISHED &&
687 !uip_outstanding(uip_connr)) {
688 uip_flags = UIP_POLL;
691 #if UIP_ACTIVE_OPEN && UIP_TCP
692 }
else if((uip_connr->
tcpstateflags & UIP_TS_MASK) == UIP_SYN_SENT) {
701 }
else if(flag == UIP_TIMER) {
703 if(uip_reasstmr != 0) {
727 ++(uip_connr->
timer);
736 if(uip_outstanding(uip_connr)) {
737 if(uip_connr->
timer-- == 0) {
747 uip_flags = UIP_TIMEDOUT;
751 BUF->flags = TCP_RST | TCP_ACK;
752 goto tcp_send_nodata;
772 goto tcp_send_synack;
781 case UIP_ESTABLISHED:
786 uip_flags = UIP_REXMIT;
794 goto tcp_send_finack;
798 }
else if((uip_connr->
tcpstateflags & UIP_TS_MASK) == UIP_ESTABLISHED) {
801 uip_flags = UIP_POLL;
810 if(flag == UIP_UDP_TIMER) {
811 if(uip_udp_conn->
lport != 0) {
815 uip_flags = UIP_POLL;
829 #if NETSTACK_CONF_WITH_IPV6
831 if((BUF->vtc & 0xf0) != 0x60) {
834 UIP_LOG(
"ipv6: invalid version.");
839 if(BUF->vhl != 0x45) {
842 UIP_LOG(
"ip: invalid version or header length.");
854 if((BUF->len[0] << 8) + BUF->len[1] <=
uip_len) {
855 uip_len = (BUF->len[0] << 8) + BUF->len[1];
856 #
if NETSTACK_CONF_WITH_IPV6
868 UIP_LOG(
"ip: packet shorter than reported in IP header.");
872 #if !NETSTACK_CONF_WITH_IPV6
874 if((BUF->ipoffset[0] & 0x3f) != 0 ||
875 BUF->ipoffset[1] != 0) {
884 UIP_LOG(
"ip: fragment dropped.");
890 if(uip_ipaddr_cmp(&uip_hostaddr, &uip_all_zeroes_addr)) {
894 #if UIP_PINGADDRCONF && !NETSTACK_CONF_WITH_IPV6
895 if(BUF->proto == UIP_PROTO_ICMP) {
896 UIP_LOG(
"ip: possible ping config packet received.");
899 UIP_LOG(
"ip: packet dropped since no address assigned.");
908 DEBUG_PRINTF(
"UDP IP checksum 0x%04x\n",
uip_ipchksum());
909 if(BUF->proto == UIP_PROTO_UDP &&
910 (uip_ipaddr_cmp(&BUF->destipaddr, &uip_broadcast_addr) ||
911 (BUF->destipaddr.u8[0] & 224) == 224)) {
925 #if !NETSTACK_CONF_WITH_IPV6
926 if(!uip_ipaddr_cmp(&BUF->destipaddr, &uip_hostaddr)) {
936 if(!uip_ipaddr_cmp(&BUF->destipaddr, &uip_hostaddr) &&
937 BUF->destipaddr.u16[0] !=
UIP_HTONS(0xff02)) {
944 #if !NETSTACK_CONF_WITH_IPV6
949 UIP_LOG(
"ip: bad checksum.");
955 if(BUF->proto == UIP_PROTO_TCP) {
963 if(BUF->proto == UIP_PROTO_UDP) {
968 #if !NETSTACK_CONF_WITH_IPV6
970 if(BUF->proto != UIP_PROTO_ICMP) {
974 UIP_LOG(
"ip: neither tcp nor icmp.");
986 if(ICMPBUF->type != ICMP_ECHO) {
989 UIP_LOG(
"icmp: not icmp echo.");
997 if(uip_ipaddr_cmp(&uip_hostaddr, &uip_all_zeroes_addr)) {
998 uip_hostaddr = BUF->destipaddr;
1002 ICMPBUF->type = ICMP_ECHO_REPLY;
1004 if(ICMPBUF->icmpchksum >=
UIP_HTONS(0xffff - (ICMP_ECHO << 8))) {
1005 ICMPBUF->icmpchksum +=
UIP_HTONS(ICMP_ECHO << 8) + 1;
1007 ICMPBUF->icmpchksum +=
UIP_HTONS(ICMP_ECHO << 8);
1022 DEBUG_PRINTF(
"icmp6_input: length %d\n",
uip_len);
1024 if(BUF->proto != UIP_PROTO_ICMP6) {
1028 UIP_LOG(
"ip: neither tcp nor icmp6.");
1036 if(ICMPBUF->type == ICMP6_NEIGHBOR_SOLICITATION) {
1037 if(uip_ipaddr_cmp(&ICMPBUF->icmp6data, &uip_hostaddr)) {
1039 if(ICMPBUF->options[0] == ICMP6_OPTION_SOURCE_LINK_ADDRESS) {
1041 uip_neighbor_add(&ICMPBUF->srcipaddr, &(ICMPBUF->options[2]));
1046 ICMPBUF->type = ICMP6_NEIGHBOR_ADVERTISEMENT;
1047 ICMPBUF->flags = ICMP6_FLAG_S;
1049 ICMPBUF->reserved1 = ICMPBUF->reserved2 = ICMPBUF->reserved3 = 0;
1053 ICMPBUF->options[0] = ICMP6_OPTION_TARGET_LINK_ADDRESS;
1054 ICMPBUF->options[1] = 1;
1055 memcpy(&(ICMPBUF->options[2]), &uip_lladdr,
sizeof(uip_lladdr));
1056 ICMPBUF->icmpchksum = 0;
1063 }
else if(ICMPBUF->type == ICMP6_ECHO) {
1072 ICMPBUF->icmpchksum = 0;
1078 DEBUG_PRINTF(
"Unknown icmp6 message type %d\n", ICMPBUF->type);
1081 UIP_LOG(
"icmp: unknown ICMP message.");
1096 #if UIP_UDP_CHECKSUMS
1102 UIP_LOG(
"udp: bad checksum.");
1110 if(UDPBUF->destport == 0) {
1111 UIP_LOG(
"udp: zero port.");
1116 for(uip_udp_conn = &uip_udp_conns[0];
1126 if(uip_udp_conn->
lport != 0 &&
1127 UDPBUF->destport == uip_udp_conn->
lport &&
1128 (uip_udp_conn->
rport == 0 ||
1129 UDPBUF->srcport == uip_udp_conn->
rport) &&
1130 (uip_ipaddr_cmp(&uip_udp_conn->
ripaddr, &uip_all_zeroes_addr) ||
1131 uip_ipaddr_cmp(&uip_udp_conn->
ripaddr, &uip_broadcast_addr) ||
1132 uip_ipaddr_cmp(&BUF->srcipaddr, &uip_udp_conn->
ripaddr))) {
1136 UIP_LOG(
"udp: no matching connection found");
1138 #if UIP_CONF_ICMP_DEST_UNREACH && !NETSTACK_CONF_WITH_IPV6
1140 memcpy(&(ICMPBUF->payload[0]), ICMPBUF, UIP_IPH_LEN + 8);
1143 ICMPBUF->type = ICMP_DEST_UNREACHABLE;
1144 ICMPBUF->icode = ICMP_PORT_UNREACHABLE;
1147 ICMPBUF->icmpchksum = 0;
1148 ICMPBUF->icmpchksum = ~
uip_chksum((uint16_t *)&(ICMPBUF->type), 36);
1160 ICMPBUF->len[0] = 0;
1161 ICMPBUF->len[1] = (uint8_t)
uip_len;
1163 ICMPBUF->proto = UIP_PROTO_ICMP;
1173 uip_flags = UIP_NEWDATA;
1182 uip_len = uip_slen + UIP_IPUDPH_LEN;
1184 #if NETSTACK_CONF_WITH_IPV6
1187 BUF->len[0] = ((
uip_len - UIP_IPH_LEN) >> 8);
1188 BUF->len[1] = ((
uip_len - UIP_IPH_LEN) & 0xff);
1191 BUF->len[1] = (
uip_len & 0xff);
1194 BUF->ttl = uip_udp_conn->
ttl;
1195 BUF->proto = UIP_PROTO_UDP;
1197 UDPBUF->udplen =
UIP_HTONS(uip_slen + UIP_UDPH_LEN);
1198 UDPBUF->udpchksum = 0;
1200 BUF->srcport = uip_udp_conn->
lport;
1201 BUF->destport = uip_udp_conn->
rport;
1208 #if UIP_UDP_CHECKSUMS
1211 if(UDPBUF->udpchksum == 0) {
1212 UDPBUF->udpchksum = 0xffff;
1231 UIP_LOG(
"tcp: bad checksum.");
1236 if(BUF->destport == 0 || BUF->srcport == 0) {
1237 UIP_LOG(
"tcp: zero port.");
1243 for(uip_connr = &uip_conns[0]; uip_connr <= &uip_conns[UIP_CONNS - 1];
1246 BUF->destport == uip_connr->
lport &&
1247 BUF->srcport == uip_connr->
rport &&
1248 uip_ipaddr_cmp(&BUF->srcipaddr, &uip_connr->
ripaddr)) {
1257 if((BUF->flags & TCP_CTL) != TCP_SYN) {
1261 tmp16 = BUF->destport;
1264 if(tmp16 == uip_listenports[c]) {
1274 if(BUF->flags & TCP_RST) {
1280 BUF->flags = TCP_RST | TCP_ACK;
1282 BUF->tcpoffset = 5 << 4;
1286 BUF->seqno[3] = BUF->ackno[3];
1290 BUF->seqno[2] = BUF->ackno[2];
1294 BUF->seqno[1] = BUF->ackno[1];
1298 BUF->seqno[0] = BUF->ackno[0];
1304 if(++BUF->ackno[3] == 0) {
1305 if(++BUF->ackno[2] == 0) {
1306 if(++BUF->ackno[1] == 0) {
1313 tmp16 = BUF->srcport;
1314 BUF->srcport = BUF->destport;
1315 BUF->destport = tmp16;
1322 goto tcp_send_noconn;
1337 uip_connr = &uip_conns[c];
1341 if(uip_connr == 0 ||
1343 uip_connr = &uip_conns[c];
1348 if(uip_connr == 0) {
1353 UIP_LOG(
"tcp: found no unused connections.");
1356 uip_conn = uip_connr;
1362 uip_connr->
nrtx = 0;
1363 uip_connr->
lport = BUF->destport;
1364 uip_connr->
rport = BUF->srcport;
1368 uip_connr->
snd_nxt[0] = iss[0];
1369 uip_connr->
snd_nxt[1] = iss[1];
1370 uip_connr->
snd_nxt[2] = iss[2];
1371 uip_connr->
snd_nxt[3] = iss[3];
1375 uip_connr->
rcv_nxt[0] = BUF->seqno[0];
1376 uip_connr->
rcv_nxt[1] = BUF->seqno[1];
1377 uip_connr->
rcv_nxt[2] = BUF->seqno[2];
1378 uip_connr->
rcv_nxt[3] = BUF->seqno[3];
1382 if((BUF->tcpoffset & 0xf0) > 0x50) {
1383 for(c = 0; c < ((BUF->tcpoffset >> 4) - 5) << 2 ;) {
1385 if(opt == TCP_OPT_END) {
1388 }
else if(opt == TCP_OPT_NOOP) {
1391 }
else if(opt == TCP_OPT_MSS &&
1417 BUF->flags = TCP_ACK;
1420 BUF->flags |= TCP_SYN;
1423 BUF->flags = TCP_SYN | TCP_ACK;
1428 BUF->optdata[0] = TCP_OPT_MSS;
1429 BUF->optdata[1] = TCP_OPT_MSS_LEN;
1432 uip_len = UIP_IPTCPH_LEN + TCP_OPT_MSS_LEN;
1433 BUF->tcpoffset = ((UIP_TCPH_LEN + TCP_OPT_MSS_LEN) / 4) << 4;
1438 uip_conn = uip_connr;
1444 if(BUF->flags & TCP_RST) {
1446 UIP_LOG(
"tcp: got reset, aborting connection.");
1447 uip_flags = UIP_ABORT;
1453 c = (BUF->tcpoffset >> 4) << 2;
1464 if(!((((uip_connr->
tcpstateflags & UIP_TS_MASK) == UIP_SYN_SENT) &&
1465 ((BUF->flags & TCP_CTL) == (TCP_SYN | TCP_ACK))) ||
1466 (((uip_connr->
tcpstateflags & UIP_TS_MASK) == UIP_SYN_RCVD) &&
1467 ((BUF->flags & TCP_CTL) == TCP_SYN)))) {
1468 if((
uip_len > 0 || ((BUF->flags & (TCP_SYN | TCP_FIN)) != 0)) &&
1469 (BUF->seqno[0] != uip_connr->
rcv_nxt[0] ||
1470 BUF->seqno[1] != uip_connr->
rcv_nxt[1] ||
1471 BUF->seqno[2] != uip_connr->
rcv_nxt[2] ||
1472 BUF->seqno[3] != uip_connr->
rcv_nxt[3])) {
1481 if((BUF->flags & TCP_ACK) && uip_outstanding(uip_connr)) {
1495 if(uip_connr->
nrtx == 0) {
1497 m = uip_connr->
rto - uip_connr->
timer;
1499 m = m - (uip_connr->
sa >> 3);
1504 m = m - (uip_connr->
sv >> 2);
1506 uip_connr->
rto = (uip_connr->
sa >> 3) + uip_connr->
sv;
1510 uip_flags = UIP_ACKDATA;
1531 if(uip_flags & UIP_ACKDATA) {
1533 uip_flags = UIP_CONNECTED;
1536 uip_flags |= UIP_NEWDATA;
1544 if((BUF->flags & TCP_CTL) == TCP_SYN) {
1545 goto tcp_send_synack;
1554 if((uip_flags & UIP_ACKDATA) &&
1555 (BUF->flags & TCP_CTL) == (TCP_SYN | TCP_ACK)) {
1558 if((BUF->tcpoffset & 0xf0) > 0x50) {
1559 for(c = 0; c < ((BUF->tcpoffset >> 4) - 5) << 2 ;) {
1561 if(opt == TCP_OPT_END) {
1564 }
else if(opt == TCP_OPT_NOOP) {
1567 }
else if(opt == TCP_OPT_MSS &&
1590 uip_connr->
rcv_nxt[0] = BUF->seqno[0];
1591 uip_connr->
rcv_nxt[1] = BUF->seqno[1];
1592 uip_connr->
rcv_nxt[2] = BUF->seqno[2];
1593 uip_connr->
rcv_nxt[3] = BUF->seqno[3];
1595 uip_flags = UIP_CONNECTED | UIP_NEWDATA;
1603 uip_flags = UIP_ABORT;
1610 case UIP_ESTABLISHED:
1622 if(BUF->flags & TCP_FIN && !(uip_connr->
tcpstateflags & UIP_STOPPED)) {
1623 if(uip_outstanding(uip_connr)) {
1627 uip_flags |= UIP_CLOSE;
1629 uip_flags |= UIP_NEWDATA;
1634 uip_connr->
nrtx = 0;
1636 BUF->flags = TCP_FIN | TCP_ACK;
1637 goto tcp_send_nodata;
1642 if((BUF->flags & TCP_URG) != 0) {
1644 uip_urglen = (BUF->urgp[0] << 8) | BUF->urgp[1];
1649 uip_add_rcv_nxt(uip_urglen);
1657 uip_len -= (BUF->urgp[0] << 8) | BUF->urgp[1];
1667 uip_flags |= UIP_NEWDATA;
1683 tmp16 = ((uint16_t)BUF->wnd[0] << 8) + (uint16_t)BUF->wnd[1];
1688 uip_connr->
mss = tmp16;
1706 if(uip_flags & (UIP_NEWDATA | UIP_ACKDATA)) {
1712 if(uip_flags & UIP_ABORT) {
1715 BUF->flags = TCP_RST | TCP_ACK;
1716 goto tcp_send_nodata;
1719 if(uip_flags & UIP_CLOSE) {
1723 uip_connr->
nrtx = 0;
1724 BUF->flags = TCP_FIN | TCP_ACK;
1725 goto tcp_send_nodata;
1733 if((uip_flags & UIP_ACKDATA) != 0) {
1740 if(uip_connr->
len == 0) {
1745 if(uip_slen > uip_connr->
mss) {
1746 uip_slen = uip_connr->
mss;
1751 uip_connr->
len = uip_slen;
1757 uip_slen = uip_connr->
len;
1760 uip_connr->
nrtx = 0;
1766 if(uip_slen > 0 && uip_connr->
len > 0) {
1770 BUF->flags = TCP_ACK | TCP_PSH;
1772 goto tcp_send_noopts;
1776 if(uip_flags & UIP_NEWDATA) {
1778 BUF->flags = TCP_ACK;
1779 goto tcp_send_noopts;
1786 if(uip_flags & UIP_ACKDATA) {
1788 uip_flags = UIP_CLOSE;
1793 case UIP_FIN_WAIT_1:
1800 if(BUF->flags & TCP_FIN) {
1801 if(uip_flags & UIP_ACKDATA) {
1803 uip_connr->
timer = 0;
1809 uip_flags = UIP_CLOSE;
1812 }
else if(uip_flags & UIP_ACKDATA) {
1822 case UIP_FIN_WAIT_2:
1826 if(BUF->flags & TCP_FIN) {
1828 uip_connr->
timer = 0;
1830 uip_flags = UIP_CLOSE;
1843 if(uip_flags & UIP_ACKDATA) {
1845 uip_connr->
timer = 0;
1853 BUF->flags = TCP_ACK;
1859 BUF->tcpoffset = (UIP_TCPH_LEN / 4) << 4;
1866 BUF->ackno[0] = uip_connr->
rcv_nxt[0];
1867 BUF->ackno[1] = uip_connr->
rcv_nxt[1];
1868 BUF->ackno[2] = uip_connr->
rcv_nxt[2];
1869 BUF->ackno[3] = uip_connr->
rcv_nxt[3];
1871 BUF->seqno[0] = uip_connr->
snd_nxt[0];
1872 BUF->seqno[1] = uip_connr->
snd_nxt[1];
1873 BUF->seqno[2] = uip_connr->
snd_nxt[2];
1874 BUF->seqno[3] = uip_connr->
snd_nxt[3];
1876 BUF->srcport = uip_connr->
lport;
1877 BUF->destport = uip_connr->
rport;
1885 BUF->wnd[0] = BUF->wnd[1] = 0;
1892 BUF->proto = UIP_PROTO_TCP;
1895 #if NETSTACK_CONF_WITH_IPV6
1898 BUF->len[0] = ((
uip_len - UIP_IPH_LEN) >> 8);
1899 BUF->len[1] = ((
uip_len - UIP_IPH_LEN) & 0xff);
1902 BUF->len[1] = (
uip_len & 0xff);
1905 BUF->urgp[0] = BUF->urgp[1] = 0;
1913 #if NETSTACK_CONF_WITH_IPV6
1920 BUF->ipoffset[0] = BUF->ipoffset[1] = 0;
1922 BUF->ipid[0] = ipid >> 8;
1923 BUF->ipid[1] = ipid & 0xff;
1927 DEBUG_PRINTF(
"uip ip_send_nolen: chkecum 0x%04x\n",
uip_ipchksum());
1930 #if NETSTACK_CONF_WITH_IPV6
1933 DEBUG_PRINTF(
"Sending packet with length %d (%d)\n",
uip_len,
1934 (BUF->len[0] << 8) | BUF->len[1]);
1954 uip_htonl(uint32_t val)
1956 return UIP_HTONL(val);
1967 if(data != uip_sappdata) {
1968 memcpy(uip_sappdata, (data), uip_slen);
void uip_log(char *msg)
Print out a uIP log message.
uint16_t uip_ipchksum(void)
Calculate the IP header checksum of the packet header in uip_buf.
#define ICMP6_ECHO_REPLY
Echo reply.
struct uip_conn * uip_conn
Pointer to the current TCP connection.
#define UIP_REASS_MAXAGE
The maximum time an IP fragment should wait in the reassembly buffer before it is dropped...
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.
void * uip_appdata
Pointer to the application data in the packet buffer.
uint8_t tcpstateflags
TCP state and flags.
The structure holding the TCP/IP statistics that are gathered if UIP_STATISTICS is set to 1...
uip_ipaddr_t ripaddr
The IP address of the remote peer.
Representation of a uIP TCP connection.
struct uip_udp_conn * uip_udp_conn
The current UDP connection.
Configuration options for uIP.
#define UIP_TTL
The IP TTL (time to live) of IP packets sent by uIP.
void uip_listen(uint16_t port)
Start listening to the specified port.
#define UIP_CONNS
The maximum number of simultaneously open TCP connections.
uint8_t uip_acc32[4]
4-byte array used for the 32-bit sequence number calculations.
#define UIP_HTONS(n)
Convert 16-bit quantity from host byte order to network byte order.
void uip_setipid(uint16_t id)
uIP initialization function.
uint16_t uip_chksum(uint16_t *data, uint16_t len)
Calculate the Internet checksum over a buffer.
Default definitions of C compiler quirk work-arounds.
Representation of a uIP UDP 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.
#define uip_buf
Macro to access uip_aligned_buf as an array of bytes.
void uip_add32(uint8_t *op32, uint16_t op16)
Carry out a 32-bit addition.
#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.
Declarations of architecture specific functions.
uint8_t snd_nxt[4]
The sequence number that was last sent by us.
uint16_t uip_htons(uint16_t val)
Convert a 16-bit quantity from host byte order to network byte order.
uip_ipaddr_t ripaddr
The IP address of the remote host.
uint16_t uip_len
The length of the packet in the uip_buf buffer.
#define UIP_STAT(s)
The uIP TCP/IP statistics.
uint8_t ttl
Default time-to-live.
#define UIP_MAXSYNRTX
The maximum number of times a SYN segment should be retransmitted before a connection request should ...
struct uip_udp_conn * uip_udp_new(const uip_ipaddr_t *ripaddr, uint16_t rport)
Set up a new UDP connection.
#define NULL
The null pointer.
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.
uint16_t uip_tcpchksum(void)
Calculate the TCP checksum of the packet in uip_buf and uip_appdata.
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_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_RECEIVE_WINDOW
The size of the advertised receiver's window.
struct uip_conn * uip_connect(const uip_ipaddr_t *ripaddr, uint16_t port)
Connect to a remote host using TCP.
uint16_t uip_udpchksum(void)
Calculate the UDP checksum of the packet in uip_buf and uip_appdata.
void uip_unlisten(uint16_t port)
Stop listening to the specified port.
uint16_t len
Length of the data that was previously sent.
void uip_send(const void *data, int len)
Send data on the current connection.
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.
CCIF uip_lladdr_t uip_lladdr
Host L2 address.
#define UIP_TCP_MSS
The TCP maximum segment size.
uint16_t mss
Current maximum segment size for the connection.
#define UIP_LISTENPORTS
The maximum number of simultaneously listening TCP ports.
Header file for database of link-local neighbors, used by IPv6 code and to be used by future ...
#define UIP_BUFSIZE
The size of the uIP packet buffer.
CCIF uip_buf_t uip_aligned_buf
Packet buffer for incoming and outgoing packets.
Macros and definitions for the ARP module.
void uip_init(void)
uIP initialization function.
#define UIP_RTO
The initial retransmission timeout counted in timer pulses.
void uip_process(uint8_t flag)
process the options within a hop by hop or destination option header