1
0
mirror of https://github.com/elua/elua.git synced 2025-01-25 01:02:54 +08:00

Replace tabs by spaces in uip code

This commit is contained in:
Martin Guy 2011-07-24 17:35:45 +02:00
parent a6b5f865d5
commit a3170a953d
12 changed files with 461 additions and 462 deletions

View File

@ -276,17 +276,17 @@ PT_THREAD(handle_dhcp(void))
s.timer_init = platform_timer_op( ELUA_DHCP_TIMER_ID, PLATFORM_TIMER_OP_START, 0 );
PT_WAIT_UNTIL(&s.pt, uip_newdata() || platform_timer_get_diff_us( ELUA_DHCP_TIMER_ID, s.timer_init, platform_timer_op( ELUA_DHCP_TIMER_ID, PLATFORM_TIMER_OP_READ, 0 ) ) >= s.ticks );
if(uip_newdata() && parse_msg() == DHCPOFFER) {
uip_flags &= ~UIP_NEWDATA;
uip_flags &= ~UIP_NEWDATA;
s.state = STATE_OFFER_RECEIVED;
break;
}
uip_flags &= ~UIP_NEWDATA;
uip_flags &= ~UIP_NEWDATA;
if(s.ticks < CLOCK_SECOND * 60) {
s.ticks *= 2;
} else {
s.ipaddr[0] = 0;
goto dhcp_failed;
}
s.ipaddr[0] = 0;
goto dhcp_failed;
}
} while(s.state != STATE_OFFER_RECEIVED);
s.ticks = CLOCK_SECOND;
@ -297,7 +297,7 @@ PT_THREAD(handle_dhcp(void))
PT_WAIT_UNTIL(&s.pt, uip_newdata() || platform_timer_get_diff_us( ELUA_DHCP_TIMER_ID, s.timer_init, platform_timer_op( ELUA_DHCP_TIMER_ID, PLATFORM_TIMER_OP_READ, 0 ) ) >= s.ticks );
if(uip_newdata() && parse_msg() == DHCPACK) {
uip_flags &= ~UIP_NEWDATA;
uip_flags &= ~UIP_NEWDATA;
s.state = STATE_CONFIG_RECEIVED;
break;
}

View File

@ -76,7 +76,7 @@
/*---------------------------------------------------------------------------*/
static void
buf_setup(struct psock_buf *buf,
u8_t *bufptr, u16_t bufsize)
u8_t *bufptr, u16_t bufsize)
{
buf->ptr = bufptr;
buf->left = bufsize;
@ -84,7 +84,7 @@ buf_setup(struct psock_buf *buf,
/*---------------------------------------------------------------------------*/
static u8_t
buf_bufdata(struct psock_buf *buf, u16_t len,
u8_t **dataptr, u16_t *datalen)
u8_t **dataptr, u16_t *datalen)
{
if(*datalen < buf->left) {
memcpy(buf->ptr, *dataptr, *datalen);
@ -112,7 +112,7 @@ buf_bufdata(struct psock_buf *buf, u16_t len,
/*---------------------------------------------------------------------------*/
static u8_t
buf_bufto(register struct psock_buf *buf, u8_t endmarker,
register u8_t **dataptr, register u16_t *datalen)
register u8_t **dataptr, register u16_t *datalen)
{
u8_t c;
while(buf->left > 0 && *datalen > 0) {
@ -177,7 +177,7 @@ data_acked(register struct psock *s)
}
/*---------------------------------------------------------------------------*/
PT_THREAD(psock_send(register struct psock *s, const char *buf,
unsigned int len))
unsigned int len))
{
PT_BEGIN(&s->psockpt);
@ -216,7 +216,7 @@ PT_THREAD(psock_send(register struct psock *s, const char *buf,
}
/*---------------------------------------------------------------------------*/
PT_THREAD(psock_generator_send(register struct psock *s,
unsigned short (*generate)(void *), void *arg))
unsigned short (*generate)(void *), void *arg))
{
PT_BEGIN(&s->psockpt);
@ -289,8 +289,8 @@ PT_THREAD(psock_readto(register struct psock *psock, unsigned char c))
psock->readlen = uip_datalen();
}
} while((buf_bufto(&psock->buf, c,
&psock->readptr,
&psock->readlen) & BUF_FOUND) == 0);
&psock->readptr,
&psock->readlen) & BUF_FOUND) == 0);
if(psock_datalen(psock) == 0) {
psock->state = STATE_NONE;
@ -317,8 +317,8 @@ PT_THREAD(psock_readbuf(register struct psock *psock))
psock->readlen = uip_datalen();
}
} while(buf_bufdata(&psock->buf, psock->bufsize,
&psock->readptr,
&psock->readlen) != BUF_FULL);
&psock->readptr,
&psock->readlen) != BUF_FULL);
if(psock_datalen(psock) == 0) {
psock->state = STATE_NONE;

View File

@ -105,19 +105,19 @@ struct psock_buf {
*/
struct psock {
struct pt pt, psockpt; /* Protothreads - one that's using the psock
functions, and one that runs inside the
psock functions. */
functions, and one that runs inside the
psock functions. */
const u8_t *sendptr; /* Pointer to the next data to be sent. */
u8_t *readptr; /* Pointer to the next data to be read. */
char *bufptr; /* Pointer to the buffer used for buffering
incoming data. */
incoming data. */
u16_t sendlen; /* The number of bytes left to be sent. */
u16_t readlen; /* The number of bytes left to be read. */
struct psock_buf buf; /* The structure holding the state of the
input buffer. */
input buffer. */
unsigned int bufsize; /* The size of the input buffer. */
unsigned char state; /* The state of the protosocket. */
@ -175,7 +175,7 @@ PT_THREAD(psock_send(struct psock *psock, const char *buf, unsigned int len));
*
* \hideinitializer
*/
#define PSOCK_SEND(psock, data, datalen) \
#define PSOCK_SEND(psock, data, datalen) \
PT_WAIT_THREAD(&((psock)->pt), psock_send(psock, data, datalen))
/**
@ -188,11 +188,11 @@ PT_THREAD(psock_send(struct psock *psock, const char *buf, unsigned int len));
*
* \hideinitializer
*/
#define PSOCK_SEND_STR(psock, str) \
#define PSOCK_SEND_STR(psock, str) \
PT_WAIT_THREAD(&((psock)->pt), psock_send(psock, str, strlen(str)))
PT_THREAD(psock_generator_send(struct psock *psock,
unsigned short (*f)(void *), void *arg));
unsigned short (*f)(void *), void *arg));
/**
* \brief Generate data with a function and send it
@ -216,9 +216,9 @@ PT_THREAD(psock_generator_send(struct psock *psock,
*
* \hideinitializer
*/
#define PSOCK_GENERATOR_SEND(psock, generator, arg) \
PT_WAIT_THREAD(&((psock)->pt), \
psock_generator_send(psock, generator, arg))
#define PSOCK_GENERATOR_SEND(psock, generator, arg) \
PT_WAIT_THREAD(&((psock)->pt), \
psock_generator_send(psock, generator, arg))
/**
@ -247,7 +247,7 @@ PT_THREAD(psock_readbuf(struct psock *psock));
*
* \hideinitializer
*/
#define PSOCK_READBUF(psock) \
#define PSOCK_READBUF(psock) \
PT_WAIT_THREAD(&((psock)->pt), psock_readbuf(psock))
PT_THREAD(psock_readto(struct psock *psock, unsigned char c));
@ -265,7 +265,7 @@ PT_THREAD(psock_readto(struct psock *psock, unsigned char c));
*
* \hideinitializer
*/
#define PSOCK_READTO(psock, c) \
#define PSOCK_READTO(psock, c) \
PT_WAIT_THREAD(&((psock)->pt), psock_readto(psock, c))
/**
@ -305,10 +305,10 @@ u16_t psock_datalen(struct psock *psock);
*
* \hideinitializer
*/
#define PSOCK_CLOSE_EXIT(psock) \
do { \
PSOCK_CLOSE(psock); \
PSOCK_EXIT(psock); \
#define PSOCK_CLOSE_EXIT(psock) \
do { \
PSOCK_CLOSE(psock); \
PSOCK_EXIT(psock); \
} while(0)
/**

View File

@ -145,12 +145,12 @@ struct pt {
*
* \hideinitializer
*/
#define PT_WAIT_UNTIL(pt, condition) \
do { \
LC_SET((pt)->lc); \
if(!(condition)) { \
return PT_WAITING; \
} \
#define PT_WAIT_UNTIL(pt, condition) \
do { \
LC_SET((pt)->lc); \
if(!(condition)) { \
return PT_WAITING; \
} \
} while(0)
/**
@ -203,10 +203,10 @@ struct pt {
*
* \hideinitializer
*/
#define PT_SPAWN(pt, child, thread) \
do { \
PT_INIT((child)); \
PT_WAIT_THREAD((pt), (thread)); \
#define PT_SPAWN(pt, child, thread) \
do { \
PT_INIT((child)); \
PT_WAIT_THREAD((pt), (thread)); \
} while(0)
/** @} */
@ -226,10 +226,10 @@ struct pt {
*
* \hideinitializer
*/
#define PT_RESTART(pt) \
do { \
PT_INIT(pt); \
return PT_WAITING; \
#define PT_RESTART(pt) \
do { \
PT_INIT(pt); \
return PT_WAITING; \
} while(0)
/**
@ -243,10 +243,10 @@ struct pt {
*
* \hideinitializer
*/
#define PT_EXIT(pt) \
do { \
PT_INIT(pt); \
return PT_EXITED; \
#define PT_EXIT(pt) \
do { \
PT_INIT(pt); \
return PT_EXITED; \
} while(0)
/** @} */
@ -287,13 +287,13 @@ struct pt {
*
* \hideinitializer
*/
#define PT_YIELD(pt) \
do { \
PT_YIELD_FLAG = 0; \
LC_SET((pt)->lc); \
if(PT_YIELD_FLAG == 0) { \
return PT_YIELDED; \
} \
#define PT_YIELD(pt) \
do { \
PT_YIELD_FLAG = 0; \
LC_SET((pt)->lc); \
if(PT_YIELD_FLAG == 0) { \
return PT_YIELDED; \
} \
} while(0)
/**
@ -307,13 +307,13 @@ struct pt {
*
* \hideinitializer
*/
#define PT_YIELD_UNTIL(pt, cond) \
do { \
PT_YIELD_FLAG = 0; \
LC_SET((pt)->lc); \
if((PT_YIELD_FLAG == 0) || !(cond)) { \
return PT_YIELDED; \
} \
#define PT_YIELD_UNTIL(pt, cond) \
do { \
PT_YIELD_FLAG = 0; \
LC_SET((pt)->lc); \
if((PT_YIELD_FLAG == 0) || !(cond)) { \
return PT_YIELDED; \
} \
} while(0)
/** @} */

View File

@ -181,23 +181,23 @@ check_entries(void)
if(namemapptr->state == STATE_NEW ||
namemapptr->state == STATE_ASKING) {
if(namemapptr->state == STATE_ASKING) {
if(--namemapptr->tmr == 0) {
if(++namemapptr->retries == MAX_RETRIES) {
namemapptr->state = STATE_ERROR;
resolv_found(namemapptr->name, NULL);
continue;
}
namemapptr->tmr = namemapptr->retries;
} else {
/* printf("Timer %d\n", namemapptr->tmr);*/
/* Its timer has not run out, so we move on to next
entry. */
continue;
}
if(--namemapptr->tmr == 0) {
if(++namemapptr->retries == MAX_RETRIES) {
namemapptr->state = STATE_ERROR;
resolv_found(namemapptr->name, NULL);
continue;
}
namemapptr->tmr = namemapptr->retries;
} else {
/* printf("Timer %d\n", namemapptr->tmr);*/
/* Its timer has not run out, so we move on to next
entry. */
continue;
}
} else {
namemapptr->state = STATE_ASKING;
namemapptr->tmr = 1;
namemapptr->retries = 0;
namemapptr->state = STATE_ASKING;
namemapptr->tmr = 1;
namemapptr->retries = 0;
}
hdr = (struct dns_hdr *)uip_appdata;
memset(hdr, 0, sizeof(struct dns_hdr));
@ -209,20 +209,20 @@ check_entries(void)
--nameptr;
/* Convert hostname into suitable query format. */
do {
++nameptr;
nptr = query;
++query;
for(n = 0; *nameptr != '.' && *nameptr != 0; ++nameptr) {
*query = *nameptr;
++query;
++n;
}
*nptr = n;
++nameptr;
nptr = query;
++query;
for(n = 0; *nameptr != '.' && *nameptr != 0; ++nameptr) {
*query = *nameptr;
++query;
++n;
}
*nptr = n;
} while(*nameptr != 0);
{
static unsigned char endquery[] =
{0,0,1,0,1};
memcpy(query, endquery, 5);
static unsigned char endquery[] =
{0,0,1,0,1};
memcpy(query, endquery, 5);
}
uip_udp_send((unsigned char)(query + 5 - (char *)uip_appdata));
break;
@ -285,40 +285,40 @@ newdata(void)
while(nanswers > 0) {
/* The first byte in the answer resource record determines if it
is a compressed record or a normal one. */
is a compressed record or a normal one. */
if(*nameptr & 0xc0) {
/* Compressed name. */
nameptr +=2;
/* printf("Compressed anwser\n");*/
/* Compressed name. */
nameptr +=2;
/* printf("Compressed anwser\n");*/
} else {
/* Not compressed name. */
nameptr = parse_name(nameptr);
/* Not compressed name. */
nameptr = parse_name(nameptr);
}
ans = (struct dns_answer *)nameptr;
/* printf("Answer: type %x, class %x, ttl %x, length %x\n",
htons(ans->type), htons(ans->class), (htons(ans->ttl[0])
<< 16) | htons(ans->ttl[1]), htons(ans->len));*/
htons(ans->type), htons(ans->class), (htons(ans->ttl[0])
<< 16) | htons(ans->ttl[1]), htons(ans->len));*/
/* Check for IP address type and Internet class. Others are
discarded. */
discarded. */
if(ans->type == HTONS(1) &&
ans->class == HTONS(1) &&
ans->len == HTONS(4)) {
/* printf("IP address %d.%d.%d.%d\n",
htons(ans->ipaddr[0]) >> 8,
htons(ans->ipaddr[0]) & 0xff,
htons(ans->ipaddr[1]) >> 8,
htons(ans->ipaddr[1]) & 0xff);*/
/* XXX: we should really check that this IP address is the one
we want. */
namemapptr->ipaddr[0] = ans->ipaddr[0];
namemapptr->ipaddr[1] = ans->ipaddr[1];
ans->class == HTONS(1) &&
ans->len == HTONS(4)) {
/* printf("IP address %d.%d.%d.%d\n",
htons(ans->ipaddr[0]) >> 8,
htons(ans->ipaddr[0]) & 0xff,
htons(ans->ipaddr[1]) >> 8,
htons(ans->ipaddr[1]) & 0xff);*/
/* XXX: we should really check that this IP address is the one
we want. */
namemapptr->ipaddr[0] = ans->ipaddr[0];
namemapptr->ipaddr[1] = ans->ipaddr[1];
resolv_found(namemapptr->name, namemapptr->ipaddr);
return;
resolv_found(namemapptr->name, namemapptr->ipaddr);
return;
} else {
nameptr = nameptr + 10 + htons(ans->len);
nameptr = nameptr + 10 + htons(ans->len);
}
--nanswers;
}

View File

@ -331,7 +331,7 @@ find_netif(void)
/* Walk through every network interface to check for a match. */
for(netif = netifs; netif != NULL; netif = netif->next) {
if(ipaddr_maskcmp(BUF->destipaddr, netif->ipaddr,
netif->netmask)) {
netif->netmask)) {
/* If there was a match, we break the loop. */
return netif;
}
@ -385,8 +385,8 @@ uip_fw_output(void)
netif = find_netif();
/* printf("uip_fw_output: netif %p ->output %p len %d\n", netif,
netif->output,
uip_len);*/
netif->output,
uip_len);*/
if(netif == NULL) {
return UIP_FW_NOROUTE;

View File

@ -53,12 +53,12 @@
*/
struct uip_fw_netif {
struct uip_fw_netif *next; /**< Pointer to the next interface when
linked in a list. */
linked in a list. */
u16_t ipaddr[2]; /**< The IP address of this interface. */
u16_t netmask[2]; /**< The netmask of the interface. */
u8_t (* output)(void);
/**< A pointer to the function that
sends a packet. */
sends a packet. */
};
/**
@ -79,8 +79,8 @@ struct uip_fw_netif {
*/
#define UIP_FW_NETIF(ip1,ip2,ip3,ip4, nm1,nm2,nm3,nm4, outputfunc) \
NULL, \
{HTONS((ip1 << 8) | ip2), HTONS((ip3 << 8) | ip4)}, \
{HTONS((nm1 << 8) | nm2), HTONS((nm3 << 8) | nm4)}, \
{HTONS((ip1 << 8) | ip2), HTONS((ip3 << 8) | ip4)}, \
{HTONS((nm1 << 8) | nm2), HTONS((nm3 << 8) | nm4)}, \
outputfunc
/**

View File

@ -91,8 +91,8 @@ uip_neighbor_add(uip_ipaddr_t ipaddr, struct uip_neighbor_addr *addr)
u8_t oldest_time;
/*printf("Adding neighbor with link address %02x:%02x:%02x:%02x:%02x:%02x\n",
addr->addr.addr[0], addr->addr.addr[1], addr->addr.addr[2], addr->addr.addr[3],
addr->addr.addr[4], addr->addr.addr[5]);*/
addr->addr.addr[0], addr->addr.addr[1], addr->addr.addr[2], addr->addr.addr[3],
addr->addr.addr[4], addr->addr.addr[5]);*/
/* Find the first unused entry or the oldest used entry. */
oldest_time = 0;
@ -151,8 +151,8 @@ uip_neighbor_lookup(uip_ipaddr_t ipaddr)
e = find_entry(ipaddr);
if(e != NULL) {
/* printf("Lookup neighbor with link address %02x:%02x:%02x:%02x:%02x:%02x\n",
e->addr.addr.addr[0], e->addr.addr.addr[1], e->addr.addr.addr[2], e->addr.addr.addr[3],
e->addr.addr.addr[4], e->addr.addr.addr[5]);*/
e->addr.addr.addr[0], e->addr.addr.addr[1], e->addr.addr.addr[2], e->addr.addr.addr[3],
e->addr.addr.addr[4], e->addr.addr.addr[5]);*/
return &e->addr;
}

View File

@ -129,51 +129,50 @@ static const uip_ipaddr_t all_zeroes_addr =
#if UIP_FIXEDETHADDR
const struct uip_eth_addr uip_ethaddr = {{UIP_ETHADDR0,
UIP_ETHADDR1,
UIP_ETHADDR2,
UIP_ETHADDR3,
UIP_ETHADDR4,
UIP_ETHADDR5}};
UIP_ETHADDR1,
UIP_ETHADDR2,
UIP_ETHADDR3,
UIP_ETHADDR4,
UIP_ETHADDR5}};
#else
struct uip_eth_addr uip_ethaddr = {{0,0,0,0,0,0}};
#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. */
u16_t uip_len, uip_slen; /* The uip_len is either 8 or 16 bits,
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. */
u8_t uip_flags; /* The uip_flags variable is used for
communication between the TCP/IP stack
and the application program. */
#if UIP_TCP
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. */
u8_t uip_forced_poll; // 1 if forcing the polling, 0 if the polling is not forced
#endif /* UIP_TCP */
@ -184,19 +183,19 @@ 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. */
void uip_setipid(u16_t id) { ipid = id; }
#if UIP_TCP
static u8_t iss[4]; /* The iss variable is used for the TCP
initial sequence number. */
initial sequence number. */
#endif /* UIP_TCP */
#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. */
@ -290,7 +289,7 @@ uip_add32(u8_t *op32, u16_t op16)
if(uip_acc32[2] == 0) {
++uip_acc32[1];
if(uip_acc32[1] == 0) {
++uip_acc32[0];
++uip_acc32[0];
}
}
}
@ -310,11 +309,11 @@ chksum(u16_t sum, const u8_t *data, u16_t len)
dataptr = data;
last_byte = data + len - 1;
while(dataptr < last_byte) { /* At least two more bytes */
while(dataptr < last_byte) { /* At least two more bytes */
t = (dataptr[0] << 8) + dataptr[1];
sum += t;
if(sum < t) {
sum++; /* carry */
sum++; /* carry */
}
dataptr += 2;
}
@ -323,7 +322,7 @@ chksum(u16_t sum, const u8_t *data, u16_t len)
t = (dataptr[0] << 8) + 0;
sum += t;
if(sum < t) {
sum++; /* carry */
sum++; /* carry */
}
}
@ -371,7 +370,7 @@ upper_layer_chksum(u8_t proto)
/* Sum TCP header and data. */
sum = chksum(sum, &uip_buf[UIP_IPH_LEN + UIP_LLH_LEN],
upper_layer_len);
upper_layer_len);
return (sum == 0) ? 0xffff : htons(sum);
}
@ -496,8 +495,8 @@ uip_connect(uip_ipaddr_t *ripaddr, u16_t rport)
}
if(cconn->tcpstateflags == UIP_TIME_WAIT) {
if(conn == 0 ||
cconn->timer > conn->timer) {
conn = cconn;
cconn->timer > conn->timer) {
conn = cconn;
}
}
}
@ -606,7 +605,7 @@ uip_listen(u16_t port)
static u8_t uip_reassbuf[UIP_REASS_BUFSIZE];
static u8_t uip_reassbitmap[UIP_REASS_BUFSIZE / (8 * 8)];
static const u8_t bitmap_bits[8] = {0xff, 0x7f, 0x3f, 0x1f,
0x0f, 0x07, 0x03, 0x01};
0x0f, 0x07, 0x03, 0x01};
static u16_t uip_reasslen;
static u8_t uip_reassflags;
#define UIP_REASS_FLAG_LASTFRAG 0x01
@ -655,28 +654,28 @@ uip_reass(void)
/* Copy the fragment into the reassembly buffer, at the right
offset. */
memcpy(&uip_reassbuf[UIP_IPH_LEN + offset],
(char *)BUF + (int)((BUF->vhl & 0x0f) * 4),
len);
(char *)BUF + (int)((BUF->vhl & 0x0f) * 4),
len);
/* Update the bitmap. */
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];
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];
bitmap_bits[(offset / 8 ) & 7];
for(i = 1 + offset / (8 * 8); i < (offset + len) / (8 * 8); ++i) {
uip_reassbitmap[i] = 0xff;
uip_reassbitmap[i] = 0xff;
}
uip_reassbitmap[(offset + len) / (8 * 8)] |=
~bitmap_bits[((offset + len) / 8 ) & 7];
~bitmap_bits[((offset + len) / 8 ) & 7];
}
/* If this fragment has the More Fragments flag set to zero, we
@ -695,27 +694,27 @@ uip_reass(void)
in the bitmap are set. */
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;
}
if(uip_reassbitmap[i] != 0xff) {
goto nullreturn;
}
}
/* 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;
(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;
@ -764,9 +763,9 @@ uip_process(u8_t flag)
if(flag == UIP_POLL_REQUEST) {
if((uip_connr->tcpstateflags & UIP_TS_MASK) == UIP_ESTABLISHED &&
!uip_outstanding(uip_connr)) {
uip_flags = UIP_POLL;
UIP_APPCALL();
goto appsend;
uip_flags = UIP_POLL;
UIP_APPCALL();
goto appsend;
}
goto drop;
@ -780,9 +779,9 @@ uip_process(u8_t flag)
/* Increase the initial sequence number. */
if(++iss[3] == 0) {
if(++iss[2] == 0) {
if(++iss[1] == 0) {
++iss[0];
}
if(++iss[1] == 0) {
++iss[0];
}
}
}
@ -798,80 +797,80 @@ uip_process(u8_t flag)
uip_connr->tcpstateflags == UIP_FIN_WAIT_2)) {
++(uip_connr->timer);
if(uip_connr->timer == UIP_TIME_WAIT_TIMEOUT) {
uip_connr->tcpstateflags = UIP_CLOSED;
uip_connr->tcpstateflags = UIP_CLOSED;
}
} else if(uip_connr->tcpstateflags != UIP_CLOSED && uip_connr->tcpstateflags != UIP_RESERVED) {
/* 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) && !uip_forced_poll) {
if(uip_connr->timer-- == 0) {
if(uip_connr->nrtx == UIP_MAXRTX ||
((uip_connr->tcpstateflags == UIP_SYN_SENT ||
uip_connr->tcpstateflags == UIP_SYN_RCVD) &&
uip_connr->nrtx == UIP_MAXSYNRTX)) {
uip_connr->tcpstateflags = UIP_CLOSED;
if(uip_connr->timer-- == 0) {
if(uip_connr->nrtx == UIP_MAXRTX ||
((uip_connr->tcpstateflags == UIP_SYN_SENT ||
uip_connr->tcpstateflags == UIP_SYN_RCVD) &&
uip_connr->nrtx == UIP_MAXSYNRTX)) {
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_flags = UIP_TIMEDOUT;
UIP_APPCALL();
/* We call UIP_APPCALL() with uip_flags set to
UIP_TIMEDOUT to inform the application that the
connection has timed out. */
uip_flags = UIP_TIMEDOUT;
UIP_APPCALL();
/* We also send a reset packet to the remote host. */
BUF->flags = TCP_RST | TCP_ACK;
goto tcp_send_nodata;
}
/* We also send a reset packet to the remote host. */
BUF->flags = TCP_RST | TCP_ACK;
goto tcp_send_nodata;
}
/* Exponential backoff. */
uip_connr->timer = UIP_RTO << (uip_connr->nrtx > 4?
4:
uip_connr->nrtx);
++(uip_connr->nrtx);
/* Exponential backoff. */
uip_connr->timer = UIP_RTO << (uip_connr->nrtx > 4?
4:
uip_connr->nrtx);
++(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. */
UIP_STAT(++uip_stat.tcp.rexmit);
switch(uip_connr->tcpstateflags & UIP_TS_MASK) {
case UIP_SYN_RCVD:
/* In the SYN_RCVD state, we should retransmit our
/* 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. */
UIP_STAT(++uip_stat.tcp.rexmit);
switch(uip_connr->tcpstateflags & UIP_TS_MASK) {
case UIP_SYN_RCVD:
/* In the SYN_RCVD state, we should retransmit our
SYNACK. */
goto tcp_send_synack;
goto tcp_send_synack;
#if UIP_ACTIVE_OPEN
case UIP_SYN_SENT:
/* In the SYN_SENT state, we retransmit out SYN. */
BUF->flags = 0;
goto tcp_send_syn;
case UIP_SYN_SENT:
/* In the SYN_SENT state, we retransmit out SYN. */
BUF->flags = 0;
goto tcp_send_syn;
#endif /* UIP_ACTIVE_OPEN */
case UIP_ESTABLISHED:
/* In the ESTABLISHED state, we call upon the application
case UIP_ESTABLISHED:
/* In the ESTABLISHED state, we call upon the application
to do the actual retransmit after which we jump into
the code for sending out the packet (the apprexmit
label). */
uip_flags = UIP_REXMIT;
UIP_APPCALL();
goto apprexmit;
uip_flags = UIP_REXMIT;
UIP_APPCALL();
goto apprexmit;
case UIP_FIN_WAIT_1:
case UIP_CLOSING:
case UIP_LAST_ACK:
/* In all these states we should retransmit a FINACK. */
goto tcp_send_finack;
case UIP_FIN_WAIT_1:
case UIP_CLOSING:
case UIP_LAST_ACK:
/* In all these states we should retransmit a FINACK. */
goto tcp_send_finack;
}
}
}
}
} else if((uip_connr->tcpstateflags & UIP_TS_MASK) == UIP_ESTABLISHED) {
/* If there was no need for a retransmission, we poll the
/* If there was no need for a retransmission, we poll the
application for new data. */
uip_flags = UIP_POLL;
UIP_APPCALL();
goto appsend;
uip_flags = UIP_POLL;
UIP_APPCALL();
goto appsend;
}
}
goto drop;
@ -928,14 +927,14 @@ uip_process(u8_t flag)
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 {
UIP_LOG("ip: packet shorter than reported in IP header.");
@ -982,7 +981,7 @@ uip_process(u8_t flag)
if(BUF->proto == UIP_PROTO_UDP &&
uip_ipaddr_cmp(BUF->destipaddr, all_ones_addr)
/*&&
uip_ipchksum() == 0xffff*/) {
uip_ipchksum() == 0xffff*/) {
goto udp_input;
}
#endif /* UIP_BROADCAST */
@ -1009,7 +1008,7 @@ uip_process(u8_t flag)
#if !UIP_CONF_IPV6
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.");
@ -1019,8 +1018,8 @@ uip_process(u8_t flag)
#if UIP_TCP
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;
}
#endif /* UIP_TCP */
@ -1034,7 +1033,7 @@ uip_process(u8_t flag)
#if !UIP_CONF_IPV6
/* ICMPv4 processing code follows. */
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.");
@ -1088,7 +1087,7 @@ uip_process(u8_t flag)
DEBUG_PRINTF("icmp6_input: length %d\n", uip_len);
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.");
@ -1103,12 +1102,12 @@ uip_process(u8_t flag)
if(uip_ipaddr_cmp(ICMPBUF->icmp6data, uip_hostaddr)) {
if(ICMPBUF->options[0] == ICMP6_OPTION_SOURCE_LINK_ADDRESS) {
/* Save the sender's address in our neighbor list. */
uip_neighbor_add(ICMPBUF->srcipaddr, &(ICMPBUF->options[2]));
/* Save the sender's address in our neighbor list. */
uip_neighbor_add(ICMPBUF->srcipaddr, &(ICMPBUF->options[2]));
}
/* 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. */
@ -1188,8 +1187,8 @@ uip_process(u8_t flag)
UDPBUF->srcport == uip_udp_conn->rport ||
uip_udp_conn->rport == HTONS(69)) &&
(uip_ipaddr_cmp(uip_udp_conn->ripaddr, all_zeroes_addr) ||
uip_ipaddr_cmp(uip_udp_conn->ripaddr, all_ones_addr) ||
uip_ipaddr_cmp(BUF->srcipaddr, uip_udp_conn->ripaddr))) {
uip_ipaddr_cmp(uip_udp_conn->ripaddr, all_ones_addr) ||
uip_ipaddr_cmp(BUF->srcipaddr, uip_udp_conn->ripaddr))) {
goto udp_found;
}
}
@ -1253,7 +1252,7 @@ uip_process(u8_t flag)
/* Start of TCP input header processing code. */
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.");
@ -1326,7 +1325,7 @@ uip_process(u8_t flag)
if(++BUF->ackno[3] == 0) {
if(++BUF->ackno[2] == 0) {
if(++BUF->ackno[1] == 0) {
++BUF->ackno[0];
++BUF->ackno[0];
}
}
}
@ -1361,8 +1360,8 @@ uip_process(u8_t flag)
}
if(uip_conns[c].tcpstateflags == UIP_TIME_WAIT) {
if(uip_connr == 0 ||
uip_conns[c].timer > uip_connr->timer) {
uip_connr = &uip_conns[c];
uip_conns[c].timer > uip_connr->timer) {
uip_connr = &uip_conns[c];
}
}
}
@ -1405,30 +1404,30 @@ uip_process(u8_t flag)
for(c = 0; c < ((BUF->tcpoffset >> 4) - 5) << 2 ;) {
opt = uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + c];
if(opt == TCP_OPT_END) {
/* End of options. */
break;
/* End of options. */
break;
} else if(opt == TCP_OPT_NOOP) {
++c;
/* NOP option. */
++c;
/* NOP option. */
} else if(opt == TCP_OPT_MSS &&
uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c] == TCP_OPT_MSS_LEN) {
/* An MSS option with the right option length. */
tmp16 = ((u16_t)uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 2 + c] << 8) |
(u16_t)uip_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN + 3 + c];
uip_connr->initialmss = uip_connr->mss =
tmp16 > UIP_TCP_MSS? UIP_TCP_MSS: tmp16;
uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c] == TCP_OPT_MSS_LEN) {
/* An MSS option with the right option length. */
tmp16 = ((u16_t)uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 2 + c] << 8) |
(u16_t)uip_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN + 3 + c];
uip_connr->initialmss = uip_connr->mss =
tmp16 > UIP_TCP_MSS? UIP_TCP_MSS: tmp16;
/* And we are done processing options. */
break;
/* And we are done processing options. */
break;
} else {
/* All other options have a length field, so that we easily
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. */
break;
}
c += uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c];
/* All other options have a length field, so that we easily
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. */
break;
}
c += uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c];
}
}
}
@ -1485,9 +1484,9 @@ uip_process(u8_t flag)
((BUF->flags & TCP_CTL) == (TCP_SYN | TCP_ACK)))) {
if((uip_len > 0 || ((BUF->flags & (TCP_SYN | TCP_FIN)) != 0)) &&
(BUF->seqno[0] != uip_connr->rcv_nxt[0] ||
BUF->seqno[1] != uip_connr->rcv_nxt[1] ||
BUF->seqno[2] != uip_connr->rcv_nxt[2] ||
BUF->seqno[3] != uip_connr->rcv_nxt[3])) {
BUF->seqno[1] != uip_connr->rcv_nxt[1] ||
BUF->seqno[2] != uip_connr->rcv_nxt[2] ||
BUF->seqno[3] != uip_connr->rcv_nxt[3])) {
goto tcp_send_ack;
}
}
@ -1512,17 +1511,17 @@ uip_process(u8_t flag)
/* Do RTT estimation, unless we have done retransmissions. */
if(uip_connr->nrtx == 0) {
signed char m;
m = uip_connr->rto - uip_connr->timer;
/* This is taken directly from VJs original code in his paper */
m = m - (uip_connr->sa >> 3);
uip_connr->sa += m;
if(m < 0) {
m = -m;
}
m = m - (uip_connr->sv >> 2);
uip_connr->sv += m;
uip_connr->rto = (uip_connr->sa >> 3) + uip_connr->sv;
signed char m;
m = uip_connr->rto - uip_connr->timer;
/* This is taken directly from VJs original code in his paper */
m = m - (uip_connr->sa >> 3);
uip_connr->sa += m;
if(m < 0) {
m = -m;
}
m = m - (uip_connr->sv >> 2);
uip_connr->sv += m;
uip_connr->rto = (uip_connr->sa >> 3) + uip_connr->sv;
}
/* Set the acknowledged flag. */
@ -1539,9 +1538,9 @@ uip_process(u8_t flag)
/* 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
@ -1571,35 +1570,35 @@ uip_process(u8_t flag)
/* Parse the TCP MSS option, if present. */
if((BUF->tcpoffset & 0xf0) > 0x50) {
for(c = 0; c < ((BUF->tcpoffset >> 4) - 5) << 2 ;) {
opt = uip_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN + c];
if(opt == TCP_OPT_END) {
/* End of options. */
break;
} else if(opt == TCP_OPT_NOOP) {
++c;
/* NOP option. */
} else if(opt == TCP_OPT_MSS &&
uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c] == TCP_OPT_MSS_LEN) {
/* An MSS option with the right option length. */
tmp16 = (uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 2 + c] << 8) |
uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 3 + c];
uip_connr->initialmss =
uip_connr->mss = tmp16 > UIP_TCP_MSS? UIP_TCP_MSS: tmp16;
for(c = 0; c < ((BUF->tcpoffset >> 4) - 5) << 2 ;) {
opt = uip_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN + c];
if(opt == TCP_OPT_END) {
/* End of options. */
break;
} else if(opt == TCP_OPT_NOOP) {
++c;
/* NOP option. */
} else if(opt == TCP_OPT_MSS &&
uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c] == TCP_OPT_MSS_LEN) {
/* An MSS option with the right option length. */
tmp16 = (uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 2 + c] << 8) |
uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 3 + c];
uip_connr->initialmss =
uip_connr->mss = tmp16 > UIP_TCP_MSS? UIP_TCP_MSS: tmp16;
/* And we are done processing options. */
break;
} else {
/* All other options have a length field, so that we easily
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. */
break;
}
c += uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c];
}
}
/* And we are done processing options. */
break;
} else {
/* All other options have a length field, so that we easily
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. */
break;
}
c += uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c];
}
}
}
uip_connr->tcpstateflags = UIP_ESTABLISHED;
uip_connr->rcv_nxt[0] = BUF->seqno[0];
@ -1636,12 +1635,12 @@ uip_process(u8_t flag)
if(BUF->flags & TCP_FIN && !(uip_connr->tcpstateflags & UIP_STOPPED)) {
if(uip_outstanding(uip_connr)) {
goto drop;
goto drop;
}
uip_add_rcv_nxt(1 + uip_len);
uip_flags |= UIP_CLOSE;
if(uip_len > 0) {
uip_flags |= UIP_NEWDATA;
uip_flags |= UIP_NEWDATA;
}
UIP_APPCALL();
uip_connr->len = 1;
@ -1658,8 +1657,8 @@ uip_process(u8_t flag)
#if UIP_URGDATA > 0
uip_urglen = (BUF->urgp[0] << 8) | BUF->urgp[1];
if(uip_urglen > uip_len) {
/* There is more urgent data in the next segment to come. */
uip_urglen = uip_len;
/* There is more urgent data in the next segment to come. */
uip_urglen = uip_len;
}
uip_add_rcv_nxt(uip_urglen);
uip_len -= uip_urglen;
@ -1725,52 +1724,52 @@ uip_process(u8_t flag)
appsend:
if(uip_flags & UIP_ABORT) {
uip_slen = 0;
uip_connr->tcpstateflags = UIP_CLOSED;
BUF->flags = TCP_RST | TCP_ACK;
goto tcp_send_nodata;
uip_slen = 0;
uip_connr->tcpstateflags = UIP_CLOSED;
BUF->flags = TCP_RST | TCP_ACK;
goto tcp_send_nodata;
}
if(uip_flags & UIP_CLOSE) {
uip_slen = 0;
uip_connr->len = 1;
uip_connr->tcpstateflags = UIP_FIN_WAIT_1;
uip_connr->nrtx = 0;
BUF->flags = TCP_FIN | TCP_ACK;
goto tcp_send_nodata;
uip_slen = 0;
uip_connr->len = 1;
uip_connr->tcpstateflags = UIP_FIN_WAIT_1;
uip_connr->nrtx = 0;
BUF->flags = TCP_FIN | TCP_ACK;
goto tcp_send_nodata;
}
/* If uip_slen > 0, the application has data to be sent. */
if(uip_slen > 0) {
/* If the connection has acknowledged data, the contents of
the ->len variable should be discarded. */
if((uip_flags & UIP_ACKDATA) != 0) {
uip_connr->len = 0;
}
/* If the connection has acknowledged data, the contents of
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. */
if(uip_connr->len == 0) {
/* If the ->len variable is non-zero the connection has
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). */
if(uip_slen > uip_connr->mss) {
uip_slen = uip_connr->mss;
}
/* The application cannot send more than what is allowed by
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. */
uip_connr->len = uip_slen;
} else {
/* Remember how much data we send out now so that we know
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. */
uip_slen = uip_connr->len;
}
/* 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. */
uip_slen = uip_connr->len;
}
}
uip_connr->nrtx = 0;
apprexmit:
@ -1779,19 +1778,19 @@ uip_process(u8_t flag)
/* If the application has data to be sent, or if the incoming
packet had new data in it, we must send out a packet. */
if(uip_slen > 0 && uip_connr->len > 0) {
/* Add the length of the IP and TCP headers. */
uip_len = uip_connr->len + UIP_TCPIP_HLEN;
/* We always set the ACK flag in response packets. */
BUF->flags = TCP_ACK | TCP_PSH;
/* Send the packet. */
goto tcp_send_noopts;
/* Add the length of the IP and TCP headers. */
uip_len = uip_connr->len + UIP_TCPIP_HLEN;
/* We always set the ACK flag in response packets. */
BUF->flags = TCP_ACK | TCP_PSH;
/* Send the packet. */
goto tcp_send_noopts;
}
/* 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;
goto tcp_send_noopts;
uip_len = UIP_TCPIP_HLEN;
BUF->flags = TCP_ACK;
goto tcp_send_noopts;
}
}
goto drop;
@ -1814,11 +1813,11 @@ uip_process(u8_t flag)
}
if(BUF->flags & TCP_FIN) {
if(uip_flags & UIP_ACKDATA) {
uip_connr->tcpstateflags = UIP_TIME_WAIT;
uip_connr->timer = 0;
uip_connr->len = 0;
uip_connr->tcpstateflags = UIP_TIME_WAIT;
uip_connr->timer = 0;
uip_connr->len = 0;
} else {
uip_connr->tcpstateflags = UIP_CLOSING;
uip_connr->tcpstateflags = UIP_CLOSING;
}
uip_add_rcv_nxt(1);
uip_flags = UIP_CLOSE;
@ -1944,7 +1943,7 @@ uip_process(u8_t flag)
UIP_STAT(++uip_stat.tcp.sent);
send:
DEBUG_PRINTF("Sending packet with length %d (%d)\n", uip_len,
(BUF->len[0] << 8) | BUF->len[1]);
(BUF->len[0] << 8) | BUF->len[1]);
UIP_STAT(++uip_stat.ip.sent);
/* Return and let the caller do the actual transmission. */

View File

@ -242,12 +242,12 @@ void uip_setipid(u16_t id);
uip_input();
if(uip_len > 0) {
uip_arp_out();
ethernet_devicedriver_send();
ethernet_devicedriver_send();
}
} else if(BUF->type == HTONS(UIP_ETHTYPE_ARP)) {
uip_arp_arpin();
if(uip_len > 0) {
ethernet_devicedriver_send();
ethernet_devicedriver_send();
}
}
\endcode
@ -926,7 +926,7 @@ struct uip_udp_conn *uip_udp_new(uip_ipaddr_t *ripaddr, u16_t rport);
*/
#if !UIP_CONF_IPV6
#define uip_ipaddr_cmp(addr1, addr2) (((u16_t *)addr1)[0] == ((u16_t *)addr2)[0] && \
((u16_t *)addr1)[1] == ((u16_t *)addr2)[1])
((u16_t *)addr1)[1] == ((u16_t *)addr2)[1])
#else /* !UIP_CONF_IPV6 */
#define uip_ipaddr_cmp(addr1, addr2) (memcmp(addr1, addr2, sizeof(uip_ip6addr_t)) == 0)
#endif /* !UIP_CONF_IPV6 */
@ -1173,26 +1173,26 @@ struct uip_conn {
u16_t lport; /**< The local TCP port, in network byte order. */
u16_t rport; /**< The local remote TCP port, in network byte
order. */
order. */
u8_t rcv_nxt[4]; /**< The sequence number that we expect to
receive next. */
receive next. */
u8_t snd_nxt[4]; /**< The sequence number that was last sent by
us. */
u16_t len; /**< Length of the data that was previously sent. */
u16_t mss; /**< Current maximum segment size for the
connection. */
connection. */
u16_t initialmss; /**< Initial maximum segment size for the
connection. */
connection. */
u8_t sa; /**< Retransmission time-out calculation state
variable. */
variable. */
u8_t sv; /**< Retransmission time-out calculation state
variable. */
variable. */
u8_t rto; /**< Retransmission time-out. */
u8_t tcpstateflags; /**< TCP state and flags. */
u8_t timer; /**< The retransmission timer. */
u8_t nrtx; /**< The number of retransmissions for the last
segment sent. */
segment sent. */
/** The application state. */
uip_tcp_appstate_t appstate;
@ -1253,30 +1253,30 @@ extern struct uip_udp_conn uip_udp_conns[UIP_UDP_CONNS];
struct uip_stats {
struct {
uip_stats_t drop; /**< Number of dropped packets at the IP
layer. */
layer. */
uip_stats_t recv; /**< Number of received packets at the IP
layer. */
layer. */
uip_stats_t sent; /**< Number of sent packets at the IP
layer. */
layer. */
uip_stats_t vhlerr; /**< Number of packets dropped due to wrong
IP version or header length. */
IP version or header length. */
uip_stats_t hblenerr; /**< Number of packets dropped due to wrong
IP length, high byte. */
IP length, high byte. */
uip_stats_t lblenerr; /**< Number of packets dropped due to wrong
IP length, low byte. */
IP length, low byte. */
uip_stats_t fragerr; /**< Number of packets dropped since they
were IP fragments. */
were IP fragments. */
uip_stats_t chkerr; /**< Number of packets dropped due to IP
checksum errors. */
checksum errors. */
uip_stats_t protoerr; /**< Number of packets dropped since they
were neither ICMP, UDP nor TCP. */
were neither ICMP, UDP nor TCP. */
} ip; /**< IP statistics. */
struct {
uip_stats_t drop; /**< Number of dropped ICMP packets. */
uip_stats_t recv; /**< Number of received ICMP packets. */
uip_stats_t sent; /**< Number of sent ICMP packets. */
uip_stats_t typeerr; /**< Number of ICMP packets with a wrong
type. */
type. */
} icmp; /**< ICMP statistics. */
#if UIP_TCP
struct {
@ -1284,15 +1284,15 @@ struct uip_stats {
uip_stats_t recv; /**< Number of recived TCP segments. */
uip_stats_t sent; /**< Number of sent TCP segments. */
uip_stats_t chkerr; /**< Number of TCP segments with a bad
checksum. */
checksum. */
uip_stats_t ackerr; /**< Number of TCP segments with a bad ACK
number. */
number. */
uip_stats_t rst; /**< Number of recevied TCP RST (reset) segments. */
uip_stats_t rexmit; /**< Number of retransmitted TCP segments. */
uip_stats_t syndrop; /**< Number of dropped SYNs due to too few
connections was avaliable. */
connections was avaliable. */
uip_stats_t synrst; /**< Number of SYNs for closed ports,
triggering a RST. */
triggering a RST. */
} tcp; /**< TCP statistics. */
#endif /* UIP_TCP */
#if UIP_UDP
@ -1301,7 +1301,7 @@ struct uip_stats {
uip_stats_t recv; /**< Number of recived UDP segments. */
uip_stats_t sent; /**< Number of sent UDP segments. */
uip_stats_t chkerr; /**< Number of UDP segments with a bad
checksum. */
checksum. */
} udp; /**< UDP statistics. */
#endif /* UIP_UDP */
};
@ -1335,33 +1335,33 @@ extern u8_t uip_flags;
functions/macros. */
#define UIP_ACKDATA 1 /* Signifies that the outstanding data was
acked and the application should send
out new data instead of retransmitting
the last data. */
acked and the application should send
out new data instead of retransmitting
the last data. */
#define UIP_NEWDATA 2 /* Flags the fact that the peer has sent
us new data. */
us new data. */
#define UIP_REXMIT 4 /* Tells the application to retransmit the
data that was last sent. */
data that was last sent. */
#define UIP_POLL 8 /* Used for polling the application, to
check if the application has data that
it wants to send. */
check if the application has data that
it wants to send. */
#define UIP_CLOSE 16 /* The remote host has closed the
connection, thus the connection has
gone away. Or the application signals
that it wants to close the
connection. */
connection, thus the connection has
gone away. Or the application signals
that it wants to close the
connection. */
#define UIP_ABORT 32 /* The remote host has aborted the
connection, thus the connection has
gone away. Or the application signals
that it wants to abort the
connection. */
connection, thus the connection has
gone away. Or the application signals
that it wants to abort the
connection. */
#define UIP_CONNECTED 64 /* We have got a connection from a remote
host and have set up a new connection
for it, or an active connection has
been successfully established. */
#define UIP_TIMEDOUT 128 /* The connection has been aborted due to
too many retransmissions. */
too many retransmissions. */
/* uip_process(flag):
*
@ -1377,16 +1377,16 @@ void uip_process(u8_t flag);
the macrose defined in this file. */
#define UIP_DATA 1 /* Tells uIP that there is incoming
data in the uip_buf buffer. The
length of the data is stored in the
global variable uip_len. */
data in the uip_buf buffer. The
length of the data is stored in the
global variable uip_len. */
#define UIP_TIMER 2 /* Tells uIP that the periodic timer
has fired. */
has fired. */
#define UIP_POLL_REQUEST 3 /* Tells uIP that a connection should
be polled. */
be polled. */
#define UIP_UDP_SEND_CONN 4 /* Tells uIP that a UDP datagram
should be constructed in the
uip_buf buffer. */
should be constructed in the
uip_buf buffer. */
#if UIP_UDP
#define UIP_UDP_TIMER 5
#endif /* UIP_UDP */
@ -1544,11 +1544,11 @@ struct uip_udpip_hdr {
#define UIP_UDPH_LEN 8 /* Size of UDP header */
#define UIP_TCPH_LEN 20 /* Size of TCP header */
#define UIP_IPUDPH_LEN (UIP_UDPH_LEN + UIP_IPH_LEN) /* Size of IP +
UDP
header */
UDP
header */
#define UIP_IPTCPH_LEN (UIP_TCPH_LEN + UIP_IPH_LEN) /* Size of IP +
TCP
header */
TCP
header */
#define UIP_TCPIP_HLEN UIP_IPTCPH_LEN

View File

@ -174,13 +174,13 @@ uip_arp_update(u16_t *ipaddr, struct uip_eth_addr *ethaddr)
/* Check if the source IP address of the incoming packet matches
the IP address in this ARP table entry. */
if(ipaddr[0] == tabptr->ipaddr[0] &&
ipaddr[1] == tabptr->ipaddr[1]) {
ipaddr[1] == tabptr->ipaddr[1]) {
/* An old entry found, update this and return. */
memcpy(tabptr->ethaddr.addr, ethaddr->addr, 6);
tabptr->time = arptime;
/* An old entry found, update this and return. */
memcpy(tabptr->ethaddr.addr, ethaddr->addr, 6);
tabptr->time = arptime;
return;
return;
}
}
}
@ -205,8 +205,8 @@ uip_arp_update(u16_t *ipaddr, struct uip_eth_addr *ethaddr)
for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
tabptr = &arp_table[i];
if(arptime - tabptr->time > tmpage) {
tmpage = arptime - tabptr->time;
c = i;
tmpage = arptime - tabptr->time;
c = i;
}
}
i = c;
@ -293,8 +293,8 @@ uip_arp_arpin(void)
reply. */
if(uip_ipaddr_cmp(BUF->dipaddr, uip_hostaddr)) {
/* First, we register the one who made the request in our ARP
table, since it is likely that we will do more communication
with this host in the future. */
table, since it is likely that we will do more communication
with this host in the future. */
uip_arp_update(BUF->sipaddr, &BUF->shwaddr);
/* The reply opcode is 2. */
@ -372,8 +372,8 @@ uip_arp_out(void)
/* Check if the destination address is on the local network. */
if(!uip_ipaddr_maskcmp(IPBUF->destipaddr, uip_hostaddr, uip_netmask)) {
/* Destination address was not on the local network, so we need to
use the default router's IP address instead of the destination
address when determining the MAC address. */
use the default router's IP address instead of the destination
address when determining the MAC address. */
uip_ipaddr_copy(ipaddr, uip_draddr);
} else {
/* Else, we use the destination IP address. */
@ -383,13 +383,13 @@ uip_arp_out(void)
for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
tabptr = &arp_table[i];
if(uip_ipaddr_cmp(ipaddr, tabptr->ipaddr)) {
break;
break;
}
}
if(i == UIP_ARPTAB_SIZE) {
/* The destination address was not in our ARP table, so we
overwrite the IP packet with an ARP request. */
overwrite the IP packet with an ARP request. */
memset(BUF->ethhdr.dest.addr, 0xff, 6);
memset(BUF->dhwaddr.addr, 0x00, 6);

View File

@ -57,16 +57,16 @@ uiplib_ipaddrconv(char *addrstr, unsigned char *ipaddr)
c = *addrstr;
++j;
if(j > 4) {
return 0;
return 0;
}
if(c == '.' || c == 0) {
*ipaddr = tmp;
++ipaddr;
tmp = 0;
*ipaddr = tmp;
++ipaddr;
tmp = 0;
} else if(c >= '0' && c <= '9') {
tmp = (tmp * 10) + (c - '0');
tmp = (tmp * 10) + (c - '0');
} else {
return 0;
return 0;
}
++addrstr;
} while(c != '.' && c != 0);