tcpip.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2001, Swedish Institute of Computer Science.
00003  * All rights reserved. 
00004  *
00005  * Redistribution and use in source and binary forms, with or without 
00006  * modification, are permitted provided that the following conditions 
00007  * are met: 
00008  * 1. Redistributions of source code must retain the above copyright 
00009  *    notice, this list of conditions and the following disclaimer. 
00010  * 2. Redistributions in binary form must reproduce the above copyright 
00011  *    notice, this list of conditions and the following disclaimer in the 
00012  *    documentation and/or other materials provided with the distribution. 
00013  * 3. Neither the name of the Institute nor the names of its contributors 
00014  *    may be used to endorse or promote products derived from this software 
00015  *    without specific prior written permission. 
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 
00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 
00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
00027  * SUCH DAMAGE. 
00028  *
00029  * This file is part of the lwIP TCP/IP stack.
00030  * 
00031  * Author: Adam Dunkels <adam@sics.se>
00032  *
00033  * $Id: tcpip_8c-source.html 88 2016-01-12 00:11:29Z reddawg $
00034  */
00035 
00036 #include <ubixos/exec.h>
00037 #include <lib/kmalloc.h>
00038 
00039 #include "net/debug.h"
00040 
00041 #include "net/opt.h"
00042 
00043 #include "net/sys.h"
00044 
00045 #include "net/memp.h"
00046 #include "net/pbuf.h"
00047 
00048 #include "net/ipv4/ip.h"
00049 #include "net/udp.h"
00050 #include "net/tcp.h"
00051 
00052 #include "net/tcpip.h"
00053 
00054 static void (* tcpip_init_done)(void *arg) = NULL;
00055 static void *tcpip_init_done_arg;
00056 static sys_mbox_t mbox;
00057 
00058 /*-----------------------------------------------------------------------------------*/
00059 static void
00060 tcpip_tcp_timer(void *arg)
00061 {
00062   tcp_tmr();
00063   sys_timeout(TCP_TMR_INTERVAL, (sys_timeout_handler)tcpip_tcp_timer, NULL);
00064 }
00065 /*-----------------------------------------------------------------------------------*/
00066 
00067 static void
00068 tcpip_thread(void *arg)
00069 {
00070   struct tcpip_msg *msg;
00071 
00072   ip_init();
00073   udp_init();
00074   tcp_init();
00075 
00076   sys_timeout(TCP_TMR_INTERVAL, (sys_timeout_handler)tcpip_tcp_timer, NULL);
00077   
00078   if(tcpip_init_done != NULL) {
00079     tcpip_init_done(tcpip_init_done_arg);
00080   }
00081 
00082   while(1) {                          /* MAIN Loop */
00083     sys_mbox_fetch(mbox, (void *)&msg);
00084     switch(msg->type) {
00085     case TCPIP_MSG_API:
00086       //kprintf("tcpip_thread: API message %p\n", msg);
00087       api_msg_input(msg->msg.apimsg);
00088       break;
00089     case TCPIP_MSG_INPUT:
00090       //kprintf("tcpip_thread: IP packet %p\n", msg);
00091       ip_input(msg->msg.inp.p, msg->msg.inp.netif);
00092       break;
00093     default:
00094       break;
00095     }
00096     memp_freep(MEMP_TCPIP_MSG, msg);
00097   }
00098 }
00099 /*-----------------------------------------------------------------------------------*/
00100 err_t
00101 tcpip_input(struct pbuf *p, struct netif *inp)
00102 {
00103   struct tcpip_msg *msg;
00104   
00105   msg = memp_mallocp(MEMP_TCPIP_MSG);
00106   if(msg == NULL) {
00107     //kprintf("BAD MESSAGE!!!\n");
00108     pbuf_free(p);    
00109     return ERR_MEM;  
00110   }
00111   //kprintf("GOOD MESSAGE\n");
00112   
00113   msg->type = TCPIP_MSG_INPUT;
00114   msg->msg.inp.p = p;
00115   msg->msg.inp.netif = inp;
00116   sys_mbox_post(mbox, msg);
00117   return ERR_OK;
00118 }
00119 /*-----------------------------------------------------------------------------------*/
00120 void
00121 tcpip_apimsg(struct api_msg *apimsg)
00122 {
00123   struct tcpip_msg *msg;
00124   msg = memp_mallocp(MEMP_TCPIP_MSG);
00125   if(msg == NULL) {
00126     memp_free(MEMP_TCPIP_MSG, apimsg);
00127     return;
00128   }
00129   msg->type = TCPIP_MSG_API;
00130   msg->msg.apimsg = apimsg;
00131   sys_mbox_post(mbox, msg);
00132 }
00133 /*-----------------------------------------------------------------------------------*/
00134 void
00135 tcpip_init(void (* initfunc)(void *), void *arg)
00136 {
00137   tcpip_init_done = initfunc;
00138   tcpip_init_done_arg = arg;
00139   mbox = sys_mbox_new();
00140   sys_thread_new((void *)tcpip_thread, NULL);
00141 }
00142 /*-----------------------------------------------------------------------------------*/
00143 
00144 
00145 

Generated on Tue Dec 12 08:52:07 2006 for UbixOS V2 by  doxygen 1.4.7