This is an initial commit of an implementation of the Chameleon

architecture for the Rime stack for Contiki. The Chameleon
architecture separates the header processing from the Rime protocol
logic. Instead of having each protocol create its own part of the
packet header, protocols use packet attributes. Before sending a
packet, a special Chameleon header processing module creates a packet
header from the packet attributes. The same Chameleon module parses
incoming packets and creates packet attributes from the header.

The details are in our SenSys 2007 paper:

Adam Dunkels, Fredrik Osterlind, Zhitao He. An Adaptive Communication
Architecture for Wireless Sensor Networks. In Proceedings of the Fifth
ACM Conference on Networked Embedded Sensor Systems (SenSys 2007),
Sydney, Australia, November 2007.

http://www.sics.se/~adam/dunkels07adaptive.pdf

This is a rewrite of the code that was developed for the paper.
This commit is contained in:
adamdunkels 2008-02-25 02:14:34 +00:00
parent 39abed8672
commit 412facb831
29 changed files with 1357 additions and 159 deletions

View file

@ -28,7 +28,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: xmac.c,v 1.17 2008/02/24 22:10:30 adamdunkels Exp $ * $Id: xmac.c,v 1.18 2008/02/25 02:14:35 adamdunkels Exp $
*/ */
/** /**
@ -58,20 +58,10 @@
#endif #endif
#define WITH_TIMETABLE 0 #define WITH_TIMETABLE 0
#define WITH_CHANNEL_CHECK 0 /* Seems to work bad when enabled */ #define WITH_CHANNEL_CHECK 0 /* Seems to work badly when enabled */
#define WITH_TIMESYNCH 0 #define WITH_TIMESYNCH 0
#define WITH_RECEIVER 1
#define WITH_QUEUE 0 #define WITH_QUEUE 0
#if !CHAMELEON
#if WITH_RECEIVER
extern
#else
static
#endif
rimeaddr_t uc_receiver;
#endif /* !CHAMELEON */
struct xmac_hdr { struct xmac_hdr {
rimeaddr_t sender; rimeaddr_t sender;
rimeaddr_t receiver; rimeaddr_t receiver;
@ -306,11 +296,7 @@ send_packet(void)
rimebuf_hdralloc(sizeof(struct xmac_hdr)); rimebuf_hdralloc(sizeof(struct xmac_hdr));
hdr = rimebuf_hdrptr(); hdr = rimebuf_hdrptr();
rimeaddr_copy(&hdr->sender, &rimeaddr_node_addr); rimeaddr_copy(&hdr->sender, &rimeaddr_node_addr);
#if CHAMELEON rimeaddr_copy(&hdr->receiver, rimebuf_addr(RIMEBUF_ADDR_RECEIVER));
rimeaddr_copy(&hdr->receiver, packattr_aget(PACKATTR_RECEIVER));
#else
rimeaddr_copy(&hdr->receiver, &uc_receiver);
#endif
rimebuf_compact(); rimebuf_compact();
t0 = RTIMER_NOW(); t0 = RTIMER_NOW();
@ -336,11 +322,7 @@ send_packet(void)
t = RTIMER_NOW(); t = RTIMER_NOW();
rimeaddr_copy(&msg.sender, &rimeaddr_node_addr); rimeaddr_copy(&msg.sender, &rimeaddr_node_addr);
#if CHAMELEON rimeaddr_copy(&msg.receiver, rimebuf_addr(RIMEBUF_ADDR_RECEIVER));
rimeaddr_copy(&msg.receiver, packattr_aget(PACKATTR_RECEIVER));
#else
rimeaddr_copy(&msg.receiver, &uc_receiver);
#endif
#if WITH_TIMETABLE #if WITH_TIMETABLE
if(rimeaddr_cmp(&msg.receiver, &rimeaddr_null)) { if(rimeaddr_cmp(&msg.receiver, &rimeaddr_null)) {

View file

@ -1,7 +1,10 @@
CHAMELEON=chameleon.c channel.c chameleon-raw.c chameleon-bitopt.c
CONTIKI_SOURCEFILES += rimebuf.c queuebuf.c rimeaddr.c ctimer.c rime.c timesynch.c \ CONTIKI_SOURCEFILES += rimebuf.c queuebuf.c rimeaddr.c ctimer.c rime.c timesynch.c \
rimestats.c ibc.c uc.c suc.c ruc.c sibc.c sabc.c abc.c nf.c \ rimestats.c ibc.c uc.c suc.c ruc.c sibc.c sabc.c abc.c nf.c \
mh.c rmh.c rucb.c polite.c ipolite.c neighbor-discovery.c \ mh.c rmh.c rucb.c polite.c ipolite.c neighbor-discovery.c \
mesh.c route.c route-discovery.c \ mesh.c route.c route-discovery.c \
collect.c neighbor.c \ collect.c neighbor.c \
trickle.c \ trickle.c \
rudolph0.c rudolph1.c rudolph2.c rudolph0.c rudolph1.c rudolph2.c \
rmesh.c meshconn.c $(CHAMELEON)

View file

@ -36,7 +36,7 @@
* *
* Author: Adam Dunkels <adam@sics.se> * Author: Adam Dunkels <adam@sics.se>
* *
* $Id: abc.c,v 1.17 2008/02/24 22:05:27 adamdunkels Exp $ * $Id: abc.c,v 1.18 2008/02/25 02:14:34 adamdunkels Exp $
*/ */
/** /**
@ -49,11 +49,6 @@
#include "contiki-net.h" #include "contiki-net.h"
#include "net/rime.h" #include "net/rime.h"
struct abc_hdr {
uint16_t channel;
};
LIST(channels);
#define DEBUG 0 #define DEBUG 0
#if DEBUG #if DEBUG
@ -63,59 +58,43 @@ LIST(channels);
#define PRINTF(...) #define PRINTF(...)
#endif #endif
static const struct rimebuf_attrlist attributes[] =
{ ABC_ATTRIBUTES RIMEBUF_ATTR_LAST };
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void
abc_open(struct abc_conn *c, uint16_t channel, abc_open(struct abc_conn *c, uint16_t channelno,
const struct abc_callbacks *callbacks) const struct abc_callbacks *callbacks)
{ {
c->channel = channel; channel_open(&c->channel, channelno);
c->u = callbacks; c->u = callbacks;
channel_set_attributes(channelno, attributes);
list_add(channels, c);
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void
abc_close(struct abc_conn *c) abc_close(struct abc_conn *c)
{ {
list_remove(channels, c); channel_close(&c->channel);
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
int int
abc_send(struct abc_conn *c) abc_send(struct abc_conn *c)
{ {
if(rimebuf_hdralloc(sizeof(struct abc_hdr))) { PRINTF("%d.%d: abc: abc_send on channel %d\n",
struct abc_hdr *hdr = rimebuf_hdrptr(); rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1],
c->channel.channelno);
PRINTF("%d.%d: abc: abc_send on channel %d\n", return chameleon_output(&c->channel);
rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1],
c->channel);
hdr->channel = c->channel;
rime_output();
return 1;
}
return 0;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void
abc_input_packet(void) abc_input(struct channel *channel)
{ {
struct abc_hdr *hdr; struct abc_conn *c = (struct abc_conn *)channel;
struct abc_conn *c; PRINTF("%d.%d: abc: abc_input_packet on channel %d\n",
rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1],
channel->channelno);
hdr = rimebuf_dataptr(); c->u->recv(c);
if(rimebuf_hdrreduce(sizeof(struct abc_hdr))) {
PRINTF("%d.%d: abc: abc_input_packet on channel %d\n",
rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1],
hdr->channel);
for(c = list_head(channels); c != NULL; c = c->next) {
if(c->channel == hdr->channel) {
c->u->recv(c);
}
}
}
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/

View file

@ -46,7 +46,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: abc.h,v 1.13 2008/02/24 22:05:27 adamdunkels Exp $ * $Id: abc.h,v 1.14 2008/02/25 02:14:34 adamdunkels Exp $
*/ */
/** /**
* \file * \file
@ -59,9 +59,12 @@
#define __ABC_H__ #define __ABC_H__
#include "net/rime/rimebuf.h" #include "net/rime/rimebuf.h"
#include "net/rime/channel.h"
struct abc_conn; struct abc_conn;
#define ABC_ATTRIBUTES
/** /**
* \brief Callback structure for abc * \brief Callback structure for abc
* *
@ -71,17 +74,8 @@ struct abc_callbacks {
void (* recv)(struct abc_conn *ptr); void (* recv)(struct abc_conn *ptr);
}; };
#ifdef CHAMELEON
#include "net/chameleon/chameleon.h"
#endif /* CHAMELEON */
struct abc_conn { struct abc_conn {
#ifdef CHAMELEON struct channel channel;
struct chameleon_channel channel;
#else /* CHAMELEON */
struct abc_conn *next;
uint16_t channel;
#endif /* CHAMELEON */
const struct abc_callbacks *u; const struct abc_callbacks *u;
}; };
@ -139,7 +133,8 @@ int abc_send(struct abc_conn *c);
* directly. * directly.
* *
*/ */
void abc_input_packet(void); void abc_input(struct channel *channel);
#endif /* __ABC_H__ */ #endif /* __ABC_H__ */
/** @} */ /** @} */

View file

@ -0,0 +1,342 @@
/*
* 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: chameleon-bitopt.c,v 1.1 2008/02/25 02:14:34 adamdunkels Exp $
*/
/**
* \file
* A Chameleon module that produces bit-optimized headers
* \author
* Adam Dunkels <adam@sics.se>
*/
#include "net/rime/chameleon.h"
#include "net/rime.h"
#include <string.h>
struct bitopt_hdr {
uint16_t channel;
};
static const uint8_t bitmask[9] = { 0x00, 0x80, 0xc0, 0xe0, 0xf0,
0xf8, 0xfc, 0xfe, 0xff };
#define DEBUG 0
#if DEBUG
#include <stdio.h>
#define PRINTF(...) printf(__VA_ARGS__)
#else
#define PRINTF(...)
#endif
/*---------------------------------------------------------------------------*/
uint8_t inline
get_bits_in_byte(uint8_t *from, int bitpos, int vallen)
{
uint16_t shifted_val;
shifted_val = (from[0] << 8) | from[1];
/* PRINTF("get_bits_in_byte: from[0] 0x%02x from[1] 0x%02x shifted_val 0x%04x, return 0x%02x vallen %d\n",
from[0], from[1], shifted_val,
(((shifted_val << bitpos) >> 8) & bitmask[vallen]) >> (8 - vallen),
vallen
);*/
return (((shifted_val << bitpos) >> 8) & bitmask[vallen]) >> (8 - vallen);
}
/*---------------------------------------------------------------------------*/
void
get_bits(uint8_t *to, uint8_t *from, int bitpos, int vallen)
{
int i, bits;
if(vallen < 8) {
*to = get_bits_in_byte(from, bitpos, vallen);
} else {
if(bitpos == 0) {
for(i = 0; i < vallen / 8; ++i) {
/* PRINTF("get_bits i %d val 0x%02x\n",
i, from[i]);*/
to[i] = from[i];
}
bits = vallen & 7;
if(bits) {
to[i] = get_bits_in_byte(&from[i], 0, bits);
}
} else {
for(i = 0; i < vallen / 8; ++i) {
/* PRINTF("get_bits i %d val 0x%02x bitpos %d\n",
i, from[i], bitpos);*/
to[i] = get_bits_in_byte(&from[i], bitpos, 8);
}
bits = vallen & 7;
if(bits) {
to[i] = get_bits_in_byte(&from[i], bitpos, bits);
}
}
}
}
/*---------------------------------------------------------------------------*/
static int
header_size(const struct rimebuf_attrlist *a)
{
int size, len;
/* Compute the total size of the final header by summing the size of
all attributes that are used on this channel. */
size = 0;
for(; a->type != RIMEBUF_ATTR_NONE; ++a) {
/* PRINTF("chameleon header_size: header type %s (%d) len %d\n",
rimebuf_attr_strings[a->type],
a->type,
a->len);*/
len = a->len;
/* if(len < 8) {
len = 8;
}*/
size += len;
}
return size;
}
/*---------------------------------------------------------------------------*/
void inline
set_bits_in_byte(uint8_t *target, int bitpos, uint8_t val, int vallen)
{
unsigned short shifted_val;
shifted_val = val << (8 - bitpos + 8 - vallen);
/* printf("set_bits_in_byte before target[0] 0x%02x target[1] 0x%02x shifted_val 0x%04x val 0x%02x vallen %d\n",
target[0], target[1], shifted_val, val, vallen);*/
target[0] |= shifted_val >> 8;
target[1] |= shifted_val & 0xff;
}
/*---------------------------------------------------------------------------*/
void
set_bits(uint8_t *ptr, int bitpos, uint8_t *val, int vallen)
{
int i, bits;
/* PRINTF("set_bits %p bitpos %d, val %p len %d\n",
ptr, bitpos, val, vallen);*/
if(vallen < 8) {
set_bits_in_byte(ptr, bitpos, *val /*>> (8 - vallen)*/, vallen);
} else {
if(bitpos == 0) {
for(i = 0; i < vallen / 8; ++i) {
/* PRINTF("set_bits i %d val %d\n",
i, val[i]);*/
ptr[i] = val[i];
}
bits = vallen & 7;
if(bits) {
set_bits_in_byte(&ptr[i], 0, val[i] >> (8 - bits), bits);
}
} else {
for(i = 0; i < vallen / 8; ++i) {
/* PRINTF("set_bits i %d val %d\n",
i, val[i]);*/
set_bits_in_byte(&ptr[i], bitpos, val[i], 8);
}
bits = vallen & 7;
if(bits) {
set_bits_in_byte(&ptr[i], 0, val[i] >> (8 - bits + bitpos), bits);
}
}
}
}
/*---------------------------------------------------------------------------*/
#if 0
static void
printbin(int n, int digits)
{
int i;
char output[128];
for(i = 0; i < digits; ++i) {
output[digits - i - 1] = (n & 1) + '0';
n >>= 1;
}
output[i] = 0;
printf(output);
}
static void
printhdr(uint8_t *hdr, int len)
{
int i, j;
j = 0;
for(i = 0; i < len; ++i) {
printbin(hdr[i], 8);
printf(", ");
++j;
if(j == 10) {
printf("\n");
j = 0;
}
}
if(j != 0) {
printf("\n");
}
}
#endif
/*---------------------------------------------------------------------------*/
static int
pack_header(struct channel *c)
{
const struct rimebuf_attrlist *a;
int hdrbytesize;
int byteptr, bitptr, len;
uint8_t *hdrptr;
struct bitopt_hdr *hdr;
/* Compute the total size of the final header by summing the size of
all attributes that are used on this channel. */
hdrbytesize = c->hdrsize / 8 + ((c->hdrsize & 7) == 0? 0: 1);
rimebuf_hdralloc(hdrbytesize);
hdrptr = rimebuf_hdrptr();
memset(hdrptr, 0, hdrbytesize);
byteptr = bitptr = 0;
for(a = c->attrlist; a->type != RIMEBUF_ATTR_NONE; ++a) {
PRINTF("%d.%d: pack_header type %s, len %d, bitptr %d, ",
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
rimebuf_attr_strings[a->type], a->len, bitptr);
/* len = (a->len & 0xf8) + ((a->len & 7) ? 8: 0);*/
len = a->len;
byteptr = bitptr / 8;
if(a->type == RIMEBUF_ADDR_SENDER ||
a->type == RIMEBUF_ADDR_RECEIVER ||
a->type == RIMEBUF_ADDR_ESENDER ||
a->type == RIMEBUF_ADDR_ERECEIVER) {
set_bits(&hdrptr[byteptr], bitptr & 7,
(uint8_t *)rimebuf_addr(a->type), len);
PRINTF("address %d.%d\n",
/* rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],*/
((uint8_t *)rimebuf_addr(a->type))[0],
((uint8_t *)rimebuf_addr(a->type))[1]);
} else {
rimebuf_attr_t val;
val = rimebuf_attr(a->type);
set_bits(&hdrptr[byteptr], bitptr & 7,
(uint8_t *)&val, len);
PRINTF("value %d\n",
/*rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],*/
val);
}
/* printhdr(hdrptr, hdrbytesize);*/
bitptr += len;
}
/* printhdr(hdrptr, hdrbytesize);*/
rimebuf_hdralloc(sizeof(struct bitopt_hdr));
hdr = (struct bitopt_hdr *)rimebuf_hdrptr();
hdr->channel = c->channelno;
return 1; /* Send out packet */
}
/*---------------------------------------------------------------------------*/
static struct channel *
unpack_header(void)
{
const struct rimebuf_attrlist *a;
int byteptr, bitptr, len;
int hdrbytesize;
uint8_t *hdrptr;
struct bitopt_hdr *hdr;
struct channel *c;
/* The packet has a header that tells us what channel the packet is
for. */
hdr = (struct bitopt_hdr *)rimebuf_dataptr();
rimebuf_hdrreduce(sizeof(struct bitopt_hdr));
c = channel_lookup(hdr->channel);
if(c == NULL) {
PRINTF("chameleon-bitopt: input: channel %d not found\n", hdr->channel);
return NULL;
}
rimebuf_attr_clear();
hdrptr = rimebuf_dataptr();
hdrbytesize = c->hdrsize / 8 + ((c->hdrsize & 7) == 0? 0: 1);
rimebuf_hdrreduce(hdrbytesize);
byteptr = bitptr = 0;
for(a = c->attrlist; a->type != RIMEBUF_ATTR_NONE; ++a) {
PRINTF("%d.%d: unpack_header type %s, len %d, bitptr %d\n",
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
rimebuf_attr_strings[a->type], a->len, bitptr);
/* len = (a->len & 0xf8) + ((a->len & 7) ? 8: 0);*/
len = a->len;
byteptr = bitptr / 8;
if(a->type == RIMEBUF_ADDR_SENDER ||
a->type == RIMEBUF_ADDR_RECEIVER ||
a->type == RIMEBUF_ADDR_ESENDER ||
a->type == RIMEBUF_ADDR_ERECEIVER) {
rimeaddr_t addr;
get_bits((uint8_t *)&addr, &hdrptr[byteptr], bitptr & 7, len);
PRINTF("%d.%d: unpack_header type %s, addr %d.%d\n",
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
rimebuf_attr_strings[a->type],
addr.u8[0], addr.u8[1]);
rimebuf_set_addr(a->type, &addr);
} else {
rimebuf_attr_t val = 0;
get_bits((uint8_t *)&val, &hdrptr[byteptr], bitptr & 7, len);
rimebuf_set_attr(a->type, val);
PRINTF("%d.%d: unpack_header type %s, val %d\n",
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
rimebuf_attr_strings[a->type],
val);
}
/* byteptr += len / 8;*/
bitptr += len;
}
return c;
}
/*---------------------------------------------------------------------------*/
const struct chameleon_module chameleon_bitopt = {
unpack_header,
pack_header,
header_size,
NULL
};
/*---------------------------------------------------------------------------*/

View file

@ -0,0 +1,46 @@
/*
* 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: chameleon-bitopt.h,v 1.1 2008/02/25 02:14:34 adamdunkels Exp $
*/
/**
* \file
* A Chameleon module that produces bit-optimized headers
* \author
* Adam Dunkels <adam@sics.se>
*/
#ifndef __CHAMELEON_BITOPT_H__
#define __CHAMELEON_BITOPT_H__
extern const struct chameleon_module chameleon_bitopt;
#endif /* __CHAMELEON_BITOPT_H__ */

View file

@ -0,0 +1,186 @@
/*
* 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: chameleon-raw.c,v 1.1 2008/02/25 02:14:34 adamdunkels Exp $
*/
/**
* \file
* A Chameleon module that produces non-optimized headers
* \author
* Adam Dunkels <adam@sics.se>
*/
#include <string.h>
#include "net/rime/chameleon.h"
#include "net/rime.h"
#define DEBUG 0
#if DEBUG
#include <stdio.h>
#define PRINTF(...) printf(__VA_ARGS__)
#else
#define PRINTF(...)
#endif
struct raw_hdr {
uint16_t channel;
};
/*---------------------------------------------------------------------------*/
static struct channel *
input(void)
{
const struct rimebuf_attrlist *a;
int byteptr, bitptr, len;
uint8_t *hdrptr;
struct raw_hdr *hdr;
struct channel *c;
/* The packet has a header that tells us what channel the packet is
for. */
hdr = (struct raw_hdr *)rimebuf_dataptr();
rimebuf_hdrreduce(sizeof(struct raw_hdr));
c = channel_lookup(hdr->channel);
if(c == NULL) {
PRINTF("chameleon-raw: input: channel %d not found\n", hdr->channel);
return NULL;
}
rimebuf_attr_clear();
hdrptr = rimebuf_dataptr();
rimebuf_hdrreduce(c->hdrsize);
byteptr = bitptr = 0;
for(a = c->attrlist; a->type != RIMEBUF_ATTR_NONE; ++a) {
PRINTF("%d.%d: unpack_header type %s, len %d\n",
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
rimebuf_attr_strings[a->type], a->len);
len = (a->len & 0xf8) + ((a->len & 7) ? 8: 0);
if(a->type == RIMEBUF_ADDR_SENDER ||
a->type == RIMEBUF_ADDR_RECEIVER ||
a->type == RIMEBUF_ADDR_ESENDER ||
a->type == RIMEBUF_ADDR_ERECEIVER) {
const rimeaddr_t addr;
memcpy((uint8_t *)&addr, &hdrptr[byteptr], len / 8);
PRINTF("%d.%d: unpack_header type %s, addr %d.%d\n",
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
rimebuf_attr_strings[a->type],
addr.u8[0], addr.u8[1]);
rimebuf_set_addr(a->type, &addr);
} else {
rimebuf_attr_t val = 0;
memcpy((uint8_t *)&val, &hdrptr[byteptr], len / 8);
rimebuf_set_attr(a->type, val);
PRINTF("%d.%d: unpack_header type %s, val %d\n",
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
rimebuf_attr_strings[a->type],
val);
}
byteptr += len / 8;
}
return c;
}
/*---------------------------------------------------------------------------*/
static int
output(struct channel *c)
{
const struct rimebuf_attrlist *a;
int byteptr, len;
uint8_t *hdrptr;
struct raw_hdr *hdr;
/* Compute the total size of the final header by summing the size of
all attributes that are used on this channel. */
rimebuf_hdralloc(c->hdrsize);
hdrptr = rimebuf_hdrptr();
byteptr = 0;
for(a = c->attrlist; a->type != RIMEBUF_ATTR_NONE; ++a) {
PRINTF("%d.%d: pack_header type %s, len %d\n",
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
rimebuf_attr_strings[a->type], a->len);
len = (a->len & 0xf8) + ((a->len & 7) ? 8: 0);
if(a->type == RIMEBUF_ADDR_SENDER ||
a->type == RIMEBUF_ADDR_RECEIVER ||
a->type == RIMEBUF_ADDR_ESENDER ||
a->type == RIMEBUF_ADDR_ERECEIVER) {
const rimeaddr_t *rimeaddr;
/* memcpy(&hdrptr[byteptr], (uint8_t *)rimebuf_attr_aget(a->type), len / 8);*/
rimeaddr = rimebuf_addr(a->type);
hdrptr[byteptr] = rimeaddr->u8[0];
hdrptr[byteptr + 1] = rimeaddr->u8[1];
PRINTF("%d.%d: address %d.%d\n",
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
((uint8_t *)rimebuf_addr(a->type))[0],
((uint8_t *)rimebuf_addr(a->type))[1]);
} else {
rimebuf_attr_t val;
val = rimebuf_attr(a->type);
hdrptr[byteptr] = rimebuf_attr(a->type);
PRINTF("%d.%d: value %d\n",
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
val);
}
byteptr += len / 8;
}
rimebuf_hdralloc(sizeof(struct raw_hdr));
hdr = (struct raw_hdr *)rimebuf_hdrptr();
hdr->channel = c->channelno;
return 1; /* Send out packet */
}
/*---------------------------------------------------------------------------*/
static int
hdrsize(const struct rimebuf_attrlist *a)
{
int size, len;
/* Compute the total size of the final header by summing the size of
all attributes that are used on this channel. */
size = 0;
for(; a->type != RIMEBUF_ATTR_NONE; ++a) {
/* PRINTF("chameleon header_size: header type %s (%d) len %d\n",
rimebuf_attr_strings[a->type],
a->type,
a->len);*/
len = a->len;
if(len < 8) {
len = 8;
}
size += len;
}
return size / 8;
}
/*---------------------------------------------------------------------------*/
const struct chameleon_module chameleon_raw = { input, output, hdrsize, NULL };

View file

@ -0,0 +1,46 @@
/*
* 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: chameleon-raw.h,v 1.1 2008/02/25 02:14:34 adamdunkels Exp $
*/
/**
* \file
* A Chameleon module that produces non-optimized headers
* \author
* Adam Dunkels <adam@sics.se>
*/
#ifndef __CHAMELEON_RAW_H__
#define __CHAMELEON_RAW_H__
extern const struct chameleon_module chameleon_raw;
#endif /* __CHAMELEON_RAW_H__ */

147
core/net/rime/chameleon.c Normal file
View file

@ -0,0 +1,147 @@
/*
* 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: chameleon.c,v 1.1 2008/02/25 02:14:34 adamdunkels Exp $
*/
/**
* \file
* Chameleon, Rime's header processing module
* \author
* Adam Dunkels <adam@sics.se>
*/
#include "net/rime/chameleon.h"
#include "net/rime/channel.h"
#include "net/rime.h"
#include "lib/list.h"
#include <stdio.h>
static const struct chameleon_module *header_module;
#define DEBUG 0
#if DEBUG
#include <stdio.h>
#define PRINTF(...) printf(__VA_ARGS__)
#else
#define PRINTF(...)
#endif
/*---------------------------------------------------------------------------*/
void
chameleon_init(const struct chameleon_module *m)
{
header_module = m;
channel_init();
}
/*---------------------------------------------------------------------------*/
static void
printbin(int n, int digits)
{
int i;
char output[128];
for(i = 0; i < digits; ++i) {
output[digits - i - 1] = (n & 1) + '0';
n >>= 1;
}
output[i] = 0;
printf(output);
}
static void
printhdr(uint8_t *hdr, int len)
{
int i, j;
j = 0;
for(i = 0; i < len; ++i) {
printbin(hdr[i], 8);
printf(" (0x%0x), ", hdr[i]);
++j;
if(j == 10) {
printf("\n");
j = 0;
}
}
if(j != 0) {
printf("\n");
}
}
/*---------------------------------------------------------------------------*/
void
chameleon_input(void)
{
struct channel *c;
PRINTF("%d.%d: chameleon_input\n",
rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1]);
printhdr(rimebuf_dataptr(), rimebuf_datalen());
c = header_module->input();
if(c != NULL) {
PRINTF("%d.%d: chameleon_input channel %d\n",
rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1],
c->channelno);
abc_input(c);
} else {
PRINTF("%d.%d: chameleon_input channel not found for incoming packet\n",
rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1]);
}
}
/*---------------------------------------------------------------------------*/
int
chameleon_output(struct channel *c)
{
int ret;
PRINTF("%d.%d: chameleon_output channel %d\n",
rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1],
c->channelno);
ret = header_module->output(c);
rimebuf_set_attr(RIMEBUF_ATTR_CHANNEL, c->channelno);
printhdr(rimebuf_hdrptr(), rimebuf_hdrlen());
if(ret) {
rime_output();
return 1;
}
return 0;
}
/*---------------------------------------------------------------------------*/
int
chameleon_hdrsize(const struct rimebuf_attrlist attrlist[])
{
return header_module->hdrsize(attrlist);
}
/*---------------------------------------------------------------------------*/

62
core/net/rime/chameleon.h Normal file
View file

@ -0,0 +1,62 @@
/*
* 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: chameleon.h,v 1.1 2008/02/25 02:14:34 adamdunkels Exp $
*/
/**
* \file
* Header file for Chameleon, Rime's header processing module
* \author
* Adam Dunkels <adam@sics.se>
*/
#ifndef __CHAMELEON_H__
#define __CHAMELEON_H__
#include "net/rime/channel.h"
#include "net/rime/chameleon-bitopt.h"
#include "net/rime/chameleon-raw.h"
struct chameleon_module {
struct channel *(* input)(void);
int (* output)(struct channel *);
int (* hdrsize)(const struct rimebuf_attrlist *);
void (* init)(void);
};
void chameleon_init(const struct chameleon_module *header_processing_module);
int chameleon_hdrsize(const struct rimebuf_attrlist attrlist[]);
void chameleon_input(void);
int chameleon_output(struct channel *c);
#endif /* __CHAMELEON_H__ */

90
core/net/rime/channel.c Normal file
View file

@ -0,0 +1,90 @@
/*
* 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: channel.c,v 1.1 2008/02/25 02:14:34 adamdunkels Exp $
*/
/**
* \file
* Rime's channel abstraction
* \author
* Adam Dunkels <adam@sics.se>
*/
#include "net/rime/chameleon.h"
#include "net/rime.h"
#include "lib/list.h"
LIST(channel_list);
/*---------------------------------------------------------------------------*/
void
channel_init(void)
{
list_init(channel_list);
}
/*---------------------------------------------------------------------------*/
void
channel_set_attributes(uint16_t channelno,
const struct rimebuf_attrlist attrlist[])
{
struct channel *c;
c = channel_lookup(channelno);
if(c != NULL) {
c->attrlist = attrlist;
c->hdrsize = chameleon_hdrsize(attrlist);
}
}
/*---------------------------------------------------------------------------*/
void
channel_open(struct channel *c, uint16_t channelno)
{
c->channelno = channelno;
list_add(channel_list, c);
}
/*---------------------------------------------------------------------------*/
void
channel_close(struct channel *c)
{
list_remove(channel_list, c);
}
/*---------------------------------------------------------------------------*/
struct channel *
channel_lookup(uint16_t channelno)
{
struct channel *c;
for(c = list_head(channel_list); c != NULL; c = c->next) {
if(c->channelno == channelno) {
return c;
}
}
return NULL;
}
/*---------------------------------------------------------------------------*/

65
core/net/rime/channel.h Normal file
View file

@ -0,0 +1,65 @@
/*
* 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: channel.h,v 1.1 2008/02/25 02:14:34 adamdunkels Exp $
*/
/**
* \file
* Header file for Rime's channel abstraction
* \author
* Adam Dunkels <adam@sics.se>
*/
#ifndef __CHANNEL_H__
#define __CHANNEL_H__
struct channel;
#include "contiki-conf.h"
#include "net/rime/rimebuf.h"
#include "net/rime/chameleon.h"
struct channel {
struct channel *next;
uint16_t channelno;
const struct rimebuf_attrlist *attrlist;
uint8_t hdrsize;
};
struct channel *channel_lookup(uint16_t channelno);
void channel_set_attributes(uint16_t channelno,
const struct rimebuf_attrlist attrlist[]);
void channel_open(struct channel *c, uint16_t channelno);
void channel_close(struct channel *c);
void channel_init(void);
#endif /* __CHANNEL_H__ */

View file

@ -33,7 +33,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: ibc.c,v 1.13 2008/02/24 22:05:27 adamdunkels Exp $ * $Id: ibc.c,v 1.14 2008/02/25 02:14:34 adamdunkels Exp $
*/ */
/** /**
@ -46,9 +46,10 @@
#include "contiki-net.h" #include "contiki-net.h"
#include <string.h> #include <string.h>
struct ibc_hdr { static const struct rimebuf_attrlist attributes[] =
rimeaddr_t sender; {
}; IBC_ATTRIBUTES RIMEBUF_ATTR_LAST
};
#define DEBUG 0 #define DEBUG 0
#if DEBUG #if DEBUG
@ -64,11 +65,9 @@ recv_from_abc(struct abc_conn *bc)
{ {
rimeaddr_t sender; rimeaddr_t sender;
struct ibc_conn *c = (struct ibc_conn *)bc; struct ibc_conn *c = (struct ibc_conn *)bc;
struct ibc_hdr *hdr = rimebuf_dataptr();
rimeaddr_copy(&sender, &hdr->sender); rimeaddr_copy(&sender, rimebuf_addr(RIMEBUF_ADDR_SENDER));
rimebuf_hdrreduce(sizeof(struct ibc_hdr));
PRINTF("%d.%d: ibc: from %d.%d\n", PRINTF("%d.%d: ibc: from %d.%d\n",
rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1], rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1],
sender.u8[0], sender.u8[1]); sender.u8[0], sender.u8[1]);
@ -83,6 +82,7 @@ ibc_open(struct ibc_conn *c, uint16_t channel,
{ {
abc_open(&c->c, channel, &ibc); abc_open(&c->c, channel, &ibc);
c->u = u; c->u = u;
channel_set_attributes(channel, attributes);
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void
@ -96,12 +96,8 @@ ibc_send(struct ibc_conn *c)
{ {
PRINTF("%d.%d: ibc_send\n", PRINTF("%d.%d: ibc_send\n",
rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1]); rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1]);
if(rimebuf_hdralloc(sizeof(struct ibc_hdr))) { rimebuf_set_addr(RIMEBUF_ADDR_SENDER, &rimeaddr_node_addr);
struct ibc_hdr *hdr = rimebuf_hdrptr(); return abc_send(&c->c);
rimeaddr_copy(&hdr->sender, &rimeaddr_node_addr);
return abc_send(&c->c);
}
return 0;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/** @} */ /** @} */

View file

@ -46,7 +46,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: ibc.h,v 1.10 2008/02/24 22:05:27 adamdunkels Exp $ * $Id: ibc.h,v 1.11 2008/02/25 02:14:34 adamdunkels Exp $
*/ */
/** /**
@ -64,6 +64,9 @@
struct ibc_conn; struct ibc_conn;
#define IBC_ATTRIBUTES { RIMEBUF_ADDR_SENDER, RIMEBUF_ADDRSIZE }, \
ABC_ATTRIBUTES
/** /**
* \brief Callback structure for ibc * \brief Callback structure for ibc
* *

View file

@ -33,7 +33,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: neighbor-discovery.c,v 1.4 2008/02/24 22:05:27 adamdunkels Exp $ * $Id: neighbor-discovery.c,v 1.5 2008/02/25 02:14:34 adamdunkels Exp $
*/ */
/** /**
@ -71,7 +71,7 @@ struct adv_msg {
#define MAX_HOPLIM 10 #define MAX_HOPLIM 10
#define MAX_INTERVAL CLOCK_SECOND * 30 #define MAX_INTERVAL CLOCK_SECOND * 60
#define MIN_INTERVAL CLOCK_SECOND * 10 #define MIN_INTERVAL CLOCK_SECOND * 10
#define NEW_VAL_INTERVAL CLOCK_SECOND * 2 #define NEW_VAL_INTERVAL CLOCK_SECOND * 2

View file

@ -33,7 +33,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: queuebuf.c,v 1.11 2008/02/24 22:05:27 adamdunkels Exp $ * $Id: queuebuf.c,v 1.12 2008/02/25 02:14:34 adamdunkels Exp $
*/ */
/** /**
@ -62,6 +62,8 @@
struct queuebuf { struct queuebuf {
uint16_t len; uint16_t len;
uint8_t data[RIMEBUF_SIZE + RIMEBUF_HDR_SIZE]; uint8_t data[RIMEBUF_SIZE + RIMEBUF_HDR_SIZE];
struct rimebuf_attr attrs[RIMEBUF_NUM_ATTRS];
struct rimebuf_addr addrs[RIMEBUF_NUM_ADDRS];
}; };
struct queuebuf_ref { struct queuebuf_ref {
@ -139,6 +141,7 @@ queuebuf_new_from_rimebuf(void)
#endif /* NETSIM */ #endif /* NETSIM */
#endif /* QUEUEBUF_STATS */ #endif /* QUEUEBUF_STATS */
buf->len = rimebuf_copyto(buf->data); buf->len = rimebuf_copyto(buf->data);
rimebuf_attr_copyto(buf->attrs, buf->addrs);
} else { } else {
PRINTF("queuebuf_new_from_rimebuf: could not allocate a queuebuf\n"); PRINTF("queuebuf_new_from_rimebuf: could not allocate a queuebuf\n");
} }
@ -179,6 +182,7 @@ queuebuf_to_rimebuf(struct queuebuf *b)
if(memb_inmemb(&bufmem, b)) { if(memb_inmemb(&bufmem, b)) {
rimebuf_copyfrom(b->data, b->len); rimebuf_copyfrom(b->data, b->len);
rimebuf_attr_copyfrom(b->attrs, b->addrs);
} else if(memb_inmemb(&refbufmem, b)) { } else if(memb_inmemb(&refbufmem, b)) {
r = (struct queuebuf_ref *)b; r = (struct queuebuf_ref *)b;
rimebuf_clear(); rimebuf_clear();

View file

@ -33,7 +33,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: rime.c,v 1.15 2008/01/14 09:42:00 adamdunkels Exp $ * $Id: rime.c,v 1.16 2008/02/25 02:14:35 adamdunkels Exp $
*/ */
/** /**
@ -44,6 +44,7 @@
*/ */
#include "net/rime.h" #include "net/rime.h"
#include "net/rime/chameleon.h"
#include "net/rime/neighbor.h" #include "net/rime/neighbor.h"
#include "net/rime/route.h" #include "net/rime/route.h"
#include "net/mac/mac.h" #include "net/mac/mac.h"
@ -80,7 +81,7 @@ input(const struct mac_driver *r)
} }
} }
RIMESTATS_ADD(rx); RIMESTATS_ADD(rx);
abc_input_packet(); chameleon_input();
} }
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -93,6 +94,8 @@ rime_init(const struct mac_driver *m)
neighbor_init(); neighbor_init();
rime_mac = m; rime_mac = m;
rime_mac->set_receive_function(input); rime_mac->set_receive_function(input);
chameleon_init(&chameleon_bitopt);
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void
@ -108,7 +111,6 @@ rime_output(void)
s->output_callback(); s->output_callback();
} }
} }
if(rime_mac) { if(rime_mac) {
rime_mac->send(); rime_mac->send();
} }

View file

@ -33,7 +33,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: rimebuf.c,v 1.11 2008/02/24 22:05:27 adamdunkels Exp $ * $Id: rimebuf.c,v 1.12 2008/02/25 02:14:35 adamdunkels Exp $
*/ */
/** /**
@ -49,6 +49,34 @@
#include "net/rime/rimebuf.h" #include "net/rime/rimebuf.h"
#include "net/rime.h" #include "net/rime.h"
struct rimebuf_attr rimebuf_attrs[RIMEBUF_NUM_ATTRS];
struct rimebuf_addr rimebuf_addrs[RIMEBUF_NUM_ADDRS];
const char *rimebuf_attr_strings[] =
{
"RIMEBUF_ATTR_NONE",
"RIMEBUF_ATTR_CHANNEL",
"RIMEBUF_ATTR_PACKET_ID",
"RIMEBUF_ATTR_PACKET_TYPE",
"RIMEBUF_ATTR_EPACKET_ID",
"RIMEBUF_ATTR_EPACKET_TYPE",
"RIMEBUF_ATTR_HOPS",
"RIMEBUF_ATTR_TTL",
"RIMEBUF_ATTR_REXMIT",
"RIMEBUF_ATTR_MAX_REXMIT",
"RIMEBUF_ATTR_NUM_REXMIT",
"RIMEBUF_ATTR_LINK_QUALITY",
"RIMEBUF_ATTR_RELIABLE",
"RIMEBUF_ATTR_ERELIABLE",
"RIMEBUF_ADDR_SENDER",
"RIMEBUF_ADDR_RECEIVER",
"RIMEBUF_ADDR_ESENDER",
"RIMEBUF_ADDR_ERECEIVER",
"RIMEBUF_ATTR_MAX",
};
static uint16_t buflen, bufptr; static uint16_t buflen, bufptr;
static uint8_t hdrptr; static uint8_t hdrptr;
@ -224,4 +252,66 @@ rimebuf_totlen(void)
return rimebuf_hdrlen() + rimebuf_datalen(); return rimebuf_hdrlen() + rimebuf_datalen();
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void
rimebuf_attr_clear(void)
{
int i;
for(i = 0; i < RIMEBUF_NUM_ATTRS; ++i) {
rimebuf_attrs[i].type = RIMEBUF_ATTR_NONE;
}
for(i = 0; i < RIMEBUF_NUM_ADDRS; ++i) {
rimebuf_addrs[i].type = RIMEBUF_ATTR_NONE;
rimebuf_addrs[i].addr = rimeaddr_null;
}
}
/*---------------------------------------------------------------------------*/
void
rimebuf_attr_copyto(struct rimebuf_attr *attrs,
struct rimebuf_addr *addrs)
{
memcpy(attrs, rimebuf_attrs, sizeof(rimebuf_attrs));
memcpy(addrs, rimebuf_addrs, sizeof(rimebuf_addrs));
}
/*---------------------------------------------------------------------------*/
void
rimebuf_attr_copyfrom(struct rimebuf_attr *attrs,
struct rimebuf_addr *addrs)
{
memcpy(rimebuf_attrs, attrs, sizeof(rimebuf_attrs));
memcpy(rimebuf_addrs, addrs, sizeof(rimebuf_addrs));
}
/*---------------------------------------------------------------------------*/
#if !RIMEBUF_CONF_ATTRS_INLINE
int
rimebuf_set_attr(uint8_t type, const rimebuf_attr_t val)
{
rimebuf_attrs[type].type = type;
rimebuf_attrs[type].val = val;
return 1;
}
/*---------------------------------------------------------------------------*/
rimebuf_attr_t
rimebuf_attr(uint8_t type)
{
return rimebuf_attrs[type].val;
}
/*---------------------------------------------------------------------------*/
int
rimebuf_set_addr(uint8_t type, const rimeaddr_t *addr)
{
rimebuf_addrs[type].type = type;
rimeaddr_copy(&rimebuf_addrs[type].addr, addr);
return 1;
}
/*---------------------------------------------------------------------------*/
const rimeaddr_t *
rimebuf_addr(uint8_t type)
{
return &rimebuf_addrs[type].addr;
}
/*---------------------------------------------------------------------------*/
#endif /* RIMEBUF_CONF_ATTRS_INLINE */
/** @} */ /** @} */

View file

@ -40,7 +40,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: rimebuf.h,v 1.12 2008/02/24 22:05:27 adamdunkels Exp $ * $Id: rimebuf.h,v 1.13 2008/02/25 02:14:35 adamdunkels Exp $
*/ */
/** /**
@ -54,6 +54,7 @@
#define __RIMEBUF_H__ #define __RIMEBUF_H__
#include "contiki-conf.h" #include "contiki-conf.h"
#include "net/rime/rimeaddr.h"
/** /**
* \brief The size of the rimebuf, in bytes * \brief The size of the rimebuf, in bytes
@ -298,6 +299,136 @@ int rimebuf_hdralloc(int size);
*/ */
int rimebuf_hdrreduce(int size); int rimebuf_hdrreduce(int size);
/* Packet attributes stuff below: */
typedef uint16_t rimebuf_attr_t;
struct rimebuf_attr {
uint8_t type;
rimebuf_attr_t val;
};
struct rimebuf_addr {
uint8_t type;
rimeaddr_t addr;
};
extern const char *rimebuf_attr_strings[];
#define RIMEBUF_ATTR_PACKET_TYPE_DATA 0
#define RIMEBUF_ATTR_PACKET_TYPE_ACK 1
enum {
RIMEBUF_ATTR_NONE,
RIMEBUF_ATTR_CHANNEL,
RIMEBUF_ATTR_PACKET_ID,
RIMEBUF_ATTR_PACKET_TYPE,
RIMEBUF_ATTR_EPACKET_ID,
RIMEBUF_ATTR_EPACKET_TYPE,
RIMEBUF_ATTR_HOPS,
RIMEBUF_ATTR_TTL,
RIMEBUF_ATTR_REXMIT,
RIMEBUF_ATTR_MAX_REXMIT,
RIMEBUF_ATTR_NUM_REXMIT,
RIMEBUF_ATTR_LINK_QUALITY,
RIMEBUF_ATTR_RELIABLE,
RIMEBUF_ATTR_ERELIABLE,
RIMEBUF_ADDR_SENDER,
RIMEBUF_ADDR_RECEIVER,
RIMEBUF_ADDR_ESENDER,
RIMEBUF_ADDR_ERECEIVER,
RIMEBUF_ATTR_MAX,
};
#define RIMEBUF_NUM_ADDRS 4
#define RIMEBUF_NUM_ATTRS (RIMEBUF_ATTR_MAX - RIMEBUF_NUM_ADDRS)
#if RIMEBUF_CONF_ATTRS_INLINE
extern struct rimebuf_attr rimebuf_attrs[];
extern struct rimebuf_addr rimebuf_addrs[];
static int rimebuf_set_attr(uint8_t type, const rimebuf_attr_t val);
static rimebuf_attr_t rimebuf_attr(uint8_t type);
static int rimebuf_set_addr(uint8_t type, const rimeaddr_t *addr);
static const rimeaddr_t *rimebuf_addr(uint8_t type);
static inline int
rimebuf_set_attr(uint8_t type, const rimebuf_attr_t val)
{
rimebuf_attrs[type].type = type;
rimebuf_attrs[type].val = val;
return 1;
}
static inline rimebuf_attr_t
rimebuf_attr(uint8_t type)
{
return rimebuf_attrs[type].val;
}
static inline int
rimebuf_set_addr(uint8_t type, const rimeaddr_t *addr)
{
rimebuf_addrs[type].type = type;
rimeaddr_copy(&rimebuf_addrs[type].addr, addr);
return 1;
}
static inline const rimeaddr_t *
rimebuf_addr(uint8_t type)
{
return &rimebuf_addrs[type].addr;
}
#else /* RIMEBUF_CONF_ATTRS_INLINE */
int rimebuf_set_attr(uint8_t type, const rimebuf_attr_t val);
rimebuf_attr_t rimebuf_attr(uint8_t type);
int rimebuf_set_addr(uint8_t type, const rimeaddr_t *addr);
const rimeaddr_t *rimebuf_addr(uint8_t type);
#endif /* RIMEBUF_CONF_ATTRS_INLINE */
void rimebuf_attr_clear(void);
int rimebuf_attr_isset(uint8_t type);
void rimebuf_attr_copyto(struct rimebuf_attr *attrs,
struct rimebuf_addr *addrs);
void rimebuf_attr_copyfrom(struct rimebuf_attr *attrs,
struct rimebuf_addr *addrs);
#define RIMEBUF_ATTRIBUTES(...) { __VA_ARGS__ RIMEBUF_ATTR_LAST }
#define RIMEBUF_ATTR_LAST { RIMEBUF_ATTR_NONE, 0 }
#define RIMEBUF_ATTR_BIT 1
#define RIMEBUF_ATTR_BYTE 8
#define RIMEBUF_ADDRSIZE (sizeof(rimeaddr_t) * RIMEBUF_ATTR_BYTE)
struct rimebuf_attrlist {
uint8_t type;
uint8_t len;
};
/* XXX The definitions below will be placed the corresponding .h files: */
#define RMH_ATTRIBUTES { RIMEBUF_ADDR_ESENDER, RIMEBUF_ADDRSIZE }, \
{ RIMEBUF_ADDR_ERECEIVER, RIMEBUF_ADDRSIZE }, \
{ RIMEBUF_ATTR_TTL, RIMEBUF_ATTR_BIT * 5 }, \
{ RIMEBUF_ATTR_MAX_REXMIT, RIMEBUF_ATTR_BIT * 5 }, \
RUC_ATTRIBUTES
#define MH_ATTRIBUTES { RIMEBUF_ADDR_ESENDER, RIMEBUF_ADDRSIZE }, \
{ RIMEBUF_ADDR_ERECEIVER, RIMEBUF_ADDRSIZE }, \
{ RIMEBUF_ATTR_TTL, RIMEBUF_ATTR_BIT * 5 }, \
UC_ATTRIBUTES
#define POLITE_ATTRIBUTES ABC_ATTRIBUTES
#define IPOLITE_ATTRIBUTES IBC_ATTRIBUTES
#define NF_ATTRIBUTES { RIMEBUF_ADDR_ESENDER, RIMEBUF_ADDRSIZE }, \
{ RIMEBUF_ATTR_HOPS, RIMEBUF_ATTR_BIT * 5 }, \
{ RIMEBUF_ATTR_EPACKET_ID, RIMEBUF_ATTR_BIT * 4 }, \
IPOLITE_ATTRIBUTES
#endif /* __RIMEBUF_H__ */ #endif /* __RIMEBUF_H__ */
/** @} */ /** @} */
/** @} */ /** @} */

View file

@ -34,7 +34,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: ruc.c,v 1.18 2008/02/24 22:05:27 adamdunkels Exp $ * $Id: ruc.c,v 1.19 2008/02/25 02:14:35 adamdunkels Exp $
*/ */
/** /**
@ -49,15 +49,18 @@
#include "net/rime.h" #include "net/rime.h"
#include <string.h> #include <string.h>
#define RUC_PACKET_ID_BITS 2
#define REXMIT_TIME CLOCK_SECOND #define REXMIT_TIME CLOCK_SECOND
#define TYPE_DATA 0 #define TYPE_DATA 0
#define TYPE_ACK 1 #define TYPE_ACK 1
struct ruc_hdr { static const struct rimebuf_attrlist attributes[] =
uint8_t type; {
uint8_t seqno; RUC_ATTRIBUTES
}; RIMEBUF_ATTR_LAST
};
#define DEBUG 0 #define DEBUG 0
#if DEBUG #if DEBUG
@ -77,7 +80,7 @@ sent_by_suc(struct suc_conn *suc)
RIMESTATS_ADD(rexmit); RIMESTATS_ADD(rexmit);
PRINTF("%d.%d: ruc: packet %u resent %u\n", PRINTF("%d.%d: ruc: packet %u resent %u\n",
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1], rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
((struct ruc_hdr *) rimebuf_dataptr())->seqno, c->rxmit); rimebuf_attr(RIMEBUF_ATTR_PACKET_ID), c->rxmit);
} }
c->rxmit++; c->rxmit++;
@ -102,20 +105,22 @@ static void
recv_from_suc(struct suc_conn *suc, rimeaddr_t *from) recv_from_suc(struct suc_conn *suc, rimeaddr_t *from)
{ {
struct ruc_conn *c = (struct ruc_conn *)suc; struct ruc_conn *c = (struct ruc_conn *)suc;
struct ruc_hdr *hdr = rimebuf_dataptr(); /* struct ruc_hdr *hdr = rimebuf_dataptr();*/
PRINTF("%d.%d: ruc: recv_from_suc from %d.%d type %d seqno %d\n", PRINTF("%d.%d: ruc: recv_from_suc from %d.%d type %d seqno %d\n",
rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1], rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1],
from->u8[0], from->u8[1], from->u8[0], from->u8[1],
hdr->type, hdr->seqno); rimebuf_attr(RIMEBUF_ATTR_PACKET_TYPE),
rimebuf_attr(RIMEBUF_ATTR_PACKET_ID));
if(hdr->type == TYPE_ACK) {
if(hdr->seqno == c->sndnxt) { if(rimebuf_attr(RIMEBUF_ATTR_PACKET_TYPE) ==
RIMEBUF_ATTR_PACKET_TYPE_ACK) {
if(rimebuf_attr(RIMEBUF_ATTR_PACKET_ID) == c->sndnxt) {
RIMESTATS_ADD(ackrx); RIMESTATS_ADD(ackrx);
PRINTF("%d.%d: ruc: ACKed %d\n", PRINTF("%d.%d: ruc: ACKed %d\n",
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1], rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
hdr->seqno); rimebuf_attr(RIMEBUF_ATTR_PACKET_ID));
++c->sndnxt; c->sndnxt = (c->sndnxt + 1) % (1 << RUC_PACKET_ID_BITS);
suc_cancel(&c->c); suc_cancel(&c->c);
if(c->u->sent != NULL) { if(c->u->sent != NULL) {
c->u->sent(c, suc_receiver(&c->c), c->rxmit); c->u->sent(c, suc_receiver(&c->c), c->rxmit);
@ -123,11 +128,12 @@ recv_from_suc(struct suc_conn *suc, rimeaddr_t *from)
} else { } else {
PRINTF("%d.%d: ruc: received bad ACK %d for %d\n", PRINTF("%d.%d: ruc: received bad ACK %d for %d\n",
rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1], rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1],
hdr->seqno, rimebuf_attr(RIMEBUF_ATTR_PACKET_ID),
c->sndnxt); c->sndnxt);
RIMESTATS_ADD(badackrx); RIMESTATS_ADD(badackrx);
} }
} else if(hdr->type == TYPE_DATA) { } else if(rimebuf_attr(RIMEBUF_ATTR_PACKET_TYPE) ==
RIMEBUF_ATTR_PACKET_TYPE_DATA) {
/* int send_ack = 1;*/ /* int send_ack = 1;*/
uint16_t packet_seqno; uint16_t packet_seqno;
struct queuebuf *q; struct queuebuf *q;
@ -136,11 +142,11 @@ recv_from_suc(struct suc_conn *suc, rimeaddr_t *from)
PRINTF("%d.%d: ruc: got packet %d\n", PRINTF("%d.%d: ruc: got packet %d\n",
rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1], rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1],
hdr->seqno); rimebuf_attr(RIMEBUF_ATTR_PACKET_ID));
packet_seqno = hdr->seqno; packet_seqno = rimebuf_attr(RIMEBUF_ATTR_PACKET_ID);
rimebuf_hdrreduce(sizeof(struct ruc_hdr)); /* rimebuf_hdrreduce(sizeof(struct ruc_hdr));*/
q = queuebuf_new_from_rimebuf(); q = queuebuf_new_from_rimebuf();
@ -149,10 +155,12 @@ recv_from_suc(struct suc_conn *suc, rimeaddr_t *from)
from->u8[0], from->u8[1], from->u8[0], from->u8[1],
packet_seqno); packet_seqno);
rimebuf_clear(); rimebuf_clear();
rimebuf_hdralloc(sizeof(struct ruc_hdr)); /* rimebuf_hdralloc(sizeof(struct ruc_hdr));
hdr = rimebuf_hdrptr(); hdr = rimebuf_hdrptr();
hdr->type = TYPE_ACK; hdr->type = TYPE_ACK;
hdr->seqno = packet_seqno; hdr->seqno = packet_seqno;*/
rimebuf_set_attr(RIMEBUF_ATTR_PACKET_TYPE, RIMEBUF_ATTR_PACKET_TYPE_ACK);
rimebuf_set_attr(RIMEBUF_ATTR_PACKET_ID, packet_seqno);
suc_send(&c->c, from); suc_send(&c->c, from);
RIMESTATS_ADD(acktx); RIMESTATS_ADD(acktx);
@ -172,6 +180,7 @@ ruc_open(struct ruc_conn *c, uint16_t channel,
const struct ruc_callbacks *u) const struct ruc_callbacks *u)
{ {
suc_open(&c->c, channel, &ruc); suc_open(&c->c, channel, &ruc);
channel_set_attributes(channel, attributes);
c->u = u; c->u = u;
c->rxmit = 0; c->rxmit = 0;
c->sndnxt = 0; c->sndnxt = 0;
@ -186,19 +195,16 @@ ruc_close(struct ruc_conn *c)
int int
ruc_send(struct ruc_conn *c, rimeaddr_t *receiver, uint8_t max_retransmissions) ruc_send(struct ruc_conn *c, rimeaddr_t *receiver, uint8_t max_retransmissions)
{ {
if(rimebuf_hdralloc(sizeof(struct ruc_hdr))) { rimebuf_set_attr(RIMEBUF_ATTR_RELIABLE, 1);
struct ruc_hdr *hdr = rimebuf_hdrptr(); rimebuf_set_attr(RIMEBUF_ATTR_PACKET_TYPE, RIMEBUF_ATTR_PACKET_TYPE_DATA);
hdr->type = TYPE_DATA; rimebuf_set_attr(RIMEBUF_ATTR_PACKET_ID, c->sndnxt);
hdr->seqno = c->sndnxt; c->max_rxmit = max_retransmissions;
c->max_rxmit = max_retransmissions; c->rxmit = 0;
c->rxmit = 0; RIMESTATS_ADD(reliabletx);
RIMESTATS_ADD(reliabletx); PRINTF("%d.%d: ruc: sending packet %d\n",
PRINTF("%d.%d: ruc: sending packet %d\n", rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1],
rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1], c->sndnxt);
c->sndnxt); return suc_send_stubborn(&c->c, receiver, REXMIT_TIME);
return suc_send_stubborn(&c->c, receiver, REXMIT_TIME);
}
return 0;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/** @} */ /** @} */

View file

@ -45,7 +45,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: ruc.h,v 1.12 2008/02/24 22:05:27 adamdunkels Exp $ * $Id: ruc.h,v 1.13 2008/02/25 02:14:35 adamdunkels Exp $
*/ */
/** /**
@ -62,6 +62,9 @@
struct ruc_conn; struct ruc_conn;
#define RUC_ATTRIBUTES { RIMEBUF_ATTR_PACKET_TYPE, RIMEBUF_ATTR_BIT }, \
{ RIMEBUF_ATTR_PACKET_ID, RIMEBUF_ATTR_BIT * 2 }, \
SUC_ATTRIBUTES
struct ruc_callbacks { struct ruc_callbacks {
void (* recv)(struct ruc_conn *c, rimeaddr_t *from, uint8_t seqno); void (* recv)(struct ruc_conn *c, rimeaddr_t *from, uint8_t seqno);
void (* sent)(struct ruc_conn *c, rimeaddr_t *to, uint8_t retransmissions); void (* sent)(struct ruc_conn *c, rimeaddr_t *to, uint8_t retransmissions);

View file

@ -28,7 +28,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: rucb.c,v 1.6 2008/02/24 22:05:27 adamdunkels Exp $ * $Id: rucb.c,v 1.7 2008/02/25 02:14:35 adamdunkels Exp $
*/ */
/** /**
@ -52,6 +52,7 @@
#define PRINTF(...) #define PRINTF(...)
#endif #endif
#include "sys/timetable.h"
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static int static int
read_data(struct rucb_conn *c) read_data(struct rucb_conn *c)
@ -76,6 +77,10 @@ acked(struct ruc_conn *ruc, rimeaddr_t *to, uint8_t retransmissions)
c->chunk++; c->chunk++;
if(read_data(c) > 0) { if(read_data(c) > 0) {
ruc_send(&c->c, &c->receiver, MAX_TRANSMISSIONS); ruc_send(&c->c, &c->receiver, MAX_TRANSMISSIONS);
/* {
extern struct timetable cc2420_timetable;
timetable_print(&cc2420_timetable);
}*/
} }
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/

View file

@ -33,7 +33,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: rudolph0.c,v 1.8 2008/02/24 22:05:27 adamdunkels Exp $ * $Id: rudolph0.c,v 1.9 2008/02/25 02:14:35 adamdunkels Exp $
*/ */
/** /**
@ -216,6 +216,13 @@ rudolph0_send(struct rudolph0_conn *c, clock_time_t send_interval)
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void
rudolph0_force_restart(struct rudolph0_conn *c)
{
c->current.h.chunk = 0;
send_nack(c);
}
/*---------------------------------------------------------------------------*/
void
rudolph0_stop(struct rudolph0_conn *c) rudolph0_stop(struct rudolph0_conn *c)
{ {
sabc_cancel(&c->c); sabc_cancel(&c->c);

View file

@ -47,7 +47,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: rudolph0.h,v 1.8 2008/02/24 22:05:27 adamdunkels Exp $ * $Id: rudolph0.h,v 1.9 2008/02/25 02:14:35 adamdunkels Exp $
*/ */
/** /**
@ -111,6 +111,9 @@ void rudolph0_close(struct rudolph0_conn *c);
void rudolph0_send(struct rudolph0_conn *c, clock_time_t interval); void rudolph0_send(struct rudolph0_conn *c, clock_time_t interval);
void rudolph0_stop(struct rudolph0_conn *c); void rudolph0_stop(struct rudolph0_conn *c);
/* Force the sender to restart sending the file from the start. */
void rudolph0_force_restart(struct rudolph0_conn *c);
void rudolph0_set_version(struct rudolph0_conn *c, int version); void rudolph0_set_version(struct rudolph0_conn *c, int version);
int rudolph0_version(struct rudolph0_conn *c); int rudolph0_version(struct rudolph0_conn *c);

View file

@ -45,7 +45,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: suc.h,v 1.10 2008/02/24 22:05:27 adamdunkels Exp $ * $Id: suc.h,v 1.11 2008/02/25 02:14:35 adamdunkels Exp $
*/ */
/** /**
@ -64,6 +64,8 @@
struct suc_conn; struct suc_conn;
#define SUC_ATTRIBUTES UC_ATTRIBUTES
struct suc_callbacks { struct suc_callbacks {
void (* recv)(struct suc_conn *c, rimeaddr_t *from); void (* recv)(struct suc_conn *c, rimeaddr_t *from);
void (* sent)(struct suc_conn *c); void (* sent)(struct suc_conn *c);

View file

@ -33,7 +33,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: trickle.c,v 1.7 2008/02/24 22:05:27 adamdunkels Exp $ * $Id: trickle.c,v 1.8 2008/02/25 02:14:35 adamdunkels Exp $
*/ */
/** /**
@ -45,6 +45,10 @@
#include "net/rime/trickle.h" #include "net/rime/trickle.h"
#if NETSIM
#include "ether.h"
#endif
#define INTERVAL_MIN 1 #define INTERVAL_MIN 1
#define INTERVAL_MAX 4 #define INTERVAL_MAX 4
@ -92,6 +96,9 @@ recv(struct nf_conn *nf, rimeaddr_t *from,
c->interval_scaling = 0; c->interval_scaling = 0;
send(c); send(c);
} else { /* hdr->seqno > c->seqno */ } else { /* hdr->seqno > c->seqno */
#if NETSIM
/* ether_set_line(from->u8[0], from->u8[1]);*/
#endif /* NETSIM */
c->seqno = seqno; c->seqno = seqno;
/* Store the incoming data in the queuebuf */ /* Store the incoming data in the queuebuf */
if(c->q != NULL) { if(c->q != NULL) {

View file

@ -34,7 +34,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: uc.c,v 1.13 2008/02/24 22:05:27 adamdunkels Exp $ * $Id: uc.c,v 1.14 2008/02/25 02:14:35 adamdunkels Exp $
*/ */
/** /**
@ -48,13 +48,11 @@
#include "net/rime/uc.h" #include "net/rime/uc.h"
#include <string.h> #include <string.h>
/* XXX This is a hack: MAC protocols may use this address as the static const struct rimebuf_attrlist attributes[] =
receiver address of packets. */ {
rimeaddr_t uc_receiver; UC_ATTRIBUTES
RIMEBUF_ATTR_LAST
struct uc_hdr { };
rimeaddr_t receiver;
};
#define DEBUG 0 #define DEBUG 0
#if DEBUG #if DEBUG
@ -69,12 +67,12 @@ static void
recv_from_ibc(struct ibc_conn *ibc, rimeaddr_t *from) recv_from_ibc(struct ibc_conn *ibc, rimeaddr_t *from)
{ {
struct uc_conn *c = (struct uc_conn *)ibc; struct uc_conn *c = (struct uc_conn *)ibc;
struct uc_hdr *hdr = rimebuf_dataptr();
PRINTF("%d.%d: uc: recv_from_ibc, receiver %d.%d\n", PRINTF("%d.%d: uc: recv_from_ibc, receiver %d.%d\n",
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1], rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
hdr->receiver.u8[0], hdr->receiver.u8[1]); rimebuf_addr(RIMEBUF_ADDR_RECEIVER)->u8[0],
if(rimeaddr_cmp(&hdr->receiver, &rimeaddr_node_addr)) { rimebuf_addr(RIMEBUF_ADDR_RECEIVER)->u8[1]);
rimebuf_hdrreduce(sizeof(struct uc_hdr)); if(rimeaddr_cmp(rimebuf_addr(RIMEBUF_ADDR_RECEIVER), &rimeaddr_node_addr)) {
c->u->recv(c, from); c->u->recv(c, from);
} }
} }
@ -87,6 +85,7 @@ uc_open(struct uc_conn *c, uint16_t channel,
{ {
ibc_open(&c->c, channel, &uc); ibc_open(&c->c, channel, &uc);
c->u = u; c->u = u;
channel_set_attributes(channel, attributes);
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void
@ -101,16 +100,8 @@ uc_send(struct uc_conn *c, const rimeaddr_t *receiver)
PRINTF("%d.%d: uc_send to %d.%d\n", PRINTF("%d.%d: uc_send to %d.%d\n",
rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1], rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1],
receiver->u8[0], receiver->u8[1]); receiver->u8[0], receiver->u8[1]);
if(rimebuf_hdralloc(sizeof(struct uc_hdr))) { rimebuf_set_addr(RIMEBUF_ADDR_RECEIVER, receiver);
int ret; return ibc_send(&c->c);
struct uc_hdr *hdr = rimebuf_hdrptr();
rimeaddr_copy(&hdr->receiver, receiver);
rimeaddr_copy(&uc_receiver, receiver);
ret = ibc_send(&c->c);
rimeaddr_copy(&uc_receiver, &rimeaddr_null);
return ret;
}
return 0;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/** @} */ /** @} */

View file

@ -45,7 +45,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: uc.h,v 1.7 2008/02/05 20:18:58 adamdunkels Exp $ * $Id: uc.h,v 1.8 2008/02/25 02:14:35 adamdunkels Exp $
*/ */
/** /**
@ -62,6 +62,9 @@
struct uc_conn; struct uc_conn;
#define UC_ATTRIBUTES { RIMEBUF_ADDR_RECEIVER, RIMEBUF_ADDRSIZE }, \
IBC_ATTRIBUTES
struct uc_callbacks { struct uc_callbacks {
void (* recv)(struct uc_conn *c, rimeaddr_t *from); void (* recv)(struct uc_conn *c, rimeaddr_t *from);
}; };

View file

@ -1,9 +1,11 @@
/* -*- C -*- */ /* -*- C -*- */
/* @(#)$Id: contiki-conf.h,v 1.24 2008/02/24 21:11:35 adamdunkels Exp $ */ /* @(#)$Id: contiki-conf.h,v 1.25 2008/02/25 02:14:34 adamdunkels Exp $ */
#ifndef CONTIKI_CONF_H #ifndef CONTIKI_CONF_H
#define CONTIKI_CONF_H #define CONTIKI_CONF_H
#define RIMEBUF_CONF_ATTRS_INLINE 1
#define SHELL_VARS_CONF_RAM_BEGIN 0x1100 #define SHELL_VARS_CONF_RAM_BEGIN 0x1100
#define SHELL_VARS_CONF_RAM_END 0x2000 #define SHELL_VARS_CONF_RAM_END 0x2000