root/webserver/example/freeRTOSexample/EnergyMeters/Common/ethernet/FreeRTOS-uIP/uip-split.c

Revision 14, 4.7 kB (checked in by phil, 15 years ago)

added unmodified FreeRTOS package V5.4.1 with only web srv demo source for LPC2368 for CrossWorks?

Line 
1 /*
2  * Copyright (c) 2004, Swedish Institute of Computer Science.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the Institute nor the names of its contributors
14  *    may be used to endorse or promote products derived from this software
15  *    without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * This file is part of the uIP TCP/IP stack
30  *
31  * Author: Adam Dunkels <adam@sics.se>
32  *
33  * $Id: uip-split.c,v 1.2 2006/06/12 08:00:30 adam Exp $
34  */
35 #include <string.h>
36
37 #include "uip-split.h"
38 #include "uip.h"
39 #include "uip-fw.h"
40 #include "uip_arch.h"
41
42 #define BUF ( ( struct uip_tcpip_hdr * ) &uip_buf[UIP_LLH_LEN] )
43
44 /*-----------------------------------------------------------------------------*/
45 void uip_split_output( void )
46 {
47         u16_t   tcplen, len1, len2;
48
49         /* We only try to split maximum sized TCP segments. */
50         if( BUF->proto == UIP_PROTO_TCP && uip_len == UIP_BUFSIZE - UIP_LLH_LEN )
51         {
52                 tcplen = uip_len - UIP_TCPIP_HLEN;
53
54                 /* Split the segment in two. If the original packet length was
55        odd, we make the second packet one byte larger. */
56                 len1 = len2 = tcplen / 2;
57                 if( len1 + len2 < tcplen )
58                 {
59                         ++len2;
60                 }
61
62                 /* Create the first packet. This is done by altering the length
63        field of the IP header and updating the checksums. */
64                 uip_len = len1 + UIP_TCPIP_HLEN;
65                 #if UIP_CONF_IPV6
66
67                 /* For IPv6, the IP length field does not include the IPv6 IP header
68        length. */
69                 BUF->len[0] = ( (uip_len - UIP_IPH_LEN) >> 8 );
70                 BUF->len[1] = ( (uip_len - UIP_IPH_LEN) & 0xff );
71                 #else /* UIP_CONF_IPV6 */
72                 BUF->len[0] = uip_len >> 8;
73                 BUF->len[1] = uip_len & 0xff;
74                 #endif /* UIP_CONF_IPV6 */
75
76                 /* Recalculate the TCP checksum. */
77                 BUF->tcpchksum = 0;
78                 BUF->tcpchksum = ~( uip_tcpchksum() );
79
80                 #if !UIP_CONF_IPV6
81
82                 /* Recalculate the IP checksum. */
83                 BUF->ipchksum = 0;
84                 BUF->ipchksum = ~( uip_ipchksum() );
85                 #endif /* UIP_CONF_IPV6 */
86
87                 /* Transmit the first packet. */
88
89                 /*    uip_fw_output();*/
90
91                 //    tcpip_output();
92
93                 /* Now, create the second packet. To do this, it is not enough to
94        just alter the length field, but we must also update the TCP
95        sequence number and point the uip_appdata to a new place in
96        memory. This place is detemined by the length of the first
97        packet (len1). */
98                 uip_len = len2 + UIP_TCPIP_HLEN;
99                 #if UIP_CONF_IPV6
100
101                 /* For IPv6, the IP length field does not include the IPv6 IP header
102        length. */
103                 BUF->len[0] = ( (uip_len - UIP_IPH_LEN) >> 8 );
104                 BUF->len[1] = ( (uip_len - UIP_IPH_LEN) & 0xff );
105                 #else /* UIP_CONF_IPV6 */
106                 BUF->len[0] = uip_len >> 8;
107                 BUF->len[1] = uip_len & 0xff;
108                 #endif /* UIP_CONF_IPV6 */
109
110                 /*    uip_appdata += len1;*/
111                 memcpy( uip_appdata, ( u8_t * ) uip_appdata + len1, len2 );
112
113                 uip_add32( BUF->seqno, len1 );
114                 BUF->seqno[0] = uip_acc32[0];
115                 BUF->seqno[1] = uip_acc32[1];
116                 BUF->seqno[2] = uip_acc32[2];
117                 BUF->seqno[3] = uip_acc32[3];
118
119                 /* Recalculate the TCP checksum. */
120                 BUF->tcpchksum = 0;
121                 BUF->tcpchksum = ~( uip_tcpchksum() );
122
123                 #if !UIP_CONF_IPV6
124
125                 /* Recalculate the IP checksum. */
126                 BUF->ipchksum = 0;
127                 BUF->ipchksum = ~( uip_ipchksum() );
128                 #endif /* UIP_CONF_IPV6 */
129
130                 /* Transmit the second packet. */
131
132                 /*    uip_fw_output();*/
133
134                 //    tcpip_output();
135         }
136         else
137         {
138                 /*    uip_fw_output();*/
139
140                 //    tcpip_output();
141         }
142 }
143
144 /*-----------------------------------------------------------------------------*/
Note: See TracBrowser for help on using the browser.