adamdunkels | ee26fe3 | 2004-03-25 09:47:10 +0000 | [diff] [blame^] | 1 | |
| 2 | #include "uip-split.h" |
| 3 | #include "uip.h" |
| 4 | #include "uip-fw.h" |
| 5 | #include "uip_arch.h" |
| 6 | |
| 7 | #define BUF ((uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN]) |
| 8 | |
| 9 | /*-----------------------------------------------------------------------------*/ |
| 10 | void |
| 11 | uip_split_output(void) |
| 12 | { |
| 13 | u16_t tcplen, len1, len2; |
| 14 | |
| 15 | /* We only try to split maximum sized TCP segments. */ |
| 16 | if(BUF->proto == UIP_PROTO_TCP && |
| 17 | uip_len == UIP_BUFSIZE - UIP_LLH_LEN) { |
| 18 | |
| 19 | tcplen = uip_len - UIP_TCPIP_HLEN; |
| 20 | /* Split the segment in two. If the original packet length was |
| 21 | odd, we make the second packet one byte larger. */ |
| 22 | len1 = len2 = tcplen / 2; |
| 23 | if(len1 + len2 < tcplen) { |
| 24 | ++len2; |
| 25 | } |
| 26 | |
| 27 | /* Create the first packet. This is done by altering the length |
| 28 | field of the IP header and updating the checksums. */ |
| 29 | uip_len = len1 + UIP_TCPIP_HLEN; |
| 30 | BUF->len[0] = (uip_len >> 8); |
| 31 | BUF->len[1] = (uip_len & 0xff); |
| 32 | |
| 33 | /* Recalculate the TCP checksum. */ |
| 34 | BUF->tcpchksum = 0; |
| 35 | BUF->tcpchksum = ~(uip_tcpchksum()); |
| 36 | |
| 37 | /* Recalculate the IP checksum. */ |
| 38 | BUF->ipchksum = 0; |
| 39 | BUF->ipchksum = ~(uip_ipchksum()); |
| 40 | |
| 41 | /* Transmit the first packet. */ |
| 42 | uip_fw_output(); |
| 43 | |
| 44 | /* Now, create the second packet. To do this, it is not enough to |
| 45 | just alter the length field, but we must also update the TCP |
| 46 | sequence number and point the uip_appdata to a new place in |
| 47 | memory. This place is detemined by the length of the first |
| 48 | packet (len1). */ |
| 49 | uip_len = len2 + UIP_TCPIP_HLEN; |
| 50 | BUF->len[0] = (uip_len >> 8); |
| 51 | BUF->len[1] = (uip_len & 0xff); |
| 52 | |
| 53 | uip_appdata += len1; |
| 54 | |
| 55 | uip_add32(BUF->seqno, len1); |
| 56 | BUF->seqno[0] = uip_acc32[0]; |
| 57 | BUF->seqno[1] = uip_acc32[1]; |
| 58 | BUF->seqno[2] = uip_acc32[2]; |
| 59 | BUF->seqno[3] = uip_acc32[3]; |
| 60 | |
| 61 | /* Recalculate the TCP checksum. */ |
| 62 | BUF->tcpchksum = 0; |
| 63 | BUF->tcpchksum = ~(uip_tcpchksum()); |
| 64 | |
| 65 | /* Recalculate the IP checksum. */ |
| 66 | BUF->ipchksum = 0; |
| 67 | BUF->ipchksum = ~(uip_ipchksum()); |
| 68 | |
| 69 | /* Transmit the second packet. */ |
| 70 | uip_fw_output(); |
| 71 | } else { |
| 72 | uip_fw_output(); |
| 73 | } |
| 74 | |
| 75 | } |
| 76 | /*-----------------------------------------------------------------------------*/ |