mbed OS5
Fork of UIPEthernet by
Diff: utility/uip.c
- Revision:
- 4:d774541a34da
- Parent:
- 3:5b17e4656dd0
- Child:
- 8:4acb22344932
--- a/utility/uip.c Sat Dec 20 11:10:40 2014 +0000 +++ b/utility/uip.c Sun Mar 08 20:26:56 2015 +0000 @@ -136,48 +136,48 @@ #endif #ifndef UIP_CONF_EXTERNAL_BUFFER u8_t uip_buf[UIP_BUFSIZE + 2]; /* The packet buffer that contains - incoming packets. */ + incoming packets. */ #endif /* UIP_CONF_EXTERNAL_BUFFER */ void* uip_appdata; /* The uip_appdata pointer points to - application data. */ + application data. */ void* uip_sappdata; /* The uip_appdata pointer points to - the application data which is to - be sent. */ + the application data which is to + be sent. */ #if UIP_URGDATA > 0 void* uip_urgdata; /* The uip_urgdata pointer points to - urgent data (out-of-band data), if - present. */ + urgent data (out-of-band data), if + present. */ u16_t uip_urglen, uip_surglen; #endif /* UIP_URGDATA > 0 */ u16_t uip_len, uip_slen; /* The uip_len is either 8 or 16 bits, - depending on the maximum packet - size. */ + depending on the maximum packet + size. */ u8_t uip_flags; /* The uip_flags variable is used for - communication between the TCP/IP stack - and the application program. */ + communication between the TCP/IP stack + and the application program. */ struct uip_conn* uip_conn; /* uip_conn always points to the current - connection. */ + connection. */ struct uip_conn uip_conns[UIP_CONNS]; /* The uip_conns array holds all TCP - connections. */ + connections. */ u16_t uip_listenports[UIP_LISTENPORTS]; /* The uip_listenports list all currently - listning ports. */ + listning ports. */ #if UIP_UDP struct uip_udp_conn* uip_udp_conn; struct uip_udp_conn uip_udp_conns[UIP_UDP_CONNS]; #endif /* UIP_UDP */ static u16_t ipid; /* Ths ipid variable is an increasing - number that is used for the IP ID - field. */ + number that is used for the IP ID + field. */ /** * @brief @@ -185,16 +185,17 @@ * @param * @retval */ + void uip_setipid(u16_t id) { ipid = id; } static u8_t iss[4]; /* The iss variable is used for the TCP - initial sequence number. */ + initial sequence number. */ #if UIP_ACTIVE_OPEN static u16_t lastport; /* Keeps track of the last port used for - a new connection. */ + a new connection. */ #endif /* UIP_ACTIVE_OPEN */ /* Temporary variables. */ @@ -598,6 +599,7 @@ * @param * @retval */ + static u8_t uip_reass(void) { u16_t offset, len; u16_t i; @@ -645,14 +647,14 @@ if(offset / (8 * 8) == (offset + len) / (8 * 8)) { /* If the two endpoints are in the same byte, we only update - that byte. */ + that byte. */ uip_reassbitmap[offset / (8 * 8)] |= bitmap_bits[(offset / 8) & 7] &~bitmap_bits[((offset + len) / 8) & 7]; } else { /* If the two endpoints are in different bytes, we update the - bytes in the endpoints and fill the stuff inbetween with - 0xff. */ + bytes in the endpoints and fill the stuff inbetween with + 0xff. */ uip_reassbitmap[offset / (8 * 8)] |= bitmap_bits[(offset / 8) & 7]; for(i = 1 + offset / (8 * 8); i < (offset + len) / (8 * 8); ++i) { uip_reassbitmap[i] = 0xff; @@ -677,7 +679,7 @@ if(uip_reassflags & UIP_REASS_FLAG_LASTFRAG) { /* Check all bytes up to and including all but the last byte in - the bitmap. */ + the bitmap. */ for(i = 0; i < uip_reasslen / (8 * 8) - 1; ++i) { if(uip_reassbitmap[i] != 0xff) { goto nullreturn; @@ -685,19 +687,19 @@ } /* Check the last byte in the bitmap. It should contain just the - right amount of bits. */ + right amount of bits. */ if(uip_reassbitmap[uip_reasslen / (8 * 8)] != (u8_t)~bitmap_bits[uip_reasslen / 8 & 7]) { goto nullreturn; } /* If we have come this far, we have a full packet in the - buffer, so we allocate a pbuf and copy the packet into it. We - also reset the timer. */ + buffer, so we allocate a pbuf and copy the packet into it. We + also reset the timer. */ uip_reasstmr = 0; memcpy(BUF, FBUF, uip_reasslen); /* Pretend to be a "normal" (i.e., not fragmented) IP packet - from now on. */ + from now on. */ BUF->ipoffset[0] = BUF->ipoffset[1] = 0; BUF->len[0] = uip_reasslen >> 8; BUF->len[1] = uip_reasslen & 0xff; @@ -784,8 +786,8 @@ if(uip_connr->tcpstateflags != UIP_CLOSED) { /* If the connection has outstanding data, we increase the - connection's timer and see if it has reached the RTO value - in which case we retransmit. */ + connection's timer and see if it has reached the RTO value + in which case we retransmit. */ if(uip_outstanding(uip_connr)) { if(uip_connr->timer-- == 0) { if @@ -799,8 +801,8 @@ uip_connr->tcpstateflags = UIP_CLOSED; /* We call UIP_APPCALL() with uip_flags set to - UIP_TIMEDOUT to inform the application that the - connection has timed out. */ + UIP_TIMEDOUT to inform the application that the + connection has timed out. */ uip_flags = UIP_TIMEDOUT; UIP_APPCALL(); @@ -814,11 +816,11 @@ ++(uip_connr->nrtx); /* Ok, so we need to retransmit. We do this differently - depending on which state we are in. In ESTABLISHED, we - call upon the application so that it may prepare the - data for the retransmit. In SYN_RCVD, we resend the - SYNACK that we sent earlier and in LAST_ACK we have to - retransmit our FINACK. */ + depending on which state we are in. In ESTABLISHED, we + call upon the application so that it may prepare the + data for the retransmit. In SYN_RCVD, we resend the + SYNACK that we sent earlier and in LAST_ACK we have to + retransmit our FINACK. */ UIP_STAT(++uip_stat.tcp.rexmit); switch(uip_connr->tcpstateflags & UIP_TS_MASK) { case UIP_SYN_RCVD: @@ -921,14 +923,14 @@ uip_len = (BUF->len[0] << 8) + BUF->len[1]; #if UIP_CONF_IPV6 uip_len += 40; /* The length reported in the IPv6 header is the - length of the payload that follows the - header. However, uIP uses the uip_len variable - for holding the size of the entire packet, - including the IP header. For IPv4 this is not a - problem as the length field in the IPv4 header - contains the length of the entire packet. But - for IPv6 we need to add the size of the IPv6 - header (40 bytes). */ + length of the payload that follows the + header. However, uIP uses the uip_len variable + for holding the size of the entire packet, + including the IP header. For IPv4 this is not a + problem as the length field in the IPv4 header + contains the length of the entire packet. But + for IPv6 we need to add the size of the IPv6 + header (40 bytes). */ #endif /* UIP_CONF_IPV6 */ } else { @@ -982,7 +984,7 @@ ( BUF->proto == UIP_PROTO_UDP && uip_ipaddr_cmp(BUF->destipaddr, all_ones_addr) /*&& - uip_ipchksum() == 0xffff*/ + uip_ipchksum() == 0xffff*/ ) { goto udp_input; } @@ -1014,7 +1016,7 @@ if(uip_ipchksum() != 0xffff) { /* Compute and check the IP header - checksum. */ + checksum. */ UIP_STAT(++uip_stat.ip.drop); UIP_STAT(++uip_stat.ip.chkerr); UIP_LOG("ip: bad checksum."); @@ -1025,8 +1027,8 @@ if(BUF->proto == UIP_PROTO_TCP) { /* Check for TCP packet. If so, - proceed with TCP input - processing. */ + proceed with TCP input + processing. */ goto tcp_input; } @@ -1042,7 +1044,7 @@ if(BUF->proto != UIP_PROTO_ICMP) { /* We only allow ICMP packets from - here. */ + here. */ UIP_STAT(++uip_stat.ip.drop); UIP_STAT(++uip_stat.ip.protoerr); UIP_LOG("ip: neither tcp nor icmp."); @@ -1100,7 +1102,7 @@ if(BUF->proto != UIP_PROTO_ICMP6) { /* We only allow ICMPv6 packets from - here. */ + here. */ UIP_STAT(++uip_stat.ip.drop); UIP_STAT(++uip_stat.ip.protoerr); UIP_LOG("ip: neither tcp nor icmp6."); @@ -1120,7 +1122,7 @@ } /* We should now send a neighbor advertisement back to where the - neighbor solicication came from. */ + neighbor solicication came from. */ ICMPBUF->type = ICMP6_NEIGHBOR_ADVERTISEMENT; ICMPBUF->flags = ICMP6_FLAG_S; /* Solicited flag. */ @@ -1274,7 +1276,7 @@ if(uip_tcpchksum() != 0xffff) { /* Compute and check the TCP - checksum. */ + checksum. */ UIP_STAT(++uip_stat.tcp.drop); UIP_STAT(++uip_stat.tcp.chkerr); UIP_LOG("tcp: bad checksum."); @@ -1452,11 +1454,11 @@ else { /* All other options have a length field, so that we easily - can skip past them. */ + can skip past them. */ if(uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c] == 0) { /* If the length field is zero, the options are malformed - and we don't process them further. */ + and we don't process them further. */ break; } @@ -1582,9 +1584,9 @@ /* Do different things depending on in what state the connection is. */ switch(uip_connr->tcpstateflags & UIP_TS_MASK) { /* CLOSED and LISTEN are not handled here. CLOSE_WAIT is not - implemented, since we force the application to close when the - peer sends a FIN (hence the application goes directly from - ESTABLISHED to LAST_ACK). */ + implemented, since we force the application to close when the + peer sends a FIN (hence the application goes directly from + ESTABLISHED to LAST_ACK). */ case UIP_SYN_RCVD: /* In SYN_RCVD we have sent out a SYNACK in response to a SYN, and we are waiting for an ACK that acknowledges the data we sent @@ -1642,11 +1644,11 @@ else { /* All other options have a length field, so that we easily - can skip past them. */ + can skip past them. */ if(uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c] == 0) { /* If the length field is zero, the options are malformed - and we don't process them further. */ + and we don't process them further. */ break; } @@ -1804,32 +1806,32 @@ if(uip_slen > 0) { /* If the connection has acknowledged data, the contents of - the ->len variable should be discarded. */ + the ->len variable should be discarded. */ if((uip_flags & UIP_ACKDATA) != 0) { uip_connr->len = 0; } /* If the ->len variable is non-zero the connection has - already data in transit and cannot send anymore right - now. */ + already data in transit and cannot send anymore right + now. */ if(uip_connr->len == 0) { /* The application cannot send more than what is allowed by - the mss (the minumum of the MSS and the available - window). */ + the mss (the minumum of the MSS and the available + window). */ if(uip_slen > uip_connr->mss) { uip_slen = uip_connr->mss; } /* Remember how much data we send out now so that we know - when everything has been acknowledged. */ + when everything has been acknowledged. */ uip_connr->len = uip_slen; } else { /* If the application already had unacknowledged data, we - make sure that the application does not send (i.e., - retransmit) out more than it previously sent out. */ + make sure that the application does not send (i.e., + retransmit) out more than it previously sent out. */ uip_slen = uip_connr->len; } } @@ -1853,7 +1855,7 @@ } /* If there is no data to send, just send out a pure ACK if - there is newdata. */ + there is newdata. */ if(uip_flags & UIP_NEWDATA) { uip_len = UIP_TCPIP_HLEN; BUF->flags = TCP_ACK;