This commit is contained in:
Richard Barry 2007-06-05 09:35:13 +00:00
parent 014d7f5b8f
commit 22e434dfaf
134 changed files with 39468 additions and 39401 deletions

View file

@ -1,5 +1,5 @@
/* /*
FreeRTOS.org V4.2.1 - Copyright (C) 2003-2007 Richard Barry. FreeRTOS.org V4.3.0 - Copyright (C) 2003-2007 Richard Barry.
This file is part of the FreeRTOS.org distribution. This file is part of the FreeRTOS.org distribution.

View file

@ -1,5 +1,5 @@
/* /*
FreeRTOS.org V4.2.1 - Copyright (C) 2003-2007 Richard Barry. FreeRTOS.org V4.3.0 - Copyright (C) 2003-2007 Richard Barry.
This file is part of the FreeRTOS.org distribution. This file is part of the FreeRTOS.org distribution.

View file

@ -1,5 +1,5 @@
/* /*
FreeRTOS.org V4.2.1 - Copyright (C) 2003-2007 Richard Barry. FreeRTOS.org V4.3.0 - Copyright (C) 2003-2007 Richard Barry.
This file is part of the FreeRTOS.org distribution. This file is part of the FreeRTOS.org distribution.

View file

@ -1,5 +1,5 @@
/* /*
FreeRTOS.org V4.2.1 - Copyright (C) 2003-2007 Richard Barry. FreeRTOS.org V4.3.0 - Copyright (C) 2003-2007 Richard Barry.
This file is part of the FreeRTOS.org distribution. This file is part of the FreeRTOS.org distribution.

View file

@ -1,5 +1,5 @@
/* /*
FreeRTOS.org V4.2.1 - Copyright (C) 2003-2007 Richard Barry. FreeRTOS.org V4.3.0 - Copyright (C) 2003-2007 Richard Barry.
This file is part of the FreeRTOS.org distribution. This file is part of the FreeRTOS.org distribution.

View file

@ -1,5 +1,5 @@
/* /*
FreeRTOS.org V4.2.1 - Copyright (C) 2003-2007 Richard Barry. FreeRTOS.org V4.3.0 - Copyright (C) 2003-2007 Richard Barry.
This file is part of the FreeRTOS.org distribution. This file is part of the FreeRTOS.org distribution.

View file

@ -1,5 +1,5 @@
/* /*
FreeRTOS.org V4.2.1 - Copyright (C) 2003-2007 Richard Barry. FreeRTOS.org V4.3.0 - Copyright (C) 2003-2007 Richard Barry.
This file is part of the FreeRTOS.org distribution. This file is part of the FreeRTOS.org distribution.

View file

@ -1,5 +1,5 @@
/* /*
FreeRTOS.org V4.2.1 - Copyright (C) 2003-2007 Richard Barry. FreeRTOS.org V4.3.0 - Copyright (C) 2003-2007 Richard Barry.
This file is part of the FreeRTOS.org distribution. This file is part of the FreeRTOS.org distribution.

View file

@ -1,5 +1,5 @@
/* /*
FreeRTOS.org V4.2.1 - Copyright (C) 2003-2007 Richard Barry. FreeRTOS.org V4.3.0 - Copyright (C) 2003-2007 Richard Barry.
This file is part of the FreeRTOS.org distribution. This file is part of the FreeRTOS.org distribution.

View file

@ -1,5 +1,5 @@
/* /*
FreeRTOS.org V4.2.1 - Copyright (C) 2003-2007 Richard Barry. FreeRTOS.org V4.3.0 - Copyright (C) 2003-2007 Richard Barry.
This file is part of the FreeRTOS.org distribution. This file is part of the FreeRTOS.org distribution.

View file

@ -1,5 +1,5 @@
/* /*
FreeRTOS.org V4.2.1 - Copyright (C) 2003-2007 Richard Barry. FreeRTOS.org V4.3.0 - Copyright (C) 2003-2007 Richard Barry.
This file is part of the FreeRTOS.org distribution. This file is part of the FreeRTOS.org distribution.

View file

@ -1,5 +1,5 @@
/* /*
FreeRTOS.org V4.2.1 - Copyright (C) 2003-2007 Richard Barry. FreeRTOS.org V4.3.0 - Copyright (C) 2003-2007 Richard Barry.
This file is part of the FreeRTOS.org distribution. This file is part of the FreeRTOS.org distribution.

View file

@ -1,5 +1,5 @@
/* /*
FreeRTOS.org V4.2.1 - Copyright (C) 2003-2007 Richard Barry. FreeRTOS.org V4.3.0 - Copyright (C) 2003-2007 Richard Barry.
This file is part of the FreeRTOS.org distribution. This file is part of the FreeRTOS.org distribution.

View file

@ -1,5 +1,5 @@
/* /*
FreeRTOS.org V4.2.1 - Copyright (C) 2003-2007 Richard Barry. FreeRTOS.org V4.3.0 - Copyright (C) 2003-2007 Richard Barry.
This file is part of the FreeRTOS.org distribution. This file is part of the FreeRTOS.org distribution.

View file

@ -1,5 +1,5 @@
/* /*
FreeRTOS.org V4.2.1 - Copyright (C) 2003-2007 Richard Barry. FreeRTOS.org V4.3.0 - Copyright (C) 2003-2007 Richard Barry.
This file is part of the FreeRTOS.org distribution. This file is part of the FreeRTOS.org distribution.

View file

@ -1,5 +1,5 @@
/* /*
FreeRTOS.org V4.2.1 - Copyright (C) 2003-2007 Richard Barry. FreeRTOS.org V4.3.0 - Copyright (C) 2003-2007 Richard Barry.
This file is part of the FreeRTOS.org distribution. This file is part of the FreeRTOS.org distribution.

View file

@ -1,5 +1,5 @@
/* /*
FreeRTOS.org V4.2.1 - Copyright (C) 2003-2007 Richard Barry. FreeRTOS.org V4.3.0 - Copyright (C) 2003-2007 Richard Barry.
This file is part of the FreeRTOS.org distribution. This file is part of the FreeRTOS.org distribution.

View file

@ -1,5 +1,5 @@
/* /*
FreeRTOS.org V4.2.1 - Copyright (C) 2003-2007 Richard Barry. FreeRTOS.org V4.3.0 - Copyright (C) 2003-2007 Richard Barry.
This file is part of the FreeRTOS.org distribution. This file is part of the FreeRTOS.org distribution.

View file

@ -1,5 +1,5 @@
/* /*
FreeRTOS.org V4.2.1 - Copyright (C) 2003-2007 Richard Barry. FreeRTOS.org V4.3.0 - Copyright (C) 2003-2007 Richard Barry.
This file is part of the FreeRTOS.org distribution. This file is part of the FreeRTOS.org distribution.

View file

@ -1,5 +1,5 @@
/* /*
FreeRTOS.org V4.2.1 - Copyright (C) 2003-2007 Richard Barry. FreeRTOS.org V4.3.0 - Copyright (C) 2003-2007 Richard Barry.
This file is part of the FreeRTOS.org distribution. This file is part of the FreeRTOS.org distribution.

View file

@ -1,5 +1,5 @@
/* /*
FreeRTOS.org V4.2.1 - Copyright (C) 2003-2007 Richard Barry. FreeRTOS.org V4.3.0 - Copyright (C) 2003-2007 Richard Barry.
This file is part of the FreeRTOS.org distribution. This file is part of the FreeRTOS.org distribution.

View file

@ -1,5 +1,5 @@
/* /*
FreeRTOS.org V4.2.1 - Copyright (C) 2003-2007 Richard Barry. FreeRTOS.org V4.3.0 - Copyright (C) 2003-2007 Richard Barry.
This file is part of the FreeRTOS.org distribution. This file is part of the FreeRTOS.org distribution.

View file

@ -1,5 +1,5 @@
/* /*
FreeRTOS.org V4.2.1 - Copyright (C) 2003-2007 Richard Barry. FreeRTOS.org V4.3.0 - Copyright (C) 2003-2007 Richard Barry.
This file is part of the FreeRTOS.org distribution. This file is part of the FreeRTOS.org distribution.

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,59 +1,59 @@
/* /*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science. * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, * 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products * 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE. * OF SUCH DAMAGE.
* *
* This file is part of the lwIP TCP/IP stack. * This file is part of the lwIP TCP/IP stack.
* *
* Author: Adam Dunkels <adam@sics.se> * Author: Adam Dunkels <adam@sics.se>
* *
*/ */
#include "lwip/err.h" #include "lwip/err.h"
#ifdef LWIP_DEBUG #ifdef LWIP_DEBUG
static char *err_strerr[] = {"Ok.", static char *err_strerr[] = {"Ok.",
"Out of memory error.", "Out of memory error.",
"Buffer error.", "Buffer error.",
"Connection aborted.", "Connection aborted.",
"Connection reset.", "Connection reset.",
"Connection closed.", "Connection closed.",
"Not connected.", "Not connected.",
"Illegal value.", "Illegal value.",
"Illegal argument.", "Illegal argument.",
"Routing problem.", "Routing problem.",
"Address in use." "Address in use."
}; };
char * char *
lwip_strerr(err_t err) lwip_strerr(err_t err)
{ {
return err_strerr[-err]; return err_strerr[-err];
} }
#endif /* LWIP_DEBUG */ #endif /* LWIP_DEBUG */

File diff suppressed because it is too large Load diff

View file

@ -1,198 +1,198 @@
/* /*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science. * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, * 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products * 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE. * OF SUCH DAMAGE.
* *
* This file is part of the lwIP TCP/IP stack. * This file is part of the lwIP TCP/IP stack.
* *
* Author: Adam Dunkels <adam@sics.se> * Author: Adam Dunkels <adam@sics.se>
* *
*/ */
#include "lwip/opt.h" #include "lwip/opt.h"
#include "lwip/sys.h" #include "lwip/sys.h"
#include "lwip/memp.h" #include "lwip/memp.h"
#include "lwip/pbuf.h" #include "lwip/pbuf.h"
#include "lwip/ip.h" #include "lwip/ip.h"
#include "lwip/ip_frag.h" #include "lwip/ip_frag.h"
#include "lwip/udp.h" #include "lwip/udp.h"
#include "lwip/tcp.h" #include "lwip/tcp.h"
#include "lwip/tcpip.h" #include "lwip/tcpip.h"
static void (* tcpip_init_done)(void *arg) = NULL; static void (* tcpip_init_done)(void *arg) = NULL;
static void *tcpip_init_done_arg; static void *tcpip_init_done_arg;
static sys_mbox_t mbox; static sys_mbox_t mbox;
#if LWIP_TCP #if LWIP_TCP
static int tcpip_tcp_timer_active = 0; static int tcpip_tcp_timer_active = 0;
static void static void
tcpip_tcp_timer(void *arg) tcpip_tcp_timer(void *arg)
{ {
(void)arg; (void)arg;
/* call TCP timer handler */ /* call TCP timer handler */
tcp_tmr(); tcp_tmr();
/* timer still needed? */ /* timer still needed? */
if (tcp_active_pcbs || tcp_tw_pcbs) { if (tcp_active_pcbs || tcp_tw_pcbs) {
/* restart timer */ /* restart timer */
sys_timeout(TCP_TMR_INTERVAL, tcpip_tcp_timer, NULL); sys_timeout(TCP_TMR_INTERVAL, tcpip_tcp_timer, NULL);
} else { } else {
/* disable timer */ /* disable timer */
tcpip_tcp_timer_active = 0; tcpip_tcp_timer_active = 0;
} }
} }
#if !NO_SYS #if !NO_SYS
void void
tcp_timer_needed(void) tcp_timer_needed(void)
{ {
/* timer is off but needed again? */ /* timer is off but needed again? */
if (!tcpip_tcp_timer_active && (tcp_active_pcbs || tcp_tw_pcbs)) { if (!tcpip_tcp_timer_active && (tcp_active_pcbs || tcp_tw_pcbs)) {
/* enable and start timer */ /* enable and start timer */
tcpip_tcp_timer_active = 1; tcpip_tcp_timer_active = 1;
sys_timeout(TCP_TMR_INTERVAL, tcpip_tcp_timer, NULL); sys_timeout(TCP_TMR_INTERVAL, tcpip_tcp_timer, NULL);
} }
} }
#endif /* !NO_SYS */ #endif /* !NO_SYS */
#endif /* LWIP_TCP */ #endif /* LWIP_TCP */
#if IP_REASSEMBLY #if IP_REASSEMBLY
static void static void
ip_timer(void *data) ip_timer(void *data)
{ {
LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip: ip_reass_tmr()\n")); LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip: ip_reass_tmr()\n"));
ip_reass_tmr(); ip_reass_tmr();
sys_timeout(1000, ip_timer, NULL); sys_timeout(1000, ip_timer, NULL);
} }
#endif #endif
static void static void
tcpip_thread(void *arg) tcpip_thread(void *arg)
{ {
struct tcpip_msg *msg; struct tcpip_msg *msg;
(void)arg; (void)arg;
ip_init(); ip_init();
#if LWIP_UDP #if LWIP_UDP
udp_init(); udp_init();
#endif #endif
#if LWIP_TCP #if LWIP_TCP
tcp_init(); tcp_init();
#endif #endif
#if IP_REASSEMBLY #if IP_REASSEMBLY
sys_timeout(1000, ip_timer, NULL); sys_timeout(1000, ip_timer, NULL);
#endif #endif
if (tcpip_init_done != NULL) { if (tcpip_init_done != NULL) {
tcpip_init_done(tcpip_init_done_arg); tcpip_init_done(tcpip_init_done_arg);
} }
while (1) { /* MAIN Loop */ while (1) { /* MAIN Loop */
sys_mbox_fetch(mbox, (void *)&msg); sys_mbox_fetch(mbox, (void *)&msg);
switch (msg->type) { switch (msg->type) {
case TCPIP_MSG_API: case TCPIP_MSG_API:
LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: API message %p\n", (void *)msg)); LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: API message %p\n", (void *)msg));
api_msg_input(msg->msg.apimsg); api_msg_input(msg->msg.apimsg);
break; break;
case TCPIP_MSG_INPUT: case TCPIP_MSG_INPUT:
LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: IP packet %p\n", (void *)msg)); LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: IP packet %p\n", (void *)msg));
ip_input(msg->msg.inp.p, msg->msg.inp.netif); ip_input(msg->msg.inp.p, msg->msg.inp.netif);
break; break;
case TCPIP_MSG_CALLBACK: case TCPIP_MSG_CALLBACK:
LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: CALLBACK %p\n", (void *)msg)); LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: CALLBACK %p\n", (void *)msg));
msg->msg.cb.f(msg->msg.cb.ctx); msg->msg.cb.f(msg->msg.cb.ctx);
break; break;
default: default:
break; break;
} }
memp_free(MEMP_TCPIP_MSG, msg); memp_free(MEMP_TCPIP_MSG, msg);
} }
} }
err_t err_t
tcpip_input(struct pbuf *p, struct netif *inp) tcpip_input(struct pbuf *p, struct netif *inp)
{ {
struct tcpip_msg *msg; struct tcpip_msg *msg;
msg = memp_malloc(MEMP_TCPIP_MSG); msg = memp_malloc(MEMP_TCPIP_MSG);
if (msg == NULL) { if (msg == NULL) {
pbuf_free(p); pbuf_free(p);
return ERR_MEM; return ERR_MEM;
} }
msg->type = TCPIP_MSG_INPUT; msg->type = TCPIP_MSG_INPUT;
msg->msg.inp.p = p; msg->msg.inp.p = p;
msg->msg.inp.netif = inp; msg->msg.inp.netif = inp;
sys_mbox_post(mbox, msg); sys_mbox_post(mbox, msg);
return ERR_OK; return ERR_OK;
} }
err_t err_t
tcpip_callback(void (*f)(void *ctx), void *ctx) tcpip_callback(void (*f)(void *ctx), void *ctx)
{ {
struct tcpip_msg *msg; struct tcpip_msg *msg;
msg = memp_malloc(MEMP_TCPIP_MSG); msg = memp_malloc(MEMP_TCPIP_MSG);
if (msg == NULL) { if (msg == NULL) {
return ERR_MEM; return ERR_MEM;
} }
msg->type = TCPIP_MSG_CALLBACK; msg->type = TCPIP_MSG_CALLBACK;
msg->msg.cb.f = f; msg->msg.cb.f = f;
msg->msg.cb.ctx = ctx; msg->msg.cb.ctx = ctx;
sys_mbox_post(mbox, msg); sys_mbox_post(mbox, msg);
return ERR_OK; return ERR_OK;
} }
void void
tcpip_apimsg(struct api_msg *apimsg) tcpip_apimsg(struct api_msg *apimsg)
{ {
struct tcpip_msg *msg; struct tcpip_msg *msg;
msg = memp_malloc(MEMP_TCPIP_MSG); msg = memp_malloc(MEMP_TCPIP_MSG);
if (msg == NULL) { if (msg == NULL) {
memp_free(MEMP_API_MSG, apimsg); memp_free(MEMP_API_MSG, apimsg);
return; return;
} }
msg->type = TCPIP_MSG_API; msg->type = TCPIP_MSG_API;
msg->msg.apimsg = apimsg; msg->msg.apimsg = apimsg;
sys_mbox_post(mbox, msg); sys_mbox_post(mbox, msg);
} }
void void
tcpip_init(void (* initfunc)(void *), void *arg) tcpip_init(void (* initfunc)(void *), void *arg)
{ {
tcpip_init_done = initfunc; tcpip_init_done = initfunc;
tcpip_init_done_arg = arg; tcpip_init_done_arg = arg;
mbox = sys_mbox_new(); mbox = sys_mbox_new();
sys_thread_new(tcpip_thread, NULL, TCPIP_THREAD_PRIO); sys_thread_new(tcpip_thread, NULL, TCPIP_THREAD_PRIO);
} }

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,168 +1,168 @@
/* /*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science. * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, * 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products * 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE. * OF SUCH DAMAGE.
* *
* This file is part of the lwIP TCP/IP stack. * This file is part of the lwIP TCP/IP stack.
* *
* Author: Adam Dunkels <adam@sics.se> * Author: Adam Dunkels <adam@sics.se>
* *
*/ */
/* inet6.c /* inet6.c
* *
* Functions common to all TCP/IP modules, such as the Internet checksum and the * Functions common to all TCP/IP modules, such as the Internet checksum and the
* byte order functions. * byte order functions.
* *
*/ */
#include "lwip/opt.h" #include "lwip/opt.h"
#include "lwip/def.h" #include "lwip/def.h"
#include "lwip/inet.h" #include "lwip/inet.h"
/* chksum: /* chksum:
* *
* Sums up all 16 bit words in a memory portion. Also includes any odd byte. * Sums up all 16 bit words in a memory portion. Also includes any odd byte.
* This function is used by the other checksum functions. * This function is used by the other checksum functions.
* *
* For now, this is not optimized. Must be optimized for the particular processor * For now, this is not optimized. Must be optimized for the particular processor
* arcitecture on which it is to run. Preferebly coded in assembler. * arcitecture on which it is to run. Preferebly coded in assembler.
*/ */
static u32_t static u32_t
chksum(void *dataptr, u16_t len) chksum(void *dataptr, u16_t len)
{ {
u16_t *sdataptr = dataptr; u16_t *sdataptr = dataptr;
u32_t acc; u32_t acc;
for(acc = 0; len > 1; len -= 2) { for(acc = 0; len > 1; len -= 2) {
acc += *sdataptr++; acc += *sdataptr++;
} }
/* add up any odd byte */ /* add up any odd byte */
if (len == 1) { if (len == 1) {
acc += htons((u16_t)(*(u8_t *)dataptr) << 8); acc += htons((u16_t)(*(u8_t *)dataptr) << 8);
} }
return acc; return acc;
} }
/* inet_chksum_pseudo: /* inet_chksum_pseudo:
* *
* Calculates the pseudo Internet checksum used by TCP and UDP for a pbuf chain. * Calculates the pseudo Internet checksum used by TCP and UDP for a pbuf chain.
*/ */
u16_t u16_t
inet_chksum_pseudo(struct pbuf *p, inet_chksum_pseudo(struct pbuf *p,
struct ip_addr *src, struct ip_addr *dest, struct ip_addr *src, struct ip_addr *dest,
u8_t proto, u32_t proto_len) u8_t proto, u32_t proto_len)
{ {
u32_t acc; u32_t acc;
struct pbuf *q; struct pbuf *q;
u8_t swapped, i; u8_t swapped, i;
acc = 0; acc = 0;
swapped = 0; swapped = 0;
for(q = p; q != NULL; q = q->next) { for(q = p; q != NULL; q = q->next) {
acc += chksum(q->payload, q->len); acc += chksum(q->payload, q->len);
while (acc >> 16) { while (acc >> 16) {
acc = (acc & 0xffff) + (acc >> 16); acc = (acc & 0xffff) + (acc >> 16);
} }
if (q->len % 2 != 0) { if (q->len % 2 != 0) {
swapped = 1 - swapped; swapped = 1 - swapped;
acc = ((acc & 0xff) << 8) | ((acc & 0xff00) >> 8); acc = ((acc & 0xff) << 8) | ((acc & 0xff00) >> 8);
} }
} }
if (swapped) { if (swapped) {
acc = ((acc & 0xff) << 8) | ((acc & 0xff00) >> 8); acc = ((acc & 0xff) << 8) | ((acc & 0xff00) >> 8);
} }
for(i = 0; i < 8; i++) { for(i = 0; i < 8; i++) {
acc += ((u16_t *)src->addr)[i] & 0xffff; acc += ((u16_t *)src->addr)[i] & 0xffff;
acc += ((u16_t *)dest->addr)[i] & 0xffff; acc += ((u16_t *)dest->addr)[i] & 0xffff;
while (acc >> 16) { while (acc >> 16) {
acc = (acc & 0xffff) + (acc >> 16); acc = (acc & 0xffff) + (acc >> 16);
} }
} }
acc += (u16_t)htons((u16_t)proto); acc += (u16_t)htons((u16_t)proto);
acc += ((u16_t *)&proto_len)[0] & 0xffff; acc += ((u16_t *)&proto_len)[0] & 0xffff;
acc += ((u16_t *)&proto_len)[1] & 0xffff; acc += ((u16_t *)&proto_len)[1] & 0xffff;
while (acc >> 16) { while (acc >> 16) {
acc = (acc & 0xffff) + (acc >> 16); acc = (acc & 0xffff) + (acc >> 16);
} }
return ~(acc & 0xffff); return ~(acc & 0xffff);
} }
/* inet_chksum: /* inet_chksum:
* *
* Calculates the Internet checksum over a portion of memory. Used primarely for IP * Calculates the Internet checksum over a portion of memory. Used primarely for IP
* and ICMP. * and ICMP.
*/ */
u16_t u16_t
inet_chksum(void *dataptr, u16_t len) inet_chksum(void *dataptr, u16_t len)
{ {
u32_t acc, sum; u32_t acc, sum;
acc = chksum(dataptr, len); acc = chksum(dataptr, len);
sum = (acc & 0xffff) + (acc >> 16); sum = (acc & 0xffff) + (acc >> 16);
sum += (sum >> 16); sum += (sum >> 16);
return ~(sum & 0xffff); return ~(sum & 0xffff);
} }
u16_t u16_t
inet_chksum_pbuf(struct pbuf *p) inet_chksum_pbuf(struct pbuf *p)
{ {
u32_t acc; u32_t acc;
struct pbuf *q; struct pbuf *q;
u8_t swapped; u8_t swapped;
acc = 0; acc = 0;
swapped = 0; swapped = 0;
for(q = p; q != NULL; q = q->next) { for(q = p; q != NULL; q = q->next) {
acc += chksum(q->payload, q->len); acc += chksum(q->payload, q->len);
while (acc >> 16) { while (acc >> 16) {
acc = (acc & 0xffff) + (acc >> 16); acc = (acc & 0xffff) + (acc >> 16);
} }
if (q->len % 2 != 0) { if (q->len % 2 != 0) {
swapped = 1 - swapped; swapped = 1 - swapped;
acc = (acc & 0xff << 8) | (acc & 0xff00 >> 8); acc = (acc & 0xff << 8) | (acc & 0xff00 >> 8);
} }
} }
if (swapped) { if (swapped) {
acc = ((acc & 0xff) << 8) | ((acc & 0xff00) >> 8); acc = ((acc & 0xff) << 8) | ((acc & 0xff00) >> 8);
} }
return ~(acc & 0xffff); return ~(acc & 0xffff);
} }

View file

@ -1,202 +1,202 @@
/* /*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science. * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, * 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products * 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE. * OF SUCH DAMAGE.
* *
* This file is part of the lwIP TCP/IP stack. * This file is part of the lwIP TCP/IP stack.
* *
* Author: Adam Dunkels <adam@sics.se> * Author: Adam Dunkels <adam@sics.se>
* *
*/ */
/* Some ICMP messages should be passed to the transport protocols. This /* Some ICMP messages should be passed to the transport protocols. This
is not implemented. */ is not implemented. */
#include <string.h> #include <string.h>
#include "lwip/opt.h" #include "lwip/opt.h"
#include "lwip/icmp.h" #include "lwip/icmp.h"
#include "lwip/inet.h" #include "lwip/inet.h"
#include "lwip/ip.h" #include "lwip/ip.h"
#include "lwip/def.h" #include "lwip/def.h"
#include "lwip/stats.h" #include "lwip/stats.h"
#include "lwip/snmp.h" #include "lwip/snmp.h"
void void
icmp_input(struct pbuf *p, struct netif *inp) icmp_input(struct pbuf *p, struct netif *inp)
{ {
u8_t type; u8_t type;
u8_t code; u8_t code;
struct icmp_echo_hdr *iecho; struct icmp_echo_hdr *iecho;
struct ip_hdr *iphdr; struct ip_hdr *iphdr;
struct ip_addr tmpaddr; struct ip_addr tmpaddr;
u16_t hlen; u16_t hlen;
ICMP_STATS_INC(icmp.recv); ICMP_STATS_INC(icmp.recv);
snmp_inc_icmpinmsgs(); snmp_inc_icmpinmsgs();
iphdr = p->payload; iphdr = p->payload;
hlen = IPH_HL(iphdr) * 4; hlen = IPH_HL(iphdr) * 4;
if (pbuf_header(p, -((s16_t)hlen)) || (p->tot_len < sizeof(u16_t)*2)) { if (pbuf_header(p, -((s16_t)hlen)) || (p->tot_len < sizeof(u16_t)*2)) {
LWIP_DEBUGF(ICMP_DEBUG, ("icmp_input: short ICMP (%"U16_F" bytes) received\n", p->tot_len)); LWIP_DEBUGF(ICMP_DEBUG, ("icmp_input: short ICMP (%"U16_F" bytes) received\n", p->tot_len));
pbuf_free(p); pbuf_free(p);
ICMP_STATS_INC(icmp.lenerr); ICMP_STATS_INC(icmp.lenerr);
snmp_inc_icmpinerrors(); snmp_inc_icmpinerrors();
return; return;
} }
type = *((u8_t *)p->payload); type = *((u8_t *)p->payload);
code = *(((u8_t *)p->payload)+1); code = *(((u8_t *)p->payload)+1);
switch (type) { switch (type) {
case ICMP_ECHO: case ICMP_ECHO:
/* broadcast or multicast destination address? */ /* broadcast or multicast destination address? */
if (ip_addr_isbroadcast(&iphdr->dest, inp) || ip_addr_ismulticast(&iphdr->dest)) { if (ip_addr_isbroadcast(&iphdr->dest, inp) || ip_addr_ismulticast(&iphdr->dest)) {
LWIP_DEBUGF(ICMP_DEBUG, ("icmp_input: Not echoing to multicast or broadcast pings\n")); LWIP_DEBUGF(ICMP_DEBUG, ("icmp_input: Not echoing to multicast or broadcast pings\n"));
ICMP_STATS_INC(icmp.err); ICMP_STATS_INC(icmp.err);
pbuf_free(p); pbuf_free(p);
return; return;
} }
LWIP_DEBUGF(ICMP_DEBUG, ("icmp_input: ping\n")); LWIP_DEBUGF(ICMP_DEBUG, ("icmp_input: ping\n"));
if (p->tot_len < sizeof(struct icmp_echo_hdr)) { if (p->tot_len < sizeof(struct icmp_echo_hdr)) {
LWIP_DEBUGF(ICMP_DEBUG, ("icmp_input: bad ICMP echo received\n")); LWIP_DEBUGF(ICMP_DEBUG, ("icmp_input: bad ICMP echo received\n"));
pbuf_free(p); pbuf_free(p);
ICMP_STATS_INC(icmp.lenerr); ICMP_STATS_INC(icmp.lenerr);
snmp_inc_icmpinerrors(); snmp_inc_icmpinerrors();
return; return;
} }
iecho = p->payload; iecho = p->payload;
if (inet_chksum_pbuf(p) != 0) { if (inet_chksum_pbuf(p) != 0) {
LWIP_DEBUGF(ICMP_DEBUG, ("icmp_input: checksum failed for received ICMP echo\n")); LWIP_DEBUGF(ICMP_DEBUG, ("icmp_input: checksum failed for received ICMP echo\n"));
pbuf_free(p); pbuf_free(p);
ICMP_STATS_INC(icmp.chkerr); ICMP_STATS_INC(icmp.chkerr);
snmp_inc_icmpinerrors(); snmp_inc_icmpinerrors();
return; return;
} }
tmpaddr.addr = iphdr->src.addr; tmpaddr.addr = iphdr->src.addr;
iphdr->src.addr = iphdr->dest.addr; iphdr->src.addr = iphdr->dest.addr;
iphdr->dest.addr = tmpaddr.addr; iphdr->dest.addr = tmpaddr.addr;
ICMPH_TYPE_SET(iecho, ICMP_ER); ICMPH_TYPE_SET(iecho, ICMP_ER);
/* adjust the checksum */ /* adjust the checksum */
if (iecho->chksum >= htons(0xffff - (ICMP_ECHO << 8))) { if (iecho->chksum >= htons(0xffff - (ICMP_ECHO << 8))) {
iecho->chksum += htons(ICMP_ECHO << 8) + 1; iecho->chksum += htons(ICMP_ECHO << 8) + 1;
} else { } else {
iecho->chksum += htons(ICMP_ECHO << 8); iecho->chksum += htons(ICMP_ECHO << 8);
} }
ICMP_STATS_INC(icmp.xmit); ICMP_STATS_INC(icmp.xmit);
/* increase number of messages attempted to send */ /* increase number of messages attempted to send */
snmp_inc_icmpoutmsgs(); snmp_inc_icmpoutmsgs();
/* increase number of echo replies attempted to send */ /* increase number of echo replies attempted to send */
snmp_inc_icmpoutechoreps(); snmp_inc_icmpoutechoreps();
pbuf_header(p, hlen); pbuf_header(p, hlen);
ip_output_if(p, &(iphdr->src), IP_HDRINCL, ip_output_if(p, &(iphdr->src), IP_HDRINCL,
IPH_TTL(iphdr), 0, IP_PROTO_ICMP, inp); IPH_TTL(iphdr), 0, IP_PROTO_ICMP, inp);
break; break;
default: default:
LWIP_DEBUGF(ICMP_DEBUG, ("icmp_input: ICMP type %"S16_F" code %"S16_F" not supported.\n", (s16_t)type, (s16_t)code)); LWIP_DEBUGF(ICMP_DEBUG, ("icmp_input: ICMP type %"S16_F" code %"S16_F" not supported.\n", (s16_t)type, (s16_t)code));
ICMP_STATS_INC(icmp.proterr); ICMP_STATS_INC(icmp.proterr);
ICMP_STATS_INC(icmp.drop); ICMP_STATS_INC(icmp.drop);
} }
pbuf_free(p); pbuf_free(p);
} }
void void
icmp_dest_unreach(struct pbuf *p, enum icmp_dur_type t) icmp_dest_unreach(struct pbuf *p, enum icmp_dur_type t)
{ {
struct pbuf *q; struct pbuf *q;
struct ip_hdr *iphdr; struct ip_hdr *iphdr;
struct icmp_dur_hdr *idur; struct icmp_dur_hdr *idur;
q = pbuf_alloc(PBUF_IP, 8 + IP_HLEN + 8, PBUF_RAM); q = pbuf_alloc(PBUF_IP, 8 + IP_HLEN + 8, PBUF_RAM);
/* ICMP header + IP header + 8 bytes of data */ /* ICMP header + IP header + 8 bytes of data */
iphdr = p->payload; iphdr = p->payload;
idur = q->payload; idur = q->payload;
ICMPH_TYPE_SET(idur, ICMP_DUR); ICMPH_TYPE_SET(idur, ICMP_DUR);
ICMPH_CODE_SET(idur, t); ICMPH_CODE_SET(idur, t);
memcpy((u8_t *)q->payload + 8, p->payload, IP_HLEN + 8); memcpy((u8_t *)q->payload + 8, p->payload, IP_HLEN + 8);
/* calculate checksum */ /* calculate checksum */
idur->chksum = 0; idur->chksum = 0;
idur->chksum = inet_chksum(idur, q->len); idur->chksum = inet_chksum(idur, q->len);
ICMP_STATS_INC(icmp.xmit); ICMP_STATS_INC(icmp.xmit);
/* increase number of messages attempted to send */ /* increase number of messages attempted to send */
snmp_inc_icmpoutmsgs(); snmp_inc_icmpoutmsgs();
/* increase number of destination unreachable messages attempted to send */ /* increase number of destination unreachable messages attempted to send */
snmp_inc_icmpoutdestunreachs(); snmp_inc_icmpoutdestunreachs();
ip_output(q, NULL, &(iphdr->src), ip_output(q, NULL, &(iphdr->src),
ICMP_TTL, 0, IP_PROTO_ICMP); ICMP_TTL, 0, IP_PROTO_ICMP);
pbuf_free(q); pbuf_free(q);
} }
#if IP_FORWARD #if IP_FORWARD
void void
icmp_time_exceeded(struct pbuf *p, enum icmp_te_type t) icmp_time_exceeded(struct pbuf *p, enum icmp_te_type t)
{ {
struct pbuf *q; struct pbuf *q;
struct ip_hdr *iphdr; struct ip_hdr *iphdr;
struct icmp_te_hdr *tehdr; struct icmp_te_hdr *tehdr;
q = pbuf_alloc(PBUF_IP, 8 + IP_HLEN + 8, PBUF_RAM); q = pbuf_alloc(PBUF_IP, 8 + IP_HLEN + 8, PBUF_RAM);
iphdr = p->payload; iphdr = p->payload;
LWIP_DEBUGF(ICMP_DEBUG, ("icmp_time_exceeded from ")); LWIP_DEBUGF(ICMP_DEBUG, ("icmp_time_exceeded from "));
ip_addr_debug_print(ICMP_DEBUG, &(iphdr->src)); ip_addr_debug_print(ICMP_DEBUG, &(iphdr->src));
LWIP_DEBUGF(ICMP_DEBUG, (" to ")); LWIP_DEBUGF(ICMP_DEBUG, (" to "));
ip_addr_debug_print(ICMP_DEBUG, &(iphdr->dest)); ip_addr_debug_print(ICMP_DEBUG, &(iphdr->dest));
LWIP_DEBUGF(ICMP_DEBUG, ("\n")); LWIP_DEBUGF(ICMP_DEBUG, ("\n"));
tehdr = q->payload; tehdr = q->payload;
ICMPH_TYPE_SET(tehdr, ICMP_TE); ICMPH_TYPE_SET(tehdr, ICMP_TE);
ICMPH_CODE_SET(tehdr, t); ICMPH_CODE_SET(tehdr, t);
/* copy fields from original packet */ /* copy fields from original packet */
memcpy((u8_t *)q->payload + 8, (u8_t *)p->payload, IP_HLEN + 8); memcpy((u8_t *)q->payload + 8, (u8_t *)p->payload, IP_HLEN + 8);
/* calculate checksum */ /* calculate checksum */
tehdr->chksum = 0; tehdr->chksum = 0;
tehdr->chksum = inet_chksum(tehdr, q->len); tehdr->chksum = inet_chksum(tehdr, q->len);
ICMP_STATS_INC(icmp.xmit); ICMP_STATS_INC(icmp.xmit);
/* increase number of messages attempted to send */ /* increase number of messages attempted to send */
snmp_inc_icmpoutmsgs(); snmp_inc_icmpoutmsgs();
/* increase number of destination unreachable messages attempted to send */ /* increase number of destination unreachable messages attempted to send */
snmp_inc_icmpouttimeexcds(); snmp_inc_icmpouttimeexcds();
ip_output(q, NULL, &(iphdr->src), ip_output(q, NULL, &(iphdr->src),
ICMP_TTL, 0, IP_PROTO_ICMP); ICMP_TTL, 0, IP_PROTO_ICMP);
pbuf_free(q); pbuf_free(q);
} }
#endif /* IP_FORWARD */ #endif /* IP_FORWARD */

File diff suppressed because it is too large Load diff

View file

@ -1,78 +1,78 @@
/* /*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science. * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, * 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products * 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE. * OF SUCH DAMAGE.
* *
* This file is part of the lwIP TCP/IP stack. * This file is part of the lwIP TCP/IP stack.
* *
* Author: Adam Dunkels <adam@sics.se> * Author: Adam Dunkels <adam@sics.se>
* *
*/ */
#include "lwip/ip_addr.h" #include "lwip/ip_addr.h"
#include "lwip/inet.h" #include "lwip/inet.h"
#include "lwip/netif.h" #include "lwip/netif.h"
#define IP_ADDR_ANY_VALUE 0x00000000UL #define IP_ADDR_ANY_VALUE 0x00000000UL
#define IP_ADDR_BROADCAST_VALUE 0xffffffffUL #define IP_ADDR_BROADCAST_VALUE 0xffffffffUL
/* used by IP_ADDR_ANY and IP_ADDR_BROADCAST in ip_addr.h */ /* used by IP_ADDR_ANY and IP_ADDR_BROADCAST in ip_addr.h */
const struct ip_addr ip_addr_any = { IP_ADDR_ANY_VALUE }; const struct ip_addr ip_addr_any = { IP_ADDR_ANY_VALUE };
const struct ip_addr ip_addr_broadcast = { IP_ADDR_BROADCAST_VALUE }; const struct ip_addr ip_addr_broadcast = { IP_ADDR_BROADCAST_VALUE };
/* Determine if an address is a broadcast address on a network interface /* Determine if an address is a broadcast address on a network interface
* *
* @param addr address to be checked * @param addr address to be checked
* @param netif the network interface against which the address is checked * @param netif the network interface against which the address is checked
* @return returns non-zero if the address is a broadcast address * @return returns non-zero if the address is a broadcast address
* *
*/ */
u8_t ip_addr_isbroadcast(struct ip_addr *addr, struct netif *netif) u8_t ip_addr_isbroadcast(struct ip_addr *addr, struct netif *netif)
{ {
u32_t addr2test; u32_t addr2test;
addr2test = addr->addr; addr2test = addr->addr;
/* all ones (broadcast) or all zeroes (old skool broadcast) */ /* all ones (broadcast) or all zeroes (old skool broadcast) */
if ((~addr2test == IP_ADDR_ANY_VALUE) || if ((~addr2test == IP_ADDR_ANY_VALUE) ||
(addr2test == IP_ADDR_ANY_VALUE)) (addr2test == IP_ADDR_ANY_VALUE))
return 1; return 1;
/* no broadcast support on this network interface? */ /* no broadcast support on this network interface? */
else if ((netif->flags & NETIF_FLAG_BROADCAST) == 0) else if ((netif->flags & NETIF_FLAG_BROADCAST) == 0)
/* the given address cannot be a broadcast address /* the given address cannot be a broadcast address
* nor can we check against any broadcast addresses */ * nor can we check against any broadcast addresses */
return 0; return 0;
/* address matches network interface address exactly? => no broadcast */ /* address matches network interface address exactly? => no broadcast */
else if (addr2test == netif->ip_addr.addr) else if (addr2test == netif->ip_addr.addr)
return 0; return 0;
/* on the same (sub) network... */ /* on the same (sub) network... */
else if (ip_addr_netcmp(addr, &(netif->ip_addr), &(netif->netmask)) else if (ip_addr_netcmp(addr, &(netif->ip_addr), &(netif->netmask))
/* ...and host identifier bits are all ones? =>... */ /* ...and host identifier bits are all ones? =>... */
&& ((addr2test & ~netif->netmask.addr) == && ((addr2test & ~netif->netmask.addr) ==
(IP_ADDR_BROADCAST_VALUE & ~netif->netmask.addr))) (IP_ADDR_BROADCAST_VALUE & ~netif->netmask.addr)))
/* => network broadcast address */ /* => network broadcast address */
return 1; return 1;
else else
return 0; return 0;
} }

View file

@ -1,388 +1,388 @@
/* @file /* @file
* *
* This is the IP packet segmentation and reassembly implementation. * This is the IP packet segmentation and reassembly implementation.
* *
*/ */
/* /*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science. * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, * 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products * 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE. * OF SUCH DAMAGE.
* *
* This file is part of the lwIP TCP/IP stack. * This file is part of the lwIP TCP/IP stack.
* *
* Author: Jani Monoses <jani@iv.ro> * Author: Jani Monoses <jani@iv.ro>
* original reassembly code by Adam Dunkels <adam@sics.se> * original reassembly code by Adam Dunkels <adam@sics.se>
* *
*/ */
#include <string.h> #include <string.h>
#include "lwip/opt.h" #include "lwip/opt.h"
#include "lwip/ip.h" #include "lwip/ip.h"
#include "lwip/ip_frag.h" #include "lwip/ip_frag.h"
#include "lwip/netif.h" #include "lwip/netif.h"
#include "lwip/snmp.h" #include "lwip/snmp.h"
#include "lwip/stats.h" #include "lwip/stats.h"
static u8_t ip_reassbuf[IP_HLEN + IP_REASS_BUFSIZE]; static u8_t ip_reassbuf[IP_HLEN + IP_REASS_BUFSIZE];
static u8_t ip_reassbitmap[IP_REASS_BUFSIZE / (8 * 8) + 1]; static u8_t ip_reassbitmap[IP_REASS_BUFSIZE / (8 * 8) + 1];
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 ip_reasslen; static u16_t ip_reasslen;
static u8_t ip_reassflags; static u8_t ip_reassflags;
#define IP_REASS_FLAG_LASTFRAG 0x01 #define IP_REASS_FLAG_LASTFRAG 0x01
static u8_t ip_reasstmr; static u8_t ip_reasstmr;
/* /*
* Copy len bytes from offset in pbuf to buffer * Copy len bytes from offset in pbuf to buffer
* *
* helper used by both ip_reass and ip_frag * helper used by both ip_reass and ip_frag
*/ */
static struct pbuf * static struct pbuf *
copy_from_pbuf(struct pbuf *p, u16_t * offset, copy_from_pbuf(struct pbuf *p, u16_t * offset,
u8_t * buffer, u16_t len) u8_t * buffer, u16_t len)
{ {
u16_t l; u16_t l;
p->payload = (u8_t *)p->payload + *offset; p->payload = (u8_t *)p->payload + *offset;
p->len -= *offset; p->len -= *offset;
while (len) { while (len) {
l = len < p->len ? len : p->len; l = len < p->len ? len : p->len;
memcpy(buffer, p->payload, l); memcpy(buffer, p->payload, l);
buffer += l; buffer += l;
len -= l; len -= l;
if (len) if (len)
p = p->next; p = p->next;
else else
*offset = l; *offset = l;
} }
return p; return p;
} }
/** /**
* Initializes IP reassembly and fragmentation states. * Initializes IP reassembly and fragmentation states.
*/ */
void void
ip_frag_init(void) ip_frag_init(void)
{ {
ip_reasstmr = 0; ip_reasstmr = 0;
ip_reassflags = 0; ip_reassflags = 0;
ip_reasslen = 0; ip_reasslen = 0;
memset(ip_reassbitmap, 0, sizeof(ip_reassbitmap)); memset(ip_reassbitmap, 0, sizeof(ip_reassbitmap));
} }
/** /**
* Reassembly timer base function * Reassembly timer base function
* for both NO_SYS == 0 and 1 (!). * for both NO_SYS == 0 and 1 (!).
* *
* Should be called every 1000 msec. * Should be called every 1000 msec.
*/ */
void void
ip_reass_tmr(void) ip_reass_tmr(void)
{ {
if (ip_reasstmr > 0) { if (ip_reasstmr > 0) {
ip_reasstmr--; ip_reasstmr--;
LWIP_DEBUGF(IP_REASS_DEBUG, ("ip_reass_tmr: timer dec %"U16_F"\n",(u16_t)ip_reasstmr)); LWIP_DEBUGF(IP_REASS_DEBUG, ("ip_reass_tmr: timer dec %"U16_F"\n",(u16_t)ip_reasstmr));
if (ip_reasstmr == 0) { if (ip_reasstmr == 0) {
/* reassembly timed out */ /* reassembly timed out */
snmp_inc_ipreasmfails(); snmp_inc_ipreasmfails();
} }
} }
} }
/** /**
* Reassembles incoming IP fragments into an IP datagram. * Reassembles incoming IP fragments into an IP datagram.
* *
* @param p points to a pbuf chain of the fragment * @param p points to a pbuf chain of the fragment
* @return NULL if reassembly is incomplete, ? otherwise * @return NULL if reassembly is incomplete, ? otherwise
*/ */
struct pbuf * struct pbuf *
ip_reass(struct pbuf *p) ip_reass(struct pbuf *p)
{ {
struct pbuf *q; struct pbuf *q;
struct ip_hdr *fraghdr, *iphdr; struct ip_hdr *fraghdr, *iphdr;
u16_t offset, len; u16_t offset, len;
u16_t i; u16_t i;
IPFRAG_STATS_INC(ip_frag.recv); IPFRAG_STATS_INC(ip_frag.recv);
snmp_inc_ipreasmreqds(); snmp_inc_ipreasmreqds();
iphdr = (struct ip_hdr *) ip_reassbuf; iphdr = (struct ip_hdr *) ip_reassbuf;
fraghdr = (struct ip_hdr *) p->payload; fraghdr = (struct ip_hdr *) p->payload;
/* If ip_reasstmr is zero, no packet is present in the buffer, so we /* If ip_reasstmr is zero, no packet is present in the buffer, so we
write the IP header of the fragment into the reassembly write the IP header of the fragment into the reassembly
buffer. The timer is updated with the maximum age. */ buffer. The timer is updated with the maximum age. */
if (ip_reasstmr == 0) { if (ip_reasstmr == 0) {
LWIP_DEBUGF(IP_REASS_DEBUG, ("ip_reass: new packet\n")); LWIP_DEBUGF(IP_REASS_DEBUG, ("ip_reass: new packet\n"));
memcpy(iphdr, fraghdr, IP_HLEN); memcpy(iphdr, fraghdr, IP_HLEN);
ip_reasstmr = IP_REASS_MAXAGE; ip_reasstmr = IP_REASS_MAXAGE;
ip_reassflags = 0; ip_reassflags = 0;
/* Clear the bitmap. */ /* Clear the bitmap. */
memset(ip_reassbitmap, 0, sizeof(ip_reassbitmap)); memset(ip_reassbitmap, 0, sizeof(ip_reassbitmap));
} }
/* Check if the incoming fragment matches the one currently present /* Check if the incoming fragment matches the one currently present
in the reasembly buffer. If so, we proceed with copying the in the reasembly buffer. If so, we proceed with copying the
fragment into the buffer. */ fragment into the buffer. */
if (ip_addr_cmp(&iphdr->src, &fraghdr->src) && if (ip_addr_cmp(&iphdr->src, &fraghdr->src) &&
ip_addr_cmp(&iphdr->dest, &fraghdr->dest) && ip_addr_cmp(&iphdr->dest, &fraghdr->dest) &&
IPH_ID(iphdr) == IPH_ID(fraghdr)) { IPH_ID(iphdr) == IPH_ID(fraghdr)) {
LWIP_DEBUGF(IP_REASS_DEBUG, ("ip_reass: matching previous fragment ID=%"X16_F"\n", LWIP_DEBUGF(IP_REASS_DEBUG, ("ip_reass: matching previous fragment ID=%"X16_F"\n",
ntohs(IPH_ID(fraghdr)))); ntohs(IPH_ID(fraghdr))));
IPFRAG_STATS_INC(ip_frag.cachehit); IPFRAG_STATS_INC(ip_frag.cachehit);
/* Find out the offset in the reassembly buffer where we should /* Find out the offset in the reassembly buffer where we should
copy the fragment. */ copy the fragment. */
len = ntohs(IPH_LEN(fraghdr)) - IPH_HL(fraghdr) * 4; len = ntohs(IPH_LEN(fraghdr)) - IPH_HL(fraghdr) * 4;
offset = (ntohs(IPH_OFFSET(fraghdr)) & IP_OFFMASK) * 8; offset = (ntohs(IPH_OFFSET(fraghdr)) & IP_OFFMASK) * 8;
/* If the offset or the offset + fragment length overflows the /* If the offset or the offset + fragment length overflows the
reassembly buffer, we discard the entire packet. */ reassembly buffer, we discard the entire packet. */
if ((offset > IP_REASS_BUFSIZE) || ((offset + len) > IP_REASS_BUFSIZE)) { if ((offset > IP_REASS_BUFSIZE) || ((offset + len) > IP_REASS_BUFSIZE)) {
LWIP_DEBUGF(IP_REASS_DEBUG, LWIP_DEBUGF(IP_REASS_DEBUG,
("ip_reass: fragment outside of buffer (%"S16_F":%"S16_F"/%"S16_F").\n", offset, ("ip_reass: fragment outside of buffer (%"S16_F":%"S16_F"/%"S16_F").\n", offset,
offset + len, IP_REASS_BUFSIZE)); offset + len, IP_REASS_BUFSIZE));
ip_reasstmr = 0; ip_reasstmr = 0;
snmp_inc_ipreasmfails(); snmp_inc_ipreasmfails();
goto nullreturn; goto nullreturn;
} }
/* Copy the fragment into the reassembly buffer, at the right /* Copy the fragment into the reassembly buffer, at the right
offset. */ offset. */
LWIP_DEBUGF(IP_REASS_DEBUG, LWIP_DEBUGF(IP_REASS_DEBUG,
("ip_reass: copying with offset %"S16_F" into %"S16_F":%"S16_F"\n", offset, ("ip_reass: copying with offset %"S16_F" into %"S16_F":%"S16_F"\n", offset,
IP_HLEN + offset, IP_HLEN + offset + len)); IP_HLEN + offset, IP_HLEN + offset + len));
i = IPH_HL(fraghdr) * 4; i = IPH_HL(fraghdr) * 4;
copy_from_pbuf(p, &i, &ip_reassbuf[IP_HLEN + offset], len); copy_from_pbuf(p, &i, &ip_reassbuf[IP_HLEN + offset], len);
/* Update the bitmap. */ /* Update the bitmap. */
if (offset / (8 * 8) == (offset + len) / (8 * 8)) { if (offset / (8 * 8) == (offset + len) / (8 * 8)) {
LWIP_DEBUGF(IP_REASS_DEBUG, LWIP_DEBUGF(IP_REASS_DEBUG,
("ip_reass: updating single byte in bitmap.\n")); ("ip_reass: updating single byte in bitmap.\n"));
/* If the two endpoints are in the same byte, we only update that byte. */ /* If the two endpoints are in the same byte, we only update that byte. */
LWIP_ASSERT("offset / (8 * 8) < sizeof(ip_reassbitmap)", LWIP_ASSERT("offset / (8 * 8) < sizeof(ip_reassbitmap)",
offset / (8 * 8) < sizeof(ip_reassbitmap)); offset / (8 * 8) < sizeof(ip_reassbitmap));
ip_reassbitmap[offset / (8 * 8)] |= ip_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. */
LWIP_ASSERT("offset / (8 * 8) < sizeof(ip_reassbitmap)", LWIP_ASSERT("offset / (8 * 8) < sizeof(ip_reassbitmap)",
offset / (8 * 8) < sizeof(ip_reassbitmap)); offset / (8 * 8) < sizeof(ip_reassbitmap));
ip_reassbitmap[offset / (8 * 8)] |= bitmap_bits[(offset / 8) & 7]; ip_reassbitmap[offset / (8 * 8)] |= bitmap_bits[(offset / 8) & 7];
LWIP_DEBUGF(IP_REASS_DEBUG, LWIP_DEBUGF(IP_REASS_DEBUG,
("ip_reass: updating many bytes in bitmap (%"S16_F":%"S16_F").\n", ("ip_reass: updating many bytes in bitmap (%"S16_F":%"S16_F").\n",
1 + offset / (8 * 8), (offset + len) / (8 * 8))); 1 + offset / (8 * 8), (offset + len) / (8 * 8)));
for (i = 1 + offset / (8 * 8); i < (offset + len) / (8 * 8); ++i) { for (i = 1 + offset / (8 * 8); i < (offset + len) / (8 * 8); ++i) {
ip_reassbitmap[i] = 0xff; ip_reassbitmap[i] = 0xff;
} }
LWIP_ASSERT("(offset + len) / (8 * 8) < sizeof(ip_reassbitmap)", LWIP_ASSERT("(offset + len) / (8 * 8) < sizeof(ip_reassbitmap)",
(offset + len) / (8 * 8) < sizeof(ip_reassbitmap)); (offset + len) / (8 * 8) < sizeof(ip_reassbitmap));
ip_reassbitmap[(offset + len) / (8 * 8)] |= ip_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
know that this is the last fragment, so we can calculate the know that this is the last fragment, so we can calculate the
size of the entire packet. We also set the size of the entire packet. We also set the
IP_REASS_FLAG_LASTFRAG flag to indicate that we have received IP_REASS_FLAG_LASTFRAG flag to indicate that we have received
the final fragment. */ the final fragment. */
if ((ntohs(IPH_OFFSET(fraghdr)) & IP_MF) == 0) { if ((ntohs(IPH_OFFSET(fraghdr)) & IP_MF) == 0) {
ip_reassflags |= IP_REASS_FLAG_LASTFRAG; ip_reassflags |= IP_REASS_FLAG_LASTFRAG;
ip_reasslen = offset + len; ip_reasslen = offset + len;
LWIP_DEBUGF(IP_REASS_DEBUG, LWIP_DEBUGF(IP_REASS_DEBUG,
("ip_reass: last fragment seen, total len %"S16_F"\n", ("ip_reass: last fragment seen, total len %"S16_F"\n",
ip_reasslen)); ip_reasslen));
} }
/* Finally, we check if we have a full packet in the buffer. We do /* Finally, we check if we have a full packet in the buffer. We do
this by checking if we have the last fragment and if all bits this by checking if we have the last fragment and if all bits
in the bitmap are set. */ in the bitmap are set. */
if (ip_reassflags & IP_REASS_FLAG_LASTFRAG) { if (ip_reassflags & IP_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. */
LWIP_ASSERT("ip_reasslen / (8 * 8) - 1 < sizeof(ip_reassbitmap)", LWIP_ASSERT("ip_reasslen / (8 * 8) - 1 < sizeof(ip_reassbitmap)",
ip_reasslen / (8 * 8) - 1 < ((u16_t) sizeof(ip_reassbitmap))); ip_reasslen / (8 * 8) - 1 < ((u16_t) sizeof(ip_reassbitmap)));
for (i = 0; i < ip_reasslen / (8 * 8) - 1; ++i) { for (i = 0; i < ip_reasslen / (8 * 8) - 1; ++i) {
if (ip_reassbitmap[i] != 0xff) { if (ip_reassbitmap[i] != 0xff) {
LWIP_DEBUGF(IP_REASS_DEBUG, LWIP_DEBUGF(IP_REASS_DEBUG,
("ip_reass: last fragment seen, bitmap %"S16_F"/%"S16_F" failed (%"X16_F")\n", ("ip_reass: last fragment seen, bitmap %"S16_F"/%"S16_F" failed (%"X16_F")\n",
i, ip_reasslen / (8 * 8) - 1, ip_reassbitmap[i])); i, ip_reasslen / (8 * 8) - 1, ip_reassbitmap[i]));
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. */
LWIP_ASSERT("ip_reasslen / (8 * 8) < sizeof(ip_reassbitmap)", LWIP_ASSERT("ip_reasslen / (8 * 8) < sizeof(ip_reassbitmap)",
ip_reasslen / (8 * 8) < sizeof(ip_reassbitmap)); ip_reasslen / (8 * 8) < sizeof(ip_reassbitmap));
if (ip_reassbitmap[ip_reasslen / (8 * 8)] != if (ip_reassbitmap[ip_reasslen / (8 * 8)] !=
(u8_t) ~ bitmap_bits[ip_reasslen / 8 & 7]) { (u8_t) ~ bitmap_bits[ip_reasslen / 8 & 7]) {
LWIP_DEBUGF(IP_REASS_DEBUG, LWIP_DEBUGF(IP_REASS_DEBUG,
("ip_reass: last fragment seen, bitmap %"S16_F" didn't contain %"X16_F" (%"X16_F")\n", ("ip_reass: last fragment seen, bitmap %"S16_F" didn't contain %"X16_F" (%"X16_F")\n",
ip_reasslen / (8 * 8), ~bitmap_bits[ip_reasslen / 8 & 7], ip_reasslen / (8 * 8), ~bitmap_bits[ip_reasslen / 8 & 7],
ip_reassbitmap[ip_reasslen / (8 * 8)])); ip_reassbitmap[ip_reasslen / (8 * 8)]));
goto nullreturn; goto nullreturn;
} }
/* 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. */
ip_reasslen += IP_HLEN; ip_reasslen += IP_HLEN;
IPH_LEN_SET(iphdr, htons(ip_reasslen)); IPH_LEN_SET(iphdr, htons(ip_reasslen));
IPH_OFFSET_SET(iphdr, 0); IPH_OFFSET_SET(iphdr, 0);
IPH_CHKSUM_SET(iphdr, 0); IPH_CHKSUM_SET(iphdr, 0);
IPH_CHKSUM_SET(iphdr, inet_chksum(iphdr, IP_HLEN)); IPH_CHKSUM_SET(iphdr, inet_chksum(iphdr, IP_HLEN));
/* 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. */
ip_reasstmr = 0; ip_reasstmr = 0;
pbuf_free(p); pbuf_free(p);
p = pbuf_alloc(PBUF_LINK, ip_reasslen, PBUF_POOL); p = pbuf_alloc(PBUF_LINK, ip_reasslen, PBUF_POOL);
if (p != NULL) { if (p != NULL) {
i = 0; i = 0;
for (q = p; q != NULL; q = q->next) { for (q = p; q != NULL; q = q->next) {
/* Copy enough bytes to fill this pbuf in the chain. The /* Copy enough bytes to fill this pbuf in the chain. The
available data in the pbuf is given by the q->len variable. */ available data in the pbuf is given by the q->len variable. */
LWIP_DEBUGF(IP_REASS_DEBUG, LWIP_DEBUGF(IP_REASS_DEBUG,
("ip_reass: memcpy from %p (%"S16_F") to %p, %"S16_F" bytes\n", ("ip_reass: memcpy from %p (%"S16_F") to %p, %"S16_F" bytes\n",
(void *)&ip_reassbuf[i], i, q->payload, (void *)&ip_reassbuf[i], i, q->payload,
q->len > ip_reasslen - i ? ip_reasslen - i : q->len)); q->len > ip_reasslen - i ? ip_reasslen - i : q->len));
memcpy(q->payload, &ip_reassbuf[i], memcpy(q->payload, &ip_reassbuf[i],
q->len > ip_reasslen - i ? ip_reasslen - i : q->len); q->len > ip_reasslen - i ? ip_reasslen - i : q->len);
i += q->len; i += q->len;
} }
IPFRAG_STATS_INC(ip_frag.fw); IPFRAG_STATS_INC(ip_frag.fw);
snmp_inc_ipreasmoks(); snmp_inc_ipreasmoks();
} else { } else {
LWIP_DEBUGF(IP_REASS_DEBUG, LWIP_DEBUGF(IP_REASS_DEBUG,
("ip_reass: pbuf_alloc(PBUF_LINK, ip_reasslen=%"U16_F", PBUF_POOL) failed\n", ip_reasslen)); ("ip_reass: pbuf_alloc(PBUF_LINK, ip_reasslen=%"U16_F", PBUF_POOL) failed\n", ip_reasslen));
IPFRAG_STATS_INC(ip_frag.memerr); IPFRAG_STATS_INC(ip_frag.memerr);
snmp_inc_ipreasmfails(); snmp_inc_ipreasmfails();
} }
LWIP_DEBUGF(IP_REASS_DEBUG, ("ip_reass: p %p\n", (void*)p)); LWIP_DEBUGF(IP_REASS_DEBUG, ("ip_reass: p %p\n", (void*)p));
return p; return p;
} }
} }
nullreturn: nullreturn:
IPFRAG_STATS_INC(ip_frag.drop); IPFRAG_STATS_INC(ip_frag.drop);
pbuf_free(p); pbuf_free(p);
return NULL; return NULL;
} }
static u8_t buf[MEM_ALIGN_SIZE(IP_FRAG_MAX_MTU)]; static u8_t buf[MEM_ALIGN_SIZE(IP_FRAG_MAX_MTU)];
/** /**
* Fragment an IP datagram if too large for the netif. * Fragment an IP datagram if too large for the netif.
* *
* Chop the datagram in MTU sized chunks and send them in order * Chop the datagram in MTU sized chunks and send them in order
* by using a fixed size static memory buffer (PBUF_ROM) * by using a fixed size static memory buffer (PBUF_ROM)
*/ */
err_t err_t
ip_frag(struct pbuf *p, struct netif *netif, struct ip_addr *dest) ip_frag(struct pbuf *p, struct netif *netif, struct ip_addr *dest)
{ {
struct pbuf *rambuf; struct pbuf *rambuf;
struct pbuf *header; struct pbuf *header;
struct ip_hdr *iphdr; struct ip_hdr *iphdr;
u16_t nfb = 0; u16_t nfb = 0;
u16_t left, cop; u16_t left, cop;
u16_t mtu = netif->mtu; u16_t mtu = netif->mtu;
u16_t ofo, omf; u16_t ofo, omf;
u16_t last; u16_t last;
u16_t poff = IP_HLEN; u16_t poff = IP_HLEN;
u16_t tmp; u16_t tmp;
/* Get a RAM based MTU sized pbuf */ /* Get a RAM based MTU sized pbuf */
rambuf = pbuf_alloc(PBUF_LINK, 0, PBUF_REF); rambuf = pbuf_alloc(PBUF_LINK, 0, PBUF_REF);
if (rambuf == NULL) { if (rambuf == NULL) {
LWIP_DEBUGF(IP_REASS_DEBUG, ("ip_frag: pbuf_alloc(PBUF_LINK, 0, PBUF_REF) failed\n")); LWIP_DEBUGF(IP_REASS_DEBUG, ("ip_frag: pbuf_alloc(PBUF_LINK, 0, PBUF_REF) failed\n"));
return ERR_MEM; return ERR_MEM;
} }
rambuf->tot_len = rambuf->len = mtu; rambuf->tot_len = rambuf->len = mtu;
rambuf->payload = MEM_ALIGN((void *)buf); rambuf->payload = MEM_ALIGN((void *)buf);
/* Copy the IP header in it */ /* Copy the IP header in it */
iphdr = rambuf->payload; iphdr = rambuf->payload;
memcpy(iphdr, p->payload, IP_HLEN); memcpy(iphdr, p->payload, IP_HLEN);
/* Save original offset */ /* Save original offset */
tmp = ntohs(IPH_OFFSET(iphdr)); tmp = ntohs(IPH_OFFSET(iphdr));
ofo = tmp & IP_OFFMASK; ofo = tmp & IP_OFFMASK;
omf = tmp & IP_MF; omf = tmp & IP_MF;
left = p->tot_len - IP_HLEN; left = p->tot_len - IP_HLEN;
while (left) { while (left) {
last = (left <= mtu - IP_HLEN); last = (left <= mtu - IP_HLEN);
/* Set new offset and MF flag */ /* Set new offset and MF flag */
ofo += nfb; ofo += nfb;
tmp = omf | (IP_OFFMASK & (ofo)); tmp = omf | (IP_OFFMASK & (ofo));
if (!last) if (!last)
tmp = tmp | IP_MF; tmp = tmp | IP_MF;
IPH_OFFSET_SET(iphdr, htons(tmp)); IPH_OFFSET_SET(iphdr, htons(tmp));
/* Fill this fragment */ /* Fill this fragment */
nfb = (mtu - IP_HLEN) / 8; nfb = (mtu - IP_HLEN) / 8;
cop = last ? left : nfb * 8; cop = last ? left : nfb * 8;
p = copy_from_pbuf(p, &poff, (u8_t *) iphdr + IP_HLEN, cop); p = copy_from_pbuf(p, &poff, (u8_t *) iphdr + IP_HLEN, cop);
/* Correct header */ /* Correct header */
IPH_LEN_SET(iphdr, htons(cop + IP_HLEN)); IPH_LEN_SET(iphdr, htons(cop + IP_HLEN));
IPH_CHKSUM_SET(iphdr, 0); IPH_CHKSUM_SET(iphdr, 0);
IPH_CHKSUM_SET(iphdr, inet_chksum(iphdr, IP_HLEN)); IPH_CHKSUM_SET(iphdr, inet_chksum(iphdr, IP_HLEN));
if (last) if (last)
pbuf_realloc(rambuf, left + IP_HLEN); pbuf_realloc(rambuf, left + IP_HLEN);
/* This part is ugly: we alloc a RAM based pbuf for /* This part is ugly: we alloc a RAM based pbuf for
* the link level header for each chunk and then * the link level header for each chunk and then
* free it.A PBUF_ROM style pbuf for which pbuf_header * free it.A PBUF_ROM style pbuf for which pbuf_header
* worked would make things simpler. * worked would make things simpler.
*/ */
header = pbuf_alloc(PBUF_LINK, 0, PBUF_RAM); header = pbuf_alloc(PBUF_LINK, 0, PBUF_RAM);
if (header != NULL) { if (header != NULL) {
pbuf_chain(header, rambuf); pbuf_chain(header, rambuf);
netif->output(netif, header, dest); netif->output(netif, header, dest);
IPFRAG_STATS_INC(ip_frag.xmit); IPFRAG_STATS_INC(ip_frag.xmit);
snmp_inc_ipfragcreates(); snmp_inc_ipfragcreates();
pbuf_free(header); pbuf_free(header);
} else { } else {
LWIP_DEBUGF(IP_REASS_DEBUG, ("ip_frag: pbuf_alloc() for header failed\n")); LWIP_DEBUGF(IP_REASS_DEBUG, ("ip_frag: pbuf_alloc() for header failed\n"));
pbuf_free(rambuf); pbuf_free(rambuf);
return ERR_MEM; return ERR_MEM;
} }
left -= cop; left -= cop;
} }
pbuf_free(rambuf); pbuf_free(rambuf);
snmp_inc_ipfragoks(); snmp_inc_ipfragoks();
return ERR_OK; return ERR_OK;
} }

View file

@ -1,414 +1,414 @@
/** @file /** @file
* *
* Dynamic memory manager * Dynamic memory manager
* *
*/ */
/* /*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science. * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, * 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products * 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE. * OF SUCH DAMAGE.
* *
* This file is part of the lwIP TCP/IP stack. * This file is part of the lwIP TCP/IP stack.
* *
* Author: Adam Dunkels <adam@sics.se> * Author: Adam Dunkels <adam@sics.se>
* *
*/ */
#include <string.h> #include <string.h>
#include "lwip/arch.h" #include "lwip/arch.h"
#include "lwip/opt.h" #include "lwip/opt.h"
#include "lwip/def.h" #include "lwip/def.h"
#include "lwip/mem.h" #include "lwip/mem.h"
#include "lwip/sys.h" #include "lwip/sys.h"
#include "lwip/stats.h" #include "lwip/stats.h"
#if (MEM_LIBC_MALLOC == 0) #if (MEM_LIBC_MALLOC == 0)
/* lwIP replacement for your libc malloc() */ /* lwIP replacement for your libc malloc() */
struct mem { struct mem {
mem_size_t next, prev; mem_size_t next, prev;
#if MEM_ALIGNMENT == 1 #if MEM_ALIGNMENT == 1
u8_t used; u8_t used;
#elif MEM_ALIGNMENT == 2 #elif MEM_ALIGNMENT == 2
u16_t used; u16_t used;
#elif MEM_ALIGNMENT == 4 #elif MEM_ALIGNMENT == 4
u32_t used; u32_t used;
#elif MEM_ALIGNMENT == 8 #elif MEM_ALIGNMENT == 8
u64_t used; u64_t used;
#else #else
#error "unhandled MEM_ALIGNMENT size" #error "unhandled MEM_ALIGNMENT size"
#endif /* MEM_ALIGNMENT */ #endif /* MEM_ALIGNMENT */
}; };
static struct mem *ram_end; static struct mem *ram_end;
#if 1 #if 1
/* Adam original */ /* Adam original */
static u8_t ram[MEM_SIZE + sizeof(struct mem) + MEM_ALIGNMENT]; static u8_t ram[MEM_SIZE + sizeof(struct mem) + MEM_ALIGNMENT];
#else #else
/* Christiaan alignment fix */ /* Christiaan alignment fix */
static u8_t *ram; static u8_t *ram;
static struct mem ram_heap[1 + ( (MEM_SIZE + sizeof(struct mem) - 1) / sizeof(struct mem))]; static struct mem ram_heap[1 + ( (MEM_SIZE + sizeof(struct mem) - 1) / sizeof(struct mem))];
#endif #endif
#define MIN_SIZE 12 #define MIN_SIZE 12
#if 0 /* this one does not align correctly for some, resulting in crashes */ #if 0 /* this one does not align correctly for some, resulting in crashes */
#define SIZEOF_STRUCT_MEM (unsigned int)MEM_ALIGN_SIZE(sizeof(struct mem)) #define SIZEOF_STRUCT_MEM (unsigned int)MEM_ALIGN_SIZE(sizeof(struct mem))
#else #else
#define SIZEOF_STRUCT_MEM (sizeof(struct mem) + \ #define SIZEOF_STRUCT_MEM (sizeof(struct mem) + \
(((sizeof(struct mem) % MEM_ALIGNMENT) == 0)? 0 : \ (((sizeof(struct mem) % MEM_ALIGNMENT) == 0)? 0 : \
(4 - (sizeof(struct mem) % MEM_ALIGNMENT)))) (4 - (sizeof(struct mem) % MEM_ALIGNMENT))))
#endif #endif
static struct mem *lfree; /* pointer to the lowest free block */ static struct mem *lfree; /* pointer to the lowest free block */
static sys_sem_t mem_sem; static sys_sem_t mem_sem;
static void static void
plug_holes(struct mem *mem) plug_holes(struct mem *mem)
{ {
struct mem *nmem; struct mem *nmem;
struct mem *pmem; struct mem *pmem;
LWIP_ASSERT("plug_holes: mem >= ram", (u8_t *)mem >= ram); LWIP_ASSERT("plug_holes: mem >= ram", (u8_t *)mem >= ram);
LWIP_ASSERT("plug_holes: mem < ram_end", (u8_t *)mem < (u8_t *)ram_end); LWIP_ASSERT("plug_holes: mem < ram_end", (u8_t *)mem < (u8_t *)ram_end);
LWIP_ASSERT("plug_holes: mem->used == 0", mem->used == 0); LWIP_ASSERT("plug_holes: mem->used == 0", mem->used == 0);
/* plug hole forward */ /* plug hole forward */
LWIP_ASSERT("plug_holes: mem->next <= MEM_SIZE", mem->next <= MEM_SIZE); LWIP_ASSERT("plug_holes: mem->next <= MEM_SIZE", mem->next <= MEM_SIZE);
nmem = (struct mem *)&ram[mem->next]; nmem = (struct mem *)&ram[mem->next];
if (mem != nmem && nmem->used == 0 && (u8_t *)nmem != (u8_t *)ram_end) { if (mem != nmem && nmem->used == 0 && (u8_t *)nmem != (u8_t *)ram_end) {
if (lfree == nmem) { if (lfree == nmem) {
lfree = mem; lfree = mem;
} }
mem->next = nmem->next; mem->next = nmem->next;
((struct mem *)&ram[nmem->next])->prev = (u8_t *)mem - ram; ((struct mem *)&ram[nmem->next])->prev = (u8_t *)mem - ram;
} }
/* plug hole backward */ /* plug hole backward */
pmem = (struct mem *)&ram[mem->prev]; pmem = (struct mem *)&ram[mem->prev];
if (pmem != mem && pmem->used == 0) { if (pmem != mem && pmem->used == 0) {
if (lfree == mem) { if (lfree == mem) {
lfree = pmem; lfree = pmem;
} }
pmem->next = mem->next; pmem->next = mem->next;
((struct mem *)&ram[mem->next])->prev = (u8_t *)pmem - ram; ((struct mem *)&ram[mem->next])->prev = (u8_t *)pmem - ram;
} }
} }
void void
mem_init(void) mem_init(void)
{ {
struct mem *mem; struct mem *mem;
#if 1 #if 1
/* Adam original */ /* Adam original */
#else #else
/* Christiaan alignment fix */ /* Christiaan alignment fix */
ram = (u8_t*)ram_heap; ram = (u8_t*)ram_heap;
#endif #endif
memset(ram, 0, MEM_SIZE); memset(ram, 0, MEM_SIZE);
mem = (struct mem *)ram; mem = (struct mem *)ram;
mem->next = MEM_SIZE; mem->next = MEM_SIZE;
mem->prev = 0; mem->prev = 0;
mem->used = 0; mem->used = 0;
ram_end = (struct mem *)&ram[MEM_SIZE]; ram_end = (struct mem *)&ram[MEM_SIZE];
ram_end->used = 1; ram_end->used = 1;
ram_end->next = MEM_SIZE; ram_end->next = MEM_SIZE;
ram_end->prev = MEM_SIZE; ram_end->prev = MEM_SIZE;
mem_sem = sys_sem_new(1); mem_sem = sys_sem_new(1);
lfree = (struct mem *)ram; lfree = (struct mem *)ram;
#if MEM_STATS #if MEM_STATS
lwip_stats.mem.avail = MEM_SIZE; lwip_stats.mem.avail = MEM_SIZE;
#endif /* MEM_STATS */ #endif /* MEM_STATS */
} }
void void
mem_free(void *rmem) mem_free(void *rmem)
{ {
struct mem *mem; struct mem *mem;
if (rmem == NULL) { if (rmem == NULL) {
LWIP_DEBUGF(MEM_DEBUG | DBG_TRACE | 2, ("mem_free(p == NULL) was called.\n")); LWIP_DEBUGF(MEM_DEBUG | DBG_TRACE | 2, ("mem_free(p == NULL) was called.\n"));
return; return;
} }
sys_sem_wait(mem_sem); sys_sem_wait(mem_sem);
LWIP_ASSERT("mem_free: legal memory", (u8_t *)rmem >= (u8_t *)ram && LWIP_ASSERT("mem_free: legal memory", (u8_t *)rmem >= (u8_t *)ram &&
(u8_t *)rmem < (u8_t *)ram_end); (u8_t *)rmem < (u8_t *)ram_end);
if ((u8_t *)rmem < (u8_t *)ram || (u8_t *)rmem >= (u8_t *)ram_end) { if ((u8_t *)rmem < (u8_t *)ram || (u8_t *)rmem >= (u8_t *)ram_end) {
LWIP_DEBUGF(MEM_DEBUG | 3, ("mem_free: illegal memory\n")); LWIP_DEBUGF(MEM_DEBUG | 3, ("mem_free: illegal memory\n"));
#if MEM_STATS #if MEM_STATS
++lwip_stats.mem.err; ++lwip_stats.mem.err;
#endif /* MEM_STATS */ #endif /* MEM_STATS */
sys_sem_signal(mem_sem); sys_sem_signal(mem_sem);
return; return;
} }
mem = (struct mem *)((u8_t *)rmem - SIZEOF_STRUCT_MEM); mem = (struct mem *)((u8_t *)rmem - SIZEOF_STRUCT_MEM);
LWIP_ASSERT("mem_free: mem->used", mem->used); LWIP_ASSERT("mem_free: mem->used", mem->used);
mem->used = 0; mem->used = 0;
if (mem < lfree) { if (mem < lfree) {
lfree = mem; lfree = mem;
} }
#if MEM_STATS #if MEM_STATS
lwip_stats.mem.used -= mem->next - ((u8_t *)mem - ram); lwip_stats.mem.used -= mem->next - ((u8_t *)mem - ram);
#endif /* MEM_STATS */ #endif /* MEM_STATS */
plug_holes(mem); plug_holes(mem);
sys_sem_signal(mem_sem); sys_sem_signal(mem_sem);
} }
void * void *
mem_realloc(void *rmem, mem_size_t newsize) mem_realloc(void *rmem, mem_size_t newsize)
{ {
mem_size_t size; mem_size_t size;
mem_size_t ptr, ptr2; mem_size_t ptr, ptr2;
struct mem *mem, *mem2; struct mem *mem, *mem2;
/* Expand the size of the allocated memory region so that we can /* Expand the size of the allocated memory region so that we can
adjust for alignment. */ adjust for alignment. */
if ((newsize % MEM_ALIGNMENT) != 0) { if ((newsize % MEM_ALIGNMENT) != 0) {
newsize += MEM_ALIGNMENT - ((newsize + SIZEOF_STRUCT_MEM) % MEM_ALIGNMENT); newsize += MEM_ALIGNMENT - ((newsize + SIZEOF_STRUCT_MEM) % MEM_ALIGNMENT);
} }
if (newsize > MEM_SIZE) { if (newsize > MEM_SIZE) {
return NULL; return NULL;
} }
sys_sem_wait(mem_sem); sys_sem_wait(mem_sem);
LWIP_ASSERT("mem_realloc: legal memory", (u8_t *)rmem >= (u8_t *)ram && LWIP_ASSERT("mem_realloc: legal memory", (u8_t *)rmem >= (u8_t *)ram &&
(u8_t *)rmem < (u8_t *)ram_end); (u8_t *)rmem < (u8_t *)ram_end);
if ((u8_t *)rmem < (u8_t *)ram || (u8_t *)rmem >= (u8_t *)ram_end) { if ((u8_t *)rmem < (u8_t *)ram || (u8_t *)rmem >= (u8_t *)ram_end) {
LWIP_DEBUGF(MEM_DEBUG | 3, ("mem_realloc: illegal memory\n")); LWIP_DEBUGF(MEM_DEBUG | 3, ("mem_realloc: illegal memory\n"));
return rmem; return rmem;
} }
mem = (struct mem *)((u8_t *)rmem - SIZEOF_STRUCT_MEM); mem = (struct mem *)((u8_t *)rmem - SIZEOF_STRUCT_MEM);
ptr = (u8_t *)mem - ram; ptr = (u8_t *)mem - ram;
size = mem->next - ptr - SIZEOF_STRUCT_MEM; size = mem->next - ptr - SIZEOF_STRUCT_MEM;
#if MEM_STATS #if MEM_STATS
lwip_stats.mem.used -= (size - newsize); lwip_stats.mem.used -= (size - newsize);
#endif /* MEM_STATS */ #endif /* MEM_STATS */
if (newsize + SIZEOF_STRUCT_MEM + MIN_SIZE < size) { if (newsize + SIZEOF_STRUCT_MEM + MIN_SIZE < size) {
ptr2 = ptr + SIZEOF_STRUCT_MEM + newsize; ptr2 = ptr + SIZEOF_STRUCT_MEM + newsize;
mem2 = (struct mem *)&ram[ptr2]; mem2 = (struct mem *)&ram[ptr2];
mem2->used = 0; mem2->used = 0;
mem2->next = mem->next; mem2->next = mem->next;
mem2->prev = ptr; mem2->prev = ptr;
mem->next = ptr2; mem->next = ptr2;
if (mem2->next != MEM_SIZE) { if (mem2->next != MEM_SIZE) {
((struct mem *)&ram[mem2->next])->prev = ptr2; ((struct mem *)&ram[mem2->next])->prev = ptr2;
} }
plug_holes(mem2); plug_holes(mem2);
} }
sys_sem_signal(mem_sem); sys_sem_signal(mem_sem);
return rmem; return rmem;
} }
#if 1 #if 1
/** /**
* Adam's mem_malloc(), suffers from bug #17922 * Adam's mem_malloc(), suffers from bug #17922
* Set if to 0 for alternative mem_malloc(). * Set if to 0 for alternative mem_malloc().
*/ */
void * void *
mem_malloc(mem_size_t size) mem_malloc(mem_size_t size)
{ {
mem_size_t ptr, ptr2; mem_size_t ptr, ptr2;
struct mem *mem, *mem2; struct mem *mem, *mem2;
if (size == 0) { if (size == 0) {
return NULL; return NULL;
} }
/* Expand the size of the allocated memory region so that we can /* Expand the size of the allocated memory region so that we can
adjust for alignment. */ adjust for alignment. */
if ((size % MEM_ALIGNMENT) != 0) { if ((size % MEM_ALIGNMENT) != 0) {
size += MEM_ALIGNMENT - ((size + SIZEOF_STRUCT_MEM) % MEM_ALIGNMENT); size += MEM_ALIGNMENT - ((size + SIZEOF_STRUCT_MEM) % MEM_ALIGNMENT);
} }
if (size > MEM_SIZE) { if (size > MEM_SIZE) {
return NULL; return NULL;
} }
sys_sem_wait(mem_sem); sys_sem_wait(mem_sem);
for (ptr = (u8_t *)lfree - ram; ptr < MEM_SIZE; ptr = ((struct mem *)&ram[ptr])->next) { for (ptr = (u8_t *)lfree - ram; ptr < MEM_SIZE; ptr = ((struct mem *)&ram[ptr])->next) {
mem = (struct mem *)&ram[ptr]; mem = (struct mem *)&ram[ptr];
if (!mem->used && if (!mem->used &&
mem->next - (ptr + SIZEOF_STRUCT_MEM) >= size + SIZEOF_STRUCT_MEM) { mem->next - (ptr + SIZEOF_STRUCT_MEM) >= size + SIZEOF_STRUCT_MEM) {
ptr2 = ptr + SIZEOF_STRUCT_MEM + size; ptr2 = ptr + SIZEOF_STRUCT_MEM + size;
mem2 = (struct mem *)&ram[ptr2]; mem2 = (struct mem *)&ram[ptr2];
mem2->prev = ptr; mem2->prev = ptr;
mem2->next = mem->next; mem2->next = mem->next;
mem->next = ptr2; mem->next = ptr2;
if (mem2->next != MEM_SIZE) { if (mem2->next != MEM_SIZE) {
((struct mem *)&ram[mem2->next])->prev = ptr2; ((struct mem *)&ram[mem2->next])->prev = ptr2;
} }
mem2->used = 0; mem2->used = 0;
mem->used = 1; mem->used = 1;
#if MEM_STATS #if MEM_STATS
lwip_stats.mem.used += (size + SIZEOF_STRUCT_MEM); lwip_stats.mem.used += (size + SIZEOF_STRUCT_MEM);
/* if (lwip_stats.mem.max < lwip_stats.mem.used) { /* if (lwip_stats.mem.max < lwip_stats.mem.used) {
lwip_stats.mem.max = lwip_stats.mem.used; lwip_stats.mem.max = lwip_stats.mem.used;
} */ } */
if (lwip_stats.mem.max < ptr2) { if (lwip_stats.mem.max < ptr2) {
lwip_stats.mem.max = ptr2; lwip_stats.mem.max = ptr2;
} }
#endif /* MEM_STATS */ #endif /* MEM_STATS */
if (mem == lfree) { if (mem == lfree) {
/* Find next free block after mem */ /* Find next free block after mem */
while (lfree->used && lfree != ram_end) { while (lfree->used && lfree != ram_end) {
lfree = (struct mem *)&ram[lfree->next]; lfree = (struct mem *)&ram[lfree->next];
} }
LWIP_ASSERT("mem_malloc: !lfree->used", !lfree->used); LWIP_ASSERT("mem_malloc: !lfree->used", !lfree->used);
} }
sys_sem_signal(mem_sem); sys_sem_signal(mem_sem);
LWIP_ASSERT("mem_malloc: allocated memory not above ram_end.", LWIP_ASSERT("mem_malloc: allocated memory not above ram_end.",
(mem_ptr_t)mem + SIZEOF_STRUCT_MEM + size <= (mem_ptr_t)ram_end); (mem_ptr_t)mem + SIZEOF_STRUCT_MEM + size <= (mem_ptr_t)ram_end);
LWIP_ASSERT("mem_malloc: allocated memory properly aligned.", LWIP_ASSERT("mem_malloc: allocated memory properly aligned.",
(unsigned long)((u8_t *)mem + SIZEOF_STRUCT_MEM) % MEM_ALIGNMENT == 0); (unsigned long)((u8_t *)mem + SIZEOF_STRUCT_MEM) % MEM_ALIGNMENT == 0);
return (u8_t *)mem + SIZEOF_STRUCT_MEM; return (u8_t *)mem + SIZEOF_STRUCT_MEM;
} }
} }
LWIP_DEBUGF(MEM_DEBUG | 2, ("mem_malloc: could not allocate %"S16_F" bytes\n", (s16_t)size)); LWIP_DEBUGF(MEM_DEBUG | 2, ("mem_malloc: could not allocate %"S16_F" bytes\n", (s16_t)size));
#if MEM_STATS #if MEM_STATS
++lwip_stats.mem.err; ++lwip_stats.mem.err;
#endif /* MEM_STATS */ #endif /* MEM_STATS */
sys_sem_signal(mem_sem); sys_sem_signal(mem_sem);
return NULL; return NULL;
} }
#else #else
/** /**
* Adam's mem_malloc() plus solution for bug #17922 * Adam's mem_malloc() plus solution for bug #17922
*/ */
void * void *
mem_malloc(mem_size_t size) mem_malloc(mem_size_t size)
{ {
mem_size_t ptr, ptr2; mem_size_t ptr, ptr2;
struct mem *mem, *mem2; struct mem *mem, *mem2;
if (size == 0) { if (size == 0) {
return NULL; return NULL;
} }
/* Expand the size of the allocated memory region so that we can /* Expand the size of the allocated memory region so that we can
adjust for alignment. */ adjust for alignment. */
if ((size % MEM_ALIGNMENT) != 0) { if ((size % MEM_ALIGNMENT) != 0) {
size += MEM_ALIGNMENT - ((size + SIZEOF_STRUCT_MEM) % MEM_ALIGNMENT); size += MEM_ALIGNMENT - ((size + SIZEOF_STRUCT_MEM) % MEM_ALIGNMENT);
} }
if (size > MEM_SIZE) { if (size > MEM_SIZE) {
return NULL; return NULL;
} }
sys_sem_wait(mem_sem); sys_sem_wait(mem_sem);
for (ptr = (u8_t *)lfree - ram; ptr < MEM_SIZE - size; ptr = ((struct mem *)&ram[ptr])->next) { for (ptr = (u8_t *)lfree - ram; ptr < MEM_SIZE - size; ptr = ((struct mem *)&ram[ptr])->next) {
mem = (struct mem *)&ram[ptr]; mem = (struct mem *)&ram[ptr];
if (!mem->used) { if (!mem->used) {
ptr2 = ptr + SIZEOF_STRUCT_MEM + size; ptr2 = ptr + SIZEOF_STRUCT_MEM + size;
if (mem->next - (ptr + (2*SIZEOF_STRUCT_MEM)) >= size) { if (mem->next - (ptr + (2*SIZEOF_STRUCT_MEM)) >= size) {
/* split large block, create empty remainder */ /* split large block, create empty remainder */
mem->next = ptr2; mem->next = ptr2;
mem->used = 1; mem->used = 1;
/* create mem2 struct */ /* create mem2 struct */
mem2 = (struct mem *)&ram[ptr2]; mem2 = (struct mem *)&ram[ptr2];
mem2->used = 0; mem2->used = 0;
mem2->next = mem->next; mem2->next = mem->next;
mem2->prev = ptr; mem2->prev = ptr;
if (mem2->next != MEM_SIZE) { if (mem2->next != MEM_SIZE) {
((struct mem *)&ram[mem2->next])->prev = ptr2; ((struct mem *)&ram[mem2->next])->prev = ptr2;
} }
} }
else if (mem->next - (ptr + SIZEOF_STRUCT_MEM) > size) { else if (mem->next - (ptr + SIZEOF_STRUCT_MEM) > size) {
/* near fit, no split, no mem2 creation, /* near fit, no split, no mem2 creation,
round up to mem->next */ round up to mem->next */
ptr2 = mem->next; ptr2 = mem->next;
mem->used = 1; mem->used = 1;
} }
else if (mem->next - (ptr + SIZEOF_STRUCT_MEM) == size) { else if (mem->next - (ptr + SIZEOF_STRUCT_MEM) == size) {
/* exact fit, do not split, no mem2 creation */ /* exact fit, do not split, no mem2 creation */
mem->next = ptr2; mem->next = ptr2;
mem->used = 1; mem->used = 1;
} }
if (mem->used) { if (mem->used) {
#if MEM_STATS #if MEM_STATS
lwip_stats.mem.used += (size + SIZEOF_STRUCT_MEM); lwip_stats.mem.used += (size + SIZEOF_STRUCT_MEM);
if (lwip_stats.mem.max < ptr2) { if (lwip_stats.mem.max < ptr2) {
lwip_stats.mem.max = ptr2; lwip_stats.mem.max = ptr2;
} }
#endif /* MEM_STATS */ #endif /* MEM_STATS */
if (mem == lfree) { if (mem == lfree) {
/* Find next free block after mem */ /* Find next free block after mem */
while (lfree->used && lfree != ram_end) { while (lfree->used && lfree != ram_end) {
lfree = (struct mem *)&ram[lfree->next]; lfree = (struct mem *)&ram[lfree->next];
} }
LWIP_ASSERT("mem_malloc: !lfree->used", !lfree->used); LWIP_ASSERT("mem_malloc: !lfree->used", !lfree->used);
} }
sys_sem_signal(mem_sem); sys_sem_signal(mem_sem);
LWIP_ASSERT("mem_malloc: allocated memory not above ram_end.", LWIP_ASSERT("mem_malloc: allocated memory not above ram_end.",
(mem_ptr_t)mem + SIZEOF_STRUCT_MEM + size <= (mem_ptr_t)ram_end); (mem_ptr_t)mem + SIZEOF_STRUCT_MEM + size <= (mem_ptr_t)ram_end);
LWIP_ASSERT("mem_malloc: allocated memory properly aligned.", LWIP_ASSERT("mem_malloc: allocated memory properly aligned.",
(unsigned long)((u8_t *)mem + SIZEOF_STRUCT_MEM) % MEM_ALIGNMENT == 0); (unsigned long)((u8_t *)mem + SIZEOF_STRUCT_MEM) % MEM_ALIGNMENT == 0);
return (u8_t *)mem + SIZEOF_STRUCT_MEM; return (u8_t *)mem + SIZEOF_STRUCT_MEM;
} }
} }
} }
LWIP_DEBUGF(MEM_DEBUG | 2, ("mem_malloc: could not allocate %"S16_F" bytes\n", (s16_t)size)); LWIP_DEBUGF(MEM_DEBUG | 2, ("mem_malloc: could not allocate %"S16_F" bytes\n", (s16_t)size));
#if MEM_STATS #if MEM_STATS
++lwip_stats.mem.err; ++lwip_stats.mem.err;
#endif /* MEM_STATS */ #endif /* MEM_STATS */
sys_sem_signal(mem_sem); sys_sem_signal(mem_sem);
return NULL; return NULL;
} }
#endif #endif
#endif /* MEM_LIBC_MALLOC == 0 */ #endif /* MEM_LIBC_MALLOC == 0 */

View file

@ -1,238 +1,238 @@
/* /*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science. * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, * 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products * 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE. * OF SUCH DAMAGE.
* *
* This file is part of the lwIP TCP/IP stack. * This file is part of the lwIP TCP/IP stack.
* *
* Author: Adam Dunkels <adam@sics.se> * Author: Adam Dunkels <adam@sics.se>
* *
*/ */
#include "lwip/opt.h" #include "lwip/opt.h"
#include "lwip/memp.h" #include "lwip/memp.h"
#include "lwip/pbuf.h" #include "lwip/pbuf.h"
#include "lwip/udp.h" #include "lwip/udp.h"
#include "lwip/raw.h" #include "lwip/raw.h"
#include "lwip/tcp.h" #include "lwip/tcp.h"
#include "lwip/api.h" #include "lwip/api.h"
#include "lwip/api_msg.h" #include "lwip/api_msg.h"
#include "lwip/tcpip.h" #include "lwip/tcpip.h"
#include "lwip/sys.h" #include "lwip/sys.h"
#include "lwip/stats.h" #include "lwip/stats.h"
struct memp { struct memp {
struct memp *next; struct memp *next;
}; };
#define MEMP_SIZE MEM_ALIGN_SIZE(sizeof(struct memp)) #define MEMP_SIZE MEM_ALIGN_SIZE(sizeof(struct memp))
static struct memp *memp_tab[MEMP_MAX]; static struct memp *memp_tab[MEMP_MAX];
static const u16_t memp_sizes[MEMP_MAX] = { static const u16_t memp_sizes[MEMP_MAX] = {
MEM_ALIGN_SIZE(sizeof(struct pbuf)), MEM_ALIGN_SIZE(sizeof(struct pbuf)),
MEM_ALIGN_SIZE(sizeof(struct raw_pcb)), MEM_ALIGN_SIZE(sizeof(struct raw_pcb)),
MEM_ALIGN_SIZE(sizeof(struct udp_pcb)), MEM_ALIGN_SIZE(sizeof(struct udp_pcb)),
MEM_ALIGN_SIZE(sizeof(struct tcp_pcb)), MEM_ALIGN_SIZE(sizeof(struct tcp_pcb)),
MEM_ALIGN_SIZE(sizeof(struct tcp_pcb_listen)), MEM_ALIGN_SIZE(sizeof(struct tcp_pcb_listen)),
MEM_ALIGN_SIZE(sizeof(struct tcp_seg)), MEM_ALIGN_SIZE(sizeof(struct tcp_seg)),
MEM_ALIGN_SIZE(sizeof(struct netbuf)), MEM_ALIGN_SIZE(sizeof(struct netbuf)),
MEM_ALIGN_SIZE(sizeof(struct netconn)), MEM_ALIGN_SIZE(sizeof(struct netconn)),
MEM_ALIGN_SIZE(sizeof(struct api_msg)), MEM_ALIGN_SIZE(sizeof(struct api_msg)),
MEM_ALIGN_SIZE(sizeof(struct tcpip_msg)), MEM_ALIGN_SIZE(sizeof(struct tcpip_msg)),
MEM_ALIGN_SIZE(sizeof(struct sys_timeo)) MEM_ALIGN_SIZE(sizeof(struct sys_timeo))
}; };
static const u16_t memp_num[MEMP_MAX] = { static const u16_t memp_num[MEMP_MAX] = {
MEMP_NUM_PBUF, MEMP_NUM_PBUF,
MEMP_NUM_RAW_PCB, MEMP_NUM_RAW_PCB,
MEMP_NUM_UDP_PCB, MEMP_NUM_UDP_PCB,
MEMP_NUM_TCP_PCB, MEMP_NUM_TCP_PCB,
MEMP_NUM_TCP_PCB_LISTEN, MEMP_NUM_TCP_PCB_LISTEN,
MEMP_NUM_TCP_SEG, MEMP_NUM_TCP_SEG,
MEMP_NUM_NETBUF, MEMP_NUM_NETBUF,
MEMP_NUM_NETCONN, MEMP_NUM_NETCONN,
MEMP_NUM_API_MSG, MEMP_NUM_API_MSG,
MEMP_NUM_TCPIP_MSG, MEMP_NUM_TCPIP_MSG,
MEMP_NUM_SYS_TIMEOUT MEMP_NUM_SYS_TIMEOUT
}; };
#define MEMP_TYPE_SIZE(qty, type) \ #define MEMP_TYPE_SIZE(qty, type) \
((qty) * (MEMP_SIZE + MEM_ALIGN_SIZE(sizeof(type)))) ((qty) * (MEMP_SIZE + MEM_ALIGN_SIZE(sizeof(type))))
static u8_t memp_memory[MEM_ALIGNMENT - 1 + static u8_t memp_memory[MEM_ALIGNMENT - 1 +
MEMP_TYPE_SIZE(MEMP_NUM_PBUF, struct pbuf) + MEMP_TYPE_SIZE(MEMP_NUM_PBUF, struct pbuf) +
MEMP_TYPE_SIZE(MEMP_NUM_RAW_PCB, struct raw_pcb) + MEMP_TYPE_SIZE(MEMP_NUM_RAW_PCB, struct raw_pcb) +
MEMP_TYPE_SIZE(MEMP_NUM_UDP_PCB, struct udp_pcb) + MEMP_TYPE_SIZE(MEMP_NUM_UDP_PCB, struct udp_pcb) +
MEMP_TYPE_SIZE(MEMP_NUM_TCP_PCB, struct tcp_pcb) + MEMP_TYPE_SIZE(MEMP_NUM_TCP_PCB, struct tcp_pcb) +
MEMP_TYPE_SIZE(MEMP_NUM_TCP_PCB_LISTEN, struct tcp_pcb_listen) + MEMP_TYPE_SIZE(MEMP_NUM_TCP_PCB_LISTEN, struct tcp_pcb_listen) +
MEMP_TYPE_SIZE(MEMP_NUM_TCP_SEG, struct tcp_seg) + MEMP_TYPE_SIZE(MEMP_NUM_TCP_SEG, struct tcp_seg) +
MEMP_TYPE_SIZE(MEMP_NUM_NETBUF, struct netbuf) + MEMP_TYPE_SIZE(MEMP_NUM_NETBUF, struct netbuf) +
MEMP_TYPE_SIZE(MEMP_NUM_NETCONN, struct netconn) + MEMP_TYPE_SIZE(MEMP_NUM_NETCONN, struct netconn) +
MEMP_TYPE_SIZE(MEMP_NUM_API_MSG, struct api_msg) + MEMP_TYPE_SIZE(MEMP_NUM_API_MSG, struct api_msg) +
MEMP_TYPE_SIZE(MEMP_NUM_TCPIP_MSG, struct tcpip_msg) + MEMP_TYPE_SIZE(MEMP_NUM_TCPIP_MSG, struct tcpip_msg) +
MEMP_TYPE_SIZE(MEMP_NUM_SYS_TIMEOUT, struct sys_timeo)]; MEMP_TYPE_SIZE(MEMP_NUM_SYS_TIMEOUT, struct sys_timeo)];
#if !SYS_LIGHTWEIGHT_PROT #if !SYS_LIGHTWEIGHT_PROT
static sys_sem_t mutex; static sys_sem_t mutex;
#endif #endif
#if MEMP_SANITY_CHECK #if MEMP_SANITY_CHECK
static int static int
memp_sanity(void) memp_sanity(void)
{ {
s16_t i, c; s16_t i, c;
struct memp *m, *n; struct memp *m, *n;
for (i = 0; i < MEMP_MAX; i++) { for (i = 0; i < MEMP_MAX; i++) {
for (m = memp_tab[i]; m != NULL; m = m->next) { for (m = memp_tab[i]; m != NULL; m = m->next) {
c = 1; c = 1;
for (n = memp_tab[i]; n != NULL; n = n->next) { for (n = memp_tab[i]; n != NULL; n = n->next) {
if (n == m && --c < 0) { if (n == m && --c < 0) {
return 0; /* LW was: abort(); */ return 0; /* LW was: abort(); */
} }
} }
} }
} }
return 1; return 1;
} }
#endif /* MEMP_SANITY_CHECK*/ #endif /* MEMP_SANITY_CHECK*/
void void
memp_init(void) memp_init(void)
{ {
struct memp *memp; struct memp *memp;
u16_t i, j; u16_t i, j;
#if MEMP_STATS #if MEMP_STATS
for (i = 0; i < MEMP_MAX; ++i) { for (i = 0; i < MEMP_MAX; ++i) {
lwip_stats.memp[i].used = lwip_stats.memp[i].max = lwip_stats.memp[i].used = lwip_stats.memp[i].max =
lwip_stats.memp[i].err = 0; lwip_stats.memp[i].err = 0;
lwip_stats.memp[i].avail = memp_num[i]; lwip_stats.memp[i].avail = memp_num[i];
} }
#endif /* MEMP_STATS */ #endif /* MEMP_STATS */
memp = MEM_ALIGN(memp_memory); memp = MEM_ALIGN(memp_memory);
for (i = 0; i < MEMP_MAX; ++i) { for (i = 0; i < MEMP_MAX; ++i) {
memp_tab[i] = NULL; memp_tab[i] = NULL;
for (j = 0; j < memp_num[i]; ++j) { for (j = 0; j < memp_num[i]; ++j) {
memp->next = memp_tab[i]; memp->next = memp_tab[i];
memp_tab[i] = memp; memp_tab[i] = memp;
memp = (struct memp *)((u8_t *)memp + MEMP_SIZE + memp_sizes[i]); memp = (struct memp *)((u8_t *)memp + MEMP_SIZE + memp_sizes[i]);
} }
} }
#if !SYS_LIGHTWEIGHT_PROT #if !SYS_LIGHTWEIGHT_PROT
mutex = sys_sem_new(1); mutex = sys_sem_new(1);
#endif #endif
} }
void * void *
memp_malloc(memp_t type) memp_malloc(memp_t type)
{ {
struct memp *memp; struct memp *memp;
void *mem; void *mem;
#if SYS_LIGHTWEIGHT_PROT #if SYS_LIGHTWEIGHT_PROT
SYS_ARCH_DECL_PROTECT(old_level); SYS_ARCH_DECL_PROTECT(old_level);
#endif #endif
LWIP_ASSERT("memp_malloc: type < MEMP_MAX", type < MEMP_MAX); LWIP_ASSERT("memp_malloc: type < MEMP_MAX", type < MEMP_MAX);
#if SYS_LIGHTWEIGHT_PROT #if SYS_LIGHTWEIGHT_PROT
SYS_ARCH_PROTECT(old_level); SYS_ARCH_PROTECT(old_level);
#else /* SYS_LIGHTWEIGHT_PROT */ #else /* SYS_LIGHTWEIGHT_PROT */
sys_sem_wait(mutex); sys_sem_wait(mutex);
#endif /* SYS_LIGHTWEIGHT_PROT */ #endif /* SYS_LIGHTWEIGHT_PROT */
memp = memp_tab[type]; memp = memp_tab[type];
if (memp != NULL) { if (memp != NULL) {
memp_tab[type] = memp->next; memp_tab[type] = memp->next;
memp->next = NULL; memp->next = NULL;
#if MEMP_STATS #if MEMP_STATS
++lwip_stats.memp[type].used; ++lwip_stats.memp[type].used;
if (lwip_stats.memp[type].used > lwip_stats.memp[type].max) { if (lwip_stats.memp[type].used > lwip_stats.memp[type].max) {
lwip_stats.memp[type].max = lwip_stats.memp[type].used; lwip_stats.memp[type].max = lwip_stats.memp[type].used;
} }
#endif /* MEMP_STATS */ #endif /* MEMP_STATS */
mem = (u8_t *)memp + MEMP_SIZE; mem = (u8_t *)memp + MEMP_SIZE;
LWIP_ASSERT("memp_malloc: memp properly aligned", LWIP_ASSERT("memp_malloc: memp properly aligned",
((mem_ptr_t)memp % MEM_ALIGNMENT) == 0); ((mem_ptr_t)memp % MEM_ALIGNMENT) == 0);
} else { } else {
LWIP_DEBUGF(MEMP_DEBUG | 2, ("memp_malloc: out of memory in pool %"S16_F"\n", type)); LWIP_DEBUGF(MEMP_DEBUG | 2, ("memp_malloc: out of memory in pool %"S16_F"\n", type));
#if MEMP_STATS #if MEMP_STATS
++lwip_stats.memp[type].err; ++lwip_stats.memp[type].err;
#endif /* MEMP_STATS */ #endif /* MEMP_STATS */
mem = NULL; mem = NULL;
} }
#if SYS_LIGHTWEIGHT_PROT #if SYS_LIGHTWEIGHT_PROT
SYS_ARCH_UNPROTECT(old_level); SYS_ARCH_UNPROTECT(old_level);
#else /* SYS_LIGHTWEIGHT_PROT */ #else /* SYS_LIGHTWEIGHT_PROT */
sys_sem_signal(mutex); sys_sem_signal(mutex);
#endif /* SYS_LIGHTWEIGHT_PROT */ #endif /* SYS_LIGHTWEIGHT_PROT */
return mem; return mem;
} }
void void
memp_free(memp_t type, void *mem) memp_free(memp_t type, void *mem)
{ {
struct memp *memp; struct memp *memp;
#if SYS_LIGHTWEIGHT_PROT #if SYS_LIGHTWEIGHT_PROT
SYS_ARCH_DECL_PROTECT(old_level); SYS_ARCH_DECL_PROTECT(old_level);
#endif /* SYS_LIGHTWEIGHT_PROT */ #endif /* SYS_LIGHTWEIGHT_PROT */
if (mem == NULL) { if (mem == NULL) {
return; return;
} }
memp = (struct memp *)((u8_t *)mem - MEMP_SIZE); memp = (struct memp *)((u8_t *)mem - MEMP_SIZE);
#if SYS_LIGHTWEIGHT_PROT #if SYS_LIGHTWEIGHT_PROT
SYS_ARCH_PROTECT(old_level); SYS_ARCH_PROTECT(old_level);
#else /* SYS_LIGHTWEIGHT_PROT */ #else /* SYS_LIGHTWEIGHT_PROT */
sys_sem_wait(mutex); sys_sem_wait(mutex);
#endif /* SYS_LIGHTWEIGHT_PROT */ #endif /* SYS_LIGHTWEIGHT_PROT */
#if MEMP_STATS #if MEMP_STATS
lwip_stats.memp[type].used--; lwip_stats.memp[type].used--;
#endif /* MEMP_STATS */ #endif /* MEMP_STATS */
memp->next = memp_tab[type]; memp->next = memp_tab[type];
memp_tab[type] = memp; memp_tab[type] = memp;
#if MEMP_SANITY_CHECK #if MEMP_SANITY_CHECK
LWIP_ASSERT("memp sanity", memp_sanity()); LWIP_ASSERT("memp sanity", memp_sanity());
#endif #endif
#if SYS_LIGHTWEIGHT_PROT #if SYS_LIGHTWEIGHT_PROT
SYS_ARCH_UNPROTECT(old_level); SYS_ARCH_UNPROTECT(old_level);
#else /* SYS_LIGHTWEIGHT_PROT */ #else /* SYS_LIGHTWEIGHT_PROT */
sys_sem_signal(mutex); sys_sem_signal(mutex);
#endif /* SYS_LIGHTWEIGHT_PROT */ #endif /* SYS_LIGHTWEIGHT_PROT */
} }

View file

@ -1,325 +1,325 @@
/** /**
* @file * @file
* *
* lwIP network interface abstraction * lwIP network interface abstraction
*/ */
/* /*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science. * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, * 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products * 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE. * OF SUCH DAMAGE.
* *
* This file is part of the lwIP TCP/IP stack. * This file is part of the lwIP TCP/IP stack.
* *
* Author: Adam Dunkels <adam@sics.se> * Author: Adam Dunkels <adam@sics.se>
* *
*/ */
#include "lwip/opt.h" #include "lwip/opt.h"
#include "lwip/def.h" #include "lwip/def.h"
#include "lwip/ip_addr.h" #include "lwip/ip_addr.h"
#include "lwip/netif.h" #include "lwip/netif.h"
#include "lwip/tcp.h" #include "lwip/tcp.h"
#include "lwip/snmp.h" #include "lwip/snmp.h"
struct netif *netif_list = NULL; struct netif *netif_list = NULL;
struct netif *netif_default = NULL; struct netif *netif_default = NULL;
/** /**
* Add a network interface to the list of lwIP netifs. * Add a network interface to the list of lwIP netifs.
* *
* @param netif a pre-allocated netif structure * @param netif a pre-allocated netif structure
* @param ipaddr IP address for the new netif * @param ipaddr IP address for the new netif
* @param netmask network mask for the new netif * @param netmask network mask for the new netif
* @param gw default gateway IP address for the new netif * @param gw default gateway IP address for the new netif
* @param state opaque data passed to the new netif * @param state opaque data passed to the new netif
* @param init callback function that initializes the interface * @param init callback function that initializes the interface
* @param input callback function that is called to pass * @param input callback function that is called to pass
* ingress packets up in the protocol layer stack. * ingress packets up in the protocol layer stack.
* *
* @return netif, or NULL if failed. * @return netif, or NULL if failed.
*/ */
struct netif * struct netif *
netif_add(struct netif *netif, struct ip_addr *ipaddr, struct ip_addr *netmask, netif_add(struct netif *netif, struct ip_addr *ipaddr, struct ip_addr *netmask,
struct ip_addr *gw, struct ip_addr *gw,
void *state, void *state,
err_t (* init)(struct netif *netif), err_t (* init)(struct netif *netif),
err_t (* input)(struct pbuf *p, struct netif *netif)) err_t (* input)(struct pbuf *p, struct netif *netif))
{ {
static s16_t netifnum = 0; static s16_t netifnum = 0;
/* reset new interface configuration state */ /* reset new interface configuration state */
netif->ip_addr.addr = 0; netif->ip_addr.addr = 0;
netif->netmask.addr = 0; netif->netmask.addr = 0;
netif->gw.addr = 0; netif->gw.addr = 0;
netif->flags = 0; netif->flags = 0;
#if LWIP_DHCP #if LWIP_DHCP
/* netif not under DHCP control by default */ /* netif not under DHCP control by default */
netif->dhcp = NULL; netif->dhcp = NULL;
#endif #endif
/* remember netif specific state information data */ /* remember netif specific state information data */
netif->state = state; netif->state = state;
netif->num = netifnum++; netif->num = netifnum++;
netif->input = input; netif->input = input;
netif_set_addr(netif, ipaddr, netmask, gw); netif_set_addr(netif, ipaddr, netmask, gw);
/* call user specified initialization function for netif */ /* call user specified initialization function for netif */
if (init(netif) != ERR_OK) { if (init(netif) != ERR_OK) {
return NULL; return NULL;
} }
/* add this netif to the list */ /* add this netif to the list */
netif->next = netif_list; netif->next = netif_list;
netif_list = netif; netif_list = netif;
snmp_inc_iflist(); snmp_inc_iflist();
LWIP_DEBUGF(NETIF_DEBUG, ("netif: added interface %c%c IP addr ", LWIP_DEBUGF(NETIF_DEBUG, ("netif: added interface %c%c IP addr ",
netif->name[0], netif->name[1])); netif->name[0], netif->name[1]));
ip_addr_debug_print(NETIF_DEBUG, ipaddr); ip_addr_debug_print(NETIF_DEBUG, ipaddr);
LWIP_DEBUGF(NETIF_DEBUG, (" netmask ")); LWIP_DEBUGF(NETIF_DEBUG, (" netmask "));
ip_addr_debug_print(NETIF_DEBUG, netmask); ip_addr_debug_print(NETIF_DEBUG, netmask);
LWIP_DEBUGF(NETIF_DEBUG, (" gw ")); LWIP_DEBUGF(NETIF_DEBUG, (" gw "));
ip_addr_debug_print(NETIF_DEBUG, gw); ip_addr_debug_print(NETIF_DEBUG, gw);
LWIP_DEBUGF(NETIF_DEBUG, ("\n")); LWIP_DEBUGF(NETIF_DEBUG, ("\n"));
return netif; return netif;
} }
void void
netif_set_addr(struct netif *netif,struct ip_addr *ipaddr, struct ip_addr *netmask, netif_set_addr(struct netif *netif,struct ip_addr *ipaddr, struct ip_addr *netmask,
struct ip_addr *gw) struct ip_addr *gw)
{ {
netif_set_ipaddr(netif, ipaddr); netif_set_ipaddr(netif, ipaddr);
netif_set_netmask(netif, netmask); netif_set_netmask(netif, netmask);
netif_set_gw(netif, gw); netif_set_gw(netif, gw);
} }
void netif_remove(struct netif * netif) void netif_remove(struct netif * netif)
{ {
if ( netif == NULL ) return; if ( netif == NULL ) return;
snmp_delete_ipaddridx_tree(netif); snmp_delete_ipaddridx_tree(netif);
/* is it the first netif? */ /* is it the first netif? */
if (netif_list == netif) { if (netif_list == netif) {
netif_list = netif->next; netif_list = netif->next;
snmp_dec_iflist(); snmp_dec_iflist();
} }
else { else {
/* look for netif further down the list */ /* look for netif further down the list */
struct netif * tmpNetif; struct netif * tmpNetif;
for (tmpNetif = netif_list; tmpNetif != NULL; tmpNetif = tmpNetif->next) { for (tmpNetif = netif_list; tmpNetif != NULL; tmpNetif = tmpNetif->next) {
if (tmpNetif->next == netif) { if (tmpNetif->next == netif) {
tmpNetif->next = netif->next; tmpNetif->next = netif->next;
snmp_dec_iflist(); snmp_dec_iflist();
break; break;
} }
} }
if (tmpNetif == NULL) if (tmpNetif == NULL)
return; /* we didn't find any netif today */ return; /* we didn't find any netif today */
} }
/* this netif is default? */ /* this netif is default? */
if (netif_default == netif) if (netif_default == netif)
/* reset default netif */ /* reset default netif */
netif_default = NULL; netif_default = NULL;
LWIP_DEBUGF( NETIF_DEBUG, ("netif_remove: removed netif\n") ); LWIP_DEBUGF( NETIF_DEBUG, ("netif_remove: removed netif\n") );
} }
struct netif * struct netif *
netif_find(char *name) netif_find(char *name)
{ {
struct netif *netif; struct netif *netif;
u8_t num; u8_t num;
if (name == NULL) { if (name == NULL) {
return NULL; return NULL;
} }
num = name[2] - '0'; num = name[2] - '0';
for(netif = netif_list; netif != NULL; netif = netif->next) { for(netif = netif_list; netif != NULL; netif = netif->next) {
if (num == netif->num && if (num == netif->num &&
name[0] == netif->name[0] && name[0] == netif->name[0] &&
name[1] == netif->name[1]) { name[1] == netif->name[1]) {
LWIP_DEBUGF(NETIF_DEBUG, ("netif_find: found %c%c\n", name[0], name[1])); LWIP_DEBUGF(NETIF_DEBUG, ("netif_find: found %c%c\n", name[0], name[1]));
return netif; return netif;
} }
} }
LWIP_DEBUGF(NETIF_DEBUG, ("netif_find: didn't find %c%c\n", name[0], name[1])); LWIP_DEBUGF(NETIF_DEBUG, ("netif_find: didn't find %c%c\n", name[0], name[1]));
return NULL; return NULL;
} }
void void
netif_set_ipaddr(struct netif *netif, struct ip_addr *ipaddr) netif_set_ipaddr(struct netif *netif, struct ip_addr *ipaddr)
{ {
/* TODO: Handling of obsolete pcbs */ /* TODO: Handling of obsolete pcbs */
/* See: http://mail.gnu.org/archive/html/lwip-users/2003-03/msg00118.html */ /* See: http://mail.gnu.org/archive/html/lwip-users/2003-03/msg00118.html */
#if LWIP_TCP #if LWIP_TCP
struct tcp_pcb *pcb; struct tcp_pcb *pcb;
struct tcp_pcb_listen *lpcb; struct tcp_pcb_listen *lpcb;
/* address is actually being changed? */ /* address is actually being changed? */
if ((ip_addr_cmp(ipaddr, &(netif->ip_addr))) == 0) if ((ip_addr_cmp(ipaddr, &(netif->ip_addr))) == 0)
{ {
/* extern struct tcp_pcb *tcp_active_pcbs; defined by tcp.h */ /* extern struct tcp_pcb *tcp_active_pcbs; defined by tcp.h */
LWIP_DEBUGF(NETIF_DEBUG | 1, ("netif_set_ipaddr: netif address being changed\n")); LWIP_DEBUGF(NETIF_DEBUG | 1, ("netif_set_ipaddr: netif address being changed\n"));
pcb = tcp_active_pcbs; pcb = tcp_active_pcbs;
while (pcb != NULL) { while (pcb != NULL) {
/* PCB bound to current local interface address? */ /* PCB bound to current local interface address? */
if (ip_addr_cmp(&(pcb->local_ip), &(netif->ip_addr))) { if (ip_addr_cmp(&(pcb->local_ip), &(netif->ip_addr))) {
/* this connection must be aborted */ /* this connection must be aborted */
struct tcp_pcb *next = pcb->next; struct tcp_pcb *next = pcb->next;
LWIP_DEBUGF(NETIF_DEBUG | 1, ("netif_set_ipaddr: aborting TCP pcb %p\n", (void *)pcb)); LWIP_DEBUGF(NETIF_DEBUG | 1, ("netif_set_ipaddr: aborting TCP pcb %p\n", (void *)pcb));
tcp_abort(pcb); tcp_abort(pcb);
pcb = next; pcb = next;
} else { } else {
pcb = pcb->next; pcb = pcb->next;
} }
} }
for (lpcb = tcp_listen_pcbs.listen_pcbs; lpcb != NULL; lpcb = lpcb->next) { for (lpcb = tcp_listen_pcbs.listen_pcbs; lpcb != NULL; lpcb = lpcb->next) {
/* PCB bound to current local interface address? */ /* PCB bound to current local interface address? */
if (ip_addr_cmp(&(lpcb->local_ip), &(netif->ip_addr))) { if (ip_addr_cmp(&(lpcb->local_ip), &(netif->ip_addr))) {
/* The PCB is listening to the old ipaddr and /* The PCB is listening to the old ipaddr and
* is set to listen to the new one instead */ * is set to listen to the new one instead */
ip_addr_set(&(lpcb->local_ip), ipaddr); ip_addr_set(&(lpcb->local_ip), ipaddr);
} }
} }
} }
#endif #endif
snmp_delete_ipaddridx_tree(netif); snmp_delete_ipaddridx_tree(netif);
snmp_delete_iprteidx_tree(0,netif); snmp_delete_iprteidx_tree(0,netif);
/* set new IP address to netif */ /* set new IP address to netif */
ip_addr_set(&(netif->ip_addr), ipaddr); ip_addr_set(&(netif->ip_addr), ipaddr);
snmp_insert_ipaddridx_tree(netif); snmp_insert_ipaddridx_tree(netif);
snmp_insert_iprteidx_tree(0,netif); snmp_insert_iprteidx_tree(0,netif);
#if 0 /* only allowed for Ethernet interfaces TODO: how can we check? */ #if 0 /* only allowed for Ethernet interfaces TODO: how can we check? */
/** For Ethernet network interfaces, we would like to send a /** For Ethernet network interfaces, we would like to send a
* "gratuitous ARP"; this is an ARP packet sent by a node in order * "gratuitous ARP"; this is an ARP packet sent by a node in order
* to spontaneously cause other nodes to update an entry in their * to spontaneously cause other nodes to update an entry in their
* ARP cache. From RFC 3220 "IP Mobility Support for IPv4" section 4.6. * ARP cache. From RFC 3220 "IP Mobility Support for IPv4" section 4.6.
*/ */
etharp_query(netif, ipaddr, NULL); etharp_query(netif, ipaddr, NULL);
#endif #endif
LWIP_DEBUGF(NETIF_DEBUG | DBG_TRACE | DBG_STATE | 3, ("netif: IP address of interface %c%c set to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n", LWIP_DEBUGF(NETIF_DEBUG | DBG_TRACE | DBG_STATE | 3, ("netif: IP address of interface %c%c set to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
netif->name[0], netif->name[1], netif->name[0], netif->name[1],
ip4_addr1(&netif->ip_addr), ip4_addr1(&netif->ip_addr),
ip4_addr2(&netif->ip_addr), ip4_addr2(&netif->ip_addr),
ip4_addr3(&netif->ip_addr), ip4_addr3(&netif->ip_addr),
ip4_addr4(&netif->ip_addr))); ip4_addr4(&netif->ip_addr)));
} }
void void
netif_set_gw(struct netif *netif, struct ip_addr *gw) netif_set_gw(struct netif *netif, struct ip_addr *gw)
{ {
ip_addr_set(&(netif->gw), gw); ip_addr_set(&(netif->gw), gw);
LWIP_DEBUGF(NETIF_DEBUG | DBG_TRACE | DBG_STATE | 3, ("netif: GW address of interface %c%c set to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n", LWIP_DEBUGF(NETIF_DEBUG | DBG_TRACE | DBG_STATE | 3, ("netif: GW address of interface %c%c set to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
netif->name[0], netif->name[1], netif->name[0], netif->name[1],
ip4_addr1(&netif->gw), ip4_addr1(&netif->gw),
ip4_addr2(&netif->gw), ip4_addr2(&netif->gw),
ip4_addr3(&netif->gw), ip4_addr3(&netif->gw),
ip4_addr4(&netif->gw))); ip4_addr4(&netif->gw)));
} }
void void
netif_set_netmask(struct netif *netif, struct ip_addr *netmask) netif_set_netmask(struct netif *netif, struct ip_addr *netmask)
{ {
snmp_delete_iprteidx_tree(0, netif); snmp_delete_iprteidx_tree(0, netif);
/* set new netmask to netif */ /* set new netmask to netif */
ip_addr_set(&(netif->netmask), netmask); ip_addr_set(&(netif->netmask), netmask);
snmp_insert_iprteidx_tree(0, netif); snmp_insert_iprteidx_tree(0, netif);
LWIP_DEBUGF(NETIF_DEBUG | DBG_TRACE | DBG_STATE | 3, ("netif: netmask of interface %c%c set to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n", LWIP_DEBUGF(NETIF_DEBUG | DBG_TRACE | DBG_STATE | 3, ("netif: netmask of interface %c%c set to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
netif->name[0], netif->name[1], netif->name[0], netif->name[1],
ip4_addr1(&netif->netmask), ip4_addr1(&netif->netmask),
ip4_addr2(&netif->netmask), ip4_addr2(&netif->netmask),
ip4_addr3(&netif->netmask), ip4_addr3(&netif->netmask),
ip4_addr4(&netif->netmask))); ip4_addr4(&netif->netmask)));
} }
void void
netif_set_default(struct netif *netif) netif_set_default(struct netif *netif)
{ {
if (netif == NULL) if (netif == NULL)
{ {
/* remove default route */ /* remove default route */
snmp_delete_iprteidx_tree(1, netif); snmp_delete_iprteidx_tree(1, netif);
} }
else else
{ {
/* install default route */ /* install default route */
snmp_insert_iprteidx_tree(1, netif); snmp_insert_iprteidx_tree(1, netif);
} }
netif_default = netif; netif_default = netif;
LWIP_DEBUGF(NETIF_DEBUG, ("netif: setting default interface %c%c\n", LWIP_DEBUGF(NETIF_DEBUG, ("netif: setting default interface %c%c\n",
netif ? netif->name[0] : '\'', netif ? netif->name[1] : '\'')); netif ? netif->name[0] : '\'', netif ? netif->name[1] : '\''));
} }
/** /**
* Bring an interface up, available for processing * Bring an interface up, available for processing
* traffic. * traffic.
* *
* @note: Enabling DHCP on a down interface will make it come * @note: Enabling DHCP on a down interface will make it come
* up once configured. * up once configured.
* *
* @see dhcp_start() * @see dhcp_start()
*/ */
void netif_set_up(struct netif *netif) void netif_set_up(struct netif *netif)
{ {
netif->flags |= NETIF_FLAG_UP; netif->flags |= NETIF_FLAG_UP;
#if LWIP_SNMP #if LWIP_SNMP
snmp_get_sysuptime(&netif->ts); snmp_get_sysuptime(&netif->ts);
#endif #endif
} }
/** /**
* Ask if an interface is up * Ask if an interface is up
*/ */
u8_t netif_is_up(struct netif *netif) u8_t netif_is_up(struct netif *netif)
{ {
return (netif->flags & NETIF_FLAG_UP)?1:0; return (netif->flags & NETIF_FLAG_UP)?1:0;
} }
/** /**
* Bring an interface down, disabling any traffic processing. * Bring an interface down, disabling any traffic processing.
* *
* @note: Enabling DHCP on a down interface will make it come * @note: Enabling DHCP on a down interface will make it come
* up once configured. * up once configured.
* *
* @see dhcp_start() * @see dhcp_start()
*/ */
void netif_set_down(struct netif *netif) void netif_set_down(struct netif *netif)
{ {
netif->flags &= ~NETIF_FLAG_UP; netif->flags &= ~NETIF_FLAG_UP;
#if LWIP_SNMP #if LWIP_SNMP
snmp_get_sysuptime(&netif->ts); snmp_get_sysuptime(&netif->ts);
#endif #endif
} }
void void
netif_init(void) netif_init(void)
{ {
netif_list = netif_default = NULL; netif_list = netif_default = NULL;
} }

File diff suppressed because it is too large Load diff

View file

@ -1,326 +1,326 @@
/** /**
* @file * @file
* *
* Implementation of raw protocol PCBs for low-level handling of * Implementation of raw protocol PCBs for low-level handling of
* different types of protocols besides (or overriding) those * different types of protocols besides (or overriding) those
* already available in lwIP. * already available in lwIP.
* *
*/ */
/* /*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science. * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, * 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products * 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE. * OF SUCH DAMAGE.
* *
* This file is part of the lwIP TCP/IP stack. * This file is part of the lwIP TCP/IP stack.
* *
* Author: Adam Dunkels <adam@sics.se> * Author: Adam Dunkels <adam@sics.se>
* *
*/ */
#include <string.h> #include <string.h>
#include "lwip/opt.h" #include "lwip/opt.h"
#include "lwip/def.h" #include "lwip/def.h"
#include "lwip/memp.h" #include "lwip/memp.h"
#include "lwip/inet.h" #include "lwip/inet.h"
#include "lwip/ip_addr.h" #include "lwip/ip_addr.h"
#include "lwip/netif.h" #include "lwip/netif.h"
#include "lwip/raw.h" #include "lwip/raw.h"
#include "lwip/stats.h" #include "lwip/stats.h"
#include "arch/perf.h" #include "arch/perf.h"
#include "lwip/snmp.h" #include "lwip/snmp.h"
#if LWIP_RAW #if LWIP_RAW
/** The list of RAW PCBs */ /** The list of RAW PCBs */
static struct raw_pcb *raw_pcbs = NULL; static struct raw_pcb *raw_pcbs = NULL;
void void
raw_init(void) raw_init(void)
{ {
raw_pcbs = NULL; raw_pcbs = NULL;
} }
/** /**
* Determine if in incoming IP packet is covered by a RAW PCB * Determine if in incoming IP packet is covered by a RAW PCB
* and if so, pass it to a user-provided receive callback function. * and if so, pass it to a user-provided receive callback function.
* *
* Given an incoming IP datagram (as a chain of pbufs) this function * Given an incoming IP datagram (as a chain of pbufs) this function
* finds a corresponding RAW PCB and calls the corresponding receive * finds a corresponding RAW PCB and calls the corresponding receive
* callback function. * callback function.
* *
* @param pbuf pbuf to be demultiplexed to a RAW PCB. * @param pbuf pbuf to be demultiplexed to a RAW PCB.
* @param netif network interface on which the datagram was received. * @param netif network interface on which the datagram was received.
* @Return - 1 if the packet has been eaten by a RAW PCB receive * @Return - 1 if the packet has been eaten by a RAW PCB receive
* callback function. The caller MAY NOT not reference the * callback function. The caller MAY NOT not reference the
* packet any longer, and MAY NOT call pbuf_free(). * packet any longer, and MAY NOT call pbuf_free().
* @return - 0 if packet is not eaten (pbuf is still referenced by the * @return - 0 if packet is not eaten (pbuf is still referenced by the
* caller). * caller).
* *
*/ */
u8_t u8_t
raw_input(struct pbuf *p, struct netif *inp) raw_input(struct pbuf *p, struct netif *inp)
{ {
struct raw_pcb *pcb; struct raw_pcb *pcb;
struct ip_hdr *iphdr; struct ip_hdr *iphdr;
s16_t proto; s16_t proto;
u8_t eaten = 0; u8_t eaten = 0;
iphdr = p->payload; iphdr = p->payload;
proto = IPH_PROTO(iphdr); proto = IPH_PROTO(iphdr);
pcb = raw_pcbs; pcb = raw_pcbs;
/* loop through all raw pcbs until the packet is eaten by one */ /* loop through all raw pcbs until the packet is eaten by one */
/* this allows multiple pcbs to match against the packet by design */ /* this allows multiple pcbs to match against the packet by design */
while ((eaten == 0) && (pcb != NULL)) { while ((eaten == 0) && (pcb != NULL)) {
if (pcb->protocol == proto) { if (pcb->protocol == proto) {
/* receive callback function available? */ /* receive callback function available? */
if (pcb->recv != NULL) { if (pcb->recv != NULL) {
/* the receive callback function did not eat the packet? */ /* the receive callback function did not eat the packet? */
if (pcb->recv(pcb->recv_arg, pcb, p, &(iphdr->src)) != 0) if (pcb->recv(pcb->recv_arg, pcb, p, &(iphdr->src)) != 0)
{ {
/* receive function ate the packet */ /* receive function ate the packet */
p = NULL; p = NULL;
eaten = 1; eaten = 1;
} }
} }
/* no receive callback function was set for this raw PCB */ /* no receive callback function was set for this raw PCB */
/* drop the packet */ /* drop the packet */
} }
pcb = pcb->next; pcb = pcb->next;
} }
return eaten; return eaten;
} }
/** /**
* Bind a RAW PCB. * Bind a RAW PCB.
* *
* @param pcb RAW PCB to be bound with a local address ipaddr. * @param pcb RAW PCB to be bound with a local address ipaddr.
* @param ipaddr local IP address to bind with. Use IP_ADDR_ANY to * @param ipaddr local IP address to bind with. Use IP_ADDR_ANY to
* bind to all local interfaces. * bind to all local interfaces.
* *
* @return lwIP error code. * @return lwIP error code.
* - ERR_OK. Successful. No error occured. * - ERR_OK. Successful. No error occured.
* - ERR_USE. The specified IP address is already bound to by * - ERR_USE. The specified IP address is already bound to by
* another RAW PCB. * another RAW PCB.
* *
* @see raw_disconnect() * @see raw_disconnect()
*/ */
err_t err_t
raw_bind(struct raw_pcb *pcb, struct ip_addr *ipaddr) raw_bind(struct raw_pcb *pcb, struct ip_addr *ipaddr)
{ {
ip_addr_set(&pcb->local_ip, ipaddr); ip_addr_set(&pcb->local_ip, ipaddr);
return ERR_OK; return ERR_OK;
} }
/** /**
* Connect an RAW PCB. This function is required by upper layers * Connect an RAW PCB. This function is required by upper layers
* of lwip. Using the raw api you could use raw_sendto() instead * of lwip. Using the raw api you could use raw_sendto() instead
* *
* This will associate the RAW PCB with the remote address. * This will associate the RAW PCB with the remote address.
* *
* @param pcb RAW PCB to be connected with remote address ipaddr and port. * @param pcb RAW PCB to be connected with remote address ipaddr and port.
* @param ipaddr remote IP address to connect with. * @param ipaddr remote IP address to connect with.
* *
* @return lwIP error code * @return lwIP error code
* *
* @see raw_disconnect() and raw_sendto() * @see raw_disconnect() and raw_sendto()
*/ */
err_t err_t
raw_connect(struct raw_pcb *pcb, struct ip_addr *ipaddr) raw_connect(struct raw_pcb *pcb, struct ip_addr *ipaddr)
{ {
ip_addr_set(&pcb->remote_ip, ipaddr); ip_addr_set(&pcb->remote_ip, ipaddr);
return ERR_OK; return ERR_OK;
} }
/** /**
* Set the callback function for received packets that match the * Set the callback function for received packets that match the
* raw PCB's protocol and binding. * raw PCB's protocol and binding.
* *
* The callback function MUST either * The callback function MUST either
* - eat the packet by calling pbuf_free() and returning non-zero. The * - eat the packet by calling pbuf_free() and returning non-zero. The
* packet will not be passed to other raw PCBs or other protocol layers. * packet will not be passed to other raw PCBs or other protocol layers.
* - not free the packet, and return zero. The packet will be matched * - not free the packet, and return zero. The packet will be matched
* against further PCBs and/or forwarded to another protocol layers. * against further PCBs and/or forwarded to another protocol layers.
* *
* @return non-zero if the packet was free()d, zero if the packet remains * @return non-zero if the packet was free()d, zero if the packet remains
* available for others. * available for others.
*/ */
void void
raw_recv(struct raw_pcb *pcb, raw_recv(struct raw_pcb *pcb,
u8_t (* recv)(void *arg, struct raw_pcb *upcb, struct pbuf *p, u8_t (* recv)(void *arg, struct raw_pcb *upcb, struct pbuf *p,
struct ip_addr *addr), struct ip_addr *addr),
void *recv_arg) void *recv_arg)
{ {
/* remember recv() callback and user data */ /* remember recv() callback and user data */
pcb->recv = recv; pcb->recv = recv;
pcb->recv_arg = recv_arg; pcb->recv_arg = recv_arg;
} }
/** /**
* Send the raw IP packet to the given address. Note that actually you cannot * Send the raw IP packet to the given address. Note that actually you cannot
* modify the IP headers (this is inconsistent with the receive callback where * modify the IP headers (this is inconsistent with the receive callback where
* you actually get the IP headers), you can only specify the IP payload here. * you actually get the IP headers), you can only specify the IP payload here.
* It requires some more changes in lwIP. (there will be a raw_send() function * It requires some more changes in lwIP. (there will be a raw_send() function
* then.) * then.)
* *
* @param pcb the raw pcb which to send * @param pcb the raw pcb which to send
* @param p the IP payload to send * @param p the IP payload to send
* @param ipaddr the destination address of the IP packet * @param ipaddr the destination address of the IP packet
* *
*/ */
err_t err_t
raw_sendto(struct raw_pcb *pcb, struct pbuf *p, struct ip_addr *ipaddr) raw_sendto(struct raw_pcb *pcb, struct pbuf *p, struct ip_addr *ipaddr)
{ {
err_t err; err_t err;
struct netif *netif; struct netif *netif;
struct ip_addr *src_ip; struct ip_addr *src_ip;
struct pbuf *q; /* q will be sent down the stack */ struct pbuf *q; /* q will be sent down the stack */
LWIP_DEBUGF(RAW_DEBUG | DBG_TRACE | 3, ("raw_sendto\n")); LWIP_DEBUGF(RAW_DEBUG | DBG_TRACE | 3, ("raw_sendto\n"));
/* not enough space to add an IP header to first pbuf in given p chain? */ /* not enough space to add an IP header to first pbuf in given p chain? */
if (pbuf_header(p, IP_HLEN)) { if (pbuf_header(p, IP_HLEN)) {
/* allocate header in new pbuf */ /* allocate header in new pbuf */
q = pbuf_alloc(PBUF_IP, 0, PBUF_RAM); q = pbuf_alloc(PBUF_IP, 0, PBUF_RAM);
/* new header pbuf could not be allocated? */ /* new header pbuf could not be allocated? */
if (q == NULL) { if (q == NULL) {
LWIP_DEBUGF(RAW_DEBUG | DBG_TRACE | 2, ("raw_sendto: could not allocate header\n")); LWIP_DEBUGF(RAW_DEBUG | DBG_TRACE | 2, ("raw_sendto: could not allocate header\n"));
return ERR_MEM; return ERR_MEM;
} }
/* chain header q in front of given pbuf p */ /* chain header q in front of given pbuf p */
pbuf_chain(q, p); pbuf_chain(q, p);
/* { first pbuf q points to header pbuf } */ /* { first pbuf q points to header pbuf } */
LWIP_DEBUGF(RAW_DEBUG, ("raw_sendto: added header pbuf %p before given pbuf %p\n", (void *)q, (void *)p)); LWIP_DEBUGF(RAW_DEBUG, ("raw_sendto: added header pbuf %p before given pbuf %p\n", (void *)q, (void *)p));
} else { } else {
/* first pbuf q equals given pbuf */ /* first pbuf q equals given pbuf */
q = p; q = p;
pbuf_header(q, -IP_HLEN); pbuf_header(q, -IP_HLEN);
} }
if ((netif = ip_route(ipaddr)) == NULL) { if ((netif = ip_route(ipaddr)) == NULL) {
LWIP_DEBUGF(RAW_DEBUG | 1, ("raw_sendto: No route to 0x%"X32_F"\n", ipaddr->addr)); LWIP_DEBUGF(RAW_DEBUG | 1, ("raw_sendto: No route to 0x%"X32_F"\n", ipaddr->addr));
#if RAW_STATS #if RAW_STATS
/* ++lwip_stats.raw.rterr;*/ /* ++lwip_stats.raw.rterr;*/
#endif /* RAW_STATS */ #endif /* RAW_STATS */
/* free any temporary header pbuf allocated by pbuf_header() */ /* free any temporary header pbuf allocated by pbuf_header() */
if (q != p) { if (q != p) {
pbuf_free(q); pbuf_free(q);
} }
return ERR_RTE; return ERR_RTE;
} }
if (ip_addr_isany(&pcb->local_ip)) { if (ip_addr_isany(&pcb->local_ip)) {
/* use outgoing network interface IP address as source address */ /* use outgoing network interface IP address as source address */
src_ip = &(netif->ip_addr); src_ip = &(netif->ip_addr);
} else { } else {
/* use RAW PCB local IP address as source address */ /* use RAW PCB local IP address as source address */
src_ip = &(pcb->local_ip); src_ip = &(pcb->local_ip);
} }
err = ip_output_if (q, src_ip, ipaddr, pcb->ttl, pcb->tos, pcb->protocol, netif); err = ip_output_if (q, src_ip, ipaddr, pcb->ttl, pcb->tos, pcb->protocol, netif);
/* did we chain a header earlier? */ /* did we chain a header earlier? */
if (q != p) { if (q != p) {
/* free the header */ /* free the header */
pbuf_free(q); pbuf_free(q);
} }
return err; return err;
} }
/** /**
* Send the raw IP packet to the address given by raw_connect() * Send the raw IP packet to the address given by raw_connect()
* *
* @param pcb the raw pcb which to send * @param pcb the raw pcb which to send
* @param p the IP payload to send * @param p the IP payload to send
* @param ipaddr the destination address of the IP packet * @param ipaddr the destination address of the IP packet
* *
*/ */
err_t err_t
raw_send(struct raw_pcb *pcb, struct pbuf *p) raw_send(struct raw_pcb *pcb, struct pbuf *p)
{ {
return raw_sendto(pcb, p, &pcb->remote_ip); return raw_sendto(pcb, p, &pcb->remote_ip);
} }
/** /**
* Remove an RAW PCB. * Remove an RAW PCB.
* *
* @param pcb RAW PCB to be removed. The PCB is removed from the list of * @param pcb RAW PCB to be removed. The PCB is removed from the list of
* RAW PCB's and the data structure is freed from memory. * RAW PCB's and the data structure is freed from memory.
* *
* @see raw_new() * @see raw_new()
*/ */
void void
raw_remove(struct raw_pcb *pcb) raw_remove(struct raw_pcb *pcb)
{ {
struct raw_pcb *pcb2; struct raw_pcb *pcb2;
/* pcb to be removed is first in list? */ /* pcb to be removed is first in list? */
if (raw_pcbs == pcb) { if (raw_pcbs == pcb) {
/* make list start at 2nd pcb */ /* make list start at 2nd pcb */
raw_pcbs = raw_pcbs->next; raw_pcbs = raw_pcbs->next;
/* pcb not 1st in list */ /* pcb not 1st in list */
} else for(pcb2 = raw_pcbs; pcb2 != NULL; pcb2 = pcb2->next) { } else for(pcb2 = raw_pcbs; pcb2 != NULL; pcb2 = pcb2->next) {
/* find pcb in raw_pcbs list */ /* find pcb in raw_pcbs list */
if (pcb2->next != NULL && pcb2->next == pcb) { if (pcb2->next != NULL && pcb2->next == pcb) {
/* remove pcb from list */ /* remove pcb from list */
pcb2->next = pcb->next; pcb2->next = pcb->next;
} }
} }
memp_free(MEMP_RAW_PCB, pcb); memp_free(MEMP_RAW_PCB, pcb);
} }
/** /**
* Create a RAW PCB. * Create a RAW PCB.
* *
* @return The RAW PCB which was created. NULL if the PCB data structure * @return The RAW PCB which was created. NULL if the PCB data structure
* could not be allocated. * could not be allocated.
* *
* @param proto the protocol number of the IPs payload (e.g. IP_PROTO_ICMP) * @param proto the protocol number of the IPs payload (e.g. IP_PROTO_ICMP)
* *
* @see raw_remove() * @see raw_remove()
*/ */
struct raw_pcb * struct raw_pcb *
raw_new(u16_t proto) { raw_new(u16_t proto) {
struct raw_pcb *pcb; struct raw_pcb *pcb;
LWIP_DEBUGF(RAW_DEBUG | DBG_TRACE | 3, ("raw_new\n")); LWIP_DEBUGF(RAW_DEBUG | DBG_TRACE | 3, ("raw_new\n"));
pcb = memp_malloc(MEMP_RAW_PCB); pcb = memp_malloc(MEMP_RAW_PCB);
/* could allocate RAW PCB? */ /* could allocate RAW PCB? */
if (pcb != NULL) { if (pcb != NULL) {
/* initialize PCB to all zeroes */ /* initialize PCB to all zeroes */
memset(pcb, 0, sizeof(struct raw_pcb)); memset(pcb, 0, sizeof(struct raw_pcb));
pcb->protocol = proto; pcb->protocol = proto;
pcb->ttl = RAW_TTL; pcb->ttl = RAW_TTL;
pcb->next = raw_pcbs; pcb->next = raw_pcbs;
raw_pcbs = pcb; raw_pcbs = pcb;
} }
return pcb; return pcb;
} }
#endif /* LWIP_RAW */ #endif /* LWIP_RAW */

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,115 +1,115 @@
/* /*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science. * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, * 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products * 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE. * OF SUCH DAMAGE.
* *
* This file is part of the lwIP TCP/IP stack. * This file is part of the lwIP TCP/IP stack.
* *
* Author: Adam Dunkels <adam@sics.se> * Author: Adam Dunkels <adam@sics.se>
* *
*/ */
#include <string.h> #include <string.h>
#include "lwip/opt.h" #include "lwip/opt.h"
#include "lwip/def.h" #include "lwip/def.h"
#include "lwip/stats.h" #include "lwip/stats.h"
#include "lwip/mem.h" #include "lwip/mem.h"
#if LWIP_STATS #if LWIP_STATS
struct stats_ lwip_stats; struct stats_ lwip_stats;
void void
stats_init(void) stats_init(void)
{ {
memset(&lwip_stats, 0, sizeof(struct stats_)); memset(&lwip_stats, 0, sizeof(struct stats_));
} }
#if LWIP_STATS_DISPLAY #if LWIP_STATS_DISPLAY
void void
stats_display_proto(struct stats_proto *proto, char *name) stats_display_proto(struct stats_proto *proto, char *name)
{ {
LWIP_PLATFORM_DIAG(("\n%s\n\t", name)); LWIP_PLATFORM_DIAG(("\n%s\n\t", name));
LWIP_PLATFORM_DIAG(("xmit: %"S16_F"\n\t", proto->xmit)); LWIP_PLATFORM_DIAG(("xmit: %"S16_F"\n\t", proto->xmit));
LWIP_PLATFORM_DIAG(("rexmit: %"S16_F"\n\t", proto->rexmit)); LWIP_PLATFORM_DIAG(("rexmit: %"S16_F"\n\t", proto->rexmit));
LWIP_PLATFORM_DIAG(("recv: %"S16_F"\n\t", proto->recv)); LWIP_PLATFORM_DIAG(("recv: %"S16_F"\n\t", proto->recv));
LWIP_PLATFORM_DIAG(("fw: %"S16_F"\n\t", proto->fw)); LWIP_PLATFORM_DIAG(("fw: %"S16_F"\n\t", proto->fw));
LWIP_PLATFORM_DIAG(("drop: %"S16_F"\n\t", proto->drop)); LWIP_PLATFORM_DIAG(("drop: %"S16_F"\n\t", proto->drop));
LWIP_PLATFORM_DIAG(("chkerr: %"S16_F"\n\t", proto->chkerr)); LWIP_PLATFORM_DIAG(("chkerr: %"S16_F"\n\t", proto->chkerr));
LWIP_PLATFORM_DIAG(("lenerr: %"S16_F"\n\t", proto->lenerr)); LWIP_PLATFORM_DIAG(("lenerr: %"S16_F"\n\t", proto->lenerr));
LWIP_PLATFORM_DIAG(("memerr: %"S16_F"\n\t", proto->memerr)); LWIP_PLATFORM_DIAG(("memerr: %"S16_F"\n\t", proto->memerr));
LWIP_PLATFORM_DIAG(("rterr: %"S16_F"\n\t", proto->rterr)); LWIP_PLATFORM_DIAG(("rterr: %"S16_F"\n\t", proto->rterr));
LWIP_PLATFORM_DIAG(("proterr: %"S16_F"\n\t", proto->proterr)); LWIP_PLATFORM_DIAG(("proterr: %"S16_F"\n\t", proto->proterr));
LWIP_PLATFORM_DIAG(("opterr: %"S16_F"\n\t", proto->opterr)); LWIP_PLATFORM_DIAG(("opterr: %"S16_F"\n\t", proto->opterr));
LWIP_PLATFORM_DIAG(("err: %"S16_F"\n\t", proto->err)); LWIP_PLATFORM_DIAG(("err: %"S16_F"\n\t", proto->err));
LWIP_PLATFORM_DIAG(("cachehit: %"S16_F"\n", proto->cachehit)); LWIP_PLATFORM_DIAG(("cachehit: %"S16_F"\n", proto->cachehit));
} }
void void
stats_display_pbuf(struct stats_pbuf *pbuf) stats_display_pbuf(struct stats_pbuf *pbuf)
{ {
LWIP_PLATFORM_DIAG(("\nPBUF\n\t")); LWIP_PLATFORM_DIAG(("\nPBUF\n\t"));
LWIP_PLATFORM_DIAG(("avail: %"S16_F"\n\t", pbuf->avail)); LWIP_PLATFORM_DIAG(("avail: %"S16_F"\n\t", pbuf->avail));
LWIP_PLATFORM_DIAG(("used: %"S16_F"\n\t", pbuf->used)); LWIP_PLATFORM_DIAG(("used: %"S16_F"\n\t", pbuf->used));
LWIP_PLATFORM_DIAG(("max: %"S16_F"\n\t", pbuf->max)); LWIP_PLATFORM_DIAG(("max: %"S16_F"\n\t", pbuf->max));
LWIP_PLATFORM_DIAG(("err: %"S16_F"\n\t", pbuf->err)); LWIP_PLATFORM_DIAG(("err: %"S16_F"\n\t", pbuf->err));
LWIP_PLATFORM_DIAG(("alloc_locked: %"S16_F"\n\t", pbuf->alloc_locked)); LWIP_PLATFORM_DIAG(("alloc_locked: %"S16_F"\n\t", pbuf->alloc_locked));
LWIP_PLATFORM_DIAG(("refresh_locked: %"S16_F"\n", pbuf->refresh_locked)); LWIP_PLATFORM_DIAG(("refresh_locked: %"S16_F"\n", pbuf->refresh_locked));
} }
void void
stats_display_mem(struct stats_mem *mem, char *name) stats_display_mem(struct stats_mem *mem, char *name)
{ {
LWIP_PLATFORM_DIAG(("\n MEM %s\n\t", name)); LWIP_PLATFORM_DIAG(("\n MEM %s\n\t", name));
LWIP_PLATFORM_DIAG(("avail: %"MEM_SIZE_F"\n\t", mem->avail)); LWIP_PLATFORM_DIAG(("avail: %"MEM_SIZE_F"\n\t", mem->avail));
LWIP_PLATFORM_DIAG(("used: %"MEM_SIZE_F"\n\t", mem->used)); LWIP_PLATFORM_DIAG(("used: %"MEM_SIZE_F"\n\t", mem->used));
LWIP_PLATFORM_DIAG(("max: %"MEM_SIZE_F"\n\t", mem->max)); LWIP_PLATFORM_DIAG(("max: %"MEM_SIZE_F"\n\t", mem->max));
LWIP_PLATFORM_DIAG(("err: %"MEM_SIZE_F"\n", mem->err)); LWIP_PLATFORM_DIAG(("err: %"MEM_SIZE_F"\n", mem->err));
} }
void void
stats_display(void) stats_display(void)
{ {
s16_t i; s16_t i;
char * memp_names[] = {"PBUF", "RAW_PCB", "UDP_PCB", "TCP_PCB", "TCP_PCB_LISTEN", char * memp_names[] = {"PBUF", "RAW_PCB", "UDP_PCB", "TCP_PCB", "TCP_PCB_LISTEN",
"TCP_SEG", "NETBUF", "NETCONN", "API_MSG", "TCP_MSG", "TIMEOUT"}; "TCP_SEG", "NETBUF", "NETCONN", "API_MSG", "TCP_MSG", "TIMEOUT"};
stats_display_proto(&lwip_stats.link, "LINK"); stats_display_proto(&lwip_stats.link, "LINK");
stats_display_proto(&lwip_stats.ip_frag, "IP_FRAG"); stats_display_proto(&lwip_stats.ip_frag, "IP_FRAG");
stats_display_proto(&lwip_stats.ip, "IP"); stats_display_proto(&lwip_stats.ip, "IP");
stats_display_proto(&lwip_stats.icmp, "ICMP"); stats_display_proto(&lwip_stats.icmp, "ICMP");
stats_display_proto(&lwip_stats.udp, "UDP"); stats_display_proto(&lwip_stats.udp, "UDP");
stats_display_proto(&lwip_stats.tcp, "TCP"); stats_display_proto(&lwip_stats.tcp, "TCP");
stats_display_pbuf(&lwip_stats.pbuf); stats_display_pbuf(&lwip_stats.pbuf);
stats_display_mem(&lwip_stats.mem, "HEAP"); stats_display_mem(&lwip_stats.mem, "HEAP");
for (i = 0; i < MEMP_MAX; i++) { for (i = 0; i < MEMP_MAX; i++) {
stats_display_mem(&lwip_stats.memp[i], memp_names[i]); stats_display_mem(&lwip_stats.memp[i], memp_names[i]);
} }
} }
#endif /* LWIP_STATS_DISPLAY */ #endif /* LWIP_STATS_DISPLAY */
#endif /* LWIP_STATS */ #endif /* LWIP_STATS */

View file

@ -1,294 +1,294 @@
/* /*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science. * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, * 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products * 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE. * OF SUCH DAMAGE.
* *
* This file is part of the lwIP TCP/IP stack. * This file is part of the lwIP TCP/IP stack.
* *
* Author: Adam Dunkels <adam@sics.se> * Author: Adam Dunkels <adam@sics.se>
* *
*/ */
#include "lwip/sys.h" #include "lwip/sys.h"
#include "lwip/opt.h" #include "lwip/opt.h"
#include "lwip/def.h" #include "lwip/def.h"
#include "lwip/memp.h" #include "lwip/memp.h"
#if (NO_SYS == 0) #if (NO_SYS == 0)
struct sswt_cb struct sswt_cb
{ {
s16_t timeflag; s16_t timeflag;
sys_sem_t *psem; sys_sem_t *psem;
}; };
void void
sys_mbox_fetch(sys_mbox_t mbox, void **msg) sys_mbox_fetch(sys_mbox_t mbox, void **msg)
{ {
u32_t time; u32_t time;
struct sys_timeouts *timeouts; struct sys_timeouts *timeouts;
struct sys_timeo *tmptimeout; struct sys_timeo *tmptimeout;
sys_timeout_handler h; sys_timeout_handler h;
void *arg; void *arg;
again: again:
timeouts = sys_arch_timeouts(); timeouts = sys_arch_timeouts();
if (!timeouts || !timeouts->next) { if (!timeouts || !timeouts->next) {
sys_arch_mbox_fetch(mbox, msg, 0); sys_arch_mbox_fetch(mbox, msg, 0);
} else { } else {
if (timeouts->next->time > 0) { if (timeouts->next->time > 0) {
time = sys_arch_mbox_fetch(mbox, msg, timeouts->next->time); time = sys_arch_mbox_fetch(mbox, msg, timeouts->next->time);
} else { } else {
time = SYS_ARCH_TIMEOUT; time = SYS_ARCH_TIMEOUT;
} }
if (time == SYS_ARCH_TIMEOUT) { if (time == SYS_ARCH_TIMEOUT) {
/* If time == SYS_ARCH_TIMEOUT, a timeout occured before a message /* If time == SYS_ARCH_TIMEOUT, a timeout occured before a message
could be fetched. We should now call the timeout handler and could be fetched. We should now call the timeout handler and
deallocate the memory allocated for the timeout. */ deallocate the memory allocated for the timeout. */
tmptimeout = timeouts->next; tmptimeout = timeouts->next;
timeouts->next = tmptimeout->next; timeouts->next = tmptimeout->next;
h = tmptimeout->h; h = tmptimeout->h;
arg = tmptimeout->arg; arg = tmptimeout->arg;
memp_free(MEMP_SYS_TIMEOUT, tmptimeout); memp_free(MEMP_SYS_TIMEOUT, tmptimeout);
if (h != NULL) { if (h != NULL) {
LWIP_DEBUGF(SYS_DEBUG, ("smf calling h=%p(%p)\n", (void *)h, (void *)arg)); LWIP_DEBUGF(SYS_DEBUG, ("smf calling h=%p(%p)\n", (void *)h, (void *)arg));
h(arg); h(arg);
} }
/* We try again to fetch a message from the mbox. */ /* We try again to fetch a message from the mbox. */
goto again; goto again;
} else { } else {
/* If time != SYS_ARCH_TIMEOUT, a message was received before the timeout /* If time != SYS_ARCH_TIMEOUT, a message was received before the timeout
occured. The time variable is set to the number of occured. The time variable is set to the number of
milliseconds we waited for the message. */ milliseconds we waited for the message. */
if (time <= timeouts->next->time) { if (time <= timeouts->next->time) {
timeouts->next->time -= time; timeouts->next->time -= time;
} else { } else {
timeouts->next->time = 0; timeouts->next->time = 0;
} }
} }
} }
} }
void void
sys_sem_wait(sys_sem_t sem) sys_sem_wait(sys_sem_t sem)
{ {
u32_t time; u32_t time;
struct sys_timeouts *timeouts; struct sys_timeouts *timeouts;
struct sys_timeo *tmptimeout; struct sys_timeo *tmptimeout;
sys_timeout_handler h; sys_timeout_handler h;
void *arg; void *arg;
/* while (sys_arch_sem_wait(sem, 1000) == 0); /* while (sys_arch_sem_wait(sem, 1000) == 0);
return;*/ return;*/
again: again:
timeouts = sys_arch_timeouts(); timeouts = sys_arch_timeouts();
if (!timeouts || !timeouts->next) { if (!timeouts || !timeouts->next) {
sys_arch_sem_wait(sem, 0); sys_arch_sem_wait(sem, 0);
} else { } else {
if (timeouts->next->time > 0) { if (timeouts->next->time > 0) {
time = sys_arch_sem_wait(sem, timeouts->next->time); time = sys_arch_sem_wait(sem, timeouts->next->time);
} else { } else {
time = SYS_ARCH_TIMEOUT; time = SYS_ARCH_TIMEOUT;
} }
if (time == SYS_ARCH_TIMEOUT) { if (time == SYS_ARCH_TIMEOUT) {
/* If time == SYS_ARCH_TIMEOUT, a timeout occured before a message /* If time == SYS_ARCH_TIMEOUT, a timeout occured before a message
could be fetched. We should now call the timeout handler and could be fetched. We should now call the timeout handler and
deallocate the memory allocated for the timeout. */ deallocate the memory allocated for the timeout. */
tmptimeout = timeouts->next; tmptimeout = timeouts->next;
timeouts->next = tmptimeout->next; timeouts->next = tmptimeout->next;
h = tmptimeout->h; h = tmptimeout->h;
arg = tmptimeout->arg; arg = tmptimeout->arg;
memp_free(MEMP_SYS_TIMEOUT, tmptimeout); memp_free(MEMP_SYS_TIMEOUT, tmptimeout);
if (h != NULL) { if (h != NULL) {
LWIP_DEBUGF(SYS_DEBUG, ("ssw h=%p(%p)\n", (void *)h, (void *)arg)); LWIP_DEBUGF(SYS_DEBUG, ("ssw h=%p(%p)\n", (void *)h, (void *)arg));
h(arg); h(arg);
} }
/* We try again to fetch a message from the mbox. */ /* We try again to fetch a message from the mbox. */
goto again; goto again;
} else { } else {
/* If time != SYS_ARCH_TIMEOUT, a message was received before the timeout /* If time != SYS_ARCH_TIMEOUT, a message was received before the timeout
occured. The time variable is set to the number of occured. The time variable is set to the number of
milliseconds we waited for the message. */ milliseconds we waited for the message. */
if (time <= timeouts->next->time) { if (time <= timeouts->next->time) {
timeouts->next->time -= time; timeouts->next->time -= time;
} else { } else {
timeouts->next->time = 0; timeouts->next->time = 0;
} }
} }
} }
} }
void void
sys_timeout(u32_t msecs, sys_timeout_handler h, void *arg) sys_timeout(u32_t msecs, sys_timeout_handler h, void *arg)
{ {
struct sys_timeouts *timeouts; struct sys_timeouts *timeouts;
struct sys_timeo *timeout, *t; struct sys_timeo *timeout, *t;
timeout = memp_malloc(MEMP_SYS_TIMEOUT); timeout = memp_malloc(MEMP_SYS_TIMEOUT);
if (timeout == NULL) { if (timeout == NULL) {
return; return;
} }
timeout->next = NULL; timeout->next = NULL;
timeout->h = h; timeout->h = h;
timeout->arg = arg; timeout->arg = arg;
timeout->time = msecs; timeout->time = msecs;
timeouts = sys_arch_timeouts(); timeouts = sys_arch_timeouts();
LWIP_DEBUGF(SYS_DEBUG, ("sys_timeout: %p msecs=%"U32_F" h=%p arg=%p\n", LWIP_DEBUGF(SYS_DEBUG, ("sys_timeout: %p msecs=%"U32_F" h=%p arg=%p\n",
(void *)timeout, msecs, (void *)h, (void *)arg)); (void *)timeout, msecs, (void *)h, (void *)arg));
LWIP_ASSERT("sys_timeout: timeouts != NULL", timeouts != NULL); LWIP_ASSERT("sys_timeout: timeouts != NULL", timeouts != NULL);
if (timeouts->next == NULL) { if (timeouts->next == NULL) {
timeouts->next = timeout; timeouts->next = timeout;
return; return;
} }
if (timeouts->next->time > msecs) { if (timeouts->next->time > msecs) {
timeouts->next->time -= msecs; timeouts->next->time -= msecs;
timeout->next = timeouts->next; timeout->next = timeouts->next;
timeouts->next = timeout; timeouts->next = timeout;
} else { } else {
for(t = timeouts->next; t != NULL; t = t->next) { for(t = timeouts->next; t != NULL; t = t->next) {
timeout->time -= t->time; timeout->time -= t->time;
if (t->next == NULL || t->next->time > timeout->time) { if (t->next == NULL || t->next->time > timeout->time) {
if (t->next != NULL) { if (t->next != NULL) {
t->next->time -= timeout->time; t->next->time -= timeout->time;
} }
timeout->next = t->next; timeout->next = t->next;
t->next = timeout; t->next = timeout;
break; break;
} }
} }
} }
} }
/* Go through timeout list (for this task only) and remove the first matching entry, /* Go through timeout list (for this task only) and remove the first matching entry,
even though the timeout has not triggered yet. even though the timeout has not triggered yet.
*/ */
void void
sys_untimeout(sys_timeout_handler h, void *arg) sys_untimeout(sys_timeout_handler h, void *arg)
{ {
struct sys_timeouts *timeouts; struct sys_timeouts *timeouts;
struct sys_timeo *prev_t, *t; struct sys_timeo *prev_t, *t;
timeouts = sys_arch_timeouts(); timeouts = sys_arch_timeouts();
if (timeouts->next == NULL) if (timeouts->next == NULL)
return; return;
for (t = timeouts->next, prev_t = NULL; t != NULL; prev_t = t, t = t->next) for (t = timeouts->next, prev_t = NULL; t != NULL; prev_t = t, t = t->next)
{ {
if ((t->h == h) && (t->arg == arg)) if ((t->h == h) && (t->arg == arg))
{ {
/* We have a match */ /* We have a match */
/* Unlink from previous in list */ /* Unlink from previous in list */
if (prev_t == NULL) if (prev_t == NULL)
timeouts->next = t->next; timeouts->next = t->next;
else else
prev_t->next = t->next; prev_t->next = t->next;
/* If not the last one, add time of this one back to next */ /* If not the last one, add time of this one back to next */
if (t->next != NULL) if (t->next != NULL)
t->next->time += t->time; t->next->time += t->time;
memp_free(MEMP_SYS_TIMEOUT, t); memp_free(MEMP_SYS_TIMEOUT, t);
return; return;
} }
} }
return; return;
} }
static void static void
sswt_handler(void *arg) sswt_handler(void *arg)
{ {
struct sswt_cb *sswt_cb = (struct sswt_cb *) arg; struct sswt_cb *sswt_cb = (struct sswt_cb *) arg;
/* Timeout. Set flag to TRUE and signal semaphore */ /* Timeout. Set flag to TRUE and signal semaphore */
sswt_cb->timeflag = 1; sswt_cb->timeflag = 1;
sys_sem_signal(*(sswt_cb->psem)); sys_sem_signal(*(sswt_cb->psem));
} }
/* Wait for a semaphore with timeout (specified in ms) */ /* Wait for a semaphore with timeout (specified in ms) */
/* timeout = 0: wait forever */ /* timeout = 0: wait forever */
/* Returns 0 on timeout. 1 otherwise */ /* Returns 0 on timeout. 1 otherwise */
int int
sys_sem_wait_timeout(sys_sem_t sem, u32_t timeout) sys_sem_wait_timeout(sys_sem_t sem, u32_t timeout)
{ {
struct sswt_cb sswt_cb; struct sswt_cb sswt_cb;
sswt_cb.psem = &sem; sswt_cb.psem = &sem;
sswt_cb.timeflag = 0; sswt_cb.timeflag = 0;
/* If timeout is zero, then just wait forever */ /* If timeout is zero, then just wait forever */
if (timeout > 0) if (timeout > 0)
/* Create a timer and pass it the address of our flag */ /* Create a timer and pass it the address of our flag */
sys_timeout(timeout, sswt_handler, &sswt_cb); sys_timeout(timeout, sswt_handler, &sswt_cb);
sys_sem_wait(sem); sys_sem_wait(sem);
/* Was it a timeout? */ /* Was it a timeout? */
if (sswt_cb.timeflag) if (sswt_cb.timeflag)
{ {
/* timeout */ /* timeout */
return 0; return 0;
} else { } else {
/* Not a timeout. Remove timeout entry */ /* Not a timeout. Remove timeout entry */
sys_untimeout(sswt_handler, &sswt_cb); sys_untimeout(sswt_handler, &sswt_cb);
return 1; return 1;
} }
} }
void void
sys_msleep(u32_t ms) sys_msleep(u32_t ms)
{ {
sys_sem_t delaysem = sys_sem_new(0); sys_sem_t delaysem = sys_sem_new(0);
sys_sem_wait_timeout(delaysem, ms); sys_sem_wait_timeout(delaysem, ms);
sys_sem_free(delaysem); sys_sem_free(delaysem);
} }
#endif /* NO_SYS */ #endif /* NO_SYS */

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,112 +1,112 @@
/* /*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science. * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, * 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products * 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE. * OF SUCH DAMAGE.
* *
* This file is part of the lwIP TCP/IP stack. * This file is part of the lwIP TCP/IP stack.
* *
* Author: Adam Dunkels <adam@sics.se> * Author: Adam Dunkels <adam@sics.se>
* *
*/ */
#ifndef __LWIP_ICMP_H__ #ifndef __LWIP_ICMP_H__
#define __LWIP_ICMP_H__ #define __LWIP_ICMP_H__
#include "lwip/arch.h" #include "lwip/arch.h"
#include "lwip/opt.h" #include "lwip/opt.h"
#include "lwip/pbuf.h" #include "lwip/pbuf.h"
#include "lwip/ip_addr.h" #include "lwip/ip_addr.h"
#include "lwip/netif.h" #include "lwip/netif.h"
#define ICMP_ER 0 /* echo reply */ #define ICMP_ER 0 /* echo reply */
#define ICMP_DUR 3 /* destination unreachable */ #define ICMP_DUR 3 /* destination unreachable */
#define ICMP_SQ 4 /* source quench */ #define ICMP_SQ 4 /* source quench */
#define ICMP_RD 5 /* redirect */ #define ICMP_RD 5 /* redirect */
#define ICMP_ECHO 8 /* echo */ #define ICMP_ECHO 8 /* echo */
#define ICMP_TE 11 /* time exceeded */ #define ICMP_TE 11 /* time exceeded */
#define ICMP_PP 12 /* parameter problem */ #define ICMP_PP 12 /* parameter problem */
#define ICMP_TS 13 /* timestamp */ #define ICMP_TS 13 /* timestamp */
#define ICMP_TSR 14 /* timestamp reply */ #define ICMP_TSR 14 /* timestamp reply */
#define ICMP_IRQ 15 /* information request */ #define ICMP_IRQ 15 /* information request */
#define ICMP_IR 16 /* information reply */ #define ICMP_IR 16 /* information reply */
enum icmp_dur_type { enum icmp_dur_type {
ICMP_DUR_NET = 0, /* net unreachable */ ICMP_DUR_NET = 0, /* net unreachable */
ICMP_DUR_HOST = 1, /* host unreachable */ ICMP_DUR_HOST = 1, /* host unreachable */
ICMP_DUR_PROTO = 2, /* protocol unreachable */ ICMP_DUR_PROTO = 2, /* protocol unreachable */
ICMP_DUR_PORT = 3, /* port unreachable */ ICMP_DUR_PORT = 3, /* port unreachable */
ICMP_DUR_FRAG = 4, /* fragmentation needed and DF set */ ICMP_DUR_FRAG = 4, /* fragmentation needed and DF set */
ICMP_DUR_SR = 5 /* source route failed */ ICMP_DUR_SR = 5 /* source route failed */
}; };
enum icmp_te_type { enum icmp_te_type {
ICMP_TE_TTL = 0, /* time to live exceeded in transit */ ICMP_TE_TTL = 0, /* time to live exceeded in transit */
ICMP_TE_FRAG = 1 /* fragment reassembly time exceeded */ ICMP_TE_FRAG = 1 /* fragment reassembly time exceeded */
}; };
void icmp_input(struct pbuf *p, struct netif *inp); void icmp_input(struct pbuf *p, struct netif *inp);
void icmp_dest_unreach(struct pbuf *p, enum icmp_dur_type t); void icmp_dest_unreach(struct pbuf *p, enum icmp_dur_type t);
void icmp_time_exceeded(struct pbuf *p, enum icmp_te_type t); void icmp_time_exceeded(struct pbuf *p, enum icmp_te_type t);
#ifdef PACK_STRUCT_USE_INCLUDES #ifdef PACK_STRUCT_USE_INCLUDES
# include "arch/bpstruct.h" # include "arch/bpstruct.h"
#endif #endif
PACK_STRUCT_BEGIN PACK_STRUCT_BEGIN
struct icmp_echo_hdr { struct icmp_echo_hdr {
PACK_STRUCT_FIELD(u16_t _type_code); PACK_STRUCT_FIELD(u16_t _type_code);
PACK_STRUCT_FIELD(u16_t chksum); PACK_STRUCT_FIELD(u16_t chksum);
PACK_STRUCT_FIELD(u16_t id); PACK_STRUCT_FIELD(u16_t id);
PACK_STRUCT_FIELD(u16_t seqno); PACK_STRUCT_FIELD(u16_t seqno);
} PACK_STRUCT_STRUCT; } PACK_STRUCT_STRUCT;
PACK_STRUCT_END PACK_STRUCT_END
PACK_STRUCT_BEGIN PACK_STRUCT_BEGIN
struct icmp_dur_hdr { struct icmp_dur_hdr {
PACK_STRUCT_FIELD(u16_t _type_code); PACK_STRUCT_FIELD(u16_t _type_code);
PACK_STRUCT_FIELD(u16_t chksum); PACK_STRUCT_FIELD(u16_t chksum);
PACK_STRUCT_FIELD(u32_t unused); PACK_STRUCT_FIELD(u32_t unused);
} PACK_STRUCT_STRUCT; } PACK_STRUCT_STRUCT;
PACK_STRUCT_END PACK_STRUCT_END
PACK_STRUCT_BEGIN PACK_STRUCT_BEGIN
struct icmp_te_hdr { struct icmp_te_hdr {
PACK_STRUCT_FIELD(u16_t _type_code); PACK_STRUCT_FIELD(u16_t _type_code);
PACK_STRUCT_FIELD(u16_t chksum); PACK_STRUCT_FIELD(u16_t chksum);
PACK_STRUCT_FIELD(u32_t unused); PACK_STRUCT_FIELD(u32_t unused);
} PACK_STRUCT_STRUCT; } PACK_STRUCT_STRUCT;
PACK_STRUCT_END PACK_STRUCT_END
#ifdef PACK_STRUCT_USE_INCLUDES #ifdef PACK_STRUCT_USE_INCLUDES
# include "arch/epstruct.h" # include "arch/epstruct.h"
#endif #endif
#define ICMPH_TYPE(hdr) (ntohs((hdr)->_type_code) >> 8) #define ICMPH_TYPE(hdr) (ntohs((hdr)->_type_code) >> 8)
#define ICMPH_CODE(hdr) (ntohs((hdr)->_type_code) & 0xff) #define ICMPH_CODE(hdr) (ntohs((hdr)->_type_code) & 0xff)
#define ICMPH_TYPE_SET(hdr, type) ((hdr)->_type_code = htons(ICMPH_CODE(hdr) | ((type) << 8))) #define ICMPH_TYPE_SET(hdr, type) ((hdr)->_type_code = htons(ICMPH_CODE(hdr) | ((type) << 8)))
#define ICMPH_CODE_SET(hdr, code) ((hdr)->_type_code = htons((code) | (ICMPH_TYPE(hdr) << 8))) #define ICMPH_CODE_SET(hdr, code) ((hdr)->_type_code = htons((code) | (ICMPH_TYPE(hdr) << 8)))
#endif /* __LWIP_ICMP_H__ */ #endif /* __LWIP_ICMP_H__ */

View file

@ -1,99 +1,99 @@
/* /*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science. * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, * 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products * 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE. * OF SUCH DAMAGE.
* *
* This file is part of the lwIP TCP/IP stack. * This file is part of the lwIP TCP/IP stack.
* *
* Author: Adam Dunkels <adam@sics.se> * Author: Adam Dunkels <adam@sics.se>
* *
*/ */
#ifndef __LWIP_INET_H__ #ifndef __LWIP_INET_H__
#define __LWIP_INET_H__ #define __LWIP_INET_H__
#include "lwip/arch.h" #include "lwip/arch.h"
#include "lwip/opt.h" #include "lwip/opt.h"
#include "lwip/pbuf.h" #include "lwip/pbuf.h"
#include "lwip/ip_addr.h" #include "lwip/ip_addr.h"
u16_t inet_chksum(void *dataptr, u16_t len); u16_t inet_chksum(void *dataptr, u16_t len);
#if 0 /* optimized routine */ #if 0 /* optimized routine */
u16_t inet_chksum4(u8_t *dataptr, u16_t len); u16_t inet_chksum4(u8_t *dataptr, u16_t len);
#endif #endif
u16_t inet_chksum_pbuf(struct pbuf *p); u16_t inet_chksum_pbuf(struct pbuf *p);
u16_t inet_chksum_pseudo(struct pbuf *p, u16_t inet_chksum_pseudo(struct pbuf *p,
struct ip_addr *src, struct ip_addr *dest, struct ip_addr *src, struct ip_addr *dest,
u8_t proto, u16_t proto_len); u8_t proto, u16_t proto_len);
u32_t inet_addr(const char *cp); u32_t inet_addr(const char *cp);
int inet_aton(const char *cp, struct in_addr *addr); int inet_aton(const char *cp, struct in_addr *addr);
char *inet_ntoa(struct in_addr addr); /* returns ptr to static buffer; not reentrant! */ char *inet_ntoa(struct in_addr addr); /* returns ptr to static buffer; not reentrant! */
#ifdef htons #ifdef htons
#undef htons #undef htons
#endif /* htons */ #endif /* htons */
#ifdef htonl #ifdef htonl
#undef htonl #undef htonl
#endif /* htonl */ #endif /* htonl */
#ifdef ntohs #ifdef ntohs
#undef ntohs #undef ntohs
#endif /* ntohs */ #endif /* ntohs */
#ifdef ntohl #ifdef ntohl
#undef ntohl #undef ntohl
#endif /* ntohl */ #endif /* ntohl */
#ifndef LWIP_PLATFORM_BYTESWAP #ifndef LWIP_PLATFORM_BYTESWAP
#define LWIP_PLATFORM_BYTESWAP 0 #define LWIP_PLATFORM_BYTESWAP 0
#endif #endif
#if BYTE_ORDER == BIG_ENDIAN #if BYTE_ORDER == BIG_ENDIAN
#define htons(x) (x) #define htons(x) (x)
#define ntohs(x) (x) #define ntohs(x) (x)
#define htonl(x) (x) #define htonl(x) (x)
#define ntohl(x) (x) #define ntohl(x) (x)
#else /* BYTE_ORDER != BIG_ENDIAN */ #else /* BYTE_ORDER != BIG_ENDIAN */
#ifdef LWIP_PREFIX_BYTEORDER_FUNCS #ifdef LWIP_PREFIX_BYTEORDER_FUNCS
/* workaround for naming collisions on some platforms */ /* workaround for naming collisions on some platforms */
#define htons lwip_htons #define htons lwip_htons
#define ntohs lwip_ntohs #define ntohs lwip_ntohs
#define htonl lwip_htonl #define htonl lwip_htonl
#define ntohl lwip_ntohl #define ntohl lwip_ntohl
#endif #endif
#if LWIP_PLATFORM_BYTESWAP #if LWIP_PLATFORM_BYTESWAP
#define htons(x) LWIP_PLATFORM_HTONS(x) #define htons(x) LWIP_PLATFORM_HTONS(x)
#define ntohs(x) LWIP_PLATFORM_HTONS(x) #define ntohs(x) LWIP_PLATFORM_HTONS(x)
#define htonl(x) LWIP_PLATFORM_HTONL(x) #define htonl(x) LWIP_PLATFORM_HTONL(x)
#define ntohl(x) LWIP_PLATFORM_HTONL(x) #define ntohl(x) LWIP_PLATFORM_HTONL(x)
#else #else
u16_t htons(u16_t x); u16_t htons(u16_t x);
u16_t ntohs(u16_t x); u16_t ntohs(u16_t x);
u32_t htonl(u32_t x); u32_t htonl(u32_t x);
u32_t ntohl(u32_t x); u32_t ntohl(u32_t x);
#endif #endif
#endif #endif
#endif /* __LWIP_INET_H__ */ #endif /* __LWIP_INET_H__ */

View file

@ -1,154 +1,154 @@
/* /*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science. * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, * 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products * 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE. * OF SUCH DAMAGE.
* *
* This file is part of the lwIP TCP/IP stack. * This file is part of the lwIP TCP/IP stack.
* *
* Author: Adam Dunkels <adam@sics.se> * Author: Adam Dunkels <adam@sics.se>
* *
*/ */
#ifndef __LWIP_IP_H__ #ifndef __LWIP_IP_H__
#define __LWIP_IP_H__ #define __LWIP_IP_H__
#include "lwip/arch.h" #include "lwip/arch.h"
#include "lwip/def.h" #include "lwip/def.h"
#include "lwip/pbuf.h" #include "lwip/pbuf.h"
#include "lwip/ip_addr.h" #include "lwip/ip_addr.h"
#include "lwip/err.h" #include "lwip/err.h"
void ip_init(void); void ip_init(void);
struct netif *ip_route(struct ip_addr *dest); struct netif *ip_route(struct ip_addr *dest);
err_t ip_input(struct pbuf *p, struct netif *inp); err_t ip_input(struct pbuf *p, struct netif *inp);
err_t ip_output(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest, err_t ip_output(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
u8_t ttl, u8_t tos, u8_t proto); u8_t ttl, u8_t tos, u8_t proto);
err_t ip_output_if(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest, err_t ip_output_if(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
u8_t ttl, u8_t tos, u8_t proto, u8_t ttl, u8_t tos, u8_t proto,
struct netif *netif); struct netif *netif);
#define IP_HLEN 20 #define IP_HLEN 20
#define IP_PROTO_ICMP 1 #define IP_PROTO_ICMP 1
#define IP_PROTO_UDP 17 #define IP_PROTO_UDP 17
#define IP_PROTO_UDPLITE 136 #define IP_PROTO_UDPLITE 136
#define IP_PROTO_TCP 6 #define IP_PROTO_TCP 6
/* This is passed as the destination address to ip_output_if (not /* This is passed as the destination address to ip_output_if (not
to ip_output), meaning that an IP header already is constructed to ip_output), meaning that an IP header already is constructed
in the pbuf. This is used when TCP retransmits. */ in the pbuf. This is used when TCP retransmits. */
#ifdef IP_HDRINCL #ifdef IP_HDRINCL
#undef IP_HDRINCL #undef IP_HDRINCL
#endif /* IP_HDRINCL */ #endif /* IP_HDRINCL */
#define IP_HDRINCL NULL #define IP_HDRINCL NULL
/* This is the common part of all PCB types. It needs to be at the /* This is the common part of all PCB types. It needs to be at the
beginning of a PCB type definition. It is located here so that beginning of a PCB type definition. It is located here so that
changes to this common part are made in one location instead of changes to this common part are made in one location instead of
having to change all PCB structs. */ having to change all PCB structs. */
#define IP_PCB struct ip_addr local_ip; \ #define IP_PCB struct ip_addr local_ip; \
struct ip_addr remote_ip; \ struct ip_addr remote_ip; \
/* Socket options */ \ /* Socket options */ \
u16_t so_options; \ u16_t so_options; \
/* Type Of Service */ \ /* Type Of Service */ \
u8_t tos; \ u8_t tos; \
/* Time To Live */ \ /* Time To Live */ \
u8_t ttl u8_t ttl
/* /*
* Option flags per-socket. These are the same like SO_XXX. * Option flags per-socket. These are the same like SO_XXX.
*/ */
#define SOF_DEBUG (u16_t)0x0001U /* turn on debugging info recording */ #define SOF_DEBUG (u16_t)0x0001U /* turn on debugging info recording */
#define SOF_ACCEPTCONN (u16_t)0x0002U /* socket has had listen() */ #define SOF_ACCEPTCONN (u16_t)0x0002U /* socket has had listen() */
#define SOF_REUSEADDR (u16_t)0x0004U /* allow local address reuse */ #define SOF_REUSEADDR (u16_t)0x0004U /* allow local address reuse */
#define SOF_KEEPALIVE (u16_t)0x0008U /* keep connections alive */ #define SOF_KEEPALIVE (u16_t)0x0008U /* keep connections alive */
#define SOF_DONTROUTE (u16_t)0x0010U /* just use interface addresses */ #define SOF_DONTROUTE (u16_t)0x0010U /* just use interface addresses */
#define SOF_BROADCAST (u16_t)0x0020U /* permit sending of broadcast msgs */ #define SOF_BROADCAST (u16_t)0x0020U /* permit sending of broadcast msgs */
#define SOF_USELOOPBACK (u16_t)0x0040U /* bypass hardware when possible */ #define SOF_USELOOPBACK (u16_t)0x0040U /* bypass hardware when possible */
#define SOF_LINGER (u16_t)0x0080U /* linger on close if data present */ #define SOF_LINGER (u16_t)0x0080U /* linger on close if data present */
#define SOF_OOBINLINE (u16_t)0x0100U /* leave received OOB data in line */ #define SOF_OOBINLINE (u16_t)0x0100U /* leave received OOB data in line */
#define SOF_REUSEPORT (u16_t)0x0200U /* allow local address & port reuse */ #define SOF_REUSEPORT (u16_t)0x0200U /* allow local address & port reuse */
#ifdef PACK_STRUCT_USE_INCLUDES #ifdef PACK_STRUCT_USE_INCLUDES
# include "arch/bpstruct.h" # include "arch/bpstruct.h"
#endif #endif
PACK_STRUCT_BEGIN PACK_STRUCT_BEGIN
struct ip_hdr { struct ip_hdr {
/* version / header length / type of service */ /* version / header length / type of service */
PACK_STRUCT_FIELD(u16_t _v_hl_tos); PACK_STRUCT_FIELD(u16_t _v_hl_tos);
/* total length */ /* total length */
PACK_STRUCT_FIELD(u16_t _len); PACK_STRUCT_FIELD(u16_t _len);
/* identification */ /* identification */
PACK_STRUCT_FIELD(u16_t _id); PACK_STRUCT_FIELD(u16_t _id);
/* fragment offset field */ /* fragment offset field */
PACK_STRUCT_FIELD(u16_t _offset); PACK_STRUCT_FIELD(u16_t _offset);
#define IP_RF 0x8000 /* reserved fragment flag */ #define IP_RF 0x8000 /* reserved fragment flag */
#define IP_DF 0x4000 /* dont fragment flag */ #define IP_DF 0x4000 /* dont fragment flag */
#define IP_MF 0x2000 /* more fragments flag */ #define IP_MF 0x2000 /* more fragments flag */
#define IP_OFFMASK 0x1fff /* mask for fragmenting bits */ #define IP_OFFMASK 0x1fff /* mask for fragmenting bits */
/* time to live / protocol*/ /* time to live / protocol*/
PACK_STRUCT_FIELD(u16_t _ttl_proto); PACK_STRUCT_FIELD(u16_t _ttl_proto);
/* checksum */ /* checksum */
PACK_STRUCT_FIELD(u16_t _chksum); PACK_STRUCT_FIELD(u16_t _chksum);
/* source and destination IP addresses */ /* source and destination IP addresses */
PACK_STRUCT_FIELD(struct ip_addr src); PACK_STRUCT_FIELD(struct ip_addr src);
PACK_STRUCT_FIELD(struct ip_addr dest); PACK_STRUCT_FIELD(struct ip_addr dest);
} PACK_STRUCT_STRUCT; } PACK_STRUCT_STRUCT;
PACK_STRUCT_END PACK_STRUCT_END
#ifdef PACK_STRUCT_USE_INCLUDES #ifdef PACK_STRUCT_USE_INCLUDES
# include "arch/epstruct.h" # include "arch/epstruct.h"
#endif #endif
#define IPH_V(hdr) (ntohs((hdr)->_v_hl_tos) >> 12) #define IPH_V(hdr) (ntohs((hdr)->_v_hl_tos) >> 12)
#define IPH_HL(hdr) ((ntohs((hdr)->_v_hl_tos) >> 8) & 0x0f) #define IPH_HL(hdr) ((ntohs((hdr)->_v_hl_tos) >> 8) & 0x0f)
#define IPH_TOS(hdr) (ntohs((hdr)->_v_hl_tos) & 0xff) #define IPH_TOS(hdr) (ntohs((hdr)->_v_hl_tos) & 0xff)
#define IPH_LEN(hdr) ((hdr)->_len) #define IPH_LEN(hdr) ((hdr)->_len)
#define IPH_ID(hdr) ((hdr)->_id) #define IPH_ID(hdr) ((hdr)->_id)
#define IPH_OFFSET(hdr) ((hdr)->_offset) #define IPH_OFFSET(hdr) ((hdr)->_offset)
#define IPH_TTL(hdr) (ntohs((hdr)->_ttl_proto) >> 8) #define IPH_TTL(hdr) (ntohs((hdr)->_ttl_proto) >> 8)
#define IPH_PROTO(hdr) (ntohs((hdr)->_ttl_proto) & 0xff) #define IPH_PROTO(hdr) (ntohs((hdr)->_ttl_proto) & 0xff)
#define IPH_CHKSUM(hdr) ((hdr)->_chksum) #define IPH_CHKSUM(hdr) ((hdr)->_chksum)
#define IPH_VHLTOS_SET(hdr, v, hl, tos) (hdr)->_v_hl_tos = (htons(((v) << 12) | ((hl) << 8) | (tos))) #define IPH_VHLTOS_SET(hdr, v, hl, tos) (hdr)->_v_hl_tos = (htons(((v) << 12) | ((hl) << 8) | (tos)))
#define IPH_LEN_SET(hdr, len) (hdr)->_len = (len) #define IPH_LEN_SET(hdr, len) (hdr)->_len = (len)
#define IPH_ID_SET(hdr, id) (hdr)->_id = (id) #define IPH_ID_SET(hdr, id) (hdr)->_id = (id)
#define IPH_OFFSET_SET(hdr, off) (hdr)->_offset = (off) #define IPH_OFFSET_SET(hdr, off) (hdr)->_offset = (off)
#define IPH_TTL_SET(hdr, ttl) (hdr)->_ttl_proto = (htons(IPH_PROTO(hdr) | ((u16_t)(ttl) << 8))) #define IPH_TTL_SET(hdr, ttl) (hdr)->_ttl_proto = (htons(IPH_PROTO(hdr) | ((u16_t)(ttl) << 8)))
#define IPH_PROTO_SET(hdr, proto) (hdr)->_ttl_proto = (htons((proto) | (IPH_TTL(hdr) << 8))) #define IPH_PROTO_SET(hdr, proto) (hdr)->_ttl_proto = (htons((proto) | (IPH_TTL(hdr) << 8)))
#define IPH_CHKSUM_SET(hdr, chksum) (hdr)->_chksum = (chksum) #define IPH_CHKSUM_SET(hdr, chksum) (hdr)->_chksum = (chksum)
#if IP_DEBUG #if IP_DEBUG
void ip_debug_print(struct pbuf *p); void ip_debug_print(struct pbuf *p);
#else #else
#define ip_debug_print(p) #define ip_debug_print(p)
#endif /* IP_DEBUG */ #endif /* IP_DEBUG */
#endif /* __LWIP_IP_H__ */ #endif /* __LWIP_IP_H__ */

View file

@ -1,160 +1,160 @@
/* /*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science. * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, * 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products * 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE. * OF SUCH DAMAGE.
* *
* This file is part of the lwIP TCP/IP stack. * This file is part of the lwIP TCP/IP stack.
* *
* Author: Adam Dunkels <adam@sics.se> * Author: Adam Dunkels <adam@sics.se>
* *
*/ */
#ifndef __LWIP_IP_ADDR_H__ #ifndef __LWIP_IP_ADDR_H__
#define __LWIP_IP_ADDR_H__ #define __LWIP_IP_ADDR_H__
#include "lwip/arch.h" #include "lwip/arch.h"
#ifdef PACK_STRUCT_USE_INCLUDES #ifdef PACK_STRUCT_USE_INCLUDES
# include "arch/bpstruct.h" # include "arch/bpstruct.h"
#endif #endif
PACK_STRUCT_BEGIN PACK_STRUCT_BEGIN
struct ip_addr { struct ip_addr {
PACK_STRUCT_FIELD(u32_t addr); PACK_STRUCT_FIELD(u32_t addr);
} PACK_STRUCT_STRUCT; } PACK_STRUCT_STRUCT;
PACK_STRUCT_END PACK_STRUCT_END
#ifdef PACK_STRUCT_USE_INCLUDES #ifdef PACK_STRUCT_USE_INCLUDES
# include "arch/epstruct.h" # include "arch/epstruct.h"
#endif #endif
/* /*
* struct ipaddr2 is used in the definition of the ARP packet format in * struct ipaddr2 is used in the definition of the ARP packet format in
* order to support compilers that don't have structure packing. * order to support compilers that don't have structure packing.
*/ */
#ifdef PACK_STRUCT_USE_INCLUDES #ifdef PACK_STRUCT_USE_INCLUDES
# include "arch/bpstruct.h" # include "arch/bpstruct.h"
#endif #endif
PACK_STRUCT_BEGIN PACK_STRUCT_BEGIN
struct ip_addr2 { struct ip_addr2 {
PACK_STRUCT_FIELD(u16_t addrw[2]); PACK_STRUCT_FIELD(u16_t addrw[2]);
} PACK_STRUCT_STRUCT; } PACK_STRUCT_STRUCT;
PACK_STRUCT_END PACK_STRUCT_END
#ifdef PACK_STRUCT_USE_INCLUDES #ifdef PACK_STRUCT_USE_INCLUDES
# include "arch/epstruct.h" # include "arch/epstruct.h"
#endif #endif
/* For compatibility with BSD code */ /* For compatibility with BSD code */
struct in_addr { struct in_addr {
u32_t s_addr; u32_t s_addr;
}; };
struct netif; struct netif;
extern const struct ip_addr ip_addr_any; extern const struct ip_addr ip_addr_any;
extern const struct ip_addr ip_addr_broadcast; extern const struct ip_addr ip_addr_broadcast;
/** IP_ADDR_ can be used as a fixed IP address /** IP_ADDR_ can be used as a fixed IP address
* for the wildcard and the broadcast address * for the wildcard and the broadcast address
*/ */
#define IP_ADDR_ANY ((struct ip_addr *)&ip_addr_any) #define IP_ADDR_ANY ((struct ip_addr *)&ip_addr_any)
#define IP_ADDR_BROADCAST ((struct ip_addr *)&ip_addr_broadcast) #define IP_ADDR_BROADCAST ((struct ip_addr *)&ip_addr_broadcast)
#define INADDR_NONE ((u32_t)0xffffffff) /* 255.255.255.255 */ #define INADDR_NONE ((u32_t)0xffffffff) /* 255.255.255.255 */
#define INADDR_LOOPBACK ((u32_t)0x7f000001) /* 127.0.0.1 */ #define INADDR_LOOPBACK ((u32_t)0x7f000001) /* 127.0.0.1 */
/* Definitions of the bits in an Internet address integer. /* Definitions of the bits in an Internet address integer.
On subnets, host and network parts are found according to On subnets, host and network parts are found according to
the subnet mask, not these masks. */ the subnet mask, not these masks. */
#define IN_CLASSA(a) ((((u32_t)(a)) & 0x80000000) == 0) #define IN_CLASSA(a) ((((u32_t)(a)) & 0x80000000) == 0)
#define IN_CLASSA_NET 0xff000000 #define IN_CLASSA_NET 0xff000000
#define IN_CLASSA_NSHIFT 24 #define IN_CLASSA_NSHIFT 24
#define IN_CLASSA_HOST (0xffffffff & ~IN_CLASSA_NET) #define IN_CLASSA_HOST (0xffffffff & ~IN_CLASSA_NET)
#define IN_CLASSA_MAX 128 #define IN_CLASSA_MAX 128
#define IN_CLASSB(a) ((((u32_t)(a)) & 0xc0000000) == 0x80000000) #define IN_CLASSB(a) ((((u32_t)(a)) & 0xc0000000) == 0x80000000)
#define IN_CLASSB_NET 0xffff0000 #define IN_CLASSB_NET 0xffff0000
#define IN_CLASSB_NSHIFT 16 #define IN_CLASSB_NSHIFT 16
#define IN_CLASSB_HOST (0xffffffff & ~IN_CLASSB_NET) #define IN_CLASSB_HOST (0xffffffff & ~IN_CLASSB_NET)
#define IN_CLASSB_MAX 65536 #define IN_CLASSB_MAX 65536
#define IN_CLASSC(a) ((((u32_t)(a)) & 0xe0000000) == 0xc0000000) #define IN_CLASSC(a) ((((u32_t)(a)) & 0xe0000000) == 0xc0000000)
#define IN_CLASSC_NET 0xffffff00 #define IN_CLASSC_NET 0xffffff00
#define IN_CLASSC_NSHIFT 8 #define IN_CLASSC_NSHIFT 8
#define IN_CLASSC_HOST (0xffffffff & ~IN_CLASSC_NET) #define IN_CLASSC_HOST (0xffffffff & ~IN_CLASSC_NET)
#define IN_CLASSD(a) (((u32_t)(a) & 0xf0000000) == 0xe0000000) #define IN_CLASSD(a) (((u32_t)(a) & 0xf0000000) == 0xe0000000)
#define IN_CLASSD_NET 0xf0000000 /* These ones aren't really */ #define IN_CLASSD_NET 0xf0000000 /* These ones aren't really */
#define IN_CLASSD_NSHIFT 28 /* net and host fields, but */ #define IN_CLASSD_NSHIFT 28 /* net and host fields, but */
#define IN_CLASSD_HOST 0x0fffffff /* routing needn't know. */ #define IN_CLASSD_HOST 0x0fffffff /* routing needn't know. */
#define IN_MULTICAST(a) IN_CLASSD(a) #define IN_MULTICAST(a) IN_CLASSD(a)
#define IN_EXPERIMENTAL(a) (((u32_t)(a) & 0xf0000000) == 0xf0000000) #define IN_EXPERIMENTAL(a) (((u32_t)(a) & 0xf0000000) == 0xf0000000)
#define IN_BADCLASS(a) (((u32_t)(a) & 0xf0000000) == 0xf0000000) #define IN_BADCLASS(a) (((u32_t)(a) & 0xf0000000) == 0xf0000000)
#define IN_LOOPBACKNET 127 /* official! */ #define IN_LOOPBACKNET 127 /* official! */
#define IP4_ADDR(ipaddr, a,b,c,d) \ #define IP4_ADDR(ipaddr, a,b,c,d) \
(ipaddr)->addr = htonl(((u32_t)((a) & 0xff) << 24) | \ (ipaddr)->addr = htonl(((u32_t)((a) & 0xff) << 24) | \
((u32_t)((b) & 0xff) << 16) | \ ((u32_t)((b) & 0xff) << 16) | \
((u32_t)((c) & 0xff) << 8) | \ ((u32_t)((c) & 0xff) << 8) | \
(u32_t)((d) & 0xff)) (u32_t)((d) & 0xff))
#define ip_addr_set(dest, src) (dest)->addr = \ #define ip_addr_set(dest, src) (dest)->addr = \
((src) == NULL? 0:\ ((src) == NULL? 0:\
(src)->addr) (src)->addr)
/** /**
* Determine if two address are on the same network. * Determine if two address are on the same network.
* *
* @arg addr1 IP address 1 * @arg addr1 IP address 1
* @arg addr2 IP address 2 * @arg addr2 IP address 2
* @arg mask network identifier mask * @arg mask network identifier mask
* @return !0 if the network identifiers of both address match * @return !0 if the network identifiers of both address match
*/ */
#define ip_addr_netcmp(addr1, addr2, mask) (((addr1)->addr & \ #define ip_addr_netcmp(addr1, addr2, mask) (((addr1)->addr & \
(mask)->addr) == \ (mask)->addr) == \
((addr2)->addr & \ ((addr2)->addr & \
(mask)->addr)) (mask)->addr))
#define ip_addr_cmp(addr1, addr2) ((addr1)->addr == (addr2)->addr) #define ip_addr_cmp(addr1, addr2) ((addr1)->addr == (addr2)->addr)
#define ip_addr_isany(addr1) ((addr1) == NULL || (addr1)->addr == 0) #define ip_addr_isany(addr1) ((addr1) == NULL || (addr1)->addr == 0)
u8_t ip_addr_isbroadcast(struct ip_addr *, struct netif *); u8_t ip_addr_isbroadcast(struct ip_addr *, struct netif *);
#define ip_addr_ismulticast(addr1) (((addr1)->addr & ntohl(0xf0000000)) == ntohl(0xe0000000)) #define ip_addr_ismulticast(addr1) (((addr1)->addr & ntohl(0xf0000000)) == ntohl(0xe0000000))
#define ip_addr_debug_print(debug, ipaddr) \ #define ip_addr_debug_print(debug, ipaddr) \
LWIP_DEBUGF(debug, ("%"U16_F".%"U16_F".%"U16_F".%"U16_F, \ LWIP_DEBUGF(debug, ("%"U16_F".%"U16_F".%"U16_F".%"U16_F, \
ipaddr ? (u16_t)(ntohl((ipaddr)->addr) >> 24) & 0xff : 0, \ ipaddr ? (u16_t)(ntohl((ipaddr)->addr) >> 24) & 0xff : 0, \
ipaddr ? (u16_t)(ntohl((ipaddr)->addr) >> 16) & 0xff : 0, \ ipaddr ? (u16_t)(ntohl((ipaddr)->addr) >> 16) & 0xff : 0, \
ipaddr ? (u16_t)(ntohl((ipaddr)->addr) >> 8) & 0xff : 0, \ ipaddr ? (u16_t)(ntohl((ipaddr)->addr) >> 8) & 0xff : 0, \
ipaddr ? (u16_t)ntohl((ipaddr)->addr) & 0xff : 0)) ipaddr ? (u16_t)ntohl((ipaddr)->addr) & 0xff : 0))
/* These are cast to u16_t, with the intent that they are often arguments /* These are cast to u16_t, with the intent that they are often arguments
* to printf using the U16_F format from cc.h. */ * to printf using the U16_F format from cc.h. */
#define ip4_addr1(ipaddr) ((u16_t)(ntohl((ipaddr)->addr) >> 24) & 0xff) #define ip4_addr1(ipaddr) ((u16_t)(ntohl((ipaddr)->addr) >> 24) & 0xff)
#define ip4_addr2(ipaddr) ((u16_t)(ntohl((ipaddr)->addr) >> 16) & 0xff) #define ip4_addr2(ipaddr) ((u16_t)(ntohl((ipaddr)->addr) >> 16) & 0xff)
#define ip4_addr3(ipaddr) ((u16_t)(ntohl((ipaddr)->addr) >> 8) & 0xff) #define ip4_addr3(ipaddr) ((u16_t)(ntohl((ipaddr)->addr) >> 8) & 0xff)
#define ip4_addr4(ipaddr) ((u16_t)(ntohl((ipaddr)->addr)) & 0xff) #define ip4_addr4(ipaddr) ((u16_t)(ntohl((ipaddr)->addr)) & 0xff)
#endif /* __LWIP_IP_ADDR_H__ */ #endif /* __LWIP_IP_ADDR_H__ */

View file

@ -1,49 +1,49 @@
/* /*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science. * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, * 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products * 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE. * OF SUCH DAMAGE.
* *
* This file is part of the lwIP TCP/IP stack. * This file is part of the lwIP TCP/IP stack.
* *
* Author: Jani Monoses <jani@iv.ro> * Author: Jani Monoses <jani@iv.ro>
* *
*/ */
#ifndef __LWIP_IP_FRAG_H__ #ifndef __LWIP_IP_FRAG_H__
#define __LWIP_IP_FRAG_H__ #define __LWIP_IP_FRAG_H__
#include "lwip/opt.h" #include "lwip/opt.h"
#include "lwip/err.h" #include "lwip/err.h"
#include "lwip/pbuf.h" #include "lwip/pbuf.h"
#include "lwip/netif.h" #include "lwip/netif.h"
#include "lwip/ip_addr.h" #include "lwip/ip_addr.h"
void ip_frag_init(void); void ip_frag_init(void);
void ip_reass_tmr(void); void ip_reass_tmr(void);
struct pbuf * ip_reass(struct pbuf *p); struct pbuf * ip_reass(struct pbuf *p);
err_t ip_frag(struct pbuf *p, struct netif *netif, struct ip_addr *dest); err_t ip_frag(struct pbuf *p, struct netif *netif, struct ip_addr *dest);
#endif /* __LWIP_IP_FRAG_H__ */ #endif /* __LWIP_IP_FRAG_H__ */

View file

@ -1,159 +1,159 @@
/* /*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science. * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, * 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products * 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE. * OF SUCH DAMAGE.
* *
* This file is part of the lwIP TCP/IP stack. * This file is part of the lwIP TCP/IP stack.
* *
* Author: Adam Dunkels <adam@sics.se> * Author: Adam Dunkels <adam@sics.se>
* *
*/ */
#ifndef __LWIP_API_H__ #ifndef __LWIP_API_H__
#define __LWIP_API_H__ #define __LWIP_API_H__
#include "lwip/opt.h" #include "lwip/opt.h"
#include "lwip/pbuf.h" #include "lwip/pbuf.h"
#include "lwip/sys.h" #include "lwip/sys.h"
#include "lwip/ip.h" #include "lwip/ip.h"
#include "lwip/raw.h" #include "lwip/raw.h"
#include "lwip/udp.h" #include "lwip/udp.h"
#include "lwip/tcp.h" #include "lwip/tcp.h"
#include "lwip/err.h" #include "lwip/err.h"
#define NETCONN_NOCOPY 0x00 #define NETCONN_NOCOPY 0x00
#define NETCONN_COPY 0x01 #define NETCONN_COPY 0x01
enum netconn_type { enum netconn_type {
NETCONN_TCP, NETCONN_TCP,
NETCONN_UDP, NETCONN_UDP,
NETCONN_UDPLITE, NETCONN_UDPLITE,
NETCONN_UDPNOCHKSUM, NETCONN_UDPNOCHKSUM,
NETCONN_RAW NETCONN_RAW
}; };
enum netconn_state { enum netconn_state {
NETCONN_NONE, NETCONN_NONE,
NETCONN_WRITE, NETCONN_WRITE,
NETCONN_ACCEPT, NETCONN_ACCEPT,
NETCONN_RECV, NETCONN_RECV,
NETCONN_CONNECT, NETCONN_CONNECT,
NETCONN_CLOSE NETCONN_CLOSE
}; };
enum netconn_evt { enum netconn_evt {
NETCONN_EVT_RCVPLUS, NETCONN_EVT_RCVPLUS,
NETCONN_EVT_RCVMINUS, NETCONN_EVT_RCVMINUS,
NETCONN_EVT_SENDPLUS, NETCONN_EVT_SENDPLUS,
NETCONN_EVT_SENDMINUS NETCONN_EVT_SENDMINUS
}; };
struct netbuf { struct netbuf {
struct pbuf *p, *ptr; struct pbuf *p, *ptr;
struct ip_addr *fromaddr; struct ip_addr *fromaddr;
u16_t fromport; u16_t fromport;
err_t err; err_t err;
}; };
struct netconn { struct netconn {
enum netconn_type type; enum netconn_type type;
enum netconn_state state; enum netconn_state state;
union { union {
struct tcp_pcb *tcp; struct tcp_pcb *tcp;
struct udp_pcb *udp; struct udp_pcb *udp;
struct raw_pcb *raw; struct raw_pcb *raw;
} pcb; } pcb;
err_t err; err_t err;
sys_mbox_t mbox; sys_mbox_t mbox;
sys_mbox_t recvmbox; sys_mbox_t recvmbox;
sys_mbox_t acceptmbox; sys_mbox_t acceptmbox;
sys_sem_t sem; sys_sem_t sem;
int socket; int socket;
u16_t recv_avail; u16_t recv_avail;
void (* callback)(struct netconn *, enum netconn_evt, u16_t len); void (* callback)(struct netconn *, enum netconn_evt, u16_t len);
}; };
/* Network buffer functions: */ /* Network buffer functions: */
struct netbuf * netbuf_new (void); struct netbuf * netbuf_new (void);
void netbuf_delete (struct netbuf *buf); void netbuf_delete (struct netbuf *buf);
void * netbuf_alloc (struct netbuf *buf, u16_t size); void * netbuf_alloc (struct netbuf *buf, u16_t size);
void netbuf_free (struct netbuf *buf); void netbuf_free (struct netbuf *buf);
void netbuf_ref (struct netbuf *buf, void netbuf_ref (struct netbuf *buf,
void *dataptr, u16_t size); void *dataptr, u16_t size);
void netbuf_chain (struct netbuf *head, void netbuf_chain (struct netbuf *head,
struct netbuf *tail); struct netbuf *tail);
u16_t netbuf_len (struct netbuf *buf); u16_t netbuf_len (struct netbuf *buf);
err_t netbuf_data (struct netbuf *buf, err_t netbuf_data (struct netbuf *buf,
void **dataptr, u16_t *len); void **dataptr, u16_t *len);
s8_t netbuf_next (struct netbuf *buf); s8_t netbuf_next (struct netbuf *buf);
void netbuf_first (struct netbuf *buf); void netbuf_first (struct netbuf *buf);
void netbuf_copy (struct netbuf *buf, void netbuf_copy (struct netbuf *buf,
void *dataptr, u16_t len); void *dataptr, u16_t len);
void netbuf_copy_partial(struct netbuf *buf, void *dataptr, void netbuf_copy_partial(struct netbuf *buf, void *dataptr,
u16_t len, u16_t offset); u16_t len, u16_t offset);
struct ip_addr * netbuf_fromaddr (struct netbuf *buf); struct ip_addr * netbuf_fromaddr (struct netbuf *buf);
u16_t netbuf_fromport (struct netbuf *buf); u16_t netbuf_fromport (struct netbuf *buf);
/* Network connection functions: */ /* Network connection functions: */
struct netconn * netconn_new (enum netconn_type type); struct netconn * netconn_new (enum netconn_type type);
struct struct
netconn *netconn_new_with_callback(enum netconn_type t, netconn *netconn_new_with_callback(enum netconn_type t,
void (*callback)(struct netconn *, enum netconn_evt, u16_t len)); void (*callback)(struct netconn *, enum netconn_evt, u16_t len));
struct struct
netconn *netconn_new_with_proto_and_callback(enum netconn_type t, u16_t proto, netconn *netconn_new_with_proto_and_callback(enum netconn_type t, u16_t proto,
void (*callback)(struct netconn *, enum netconn_evt, u16_t len)); void (*callback)(struct netconn *, enum netconn_evt, u16_t len));
err_t netconn_delete (struct netconn *conn); err_t netconn_delete (struct netconn *conn);
enum netconn_type netconn_type (struct netconn *conn); enum netconn_type netconn_type (struct netconn *conn);
err_t netconn_peer (struct netconn *conn, err_t netconn_peer (struct netconn *conn,
struct ip_addr *addr, struct ip_addr *addr,
u16_t *port); u16_t *port);
err_t netconn_addr (struct netconn *conn, err_t netconn_addr (struct netconn *conn,
struct ip_addr **addr, struct ip_addr **addr,
u16_t *port); u16_t *port);
err_t netconn_bind (struct netconn *conn, err_t netconn_bind (struct netconn *conn,
struct ip_addr *addr, struct ip_addr *addr,
u16_t port); u16_t port);
err_t netconn_connect (struct netconn *conn, err_t netconn_connect (struct netconn *conn,
struct ip_addr *addr, struct ip_addr *addr,
u16_t port); u16_t port);
err_t netconn_disconnect (struct netconn *conn); err_t netconn_disconnect (struct netconn *conn);
err_t netconn_listen (struct netconn *conn); err_t netconn_listen (struct netconn *conn);
struct netconn * netconn_accept (struct netconn *conn); struct netconn * netconn_accept (struct netconn *conn);
struct netbuf * netconn_recv (struct netconn *conn); struct netbuf * netconn_recv (struct netconn *conn);
err_t netconn_send (struct netconn *conn, err_t netconn_send (struct netconn *conn,
struct netbuf *buf); struct netbuf *buf);
err_t netconn_write (struct netconn *conn, err_t netconn_write (struct netconn *conn,
void *dataptr, u16_t size, void *dataptr, u16_t size,
u8_t copy); u8_t copy);
err_t netconn_close (struct netconn *conn); err_t netconn_close (struct netconn *conn);
err_t netconn_err (struct netconn *conn); err_t netconn_err (struct netconn *conn);
#endif /* __LWIP_API_H__ */ #endif /* __LWIP_API_H__ */

View file

@ -1,94 +1,94 @@
/* /*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science. * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, * 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products * 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE. * OF SUCH DAMAGE.
* *
* This file is part of the lwIP TCP/IP stack. * This file is part of the lwIP TCP/IP stack.
* *
* Author: Adam Dunkels <adam@sics.se> * Author: Adam Dunkels <adam@sics.se>
* *
*/ */
#ifndef __LWIP_API_MSG_H__ #ifndef __LWIP_API_MSG_H__
#define __LWIP_API_MSG_H__ #define __LWIP_API_MSG_H__
#include "lwip/opt.h" #include "lwip/opt.h"
#include "lwip/pbuf.h" #include "lwip/pbuf.h"
#include "lwip/sys.h" #include "lwip/sys.h"
#include "lwip/ip.h" #include "lwip/ip.h"
#include "lwip/udp.h" #include "lwip/udp.h"
#include "lwip/tcp.h" #include "lwip/tcp.h"
#include "lwip/api.h" #include "lwip/api.h"
enum api_msg_type { enum api_msg_type {
API_MSG_NEWCONN, API_MSG_NEWCONN,
API_MSG_DELCONN, API_MSG_DELCONN,
API_MSG_BIND, API_MSG_BIND,
API_MSG_CONNECT, API_MSG_CONNECT,
API_MSG_DISCONNECT, API_MSG_DISCONNECT,
API_MSG_LISTEN, API_MSG_LISTEN,
API_MSG_ACCEPT, API_MSG_ACCEPT,
API_MSG_SEND, API_MSG_SEND,
API_MSG_RECV, API_MSG_RECV,
API_MSG_WRITE, API_MSG_WRITE,
API_MSG_CLOSE, API_MSG_CLOSE,
API_MSG_MAX API_MSG_MAX
}; };
struct api_msg_msg { struct api_msg_msg {
struct netconn *conn; struct netconn *conn;
enum netconn_type conntype; enum netconn_type conntype;
union { union {
struct pbuf *p; struct pbuf *p;
struct { struct {
struct ip_addr *ipaddr; struct ip_addr *ipaddr;
u16_t port; u16_t port;
} bc; } bc;
struct { struct {
void *dataptr; void *dataptr;
u16_t len; u16_t len;
u8_t copy; u8_t copy;
} w; } w;
sys_mbox_t mbox; sys_mbox_t mbox;
u16_t len; u16_t len;
} msg; } msg;
}; };
struct api_msg { struct api_msg {
enum api_msg_type type; enum api_msg_type type;
struct api_msg_msg msg; struct api_msg_msg msg;
}; };
void api_msg_input(struct api_msg *msg); void api_msg_input(struct api_msg *msg);
void api_msg_post(struct api_msg *msg); void api_msg_post(struct api_msg *msg);
#endif /* __LWIP_API_MSG_H__ */ #endif /* __LWIP_API_MSG_H__ */

View file

@ -1,218 +1,218 @@
/* /*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science. * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, * 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products * 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE. * OF SUCH DAMAGE.
* *
* This file is part of the lwIP TCP/IP stack. * This file is part of the lwIP TCP/IP stack.
* *
* Author: Adam Dunkels <adam@sics.se> * Author: Adam Dunkels <adam@sics.se>
* *
*/ */
#ifndef __LWIP_ARCH_H__ #ifndef __LWIP_ARCH_H__
#define __LWIP_ARCH_H__ #define __LWIP_ARCH_H__
#ifndef LITTLE_ENDIAN #ifndef LITTLE_ENDIAN
#define LITTLE_ENDIAN 1234 #define LITTLE_ENDIAN 1234
#endif #endif
#ifndef BIG_ENDIAN #ifndef BIG_ENDIAN
#define BIG_ENDIAN 4321 #define BIG_ENDIAN 4321
#endif #endif
#include "arch/cc.h" #include "arch/cc.h"
#ifndef PACK_STRUCT_BEGIN #ifndef PACK_STRUCT_BEGIN
#define PACK_STRUCT_BEGIN #define PACK_STRUCT_BEGIN
#endif /* PACK_STRUCT_BEGIN */ #endif /* PACK_STRUCT_BEGIN */
#ifndef PACK_STRUCT_END #ifndef PACK_STRUCT_END
#define PACK_STRUCT_END #define PACK_STRUCT_END
#endif /* PACK_STRUCT_END */ #endif /* PACK_STRUCT_END */
#ifndef PACK_STRUCT_FIELD #ifndef PACK_STRUCT_FIELD
#define PACK_STRUCT_FIELD(x) x #define PACK_STRUCT_FIELD(x) x
#endif /* PACK_STRUCT_FIELD */ #endif /* PACK_STRUCT_FIELD */
#ifndef PACK_STRUCT_STRUCT #ifndef PACK_STRUCT_STRUCT
#define PACK_STRUCT_STRUCT #define PACK_STRUCT_STRUCT
#endif /* PACK_STRUCT_STRUCT */ #endif /* PACK_STRUCT_STRUCT */
#ifdef LWIP_PROVIDE_ERRNO #ifdef LWIP_PROVIDE_ERRNO
#define EPERM 1 /* Operation not permitted */ #define EPERM 1 /* Operation not permitted */
#define ENOENT 2 /* No such file or directory */ #define ENOENT 2 /* No such file or directory */
#define ESRCH 3 /* No such process */ #define ESRCH 3 /* No such process */
#define EINTR 4 /* Interrupted system call */ #define EINTR 4 /* Interrupted system call */
#define EIO 5 /* I/O error */ #define EIO 5 /* I/O error */
#define ENXIO 6 /* No such device or address */ #define ENXIO 6 /* No such device or address */
#define E2BIG 7 /* Arg list too long */ #define E2BIG 7 /* Arg list too long */
#define ENOEXEC 8 /* Exec format error */ #define ENOEXEC 8 /* Exec format error */
#define EBADF 9 /* Bad file number */ #define EBADF 9 /* Bad file number */
#define ECHILD 10 /* No child processes */ #define ECHILD 10 /* No child processes */
#define EAGAIN 11 /* Try again */ #define EAGAIN 11 /* Try again */
#define ENOMEM 12 /* Out of memory */ #define ENOMEM 12 /* Out of memory */
#define EACCES 13 /* Permission denied */ #define EACCES 13 /* Permission denied */
#define EFAULT 14 /* Bad address */ #define EFAULT 14 /* Bad address */
#define ENOTBLK 15 /* Block device required */ #define ENOTBLK 15 /* Block device required */
#define EBUSY 16 /* Device or resource busy */ #define EBUSY 16 /* Device or resource busy */
#define EEXIST 17 /* File exists */ #define EEXIST 17 /* File exists */
#define EXDEV 18 /* Cross-device link */ #define EXDEV 18 /* Cross-device link */
#define ENODEV 19 /* No such device */ #define ENODEV 19 /* No such device */
#define ENOTDIR 20 /* Not a directory */ #define ENOTDIR 20 /* Not a directory */
#define EISDIR 21 /* Is a directory */ #define EISDIR 21 /* Is a directory */
#define EINVAL 22 /* Invalid argument */ #define EINVAL 22 /* Invalid argument */
#define ENFILE 23 /* File table overflow */ #define ENFILE 23 /* File table overflow */
#define EMFILE 24 /* Too many open files */ #define EMFILE 24 /* Too many open files */
#define ENOTTY 25 /* Not a typewriter */ #define ENOTTY 25 /* Not a typewriter */
#define ETXTBSY 26 /* Text file busy */ #define ETXTBSY 26 /* Text file busy */
#define EFBIG 27 /* File too large */ #define EFBIG 27 /* File too large */
#define ENOSPC 28 /* No space left on device */ #define ENOSPC 28 /* No space left on device */
#define ESPIPE 29 /* Illegal seek */ #define ESPIPE 29 /* Illegal seek */
#define EROFS 30 /* Read-only file system */ #define EROFS 30 /* Read-only file system */
#define EMLINK 31 /* Too many links */ #define EMLINK 31 /* Too many links */
#define EPIPE 32 /* Broken pipe */ #define EPIPE 32 /* Broken pipe */
#define EDOM 33 /* Math argument out of domain of func */ #define EDOM 33 /* Math argument out of domain of func */
#define ERANGE 34 /* Math result not representable */ #define ERANGE 34 /* Math result not representable */
#define EDEADLK 35 /* Resource deadlock would occur */ #define EDEADLK 35 /* Resource deadlock would occur */
#define ENAMETOOLONG 36 /* File name too long */ #define ENAMETOOLONG 36 /* File name too long */
#define ENOLCK 37 /* No record locks available */ #define ENOLCK 37 /* No record locks available */
#define ENOSYS 38 /* Function not implemented */ #define ENOSYS 38 /* Function not implemented */
#define ENOTEMPTY 39 /* Directory not empty */ #define ENOTEMPTY 39 /* Directory not empty */
#define ELOOP 40 /* Too many symbolic links encountered */ #define ELOOP 40 /* Too many symbolic links encountered */
#define EWOULDBLOCK EAGAIN /* Operation would block */ #define EWOULDBLOCK EAGAIN /* Operation would block */
#define ENOMSG 42 /* No message of desired type */ #define ENOMSG 42 /* No message of desired type */
#define EIDRM 43 /* Identifier removed */ #define EIDRM 43 /* Identifier removed */
#define ECHRNG 44 /* Channel number out of range */ #define ECHRNG 44 /* Channel number out of range */
#define EL2NSYNC 45 /* Level 2 not synchronized */ #define EL2NSYNC 45 /* Level 2 not synchronized */
#define EL3HLT 46 /* Level 3 halted */ #define EL3HLT 46 /* Level 3 halted */
#define EL3RST 47 /* Level 3 reset */ #define EL3RST 47 /* Level 3 reset */
#define ELNRNG 48 /* Link number out of range */ #define ELNRNG 48 /* Link number out of range */
#define EUNATCH 49 /* Protocol driver not attached */ #define EUNATCH 49 /* Protocol driver not attached */
#define ENOCSI 50 /* No CSI structure available */ #define ENOCSI 50 /* No CSI structure available */
#define EL2HLT 51 /* Level 2 halted */ #define EL2HLT 51 /* Level 2 halted */
#define EBADE 52 /* Invalid exchange */ #define EBADE 52 /* Invalid exchange */
#define EBADR 53 /* Invalid request descriptor */ #define EBADR 53 /* Invalid request descriptor */
#define EXFULL 54 /* Exchange full */ #define EXFULL 54 /* Exchange full */
#define ENOANO 55 /* No anode */ #define ENOANO 55 /* No anode */
#define EBADRQC 56 /* Invalid request code */ #define EBADRQC 56 /* Invalid request code */
#define EBADSLT 57 /* Invalid slot */ #define EBADSLT 57 /* Invalid slot */
#define EDEADLOCK EDEADLK #define EDEADLOCK EDEADLK
#define EBFONT 59 /* Bad font file format */ #define EBFONT 59 /* Bad font file format */
#define ENOSTR 60 /* Device not a stream */ #define ENOSTR 60 /* Device not a stream */
#define ENODATA 61 /* No data available */ #define ENODATA 61 /* No data available */
#define ETIME 62 /* Timer expired */ #define ETIME 62 /* Timer expired */
#define ENOSR 63 /* Out of streams resources */ #define ENOSR 63 /* Out of streams resources */
#define ENONET 64 /* Machine is not on the network */ #define ENONET 64 /* Machine is not on the network */
#define ENOPKG 65 /* Package not installed */ #define ENOPKG 65 /* Package not installed */
#define EREMOTE 66 /* Object is remote */ #define EREMOTE 66 /* Object is remote */
#define ENOLINK 67 /* Link has been severed */ #define ENOLINK 67 /* Link has been severed */
#define EADV 68 /* Advertise error */ #define EADV 68 /* Advertise error */
#define ESRMNT 69 /* Srmount error */ #define ESRMNT 69 /* Srmount error */
#define ECOMM 70 /* Communication error on send */ #define ECOMM 70 /* Communication error on send */
#define EPROTO 71 /* Protocol error */ #define EPROTO 71 /* Protocol error */
#define EMULTIHOP 72 /* Multihop attempted */ #define EMULTIHOP 72 /* Multihop attempted */
#define EDOTDOT 73 /* RFS specific error */ #define EDOTDOT 73 /* RFS specific error */
#define EBADMSG 74 /* Not a data message */ #define EBADMSG 74 /* Not a data message */
#define EOVERFLOW 75 /* Value too large for defined data type */ #define EOVERFLOW 75 /* Value too large for defined data type */
#define ENOTUNIQ 76 /* Name not unique on network */ #define ENOTUNIQ 76 /* Name not unique on network */
#define EBADFD 77 /* File descriptor in bad state */ #define EBADFD 77 /* File descriptor in bad state */
#define EREMCHG 78 /* Remote address changed */ #define EREMCHG 78 /* Remote address changed */
#define ELIBACC 79 /* Can not access a needed shared library */ #define ELIBACC 79 /* Can not access a needed shared library */
#define ELIBBAD 80 /* Accessing a corrupted shared library */ #define ELIBBAD 80 /* Accessing a corrupted shared library */
#define ELIBSCN 81 /* .lib section in a.out corrupted */ #define ELIBSCN 81 /* .lib section in a.out corrupted */
#define ELIBMAX 82 /* Attempting to link in too many shared libraries */ #define ELIBMAX 82 /* Attempting to link in too many shared libraries */
#define ELIBEXEC 83 /* Cannot exec a shared library directly */ #define ELIBEXEC 83 /* Cannot exec a shared library directly */
#define EILSEQ 84 /* Illegal byte sequence */ #define EILSEQ 84 /* Illegal byte sequence */
#define ERESTART 85 /* Interrupted system call should be restarted */ #define ERESTART 85 /* Interrupted system call should be restarted */
#define ESTRPIPE 86 /* Streams pipe error */ #define ESTRPIPE 86 /* Streams pipe error */
#define EUSERS 87 /* Too many users */ #define EUSERS 87 /* Too many users */
#define ENOTSOCK 88 /* Socket operation on non-socket */ #define ENOTSOCK 88 /* Socket operation on non-socket */
#define EDESTADDRREQ 89 /* Destination address required */ #define EDESTADDRREQ 89 /* Destination address required */
#define EMSGSIZE 90 /* Message too long */ #define EMSGSIZE 90 /* Message too long */
#define EPROTOTYPE 91 /* Protocol wrong type for socket */ #define EPROTOTYPE 91 /* Protocol wrong type for socket */
#define ENOPROTOOPT 92 /* Protocol not available */ #define ENOPROTOOPT 92 /* Protocol not available */
#define EPROTONOSUPPORT 93 /* Protocol not supported */ #define EPROTONOSUPPORT 93 /* Protocol not supported */
#define ESOCKTNOSUPPORT 94 /* Socket type not supported */ #define ESOCKTNOSUPPORT 94 /* Socket type not supported */
#define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */ #define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */
#define EPFNOSUPPORT 96 /* Protocol family not supported */ #define EPFNOSUPPORT 96 /* Protocol family not supported */
#define EAFNOSUPPORT 97 /* Address family not supported by protocol */ #define EAFNOSUPPORT 97 /* Address family not supported by protocol */
#define EADDRINUSE 98 /* Address already in use */ #define EADDRINUSE 98 /* Address already in use */
#define EADDRNOTAVAIL 99 /* Cannot assign requested address */ #define EADDRNOTAVAIL 99 /* Cannot assign requested address */
#define ENETDOWN 100 /* Network is down */ #define ENETDOWN 100 /* Network is down */
#define ENETUNREACH 101 /* Network is unreachable */ #define ENETUNREACH 101 /* Network is unreachable */
#define ENETRESET 102 /* Network dropped connection because of reset */ #define ENETRESET 102 /* Network dropped connection because of reset */
#define ECONNABORTED 103 /* Software caused connection abort */ #define ECONNABORTED 103 /* Software caused connection abort */
#define ECONNRESET 104 /* Connection reset by peer */ #define ECONNRESET 104 /* Connection reset by peer */
#define ENOBUFS 105 /* No buffer space available */ #define ENOBUFS 105 /* No buffer space available */
#define EISCONN 106 /* Transport endpoint is already connected */ #define EISCONN 106 /* Transport endpoint is already connected */
#define ENOTCONN 107 /* Transport endpoint is not connected */ #define ENOTCONN 107 /* Transport endpoint is not connected */
#define ESHUTDOWN 108 /* Cannot send after transport endpoint shutdown */ #define ESHUTDOWN 108 /* Cannot send after transport endpoint shutdown */
#define ETOOMANYREFS 109 /* Too many references: cannot splice */ #define ETOOMANYREFS 109 /* Too many references: cannot splice */
#define ETIMEDOUT 110 /* Connection timed out */ #define ETIMEDOUT 110 /* Connection timed out */
#define ECONNREFUSED 111 /* Connection refused */ #define ECONNREFUSED 111 /* Connection refused */
#define EHOSTDOWN 112 /* Host is down */ #define EHOSTDOWN 112 /* Host is down */
#define EHOSTUNREACH 113 /* No route to host */ #define EHOSTUNREACH 113 /* No route to host */
#define EALREADY 114 /* Operation already in progress */ #define EALREADY 114 /* Operation already in progress */
#define EINPROGRESS 115 /* Operation now in progress */ #define EINPROGRESS 115 /* Operation now in progress */
#define ESTALE 116 /* Stale NFS file handle */ #define ESTALE 116 /* Stale NFS file handle */
#define EUCLEAN 117 /* Structure needs cleaning */ #define EUCLEAN 117 /* Structure needs cleaning */
#define ENOTNAM 118 /* Not a XENIX named type file */ #define ENOTNAM 118 /* Not a XENIX named type file */
#define ENAVAIL 119 /* No XENIX semaphores available */ #define ENAVAIL 119 /* No XENIX semaphores available */
#define EISNAM 120 /* Is a named type file */ #define EISNAM 120 /* Is a named type file */
#define EREMOTEIO 121 /* Remote I/O error */ #define EREMOTEIO 121 /* Remote I/O error */
#define EDQUOT 122 /* Quota exceeded */ #define EDQUOT 122 /* Quota exceeded */
#define ENOMEDIUM 123 /* No medium found */ #define ENOMEDIUM 123 /* No medium found */
#define EMEDIUMTYPE 124 /* Wrong medium type */ #define EMEDIUMTYPE 124 /* Wrong medium type */
#define ENSROK 0 /* DNS server returned answer with no data */ #define ENSROK 0 /* DNS server returned answer with no data */
#define ENSRNODATA 160 /* DNS server returned answer with no data */ #define ENSRNODATA 160 /* DNS server returned answer with no data */
#define ENSRFORMERR 161 /* DNS server claims query was misformatted */ #define ENSRFORMERR 161 /* DNS server claims query was misformatted */
#define ENSRSERVFAIL 162 /* DNS server returned general failure */ #define ENSRSERVFAIL 162 /* DNS server returned general failure */
#define ENSRNOTFOUND 163 /* Domain name not found */ #define ENSRNOTFOUND 163 /* Domain name not found */
#define ENSRNOTIMP 164 /* DNS server does not implement requested operation */ #define ENSRNOTIMP 164 /* DNS server does not implement requested operation */
#define ENSRREFUSED 165 /* DNS server refused query */ #define ENSRREFUSED 165 /* DNS server refused query */
#define ENSRBADQUERY 166 /* Misformatted DNS query */ #define ENSRBADQUERY 166 /* Misformatted DNS query */
#define ENSRBADNAME 167 /* Misformatted domain name */ #define ENSRBADNAME 167 /* Misformatted domain name */
#define ENSRBADFAMILY 168 /* Unsupported address family */ #define ENSRBADFAMILY 168 /* Unsupported address family */
#define ENSRBADRESP 169 /* Misformatted DNS reply */ #define ENSRBADRESP 169 /* Misformatted DNS reply */
#define ENSRCONNREFUSED 170 /* Could not contact DNS servers */ #define ENSRCONNREFUSED 170 /* Could not contact DNS servers */
#define ENSRTIMEOUT 171 /* Timeout while contacting DNS servers */ #define ENSRTIMEOUT 171 /* Timeout while contacting DNS servers */
#define ENSROF 172 /* End of file */ #define ENSROF 172 /* End of file */
#define ENSRFILE 173 /* Error reading file */ #define ENSRFILE 173 /* Error reading file */
#define ENSRNOMEM 174 /* Out of memory */ #define ENSRNOMEM 174 /* Out of memory */
#define ENSRDESTRUCTION 175 /* Application terminated lookup */ #define ENSRDESTRUCTION 175 /* Application terminated lookup */
#define ENSRQUERYDOMAINTOOLONG 176 /* Domain name is too long */ #define ENSRQUERYDOMAINTOOLONG 176 /* Domain name is too long */
#define ENSRCNAMELOOP 177 /* Domain name is too long */ #define ENSRCNAMELOOP 177 /* Domain name is too long */
#ifndef errno #ifndef errno
extern int errno; extern int errno;
#endif #endif
#endif /* LWIP_PROVIDE_ERRNO */ #endif /* LWIP_PROVIDE_ERRNO */
#endif /* __LWIP_ARCH_H__ */ #endif /* __LWIP_ARCH_H__ */

View file

@ -1,87 +1,87 @@
/* /*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science. * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, * 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products * 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE. * OF SUCH DAMAGE.
* *
* This file is part of the lwIP TCP/IP stack. * This file is part of the lwIP TCP/IP stack.
* *
* Author: Adam Dunkels <adam@sics.se> * Author: Adam Dunkels <adam@sics.se>
* *
*/ */
#ifndef __LWIP_DEBUG_H__ #ifndef __LWIP_DEBUG_H__
#define __LWIP_DEBUG_H__ #define __LWIP_DEBUG_H__
#include "arch/cc.h" #include "arch/cc.h"
/** lower two bits indicate debug level /** lower two bits indicate debug level
* - 0 off * - 0 off
* - 1 warning * - 1 warning
* - 2 serious * - 2 serious
* - 3 severe * - 3 severe
*/ */
#define DBG_LEVEL_OFF 0 #define DBG_LEVEL_OFF 0
#define DBG_LEVEL_WARNING 1 /* bad checksums, dropped packets, ... */ #define DBG_LEVEL_WARNING 1 /* bad checksums, dropped packets, ... */
#define DBG_LEVEL_SERIOUS 2 /* memory allocation failures, ... */ #define DBG_LEVEL_SERIOUS 2 /* memory allocation failures, ... */
#define DBG_LEVEL_SEVERE 3 /* */ #define DBG_LEVEL_SEVERE 3 /* */
#define DBG_MASK_LEVEL 3 #define DBG_MASK_LEVEL 3
/** flag for LWIP_DEBUGF to enable that debug message */ /** flag for LWIP_DEBUGF to enable that debug message */
#define DBG_ON 0x80U #define DBG_ON 0x80U
/** flag for LWIP_DEBUGF to disable that debug message */ /** flag for LWIP_DEBUGF to disable that debug message */
#define DBG_OFF 0x00U #define DBG_OFF 0x00U
/** flag for LWIP_DEBUGF indicating a tracing message (to follow program flow) */ /** flag for LWIP_DEBUGF indicating a tracing message (to follow program flow) */
#define DBG_TRACE 0x40U #define DBG_TRACE 0x40U
/** flag for LWIP_DEBUGF indicating a state debug message (to follow module states) */ /** flag for LWIP_DEBUGF indicating a state debug message (to follow module states) */
#define DBG_STATE 0x20U #define DBG_STATE 0x20U
/** flag for LWIP_DEBUGF indicating newly added code, not thoroughly tested yet */ /** flag for LWIP_DEBUGF indicating newly added code, not thoroughly tested yet */
#define DBG_FRESH 0x10U #define DBG_FRESH 0x10U
/** flag for LWIP_DEBUGF to halt after printing this debug message */ /** flag for LWIP_DEBUGF to halt after printing this debug message */
#define DBG_HALT 0x08U #define DBG_HALT 0x08U
#ifndef LWIP_NOASSERT #ifndef LWIP_NOASSERT
# define LWIP_ASSERT(x,y) do { if(!(y)) LWIP_PLATFORM_ASSERT(x); } while(0) # define LWIP_ASSERT(x,y) do { if(!(y)) LWIP_PLATFORM_ASSERT(x); } while(0)
#else #else
# define LWIP_ASSERT(x,y) # define LWIP_ASSERT(x,y)
#endif #endif
#ifdef LWIP_DEBUG #ifdef LWIP_DEBUG
/** print debug message only if debug message type is enabled... /** print debug message only if debug message type is enabled...
* AND is of correct type AND is at least DBG_LEVEL * AND is of correct type AND is at least DBG_LEVEL
*/ */
# define LWIP_DEBUGF(debug,x) do { if (((debug) & DBG_ON) && ((debug) & DBG_TYPES_ON) && ((s16_t)((debug) & DBG_MASK_LEVEL) >= DBG_MIN_LEVEL)) { LWIP_PLATFORM_DIAG(x); if ((debug) & DBG_HALT) while(1); } } while(0) # define LWIP_DEBUGF(debug,x) do { if (((debug) & DBG_ON) && ((debug) & DBG_TYPES_ON) && ((s16_t)((debug) & DBG_MASK_LEVEL) >= DBG_MIN_LEVEL)) { LWIP_PLATFORM_DIAG(x); if ((debug) & DBG_HALT) while(1); } } while(0)
# define LWIP_ERROR(x) do { LWIP_PLATFORM_DIAG(x); } while(0) # define LWIP_ERROR(x) do { LWIP_PLATFORM_DIAG(x); } while(0)
#else /* LWIP_DEBUG */ #else /* LWIP_DEBUG */
# define LWIP_DEBUGF(debug,x) # define LWIP_DEBUGF(debug,x)
# define LWIP_ERROR(x) # define LWIP_ERROR(x)
#endif /* LWIP_DEBUG */ #endif /* LWIP_DEBUG */
#endif /* __LWIP_DEBUG_H__ */ #endif /* __LWIP_DEBUG_H__ */

View file

@ -1,47 +1,47 @@
/* /*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science. * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, * 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products * 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE. * OF SUCH DAMAGE.
* *
* This file is part of the lwIP TCP/IP stack. * This file is part of the lwIP TCP/IP stack.
* *
* Author: Adam Dunkels <adam@sics.se> * Author: Adam Dunkels <adam@sics.se>
* *
*/ */
#ifndef __LWIP_DEF_H__ #ifndef __LWIP_DEF_H__
#define __LWIP_DEF_H__ #define __LWIP_DEF_H__
/* this might define NULL already */ /* this might define NULL already */
#include "arch/cc.h" #include "arch/cc.h"
#define LWIP_MAX(x , y) (x) > (y) ? (x) : (y) #define LWIP_MAX(x , y) (x) > (y) ? (x) : (y)
#define LWIP_MIN(x , y) (x) < (y) ? (x) : (y) #define LWIP_MIN(x , y) (x) < (y) ? (x) : (y)
#ifndef NULL #ifndef NULL
#define NULL ((void *)0) #define NULL ((void *)0)
#endif #endif
#endif /* __LWIP_DEF_H__ */ #endif /* __LWIP_DEF_H__ */

View file

@ -1,223 +1,223 @@
/** @file /** @file
*/ */
#ifndef __LWIP_DHCP_H__ #ifndef __LWIP_DHCP_H__
#define __LWIP_DHCP_H__ #define __LWIP_DHCP_H__
#include "lwip/opt.h" #include "lwip/opt.h"
#include "lwip/netif.h" #include "lwip/netif.h"
#include "lwip/udp.h" #include "lwip/udp.h"
/** period (in seconds) of the application calling dhcp_coarse_tmr() */ /** period (in seconds) of the application calling dhcp_coarse_tmr() */
#define DHCP_COARSE_TIMER_SECS 60 #define DHCP_COARSE_TIMER_SECS 60
/** period (in milliseconds) of the application calling dhcp_fine_tmr() */ /** period (in milliseconds) of the application calling dhcp_fine_tmr() */
#define DHCP_FINE_TIMER_MSECS 500 #define DHCP_FINE_TIMER_MSECS 500
struct dhcp struct dhcp
{ {
/** current DHCP state machine state */ /** current DHCP state machine state */
u8_t state; u8_t state;
/** retries of current request */ /** retries of current request */
u8_t tries; u8_t tries;
/** transaction identifier of last sent request */ /** transaction identifier of last sent request */
u32_t xid; u32_t xid;
/** our connection to the DHCP server */ /** our connection to the DHCP server */
struct udp_pcb *pcb; struct udp_pcb *pcb;
/** (first) pbuf of incoming msg */ /** (first) pbuf of incoming msg */
struct pbuf *p; struct pbuf *p;
/** incoming msg */ /** incoming msg */
struct dhcp_msg *msg_in; struct dhcp_msg *msg_in;
/** incoming msg options */ /** incoming msg options */
struct dhcp_msg *options_in; struct dhcp_msg *options_in;
/** ingoing msg options length */ /** ingoing msg options length */
u16_t options_in_len; u16_t options_in_len;
struct pbuf *p_out; /* pbuf of outcoming msg */ struct pbuf *p_out; /* pbuf of outcoming msg */
struct dhcp_msg *msg_out; /* outgoing msg */ struct dhcp_msg *msg_out; /* outgoing msg */
u16_t options_out_len; /* outgoing msg options length */ u16_t options_out_len; /* outgoing msg options length */
u16_t request_timeout; /* #ticks with period DHCP_FINE_TIMER_SECS for request timeout */ u16_t request_timeout; /* #ticks with period DHCP_FINE_TIMER_SECS for request timeout */
u16_t t1_timeout; /* #ticks with period DHCP_COARSE_TIMER_SECS for renewal time */ u16_t t1_timeout; /* #ticks with period DHCP_COARSE_TIMER_SECS for renewal time */
u16_t t2_timeout; /* #ticks with period DHCP_COARSE_TIMER_SECS for rebind time */ u16_t t2_timeout; /* #ticks with period DHCP_COARSE_TIMER_SECS for rebind time */
struct ip_addr server_ip_addr; /* dhcp server address that offered this lease */ struct ip_addr server_ip_addr; /* dhcp server address that offered this lease */
struct ip_addr offered_ip_addr; struct ip_addr offered_ip_addr;
struct ip_addr offered_sn_mask; struct ip_addr offered_sn_mask;
struct ip_addr offered_gw_addr; struct ip_addr offered_gw_addr;
struct ip_addr offered_bc_addr; struct ip_addr offered_bc_addr;
#define DHCP_MAX_DNS 2 #define DHCP_MAX_DNS 2
u32_t dns_count; /* actual number of DNS servers obtained */ u32_t dns_count; /* actual number of DNS servers obtained */
struct ip_addr offered_dns_addr[DHCP_MAX_DNS]; /* DNS server addresses */ struct ip_addr offered_dns_addr[DHCP_MAX_DNS]; /* DNS server addresses */
u32_t offered_t0_lease; /* lease period (in seconds) */ u32_t offered_t0_lease; /* lease period (in seconds) */
u32_t offered_t1_renew; /* recommended renew time (usually 50% of lease period) */ u32_t offered_t1_renew; /* recommended renew time (usually 50% of lease period) */
u32_t offered_t2_rebind; /* recommended rebind time (usually 66% of lease period) */ u32_t offered_t2_rebind; /* recommended rebind time (usually 66% of lease period) */
/** Patch #1308 /** Patch #1308
* TODO: See dhcp.c "TODO"s * TODO: See dhcp.c "TODO"s
*/ */
#if 0 #if 0
struct ip_addr offered_si_addr; struct ip_addr offered_si_addr;
u8_t *boot_file_name; u8_t *boot_file_name;
#endif #endif
}; };
/* MUST be compiled with "pack structs" or equivalent! */ /* MUST be compiled with "pack structs" or equivalent! */
#ifdef PACK_STRUCT_USE_INCLUDES #ifdef PACK_STRUCT_USE_INCLUDES
# include "arch/bpstruct.h" # include "arch/bpstruct.h"
#endif #endif
PACK_STRUCT_BEGIN PACK_STRUCT_BEGIN
/** minimum set of fields of any DHCP message */ /** minimum set of fields of any DHCP message */
struct dhcp_msg struct dhcp_msg
{ {
PACK_STRUCT_FIELD(u8_t op); PACK_STRUCT_FIELD(u8_t op);
PACK_STRUCT_FIELD(u8_t htype); PACK_STRUCT_FIELD(u8_t htype);
PACK_STRUCT_FIELD(u8_t hlen); PACK_STRUCT_FIELD(u8_t hlen);
PACK_STRUCT_FIELD(u8_t hops); PACK_STRUCT_FIELD(u8_t hops);
PACK_STRUCT_FIELD(u32_t xid); PACK_STRUCT_FIELD(u32_t xid);
PACK_STRUCT_FIELD(u16_t secs); PACK_STRUCT_FIELD(u16_t secs);
PACK_STRUCT_FIELD(u16_t flags); PACK_STRUCT_FIELD(u16_t flags);
PACK_STRUCT_FIELD(struct ip_addr ciaddr); PACK_STRUCT_FIELD(struct ip_addr ciaddr);
PACK_STRUCT_FIELD(struct ip_addr yiaddr); PACK_STRUCT_FIELD(struct ip_addr yiaddr);
PACK_STRUCT_FIELD(struct ip_addr siaddr); PACK_STRUCT_FIELD(struct ip_addr siaddr);
PACK_STRUCT_FIELD(struct ip_addr giaddr); PACK_STRUCT_FIELD(struct ip_addr giaddr);
#define DHCP_CHADDR_LEN 16U #define DHCP_CHADDR_LEN 16U
PACK_STRUCT_FIELD(u8_t chaddr[DHCP_CHADDR_LEN]); PACK_STRUCT_FIELD(u8_t chaddr[DHCP_CHADDR_LEN]);
#define DHCP_SNAME_LEN 64U #define DHCP_SNAME_LEN 64U
PACK_STRUCT_FIELD(u8_t sname[DHCP_SNAME_LEN]); PACK_STRUCT_FIELD(u8_t sname[DHCP_SNAME_LEN]);
#define DHCP_FILE_LEN 128U #define DHCP_FILE_LEN 128U
PACK_STRUCT_FIELD(u8_t file[DHCP_FILE_LEN]); PACK_STRUCT_FIELD(u8_t file[DHCP_FILE_LEN]);
PACK_STRUCT_FIELD(u32_t cookie); PACK_STRUCT_FIELD(u32_t cookie);
#define DHCP_MIN_OPTIONS_LEN 68U #define DHCP_MIN_OPTIONS_LEN 68U
/** make sure user does not configure this too small */ /** make sure user does not configure this too small */
#if ((defined(DHCP_OPTIONS_LEN)) && (DHCP_OPTIONS_LEN < DHCP_MIN_OPTIONS_LEN)) #if ((defined(DHCP_OPTIONS_LEN)) && (DHCP_OPTIONS_LEN < DHCP_MIN_OPTIONS_LEN))
# undef DHCP_OPTIONS_LEN # undef DHCP_OPTIONS_LEN
#endif #endif
/** allow this to be configured in lwipopts.h, but not too small */ /** allow this to be configured in lwipopts.h, but not too small */
#if (!defined(DHCP_OPTIONS_LEN)) #if (!defined(DHCP_OPTIONS_LEN))
/** set this to be sufficient for your options in outgoing DHCP msgs */ /** set this to be sufficient for your options in outgoing DHCP msgs */
# define DHCP_OPTIONS_LEN DHCP_MIN_OPTIONS_LEN # define DHCP_OPTIONS_LEN DHCP_MIN_OPTIONS_LEN
#endif #endif
PACK_STRUCT_FIELD(u8_t options[DHCP_OPTIONS_LEN]); PACK_STRUCT_FIELD(u8_t options[DHCP_OPTIONS_LEN]);
} PACK_STRUCT_STRUCT; } PACK_STRUCT_STRUCT;
PACK_STRUCT_END PACK_STRUCT_END
#ifdef PACK_STRUCT_USE_INCLUDES #ifdef PACK_STRUCT_USE_INCLUDES
# include "arch/epstruct.h" # include "arch/epstruct.h"
#endif #endif
/** start DHCP configuration */ /** start DHCP configuration */
err_t dhcp_start(struct netif *netif); err_t dhcp_start(struct netif *netif);
/** enforce early lease renewal (not needed normally)*/ /** enforce early lease renewal (not needed normally)*/
err_t dhcp_renew(struct netif *netif); err_t dhcp_renew(struct netif *netif);
/** release the DHCP lease, usually called before dhcp_stop()*/ /** release the DHCP lease, usually called before dhcp_stop()*/
err_t dhcp_release(struct netif *netif); err_t dhcp_release(struct netif *netif);
/** stop DHCP configuration */ /** stop DHCP configuration */
void dhcp_stop(struct netif *netif); void dhcp_stop(struct netif *netif);
/** inform server of our manual IP address */ /** inform server of our manual IP address */
void dhcp_inform(struct netif *netif); void dhcp_inform(struct netif *netif);
/** if enabled, check whether the offered IP address is not in use, using ARP */ /** if enabled, check whether the offered IP address is not in use, using ARP */
#if DHCP_DOES_ARP_CHECK #if DHCP_DOES_ARP_CHECK
void dhcp_arp_reply(struct netif *netif, struct ip_addr *addr); void dhcp_arp_reply(struct netif *netif, struct ip_addr *addr);
#endif #endif
/** to be called every minute */ /** to be called every minute */
void dhcp_coarse_tmr(void); void dhcp_coarse_tmr(void);
/** to be called every half second */ /** to be called every half second */
void dhcp_fine_tmr(void); void dhcp_fine_tmr(void);
/** DHCP message item offsets and length */ /** DHCP message item offsets and length */
#define DHCP_MSG_OFS (UDP_DATA_OFS) #define DHCP_MSG_OFS (UDP_DATA_OFS)
#define DHCP_OP_OFS (DHCP_MSG_OFS + 0) #define DHCP_OP_OFS (DHCP_MSG_OFS + 0)
#define DHCP_HTYPE_OFS (DHCP_MSG_OFS + 1) #define DHCP_HTYPE_OFS (DHCP_MSG_OFS + 1)
#define DHCP_HLEN_OFS (DHCP_MSG_OFS + 2) #define DHCP_HLEN_OFS (DHCP_MSG_OFS + 2)
#define DHCP_HOPS_OFS (DHCP_MSG_OFS + 3) #define DHCP_HOPS_OFS (DHCP_MSG_OFS + 3)
#define DHCP_XID_OFS (DHCP_MSG_OFS + 4) #define DHCP_XID_OFS (DHCP_MSG_OFS + 4)
#define DHCP_SECS_OFS (DHCP_MSG_OFS + 8) #define DHCP_SECS_OFS (DHCP_MSG_OFS + 8)
#define DHCP_FLAGS_OFS (DHCP_MSG_OFS + 10) #define DHCP_FLAGS_OFS (DHCP_MSG_OFS + 10)
#define DHCP_CIADDR_OFS (DHCP_MSG_OFS + 12) #define DHCP_CIADDR_OFS (DHCP_MSG_OFS + 12)
#define DHCP_YIADDR_OFS (DHCP_MSG_OFS + 16) #define DHCP_YIADDR_OFS (DHCP_MSG_OFS + 16)
#define DHCP_SIADDR_OFS (DHCP_MSG_OFS + 20) #define DHCP_SIADDR_OFS (DHCP_MSG_OFS + 20)
#define DHCP_GIADDR_OFS (DHCP_MSG_OFS + 24) #define DHCP_GIADDR_OFS (DHCP_MSG_OFS + 24)
#define DHCP_CHADDR_OFS (DHCP_MSG_OFS + 28) #define DHCP_CHADDR_OFS (DHCP_MSG_OFS + 28)
#define DHCP_SNAME_OFS (DHCP_MSG_OFS + 44) #define DHCP_SNAME_OFS (DHCP_MSG_OFS + 44)
#define DHCP_FILE_OFS (DHCP_MSG_OFS + 108) #define DHCP_FILE_OFS (DHCP_MSG_OFS + 108)
#define DHCP_MSG_LEN 236 #define DHCP_MSG_LEN 236
#define DHCP_COOKIE_OFS (DHCP_MSG_OFS + DHCP_MSG_LEN) #define DHCP_COOKIE_OFS (DHCP_MSG_OFS + DHCP_MSG_LEN)
#define DHCP_OPTIONS_OFS (DHCP_MSG_OFS + DHCP_MSG_LEN + 4) #define DHCP_OPTIONS_OFS (DHCP_MSG_OFS + DHCP_MSG_LEN + 4)
#define DHCP_CLIENT_PORT 68 #define DHCP_CLIENT_PORT 68
#define DHCP_SERVER_PORT 67 #define DHCP_SERVER_PORT 67
/** DHCP client states */ /** DHCP client states */
#define DHCP_REQUESTING 1 #define DHCP_REQUESTING 1
#define DHCP_INIT 2 #define DHCP_INIT 2
#define DHCP_REBOOTING 3 #define DHCP_REBOOTING 3
#define DHCP_REBINDING 4 #define DHCP_REBINDING 4
#define DHCP_RENEWING 5 #define DHCP_RENEWING 5
#define DHCP_SELECTING 6 #define DHCP_SELECTING 6
#define DHCP_INFORMING 7 #define DHCP_INFORMING 7
#define DHCP_CHECKING 8 #define DHCP_CHECKING 8
#define DHCP_PERMANENT 9 #define DHCP_PERMANENT 9
#define DHCP_BOUND 10 #define DHCP_BOUND 10
/** not yet implemented #define DHCP_RELEASING 11 */ /** not yet implemented #define DHCP_RELEASING 11 */
#define DHCP_BACKING_OFF 12 #define DHCP_BACKING_OFF 12
#define DHCP_OFF 13 #define DHCP_OFF 13
#define DHCP_BOOTREQUEST 1 #define DHCP_BOOTREQUEST 1
#define DHCP_BOOTREPLY 2 #define DHCP_BOOTREPLY 2
#define DHCP_DISCOVER 1 #define DHCP_DISCOVER 1
#define DHCP_OFFER 2 #define DHCP_OFFER 2
#define DHCP_REQUEST 3 #define DHCP_REQUEST 3
#define DHCP_DECLINE 4 #define DHCP_DECLINE 4
#define DHCP_ACK 5 #define DHCP_ACK 5
#define DHCP_NAK 6 #define DHCP_NAK 6
#define DHCP_RELEASE 7 #define DHCP_RELEASE 7
#define DHCP_INFORM 8 #define DHCP_INFORM 8
#define DHCP_HTYPE_ETH 1 #define DHCP_HTYPE_ETH 1
#define DHCP_HLEN_ETH 6 #define DHCP_HLEN_ETH 6
#define DHCP_BROADCAST_FLAG 15 #define DHCP_BROADCAST_FLAG 15
#define DHCP_BROADCAST_MASK (1 << DHCP_FLAG_BROADCAST) #define DHCP_BROADCAST_MASK (1 << DHCP_FLAG_BROADCAST)
/** BootP options */ /** BootP options */
#define DHCP_OPTION_PAD 0 #define DHCP_OPTION_PAD 0
#define DHCP_OPTION_SUBNET_MASK 1 /* RFC 2132 3.3 */ #define DHCP_OPTION_SUBNET_MASK 1 /* RFC 2132 3.3 */
#define DHCP_OPTION_ROUTER 3 #define DHCP_OPTION_ROUTER 3
#define DHCP_OPTION_DNS_SERVER 6 #define DHCP_OPTION_DNS_SERVER 6
#define DHCP_OPTION_HOSTNAME 12 #define DHCP_OPTION_HOSTNAME 12
#define DHCP_OPTION_IP_TTL 23 #define DHCP_OPTION_IP_TTL 23
#define DHCP_OPTION_MTU 26 #define DHCP_OPTION_MTU 26
#define DHCP_OPTION_BROADCAST 28 #define DHCP_OPTION_BROADCAST 28
#define DHCP_OPTION_TCP_TTL 37 #define DHCP_OPTION_TCP_TTL 37
#define DHCP_OPTION_END 255 #define DHCP_OPTION_END 255
/** DHCP options */ /** DHCP options */
#define DHCP_OPTION_REQUESTED_IP 50 /* RFC 2132 9.1, requested IP address */ #define DHCP_OPTION_REQUESTED_IP 50 /* RFC 2132 9.1, requested IP address */
#define DHCP_OPTION_LEASE_TIME 51 /* RFC 2132 9.2, time in seconds, in 4 bytes */ #define DHCP_OPTION_LEASE_TIME 51 /* RFC 2132 9.2, time in seconds, in 4 bytes */
#define DHCP_OPTION_OVERLOAD 52 /* RFC2132 9.3, use file and/or sname field for options */ #define DHCP_OPTION_OVERLOAD 52 /* RFC2132 9.3, use file and/or sname field for options */
#define DHCP_OPTION_MESSAGE_TYPE 53 /* RFC 2132 9.6, important for DHCP */ #define DHCP_OPTION_MESSAGE_TYPE 53 /* RFC 2132 9.6, important for DHCP */
#define DHCP_OPTION_MESSAGE_TYPE_LEN 1 #define DHCP_OPTION_MESSAGE_TYPE_LEN 1
#define DHCP_OPTION_SERVER_ID 54 /* RFC 2132 9.7, server IP address */ #define DHCP_OPTION_SERVER_ID 54 /* RFC 2132 9.7, server IP address */
#define DHCP_OPTION_PARAMETER_REQUEST_LIST 55 /* RFC 2132 9.8, requested option types */ #define DHCP_OPTION_PARAMETER_REQUEST_LIST 55 /* RFC 2132 9.8, requested option types */
#define DHCP_OPTION_MAX_MSG_SIZE 57 /* RFC 2132 9.10, message size accepted >= 576 */ #define DHCP_OPTION_MAX_MSG_SIZE 57 /* RFC 2132 9.10, message size accepted >= 576 */
#define DHCP_OPTION_MAX_MSG_SIZE_LEN 2 #define DHCP_OPTION_MAX_MSG_SIZE_LEN 2
#define DHCP_OPTION_T1 58 /* T1 renewal time */ #define DHCP_OPTION_T1 58 /* T1 renewal time */
#define DHCP_OPTION_T2 59 /* T2 rebinding time */ #define DHCP_OPTION_T2 59 /* T2 rebinding time */
#define DHCP_OPTION_CLIENT_ID 61 #define DHCP_OPTION_CLIENT_ID 61
#define DHCP_OPTION_TFTP_SERVERNAME 66 #define DHCP_OPTION_TFTP_SERVERNAME 66
#define DHCP_OPTION_BOOTFILE 67 #define DHCP_OPTION_BOOTFILE 67
/** possible combinations of overloading the file and sname fields with options */ /** possible combinations of overloading the file and sname fields with options */
#define DHCP_OVERLOAD_NONE 0 #define DHCP_OVERLOAD_NONE 0
#define DHCP_OVERLOAD_FILE 1 #define DHCP_OVERLOAD_FILE 1
#define DHCP_OVERLOAD_SNAME 2 #define DHCP_OVERLOAD_SNAME 2
#define DHCP_OVERLOAD_SNAME_FILE 3 #define DHCP_OVERLOAD_SNAME_FILE 3
#endif /*__LWIP_DHCP_H__*/ #endif /*__LWIP_DHCP_H__*/

View file

@ -1,70 +1,70 @@
/* /*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science. * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, * 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products * 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE. * OF SUCH DAMAGE.
* *
* This file is part of the lwIP TCP/IP stack. * This file is part of the lwIP TCP/IP stack.
* *
* Author: Adam Dunkels <adam@sics.se> * Author: Adam Dunkels <adam@sics.se>
* *
*/ */
#ifndef __LWIP_ERR_H__ #ifndef __LWIP_ERR_H__
#define __LWIP_ERR_H__ #define __LWIP_ERR_H__
#include "lwip/opt.h" #include "lwip/opt.h"
#include "arch/cc.h" #include "arch/cc.h"
typedef s8_t err_t; typedef s8_t err_t;
/* Definitions for error constants. */ /* Definitions for error constants. */
#define ERR_OK 0 /* No error, everything OK. */ #define ERR_OK 0 /* No error, everything OK. */
#define ERR_MEM -1 /* Out of memory error. */ #define ERR_MEM -1 /* Out of memory error. */
#define ERR_BUF -2 /* Buffer error. */ #define ERR_BUF -2 /* Buffer error. */
#define ERR_ABRT -3 /* Connection aborted. */ #define ERR_ABRT -3 /* Connection aborted. */
#define ERR_RST -4 /* Connection reset. */ #define ERR_RST -4 /* Connection reset. */
#define ERR_CLSD -5 /* Connection closed. */ #define ERR_CLSD -5 /* Connection closed. */
#define ERR_CONN -6 /* Not connected. */ #define ERR_CONN -6 /* Not connected. */
#define ERR_VAL -7 /* Illegal value. */ #define ERR_VAL -7 /* Illegal value. */
#define ERR_ARG -8 /* Illegal argument. */ #define ERR_ARG -8 /* Illegal argument. */
#define ERR_RTE -9 /* Routing problem. */ #define ERR_RTE -9 /* Routing problem. */
#define ERR_USE -10 /* Address in use. */ #define ERR_USE -10 /* Address in use. */
#define ERR_IF -11 /* Low-level netif error */ #define ERR_IF -11 /* Low-level netif error */
#define ERR_ISCONN -12 /* Already connected. */ #define ERR_ISCONN -12 /* Already connected. */
#ifdef LWIP_DEBUG #ifdef LWIP_DEBUG
extern char *lwip_strerr(err_t err); extern char *lwip_strerr(err_t err);
#else #else
#define lwip_strerr(x) "" #define lwip_strerr(x) ""
#endif /* LWIP_DEBUG */ #endif /* LWIP_DEBUG */
#endif /* __LWIP_ERR_H__ */ #endif /* __LWIP_ERR_H__ */

View file

@ -1,69 +1,69 @@
/* /*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science. * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, * 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products * 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE. * OF SUCH DAMAGE.
* *
* This file is part of the lwIP TCP/IP stack. * This file is part of the lwIP TCP/IP stack.
* *
* Author: Adam Dunkels <adam@sics.se> * Author: Adam Dunkels <adam@sics.se>
* *
*/ */
#ifndef __LWIP_MEM_H__ #ifndef __LWIP_MEM_H__
#define __LWIP_MEM_H__ #define __LWIP_MEM_H__
#include "lwip/opt.h" #include "lwip/opt.h"
#include "lwip/arch.h" #include "lwip/arch.h"
#if MEM_SIZE > 64000l #if MEM_SIZE > 64000l
typedef u32_t mem_size_t; typedef u32_t mem_size_t;
#define MEM_SIZE_F U32_F #define MEM_SIZE_F U32_F
#else #else
typedef u16_t mem_size_t; typedef u16_t mem_size_t;
#define MEM_SIZE_F U16_F #define MEM_SIZE_F U16_F
#endif /* MEM_SIZE > 64000 */ #endif /* MEM_SIZE > 64000 */
#if MEM_LIBC_MALLOC #if MEM_LIBC_MALLOC
/* aliases for C library malloc() */ /* aliases for C library malloc() */
#define mem_init() #define mem_init()
#define mem_free(x) free(x) #define mem_free(x) free(x)
#define mem_malloc(x) malloc(x) #define mem_malloc(x) malloc(x)
#define mem_realloc(x, size) realloc(x,size) #define mem_realloc(x, size) realloc(x,size)
#else #else
/* lwIP alternative malloc */ /* lwIP alternative malloc */
void mem_init(void); void mem_init(void);
void *mem_malloc(mem_size_t size); void *mem_malloc(mem_size_t size);
void mem_free(void *mem); void mem_free(void *mem);
void *mem_realloc(void *mem, mem_size_t size); void *mem_realloc(void *mem, mem_size_t size);
#endif #endif
#ifndef MEM_ALIGN_SIZE #ifndef MEM_ALIGN_SIZE
#define MEM_ALIGN_SIZE(size) (((size) + MEM_ALIGNMENT - 1) & ~(MEM_ALIGNMENT-1)) #define MEM_ALIGN_SIZE(size) (((size) + MEM_ALIGNMENT - 1) & ~(MEM_ALIGNMENT-1))
#endif #endif
#ifndef MEM_ALIGN #ifndef MEM_ALIGN
#define MEM_ALIGN(addr) ((void *)(((mem_ptr_t)(addr) + MEM_ALIGNMENT - 1) & ~(mem_ptr_t)(MEM_ALIGNMENT-1))) #define MEM_ALIGN(addr) ((void *)(((mem_ptr_t)(addr) + MEM_ALIGNMENT - 1) & ~(mem_ptr_t)(MEM_ALIGNMENT-1)))
#endif #endif
#endif /* __LWIP_MEM_H__ */ #endif /* __LWIP_MEM_H__ */

View file

@ -1,63 +1,63 @@
/* /*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science. * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, * 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products * 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE. * OF SUCH DAMAGE.
* *
* This file is part of the lwIP TCP/IP stack. * This file is part of the lwIP TCP/IP stack.
* *
* Author: Adam Dunkels <adam@sics.se> * Author: Adam Dunkels <adam@sics.se>
* *
*/ */
#ifndef __LWIP_MEMP_H__ #ifndef __LWIP_MEMP_H__
#define __LWIP_MEMP_H__ #define __LWIP_MEMP_H__
#include "lwip/opt.h" #include "lwip/opt.h"
typedef enum { typedef enum {
MEMP_PBUF, MEMP_PBUF,
MEMP_RAW_PCB, MEMP_RAW_PCB,
MEMP_UDP_PCB, MEMP_UDP_PCB,
MEMP_TCP_PCB, MEMP_TCP_PCB,
MEMP_TCP_PCB_LISTEN, MEMP_TCP_PCB_LISTEN,
MEMP_TCP_SEG, MEMP_TCP_SEG,
MEMP_NETBUF, MEMP_NETBUF,
MEMP_NETCONN, MEMP_NETCONN,
MEMP_API_MSG, MEMP_API_MSG,
MEMP_TCPIP_MSG, MEMP_TCPIP_MSG,
MEMP_SYS_TIMEOUT, MEMP_SYS_TIMEOUT,
MEMP_MAX MEMP_MAX
} memp_t; } memp_t;
void memp_init(void); void memp_init(void);
void *memp_malloc(memp_t type); void *memp_malloc(memp_t type);
void *memp_realloc(memp_t fromtype, memp_t totype, void *mem); void *memp_realloc(memp_t fromtype, memp_t totype, void *mem);
void memp_free(memp_t type, void *mem); void memp_free(memp_t type, void *mem);
#endif /* __LWIP_MEMP_H__ */ #endif /* __LWIP_MEMP_H__ */

View file

@ -1,165 +1,165 @@
/* /*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science. * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, * 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products * 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE. * OF SUCH DAMAGE.
* *
* This file is part of the lwIP TCP/IP stack. * This file is part of the lwIP TCP/IP stack.
* *
* Author: Adam Dunkels <adam@sics.se> * Author: Adam Dunkels <adam@sics.se>
* *
*/ */
#ifndef __LWIP_NETIF_H__ #ifndef __LWIP_NETIF_H__
#define __LWIP_NETIF_H__ #define __LWIP_NETIF_H__
#include "lwip/opt.h" #include "lwip/opt.h"
#include "lwip/err.h" #include "lwip/err.h"
#include "lwip/ip_addr.h" #include "lwip/ip_addr.h"
#include "lwip/inet.h" #include "lwip/inet.h"
#include "lwip/pbuf.h" #include "lwip/pbuf.h"
#if LWIP_DHCP #if LWIP_DHCP
# include "lwip/dhcp.h" # include "lwip/dhcp.h"
#endif #endif
/** must be the maximum of all used hardware address lengths /** must be the maximum of all used hardware address lengths
across all types of interfaces in use */ across all types of interfaces in use */
#define NETIF_MAX_HWADDR_LEN 6U #define NETIF_MAX_HWADDR_LEN 6U
/** TODO: define the use (where, when, whom) of netif flags */ /** TODO: define the use (where, when, whom) of netif flags */
/** whether the network interface is 'up'. this is /** whether the network interface is 'up'. this is
* a software flag used to control whether this network * a software flag used to control whether this network
* interface is enabled and processes traffic. * interface is enabled and processes traffic.
*/ */
#define NETIF_FLAG_UP 0x1U #define NETIF_FLAG_UP 0x1U
/** if set, the netif has broadcast capability */ /** if set, the netif has broadcast capability */
#define NETIF_FLAG_BROADCAST 0x2U #define NETIF_FLAG_BROADCAST 0x2U
/** if set, the netif is one end of a point-to-point connection */ /** if set, the netif is one end of a point-to-point connection */
#define NETIF_FLAG_POINTTOPOINT 0x4U #define NETIF_FLAG_POINTTOPOINT 0x4U
/** if set, the interface is configured using DHCP */ /** if set, the interface is configured using DHCP */
#define NETIF_FLAG_DHCP 0x08U #define NETIF_FLAG_DHCP 0x08U
/** if set, the interface has an active link /** if set, the interface has an active link
* (set by the network interface driver) */ * (set by the network interface driver) */
#define NETIF_FLAG_LINK_UP 0x10U #define NETIF_FLAG_LINK_UP 0x10U
/** Generic data structure used for all lwIP network interfaces. /** Generic data structure used for all lwIP network interfaces.
* The following fields should be filled in by the initialization * The following fields should be filled in by the initialization
* function for the device driver: hwaddr_len, hwaddr[], mtu, flags */ * function for the device driver: hwaddr_len, hwaddr[], mtu, flags */
struct netif { struct netif {
/** pointer to next in linked list */ /** pointer to next in linked list */
struct netif *next; struct netif *next;
/** IP address configuration in network byte order */ /** IP address configuration in network byte order */
struct ip_addr ip_addr; struct ip_addr ip_addr;
struct ip_addr netmask; struct ip_addr netmask;
struct ip_addr gw; struct ip_addr gw;
/** This function is called by the network device driver /** This function is called by the network device driver
* to pass a packet up the TCP/IP stack. */ * to pass a packet up the TCP/IP stack. */
err_t (* input)(struct pbuf *p, struct netif *inp); err_t (* input)(struct pbuf *p, struct netif *inp);
/** This function is called by the IP module when it wants /** This function is called by the IP module when it wants
* to send a packet on the interface. This function typically * to send a packet on the interface. This function typically
* first resolves the hardware address, then sends the packet. */ * first resolves the hardware address, then sends the packet. */
err_t (* output)(struct netif *netif, struct pbuf *p, err_t (* output)(struct netif *netif, struct pbuf *p,
struct ip_addr *ipaddr); struct ip_addr *ipaddr);
/** This function is called by the ARP module when it wants /** This function is called by the ARP module when it wants
* to send a packet on the interface. This function outputs * to send a packet on the interface. This function outputs
* the pbuf as-is on the link medium. */ * the pbuf as-is on the link medium. */
err_t (* linkoutput)(struct netif *netif, struct pbuf *p); err_t (* linkoutput)(struct netif *netif, struct pbuf *p);
/** This field can be set by the device driver and could point /** This field can be set by the device driver and could point
* to state information for the device. */ * to state information for the device. */
void *state; void *state;
#if LWIP_DHCP #if LWIP_DHCP
/** the DHCP client state information for this netif */ /** the DHCP client state information for this netif */
struct dhcp *dhcp; struct dhcp *dhcp;
#endif #endif
/** number of bytes used in hwaddr */ /** number of bytes used in hwaddr */
u8_t hwaddr_len; u8_t hwaddr_len;
/** link level hardware address of this interface */ /** link level hardware address of this interface */
u8_t hwaddr[NETIF_MAX_HWADDR_LEN]; u8_t hwaddr[NETIF_MAX_HWADDR_LEN];
/** maximum transfer unit (in bytes) */ /** maximum transfer unit (in bytes) */
u16_t mtu; u16_t mtu;
/** flags (see NETIF_FLAG_ above) */ /** flags (see NETIF_FLAG_ above) */
u8_t flags; u8_t flags;
/** descriptive abbreviation */ /** descriptive abbreviation */
char name[2]; char name[2];
/** number of this interface */ /** number of this interface */
u8_t num; u8_t num;
#if LWIP_SNMP #if LWIP_SNMP
/** link type (ifType values per RFC1213) */ /** link type (ifType values per RFC1213) */
u8_t link_type; u8_t link_type;
/** (estimate) link speed */ /** (estimate) link speed */
u32_t link_speed; u32_t link_speed;
/** timestamp at last change made (up/down) */ /** timestamp at last change made (up/down) */
u32_t ts; u32_t ts;
/** counters */ /** counters */
u32_t ifinoctets; u32_t ifinoctets;
u32_t ifinucastpkts; u32_t ifinucastpkts;
u32_t ifinnucastpkts; u32_t ifinnucastpkts;
u32_t ifindiscards; u32_t ifindiscards;
u32_t ifoutoctets; u32_t ifoutoctets;
u32_t ifoutucastpkts; u32_t ifoutucastpkts;
u32_t ifoutnucastpkts; u32_t ifoutnucastpkts;
u32_t ifoutdiscards; u32_t ifoutdiscards;
#endif #endif
}; };
/** The list of network interfaces. */ /** The list of network interfaces. */
extern struct netif *netif_list; extern struct netif *netif_list;
/** The default network interface. */ /** The default network interface. */
extern struct netif *netif_default; extern struct netif *netif_default;
/* netif_init() must be called first. */ /* netif_init() must be called first. */
void netif_init(void); void netif_init(void);
struct netif *netif_add(struct netif *netif, struct ip_addr *ipaddr, struct ip_addr *netmask, struct netif *netif_add(struct netif *netif, struct ip_addr *ipaddr, struct ip_addr *netmask,
struct ip_addr *gw, struct ip_addr *gw,
void *state, void *state,
err_t (* init)(struct netif *netif), err_t (* init)(struct netif *netif),
err_t (* input)(struct pbuf *p, struct netif *netif)); err_t (* input)(struct pbuf *p, struct netif *netif));
void void
netif_set_addr(struct netif *netif,struct ip_addr *ipaddr, struct ip_addr *netmask, netif_set_addr(struct netif *netif,struct ip_addr *ipaddr, struct ip_addr *netmask,
struct ip_addr *gw); struct ip_addr *gw);
void netif_remove(struct netif * netif); void netif_remove(struct netif * netif);
/* Returns a network interface given its name. The name is of the form /* Returns a network interface given its name. The name is of the form
"et0", where the first two letters are the "name" field in the "et0", where the first two letters are the "name" field in the
netif structure, and the digit is in the num field in the same netif structure, and the digit is in the num field in the same
structure. */ structure. */
struct netif *netif_find(char *name); struct netif *netif_find(char *name);
void netif_set_default(struct netif *netif); void netif_set_default(struct netif *netif);
void netif_set_ipaddr(struct netif *netif, struct ip_addr *ipaddr); void netif_set_ipaddr(struct netif *netif, struct ip_addr *ipaddr);
void netif_set_netmask(struct netif *netif, struct ip_addr *netmast); void netif_set_netmask(struct netif *netif, struct ip_addr *netmast);
void netif_set_gw(struct netif *netif, struct ip_addr *gw); void netif_set_gw(struct netif *netif, struct ip_addr *gw);
void netif_set_up(struct netif *netif); void netif_set_up(struct netif *netif);
void netif_set_down(struct netif *netif); void netif_set_down(struct netif *netif);
u8_t netif_is_up(struct netif *netif); u8_t netif_is_up(struct netif *netif);
#endif /* __LWIP_NETIF_H__ */ #endif /* __LWIP_NETIF_H__ */

View file

@ -1,113 +1,113 @@
/* /*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science. * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, * 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products * 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE. * OF SUCH DAMAGE.
* *
* This file is part of the lwIP TCP/IP stack. * This file is part of the lwIP TCP/IP stack.
* *
* Author: Adam Dunkels <adam@sics.se> * Author: Adam Dunkels <adam@sics.se>
* *
*/ */
#ifndef __LWIP_PBUF_H__ #ifndef __LWIP_PBUF_H__
#define __LWIP_PBUF_H__ #define __LWIP_PBUF_H__
#include "arch/cc.h" #include "arch/cc.h"
#define PBUF_TRANSPORT_HLEN 20 #define PBUF_TRANSPORT_HLEN 20
#define PBUF_IP_HLEN 20 #define PBUF_IP_HLEN 20
typedef enum { typedef enum {
PBUF_TRANSPORT, PBUF_TRANSPORT,
PBUF_IP, PBUF_IP,
PBUF_LINK, PBUF_LINK,
PBUF_RAW PBUF_RAW
} pbuf_layer; } pbuf_layer;
typedef enum { typedef enum {
PBUF_RAM, PBUF_RAM,
PBUF_ROM, PBUF_ROM,
PBUF_REF, PBUF_REF,
PBUF_POOL PBUF_POOL
} pbuf_flag; } pbuf_flag;
/* Definitions for the pbuf flag field. These are NOT the flags that /* Definitions for the pbuf flag field. These are NOT the flags that
* are passed to pbuf_alloc(). */ * are passed to pbuf_alloc(). */
#define PBUF_FLAG_RAM 0x00U /* Flags that pbuf data is stored in RAM */ #define PBUF_FLAG_RAM 0x00U /* Flags that pbuf data is stored in RAM */
#define PBUF_FLAG_ROM 0x01U /* Flags that pbuf data is stored in ROM */ #define PBUF_FLAG_ROM 0x01U /* Flags that pbuf data is stored in ROM */
#define PBUF_FLAG_POOL 0x02U /* Flags that the pbuf comes from the pbuf pool */ #define PBUF_FLAG_POOL 0x02U /* Flags that the pbuf comes from the pbuf pool */
#define PBUF_FLAG_REF 0x04U /* Flags thet the pbuf payload refers to RAM */ #define PBUF_FLAG_REF 0x04U /* Flags thet the pbuf payload refers to RAM */
/** indicates this packet was broadcast on the link */ /** indicates this packet was broadcast on the link */
#define PBUF_FLAG_LINK_BROADCAST 0x80U #define PBUF_FLAG_LINK_BROADCAST 0x80U
struct pbuf { struct pbuf {
/** next pbuf in singly linked pbuf chain */ /** next pbuf in singly linked pbuf chain */
struct pbuf *next; struct pbuf *next;
/** pointer to the actual data in the buffer */ /** pointer to the actual data in the buffer */
void *payload; void *payload;
/** /**
* total length of this buffer and all next buffers in chain * total length of this buffer and all next buffers in chain
* belonging to the same packet. * belonging to the same packet.
* *
* For non-queue packet chains this is the invariant: * For non-queue packet chains this is the invariant:
* p->tot_len == p->len + (p->next? p->next->tot_len: 0) * p->tot_len == p->len + (p->next? p->next->tot_len: 0)
*/ */
u16_t tot_len; u16_t tot_len;
/** length of this buffer */ /** length of this buffer */
u16_t len; u16_t len;
/** flags telling the type of pbuf, see PBUF_FLAG_ */ /** flags telling the type of pbuf, see PBUF_FLAG_ */
u16_t flags; u16_t flags;
/** /**
* the reference count always equals the number of pointers * the reference count always equals the number of pointers
* that refer to this pbuf. This can be pointers from an application, * that refer to this pbuf. This can be pointers from an application,
* the stack itself, or pbuf->next pointers from a chain. * the stack itself, or pbuf->next pointers from a chain.
*/ */
u16_t ref; u16_t ref;
}; };
void pbuf_init(void); void pbuf_init(void);
struct pbuf *pbuf_alloc(pbuf_layer l, u16_t size, pbuf_flag flag); struct pbuf *pbuf_alloc(pbuf_layer l, u16_t size, pbuf_flag flag);
void pbuf_realloc(struct pbuf *p, u16_t size); void pbuf_realloc(struct pbuf *p, u16_t size);
u8_t pbuf_header(struct pbuf *p, s16_t header_size); u8_t pbuf_header(struct pbuf *p, s16_t header_size);
void pbuf_ref(struct pbuf *p); void pbuf_ref(struct pbuf *p);
void pbuf_ref_chain(struct pbuf *p); void pbuf_ref_chain(struct pbuf *p);
u8_t pbuf_free(struct pbuf *p); u8_t pbuf_free(struct pbuf *p);
u8_t pbuf_clen(struct pbuf *p); u8_t pbuf_clen(struct pbuf *p);
void pbuf_cat(struct pbuf *h, struct pbuf *t); void pbuf_cat(struct pbuf *h, struct pbuf *t);
void pbuf_chain(struct pbuf *h, struct pbuf *t); void pbuf_chain(struct pbuf *h, struct pbuf *t);
struct pbuf *pbuf_take(struct pbuf *f); struct pbuf *pbuf_take(struct pbuf *f);
struct pbuf *pbuf_dechain(struct pbuf *p); struct pbuf *pbuf_dechain(struct pbuf *p);
void pbuf_queue(struct pbuf *p, struct pbuf *n); void pbuf_queue(struct pbuf *p, struct pbuf *n);
struct pbuf * pbuf_dequeue(struct pbuf *p); struct pbuf * pbuf_dequeue(struct pbuf *p);
#endif /* __LWIP_PBUF_H__ */ #endif /* __LWIP_PBUF_H__ */

View file

@ -1,74 +1,74 @@
/* /*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science. * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, * 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products * 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE. * OF SUCH DAMAGE.
* *
* This file is part of the lwIP TCP/IP stack. * This file is part of the lwIP TCP/IP stack.
* *
* Author: Adam Dunkels <adam@sics.se> * Author: Adam Dunkels <adam@sics.se>
* *
*/ */
#ifndef __LWIP_RAW_H__ #ifndef __LWIP_RAW_H__
#define __LWIP_RAW_H__ #define __LWIP_RAW_H__
#include "lwip/arch.h" #include "lwip/arch.h"
#include "lwip/pbuf.h" #include "lwip/pbuf.h"
#include "lwip/inet.h" #include "lwip/inet.h"
#include "lwip/ip.h" #include "lwip/ip.h"
struct raw_pcb { struct raw_pcb {
/* Common members of all PCB types */ /* Common members of all PCB types */
IP_PCB; IP_PCB;
struct raw_pcb *next; struct raw_pcb *next;
u16_t protocol; u16_t protocol;
u8_t (* recv)(void *arg, struct raw_pcb *pcb, struct pbuf *p, u8_t (* recv)(void *arg, struct raw_pcb *pcb, struct pbuf *p,
struct ip_addr *addr); struct ip_addr *addr);
void *recv_arg; void *recv_arg;
}; };
/* The following functions is the application layer interface to the /* The following functions is the application layer interface to the
RAW code. */ RAW code. */
struct raw_pcb * raw_new (u16_t proto); struct raw_pcb * raw_new (u16_t proto);
void raw_remove (struct raw_pcb *pcb); void raw_remove (struct raw_pcb *pcb);
err_t raw_bind (struct raw_pcb *pcb, struct ip_addr *ipaddr); err_t raw_bind (struct raw_pcb *pcb, struct ip_addr *ipaddr);
err_t raw_connect (struct raw_pcb *pcb, struct ip_addr *ipaddr); err_t raw_connect (struct raw_pcb *pcb, struct ip_addr *ipaddr);
void raw_recv (struct raw_pcb *pcb, void raw_recv (struct raw_pcb *pcb,
u8_t (* recv)(void *arg, struct raw_pcb *pcb, u8_t (* recv)(void *arg, struct raw_pcb *pcb,
struct pbuf *p, struct pbuf *p,
struct ip_addr *addr), struct ip_addr *addr),
void *recv_arg); void *recv_arg);
err_t raw_sendto (struct raw_pcb *pcb, struct pbuf *p, struct ip_addr *ipaddr); err_t raw_sendto (struct raw_pcb *pcb, struct pbuf *p, struct ip_addr *ipaddr);
err_t raw_send (struct raw_pcb *pcb, struct pbuf *p); err_t raw_send (struct raw_pcb *pcb, struct pbuf *p);
/* The following functions are the lower layer interface to RAW. */ /* The following functions are the lower layer interface to RAW. */
u8_t raw_input (struct pbuf *p, struct netif *inp); u8_t raw_input (struct pbuf *p, struct netif *inp);
void raw_init (void); void raw_init (void);
#endif /* __LWIP_RAW_H__ */ #endif /* __LWIP_RAW_H__ */

View file

@ -1,63 +1,63 @@
/* /*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science. * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, * 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products * 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE. * OF SUCH DAMAGE.
* *
* This file is part of the lwIP TCP/IP stack. * This file is part of the lwIP TCP/IP stack.
*/ */
/* /*
* This is the interface to the platform specific serial IO module * This is the interface to the platform specific serial IO module
* It needs to be implemented by those platforms which need SLIP or PPP * It needs to be implemented by those platforms which need SLIP or PPP
*/ */
#include "arch/cc.h" #include "arch/cc.h"
#ifndef __sio_fd_t_defined #ifndef __sio_fd_t_defined
typedef void * sio_fd_t; typedef void * sio_fd_t;
#endif #endif
#ifndef sio_open #ifndef sio_open
sio_fd_t sio_open(u8_t); sio_fd_t sio_open(u8_t);
#endif #endif
#ifndef sio_send #ifndef sio_send
void sio_send(u8_t, sio_fd_t); void sio_send(u8_t, sio_fd_t);
#endif #endif
#ifndef sio_recv #ifndef sio_recv
u8_t sio_recv(sio_fd_t); u8_t sio_recv(sio_fd_t);
#endif #endif
#ifndef sio_read #ifndef sio_read
u32_t sio_read(sio_fd_t, u8_t *, u32_t); u32_t sio_read(sio_fd_t, u8_t *, u32_t);
#endif #endif
#ifndef sio_write #ifndef sio_write
u32_t sio_write(sio_fd_t, u8_t *, u32_t); u32_t sio_write(sio_fd_t, u8_t *, u32_t);
#endif #endif
#ifndef sio_read_abort #ifndef sio_read_abort
void sio_read_abort(sio_fd_t); void sio_read_abort(sio_fd_t);
#endif #endif

View file

@ -1,309 +1,309 @@
/* /*
* Copyright (c) 2001, 2002 Leon Woestenberg <leon.woestenberg@axon.tv> * Copyright (c) 2001, 2002 Leon Woestenberg <leon.woestenberg@axon.tv>
* Copyright (c) 2001, 2002 Axon Digital Design B.V., The Netherlands. * Copyright (c) 2001, 2002 Axon Digital Design B.V., The Netherlands.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, * 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products * 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE. * OF SUCH DAMAGE.
* *
* This file is part of the lwIP TCP/IP stack. * This file is part of the lwIP TCP/IP stack.
* *
* Author: Leon Woestenberg <leon.woestenberg@axon.tv> * Author: Leon Woestenberg <leon.woestenberg@axon.tv>
* *
*/ */
#ifndef __LWIP_SNMP_H__ #ifndef __LWIP_SNMP_H__
#define __LWIP_SNMP_H__ #define __LWIP_SNMP_H__
#include "lwip/opt.h" #include "lwip/opt.h"
#include "lwip/netif.h" #include "lwip/netif.h"
#include "lwip/udp.h" #include "lwip/udp.h"
/* SNMP support available? */ /* SNMP support available? */
#if defined(LWIP_SNMP) && (LWIP_SNMP > 0) #if defined(LWIP_SNMP) && (LWIP_SNMP > 0)
/** fixed maximum length for object identifier type */ /** fixed maximum length for object identifier type */
#define LWIP_SNMP_OBJ_ID_LEN 32 #define LWIP_SNMP_OBJ_ID_LEN 32
/** internal object identifier representation */ /** internal object identifier representation */
struct snmp_obj_id struct snmp_obj_id
{ {
u8_t len; u8_t len;
s32_t id[LWIP_SNMP_OBJ_ID_LEN]; s32_t id[LWIP_SNMP_OBJ_ID_LEN];
}; };
/* system */ /* system */
void snmp_set_sysdesr(u8_t* str, u8_t* strlen); void snmp_set_sysdesr(u8_t* str, u8_t* strlen);
void snmp_set_sysobjid(struct snmp_obj_id *oid); void snmp_set_sysobjid(struct snmp_obj_id *oid);
void snmp_get_sysobjid_ptr(struct snmp_obj_id **oid); void snmp_get_sysobjid_ptr(struct snmp_obj_id **oid);
void snmp_inc_sysuptime(void); void snmp_inc_sysuptime(void);
void snmp_get_sysuptime(u32_t *value); void snmp_get_sysuptime(u32_t *value);
void snmp_set_syscontact(u8_t *ocstr, u8_t *ocstrlen); void snmp_set_syscontact(u8_t *ocstr, u8_t *ocstrlen);
void snmp_set_sysname(u8_t *ocstr, u8_t *ocstrlen); void snmp_set_sysname(u8_t *ocstr, u8_t *ocstrlen);
void snmp_set_syslocation(u8_t *ocstr, u8_t *ocstrlen); void snmp_set_syslocation(u8_t *ocstr, u8_t *ocstrlen);
/* network interface */ /* network interface */
void snmp_add_ifinoctets(struct netif *ni, u32_t value); void snmp_add_ifinoctets(struct netif *ni, u32_t value);
void snmp_inc_ifinucastpkts(struct netif *ni); void snmp_inc_ifinucastpkts(struct netif *ni);
void snmp_inc_ifinnucastpkts(struct netif *ni); void snmp_inc_ifinnucastpkts(struct netif *ni);
void snmp_inc_ifindiscards(struct netif *ni); void snmp_inc_ifindiscards(struct netif *ni);
void snmp_add_ifoutoctets(struct netif *ni, u32_t value); void snmp_add_ifoutoctets(struct netif *ni, u32_t value);
void snmp_inc_ifoutucastpkts(struct netif *ni); void snmp_inc_ifoutucastpkts(struct netif *ni);
void snmp_inc_ifoutnucastpkts(struct netif *ni); void snmp_inc_ifoutnucastpkts(struct netif *ni);
void snmp_inc_ifoutdiscards(struct netif *ni); void snmp_inc_ifoutdiscards(struct netif *ni);
void snmp_inc_iflist(void); void snmp_inc_iflist(void);
void snmp_dec_iflist(void); void snmp_dec_iflist(void);
/* ARP (for atTable and ipNetToMediaTable) */ /* ARP (for atTable and ipNetToMediaTable) */
void snmp_insert_arpidx_tree(struct netif *ni, struct ip_addr *ip); void snmp_insert_arpidx_tree(struct netif *ni, struct ip_addr *ip);
void snmp_delete_arpidx_tree(struct netif *ni, struct ip_addr *ip); void snmp_delete_arpidx_tree(struct netif *ni, struct ip_addr *ip);
/* IP */ /* IP */
void snmp_inc_ipinreceives(void); void snmp_inc_ipinreceives(void);
void snmp_inc_ipinhdrerrors(void); void snmp_inc_ipinhdrerrors(void);
void snmp_inc_ipinaddrerrors(void); void snmp_inc_ipinaddrerrors(void);
void snmp_inc_ipforwdatagrams(void); void snmp_inc_ipforwdatagrams(void);
void snmp_inc_ipinunknownprotos(void); void snmp_inc_ipinunknownprotos(void);
void snmp_inc_ipindiscards(void); void snmp_inc_ipindiscards(void);
void snmp_inc_ipindelivers(void); void snmp_inc_ipindelivers(void);
void snmp_inc_ipoutrequests(void); void snmp_inc_ipoutrequests(void);
void snmp_inc_ipoutdiscards(void); void snmp_inc_ipoutdiscards(void);
void snmp_inc_ipoutnoroutes(void); void snmp_inc_ipoutnoroutes(void);
void snmp_inc_ipreasmreqds(void); void snmp_inc_ipreasmreqds(void);
void snmp_inc_ipreasmoks(void); void snmp_inc_ipreasmoks(void);
void snmp_inc_ipreasmfails(void); void snmp_inc_ipreasmfails(void);
void snmp_inc_ipfragoks(void); void snmp_inc_ipfragoks(void);
void snmp_inc_ipfragfails(void); void snmp_inc_ipfragfails(void);
void snmp_inc_ipfragcreates(void); void snmp_inc_ipfragcreates(void);
void snmp_inc_iproutingdiscards(void); void snmp_inc_iproutingdiscards(void);
void snmp_insert_ipaddridx_tree(struct netif *ni); void snmp_insert_ipaddridx_tree(struct netif *ni);
void snmp_delete_ipaddridx_tree(struct netif *ni); void snmp_delete_ipaddridx_tree(struct netif *ni);
void snmp_insert_iprteidx_tree(u8_t dflt, struct netif *ni); void snmp_insert_iprteidx_tree(u8_t dflt, struct netif *ni);
void snmp_delete_iprteidx_tree(u8_t dflt, struct netif *ni); void snmp_delete_iprteidx_tree(u8_t dflt, struct netif *ni);
/* ICMP */ /* ICMP */
void snmp_inc_icmpinmsgs(void); void snmp_inc_icmpinmsgs(void);
void snmp_inc_icmpinerrors(void); void snmp_inc_icmpinerrors(void);
void snmp_inc_icmpindestunreachs(void); void snmp_inc_icmpindestunreachs(void);
void snmp_inc_icmpintimeexcds(void); void snmp_inc_icmpintimeexcds(void);
void snmp_inc_icmpinparmprobs(void); void snmp_inc_icmpinparmprobs(void);
void snmp_inc_icmpinsrcquenchs(void); void snmp_inc_icmpinsrcquenchs(void);
void snmp_inc_icmpinredirects(void); void snmp_inc_icmpinredirects(void);
void snmp_inc_icmpinechos(void); void snmp_inc_icmpinechos(void);
void snmp_inc_icmpinechoreps(void); void snmp_inc_icmpinechoreps(void);
void snmp_inc_icmpintimestamps(void); void snmp_inc_icmpintimestamps(void);
void snmp_inc_icmpintimestampreps(void); void snmp_inc_icmpintimestampreps(void);
void snmp_inc_icmpinaddrmasks(void); void snmp_inc_icmpinaddrmasks(void);
void snmp_inc_icmpinaddrmaskreps(void); void snmp_inc_icmpinaddrmaskreps(void);
void snmp_inc_icmpoutmsgs(void); void snmp_inc_icmpoutmsgs(void);
void snmp_inc_icmpouterrors(void); void snmp_inc_icmpouterrors(void);
void snmp_inc_icmpoutdestunreachs(void); void snmp_inc_icmpoutdestunreachs(void);
void snmp_inc_icmpouttimeexcds(void); void snmp_inc_icmpouttimeexcds(void);
void snmp_inc_icmpoutparmprobs(void); void snmp_inc_icmpoutparmprobs(void);
void snmp_inc_icmpoutsrcquenchs(void); void snmp_inc_icmpoutsrcquenchs(void);
void snmp_inc_icmpoutredirects(void); void snmp_inc_icmpoutredirects(void);
void snmp_inc_icmpoutechos(void); void snmp_inc_icmpoutechos(void);
void snmp_inc_icmpoutechoreps(void); void snmp_inc_icmpoutechoreps(void);
void snmp_inc_icmpouttimestamps(void); void snmp_inc_icmpouttimestamps(void);
void snmp_inc_icmpouttimestampreps(void); void snmp_inc_icmpouttimestampreps(void);
void snmp_inc_icmpoutaddrmasks(void); void snmp_inc_icmpoutaddrmasks(void);
void snmp_inc_icmpoutaddrmaskreps(void); void snmp_inc_icmpoutaddrmaskreps(void);
/* TCP */ /* TCP */
void snmp_inc_tcpactiveopens(void); void snmp_inc_tcpactiveopens(void);
void snmp_inc_tcppassiveopens(void); void snmp_inc_tcppassiveopens(void);
void snmp_inc_tcpattemptfails(void); void snmp_inc_tcpattemptfails(void);
void snmp_inc_tcpestabresets(void); void snmp_inc_tcpestabresets(void);
void snmp_inc_tcpinsegs(void); void snmp_inc_tcpinsegs(void);
void snmp_inc_tcpoutsegs(void); void snmp_inc_tcpoutsegs(void);
void snmp_inc_tcpretranssegs(void); void snmp_inc_tcpretranssegs(void);
void snmp_inc_tcpinerrs(void); void snmp_inc_tcpinerrs(void);
void snmp_inc_tcpoutrsts(void); void snmp_inc_tcpoutrsts(void);
/* UDP */ /* UDP */
void snmp_inc_udpindatagrams(void); void snmp_inc_udpindatagrams(void);
void snmp_inc_udpnoports(void); void snmp_inc_udpnoports(void);
void snmp_inc_udpinerrors(void); void snmp_inc_udpinerrors(void);
void snmp_inc_udpoutdatagrams(void); void snmp_inc_udpoutdatagrams(void);
void snmp_insert_udpidx_tree(struct udp_pcb *pcb); void snmp_insert_udpidx_tree(struct udp_pcb *pcb);
void snmp_delete_udpidx_tree(struct udp_pcb *pcb); void snmp_delete_udpidx_tree(struct udp_pcb *pcb);
/* SNMP */ /* SNMP */
void snmp_inc_snmpinpkts(void); void snmp_inc_snmpinpkts(void);
void snmp_inc_snmpoutpkts(void); void snmp_inc_snmpoutpkts(void);
void snmp_inc_snmpinbadversions(void); void snmp_inc_snmpinbadversions(void);
void snmp_inc_snmpinbadcommunitynames(void); void snmp_inc_snmpinbadcommunitynames(void);
void snmp_inc_snmpinbadcommunityuses(void); void snmp_inc_snmpinbadcommunityuses(void);
void snmp_inc_snmpinasnparseerrs(void); void snmp_inc_snmpinasnparseerrs(void);
void snmp_inc_snmpintoobigs(void); void snmp_inc_snmpintoobigs(void);
void snmp_inc_snmpinnosuchnames(void); void snmp_inc_snmpinnosuchnames(void);
void snmp_inc_snmpinbadvalues(void); void snmp_inc_snmpinbadvalues(void);
void snmp_inc_snmpinreadonlys(void); void snmp_inc_snmpinreadonlys(void);
void snmp_inc_snmpingenerrs(void); void snmp_inc_snmpingenerrs(void);
void snmp_add_snmpintotalreqvars(u8_t value); void snmp_add_snmpintotalreqvars(u8_t value);
void snmp_add_snmpintotalsetvars(u8_t value); void snmp_add_snmpintotalsetvars(u8_t value);
void snmp_inc_snmpingetrequests(void); void snmp_inc_snmpingetrequests(void);
void snmp_inc_snmpingetnexts(void); void snmp_inc_snmpingetnexts(void);
void snmp_inc_snmpinsetrequests(void); void snmp_inc_snmpinsetrequests(void);
void snmp_inc_snmpingetresponses(void); void snmp_inc_snmpingetresponses(void);
void snmp_inc_snmpintraps(void); void snmp_inc_snmpintraps(void);
void snmp_inc_snmpouttoobigs(void); void snmp_inc_snmpouttoobigs(void);
void snmp_inc_snmpoutnosuchnames(void); void snmp_inc_snmpoutnosuchnames(void);
void snmp_inc_snmpoutbadvalues(void); void snmp_inc_snmpoutbadvalues(void);
void snmp_inc_snmpoutgenerrs(void); void snmp_inc_snmpoutgenerrs(void);
void snmp_inc_snmpoutgetrequests(void); void snmp_inc_snmpoutgetrequests(void);
void snmp_inc_snmpoutgetnexts(void); void snmp_inc_snmpoutgetnexts(void);
void snmp_inc_snmpoutsetrequests(void); void snmp_inc_snmpoutsetrequests(void);
void snmp_inc_snmpoutgetresponses(void); void snmp_inc_snmpoutgetresponses(void);
void snmp_inc_snmpouttraps(void); void snmp_inc_snmpouttraps(void);
void snmp_get_snmpgrpid_ptr(struct snmp_obj_id **oid); void snmp_get_snmpgrpid_ptr(struct snmp_obj_id **oid);
void snmp_set_snmpenableauthentraps(u8_t *value); void snmp_set_snmpenableauthentraps(u8_t *value);
void snmp_get_snmpenableauthentraps(u8_t *value); void snmp_get_snmpenableauthentraps(u8_t *value);
/* LWIP_SNMP support not available */ /* LWIP_SNMP support not available */
/* define everything to be empty */ /* define everything to be empty */
#else #else
/* system */ /* system */
#define snmp_set_sysdesr(str, strlen) #define snmp_set_sysdesr(str, strlen)
#define snmp_get_sysobjid_ptr(oid) #define snmp_get_sysobjid_ptr(oid)
#define snmp_inc_sysuptime() #define snmp_inc_sysuptime()
#define snmp_get_sysuptime(value) #define snmp_get_sysuptime(value)
/* network interface */ /* network interface */
#define snmp_add_ifinoctets(ni,value) #define snmp_add_ifinoctets(ni,value)
#define snmp_inc_ifinucastpkts(ni) #define snmp_inc_ifinucastpkts(ni)
#define snmp_inc_ifinnucastpkts(ni) #define snmp_inc_ifinnucastpkts(ni)
#define snmp_inc_ifindiscards(ni) #define snmp_inc_ifindiscards(ni)
#define snmp_add_ifoutoctets(ni,value) #define snmp_add_ifoutoctets(ni,value)
#define snmp_inc_ifoutucastpkts(ni) #define snmp_inc_ifoutucastpkts(ni)
#define snmp_inc_ifoutnucastpkts(ni) #define snmp_inc_ifoutnucastpkts(ni)
#define snmp_inc_ifoutdiscards(ni) #define snmp_inc_ifoutdiscards(ni)
#define snmp_inc_iflist() #define snmp_inc_iflist()
#define snmp_dec_iflist() #define snmp_dec_iflist()
/* ARP */ /* ARP */
#define snmp_insert_arpidx_tree(ni,ip) #define snmp_insert_arpidx_tree(ni,ip)
#define snmp_delete_arpidx_tree(ni,ip) #define snmp_delete_arpidx_tree(ni,ip)
/* IP */ /* IP */
#define snmp_inc_ipinreceives() #define snmp_inc_ipinreceives()
#define snmp_inc_ipinhdrerrors() #define snmp_inc_ipinhdrerrors()
#define snmp_inc_ipinaddrerrors() #define snmp_inc_ipinaddrerrors()
#define snmp_inc_ipforwdatagrams() #define snmp_inc_ipforwdatagrams()
#define snmp_inc_ipinunknownprotos() #define snmp_inc_ipinunknownprotos()
#define snmp_inc_ipindiscards() #define snmp_inc_ipindiscards()
#define snmp_inc_ipindelivers() #define snmp_inc_ipindelivers()
#define snmp_inc_ipoutrequests() #define snmp_inc_ipoutrequests()
#define snmp_inc_ipoutdiscards() #define snmp_inc_ipoutdiscards()
#define snmp_inc_ipoutnoroutes() #define snmp_inc_ipoutnoroutes()
#define snmp_inc_ipreasmreqds() #define snmp_inc_ipreasmreqds()
#define snmp_inc_ipreasmoks() #define snmp_inc_ipreasmoks()
#define snmp_inc_ipreasmfails() #define snmp_inc_ipreasmfails()
#define snmp_inc_ipfragoks() #define snmp_inc_ipfragoks()
#define snmp_inc_ipfragfails() #define snmp_inc_ipfragfails()
#define snmp_inc_ipfragcreates() #define snmp_inc_ipfragcreates()
#define snmp_inc_iproutingdiscards() #define snmp_inc_iproutingdiscards()
#define snmp_insert_ipaddridx_tree(ni) #define snmp_insert_ipaddridx_tree(ni)
#define snmp_delete_ipaddridx_tree(ni) #define snmp_delete_ipaddridx_tree(ni)
#define snmp_insert_iprteidx_tree(dflt, ni) #define snmp_insert_iprteidx_tree(dflt, ni)
#define snmp_delete_iprteidx_tree(dflt, ni) #define snmp_delete_iprteidx_tree(dflt, ni)
/* ICMP */ /* ICMP */
#define snmp_inc_icmpinmsgs() #define snmp_inc_icmpinmsgs()
#define snmp_inc_icmpinerrors() #define snmp_inc_icmpinerrors()
#define snmp_inc_icmpindestunreachs() #define snmp_inc_icmpindestunreachs()
#define snmp_inc_icmpintimeexcds() #define snmp_inc_icmpintimeexcds()
#define snmp_inc_icmpinparmprobs() #define snmp_inc_icmpinparmprobs()
#define snmp_inc_icmpinsrcquenchs() #define snmp_inc_icmpinsrcquenchs()
#define snmp_inc_icmpinredirects() #define snmp_inc_icmpinredirects()
#define snmp_inc_icmpinechos() #define snmp_inc_icmpinechos()
#define snmp_inc_icmpinechoreps() #define snmp_inc_icmpinechoreps()
#define snmp_inc_icmpintimestamps() #define snmp_inc_icmpintimestamps()
#define snmp_inc_icmpintimestampreps() #define snmp_inc_icmpintimestampreps()
#define snmp_inc_icmpinaddrmasks() #define snmp_inc_icmpinaddrmasks()
#define snmp_inc_icmpinaddrmaskreps() #define snmp_inc_icmpinaddrmaskreps()
#define snmp_inc_icmpoutmsgs() #define snmp_inc_icmpoutmsgs()
#define snmp_inc_icmpouterrors() #define snmp_inc_icmpouterrors()
#define snmp_inc_icmpoutdestunreachs() #define snmp_inc_icmpoutdestunreachs()
#define snmp_inc_icmpouttimeexcds() #define snmp_inc_icmpouttimeexcds()
#define snmp_inc_icmpoutparmprobs() #define snmp_inc_icmpoutparmprobs()
#define snmp_inc_icmpoutsrcquenchs() #define snmp_inc_icmpoutsrcquenchs()
#define snmp_inc_icmpoutredirects() #define snmp_inc_icmpoutredirects()
#define snmp_inc_icmpoutechos() #define snmp_inc_icmpoutechos()
#define snmp_inc_icmpoutechoreps() #define snmp_inc_icmpoutechoreps()
#define snmp_inc_icmpouttimestamps() #define snmp_inc_icmpouttimestamps()
#define snmp_inc_icmpouttimestampreps() #define snmp_inc_icmpouttimestampreps()
#define snmp_inc_icmpoutaddrmasks() #define snmp_inc_icmpoutaddrmasks()
#define snmp_inc_icmpoutaddrmaskreps() #define snmp_inc_icmpoutaddrmaskreps()
/* TCP */ /* TCP */
#define snmp_inc_tcpactiveopens() #define snmp_inc_tcpactiveopens()
#define snmp_inc_tcppassiveopens() #define snmp_inc_tcppassiveopens()
#define snmp_inc_tcpattemptfails() #define snmp_inc_tcpattemptfails()
#define snmp_inc_tcpestabresets() #define snmp_inc_tcpestabresets()
#define snmp_inc_tcpinsegs() #define snmp_inc_tcpinsegs()
#define snmp_inc_tcpoutsegs() #define snmp_inc_tcpoutsegs()
#define snmp_inc_tcpretranssegs() #define snmp_inc_tcpretranssegs()
#define snmp_inc_tcpinerrs() #define snmp_inc_tcpinerrs()
#define snmp_inc_tcpoutrsts() #define snmp_inc_tcpoutrsts()
/* UDP */ /* UDP */
#define snmp_inc_udpindatagrams() #define snmp_inc_udpindatagrams()
#define snmp_inc_udpnoports() #define snmp_inc_udpnoports()
#define snmp_inc_udpinerrors() #define snmp_inc_udpinerrors()
#define snmp_inc_udpoutdatagrams() #define snmp_inc_udpoutdatagrams()
#define snmp_insert_udpidx_tree(pcb) #define snmp_insert_udpidx_tree(pcb)
#define snmp_delete_udpidx_tree(pcb) #define snmp_delete_udpidx_tree(pcb)
/* SNMP */ /* SNMP */
#define snmp_inc_snmpinpkts() #define snmp_inc_snmpinpkts()
#define snmp_inc_snmpoutpkts() #define snmp_inc_snmpoutpkts()
#define snmp_inc_snmpinbadversions() #define snmp_inc_snmpinbadversions()
#define snmp_inc_snmpinbadcommunitynames() #define snmp_inc_snmpinbadcommunitynames()
#define snmp_inc_snmpinbadcommunityuses() #define snmp_inc_snmpinbadcommunityuses()
#define snmp_inc_snmpinasnparseerrs() #define snmp_inc_snmpinasnparseerrs()
#define snmp_inc_snmpintoobigs() #define snmp_inc_snmpintoobigs()
#define snmp_inc_snmpinnosuchnames() #define snmp_inc_snmpinnosuchnames()
#define snmp_inc_snmpinbadvalues() #define snmp_inc_snmpinbadvalues()
#define snmp_inc_snmpinreadonlys() #define snmp_inc_snmpinreadonlys()
#define snmp_inc_snmpingenerrs() #define snmp_inc_snmpingenerrs()
#define snmp_add_snmpintotalreqvars(value) #define snmp_add_snmpintotalreqvars(value)
#define snmp_add_snmpintotalsetvars(value) #define snmp_add_snmpintotalsetvars(value)
#define snmp_inc_snmpingetrequests() #define snmp_inc_snmpingetrequests()
#define snmp_inc_snmpingetnexts() #define snmp_inc_snmpingetnexts()
#define snmp_inc_snmpinsetrequests() #define snmp_inc_snmpinsetrequests()
#define snmp_inc_snmpingetresponses() #define snmp_inc_snmpingetresponses()
#define snmp_inc_snmpintraps() #define snmp_inc_snmpintraps()
#define snmp_inc_snmpouttoobigs() #define snmp_inc_snmpouttoobigs()
#define snmp_inc_snmpoutnosuchnames() #define snmp_inc_snmpoutnosuchnames()
#define snmp_inc_snmpoutbadvalues() #define snmp_inc_snmpoutbadvalues()
#define snmp_inc_snmpoutgenerrs() #define snmp_inc_snmpoutgenerrs()
#define snmp_inc_snmpoutgetrequests() #define snmp_inc_snmpoutgetrequests()
#define snmp_inc_snmpoutgetnexts() #define snmp_inc_snmpoutgetnexts()
#define snmp_inc_snmpoutsetrequests() #define snmp_inc_snmpoutsetrequests()
#define snmp_inc_snmpoutgetresponses() #define snmp_inc_snmpoutgetresponses()
#define snmp_inc_snmpouttraps() #define snmp_inc_snmpouttraps()
#define snmp_get_snmpgrpid_ptr(oid) #define snmp_get_snmpgrpid_ptr(oid)
#define snmp_set_snmpenableauthentraps(value) #define snmp_set_snmpenableauthentraps(value)
#define snmp_get_snmpenableauthentraps(value) #define snmp_get_snmpenableauthentraps(value)
#endif #endif
#endif /* __LWIP_SNMP_H__ */ #endif /* __LWIP_SNMP_H__ */

View file

@ -1,90 +1,90 @@
/** /**
* @file * @file
* Abstract Syntax Notation One (ISO 8824, 8825) codec. * Abstract Syntax Notation One (ISO 8824, 8825) codec.
*/ */
/* /*
* Copyright (c) 2006 Axon Digital Design B.V., The Netherlands. * Copyright (c) 2006 Axon Digital Design B.V., The Netherlands.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, * 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products * 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE. * OF SUCH DAMAGE.
* *
* Author: Christiaan Simons <christiaan.simons@axon.tv> * Author: Christiaan Simons <christiaan.simons@axon.tv>
*/ */
#ifndef __LWIP_SNMP_ASN1_H__ #ifndef __LWIP_SNMP_ASN1_H__
#define __LWIP_SNMP_ASN1_H__ #define __LWIP_SNMP_ASN1_H__
#include "lwip/opt.h" #include "lwip/opt.h"
#include "arch/cc.h" #include "arch/cc.h"
#include "lwip/err.h" #include "lwip/err.h"
#include "lwip/pbuf.h" #include "lwip/pbuf.h"
#include "lwip/snmp.h" #include "lwip/snmp.h"
#define SNMP_ASN1_UNIV (!0x80 | !0x40) #define SNMP_ASN1_UNIV (!0x80 | !0x40)
#define SNMP_ASN1_APPLIC (!0x80 | 0x40) #define SNMP_ASN1_APPLIC (!0x80 | 0x40)
#define SNMP_ASN1_CONTXT ( 0x80 | !0x40) #define SNMP_ASN1_CONTXT ( 0x80 | !0x40)
#define SNMP_ASN1_CONSTR (0x20) #define SNMP_ASN1_CONSTR (0x20)
#define SNMP_ASN1_PRIMIT (!0x20) #define SNMP_ASN1_PRIMIT (!0x20)
/* universal tags */ /* universal tags */
#define SNMP_ASN1_INTEG 2 #define SNMP_ASN1_INTEG 2
#define SNMP_ASN1_OC_STR 4 #define SNMP_ASN1_OC_STR 4
#define SNMP_ASN1_NUL 5 #define SNMP_ASN1_NUL 5
#define SNMP_ASN1_OBJ_ID 6 #define SNMP_ASN1_OBJ_ID 6
#define SNMP_ASN1_SEQ 16 #define SNMP_ASN1_SEQ 16
/* application specific (SNMP) tags */ /* application specific (SNMP) tags */
#define SNMP_ASN1_IPADDR 0 /* octet string size(4) */ #define SNMP_ASN1_IPADDR 0 /* octet string size(4) */
#define SNMP_ASN1_COUNTER 1 /* u32_t */ #define SNMP_ASN1_COUNTER 1 /* u32_t */
#define SNMP_ASN1_GAUGE 2 /* u32_t */ #define SNMP_ASN1_GAUGE 2 /* u32_t */
#define SNMP_ASN1_TIMETICKS 3 /* u32_t */ #define SNMP_ASN1_TIMETICKS 3 /* u32_t */
#define SNMP_ASN1_OPAQUE 4 /* octet string */ #define SNMP_ASN1_OPAQUE 4 /* octet string */
/* context specific (SNMP) tags */ /* context specific (SNMP) tags */
#define SNMP_ASN1_PDU_GET_REQ 0 #define SNMP_ASN1_PDU_GET_REQ 0
#define SNMP_ASN1_PDU_GET_NEXT_REQ 1 #define SNMP_ASN1_PDU_GET_NEXT_REQ 1
#define SNMP_ASN1_PDU_GET_RESP 2 #define SNMP_ASN1_PDU_GET_RESP 2
#define SNMP_ASN1_PDU_SET_REQ 3 #define SNMP_ASN1_PDU_SET_REQ 3
#define SNMP_ASN1_PDU_TRAP 4 #define SNMP_ASN1_PDU_TRAP 4
err_t snmp_asn1_dec_type(struct pbuf *p, u16_t ofs, u8_t *type); err_t snmp_asn1_dec_type(struct pbuf *p, u16_t ofs, u8_t *type);
err_t snmp_asn1_dec_length(struct pbuf *p, u16_t ofs, u8_t *octets_used, u16_t *length); err_t snmp_asn1_dec_length(struct pbuf *p, u16_t ofs, u8_t *octets_used, u16_t *length);
err_t snmp_asn1_dec_u32t(struct pbuf *p, u16_t ofs, u16_t len, u32_t *value); err_t snmp_asn1_dec_u32t(struct pbuf *p, u16_t ofs, u16_t len, u32_t *value);
err_t snmp_asn1_dec_s32t(struct pbuf *p, u16_t ofs, u16_t len, s32_t *value); err_t snmp_asn1_dec_s32t(struct pbuf *p, u16_t ofs, u16_t len, s32_t *value);
err_t snmp_asn1_dec_oid(struct pbuf *p, u16_t ofs, u16_t len, struct snmp_obj_id *oid); err_t snmp_asn1_dec_oid(struct pbuf *p, u16_t ofs, u16_t len, struct snmp_obj_id *oid);
err_t snmp_asn1_dec_raw(struct pbuf *p, u16_t ofs, u16_t len, u16_t raw_len, u8_t *raw); err_t snmp_asn1_dec_raw(struct pbuf *p, u16_t ofs, u16_t len, u16_t raw_len, u8_t *raw);
void snmp_asn1_enc_length_cnt(u16_t length, u8_t *octets_needed); void snmp_asn1_enc_length_cnt(u16_t length, u8_t *octets_needed);
void snmp_asn1_enc_u32t_cnt(u32_t value, u16_t *octets_needed); void snmp_asn1_enc_u32t_cnt(u32_t value, u16_t *octets_needed);
void snmp_asn1_enc_s32t_cnt(s32_t value, u16_t *octets_needed); void snmp_asn1_enc_s32t_cnt(s32_t value, u16_t *octets_needed);
void snmp_asn1_enc_oid_cnt(u8_t ident_len, s32_t *ident, u16_t *octets_needed); void snmp_asn1_enc_oid_cnt(u8_t ident_len, s32_t *ident, u16_t *octets_needed);
err_t snmp_asn1_enc_type(struct pbuf *p, u16_t ofs, u8_t type); err_t snmp_asn1_enc_type(struct pbuf *p, u16_t ofs, u8_t type);
err_t snmp_asn1_enc_length(struct pbuf *p, u16_t ofs, u16_t length); err_t snmp_asn1_enc_length(struct pbuf *p, u16_t ofs, u16_t length);
err_t snmp_asn1_enc_u32t(struct pbuf *p, u16_t ofs, u8_t octets_needed, u32_t value); err_t snmp_asn1_enc_u32t(struct pbuf *p, u16_t ofs, u8_t octets_needed, u32_t value);
err_t snmp_asn1_enc_s32t(struct pbuf *p, u16_t ofs, u8_t octets_needed, s32_t value); err_t snmp_asn1_enc_s32t(struct pbuf *p, u16_t ofs, u8_t octets_needed, s32_t value);
err_t snmp_asn1_enc_oid(struct pbuf *p, u16_t ofs, u8_t ident_len, s32_t *ident); err_t snmp_asn1_enc_oid(struct pbuf *p, u16_t ofs, u8_t ident_len, s32_t *ident);
err_t snmp_asn1_enc_raw(struct pbuf *p, u16_t ofs, u8_t raw_len, u8_t *raw); err_t snmp_asn1_enc_raw(struct pbuf *p, u16_t ofs, u8_t raw_len, u8_t *raw);
#endif #endif

View file

@ -1,292 +1,292 @@
/** /**
* @file * @file
* SNMP Agent message handling structures. * SNMP Agent message handling structures.
*/ */
/* /*
* Copyright (c) 2006 Axon Digital Design B.V., The Netherlands. * Copyright (c) 2006 Axon Digital Design B.V., The Netherlands.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, * 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products * 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE. * OF SUCH DAMAGE.
* *
* Author: Christiaan Simons <christiaan.simons@axon.tv> * Author: Christiaan Simons <christiaan.simons@axon.tv>
*/ */
#ifndef __LWIP_SNMP_MSG_H__ #ifndef __LWIP_SNMP_MSG_H__
#define __LWIP_SNMP_MSG_H__ #define __LWIP_SNMP_MSG_H__
#include "lwip/opt.h" #include "lwip/opt.h"
#include "arch/cc.h" #include "arch/cc.h"
#include "lwip/snmp.h" #include "lwip/snmp.h"
#include "lwip/snmp_structs.h" #include "lwip/snmp_structs.h"
#if SNMP_PRIVATE_MIB #if SNMP_PRIVATE_MIB
#include "private_mib.h" #include "private_mib.h"
#endif #endif
#define SNMP_IN_PORT 161 #define SNMP_IN_PORT 161
#define SNMP_TRAP_PORT 162 #define SNMP_TRAP_PORT 162
#define SNMP_ES_NOERROR 0 #define SNMP_ES_NOERROR 0
#define SNMP_ES_TOOBIG 1 #define SNMP_ES_TOOBIG 1
#define SNMP_ES_NOSUCHNAME 2 #define SNMP_ES_NOSUCHNAME 2
#define SNMP_ES_BADVALUE 3 #define SNMP_ES_BADVALUE 3
#define SNMP_ES_READONLY 4 #define SNMP_ES_READONLY 4
#define SNMP_ES_GENERROR 5 #define SNMP_ES_GENERROR 5
#define SNMP_GENTRAP_COLDSTART 0 #define SNMP_GENTRAP_COLDSTART 0
#define SNMP_GENTRAP_WARMSTART 1 #define SNMP_GENTRAP_WARMSTART 1
#define SNMP_GENTRAP_AUTHFAIL 4 #define SNMP_GENTRAP_AUTHFAIL 4
#define SNMP_GENTRAP_ENTERPRISESPC 6 #define SNMP_GENTRAP_ENTERPRISESPC 6
struct snmp_varbind struct snmp_varbind
{ {
/* next pointer, NULL for last in list */ /* next pointer, NULL for last in list */
struct snmp_varbind *next; struct snmp_varbind *next;
/* previous pointer, NULL for first in list */ /* previous pointer, NULL for first in list */
struct snmp_varbind *prev; struct snmp_varbind *prev;
/* object identifier length (in s32_t) */ /* object identifier length (in s32_t) */
u8_t ident_len; u8_t ident_len;
/* object identifier array */ /* object identifier array */
s32_t *ident; s32_t *ident;
/* object value ASN1 type */ /* object value ASN1 type */
u8_t value_type; u8_t value_type;
/* object value length (in u8_t) */ /* object value length (in u8_t) */
u8_t value_len; u8_t value_len;
/* object value */ /* object value */
void *value; void *value;
/* encoding varbind seq length length */ /* encoding varbind seq length length */
u8_t seqlenlen; u8_t seqlenlen;
/* encoding object identifier length length */ /* encoding object identifier length length */
u8_t olenlen; u8_t olenlen;
/* encoding object value length length */ /* encoding object value length length */
u8_t vlenlen; u8_t vlenlen;
/* encoding varbind seq length */ /* encoding varbind seq length */
u16_t seqlen; u16_t seqlen;
/* encoding object identifier length */ /* encoding object identifier length */
u16_t olen; u16_t olen;
/* encoding object value length */ /* encoding object value length */
u16_t vlen; u16_t vlen;
}; };
struct snmp_varbind_root struct snmp_varbind_root
{ {
struct snmp_varbind *head; struct snmp_varbind *head;
struct snmp_varbind *tail; struct snmp_varbind *tail;
/* number of variable bindings in list */ /* number of variable bindings in list */
u8_t count; u8_t count;
/* encoding varbind-list seq length length */ /* encoding varbind-list seq length length */
u8_t seqlenlen; u8_t seqlenlen;
/* encoding varbind-list seq length */ /* encoding varbind-list seq length */
u16_t seqlen; u16_t seqlen;
}; };
/** output response message header length fields */ /** output response message header length fields */
struct snmp_resp_header_lengths struct snmp_resp_header_lengths
{ {
/* encoding error-index length length */ /* encoding error-index length length */
u8_t erridxlenlen; u8_t erridxlenlen;
/* encoding error-status length length */ /* encoding error-status length length */
u8_t errstatlenlen; u8_t errstatlenlen;
/* encoding request id length length */ /* encoding request id length length */
u8_t ridlenlen; u8_t ridlenlen;
/* encoding pdu length length */ /* encoding pdu length length */
u8_t pdulenlen; u8_t pdulenlen;
/* encoding community length length */ /* encoding community length length */
u8_t comlenlen; u8_t comlenlen;
/* encoding version length length */ /* encoding version length length */
u8_t verlenlen; u8_t verlenlen;
/* encoding sequence length length */ /* encoding sequence length length */
u8_t seqlenlen; u8_t seqlenlen;
/* encoding error-index length */ /* encoding error-index length */
u16_t erridxlen; u16_t erridxlen;
/* encoding error-status length */ /* encoding error-status length */
u16_t errstatlen; u16_t errstatlen;
/* encoding request id length */ /* encoding request id length */
u16_t ridlen; u16_t ridlen;
/* encoding pdu length */ /* encoding pdu length */
u16_t pdulen; u16_t pdulen;
/* encoding community length */ /* encoding community length */
u16_t comlen; u16_t comlen;
/* encoding version length */ /* encoding version length */
u16_t verlen; u16_t verlen;
/* encoding sequence length */ /* encoding sequence length */
u16_t seqlen; u16_t seqlen;
}; };
/** output response message header length fields */ /** output response message header length fields */
struct snmp_trap_header_lengths struct snmp_trap_header_lengths
{ {
/* encoding timestamp length length */ /* encoding timestamp length length */
u8_t tslenlen; u8_t tslenlen;
/* encoding specific-trap length length */ /* encoding specific-trap length length */
u8_t strplenlen; u8_t strplenlen;
/* encoding generic-trap length length */ /* encoding generic-trap length length */
u8_t gtrplenlen; u8_t gtrplenlen;
/* encoding agent-addr length length */ /* encoding agent-addr length length */
u8_t aaddrlenlen; u8_t aaddrlenlen;
/* encoding enterprise-id length length */ /* encoding enterprise-id length length */
u8_t eidlenlen; u8_t eidlenlen;
/* encoding pdu length length */ /* encoding pdu length length */
u8_t pdulenlen; u8_t pdulenlen;
/* encoding community length length */ /* encoding community length length */
u8_t comlenlen; u8_t comlenlen;
/* encoding version length length */ /* encoding version length length */
u8_t verlenlen; u8_t verlenlen;
/* encoding sequence length length */ /* encoding sequence length length */
u8_t seqlenlen; u8_t seqlenlen;
/* encoding timestamp length */ /* encoding timestamp length */
u16_t tslen; u16_t tslen;
/* encoding specific-trap length */ /* encoding specific-trap length */
u16_t strplen; u16_t strplen;
/* encoding generic-trap length */ /* encoding generic-trap length */
u16_t gtrplen; u16_t gtrplen;
/* encoding agent-addr length */ /* encoding agent-addr length */
u16_t aaddrlen; u16_t aaddrlen;
/* encoding enterprise-id length */ /* encoding enterprise-id length */
u16_t eidlen; u16_t eidlen;
/* encoding pdu length */ /* encoding pdu length */
u16_t pdulen; u16_t pdulen;
/* encoding community length */ /* encoding community length */
u16_t comlen; u16_t comlen;
/* encoding version length */ /* encoding version length */
u16_t verlen; u16_t verlen;
/* encoding sequence length */ /* encoding sequence length */
u16_t seqlen; u16_t seqlen;
}; };
/* Accepting new SNMP messages. */ /* Accepting new SNMP messages. */
#define SNMP_MSG_EMPTY 0 #define SNMP_MSG_EMPTY 0
/* Search for matching object for variable binding. */ /* Search for matching object for variable binding. */
#define SNMP_MSG_SEARCH_OBJ 1 #define SNMP_MSG_SEARCH_OBJ 1
/* Perform SNMP operation on in-memory object. /* Perform SNMP operation on in-memory object.
Pass-through states, for symmetry only. */ Pass-through states, for symmetry only. */
#define SNMP_MSG_INTERNAL_GET_OBJDEF 2 #define SNMP_MSG_INTERNAL_GET_OBJDEF 2
#define SNMP_MSG_INTERNAL_GET_VALUE 3 #define SNMP_MSG_INTERNAL_GET_VALUE 3
#define SNMP_MSG_INTERNAL_SET_TEST 4 #define SNMP_MSG_INTERNAL_SET_TEST 4
#define SNMP_MSG_INTERNAL_GET_OBJDEF_S 5 #define SNMP_MSG_INTERNAL_GET_OBJDEF_S 5
#define SNMP_MSG_INTERNAL_SET_VALUE 6 #define SNMP_MSG_INTERNAL_SET_VALUE 6
/* Perform SNMP operation on object located externally. /* Perform SNMP operation on object located externally.
In theory this could be used for building a proxy agent. In theory this could be used for building a proxy agent.
Practical use is for an enterprise spc. app. gateway. */ Practical use is for an enterprise spc. app. gateway. */
#define SNMP_MSG_EXTERNAL_GET_OBJDEF 7 #define SNMP_MSG_EXTERNAL_GET_OBJDEF 7
#define SNMP_MSG_EXTERNAL_GET_VALUE 8 #define SNMP_MSG_EXTERNAL_GET_VALUE 8
#define SNMP_MSG_EXTERNAL_SET_TEST 9 #define SNMP_MSG_EXTERNAL_SET_TEST 9
#define SNMP_MSG_EXTERNAL_GET_OBJDEF_S 10 #define SNMP_MSG_EXTERNAL_GET_OBJDEF_S 10
#define SNMP_MSG_EXTERNAL_SET_VALUE 11 #define SNMP_MSG_EXTERNAL_SET_VALUE 11
#define SNMP_COMMUNITY_STR_LEN 64 #define SNMP_COMMUNITY_STR_LEN 64
struct snmp_msg_pstat struct snmp_msg_pstat
{ {
/* lwIP local port (161) binding */ /* lwIP local port (161) binding */
struct udp_pcb *pcb; struct udp_pcb *pcb;
/* source IP address */ /* source IP address */
struct ip_addr sip; struct ip_addr sip;
/* source UDP port */ /* source UDP port */
u16_t sp; u16_t sp;
/* request type */ /* request type */
u8_t rt; u8_t rt;
/* request ID */ /* request ID */
s32_t rid; s32_t rid;
/* error status */ /* error status */
s32_t error_status; s32_t error_status;
/* error index */ /* error index */
s32_t error_index; s32_t error_index;
/* community name (zero terminated) */ /* community name (zero terminated) */
u8_t community[SNMP_COMMUNITY_STR_LEN + 1]; u8_t community[SNMP_COMMUNITY_STR_LEN + 1];
/* community string length (exclusive zero term) */ /* community string length (exclusive zero term) */
u8_t com_strlen; u8_t com_strlen;
/* one out of MSG_EMPTY, MSG_DEMUX, MSG_INTERNAL, MSG_EXTERNAL_x */ /* one out of MSG_EMPTY, MSG_DEMUX, MSG_INTERNAL, MSG_EXTERNAL_x */
u8_t state; u8_t state;
/* saved arguments for MSG_EXTERNAL_x */ /* saved arguments for MSG_EXTERNAL_x */
struct mib_external_node *ext_mib_node; struct mib_external_node *ext_mib_node;
struct snmp_name_ptr ext_name_ptr; struct snmp_name_ptr ext_name_ptr;
struct obj_def ext_object_def; struct obj_def ext_object_def;
struct snmp_obj_id ext_oid; struct snmp_obj_id ext_oid;
/* index into input variable binding list */ /* index into input variable binding list */
u8_t vb_idx; u8_t vb_idx;
/* ptr into input variable binding list */ /* ptr into input variable binding list */
struct snmp_varbind *vb_ptr; struct snmp_varbind *vb_ptr;
/* list of variable bindings from input */ /* list of variable bindings from input */
struct snmp_varbind_root invb; struct snmp_varbind_root invb;
/* list of variable bindings to output */ /* list of variable bindings to output */
struct snmp_varbind_root outvb; struct snmp_varbind_root outvb;
/* output response lengths used in ASN encoding */ /* output response lengths used in ASN encoding */
struct snmp_resp_header_lengths rhl; struct snmp_resp_header_lengths rhl;
}; };
struct snmp_msg_trap struct snmp_msg_trap
{ {
/* lwIP local port (161) binding */ /* lwIP local port (161) binding */
struct udp_pcb *pcb; struct udp_pcb *pcb;
/* destination IP address in network order */ /* destination IP address in network order */
struct ip_addr dip; struct ip_addr dip;
/* source enterprise ID (sysObjectID) */ /* source enterprise ID (sysObjectID) */
struct snmp_obj_id *enterprise; struct snmp_obj_id *enterprise;
/* source IP address, raw network order format */ /* source IP address, raw network order format */
u8_t sip_raw[4]; u8_t sip_raw[4];
/* generic trap code */ /* generic trap code */
u32_t gen_trap; u32_t gen_trap;
/* specific trap code */ /* specific trap code */
u32_t spc_trap; u32_t spc_trap;
/* timestamp */ /* timestamp */
u32_t ts; u32_t ts;
/* list of variable bindings to output */ /* list of variable bindings to output */
struct snmp_varbind_root outvb; struct snmp_varbind_root outvb;
/* output trap lengths used in ASN encoding */ /* output trap lengths used in ASN encoding */
struct snmp_trap_header_lengths thl; struct snmp_trap_header_lengths thl;
}; };
/** Agent Version constant, 0 = v1 oddity */ /** Agent Version constant, 0 = v1 oddity */
extern const s32_t snmp_version; extern const s32_t snmp_version;
/** Agent default "public" community string */ /** Agent default "public" community string */
extern const char snmp_publiccommunity[7]; extern const char snmp_publiccommunity[7];
extern struct snmp_msg_trap trap_msg; extern struct snmp_msg_trap trap_msg;
/** Agent setup, start listening to port 161. */ /** Agent setup, start listening to port 161. */
void snmp_init(void); void snmp_init(void);
void snmp_trap_dst_enable(u8_t dst_idx, u8_t enable); void snmp_trap_dst_enable(u8_t dst_idx, u8_t enable);
void snmp_trap_dst_ip_set(u8_t dst_idx, struct ip_addr *dst); void snmp_trap_dst_ip_set(u8_t dst_idx, struct ip_addr *dst);
/** Varbind-list functions. */ /** Varbind-list functions. */
struct snmp_varbind* snmp_varbind_alloc(struct snmp_obj_id *oid, u8_t type, u8_t len); struct snmp_varbind* snmp_varbind_alloc(struct snmp_obj_id *oid, u8_t type, u8_t len);
void snmp_varbind_free(struct snmp_varbind *vb); void snmp_varbind_free(struct snmp_varbind *vb);
void snmp_varbind_list_free(struct snmp_varbind_root *root); void snmp_varbind_list_free(struct snmp_varbind_root *root);
void snmp_varbind_tail_add(struct snmp_varbind_root *root, struct snmp_varbind *vb); void snmp_varbind_tail_add(struct snmp_varbind_root *root, struct snmp_varbind *vb);
struct snmp_varbind* snmp_varbind_tail_remove(struct snmp_varbind_root *root); struct snmp_varbind* snmp_varbind_tail_remove(struct snmp_varbind_root *root);
/** Handle an internal (recv) or external (private response) event. */ /** Handle an internal (recv) or external (private response) event. */
void snmp_msg_event(u8_t request_id); void snmp_msg_event(u8_t request_id);
err_t snmp_send_response(struct snmp_msg_pstat *m_stat); err_t snmp_send_response(struct snmp_msg_pstat *m_stat);
err_t snmp_send_trap(s8_t generic_trap, struct snmp_obj_id *eoid, s32_t specific_trap); err_t snmp_send_trap(s8_t generic_trap, struct snmp_obj_id *eoid, s32_t specific_trap);
void snmp_coldstart_trap(void); void snmp_coldstart_trap(void);
void snmp_authfail_trap(void); void snmp_authfail_trap(void);
#endif #endif

View file

@ -1,253 +1,253 @@
/** /**
* @file * @file
* Generic MIB tree structures. * Generic MIB tree structures.
* *
* @todo namespace prefixes * @todo namespace prefixes
*/ */
/* /*
* Copyright (c) 2006 Axon Digital Design B.V., The Netherlands. * Copyright (c) 2006 Axon Digital Design B.V., The Netherlands.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, * 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products * 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE. * OF SUCH DAMAGE.
* *
* Author: Christiaan Simons <christiaan.simons@axon.tv> * Author: Christiaan Simons <christiaan.simons@axon.tv>
*/ */
#ifndef __LWIP_SNMP_STRUCTS_H__ #ifndef __LWIP_SNMP_STRUCTS_H__
#define __LWIP_SNMP_STRUCTS_H__ #define __LWIP_SNMP_STRUCTS_H__
#include "lwip/opt.h" #include "lwip/opt.h"
#if LWIP_SNMP #if LWIP_SNMP
#include "arch/cc.h" #include "arch/cc.h"
#include "lwip/snmp.h" #include "lwip/snmp.h"
#if SNMP_PRIVATE_MIB #if SNMP_PRIVATE_MIB
#include "private_mib.h" #include "private_mib.h"
#endif #endif
/* MIB object instance */ /* MIB object instance */
#define MIB_OBJECT_NONE 0 #define MIB_OBJECT_NONE 0
#define MIB_OBJECT_SCALAR 1 #define MIB_OBJECT_SCALAR 1
#define MIB_OBJECT_TAB 2 #define MIB_OBJECT_TAB 2
/* MIB object access */ /* MIB object access */
#define MIB_OBJECT_READ_ONLY 0 #define MIB_OBJECT_READ_ONLY 0
#define MIB_OBJECT_READ_WRITE 1 #define MIB_OBJECT_READ_WRITE 1
#define MIB_OBJECT_WRITE_ONLY 2 #define MIB_OBJECT_WRITE_ONLY 2
#define MIB_OBJECT_NOT_ACCESSIBLE 3 #define MIB_OBJECT_NOT_ACCESSIBLE 3
/** object definition returned by (get_object_def)() */ /** object definition returned by (get_object_def)() */
struct obj_def struct obj_def
{ {
/* MIB_OBJECT_NONE (0), MIB_OBJECT_SCALAR (1), MIB_OBJECT_TAB (2) */ /* MIB_OBJECT_NONE (0), MIB_OBJECT_SCALAR (1), MIB_OBJECT_TAB (2) */
u8_t instance; u8_t instance;
/* 0 read-only, 1 read-write, 2 write-only, 3 not-accessible */ /* 0 read-only, 1 read-write, 2 write-only, 3 not-accessible */
u8_t access; u8_t access;
/* ASN type for this object */ /* ASN type for this object */
u8_t asn_type; u8_t asn_type;
/* value length (host length) */ /* value length (host length) */
u16_t v_len; u16_t v_len;
/* length of instance part of supplied object identifier */ /* length of instance part of supplied object identifier */
u8_t id_inst_len; u8_t id_inst_len;
/* instance part of supplied object identifier */ /* instance part of supplied object identifier */
s32_t *id_inst_ptr; s32_t *id_inst_ptr;
}; };
struct snmp_name_ptr struct snmp_name_ptr
{ {
u8_t ident_len; u8_t ident_len;
s32_t *ident; s32_t *ident;
}; };
/** MIB const scalar (.0) node */ /** MIB const scalar (.0) node */
#define MIB_NODE_SC 0x01 #define MIB_NODE_SC 0x01
/** MIB const array node */ /** MIB const array node */
#define MIB_NODE_AR 0x02 #define MIB_NODE_AR 0x02
/** MIB array node (mem_malloced from RAM) */ /** MIB array node (mem_malloced from RAM) */
#define MIB_NODE_RA 0x03 #define MIB_NODE_RA 0x03
/** MIB list root node (mem_malloced from RAM) */ /** MIB list root node (mem_malloced from RAM) */
#define MIB_NODE_LR 0x04 #define MIB_NODE_LR 0x04
/** MIB node for external objects */ /** MIB node for external objects */
#define MIB_NODE_EX 0x05 #define MIB_NODE_EX 0x05
/** node "base class" layout, the mandatory fields for a node */ /** node "base class" layout, the mandatory fields for a node */
struct mib_node struct mib_node
{ {
/** returns struct obj_def for the given object identifier */ /** returns struct obj_def for the given object identifier */
void (*get_object_def)(u8_t ident_len, s32_t *ident, struct obj_def *od); void (*get_object_def)(u8_t ident_len, s32_t *ident, struct obj_def *od);
/** returns object value for the given object identifier, /** returns object value for the given object identifier,
@note the caller must allocate at least len bytes for the value */ @note the caller must allocate at least len bytes for the value */
void (*get_value)(struct obj_def *od, u16_t len, void *value); void (*get_value)(struct obj_def *od, u16_t len, void *value);
/** tests length and/or range BEFORE setting */ /** tests length and/or range BEFORE setting */
u8_t (*set_test)(struct obj_def *od, u16_t len, void *value); u8_t (*set_test)(struct obj_def *od, u16_t len, void *value);
/** sets object value, only to be called when set_test() */ /** sets object value, only to be called when set_test() */
void (*set_value)(struct obj_def *od, u16_t len, void *value); void (*set_value)(struct obj_def *od, u16_t len, void *value);
/** One out of MIB_NODE_AR, MIB_NODE_LR or MIB_NODE_EX */ /** One out of MIB_NODE_AR, MIB_NODE_LR or MIB_NODE_EX */
const u8_t node_type; const u8_t node_type;
/* array or max list length */ /* array or max list length */
const u16_t maxlength; const u16_t maxlength;
}; };
/** derived node for scalars .0 index */ /** derived node for scalars .0 index */
typedef struct mib_node mib_scalar_node; typedef struct mib_node mib_scalar_node;
/** derived node, points to a fixed size const array /** derived node, points to a fixed size const array
of sub-identifiers plus a 'child' pointer */ of sub-identifiers plus a 'child' pointer */
struct mib_array_node struct mib_array_node
{ {
/* inherited "base class" members */ /* inherited "base class" members */
void (* const get_object_def)(u8_t ident_len, s32_t *ident, struct obj_def *od); void (* const get_object_def)(u8_t ident_len, s32_t *ident, struct obj_def *od);
void (* const get_value)(struct obj_def *od, u16_t len, void *value); void (* const get_value)(struct obj_def *od, u16_t len, void *value);
u8_t (*set_test)(struct obj_def *od, u16_t len, void *value); u8_t (*set_test)(struct obj_def *od, u16_t len, void *value);
void (*set_value)(struct obj_def *od, u16_t len, void *value); void (*set_value)(struct obj_def *od, u16_t len, void *value);
const u8_t node_type; const u8_t node_type;
const u16_t maxlength; const u16_t maxlength;
/* aditional struct members */ /* aditional struct members */
const s32_t *objid; const s32_t *objid;
struct mib_node* const *nptr; struct mib_node* const *nptr;
}; };
/** derived node, points to a fixed size mem_malloced array /** derived node, points to a fixed size mem_malloced array
of sub-identifiers plus a 'child' pointer */ of sub-identifiers plus a 'child' pointer */
struct mib_ram_array_node struct mib_ram_array_node
{ {
/* inherited "base class" members */ /* inherited "base class" members */
void (*get_object_def)(u8_t ident_len, s32_t *ident, struct obj_def *od); void (*get_object_def)(u8_t ident_len, s32_t *ident, struct obj_def *od);
void (*get_value)(struct obj_def *od, u16_t len, void *value); void (*get_value)(struct obj_def *od, u16_t len, void *value);
u8_t (*set_test)(struct obj_def *od, u16_t len, void *value); u8_t (*set_test)(struct obj_def *od, u16_t len, void *value);
void (*set_value)(struct obj_def *od, u16_t len, void *value); void (*set_value)(struct obj_def *od, u16_t len, void *value);
u8_t node_type; u8_t node_type;
u16_t maxlength; u16_t maxlength;
/* aditional struct members */ /* aditional struct members */
s32_t *objid; s32_t *objid;
struct mib_node **nptr; struct mib_node **nptr;
}; };
struct mib_list_node struct mib_list_node
{ {
struct mib_list_node *prev; struct mib_list_node *prev;
struct mib_list_node *next; struct mib_list_node *next;
s32_t objid; s32_t objid;
struct mib_node *nptr; struct mib_node *nptr;
}; };
/** derived node, points to a doubly linked list /** derived node, points to a doubly linked list
of sub-identifiers plus a 'child' pointer */ of sub-identifiers plus a 'child' pointer */
struct mib_list_rootnode struct mib_list_rootnode
{ {
/* inherited "base class" members */ /* inherited "base class" members */
void (*get_object_def)(u8_t ident_len, s32_t *ident, struct obj_def *od); void (*get_object_def)(u8_t ident_len, s32_t *ident, struct obj_def *od);
void (*get_value)(struct obj_def *od, u16_t len, void *value); void (*get_value)(struct obj_def *od, u16_t len, void *value);
u8_t (*set_test)(struct obj_def *od, u16_t len, void *value); u8_t (*set_test)(struct obj_def *od, u16_t len, void *value);
void (*set_value)(struct obj_def *od, u16_t len, void *value); void (*set_value)(struct obj_def *od, u16_t len, void *value);
u8_t node_type; u8_t node_type;
u16_t maxlength; u16_t maxlength;
/* aditional struct members */ /* aditional struct members */
struct mib_list_node *head; struct mib_list_node *head;
struct mib_list_node *tail; struct mib_list_node *tail;
/* counts list nodes in list */ /* counts list nodes in list */
u16_t count; u16_t count;
}; };
/** derived node, has access functions for mib object in external memory or device /** derived node, has access functions for mib object in external memory or device
using 'tree_level' and 'idx', with a range 0 .. (level_length() - 1) */ using 'tree_level' and 'idx', with a range 0 .. (level_length() - 1) */
struct mib_external_node struct mib_external_node
{ {
/* inherited "base class" members */ /* inherited "base class" members */
void (*get_object_def)(u8_t ident_len, s32_t *ident, struct obj_def *od); void (*get_object_def)(u8_t ident_len, s32_t *ident, struct obj_def *od);
void (*get_value)(struct obj_def *od, u16_t len, void *value); void (*get_value)(struct obj_def *od, u16_t len, void *value);
u8_t (*set_test)(struct obj_def *od, u16_t len, void *value); u8_t (*set_test)(struct obj_def *od, u16_t len, void *value);
void (*set_value)(struct obj_def *od, u16_t len, void *value); void (*set_value)(struct obj_def *od, u16_t len, void *value);
u8_t node_type; u8_t node_type;
u16_t maxlength; u16_t maxlength;
/* aditional struct members */ /* aditional struct members */
/** points to an extenal (in memory) record of some sort of addressing /** points to an extenal (in memory) record of some sort of addressing
information, passed to and interpreted by the funtions below */ information, passed to and interpreted by the funtions below */
void* addr_inf; void* addr_inf;
/** tree levels under this node */ /** tree levels under this node */
u8_t tree_levels; u8_t tree_levels;
/** number of objects at this level */ /** number of objects at this level */
u16_t (*level_length)(void* addr_inf, u8_t level); u16_t (*level_length)(void* addr_inf, u8_t level);
/** compares object sub identifier with external id /** compares object sub identifier with external id
return zero when equal, nonzero when unequal */ return zero when equal, nonzero when unequal */
s32_t (*ident_cmp)(void* addr_inf, u8_t level, u16_t idx, s32_t sub_id); s32_t (*ident_cmp)(void* addr_inf, u8_t level, u16_t idx, s32_t sub_id);
void (*get_objid)(void* addr_inf, u8_t level, u16_t idx, s32_t *sub_id); void (*get_objid)(void* addr_inf, u8_t level, u16_t idx, s32_t *sub_id);
/** async Questions */ /** async Questions */
void (*get_object_def_q)(void* addr_inf, u8_t rid, u8_t ident_len, s32_t *ident); void (*get_object_def_q)(void* addr_inf, u8_t rid, u8_t ident_len, s32_t *ident);
void (*get_value_q)(u8_t rid, struct obj_def *od); void (*get_value_q)(u8_t rid, struct obj_def *od);
void (*set_test_q)(u8_t rid, struct obj_def *od); void (*set_test_q)(u8_t rid, struct obj_def *od);
void (*set_value_q)(u8_t rid, struct obj_def *od, u16_t len, void *value); void (*set_value_q)(u8_t rid, struct obj_def *od, u16_t len, void *value);
/** async Answers */ /** async Answers */
void (*get_object_def_a)(u8_t rid, u8_t ident_len, s32_t *ident, struct obj_def *od); void (*get_object_def_a)(u8_t rid, u8_t ident_len, s32_t *ident, struct obj_def *od);
void (*get_value_a)(u8_t rid, struct obj_def *od, u16_t len, void *value); void (*get_value_a)(u8_t rid, struct obj_def *od, u16_t len, void *value);
u8_t (*set_test_a)(u8_t rid, struct obj_def *od, u16_t len, void *value); u8_t (*set_test_a)(u8_t rid, struct obj_def *od, u16_t len, void *value);
void (*set_value_a)(u8_t rid, struct obj_def *od, u16_t len, void *value); void (*set_value_a)(u8_t rid, struct obj_def *od, u16_t len, void *value);
/** async Panic Close (agent returns error reply, /** async Panic Close (agent returns error reply,
e.g. used for external transaction cleanup) */ e.g. used for external transaction cleanup) */
void (*get_object_def_pc)(u8_t rid, u8_t ident_len, s32_t *ident); void (*get_object_def_pc)(u8_t rid, u8_t ident_len, s32_t *ident);
void (*get_value_pc)(u8_t rid, struct obj_def *od); void (*get_value_pc)(u8_t rid, struct obj_def *od);
void (*set_test_pc)(u8_t rid, struct obj_def *od); void (*set_test_pc)(u8_t rid, struct obj_def *od);
void (*set_value_pc)(u8_t rid, struct obj_def *od); void (*set_value_pc)(u8_t rid, struct obj_def *od);
}; };
/** export MIB tree from mib2.c */ /** export MIB tree from mib2.c */
extern const struct mib_array_node internet; extern const struct mib_array_node internet;
/** dummy function pointers for non-leaf MIB nodes from mib2.c */ /** dummy function pointers for non-leaf MIB nodes from mib2.c */
void noleafs_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od); void noleafs_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
void noleafs_get_value(struct obj_def *od, u16_t len, void *value); void noleafs_get_value(struct obj_def *od, u16_t len, void *value);
u8_t noleafs_set_test(struct obj_def *od, u16_t len, void *value); u8_t noleafs_set_test(struct obj_def *od, u16_t len, void *value);
void noleafs_set_value(struct obj_def *od, u16_t len, void *value); void noleafs_set_value(struct obj_def *od, u16_t len, void *value);
void snmp_oidtoip(s32_t *ident, struct ip_addr *ip); void snmp_oidtoip(s32_t *ident, struct ip_addr *ip);
void snmp_iptooid(struct ip_addr *ip, s32_t *ident); void snmp_iptooid(struct ip_addr *ip, s32_t *ident);
void snmp_ifindextonetif(s32_t ifindex, struct netif **netif); void snmp_ifindextonetif(s32_t ifindex, struct netif **netif);
void snmp_netiftoifindex(struct netif *netif, s32_t *ifidx); void snmp_netiftoifindex(struct netif *netif, s32_t *ifidx);
struct mib_list_node* snmp_mib_ln_alloc(s32_t id); struct mib_list_node* snmp_mib_ln_alloc(s32_t id);
void snmp_mib_ln_free(struct mib_list_node *ln); void snmp_mib_ln_free(struct mib_list_node *ln);
struct mib_list_rootnode* snmp_mib_lrn_alloc(void); struct mib_list_rootnode* snmp_mib_lrn_alloc(void);
void snmp_mib_lrn_free(struct mib_list_rootnode *lrn); void snmp_mib_lrn_free(struct mib_list_rootnode *lrn);
s8_t snmp_mib_node_insert(struct mib_list_rootnode *rn, s32_t objid, struct mib_list_node **insn); s8_t snmp_mib_node_insert(struct mib_list_rootnode *rn, s32_t objid, struct mib_list_node **insn);
s8_t snmp_mib_node_find(struct mib_list_rootnode *rn, s32_t objid, struct mib_list_node **fn); s8_t snmp_mib_node_find(struct mib_list_rootnode *rn, s32_t objid, struct mib_list_node **fn);
struct mib_list_rootnode *snmp_mib_node_delete(struct mib_list_rootnode *rn, struct mib_list_node *n); struct mib_list_rootnode *snmp_mib_node_delete(struct mib_list_rootnode *rn, struct mib_list_node *n);
struct mib_node* snmp_search_tree(struct mib_node *node, u8_t ident_len, s32_t *ident, struct snmp_name_ptr *np); struct mib_node* snmp_search_tree(struct mib_node *node, u8_t ident_len, s32_t *ident, struct snmp_name_ptr *np);
struct mib_node* snmp_expand_tree(struct mib_node *node, u8_t ident_len, s32_t *ident, struct snmp_obj_id *oidret); struct mib_node* snmp_expand_tree(struct mib_node *node, u8_t ident_len, s32_t *ident, struct snmp_obj_id *oidret);
u8_t snmp_iso_prefix_tst(u8_t ident_len, s32_t *ident); u8_t snmp_iso_prefix_tst(u8_t ident_len, s32_t *ident);
u8_t snmp_iso_prefix_expand(u8_t ident_len, s32_t *ident, struct snmp_obj_id *oidret); u8_t snmp_iso_prefix_expand(u8_t ident_len, s32_t *ident, struct snmp_obj_id *oidret);
#endif /* LWIP_SNMP */ #endif /* LWIP_SNMP */
#endif #endif

View file

@ -1,271 +1,271 @@
/* /*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science. * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, * 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products * 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE. * OF SUCH DAMAGE.
* *
* This file is part of the lwIP TCP/IP stack. * This file is part of the lwIP TCP/IP stack.
* *
* Author: Adam Dunkels <adam@sics.se> * Author: Adam Dunkels <adam@sics.se>
* *
*/ */
#ifndef __LWIP_SOCKETS_H__ #ifndef __LWIP_SOCKETS_H__
#define __LWIP_SOCKETS_H__ #define __LWIP_SOCKETS_H__
#include "lwip/ip_addr.h" #include "lwip/ip_addr.h"
struct sockaddr_in { struct sockaddr_in {
u8_t sin_len; u8_t sin_len;
u8_t sin_family; u8_t sin_family;
u16_t sin_port; u16_t sin_port;
struct in_addr sin_addr; struct in_addr sin_addr;
char sin_zero[8]; char sin_zero[8];
}; };
struct sockaddr { struct sockaddr {
u8_t sa_len; u8_t sa_len;
u8_t sa_family; u8_t sa_family;
char sa_data[14]; char sa_data[14];
}; };
#ifndef socklen_t #ifndef socklen_t
# define socklen_t int # define socklen_t int
#endif #endif
#define SOCK_STREAM 1 #define SOCK_STREAM 1
#define SOCK_DGRAM 2 #define SOCK_DGRAM 2
#define SOCK_RAW 3 #define SOCK_RAW 3
/* /*
* Option flags per-socket. * Option flags per-socket.
*/ */
#define SO_DEBUG 0x0001 /* turn on debugging info recording */ #define SO_DEBUG 0x0001 /* turn on debugging info recording */
#define SO_ACCEPTCONN 0x0002 /* socket has had listen() */ #define SO_ACCEPTCONN 0x0002 /* socket has had listen() */
#define SO_REUSEADDR 0x0004 /* allow local address reuse */ #define SO_REUSEADDR 0x0004 /* allow local address reuse */
#define SO_KEEPALIVE 0x0008 /* keep connections alive */ #define SO_KEEPALIVE 0x0008 /* keep connections alive */
#define SO_DONTROUTE 0x0010 /* just use interface addresses */ #define SO_DONTROUTE 0x0010 /* just use interface addresses */
#define SO_BROADCAST 0x0020 /* permit sending of broadcast msgs */ #define SO_BROADCAST 0x0020 /* permit sending of broadcast msgs */
#define SO_USELOOPBACK 0x0040 /* bypass hardware when possible */ #define SO_USELOOPBACK 0x0040 /* bypass hardware when possible */
#define SO_LINGER 0x0080 /* linger on close if data present */ #define SO_LINGER 0x0080 /* linger on close if data present */
#define SO_OOBINLINE 0x0100 /* leave received OOB data in line */ #define SO_OOBINLINE 0x0100 /* leave received OOB data in line */
#define SO_REUSEPORT 0x0200 /* allow local address & port reuse */ #define SO_REUSEPORT 0x0200 /* allow local address & port reuse */
#define SO_DONTLINGER (int)(~SO_LINGER) #define SO_DONTLINGER (int)(~SO_LINGER)
/* /*
* Additional options, not kept in so_options. * Additional options, not kept in so_options.
*/ */
#define SO_SNDBUF 0x1001 /* send buffer size */ #define SO_SNDBUF 0x1001 /* send buffer size */
#define SO_RCVBUF 0x1002 /* receive buffer size */ #define SO_RCVBUF 0x1002 /* receive buffer size */
#define SO_SNDLOWAT 0x1003 /* send low-water mark */ #define SO_SNDLOWAT 0x1003 /* send low-water mark */
#define SO_RCVLOWAT 0x1004 /* receive low-water mark */ #define SO_RCVLOWAT 0x1004 /* receive low-water mark */
#define SO_SNDTIMEO 0x1005 /* send timeout */ #define SO_SNDTIMEO 0x1005 /* send timeout */
#define SO_RCVTIMEO 0x1006 /* receive timeout */ #define SO_RCVTIMEO 0x1006 /* receive timeout */
#define SO_ERROR 0x1007 /* get error status and clear */ #define SO_ERROR 0x1007 /* get error status and clear */
#define SO_TYPE 0x1008 /* get socket type */ #define SO_TYPE 0x1008 /* get socket type */
/* /*
* Structure used for manipulating linger option. * Structure used for manipulating linger option.
*/ */
struct linger { struct linger {
int l_onoff; /* option on/off */ int l_onoff; /* option on/off */
int l_linger; /* linger time */ int l_linger; /* linger time */
}; };
/* /*
* Level number for (get/set)sockopt() to apply to socket itself. * Level number for (get/set)sockopt() to apply to socket itself.
*/ */
#define SOL_SOCKET 0xfff /* options for socket level */ #define SOL_SOCKET 0xfff /* options for socket level */
#define AF_UNSPEC 0 #define AF_UNSPEC 0
#define AF_INET 2 #define AF_INET 2
#define PF_INET AF_INET #define PF_INET AF_INET
#define PF_UNSPEC AF_UNSPEC #define PF_UNSPEC AF_UNSPEC
#define IPPROTO_IP 0 #define IPPROTO_IP 0
#define IPPROTO_TCP 6 #define IPPROTO_TCP 6
#define IPPROTO_UDP 17 #define IPPROTO_UDP 17
#define INADDR_ANY 0 #define INADDR_ANY 0
#define INADDR_BROADCAST 0xffffffff #define INADDR_BROADCAST 0xffffffff
/* Flags we can use with send and recv. */ /* Flags we can use with send and recv. */
#define MSG_DONTWAIT 0x40 /* Nonblocking i/o for this operation only */ #define MSG_DONTWAIT 0x40 /* Nonblocking i/o for this operation only */
/* /*
* Options for level IPPROTO_IP * Options for level IPPROTO_IP
*/ */
#define IP_TOS 1 #define IP_TOS 1
#define IP_TTL 2 #define IP_TTL 2
#define IPTOS_TOS_MASK 0x1E #define IPTOS_TOS_MASK 0x1E
#define IPTOS_TOS(tos) ((tos) & IPTOS_TOS_MASK) #define IPTOS_TOS(tos) ((tos) & IPTOS_TOS_MASK)
#define IPTOS_LOWDELAY 0x10 #define IPTOS_LOWDELAY 0x10
#define IPTOS_THROUGHPUT 0x08 #define IPTOS_THROUGHPUT 0x08
#define IPTOS_RELIABILITY 0x04 #define IPTOS_RELIABILITY 0x04
#define IPTOS_LOWCOST 0x02 #define IPTOS_LOWCOST 0x02
#define IPTOS_MINCOST IPTOS_LOWCOST #define IPTOS_MINCOST IPTOS_LOWCOST
/* /*
* Definitions for IP precedence (also in ip_tos) (hopefully unused) * Definitions for IP precedence (also in ip_tos) (hopefully unused)
*/ */
#define IPTOS_PREC_MASK 0xe0 #define IPTOS_PREC_MASK 0xe0
#define IPTOS_PREC(tos) ((tos) & IPTOS_PREC_MASK) #define IPTOS_PREC(tos) ((tos) & IPTOS_PREC_MASK)
#define IPTOS_PREC_NETCONTROL 0xe0 #define IPTOS_PREC_NETCONTROL 0xe0
#define IPTOS_PREC_INTERNETCONTROL 0xc0 #define IPTOS_PREC_INTERNETCONTROL 0xc0
#define IPTOS_PREC_CRITIC_ECP 0xa0 #define IPTOS_PREC_CRITIC_ECP 0xa0
#define IPTOS_PREC_FLASHOVERRIDE 0x80 #define IPTOS_PREC_FLASHOVERRIDE 0x80
#define IPTOS_PREC_FLASH 0x60 #define IPTOS_PREC_FLASH 0x60
#define IPTOS_PREC_IMMEDIATE 0x40 #define IPTOS_PREC_IMMEDIATE 0x40
#define IPTOS_PREC_PRIORITY 0x20 #define IPTOS_PREC_PRIORITY 0x20
#define IPTOS_PREC_ROUTINE 0x00 #define IPTOS_PREC_ROUTINE 0x00
/* /*
* Commands for ioctlsocket(), taken from the BSD file fcntl.h. * Commands for ioctlsocket(), taken from the BSD file fcntl.h.
* *
* *
* Ioctl's have the command encoded in the lower word, * Ioctl's have the command encoded in the lower word,
* and the size of any in or out parameters in the upper * and the size of any in or out parameters in the upper
* word. The high 2 bits of the upper word are used * word. The high 2 bits of the upper word are used
* to encode the in/out status of the parameter; for now * to encode the in/out status of the parameter; for now
* we restrict parameters to at most 128 bytes. * we restrict parameters to at most 128 bytes.
*/ */
#if !defined(FIONREAD) || !defined(FIONBIO) #if !defined(FIONREAD) || !defined(FIONBIO)
#define IOCPARM_MASK 0x7f /* parameters must be < 128 bytes */ #define IOCPARM_MASK 0x7f /* parameters must be < 128 bytes */
#define IOC_VOID 0x20000000 /* no parameters */ #define IOC_VOID 0x20000000 /* no parameters */
#define IOC_OUT 0x40000000 /* copy out parameters */ #define IOC_OUT 0x40000000 /* copy out parameters */
#define IOC_IN 0x80000000 /* copy in parameters */ #define IOC_IN 0x80000000 /* copy in parameters */
#define IOC_INOUT (IOC_IN|IOC_OUT) #define IOC_INOUT (IOC_IN|IOC_OUT)
/* 0x20000000 distinguishes new & /* 0x20000000 distinguishes new &
old ioctl's */ old ioctl's */
#define _IO(x,y) (IOC_VOID|((x)<<8)|(y)) #define _IO(x,y) (IOC_VOID|((x)<<8)|(y))
#define _IOR(x,y,t) (IOC_OUT|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y)) #define _IOR(x,y,t) (IOC_OUT|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))
#define _IOW(x,y,t) (IOC_IN|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y)) #define _IOW(x,y,t) (IOC_IN|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))
#endif #endif
#ifndef FIONREAD #ifndef FIONREAD
#define FIONREAD _IOR('f', 127, unsigned long) /* get # bytes to read */ #define FIONREAD _IOR('f', 127, unsigned long) /* get # bytes to read */
#endif #endif
#ifndef FIONBIO #ifndef FIONBIO
#define FIONBIO _IOW('f', 126, unsigned long) /* set/clear non-blocking i/o */ #define FIONBIO _IOW('f', 126, unsigned long) /* set/clear non-blocking i/o */
#endif #endif
/* Socket I/O Controls */ /* Socket I/O Controls */
#ifndef SIOCSHIWAT #ifndef SIOCSHIWAT
#define SIOCSHIWAT _IOW('s', 0, unsigned long) /* set high watermark */ #define SIOCSHIWAT _IOW('s', 0, unsigned long) /* set high watermark */
#define SIOCGHIWAT _IOR('s', 1, unsigned long) /* get high watermark */ #define SIOCGHIWAT _IOR('s', 1, unsigned long) /* get high watermark */
#define SIOCSLOWAT _IOW('s', 2, unsigned long) /* set low watermark */ #define SIOCSLOWAT _IOW('s', 2, unsigned long) /* set low watermark */
#define SIOCGLOWAT _IOR('s', 3, unsigned long) /* get low watermark */ #define SIOCGLOWAT _IOR('s', 3, unsigned long) /* get low watermark */
#define SIOCATMARK _IOR('s', 7, unsigned long) /* at oob mark? */ #define SIOCATMARK _IOR('s', 7, unsigned long) /* at oob mark? */
#endif #endif
#ifndef O_NONBLOCK #ifndef O_NONBLOCK
#define O_NONBLOCK 04000U #define O_NONBLOCK 04000U
#endif #endif
#ifndef FD_SET #ifndef FD_SET
#undef FD_SETSIZE #undef FD_SETSIZE
#define FD_SETSIZE 16 #define FD_SETSIZE 16
#define FD_SET(n, p) ((p)->fd_bits[(n)/8] |= (1 << ((n) & 7))) #define FD_SET(n, p) ((p)->fd_bits[(n)/8] |= (1 << ((n) & 7)))
#define FD_CLR(n, p) ((p)->fd_bits[(n)/8] &= ~(1 << ((n) & 7))) #define FD_CLR(n, p) ((p)->fd_bits[(n)/8] &= ~(1 << ((n) & 7)))
#define FD_ISSET(n,p) ((p)->fd_bits[(n)/8] & (1 << ((n) & 7))) #define FD_ISSET(n,p) ((p)->fd_bits[(n)/8] & (1 << ((n) & 7)))
#define FD_ZERO(p) memset((void*)(p),0,sizeof(*(p))) #define FD_ZERO(p) memset((void*)(p),0,sizeof(*(p)))
typedef struct fd_set { typedef struct fd_set {
unsigned char fd_bits [(FD_SETSIZE+7)/8]; unsigned char fd_bits [(FD_SETSIZE+7)/8];
} fd_set; } fd_set;
/* /*
* only define this in sockets.c so it does not interfere * only define this in sockets.c so it does not interfere
* with other projects namespaces where timeval is present * with other projects namespaces where timeval is present
*/ */
#ifndef LWIP_TIMEVAL_PRIVATE #ifndef LWIP_TIMEVAL_PRIVATE
#define LWIP_TIMEVAL_PRIVATE 1 #define LWIP_TIMEVAL_PRIVATE 1
#endif #endif
#if LWIP_TIMEVAL_PRIVATE #if LWIP_TIMEVAL_PRIVATE
struct timeval { struct timeval {
long tv_sec; /* seconds */ long tv_sec; /* seconds */
long tv_usec; /* and microseconds */ long tv_usec; /* and microseconds */
}; };
#endif #endif
#endif #endif
int lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen); int lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen);
int lwip_bind(int s, struct sockaddr *name, socklen_t namelen); int lwip_bind(int s, struct sockaddr *name, socklen_t namelen);
int lwip_shutdown(int s, int how); int lwip_shutdown(int s, int how);
int lwip_getpeername (int s, struct sockaddr *name, socklen_t *namelen); int lwip_getpeername (int s, struct sockaddr *name, socklen_t *namelen);
int lwip_getsockname (int s, struct sockaddr *name, socklen_t *namelen); int lwip_getsockname (int s, struct sockaddr *name, socklen_t *namelen);
int lwip_getsockopt (int s, int level, int optname, void *optval, socklen_t *optlen); int lwip_getsockopt (int s, int level, int optname, void *optval, socklen_t *optlen);
int lwip_setsockopt (int s, int level, int optname, const void *optval, socklen_t optlen); int lwip_setsockopt (int s, int level, int optname, const void *optval, socklen_t optlen);
int lwip_close(int s); int lwip_close(int s);
int lwip_connect(int s, struct sockaddr *name, socklen_t namelen); int lwip_connect(int s, struct sockaddr *name, socklen_t namelen);
int lwip_listen(int s, int backlog); int lwip_listen(int s, int backlog);
int lwip_recv(int s, void *mem, int len, unsigned int flags); int lwip_recv(int s, void *mem, int len, unsigned int flags);
int lwip_read(int s, void *mem, int len); int lwip_read(int s, void *mem, int len);
int lwip_recvfrom(int s, void *mem, int len, unsigned int flags, int lwip_recvfrom(int s, void *mem, int len, unsigned int flags,
struct sockaddr *from, socklen_t *fromlen); struct sockaddr *from, socklen_t *fromlen);
int lwip_send(int s, void *dataptr, int size, unsigned int flags); int lwip_send(int s, void *dataptr, int size, unsigned int flags);
int lwip_sendto(int s, void *dataptr, int size, unsigned int flags, int lwip_sendto(int s, void *dataptr, int size, unsigned int flags,
struct sockaddr *to, socklen_t tolen); struct sockaddr *to, socklen_t tolen);
int lwip_socket(int domain, int type, int protocol); int lwip_socket(int domain, int type, int protocol);
int lwip_write(int s, void *dataptr, int size); int lwip_write(int s, void *dataptr, int size);
int lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, int lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset,
struct timeval *timeout); struct timeval *timeout);
int lwip_ioctl(int s, long cmd, void *argp); int lwip_ioctl(int s, long cmd, void *argp);
#if LWIP_COMPAT_SOCKETS #if LWIP_COMPAT_SOCKETS
#define accept(a,b,c) lwip_accept(a,b,c) #define accept(a,b,c) lwip_accept(a,b,c)
#define bind(a,b,c) lwip_bind(a,b,c) #define bind(a,b,c) lwip_bind(a,b,c)
#define shutdown(a,b) lwip_shutdown(a,b) #define shutdown(a,b) lwip_shutdown(a,b)
#define close(s) lwip_close(s) #define close(s) lwip_close(s)
#define connect(a,b,c) lwip_connect(a,b,c) #define connect(a,b,c) lwip_connect(a,b,c)
#define getsockname(a,b,c) lwip_getsockname(a,b,c) #define getsockname(a,b,c) lwip_getsockname(a,b,c)
#define getpeername(a,b,c) lwip_getpeername(a,b,c) #define getpeername(a,b,c) lwip_getpeername(a,b,c)
#define setsockopt(a,b,c,d,e) lwip_setsockopt(a,b,c,d,e) #define setsockopt(a,b,c,d,e) lwip_setsockopt(a,b,c,d,e)
#define getsockopt(a,b,c,d,e) lwip_getsockopt(a,b,c,d,e) #define getsockopt(a,b,c,d,e) lwip_getsockopt(a,b,c,d,e)
#define listen(a,b) lwip_listen(a,b) #define listen(a,b) lwip_listen(a,b)
#define recv(a,b,c,d) lwip_recv(a,b,c,d) #define recv(a,b,c,d) lwip_recv(a,b,c,d)
#define read(a,b,c) lwip_read(a,b,c) #define read(a,b,c) lwip_read(a,b,c)
#define recvfrom(a,b,c,d,e,f) lwip_recvfrom(a,b,c,d,e,f) #define recvfrom(a,b,c,d,e,f) lwip_recvfrom(a,b,c,d,e,f)
#define send(a,b,c,d) lwip_send(a,b,c,d) #define send(a,b,c,d) lwip_send(a,b,c,d)
#define sendto(a,b,c,d,e,f) lwip_sendto(a,b,c,d,e,f) #define sendto(a,b,c,d,e,f) lwip_sendto(a,b,c,d,e,f)
#define socket(a,b,c) lwip_socket(a,b,c) #define socket(a,b,c) lwip_socket(a,b,c)
#define write(a,b,c) lwip_write(a,b,c) #define write(a,b,c) lwip_write(a,b,c)
#define select(a,b,c,d,e) lwip_select(a,b,c,d,e) #define select(a,b,c,d,e) lwip_select(a,b,c,d,e)
#define ioctlsocket(a,b,c) lwip_ioctl(a,b,c) #define ioctlsocket(a,b,c) lwip_ioctl(a,b,c)
#endif /* LWIP_COMPAT_SOCKETS */ #endif /* LWIP_COMPAT_SOCKETS */
#endif /* __LWIP_SOCKETS_H__ */ #endif /* __LWIP_SOCKETS_H__ */

View file

@ -1,158 +1,158 @@
/* /*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science. * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, * 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products * 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE. * OF SUCH DAMAGE.
* *
* This file is part of the lwIP TCP/IP stack. * This file is part of the lwIP TCP/IP stack.
* *
* Author: Adam Dunkels <adam@sics.se> * Author: Adam Dunkels <adam@sics.se>
* *
*/ */
#ifndef __LWIP_STATS_H__ #ifndef __LWIP_STATS_H__
#define __LWIP_STATS_H__ #define __LWIP_STATS_H__
#include "lwip/opt.h" #include "lwip/opt.h"
#include "arch/cc.h" #include "arch/cc.h"
#include "lwip/mem.h" #include "lwip/mem.h"
#include "lwip/memp.h" #include "lwip/memp.h"
#if LWIP_STATS #if LWIP_STATS
struct stats_proto { struct stats_proto {
u16_t xmit; /* Transmitted packets. */ u16_t xmit; /* Transmitted packets. */
u16_t rexmit; /* Retransmitted packets. */ u16_t rexmit; /* Retransmitted packets. */
u16_t recv; /* Received packets. */ u16_t recv; /* Received packets. */
u16_t fw; /* Forwarded packets. */ u16_t fw; /* Forwarded packets. */
u16_t drop; /* Dropped packets. */ u16_t drop; /* Dropped packets. */
u16_t chkerr; /* Checksum error. */ u16_t chkerr; /* Checksum error. */
u16_t lenerr; /* Invalid length error. */ u16_t lenerr; /* Invalid length error. */
u16_t memerr; /* Out of memory error. */ u16_t memerr; /* Out of memory error. */
u16_t rterr; /* Routing error. */ u16_t rterr; /* Routing error. */
u16_t proterr; /* Protocol error. */ u16_t proterr; /* Protocol error. */
u16_t opterr; /* Error in options. */ u16_t opterr; /* Error in options. */
u16_t err; /* Misc error. */ u16_t err; /* Misc error. */
u16_t cachehit; u16_t cachehit;
}; };
struct stats_mem { struct stats_mem {
mem_size_t avail; mem_size_t avail;
mem_size_t used; mem_size_t used;
mem_size_t max; mem_size_t max;
mem_size_t err; mem_size_t err;
}; };
struct stats_pbuf { struct stats_pbuf {
u16_t avail; u16_t avail;
u16_t used; u16_t used;
u16_t max; u16_t max;
u16_t err; u16_t err;
u16_t alloc_locked; u16_t alloc_locked;
u16_t refresh_locked; u16_t refresh_locked;
}; };
struct stats_syselem { struct stats_syselem {
u16_t used; u16_t used;
u16_t max; u16_t max;
u16_t err; u16_t err;
}; };
struct stats_sys { struct stats_sys {
struct stats_syselem sem; struct stats_syselem sem;
struct stats_syselem mbox; struct stats_syselem mbox;
}; };
struct stats_ { struct stats_ {
struct stats_proto link; struct stats_proto link;
struct stats_proto ip_frag; struct stats_proto ip_frag;
struct stats_proto ip; struct stats_proto ip;
struct stats_proto icmp; struct stats_proto icmp;
struct stats_proto udp; struct stats_proto udp;
struct stats_proto tcp; struct stats_proto tcp;
struct stats_pbuf pbuf; struct stats_pbuf pbuf;
struct stats_mem mem; struct stats_mem mem;
struct stats_mem memp[MEMP_MAX]; struct stats_mem memp[MEMP_MAX];
struct stats_sys sys; struct stats_sys sys;
}; };
extern struct stats_ lwip_stats; extern struct stats_ lwip_stats;
void stats_init(void); void stats_init(void);
#define STATS_INC(x) ++lwip_stats.x #define STATS_INC(x) ++lwip_stats.x
#else #else
#define stats_init() #define stats_init()
#define STATS_INC(x) #define STATS_INC(x)
#endif /* LWIP_STATS */ #endif /* LWIP_STATS */
#if TCP_STATS #if TCP_STATS
#define TCP_STATS_INC(x) STATS_INC(x) #define TCP_STATS_INC(x) STATS_INC(x)
#else #else
#define TCP_STATS_INC(x) #define TCP_STATS_INC(x)
#endif #endif
#if UDP_STATS #if UDP_STATS
#define UDP_STATS_INC(x) STATS_INC(x) #define UDP_STATS_INC(x) STATS_INC(x)
#else #else
#define UDP_STATS_INC(x) #define UDP_STATS_INC(x)
#endif #endif
#if ICMP_STATS #if ICMP_STATS
#define ICMP_STATS_INC(x) STATS_INC(x) #define ICMP_STATS_INC(x) STATS_INC(x)
#else #else
#define ICMP_STATS_INC(x) #define ICMP_STATS_INC(x)
#endif #endif
#if IP_STATS #if IP_STATS
#define IP_STATS_INC(x) STATS_INC(x) #define IP_STATS_INC(x) STATS_INC(x)
#else #else
#define IP_STATS_INC(x) #define IP_STATS_INC(x)
#endif #endif
#if IPFRAG_STATS #if IPFRAG_STATS
#define IPFRAG_STATS_INC(x) STATS_INC(x) #define IPFRAG_STATS_INC(x) STATS_INC(x)
#else #else
#define IPFRAG_STATS_INC(x) #define IPFRAG_STATS_INC(x)
#endif #endif
#if LINK_STATS #if LINK_STATS
#define LINK_STATS_INC(x) STATS_INC(x) #define LINK_STATS_INC(x) STATS_INC(x)
#else #else
#define LINK_STATS_INC(x) #define LINK_STATS_INC(x)
#endif #endif
/* Display of statistics */ /* Display of statistics */
#if LWIP_STATS_DISPLAY #if LWIP_STATS_DISPLAY
void stats_display(void); void stats_display(void);
#else #else
#define stats_display() #define stats_display()
#endif #endif
#endif /* __LWIP_STATS_H__ */ #endif /* __LWIP_STATS_H__ */

View file

@ -1,183 +1,183 @@
/* /*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science. * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, * 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products * 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE. * OF SUCH DAMAGE.
* *
* This file is part of the lwIP TCP/IP stack. * This file is part of the lwIP TCP/IP stack.
* *
* Author: Adam Dunkels <adam@sics.se> * Author: Adam Dunkels <adam@sics.se>
* *
*/ */
#ifndef __LWIP_SYS_H__ #ifndef __LWIP_SYS_H__
#define __LWIP_SYS_H__ #define __LWIP_SYS_H__
#include "arch/cc.h" #include "arch/cc.h"
#include "lwip/opt.h" #include "lwip/opt.h"
#if NO_SYS #if NO_SYS
/* For a totally minimal and standalone system, we provide null /* For a totally minimal and standalone system, we provide null
definitions of the sys_ functions. */ definitions of the sys_ functions. */
typedef u8_t sys_sem_t; typedef u8_t sys_sem_t;
typedef u8_t sys_mbox_t; typedef u8_t sys_mbox_t;
struct sys_timeo {u8_t dummy;}; struct sys_timeo {u8_t dummy;};
#define sys_init() #define sys_init()
#define sys_timeout(m,h,a) #define sys_timeout(m,h,a)
#define sys_untimeout(m,a) #define sys_untimeout(m,a)
#define sys_sem_new(c) c #define sys_sem_new(c) c
#define sys_sem_signal(s) #define sys_sem_signal(s)
#define sys_sem_wait(s) #define sys_sem_wait(s)
#define sys_sem_free(s) #define sys_sem_free(s)
#define sys_mbox_new() 0 #define sys_mbox_new() 0
#define sys_mbox_fetch(m,d) #define sys_mbox_fetch(m,d)
#define sys_mbox_post(m,d) #define sys_mbox_post(m,d)
#define sys_mbox_free(m) #define sys_mbox_free(m)
#define sys_thread_new(t,a,p) #define sys_thread_new(t,a,p)
#else /* NO_SYS */ #else /* NO_SYS */
#include "arch/sys_arch.h" #include "arch/sys_arch.h"
/** Return code for timeouts from sys_arch_mbox_fetch and sys_arch_sem_wait */ /** Return code for timeouts from sys_arch_mbox_fetch and sys_arch_sem_wait */
#define SYS_ARCH_TIMEOUT 0xffffffff #define SYS_ARCH_TIMEOUT 0xffffffff
typedef void (* sys_timeout_handler)(void *arg); typedef void (* sys_timeout_handler)(void *arg);
struct sys_timeo { struct sys_timeo {
struct sys_timeo *next; struct sys_timeo *next;
u32_t time; u32_t time;
sys_timeout_handler h; sys_timeout_handler h;
void *arg; void *arg;
}; };
struct sys_timeouts { struct sys_timeouts {
struct sys_timeo *next; struct sys_timeo *next;
}; };
/* sys_init() must be called before anthing else. */ /* sys_init() must be called before anthing else. */
void sys_init(void); void sys_init(void);
/* /*
* sys_timeout(): * sys_timeout():
* *
* Schedule a timeout a specified amount of milliseconds in the * Schedule a timeout a specified amount of milliseconds in the
* future. When the timeout occurs, the specified timeout handler will * future. When the timeout occurs, the specified timeout handler will
* be called. The handler will be passed the "arg" argument when * be called. The handler will be passed the "arg" argument when
* called. * called.
* *
*/ */
void sys_timeout(u32_t msecs, sys_timeout_handler h, void *arg); void sys_timeout(u32_t msecs, sys_timeout_handler h, void *arg);
void sys_untimeout(sys_timeout_handler h, void *arg); void sys_untimeout(sys_timeout_handler h, void *arg);
struct sys_timeouts *sys_arch_timeouts(void); struct sys_timeouts *sys_arch_timeouts(void);
/* Semaphore functions. */ /* Semaphore functions. */
sys_sem_t sys_sem_new(u8_t count); sys_sem_t sys_sem_new(u8_t count);
void sys_sem_signal(sys_sem_t sem); void sys_sem_signal(sys_sem_t sem);
u32_t sys_arch_sem_wait(sys_sem_t sem, u32_t timeout); u32_t sys_arch_sem_wait(sys_sem_t sem, u32_t timeout);
void sys_sem_free(sys_sem_t sem); void sys_sem_free(sys_sem_t sem);
void sys_sem_wait(sys_sem_t sem); void sys_sem_wait(sys_sem_t sem);
int sys_sem_wait_timeout(sys_sem_t sem, u32_t timeout); int sys_sem_wait_timeout(sys_sem_t sem, u32_t timeout);
/* Time functions. */ /* Time functions. */
#ifndef sys_msleep #ifndef sys_msleep
void sys_msleep(u32_t ms); /* only has a (close to) 1 jiffy resolution. */ void sys_msleep(u32_t ms); /* only has a (close to) 1 jiffy resolution. */
#endif #endif
#ifndef sys_jiffies #ifndef sys_jiffies
u32_t sys_jiffies(void); /* since power up. */ u32_t sys_jiffies(void); /* since power up. */
#endif #endif
/* Mailbox functions. */ /* Mailbox functions. */
sys_mbox_t sys_mbox_new(void); sys_mbox_t sys_mbox_new(void);
void sys_mbox_post(sys_mbox_t mbox, void *msg); void sys_mbox_post(sys_mbox_t mbox, void *msg);
u32_t sys_arch_mbox_fetch(sys_mbox_t mbox, void **msg, u32_t timeout); u32_t sys_arch_mbox_fetch(sys_mbox_t mbox, void **msg, u32_t timeout);
void sys_mbox_free(sys_mbox_t mbox); void sys_mbox_free(sys_mbox_t mbox);
void sys_mbox_fetch(sys_mbox_t mbox, void **msg); void sys_mbox_fetch(sys_mbox_t mbox, void **msg);
/* Thread functions. */ /* Thread functions. */
sys_thread_t sys_thread_new(void (* thread)(void *arg), void *arg, int prio); sys_thread_t sys_thread_new(void (* thread)(void *arg), void *arg, int prio);
/* The following functions are used only in Unix code, and /* The following functions are used only in Unix code, and
can be omitted when porting the stack. */ can be omitted when porting the stack. */
/* Returns the current time in microseconds. */ /* Returns the current time in microseconds. */
unsigned long sys_now(void); unsigned long sys_now(void);
#endif /* NO_SYS */ #endif /* NO_SYS */
/* Critical Region Protection */ /* Critical Region Protection */
/* These functions must be implemented in the sys_arch.c file. /* These functions must be implemented in the sys_arch.c file.
In some implementations they can provide a more light-weight protection In some implementations they can provide a more light-weight protection
mechanism than using semaphores. Otherwise semaphores can be used for mechanism than using semaphores. Otherwise semaphores can be used for
implementation */ implementation */
#ifndef SYS_ARCH_PROTECT #ifndef SYS_ARCH_PROTECT
/** SYS_LIGHTWEIGHT_PROT /** SYS_LIGHTWEIGHT_PROT
* define SYS_LIGHTWEIGHT_PROT in lwipopts.h if you want inter-task protection * define SYS_LIGHTWEIGHT_PROT in lwipopts.h if you want inter-task protection
* for certain critical regions during buffer allocation, deallocation and memory * for certain critical regions during buffer allocation, deallocation and memory
* allocation and deallocation. * allocation and deallocation.
*/ */
#if SYS_LIGHTWEIGHT_PROT #if SYS_LIGHTWEIGHT_PROT
/** SYS_ARCH_DECL_PROTECT /** SYS_ARCH_DECL_PROTECT
* declare a protection variable. This macro will default to defining a variable of * declare a protection variable. This macro will default to defining a variable of
* type sys_prot_t. If a particular port needs a different implementation, then * type sys_prot_t. If a particular port needs a different implementation, then
* this macro may be defined in sys_arch.h. * this macro may be defined in sys_arch.h.
*/ */
#define SYS_ARCH_DECL_PROTECT(lev) sys_prot_t lev #define SYS_ARCH_DECL_PROTECT(lev) sys_prot_t lev
/** SYS_ARCH_PROTECT /** SYS_ARCH_PROTECT
* Perform a "fast" protect. This could be implemented by * Perform a "fast" protect. This could be implemented by
* disabling interrupts for an embedded system or by using a semaphore or * disabling interrupts for an embedded system or by using a semaphore or
* mutex. The implementation should allow calling SYS_ARCH_PROTECT when * mutex. The implementation should allow calling SYS_ARCH_PROTECT when
* already protected. The old protection level is returned in the variable * already protected. The old protection level is returned in the variable
* "lev". This macro will default to calling the sys_arch_protect() function * "lev". This macro will default to calling the sys_arch_protect() function
* which should be implemented in sys_arch.c. If a particular port needs a * which should be implemented in sys_arch.c. If a particular port needs a
* different implementation, then this macro may be defined in sys_arch.h * different implementation, then this macro may be defined in sys_arch.h
*/ */
#define SYS_ARCH_PROTECT(lev) lev = sys_arch_protect() #define SYS_ARCH_PROTECT(lev) lev = sys_arch_protect()
/** SYS_ARCH_UNPROTECT /** SYS_ARCH_UNPROTECT
* Perform a "fast" set of the protection level to "lev". This could be * Perform a "fast" set of the protection level to "lev". This could be
* implemented by setting the interrupt level to "lev" within the MACRO or by * implemented by setting the interrupt level to "lev" within the MACRO or by
* using a semaphore or mutex. This macro will default to calling the * using a semaphore or mutex. This macro will default to calling the
* sys_arch_unprotect() function which should be implemented in * sys_arch_unprotect() function which should be implemented in
* sys_arch.c. If a particular port needs a different implementation, then * sys_arch.c. If a particular port needs a different implementation, then
* this macro may be defined in sys_arch.h * this macro may be defined in sys_arch.h
*/ */
#define SYS_ARCH_UNPROTECT(lev) sys_arch_unprotect(lev) #define SYS_ARCH_UNPROTECT(lev) sys_arch_unprotect(lev)
sys_prot_t sys_arch_protect(void); sys_prot_t sys_arch_protect(void);
void sys_arch_unprotect(sys_prot_t pval); void sys_arch_unprotect(sys_prot_t pval);
#else #else
#define SYS_ARCH_DECL_PROTECT(lev) #define SYS_ARCH_DECL_PROTECT(lev)
#define SYS_ARCH_PROTECT(lev) #define SYS_ARCH_PROTECT(lev)
#define SYS_ARCH_UNPROTECT(lev) #define SYS_ARCH_UNPROTECT(lev)
#endif /* SYS_LIGHTWEIGHT_PROT */ #endif /* SYS_LIGHTWEIGHT_PROT */
#endif /* SYS_ARCH_PROTECT */ #endif /* SYS_ARCH_PROTECT */
#endif /* __LWIP_SYS_H__ */ #endif /* __LWIP_SYS_H__ */

File diff suppressed because it is too large Load diff

View file

@ -1,68 +1,68 @@
/* /*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science. * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, * 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products * 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE. * OF SUCH DAMAGE.
* *
* This file is part of the lwIP TCP/IP stack. * This file is part of the lwIP TCP/IP stack.
* *
* Author: Adam Dunkels <adam@sics.se> * Author: Adam Dunkels <adam@sics.se>
* *
*/ */
#ifndef __LWIP_TCPIP_H__ #ifndef __LWIP_TCPIP_H__
#define __LWIP_TCPIP_H__ #define __LWIP_TCPIP_H__
#include "lwip/api_msg.h" #include "lwip/api_msg.h"
#include "lwip/pbuf.h" #include "lwip/pbuf.h"
void tcpip_init(void (* tcpip_init_done)(void *), void *arg); void tcpip_init(void (* tcpip_init_done)(void *), void *arg);
void tcpip_apimsg(struct api_msg *apimsg); void tcpip_apimsg(struct api_msg *apimsg);
err_t tcpip_input(struct pbuf *p, struct netif *inp); err_t tcpip_input(struct pbuf *p, struct netif *inp);
err_t tcpip_callback(void (*f)(void *ctx), void *ctx); err_t tcpip_callback(void (*f)(void *ctx), void *ctx);
void tcpip_tcp_timer_needed(void); void tcpip_tcp_timer_needed(void);
enum tcpip_msg_type { enum tcpip_msg_type {
TCPIP_MSG_API, TCPIP_MSG_API,
TCPIP_MSG_INPUT, TCPIP_MSG_INPUT,
TCPIP_MSG_CALLBACK TCPIP_MSG_CALLBACK
}; };
struct tcpip_msg { struct tcpip_msg {
enum tcpip_msg_type type; enum tcpip_msg_type type;
sys_sem_t *sem; sys_sem_t *sem;
union { union {
struct api_msg *apimsg; struct api_msg *apimsg;
struct { struct {
struct pbuf *p; struct pbuf *p;
struct netif *netif; struct netif *netif;
} inp; } inp;
struct { struct {
void (*f)(void *ctx); void (*f)(void *ctx);
void *ctx; void *ctx;
} cb; } cb;
} msg; } msg;
}; };
#endif /* __LWIP_TCPIP_H__ */ #endif /* __LWIP_TCPIP_H__ */

View file

@ -1,106 +1,106 @@
/* /*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science. * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, * 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products * 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE. * OF SUCH DAMAGE.
* *
* This file is part of the lwIP TCP/IP stack. * This file is part of the lwIP TCP/IP stack.
* *
* Author: Adam Dunkels <adam@sics.se> * Author: Adam Dunkels <adam@sics.se>
* *
*/ */
#ifndef __LWIP_UDP_H__ #ifndef __LWIP_UDP_H__
#define __LWIP_UDP_H__ #define __LWIP_UDP_H__
#include "lwip/arch.h" #include "lwip/arch.h"
#include "lwip/pbuf.h" #include "lwip/pbuf.h"
#include "lwip/inet.h" #include "lwip/inet.h"
#include "lwip/ip.h" #include "lwip/ip.h"
#define UDP_HLEN 8 #define UDP_HLEN 8
struct udp_hdr { struct udp_hdr {
PACK_STRUCT_FIELD(u16_t src); PACK_STRUCT_FIELD(u16_t src);
PACK_STRUCT_FIELD(u16_t dest); /* src/dest UDP ports */ PACK_STRUCT_FIELD(u16_t dest); /* src/dest UDP ports */
PACK_STRUCT_FIELD(u16_t len); PACK_STRUCT_FIELD(u16_t len);
PACK_STRUCT_FIELD(u16_t chksum); PACK_STRUCT_FIELD(u16_t chksum);
} PACK_STRUCT_STRUCT; } PACK_STRUCT_STRUCT;
#define UDP_FLAGS_NOCHKSUM 0x01U #define UDP_FLAGS_NOCHKSUM 0x01U
#define UDP_FLAGS_UDPLITE 0x02U #define UDP_FLAGS_UDPLITE 0x02U
#define UDP_FLAGS_CONNECTED 0x04U #define UDP_FLAGS_CONNECTED 0x04U
struct udp_pcb { struct udp_pcb {
/* Common members of all PCB types */ /* Common members of all PCB types */
IP_PCB; IP_PCB;
/* Protocol specific PCB members */ /* Protocol specific PCB members */
struct udp_pcb *next; struct udp_pcb *next;
u8_t flags; u8_t flags;
u16_t local_port, remote_port; u16_t local_port, remote_port;
u16_t chksum_len; u16_t chksum_len;
void (* recv)(void *arg, struct udp_pcb *pcb, struct pbuf *p, void (* recv)(void *arg, struct udp_pcb *pcb, struct pbuf *p,
struct ip_addr *addr, u16_t port); struct ip_addr *addr, u16_t port);
void *recv_arg; void *recv_arg;
}; };
/* udp_pcbs export for exernal reference (e.g. SNMP agent) */ /* udp_pcbs export for exernal reference (e.g. SNMP agent) */
extern struct udp_pcb *udp_pcbs; extern struct udp_pcb *udp_pcbs;
/* The following functions is the application layer interface to the /* The following functions is the application layer interface to the
UDP code. */ UDP code. */
struct udp_pcb * udp_new (void); struct udp_pcb * udp_new (void);
void udp_remove (struct udp_pcb *pcb); void udp_remove (struct udp_pcb *pcb);
err_t udp_bind (struct udp_pcb *pcb, struct ip_addr *ipaddr, err_t udp_bind (struct udp_pcb *pcb, struct ip_addr *ipaddr,
u16_t port); u16_t port);
err_t udp_connect (struct udp_pcb *pcb, struct ip_addr *ipaddr, err_t udp_connect (struct udp_pcb *pcb, struct ip_addr *ipaddr,
u16_t port); u16_t port);
void udp_disconnect (struct udp_pcb *pcb); void udp_disconnect (struct udp_pcb *pcb);
void udp_recv (struct udp_pcb *pcb, void udp_recv (struct udp_pcb *pcb,
void (* recv)(void *arg, struct udp_pcb *upcb, void (* recv)(void *arg, struct udp_pcb *upcb,
struct pbuf *p, struct pbuf *p,
struct ip_addr *addr, struct ip_addr *addr,
u16_t port), u16_t port),
void *recv_arg); void *recv_arg);
err_t udp_sendto (struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *dst_ip, u16_t dst_port); err_t udp_sendto (struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *dst_ip, u16_t dst_port);
err_t udp_send (struct udp_pcb *pcb, struct pbuf *p); err_t udp_send (struct udp_pcb *pcb, struct pbuf *p);
#define udp_flags(pcb) ((pcb)->flags) #define udp_flags(pcb) ((pcb)->flags)
#define udp_setflags(pcb, f) ((pcb)->flags = (f)) #define udp_setflags(pcb, f) ((pcb)->flags = (f))
/* The following functions are the lower layer interface to UDP. */ /* The following functions are the lower layer interface to UDP. */
void udp_input (struct pbuf *p, struct netif *inp); void udp_input (struct pbuf *p, struct netif *inp);
void udp_init (void); void udp_init (void);
#if UDP_DEBUG #if UDP_DEBUG
void udp_debug_print(struct udp_hdr *udphdr); void udp_debug_print(struct udp_hdr *udphdr);
#else #else
#define udp_debug_print(udphdr) #define udp_debug_print(udphdr)
#endif #endif
#endif /* __LWIP_UDP_H__ */ #endif /* __LWIP_UDP_H__ */

View file

@ -1,129 +1,129 @@
/* /*
* Copyright (c) 2001-2003 Swedish Institute of Computer Science. * Copyright (c) 2001-2003 Swedish Institute of Computer Science.
* Copyright (c) 2003-2004 Leon Woestenberg <leon.woestenberg@axon.tv> * Copyright (c) 2003-2004 Leon Woestenberg <leon.woestenberg@axon.tv>
* Copyright (c) 2003-2004 Axon Digital Design B.V., The Netherlands. * Copyright (c) 2003-2004 Axon Digital Design B.V., The Netherlands.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, * 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products * 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE. * OF SUCH DAMAGE.
* *
* This file is part of the lwIP TCP/IP stack. * This file is part of the lwIP TCP/IP stack.
* *
* Author: Adam Dunkels <adam@sics.se> * Author: Adam Dunkels <adam@sics.se>
* *
*/ */
#ifndef __NETIF_ETHARP_H__ #ifndef __NETIF_ETHARP_H__
#define __NETIF_ETHARP_H__ #define __NETIF_ETHARP_H__
#ifndef ETH_PAD_SIZE #ifndef ETH_PAD_SIZE
#define ETH_PAD_SIZE 0 #define ETH_PAD_SIZE 0
#endif #endif
#include "lwip/pbuf.h" #include "lwip/pbuf.h"
#include "lwip/ip_addr.h" #include "lwip/ip_addr.h"
#include "lwip/netif.h" #include "lwip/netif.h"
#include "lwip/ip.h" #include "lwip/ip.h"
#ifdef PACK_STRUCT_USE_INCLUDES #ifdef PACK_STRUCT_USE_INCLUDES
# include "arch/bpstruct.h" # include "arch/bpstruct.h"
#endif #endif
PACK_STRUCT_BEGIN PACK_STRUCT_BEGIN
struct eth_addr { struct eth_addr {
PACK_STRUCT_FIELD(u8_t addr[6]); PACK_STRUCT_FIELD(u8_t addr[6]);
} PACK_STRUCT_STRUCT; } PACK_STRUCT_STRUCT;
PACK_STRUCT_END PACK_STRUCT_END
#ifdef PACK_STRUCT_USE_INCLUDES #ifdef PACK_STRUCT_USE_INCLUDES
# include "arch/epstruct.h" # include "arch/epstruct.h"
#endif #endif
#ifdef PACK_STRUCT_USE_INCLUDES #ifdef PACK_STRUCT_USE_INCLUDES
# include "arch/bpstruct.h" # include "arch/bpstruct.h"
#endif #endif
PACK_STRUCT_BEGIN PACK_STRUCT_BEGIN
struct eth_hdr { struct eth_hdr {
#if ETH_PAD_SIZE #if ETH_PAD_SIZE
PACK_STRUCT_FIELD(u8_t padding[ETH_PAD_SIZE]); PACK_STRUCT_FIELD(u8_t padding[ETH_PAD_SIZE]);
#endif #endif
PACK_STRUCT_FIELD(struct eth_addr dest); PACK_STRUCT_FIELD(struct eth_addr dest);
PACK_STRUCT_FIELD(struct eth_addr src); PACK_STRUCT_FIELD(struct eth_addr src);
PACK_STRUCT_FIELD(u16_t type); PACK_STRUCT_FIELD(u16_t type);
} PACK_STRUCT_STRUCT; } PACK_STRUCT_STRUCT;
PACK_STRUCT_END PACK_STRUCT_END
#ifdef PACK_STRUCT_USE_INCLUDES #ifdef PACK_STRUCT_USE_INCLUDES
# include "arch/epstruct.h" # include "arch/epstruct.h"
#endif #endif
#ifdef PACK_STRUCT_USE_INCLUDES #ifdef PACK_STRUCT_USE_INCLUDES
# include "arch/bpstruct.h" # include "arch/bpstruct.h"
#endif #endif
PACK_STRUCT_BEGIN PACK_STRUCT_BEGIN
/** the ARP message */ /** the ARP message */
struct etharp_hdr { struct etharp_hdr {
PACK_STRUCT_FIELD(struct eth_hdr ethhdr); PACK_STRUCT_FIELD(struct eth_hdr ethhdr);
PACK_STRUCT_FIELD(u16_t hwtype); PACK_STRUCT_FIELD(u16_t hwtype);
PACK_STRUCT_FIELD(u16_t proto); PACK_STRUCT_FIELD(u16_t proto);
PACK_STRUCT_FIELD(u16_t _hwlen_protolen); PACK_STRUCT_FIELD(u16_t _hwlen_protolen);
PACK_STRUCT_FIELD(u16_t opcode); PACK_STRUCT_FIELD(u16_t opcode);
PACK_STRUCT_FIELD(struct eth_addr shwaddr); PACK_STRUCT_FIELD(struct eth_addr shwaddr);
PACK_STRUCT_FIELD(struct ip_addr2 sipaddr); PACK_STRUCT_FIELD(struct ip_addr2 sipaddr);
PACK_STRUCT_FIELD(struct eth_addr dhwaddr); PACK_STRUCT_FIELD(struct eth_addr dhwaddr);
PACK_STRUCT_FIELD(struct ip_addr2 dipaddr); PACK_STRUCT_FIELD(struct ip_addr2 dipaddr);
} PACK_STRUCT_STRUCT; } PACK_STRUCT_STRUCT;
PACK_STRUCT_END PACK_STRUCT_END
#ifdef PACK_STRUCT_USE_INCLUDES #ifdef PACK_STRUCT_USE_INCLUDES
# include "arch/epstruct.h" # include "arch/epstruct.h"
#endif #endif
#ifdef PACK_STRUCT_USE_INCLUDES #ifdef PACK_STRUCT_USE_INCLUDES
# include "arch/bpstruct.h" # include "arch/bpstruct.h"
#endif #endif
PACK_STRUCT_BEGIN PACK_STRUCT_BEGIN
struct ethip_hdr { struct ethip_hdr {
PACK_STRUCT_FIELD(struct eth_hdr eth); PACK_STRUCT_FIELD(struct eth_hdr eth);
PACK_STRUCT_FIELD(struct ip_hdr ip); PACK_STRUCT_FIELD(struct ip_hdr ip);
} PACK_STRUCT_STRUCT; } PACK_STRUCT_STRUCT;
PACK_STRUCT_END PACK_STRUCT_END
#ifdef PACK_STRUCT_USE_INCLUDES #ifdef PACK_STRUCT_USE_INCLUDES
# include "arch/epstruct.h" # include "arch/epstruct.h"
#endif #endif
/** 5 seconds period */ /** 5 seconds period */
#define ARP_TMR_INTERVAL 5000 #define ARP_TMR_INTERVAL 5000
#define ETHTYPE_ARP 0x0806 #define ETHTYPE_ARP 0x0806
#define ETHTYPE_IP 0x0800 #define ETHTYPE_IP 0x0800
void etharp_init(void); void etharp_init(void);
void etharp_tmr(void); void etharp_tmr(void);
s8_t etharp_find_addr(struct netif *netif, struct ip_addr *ipaddr, s8_t etharp_find_addr(struct netif *netif, struct ip_addr *ipaddr,
struct eth_addr **eth_ret, struct ip_addr **ip_ret); struct eth_addr **eth_ret, struct ip_addr **ip_ret);
void etharp_ip_input(struct netif *netif, struct pbuf *p); void etharp_ip_input(struct netif *netif, struct pbuf *p);
void etharp_arp_input(struct netif *netif, struct eth_addr *ethaddr, void etharp_arp_input(struct netif *netif, struct eth_addr *ethaddr,
struct pbuf *p); struct pbuf *p);
err_t etharp_output(struct netif *netif, struct ip_addr *ipaddr, err_t etharp_output(struct netif *netif, struct ip_addr *ipaddr,
struct pbuf *q); struct pbuf *q);
err_t etharp_query(struct netif *netif, struct ip_addr *ipaddr, struct pbuf *q); err_t etharp_query(struct netif *netif, struct ip_addr *ipaddr, struct pbuf *q);
err_t etharp_request(struct netif *netif, struct ip_addr *ipaddr); err_t etharp_request(struct netif *netif, struct ip_addr *ipaddr);
#endif /* __NETIF_ARP_H__ */ #endif /* __NETIF_ARP_H__ */

View file

@ -1,39 +1,39 @@
/* /*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science. * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, * 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products * 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE. * OF SUCH DAMAGE.
* *
* This file is part of the lwIP TCP/IP stack. * This file is part of the lwIP TCP/IP stack.
* *
* Author: Adam Dunkels <adam@sics.se> * Author: Adam Dunkels <adam@sics.se>
* *
*/ */
#ifndef __NETIF_LOOPIF_H__ #ifndef __NETIF_LOOPIF_H__
#define __NETIF_LOOPIF_H__ #define __NETIF_LOOPIF_H__
#include "lwip/netif.h" #include "lwip/netif.h"
err_t loopif_init(struct netif *netif); err_t loopif_init(struct netif *netif);
#endif /* __NETIF_LOOPIF_H__ */ #endif /* __NETIF_LOOPIF_H__ */

View file

@ -1,42 +1,42 @@
/* /*
* Copyright (c) 2001, Swedish Institute of Computer Science. * Copyright (c) 2001, Swedish Institute of Computer Science.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
* are met: * are met:
* 1. Redistributions of source code must retain the above copyright * 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright * 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors * 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software * may be used to endorse or promote products derived from this software
* without specific prior written permission. * without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* This file is part of the lwIP TCP/IP stack. * This file is part of the lwIP TCP/IP stack.
* *
* Author: Adam Dunkels <adam@sics.se> * Author: Adam Dunkels <adam@sics.se>
* *
*/ */
#ifndef __NETIF_SLIPIF_H__ #ifndef __NETIF_SLIPIF_H__
#define __NETIF_SLIPIF_H__ #define __NETIF_SLIPIF_H__
#include "lwip/netif.h" #include "lwip/netif.h"
err_t slipif_init(struct netif * netif); err_t slipif_init(struct netif * netif);
#endif #endif

File diff suppressed because it is too large Load diff

View file

@ -1,326 +1,326 @@
/* /*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science. * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, * 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products * 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE. * OF SUCH DAMAGE.
* *
* This file is part of the lwIP TCP/IP stack. * This file is part of the lwIP TCP/IP stack.
* *
* Author: Adam Dunkels <adam@sics.se> * Author: Adam Dunkels <adam@sics.se>
* *
*/ */
/* /*
* This file is a skeleton for developing Ethernet network interface * This file is a skeleton for developing Ethernet network interface
* drivers for lwIP. Add code to the low_level functions and do a * drivers for lwIP. Add code to the low_level functions and do a
* search-and-replace for the word "ethernetif" to replace it with * search-and-replace for the word "ethernetif" to replace it with
* something that better describes your network interface. * something that better describes your network interface.
*/ */
#include "lwip/opt.h" #include "lwip/opt.h"
#include "lwip/def.h" #include "lwip/def.h"
#include "lwip/mem.h" #include "lwip/mem.h"
#include "lwip/pbuf.h" #include "lwip/pbuf.h"
#include "lwip/sys.h" #include "lwip/sys.h"
#include <lwip/stats.h> #include <lwip/stats.h>
#include "netif/etharp.h" #include "netif/etharp.h"
/* Define those to better describe your network interface. */ /* Define those to better describe your network interface. */
#define IFNAME0 'e' #define IFNAME0 'e'
#define IFNAME1 'n' #define IFNAME1 'n'
struct ethernetif { struct ethernetif {
struct eth_addr *ethaddr; struct eth_addr *ethaddr;
/* Add whatever per-interface state that is needed here. */ /* Add whatever per-interface state that is needed here. */
}; };
static const struct eth_addr ethbroadcast = {{0xff,0xff,0xff,0xff,0xff,0xff}}; static const struct eth_addr ethbroadcast = {{0xff,0xff,0xff,0xff,0xff,0xff}};
/* Forward declarations. */ /* Forward declarations. */
static void ethernetif_input(struct netif *netif); static void ethernetif_input(struct netif *netif);
static err_t ethernetif_output(struct netif *netif, struct pbuf *p, static err_t ethernetif_output(struct netif *netif, struct pbuf *p,
struct ip_addr *ipaddr); struct ip_addr *ipaddr);
static void static void
low_level_init(struct netif *netif) low_level_init(struct netif *netif)
{ {
struct ethernetif *ethernetif = netif->state; struct ethernetif *ethernetif = netif->state;
/* set MAC hardware address length */ /* set MAC hardware address length */
netif->hwaddr_len = 6; netif->hwaddr_len = 6;
/* set MAC hardware address */ /* set MAC hardware address */
netif->hwaddr[0] = ; netif->hwaddr[0] = ;
... ...
netif->hwaddr[5] = ; netif->hwaddr[5] = ;
/* maximum transfer unit */ /* maximum transfer unit */
netif->mtu = 1500; netif->mtu = 1500;
/* broadcast capability */ /* broadcast capability */
netif->flags = NETIF_FLAG_BROADCAST; netif->flags = NETIF_FLAG_BROADCAST;
/* Do whatever else is needed to initialize interface. */ /* Do whatever else is needed to initialize interface. */
} }
/* /*
* low_level_output(): * low_level_output():
* *
* Should do the actual transmission of the packet. The packet is * Should do the actual transmission of the packet. The packet is
* contained in the pbuf that is passed to the function. This pbuf * contained in the pbuf that is passed to the function. This pbuf
* might be chained. * might be chained.
* *
*/ */
static err_t static err_t
low_level_output(struct netif *netif, struct pbuf *p) low_level_output(struct netif *netif, struct pbuf *p)
{ {
struct ethernetif *ethernetif = netif->state; struct ethernetif *ethernetif = netif->state;
struct pbuf *q; struct pbuf *q;
initiate transfer(); initiate transfer();
#if ETH_PAD_SIZE #if ETH_PAD_SIZE
pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */ pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */
#endif #endif
for(q = p; q != NULL; q = q->next) { for(q = p; q != NULL; q = q->next) {
/* Send the data from the pbuf to the interface, one pbuf at a /* Send the data from the pbuf to the interface, one pbuf at a
time. The size of the data in each pbuf is kept in the ->len time. The size of the data in each pbuf is kept in the ->len
variable. */ variable. */
send data from(q->payload, q->len); send data from(q->payload, q->len);
} }
signal that packet should be sent(); signal that packet should be sent();
#if ETH_PAD_SIZE #if ETH_PAD_SIZE
pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */ pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */
#endif #endif
#if LINK_STATS #if LINK_STATS
lwip_stats.link.xmit++; lwip_stats.link.xmit++;
#endif /* LINK_STATS */ #endif /* LINK_STATS */
return ERR_OK; return ERR_OK;
} }
/* /*
* low_level_input(): * low_level_input():
* *
* Should allocate a pbuf and transfer the bytes of the incoming * Should allocate a pbuf and transfer the bytes of the incoming
* packet from the interface into the pbuf. * packet from the interface into the pbuf.
* *
*/ */
static struct pbuf * static struct pbuf *
low_level_input(struct netif *netif) low_level_input(struct netif *netif)
{ {
struct ethernetif *ethernetif = netif->state; struct ethernetif *ethernetif = netif->state;
struct pbuf *p, *q; struct pbuf *p, *q;
u16_t len; u16_t len;
/* Obtain the size of the packet and put it into the "len" /* Obtain the size of the packet and put it into the "len"
variable. */ variable. */
len = ; len = ;
#if ETH_PAD_SIZE #if ETH_PAD_SIZE
len += ETH_PAD_SIZE; /* allow room for Ethernet padding */ len += ETH_PAD_SIZE; /* allow room for Ethernet padding */
#endif #endif
/* We allocate a pbuf chain of pbufs from the pool. */ /* We allocate a pbuf chain of pbufs from the pool. */
p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL); p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL);
if (p != NULL) { if (p != NULL) {
#if ETH_PAD_SIZE #if ETH_PAD_SIZE
pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */ pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */
#endif #endif
/* We iterate over the pbuf chain until we have read the entire /* We iterate over the pbuf chain until we have read the entire
* packet into the pbuf. */ * packet into the pbuf. */
for(q = p; q != NULL; q = q->next) { for(q = p; q != NULL; q = q->next) {
/* Read enough bytes to fill this pbuf in the chain. The /* Read enough bytes to fill this pbuf in the chain. The
* available data in the pbuf is given by the q->len * available data in the pbuf is given by the q->len
* variable. */ * variable. */
read data into(q->payload, q->len); read data into(q->payload, q->len);
} }
acknowledge that packet has been read(); acknowledge that packet has been read();
#if ETH_PAD_SIZE #if ETH_PAD_SIZE
pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */ pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */
#endif #endif
#if LINK_STATS #if LINK_STATS
lwip_stats.link.recv++; lwip_stats.link.recv++;
#endif /* LINK_STATS */ #endif /* LINK_STATS */
} else { } else {
drop packet(); drop packet();
#if LINK_STATS #if LINK_STATS
lwip_stats.link.memerr++; lwip_stats.link.memerr++;
lwip_stats.link.drop++; lwip_stats.link.drop++;
#endif /* LINK_STATS */ #endif /* LINK_STATS */
} }
return p; return p;
} }
/* /*
* ethernetif_output(): * ethernetif_output():
* *
* This function is called by the TCP/IP stack when an IP packet * This function is called by the TCP/IP stack when an IP packet
* should be sent. It calls the function called low_level_output() to * should be sent. It calls the function called low_level_output() to
* do the actual transmission of the packet. * do the actual transmission of the packet.
* *
*/ */
static err_t static err_t
ethernetif_output(struct netif *netif, struct pbuf *p, ethernetif_output(struct netif *netif, struct pbuf *p,
struct ip_addr *ipaddr) struct ip_addr *ipaddr)
{ {
/* resolve hardware address, then send (or queue) packet */ /* resolve hardware address, then send (or queue) packet */
return etharp_output(netif, ipaddr, p); return etharp_output(netif, ipaddr, p);
} }
/* /*
* ethernetif_input(): * ethernetif_input():
* *
* This function should be called when a packet is ready to be read * This function should be called when a packet is ready to be read
* from the interface. It uses the function low_level_input() that * from the interface. It uses the function low_level_input() that
* should handle the actual reception of bytes from the network * should handle the actual reception of bytes from the network
* interface. * interface.
* *
*/ */
static void static void
ethernetif_input(struct netif *netif) ethernetif_input(struct netif *netif)
{ {
struct ethernetif *ethernetif; struct ethernetif *ethernetif;
struct eth_hdr *ethhdr; struct eth_hdr *ethhdr;
struct pbuf *p; struct pbuf *p;
ethernetif = netif->state; ethernetif = netif->state;
/* move received packet into a new pbuf */ /* move received packet into a new pbuf */
p = low_level_input(netif); p = low_level_input(netif);
/* no packet could be read, silently ignore this */ /* no packet could be read, silently ignore this */
if (p == NULL) return; if (p == NULL) return;
/* points to packet payload, which starts with an Ethernet header */ /* points to packet payload, which starts with an Ethernet header */
ethhdr = p->payload; ethhdr = p->payload;
#if LINK_STATS #if LINK_STATS
lwip_stats.link.recv++; lwip_stats.link.recv++;
#endif /* LINK_STATS */ #endif /* LINK_STATS */
ethhdr = p->payload; ethhdr = p->payload;
switch (htons(ethhdr->type)) { switch (htons(ethhdr->type)) {
/* IP packet? */ /* IP packet? */
case ETHTYPE_IP: case ETHTYPE_IP:
#if 0 #if 0
/* CSi disabled ARP table update on ingress IP packets. /* CSi disabled ARP table update on ingress IP packets.
This seems to work but needs thorough testing. */ This seems to work but needs thorough testing. */
/* update ARP table */ /* update ARP table */
etharp_ip_input(netif, p); etharp_ip_input(netif, p);
#endif #endif
/* skip Ethernet header */ /* skip Ethernet header */
pbuf_header(p, -sizeof(struct eth_hdr)); pbuf_header(p, -sizeof(struct eth_hdr));
/* pass to network layer */ /* pass to network layer */
netif->input(p, netif); netif->input(p, netif);
break; break;
case ETHTYPE_ARP: case ETHTYPE_ARP:
/* pass p to ARP module */ /* pass p to ARP module */
etharp_arp_input(netif, ethernetif->ethaddr, p); etharp_arp_input(netif, ethernetif->ethaddr, p);
break; break;
default: default:
pbuf_free(p); pbuf_free(p);
p = NULL; p = NULL;
break; break;
} }
} }
static void static void
arp_timer(void *arg) arp_timer(void *arg)
{ {
etharp_tmr(); etharp_tmr();
sys_timeout(ARP_TMR_INTERVAL, arp_timer, NULL); sys_timeout(ARP_TMR_INTERVAL, arp_timer, NULL);
} }
/* /*
* ethernetif_init(): * ethernetif_init():
* *
* Should be called at the beginning of the program to set up the * Should be called at the beginning of the program to set up the
* network interface. It calls the function low_level_init() to do the * network interface. It calls the function low_level_init() to do the
* actual setup of the hardware. * actual setup of the hardware.
* *
*/ */
err_t err_t
ethernetif_init(struct netif *netif) ethernetif_init(struct netif *netif)
{ {
struct ethernetif *ethernetif; struct ethernetif *ethernetif;
ethernetif = mem_malloc(sizeof(struct ethernetif)); ethernetif = mem_malloc(sizeof(struct ethernetif));
if (ethernetif == NULL) if (ethernetif == NULL)
{ {
LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_init: out of memory\n")); LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_init: out of memory\n"));
return ERR_MEM; return ERR_MEM;
} }
#if LWIP_SNMP #if LWIP_SNMP
/* ifType ethernetCsmacd(6) @see RFC1213 */ /* ifType ethernetCsmacd(6) @see RFC1213 */
netif->link_type = 6; netif->link_type = 6;
/* your link speed here */ /* your link speed here */
netif->link_speed = ; netif->link_speed = ;
netif->ts = 0; netif->ts = 0;
netif->ifinoctets = 0; netif->ifinoctets = 0;
netif->ifinucastpkts = 0; netif->ifinucastpkts = 0;
netif->ifinnucastpkts = 0; netif->ifinnucastpkts = 0;
netif->ifindiscards = 0; netif->ifindiscards = 0;
netif->ifoutoctets = 0; netif->ifoutoctets = 0;
netif->ifoutucastpkts = 0; netif->ifoutucastpkts = 0;
netif->ifoutnucastpkts = 0; netif->ifoutnucastpkts = 0;
netif->ifoutdiscards = 0; netif->ifoutdiscards = 0;
#endif #endif
netif->state = ethernetif; netif->state = ethernetif;
netif->name[0] = IFNAME0; netif->name[0] = IFNAME0;
netif->name[1] = IFNAME1; netif->name[1] = IFNAME1;
netif->output = ethernetif_output; netif->output = ethernetif_output;
netif->linkoutput = low_level_output; netif->linkoutput = low_level_output;
ethernetif->ethaddr = (struct eth_addr *)&(netif->hwaddr[0]); ethernetif->ethaddr = (struct eth_addr *)&(netif->hwaddr[0]);
low_level_init(netif); low_level_init(netif);
etharp_init(); etharp_init();
sys_timeout(ARP_TMR_INTERVAL, arp_timer, NULL); sys_timeout(ARP_TMR_INTERVAL, arp_timer, NULL);
return ERR_OK; return ERR_OK;
} }

View file

@ -1,119 +1,119 @@
/* /*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science. * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, * 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, * 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products * 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE. * OF SUCH DAMAGE.
* *
* This file is part of the lwIP TCP/IP stack. * This file is part of the lwIP TCP/IP stack.
* *
* Author: Adam Dunkels <adam@sics.se> * Author: Adam Dunkels <adam@sics.se>
* *
*/ */
#include "lwip/opt.h" #include "lwip/opt.h"
#if LWIP_HAVE_LOOPIF #if LWIP_HAVE_LOOPIF
#include "netif/loopif.h" #include "netif/loopif.h"
#include "lwip/mem.h" #include "lwip/mem.h"
#if defined(LWIP_DEBUG) && defined(LWIP_TCPDUMP) #if defined(LWIP_DEBUG) && defined(LWIP_TCPDUMP)
#include "netif/tcpdump.h" #include "netif/tcpdump.h"
#endif /* LWIP_DEBUG && LWIP_TCPDUMP */ #endif /* LWIP_DEBUG && LWIP_TCPDUMP */
#include "lwip/tcp.h" #include "lwip/tcp.h"
#include "lwip/ip.h" #include "lwip/ip.h"
static void static void
loopif_input( void * arg ) loopif_input( void * arg )
{ {
struct netif *netif = (struct netif *)( ((void **)arg)[ 0 ] ); struct netif *netif = (struct netif *)( ((void **)arg)[ 0 ] );
struct pbuf *r = (struct pbuf *)( ((void **)arg)[ 1 ] ); struct pbuf *r = (struct pbuf *)( ((void **)arg)[ 1 ] );
mem_free( arg ); mem_free( arg );
netif -> input( r, netif ); netif -> input( r, netif );
} }
static err_t static err_t
loopif_output(struct netif *netif, struct pbuf *p, loopif_output(struct netif *netif, struct pbuf *p,
struct ip_addr *ipaddr) struct ip_addr *ipaddr)
{ {
struct pbuf *q, *r; struct pbuf *q, *r;
u8_t *ptr; u8_t *ptr;
void **arg; void **arg;
#if defined(LWIP_DEBUG) && defined(LWIP_TCPDUMP) #if defined(LWIP_DEBUG) && defined(LWIP_TCPDUMP)
tcpdump(p); tcpdump(p);
#endif /* LWIP_DEBUG && LWIP_TCPDUMP */ #endif /* LWIP_DEBUG && LWIP_TCPDUMP */
r = pbuf_alloc(PBUF_RAW, p->tot_len, PBUF_RAM); r = pbuf_alloc(PBUF_RAW, p->tot_len, PBUF_RAM);
if (r != NULL) { if (r != NULL) {
ptr = r->payload; ptr = r->payload;
for(q = p; q != NULL; q = q->next) { for(q = p; q != NULL; q = q->next) {
memcpy(ptr, q->payload, q->len); memcpy(ptr, q->payload, q->len);
ptr += q->len; ptr += q->len;
} }
arg = mem_malloc( sizeof( void *[2])); arg = mem_malloc( sizeof( void *[2]));
if( NULL == arg ) { if( NULL == arg ) {
return ERR_MEM; return ERR_MEM;
} }
arg[0] = netif; arg[0] = netif;
arg[1] = r; arg[1] = r;
/** /**
* workaround (patch #1779) to try to prevent bug #2595: * workaround (patch #1779) to try to prevent bug #2595:
* When connecting to "localhost" with the loopif interface, * When connecting to "localhost" with the loopif interface,
* tcp_output doesn't get the opportunity to finnish sending the * tcp_output doesn't get the opportunity to finnish sending the
* segment before tcp_process gets it, resulting in tcp_process * segment before tcp_process gets it, resulting in tcp_process
* referencing pcb->unacked-> which still is NULL. * referencing pcb->unacked-> which still is NULL.
* *
* TODO: Is there still a race condition here? Leon * TODO: Is there still a race condition here? Leon
*/ */
sys_timeout( 1, loopif_input, arg ); sys_timeout( 1, loopif_input, arg );
return ERR_OK; return ERR_OK;
} }
return ERR_MEM; return ERR_MEM;
} }
err_t err_t
loopif_init(struct netif *netif) loopif_init(struct netif *netif)
{ {
netif->name[0] = 'l'; netif->name[0] = 'l';
netif->name[1] = 'o'; netif->name[1] = 'o';
#if 0 /** TODO: I think this should be enabled, or not? Leon */ #if 0 /** TODO: I think this should be enabled, or not? Leon */
netif->input = loopif_input; netif->input = loopif_input;
#endif #endif
netif->output = loopif_output; netif->output = loopif_output;
return ERR_OK; return ERR_OK;
} }
#endif /* LWIP_HAVE_LOOPIF */ #endif /* LWIP_HAVE_LOOPIF */

File diff suppressed because it is too large Load diff

View file

@ -1,94 +1,94 @@
/***************************************************************************** /*****************************************************************************
* auth.h - PPP Authentication and phase control header file. * auth.h - PPP Authentication and phase control header file.
* *
* Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc. * Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc.
* portions Copyright (c) 1998 Global Election Systems Inc. * portions Copyright (c) 1998 Global Election Systems Inc.
* *
* The authors hereby grant permission to use, copy, modify, distribute, * The authors hereby grant permission to use, copy, modify, distribute,
* and license this software and its documentation for any purpose, provided * and license this software and its documentation for any purpose, provided
* that existing copyright notices are retained in all copies and that this * that existing copyright notices are retained in all copies and that this
* notice and the following disclaimer are included verbatim in any * notice and the following disclaimer are included verbatim in any
* distributions. No written agreement, license, or royalty fee is required * distributions. No written agreement, license, or royalty fee is required
* for any of the authorized uses. * for any of the authorized uses.
* *
* THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
****************************************************************************** ******************************************************************************
* REVISION HISTORY * REVISION HISTORY
* *
* 03-01-01 Marc Boucher <marc@mbsi.ca> * 03-01-01 Marc Boucher <marc@mbsi.ca>
* Ported to lwIP. * Ported to lwIP.
* 97-12-04 Guy Lancaster <lancasterg@acm.org>, Global Election Systems Inc. * 97-12-04 Guy Lancaster <lancasterg@acm.org>, Global Election Systems Inc.
* Original derived from BSD pppd.h. * Original derived from BSD pppd.h.
*****************************************************************************/ *****************************************************************************/
/* /*
* pppd.h - PPP daemon global declarations. * pppd.h - PPP daemon global declarations.
* *
* Copyright (c) 1989 Carnegie Mellon University. * Copyright (c) 1989 Carnegie Mellon University.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms are permitted * Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are * provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation, * duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such * advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed * distribution and use acknowledge that the software was developed
* by Carnegie Mellon University. The name of the * by Carnegie Mellon University. The name of the
* University may not be used to endorse or promote products derived * University may not be used to endorse or promote products derived
* from this software without specific prior written permission. * from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
* *
*/ */
#ifndef AUTH_H #ifndef AUTH_H
#define AUTH_H #define AUTH_H
/*********************** /***********************
*** PUBLIC FUNCTIONS *** *** PUBLIC FUNCTIONS ***
***********************/ ***********************/
void link_required (int); /* we are starting to use the link */ void link_required (int); /* we are starting to use the link */
void link_terminated (int); /* we are finished with the link */ void link_terminated (int); /* we are finished with the link */
void link_down (int); /* the LCP layer has left the Opened state */ void link_down (int); /* the LCP layer has left the Opened state */
void link_established (int); /* the link is up; authenticate now */ void link_established (int); /* the link is up; authenticate now */
void np_up (int, u16_t); /* a network protocol has come up */ void np_up (int, u16_t); /* a network protocol has come up */
void np_down (int, u16_t); /* a network protocol has gone down */ void np_down (int, u16_t); /* a network protocol has gone down */
void np_finished (int, u16_t); /* a network protocol no longer needs link */ void np_finished (int, u16_t); /* a network protocol no longer needs link */
void auth_peer_fail (int, u16_t);/* peer failed to authenticate itself */ void auth_peer_fail (int, u16_t);/* peer failed to authenticate itself */
/* peer successfully authenticated itself */ /* peer successfully authenticated itself */
void auth_peer_success (int, u16_t, char *, int); void auth_peer_success (int, u16_t, char *, int);
/* we failed to authenticate ourselves */ /* we failed to authenticate ourselves */
void auth_withpeer_fail (int, u16_t); void auth_withpeer_fail (int, u16_t);
/* we successfully authenticated ourselves */ /* we successfully authenticated ourselves */
void auth_withpeer_success (int, u16_t); void auth_withpeer_success (int, u16_t);
/* check authentication options supplied */ /* check authentication options supplied */
void auth_check_options (void); void auth_check_options (void);
void auth_reset (int); /* check what secrets we have */ void auth_reset (int); /* check what secrets we have */
/* Check peer-supplied username/password */ /* Check peer-supplied username/password */
int check_passwd (int, char *, int, char *, int, char **, int *); int check_passwd (int, char *, int, char *, int, char **, int *);
/* get "secret" for chap */ /* get "secret" for chap */
int get_secret (int, char *, char *, char *, int *, int); int get_secret (int, char *, char *, char *, int *, int);
/* check if IP address is authorized */ /* check if IP address is authorized */
int auth_ip_addr (int, u32_t); int auth_ip_addr (int, u32_t);
/* check if IP address is unreasonable */ /* check if IP address is unreasonable */
int bad_ip_adrs (u32_t); int bad_ip_adrs (u32_t);
#endif /* AUTH_H */ #endif /* AUTH_H */

File diff suppressed because it is too large Load diff

View file

@ -1,167 +1,167 @@
/***************************************************************************** /*****************************************************************************
* chap.h - Network Challenge Handshake Authentication Protocol header file. * chap.h - Network Challenge Handshake Authentication Protocol header file.
* *
* Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc. * Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc.
* portions Copyright (c) 1998 Global Election Systems Inc. * portions Copyright (c) 1998 Global Election Systems Inc.
* *
* The authors hereby grant permission to use, copy, modify, distribute, * The authors hereby grant permission to use, copy, modify, distribute,
* and license this software and its documentation for any purpose, provided * and license this software and its documentation for any purpose, provided
* that existing copyright notices are retained in all copies and that this * that existing copyright notices are retained in all copies and that this
* notice and the following disclaimer are included verbatim in any * notice and the following disclaimer are included verbatim in any
* distributions. No written agreement, license, or royalty fee is required * distributions. No written agreement, license, or royalty fee is required
* for any of the authorized uses. * for any of the authorized uses.
* *
* THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
****************************************************************************** ******************************************************************************
* REVISION HISTORY * REVISION HISTORY
* *
* 03-01-01 Marc Boucher <marc@mbsi.ca> * 03-01-01 Marc Boucher <marc@mbsi.ca>
* Ported to lwIP. * Ported to lwIP.
* 97-12-03 Guy Lancaster <lancasterg@acm.org>, Global Election Systems Inc. * 97-12-03 Guy Lancaster <lancasterg@acm.org>, Global Election Systems Inc.
* Original built from BSD network code. * Original built from BSD network code.
******************************************************************************/ ******************************************************************************/
/* /*
* chap.h - Challenge Handshake Authentication Protocol definitions. * chap.h - Challenge Handshake Authentication Protocol definitions.
* *
* Copyright (c) 1993 The Australian National University. * Copyright (c) 1993 The Australian National University.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms are permitted * Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are * provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation, * duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such * advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed * distribution and use acknowledge that the software was developed
* by the Australian National University. The name of the University * by the Australian National University. The name of the University
* may not be used to endorse or promote products derived from this * may not be used to endorse or promote products derived from this
* software without specific prior written permission. * software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
* *
* Copyright (c) 1991 Gregory M. Christy * Copyright (c) 1991 Gregory M. Christy
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms are permitted * Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are * provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation, * duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such * advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed * distribution and use acknowledge that the software was developed
* by the author. * by the author.
* *
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
* *
* $Id: chap.h,v 1.1 2003/05/27 14:37:56 jani Exp $ * $Id: chap.h,v 1.1 2003/05/27 14:37:56 jani Exp $
*/ */
#ifndef CHAP_H #ifndef CHAP_H
#define CHAP_H #define CHAP_H
/************************* /*************************
*** PUBLIC DEFINITIONS *** *** PUBLIC DEFINITIONS ***
*************************/ *************************/
/* Code + ID + length */ /* Code + ID + length */
#define CHAP_HEADERLEN 4 #define CHAP_HEADERLEN 4
/* /*
* CHAP codes. * CHAP codes.
*/ */
#define CHAP_DIGEST_MD5 5 /* use MD5 algorithm */ #define CHAP_DIGEST_MD5 5 /* use MD5 algorithm */
#define MD5_SIGNATURE_SIZE 16 /* 16 bytes in a MD5 message digest */ #define MD5_SIGNATURE_SIZE 16 /* 16 bytes in a MD5 message digest */
#define CHAP_MICROSOFT 0x80 /* use Microsoft-compatible alg. */ #define CHAP_MICROSOFT 0x80 /* use Microsoft-compatible alg. */
#define MS_CHAP_RESPONSE_LEN 49 /* Response length for MS-CHAP */ #define MS_CHAP_RESPONSE_LEN 49 /* Response length for MS-CHAP */
#define CHAP_CHALLENGE 1 #define CHAP_CHALLENGE 1
#define CHAP_RESPONSE 2 #define CHAP_RESPONSE 2
#define CHAP_SUCCESS 3 #define CHAP_SUCCESS 3
#define CHAP_FAILURE 4 #define CHAP_FAILURE 4
/* /*
* Challenge lengths (for challenges we send) and other limits. * Challenge lengths (for challenges we send) and other limits.
*/ */
#define MIN_CHALLENGE_LENGTH 32 #define MIN_CHALLENGE_LENGTH 32
#define MAX_CHALLENGE_LENGTH 64 #define MAX_CHALLENGE_LENGTH 64
#define MAX_RESPONSE_LENGTH 64 /* sufficient for MD5 or MS-CHAP */ #define MAX_RESPONSE_LENGTH 64 /* sufficient for MD5 or MS-CHAP */
/* /*
* Client (peer) states. * Client (peer) states.
*/ */
#define CHAPCS_INITIAL 0 /* Lower layer down, not opened */ #define CHAPCS_INITIAL 0 /* Lower layer down, not opened */
#define CHAPCS_CLOSED 1 /* Lower layer up, not opened */ #define CHAPCS_CLOSED 1 /* Lower layer up, not opened */
#define CHAPCS_PENDING 2 /* Auth us to peer when lower up */ #define CHAPCS_PENDING 2 /* Auth us to peer when lower up */
#define CHAPCS_LISTEN 3 /* Listening for a challenge */ #define CHAPCS_LISTEN 3 /* Listening for a challenge */
#define CHAPCS_RESPONSE 4 /* Sent response, waiting for status */ #define CHAPCS_RESPONSE 4 /* Sent response, waiting for status */
#define CHAPCS_OPEN 5 /* We've received Success */ #define CHAPCS_OPEN 5 /* We've received Success */
/* /*
* Server (authenticator) states. * Server (authenticator) states.
*/ */
#define CHAPSS_INITIAL 0 /* Lower layer down, not opened */ #define CHAPSS_INITIAL 0 /* Lower layer down, not opened */
#define CHAPSS_CLOSED 1 /* Lower layer up, not opened */ #define CHAPSS_CLOSED 1 /* Lower layer up, not opened */
#define CHAPSS_PENDING 2 /* Auth peer when lower up */ #define CHAPSS_PENDING 2 /* Auth peer when lower up */
#define CHAPSS_INITIAL_CHAL 3 /* We've sent the first challenge */ #define CHAPSS_INITIAL_CHAL 3 /* We've sent the first challenge */
#define CHAPSS_OPEN 4 /* We've sent a Success msg */ #define CHAPSS_OPEN 4 /* We've sent a Success msg */
#define CHAPSS_RECHALLENGE 5 /* We've sent another challenge */ #define CHAPSS_RECHALLENGE 5 /* We've sent another challenge */
#define CHAPSS_BADAUTH 6 /* We've sent a Failure msg */ #define CHAPSS_BADAUTH 6 /* We've sent a Failure msg */
/************************ /************************
*** PUBLIC DATA TYPES *** *** PUBLIC DATA TYPES ***
************************/ ************************/
/* /*
* Each interface is described by a chap structure. * Each interface is described by a chap structure.
*/ */
typedef struct chap_state { typedef struct chap_state {
int unit; /* Interface unit number */ int unit; /* Interface unit number */
int clientstate; /* Client state */ int clientstate; /* Client state */
int serverstate; /* Server state */ int serverstate; /* Server state */
u_char challenge[MAX_CHALLENGE_LENGTH]; /* last challenge string sent */ u_char challenge[MAX_CHALLENGE_LENGTH]; /* last challenge string sent */
u_char chal_len; /* challenge length */ u_char chal_len; /* challenge length */
u_char chal_id; /* ID of last challenge */ u_char chal_id; /* ID of last challenge */
u_char chal_type; /* hash algorithm for challenges */ u_char chal_type; /* hash algorithm for challenges */
u_char id; /* Current id */ u_char id; /* Current id */
char *chal_name; /* Our name to use with challenge */ char *chal_name; /* Our name to use with challenge */
int chal_interval; /* Time until we challenge peer again */ int chal_interval; /* Time until we challenge peer again */
int timeouttime; /* Timeout time in seconds */ int timeouttime; /* Timeout time in seconds */
int max_transmits; /* Maximum # of challenge transmissions */ int max_transmits; /* Maximum # of challenge transmissions */
int chal_transmits; /* Number of transmissions of challenge */ int chal_transmits; /* Number of transmissions of challenge */
int resp_transmits; /* Number of transmissions of response */ int resp_transmits; /* Number of transmissions of response */
u_char response[MAX_RESPONSE_LENGTH]; /* Response to send */ u_char response[MAX_RESPONSE_LENGTH]; /* Response to send */
u_char resp_length; /* length of response */ u_char resp_length; /* length of response */
u_char resp_id; /* ID for response messages */ u_char resp_id; /* ID for response messages */
u_char resp_type; /* hash algorithm for responses */ u_char resp_type; /* hash algorithm for responses */
char *resp_name; /* Our name to send with response */ char *resp_name; /* Our name to send with response */
} chap_state; } chap_state;
/****************** /******************
*** PUBLIC DATA *** *** PUBLIC DATA ***
******************/ ******************/
extern chap_state chap[]; extern chap_state chap[];
extern struct protent chap_protent; extern struct protent chap_protent;
/*********************** /***********************
*** PUBLIC FUNCTIONS *** *** PUBLIC FUNCTIONS ***
***********************/ ***********************/
void ChapAuthWithPeer (int, char *, int); void ChapAuthWithPeer (int, char *, int);
void ChapAuthPeer (int, char *, int); void ChapAuthPeer (int, char *, int);
#endif /* CHAP_H */ #endif /* CHAP_H */

View file

@ -1,398 +1,398 @@
/*** WARNING - THIS CODE HAS NOT BEEN FINISHED! ***/ /*** WARNING - THIS CODE HAS NOT BEEN FINISHED! ***/
/***************************************************************************** /*****************************************************************************
* chpms.c - Network MicroSoft Challenge Handshake Authentication Protocol program file. * chpms.c - Network MicroSoft Challenge Handshake Authentication Protocol program file.
* *
* Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc. * Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc.
* Copyright (c) 1997 by Global Election Systems Inc. All rights reserved. * Copyright (c) 1997 by Global Election Systems Inc. All rights reserved.
* *
* The authors hereby grant permission to use, copy, modify, distribute, * The authors hereby grant permission to use, copy, modify, distribute,
* and license this software and its documentation for any purpose, provided * and license this software and its documentation for any purpose, provided
* that existing copyright notices are retained in all copies and that this * that existing copyright notices are retained in all copies and that this
* notice and the following disclaimer are included verbatim in any * notice and the following disclaimer are included verbatim in any
* distributions. No written agreement, license, or royalty fee is required * distributions. No written agreement, license, or royalty fee is required
* for any of the authorized uses. * for any of the authorized uses.
* *
* THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
****************************************************************************** ******************************************************************************
* REVISION HISTORY * REVISION HISTORY
* *
* 03-01-01 Marc Boucher <marc@mbsi.ca> * 03-01-01 Marc Boucher <marc@mbsi.ca>
* Ported to lwIP. * Ported to lwIP.
* 97-12-08 Guy Lancaster <lancasterg@acm.org>, Global Election Systems Inc. * 97-12-08 Guy Lancaster <lancasterg@acm.org>, Global Election Systems Inc.
* Original based on BSD chap_ms.c. * Original based on BSD chap_ms.c.
*****************************************************************************/ *****************************************************************************/
/* /*
* chap_ms.c - Microsoft MS-CHAP compatible implementation. * chap_ms.c - Microsoft MS-CHAP compatible implementation.
* *
* Copyright (c) 1995 Eric Rosenquist, Strata Software Limited. * Copyright (c) 1995 Eric Rosenquist, Strata Software Limited.
* http://www.strataware.com/ * http://www.strataware.com/
* *
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms are permitted * Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are * provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation, * duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such * advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed * distribution and use acknowledge that the software was developed
* by Eric Rosenquist. The name of the author may not be used to * by Eric Rosenquist. The name of the author may not be used to
* endorse or promote products derived from this software without * endorse or promote products derived from this software without
* specific prior written permission. * specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/ */
/* /*
* Modifications by Lauri Pesonen / lpesonen@clinet.fi, april 1997 * Modifications by Lauri Pesonen / lpesonen@clinet.fi, april 1997
* *
* Implemented LANManager type password response to MS-CHAP challenges. * Implemented LANManager type password response to MS-CHAP challenges.
* Now pppd provides both NT style and LANMan style blocks, and the * Now pppd provides both NT style and LANMan style blocks, and the
* prefered is set by option "ms-lanman". Default is to use NT. * prefered is set by option "ms-lanman". Default is to use NT.
* The hash text (StdText) was taken from Win95 RASAPI32.DLL. * The hash text (StdText) was taken from Win95 RASAPI32.DLL.
* *
* You should also use DOMAIN\\USERNAME as described in README.MSCHAP80 * You should also use DOMAIN\\USERNAME as described in README.MSCHAP80
*/ */
#define USE_CRYPT #define USE_CRYPT
#include "ppp.h" #include "ppp.h"
#if MSCHAP_SUPPORT > 0 #if MSCHAP_SUPPORT > 0
#include "md4.h" #include "md4.h"
#ifndef USE_CRYPT #ifndef USE_CRYPT
#include "des.h" #include "des.h"
#endif #endif
#include "chap.h" #include "chap.h"
#include "chpms.h" #include "chpms.h"
#include "pppdebug.h" #include "pppdebug.h"
/*************************/ /*************************/
/*** LOCAL DEFINITIONS ***/ /*** LOCAL DEFINITIONS ***/
/*************************/ /*************************/
/************************/ /************************/
/*** LOCAL DATA TYPES ***/ /*** LOCAL DATA TYPES ***/
/************************/ /************************/
typedef struct { typedef struct {
u_char LANManResp[24]; u_char LANManResp[24];
u_char NTResp[24]; u_char NTResp[24];
u_char UseNT; /* If 1, ignore the LANMan response field */ u_char UseNT; /* If 1, ignore the LANMan response field */
} MS_ChapResponse; } MS_ChapResponse;
/* We use MS_CHAP_RESPONSE_LEN, rather than sizeof(MS_ChapResponse), /* We use MS_CHAP_RESPONSE_LEN, rather than sizeof(MS_ChapResponse),
in case this struct gets padded. */ in case this struct gets padded. */
/***********************************/ /***********************************/
/*** LOCAL FUNCTION DECLARATIONS ***/ /*** LOCAL FUNCTION DECLARATIONS ***/
/***********************************/ /***********************************/
/* XXX Don't know what to do with these. */ /* XXX Don't know what to do with these. */
extern void setkey(const char *); extern void setkey(const char *);
extern void encrypt(char *, int); extern void encrypt(char *, int);
static void DesEncrypt (u_char *, u_char *, u_char *); static void DesEncrypt (u_char *, u_char *, u_char *);
static void MakeKey (u_char *, u_char *); static void MakeKey (u_char *, u_char *);
#ifdef USE_CRYPT #ifdef USE_CRYPT
static void Expand (u_char *, u_char *); static void Expand (u_char *, u_char *);
static void Collapse (u_char *, u_char *); static void Collapse (u_char *, u_char *);
#endif #endif
static void ChallengeResponse( static void ChallengeResponse(
u_char *challenge, /* IN 8 octets */ u_char *challenge, /* IN 8 octets */
u_char *pwHash, /* IN 16 octets */ u_char *pwHash, /* IN 16 octets */
u_char *response /* OUT 24 octets */ u_char *response /* OUT 24 octets */
); );
static void ChapMS_NT( static void ChapMS_NT(
char *rchallenge, char *rchallenge,
int rchallenge_len, int rchallenge_len,
char *secret, char *secret,
int secret_len, int secret_len,
MS_ChapResponse *response MS_ChapResponse *response
); );
static u_char Get7Bits( static u_char Get7Bits(
u_char *input, u_char *input,
int startBit int startBit
); );
/***********************************/ /***********************************/
/*** PUBLIC FUNCTION DEFINITIONS ***/ /*** PUBLIC FUNCTION DEFINITIONS ***/
/***********************************/ /***********************************/
void ChapMS( void ChapMS(
chap_state *cstate, chap_state *cstate,
char *rchallenge, char *rchallenge,
int rchallenge_len, int rchallenge_len,
char *secret, char *secret,
int secret_len int secret_len
) )
{ {
MS_ChapResponse response; MS_ChapResponse response;
#ifdef MSLANMAN #ifdef MSLANMAN
extern int ms_lanman; extern int ms_lanman;
#endif #endif
#if 0 #if 0
CHAPDEBUG((LOG_INFO, "ChapMS: secret is '%.*s'\n", secret_len, secret)); CHAPDEBUG((LOG_INFO, "ChapMS: secret is '%.*s'\n", secret_len, secret));
#endif #endif
BZERO(&response, sizeof(response)); BZERO(&response, sizeof(response));
/* Calculate both always */ /* Calculate both always */
ChapMS_NT(rchallenge, rchallenge_len, secret, secret_len, &response); ChapMS_NT(rchallenge, rchallenge_len, secret, secret_len, &response);
#ifdef MSLANMAN #ifdef MSLANMAN
ChapMS_LANMan(rchallenge, rchallenge_len, secret, secret_len, &response); ChapMS_LANMan(rchallenge, rchallenge_len, secret, secret_len, &response);
/* prefered method is set by option */ /* prefered method is set by option */
response.UseNT = !ms_lanman; response.UseNT = !ms_lanman;
#else #else
response.UseNT = 1; response.UseNT = 1;
#endif #endif
BCOPY(&response, cstate->response, MS_CHAP_RESPONSE_LEN); BCOPY(&response, cstate->response, MS_CHAP_RESPONSE_LEN);
cstate->resp_length = MS_CHAP_RESPONSE_LEN; cstate->resp_length = MS_CHAP_RESPONSE_LEN;
} }
/**********************************/ /**********************************/
/*** LOCAL FUNCTION DEFINITIONS ***/ /*** LOCAL FUNCTION DEFINITIONS ***/
/**********************************/ /**********************************/
static void ChallengeResponse( static void ChallengeResponse(
u_char *challenge, /* IN 8 octets */ u_char *challenge, /* IN 8 octets */
u_char *pwHash, /* IN 16 octets */ u_char *pwHash, /* IN 16 octets */
u_char *response /* OUT 24 octets */ u_char *response /* OUT 24 octets */
) )
{ {
char ZPasswordHash[21]; char ZPasswordHash[21];
BZERO(ZPasswordHash, sizeof(ZPasswordHash)); BZERO(ZPasswordHash, sizeof(ZPasswordHash));
BCOPY(pwHash, ZPasswordHash, 16); BCOPY(pwHash, ZPasswordHash, 16);
#if 0 #if 0
log_packet(ZPasswordHash, sizeof(ZPasswordHash), "ChallengeResponse - ZPasswordHash", LOG_DEBUG); log_packet(ZPasswordHash, sizeof(ZPasswordHash), "ChallengeResponse - ZPasswordHash", LOG_DEBUG);
#endif #endif
DesEncrypt(challenge, ZPasswordHash + 0, response + 0); DesEncrypt(challenge, ZPasswordHash + 0, response + 0);
DesEncrypt(challenge, ZPasswordHash + 7, response + 8); DesEncrypt(challenge, ZPasswordHash + 7, response + 8);
DesEncrypt(challenge, ZPasswordHash + 14, response + 16); DesEncrypt(challenge, ZPasswordHash + 14, response + 16);
#if 0 #if 0
log_packet(response, 24, "ChallengeResponse - response", LOG_DEBUG); log_packet(response, 24, "ChallengeResponse - response", LOG_DEBUG);
#endif #endif
} }
#ifdef USE_CRYPT #ifdef USE_CRYPT
static void DesEncrypt( static void DesEncrypt(
u_char *clear, /* IN 8 octets */ u_char *clear, /* IN 8 octets */
u_char *key, /* IN 7 octets */ u_char *key, /* IN 7 octets */
u_char *cipher /* OUT 8 octets */ u_char *cipher /* OUT 8 octets */
) )
{ {
u_char des_key[8]; u_char des_key[8];
u_char crypt_key[66]; u_char crypt_key[66];
u_char des_input[66]; u_char des_input[66];
MakeKey(key, des_key); MakeKey(key, des_key);
Expand(des_key, crypt_key); Expand(des_key, crypt_key);
setkey(crypt_key); setkey(crypt_key);
#if 0 #if 0
CHAPDEBUG((LOG_INFO, "DesEncrypt: 8 octet input : %02X%02X%02X%02X%02X%02X%02X%02X\n", CHAPDEBUG((LOG_INFO, "DesEncrypt: 8 octet input : %02X%02X%02X%02X%02X%02X%02X%02X\n",
clear[0], clear[1], clear[2], clear[3], clear[4], clear[5], clear[6], clear[7])); clear[0], clear[1], clear[2], clear[3], clear[4], clear[5], clear[6], clear[7]));
#endif #endif
Expand(clear, des_input); Expand(clear, des_input);
encrypt(des_input, 0); encrypt(des_input, 0);
Collapse(des_input, cipher); Collapse(des_input, cipher);
#if 0 #if 0
CHAPDEBUG((LOG_INFO, "DesEncrypt: 8 octet output: %02X%02X%02X%02X%02X%02X%02X%02X\n", CHAPDEBUG((LOG_INFO, "DesEncrypt: 8 octet output: %02X%02X%02X%02X%02X%02X%02X%02X\n",
cipher[0], cipher[1], cipher[2], cipher[3], cipher[4], cipher[5], cipher[6], cipher[7])); cipher[0], cipher[1], cipher[2], cipher[3], cipher[4], cipher[5], cipher[6], cipher[7]));
#endif #endif
} }
#else /* USE_CRYPT */ #else /* USE_CRYPT */
static void DesEncrypt( static void DesEncrypt(
u_char *clear, /* IN 8 octets */ u_char *clear, /* IN 8 octets */
u_char *key, /* IN 7 octets */ u_char *key, /* IN 7 octets */
u_char *cipher /* OUT 8 octets */ u_char *cipher /* OUT 8 octets */
) )
{ {
des_cblock des_key; des_cblock des_key;
des_key_schedule key_schedule; des_key_schedule key_schedule;
MakeKey(key, des_key); MakeKey(key, des_key);
des_set_key(&des_key, key_schedule); des_set_key(&des_key, key_schedule);
#if 0 #if 0
CHAPDEBUG((LOG_INFO, "DesEncrypt: 8 octet input : %02X%02X%02X%02X%02X%02X%02X%02X\n", CHAPDEBUG((LOG_INFO, "DesEncrypt: 8 octet input : %02X%02X%02X%02X%02X%02X%02X%02X\n",
clear[0], clear[1], clear[2], clear[3], clear[4], clear[5], clear[6], clear[7])); clear[0], clear[1], clear[2], clear[3], clear[4], clear[5], clear[6], clear[7]));
#endif #endif
des_ecb_encrypt((des_cblock *)clear, (des_cblock *)cipher, key_schedule, 1); des_ecb_encrypt((des_cblock *)clear, (des_cblock *)cipher, key_schedule, 1);
#if 0 #if 0
CHAPDEBUG((LOG_INFO, "DesEncrypt: 8 octet output: %02X%02X%02X%02X%02X%02X%02X%02X\n", CHAPDEBUG((LOG_INFO, "DesEncrypt: 8 octet output: %02X%02X%02X%02X%02X%02X%02X%02X\n",
cipher[0], cipher[1], cipher[2], cipher[3], cipher[4], cipher[5], cipher[6], cipher[7])); cipher[0], cipher[1], cipher[2], cipher[3], cipher[4], cipher[5], cipher[6], cipher[7]));
#endif #endif
} }
#endif /* USE_CRYPT */ #endif /* USE_CRYPT */
static u_char Get7Bits( static u_char Get7Bits(
u_char *input, u_char *input,
int startBit int startBit
) )
{ {
register unsigned int word; register unsigned int word;
word = (unsigned)input[startBit / 8] << 8; word = (unsigned)input[startBit / 8] << 8;
word |= (unsigned)input[startBit / 8 + 1]; word |= (unsigned)input[startBit / 8 + 1];
word >>= 15 - (startBit % 8 + 7); word >>= 15 - (startBit % 8 + 7);
return word & 0xFE; return word & 0xFE;
} }
#ifdef USE_CRYPT #ifdef USE_CRYPT
/* in == 8-byte string (expanded version of the 56-bit key) /* in == 8-byte string (expanded version of the 56-bit key)
* out == 64-byte string where each byte is either 1 or 0 * out == 64-byte string where each byte is either 1 or 0
* Note that the low-order "bit" is always ignored by by setkey() * Note that the low-order "bit" is always ignored by by setkey()
*/ */
static void Expand(u_char *in, u_char *out) static void Expand(u_char *in, u_char *out)
{ {
int j, c; int j, c;
int i; int i;
for(i = 0; i < 64; in++){ for(i = 0; i < 64; in++){
c = *in; c = *in;
for(j = 7; j >= 0; j--) for(j = 7; j >= 0; j--)
*out++ = (c >> j) & 01; *out++ = (c >> j) & 01;
i += 8; i += 8;
} }
} }
/* The inverse of Expand /* The inverse of Expand
*/ */
static void Collapse(u_char *in, u_char *out) static void Collapse(u_char *in, u_char *out)
{ {
int j; int j;
int i; int i;
unsigned int c; unsigned int c;
for (i = 0; i < 64; i += 8, out++) { for (i = 0; i < 64; i += 8, out++) {
c = 0; c = 0;
for (j = 7; j >= 0; j--, in++) for (j = 7; j >= 0; j--, in++)
c |= *in << j; c |= *in << j;
*out = c & 0xff; *out = c & 0xff;
} }
} }
#endif #endif
static void MakeKey( static void MakeKey(
u_char *key, /* IN 56 bit DES key missing parity bits */ u_char *key, /* IN 56 bit DES key missing parity bits */
u_char *des_key /* OUT 64 bit DES key with parity bits added */ u_char *des_key /* OUT 64 bit DES key with parity bits added */
) )
{ {
des_key[0] = Get7Bits(key, 0); des_key[0] = Get7Bits(key, 0);
des_key[1] = Get7Bits(key, 7); des_key[1] = Get7Bits(key, 7);
des_key[2] = Get7Bits(key, 14); des_key[2] = Get7Bits(key, 14);
des_key[3] = Get7Bits(key, 21); des_key[3] = Get7Bits(key, 21);
des_key[4] = Get7Bits(key, 28); des_key[4] = Get7Bits(key, 28);
des_key[5] = Get7Bits(key, 35); des_key[5] = Get7Bits(key, 35);
des_key[6] = Get7Bits(key, 42); des_key[6] = Get7Bits(key, 42);
des_key[7] = Get7Bits(key, 49); des_key[7] = Get7Bits(key, 49);
#ifndef USE_CRYPT #ifndef USE_CRYPT
des_set_odd_parity((des_cblock *)des_key); des_set_odd_parity((des_cblock *)des_key);
#endif #endif
#if 0 #if 0
CHAPDEBUG((LOG_INFO, "MakeKey: 56-bit input : %02X%02X%02X%02X%02X%02X%02X\n", CHAPDEBUG((LOG_INFO, "MakeKey: 56-bit input : %02X%02X%02X%02X%02X%02X%02X\n",
key[0], key[1], key[2], key[3], key[4], key[5], key[6])); key[0], key[1], key[2], key[3], key[4], key[5], key[6]));
CHAPDEBUG((LOG_INFO, "MakeKey: 64-bit output: %02X%02X%02X%02X%02X%02X%02X%02X\n", CHAPDEBUG((LOG_INFO, "MakeKey: 64-bit output: %02X%02X%02X%02X%02X%02X%02X%02X\n",
des_key[0], des_key[1], des_key[2], des_key[3], des_key[4], des_key[5], des_key[6], des_key[7])); des_key[0], des_key[1], des_key[2], des_key[3], des_key[4], des_key[5], des_key[6], des_key[7]));
#endif #endif
} }
static void ChapMS_NT( static void ChapMS_NT(
char *rchallenge, char *rchallenge,
int rchallenge_len, int rchallenge_len,
char *secret, char *secret,
int secret_len, int secret_len,
MS_ChapResponse *response MS_ChapResponse *response
) )
{ {
int i; int i;
MDstruct md4Context; MDstruct md4Context;
u_char unicodePassword[MAX_NT_PASSWORD * 2]; u_char unicodePassword[MAX_NT_PASSWORD * 2];
static int low_byte_first = -1; static int low_byte_first = -1;
/* Initialize the Unicode version of the secret (== password). */ /* Initialize the Unicode version of the secret (== password). */
/* This implicitly supports 8-bit ISO8859/1 characters. */ /* This implicitly supports 8-bit ISO8859/1 characters. */
BZERO(unicodePassword, sizeof(unicodePassword)); BZERO(unicodePassword, sizeof(unicodePassword));
for (i = 0; i < secret_len; i++) for (i = 0; i < secret_len; i++)
unicodePassword[i * 2] = (u_char)secret[i]; unicodePassword[i * 2] = (u_char)secret[i];
MDbegin(&md4Context); MDbegin(&md4Context);
MDupdate(&md4Context, unicodePassword, secret_len * 2 * 8); /* Unicode is 2 bytes/char, *8 for bit count */ MDupdate(&md4Context, unicodePassword, secret_len * 2 * 8); /* Unicode is 2 bytes/char, *8 for bit count */
if (low_byte_first == -1) if (low_byte_first == -1)
low_byte_first = (htons((unsigned short int)1) != 1); low_byte_first = (htons((unsigned short int)1) != 1);
if (low_byte_first == 0) if (low_byte_first == 0)
MDreverse((u_long *)&md4Context); /* sfb 961105 */ MDreverse((u_long *)&md4Context); /* sfb 961105 */
MDupdate(&md4Context, NULL, 0); /* Tell MD4 we're done */ MDupdate(&md4Context, NULL, 0); /* Tell MD4 we're done */
ChallengeResponse(rchallenge, (char *)md4Context.buffer, response->NTResp); ChallengeResponse(rchallenge, (char *)md4Context.buffer, response->NTResp);
} }
#ifdef MSLANMAN #ifdef MSLANMAN
static u_char *StdText = (u_char *)"KGS!@#$%"; /* key from rasapi32.dll */ static u_char *StdText = (u_char *)"KGS!@#$%"; /* key from rasapi32.dll */
static ChapMS_LANMan( static ChapMS_LANMan(
char *rchallenge, char *rchallenge,
int rchallenge_len, int rchallenge_len,
char *secret, char *secret,
int secret_len, int secret_len,
MS_ChapResponse *response MS_ChapResponse *response
) )
{ {
int i; int i;
u_char UcasePassword[MAX_NT_PASSWORD]; /* max is actually 14 */ u_char UcasePassword[MAX_NT_PASSWORD]; /* max is actually 14 */
u_char PasswordHash[16]; u_char PasswordHash[16];
/* LANMan password is case insensitive */ /* LANMan password is case insensitive */
BZERO(UcasePassword, sizeof(UcasePassword)); BZERO(UcasePassword, sizeof(UcasePassword));
for (i = 0; i < secret_len; i++) for (i = 0; i < secret_len; i++)
UcasePassword[i] = (u_char)toupper(secret[i]); UcasePassword[i] = (u_char)toupper(secret[i]);
DesEncrypt( StdText, UcasePassword + 0, PasswordHash + 0 ); DesEncrypt( StdText, UcasePassword + 0, PasswordHash + 0 );
DesEncrypt( StdText, UcasePassword + 7, PasswordHash + 8 ); DesEncrypt( StdText, UcasePassword + 7, PasswordHash + 8 );
ChallengeResponse(rchallenge, PasswordHash, response->LANManResp); ChallengeResponse(rchallenge, PasswordHash, response->LANManResp);
} }
#endif #endif
#endif /* MSCHAP_SUPPORT */ #endif /* MSCHAP_SUPPORT */

View file

@ -1,64 +1,64 @@
/***************************************************************************** /*****************************************************************************
* chpms.h - Network Microsoft Challenge Handshake Protocol header file. * chpms.h - Network Microsoft Challenge Handshake Protocol header file.
* *
* Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc. * Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc.
* portions Copyright (c) 1998 Global Election Systems Inc. * portions Copyright (c) 1998 Global Election Systems Inc.
* *
* The authors hereby grant permission to use, copy, modify, distribute, * The authors hereby grant permission to use, copy, modify, distribute,
* and license this software and its documentation for any purpose, provided * and license this software and its documentation for any purpose, provided
* that existing copyright notices are retained in all copies and that this * that existing copyright notices are retained in all copies and that this
* notice and the following disclaimer are included verbatim in any * notice and the following disclaimer are included verbatim in any
* distributions. No written agreement, license, or royalty fee is required * distributions. No written agreement, license, or royalty fee is required
* for any of the authorized uses. * for any of the authorized uses.
* *
* THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
****************************************************************************** ******************************************************************************
* REVISION HISTORY * REVISION HISTORY
* *
* 03-01-01 Marc Boucher <marc@mbsi.ca> * 03-01-01 Marc Boucher <marc@mbsi.ca>
* Ported to lwIP. * Ported to lwIP.
* 98-01-30 Guy Lancaster <lancasterg@acm.org>, Global Election Systems Inc. * 98-01-30 Guy Lancaster <lancasterg@acm.org>, Global Election Systems Inc.
* Original built from BSD network code. * Original built from BSD network code.
******************************************************************************/ ******************************************************************************/
/* /*
* chap.h - Challenge Handshake Authentication Protocol definitions. * chap.h - Challenge Handshake Authentication Protocol definitions.
* *
* Copyright (c) 1995 Eric Rosenquist, Strata Software Limited. * Copyright (c) 1995 Eric Rosenquist, Strata Software Limited.
* http://www.strataware.com/ * http://www.strataware.com/
* *
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms are permitted * Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are * provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation, * duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such * advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed * distribution and use acknowledge that the software was developed
* by Eric Rosenquist. The name of the author may not be used to * by Eric Rosenquist. The name of the author may not be used to
* endorse or promote products derived from this software without * endorse or promote products derived from this software without
* specific prior written permission. * specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
* *
* $Id: chpms.h,v 1.3 2004/02/07 00:30:03 likewise Exp $ * $Id: chpms.h,v 1.3 2004/02/07 00:30:03 likewise Exp $
*/ */
#ifndef CHPMS_H #ifndef CHPMS_H
#define CHPMS_H #define CHPMS_H
#define MAX_NT_PASSWORD 256 /* Maximum number of (Unicode) chars in an NT password */ #define MAX_NT_PASSWORD 256 /* Maximum number of (Unicode) chars in an NT password */
void ChapMS (chap_state *, char *, int, char *, int); void ChapMS (chap_state *, char *, int, char *, int);
#endif /* CHPMS_H */ #endif /* CHPMS_H */

File diff suppressed because it is too large Load diff

View file

@ -1,187 +1,187 @@
/***************************************************************************** /*****************************************************************************
* fsm.h - Network Control Protocol Finite State Machine header file. * fsm.h - Network Control Protocol Finite State Machine header file.
* *
* Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc. * Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc.
* Copyright (c) 1997 Global Election Systems Inc. * Copyright (c) 1997 Global Election Systems Inc.
* *
* The authors hereby grant permission to use, copy, modify, distribute, * The authors hereby grant permission to use, copy, modify, distribute,
* and license this software and its documentation for any purpose, provided * and license this software and its documentation for any purpose, provided
* that existing copyright notices are retained in all copies and that this * that existing copyright notices are retained in all copies and that this
* notice and the following disclaimer are included verbatim in any * notice and the following disclaimer are included verbatim in any
* distributions. No written agreement, license, or royalty fee is required * distributions. No written agreement, license, or royalty fee is required
* for any of the authorized uses. * for any of the authorized uses.
* *
* THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
****************************************************************************** ******************************************************************************
* REVISION HISTORY * REVISION HISTORY
* *
* 03-01-01 Marc Boucher <marc@mbsi.ca> * 03-01-01 Marc Boucher <marc@mbsi.ca>
* Ported to lwIP. * Ported to lwIP.
* 97-11-05 Guy Lancaster <glanca@gesn.com>, Global Election Systems Inc. * 97-11-05 Guy Lancaster <glanca@gesn.com>, Global Election Systems Inc.
* Original based on BSD code. * Original based on BSD code.
*****************************************************************************/ *****************************************************************************/
/* /*
* fsm.h - {Link, IP} Control Protocol Finite State Machine definitions. * fsm.h - {Link, IP} Control Protocol Finite State Machine definitions.
* *
* Copyright (c) 1989 Carnegie Mellon University. * Copyright (c) 1989 Carnegie Mellon University.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms are permitted * Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are * provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation, * duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such * advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed * distribution and use acknowledge that the software was developed
* by Carnegie Mellon University. The name of the * by Carnegie Mellon University. The name of the
* University may not be used to endorse or promote products derived * University may not be used to endorse or promote products derived
* from this software without specific prior written permission. * from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
* *
* $Id: fsm.h,v 1.1 2003/05/27 14:37:56 jani Exp $ * $Id: fsm.h,v 1.1 2003/05/27 14:37:56 jani Exp $
*/ */
#ifndef FSM_H #ifndef FSM_H
#define FSM_H #define FSM_H
/***************************************************************************** /*****************************************************************************
************************* PUBLIC DEFINITIONS ********************************* ************************* PUBLIC DEFINITIONS *********************************
*****************************************************************************/ *****************************************************************************/
/* /*
* LCP Packet header = Code, id, length. * LCP Packet header = Code, id, length.
*/ */
#define HEADERLEN (sizeof (u_char) + sizeof (u_char) + sizeof (u_short)) #define HEADERLEN (sizeof (u_char) + sizeof (u_char) + sizeof (u_short))
/* /*
* CP (LCP, IPCP, etc.) codes. * CP (LCP, IPCP, etc.) codes.
*/ */
#define CONFREQ 1 /* Configuration Request */ #define CONFREQ 1 /* Configuration Request */
#define CONFACK 2 /* Configuration Ack */ #define CONFACK 2 /* Configuration Ack */
#define CONFNAK 3 /* Configuration Nak */ #define CONFNAK 3 /* Configuration Nak */
#define CONFREJ 4 /* Configuration Reject */ #define CONFREJ 4 /* Configuration Reject */
#define TERMREQ 5 /* Termination Request */ #define TERMREQ 5 /* Termination Request */
#define TERMACK 6 /* Termination Ack */ #define TERMACK 6 /* Termination Ack */
#define CODEREJ 7 /* Code Reject */ #define CODEREJ 7 /* Code Reject */
/* /*
* Link states. * Link states.
*/ */
#define INITIAL 0 /* Down, hasn't been opened */ #define INITIAL 0 /* Down, hasn't been opened */
#define STARTING 1 /* Down, been opened */ #define STARTING 1 /* Down, been opened */
#define CLOSED 2 /* Up, hasn't been opened */ #define CLOSED 2 /* Up, hasn't been opened */
#define STOPPED 3 /* Open, waiting for down event */ #define STOPPED 3 /* Open, waiting for down event */
#define CLOSING 4 /* Terminating the connection, not open */ #define CLOSING 4 /* Terminating the connection, not open */
#define STOPPING 5 /* Terminating, but open */ #define STOPPING 5 /* Terminating, but open */
#define REQSENT 6 /* We've sent a Config Request */ #define REQSENT 6 /* We've sent a Config Request */
#define ACKRCVD 7 /* We've received a Config Ack */ #define ACKRCVD 7 /* We've received a Config Ack */
#define ACKSENT 8 /* We've sent a Config Ack */ #define ACKSENT 8 /* We've sent a Config Ack */
#define OPENED 9 /* Connection available */ #define OPENED 9 /* Connection available */
/* /*
* Flags - indicate options controlling FSM operation * Flags - indicate options controlling FSM operation
*/ */
#define OPT_PASSIVE 1 /* Don't die if we don't get a response */ #define OPT_PASSIVE 1 /* Don't die if we don't get a response */
#define OPT_RESTART 2 /* Treat 2nd OPEN as DOWN, UP */ #define OPT_RESTART 2 /* Treat 2nd OPEN as DOWN, UP */
#define OPT_SILENT 4 /* Wait for peer to speak first */ #define OPT_SILENT 4 /* Wait for peer to speak first */
/***************************************************************************** /*****************************************************************************
************************* PUBLIC DATA TYPES ********************************** ************************* PUBLIC DATA TYPES **********************************
*****************************************************************************/ *****************************************************************************/
/* /*
* Each FSM is described by an fsm structure and fsm callbacks. * Each FSM is described by an fsm structure and fsm callbacks.
*/ */
typedef struct fsm { typedef struct fsm {
int unit; /* Interface unit number */ int unit; /* Interface unit number */
u_short protocol; /* Data Link Layer Protocol field value */ u_short protocol; /* Data Link Layer Protocol field value */
int state; /* State */ int state; /* State */
int flags; /* Contains option bits */ int flags; /* Contains option bits */
u_char id; /* Current id */ u_char id; /* Current id */
u_char reqid; /* Current request id */ u_char reqid; /* Current request id */
u_char seen_ack; /* Have received valid Ack/Nak/Rej to Req */ u_char seen_ack; /* Have received valid Ack/Nak/Rej to Req */
int timeouttime; /* Timeout time in milliseconds */ int timeouttime; /* Timeout time in milliseconds */
int maxconfreqtransmits;/* Maximum Configure-Request transmissions */ int maxconfreqtransmits;/* Maximum Configure-Request transmissions */
int retransmits; /* Number of retransmissions left */ int retransmits; /* Number of retransmissions left */
int maxtermtransmits; /* Maximum Terminate-Request transmissions */ int maxtermtransmits; /* Maximum Terminate-Request transmissions */
int nakloops; /* Number of nak loops since last ack */ int nakloops; /* Number of nak loops since last ack */
int maxnakloops; /* Maximum number of nak loops tolerated */ int maxnakloops; /* Maximum number of nak loops tolerated */
struct fsm_callbacks* callbacks;/* Callback routines */ struct fsm_callbacks* callbacks;/* Callback routines */
char* term_reason; /* Reason for closing protocol */ char* term_reason; /* Reason for closing protocol */
int term_reason_len; /* Length of term_reason */ int term_reason_len; /* Length of term_reason */
} fsm; } fsm;
typedef struct fsm_callbacks { typedef struct fsm_callbacks {
void (*resetci) /* Reset our Configuration Information */ void (*resetci) /* Reset our Configuration Information */
(fsm*); (fsm*);
int (*cilen) /* Length of our Configuration Information */ int (*cilen) /* Length of our Configuration Information */
(fsm*); (fsm*);
void (*addci) /* Add our Configuration Information */ void (*addci) /* Add our Configuration Information */
(fsm*, u_char*, int*); (fsm*, u_char*, int*);
int (*ackci) /* ACK our Configuration Information */ int (*ackci) /* ACK our Configuration Information */
(fsm*, u_char*, int); (fsm*, u_char*, int);
int (*nakci) /* NAK our Configuration Information */ int (*nakci) /* NAK our Configuration Information */
(fsm*, u_char*, int); (fsm*, u_char*, int);
int (*rejci) /* Reject our Configuration Information */ int (*rejci) /* Reject our Configuration Information */
(fsm*, u_char*, int); (fsm*, u_char*, int);
int (*reqci) /* Request peer's Configuration Information */ int (*reqci) /* Request peer's Configuration Information */
(fsm*, u_char*, int*, int); (fsm*, u_char*, int*, int);
void (*up) /* Called when fsm reaches OPENED state */ void (*up) /* Called when fsm reaches OPENED state */
(fsm*); (fsm*);
void (*down) /* Called when fsm leaves OPENED state */ void (*down) /* Called when fsm leaves OPENED state */
(fsm*); (fsm*);
void (*starting) /* Called when we want the lower layer */ void (*starting) /* Called when we want the lower layer */
(fsm*); (fsm*);
void (*finished) /* Called when we don't want the lower layer */ void (*finished) /* Called when we don't want the lower layer */
(fsm*); (fsm*);
void (*protreject) /* Called when Protocol-Reject received */ void (*protreject) /* Called when Protocol-Reject received */
(int); (int);
void (*retransmit) /* Retransmission is necessary */ void (*retransmit) /* Retransmission is necessary */
(fsm*); (fsm*);
int (*extcode) /* Called when unknown code received */ int (*extcode) /* Called when unknown code received */
(fsm*, int, u_char, u_char*, int); (fsm*, int, u_char, u_char*, int);
char *proto_name; /* String name for protocol (for messages) */ char *proto_name; /* String name for protocol (for messages) */
} fsm_callbacks; } fsm_callbacks;
/***************************************************************************** /*****************************************************************************
*********************** PUBLIC DATA STRUCTURES ******************************* *********************** PUBLIC DATA STRUCTURES *******************************
*****************************************************************************/ *****************************************************************************/
/* /*
* Variables * Variables
*/ */
extern int peer_mru[]; /* currently negotiated peer MRU (per unit) */ extern int peer_mru[]; /* currently negotiated peer MRU (per unit) */
/***************************************************************************** /*****************************************************************************
************************** PUBLIC FUNCTIONS ********************************** ************************** PUBLIC FUNCTIONS **********************************
*****************************************************************************/ *****************************************************************************/
/* /*
* Prototypes * Prototypes
*/ */
void fsm_init (fsm*); void fsm_init (fsm*);
void fsm_lowerup (fsm*); void fsm_lowerup (fsm*);
void fsm_lowerdown (fsm*); void fsm_lowerdown (fsm*);
void fsm_open (fsm*); void fsm_open (fsm*);
void fsm_close (fsm*, char*); void fsm_close (fsm*, char*);
void fsm_input (fsm*, u_char*, int); void fsm_input (fsm*, u_char*, int);
void fsm_protreject (fsm*); void fsm_protreject (fsm*);
void fsm_sdata (fsm*, u_char, u_char, u_char*, int); void fsm_sdata (fsm*, u_char, u_char, u_char*, int);
#endif /* FSM_H */ #endif /* FSM_H */

File diff suppressed because it is too large Load diff

View file

@ -1,126 +1,126 @@
/***************************************************************************** /*****************************************************************************
* ipcp.h - PPP IP NCP: Internet Protocol Network Control Protocol header file. * ipcp.h - PPP IP NCP: Internet Protocol Network Control Protocol header file.
* *
* Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc. * Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc.
* portions Copyright (c) 1997 Global Election Systems Inc. * portions Copyright (c) 1997 Global Election Systems Inc.
* *
* The authors hereby grant permission to use, copy, modify, distribute, * The authors hereby grant permission to use, copy, modify, distribute,
* and license this software and its documentation for any purpose, provided * and license this software and its documentation for any purpose, provided
* that existing copyright notices are retained in all copies and that this * that existing copyright notices are retained in all copies and that this
* notice and the following disclaimer are included verbatim in any * notice and the following disclaimer are included verbatim in any
* distributions. No written agreement, license, or royalty fee is required * distributions. No written agreement, license, or royalty fee is required
* for any of the authorized uses. * for any of the authorized uses.
* *
* THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
****************************************************************************** ******************************************************************************
* REVISION HISTORY * REVISION HISTORY
* *
* 03-01-01 Marc Boucher <marc@mbsi.ca> * 03-01-01 Marc Boucher <marc@mbsi.ca>
* Ported to lwIP. * Ported to lwIP.
* 97-12-04 Guy Lancaster <glanca@gesn.com>, Global Election Systems Inc. * 97-12-04 Guy Lancaster <glanca@gesn.com>, Global Election Systems Inc.
* Original derived from BSD codes. * Original derived from BSD codes.
*****************************************************************************/ *****************************************************************************/
/* /*
* ipcp.h - IP Control Protocol definitions. * ipcp.h - IP Control Protocol definitions.
* *
* Copyright (c) 1989 Carnegie Mellon University. * Copyright (c) 1989 Carnegie Mellon University.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms are permitted * Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are * provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation, * duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such * advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed * distribution and use acknowledge that the software was developed
* by Carnegie Mellon University. The name of the * by Carnegie Mellon University. The name of the
* University may not be used to endorse or promote products derived * University may not be used to endorse or promote products derived
* from this software without specific prior written permission. * from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
* *
* $Id: ipcp.h,v 1.1 2003/05/27 14:37:56 jani Exp $ * $Id: ipcp.h,v 1.1 2003/05/27 14:37:56 jani Exp $
*/ */
#ifndef IPCP_H #ifndef IPCP_H
#define IPCP_H #define IPCP_H
/************************* /*************************
*** PUBLIC DEFINITIONS *** *** PUBLIC DEFINITIONS ***
*************************/ *************************/
/* /*
* Options. * Options.
*/ */
#define CI_ADDRS 1 /* IP Addresses */ #define CI_ADDRS 1 /* IP Addresses */
#define CI_COMPRESSTYPE 2 /* Compression Type */ #define CI_COMPRESSTYPE 2 /* Compression Type */
#define CI_ADDR 3 #define CI_ADDR 3
#define CI_MS_WINS1 128 /* Primary WINS value */ #define CI_MS_WINS1 128 /* Primary WINS value */
#define CI_MS_DNS1 129 /* Primary DNS value */ #define CI_MS_DNS1 129 /* Primary DNS value */
#define CI_MS_WINS2 130 /* Secondary WINS value */ #define CI_MS_WINS2 130 /* Secondary WINS value */
#define CI_MS_DNS2 131 /* Secondary DNS value */ #define CI_MS_DNS2 131 /* Secondary DNS value */
#define IPCP_VJMODE_OLD 1 /* "old" mode (option # = 0x0037) */ #define IPCP_VJMODE_OLD 1 /* "old" mode (option # = 0x0037) */
#define IPCP_VJMODE_RFC1172 2 /* "old-rfc"mode (option # = 0x002d) */ #define IPCP_VJMODE_RFC1172 2 /* "old-rfc"mode (option # = 0x002d) */
#define IPCP_VJMODE_RFC1332 3 /* "new-rfc"mode (option # = 0x002d, */ #define IPCP_VJMODE_RFC1332 3 /* "new-rfc"mode (option # = 0x002d, */
/* maxslot and slot number compression) */ /* maxslot and slot number compression) */
#define IPCP_VJ_COMP 0x002d /* current value for VJ compression option*/ #define IPCP_VJ_COMP 0x002d /* current value for VJ compression option*/
#define IPCP_VJ_COMP_OLD 0x0037 /* "old" (i.e, broken) value for VJ */ #define IPCP_VJ_COMP_OLD 0x0037 /* "old" (i.e, broken) value for VJ */
/* compression option*/ /* compression option*/
/************************ /************************
*** PUBLIC DATA TYPES *** *** PUBLIC DATA TYPES ***
************************/ ************************/
typedef struct ipcp_options { typedef struct ipcp_options {
u_int neg_addr : 1; /* Negotiate IP Address? */ u_int neg_addr : 1; /* Negotiate IP Address? */
u_int old_addrs : 1; /* Use old (IP-Addresses) option? */ u_int old_addrs : 1; /* Use old (IP-Addresses) option? */
u_int req_addr : 1; /* Ask peer to send IP address? */ u_int req_addr : 1; /* Ask peer to send IP address? */
u_int default_route : 1; /* Assign default route through interface? */ u_int default_route : 1; /* Assign default route through interface? */
u_int proxy_arp : 1; /* Make proxy ARP entry for peer? */ u_int proxy_arp : 1; /* Make proxy ARP entry for peer? */
u_int neg_vj : 1; /* Van Jacobson Compression? */ u_int neg_vj : 1; /* Van Jacobson Compression? */
u_int old_vj : 1; /* use old (short) form of VJ option? */ u_int old_vj : 1; /* use old (short) form of VJ option? */
u_int accept_local : 1; /* accept peer's value for ouraddr */ u_int accept_local : 1; /* accept peer's value for ouraddr */
u_int accept_remote : 1; /* accept peer's value for hisaddr */ u_int accept_remote : 1; /* accept peer's value for hisaddr */
u_int req_dns1 : 1; /* Ask peer to send primary DNS address? */ u_int req_dns1 : 1; /* Ask peer to send primary DNS address? */
u_int req_dns2 : 1; /* Ask peer to send secondary DNS address? */ u_int req_dns2 : 1; /* Ask peer to send secondary DNS address? */
u_short vj_protocol; /* protocol value to use in VJ option */ u_short vj_protocol; /* protocol value to use in VJ option */
u_char maxslotindex; /* VJ slots - 1. */ u_char maxslotindex; /* VJ slots - 1. */
u_char cflag; /* VJ slot compression flag. */ u_char cflag; /* VJ slot compression flag. */
u32_t ouraddr, hisaddr; /* Addresses in NETWORK BYTE ORDER */ u32_t ouraddr, hisaddr; /* Addresses in NETWORK BYTE ORDER */
u32_t dnsaddr[2]; /* Primary and secondary MS DNS entries */ u32_t dnsaddr[2]; /* Primary and secondary MS DNS entries */
u32_t winsaddr[2]; /* Primary and secondary MS WINS entries */ u32_t winsaddr[2]; /* Primary and secondary MS WINS entries */
} ipcp_options; } ipcp_options;
/***************************** /*****************************
*** PUBLIC DATA STRUCTURES *** *** PUBLIC DATA STRUCTURES ***
*****************************/ *****************************/
extern fsm ipcp_fsm[]; extern fsm ipcp_fsm[];
extern ipcp_options ipcp_wantoptions[]; extern ipcp_options ipcp_wantoptions[];
extern ipcp_options ipcp_gotoptions[]; extern ipcp_options ipcp_gotoptions[];
extern ipcp_options ipcp_allowoptions[]; extern ipcp_options ipcp_allowoptions[];
extern ipcp_options ipcp_hisoptions[]; extern ipcp_options ipcp_hisoptions[];
extern struct protent ipcp_protent; extern struct protent ipcp_protent;
/*********************** /***********************
*** PUBLIC FUNCTIONS *** *** PUBLIC FUNCTIONS ***
***********************/ ***********************/
#endif /* IPCP_H */ #endif /* IPCP_H */

File diff suppressed because it is too large Load diff

View file

@ -1,169 +1,169 @@
/***************************************************************************** /*****************************************************************************
* lcp.h - Network Link Control Protocol header file. * lcp.h - Network Link Control Protocol header file.
* *
* Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc. * Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc.
* portions Copyright (c) 1997 Global Election Systems Inc. * portions Copyright (c) 1997 Global Election Systems Inc.
* *
* The authors hereby grant permission to use, copy, modify, distribute, * The authors hereby grant permission to use, copy, modify, distribute,
* and license this software and its documentation for any purpose, provided * and license this software and its documentation for any purpose, provided
* that existing copyright notices are retained in all copies and that this * that existing copyright notices are retained in all copies and that this
* notice and the following disclaimer are included verbatim in any * notice and the following disclaimer are included verbatim in any
* distributions. No written agreement, license, or royalty fee is required * distributions. No written agreement, license, or royalty fee is required
* for any of the authorized uses. * for any of the authorized uses.
* *
* THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
****************************************************************************** ******************************************************************************
* REVISION HISTORY * REVISION HISTORY
* *
* 03-01-01 Marc Boucher <marc@mbsi.ca> * 03-01-01 Marc Boucher <marc@mbsi.ca>
* Ported to lwIP. * Ported to lwIP.
* 97-11-05 Guy Lancaster <glanca@gesn.com>, Global Election Systems Inc. * 97-11-05 Guy Lancaster <glanca@gesn.com>, Global Election Systems Inc.
* Original derived from BSD codes. * Original derived from BSD codes.
*****************************************************************************/ *****************************************************************************/
/* /*
* lcp.h - Link Control Protocol definitions. * lcp.h - Link Control Protocol definitions.
* *
* Copyright (c) 1989 Carnegie Mellon University. * Copyright (c) 1989 Carnegie Mellon University.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms are permitted * Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are * provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation, * duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such * advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed * distribution and use acknowledge that the software was developed
* by Carnegie Mellon University. The name of the * by Carnegie Mellon University. The name of the
* University may not be used to endorse or promote products derived * University may not be used to endorse or promote products derived
* from this software without specific prior written permission. * from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
* *
* $Id: lcp.h,v 1.1 2003/05/27 14:37:56 jani Exp $ * $Id: lcp.h,v 1.1 2003/05/27 14:37:56 jani Exp $
*/ */
#ifndef LCP_H #ifndef LCP_H
#define LCP_H #define LCP_H
/************************* /*************************
*** PUBLIC DEFINITIONS *** *** PUBLIC DEFINITIONS ***
*************************/ *************************/
/* /*
* Options. * Options.
*/ */
#define CI_MRU 1 /* Maximum Receive Unit */ #define CI_MRU 1 /* Maximum Receive Unit */
#define CI_ASYNCMAP 2 /* Async Control Character Map */ #define CI_ASYNCMAP 2 /* Async Control Character Map */
#define CI_AUTHTYPE 3 /* Authentication Type */ #define CI_AUTHTYPE 3 /* Authentication Type */
#define CI_QUALITY 4 /* Quality Protocol */ #define CI_QUALITY 4 /* Quality Protocol */
#define CI_MAGICNUMBER 5 /* Magic Number */ #define CI_MAGICNUMBER 5 /* Magic Number */
#define CI_PCOMPRESSION 7 /* Protocol Field Compression */ #define CI_PCOMPRESSION 7 /* Protocol Field Compression */
#define CI_ACCOMPRESSION 8 /* Address/Control Field Compression */ #define CI_ACCOMPRESSION 8 /* Address/Control Field Compression */
#define CI_CALLBACK 13 /* callback */ #define CI_CALLBACK 13 /* callback */
#define CI_MRRU 17 /* max reconstructed receive unit; multilink */ #define CI_MRRU 17 /* max reconstructed receive unit; multilink */
#define CI_SSNHF 18 /* short sequence numbers for multilink */ #define CI_SSNHF 18 /* short sequence numbers for multilink */
#define CI_EPDISC 19 /* endpoint discriminator */ #define CI_EPDISC 19 /* endpoint discriminator */
/* /*
* LCP-specific packet types. * LCP-specific packet types.
*/ */
#define PROTREJ 8 /* Protocol Reject */ #define PROTREJ 8 /* Protocol Reject */
#define ECHOREQ 9 /* Echo Request */ #define ECHOREQ 9 /* Echo Request */
#define ECHOREP 10 /* Echo Reply */ #define ECHOREP 10 /* Echo Reply */
#define DISCREQ 11 /* Discard Request */ #define DISCREQ 11 /* Discard Request */
#define CBCP_OPT 6 /* Use callback control protocol */ #define CBCP_OPT 6 /* Use callback control protocol */
/************************ /************************
*** PUBLIC DATA TYPES *** *** PUBLIC DATA TYPES ***
************************/ ************************/
/* /*
* The state of options is described by an lcp_options structure. * The state of options is described by an lcp_options structure.
*/ */
typedef struct lcp_options { typedef struct lcp_options {
u_int passive : 1; /* Don't die if we don't get a response */ u_int passive : 1; /* Don't die if we don't get a response */
u_int silent : 1; /* Wait for the other end to start first */ u_int silent : 1; /* Wait for the other end to start first */
u_int restart : 1; /* Restart vs. exit after close */ u_int restart : 1; /* Restart vs. exit after close */
u_int neg_mru : 1; /* Negotiate the MRU? */ u_int neg_mru : 1; /* Negotiate the MRU? */
u_int neg_asyncmap : 1; /* Negotiate the async map? */ u_int neg_asyncmap : 1; /* Negotiate the async map? */
u_int neg_upap : 1; /* Ask for UPAP authentication? */ u_int neg_upap : 1; /* Ask for UPAP authentication? */
u_int neg_chap : 1; /* Ask for CHAP authentication? */ u_int neg_chap : 1; /* Ask for CHAP authentication? */
u_int neg_magicnumber : 1; /* Ask for magic number? */ u_int neg_magicnumber : 1; /* Ask for magic number? */
u_int neg_pcompression : 1; /* HDLC Protocol Field Compression? */ u_int neg_pcompression : 1; /* HDLC Protocol Field Compression? */
u_int neg_accompression : 1; /* HDLC Address/Control Field Compression? */ u_int neg_accompression : 1; /* HDLC Address/Control Field Compression? */
u_int neg_lqr : 1; /* Negotiate use of Link Quality Reports */ u_int neg_lqr : 1; /* Negotiate use of Link Quality Reports */
u_int neg_cbcp : 1; /* Negotiate use of CBCP */ u_int neg_cbcp : 1; /* Negotiate use of CBCP */
#ifdef PPP_MULTILINK #ifdef PPP_MULTILINK
u_int neg_mrru : 1; /* Negotiate multilink MRRU */ u_int neg_mrru : 1; /* Negotiate multilink MRRU */
u_int neg_ssnhf : 1; /* Negotiate short sequence numbers */ u_int neg_ssnhf : 1; /* Negotiate short sequence numbers */
u_int neg_endpoint : 1; /* Negotiate endpoint discriminator */ u_int neg_endpoint : 1; /* Negotiate endpoint discriminator */
#endif #endif
u_short mru; /* Value of MRU */ u_short mru; /* Value of MRU */
#ifdef PPP_MULTILINK #ifdef PPP_MULTILINK
u_short mrru; /* Value of MRRU, and multilink enable */ u_short mrru; /* Value of MRRU, and multilink enable */
#endif #endif
u_char chap_mdtype; /* which MD type (hashing algorithm) */ u_char chap_mdtype; /* which MD type (hashing algorithm) */
u32_t asyncmap; /* Value of async map */ u32_t asyncmap; /* Value of async map */
u32_t magicnumber; u32_t magicnumber;
int numloops; /* Number of loops during magic number neg. */ int numloops; /* Number of loops during magic number neg. */
u32_t lqr_period; /* Reporting period for LQR 1/100ths second */ u32_t lqr_period; /* Reporting period for LQR 1/100ths second */
#ifdef PPP_MULTILINK #ifdef PPP_MULTILINK
struct epdisc endpoint; /* endpoint discriminator */ struct epdisc endpoint; /* endpoint discriminator */
#endif #endif
} lcp_options; } lcp_options;
/* /*
* Values for phase from BSD pppd.h based on RFC 1661. * Values for phase from BSD pppd.h based on RFC 1661.
*/ */
typedef enum { typedef enum {
PHASE_DEAD = 0, PHASE_DEAD = 0,
PHASE_INITIALIZE, PHASE_INITIALIZE,
PHASE_ESTABLISH, PHASE_ESTABLISH,
PHASE_AUTHENTICATE, PHASE_AUTHENTICATE,
PHASE_CALLBACK, PHASE_CALLBACK,
PHASE_NETWORK, PHASE_NETWORK,
PHASE_TERMINATE PHASE_TERMINATE
} LinkPhase; } LinkPhase;
/***************************** /*****************************
*** PUBLIC DATA STRUCTURES *** *** PUBLIC DATA STRUCTURES ***
*****************************/ *****************************/
extern LinkPhase lcp_phase[NUM_PPP]; /* Phase of link session (RFC 1661) */ extern LinkPhase lcp_phase[NUM_PPP]; /* Phase of link session (RFC 1661) */
extern lcp_options lcp_wantoptions[]; extern lcp_options lcp_wantoptions[];
extern lcp_options lcp_gotoptions[]; extern lcp_options lcp_gotoptions[];
extern lcp_options lcp_allowoptions[]; extern lcp_options lcp_allowoptions[];
extern lcp_options lcp_hisoptions[]; extern lcp_options lcp_hisoptions[];
extern ext_accm xmit_accm[]; extern ext_accm xmit_accm[];
/*********************** /***********************
*** PUBLIC FUNCTIONS *** *** PUBLIC FUNCTIONS ***
***********************/ ***********************/
void lcp_init (int); void lcp_init (int);
void lcp_open (int); void lcp_open (int);
void lcp_close (int, char *); void lcp_close (int, char *);
void lcp_lowerup (int); void lcp_lowerup (int);
void lcp_lowerdown (int); void lcp_lowerdown (int);
void lcp_sprotrej (int, u_char *, int); /* send protocol reject */ void lcp_sprotrej (int, u_char *, int); /* send protocol reject */
extern struct protent lcp_protent; extern struct protent lcp_protent;
/* Default number of times we receive our magic number from the peer /* Default number of times we receive our magic number from the peer
before deciding the link is looped-back. */ before deciding the link is looped-back. */
#define DEFLOOPBACKFAIL 10 #define DEFLOOPBACKFAIL 10
#endif /* LCP_H */ #endif /* LCP_H */

View file

@ -1,79 +1,79 @@
/***************************************************************************** /*****************************************************************************
* magic.c - Network Random Number Generator program file. * magic.c - Network Random Number Generator program file.
* *
* Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc. * Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc.
* portions Copyright (c) 1997 by Global Election Systems Inc. * portions Copyright (c) 1997 by Global Election Systems Inc.
* *
* The authors hereby grant permission to use, copy, modify, distribute, * The authors hereby grant permission to use, copy, modify, distribute,
* and license this software and its documentation for any purpose, provided * and license this software and its documentation for any purpose, provided
* that existing copyright notices are retained in all copies and that this * that existing copyright notices are retained in all copies and that this
* notice and the following disclaimer are included verbatim in any * notice and the following disclaimer are included verbatim in any
* distributions. No written agreement, license, or royalty fee is required * distributions. No written agreement, license, or royalty fee is required
* for any of the authorized uses. * for any of the authorized uses.
* *
* THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
****************************************************************************** ******************************************************************************
* REVISION HISTORY * REVISION HISTORY
* *
* 03-01-01 Marc Boucher <marc@mbsi.ca> * 03-01-01 Marc Boucher <marc@mbsi.ca>
* Ported to lwIP. * Ported to lwIP.
* 97-12-04 Guy Lancaster <lancasterg@acm.org>, Global Election Systems Inc. * 97-12-04 Guy Lancaster <lancasterg@acm.org>, Global Election Systems Inc.
* Original based on BSD magic.c. * Original based on BSD magic.c.
*****************************************************************************/ *****************************************************************************/
/* /*
* magic.c - PPP Magic Number routines. * magic.c - PPP Magic Number routines.
* *
* Copyright (c) 1989 Carnegie Mellon University. * Copyright (c) 1989 Carnegie Mellon University.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms are permitted * Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are * provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation, * duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such * advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed * distribution and use acknowledge that the software was developed
* by Carnegie Mellon University. The name of the * by Carnegie Mellon University. The name of the
* University may not be used to endorse or promote products derived * University may not be used to endorse or promote products derived
* from this software without specific prior written permission. * from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/ */
#include "ppp.h" #include "ppp.h"
#include "randm.h" #include "randm.h"
#include "magic.h" #include "magic.h"
/***********************************/ /***********************************/
/*** PUBLIC FUNCTION DEFINITIONS ***/ /*** PUBLIC FUNCTION DEFINITIONS ***/
/***********************************/ /***********************************/
/* /*
* magicInit - Initialize the magic number generator. * magicInit - Initialize the magic number generator.
* *
* Since we use another random number generator that has its own * Since we use another random number generator that has its own
* initialization, we do nothing here. * initialization, we do nothing here.
*/ */
void magicInit() void magicInit()
{ {
return; return;
} }
/* /*
* magic - Returns the next magic number. * magic - Returns the next magic number.
*/ */
u32_t magic() u32_t magic()
{ {
return avRandom(); return avRandom();
} }

View file

@ -1,64 +1,64 @@
/***************************************************************************** /*****************************************************************************
* magic.h - Network Random Number Generator header file. * magic.h - Network Random Number Generator header file.
* *
* Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc. * Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc.
* portions Copyright (c) 1997 Global Election Systems Inc. * portions Copyright (c) 1997 Global Election Systems Inc.
* *
* The authors hereby grant permission to use, copy, modify, distribute, * The authors hereby grant permission to use, copy, modify, distribute,
* and license this software and its documentation for any purpose, provided * and license this software and its documentation for any purpose, provided
* that existing copyright notices are retained in all copies and that this * that existing copyright notices are retained in all copies and that this
* notice and the following disclaimer are included verbatim in any * notice and the following disclaimer are included verbatim in any
* distributions. No written agreement, license, or royalty fee is required * distributions. No written agreement, license, or royalty fee is required
* for any of the authorized uses. * for any of the authorized uses.
* *
* THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
****************************************************************************** ******************************************************************************
* REVISION HISTORY * REVISION HISTORY
* *
* 03-01-01 Marc Boucher <marc@mbsi.ca> * 03-01-01 Marc Boucher <marc@mbsi.ca>
* Ported to lwIP. * Ported to lwIP.
* 97-12-04 Guy Lancaster <glanca@gesn.com>, Global Election Systems Inc. * 97-12-04 Guy Lancaster <glanca@gesn.com>, Global Election Systems Inc.
* Original derived from BSD codes. * Original derived from BSD codes.
*****************************************************************************/ *****************************************************************************/
/* /*
* magic.h - PPP Magic Number definitions. * magic.h - PPP Magic Number definitions.
* *
* Copyright (c) 1989 Carnegie Mellon University. * Copyright (c) 1989 Carnegie Mellon University.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms are permitted * Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are * provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation, * duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such * advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed * distribution and use acknowledge that the software was developed
* by Carnegie Mellon University. The name of the * by Carnegie Mellon University. The name of the
* University may not be used to endorse or promote products derived * University may not be used to endorse or promote products derived
* from this software without specific prior written permission. * from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
* *
* $Id: magic.h,v 1.1 2003/05/27 14:37:56 jani Exp $ * $Id: magic.h,v 1.1 2003/05/27 14:37:56 jani Exp $
*/ */
#ifndef MAGIC_H #ifndef MAGIC_H
#define MAGIC_H #define MAGIC_H
/***************************************************************************** /*****************************************************************************
************************** PUBLIC FUNCTIONS ********************************** ************************** PUBLIC FUNCTIONS **********************************
*****************************************************************************/ *****************************************************************************/
void magicInit(void); /* Initialize the magic number generator */ void magicInit(void); /* Initialize the magic number generator */
u32_t magic(void); /* Returns the next magic number */ u32_t magic(void); /* Returns the next magic number */
#endif /* MAGIC_H */ #endif /* MAGIC_H */

Some files were not shown because too many files have changed in this diff Show more