Contiki 2.5
contiki-main.c
1 /*
2  * Copyright (c) 2006, Swedish Institute of Computer Science.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the Institute nor the names of its contributors
14  * may be used to endorse or promote products derived from this software
15  * without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * This file is part of the Contiki operating system.
30  *
31  * Author: Oliver Schmidt <ol.sc@web.de>
32  *
33  * $Id: contiki-main.c,v 1.21 2010/10/27 22:17:39 oliverschmidt Exp $
34  */
35 
36 #define WIN32_LEAN_AND_MEAN
37 #include <windows.h>
38 #include <winsock2.h>
39 #include <stdio.h>
40 
41 #include "contiki-net.h"
42 
43 #include "sys/clock.h"
44 #include "ctk/ctk.h"
45 #include "ctk/ctk-console.h"
46 
47 #include "../../apps/directory/directory-dsc.h"
48 #include "../../apps/webbrowser/www-dsc.h"
49 
50 #include "sys/etimer.h"
51 #include "net/wpcap-drv.h"
52 
53 #ifdef PLATFORM_BUILD
54 #include "program-handler.h"
55 #endif /* PLATFORM_BUILD */
56 
57 #if WITH_GUI
58 #define CTK_PROCESS &ctk_process,
59 #else /* WITH_GUI */
60 #define CTK_PROCESS
61 #endif /* WITH_GUI */
62 
63 PROCINIT(&etimer_process,
64  &wpcap_process,
65  CTK_PROCESS
66  &tcpip_process,
67  &resolv_process);
68 
69 /*-----------------------------------------------------------------------------------*/
70 void
71 debug_printf(char *format, ...)
72 {
73  va_list argptr;
74  char buffer[1024];
75 
76  va_start(argptr, format);
77  vsprintf(buffer, format, argptr);
78  va_end(argptr);
79 
80 #if WITH_GUI
81  OutputDebugString(buffer);
82 #else /* WITH_GUI */
83  fputs(buffer, stderr);
84 #endif /* WITH_GUI */
85 }
86 /*-----------------------------------------------------------------------------------*/
87 void
88 uip_log(char *message)
89 {
90  debug_printf("%s\n", message);
91 }
92 /*-----------------------------------------------------------------------------------*/
93 void
94 log_message(const char *part1, const char *part2)
95 {
96  debug_printf("%s%s\n", part1, part2);
97 }
98 /*-----------------------------------------------------------------------------------*/
99 int
100 main(void)
101 {
102  process_init();
103 
104  procinit_init();
105 
106 #ifdef PLATFORM_BUILD
107  program_handler_add(&directory_dsc, "Directory", 1);
108  program_handler_add(&www_dsc, "Web browser", 1);
109 #endif /* PLATFORM_BUILD */
110 
111  autostart_start(autostart_processes);
112 
113 #if !UIP_CONF_IPV6
114  {
115  uip_ipaddr_t addr;
116  uip_ipaddr(&addr, 10,1,1,1);
117  uip_sethostaddr(&addr);
118  log_message("IP Address: ", inet_ntoa(*(struct in_addr*)&addr));
119 
120  uip_ipaddr(&addr, 255,0,0,0);
121  uip_setnetmask(&addr);
122  log_message("Subnet Mask: ", inet_ntoa(*(struct in_addr*)&addr));
123 
124  uip_ipaddr(&addr, 10,1,1,100);
125  uip_setdraddr(&addr);
126  log_message("Def. Router: ", inet_ntoa(*(struct in_addr*)&addr));
127 
128  uip_ipaddr(&addr, 10,1,1,100);
129  resolv_conf(&addr);
130  log_message("DNS Server: ", inet_ntoa(*(struct in_addr*)&addr));
131  }
132 
133 #else /* UIP_CONF_IPV6 */
134 
135 #if !UIP_CONF_IPV6_RPL
136 #ifdef HARD_CODED_ADDRESS
137  uip_ipaddr_t ipaddr;
138  uiplib_ipaddrconv(HARD_CODED_ADDRESS, &ipaddr);
139  if ((ipaddr.u16[0]!=0) || (ipaddr.u16[1]!=0) || (ipaddr.u16[2]!=0) || (ipaddr.u16[3]!=0)) {
140 #if UIP_CONF_ROUTER
141  uip_ds6_prefix_add(&ipaddr, UIP_DEFAULT_PREFIX_LEN, 0, 0, 0, 0);
142 #else /* UIP_CONF_ROUTER */
143  uip_ds6_prefix_add(&ipaddr, UIP_DEFAULT_PREFIX_LEN, 0);
144 #endif /* UIP_CONF_ROUTER */
145 #if !UIP_CONF_IPV6_RPL
146  uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
147  uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);
148 #endif
149  }
150 #endif /* HARD_CODED_ADDRESS */
151 #endif
152 #endif
153 
154  while(1) {
155 
156  process_run();
157 
159 
160  /* Allow user-mode APC to execute. */
161  SleepEx(10, TRUE);
162 
163 #if WITH_GUI
164  if(console_resize()) {
165  ctk_restore();
166  }
167 #endif /* WITH_GUI */
168  }
169 }
170 /*-----------------------------------------------------------------------------------*/