2 * Copyright (c) 2001, 2002 Swedish Institute of Computer Science.
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
19 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
21 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
27 * This file is part of the lwIP TCP/IP stack.
29 * Author: Adam Dunkels <adam@sics.se>
33 #include "lwip/debug.h"
39 #include "lwip/memp.h"
40 #include "lwip/pbuf.h"
46 #include "lwip/tcpip.h"
48 static void (* tcpip_init_done)(void *arg) = NULL;
49 static void *tcpip_init_done_arg;
50 static sys_mbox_t mbox;
52 /*-----------------------------------------------------------------------------------*/
54 tcpip_tcp_timer(void *arg)
57 sys_timeout(TCP_TMR_INTERVAL, (sys_timeout_handler)tcpip_tcp_timer, NULL);
59 /*-----------------------------------------------------------------------------------*/
62 tcpip_thread(void *arg)
64 struct tcpip_msg *msg;
70 sys_timeout(TCP_TMR_INTERVAL, (sys_timeout_handler)tcpip_tcp_timer, NULL);
72 if(tcpip_init_done != NULL) {
73 tcpip_init_done(tcpip_init_done_arg);
76 while(1) { /* MAIN Loop */
77 sys_mbox_fetch(mbox, (void *)&msg);
80 DEBUGF(TCPIP_DEBUG, ("tcpip_thread: API message %p\n", (void *)msg));
81 api_msg_input(msg->msg.apimsg);
84 DEBUGF(TCPIP_DEBUG, ("tcpip_thread: IP packet %p\n", (void *)msg));
85 ip_input(msg->msg.inp.p, msg->msg.inp.netif);
90 memp_freep(MEMP_TCPIP_MSG, msg);
93 /*-----------------------------------------------------------------------------------*/
95 tcpip_input(struct pbuf *p, struct netif *inp)
97 struct tcpip_msg *msg;
99 msg = memp_mallocp(MEMP_TCPIP_MSG);
105 msg->type = TCPIP_MSG_INPUT;
107 msg->msg.inp.netif = inp;
108 sys_mbox_post(mbox, msg);
111 /*-----------------------------------------------------------------------------------*/
113 tcpip_apimsg(struct api_msg *apimsg)
115 struct tcpip_msg *msg;
116 msg = memp_mallocp(MEMP_TCPIP_MSG);
118 memp_free(MEMP_API_MSG, apimsg);
121 msg->type = TCPIP_MSG_API;
122 msg->msg.apimsg = apimsg;
123 sys_mbox_post(mbox, msg);
125 /*-----------------------------------------------------------------------------------*/
127 tcpip_init(void (* initfunc)(void *), void *arg)
129 tcpip_init_done = initfunc;
130 tcpip_init_done_arg = arg;
131 mbox = sys_mbox_new();
132 sys_thread_new((void *)tcpip_thread, NULL);
134 /*-----------------------------------------------------------------------------------*/