Contiki 3.x
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  */
34 
35 #define WIN32_LEAN_AND_MEAN
36 #include <windows.h>
37 #include <winsock2.h>
38 #include <stdio.h>
39 
40 #include "contiki-net.h"
41 
42 #include "sys/clock.h"
43 #include "ctk/ctk.h"
44 #include "ctk/ctk-console.h"
45 
46 #include "../../apps/directory/directory-dsc.h"
47 #include "../../apps/webbrowser/www-dsc.h"
48 
49 #include "sys/etimer.h"
50 #include "net/wpcap-drv.h"
51 
52 #ifdef PLATFORM_BUILD
53 #include "program-handler.h"
54 #endif /* PLATFORM_BUILD */
55 
56 #if WITH_GUI
57 #define CTK_PROCESS &ctk_process,
58 #else /* WITH_GUI */
59 #define CTK_PROCESS
60 #endif /* WITH_GUI */
61 
62 PROCINIT(&etimer_process,
63  &wpcap_process,
64  CTK_PROCESS
65  &tcpip_process,
66  &resolv_process);
67 
68 /*-----------------------------------------------------------------------------------*/
69 void
70 debug_printf(char *format, ...)
71 {
72  va_list argptr;
73  char buffer[1024];
74 
75  va_start(argptr, format);
76  vsprintf(buffer, format, argptr);
77  va_end(argptr);
78 
79 #if WITH_GUI
80  OutputDebugString(buffer);
81 #else /* WITH_GUI */
82  fputs(buffer, stderr);
83 #endif /* WITH_GUI */
84 }
85 /*-----------------------------------------------------------------------------------*/
86 void
87 uip_log(char *message)
88 {
89  debug_printf("%s\n", message);
90 }
91 /*-----------------------------------------------------------------------------------*/
92 void
93 log_message(const char *part1, const char *part2)
94 {
95  debug_printf("%s%s\n", part1, part2);
96 }
97 /*-----------------------------------------------------------------------------------*/
98 int contiki_argc = 0;
99 char **contiki_argv;
100 
101 int
102 main(int argc, char **argv)
103 {
104  contiki_argc = argc;
105  contiki_argv = argv;
106 
107  /* The first one or two args are used for wpcap configuration */
108  /* so this needs to be "removed" from contiki_args. */
109  contiki_argc--;
110  contiki_argv++;
111 #ifdef UIP_FALLBACK_INTERFACE
112  contiki_argc--;
113  contiki_argv++;
114 #endif
115 
116  process_init();
117 
118  procinit_init();
119 
120 #ifdef PLATFORM_BUILD
121  program_handler_add(&directory_dsc, "Directory", 1);
122  program_handler_add(&www_dsc, "Web browser", 1);
123 #endif /* PLATFORM_BUILD */
124 
125  autostart_start(autostart_processes);
126 
127 #if !UIP_CONF_IPV6
128  {
129  uip_ipaddr_t addr;
130  uip_ipaddr(&addr, 192,168,0,111);
131  uip_sethostaddr(&addr);
132  log_message("IP Address: ", inet_ntoa(*(struct in_addr*)&addr));
133 
134  uip_ipaddr(&addr, 255,255,255,0);
135  uip_setnetmask(&addr);
136  log_message("Subnet Mask: ", inet_ntoa(*(struct in_addr*)&addr));
137 
138  uip_ipaddr(&addr, 192,168,0,1);
139  uip_setdraddr(&addr);
140  log_message("Def. Router: ", inet_ntoa(*(struct in_addr*)&addr));
141 
142  uip_ipaddr(&addr, 192,168,0,1);
143  resolv_conf(&addr);
144  log_message("DNS Server: ", inet_ntoa(*(struct in_addr*)&addr));
145  }
146 
147 #else /* UIP_CONF_IPV6 */
148 
149 #if !UIP_CONF_IPV6_RPL
150 #ifdef HARD_CODED_ADDRESS
151  uip_ipaddr_t ipaddr;
152  uiplib_ipaddrconv(HARD_CODED_ADDRESS, &ipaddr);
153  if ((ipaddr.u16[0]!=0) || (ipaddr.u16[1]!=0) || (ipaddr.u16[2]!=0) || (ipaddr.u16[3]!=0)) {
154 #if UIP_CONF_ROUTER
155  uip_ds6_prefix_add(&ipaddr, UIP_DEFAULT_PREFIX_LEN, 0, 0, 0, 0);
156 #else /* UIP_CONF_ROUTER */
157  uip_ds6_prefix_add(&ipaddr, UIP_DEFAULT_PREFIX_LEN, 0);
158 #endif /* UIP_CONF_ROUTER */
159 #if !UIP_CONF_IPV6_RPL
160  uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
161  uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);
162 #endif
163  }
164 #endif /* HARD_CODED_ADDRESS */
165 #endif
166 #endif
167 
168  while(1) {
169 
170  process_run();
171 
173 
174  /* Allow user-mode APC to execute. */
175  SleepEx(10, TRUE);
176 
177 #ifdef PLATFORM_BUILD
178  if(console_resize()) {
179  ctk_restore();
180  }
181 #endif /* PLATFORM_BUILD */
182  }
183 }
184 /*-----------------------------------------------------------------------------------*/
#define uip_sethostaddr(addr)
Set the IP address of this host.
Definition: uip.h:195
CCIF uip_lladdr_t uip_lladdr
Host L2 address.
Definition: uip6.c:115
void uip_ds6_set_addr_iid(uip_ipaddr_t *ipaddr, uip_lladdr_t *lladdr)
set the last 64 bits of an IP address based on the MAC address
Definition: uip-ds6.c:535
void uip_log(char *msg)
Print out a uIP log message.
Definition: uip-log.c:3
int main(void)
This is main...
Definition: ethconfig.c:49
#define uiplib_ipaddrconv
Convert a textual representation of an IP address to a numerical representation.
Definition: uiplib.h:71
void process_init(void)
Initialize the process module.
Definition: process.c:208
#define uip_setdraddr(addr)
Set the default router&#39;s IP address.
Definition: uip.h:227
void program_handler_add(struct dsc *dsc, char *menuname, unsigned char desktop)
Add a program to the program handler.
#define TRUE
An alias for one, used for clarity.
void etimer_request_poll(void)
Make the event timer aware that the clock has changed.
Definition: etimer.c:145
int process_run(void)
Run the system once - call poll handlers and process one event.
Definition: process.c:302
#define uip_ipaddr(addr, addr0, addr1, addr2, addr3)
Construct an IP address from four bytes.
Definition: uip.h:955
Event timer header file.
#define uip_setnetmask(addr)
Set the netmask.
Definition: uip.h:239
CTK header file.