Contiki 2.6
|
00001 /* 00002 * Copyright (c) 2006, 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 Contiki operating system. 00030 * 00031 * Author: Oliver Schmidt <ol.sc@web.de> 00032 * 00033 * $Id: contiki-main.c,v 1.21 2010/10/27 22:17:39 oliverschmidt Exp $ 00034 */ 00035 00036 #define WIN32_LEAN_AND_MEAN 00037 #include <windows.h> 00038 #include <winsock2.h> 00039 #include <stdio.h> 00040 00041 #include "contiki-net.h" 00042 00043 #include "sys/clock.h" 00044 #include "ctk/ctk.h" 00045 #include "ctk/ctk-console.h" 00046 00047 #include "../../apps/directory/directory-dsc.h" 00048 #include "../../apps/webbrowser/www-dsc.h" 00049 00050 #include "sys/etimer.h" 00051 #include "net/wpcap-drv.h" 00052 00053 #ifdef PLATFORM_BUILD 00054 #include "program-handler.h" 00055 #endif /* PLATFORM_BUILD */ 00056 00057 #if WITH_GUI 00058 #define CTK_PROCESS &ctk_process, 00059 #else /* WITH_GUI */ 00060 #define CTK_PROCESS 00061 #endif /* WITH_GUI */ 00062 00063 PROCINIT(&etimer_process, 00064 &wpcap_process, 00065 CTK_PROCESS 00066 &tcpip_process, 00067 &resolv_process); 00068 00069 /*-----------------------------------------------------------------------------------*/ 00070 void 00071 debug_printf(char *format, ...) 00072 { 00073 va_list argptr; 00074 char buffer[1024]; 00075 00076 va_start(argptr, format); 00077 vsprintf(buffer, format, argptr); 00078 va_end(argptr); 00079 00080 #if WITH_GUI 00081 OutputDebugString(buffer); 00082 #else /* WITH_GUI */ 00083 fputs(buffer, stderr); 00084 #endif /* WITH_GUI */ 00085 } 00086 /*-----------------------------------------------------------------------------------*/ 00087 void 00088 uip_log(char *message) 00089 { 00090 debug_printf("%s\n", message); 00091 } 00092 /*-----------------------------------------------------------------------------------*/ 00093 void 00094 log_message(const char *part1, const char *part2) 00095 { 00096 debug_printf("%s%s\n", part1, part2); 00097 } 00098 /*-----------------------------------------------------------------------------------*/ 00099 int 00100 main(void) 00101 { 00102 process_init(); 00103 00104 procinit_init(); 00105 00106 #ifdef PLATFORM_BUILD 00107 program_handler_add(&directory_dsc, "Directory", 1); 00108 program_handler_add(&www_dsc, "Web browser", 1); 00109 #endif /* PLATFORM_BUILD */ 00110 00111 autostart_start(autostart_processes); 00112 00113 #if !UIP_CONF_IPV6 00114 { 00115 uip_ipaddr_t addr; 00116 uip_ipaddr(&addr, 10,1,1,1); 00117 uip_sethostaddr(&addr); 00118 log_message("IP Address: ", inet_ntoa(*(struct in_addr*)&addr)); 00119 00120 uip_ipaddr(&addr, 255,0,0,0); 00121 uip_setnetmask(&addr); 00122 log_message("Subnet Mask: ", inet_ntoa(*(struct in_addr*)&addr)); 00123 00124 uip_ipaddr(&addr, 10,1,1,100); 00125 uip_setdraddr(&addr); 00126 log_message("Def. Router: ", inet_ntoa(*(struct in_addr*)&addr)); 00127 00128 uip_ipaddr(&addr, 10,1,1,100); 00129 resolv_conf(&addr); 00130 log_message("DNS Server: ", inet_ntoa(*(struct in_addr*)&addr)); 00131 } 00132 00133 #else /* UIP_CONF_IPV6 */ 00134 00135 #if !UIP_CONF_IPV6_RPL 00136 #ifdef HARD_CODED_ADDRESS 00137 uip_ipaddr_t ipaddr; 00138 uiplib_ipaddrconv(HARD_CODED_ADDRESS, &ipaddr); 00139 if ((ipaddr.u16[0]!=0) || (ipaddr.u16[1]!=0) || (ipaddr.u16[2]!=0) || (ipaddr.u16[3]!=0)) { 00140 #if UIP_CONF_ROUTER 00141 uip_ds6_prefix_add(&ipaddr, UIP_DEFAULT_PREFIX_LEN, 0, 0, 0, 0); 00142 #else /* UIP_CONF_ROUTER */ 00143 uip_ds6_prefix_add(&ipaddr, UIP_DEFAULT_PREFIX_LEN, 0); 00144 #endif /* UIP_CONF_ROUTER */ 00145 #if !UIP_CONF_IPV6_RPL 00146 uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr); 00147 uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF); 00148 #endif 00149 } 00150 #endif /* HARD_CODED_ADDRESS */ 00151 #endif 00152 #endif 00153 00154 while(1) { 00155 00156 process_run(); 00157 00158 etimer_request_poll(); 00159 00160 /* Allow user-mode APC to execute. */ 00161 SleepEx(10, TRUE); 00162 00163 #if WITH_GUI 00164 if(console_resize()) { 00165 ctk_restore(); 00166 } 00167 #endif /* WITH_GUI */ 00168 } 00169 } 00170 /*-----------------------------------------------------------------------------------*/