00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
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) {                          
00083     sys_mbox_fetch(mbox, (void *)&msg);
00084     switch(msg->type) {
00085     case TCPIP_MSG_API:
00086       
00087       api_msg_input(msg->msg.apimsg);
00088       break;
00089     case TCPIP_MSG_INPUT:
00090       
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     
00108     pbuf_free(p);    
00109     return ERR_MEM;  
00110   }
00111   
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