1 #define DEBUG_PRINTF(...)
100 { UIP_IPADDR0, UIP_IPADDR1, UIP_IPADDR2, UIP_IPADDR3 };
102 { UIP_DRIPADDR0, UIP_DRIPADDR1, UIP_DRIPADDR2, UIP_DRIPADDR3 };
104 { UIP_NETMASK0, UIP_NETMASK1, UIP_NETMASK2, UIP_NETMASK3 };
111 { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
112 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } };
114 { { 0xff, 0xff, 0xff, 0xff } };
141 u16_t uip_urglen, uip_surglen;
175 #if UIP_ACTIVE_OPEN || UIP_UDP
176 static u16_t lastport;
194 #define TCP_OPT_END 0
195 #define TCP_OPT_NOOP 1
196 #define TCP_OPT_MSS 2
198 #define TCP_OPT_MSS_LEN 4
200 #define ICMP_ECHO_REPLY 0
203 #define ICMP_DEST_UNREACHABLE 3
204 #define ICMP_PORT_UNREACHABLE 3
206 #define ICMP6_ECHO_REPLY 129
207 #define ICMP6_ECHO 128
208 #define ICMP6_NEIGHBOR_SOLICITATION 135
209 #define ICMP6_NEIGHBOR_ADVERTISEMENT 136
211 #define ICMP6_FLAG_S (1 << 6)
213 #define ICMP6_OPTION_SOURCE_LINK_ADDRESS 1
214 #define ICMP6_OPTION_TARGET_LINK_ADDRESS 2
218 #define BUF ((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])
219 #define FBUF ((struct uip_tcpip_hdr *)&uip_reassbuf[0])
220 #define ICMPBUF ((struct uip_icmpip_hdr *)&uip_buf[UIP_LLH_LEN])
221 #define UDPBUF ((struct uip_udpip_hdr *)&uip_buf[UIP_LLH_LEN])
224 #if UIP_STATISTICS == 1
226 #define UIP_STAT(s) s
234 #define UIP_LOG(m) uip_log(m)
245 uip_acc32[1] = op32[1];
246 uip_acc32[0] = op32[0];
248 if(uip_acc32[2] < (op16 >> 8)) {
250 if(uip_acc32[1] == 0) {
256 if(uip_acc32[3] < (op16 & 0xff)) {
258 if(uip_acc32[2] == 0) {
260 if(uip_acc32[1] == 0) {
269 #if ! UIP_ARCH_CHKSUM
272 chksum(u16_t sum,
const u8_t *data, u16_t len)
276 const u8_t *last_byte;
279 last_byte = data + len - 1;
281 while(dataptr < last_byte) {
282 t = (dataptr[0] << 8) + dataptr[1];
290 if(dataptr == last_byte) {
291 t = (dataptr[0] << 8) + 0;
305 return uip_htons(chksum(0, (u8_t *)data, len));
308 #ifndef UIP_ARCH_IPCHKSUM
314 sum = chksum(0, &uip_buf[
UIP_LLH_LEN], UIP_IPH_LEN);
315 DEBUG_PRINTF(
"uip_ipchksum: sum 0x%04x\n", sum);
316 return (sum == 0) ? 0xffff :
uip_htons(sum);
321 upper_layer_chksum(u8_t proto)
323 u16_t upper_layer_len;
327 upper_layer_len = (((
u16_t)(BUF->len[0]) << 8) + BUF->len[1]);
329 upper_layer_len = (((
u16_t)(BUF->len[0]) << 8) + BUF->len[1]) - UIP_IPH_LEN;
335 sum = upper_layer_len + proto;
337 sum = chksum(sum, (u8_t *)&BUF->srcipaddr, 2 *
sizeof(
uip_ipaddr_t));
340 sum = chksum(sum, &uip_buf[UIP_IPH_LEN +
UIP_LLH_LEN],
343 return (sum == 0) ? 0xffff :
uip_htons(sum);
350 return upper_layer_chksum(UIP_PROTO_ICMP6);
358 return upper_layer_chksum(UIP_PROTO_TCP);
361 #if UIP_UDP_CHECKSUMS
365 return upper_layer_chksum(UIP_PROTO_UDP);
374 uip_listenports[c] = 0;
379 #if UIP_ACTIVE_OPEN || UIP_UDP
385 uip_udp_conns[c].
lport = 0;
391 #if UIP_FIXEDADDR == 0
401 register struct uip_conn *conn, *cconn;
407 if(lastport >= 32000) {
414 conn = &uip_conns[c];
423 cconn = &uip_conns[c];
464 struct uip_udp_conn *
467 register struct uip_udp_conn *conn;
473 if(lastport >= 32000) {
486 if(uip_udp_conns[c].
lport == 0) {
487 conn = &uip_udp_conns[c];
498 if(ripaddr ==
NULL) {
513 if(uip_listenports[c] == port) {
514 uip_listenports[c] = 0;
524 if(uip_listenports[c] == 0) {
525 uip_listenports[c] = port;
533 #if UIP_REASSEMBLY && !UIP_CONF_IPV6
534 #define UIP_REASS_BUFSIZE (UIP_BUFSIZE - UIP_LLH_LEN)
535 static u8_t uip_reassbuf[UIP_REASS_BUFSIZE];
536 static u8_t uip_reassbitmap[UIP_REASS_BUFSIZE / (8 * 8)];
537 static const u8_t bitmap_bits[8] = {0xff, 0x7f, 0x3f, 0x1f,
538 0x0f, 0x07, 0x03, 0x01};
539 static u16_t uip_reasslen;
540 static u8_t uip_reassflags;
541 #define UIP_REASS_FLAG_LASTFRAG 0x01
542 static u8_t uip_reasstmr;
555 if(uip_reasstmr == 0) {
556 memcpy(uip_reassbuf, &BUF->vhl, UIP_IPH_LEN);
560 memset(uip_reassbitmap, 0,
sizeof(uip_reassbitmap));
566 if(BUF->srcipaddr[0] == FBUF->srcipaddr[0] &&
567 BUF->srcipaddr[1] == FBUF->srcipaddr[1] &&
568 BUF->destipaddr[0] == FBUF->destipaddr[0] &&
569 BUF->destipaddr[1] == FBUF->destipaddr[1] &&
570 BUF->ipid[0] == FBUF->ipid[0] &&
571 BUF->ipid[1] == FBUF->ipid[1]) {
573 len = (BUF->len[0] << 8) + BUF->len[1] - (BUF->vhl & 0x0f) * 4;
574 offset = (((BUF->ipoffset[0] & 0x3f) << 8) + BUF->ipoffset[1]) * 8;
578 if(offset > UIP_REASS_BUFSIZE ||
579 offset + len > UIP_REASS_BUFSIZE) {
586 memcpy(&uip_reassbuf[UIP_IPH_LEN + offset],
587 (
char *)BUF + (
int)((BUF->vhl & 0x0f) * 4),
591 if(offset / (8 * 8) == (offset + len) / (8 * 8)) {
595 uip_reassbitmap[offset / (8 * 8)] |=
596 bitmap_bits[(offset / 8 ) & 7] &
597 ~bitmap_bits[((offset + len) / 8 ) & 7];
602 uip_reassbitmap[offset / (8 * 8)] |=
603 bitmap_bits[(offset / 8 ) & 7];
604 for(i = 1 + offset / (8 * 8); i < (offset + len) / (8 * 8); ++i) {
605 uip_reassbitmap[i] = 0xff;
607 uip_reassbitmap[(offset + len) / (8 * 8)] |=
608 ~bitmap_bits[((offset + len) / 8 ) & 7];
617 if((BUF->ipoffset[0] & IP_MF) == 0) {
618 uip_reassflags |= UIP_REASS_FLAG_LASTFRAG;
619 uip_reasslen = offset + len;
625 if(uip_reassflags & UIP_REASS_FLAG_LASTFRAG) {
628 for(i = 0; i < uip_reasslen / (8 * 8) - 1; ++i) {
629 if(uip_reassbitmap[i] != 0xff) {
635 if(uip_reassbitmap[uip_reasslen / (8 * 8)] !=
636 (
u8_t)~bitmap_bits[uip_reasslen / 8 & 7]) {
644 memcpy(BUF, FBUF, uip_reasslen);
648 BUF->ipoffset[0] = BUF->ipoffset[1] = 0;
649 BUF->len[0] = uip_reasslen >> 8;
650 BUF->len[1] = uip_reasslen & 0xff;
664 uip_add_rcv_nxt(u16_t n)
676 register struct uip_conn *uip_connr =
uip_conn;
679 if(flag == UIP_UDP_SEND_CONN) {
688 if(flag == UIP_POLL_REQUEST) {
689 if((uip_connr->
tcpstateflags & UIP_TS_MASK) == UIP_ESTABLISHED &&
690 !uip_outstanding(uip_connr)) {
691 uip_flags = UIP_POLL;
695 }
else if((uip_connr->
tcpstateflags & UIP_TS_MASK) == UIP_SYN_SENT) {
704 }
else if(flag == UIP_TIMER) {
706 if(uip_reasstmr != 0) {
729 ++(uip_connr->
timer);
738 if(uip_outstanding(uip_connr)) {
739 if(uip_connr->
timer-- == 0) {
749 uip_flags = UIP_TIMEDOUT;
753 BUF->flags = TCP_RST | TCP_ACK;
754 goto tcp_send_nodata;
774 goto tcp_send_synack;
783 case UIP_ESTABLISHED:
788 uip_flags = UIP_REXMIT;
796 goto tcp_send_finack;
800 }
else if((uip_connr->
tcpstateflags & UIP_TS_MASK) == UIP_ESTABLISHED) {
803 uip_flags = UIP_POLL;
811 if(flag == UIP_UDP_TIMER) {
812 if(uip_udp_conn->
lport != 0) {
816 uip_flags = UIP_POLL;
832 if((BUF->vtc & 0xf0) != 0x60) {
835 UIP_LOG(
"ipv6: invalid version.");
840 if(BUF->vhl != 0x45) {
843 UIP_LOG(
"ip: invalid version or header length.");
855 if((BUF->len[0] << 8) + BUF->len[1] <=
uip_len) {
856 uip_len = (BUF->len[0] << 8) + BUF->len[1];
869 UIP_LOG(
"ip: packet shorter than reported in IP header.");
875 if((BUF->ipoffset[0] & 0x3f) != 0 ||
876 BUF->ipoffset[1] != 0) {
885 UIP_LOG(
"ip: fragment dropped.");
895 #if UIP_PINGADDRCONF && !UIP_CONF_IPV6
896 if(BUF->proto == UIP_PROTO_ICMP) {
897 UIP_LOG(
"ip: possible ping config packet received.");
900 UIP_LOG(
"ip: packet dropped since no address assigned.");
909 DEBUG_PRINTF(
"UDP IP checksum 0x%04x\n",
uip_ipchksum());
910 if(BUF->proto == UIP_PROTO_UDP &&
912 (BUF->destipaddr.u8[0] & 224) == 224)) {
938 BUF->destipaddr.u16[0] !=
UIP_HTONS(0xff02)) {
950 UIP_LOG(
"ip: bad checksum.");
955 if(BUF->proto == UIP_PROTO_TCP) {
962 if(BUF->proto == UIP_PROTO_UDP) {
969 if(BUF->proto != UIP_PROTO_ICMP) {
973 UIP_LOG(
"ip: neither tcp nor icmp.");
985 if(ICMPBUF->type != ICMP_ECHO) {
988 UIP_LOG(
"icmp: not icmp echo.");
997 uip_hostaddr = BUF->destipaddr;
1001 ICMPBUF->type = ICMP_ECHO_REPLY;
1003 if(ICMPBUF->icmpchksum >=
UIP_HTONS(0xffff - (ICMP_ECHO << 8))) {
1004 ICMPBUF->icmpchksum +=
UIP_HTONS(ICMP_ECHO << 8) + 1;
1006 ICMPBUF->icmpchksum +=
UIP_HTONS(ICMP_ECHO << 8);
1021 DEBUG_PRINTF(
"icmp6_input: length %d\n",
uip_len);
1023 if(BUF->proto != UIP_PROTO_ICMP6) {
1027 UIP_LOG(
"ip: neither tcp nor icmp6.");
1035 if(ICMPBUF->type == ICMP6_NEIGHBOR_SOLICITATION) {
1038 if(ICMPBUF->options[0] == ICMP6_OPTION_SOURCE_LINK_ADDRESS) {
1040 uip_neighbor_add(&ICMPBUF->srcipaddr, &(ICMPBUF->options[2]));
1045 ICMPBUF->type = ICMP6_NEIGHBOR_ADVERTISEMENT;
1046 ICMPBUF->flags = ICMP6_FLAG_S;
1048 ICMPBUF->reserved1 = ICMPBUF->reserved2 = ICMPBUF->reserved3 = 0;
1052 ICMPBUF->options[0] = ICMP6_OPTION_TARGET_LINK_ADDRESS;
1053 ICMPBUF->options[1] = 1;
1054 memcpy(&(ICMPBUF->options[2]), &uip_ethaddr,
sizeof(uip_ethaddr));
1055 ICMPBUF->icmpchksum = 0;
1062 }
else if(ICMPBUF->type == ICMP6_ECHO) {
1071 ICMPBUF->icmpchksum = 0;
1077 DEBUG_PRINTF(
"Unknown icmp6 message type %d\n", ICMPBUF->type);
1080 UIP_LOG(
"icmp: unknown ICMP message.");
1095 #if UIP_UDP_CHECKSUMS
1101 UIP_LOG(
"udp: bad checksum.");
1109 if(UDPBUF->destport == 0) {
1110 UIP_LOG(
"udp: zero port.");
1115 for(uip_udp_conn = &uip_udp_conns[0];
1125 if(uip_udp_conn->
lport != 0 &&
1126 UDPBUF->destport == uip_udp_conn->
lport &&
1127 (uip_udp_conn->
rport == 0 ||
1128 UDPBUF->srcport == uip_udp_conn->
rport) &&
1135 UIP_LOG(
"udp: no matching connection found");
1136 #if UIP_CONF_ICMP_DEST_UNREACH && !UIP_CONF_IPV6
1138 memcpy(&(ICMPBUF->payload[0]), ICMPBUF, UIP_IPH_LEN + 8);
1141 ICMPBUF->type = ICMP_DEST_UNREACHABLE;
1142 ICMPBUF->icode = ICMP_PORT_UNREACHABLE;
1145 ICMPBUF->icmpchksum = 0;
1146 ICMPBUF->icmpchksum = ~
uip_chksum((u16_t *)&(ICMPBUF->type), 36);
1158 ICMPBUF->len[0] = 0;
1161 ICMPBUF->proto = UIP_PROTO_ICMP;
1170 uip_flags = UIP_NEWDATA;
1179 uip_len = uip_slen + UIP_IPUDPH_LEN;
1184 BUF->len[0] = ((
uip_len - UIP_IPH_LEN) >> 8);
1185 BUF->len[1] = ((
uip_len - UIP_IPH_LEN) & 0xff);
1188 BUF->len[1] = (
uip_len & 0xff);
1191 BUF->ttl = uip_udp_conn->
ttl;
1192 BUF->proto = UIP_PROTO_UDP;
1194 UDPBUF->udplen =
UIP_HTONS(uip_slen + UIP_UDPH_LEN);
1195 UDPBUF->udpchksum = 0;
1197 BUF->srcport = uip_udp_conn->
lport;
1198 BUF->destport = uip_udp_conn->
rport;
1205 #if UIP_UDP_CHECKSUMS
1208 if(UDPBUF->udpchksum == 0) {
1209 UDPBUF->udpchksum = 0xffff;
1226 UIP_LOG(
"tcp: bad checksum.");
1231 if(BUF->destport == 0 || BUF->srcport == 0) {
1232 UIP_LOG(
"tcp: zero port.");
1238 for(uip_connr = &uip_conns[0]; uip_connr <= &uip_conns[UIP_CONNS - 1];
1241 BUF->destport == uip_connr->
lport &&
1242 BUF->srcport == uip_connr->
rport &&
1252 if((BUF->flags & TCP_CTL) != TCP_SYN) {
1256 tmp16 = BUF->destport;
1259 if(tmp16 == uip_listenports[c]) {
1269 if(BUF->flags & TCP_RST) {
1275 BUF->flags = TCP_RST | TCP_ACK;
1277 BUF->tcpoffset = 5 << 4;
1281 BUF->seqno[3] = BUF->ackno[3];
1285 BUF->seqno[2] = BUF->ackno[2];
1289 BUF->seqno[1] = BUF->ackno[1];
1293 BUF->seqno[0] = BUF->ackno[0];
1299 if(++BUF->ackno[3] == 0) {
1300 if(++BUF->ackno[2] == 0) {
1301 if(++BUF->ackno[1] == 0) {
1308 tmp16 = BUF->srcport;
1309 BUF->srcport = BUF->destport;
1310 BUF->destport = tmp16;
1317 goto tcp_send_noconn;
1332 uip_connr = &uip_conns[c];
1336 if(uip_connr == 0 ||
1338 uip_connr = &uip_conns[c];
1343 if(uip_connr == 0) {
1348 UIP_LOG(
"tcp: found no unused connections.");
1351 uip_conn = uip_connr;
1357 uip_connr->
nrtx = 0;
1358 uip_connr->
lport = BUF->destport;
1359 uip_connr->
rport = BUF->srcport;
1363 uip_connr->
snd_nxt[0] = iss[0];
1364 uip_connr->
snd_nxt[1] = iss[1];
1365 uip_connr->
snd_nxt[2] = iss[2];
1366 uip_connr->
snd_nxt[3] = iss[3];
1370 uip_connr->
rcv_nxt[3] = BUF->seqno[3];
1371 uip_connr->
rcv_nxt[2] = BUF->seqno[2];
1372 uip_connr->
rcv_nxt[1] = BUF->seqno[1];
1373 uip_connr->
rcv_nxt[0] = BUF->seqno[0];
1377 if((BUF->tcpoffset & 0xf0) > 0x50) {
1378 for(c = 0; c < ((BUF->tcpoffset >> 4) - 5) << 2 ;) {
1380 if(opt == TCP_OPT_END) {
1383 }
else if(opt == TCP_OPT_NOOP) {
1386 }
else if(opt == TCP_OPT_MSS &&
1387 uip_buf[UIP_TCPIP_HLEN +
UIP_LLH_LEN + 1 + c] == TCP_OPT_MSS_LEN) {
1399 if(uip_buf[UIP_TCPIP_HLEN +
UIP_LLH_LEN + 1 + c] == 0) {
1404 c += uip_buf[UIP_TCPIP_HLEN +
UIP_LLH_LEN + 1 + c];
1412 BUF->flags = TCP_ACK;
1415 BUF->flags |= TCP_SYN;
1418 BUF->flags = TCP_SYN | TCP_ACK;
1423 BUF->optdata[0] = TCP_OPT_MSS;
1424 BUF->optdata[1] = TCP_OPT_MSS_LEN;
1427 uip_len = UIP_IPTCPH_LEN + TCP_OPT_MSS_LEN;
1428 BUF->tcpoffset = ((UIP_TCPH_LEN + TCP_OPT_MSS_LEN) / 4) << 4;
1433 uip_conn = uip_connr;
1439 if(BUF->flags & TCP_RST) {
1441 UIP_LOG(
"tcp: got reset, aborting connection.");
1442 uip_flags = UIP_ABORT;
1448 c = (BUF->tcpoffset >> 4) << 2;
1459 if(!((((uip_connr->
tcpstateflags & UIP_TS_MASK) == UIP_SYN_SENT) &&
1460 ((BUF->flags & TCP_CTL) == (TCP_SYN | TCP_ACK))) ||
1461 (((uip_connr->
tcpstateflags & UIP_TS_MASK) == UIP_SYN_RCVD) &&
1462 ((BUF->flags & TCP_CTL) == TCP_SYN)))) {
1463 if((
uip_len > 0 || ((BUF->flags & (TCP_SYN | TCP_FIN)) != 0)) &&
1464 (BUF->seqno[0] != uip_connr->
rcv_nxt[0] ||
1465 BUF->seqno[1] != uip_connr->
rcv_nxt[1] ||
1466 BUF->seqno[2] != uip_connr->
rcv_nxt[2] ||
1467 BUF->seqno[3] != uip_connr->
rcv_nxt[3])) {
1476 if((BUF->flags & TCP_ACK) && uip_outstanding(uip_connr)) {
1490 if(uip_connr->
nrtx == 0) {
1492 m = uip_connr->
rto - uip_connr->
timer;
1494 m = m - (uip_connr->
sa >> 3);
1499 m = m - (uip_connr->
sv >> 2);
1501 uip_connr->
rto = (uip_connr->
sa >> 3) + uip_connr->
sv;
1505 uip_flags = UIP_ACKDATA;
1526 if(uip_flags & UIP_ACKDATA) {
1528 uip_flags = UIP_CONNECTED;
1531 uip_flags |= UIP_NEWDATA;
1539 if((BUF->flags & TCP_CTL) == TCP_SYN) {
1540 goto tcp_send_synack;
1549 if((uip_flags & UIP_ACKDATA) &&
1550 (BUF->flags & TCP_CTL) == (TCP_SYN | TCP_ACK)) {
1553 if((BUF->tcpoffset & 0xf0) > 0x50) {
1554 for(c = 0; c < ((BUF->tcpoffset >> 4) - 5) << 2 ;) {
1556 if(opt == TCP_OPT_END) {
1559 }
else if(opt == TCP_OPT_NOOP) {
1562 }
else if(opt == TCP_OPT_MSS &&
1563 uip_buf[UIP_TCPIP_HLEN +
UIP_LLH_LEN + 1 + c] == TCP_OPT_MSS_LEN) {
1565 tmp16 = (uip_buf[UIP_TCPIP_HLEN +
UIP_LLH_LEN + 2 + c] << 8) |
1575 if(uip_buf[UIP_TCPIP_HLEN +
UIP_LLH_LEN + 1 + c] == 0) {
1580 c += uip_buf[UIP_TCPIP_HLEN +
UIP_LLH_LEN + 1 + c];
1585 uip_connr->
rcv_nxt[0] = BUF->seqno[0];
1586 uip_connr->
rcv_nxt[1] = BUF->seqno[1];
1587 uip_connr->
rcv_nxt[2] = BUF->seqno[2];
1588 uip_connr->
rcv_nxt[3] = BUF->seqno[3];
1590 uip_flags = UIP_CONNECTED | UIP_NEWDATA;
1598 uip_flags = UIP_ABORT;
1605 case UIP_ESTABLISHED:
1617 if(BUF->flags & TCP_FIN && !(uip_connr->
tcpstateflags & UIP_STOPPED)) {
1618 if(uip_outstanding(uip_connr)) {
1622 uip_flags |= UIP_CLOSE;
1624 uip_flags |= UIP_NEWDATA;
1629 uip_connr->
nrtx = 0;
1631 BUF->flags = TCP_FIN | TCP_ACK;
1632 goto tcp_send_nodata;
1637 if((BUF->flags & TCP_URG) != 0) {
1639 uip_urglen = (BUF->urgp[0] << 8) | BUF->urgp[1];
1644 uip_add_rcv_nxt(uip_urglen);
1652 uip_len -= (BUF->urgp[0] << 8) | BUF->urgp[1];
1662 uip_flags |= UIP_NEWDATA;
1678 tmp16 = ((
u16_t)BUF->wnd[0] << 8) + (
u16_t)BUF->wnd[1];
1683 uip_connr->
mss = tmp16;
1701 if(uip_flags & (UIP_NEWDATA | UIP_ACKDATA)) {
1707 if(uip_flags & UIP_ABORT) {
1710 BUF->flags = TCP_RST | TCP_ACK;
1711 goto tcp_send_nodata;
1714 if(uip_flags & UIP_CLOSE) {
1718 uip_connr->
nrtx = 0;
1719 BUF->flags = TCP_FIN | TCP_ACK;
1720 goto tcp_send_nodata;
1728 if((uip_flags & UIP_ACKDATA) != 0) {
1735 if(uip_connr->
len == 0) {
1740 if(uip_slen > uip_connr->
mss) {
1741 uip_slen = uip_connr->
mss;
1746 uip_connr->
len = uip_slen;
1752 uip_slen = uip_connr->
len;
1755 uip_connr->
nrtx = 0;
1761 if(uip_slen > 0 && uip_connr->
len > 0) {
1765 BUF->flags = TCP_ACK | TCP_PSH;
1767 goto tcp_send_noopts;
1771 if(uip_flags & UIP_NEWDATA) {
1773 BUF->flags = TCP_ACK;
1774 goto tcp_send_noopts;
1781 if(uip_flags & UIP_ACKDATA) {
1783 uip_flags = UIP_CLOSE;
1788 case UIP_FIN_WAIT_1:
1795 if(BUF->flags & TCP_FIN) {
1796 if(uip_flags & UIP_ACKDATA) {
1798 uip_connr->
timer = 0;
1804 uip_flags = UIP_CLOSE;
1807 }
else if(uip_flags & UIP_ACKDATA) {
1817 case UIP_FIN_WAIT_2:
1821 if(BUF->flags & TCP_FIN) {
1823 uip_connr->
timer = 0;
1825 uip_flags = UIP_CLOSE;
1838 if(uip_flags & UIP_ACKDATA) {
1840 uip_connr->
timer = 0;
1848 BUF->flags = TCP_ACK;
1854 BUF->tcpoffset = (UIP_TCPH_LEN / 4) << 4;
1861 BUF->ackno[0] = uip_connr->
rcv_nxt[0];
1862 BUF->ackno[1] = uip_connr->
rcv_nxt[1];
1863 BUF->ackno[2] = uip_connr->
rcv_nxt[2];
1864 BUF->ackno[3] = uip_connr->
rcv_nxt[3];
1866 BUF->seqno[0] = uip_connr->
snd_nxt[0];
1867 BUF->seqno[1] = uip_connr->
snd_nxt[1];
1868 BUF->seqno[2] = uip_connr->
snd_nxt[2];
1869 BUF->seqno[3] = uip_connr->
snd_nxt[3];
1871 BUF->proto = UIP_PROTO_TCP;
1873 BUF->srcport = uip_connr->
lport;
1874 BUF->destport = uip_connr->
rport;
1882 BUF->wnd[0] = BUF->wnd[1] = 0;
1893 BUF->len[0] = ((
uip_len - UIP_IPH_LEN) >> 8);
1894 BUF->len[1] = ((
uip_len - UIP_IPH_LEN) & 0xff);
1897 BUF->len[1] = (
uip_len & 0xff);
1900 BUF->urgp[0] = BUF->urgp[1] = 0;
1914 BUF->ipoffset[0] = BUF->ipoffset[1] = 0;
1916 BUF->ipid[0] = ipid >> 8;
1917 BUF->ipid[1] = ipid & 0xff;
1921 DEBUG_PRINTF(
"uip ip_send_nolen: chkecum 0x%04x\n",
uip_ipchksum());
1927 DEBUG_PRINTF(
"Sending packet with length %d (%d)\n",
uip_len,
1928 (BUF->len[0] << 8) | BUF->len[1]);
1948 uip_htonl(u32_t val)
1950 return UIP_HTONL(val);
1957 #define MIN(a,b) ((a) < (b)? (a): (b))
1959 (
int)((
char *)uip_sappdata - (
char *)&uip_buf[
UIP_LLH_LEN + UIP_TCPIP_HLEN]));
1962 if(data != uip_sappdata) {
1963 memcpy(uip_sappdata, (data), uip_slen);