Initial import of the experimental Rime code into the SourceForge CVS.
This commit is contained in:
parent
cba13ef56c
commit
2d7aab3ffe
30 changed files with 2628 additions and 0 deletions
2
core/net/rime/Makefile.rime
Normal file
2
core/net/rime/Makefile.rime
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
CONTIKI_SOURCEFILES += rimebuf.c queuebuf.c ctimer.c neighbor.c rime.c \
|
||||||
|
abc-udp.c ibc.c uc.c suc.c ruc.c sibc.c sabc.c ccsabc.c
|
88
core/net/rime/abc-udp.c
Normal file
88
core/net/rime/abc-udp.c
Normal file
|
@ -0,0 +1,88 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2006, 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.
|
||||||
|
*
|
||||||
|
* $Id: abc-udp.c,v 1.1 2007/02/28 16:38:51 adamdunkels Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* Implementation of the Rime module Anonymous BroadCast (abc) using UDP local broadcast packets.
|
||||||
|
* \author
|
||||||
|
* Adam Dunkels <adam@sics.se>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "net/rime.h"
|
||||||
|
|
||||||
|
#define PORT 8096
|
||||||
|
|
||||||
|
static u8_t started;
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
PROCESS(abc_udp_process, "abc_udp");
|
||||||
|
PROCESS_THREAD(abc_udp_process, ev, data)
|
||||||
|
{
|
||||||
|
struct abc_conn *c;
|
||||||
|
|
||||||
|
|
||||||
|
PROCESS_BEGIN();
|
||||||
|
|
||||||
|
while(1) {
|
||||||
|
PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event && uip_newdata());
|
||||||
|
DEBUGF(0, "%d: abc_udp_process: new data %p\n", node_id, data);
|
||||||
|
c = data;
|
||||||
|
rimebuf_copyfrom(uip_appdata, uip_datalen());
|
||||||
|
c->u->recv(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
PROCESS_END();
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
abc_setup(struct abc_conn *c, u16_t channel,
|
||||||
|
const struct abc_ulayer *u)
|
||||||
|
{
|
||||||
|
if(!started) {
|
||||||
|
process_start(&abc_udp_process, NULL);
|
||||||
|
started = 1;
|
||||||
|
}
|
||||||
|
PROCESS_CONTEXT_BEGIN(&abc_udp_process);
|
||||||
|
c->c = udp_broadcast_new(HTONS(PORT + channel), c);
|
||||||
|
PROCESS_CONTEXT_END(&abc_udp_process);
|
||||||
|
c->u = u;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
int
|
||||||
|
abc_send(struct abc_conn *c)
|
||||||
|
{
|
||||||
|
DEBUGF(0, "%d: abc_send\n", node_id);
|
||||||
|
uip_len = rimebuf_copyto(uip_buf);
|
||||||
|
uip_udp_packet_send(c->c, uip_buf, uip_len);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
62
core/net/rime/abc.h
Normal file
62
core/net/rime/abc.h
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2006, 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.
|
||||||
|
*
|
||||||
|
* $Id: abc.h,v 1.1 2007/02/28 16:38:51 adamdunkels Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* Header file for the Rime module Anonymous BroadCast (abc)
|
||||||
|
* \author
|
||||||
|
* Adam Dunkels <adam@sics.se>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __ABC_H__
|
||||||
|
#define __ABC_H__
|
||||||
|
|
||||||
|
#include "contiki-net.h"
|
||||||
|
#include "net/rime/rimebuf.h"
|
||||||
|
|
||||||
|
struct abc_conn;
|
||||||
|
|
||||||
|
struct abc_ulayer {
|
||||||
|
void (* recv)(struct abc_conn *ptr);
|
||||||
|
};
|
||||||
|
|
||||||
|
struct abc_conn {
|
||||||
|
struct uip_udp_conn *c;
|
||||||
|
const struct abc_ulayer *u;
|
||||||
|
};
|
||||||
|
|
||||||
|
void abc_setup(struct abc_conn *c, u16_t channel,
|
||||||
|
const struct abc_ulayer *u);
|
||||||
|
int abc_send(struct abc_conn *c);
|
||||||
|
|
||||||
|
#endif /* __BC_H__ */
|
91
core/net/rime/ccsabc.c
Normal file
91
core/net/rime/ccsabc.c
Normal file
|
@ -0,0 +1,91 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2007, 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.
|
||||||
|
*
|
||||||
|
* $Id: ccsabc.c,v 1.1 2007/02/28 16:38:51 adamdunkels Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* Congestion-Controlled Stubborn Anonymous BroadCast (ccsabc)
|
||||||
|
* \author
|
||||||
|
* Adam Dunkels <adam@sics.se>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "net/rime/ccsabc.h"
|
||||||
|
|
||||||
|
#define STATE_LISTENPERIOD 0
|
||||||
|
#define STATE_SENDINGPERIOD 1
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static void
|
||||||
|
recv_from_sabc(struct sabc_conn *sabc)
|
||||||
|
{
|
||||||
|
struct ccsabc_conn *c = (struct ccsabc_conn *)sabc;
|
||||||
|
if(c->u->recv != NULL) {
|
||||||
|
c->u->recv(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static void
|
||||||
|
sent_from_sabc(struct sabc_conn *sabc)
|
||||||
|
{
|
||||||
|
struct ccsabc_conn *c = (struct ccsabc_conn *)sabc;
|
||||||
|
if(c->u->sent != NULL) {
|
||||||
|
c->u->sent(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static const struct sabc_ulayer ccsabc = {recv_from_sabc, sent_from_sabc};
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
ccsabc_setup(struct ccsabc_conn *c, u16_t channel,
|
||||||
|
const struct ccsabc_ulayer *u)
|
||||||
|
{
|
||||||
|
sabc_setup(&c->c, channel, &ccsabc);
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
int
|
||||||
|
ccsabc_send_stubborn(struct ccsabc_conn *c, clock_time_t t)
|
||||||
|
{
|
||||||
|
return sabc_send_stubborn(&c->c, t);
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
ccsabc_cancel(struct ccsabc_conn *c)
|
||||||
|
{
|
||||||
|
sabc_cancel(&c->c);
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
ccsabc_set_timer(struct ccsabc_conn *c, clock_time_t t)
|
||||||
|
{
|
||||||
|
sabc_set_timer(&c->c, t);
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
69
core/net/rime/ccsabc.h
Normal file
69
core/net/rime/ccsabc.h
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2007, 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.
|
||||||
|
*
|
||||||
|
* $Id: ccsabc.h,v 1.1 2007/02/28 16:38:51 adamdunkels Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* Congestion-Controlled Stubborn Anonymous BroadCast (ccsabc)
|
||||||
|
* \author
|
||||||
|
* Adam Dunkels <adam@sics.se>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __CCSABC_H__
|
||||||
|
#define __CCSABC_H__
|
||||||
|
|
||||||
|
#include "net/rime.h"
|
||||||
|
#include "net/rime/sabc.h"
|
||||||
|
|
||||||
|
struct ccsabc_conn;
|
||||||
|
|
||||||
|
struct ccsabc_ulayer {
|
||||||
|
void (* recv)(struct ccsabc_conn *c);
|
||||||
|
void (* sent)(struct ccsabc_conn *c);
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ccsabc_conn {
|
||||||
|
struct sabc_conn conn;
|
||||||
|
const struct ccsabc_ulayer *u;
|
||||||
|
unsigned char state;
|
||||||
|
unsigned char c;
|
||||||
|
};
|
||||||
|
|
||||||
|
void ccsabc_setup(struct ccsabc_conn *c, u16_t channel,
|
||||||
|
const struct ccsabc_ulayer *u);
|
||||||
|
|
||||||
|
int ccsabc_send_stubborn(struct ccsabc_conn *c, clock_time_t t);
|
||||||
|
void ccsabc_cancel(struct ccsabc_conn *c);
|
||||||
|
|
||||||
|
void ccsabc_set_timer(struct ccsabc_conn *c, clock_time_t t);
|
||||||
|
|
||||||
|
#endif /* __CCSABC_H__ */
|
114
core/net/rime/ctimer.c
Normal file
114
core/net/rime/ctimer.c
Normal file
|
@ -0,0 +1,114 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2006, 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.
|
||||||
|
*
|
||||||
|
* $Id: ctimer.c,v 1.1 2007/02/28 16:38:51 adamdunkels Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* A brief description of what this file is.
|
||||||
|
* \author
|
||||||
|
* Adam Dunkels <adam@sics.se>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "net/rime/ctimer.h"
|
||||||
|
#include "contiki.h"
|
||||||
|
#include "lib/list.h"
|
||||||
|
#include "net/rime.h"
|
||||||
|
|
||||||
|
LIST(ctimer_list);
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
PROCESS(ctimer_process, "ctimer process");
|
||||||
|
PROCESS_THREAD(ctimer_process, ev, data)
|
||||||
|
{
|
||||||
|
struct ctimer *c;
|
||||||
|
PROCESS_BEGIN();
|
||||||
|
|
||||||
|
list_init(ctimer_list);
|
||||||
|
|
||||||
|
while(1) {
|
||||||
|
PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_TIMER);
|
||||||
|
for(c = list_head(ctimer_list); c != NULL; c = c->next) {
|
||||||
|
if(&c->etimer == data) {
|
||||||
|
list_remove(ctimer_list, c);
|
||||||
|
PROCESS_CONTEXT_BEGIN(c->p);
|
||||||
|
if(c->f != NULL) {
|
||||||
|
c->f(c->ptr);
|
||||||
|
}
|
||||||
|
PROCESS_CONTEXT_END(c->p);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
PROCESS_END();
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
ctimer_init(void)
|
||||||
|
{
|
||||||
|
process_start(&ctimer_process, NULL);
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
ctimer_set(struct ctimer *c, clock_time_t t,
|
||||||
|
void (*f)(void *), void *ptr)
|
||||||
|
{
|
||||||
|
DEBUGF(3, "ctimer_set %p %d\n", c, t);
|
||||||
|
c->p = PROCESS_CURRENT();
|
||||||
|
c->f = f;
|
||||||
|
c->ptr = ptr;
|
||||||
|
|
||||||
|
PROCESS_CONTEXT_BEGIN(&ctimer_process);
|
||||||
|
etimer_set(&c->etimer, t);
|
||||||
|
PROCESS_CONTEXT_END(&ctimer_process);
|
||||||
|
|
||||||
|
list_remove(ctimer_list, c);
|
||||||
|
list_add(ctimer_list, c);
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
ctimer_reset(struct ctimer *c)
|
||||||
|
{
|
||||||
|
PROCESS_CONTEXT_BEGIN(&ctimer_process);
|
||||||
|
etimer_reset(&c->etimer);
|
||||||
|
PROCESS_CONTEXT_END(&ctimer_process);
|
||||||
|
|
||||||
|
list_remove(ctimer_list, c);
|
||||||
|
list_add(ctimer_list, c);
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
ctimer_stop(struct ctimer *c)
|
||||||
|
{
|
||||||
|
etimer_stop(&c->etimer);
|
||||||
|
list_remove(ctimer_list, c);
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
62
core/net/rime/ctimer.h
Normal file
62
core/net/rime/ctimer.h
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2006, 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.
|
||||||
|
*
|
||||||
|
* $Id: ctimer.h,v 1.1 2007/02/28 16:38:51 adamdunkels Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* Module which calls a function after a time
|
||||||
|
* \author
|
||||||
|
* Adam Dunkels <adam@sics.se>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __CTIMER_H__
|
||||||
|
#define __CTIMER_H__
|
||||||
|
|
||||||
|
#include "sys/etimer.h"
|
||||||
|
|
||||||
|
struct ctimer {
|
||||||
|
struct ctimer *next;
|
||||||
|
struct etimer etimer;
|
||||||
|
struct process *p;
|
||||||
|
void (*f)(void *);
|
||||||
|
void *ptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
void ctimer_reset(struct ctimer *c);
|
||||||
|
|
||||||
|
void ctimer_set(struct ctimer *c, clock_time_t t,
|
||||||
|
void (*f)(void *), void *ptr);
|
||||||
|
void ctimer_stop(struct ctimer *c);
|
||||||
|
|
||||||
|
void ctimer_init(void);
|
||||||
|
|
||||||
|
#endif /* __CTIMER_H__ */
|
81
core/net/rime/ibc.c
Normal file
81
core/net/rime/ibc.c
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2006, 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.
|
||||||
|
*
|
||||||
|
* $Id: ibc.c,v 1.1 2007/02/28 16:38:51 adamdunkels Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* A brief description of what this file is.
|
||||||
|
* \author
|
||||||
|
* Adam Dunkels <adam@sics.se>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "net/rime/ibc.h"
|
||||||
|
#include "net/rime.h"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
struct ibc_hdr {
|
||||||
|
node_id_t sender_id;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static void
|
||||||
|
recv_from_abc(struct abc_conn *bc)
|
||||||
|
{
|
||||||
|
struct ibc_conn *c = (struct ibc_conn *)bc;
|
||||||
|
struct ibc_hdr *hdr = rimebuf_dataptr();
|
||||||
|
rimebuf_hdrreduce(sizeof(struct ibc_hdr));
|
||||||
|
DEBUGF(1, "%d: ibc: recv_from_bc\n", node_id);
|
||||||
|
c->u->recv(c, hdr->sender_id);
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static const struct abc_ulayer ibc = {recv_from_abc};
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
ibc_setup(struct ibc_conn *c, u16_t channel,
|
||||||
|
const struct ibc_ulayer *u)
|
||||||
|
{
|
||||||
|
abc_setup(&c->c, channel, &ibc);
|
||||||
|
c->u = u;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
int
|
||||||
|
ibc_send(struct ibc_conn *c)
|
||||||
|
{
|
||||||
|
DEBUGF(1, "%d: ibc_send\n", node_id);
|
||||||
|
if(rimebuf_hdrextend(sizeof(struct ibc_hdr))) {
|
||||||
|
struct ibc_hdr *hdr = rimebuf_hdrptr();
|
||||||
|
hdr->sender_id = node_id;
|
||||||
|
return abc_send(&c->c);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
62
core/net/rime/ibc.h
Normal file
62
core/net/rime/ibc.h
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2006, 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.
|
||||||
|
*
|
||||||
|
* $Id: ibc.h,v 1.1 2007/02/28 16:38:51 adamdunkels Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* A brief description of what this file is.
|
||||||
|
* \author
|
||||||
|
* Adam Dunkels <adam@sics.se>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __IBC_H__
|
||||||
|
#define __IBC_H__
|
||||||
|
|
||||||
|
#include "net/rime/abc.h"
|
||||||
|
#include "net/rime/node-id-t.h"
|
||||||
|
|
||||||
|
struct ibc_conn;
|
||||||
|
|
||||||
|
struct ibc_ulayer {
|
||||||
|
void (* recv)(struct ibc_conn *ptr, node_id_t sender);
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ibc_conn {
|
||||||
|
struct abc_conn c;
|
||||||
|
const struct ibc_ulayer *u;
|
||||||
|
};
|
||||||
|
|
||||||
|
void ibc_setup(struct ibc_conn *c, u16_t channel,
|
||||||
|
const struct ibc_ulayer *u);
|
||||||
|
int ibc_send(struct ibc_conn *c);
|
||||||
|
|
||||||
|
#endif /* __IBC_H__ */
|
207
core/net/rime/neighbor.c
Normal file
207
core/net/rime/neighbor.c
Normal file
|
@ -0,0 +1,207 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2006, 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.
|
||||||
|
*
|
||||||
|
* $Id: neighbor.c,v 1.1 2007/02/28 16:38:51 adamdunkels Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* Radio neighborhood management
|
||||||
|
* \author
|
||||||
|
* Adam Dunkels <adam@sics.se>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
|
#include "contiki.h"
|
||||||
|
#include "net/rime/neighbor.h"
|
||||||
|
#include "node-id.h"
|
||||||
|
|
||||||
|
#define MAX_NEIGHBORS 5
|
||||||
|
|
||||||
|
#define HOPCOUNT_MAX 32
|
||||||
|
|
||||||
|
static struct neighbor neighbors[MAX_NEIGHBORS];
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
neighbor_periodic(int max_time)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for(i = 0; i < MAX_NEIGHBORS; ++i) {
|
||||||
|
if(neighbors[i].nodeid != 0 &&
|
||||||
|
neighbors[i].time < max_time) {
|
||||||
|
neighbors[i].time++;
|
||||||
|
if(neighbors[i].time == max_time) {
|
||||||
|
neighbors[i].hopcount = HOPCOUNT_MAX;
|
||||||
|
/* printf("%d: removing old neighbor %d\n", node_id, neighbors[i].nodeid);*/
|
||||||
|
neighbors[i].nodeid = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
neighbor_init(void)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for(i = 0; i < MAX_NEIGHBORS; ++i) {
|
||||||
|
neighbors[i].nodeid = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
struct neighbor *
|
||||||
|
neighbor_find(node_id_t nodeid)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for(i = 0; i < MAX_NEIGHBORS; ++i) {
|
||||||
|
if(neighbors[i].nodeid == nodeid) {
|
||||||
|
return &neighbors[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
neighbor_update(struct neighbor *n, u8_t hopcount, u16_t signal)
|
||||||
|
{
|
||||||
|
if(n != NULL) {
|
||||||
|
n->hopcount = hopcount;
|
||||||
|
n->signal = signal;
|
||||||
|
n->time = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
neighbor_add(node_id_t nodeid, u8_t nhopcount, u16_t nsignal)
|
||||||
|
{
|
||||||
|
int i, n;
|
||||||
|
u8_t hopcount;
|
||||||
|
u16_t signal;
|
||||||
|
|
||||||
|
/* Find the first unused entry or the used entry with the highest
|
||||||
|
hopcount and lowest signal strength. */
|
||||||
|
hopcount = 0;
|
||||||
|
signal = USHRT_MAX;
|
||||||
|
|
||||||
|
for(i = 0; i < MAX_NEIGHBORS; ++i) {
|
||||||
|
if(neighbors[i].nodeid == 0 ||
|
||||||
|
neighbors[i].nodeid == nodeid) {
|
||||||
|
n = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(neighbors[i].nodeid != 0) {
|
||||||
|
if(neighbors[i].hopcount > hopcount) {
|
||||||
|
hopcount = neighbors[i].hopcount;
|
||||||
|
signal = neighbors[i].signal;
|
||||||
|
n = i;
|
||||||
|
} else if(neighbors[i].hopcount == hopcount) {
|
||||||
|
if(neighbors[i].signal < signal) {
|
||||||
|
hopcount = neighbors[i].hopcount;
|
||||||
|
signal = neighbors[i].signal;
|
||||||
|
n = i;
|
||||||
|
/* printf("%d: found worst neighbor %d with hopcount %d, signal %d\n",
|
||||||
|
node_id, neighbors[n].nodeid, hopcount, signal);*/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* printf("%d: adding neighbor %d with hopcount %d, signal %d at %d\n",
|
||||||
|
node_id, neighbors[n].nodeid, hopcount, signal, n);*/
|
||||||
|
|
||||||
|
neighbors[n].time = 0;
|
||||||
|
neighbors[n].nodeid = nodeid;
|
||||||
|
neighbors[n].hopcount = nhopcount;
|
||||||
|
neighbors[n].signal = nsignal;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
neighbor_remove(node_id_t nodeid)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for(i = 0; i < MAX_NEIGHBORS; ++i) {
|
||||||
|
if(neighbors[i].nodeid == nodeid) {
|
||||||
|
printf("%d: removing %d @ %d\n", node_id, nodeid, i);
|
||||||
|
neighbors[i].nodeid = 0;
|
||||||
|
neighbors[i].hopcount = HOPCOUNT_MAX;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
struct neighbor *
|
||||||
|
neighbor_best(void)
|
||||||
|
{
|
||||||
|
int i, found;
|
||||||
|
int lowest, best;
|
||||||
|
u8_t hopcount;
|
||||||
|
u16_t signal;
|
||||||
|
|
||||||
|
hopcount = HOPCOUNT_MAX;
|
||||||
|
lowest = 0;
|
||||||
|
found = 0;
|
||||||
|
|
||||||
|
/* printf("%d: ", node_id);*/
|
||||||
|
|
||||||
|
/* Find the lowest hopcount. */
|
||||||
|
for(i = 0; i < MAX_NEIGHBORS; ++i) {
|
||||||
|
/* printf("%d:%d ", neighbors[i].nodeid, neighbors[i].hopcount);*/
|
||||||
|
if(neighbors[i].nodeid != 0 &&
|
||||||
|
hopcount > neighbors[i].hopcount) {
|
||||||
|
hopcount = neighbors[i].hopcount;
|
||||||
|
lowest = i;
|
||||||
|
found = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* printf("\n");*/
|
||||||
|
|
||||||
|
/* Find the neighbor with highest signal strength of the ones that
|
||||||
|
have the lowest hopcount. */
|
||||||
|
if(found) {
|
||||||
|
signal = 0;
|
||||||
|
best = lowest;
|
||||||
|
for(i = 0; i < MAX_NEIGHBORS; ++i) {
|
||||||
|
if(neighbors[i].nodeid != 0 &&
|
||||||
|
hopcount == neighbors[i].hopcount &&
|
||||||
|
neighbors[i].signal > signal) {
|
||||||
|
signal = neighbors[i].signal;
|
||||||
|
best = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return &neighbors[best];
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
67
core/net/rime/neighbor.h
Normal file
67
core/net/rime/neighbor.h
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2006, 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.
|
||||||
|
*
|
||||||
|
* $Id: neighbor.h,v 1.1 2007/02/28 16:38:51 adamdunkels Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* Header file for the Contiki radio neighborhood management
|
||||||
|
* \author
|
||||||
|
* Adam Dunkels <adam@sics.se>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __NEIGHBOR_H__
|
||||||
|
#define __NEIGHBOR_H__
|
||||||
|
|
||||||
|
#include "net/rime/node-id-t.h"
|
||||||
|
|
||||||
|
struct neighbor {
|
||||||
|
u16_t signal;
|
||||||
|
u16_t time;
|
||||||
|
node_id_t nodeid;
|
||||||
|
u8_t hopcount;
|
||||||
|
};
|
||||||
|
|
||||||
|
void neighbor_init(void);
|
||||||
|
void neighbor_periodic(int max_time);
|
||||||
|
|
||||||
|
void neighbor_add(node_id_t nodeid, u8_t hopcount, u16_t signal);
|
||||||
|
void neighbor_update(struct neighbor *n, u8_t hopcount, u16_t signal);
|
||||||
|
|
||||||
|
void neighbor_remove(node_id_t nodeid);
|
||||||
|
|
||||||
|
struct neighbor *neighbor_find(node_id_t nodeid);
|
||||||
|
struct neighbor *neighbor_best(void);
|
||||||
|
|
||||||
|
#define NEIGHBOR_NODEID(n) ((n)->nodeid)
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* __NEIGHBOR_H__ */
|
50
core/net/rime/node-id-t.h
Normal file
50
core/net/rime/node-id-t.h
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2006, 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.
|
||||||
|
*
|
||||||
|
* $Id: node-id-t.h,v 1.1 2007/02/28 16:38:51 adamdunkels Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* A brief description of what this file is.
|
||||||
|
* \author
|
||||||
|
* Adam Dunkels <adam@sics.se>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __NODE_ID_T_H__
|
||||||
|
#define __NODE_ID_T_H__
|
||||||
|
|
||||||
|
#include "contiki-net.h"
|
||||||
|
|
||||||
|
typedef u16_t node_id_t;
|
||||||
|
|
||||||
|
#include "node-id.h"
|
||||||
|
|
||||||
|
#endif /* __NODE-ID_T_H__ */
|
116
core/net/rime/queuebuf.c
Normal file
116
core/net/rime/queuebuf.c
Normal file
|
@ -0,0 +1,116 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2006, 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.
|
||||||
|
*
|
||||||
|
* $Id: queuebuf.c,v 1.1 2007/02/28 16:38:51 adamdunkels Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* A brief description of what this file is.
|
||||||
|
* \author
|
||||||
|
* Adam Dunkels <adam@sics.se>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "net/rime/queuebuf.h"
|
||||||
|
|
||||||
|
#define QUEUEBUF_NUM 2
|
||||||
|
#define QUEUEBUF_REF_NUM 2
|
||||||
|
|
||||||
|
struct queuebuf {
|
||||||
|
u16_t len;
|
||||||
|
u8_t data[NETBUF_SIZE + NETBUF_HDR_SIZE];
|
||||||
|
};
|
||||||
|
|
||||||
|
struct queuebuf_ref {
|
||||||
|
u16_t len;
|
||||||
|
u8_t *ref;
|
||||||
|
u8_t hdr[NETBUF_HDR_SIZE];
|
||||||
|
u8_t hdrlen;
|
||||||
|
};
|
||||||
|
|
||||||
|
MEMB(bufmem, struct queuebuf, QUEUEBUF_NUM);
|
||||||
|
MEMB(refbufmem, struct queuebuf_ref, QUEUEBUF_REF_NUM);
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
queuebuf_init(void)
|
||||||
|
{
|
||||||
|
memb_init(&bufmem);
|
||||||
|
memb_init(&refbufmem);
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
struct queuebuf *
|
||||||
|
queuebuf_new_from_rimebuf(void)
|
||||||
|
{
|
||||||
|
struct queuebuf *buf;
|
||||||
|
struct queuebuf_ref *rbuf;
|
||||||
|
|
||||||
|
if(rimebuf_is_reference()) {
|
||||||
|
rbuf = memb_alloc(&refbufmem);
|
||||||
|
if(rbuf != NULL) {
|
||||||
|
rbuf->len = rimebuf_len();
|
||||||
|
rbuf->ref = rimebuf_reference_ptr();
|
||||||
|
rbuf->hdrlen = rimebuf_copyto_hdr(rbuf->hdr);
|
||||||
|
}
|
||||||
|
return (struct queuebuf *)rbuf;
|
||||||
|
} else {
|
||||||
|
buf = memb_alloc(&bufmem);
|
||||||
|
if(buf != NULL) {
|
||||||
|
buf->len = rimebuf_copyto(buf->data);
|
||||||
|
}
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
queuebuf_free(struct queuebuf *buf)
|
||||||
|
{
|
||||||
|
if(memb_inmemb(&bufmem, buf)) {
|
||||||
|
memb_free(&bufmem, buf);
|
||||||
|
} else if(memb_inmemb(&refbufmem, buf)) {
|
||||||
|
memb_free(&refbufmem, buf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
queuebuf_to_rimebuf(struct queuebuf *b)
|
||||||
|
{
|
||||||
|
struct queuebuf_ref *r;
|
||||||
|
|
||||||
|
if(memb_inmemb(&bufmem, b)) {
|
||||||
|
rimebuf_copyfrom(b->data, b->len);
|
||||||
|
} else if(memb_inmemb(&refbufmem, b)) {
|
||||||
|
r = (struct queuebuf_ref *)b;
|
||||||
|
rimebuf_clear();
|
||||||
|
rimebuf_copyfrom(r->ref, r->len);
|
||||||
|
rimebuf_hdrextend(r->hdrlen);
|
||||||
|
memcpy(rimebuf_hdrptr(), r->hdr, r->hdrlen);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
55
core/net/rime/queuebuf.h
Normal file
55
core/net/rime/queuebuf.h
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2006, 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.
|
||||||
|
*
|
||||||
|
* $Id: queuebuf.h,v 1.1 2007/02/28 16:38:51 adamdunkels Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* A brief description of what this file is.
|
||||||
|
* \author
|
||||||
|
* Adam Dunkels <adam@sics.se>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __QUEUEBUF_H__
|
||||||
|
#define __QUEUEBUF_H__
|
||||||
|
|
||||||
|
#include "net/rime/rimebuf.h"
|
||||||
|
|
||||||
|
struct queuebuf;
|
||||||
|
|
||||||
|
void queuebuf_init(void);
|
||||||
|
|
||||||
|
struct queuebuf *queuebuf_new_from_rimebuf(void);
|
||||||
|
void queuebuf_free(struct queuebuf *b);
|
||||||
|
void queuebuf_from_rimebuf(struct queuebuf *b);
|
||||||
|
void queuebuf_to_rimebuf(struct queuebuf *b);
|
||||||
|
|
||||||
|
#endif /* __QUEUEBUF_H__ */
|
107
core/net/rime/rbc.c
Normal file
107
core/net/rime/rbc.c
Normal file
|
@ -0,0 +1,107 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2006, 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.
|
||||||
|
*
|
||||||
|
* $Id: rbc.c,v 1.1 2007/02/28 16:38:52 adamdunkels Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* A brief description of what this file is.
|
||||||
|
* \author
|
||||||
|
* Adam Dunkels <adam@sics.se>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "net/rime/rbc.h"
|
||||||
|
|
||||||
|
struct rbc_hdr {
|
||||||
|
u16_t seqno;
|
||||||
|
u16_t ackno;
|
||||||
|
};
|
||||||
|
|
||||||
|
PROCESS(rbc_process, "Reliable local broadcast");
|
||||||
|
PROCESS_THREAD(rbc_process, ev, data)
|
||||||
|
{
|
||||||
|
struct rbc_conn *c = (struct rbc_conn *)data;
|
||||||
|
u8_t *packet;
|
||||||
|
u16_t packetlen;
|
||||||
|
|
||||||
|
PROCESS_BEGIN();
|
||||||
|
|
||||||
|
while(1) {
|
||||||
|
PROCESS_WAIT_UNTIL(ev == PROCESS_EVENT_COM &&
|
||||||
|
llbc_received(&c->c, &packet, &packetlen));
|
||||||
|
printf("rbc: received %p %d\n", packet, packetlen);
|
||||||
|
}
|
||||||
|
|
||||||
|
PROCESS_END();
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
rbc_setup(struct rbc_conn *c, u16_t id)
|
||||||
|
{
|
||||||
|
PROCESS_CONTEXT_BEGIN(&rbc_process);
|
||||||
|
llbc_setup(&c->c, id);
|
||||||
|
PROCESS_CONTEXT_END(&rbc_process);
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static int
|
||||||
|
send(struct rbc_conn *c, struct lcpbuf *buf)
|
||||||
|
{
|
||||||
|
int r;
|
||||||
|
PROCESS_CONTEXT_BEGIN(&rbc_process);
|
||||||
|
r = llbc_send(&c->c, buf);
|
||||||
|
PROCESS_CONTEXT_END(&rbc_process);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static int
|
||||||
|
all_acked(struct rbc_conn *c)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
int
|
||||||
|
rbc_send(struct rbc_conn *c, struct lcpbuf *buf)
|
||||||
|
{
|
||||||
|
PT_BEGIN(&c->pt);
|
||||||
|
|
||||||
|
send(c, buf);
|
||||||
|
|
||||||
|
PT_WAIT_UNTIL(&c->pt, all_acked(c));
|
||||||
|
|
||||||
|
PT_END(&c->pt);
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
int
|
||||||
|
rbc_received(struct rbc_conn *c, u8_t **data, u16_t *datalen)
|
||||||
|
{
|
||||||
|
return llbc_received(c, data, datalen);
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
56
core/net/rime/rbc.h
Normal file
56
core/net/rime/rbc.h
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2006, 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.
|
||||||
|
*
|
||||||
|
* $Id: rbc.h,v 1.1 2007/02/28 16:38:52 adamdunkels Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* A brief description of what this file is.
|
||||||
|
* \author
|
||||||
|
* Adam Dunkels <adam@sics.se>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __RBC_H__
|
||||||
|
#define __RBC_H__
|
||||||
|
|
||||||
|
#include "net/rime/abc.h"
|
||||||
|
|
||||||
|
struct rbc_conn {
|
||||||
|
struct abc_conn c;
|
||||||
|
struct pt pt;
|
||||||
|
u16_t num_acked;
|
||||||
|
};
|
||||||
|
|
||||||
|
void rbc_setup(struct rbc_conn *c, u16_t channel);
|
||||||
|
int rbc_send(struct rbc_conn *c, struct lcpbuf *buf);
|
||||||
|
int rbc_received(struct rbc_conn *c, u8_t **data, u16_t *len);
|
||||||
|
|
||||||
|
#endif /* __RBC_H__ */
|
54
core/net/rime/rime-debug.h
Normal file
54
core/net/rime/rime-debug.h
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2006, 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.
|
||||||
|
*
|
||||||
|
* $Id: rime-debug.h,v 1.1 2007/02/28 16:38:52 adamdunkels Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* A brief description of what this file is.
|
||||||
|
* \author
|
||||||
|
* Adam Dunkels <adam@sics.se>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __RIME_DEBUG_H__
|
||||||
|
#define __RIME_DEBUG_H__
|
||||||
|
|
||||||
|
#define DEBUG_LEVEL 0
|
||||||
|
|
||||||
|
#if DEBUG_LEVEL > 0
|
||||||
|
#include <stdio.h>
|
||||||
|
#define DEBUGF(level, ...) if(DEBUG_LEVEL <= level) {printf("%.*s %lu ", 6 - level, " ", clock_time() / CLOCK_SECOND); printf(__VA_ARGS__);}
|
||||||
|
#else
|
||||||
|
#define DEBUGF(level, ...)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* __RINE_DEBUG_H__ */
|
50
core/net/rime/rime.c
Normal file
50
core/net/rime/rime.c
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2006, 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.
|
||||||
|
*
|
||||||
|
* $Id: rime.c,v 1.1 2007/02/28 16:38:52 adamdunkels Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* A brief description of what this file is.
|
||||||
|
* \author
|
||||||
|
* Adam Dunkels <adam@sics.se>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "net/rime.h"
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
rime_init(void)
|
||||||
|
{
|
||||||
|
ctimer_init();
|
||||||
|
queuebuf_init();
|
||||||
|
rimebuf_clear();
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
193
core/net/rime/rimebuf.c
Normal file
193
core/net/rime/rimebuf.c
Normal file
|
@ -0,0 +1,193 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2006, 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.
|
||||||
|
*
|
||||||
|
* $Id: rimebuf.c,v 1.1 2007/02/28 16:38:52 adamdunkels Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* A brief description of what this file is.
|
||||||
|
* \author
|
||||||
|
* Adam Dunkels <adam@sics.se>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "contiki-net.h"
|
||||||
|
#include "net/rime/rimebuf.h"
|
||||||
|
#include "net/rime.h"
|
||||||
|
|
||||||
|
|
||||||
|
static u16_t buflen, bufptr;
|
||||||
|
static u8_t rimebuf[NETBUF_SIZE];
|
||||||
|
|
||||||
|
static u8_t *rimebufptr;
|
||||||
|
|
||||||
|
static u8_t hdrptr;
|
||||||
|
static u8_t rimebuf_hdr[NETBUF_HDR_SIZE];
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
rimebuf_clear(void)
|
||||||
|
{
|
||||||
|
buflen = bufptr = 0;
|
||||||
|
hdrptr = NETBUF_HDR_SIZE;
|
||||||
|
|
||||||
|
rimebufptr = rimebuf;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
int
|
||||||
|
rimebuf_copyfrom(u8_t *from, u16_t len)
|
||||||
|
{
|
||||||
|
u16_t l;
|
||||||
|
|
||||||
|
rimebuf_clear();
|
||||||
|
l = len > NETBUF_SIZE? NETBUF_SIZE: len;
|
||||||
|
memcpy(rimebufptr, from, l);
|
||||||
|
buflen = l;
|
||||||
|
return l;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
int
|
||||||
|
rimebuf_copyto_hdr(u8_t *to)
|
||||||
|
{
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
DEBUGF(0, "rimebuf_write_hdr: header:\n");
|
||||||
|
for(i = hdrptr; i < NETBUF_HDR_SIZE; ++i) {
|
||||||
|
DEBUGF(0, "0x%02x, ", rimebuf_hdr[i]);
|
||||||
|
}
|
||||||
|
DEBUGF(0, "\n");
|
||||||
|
}
|
||||||
|
memcpy(to, rimebuf_hdr + hdrptr, NETBUF_HDR_SIZE - hdrptr);
|
||||||
|
return NETBUF_HDR_SIZE - hdrptr;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
int
|
||||||
|
rimebuf_copyto(u8_t *to)
|
||||||
|
{
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
char buffer[1000];
|
||||||
|
char *bufferptr = buffer;
|
||||||
|
|
||||||
|
bufferptr[0] = 0;
|
||||||
|
for(i = hdrptr; i < NETBUF_HDR_SIZE; ++i) {
|
||||||
|
bufferptr += sprintf(bufferptr, "0x%02x, ", rimebuf_hdr[i]);
|
||||||
|
}
|
||||||
|
DEBUGF(0, "rimebuf_write: header: %s\n", buffer);
|
||||||
|
bufferptr = buffer;
|
||||||
|
bufferptr[0] = 0;
|
||||||
|
for(i = bufptr; i < buflen + bufptr; ++i) {
|
||||||
|
bufferptr += sprintf(bufferptr, "0x%02x, ", rimebuf[i]);
|
||||||
|
}
|
||||||
|
DEBUGF(0, "rimebuf_write: data: %s\n", buffer);
|
||||||
|
}
|
||||||
|
memcpy(to, rimebuf_hdr + hdrptr, NETBUF_HDR_SIZE - hdrptr);
|
||||||
|
memcpy(to + NETBUF_HDR_SIZE - hdrptr, rimebufptr + bufptr,
|
||||||
|
buflen);
|
||||||
|
return NETBUF_HDR_SIZE - hdrptr + buflen;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
int
|
||||||
|
rimebuf_hdrextend(int size)
|
||||||
|
{
|
||||||
|
if(hdrptr > size) {
|
||||||
|
hdrptr -= size;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
hdrptr = 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
int
|
||||||
|
rimebuf_hdrreduce(int size)
|
||||||
|
{
|
||||||
|
if(buflen < size) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bufptr += size;
|
||||||
|
buflen -= size;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
rimebuf_set_len(u16_t len)
|
||||||
|
{
|
||||||
|
DEBUGF(0, "rimebuf_set_len: len %d\n", len);
|
||||||
|
buflen = len;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
void *
|
||||||
|
rimebuf_dataptr(void)
|
||||||
|
{
|
||||||
|
return (void *)(&rimebuf[bufptr]);
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
void *
|
||||||
|
rimebuf_hdrptr(void)
|
||||||
|
{
|
||||||
|
return (void *)(&rimebuf_hdr[hdrptr]);
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
rimebuf_reference(void *ptr, u16_t len)
|
||||||
|
{
|
||||||
|
rimebuf_clear();
|
||||||
|
rimebufptr = ptr;
|
||||||
|
buflen = len;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
int
|
||||||
|
rimebuf_is_reference(void)
|
||||||
|
{
|
||||||
|
return rimebufptr != rimebuf;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
void *
|
||||||
|
rimebuf_reference_ptr(void)
|
||||||
|
{
|
||||||
|
return rimebufptr;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
u16_t
|
||||||
|
rimebuf_len(void)
|
||||||
|
{
|
||||||
|
return buflen;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
u8_t
|
||||||
|
rimebuf_hdrlen(void)
|
||||||
|
{
|
||||||
|
return NETBUF_HDR_SIZE - hdrptr;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
74
core/net/rime/rimebuf.h
Normal file
74
core/net/rime/rimebuf.h
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2006, 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.
|
||||||
|
*
|
||||||
|
* $Id: rimebuf.h,v 1.1 2007/02/28 16:38:52 adamdunkels Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* A brief description of what this file is.
|
||||||
|
* \author
|
||||||
|
* Adam Dunkels <adam@sics.se>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __NETBUF_H__
|
||||||
|
#define __NETBUF_H__
|
||||||
|
|
||||||
|
#include "contiki-net.h"
|
||||||
|
|
||||||
|
#define NETBUF_SIZE 128
|
||||||
|
#define NETBUF_HDR_SIZE 16
|
||||||
|
|
||||||
|
void *rimebuf_dataptr(void);
|
||||||
|
void *rimebuf_hdrptr(void);
|
||||||
|
|
||||||
|
u8_t rimebuf_hdrlen(void);
|
||||||
|
|
||||||
|
u16_t rimebuf_len(void);
|
||||||
|
void rimebuf_set_len(u16_t len);
|
||||||
|
|
||||||
|
void rimebuf_reference(void *ptr, u16_t len);
|
||||||
|
int rimebuf_is_reference(void);
|
||||||
|
void *rimebuf_reference_ptr(void);
|
||||||
|
|
||||||
|
int rimebuf_copyfrom(u8_t *from, u16_t len);
|
||||||
|
|
||||||
|
int rimebuf_copyto(u8_t *to);
|
||||||
|
int rimebuf_copyto_hdr(u8_t *to);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int rimebuf_hdrextend(int size);
|
||||||
|
int rimebuf_hdrreduce(int size);
|
||||||
|
|
||||||
|
void rimebuf_clear(void);
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* __NETBUF_H__ */
|
134
core/net/rime/ruc.c
Normal file
134
core/net/rime/ruc.c
Normal file
|
@ -0,0 +1,134 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2006, 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.
|
||||||
|
*
|
||||||
|
* $Id: ruc.c,v 1.1 2007/02/28 16:38:52 adamdunkels Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* A brief description of what this file is.
|
||||||
|
* \author
|
||||||
|
* Adam Dunkels <adam@sics.se>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "net/rime/ruc.h"
|
||||||
|
#include "net/rime/neighbor.h"
|
||||||
|
#include "net/rime.h"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#define TYPE_DATA 0
|
||||||
|
#define TYPE_ACK 1
|
||||||
|
|
||||||
|
struct ruc_hdr {
|
||||||
|
u8_t type;
|
||||||
|
u8_t seqno;
|
||||||
|
};
|
||||||
|
|
||||||
|
enum {
|
||||||
|
STATE_READY,
|
||||||
|
STATE_SENDING
|
||||||
|
};
|
||||||
|
|
||||||
|
static u8_t seqno;
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static void
|
||||||
|
sent_by_suc(struct suc_conn *suc)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static void
|
||||||
|
recv_from_suc(struct suc_conn *suc, node_id_t from_id)
|
||||||
|
{
|
||||||
|
struct ruc_conn *c = (struct ruc_conn *)suc;
|
||||||
|
struct ruc_hdr *hdr = rimebuf_dataptr();
|
||||||
|
|
||||||
|
DEBUGF(4, "%d: ruc: recv_from_suc type %d seqno %d\n", node_id,
|
||||||
|
hdr->type, hdr->seqno);
|
||||||
|
|
||||||
|
if(hdr->type == TYPE_ACK) {
|
||||||
|
if(hdr->seqno == seqno) {
|
||||||
|
DEBUGF(4, "%d: ruc: ACKed\n", node_id);
|
||||||
|
++seqno;
|
||||||
|
suc_cancel(&c->c);
|
||||||
|
if(c->u->sent != NULL) {
|
||||||
|
c->u->sent(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if(hdr->type == TYPE_DATA) {
|
||||||
|
int send_ack = 1;
|
||||||
|
u16_t packet_seqno;
|
||||||
|
|
||||||
|
packet_seqno = hdr->seqno;
|
||||||
|
|
||||||
|
|
||||||
|
rimebuf_hdrreduce(sizeof(struct ruc_hdr));
|
||||||
|
if(c->u->recv != NULL) {
|
||||||
|
send_ack = c->u->recv(c, from_id, packet_seqno);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(send_ack) {
|
||||||
|
DEBUGF(4, "%d: ruc: Sending ACK to %d for %d\n", node_id, from_id,
|
||||||
|
packet_seqno);
|
||||||
|
rimebuf_clear();
|
||||||
|
rimebuf_hdrextend(sizeof(struct ruc_hdr));
|
||||||
|
hdr = rimebuf_hdrptr();
|
||||||
|
hdr->type = TYPE_ACK;
|
||||||
|
hdr->seqno = packet_seqno;
|
||||||
|
suc_send_uc(&c->c, from_id);
|
||||||
|
} else {
|
||||||
|
DEBUGF(4, "%d: Not sending ACK\n", node_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static const struct suc_ulayer ruc = {recv_from_suc, sent_by_suc};
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
ruc_setup(struct ruc_conn *c, u16_t channel,
|
||||||
|
const struct ruc_ulayer *u)
|
||||||
|
{
|
||||||
|
suc_setup(&c->c, channel, &ruc);
|
||||||
|
c->u = u;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
int
|
||||||
|
ruc_send(struct ruc_conn *c, node_id_t receiver_id)
|
||||||
|
{
|
||||||
|
if(rimebuf_hdrextend(sizeof(struct ruc_hdr))) {
|
||||||
|
struct ruc_hdr *hdr = rimebuf_hdrptr();
|
||||||
|
hdr->type = TYPE_DATA;
|
||||||
|
hdr->seqno = seqno;
|
||||||
|
return suc_send_stubborn(&c->c, receiver_id);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
64
core/net/rime/ruc.h
Normal file
64
core/net/rime/ruc.h
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2006, 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.
|
||||||
|
*
|
||||||
|
* $Id: ruc.h,v 1.1 2007/02/28 16:38:52 adamdunkels Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* A brief description of what this file is.
|
||||||
|
* \author
|
||||||
|
* Adam Dunkels <adam@sics.se>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __RUC_H__
|
||||||
|
#define __RUC_H__
|
||||||
|
|
||||||
|
#include "net/rime/suc.h"
|
||||||
|
|
||||||
|
struct ruc_conn;
|
||||||
|
|
||||||
|
struct ruc_ulayer {
|
||||||
|
int (* recv)(struct ruc_conn *c, node_id_t from, u8_t seqno);
|
||||||
|
void (* sent)(struct ruc_conn *c);
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ruc_conn {
|
||||||
|
struct suc_conn c;
|
||||||
|
const struct ruc_ulayer *u;
|
||||||
|
u8_t state;
|
||||||
|
};
|
||||||
|
|
||||||
|
void ruc_setup(struct ruc_conn *c, u16_t channel,
|
||||||
|
const struct ruc_ulayer *u);
|
||||||
|
|
||||||
|
int ruc_send(struct ruc_conn *c, node_id_t receiver_id);
|
||||||
|
|
||||||
|
#endif /* __RRUC_H__ */
|
107
core/net/rime/sabc.c
Normal file
107
core/net/rime/sabc.c
Normal file
|
@ -0,0 +1,107 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2006, 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.
|
||||||
|
*
|
||||||
|
* $Id: sabc.c,v 1.1 2007/02/28 16:38:52 adamdunkels Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* Implementation of the Rime module Stubborn Anonymous
|
||||||
|
* BroadCast (sabc)
|
||||||
|
* \author
|
||||||
|
* Adam Dunkels <adam@sics.se>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "net/rime/sabc.h"
|
||||||
|
#include "net/rime.h"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static void
|
||||||
|
recv_from_abc(struct abc_conn *abc)
|
||||||
|
{
|
||||||
|
register struct sabc_conn *c = (struct sabc_conn *)abc;
|
||||||
|
/* DEBUGF(3, "sabc: recv_from_abc from %d\n", from_id);*/
|
||||||
|
if(c->u->recv != NULL) {
|
||||||
|
c->u->recv(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static const struct abc_ulayer sabc = {recv_from_abc};
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
sabc_setup(struct sabc_conn *c, u16_t channel,
|
||||||
|
const struct sabc_ulayer *u)
|
||||||
|
{
|
||||||
|
abc_setup(&c->c, channel, &sabc);
|
||||||
|
c->u = u;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static void
|
||||||
|
send(void *ptr)
|
||||||
|
{
|
||||||
|
struct sabc_conn *c = ptr;
|
||||||
|
|
||||||
|
/* DEBUGF(3, "sabc: send()\n");*/
|
||||||
|
queuebuf_to_rimebuf(c->buf);
|
||||||
|
abc_send(&c->c);
|
||||||
|
ctimer_reset(&c->t);
|
||||||
|
if(c->u->sent != NULL) {
|
||||||
|
c->u->sent(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
sabc_set_timer(struct sabc_conn *c, clock_time_t t)
|
||||||
|
{
|
||||||
|
ctimer_set(&c->t, t, send, c);
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
int
|
||||||
|
sabc_send_stubborn(struct sabc_conn *c, clock_time_t t)
|
||||||
|
{
|
||||||
|
if(c->buf != NULL) {
|
||||||
|
queuebuf_free(c->buf);
|
||||||
|
}
|
||||||
|
c->buf = queuebuf_new_from_rimebuf();
|
||||||
|
if(c->buf == NULL) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
ctimer_set(&c->t, t, send, c);
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
sabc_cancel(struct sabc_conn *c)
|
||||||
|
{
|
||||||
|
ctimer_stop(&c->t);
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
149
core/net/rime/sabc.h
Normal file
149
core/net/rime/sabc.h
Normal file
|
@ -0,0 +1,149 @@
|
||||||
|
/**
|
||||||
|
* \addtogroup rime
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \defgroup rime-sabc Stubborn Anonymous best-effort local area BroadCast
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
* The sabc module provides stubborn anonymous best-effort local area
|
||||||
|
* broadcast. A message sent with the sabc module is repeated until
|
||||||
|
* either the mssage is canceled or a new message is sent. Messages
|
||||||
|
* sent with the sabc module are not identified with a sender ID.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2006, 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.
|
||||||
|
*
|
||||||
|
* $Id: sabc.h,v 1.1 2007/02/28 16:38:52 adamdunkels Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* Header file for the Rime module Stubborn Anonymous BroadCast (sabc)
|
||||||
|
* \author
|
||||||
|
* Adam Dunkels <adam@sics.se>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __SABC_H__
|
||||||
|
#define __SABC_H__
|
||||||
|
|
||||||
|
#include "net/rime/uc.h"
|
||||||
|
#include "net/rime/ctimer.h"
|
||||||
|
#include "net/rime/queuebuf.h"
|
||||||
|
|
||||||
|
struct sabc_conn;
|
||||||
|
|
||||||
|
struct sabc_ulayer {
|
||||||
|
void (* recv)(struct sabc_conn *c);
|
||||||
|
void (* sent)(struct sabc_conn *c);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A sabc connection. This is an opaque structure with no user-visible
|
||||||
|
* fields. The sabc_setup() function is used for setting up a sabc
|
||||||
|
* connection.
|
||||||
|
*/
|
||||||
|
struct sabc_conn {
|
||||||
|
struct abc_conn c;
|
||||||
|
struct ctimer t;
|
||||||
|
struct queuebuf *buf;
|
||||||
|
const struct sabc_ulayer *u;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Set up a sabc connection.
|
||||||
|
* \param c A pointer to a user-supplied struct sabc variable.
|
||||||
|
* \param channel The Rime channel on which messages should be sent.
|
||||||
|
* \param u Pointer to the upper layer functions that should be used
|
||||||
|
* for this connection.
|
||||||
|
*
|
||||||
|
* This function sets up a sabc connection on the
|
||||||
|
* specified channel. No checks are made if the channel is
|
||||||
|
* currently used by another connection.
|
||||||
|
*
|
||||||
|
* This function must be called before any other function
|
||||||
|
* that operates on the connection is called.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void sabc_setup(struct sabc_conn *c, u16_t channel,
|
||||||
|
const struct sabc_ulayer *u);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Send a stubborn message.
|
||||||
|
* \param c A sabc connection that must have been previously set up
|
||||||
|
* with sabc_setup()
|
||||||
|
* \param t The time between message retransmissions.
|
||||||
|
*
|
||||||
|
* This function sends a message from the Rime buffer. The
|
||||||
|
* message must have been previously constructed in the
|
||||||
|
* Rime buffer. When this function returns, the message
|
||||||
|
* has been copied into a queue buffer.
|
||||||
|
*
|
||||||
|
* If another message has previously been sent, the old
|
||||||
|
* message is canceled.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
int sabc_send_stubborn(struct sabc_conn *c, clock_time_t t);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Cancel the current stubborn message.
|
||||||
|
* \param c A sabc connection that must have been previously set up
|
||||||
|
* with sabc_setup()
|
||||||
|
*
|
||||||
|
* This function cancels a stubborn message that has
|
||||||
|
* previously been sent with the sabc_send_stubborn()
|
||||||
|
* function.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void sabc_cancel(struct sabc_conn *c);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Set the retransmission time of the current stubborn message.
|
||||||
|
* \param c A sabc connection that must have been previously set up
|
||||||
|
* with sabc_setup()
|
||||||
|
* \param t The new time between message retransmissions.
|
||||||
|
*
|
||||||
|
* This function sets the retransmission timer for the
|
||||||
|
* current stubborn message to a new value.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void sabc_set_timer(struct sabc_conn *c, clock_time_t t);
|
||||||
|
|
||||||
|
#endif /* __SABC_H__ */
|
||||||
|
|
||||||
|
/** @} */
|
106
core/net/rime/sibc.c
Normal file
106
core/net/rime/sibc.c
Normal file
|
@ -0,0 +1,106 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2006, 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.
|
||||||
|
*
|
||||||
|
* $Id: sibc.c,v 1.1 2007/02/28 16:38:52 adamdunkels Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* Implementation of the Rime module Stubborn Identified BroadCast (sibc)
|
||||||
|
* \author
|
||||||
|
* Adam Dunkels <adam@sics.se>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "net/rime/sibc.h"
|
||||||
|
#include "net/rime.h"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static void
|
||||||
|
recv_from_ibc(struct ibc_conn *ibc, node_id_t from_id)
|
||||||
|
{
|
||||||
|
register struct sibc_conn *c = (struct sibc_conn *)ibc;
|
||||||
|
/* DEBUGF(3, "sibc: recv_from_ibc from %d\n", from_id);*/
|
||||||
|
if(c->u->recv != NULL) {
|
||||||
|
c->u->recv(c, from_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static const struct ibc_ulayer sibc = {recv_from_ibc};
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
sibc_setup(struct sibc_conn *c, u16_t channel,
|
||||||
|
const struct sibc_ulayer *u)
|
||||||
|
{
|
||||||
|
ibc_setup(&c->c, channel, &sibc);
|
||||||
|
c->u = u;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static void
|
||||||
|
send(void *ptr)
|
||||||
|
{
|
||||||
|
struct sibc_conn *c = ptr;
|
||||||
|
|
||||||
|
/* DEBUGF(3, "sibc: send()\n");*/
|
||||||
|
queuebuf_to_rimebuf(c->buf);
|
||||||
|
ibc_send(&c->c);
|
||||||
|
ctimer_reset(&c->t);
|
||||||
|
if(c->u->sent != NULL) {
|
||||||
|
c->u->sent(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
sibc_set_timer(struct sibc_conn *c, clock_time_t t)
|
||||||
|
{
|
||||||
|
ctimer_set(&c->t, t, send, c);
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
int
|
||||||
|
sibc_send_stubborn(struct sibc_conn *c, clock_time_t t)
|
||||||
|
{
|
||||||
|
if(c->buf != NULL) {
|
||||||
|
queuebuf_free(c->buf);
|
||||||
|
}
|
||||||
|
c->buf = queuebuf_new_from_rimebuf();
|
||||||
|
if(c->buf == NULL) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
ctimer_set(&c->t, t, send, c);
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
sibc_cancel(struct sibc_conn *c)
|
||||||
|
{
|
||||||
|
ctimer_stop(&c->t);
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
70
core/net/rime/sibc.h
Normal file
70
core/net/rime/sibc.h
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2006, 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.
|
||||||
|
*
|
||||||
|
* $Id: sibc.h,v 1.1 2007/02/28 16:38:52 adamdunkels Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* Header file for the Rime module Stubborn Identified BroadCast (sibc)
|
||||||
|
* \author
|
||||||
|
* Adam Dunkels <adam@sics.se>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __SIBC_H__
|
||||||
|
#define __SIBC_H__
|
||||||
|
|
||||||
|
#include "net/rime/uc.h"
|
||||||
|
#include "net/rime/ctimer.h"
|
||||||
|
#include "net/rime/queuebuf.h"
|
||||||
|
|
||||||
|
struct sibc_conn;
|
||||||
|
|
||||||
|
struct sibc_ulayer {
|
||||||
|
void (* recv)(struct sibc_conn *c, node_id_t from);
|
||||||
|
void (* sent)(struct sibc_conn *c);
|
||||||
|
};
|
||||||
|
|
||||||
|
struct sibc_conn {
|
||||||
|
struct ibc_conn c;
|
||||||
|
struct ctimer t;
|
||||||
|
struct queuebuf *buf;
|
||||||
|
const struct sibc_ulayer *u;
|
||||||
|
};
|
||||||
|
|
||||||
|
void sibc_setup(struct sibc_conn *c, u16_t channel,
|
||||||
|
const struct sibc_ulayer *u);
|
||||||
|
|
||||||
|
int sibc_send_stubborn(struct sibc_conn *c, clock_time_t t);
|
||||||
|
void sibc_cancel(struct sibc_conn *c);
|
||||||
|
|
||||||
|
void sibc_set_timer(struct sibc_conn *c, clock_time_t t);
|
||||||
|
|
||||||
|
#endif /* __SIBC_H__ */
|
120
core/net/rime/suc.c
Normal file
120
core/net/rime/suc.c
Normal file
|
@ -0,0 +1,120 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2006, 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.
|
||||||
|
*
|
||||||
|
* $Id: suc.c,v 1.1 2007/02/28 16:38:52 adamdunkels Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* A brief description of what this file is.
|
||||||
|
* \author
|
||||||
|
* Adam Dunkels <adam@sics.se>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "net/rime/suc.h"
|
||||||
|
#include "net/rime.h"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static void
|
||||||
|
recv_from_uc(struct uc_conn *uc, node_id_t from_id)
|
||||||
|
{
|
||||||
|
register struct suc_conn *c = (struct suc_conn *)uc;
|
||||||
|
DEBUGF(3, "%d: suc: recv_from_uc from %d %p\n", node_id, from_id, c);
|
||||||
|
if(c->u->recv != NULL) {
|
||||||
|
c->u->recv(c, from_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static const struct uc_ulayer suc = {recv_from_uc};
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
suc_setup(struct suc_conn *c, u16_t channel,
|
||||||
|
const struct suc_ulayer *u)
|
||||||
|
{
|
||||||
|
uc_setup(&c->c, channel, &suc);
|
||||||
|
c->u = u;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static void
|
||||||
|
send(void *ptr)
|
||||||
|
{
|
||||||
|
struct suc_conn *c = ptr;
|
||||||
|
|
||||||
|
DEBUGF(3, "%d: suc: resend to %d\n", node_id, c->receiver_id);
|
||||||
|
queuebuf_to_rimebuf(c->buf);
|
||||||
|
uc_send(&c->c, c->receiver_id);
|
||||||
|
suc_set_timer(c, CLOCK_SECOND);
|
||||||
|
if(c->u->sent != NULL) {
|
||||||
|
c->u->sent(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
suc_set_timer(struct suc_conn *c, clock_time_t t)
|
||||||
|
{
|
||||||
|
ctimer_set(&c->t, t, send, c);
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
int
|
||||||
|
suc_send_stubborn(struct suc_conn *c, node_id_t receiver_id)
|
||||||
|
{
|
||||||
|
if(c->buf != NULL) {
|
||||||
|
queuebuf_free(c->buf);
|
||||||
|
}
|
||||||
|
c->buf = queuebuf_new_from_rimebuf();
|
||||||
|
if(c->buf == NULL) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
c->receiver_id = receiver_id;
|
||||||
|
ctimer_set(&c->t, CLOCK_SECOND, send, c);
|
||||||
|
|
||||||
|
DEBUGF(3, "%d: suc_send_stubborn to %d\n", node_id, c->receiver_id);
|
||||||
|
uc_send(&c->c, c->receiver_id);
|
||||||
|
if(c->u->sent != NULL) {
|
||||||
|
c->u->sent(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
int
|
||||||
|
suc_send_uc(struct suc_conn *c, node_id_t receiver_id)
|
||||||
|
{
|
||||||
|
return uc_send(&c->c, receiver_id);
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
suc_cancel(struct suc_conn *c)
|
||||||
|
{
|
||||||
|
ctimer_stop(&c->t);
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
73
core/net/rime/suc.h
Normal file
73
core/net/rime/suc.h
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2006, 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.
|
||||||
|
*
|
||||||
|
* $Id: suc.h,v 1.1 2007/02/28 16:38:52 adamdunkels Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* A brief description of what this file is.
|
||||||
|
* \author
|
||||||
|
* Adam Dunkels <adam@sics.se>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __SUC_H__
|
||||||
|
#define __SUC_H__
|
||||||
|
|
||||||
|
#include "net/rime/uc.h"
|
||||||
|
#include "net/rime/ctimer.h"
|
||||||
|
#include "net/rime/queuebuf.h"
|
||||||
|
|
||||||
|
struct suc_conn;
|
||||||
|
|
||||||
|
struct suc_ulayer {
|
||||||
|
void (* recv)(struct suc_conn *c, node_id_t from);
|
||||||
|
void (* sent)(struct suc_conn *c);
|
||||||
|
};
|
||||||
|
|
||||||
|
struct suc_conn {
|
||||||
|
struct uc_conn c;
|
||||||
|
struct ctimer t;
|
||||||
|
struct queuebuf *buf;
|
||||||
|
const struct suc_ulayer *u;
|
||||||
|
node_id_t receiver_id;
|
||||||
|
};
|
||||||
|
|
||||||
|
void suc_setup(struct suc_conn *c, u16_t channel,
|
||||||
|
const struct suc_ulayer *u);
|
||||||
|
|
||||||
|
int suc_send_stubborn(struct suc_conn *c, node_id_t receiver_id);
|
||||||
|
void suc_cancel(struct suc_conn *c);
|
||||||
|
|
||||||
|
int suc_send_uc(struct suc_conn *c, node_id_t receiver_id);
|
||||||
|
|
||||||
|
void suc_set_timer(struct suc_conn *c, clock_time_t t);
|
||||||
|
|
||||||
|
#endif /* __SUC_H__ */
|
84
core/net/rime/uc.c
Normal file
84
core/net/rime/uc.c
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2006, 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.
|
||||||
|
*
|
||||||
|
* $Id: uc.c,v 1.1 2007/02/28 16:38:52 adamdunkels Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* A brief description of what this file is.
|
||||||
|
* \author
|
||||||
|
* Adam Dunkels <adam@sics.se>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "net/rime.h"
|
||||||
|
#include "net/rime/uc.h"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
struct uc_hdr {
|
||||||
|
node_id_t receiver_id;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static void
|
||||||
|
recv_from_ibc(struct ibc_conn *ibc, node_id_t from_id)
|
||||||
|
{
|
||||||
|
struct uc_conn *c = (struct uc_conn *)ibc;
|
||||||
|
struct uc_hdr *hdr = rimebuf_dataptr();
|
||||||
|
DEBUGF(2, "%d: uc: recv_from_ibc, receiver id %d %p hdr %p\n",
|
||||||
|
node_id, hdr->receiver_id, c, hdr);
|
||||||
|
if(hdr->receiver_id == node_id) {
|
||||||
|
rimebuf_hdrreduce(sizeof(struct uc_hdr));
|
||||||
|
c->u->recv(c, from_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static const struct ibc_ulayer uc = {recv_from_ibc};
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
void
|
||||||
|
uc_setup(struct uc_conn *c, u16_t channel,
|
||||||
|
const struct uc_ulayer *u)
|
||||||
|
{
|
||||||
|
ibc_setup(&c->c, channel, &uc);
|
||||||
|
c->u = u;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
int
|
||||||
|
uc_send(struct uc_conn *c, node_id_t receiver_id)
|
||||||
|
{
|
||||||
|
DEBUGF(2, "%d: uc_send to %d\n", node_id, receiver_id);
|
||||||
|
if(rimebuf_hdrextend(sizeof(struct uc_hdr))) {
|
||||||
|
struct uc_hdr *hdr = rimebuf_hdrptr();
|
||||||
|
hdr->receiver_id = receiver_id;
|
||||||
|
return ibc_send(&c->c);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
61
core/net/rime/uc.h
Normal file
61
core/net/rime/uc.h
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2006, 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.
|
||||||
|
*
|
||||||
|
* $Id: uc.h,v 1.1 2007/02/28 16:38:52 adamdunkels Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* A brief description of what this file is.
|
||||||
|
* \author
|
||||||
|
* Adam Dunkels <adam@sics.se>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __UC_H__
|
||||||
|
#define __UC_H__
|
||||||
|
|
||||||
|
#include "net/rime/ibc.h"
|
||||||
|
|
||||||
|
struct uc_conn;
|
||||||
|
|
||||||
|
struct uc_ulayer {
|
||||||
|
void (* recv)(struct uc_conn *c, node_id_t from_id);
|
||||||
|
};
|
||||||
|
|
||||||
|
struct uc_conn {
|
||||||
|
struct ibc_conn c;
|
||||||
|
const struct uc_ulayer *u;
|
||||||
|
};
|
||||||
|
|
||||||
|
void uc_setup(struct uc_conn *c, u16_t channel,
|
||||||
|
const struct uc_ulayer *u);
|
||||||
|
int uc_send(struct uc_conn *c, node_id_t receiver_id);
|
||||||
|
|
||||||
|
#endif /* __UC_H__ */
|
Loading…
Reference in a new issue