These are the examples provided for [[/users/frank26080115/libraries/LPC1700CMSIS_Lib/]] Note, the entire "program" is not compilable!

Committer:
frank26080115
Date:
Sun Mar 20 05:38:56 2011 +0000
Revision:
0:bf7b9fba3924

        

Who changed what in which revision?

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