2006-06-17 22:41:10 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2004, Swedish Institute of Computer Science.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. Neither the name of the Institute nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* This file is part of the Contiki operating system.
|
|
|
|
*
|
|
|
|
* Author: Adam Dunkels <adam@sics.se>
|
|
|
|
*
|
2008-11-09 12:30:32 +00:00
|
|
|
* $Id: contiki-main.c,v 1.32 2008/11/09 12:30:32 adamdunkels Exp $
|
2006-06-17 22:41:10 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "contiki.h"
|
|
|
|
#include "contiki-net.h"
|
|
|
|
#include "contiki-lib.h"
|
2007-03-22 23:59:26 +00:00
|
|
|
|
2008-02-03 20:49:50 +00:00
|
|
|
#include "dev/serial.h"
|
2007-03-15 21:58:13 +00:00
|
|
|
#include "net/rime.h"
|
2006-06-17 22:41:10 +00:00
|
|
|
|
2007-04-01 21:05:17 +00:00
|
|
|
#ifdef __CYGWIN__
|
2007-05-20 21:41:31 +00:00
|
|
|
#include "net/wpcap-drv.h"
|
2008-01-04 21:53:32 +00:00
|
|
|
#else /* __CYGWIN__ */
|
2007-05-20 21:41:31 +00:00
|
|
|
#include "net/tapdev-drv.h"
|
2008-01-04 21:53:32 +00:00
|
|
|
#endif /* __CYGWIN__ */
|
2007-03-14 00:32:30 +00:00
|
|
|
#include "net/ethernode-uip.h"
|
2007-03-13 13:07:47 +00:00
|
|
|
#include "net/ethernode-rime.h"
|
2006-06-17 22:41:10 +00:00
|
|
|
#include "net/ethernode.h"
|
2007-03-22 18:59:34 +00:00
|
|
|
#include "net/uip-over-mesh.h"
|
2007-03-15 21:58:13 +00:00
|
|
|
|
2007-11-17 18:01:00 +00:00
|
|
|
#include "net/mac/nullmac.h"
|
2008-05-27 19:07:20 +00:00
|
|
|
#include "net/mac/lpp.h"
|
2007-11-17 18:01:00 +00:00
|
|
|
|
2006-06-17 22:41:10 +00:00
|
|
|
#include "ether.h"
|
|
|
|
|
2007-11-17 18:01:00 +00:00
|
|
|
#include <stdio.h>
|
2008-02-03 20:49:50 +00:00
|
|
|
#ifndef HAVE_SNPRINTF
|
|
|
|
int snprintf(char *str, size_t size, const char *format, ...);
|
|
|
|
#endif /* HAVE_SNPRINTF */
|
|
|
|
|
2006-06-17 22:41:10 +00:00
|
|
|
#include <stdlib.h>
|
2007-11-28 12:54:41 +00:00
|
|
|
#include <sys/select.h>
|
2007-11-17 18:01:00 +00:00
|
|
|
#include <unistd.h>
|
2006-06-17 22:41:10 +00:00
|
|
|
|
|
|
|
#include "dev/button-sensor.h"
|
|
|
|
#include "dev/pir-sensor.h"
|
|
|
|
#include "dev/vib-sensor.h"
|
2006-10-06 08:25:30 +00:00
|
|
|
#include "dev/radio-sensor.h"
|
2006-06-17 22:41:10 +00:00
|
|
|
#include "dev/leds.h"
|
|
|
|
|
2008-01-14 09:38:16 +00:00
|
|
|
#ifdef __CYGWIN__
|
|
|
|
__attribute__((dllimport)) extern int __argc;
|
|
|
|
__attribute__((dllimport)) extern char **__argv[];
|
|
|
|
#endif /* __CYGWIN__ */
|
|
|
|
|
|
|
|
|
2007-04-01 21:05:17 +00:00
|
|
|
#ifdef __CYGWIN__
|
|
|
|
static struct uip_fw_netif extif =
|
|
|
|
{UIP_FW_NETIF(0,0,0,0, 0,0,0,0, wpcap_output)};
|
2008-01-04 21:53:32 +00:00
|
|
|
#else /* __CYGWIN__ */
|
2007-04-01 21:05:17 +00:00
|
|
|
static struct uip_fw_netif extif =
|
2007-03-29 22:24:47 +00:00
|
|
|
{UIP_FW_NETIF(0,0,0,0, 0,0,0,0, tapdev_output)};
|
2008-01-04 21:53:32 +00:00
|
|
|
#endif /* __CYGWIN__ */
|
2007-03-22 18:59:34 +00:00
|
|
|
static struct uip_fw_netif meshif =
|
|
|
|
{UIP_FW_NETIF(172,16,0,0, 255,255,0,0, uip_over_mesh_send)};
|
2007-03-14 00:32:30 +00:00
|
|
|
/*static struct uip_fw_netif ethernodeif =
|
|
|
|
{UIP_FW_NETIF(172,16,0,0, 255,255,0,0, ethernode_drv_send)};*/
|
2006-06-17 22:41:10 +00:00
|
|
|
|
|
|
|
static const struct uip_eth_addr ethaddr = {{0x00,0x06,0x98,0x01,0x02,0x12}};
|
|
|
|
|
2006-10-06 08:25:30 +00:00
|
|
|
SENSORS(&button_sensor, &pir_sensor, &vib_sensor, &radio_sensor);
|
2006-06-17 22:41:10 +00:00
|
|
|
|
2008-11-09 12:30:32 +00:00
|
|
|
PROCINIT(&sensors_process, &etimer_process, &tcpip_process);
|
2006-06-17 22:41:10 +00:00
|
|
|
|
2007-12-17 01:12:09 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
#ifdef __CYGWIN__
|
|
|
|
static void
|
|
|
|
remove_route(int s)
|
|
|
|
{
|
|
|
|
char buf[1024];
|
|
|
|
|
|
|
|
snprintf(buf, sizeof(buf), "route delete %d.%d.%d.%d",
|
|
|
|
uip_ipaddr_to_quad(&meshif.ipaddr));
|
|
|
|
printf("%s\n", buf);
|
|
|
|
system(buf);
|
|
|
|
_exit(0);
|
|
|
|
}
|
2008-01-04 21:53:32 +00:00
|
|
|
#endif /* __CYGWIN__ */
|
2006-06-17 22:41:10 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
|
|
|
contiki_main(int flag)
|
|
|
|
{
|
2006-10-23 09:01:06 +00:00
|
|
|
random_init(getpid());
|
2007-03-14 00:32:30 +00:00
|
|
|
srand(getpid());
|
2006-06-17 22:41:10 +00:00
|
|
|
|
|
|
|
leds_init();
|
|
|
|
|
|
|
|
process_init();
|
|
|
|
|
|
|
|
procinit_init();
|
2007-03-14 00:32:30 +00:00
|
|
|
|
2008-01-14 09:38:16 +00:00
|
|
|
serial_init();
|
2007-03-22 18:59:34 +00:00
|
|
|
|
2008-01-14 09:38:16 +00:00
|
|
|
uip_init();
|
|
|
|
|
2007-11-15 13:07:42 +00:00
|
|
|
ctimer_init();
|
2007-10-25 08:26:49 +00:00
|
|
|
rime_init(nullmac_init(ðernode_driver));
|
|
|
|
|
2007-03-22 18:59:34 +00:00
|
|
|
uip_over_mesh_init(0);
|
2008-11-09 12:30:32 +00:00
|
|
|
uip_over_mesh_set_net(&meshif.ipaddr, &meshif.netmask);
|
|
|
|
|
2006-06-17 22:41:10 +00:00
|
|
|
if(flag == 1) {
|
2007-04-01 21:05:17 +00:00
|
|
|
#ifdef __CYGWIN__
|
2008-01-14 09:38:16 +00:00
|
|
|
if(__argc > 2 && (*__argv)[1][0] != '-') {
|
|
|
|
process_start(&wpcap_process, NULL);
|
|
|
|
{
|
|
|
|
char buf[1024];
|
2008-03-03 20:21:59 +00:00
|
|
|
uip_ipaddr_t ifaddr;
|
2008-11-09 12:30:32 +00:00
|
|
|
extern uip_ipaddr_t winifaddr;
|
2008-03-03 20:21:59 +00:00
|
|
|
|
2008-11-09 12:30:32 +00:00
|
|
|
uip_ipaddr_copy(&ifaddr, &winifaddr);
|
2008-01-14 09:38:16 +00:00
|
|
|
|
|
|
|
snprintf(buf, sizeof(buf), "route add %d.%d.%d.%d mask %d.%d.%d.%d %d.%d.%d.%d",
|
|
|
|
uip_ipaddr_to_quad(&meshif.ipaddr),
|
|
|
|
uip_ipaddr_to_quad(&meshif.netmask),
|
2008-03-03 20:21:59 +00:00
|
|
|
uip_ipaddr_to_quad(&ifaddr));
|
2008-01-14 09:38:16 +00:00
|
|
|
printf("%s\n", buf);
|
|
|
|
system(buf);
|
|
|
|
signal(SIGTERM, remove_route);
|
|
|
|
}
|
2007-12-17 01:12:09 +00:00
|
|
|
}
|
2008-01-04 21:53:32 +00:00
|
|
|
#else /* __CYGWIN__ */
|
2007-03-28 20:15:15 +00:00
|
|
|
process_start(&tapdev_process, NULL);
|
2008-01-04 21:53:32 +00:00
|
|
|
#endif /* __CYGWIN__ */
|
2008-11-09 12:30:32 +00:00
|
|
|
process_start(&uip_fw_process, NULL);
|
|
|
|
|
2007-03-22 18:59:34 +00:00
|
|
|
uip_fw_register(&meshif);
|
2007-04-01 21:05:17 +00:00
|
|
|
uip_fw_default(&extif);
|
2008-01-04 22:21:04 +00:00
|
|
|
printf("uip_hostaddr %d.%d.%d.%d\n", uip_ipaddr_to_quad(&uip_hostaddr));
|
2008-11-09 12:30:32 +00:00
|
|
|
uip_over_mesh_make_announced_gateway();
|
2006-06-17 22:41:10 +00:00
|
|
|
} else {
|
2008-11-09 12:30:32 +00:00
|
|
|
process_start(&uip_fw_process, NULL);
|
2007-03-22 18:59:34 +00:00
|
|
|
uip_fw_default(&meshif);
|
2006-06-17 22:41:10 +00:00
|
|
|
}
|
2007-03-22 18:59:34 +00:00
|
|
|
|
2006-06-17 22:41:10 +00:00
|
|
|
leds_green(LEDS_ON);
|
|
|
|
|
2007-05-22 21:08:57 +00:00
|
|
|
rtimer_init();
|
|
|
|
|
2008-02-10 22:36:36 +00:00
|
|
|
autostart_start(autostart_processes);
|
2007-03-13 13:07:47 +00:00
|
|
|
|
2006-06-17 22:41:10 +00:00
|
|
|
while(1) {
|
|
|
|
int n;
|
2007-11-28 12:54:41 +00:00
|
|
|
struct timeval tv;
|
2007-11-26 23:28:33 +00:00
|
|
|
|
2006-06-17 22:41:10 +00:00
|
|
|
n = process_run();
|
|
|
|
/* if(n > 0) {
|
2008-08-15 19:34:07 +00:00
|
|
|
printf("%d processes in queue\n", n);
|
2006-06-17 22:41:10 +00:00
|
|
|
}*/
|
2007-11-28 12:54:41 +00:00
|
|
|
tv.tv_sec = 0;
|
|
|
|
tv.tv_usec = 1;
|
|
|
|
select(0, NULL, NULL, NULL, &tv);
|
2006-06-17 22:41:10 +00:00
|
|
|
etimer_request_poll();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
process_event_t codeprop_event_quit;
|