Use IP over Rime

This commit is contained in:
ksb 2009-07-11 15:07:59 +00:00
parent 88669e1675
commit 3c3714c178
9 changed files with 265 additions and 118 deletions

View file

@ -8,12 +8,17 @@
#include <debug-uart.h>
#include <net/uip-fw-drv.h>
#include <net/uip-over-mesh.h>
#include <dev/slip.h>
#include "contiki-main.h"
/* SLIP interface */
extern struct uip_fw_netif cc2420if;
rimeaddr_t node_addr = {{0,129}};
static struct uip_fw_netif slipif =
{UIP_FW_NETIF(0,0,0,0, 255,255,255,255, slip_send)};
@ -25,6 +30,7 @@ static unsigned char interrupt_buffer[16];
#define DEV_TO_HOST 0x81
#define HOST_TO_DEV 0x02
#define GATEWAY_TRICKLE_CHANNEL 8
void
slip_arch_init(unsigned long ubr)
{
@ -36,6 +42,26 @@ slip_arch_writeb(unsigned char c)
while(usb_send_data(DEV_TO_HOST, &c, 1) != 1);
}
#if WITH_UIP
static void
set_gateway(void)
{
struct gateway_msg msg;
/* Make this node the gateway node, unless it already is the
gateway. */
if(!is_gateway) {
leds_on(LEDS_RED);
printf("%d.%d: making myself the gateway\n",
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1]);
uip_over_mesh_set_gateway(&rimeaddr_node_addr);
rimeaddr_copy(&(msg.gateway), &rimeaddr_node_addr);
rimebuf_copyfrom(&msg, sizeof(struct gateway_msg));
trickle_send(&gateway_trickle);
is_gateway = 1;
}
}
#endif /* WITH_UIP */
PROCESS(gateway_process, "Gateway process");
@ -49,14 +75,17 @@ PROCESS_THREAD(gateway_process, ev , data)
usb_cdc_acm_setup();
uip_fw_default(&slipif);
uip_fw_register(&cc2420if);
uip_over_mesh_set_gateway_netif(&slipif);
process_start(&slip_process, NULL);
set_gateway();
while(ev != PROCESS_EVENT_EXIT) {
PROCESS_WAIT_EVENT();
if (ev == PROCESS_EVENT_TIMER) {
leds_toggle(LEDS_YELLOW);
/* printf("FIFOP: %d\n", FIFOP_IS_1); */
etimer_restart(&timer);
} else if (ev == PROCESS_EVENT_MSG) {
const struct usb_user_msg * const msg = data;
@ -81,8 +110,8 @@ PROCESS_THREAD(gateway_process, ev , data)
break;
case USB_USER_MSG_TYPE_EP_OUT(2):
{
unsigned int len = msg->data.length;
/* printf("Received %d:\n", len); */
/*unsigned int len = msg->data.length;
printf("Received %d:\n", len); */
{
unsigned char ch;
unsigned int xfer;