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:
parent
a6b5f865d5
commit
a3170a953d
@ -276,17 +276,17 @@ PT_THREAD(handle_dhcp(void))
|
|||||||
s.timer_init = platform_timer_op( ELUA_DHCP_TIMER_ID, PLATFORM_TIMER_OP_START, 0 );
|
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 );
|
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) {
|
if(uip_newdata() && parse_msg() == DHCPOFFER) {
|
||||||
uip_flags &= ~UIP_NEWDATA;
|
uip_flags &= ~UIP_NEWDATA;
|
||||||
s.state = STATE_OFFER_RECEIVED;
|
s.state = STATE_OFFER_RECEIVED;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
uip_flags &= ~UIP_NEWDATA;
|
uip_flags &= ~UIP_NEWDATA;
|
||||||
if(s.ticks < CLOCK_SECOND * 60) {
|
if(s.ticks < CLOCK_SECOND * 60) {
|
||||||
s.ticks *= 2;
|
s.ticks *= 2;
|
||||||
} else {
|
} else {
|
||||||
s.ipaddr[0] = 0;
|
s.ipaddr[0] = 0;
|
||||||
goto dhcp_failed;
|
goto dhcp_failed;
|
||||||
}
|
}
|
||||||
} while(s.state != STATE_OFFER_RECEIVED);
|
} while(s.state != STATE_OFFER_RECEIVED);
|
||||||
|
|
||||||
s.ticks = CLOCK_SECOND;
|
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 );
|
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) {
|
if(uip_newdata() && parse_msg() == DHCPACK) {
|
||||||
uip_flags &= ~UIP_NEWDATA;
|
uip_flags &= ~UIP_NEWDATA;
|
||||||
s.state = STATE_CONFIG_RECEIVED;
|
s.state = STATE_CONFIG_RECEIVED;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,7 @@
|
|||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static void
|
static void
|
||||||
buf_setup(struct psock_buf *buf,
|
buf_setup(struct psock_buf *buf,
|
||||||
u8_t *bufptr, u16_t bufsize)
|
u8_t *bufptr, u16_t bufsize)
|
||||||
{
|
{
|
||||||
buf->ptr = bufptr;
|
buf->ptr = bufptr;
|
||||||
buf->left = bufsize;
|
buf->left = bufsize;
|
||||||
@ -84,7 +84,7 @@ buf_setup(struct psock_buf *buf,
|
|||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static u8_t
|
static u8_t
|
||||||
buf_bufdata(struct psock_buf *buf, u16_t len,
|
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) {
|
if(*datalen < buf->left) {
|
||||||
memcpy(buf->ptr, *dataptr, *datalen);
|
memcpy(buf->ptr, *dataptr, *datalen);
|
||||||
@ -112,7 +112,7 @@ buf_bufdata(struct psock_buf *buf, u16_t len,
|
|||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static u8_t
|
static u8_t
|
||||||
buf_bufto(register struct psock_buf *buf, u8_t endmarker,
|
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;
|
u8_t c;
|
||||||
while(buf->left > 0 && *datalen > 0) {
|
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,
|
PT_THREAD(psock_send(register struct psock *s, const char *buf,
|
||||||
unsigned int len))
|
unsigned int len))
|
||||||
{
|
{
|
||||||
PT_BEGIN(&s->psockpt);
|
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,
|
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);
|
PT_BEGIN(&s->psockpt);
|
||||||
|
|
||||||
@ -289,8 +289,8 @@ PT_THREAD(psock_readto(register struct psock *psock, unsigned char c))
|
|||||||
psock->readlen = uip_datalen();
|
psock->readlen = uip_datalen();
|
||||||
}
|
}
|
||||||
} while((buf_bufto(&psock->buf, c,
|
} while((buf_bufto(&psock->buf, c,
|
||||||
&psock->readptr,
|
&psock->readptr,
|
||||||
&psock->readlen) & BUF_FOUND) == 0);
|
&psock->readlen) & BUF_FOUND) == 0);
|
||||||
|
|
||||||
if(psock_datalen(psock) == 0) {
|
if(psock_datalen(psock) == 0) {
|
||||||
psock->state = STATE_NONE;
|
psock->state = STATE_NONE;
|
||||||
@ -317,8 +317,8 @@ PT_THREAD(psock_readbuf(register struct psock *psock))
|
|||||||
psock->readlen = uip_datalen();
|
psock->readlen = uip_datalen();
|
||||||
}
|
}
|
||||||
} while(buf_bufdata(&psock->buf, psock->bufsize,
|
} while(buf_bufdata(&psock->buf, psock->bufsize,
|
||||||
&psock->readptr,
|
&psock->readptr,
|
||||||
&psock->readlen) != BUF_FULL);
|
&psock->readlen) != BUF_FULL);
|
||||||
|
|
||||||
if(psock_datalen(psock) == 0) {
|
if(psock_datalen(psock) == 0) {
|
||||||
psock->state = STATE_NONE;
|
psock->state = STATE_NONE;
|
||||||
|
@ -105,19 +105,19 @@ struct psock_buf {
|
|||||||
*/
|
*/
|
||||||
struct psock {
|
struct psock {
|
||||||
struct pt pt, psockpt; /* Protothreads - one that's using the psock
|
struct pt pt, psockpt; /* Protothreads - one that's using the psock
|
||||||
functions, and one that runs inside the
|
functions, and one that runs inside the
|
||||||
psock functions. */
|
psock functions. */
|
||||||
const u8_t *sendptr; /* Pointer to the next data to be sent. */
|
const u8_t *sendptr; /* Pointer to the next data to be sent. */
|
||||||
u8_t *readptr; /* Pointer to the next data to be read. */
|
u8_t *readptr; /* Pointer to the next data to be read. */
|
||||||
|
|
||||||
char *bufptr; /* Pointer to the buffer used for buffering
|
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 sendlen; /* The number of bytes left to be sent. */
|
||||||
u16_t readlen; /* The number of bytes left to be read. */
|
u16_t readlen; /* The number of bytes left to be read. */
|
||||||
|
|
||||||
struct psock_buf buf; /* The structure holding the state of the
|
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 int bufsize; /* The size of the input buffer. */
|
||||||
|
|
||||||
unsigned char state; /* The state of the protosocket. */
|
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
|
* \hideinitializer
|
||||||
*/
|
*/
|
||||||
#define PSOCK_SEND(psock, data, datalen) \
|
#define PSOCK_SEND(psock, data, datalen) \
|
||||||
PT_WAIT_THREAD(&((psock)->pt), 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
|
* \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_WAIT_THREAD(&((psock)->pt), psock_send(psock, str, strlen(str)))
|
||||||
|
|
||||||
PT_THREAD(psock_generator_send(struct psock *psock,
|
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
|
* \brief Generate data with a function and send it
|
||||||
@ -216,9 +216,9 @@ PT_THREAD(psock_generator_send(struct psock *psock,
|
|||||||
*
|
*
|
||||||
* \hideinitializer
|
* \hideinitializer
|
||||||
*/
|
*/
|
||||||
#define PSOCK_GENERATOR_SEND(psock, generator, arg) \
|
#define PSOCK_GENERATOR_SEND(psock, generator, arg) \
|
||||||
PT_WAIT_THREAD(&((psock)->pt), \
|
PT_WAIT_THREAD(&((psock)->pt), \
|
||||||
psock_generator_send(psock, generator, arg))
|
psock_generator_send(psock, generator, arg))
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -247,7 +247,7 @@ PT_THREAD(psock_readbuf(struct psock *psock));
|
|||||||
*
|
*
|
||||||
* \hideinitializer
|
* \hideinitializer
|
||||||
*/
|
*/
|
||||||
#define PSOCK_READBUF(psock) \
|
#define PSOCK_READBUF(psock) \
|
||||||
PT_WAIT_THREAD(&((psock)->pt), psock_readbuf(psock))
|
PT_WAIT_THREAD(&((psock)->pt), psock_readbuf(psock))
|
||||||
|
|
||||||
PT_THREAD(psock_readto(struct psock *psock, unsigned char c));
|
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
|
* \hideinitializer
|
||||||
*/
|
*/
|
||||||
#define PSOCK_READTO(psock, c) \
|
#define PSOCK_READTO(psock, c) \
|
||||||
PT_WAIT_THREAD(&((psock)->pt), 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
|
* \hideinitializer
|
||||||
*/
|
*/
|
||||||
#define PSOCK_CLOSE_EXIT(psock) \
|
#define PSOCK_CLOSE_EXIT(psock) \
|
||||||
do { \
|
do { \
|
||||||
PSOCK_CLOSE(psock); \
|
PSOCK_CLOSE(psock); \
|
||||||
PSOCK_EXIT(psock); \
|
PSOCK_EXIT(psock); \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
64
src/uip/pt.h
64
src/uip/pt.h
@ -145,12 +145,12 @@ struct pt {
|
|||||||
*
|
*
|
||||||
* \hideinitializer
|
* \hideinitializer
|
||||||
*/
|
*/
|
||||||
#define PT_WAIT_UNTIL(pt, condition) \
|
#define PT_WAIT_UNTIL(pt, condition) \
|
||||||
do { \
|
do { \
|
||||||
LC_SET((pt)->lc); \
|
LC_SET((pt)->lc); \
|
||||||
if(!(condition)) { \
|
if(!(condition)) { \
|
||||||
return PT_WAITING; \
|
return PT_WAITING; \
|
||||||
} \
|
} \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -203,10 +203,10 @@ struct pt {
|
|||||||
*
|
*
|
||||||
* \hideinitializer
|
* \hideinitializer
|
||||||
*/
|
*/
|
||||||
#define PT_SPAWN(pt, child, thread) \
|
#define PT_SPAWN(pt, child, thread) \
|
||||||
do { \
|
do { \
|
||||||
PT_INIT((child)); \
|
PT_INIT((child)); \
|
||||||
PT_WAIT_THREAD((pt), (thread)); \
|
PT_WAIT_THREAD((pt), (thread)); \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
@ -226,10 +226,10 @@ struct pt {
|
|||||||
*
|
*
|
||||||
* \hideinitializer
|
* \hideinitializer
|
||||||
*/
|
*/
|
||||||
#define PT_RESTART(pt) \
|
#define PT_RESTART(pt) \
|
||||||
do { \
|
do { \
|
||||||
PT_INIT(pt); \
|
PT_INIT(pt); \
|
||||||
return PT_WAITING; \
|
return PT_WAITING; \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -243,10 +243,10 @@ struct pt {
|
|||||||
*
|
*
|
||||||
* \hideinitializer
|
* \hideinitializer
|
||||||
*/
|
*/
|
||||||
#define PT_EXIT(pt) \
|
#define PT_EXIT(pt) \
|
||||||
do { \
|
do { \
|
||||||
PT_INIT(pt); \
|
PT_INIT(pt); \
|
||||||
return PT_EXITED; \
|
return PT_EXITED; \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
@ -287,13 +287,13 @@ struct pt {
|
|||||||
*
|
*
|
||||||
* \hideinitializer
|
* \hideinitializer
|
||||||
*/
|
*/
|
||||||
#define PT_YIELD(pt) \
|
#define PT_YIELD(pt) \
|
||||||
do { \
|
do { \
|
||||||
PT_YIELD_FLAG = 0; \
|
PT_YIELD_FLAG = 0; \
|
||||||
LC_SET((pt)->lc); \
|
LC_SET((pt)->lc); \
|
||||||
if(PT_YIELD_FLAG == 0) { \
|
if(PT_YIELD_FLAG == 0) { \
|
||||||
return PT_YIELDED; \
|
return PT_YIELDED; \
|
||||||
} \
|
} \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -307,13 +307,13 @@ struct pt {
|
|||||||
*
|
*
|
||||||
* \hideinitializer
|
* \hideinitializer
|
||||||
*/
|
*/
|
||||||
#define PT_YIELD_UNTIL(pt, cond) \
|
#define PT_YIELD_UNTIL(pt, cond) \
|
||||||
do { \
|
do { \
|
||||||
PT_YIELD_FLAG = 0; \
|
PT_YIELD_FLAG = 0; \
|
||||||
LC_SET((pt)->lc); \
|
LC_SET((pt)->lc); \
|
||||||
if((PT_YIELD_FLAG == 0) || !(cond)) { \
|
if((PT_YIELD_FLAG == 0) || !(cond)) { \
|
||||||
return PT_YIELDED; \
|
return PT_YIELDED; \
|
||||||
} \
|
} \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
104
src/uip/resolv.c
104
src/uip/resolv.c
@ -181,23 +181,23 @@ check_entries(void)
|
|||||||
if(namemapptr->state == STATE_NEW ||
|
if(namemapptr->state == STATE_NEW ||
|
||||||
namemapptr->state == STATE_ASKING) {
|
namemapptr->state == STATE_ASKING) {
|
||||||
if(namemapptr->state == STATE_ASKING) {
|
if(namemapptr->state == STATE_ASKING) {
|
||||||
if(--namemapptr->tmr == 0) {
|
if(--namemapptr->tmr == 0) {
|
||||||
if(++namemapptr->retries == MAX_RETRIES) {
|
if(++namemapptr->retries == MAX_RETRIES) {
|
||||||
namemapptr->state = STATE_ERROR;
|
namemapptr->state = STATE_ERROR;
|
||||||
resolv_found(namemapptr->name, NULL);
|
resolv_found(namemapptr->name, NULL);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
namemapptr->tmr = namemapptr->retries;
|
namemapptr->tmr = namemapptr->retries;
|
||||||
} else {
|
} else {
|
||||||
/* printf("Timer %d\n", namemapptr->tmr);*/
|
/* printf("Timer %d\n", namemapptr->tmr);*/
|
||||||
/* Its timer has not run out, so we move on to next
|
/* Its timer has not run out, so we move on to next
|
||||||
entry. */
|
entry. */
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
namemapptr->state = STATE_ASKING;
|
namemapptr->state = STATE_ASKING;
|
||||||
namemapptr->tmr = 1;
|
namemapptr->tmr = 1;
|
||||||
namemapptr->retries = 0;
|
namemapptr->retries = 0;
|
||||||
}
|
}
|
||||||
hdr = (struct dns_hdr *)uip_appdata;
|
hdr = (struct dns_hdr *)uip_appdata;
|
||||||
memset(hdr, 0, sizeof(struct dns_hdr));
|
memset(hdr, 0, sizeof(struct dns_hdr));
|
||||||
@ -209,20 +209,20 @@ check_entries(void)
|
|||||||
--nameptr;
|
--nameptr;
|
||||||
/* Convert hostname into suitable query format. */
|
/* Convert hostname into suitable query format. */
|
||||||
do {
|
do {
|
||||||
++nameptr;
|
++nameptr;
|
||||||
nptr = query;
|
nptr = query;
|
||||||
++query;
|
++query;
|
||||||
for(n = 0; *nameptr != '.' && *nameptr != 0; ++nameptr) {
|
for(n = 0; *nameptr != '.' && *nameptr != 0; ++nameptr) {
|
||||||
*query = *nameptr;
|
*query = *nameptr;
|
||||||
++query;
|
++query;
|
||||||
++n;
|
++n;
|
||||||
}
|
}
|
||||||
*nptr = n;
|
*nptr = n;
|
||||||
} while(*nameptr != 0);
|
} while(*nameptr != 0);
|
||||||
{
|
{
|
||||||
static unsigned char endquery[] =
|
static unsigned char endquery[] =
|
||||||
{0,0,1,0,1};
|
{0,0,1,0,1};
|
||||||
memcpy(query, endquery, 5);
|
memcpy(query, endquery, 5);
|
||||||
}
|
}
|
||||||
uip_udp_send((unsigned char)(query + 5 - (char *)uip_appdata));
|
uip_udp_send((unsigned char)(query + 5 - (char *)uip_appdata));
|
||||||
break;
|
break;
|
||||||
@ -285,40 +285,40 @@ newdata(void)
|
|||||||
|
|
||||||
while(nanswers > 0) {
|
while(nanswers > 0) {
|
||||||
/* The first byte in the answer resource record determines if it
|
/* 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) {
|
if(*nameptr & 0xc0) {
|
||||||
/* Compressed name. */
|
/* Compressed name. */
|
||||||
nameptr +=2;
|
nameptr +=2;
|
||||||
/* printf("Compressed anwser\n");*/
|
/* printf("Compressed anwser\n");*/
|
||||||
} else {
|
} else {
|
||||||
/* Not compressed name. */
|
/* Not compressed name. */
|
||||||
nameptr = parse_name(nameptr);
|
nameptr = parse_name(nameptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
ans = (struct dns_answer *)nameptr;
|
ans = (struct dns_answer *)nameptr;
|
||||||
/* printf("Answer: type %x, class %x, ttl %x, length %x\n",
|
/* printf("Answer: type %x, class %x, ttl %x, length %x\n",
|
||||||
htons(ans->type), htons(ans->class), (htons(ans->ttl[0])
|
htons(ans->type), htons(ans->class), (htons(ans->ttl[0])
|
||||||
<< 16) | htons(ans->ttl[1]), htons(ans->len));*/
|
<< 16) | htons(ans->ttl[1]), htons(ans->len));*/
|
||||||
|
|
||||||
/* Check for IP address type and Internet class. Others are
|
/* Check for IP address type and Internet class. Others are
|
||||||
discarded. */
|
discarded. */
|
||||||
if(ans->type == HTONS(1) &&
|
if(ans->type == HTONS(1) &&
|
||||||
ans->class == HTONS(1) &&
|
ans->class == HTONS(1) &&
|
||||||
ans->len == HTONS(4)) {
|
ans->len == HTONS(4)) {
|
||||||
/* printf("IP address %d.%d.%d.%d\n",
|
/* printf("IP address %d.%d.%d.%d\n",
|
||||||
htons(ans->ipaddr[0]) >> 8,
|
htons(ans->ipaddr[0]) >> 8,
|
||||||
htons(ans->ipaddr[0]) & 0xff,
|
htons(ans->ipaddr[0]) & 0xff,
|
||||||
htons(ans->ipaddr[1]) >> 8,
|
htons(ans->ipaddr[1]) >> 8,
|
||||||
htons(ans->ipaddr[1]) & 0xff);*/
|
htons(ans->ipaddr[1]) & 0xff);*/
|
||||||
/* XXX: we should really check that this IP address is the one
|
/* XXX: we should really check that this IP address is the one
|
||||||
we want. */
|
we want. */
|
||||||
namemapptr->ipaddr[0] = ans->ipaddr[0];
|
namemapptr->ipaddr[0] = ans->ipaddr[0];
|
||||||
namemapptr->ipaddr[1] = ans->ipaddr[1];
|
namemapptr->ipaddr[1] = ans->ipaddr[1];
|
||||||
|
|
||||||
resolv_found(namemapptr->name, namemapptr->ipaddr);
|
resolv_found(namemapptr->name, namemapptr->ipaddr);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
nameptr = nameptr + 10 + htons(ans->len);
|
nameptr = nameptr + 10 + htons(ans->len);
|
||||||
}
|
}
|
||||||
--nanswers;
|
--nanswers;
|
||||||
}
|
}
|
||||||
|
@ -331,7 +331,7 @@ find_netif(void)
|
|||||||
/* Walk through every network interface to check for a match. */
|
/* Walk through every network interface to check for a match. */
|
||||||
for(netif = netifs; netif != NULL; netif = netif->next) {
|
for(netif = netifs; netif != NULL; netif = netif->next) {
|
||||||
if(ipaddr_maskcmp(BUF->destipaddr, netif->ipaddr,
|
if(ipaddr_maskcmp(BUF->destipaddr, netif->ipaddr,
|
||||||
netif->netmask)) {
|
netif->netmask)) {
|
||||||
/* If there was a match, we break the loop. */
|
/* If there was a match, we break the loop. */
|
||||||
return netif;
|
return netif;
|
||||||
}
|
}
|
||||||
@ -385,8 +385,8 @@ uip_fw_output(void)
|
|||||||
|
|
||||||
netif = find_netif();
|
netif = find_netif();
|
||||||
/* printf("uip_fw_output: netif %p ->output %p len %d\n", netif,
|
/* printf("uip_fw_output: netif %p ->output %p len %d\n", netif,
|
||||||
netif->output,
|
netif->output,
|
||||||
uip_len);*/
|
uip_len);*/
|
||||||
|
|
||||||
if(netif == NULL) {
|
if(netif == NULL) {
|
||||||
return UIP_FW_NOROUTE;
|
return UIP_FW_NOROUTE;
|
||||||
|
@ -53,12 +53,12 @@
|
|||||||
*/
|
*/
|
||||||
struct uip_fw_netif {
|
struct uip_fw_netif {
|
||||||
struct uip_fw_netif *next; /**< Pointer to the next interface when
|
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 ipaddr[2]; /**< The IP address of this interface. */
|
||||||
u16_t netmask[2]; /**< The netmask of the interface. */
|
u16_t netmask[2]; /**< The netmask of the interface. */
|
||||||
u8_t (* output)(void);
|
u8_t (* output)(void);
|
||||||
/**< A pointer to the function that
|
/**< 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) \
|
#define UIP_FW_NETIF(ip1,ip2,ip3,ip4, nm1,nm2,nm3,nm4, outputfunc) \
|
||||||
NULL, \
|
NULL, \
|
||||||
{HTONS((ip1 << 8) | ip2), HTONS((ip3 << 8) | ip4)}, \
|
{HTONS((ip1 << 8) | ip2), HTONS((ip3 << 8) | ip4)}, \
|
||||||
{HTONS((nm1 << 8) | nm2), HTONS((nm3 << 8) | nm4)}, \
|
{HTONS((nm1 << 8) | nm2), HTONS((nm3 << 8) | nm4)}, \
|
||||||
outputfunc
|
outputfunc
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -91,8 +91,8 @@ uip_neighbor_add(uip_ipaddr_t ipaddr, struct uip_neighbor_addr *addr)
|
|||||||
u8_t oldest_time;
|
u8_t oldest_time;
|
||||||
|
|
||||||
/*printf("Adding neighbor with link address %02x:%02x:%02x:%02x:%02x:%02x\n",
|
/*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[0], addr->addr.addr[1], addr->addr.addr[2], addr->addr.addr[3],
|
||||||
addr->addr.addr[4], addr->addr.addr[5]);*/
|
addr->addr.addr[4], addr->addr.addr[5]);*/
|
||||||
|
|
||||||
/* Find the first unused entry or the oldest used entry. */
|
/* Find the first unused entry or the oldest used entry. */
|
||||||
oldest_time = 0;
|
oldest_time = 0;
|
||||||
@ -151,8 +151,8 @@ uip_neighbor_lookup(uip_ipaddr_t ipaddr)
|
|||||||
e = find_entry(ipaddr);
|
e = find_entry(ipaddr);
|
||||||
if(e != NULL) {
|
if(e != NULL) {
|
||||||
/* printf("Lookup neighbor with link address %02x:%02x:%02x:%02x:%02x:%02x\n",
|
/* 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[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[4], e->addr.addr.addr[5]);*/
|
||||||
|
|
||||||
return &e->addr;
|
return &e->addr;
|
||||||
}
|
}
|
||||||
|
525
src/uip/uip.c
525
src/uip/uip.c
@ -129,52 +129,51 @@ static const uip_ipaddr_t all_zeroes_addr =
|
|||||||
|
|
||||||
#if UIP_FIXEDETHADDR
|
#if UIP_FIXEDETHADDR
|
||||||
const struct uip_eth_addr uip_ethaddr = {{UIP_ETHADDR0,
|
const struct uip_eth_addr uip_ethaddr = {{UIP_ETHADDR0,
|
||||||
UIP_ETHADDR1,
|
UIP_ETHADDR1,
|
||||||
UIP_ETHADDR2,
|
UIP_ETHADDR2,
|
||||||
UIP_ETHADDR3,
|
UIP_ETHADDR3,
|
||||||
UIP_ETHADDR4,
|
UIP_ETHADDR4,
|
||||||
UIP_ETHADDR5}};
|
UIP_ETHADDR5}};
|
||||||
#else
|
#else
|
||||||
struct uip_eth_addr uip_ethaddr = {{0,0,0,0,0,0}};
|
struct uip_eth_addr uip_ethaddr = {{0,0,0,0,0,0}};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef UIP_CONF_EXTERNAL_BUFFER
|
#ifndef UIP_CONF_EXTERNAL_BUFFER
|
||||||
u8_t uip_buf[UIP_BUFSIZE + 2]; /* The packet buffer that contains
|
u8_t uip_buf[UIP_BUFSIZE + 2]; /* The packet buffer that contains
|
||||||
incoming packets. */
|
incoming packets. */
|
||||||
#endif /* UIP_CONF_EXTERNAL_BUFFER */
|
#endif /* UIP_CONF_EXTERNAL_BUFFER */
|
||||||
|
|
||||||
void *uip_appdata; /* The uip_appdata pointer points to
|
void *uip_appdata; /* The uip_appdata pointer points to
|
||||||
application data. */
|
application data. */
|
||||||
void *uip_sappdata; /* The uip_appdata pointer points to
|
void *uip_sappdata; /* The uip_appdata pointer points to
|
||||||
the application data which is to
|
the application data which is to
|
||||||
be sent. */
|
be sent. */
|
||||||
#if UIP_URGDATA > 0
|
#if UIP_URGDATA > 0
|
||||||
void *uip_urgdata; /* The uip_urgdata pointer points to
|
void *uip_urgdata; /* The uip_urgdata pointer points to
|
||||||
urgent data (out-of-band data), if
|
urgent data (out-of-band data), if
|
||||||
present. */
|
present. */
|
||||||
u16_t uip_urglen, uip_surglen;
|
u16_t uip_urglen, uip_surglen;
|
||||||
#endif /* UIP_URGDATA > 0 */
|
#endif /* UIP_URGDATA > 0 */
|
||||||
|
|
||||||
u16_t uip_len, uip_slen;
|
u16_t uip_len, uip_slen; /* The uip_len is either 8 or 16 bits,
|
||||||
/* The uip_len is either 8 or 16 bits,
|
depending on the maximum packet
|
||||||
depending on the maximum packet
|
size. */
|
||||||
size. */
|
|
||||||
|
|
||||||
u8_t uip_flags; /* The uip_flags variable is used for
|
u8_t uip_flags; /* The uip_flags variable is used for
|
||||||
communication between the TCP/IP stack
|
communication between the TCP/IP stack
|
||||||
and the application program. */
|
and the application program. */
|
||||||
|
|
||||||
#if UIP_TCP
|
#if UIP_TCP
|
||||||
struct uip_conn *uip_conn; /* uip_conn always points to the current
|
struct uip_conn *uip_conn; /* uip_conn always points to the current
|
||||||
connection. */
|
connection. */
|
||||||
|
|
||||||
struct uip_conn uip_conns[UIP_CONNS];
|
struct uip_conn uip_conns[UIP_CONNS];
|
||||||
/* The uip_conns array holds all TCP
|
/* The uip_conns array holds all TCP
|
||||||
connections. */
|
connections. */
|
||||||
u16_t uip_listenports[UIP_LISTENPORTS];
|
u16_t uip_listenports[UIP_LISTENPORTS];
|
||||||
/* The uip_listenports list all currently
|
/* 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
|
u8_t uip_forced_poll; // 1 if forcing the polling, 0 if the polling is not forced
|
||||||
#endif /* UIP_TCP */
|
#endif /* UIP_TCP */
|
||||||
|
|
||||||
@ -184,19 +183,19 @@ struct uip_udp_conn uip_udp_conns[UIP_UDP_CONNS];
|
|||||||
#endif /* UIP_UDP */
|
#endif /* UIP_UDP */
|
||||||
|
|
||||||
static u16_t ipid; /* Ths ipid variable is an increasing
|
static u16_t ipid; /* Ths ipid variable is an increasing
|
||||||
number that is used for the IP ID
|
number that is used for the IP ID
|
||||||
field. */
|
field. */
|
||||||
|
|
||||||
void uip_setipid(u16_t id) { ipid = id; }
|
void uip_setipid(u16_t id) { ipid = id; }
|
||||||
|
|
||||||
#if UIP_TCP
|
#if UIP_TCP
|
||||||
static u8_t iss[4]; /* The iss variable is used for the TCP
|
static u8_t iss[4]; /* The iss variable is used for the TCP
|
||||||
initial sequence number. */
|
initial sequence number. */
|
||||||
#endif /* UIP_TCP */
|
#endif /* UIP_TCP */
|
||||||
|
|
||||||
#if UIP_ACTIVE_OPEN
|
#if UIP_ACTIVE_OPEN
|
||||||
static u16_t lastport; /* Keeps track of the last port used for
|
static u16_t lastport; /* Keeps track of the last port used for
|
||||||
a new connection. */
|
a new connection. */
|
||||||
#endif /* UIP_ACTIVE_OPEN */
|
#endif /* UIP_ACTIVE_OPEN */
|
||||||
|
|
||||||
/* Temporary variables. */
|
/* Temporary variables. */
|
||||||
@ -290,7 +289,7 @@ uip_add32(u8_t *op32, u16_t op16)
|
|||||||
if(uip_acc32[2] == 0) {
|
if(uip_acc32[2] == 0) {
|
||||||
++uip_acc32[1];
|
++uip_acc32[1];
|
||||||
if(uip_acc32[1] == 0) {
|
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;
|
dataptr = data;
|
||||||
last_byte = data + len - 1;
|
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];
|
t = (dataptr[0] << 8) + dataptr[1];
|
||||||
sum += t;
|
sum += t;
|
||||||
if(sum < t) {
|
if(sum < t) {
|
||||||
sum++; /* carry */
|
sum++; /* carry */
|
||||||
}
|
}
|
||||||
dataptr += 2;
|
dataptr += 2;
|
||||||
}
|
}
|
||||||
@ -323,7 +322,7 @@ chksum(u16_t sum, const u8_t *data, u16_t len)
|
|||||||
t = (dataptr[0] << 8) + 0;
|
t = (dataptr[0] << 8) + 0;
|
||||||
sum += t;
|
sum += t;
|
||||||
if(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 TCP header and data. */
|
||||||
sum = chksum(sum, &uip_buf[UIP_IPH_LEN + UIP_LLH_LEN],
|
sum = chksum(sum, &uip_buf[UIP_IPH_LEN + UIP_LLH_LEN],
|
||||||
upper_layer_len);
|
upper_layer_len);
|
||||||
|
|
||||||
return (sum == 0) ? 0xffff : htons(sum);
|
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(cconn->tcpstateflags == UIP_TIME_WAIT) {
|
||||||
if(conn == 0 ||
|
if(conn == 0 ||
|
||||||
cconn->timer > conn->timer) {
|
cconn->timer > conn->timer) {
|
||||||
conn = cconn;
|
conn = cconn;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -606,7 +605,7 @@ uip_listen(u16_t port)
|
|||||||
static u8_t uip_reassbuf[UIP_REASS_BUFSIZE];
|
static u8_t uip_reassbuf[UIP_REASS_BUFSIZE];
|
||||||
static u8_t uip_reassbitmap[UIP_REASS_BUFSIZE / (8 * 8)];
|
static u8_t uip_reassbitmap[UIP_REASS_BUFSIZE / (8 * 8)];
|
||||||
static const u8_t bitmap_bits[8] = {0xff, 0x7f, 0x3f, 0x1f,
|
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 u16_t uip_reasslen;
|
||||||
static u8_t uip_reassflags;
|
static u8_t uip_reassflags;
|
||||||
#define UIP_REASS_FLAG_LASTFRAG 0x01
|
#define UIP_REASS_FLAG_LASTFRAG 0x01
|
||||||
@ -655,28 +654,28 @@ uip_reass(void)
|
|||||||
/* Copy the fragment into the reassembly buffer, at the right
|
/* Copy the fragment into the reassembly buffer, at the right
|
||||||
offset. */
|
offset. */
|
||||||
memcpy(&uip_reassbuf[UIP_IPH_LEN + offset],
|
memcpy(&uip_reassbuf[UIP_IPH_LEN + offset],
|
||||||
(char *)BUF + (int)((BUF->vhl & 0x0f) * 4),
|
(char *)BUF + (int)((BUF->vhl & 0x0f) * 4),
|
||||||
len);
|
len);
|
||||||
|
|
||||||
/* Update the bitmap. */
|
/* Update the bitmap. */
|
||||||
if(offset / (8 * 8) == (offset + len) / (8 * 8)) {
|
if(offset / (8 * 8) == (offset + len) / (8 * 8)) {
|
||||||
/* If the two endpoints are in the same byte, we only update
|
/* If the two endpoints are in the same byte, we only update
|
||||||
that byte. */
|
that byte. */
|
||||||
|
|
||||||
uip_reassbitmap[offset / (8 * 8)] |=
|
uip_reassbitmap[offset / (8 * 8)] |=
|
||||||
bitmap_bits[(offset / 8 ) & 7] &
|
bitmap_bits[(offset / 8 ) & 7] &
|
||||||
~bitmap_bits[((offset + len) / 8 ) & 7];
|
~bitmap_bits[((offset + len) / 8 ) & 7];
|
||||||
} else {
|
} else {
|
||||||
/* If the two endpoints are in different bytes, we update the
|
/* If the two endpoints are in different bytes, we update the
|
||||||
bytes in the endpoints and fill the stuff inbetween with
|
bytes in the endpoints and fill the stuff inbetween with
|
||||||
0xff. */
|
0xff. */
|
||||||
uip_reassbitmap[offset / (8 * 8)] |=
|
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) {
|
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)] |=
|
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
|
/* If this fragment has the More Fragments flag set to zero, we
|
||||||
@ -695,27 +694,27 @@ uip_reass(void)
|
|||||||
in the bitmap are set. */
|
in the bitmap are set. */
|
||||||
if(uip_reassflags & UIP_REASS_FLAG_LASTFRAG) {
|
if(uip_reassflags & UIP_REASS_FLAG_LASTFRAG) {
|
||||||
/* Check all bytes up to and including all but the last byte in
|
/* 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) {
|
for(i = 0; i < uip_reasslen / (8 * 8) - 1; ++i) {
|
||||||
if(uip_reassbitmap[i] != 0xff) {
|
if(uip_reassbitmap[i] != 0xff) {
|
||||||
goto nullreturn;
|
goto nullreturn;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Check the last byte in the bitmap. It should contain just the
|
/* 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)] !=
|
if(uip_reassbitmap[uip_reasslen / (8 * 8)] !=
|
||||||
(u8_t)~bitmap_bits[uip_reasslen / 8 & 7]) {
|
(u8_t)~bitmap_bits[uip_reasslen / 8 & 7]) {
|
||||||
goto nullreturn;
|
goto nullreturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If we have come this far, we have a full packet in the
|
/* 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
|
buffer, so we allocate a pbuf and copy the packet into it. We
|
||||||
also reset the timer. */
|
also reset the timer. */
|
||||||
uip_reasstmr = 0;
|
uip_reasstmr = 0;
|
||||||
memcpy(BUF, FBUF, uip_reasslen);
|
memcpy(BUF, FBUF, uip_reasslen);
|
||||||
|
|
||||||
/* Pretend to be a "normal" (i.e., not fragmented) IP packet
|
/* 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->ipoffset[0] = BUF->ipoffset[1] = 0;
|
||||||
BUF->len[0] = uip_reasslen >> 8;
|
BUF->len[0] = uip_reasslen >> 8;
|
||||||
BUF->len[1] = uip_reasslen & 0xff;
|
BUF->len[1] = uip_reasslen & 0xff;
|
||||||
@ -764,9 +763,9 @@ uip_process(u8_t flag)
|
|||||||
if(flag == UIP_POLL_REQUEST) {
|
if(flag == UIP_POLL_REQUEST) {
|
||||||
if((uip_connr->tcpstateflags & UIP_TS_MASK) == UIP_ESTABLISHED &&
|
if((uip_connr->tcpstateflags & UIP_TS_MASK) == UIP_ESTABLISHED &&
|
||||||
!uip_outstanding(uip_connr)) {
|
!uip_outstanding(uip_connr)) {
|
||||||
uip_flags = UIP_POLL;
|
uip_flags = UIP_POLL;
|
||||||
UIP_APPCALL();
|
UIP_APPCALL();
|
||||||
goto appsend;
|
goto appsend;
|
||||||
}
|
}
|
||||||
goto drop;
|
goto drop;
|
||||||
|
|
||||||
@ -780,9 +779,9 @@ uip_process(u8_t flag)
|
|||||||
/* Increase the initial sequence number. */
|
/* Increase the initial sequence number. */
|
||||||
if(++iss[3] == 0) {
|
if(++iss[3] == 0) {
|
||||||
if(++iss[2] == 0) {
|
if(++iss[2] == 0) {
|
||||||
if(++iss[1] == 0) {
|
if(++iss[1] == 0) {
|
||||||
++iss[0];
|
++iss[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -798,80 +797,80 @@ uip_process(u8_t flag)
|
|||||||
uip_connr->tcpstateflags == UIP_FIN_WAIT_2)) {
|
uip_connr->tcpstateflags == UIP_FIN_WAIT_2)) {
|
||||||
++(uip_connr->timer);
|
++(uip_connr->timer);
|
||||||
if(uip_connr->timer == UIP_TIME_WAIT_TIMEOUT) {
|
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) {
|
} else if(uip_connr->tcpstateflags != UIP_CLOSED && uip_connr->tcpstateflags != UIP_RESERVED) {
|
||||||
/* If the connection has outstanding data, we increase the
|
/* If the connection has outstanding data, we increase the
|
||||||
connection's timer and see if it has reached the RTO value
|
connection's timer and see if it has reached the RTO value
|
||||||
in which case we retransmit. */
|
in which case we retransmit. */
|
||||||
if(uip_outstanding(uip_connr) && !uip_forced_poll) {
|
if(uip_outstanding(uip_connr) && !uip_forced_poll) {
|
||||||
if(uip_connr->timer-- == 0) {
|
if(uip_connr->timer-- == 0) {
|
||||||
if(uip_connr->nrtx == UIP_MAXRTX ||
|
if(uip_connr->nrtx == UIP_MAXRTX ||
|
||||||
((uip_connr->tcpstateflags == UIP_SYN_SENT ||
|
((uip_connr->tcpstateflags == UIP_SYN_SENT ||
|
||||||
uip_connr->tcpstateflags == UIP_SYN_RCVD) &&
|
uip_connr->tcpstateflags == UIP_SYN_RCVD) &&
|
||||||
uip_connr->nrtx == UIP_MAXSYNRTX)) {
|
uip_connr->nrtx == UIP_MAXSYNRTX)) {
|
||||||
uip_connr->tcpstateflags = UIP_CLOSED;
|
uip_connr->tcpstateflags = UIP_CLOSED;
|
||||||
|
|
||||||
/* We call UIP_APPCALL() with uip_flags set to
|
/* We call UIP_APPCALL() with uip_flags set to
|
||||||
UIP_TIMEDOUT to inform the application that the
|
UIP_TIMEDOUT to inform the application that the
|
||||||
connection has timed out. */
|
connection has timed out. */
|
||||||
uip_flags = UIP_TIMEDOUT;
|
uip_flags = UIP_TIMEDOUT;
|
||||||
UIP_APPCALL();
|
UIP_APPCALL();
|
||||||
|
|
||||||
/* We also send a reset packet to the remote host. */
|
/* We also send a reset packet to the remote host. */
|
||||||
BUF->flags = TCP_RST | TCP_ACK;
|
BUF->flags = TCP_RST | TCP_ACK;
|
||||||
goto tcp_send_nodata;
|
goto tcp_send_nodata;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Exponential backoff. */
|
/* Exponential backoff. */
|
||||||
uip_connr->timer = UIP_RTO << (uip_connr->nrtx > 4?
|
uip_connr->timer = UIP_RTO << (uip_connr->nrtx > 4?
|
||||||
4:
|
4:
|
||||||
uip_connr->nrtx);
|
uip_connr->nrtx);
|
||||||
++(uip_connr->nrtx);
|
++(uip_connr->nrtx);
|
||||||
|
|
||||||
/* Ok, so we need to retransmit. We do this differently
|
/* Ok, so we need to retransmit. We do this differently
|
||||||
depending on which state we are in. In ESTABLISHED, we
|
depending on which state we are in. In ESTABLISHED, we
|
||||||
call upon the application so that it may prepare the
|
call upon the application so that it may prepare the
|
||||||
data for the retransmit. In SYN_RCVD, we resend the
|
data for the retransmit. In SYN_RCVD, we resend the
|
||||||
SYNACK that we sent earlier and in LAST_ACK we have to
|
SYNACK that we sent earlier and in LAST_ACK we have to
|
||||||
retransmit our FINACK. */
|
retransmit our FINACK. */
|
||||||
UIP_STAT(++uip_stat.tcp.rexmit);
|
UIP_STAT(++uip_stat.tcp.rexmit);
|
||||||
switch(uip_connr->tcpstateflags & UIP_TS_MASK) {
|
switch(uip_connr->tcpstateflags & UIP_TS_MASK) {
|
||||||
case UIP_SYN_RCVD:
|
case UIP_SYN_RCVD:
|
||||||
/* In the SYN_RCVD state, we should retransmit our
|
/* In the SYN_RCVD state, we should retransmit our
|
||||||
SYNACK. */
|
SYNACK. */
|
||||||
goto tcp_send_synack;
|
goto tcp_send_synack;
|
||||||
|
|
||||||
#if UIP_ACTIVE_OPEN
|
#if UIP_ACTIVE_OPEN
|
||||||
case UIP_SYN_SENT:
|
case UIP_SYN_SENT:
|
||||||
/* In the SYN_SENT state, we retransmit out SYN. */
|
/* In the SYN_SENT state, we retransmit out SYN. */
|
||||||
BUF->flags = 0;
|
BUF->flags = 0;
|
||||||
goto tcp_send_syn;
|
goto tcp_send_syn;
|
||||||
#endif /* UIP_ACTIVE_OPEN */
|
#endif /* UIP_ACTIVE_OPEN */
|
||||||
|
|
||||||
case UIP_ESTABLISHED:
|
case UIP_ESTABLISHED:
|
||||||
/* In the ESTABLISHED state, we call upon the application
|
/* In the ESTABLISHED state, we call upon the application
|
||||||
to do the actual retransmit after which we jump into
|
to do the actual retransmit after which we jump into
|
||||||
the code for sending out the packet (the apprexmit
|
the code for sending out the packet (the apprexmit
|
||||||
label). */
|
label). */
|
||||||
uip_flags = UIP_REXMIT;
|
uip_flags = UIP_REXMIT;
|
||||||
UIP_APPCALL();
|
UIP_APPCALL();
|
||||||
goto apprexmit;
|
goto apprexmit;
|
||||||
|
|
||||||
case UIP_FIN_WAIT_1:
|
case UIP_FIN_WAIT_1:
|
||||||
case UIP_CLOSING:
|
case UIP_CLOSING:
|
||||||
case UIP_LAST_ACK:
|
case UIP_LAST_ACK:
|
||||||
/* In all these states we should retransmit a FINACK. */
|
/* In all these states we should retransmit a FINACK. */
|
||||||
goto tcp_send_finack;
|
goto tcp_send_finack;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if((uip_connr->tcpstateflags & UIP_TS_MASK) == UIP_ESTABLISHED) {
|
} 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. */
|
application for new data. */
|
||||||
uip_flags = UIP_POLL;
|
uip_flags = UIP_POLL;
|
||||||
UIP_APPCALL();
|
UIP_APPCALL();
|
||||||
goto appsend;
|
goto appsend;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
goto drop;
|
goto drop;
|
||||||
@ -928,14 +927,14 @@ uip_process(u8_t flag)
|
|||||||
uip_len = (BUF->len[0] << 8) + BUF->len[1];
|
uip_len = (BUF->len[0] << 8) + BUF->len[1];
|
||||||
#if UIP_CONF_IPV6
|
#if UIP_CONF_IPV6
|
||||||
uip_len += 40; /* The length reported in the IPv6 header is the
|
uip_len += 40; /* The length reported in the IPv6 header is the
|
||||||
length of the payload that follows the
|
length of the payload that follows the
|
||||||
header. However, uIP uses the uip_len variable
|
header. However, uIP uses the uip_len variable
|
||||||
for holding the size of the entire packet,
|
for holding the size of the entire packet,
|
||||||
including the IP header. For IPv4 this is not a
|
including the IP header. For IPv4 this is not a
|
||||||
problem as the length field in the IPv4 header
|
problem as the length field in the IPv4 header
|
||||||
contains the length of the entire packet. But
|
contains the length of the entire packet. But
|
||||||
for IPv6 we need to add the size of the IPv6
|
for IPv6 we need to add the size of the IPv6
|
||||||
header (40 bytes). */
|
header (40 bytes). */
|
||||||
#endif /* UIP_CONF_IPV6 */
|
#endif /* UIP_CONF_IPV6 */
|
||||||
} else {
|
} else {
|
||||||
UIP_LOG("ip: packet shorter than reported in IP header.");
|
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 &&
|
if(BUF->proto == UIP_PROTO_UDP &&
|
||||||
uip_ipaddr_cmp(BUF->destipaddr, all_ones_addr)
|
uip_ipaddr_cmp(BUF->destipaddr, all_ones_addr)
|
||||||
/*&&
|
/*&&
|
||||||
uip_ipchksum() == 0xffff*/) {
|
uip_ipchksum() == 0xffff*/) {
|
||||||
goto udp_input;
|
goto udp_input;
|
||||||
}
|
}
|
||||||
#endif /* UIP_BROADCAST */
|
#endif /* UIP_BROADCAST */
|
||||||
@ -1009,7 +1008,7 @@ uip_process(u8_t flag)
|
|||||||
|
|
||||||
#if !UIP_CONF_IPV6
|
#if !UIP_CONF_IPV6
|
||||||
if(uip_ipchksum() != 0xffff) { /* Compute and check the IP header
|
if(uip_ipchksum() != 0xffff) { /* Compute and check the IP header
|
||||||
checksum. */
|
checksum. */
|
||||||
UIP_STAT(++uip_stat.ip.drop);
|
UIP_STAT(++uip_stat.ip.drop);
|
||||||
UIP_STAT(++uip_stat.ip.chkerr);
|
UIP_STAT(++uip_stat.ip.chkerr);
|
||||||
UIP_LOG("ip: bad checksum.");
|
UIP_LOG("ip: bad checksum.");
|
||||||
@ -1019,8 +1018,8 @@ uip_process(u8_t flag)
|
|||||||
|
|
||||||
#if UIP_TCP
|
#if UIP_TCP
|
||||||
if(BUF->proto == UIP_PROTO_TCP) { /* Check for TCP packet. If so,
|
if(BUF->proto == UIP_PROTO_TCP) { /* Check for TCP packet. If so,
|
||||||
proceed with TCP input
|
proceed with TCP input
|
||||||
processing. */
|
processing. */
|
||||||
goto tcp_input;
|
goto tcp_input;
|
||||||
}
|
}
|
||||||
#endif /* UIP_TCP */
|
#endif /* UIP_TCP */
|
||||||
@ -1034,7 +1033,7 @@ uip_process(u8_t flag)
|
|||||||
#if !UIP_CONF_IPV6
|
#if !UIP_CONF_IPV6
|
||||||
/* ICMPv4 processing code follows. */
|
/* ICMPv4 processing code follows. */
|
||||||
if(BUF->proto != UIP_PROTO_ICMP) { /* We only allow ICMP packets from
|
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.drop);
|
||||||
UIP_STAT(++uip_stat.ip.protoerr);
|
UIP_STAT(++uip_stat.ip.protoerr);
|
||||||
UIP_LOG("ip: neither tcp nor icmp.");
|
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);
|
DEBUG_PRINTF("icmp6_input: length %d\n", uip_len);
|
||||||
|
|
||||||
if(BUF->proto != UIP_PROTO_ICMP6) { /* We only allow ICMPv6 packets from
|
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.drop);
|
||||||
UIP_STAT(++uip_stat.ip.protoerr);
|
UIP_STAT(++uip_stat.ip.protoerr);
|
||||||
UIP_LOG("ip: neither tcp nor icmp6.");
|
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(uip_ipaddr_cmp(ICMPBUF->icmp6data, uip_hostaddr)) {
|
||||||
|
|
||||||
if(ICMPBUF->options[0] == ICMP6_OPTION_SOURCE_LINK_ADDRESS) {
|
if(ICMPBUF->options[0] == ICMP6_OPTION_SOURCE_LINK_ADDRESS) {
|
||||||
/* Save the sender's address in our neighbor list. */
|
/* Save the sender's address in our neighbor list. */
|
||||||
uip_neighbor_add(ICMPBUF->srcipaddr, &(ICMPBUF->options[2]));
|
uip_neighbor_add(ICMPBUF->srcipaddr, &(ICMPBUF->options[2]));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We should now send a neighbor advertisement back to where the
|
/* 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->type = ICMP6_NEIGHBOR_ADVERTISEMENT;
|
||||||
ICMPBUF->flags = ICMP6_FLAG_S; /* Solicited flag. */
|
ICMPBUF->flags = ICMP6_FLAG_S; /* Solicited flag. */
|
||||||
|
|
||||||
@ -1188,8 +1187,8 @@ uip_process(u8_t flag)
|
|||||||
UDPBUF->srcport == uip_udp_conn->rport ||
|
UDPBUF->srcport == uip_udp_conn->rport ||
|
||||||
uip_udp_conn->rport == HTONS(69)) &&
|
uip_udp_conn->rport == HTONS(69)) &&
|
||||||
(uip_ipaddr_cmp(uip_udp_conn->ripaddr, all_zeroes_addr) ||
|
(uip_ipaddr_cmp(uip_udp_conn->ripaddr, all_zeroes_addr) ||
|
||||||
uip_ipaddr_cmp(uip_udp_conn->ripaddr, all_ones_addr) ||
|
uip_ipaddr_cmp(uip_udp_conn->ripaddr, all_ones_addr) ||
|
||||||
uip_ipaddr_cmp(BUF->srcipaddr, uip_udp_conn->ripaddr))) {
|
uip_ipaddr_cmp(BUF->srcipaddr, uip_udp_conn->ripaddr))) {
|
||||||
goto udp_found;
|
goto udp_found;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1253,7 +1252,7 @@ uip_process(u8_t flag)
|
|||||||
/* Start of TCP input header processing code. */
|
/* Start of TCP input header processing code. */
|
||||||
|
|
||||||
if(uip_tcpchksum() != 0xffff) { /* Compute and check the TCP
|
if(uip_tcpchksum() != 0xffff) { /* Compute and check the TCP
|
||||||
checksum. */
|
checksum. */
|
||||||
UIP_STAT(++uip_stat.tcp.drop);
|
UIP_STAT(++uip_stat.tcp.drop);
|
||||||
UIP_STAT(++uip_stat.tcp.chkerr);
|
UIP_STAT(++uip_stat.tcp.chkerr);
|
||||||
UIP_LOG("tcp: bad checksum.");
|
UIP_LOG("tcp: bad checksum.");
|
||||||
@ -1326,7 +1325,7 @@ uip_process(u8_t flag)
|
|||||||
if(++BUF->ackno[3] == 0) {
|
if(++BUF->ackno[3] == 0) {
|
||||||
if(++BUF->ackno[2] == 0) {
|
if(++BUF->ackno[2] == 0) {
|
||||||
if(++BUF->ackno[1] == 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_conns[c].tcpstateflags == UIP_TIME_WAIT) {
|
||||||
if(uip_connr == 0 ||
|
if(uip_connr == 0 ||
|
||||||
uip_conns[c].timer > uip_connr->timer) {
|
uip_conns[c].timer > uip_connr->timer) {
|
||||||
uip_connr = &uip_conns[c];
|
uip_connr = &uip_conns[c];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1405,30 +1404,30 @@ uip_process(u8_t flag)
|
|||||||
for(c = 0; c < ((BUF->tcpoffset >> 4) - 5) << 2 ;) {
|
for(c = 0; c < ((BUF->tcpoffset >> 4) - 5) << 2 ;) {
|
||||||
opt = uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + c];
|
opt = uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + c];
|
||||||
if(opt == TCP_OPT_END) {
|
if(opt == TCP_OPT_END) {
|
||||||
/* End of options. */
|
/* End of options. */
|
||||||
break;
|
break;
|
||||||
} else if(opt == TCP_OPT_NOOP) {
|
} else if(opt == TCP_OPT_NOOP) {
|
||||||
++c;
|
++c;
|
||||||
/* NOP option. */
|
/* NOP option. */
|
||||||
} else if(opt == TCP_OPT_MSS &&
|
} else if(opt == TCP_OPT_MSS &&
|
||||||
uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c] == TCP_OPT_MSS_LEN) {
|
uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c] == TCP_OPT_MSS_LEN) {
|
||||||
/* An MSS option with the right option length. */
|
/* An MSS option with the right option length. */
|
||||||
tmp16 = ((u16_t)uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 2 + c] << 8) |
|
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];
|
(u16_t)uip_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN + 3 + c];
|
||||||
uip_connr->initialmss = uip_connr->mss =
|
uip_connr->initialmss = uip_connr->mss =
|
||||||
tmp16 > UIP_TCP_MSS? UIP_TCP_MSS: tmp16;
|
tmp16 > UIP_TCP_MSS? UIP_TCP_MSS: tmp16;
|
||||||
|
|
||||||
/* And we are done processing options. */
|
/* And we are done processing options. */
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
/* All other options have a length field, so that we easily
|
/* 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(uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c] == 0) {
|
||||||
/* If the length field is zero, the options are malformed
|
/* 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;
|
break;
|
||||||
}
|
}
|
||||||
c += uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c];
|
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)))) {
|
((BUF->flags & TCP_CTL) == (TCP_SYN | TCP_ACK)))) {
|
||||||
if((uip_len > 0 || ((BUF->flags & (TCP_SYN | TCP_FIN)) != 0)) &&
|
if((uip_len > 0 || ((BUF->flags & (TCP_SYN | TCP_FIN)) != 0)) &&
|
||||||
(BUF->seqno[0] != uip_connr->rcv_nxt[0] ||
|
(BUF->seqno[0] != uip_connr->rcv_nxt[0] ||
|
||||||
BUF->seqno[1] != uip_connr->rcv_nxt[1] ||
|
BUF->seqno[1] != uip_connr->rcv_nxt[1] ||
|
||||||
BUF->seqno[2] != uip_connr->rcv_nxt[2] ||
|
BUF->seqno[2] != uip_connr->rcv_nxt[2] ||
|
||||||
BUF->seqno[3] != uip_connr->rcv_nxt[3])) {
|
BUF->seqno[3] != uip_connr->rcv_nxt[3])) {
|
||||||
goto tcp_send_ack;
|
goto tcp_send_ack;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1508,21 +1507,21 @@ uip_process(u8_t flag)
|
|||||||
uip_connr->snd_nxt[1] = uip_acc32[1];
|
uip_connr->snd_nxt[1] = uip_acc32[1];
|
||||||
uip_connr->snd_nxt[2] = uip_acc32[2];
|
uip_connr->snd_nxt[2] = uip_acc32[2];
|
||||||
uip_connr->snd_nxt[3] = uip_acc32[3];
|
uip_connr->snd_nxt[3] = uip_acc32[3];
|
||||||
|
|
||||||
|
|
||||||
/* Do RTT estimation, unless we have done retransmissions. */
|
/* Do RTT estimation, unless we have done retransmissions. */
|
||||||
if(uip_connr->nrtx == 0) {
|
if(uip_connr->nrtx == 0) {
|
||||||
signed char m;
|
signed char m;
|
||||||
m = uip_connr->rto - uip_connr->timer;
|
m = uip_connr->rto - uip_connr->timer;
|
||||||
/* This is taken directly from VJs original code in his paper */
|
/* This is taken directly from VJs original code in his paper */
|
||||||
m = m - (uip_connr->sa >> 3);
|
m = m - (uip_connr->sa >> 3);
|
||||||
uip_connr->sa += m;
|
uip_connr->sa += m;
|
||||||
if(m < 0) {
|
if(m < 0) {
|
||||||
m = -m;
|
m = -m;
|
||||||
}
|
}
|
||||||
m = m - (uip_connr->sv >> 2);
|
m = m - (uip_connr->sv >> 2);
|
||||||
uip_connr->sv += m;
|
uip_connr->sv += m;
|
||||||
uip_connr->rto = (uip_connr->sa >> 3) + uip_connr->sv;
|
uip_connr->rto = (uip_connr->sa >> 3) + uip_connr->sv;
|
||||||
|
|
||||||
}
|
}
|
||||||
/* Set the acknowledged flag. */
|
/* Set the acknowledged flag. */
|
||||||
@ -1539,9 +1538,9 @@ uip_process(u8_t flag)
|
|||||||
/* Do different things depending on in what state the connection is. */
|
/* Do different things depending on in what state the connection is. */
|
||||||
switch(uip_connr->tcpstateflags & UIP_TS_MASK) {
|
switch(uip_connr->tcpstateflags & UIP_TS_MASK) {
|
||||||
/* CLOSED and LISTEN are not handled here. CLOSE_WAIT is not
|
/* CLOSED and LISTEN are not handled here. CLOSE_WAIT is not
|
||||||
implemented, since we force the application to close when the
|
implemented, since we force the application to close when the
|
||||||
peer sends a FIN (hence the application goes directly from
|
peer sends a FIN (hence the application goes directly from
|
||||||
ESTABLISHED to LAST_ACK). */
|
ESTABLISHED to LAST_ACK). */
|
||||||
case UIP_SYN_RCVD:
|
case UIP_SYN_RCVD:
|
||||||
/* In SYN_RCVD we have sent out a SYNACK in response to a SYN, and
|
/* 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
|
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. */
|
/* Parse the TCP MSS option, if present. */
|
||||||
if((BUF->tcpoffset & 0xf0) > 0x50) {
|
if((BUF->tcpoffset & 0xf0) > 0x50) {
|
||||||
for(c = 0; c < ((BUF->tcpoffset >> 4) - 5) << 2 ;) {
|
for(c = 0; c < ((BUF->tcpoffset >> 4) - 5) << 2 ;) {
|
||||||
opt = uip_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN + c];
|
opt = uip_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN + c];
|
||||||
if(opt == TCP_OPT_END) {
|
if(opt == TCP_OPT_END) {
|
||||||
/* End of options. */
|
/* End of options. */
|
||||||
break;
|
break;
|
||||||
} else if(opt == TCP_OPT_NOOP) {
|
} else if(opt == TCP_OPT_NOOP) {
|
||||||
++c;
|
++c;
|
||||||
/* NOP option. */
|
/* NOP option. */
|
||||||
} else if(opt == TCP_OPT_MSS &&
|
} else if(opt == TCP_OPT_MSS &&
|
||||||
uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c] == TCP_OPT_MSS_LEN) {
|
uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c] == TCP_OPT_MSS_LEN) {
|
||||||
/* An MSS option with the right option length. */
|
/* An MSS option with the right option length. */
|
||||||
tmp16 = (uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 2 + c] << 8) |
|
tmp16 = (uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 2 + c] << 8) |
|
||||||
uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 3 + c];
|
uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 3 + c];
|
||||||
uip_connr->initialmss =
|
uip_connr->initialmss =
|
||||||
uip_connr->mss = tmp16 > UIP_TCP_MSS? UIP_TCP_MSS: tmp16;
|
uip_connr->mss = tmp16 > UIP_TCP_MSS? UIP_TCP_MSS: tmp16;
|
||||||
|
|
||||||
/* And we are done processing options. */
|
/* And we are done processing options. */
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
/* All other options have a length field, so that we easily
|
/* 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(uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c] == 0) {
|
||||||
/* If the length field is zero, the options are malformed
|
/* 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;
|
break;
|
||||||
}
|
}
|
||||||
c += uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c];
|
c += uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
uip_connr->tcpstateflags = UIP_ESTABLISHED;
|
uip_connr->tcpstateflags = UIP_ESTABLISHED;
|
||||||
uip_connr->rcv_nxt[0] = BUF->seqno[0];
|
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(BUF->flags & TCP_FIN && !(uip_connr->tcpstateflags & UIP_STOPPED)) {
|
||||||
if(uip_outstanding(uip_connr)) {
|
if(uip_outstanding(uip_connr)) {
|
||||||
goto drop;
|
goto drop;
|
||||||
}
|
}
|
||||||
uip_add_rcv_nxt(1 + uip_len);
|
uip_add_rcv_nxt(1 + uip_len);
|
||||||
uip_flags |= UIP_CLOSE;
|
uip_flags |= UIP_CLOSE;
|
||||||
if(uip_len > 0) {
|
if(uip_len > 0) {
|
||||||
uip_flags |= UIP_NEWDATA;
|
uip_flags |= UIP_NEWDATA;
|
||||||
}
|
}
|
||||||
UIP_APPCALL();
|
UIP_APPCALL();
|
||||||
uip_connr->len = 1;
|
uip_connr->len = 1;
|
||||||
@ -1658,8 +1657,8 @@ uip_process(u8_t flag)
|
|||||||
#if UIP_URGDATA > 0
|
#if UIP_URGDATA > 0
|
||||||
uip_urglen = (BUF->urgp[0] << 8) | BUF->urgp[1];
|
uip_urglen = (BUF->urgp[0] << 8) | BUF->urgp[1];
|
||||||
if(uip_urglen > uip_len) {
|
if(uip_urglen > uip_len) {
|
||||||
/* There is more urgent data in the next segment to come. */
|
/* There is more urgent data in the next segment to come. */
|
||||||
uip_urglen = uip_len;
|
uip_urglen = uip_len;
|
||||||
}
|
}
|
||||||
uip_add_rcv_nxt(uip_urglen);
|
uip_add_rcv_nxt(uip_urglen);
|
||||||
uip_len -= uip_urglen;
|
uip_len -= uip_urglen;
|
||||||
@ -1725,52 +1724,52 @@ uip_process(u8_t flag)
|
|||||||
appsend:
|
appsend:
|
||||||
|
|
||||||
if(uip_flags & UIP_ABORT) {
|
if(uip_flags & UIP_ABORT) {
|
||||||
uip_slen = 0;
|
uip_slen = 0;
|
||||||
uip_connr->tcpstateflags = UIP_CLOSED;
|
uip_connr->tcpstateflags = UIP_CLOSED;
|
||||||
BUF->flags = TCP_RST | TCP_ACK;
|
BUF->flags = TCP_RST | TCP_ACK;
|
||||||
goto tcp_send_nodata;
|
goto tcp_send_nodata;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(uip_flags & UIP_CLOSE) {
|
if(uip_flags & UIP_CLOSE) {
|
||||||
uip_slen = 0;
|
uip_slen = 0;
|
||||||
uip_connr->len = 1;
|
uip_connr->len = 1;
|
||||||
uip_connr->tcpstateflags = UIP_FIN_WAIT_1;
|
uip_connr->tcpstateflags = UIP_FIN_WAIT_1;
|
||||||
uip_connr->nrtx = 0;
|
uip_connr->nrtx = 0;
|
||||||
BUF->flags = TCP_FIN | TCP_ACK;
|
BUF->flags = TCP_FIN | TCP_ACK;
|
||||||
goto tcp_send_nodata;
|
goto tcp_send_nodata;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If uip_slen > 0, the application has data to be sent. */
|
/* If uip_slen > 0, the application has data to be sent. */
|
||||||
if(uip_slen > 0) {
|
if(uip_slen > 0) {
|
||||||
|
|
||||||
/* If the connection has acknowledged data, the contents of
|
/* 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) {
|
if((uip_flags & UIP_ACKDATA) != 0) {
|
||||||
uip_connr->len = 0;
|
uip_connr->len = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If the ->len variable is non-zero the connection has
|
/* If the ->len variable is non-zero the connection has
|
||||||
already data in transit and cannot send anymore right
|
already data in transit and cannot send anymore right
|
||||||
now. */
|
now. */
|
||||||
if(uip_connr->len == 0) {
|
if(uip_connr->len == 0) {
|
||||||
|
|
||||||
/* The application cannot send more than what is allowed by
|
/* The application cannot send more than what is allowed by
|
||||||
the mss (the minumum of the MSS and the available
|
the mss (the minumum of the MSS and the available
|
||||||
window). */
|
window). */
|
||||||
if(uip_slen > uip_connr->mss) {
|
if(uip_slen > uip_connr->mss) {
|
||||||
uip_slen = uip_connr->mss;
|
uip_slen = uip_connr->mss;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Remember how much data we send out now so that we know
|
/* 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;
|
uip_connr->len = uip_slen;
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
/* If the application already had unacknowledged data, we
|
/* If the application already had unacknowledged data, we
|
||||||
make sure that the application does not send (i.e.,
|
make sure that the application does not send (i.e.,
|
||||||
retransmit) out more than it previously sent out. */
|
retransmit) out more than it previously sent out. */
|
||||||
uip_slen = uip_connr->len;
|
uip_slen = uip_connr->len;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
uip_connr->nrtx = 0;
|
uip_connr->nrtx = 0;
|
||||||
apprexmit:
|
apprexmit:
|
||||||
@ -1779,19 +1778,19 @@ uip_process(u8_t flag)
|
|||||||
/* If the application has data to be sent, or if the incoming
|
/* If the application has data to be sent, or if the incoming
|
||||||
packet had new data in it, we must send out a packet. */
|
packet had new data in it, we must send out a packet. */
|
||||||
if(uip_slen > 0 && uip_connr->len > 0) {
|
if(uip_slen > 0 && uip_connr->len > 0) {
|
||||||
/* Add the length of the IP and TCP headers. */
|
/* Add the length of the IP and TCP headers. */
|
||||||
uip_len = uip_connr->len + UIP_TCPIP_HLEN;
|
uip_len = uip_connr->len + UIP_TCPIP_HLEN;
|
||||||
/* We always set the ACK flag in response packets. */
|
/* We always set the ACK flag in response packets. */
|
||||||
BUF->flags = TCP_ACK | TCP_PSH;
|
BUF->flags = TCP_ACK | TCP_PSH;
|
||||||
/* Send the packet. */
|
/* Send the packet. */
|
||||||
goto tcp_send_noopts;
|
goto tcp_send_noopts;
|
||||||
}
|
}
|
||||||
/* If there is no data to send, just send out a pure ACK if
|
/* 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) {
|
if(uip_flags & UIP_NEWDATA) {
|
||||||
uip_len = UIP_TCPIP_HLEN;
|
uip_len = UIP_TCPIP_HLEN;
|
||||||
BUF->flags = TCP_ACK;
|
BUF->flags = TCP_ACK;
|
||||||
goto tcp_send_noopts;
|
goto tcp_send_noopts;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
goto drop;
|
goto drop;
|
||||||
@ -1814,11 +1813,11 @@ uip_process(u8_t flag)
|
|||||||
}
|
}
|
||||||
if(BUF->flags & TCP_FIN) {
|
if(BUF->flags & TCP_FIN) {
|
||||||
if(uip_flags & UIP_ACKDATA) {
|
if(uip_flags & UIP_ACKDATA) {
|
||||||
uip_connr->tcpstateflags = UIP_TIME_WAIT;
|
uip_connr->tcpstateflags = UIP_TIME_WAIT;
|
||||||
uip_connr->timer = 0;
|
uip_connr->timer = 0;
|
||||||
uip_connr->len = 0;
|
uip_connr->len = 0;
|
||||||
} else {
|
} else {
|
||||||
uip_connr->tcpstateflags = UIP_CLOSING;
|
uip_connr->tcpstateflags = UIP_CLOSING;
|
||||||
}
|
}
|
||||||
uip_add_rcv_nxt(1);
|
uip_add_rcv_nxt(1);
|
||||||
uip_flags = UIP_CLOSE;
|
uip_flags = UIP_CLOSE;
|
||||||
@ -1944,7 +1943,7 @@ uip_process(u8_t flag)
|
|||||||
UIP_STAT(++uip_stat.tcp.sent);
|
UIP_STAT(++uip_stat.tcp.sent);
|
||||||
send:
|
send:
|
||||||
DEBUG_PRINTF("Sending packet with length %d (%d)\n", uip_len,
|
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);
|
UIP_STAT(++uip_stat.ip.sent);
|
||||||
/* Return and let the caller do the actual transmission. */
|
/* Return and let the caller do the actual transmission. */
|
||||||
|
104
src/uip/uip.h
104
src/uip/uip.h
@ -242,12 +242,12 @@ void uip_setipid(u16_t id);
|
|||||||
uip_input();
|
uip_input();
|
||||||
if(uip_len > 0) {
|
if(uip_len > 0) {
|
||||||
uip_arp_out();
|
uip_arp_out();
|
||||||
ethernet_devicedriver_send();
|
ethernet_devicedriver_send();
|
||||||
}
|
}
|
||||||
} else if(BUF->type == HTONS(UIP_ETHTYPE_ARP)) {
|
} else if(BUF->type == HTONS(UIP_ETHTYPE_ARP)) {
|
||||||
uip_arp_arpin();
|
uip_arp_arpin();
|
||||||
if(uip_len > 0) {
|
if(uip_len > 0) {
|
||||||
ethernet_devicedriver_send();
|
ethernet_devicedriver_send();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
\endcode
|
\endcode
|
||||||
@ -926,7 +926,7 @@ struct uip_udp_conn *uip_udp_new(uip_ipaddr_t *ripaddr, u16_t rport);
|
|||||||
*/
|
*/
|
||||||
#if !UIP_CONF_IPV6
|
#if !UIP_CONF_IPV6
|
||||||
#define uip_ipaddr_cmp(addr1, addr2) (((u16_t *)addr1)[0] == ((u16_t *)addr2)[0] && \
|
#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 */
|
#else /* !UIP_CONF_IPV6 */
|
||||||
#define uip_ipaddr_cmp(addr1, addr2) (memcmp(addr1, addr2, sizeof(uip_ip6addr_t)) == 0)
|
#define uip_ipaddr_cmp(addr1, addr2) (memcmp(addr1, addr2, sizeof(uip_ip6addr_t)) == 0)
|
||||||
#endif /* !UIP_CONF_IPV6 */
|
#endif /* !UIP_CONF_IPV6 */
|
||||||
@ -1173,26 +1173,26 @@ struct uip_conn {
|
|||||||
|
|
||||||
u16_t lport; /**< The local TCP port, in network byte order. */
|
u16_t lport; /**< The local TCP port, in network byte order. */
|
||||||
u16_t rport; /**< The local remote TCP port, in network byte
|
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
|
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
|
u8_t snd_nxt[4]; /**< The sequence number that was last sent by
|
||||||
us. */
|
us. */
|
||||||
u16_t len; /**< Length of the data that was previously sent. */
|
u16_t len; /**< Length of the data that was previously sent. */
|
||||||
u16_t mss; /**< Current maximum segment size for the
|
u16_t mss; /**< Current maximum segment size for the
|
||||||
connection. */
|
connection. */
|
||||||
u16_t initialmss; /**< Initial maximum segment size for the
|
u16_t initialmss; /**< Initial maximum segment size for the
|
||||||
connection. */
|
connection. */
|
||||||
u8_t sa; /**< Retransmission time-out calculation state
|
u8_t sa; /**< Retransmission time-out calculation state
|
||||||
variable. */
|
variable. */
|
||||||
u8_t sv; /**< Retransmission time-out calculation state
|
u8_t sv; /**< Retransmission time-out calculation state
|
||||||
variable. */
|
variable. */
|
||||||
u8_t rto; /**< Retransmission time-out. */
|
u8_t rto; /**< Retransmission time-out. */
|
||||||
u8_t tcpstateflags; /**< TCP state and flags. */
|
u8_t tcpstateflags; /**< TCP state and flags. */
|
||||||
u8_t timer; /**< The retransmission timer. */
|
u8_t timer; /**< The retransmission timer. */
|
||||||
u8_t nrtx; /**< The number of retransmissions for the last
|
u8_t nrtx; /**< The number of retransmissions for the last
|
||||||
segment sent. */
|
segment sent. */
|
||||||
|
|
||||||
/** The application state. */
|
/** The application state. */
|
||||||
uip_tcp_appstate_t appstate;
|
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 {
|
||||||
struct {
|
struct {
|
||||||
uip_stats_t drop; /**< Number of dropped packets at the IP
|
uip_stats_t drop; /**< Number of dropped packets at the IP
|
||||||
layer. */
|
layer. */
|
||||||
uip_stats_t recv; /**< Number of received packets at the IP
|
uip_stats_t recv; /**< Number of received packets at the IP
|
||||||
layer. */
|
layer. */
|
||||||
uip_stats_t sent; /**< Number of sent packets at the IP
|
uip_stats_t sent; /**< Number of sent packets at the IP
|
||||||
layer. */
|
layer. */
|
||||||
uip_stats_t vhlerr; /**< Number of packets dropped due to wrong
|
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
|
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
|
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
|
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
|
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
|
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. */
|
} ip; /**< IP statistics. */
|
||||||
struct {
|
struct {
|
||||||
uip_stats_t drop; /**< Number of dropped ICMP packets. */
|
uip_stats_t drop; /**< Number of dropped ICMP packets. */
|
||||||
uip_stats_t recv; /**< Number of received ICMP packets. */
|
uip_stats_t recv; /**< Number of received ICMP packets. */
|
||||||
uip_stats_t sent; /**< Number of sent ICMP packets. */
|
uip_stats_t sent; /**< Number of sent ICMP packets. */
|
||||||
uip_stats_t typeerr; /**< Number of ICMP packets with a wrong
|
uip_stats_t typeerr; /**< Number of ICMP packets with a wrong
|
||||||
type. */
|
type. */
|
||||||
} icmp; /**< ICMP statistics. */
|
} icmp; /**< ICMP statistics. */
|
||||||
#if UIP_TCP
|
#if UIP_TCP
|
||||||
struct {
|
struct {
|
||||||
@ -1284,15 +1284,15 @@ struct uip_stats {
|
|||||||
uip_stats_t recv; /**< Number of recived TCP segments. */
|
uip_stats_t recv; /**< Number of recived TCP segments. */
|
||||||
uip_stats_t sent; /**< Number of sent TCP segments. */
|
uip_stats_t sent; /**< Number of sent TCP segments. */
|
||||||
uip_stats_t chkerr; /**< Number of TCP segments with a bad
|
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
|
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 rst; /**< Number of recevied TCP RST (reset) segments. */
|
||||||
uip_stats_t rexmit; /**< Number of retransmitted TCP segments. */
|
uip_stats_t rexmit; /**< Number of retransmitted TCP segments. */
|
||||||
uip_stats_t syndrop; /**< Number of dropped SYNs due to too few
|
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,
|
uip_stats_t synrst; /**< Number of SYNs for closed ports,
|
||||||
triggering a RST. */
|
triggering a RST. */
|
||||||
} tcp; /**< TCP statistics. */
|
} tcp; /**< TCP statistics. */
|
||||||
#endif /* UIP_TCP */
|
#endif /* UIP_TCP */
|
||||||
#if UIP_UDP
|
#if UIP_UDP
|
||||||
@ -1301,7 +1301,7 @@ struct uip_stats {
|
|||||||
uip_stats_t recv; /**< Number of recived UDP segments. */
|
uip_stats_t recv; /**< Number of recived UDP segments. */
|
||||||
uip_stats_t sent; /**< Number of sent UDP segments. */
|
uip_stats_t sent; /**< Number of sent UDP segments. */
|
||||||
uip_stats_t chkerr; /**< Number of UDP segments with a bad
|
uip_stats_t chkerr; /**< Number of UDP segments with a bad
|
||||||
checksum. */
|
checksum. */
|
||||||
} udp; /**< UDP statistics. */
|
} udp; /**< UDP statistics. */
|
||||||
#endif /* UIP_UDP */
|
#endif /* UIP_UDP */
|
||||||
};
|
};
|
||||||
@ -1335,33 +1335,33 @@ extern u8_t uip_flags;
|
|||||||
functions/macros. */
|
functions/macros. */
|
||||||
|
|
||||||
#define UIP_ACKDATA 1 /* Signifies that the outstanding data was
|
#define UIP_ACKDATA 1 /* Signifies that the outstanding data was
|
||||||
acked and the application should send
|
acked and the application should send
|
||||||
out new data instead of retransmitting
|
out new data instead of retransmitting
|
||||||
the last data. */
|
the last data. */
|
||||||
#define UIP_NEWDATA 2 /* Flags the fact that the peer has sent
|
#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
|
#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
|
#define UIP_POLL 8 /* Used for polling the application, to
|
||||||
check if the application has data that
|
check if the application has data that
|
||||||
it wants to send. */
|
it wants to send. */
|
||||||
#define UIP_CLOSE 16 /* The remote host has closed the
|
#define UIP_CLOSE 16 /* The remote host has closed the
|
||||||
connection, thus the connection has
|
connection, thus the connection has
|
||||||
gone away. Or the application signals
|
gone away. Or the application signals
|
||||||
that it wants to close the
|
that it wants to close the
|
||||||
connection. */
|
connection. */
|
||||||
#define UIP_ABORT 32 /* The remote host has aborted the
|
#define UIP_ABORT 32 /* The remote host has aborted the
|
||||||
connection, thus the connection has
|
connection, thus the connection has
|
||||||
gone away. Or the application signals
|
gone away. Or the application signals
|
||||||
that it wants to abort the
|
that it wants to abort the
|
||||||
connection. */
|
connection. */
|
||||||
#define UIP_CONNECTED 64 /* We have got a connection from a remote
|
#define UIP_CONNECTED 64 /* We have got a connection from a remote
|
||||||
host and have set up a new connection
|
host and have set up a new connection
|
||||||
for it, or an active connection has
|
for it, or an active connection has
|
||||||
been successfully established. */
|
been successfully established. */
|
||||||
|
|
||||||
#define UIP_TIMEDOUT 128 /* The connection has been aborted due to
|
#define UIP_TIMEDOUT 128 /* The connection has been aborted due to
|
||||||
too many retransmissions. */
|
too many retransmissions. */
|
||||||
|
|
||||||
/* uip_process(flag):
|
/* uip_process(flag):
|
||||||
*
|
*
|
||||||
@ -1377,16 +1377,16 @@ void uip_process(u8_t flag);
|
|||||||
the macrose defined in this file. */
|
the macrose defined in this file. */
|
||||||
|
|
||||||
#define UIP_DATA 1 /* Tells uIP that there is incoming
|
#define UIP_DATA 1 /* Tells uIP that there is incoming
|
||||||
data in the uip_buf buffer. The
|
data in the uip_buf buffer. The
|
||||||
length of the data is stored in the
|
length of the data is stored in the
|
||||||
global variable uip_len. */
|
global variable uip_len. */
|
||||||
#define UIP_TIMER 2 /* Tells uIP that the periodic timer
|
#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
|
#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
|
#define UIP_UDP_SEND_CONN 4 /* Tells uIP that a UDP datagram
|
||||||
should be constructed in the
|
should be constructed in the
|
||||||
uip_buf buffer. */
|
uip_buf buffer. */
|
||||||
#if UIP_UDP
|
#if UIP_UDP
|
||||||
#define UIP_UDP_TIMER 5
|
#define UIP_UDP_TIMER 5
|
||||||
#endif /* UIP_UDP */
|
#endif /* UIP_UDP */
|
||||||
@ -1544,11 +1544,11 @@ struct uip_udpip_hdr {
|
|||||||
#define UIP_UDPH_LEN 8 /* Size of UDP header */
|
#define UIP_UDPH_LEN 8 /* Size of UDP header */
|
||||||
#define UIP_TCPH_LEN 20 /* Size of TCP header */
|
#define UIP_TCPH_LEN 20 /* Size of TCP header */
|
||||||
#define UIP_IPUDPH_LEN (UIP_UDPH_LEN + UIP_IPH_LEN) /* Size of IP +
|
#define UIP_IPUDPH_LEN (UIP_UDPH_LEN + UIP_IPH_LEN) /* Size of IP +
|
||||||
UDP
|
UDP
|
||||||
header */
|
header */
|
||||||
#define UIP_IPTCPH_LEN (UIP_TCPH_LEN + UIP_IPH_LEN) /* Size of IP +
|
#define UIP_IPTCPH_LEN (UIP_TCPH_LEN + UIP_IPH_LEN) /* Size of IP +
|
||||||
TCP
|
TCP
|
||||||
header */
|
header */
|
||||||
#define UIP_TCPIP_HLEN UIP_IPTCPH_LEN
|
#define UIP_TCPIP_HLEN UIP_IPTCPH_LEN
|
||||||
|
|
||||||
|
|
||||||
|
@ -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
|
/* Check if the source IP address of the incoming packet matches
|
||||||
the IP address in this ARP table entry. */
|
the IP address in this ARP table entry. */
|
||||||
if(ipaddr[0] == tabptr->ipaddr[0] &&
|
if(ipaddr[0] == tabptr->ipaddr[0] &&
|
||||||
ipaddr[1] == tabptr->ipaddr[1]) {
|
ipaddr[1] == tabptr->ipaddr[1]) {
|
||||||
|
|
||||||
/* An old entry found, update this and return. */
|
/* An old entry found, update this and return. */
|
||||||
memcpy(tabptr->ethaddr.addr, ethaddr->addr, 6);
|
memcpy(tabptr->ethaddr.addr, ethaddr->addr, 6);
|
||||||
tabptr->time = arptime;
|
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) {
|
for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
|
||||||
tabptr = &arp_table[i];
|
tabptr = &arp_table[i];
|
||||||
if(arptime - tabptr->time > tmpage) {
|
if(arptime - tabptr->time > tmpage) {
|
||||||
tmpage = arptime - tabptr->time;
|
tmpage = arptime - tabptr->time;
|
||||||
c = i;
|
c = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
i = c;
|
i = c;
|
||||||
@ -238,7 +238,7 @@ void
|
|||||||
uip_arp_ipin(void)
|
uip_arp_ipin(void)
|
||||||
{
|
{
|
||||||
uip_len -= sizeof(struct uip_eth_hdr);
|
uip_len -= sizeof(struct uip_eth_hdr);
|
||||||
|
|
||||||
/* Only insert/update an entry if the source IP address of the
|
/* Only insert/update an entry if the source IP address of the
|
||||||
incoming IP packet comes from a host on the local network. */
|
incoming IP packet comes from a host on the local network. */
|
||||||
if((IPBUF->srcipaddr[0] & uip_netmask[0]) !=
|
if((IPBUF->srcipaddr[0] & uip_netmask[0]) !=
|
||||||
@ -293,8 +293,8 @@ uip_arp_arpin(void)
|
|||||||
reply. */
|
reply. */
|
||||||
if(uip_ipaddr_cmp(BUF->dipaddr, uip_hostaddr)) {
|
if(uip_ipaddr_cmp(BUF->dipaddr, uip_hostaddr)) {
|
||||||
/* First, we register the one who made the request in our ARP
|
/* First, we register the one who made the request in our ARP
|
||||||
table, since it is likely that we will do more communication
|
table, since it is likely that we will do more communication
|
||||||
with this host in the future. */
|
with this host in the future. */
|
||||||
uip_arp_update(BUF->sipaddr, &BUF->shwaddr);
|
uip_arp_update(BUF->sipaddr, &BUF->shwaddr);
|
||||||
|
|
||||||
/* The reply opcode is 2. */
|
/* The reply opcode is 2. */
|
||||||
@ -372,8 +372,8 @@ uip_arp_out(void)
|
|||||||
/* Check if the destination address is on the local network. */
|
/* Check if the destination address is on the local network. */
|
||||||
if(!uip_ipaddr_maskcmp(IPBUF->destipaddr, uip_hostaddr, uip_netmask)) {
|
if(!uip_ipaddr_maskcmp(IPBUF->destipaddr, uip_hostaddr, uip_netmask)) {
|
||||||
/* Destination address was not on the local network, so we need to
|
/* Destination address was not on the local network, so we need to
|
||||||
use the default router's IP address instead of the destination
|
use the default router's IP address instead of the destination
|
||||||
address when determining the MAC address. */
|
address when determining the MAC address. */
|
||||||
uip_ipaddr_copy(ipaddr, uip_draddr);
|
uip_ipaddr_copy(ipaddr, uip_draddr);
|
||||||
} else {
|
} else {
|
||||||
/* Else, we use the destination IP address. */
|
/* Else, we use the destination IP address. */
|
||||||
@ -383,13 +383,13 @@ uip_arp_out(void)
|
|||||||
for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
|
for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {
|
||||||
tabptr = &arp_table[i];
|
tabptr = &arp_table[i];
|
||||||
if(uip_ipaddr_cmp(ipaddr, tabptr->ipaddr)) {
|
if(uip_ipaddr_cmp(ipaddr, tabptr->ipaddr)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(i == UIP_ARPTAB_SIZE) {
|
if(i == UIP_ARPTAB_SIZE) {
|
||||||
/* The destination address was not in our ARP table, so we
|
/* 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->ethhdr.dest.addr, 0xff, 6);
|
||||||
memset(BUF->dhwaddr.addr, 0x00, 6);
|
memset(BUF->dhwaddr.addr, 0x00, 6);
|
||||||
|
@ -57,16 +57,16 @@ uiplib_ipaddrconv(char *addrstr, unsigned char *ipaddr)
|
|||||||
c = *addrstr;
|
c = *addrstr;
|
||||||
++j;
|
++j;
|
||||||
if(j > 4) {
|
if(j > 4) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if(c == '.' || c == 0) {
|
if(c == '.' || c == 0) {
|
||||||
*ipaddr = tmp;
|
*ipaddr = tmp;
|
||||||
++ipaddr;
|
++ipaddr;
|
||||||
tmp = 0;
|
tmp = 0;
|
||||||
} else if(c >= '0' && c <= '9') {
|
} else if(c >= '0' && c <= '9') {
|
||||||
tmp = (tmp * 10) + (c - '0');
|
tmp = (tmp * 10) + (c - '0');
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
++addrstr;
|
++addrstr;
|
||||||
} while(c != '.' && c != 0);
|
} while(c != '.' && c != 0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user