Merge branch 'master' of ssh://contiki.git.sourceforge.net/gitroot/contiki/contiki

This commit is contained in:
Fredrik Osterlind 2011-12-12 16:47:29 +01:00
commit 43e5906129
120 changed files with 2878 additions and 8021 deletions

View file

@ -72,7 +72,7 @@ db_get_result_message(db_result_t code)
case DB_NAME_ERROR:
return "Invalid name";
case DB_RELATIONAL_ERROR:
return "Relational algebra error";
return "Semantic error";
case DB_TYPE_ERROR:
return "Type error";
case DB_IMPLEMENTATION_ERROR:

View file

@ -98,7 +98,7 @@ aql_execute(db_handle_t *handle, aql_adt_t *adt)
switch(optype) {
case AQL_TYPE_CREATE_ATTRIBUTE:
attr = &adt->attributes[0];
if(relation_attribute_add(rel, DB_MEMORY, attr->name, attr->domain,
if(relation_attribute_add(rel, DB_STORAGE, attr->name, attr->domain,
attr->element_size) != NULL) {
result = DB_OK;
}

View file

@ -123,9 +123,9 @@ int
uint32_2_bytes(uint8_t *bytes, uint32_t var)
{
int i = 0;
if (0xFF000000 & var) bytes[i++] = var>>24;
if (0xFF0000 & var) bytes[i++] = var>>16;
if (0xFF00 & var) bytes[i++] = var>>8;
if (0xFF000000 & var) bytes[i++] = (0xFF & var>>24);
if (0xFFFF0000 & var) bytes[i++] = (0xFF & var>>16);
if (0xFFFFFF00 & var) bytes[i++] = (0xFF & var>>8);
bytes[i++] = 0xFF & var;
return i;

View file

@ -136,10 +136,10 @@ serialize_int_option(int number, int current_number, uint8_t *buffer, uint32_t v
uint8_t *option = &buffer[i];
if (0xFF000000 & value) buffer[++i] = (uint8_t) (value>>24);
if (0x00FF0000 & value) buffer[++i] = (uint8_t) (value>>16);
if (0x0000FF00 & value) buffer[++i] = (uint8_t) (value>>8);
if (0x000000FF & value) buffer[++i] = (uint8_t) value;
if (0xFF000000 & value) buffer[++i] = (uint8_t) (0xFF & value>>24);
if (0xFFFF0000 & value) buffer[++i] = (uint8_t) (0xFF & value>>16);
if (0xFFFFFF00 & value) buffer[++i] = (uint8_t) (0xFF & value>>8);
if ( value) buffer[++i] = (uint8_t) (0xFF & value);
i += set_option_header(number - current_number, i-start_i, option);

View file

@ -148,6 +148,7 @@ handle_incoming_data(void)
}
else
{
block_size = REST_MAX_CHUNK_SIZE;
new_offset = 0;
}
@ -304,7 +305,7 @@ coap_set_rest_status(void *packet, unsigned int code)
/*- Server part ---------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------------*/
/* The discover resource is automatically included for CoAP. */
RESOURCE(well_known_core, METHOD_GET, ".well-known/core", "");
RESOURCE(well_known_core, METHOD_GET, ".well-known/core", "ct=40");
void
well_known_core_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
{

View file

@ -137,10 +137,10 @@ serialize_int_option(int number, int current_number, uint8_t *buffer, uint32_t v
uint8_t *option = &buffer[i];
if (0xFF000000 & value) buffer[++i] = (uint8_t) (value>>24);
if (0x00FF0000 & value) buffer[++i] = (uint8_t) (value>>16);
if (0x0000FF00 & value) buffer[++i] = (uint8_t) (value>>8);
if (0x000000FF & value) buffer[++i] = (uint8_t) value;
if (0xFF000000 & value) buffer[++i] = (uint8_t) (0xFF & value>>24);
if (0xFFFF0000 & value) buffer[++i] = (uint8_t) (0xFF & value>>16);
if (0xFFFFFF00 & value) buffer[++i] = (uint8_t) (0xFF & value>>8);
if (0xFFFFFFFF & value) buffer[++i] = (uint8_t) (0xFF & value);
i += set_option_header(number - current_number, i-start_i, option);
@ -680,7 +680,7 @@ coap_parse_message(void *packet, uint8_t *data, uint16_t data_len)
((coap_packet_t *)packet)->block2_num = parse_int_option(current_option, option_len);
((coap_packet_t *)packet)->block2_more = (((coap_packet_t *)packet)->block2_num & 0x08)>>3;
((coap_packet_t *)packet)->block2_size = 16 << (((coap_packet_t *)packet)->block2_num & 0x07);
((coap_packet_t *)packet)->block2_offset = (((coap_packet_t *)packet)->block2_num & ~0x0F)<<(((coap_packet_t *)packet)->block2_num & 0x07);
((coap_packet_t *)packet)->block2_offset = (((coap_packet_t *)packet)->block2_num & ~0x0000000F)<<(((coap_packet_t *)packet)->block2_num & 0x07);
((coap_packet_t *)packet)->block2_num >>= 4;
PRINTF("Block2 [%lu%s (%u B/blk)]\n", ((coap_packet_t *)packet)->block2_num, ((coap_packet_t *)packet)->block2_more ? "+" : "", ((coap_packet_t *)packet)->block2_size);
break;
@ -1035,7 +1035,7 @@ coap_set_header_block2(void *packet, uint32_t num, uint8_t more, uint16_t size)
if (num>0x0FFFFF) return 0;
((coap_packet_t *)packet)->block2_num = num;
((coap_packet_t *)packet)->block2_more = more;
((coap_packet_t *)packet)->block2_more = more ? 1 : 0;
((coap_packet_t *)packet)->block2_size = size;
SET_OPTION((coap_packet_t *)packet, COAP_OPTION_BLOCK2);

View file

@ -54,9 +54,24 @@
#define PRINTADDR(addr)
#endif
/** \brief The sequence number (0x00 - 0xff) added to the transmitted
* data or MAC command frame. The default is a random value within
* the range.
*/
static uint8_t mac_dsn;
static uint8_t initialized = 0;
/** \brief The 16-bit identifier of the PAN on which the device is
* sending to. If this value is 0xffff, the device is not
* associated.
*/
static const uint16_t mac_dst_pan_id = IEEE802154_PANID;
/** \brief The 16-bit identifier of the PAN on which the device is
* operating. If this value is 0xffff, the device is not
* associated.
*/
static const uint16_t mac_src_pan_id = IEEE802154_PANID;
/*---------------------------------------------------------------------------*/
@ -145,7 +160,7 @@ create(void)
/* Set the source PAN ID to the global variable. */
params.src_pid = mac_src_pan_id;
/*
* Set up the source address using only the long address mode for
* phase 1.

View file

@ -50,7 +50,7 @@
#if PHASE_CONF_DRIFT_CORRECT
#define PHASE_DRIFT_CORRECT PHASE_CONF_DRIFT_CORRECT
#else
#define PHASE_DRIFT_CORRECT 1
#define PHASE_DRIFT_CORRECT 0
#endif
struct phase {

View file

@ -39,6 +39,8 @@
#include "net/neighbor-info.h"
#include "net/neighbor-attr.h"
#include "net/uip-ds6.h"
#include "net/uip-nd6.h"
#define DEBUG DEBUG_NONE
#include "net/uip-debug.h"
@ -104,6 +106,9 @@ neighbor_info_packet_sent(int status, int numtx)
{
const rimeaddr_t *dest;
link_metric_t packet_metric;
#if UIP_DS6_LL_NUD
uip_ds6_nbr_t *nbr;
#endif /* UIP_DS6_LL_NUD */
dest = packetbuf_addr(PACKETBUF_ADDR_RECEIVER);
if(rimeaddr_cmp(dest, &rimeaddr_null)) {
@ -119,6 +124,17 @@ neighbor_info_packet_sent(int status, int numtx)
switch(status) {
case MAC_TX_OK:
add_neighbor(dest);
#if UIP_DS6_LL_NUD
nbr = uip_ds6_nbr_ll_lookup((uip_lladdr_t *)dest);
if(nbr != NULL &&
(nbr->state == STALE || nbr->state == DELAY || nbr->state == PROBE)) {
nbr->state = REACHABLE;
stimer_set(&nbr->reachable, UIP_ND6_REACHABLE_TIME / 1000);
PRINTF("neighbor-info : received a link layer ACK : ");
PRINTLLADDR((uip_lladdr_t *)dest);
PRINTF(" is reachable.\n");
}
#endif /* UIP_DS6_LL_NUD */
break;
case MAC_TX_NOACK:
packet_metric = ETX_NOACK_PENALTY;

View file

@ -126,7 +126,7 @@ struct ack_msg {
full, incoming packets are dropped instead of being forwarded. */
#define MAX_MAC_REXMITS 2
#define MAX_ACK_MAC_REXMITS 5
#define REXMIT_TIME CLOCK_SECOND * 4
#define REXMIT_TIME CLOCK_SECOND * 32 / NETSTACK_CONF_RDC_CHANNEL_CHECK_RATE
#define FORWARD_PACKET_LIFETIME_BASE REXMIT_TIME * 2
#define MAX_SENDING_QUEUE 3 * QUEUEBUF_NUM / 4
#define MIN_AVAILABLE_QUEUE_ENTRIES 4

View file

@ -72,7 +72,7 @@ const struct mac_driver *rime_mac;
#ifdef RIME_CONF_BROADCAST_ANNOUNCEMENT_BUMP_TIME
#define BROADCAST_ANNOUNCEMENT_BUMP_TIME RIME_CONF_BROADCAST_ANNOUNCEMENT_BUMP_TIME
#else /* RIME_CONF_BROADCAST_ANNOUNCEMENT_BUMP_TIME */
#define BROADCAST_ANNOUNCEMENT_BUMP_TIME CLOCK_SECOND * 8
#define BROADCAST_ANNOUNCEMENT_BUMP_TIME CLOCK_SECOND * 32 / NETSTACK_CONF_RDC_CHANNEL_CHECK_RATE
#endif /* RIME_CONF_BROADCAST_ANNOUNCEMENT_BUMP_TIME */
#ifdef RIME_CONF_BROADCAST_ANNOUNCEMENT_MIN_TIME

View file

@ -1,2 +1,2 @@
CONTIKI_SOURCEFILES += rpl.c rpl-dag.c rpl-icmp6.c rpl-timers.c \
rpl-of-etx.c
rpl-of-etx.c rpl-ext-header.c

1087
core/net/rpl/rpl-dag.c Normal file → Executable file

File diff suppressed because it is too large Load diff

293
core/net/rpl/rpl-ext-header.c Executable file
View file

@ -0,0 +1,293 @@
/**
* \addtogroup uip6
* @{
*/
/*
* Copyright (c) 2009, 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.
*/
/**
* \file
* Management of extension headers for ContikiRPL.
*
* \author Vincent Brillault <vincent.brillault@imag.fr>,
* Joakim Eriksson <joakime@sics.se>,
* Niclas Finne <nfi@sics.se>,
* Nicolas Tsiftes <nvt@sics.se>.
*/
#include "net/uip.h"
#include "net/tcpip.h"
#include "net/uip-ds6.h"
#include "net/rpl/rpl-private.h"
#define DEBUG DEBUG_NONE
#include "net/uip-debug.h"
#include <limits.h>
#include <string.h>
/************************************************************************/
#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
#define UIP_EXT_BUF ((struct uip_ext_hdr *)&uip_buf[uip_l2_l3_hdr_len])
#define UIP_HBHO_BUF ((struct uip_hbho_hdr *)&uip_buf[uip_l2_l3_hdr_len])
#define UIP_HBHO_NEXT_BUF ((struct uip_ext_hdr *)&uip_buf[uip_l2_l3_hdr_len + RPL_HOP_BY_HOP_LEN])
#define UIP_EXT_HDR_OPT_BUF ((struct uip_ext_hdr_opt *)&uip_buf[uip_l2_l3_hdr_len + uip_ext_opt_offset])
#define UIP_EXT_HDR_OPT_PADN_BUF ((struct uip_ext_hdr_opt_padn *)&uip_buf[uip_l2_l3_hdr_len + uip_ext_opt_offset])
#define UIP_EXT_HDR_OPT_RPL_BUF ((struct uip_ext_hdr_opt_rpl *)&uip_buf[uip_l2_l3_hdr_len + uip_ext_opt_offset])
/************************************************************************/
int
rpl_verify_header(int uip_ext_opt_offset)
{
rpl_instance_t *instance;
long diff;
int down;
if(UIP_EXT_HDR_OPT_RPL_BUF->opt_len != RPL_HDR_OPT_LEN) {
PRINTF("RPL: Bad header option! (wrong length)\n");
return 1;
}
if(UIP_EXT_HDR_OPT_RPL_BUF->flags & RPL_HDR_OPT_FWD_ERR) {
PRINTF("RPL: Forward error!\n");
/* We should try to repair it, not implemented for the moment */
return 2;
}
instance = rpl_get_instance(UIP_EXT_HDR_OPT_RPL_BUF->instance);
if(instance == NULL) {
PRINTF("RPL: Unknown instance: %u\n",
UIP_EXT_HDR_OPT_RPL_BUF->instance);
return 1;
}
if(!instance->current_dag->joined) {
PRINTF("RPL: No DAG in the instance\n");
return 1;
}
down = 0;
if(UIP_EXT_HDR_OPT_RPL_BUF->flags & RPL_HDR_OPT_DOWN) {
down = 1;
}
PRINTF("RPL: Packet going %s\n", down == 1 ? "down" : "up");
diff = UIP_EXT_HDR_OPT_RPL_BUF->senderrank - instance->current_dag->rank;
if((down && diff > 0) || (!down && diff < 0)) {
PRINTF("RPL: Loop detected\n");
if(UIP_EXT_HDR_OPT_RPL_BUF->flags & RPL_HDR_OPT_RANK_ERR) {
PRINTF("RPL: Rank error signalled in RPL option!\n");
/* We should try to repair it, not implemented for the moment */
return 3;
}
PRINTF("RPL: Single error tolerated\n");
UIP_EXT_HDR_OPT_RPL_BUF->flags |= RPL_HDR_OPT_RANK_ERR;
return 0;
}
PRINTF("RPL: Rank OK\n");
return 0;
}
/************************************************************************/
static void
set_rpl_opt(unsigned uip_ext_opt_offset)
{
uint8_t temp_len;
memmove(UIP_HBHO_NEXT_BUF, UIP_EXT_BUF, uip_len - UIP_IPH_LEN);
memset(UIP_HBHO_BUF, 0, RPL_HOP_BY_HOP_LEN);
UIP_HBHO_BUF->next = UIP_IP_BUF->proto;
UIP_IP_BUF->proto = UIP_PROTO_HBHO;
UIP_HBHO_BUF->len = RPL_HOP_BY_HOP_LEN - 8;
UIP_EXT_HDR_OPT_RPL_BUF->opt_type = UIP_EXT_HDR_OPT_RPL;
UIP_EXT_HDR_OPT_RPL_BUF->opt_len = RPL_HDR_OPT_LEN;
UIP_EXT_HDR_OPT_RPL_BUF->flags = 0;
UIP_EXT_HDR_OPT_RPL_BUF->instance = 0;
UIP_EXT_HDR_OPT_RPL_BUF->senderrank = 0;
uip_len += RPL_HOP_BY_HOP_LEN;
temp_len = UIP_IP_BUF->len[1];
UIP_IP_BUF->len[1] += UIP_HBHO_BUF->len + 8;
if(UIP_IP_BUF->len[1] < temp_len) {
UIP_IP_BUF->len[0]++;
}
}
/************************************************************************/
void
rpl_update_header_empty(void)
{
rpl_instance_t *instance;
int uip_ext_opt_offset;
int last_uip_ext_len;
last_uip_ext_len = uip_ext_len;
uip_ext_len = 0;
uip_ext_opt_offset = 2;
PRINTF("RPL: Verifying the presence of the RPL header option\n");
switch(UIP_IP_BUF->proto) {
case UIP_PROTO_HBHO:
if(UIP_HBHO_BUF->len != RPL_HOP_BY_HOP_LEN - 8) {
PRINTF("RPL: Non RPL Hop-by-hop options support not implemented\n");
uip_ext_len = last_uip_ext_len;
return;
}
instance = rpl_get_instance(UIP_EXT_HDR_OPT_RPL_BUF->instance);
if(instance == NULL || !instance->used || !instance->current_dag->joined) {
PRINTF("RPL: Unable to add hop-by-hop extension header: incorrect instance\n");
return;
}
break;
default:
PRINTF("RPL: No hop-by-hop option found, creating it\n");
if(uip_len + RPL_HOP_BY_HOP_LEN > UIP_LINK_MTU) {
PRINTF("RPL: Packet too long: impossible to add hop-by-hop option\n");
uip_ext_len = last_uip_ext_len;
return;
}
set_rpl_opt(uip_ext_opt_offset);
uip_ext_len = last_uip_ext_len + RPL_HOP_BY_HOP_LEN;
return;
}
switch(UIP_EXT_HDR_OPT_BUF->type) {
case UIP_EXT_HDR_OPT_RPL:
PRINTF("RPL: Updating RPL option\n");
UIP_EXT_HDR_OPT_RPL_BUF->senderrank=instance->current_dag->rank;
uip_ext_len = last_uip_ext_len;
return;
default:
PRINTF("RPL: Multi Hop-by-hop options not implemented\n");
uip_ext_len = last_uip_ext_len;
return;
}
}
/************************************************************************/
int
rpl_update_header_final(uip_ipaddr_t *addr)
{
rpl_parent_t *parent;
int uip_ext_opt_offset;
int last_uip_ext_len;
last_uip_ext_len = uip_ext_len;
uip_ext_len = 0;
uip_ext_opt_offset = 2;
if(UIP_IP_BUF->proto == UIP_PROTO_HBHO) {
if(UIP_HBHO_BUF->len != RPL_HOP_BY_HOP_LEN - 8) {
PRINTF("RPL: Non RPL Hop-by-hop options support not implemented\n");
uip_ext_len = last_uip_ext_len;
return 0;
}
if(UIP_EXT_HDR_OPT_BUF->type == UIP_EXT_HDR_OPT_RPL) {
if(UIP_EXT_HDR_OPT_RPL_BUF->senderrank == 0) {
PRINTF("RPL: Updating RPL option\n");
if(default_instance == NULL || !default_instance->used || !default_instance->current_dag->joined) {
PRINTF("RPL: Unable to add hop-by-hop extension header: incorrect default instance\n");
return 1;
}
parent = rpl_find_parent(default_instance->current_dag, addr);
if(parent == NULL || parent != parent->dag->preferred_parent) {
UIP_EXT_HDR_OPT_RPL_BUF->flags = RPL_HDR_OPT_DOWN;
}
UIP_EXT_HDR_OPT_RPL_BUF->instance = default_instance->instance_id;
UIP_EXT_HDR_OPT_RPL_BUF->senderrank = default_instance->current_dag->rank;
uip_ext_len = last_uip_ext_len;
}
}
}
return 0;
}
/************************************************************************/
void
rpl_remove_header(void)
{
int last_uip_ext_len;
uint8_t temp_len;
last_uip_ext_len = uip_ext_len;
uip_ext_len = 0;
PRINTF("RPL: Verifying the presence of the RPL header option\n");
switch(UIP_IP_BUF->proto){
case UIP_PROTO_HBHO:
PRINTF("RPL: Removing the RPL header option\n");
UIP_IP_BUF->proto = UIP_HBHO_BUF->next;
temp_len = UIP_IP_BUF->len[1];
uip_len -= UIP_HBHO_BUF->len + 8;
UIP_IP_BUF->len[1] -= UIP_HBHO_BUF->len + 8;
if(UIP_IP_BUF->len[1] > temp_len) {
UIP_IP_BUF->len[0]--;
}
memmove(UIP_EXT_BUF, UIP_HBHO_NEXT_BUF, uip_len - UIP_IPH_LEN);
break;
default:
PRINTF("RPL: No hop-by-hop Option found\n");
}
}
/************************************************************************/
uint8_t
rpl_invert_header(void)
{
uint8_t uip_ext_opt_offset;
uint8_t last_uip_ext_len;
last_uip_ext_len = uip_ext_len;
uip_ext_len = 0;
uip_ext_opt_offset = 2;
PRINTF("RPL: Verifying the presence of the RPL header option\n");
switch(UIP_IP_BUF->proto) {
case UIP_PROTO_HBHO:
break;
default:
PRINTF("RPL: No hop-by-hop Option found\n");
uip_ext_len = last_uip_ext_len;
return 0;
}
switch (UIP_EXT_HDR_OPT_BUF->type) {
case UIP_EXT_HDR_OPT_RPL:
PRINTF("RPL: Updating RPL option (switching direction)\n");
UIP_EXT_HDR_OPT_RPL_BUF->flags &= RPL_HDR_OPT_DOWN;
UIP_EXT_HDR_OPT_RPL_BUF->flags ^= RPL_HDR_OPT_DOWN;
UIP_EXT_HDR_OPT_RPL_BUF->senderrank = rpl_get_instance(UIP_EXT_HDR_OPT_RPL_BUF->instance)->current_dag->rank;
uip_ext_len = last_uip_ext_len;
return RPL_HOP_BY_HOP_LEN;
default:
PRINTF("RPL: Multi Hop-by-hop options not implemented\n");
uip_ext_len = last_uip_ext_len;
return 0;
}
}
/************************************************************************/

215
core/net/rpl/rpl-icmp6.c Normal file → Executable file
View file

@ -81,8 +81,17 @@ void RPL_DEBUG_DIO_INPUT(uip_ipaddr_t *, rpl_dio_t *);
void RPL_DEBUG_DAO_OUTPUT(rpl_parent_t *);
#endif
static uint8_t dao_sequence = RPL_LOLLIPOP_INIT;
/* some debug callbacks useful when debugging RPL networks */
#ifdef RPL_DEBUG_DIO_INPUT
void RPL_DEBUG_DIO_INPUT(uip_ipaddr_t *, rpl_dio_t *);
#endif
#ifdef RPL_DEBUG_DAO_OUTPUT
void RPL_DEBUG_DAO_OUTPUT(rpl_parent_t *);
#endif
static uint8_t dao_sequence;
/*---------------------------------------------------------------------------*/
static int
get_global_addr(uip_ipaddr_t *addr)
@ -135,21 +144,27 @@ set16(uint8_t *buffer, int pos, uint16_t value)
static void
dis_input(void)
{
rpl_dag_t *dag;
rpl_instance_t *instance;
rpl_instance_t *end;
/* DAG Information Solicitation */
PRINTF("RPL: Received a DIS from ");
PRINT6ADDR(&UIP_IP_BUF->srcipaddr);
PRINTF("\n");
dag = rpl_get_dag(RPL_ANY_INSTANCE);
if(dag != NULL) {
if(uip_is_addr_mcast(&UIP_IP_BUF->destipaddr)) {
PRINTF("RPL: Multicast DIS => reset DIO timer\n");
rpl_reset_dio_timer(dag, 0);
} else {
PRINTF("RPL: Unicast DIS, reply to sender\n");
dio_output(dag, &UIP_IP_BUF->srcipaddr);
for(instance = &instance_table[0], end = instance + RPL_MAX_INSTANCES; instance < end; ++instance) {
if(instance->used == 1 ) {
#if RPL_LEAF_ONLY
if(!uip_is_addr_mcast(&UIP_IP_BUF->destipaddr)) {
#else /* !RPL_LEAF_ONLY */
if(uip_is_addr_mcast(&UIP_IP_BUF->destipaddr)) {
PRINTF("RPL: Multicast DIS => reset DIO timer\n");
rpl_reset_dio_timer(instance, 0);
} else {
#endif /* !RPL_LEAF_ONLY */
PRINTF("RPL: Unicast DIS, reply to sender\n");
dio_output(instance, &UIP_IP_BUF->srcipaddr);
}
}
}
}
@ -224,7 +239,7 @@ dio_input(void)
buffer_length = uip_len - uip_l2_l3_icmp_hdr_len;
#if RPL_CONF_ADJUST_LLH_LEN
buffer_length+=UIP_LLH_LEN; //Add jackdaw, minimal-net ethernet header
buffer_length += UIP_LLH_LEN; /* Add jackdaw, minimal-net ethernet header */
#endif
/* Process the DIO base option. */
@ -236,6 +251,7 @@ dio_input(void)
dio.rank = get16(buffer, i);
i += 2;
PRINTF("RPL: Incoming DIO InstanceID-Version %u-%u\n", (unsigned)dio.instance_id,(unsigned)dio.version);
PRINTF("RPL: Incoming DIO rank %u\n", (unsigned)dio.rank);
dio.grounded = buffer[i] & RPL_DIO_GROUNDED;
@ -249,6 +265,10 @@ dio_input(void)
memcpy(&dio.dag_id, buffer + i, sizeof(dio.dag_id));
i += sizeof(dio.dag_id);
PRINTF("RPL: Incoming DIO DODAG ");
PRINT6ADDR(&dio.dag_id);
PRINTF(", preference: %u\n", dio.preference);
/* Check if there are any DIO suboptions. */
for(; i < buffer_length; i += len) {
subopt_type = buffer[i];
@ -274,7 +294,6 @@ dio_input(void)
RPL_STAT(rpl_stats.malformed_msgs++);
return;
}
dio.mc.type = buffer[i + 2];
dio.mc.flags = buffer[i + 3] << 1;
dio.mc.flags |= buffer[i + 4] >> 7;
@ -375,19 +394,35 @@ dio_input(void)
}
/*---------------------------------------------------------------------------*/
void
dio_output(rpl_dag_t *dag, uip_ipaddr_t *uc_addr)
dio_output(rpl_instance_t *instance, uip_ipaddr_t *uc_addr)
{
unsigned char *buffer;
int pos;
#if !RPL_LEAF_ONLY
uip_ipaddr_t addr;
#endif /* !RPL_LEAF_ONLY */
#if RPL_LEAF_ONLY
/* only respond to unicast DIS */
if(uc_addr == NULL) {
return;
}
#endif /* RPL_LEAF_ONLY */
rpl_dag_t *dag = instance->current_dag;
/* DAG Information Object */
pos = 0;
buffer = UIP_ICMP_PAYLOAD;
buffer[pos++] = dag->instance_id;
buffer[pos++] = instance->instance_id;
buffer[pos++] = dag->version;
#if RPL_LEAF_ONLY
set16(buffer, pos, INFINITE_RANK);
#else /* RPL_LEAF_ONLY */
set16(buffer, pos, dag->rank);
#endif /* RPL_LEAF_ONLY */
pos += 2;
buffer[pos] = 0;
@ -395,8 +430,15 @@ dio_output(rpl_dag_t *dag, uip_ipaddr_t *uc_addr)
buffer[pos] |= RPL_DIO_GROUNDED;
}
buffer[pos++] = dag->mop << RPL_DIO_MOP_SHIFT;
buffer[pos++] = ++dag->dtsn_out;
buffer[pos] |= instance->mop << RPL_DIO_MOP_SHIFT;
buffer[pos] |= dag->preference & RPL_DIO_PREFERENCE_MASK;
pos++;
buffer[pos++] = instance->dtsn_out;
if(RPL_LOLLIPOP_IS_INIT(instance->dtsn_out)) {
RPL_LOLLIPOP_INCREMENT(instance->dtsn_out);
}
/* reserved 2 bytes */
buffer[pos++] = 0; /* flags */
@ -405,48 +447,49 @@ dio_output(rpl_dag_t *dag, uip_ipaddr_t *uc_addr)
memcpy(buffer + pos, &dag->dag_id, sizeof(dag->dag_id));
pos += 16;
if(dag->mc.type != RPL_DAG_MC_NONE) {
dag->of->update_metric_container(dag);
#if !RPL_LEAF_ONLY
if(instance->mc.type != RPL_DAG_MC_NONE) {
instance->of->update_metric_container(instance);
buffer[pos++] = RPL_OPTION_DAG_METRIC_CONTAINER;
buffer[pos++] = 6;
buffer[pos++] = dag->mc.type;
buffer[pos++] = dag->mc.flags >> 1;
buffer[pos] = (dag->mc.flags & 1) << 7;
buffer[pos++] |= (dag->mc.aggr << 4) | dag->mc.prec;
if(dag->mc.type == RPL_DAG_MC_ETX) {
buffer[pos++] = instance->mc.type;
buffer[pos++] = instance->mc.flags >> 1;
buffer[pos] = (instance->mc.flags & 1) << 7;
buffer[pos++] |= (instance->mc.aggr << 4) | instance->mc.prec;
if(instance->mc.type == RPL_DAG_MC_ETX) {
buffer[pos++] = 2;
set16(buffer, pos, dag->mc.obj.etx);
set16(buffer, pos, instance->mc.obj.etx);
pos += 2;
} else if(dag->mc.type == RPL_DAG_MC_ENERGY) {
} else if(instance->mc.type == RPL_DAG_MC_ENERGY) {
buffer[pos++] = 2;
buffer[pos++] = dag->mc.obj.energy.flags;
buffer[pos++] = dag->mc.obj.energy.energy_est;
buffer[pos++] = instance->mc.obj.energy.flags;
buffer[pos++] = instance->mc.obj.energy.energy_est;
} else {
PRINTF("RPL: Unable to send DIO because of unhandled DAG MC type %u\n",
(unsigned)dag->mc.type);
(unsigned)instance->mc.type);
return;
}
}
#endif /* !RPL_LEAF_ONLY */
/* Always add a DAG configuration option. */
buffer[pos++] = RPL_OPTION_DAG_CONF;
buffer[pos++] = 14;
buffer[pos++] = 0; /* No Auth, PCS = 0 */
buffer[pos++] = dag->dio_intdoubl;
buffer[pos++] = dag->dio_intmin;
buffer[pos++] = dag->dio_redundancy;
set16(buffer, pos, dag->max_rankinc);
buffer[pos++] = instance->dio_intdoubl;
buffer[pos++] = instance->dio_intmin;
buffer[pos++] = instance->dio_redundancy;
set16(buffer, pos, instance->max_rankinc);
pos += 2;
set16(buffer, pos, dag->min_hoprankinc);
set16(buffer, pos, instance->min_hoprankinc);
pos += 2;
/* OCP is in the DAG_CONF option */
set16(buffer, pos, dag->of->ocp);
set16(buffer, pos, instance->of->ocp);
pos += 2;
buffer[pos++] = 0; /* reserved */
buffer[pos++] = dag->default_lifetime;
set16(buffer, pos, dag->lifetime_unit);
buffer[pos++] = instance->default_lifetime;
set16(buffer, pos, instance->lifetime_unit);
pos += 2;
/* Check if we have a prefix to send also. */
@ -471,19 +514,27 @@ dio_output(rpl_dag_t *dag, uip_ipaddr_t *uc_addr)
dag->prefix_info.length);
}
#if RPL_LEAF_ONLY
PRINTF("RPL: Sending unicast-DIO with rank %u to ",
(unsigned)dag->rank);
PRINT6ADDR(uc_addr);
PRINTF("\n");
uip_icmp6_send(uc_addr, ICMP6_RPL, RPL_CODE_DIO, pos);
#else /* RPL_LEAF_ONLY */
/* Unicast requests get unicast replies! */
if(uc_addr == NULL) {
PRINTF("RPL: Sending a multicast-DIO with rank %u\n",
(unsigned)dag->rank);
(unsigned)instance->current_dag->rank);
uip_create_linklocal_rplnodes_mcast(&addr);
uip_icmp6_send(&addr, ICMP6_RPL, RPL_CODE_DIO, pos);
} else {
PRINTF("RPL: Sending unicast-DIO with rank %u to ",
(unsigned)dag->rank);
(unsigned)instance->current_dag->rank);
PRINT6ADDR(uc_addr);
PRINTF("\n");
uip_icmp6_send(uc_addr, ICMP6_RPL, RPL_CODE_DIO, pos);
}
#endif /* RPL_LEAF_ONLY */
}
/*---------------------------------------------------------------------------*/
static void
@ -491,10 +542,11 @@ dao_input(void)
{
uip_ipaddr_t dao_sender_addr;
rpl_dag_t *dag;
rpl_instance_t *instance;
unsigned char *buffer;
uint16_t sequence;
uint8_t instance_id;
rpl_lifetime_t lifetime;
uint8_t lifetime;
uint8_t prefixlen;
uint8_t flags;
uint8_t subopt_type;
@ -520,32 +572,37 @@ dao_input(void)
buffer = UIP_ICMP_PAYLOAD;
buffer_length = uip_len - uip_l2_l3_icmp_hdr_len;
#if RPL_CONF_ADJUST_LLH_LEN
buffer_length += UIP_LLH_LEN; /* Add jackdaw, minimal-net ethernet header */
#endif
pos = 0;
instance_id = buffer[pos++];
dag = rpl_get_dag(instance_id);
if(dag == NULL) {
PRINTF("RPL: Ignoring a DAO for a different RPL instance (%u)\n",
instance = rpl_get_instance(instance_id);
if(instance == NULL) {
PRINTF("RPL: Ignoring a DAO for an unknown RPL instance(%u)\n",
instance_id);
return;
}
lifetime = dag->default_lifetime;
lifetime = instance->default_lifetime;
flags = buffer[pos++];
/* reserved */
pos++;
sequence = buffer[pos++];
dag = instance->current_dag;
/* Is the DAGID present? */
if(flags & RPL_DAO_D_FLAG) {
/* Currently the DAG ID is ignored since we only use global
RPL Instance IDs. */
if(memcmp(&dag->dag_id, &buffer[pos], sizeof(dag->dag_id))) {
PRINTF("RPL: Ignoring a DAO for a DODAG different from ours\n");
return;
}
pos += 16;
} else {
/* Perhaps, there are verification to do but ... */
}
/* Check if there are any RPL options present. */
@ -561,7 +618,7 @@ dao_input(void)
switch(subopt_type) {
case RPL_OPTION_TARGET:
/* handle the target option */
/* Handle the target option. */
prefixlen = buffer[i + 3];
memset(&prefix, 0, sizeof(prefix));
memcpy(&prefix, buffer + i + 4, (prefixlen + 7) / CHAR_BIT);
@ -577,7 +634,7 @@ dao_input(void)
}
PRINTF("RPL: DAO lifetime: %u, prefix length: %u prefix: ",
(unsigned)lifetime, (unsigned)prefixlen);
(unsigned)lifetime, (unsigned)prefixlen);
PRINT6ADDR(&prefix);
PRINTF("\n");
@ -585,7 +642,7 @@ dao_input(void)
if(lifetime == ZERO_LIFETIME) {
/* No-Path DAO received; invoke the route purging routine. */
if(rep != NULL && rep->state.saved_lifetime == 0) {
if(rep != NULL && rep->state.saved_lifetime == 0 && rep->length == prefixlen) {
PRINTF("RPL: Setting expiration timer for prefix ");
PRINT6ADDR(&prefix);
PRINTF("\n");
@ -601,25 +658,25 @@ dao_input(void)
if(learned_from == RPL_ROUTE_FROM_UNICAST_DAO) {
/* Check whether this is a DAO forwarding loop. */
p = rpl_find_parent(dag, &dao_sender_addr);
if(p != NULL && DAG_RANK(p->rank, dag) < DAG_RANK(dag->rank, dag)) {
/* check if this is a new DAO registration with an "illegal" rank */
/* if we already route to this node it is likely */
if(p != NULL && DAG_RANK(p->rank, instance) < DAG_RANK(dag->rank, instance)) {
PRINTF("RPL: Loop detected when receiving a unicast DAO from a node with a lower rank! (%u < %u)\n",
DAG_RANK(p->rank, dag), DAG_RANK(dag->rank, dag));
DAG_RANK(p->rank, instance), DAG_RANK(dag->rank, instance));
p->rank = INFINITE_RANK;
p->updated = 1;
return;
}
}
rep = rpl_add_route(dag, &prefix, prefixlen, &dao_sender_addr);
if(rep == NULL) {
rep = rpl_add_route(dag, &prefix, prefixlen, &dao_sender_addr);
if(rep == NULL) {
RPL_STAT(rpl_stats.mem_overflows++);
PRINTF("RPL: Could not add a route after receiving a DAO\n");
return;
}
RPL_STAT(rpl_stats.mem_overflows++);
PRINTF("RPL: Could not add a route after receiving a DAO\n");
return;
}
rep->state.lifetime = RPL_LIFETIME(dag, lifetime);
rep->state.lifetime = RPL_LIFETIME(instance, lifetime);
rep->state.learned_from = learned_from;
if(learned_from == RPL_ROUTE_FROM_UNICAST_DAO) {
@ -629,16 +686,18 @@ dao_input(void)
PRINTF("\n");
uip_icmp6_send(&dag->preferred_parent->addr,
ICMP6_RPL, RPL_CODE_DAO, buffer_length);
} else if(flags & RPL_DAO_K_FLAG) {
dao_ack_output(dag, &dao_sender_addr, sequence);
}
if(flags & RPL_DAO_K_FLAG) {
dao_ack_output(instance, &dao_sender_addr, sequence);
}
}
}
/*---------------------------------------------------------------------------*/
void
dao_output(rpl_parent_t *n, rpl_lifetime_t lifetime)
dao_output(rpl_parent_t *n, uint8_t lifetime)
{
rpl_dag_t *dag;
rpl_instance_t *instance;
unsigned char *buffer;
uint8_t prefixlen;
uip_ipaddr_t addr;
@ -652,7 +711,7 @@ dao_output(rpl_parent_t *n, rpl_lifetime_t lifetime)
}
if(n == NULL) {
dag = rpl_get_dag(RPL_ANY_INSTANCE);
dag = rpl_get_any_dag();
if(dag == NULL) {
PRINTF("RPL: Did not join a DAG before sending DAO\n");
return;
@ -661,23 +720,32 @@ dao_output(rpl_parent_t *n, rpl_lifetime_t lifetime)
dag = n->dag;
}
instance = dag->instance;
#ifdef RPL_DEBUG_DAO_OUTPUT
RPL_DEBUG_DAO_OUTPUT(n);
#endif
buffer = UIP_ICMP_PAYLOAD;
++dao_sequence;
RPL_LOLLIPOP_INCREMENT(dao_sequence);
pos = 0;
buffer[pos++] = dag->instance_id;
buffer[pos++] = instance->instance_id;
buffer[pos] = 0;
#if RPL_DAO_SPECIFY_DODAG
buffer[pos] |= RPL_DAO_D_FLAG;
#endif /* RPL_DAO_SPECIFY_DODAG */
#if RPL_CONF_DAO_ACK
buffer[pos++] = RPL_DAO_K_FLAG; /* DAO ACK request, no DODAGID */
#else
buffer[pos++] = 0; /* No DAO ACK request, no DODAGID */
#endif
buffer[pos] |= RPL_DAO_K_FLAG;
#endif /* RPL_CONF_DAO_ACK */
++pos;
buffer[pos++] = 0; /* reserved */
buffer[pos++] = dao_sequence & 0xff;
buffer[pos++] = dao_sequence;
#if RPL_DAO_SPECIFY_DODAG
memcpy(buffer + pos, &dag->dag_id, sizeof(dag->dag_id));
pos+=sizeof(dag->dag_id);
#endif /* RPL_DAO_SPECIFY_DODAG */
/* create target subopt */
prefixlen = sizeof(prefix) * CHAR_BIT;
@ -726,9 +794,6 @@ dao_ack_input(void)
buffer = UIP_ICMP_PAYLOAD;
buffer_length = uip_len - uip_l2_l3_icmp_hdr_len;
#if RPL_CONF_ADJUST_LLH_LEN
buffer_length+=UIP_LLH_LEN; //Add jackdaw, minimal-net ethernet header
#endif
instance_id = buffer[0];
sequence = buffer[2];
@ -741,7 +806,7 @@ dao_ack_input(void)
}
/*---------------------------------------------------------------------------*/
void
dao_ack_output(rpl_dag_t *dag, uip_ipaddr_t *dest, uint8_t sequence)
dao_ack_output(rpl_instance_t *instance, uip_ipaddr_t *dest, uint8_t sequence)
{
unsigned char *buffer;
@ -751,7 +816,7 @@ dao_ack_output(rpl_dag_t *dag, uip_ipaddr_t *dest, uint8_t sequence)
buffer = UIP_ICMP_PAYLOAD;
buffer[0] = dag->instance_id;
buffer[0] = instance->instance_id;
buffer[1] = 0;
buffer[2] = sequence;
buffer[3] = 0;

View file

@ -52,13 +52,15 @@
static void reset(rpl_dag_t *);
static void parent_state_callback(rpl_parent_t *, int, int);
static rpl_parent_t *best_parent(rpl_parent_t *, rpl_parent_t *);
static rpl_dag_t *best_dag(rpl_dag_t *, rpl_dag_t *);
static rpl_rank_t calculate_rank(rpl_parent_t *, rpl_rank_t);
static void update_metric_container(rpl_dag_t *);
static void update_metric_container(rpl_instance_t *);
rpl_of_t rpl_of_etx = {
reset,
parent_state_callback,
best_parent,
best_dag,
calculate_rank,
update_metric_container,
1
@ -86,14 +88,14 @@ typedef uint16_t rpl_path_metric_t;
static rpl_path_metric_t
calculate_path_metric(rpl_parent_t *p)
{
if(p == NULL || (p->mc.obj.etx == 0 && p->rank > ROOT_RANK(p->dag))) {
if(p == NULL || (p->mc.obj.etx == 0 && p->rank > ROOT_RANK(p->dag->instance))) {
return MAX_PATH_COST * RPL_DAG_MC_ETX_DIVISOR;
}
return p->mc.obj.etx + NI_ETX_TO_RPL_ETX(p->link_metric);
}
static void
reset(rpl_dag_t *dag)
reset(rpl_dag_t *sag)
{
}
@ -114,7 +116,7 @@ calculate_rank(rpl_parent_t *p, rpl_rank_t base_rank)
}
rank_increase = NEIGHBOR_INFO_FIX2ETX(INITIAL_LINK_METRIC) * DEFAULT_MIN_HOPRANKINC;
} else {
rank_increase = NEIGHBOR_INFO_FIX2ETX(p->link_metric) * p->dag->min_hoprankinc;
rank_increase = NEIGHBOR_INFO_FIX2ETX(p->link_metric) * p->dag->instance->min_hoprankinc;
if(base_rank == 0) {
base_rank = p->rank;
}
@ -132,6 +134,32 @@ calculate_rank(rpl_parent_t *p, rpl_rank_t base_rank)
return new_rank;
}
static rpl_dag_t *
best_dag(rpl_dag_t *d1, rpl_dag_t *d2)
{
if(d1->grounded) {
if (!d2->grounded) {
return d1;
}
} else if(d2->grounded) {
return d2;
}
if(d1->preference < d2->preference) {
return d2;
} else {
if(d1->preference > d2->preference) {
return d1;
}
}
if(d2->rank < d1->rank) {
return d2;
} else {
return d1;
}
}
static rpl_parent_t *
best_parent(rpl_parent_t *p1, rpl_parent_t *p2)
{
@ -142,7 +170,7 @@ best_parent(rpl_parent_t *p1, rpl_parent_t *p2)
dag = p1->dag; /* Both parents must be in the same DAG. */
min_diff = RPL_DAG_MC_ETX_DIVISOR /
min_diff = RPL_DAG_MC_ETX_DIVISOR /
PARENT_SWITCH_THRESHOLD_DIV;
p1_metric = calculate_path_metric(p1);
@ -164,18 +192,26 @@ best_parent(rpl_parent_t *p1, rpl_parent_t *p2)
}
static void
update_metric_container(rpl_dag_t *dag)
update_metric_container(rpl_instance_t *instance)
{
rpl_path_metric_t path_metric;
rpl_dag_t *dag;
#if RPL_DAG_MC == RPL_DAG_MC_ENERGY
uint8_t type;
#endif
dag->mc.flags = RPL_DAG_MC_FLAG_P;
dag->mc.aggr = RPL_DAG_MC_AGGR_ADDITIVE;
dag->mc.prec = 0;
instance->mc.flags = RPL_DAG_MC_FLAG_P;
instance->mc.aggr = RPL_DAG_MC_AGGR_ADDITIVE;
instance->mc.prec = 0;
if(dag->rank == ROOT_RANK(dag)) {
dag = instance->current_dag;
if (!dag->joined) {
/* We should probably do something here */
return;
}
if(dag->rank == ROOT_RANK(instance)) {
path_metric = 0;
} else {
path_metric = calculate_path_metric(dag->preferred_parent);
@ -183,27 +219,27 @@ update_metric_container(rpl_dag_t *dag)
#if RPL_DAG_MC == RPL_DAG_MC_ETX
dag->mc.type = RPL_DAG_MC_ETX;
dag->mc.length = sizeof(dag->mc.obj.etx);
dag->mc.obj.etx = path_metric;
instance->mc.type = RPL_DAG_MC_ETX;
instance->mc.length = sizeof(instance->mc.obj.etx);
instance->mc.obj.etx = path_metric;
PRINTF("RPL: My path ETX to the root is %u.%u\n",
dag->mc.obj.etx / RPL_DAG_MC_ETX_DIVISOR,
(dag->mc.obj.etx % RPL_DAG_MC_ETX_DIVISOR * 100) / RPL_DAG_MC_ETX_DIVISOR);
instance->mc.obj.etx / RPL_DAG_MC_ETX_DIVISOR,
(instance->mc.obj.etx % RPL_DAG_MC_ETX_DIVISOR * 100) / RPL_DAG_MC_ETX_DIVISOR);
#elif RPL_DAG_MC == RPL_DAG_MC_ENERGY
dag->mc.type = RPL_DAG_MC_ENERGY;
dag->mc.length = sizeof(dag->mc.obj.energy);
instance->mc.type = RPL_DAG_MC_ENERGY;
instance->mc.length = sizeof(instance->mc.obj.energy);
if(dag->rank == ROOT_RANK(dag)) {
if(dag->rank == ROOT_RANK(instance)) {
type = RPL_DAG_MC_ENERGY_TYPE_MAINS;
} else {
type = RPL_DAG_MC_ENERGY_TYPE_BATTERY;
}
dag->mc.obj.energy.flags = type << RPL_DAG_MC_ENERGY_TYPE;
dag->mc.obj.energy.energy_est = path_metric;
instance->mc.obj.energy.flags = type << RPL_DAG_MC_ENERGY_TYPE;
instance->mc.obj.energy.energy_est = path_metric;
#else

View file

@ -48,6 +48,7 @@
static void reset(rpl_dag_t *);
static rpl_parent_t *best_parent(rpl_parent_t *, rpl_parent_t *);
static rpl_dag_t *best_dag(rpl_dag_t *, rpl_dag_t *);
static rpl_rank_t calculate_rank(rpl_parent_t *, rpl_rank_t);
static void update_metric_container(rpl_dag_t *);
@ -55,6 +56,7 @@ rpl_of_t rpl_of0 = {
reset,
NULL,
best_parent,
best_dag,
calculate_rank,
update_metric_container,
0
@ -92,6 +94,32 @@ calculate_rank(rpl_parent_t *p, rpl_rank_t base_rank)
}
static rpl_dag_t *
best_dag(rpl_dag_t *d1, rpl_dag_t *d2)
{
if(d1->grounded) {
if (!d2->grounded) {
return d1;
}
} else if(d2->grounded) {
return d2;
}
if(d1->preference < d2->preference) {
return d2;
} else {
if(d1->preference > d2->preference) {
return d1;
}
}
if(d2->rank < d1->rank) {
return d2;
} else {
return d1;
}
}
static rpl_parent_t *
best_parent(rpl_parent_t *p1, rpl_parent_t *p2)
{
@ -127,7 +155,7 @@ best_parent(rpl_parent_t *p1, rpl_parent_t *p2)
}
static void
update_metric_container(rpl_dag_t *dag)
update_metric_container(rpl_instance_t *instance)
{
dag->mc.type = RPL_DAG_MC_NONE;
instance->mc.type = RPL_DAG_MC_NONE;
}

View file

@ -94,6 +94,16 @@
#define RPL_DAO_K_FLAG 0x80 /* DAO ACK requested */
#define RPL_DAO_D_FLAG 0x40 /* DODAG ID present */
/*---------------------------------------------------------------------------*/
/* RPL IPv6 extension header option. */
#define RPL_HDR_OPT_LEN 4
#define RPL_HOP_BY_HOP_LEN (RPL_HDR_OPT_LEN + 2 + 2)
#define RPL_HDR_OPT_DOWN 0x80
#define RPL_HDR_OPT_DOWN_SHIFT 7
#define RPL_HDR_OPT_RANK_ERR 0x40
#define RPL_HDR_OPT_RANK_ERR_SHIFT 6
#define RPL_HDR_OPT_FWD_ERR 0x20
#define RPL_HDR_OPT_FWD_ERR_SHIFT 5
/*---------------------------------------------------------------------------*/
/* Default values for RPL constants and variables. */
/* The default value for the DAO timer. */
@ -108,8 +118,8 @@
/* Default route lifetime as a multiple of the lifetime unit. */
#define RPL_DEFAULT_LIFETIME 0xff
#define RPL_LIFETIME(dag, lifetime) \
((unsigned long)(dag)->lifetime_unit * lifetime)
#define RPL_LIFETIME(instance, lifetime) \
(((unsigned long)(instance)->lifetime_unit) * lifetime)
#ifndef RPL_CONF_MIN_HOPRANKINC
#define DEFAULT_MIN_HOPRANKINC 256
@ -118,13 +128,13 @@
#endif
#define DEFAULT_MAX_RANKINC (3 * DEFAULT_MIN_HOPRANKINC)
#define DAG_RANK(fixpt_rank, dag) ((fixpt_rank) / (dag)->min_hoprankinc)
#define DAG_RANK(fixpt_rank, instance) ((fixpt_rank) / (instance)->min_hoprankinc)
/* Rank of a virtual root node that coordinates DAG root nodes. */
#define BASE_RANK 0
/* Rank of a root node. */
#define ROOT_RANK(dag) (dag)->min_hoprankinc
#define ROOT_RANK(instance) (instance)->min_hoprankinc
#define INFINITE_RANK 0xffff
@ -208,7 +218,7 @@ struct rpl_dio {
uint8_t dag_intdoubl;
uint8_t dag_intmin;
uint8_t dag_redund;
rpl_lifetime_t default_lifetime;
uint8_t default_lifetime;
uint16_t lifetime_unit;
rpl_rank_t dag_max_rankinc;
rpl_rank_t dag_min_hoprankinc;
@ -241,33 +251,44 @@ extern rpl_stats_t rpl_stats;
#define RPL_STAT(code)
#endif /* RPL_CONF_STATS */
/*---------------------------------------------------------------------------*/
/* Instances */
extern rpl_instance_t instance_table[];
extern rpl_instance_t *default_instance;
/* ICMPv6 functions for RPL. */
void dis_output(uip_ipaddr_t *addr);
void dio_output(rpl_dag_t *, uip_ipaddr_t *uc_addr);
void dao_output(rpl_parent_t *, rpl_lifetime_t lifetime);
void dao_ack_output(rpl_dag_t *, uip_ipaddr_t *, uint8_t);
void uip_rpl_input(void);
void dio_output(rpl_instance_t *, uip_ipaddr_t *uc_addr);
void dao_output(rpl_parent_t *, uint8_t lifetime);
void dao_ack_output(rpl_instance_t *, uip_ipaddr_t *, uint8_t);
/* RPL logic functions. */
void rpl_join_dag(rpl_dag_t *);
void rpl_local_repair(rpl_dag_t *dag);
int rpl_set_default_route(rpl_dag_t *dag, uip_ipaddr_t *from);
void rpl_join_dag(uip_ipaddr_t *from, rpl_dio_t *dio);
void rpl_join_instance(uip_ipaddr_t *from, rpl_dio_t *dio);
void rpl_local_repair(rpl_instance_t *instance);
void rpl_process_dio(uip_ipaddr_t *, rpl_dio_t *);
int rpl_process_parent_event(rpl_dag_t *, rpl_parent_t *);
int rpl_process_parent_event(rpl_instance_t *, rpl_parent_t *);
/* DAG object management. */
rpl_dag_t *rpl_alloc_dag(uint8_t);
void rpl_free_dag(rpl_dag_t *);
rpl_dag_t *rpl_alloc_dodag(uint8_t, uip_ipaddr_t *);
rpl_instance_t *rpl_alloc_instance(uint8_t);
void rpl_free_dodag(rpl_dag_t *);
void rpl_free_instance(rpl_instance_t *);
/* DAG parent management function. */
rpl_parent_t *rpl_add_parent(rpl_dag_t *, rpl_dio_t *dio, uip_ipaddr_t *);
rpl_parent_t *rpl_find_parent(rpl_dag_t *, uip_ipaddr_t *);
int rpl_remove_parent(rpl_dag_t *, rpl_parent_t *);
rpl_parent_t * rpl_find_parent_any_dag(rpl_instance_t *instance, uip_ipaddr_t *addr);
rpl_dag_t * rpl_find_parent_dag(rpl_instance_t *instance, uip_ipaddr_t *addr);
void rpl_nullify_parent(rpl_dag_t *, rpl_parent_t *);
void rpl_remove_parent(rpl_dag_t *, rpl_parent_t *);
void rpl_move_parent(rpl_dag_t *dag_src, rpl_dag_t *dag_dst, rpl_parent_t *parent);
rpl_parent_t *rpl_select_parent(rpl_dag_t *dag);
rpl_dag_t *rpl_select_dodag(rpl_instance_t *instance,rpl_parent_t *parent);
void rpl_recalculate_ranks(void);
/* RPL routing table functions. */
void rpl_remove_routes(rpl_dag_t *dag);
void rpl_remove_routes_by_nexthop(uip_ipaddr_t *nexthop, rpl_dag_t *dag);
uip_ds6_route_t *rpl_add_route(rpl_dag_t *dag, uip_ipaddr_t *prefix,
int prefix_len, uip_ipaddr_t *next_hop);
void rpl_purge_routes(void);
@ -276,8 +297,8 @@ void rpl_purge_routes(void);
rpl_of_t *rpl_find_of(rpl_ocp_t);
/* Timer functions. */
void rpl_schedule_dao(rpl_dag_t *);
void rpl_reset_dio_timer(rpl_dag_t *, uint8_t);
void rpl_schedule_dao(rpl_instance_t *);
void rpl_reset_dio_timer(rpl_instance_t *, uint8_t);
void rpl_reset_periodic_timer(void);
/* Route poisoning. */

View file

@ -51,7 +51,7 @@
static struct ctimer periodic_timer;
static void handle_periodic_timer(void *ptr);
static void new_dio_interval(rpl_dag_t *dag);
static void new_dio_interval(rpl_instance_t *instance);
static void handle_dio_timer(void *ptr);
static uint16_t next_dis;
@ -69,7 +69,7 @@ handle_periodic_timer(void *ptr)
/* handle DIS */
#ifdef RPL_DIS_SEND
next_dis++;
if(rpl_get_dag(RPL_ANY_INSTANCE) == NULL && next_dis >= RPL_DIS_INTERVAL) {
if(rpl_get_any_dag() == NULL && next_dis >= RPL_DIS_INTERVAL) {
next_dis = 0;
dis_output(NULL);
}
@ -78,17 +78,17 @@ handle_periodic_timer(void *ptr)
}
/************************************************************************/
static void
new_dio_interval(rpl_dag_t *dag)
new_dio_interval(rpl_instance_t *instance)
{
uint32_t time;
/* TODO: too small timer intervals for many cases */
time = 1UL << dag->dio_intcurrent;
time = 1UL << instance->dio_intcurrent;
/* Convert from milliseconds to CLOCK_TICKS. */
time = (time * CLOCK_SECOND) / 1000;
dag->dio_next_delay = time;
instance->dio_next_delay = time;
/* random number between I/2 and I */
time = time >> 1;
@ -99,36 +99,36 @@ new_dio_interval(rpl_dag_t *dag)
* operate efficiently. Therefore we need to calculate the delay between
* the randomized time and the start time of the next interval.
*/
dag->dio_next_delay -= time;
dag->dio_send = 1;
instance->dio_next_delay -= time;
instance->dio_send = 1;
#if RPL_CONF_STATS
/* keep some stats */
dag->dio_totint++;
dag->dio_totrecv += dag->dio_counter;
instance->dio_totint++;
instance->dio_totrecv += instance->dio_counter;
ANNOTATE("#A rank=%u.%u(%u),stats=%d %d %d %d,color=%s\n",
DAG_RANK(dag->rank, dag),
(10 * (dag->rank % dag->min_hoprankinc)) / dag->min_hoprankinc,
dag->version,
dag->dio_totint, dag->dio_totsend,
dag->dio_totrecv,dag->dio_intcurrent,
dag->rank == ROOT_RANK(dag) ? "BLUE" : "ORANGE");
DAG_RANK(instance->current_dag->rank, instance),
(10 * (instance->current_dag->rank % instance->min_hoprankinc)) / instance->min_hoprankinc,
instance->current_dag->version,
instance->dio_totint, instance->dio_totsend,
instance->dio_totrecv,instance->dio_intcurrent,
instance->current_dag->rank == ROOT_RANK(instance) ? "BLUE" : "ORANGE");
#endif /* RPL_CONF_STATS */
/* reset the redundancy counter */
dag->dio_counter = 0;
instance->dio_counter = 0;
/* schedule the timer */
PRINTF("RPL: Scheduling DIO timer %lu ticks in future (Interval)\n", time);
ctimer_set(&dag->dio_timer, time, &handle_dio_timer, dag);
ctimer_set(&instance->dio_timer, time, &handle_dio_timer, instance);
}
/************************************************************************/
static void
handle_dio_timer(void *ptr)
{
rpl_dag_t *dag;
rpl_instance_t *instance;
dag = (rpl_dag_t *)ptr;
instance = (rpl_instance_t *)ptr;
PRINTF("RPL: DIO Timer triggered\n");
if(!dio_send_ok) {
@ -136,33 +136,33 @@ handle_dio_timer(void *ptr)
dio_send_ok = 1;
} else {
PRINTF("RPL: Postponing DIO transmission since link local address is not ok\n");
ctimer_set(&dag->dio_timer, CLOCK_SECOND, &handle_dio_timer, dag);
ctimer_set(&instance->dio_timer, CLOCK_SECOND, &handle_dio_timer, instance);
return;
}
}
if(dag->dio_send) {
if(instance->dio_send) {
/* send DIO if counter is less than desired redundancy */
if(dag->dio_counter < dag->dio_redundancy) {
if(instance->dio_counter < instance->dio_redundancy) {
#if RPL_CONF_STATS
dag->dio_totsend++;
instance->dio_totsend++;
#endif /* RPL_CONF_STATS */
dio_output(dag, NULL);
dio_output(instance, NULL);
} else {
PRINTF("RPL: Supressing DIO transmission (%d >= %d)\n",
dag->dio_counter, dag->dio_redundancy);
instance->dio_counter, instance->dio_redundancy);
}
dag->dio_send = 0;
PRINTF("RPL: Scheduling DIO timer %u ticks in future (sent)\n",
dag->dio_next_delay);
ctimer_set(&dag->dio_timer, dag->dio_next_delay, handle_dio_timer, dag);
instance->dio_send = 0;
PRINTF("RPL: Scheduling DIO timer %"PRIu32" ticks in future (sent)\n",
instance->dio_next_delay);
ctimer_set(&instance->dio_timer, instance->dio_next_delay, handle_dio_timer, instance);
} else {
/* check if we need to double interval */
if(dag->dio_intcurrent < dag->dio_intmin + dag->dio_intdoubl) {
dag->dio_intcurrent++;
PRINTF("RPL: DIO Timer interval doubled %d\n", dag->dio_intcurrent);
if(instance->dio_intcurrent < instance->dio_intmin + instance->dio_intdoubl) {
instance->dio_intcurrent++;
PRINTF("RPL: DIO Timer interval doubled %d\n", instance->dio_intcurrent);
}
new_dio_interval(dag);
new_dio_interval(instance);
}
}
/************************************************************************/
@ -173,61 +173,64 @@ rpl_reset_periodic_timer(void)
ctimer_set(&periodic_timer, CLOCK_SECOND, handle_periodic_timer, NULL);
}
/************************************************************************/
/* Resets the DIO timer in the DAG to its minimal interval. */
/* Resets the DIO timer in the instance to its minimal interval. */
void
rpl_reset_dio_timer(rpl_dag_t *dag, uint8_t force)
rpl_reset_dio_timer(rpl_instance_t *instance, uint8_t force)
{
/* only reset if not just reset or started */
if(force || dag->dio_intcurrent > dag->dio_intmin) {
dag->dio_counter = 0;
dag->dio_intcurrent = dag->dio_intmin;
new_dio_interval(dag);
#if !RPL_LEAF_ONLY
/* Do not reset if we are already on the minimum interval,
unless forced to do so. */
if(force || instance->dio_intcurrent > instance->dio_intmin) {
instance->dio_counter = 0;
instance->dio_intcurrent = instance->dio_intmin;
new_dio_interval(instance);
}
#if RPL_CONF_STATS
rpl_stats.resets++;
#endif
#endif /* RPL_CONF_STATS */
#endif /* RPL_LEAF_ONLY */
}
/************************************************************************/
static void
handle_dao_timer(void *ptr)
{
rpl_dag_t *dag;
rpl_instance_t *instance;
dag = (rpl_dag_t *)ptr;
instance = (rpl_instance_t *)ptr;
if (!dio_send_ok && uip_ds6_get_link_local(ADDR_PREFERRED) == NULL) {
PRINTF("RPL: Postpone DAO transmission... \n");
ctimer_set(&dag->dao_timer, CLOCK_SECOND, handle_dao_timer, dag);
if(!dio_send_ok && uip_ds6_get_link_local(ADDR_PREFERRED) == NULL) {
PRINTF("RPL: Postpone DAO transmission\n");
ctimer_set(&instance->dao_timer, CLOCK_SECOND, handle_dao_timer, instance);
return;
}
/* Send the DAO to the DAO parent set -- the preferred parent in our case. */
if(dag->preferred_parent != NULL) {
if(instance->current_dag->preferred_parent != NULL) {
PRINTF("RPL: handle_dao_timer - sending DAO\n");
/* Set the route lifetime to the default value. */
dao_output(dag->preferred_parent, dag->default_lifetime);
dao_output(instance->current_dag->preferred_parent, instance->default_lifetime);
} else {
PRINTF("RPL: No suitable DAO parent\n");
}
ctimer_stop(&dag->dao_timer);
ctimer_stop(&instance->dao_timer);
}
/************************************************************************/
void
rpl_schedule_dao(rpl_dag_t *dag)
rpl_schedule_dao(rpl_instance_t *instance)
{
clock_time_t expiration_time;
expiration_time = etimer_expiration_time(&dag->dao_timer.etimer);
expiration_time = etimer_expiration_time(&instance->dao_timer.etimer);
if(!etimer_expired(&dag->dao_timer.etimer)) {
if(!etimer_expired(&instance->dao_timer.etimer)) {
PRINTF("RPL: DAO timer already scheduled\n");
} else {
expiration_time = DEFAULT_DAO_LATENCY / 2 +
(random_rand() % (DEFAULT_DAO_LATENCY));
PRINTF("RPL: Scheduling DAO timer %u ticks in the future\n",
(unsigned)expiration_time);
ctimer_set(&dag->dao_timer, expiration_time,
handle_dao_timer, dag);
ctimer_set(&instance->dao_timer, expiration_time,
handle_dao_timer, instance);
}
}
/************************************************************************/

View file

@ -86,6 +86,23 @@ rpl_remove_routes(rpl_dag_t *dag)
}
}
/************************************************************************/
void
rpl_remove_routes_by_nexthop(uip_ipaddr_t *nexthop, rpl_dag_t *dag)
{
uip_ds6_route_t *locroute;
for(locroute = uip_ds6_routing_table;
locroute < uip_ds6_routing_table + UIP_DS6_ROUTE_NB;
locroute++) {
if(locroute->isused
&& uip_ipaddr_cmp(&locroute->nexthop, nexthop)
&& locroute->state.dag == dag) {
locroute->isused = 0;
}
}
ANNOTATE("#L %u 0\n",nexthop->u8[sizeof(uip_ipaddr_t) - 1]);
}
/************************************************************************/
uip_ds6_route_t *
rpl_add_route(rpl_dag_t *dag, uip_ipaddr_t *prefix, int prefix_len,
uip_ipaddr_t *next_hop)
@ -107,7 +124,7 @@ rpl_add_route(rpl_dag_t *dag, uip_ipaddr_t *prefix, int prefix_len,
uip_ipaddr_copy(&rep->nexthop, next_hop);
}
rep->state.dag = dag;
rep->state.lifetime = RPL_LIFETIME(dag, dag->default_lifetime);
rep->state.lifetime = RPL_LIFETIME(dag->instance, dag->instance->default_lifetime);
rep->state.learned_from = RPL_ROUTE_FROM_INTERNAL;
PRINTF("RPL: Added a route to ");
@ -123,8 +140,9 @@ static void
rpl_link_neighbor_callback(const rimeaddr_t *addr, int known, int etx)
{
uip_ipaddr_t ipaddr;
rpl_dag_t *dag;
rpl_parent_t *parent;
rpl_instance_t *instance;
rpl_instance_t *end;
uip_ip6addr(&ipaddr, 0xfe80, 0, 0, 0, 0, 0, 0, 0);
uip_ds6_set_addr_iid(&ipaddr, (uip_lladdr_t *)addr);
@ -132,66 +150,55 @@ rpl_link_neighbor_callback(const rimeaddr_t *addr, int known, int etx)
PRINT6ADDR(&ipaddr);
PRINTF(" is %sknown. ETX = %u\n", known ? "" : "no longer ", NEIGHBOR_INFO_FIX2ETX(etx));
dag = rpl_get_dag(RPL_DEFAULT_INSTANCE);
if(dag == NULL) {
return;
}
for(instance = &instance_table[0], end = instance + RPL_MAX_INSTANCES; instance < end; ++instance) {
if(instance->used == 1 ) {
parent = rpl_find_parent_any_dag(instance, &ipaddr);
if(parent != NULL) {
/* Trigger DAG rank recalculation. */
parent->updated = 1;
parent->link_metric = etx;
parent = rpl_find_parent(dag, &ipaddr);
if(parent == NULL) {
if(!known) {
PRINTF("RPL: Deleting routes installed by DAOs received from ");
PRINT6ADDR(&ipaddr);
PRINTF("\n");
uip_ds6_route_rm_by_nexthop(&ipaddr);
if(instance->of->parent_state_callback != NULL) {
instance->of->parent_state_callback(parent, known, etx);
}
if(!known) {
PRINTF("RPL: Removing parent ");
PRINT6ADDR(&parent->addr);
PRINTF(" in instance %u because of bad connectivity (ETX %d)\n", instance->instance_id, etx);
parent->rank = INFINITE_RANK;
}
}
}
return;
}
/* Trigger DAG rank recalculation. */
parent->updated = 1;
parent->link_metric = etx;
if(dag->of->parent_state_callback != NULL) {
dag->of->parent_state_callback(parent, known, etx);
}
if(!known) {
PRINTF("RPL: Removing parent ");
PRINT6ADDR(&parent->addr);
PRINTF(" because of bad connectivity (ETX %d)\n", etx);
parent->rank = INFINITE_RANK;
PRINTF("RPL: Deleting routes installed by DAOs received from ");
PRINT6ADDR(&ipaddr);
PRINTF("\n");
uip_ds6_route_rm_by_nexthop(&ipaddr);
}
}
/************************************************************************/
void
rpl_ipv6_neighbor_callback(uip_ds6_nbr_t *nbr)
{
rpl_dag_t *dag;
rpl_parent_t *p;
/* This only handles one DODAG - if multiple we need to check all */
dag = rpl_get_dag(RPL_ANY_INSTANCE);
if(dag == NULL) {
return;
}
/* if this is our default route then clean the dag->def_route state */
if(dag->def_route != NULL &&
uip_ipaddr_cmp(&dag->def_route->ipaddr, &nbr->ipaddr)) {
dag->def_route = NULL;
}
rpl_instance_t *instance;
rpl_instance_t *end;
if(!nbr->isused) {
PRINTF("RPL: Removing neighbor ");
PRINT6ADDR(&nbr->ipaddr);
PRINTF("\n");
p = rpl_find_parent(dag, &nbr->ipaddr);
if(p != NULL) {
p->rank = INFINITE_RANK;
/* Trigger DAG rank recalculation. */
p->updated = 1;
for(instance = &instance_table[0], end = instance + RPL_MAX_INSTANCES; instance < end; ++instance) {
if(instance->used == 1 ) {
p = rpl_find_parent_any_dag(instance, &nbr->ipaddr);
if(p != NULL) {
p->rank = INFINITE_RANK;
/* Trigger DAG rank recalculation. */
p->updated = 1;
}
}
}
}
}
@ -201,6 +208,7 @@ rpl_init(void)
{
uip_ipaddr_t rplmaddr;
PRINTF("RPL started\n");
default_instance = NULL;
rpl_reset_periodic_timer();
neighbor_info_subscribe(rpl_link_neighbor_callback);

View file

@ -73,19 +73,77 @@
#endif /* RPL_CONF_OF */
/* This value decides which DAG instance we should participate in by default. */
#define RPL_DEFAULT_INSTANCE 0
#define RPL_DEFAULT_INSTANCE 0x1e
/*
* This value decides if this node must stay as a leaf or not
* as allowed by draft-ietf-roll-rpl-19#section-8.5
*/
#ifdef RPL_CONF_LEAF_ONLY
#define RPL_LEAF_ONLY RPL_CONF_LEAF_ONLY
#else
#define RPL_LEAF_ONLY 0
#endif
/*
* Maximum of concurent rpl-instances
*/
#ifndef RPL_CONF_MAX_INSTANCES
#define RPL_MAX_INSTANCES 1
#else
#define RPL_MAX_INSTANCES RPL_CONF_MAX_INSTANCES
#endif /* !RPL_CONF_MAX_INSTANCES */
/*
* Maximum of concurent dodag inside an instance
*/
#ifndef RPL_CONF_MAX_DODAG_PER_INSTANCE
#define RPL_MAX_DODAG_PER_INSTANCE 2
#else
#define RPL_MAX_DODAG_PER_INSTANCE RPL_CONF_MAX_DODAG_PER_INSTANCE
#endif /* !RPL_CONF_MAX_DODAG_PER_INSTANCE */
/*
*
*/
#ifndef RPL_CONF_DAO_SPECIFY_DODAG
#if RPL_MAX_DODAG_PER_INSTANCE > 1
#define RPL_DAO_SPECIFY_DODAG 1
#else /* RPL_MAX_DODAG_PER_INSTANCE > 1*/
#define RPL_DAO_SPECIFY_DODAG 0
#endif /* RPL_MAX_DODAG_PER_INSTANCE > 1 */
#else /* RPL_CONF_DAO_SPECIFY_DODAG */
#define RPL_DAO_SPECIFY_DODAG RPL_CONF_DAO_SPECIFY_DODAG
#endif /* RPL_CONF_DAO_SPECIFY_DODAG */
/* This value is used to access an arbitrary DAG. It will likely be
replaced when we support multiple DAGs more. */
#define RPL_ANY_INSTANCE -1
/*---------------------------------------------------------------------------*/
/* The amount of parents that this node has in a particular DAG. */
#define RPL_PARENT_COUNT(dag) list_length((dag)->parents)
/*---------------------------------------------------------------------------*/
typedef uint16_t rpl_rank_t;
typedef uint8_t rpl_lifetime_t;
typedef uint16_t rpl_ocp_t;
/*---------------------------------------------------------------------------*/
/* Lollipop counters */
#define RPL_LOLLIPOP_MAX_VALUE 255
#define RPL_LOLLIPOP_CIRCULAR_REGION 127
#define RPL_LOLLIPOP_SEQUENCE_WINDOWS 16
#define RPL_LOLLIPOP_INIT RPL_LOLLIPOP_MAX_VALUE - RPL_LOLLIPOP_SEQUENCE_WINDOWS + 1
#define RPL_LOLLIPOP_INCREMENT(counter) (counter > RPL_LOLLIPOP_CIRCULAR_REGION ?\
(counter == RPL_LOLLIPOP_MAX_VALUE ? counter=0 : ++counter):\
(counter == RPL_LOLLIPOP_CIRCULAR_REGION ? counter=0 : ++counter))
#define RPL_LOLLIPOP_IS_INIT(counter) (counter > RPL_LOLLIPOP_CIRCULAR_REGION)
#define RPL_LOLLIPOP_GREATER_THAN_LOCAL(A,B) (((A < B) && (RPL_LOLLIPOP_CIRCULAR_REGION + 1 - B + A < RPL_LOLLIPOP_SEQUENCE_WINDOWS)) || \
((A > B) && (A - B < RPL_LOLLIPOP_SEQUENCE_WINDOWS)))
#define RPL_LOLLIPOP_GREATER_THAN(A,B) ((A > RPL_LOLLIPOP_CIRCULAR_REGION )?\
((B > RPL_LOLLIPOP_CIRCULAR_REGION )?\
RPL_LOLLIPOP_GREATER_THAN_LOCAL(A,B):\
0):\
((B > RPL_LOLLIPOP_CIRCULAR_REGION )?\
1:\
RPL_LOLLIPOP_GREATER_THAN_LOCAL(A,B)))
/*---------------------------------------------------------------------------*/
/* DAG Metric Container Object Types, to be confirmed by IANA. */
#define RPL_DAG_MC_NONE 0 /* Local identifier for empty MC */
@ -139,6 +197,7 @@ struct rpl_metric_container {
};
typedef struct rpl_metric_container rpl_metric_container_t;
/*---------------------------------------------------------------------------*/
struct rpl_instance;
struct rpl_dag;
/*---------------------------------------------------------------------------*/
struct rpl_parent {
@ -153,6 +212,35 @@ struct rpl_parent {
};
typedef struct rpl_parent rpl_parent_t;
/*---------------------------------------------------------------------------*/
/* RPL DIO prefix suboption */
struct rpl_prefix {
uip_ipaddr_t prefix;
uint32_t lifetime;
uint8_t length;
uint8_t flags;
};
typedef struct rpl_prefix rpl_prefix_t;
/*---------------------------------------------------------------------------*/
/* Directed Acyclic Graph */
struct rpl_dag {
uip_ipaddr_t dag_id;
rpl_rank_t min_rank; /* should be reset per DODAG iteration! */
uint8_t version;
uint8_t grounded;
uint8_t preference;
uint8_t used;
/* live data for the DAG */
uint8_t joined;
rpl_parent_t *preferred_parent;
rpl_rank_t rank;
struct rpl_instance *instance;
void *parent_list;
list_t parents;
rpl_prefix_t prefix_info;
};
typedef struct rpl_dag rpl_dag_t;
typedef struct rpl_instance rpl_instance_t;
/*---------------------------------------------------------------------------*/
/*
* API for RPL objective functions (OF)
*
@ -171,6 +259,10 @@ typedef struct rpl_parent rpl_parent_t;
*
* Compares two parents and returns the best one, according to the OF.
*
* best_dag(dodag1, dodag2)
*
* Compares two dodags and returns the best one, according to the OF.
*
* calculate_rank(parent, base_rank)
*
* Calculates a rank value using the parent rank and a base rank.
@ -188,51 +280,36 @@ struct rpl_of {
void (*reset)(struct rpl_dag *);
void (*parent_state_callback)(rpl_parent_t *, int, int);
rpl_parent_t *(*best_parent)(rpl_parent_t *, rpl_parent_t *);
rpl_dag_t *(*best_dag)(rpl_dag_t *, rpl_dag_t *);
rpl_rank_t (*calculate_rank)(rpl_parent_t *, rpl_rank_t);
void (*update_metric_container)(struct rpl_dag *);
void (*update_metric_container)( rpl_instance_t *);
rpl_ocp_t ocp;
};
typedef struct rpl_of rpl_of_t;
/*---------------------------------------------------------------------------*/
/* RPL DIO prefix suboption */
struct rpl_prefix {
uip_ipaddr_t prefix;
uint32_t lifetime;
uint8_t length;
uint8_t flags;
};
typedef struct rpl_prefix rpl_prefix_t;
/*---------------------------------------------------------------------------*/
/* Directed Acyclic Graph */
struct rpl_dag {
/* Instance */
struct rpl_instance {
/* DAG configuration */
rpl_metric_container_t mc;
rpl_of_t *of;
uip_ipaddr_t dag_id;
rpl_dag_t *current_dag;
rpl_dag_t dag_table[RPL_MAX_DODAG_PER_INSTANCE];
/* The current default router - used for routing "upwards" */
uip_ds6_defrt_t *def_route;
rpl_rank_t rank;
rpl_rank_t min_rank; /* should be reset per DODAG iteration! */
uint8_t dtsn_out;
uint8_t instance_id;
uint8_t version;
uint8_t grounded;
uint8_t used;
uint8_t dtsn_out;
uint8_t mop;
uint8_t preference;
uint8_t dio_intdoubl;
uint8_t dio_intmin;
uint8_t dio_redundancy;
uint8_t default_lifetime;
uint8_t dio_intcurrent;
uint8_t dio_send; /* for keeping track of which mode the timer is in */
uint8_t dio_counter;
rpl_rank_t max_rankinc;
rpl_rank_t min_hoprankinc;
uint8_t used;
uint8_t default_lifetime;
uint16_t lifetime_unit; /* lifetime in seconds = l_u * d_l */
/* live data for the DAG */
uint8_t joined;
uint8_t dio_intcurrent;
uint8_t dio_send; /* for keeping track of which mode the timer is in
*/
uint8_t dio_counter;
#if RPL_CONF_STATS
uint16_t dio_totint;
uint16_t dio_totsend;
@ -241,19 +318,23 @@ struct rpl_dag {
uint32_t dio_next_delay; /* delay for completion of dio interval */
struct ctimer dio_timer;
struct ctimer dao_timer;
rpl_parent_t *preferred_parent;
void *parent_list;
list_t parents;
rpl_prefix_t prefix_info;
};
typedef struct rpl_dag rpl_dag_t;
/*---------------------------------------------------------------------------*/
/* Public RPL functions. */
void rpl_init(void);
rpl_dag_t *rpl_set_root(uip_ipaddr_t *);
int rpl_set_prefix(rpl_dag_t *dag, uip_ipaddr_t *prefix, int len);
int rpl_repair_dag(rpl_dag_t *dag);
int rpl_set_default_route(rpl_dag_t *dag, uip_ipaddr_t *from);
rpl_dag_t *rpl_get_dag(int instance_id);
void uip_rpl_input(void);
rpl_dag_t *rpl_set_root(uint8_t instance_id, uip_ipaddr_t * dag_id);
int rpl_set_prefix(rpl_dag_t *dag, uip_ipaddr_t *prefix, unsigned len);
int rpl_repair_root(uint8_t instance_id);
int rpl_set_default_route(rpl_instance_t *instance, uip_ipaddr_t *from);
rpl_dag_t *rpl_get_any_dag(void);
rpl_dag_t *rpl_get_dodag(uint8_t instance_id, uip_ipaddr_t *dag_id);
rpl_instance_t *rpl_get_instance(uint8_t instance_id);
void rpl_update_header_empty(void);
int rpl_update_header_final(uip_ipaddr_t *addr);
int rpl_verify_header(int);
void rpl_remove_header(void);
uint8_t rpl_invert_header(void);
/*---------------------------------------------------------------------------*/
#endif /* RPL_H */

View file

@ -27,10 +27,8 @@
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
*
* $Id: tcpip.c,v 1.30 2010/10/29 05:36:07 adamdunkels Exp $
*/
/**
* \file
* Code for tunnelling uIP packets over the Rime mesh routing module
@ -39,29 +37,20 @@
* \author Mathilde Durvy <mdurvy@cisco.com> (IPv6 related code)
* \author Julien Abeille <jabeille@cisco.com> (IPv6 related code)
*/
#include "contiki-net.h"
#include "net/uip-split.h"
#include "net/uip-packetqueue.h"
#include <string.h>
#if UIP_CONF_IPV6
#include "net/uip-nd6.h"
#include "net/uip-ds6.h"
#endif
#define DEBUG 0
#if DEBUG
#include <stdio.h>
#define PRINTF(...) printf(__VA_ARGS__)
#define PRINT6ADDR(addr) PRINTF(" %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x ", ((u8_t *)addr)[0], ((u8_t *)addr)[1], ((u8_t *)addr)[2], ((u8_t *)addr)[3], ((u8_t *)addr)[4], ((u8_t *)addr)[5], ((u8_t *)addr)[6], ((u8_t *)addr)[7], ((u8_t *)addr)[8], ((u8_t *)addr)[9], ((u8_t *)addr)[10], ((u8_t *)addr)[11], ((u8_t *)addr)[12], ((u8_t *)addr)[13], ((u8_t *)addr)[14], ((u8_t *)addr)[15])
#define PRINTLLADDR(lladdr) PRINTF(" %02x:%02x:%02x:%02x:%02x:%02x ",lladdr->addr[0], lladdr->addr[1], lladdr->addr[2], lladdr->addr[3],lladdr->addr[4], lladdr->addr[5])
#else
#define PRINTF(...)
#define PRINT6ADDR(addr)
#endif
#include <string.h>
#define DEBUG DEBUG_NONE
#include "net/uip-debug.h"
#if UIP_LOGGING
#include <stdio.h>
@ -78,21 +67,21 @@ void uip_log(char *msg);
#ifdef UIP_FALLBACK_INTERFACE
extern struct uip_fallback_interface UIP_FALLBACK_INTERFACE;
#endif
#if UIP_CONF_IPV6_RPL
void rpl_init(void);
#include "rpl/rpl.h"
#endif
process_event_t tcpip_event;
#if UIP_CONF_ICMP6
process_event_t tcpip_icmp6_event;
#endif /* UIP_CONF_ICMP6 */
/*static struct tcpip_event_args ev_args;*/
/*periodic check of active connections*/
/* Periodic check of active connections. */
static struct etimer periodic;
#if UIP_CONF_IPV6 && UIP_CONF_IPV6_REASSEMBLY
/*timer for reassembly*/
/* Timer for reassembly. */
extern struct etimer uip_reass_timer;
#endif
@ -412,21 +401,19 @@ eventhandler(process_event_t ev, process_data_t data)
cptr->appstate.p = PROCESS_NONE;
cptr->tcpstateflags = UIP_CLOSED;
}
}
}
#endif /* UIP_TCP */
#if UIP_UDP
{
register struct uip_udp_conn *cptr;
for(cptr = &uip_udp_conns[0];
cptr < &uip_udp_conns[UIP_UDP_CONNS]; ++cptr) {
if(cptr->appstate.p == p) {
cptr->lport = 0;
}
}
}
#endif /* UIP_UDP */
break;
@ -477,12 +464,12 @@ eventhandler(process_event_t ev, process_data_t data)
* check the different timers for neighbor discovery and
* stateless autoconfiguration
*/
/*if(data == &uip_nd6_timer_periodic &&
etimer_expired(&uip_nd6_timer_periodic)) {
uip_nd6_periodic();
/*if(data == &uip_ds6_timer_periodic &&
etimer_expired(&uip_ds6_timer_periodic)) {
uip_ds6_periodic();
tcpip_ipv6_output();
}*/
#if !UIP_CONF_ROUTER
#if !UIP_CONF_ROUTER
if(data == &uip_ds6_timer_rs &&
etimer_expired(&uip_ds6_timer_rs)){
uip_ds6_send_rs();
@ -551,22 +538,24 @@ void
tcpip_ipv6_output(void)
{
uip_ds6_nbr_t *nbr = NULL;
uip_ipaddr_t* nexthop;
uip_ipaddr_t *nexthop;
if(uip_len == 0) {
return;
}
if(uip_len > UIP_LINK_MTU) {
UIP_LOG("tcpip_ipv6_output: Packet to big");
uip_len = 0;
return;
}
if(uip_is_addr_unspecified(&UIP_IP_BUF->destipaddr)){
UIP_LOG("tcpip_ipv6_output: Destination address unspecified");
uip_len = 0;
return;
}
if(!uip_is_addr_mcast(&UIP_IP_BUF->destipaddr)) {
/* Next hop determination */
nbr = NULL;
@ -578,10 +567,18 @@ tcpip_ipv6_output(void)
if(locrt == NULL) {
if((nexthop = uip_ds6_defrt_choose()) == NULL) {
#ifdef UIP_FALLBACK_INTERFACE
printf("FALLBACK: removing ext hdrs & setting proto %d %d\n",
uip_ext_len, *((uint8_t *)UIP_IP_BUF + 40));
if(uip_ext_len > 0) {
uint8_t proto = *((uint8_t *)UIP_IP_BUF + 40);
remove_ext_hdr();
/* This should be copied from the ext header... */
UIP_IP_BUF->proto = proto;
}
UIP_FALLBACK_INTERFACE.output();
#else
PRINTF("tcpip_ipv6_output: Destination off-link but no route\n");
#endif
#endif /* !UIP_FALLBACK_INTERFACE */
uip_len = 0;
return;
}
@ -589,16 +586,20 @@ tcpip_ipv6_output(void)
nexthop = &locrt->nexthop;
}
}
/* end of next hop determination */
/* End of next hop determination */
#if UIP_CONF_IPV6_RPL
if(rpl_update_header_final(nexthop)) {
uip_len = 0;
return;
}
#endif /* UIP_CONF_IPV6_RPL */
if((nbr = uip_ds6_nbr_lookup(nexthop)) == NULL) {
// printf("add1 %d\n", nexthop->u8[15]);
if((nbr = uip_ds6_nbr_add(nexthop, NULL, 0, NBR_INCOMPLETE)) == NULL) {
// printf("add n\n");
uip_len = 0;
return;
} else {
#if UIP_CONF_IPV6_QUEUE_PKT
/* copy outgoing pkt in the queuing buffer for later transmmit */
/* Copy outgoing pkt in the queuing buffer for later transmit. */
if(uip_packetqueue_alloc(&nbr->packethandle, UIP_DS6_NBR_PACKET_LIFETIME) != NULL) {
memcpy(uip_packetqueue_buf(&nbr->packethandle), UIP_IP_BUF, uip_len);
uip_packetqueue_set_buflen(&nbr->packethandle, uip_len);
@ -616,59 +617,47 @@ tcpip_ipv6_output(void)
uip_nd6_ns_output(NULL, NULL, &nbr->ipaddr);
}
stimer_set(&(nbr->sendns), uip_ds6_if.retrans_timer / 1000);
stimer_set(&nbr->sendns, uip_ds6_if.retrans_timer / 1000);
nbr->nscount = 1;
}
} else {
if(nbr->state == NBR_INCOMPLETE) {
PRINTF("tcpip_ipv6_output: nbr cache entry incomplete\n");
#if UIP_CONF_IPV6_QUEUE_PKT
/* copy outgoing pkt in the queuing buffer for later transmmit and set
the destination nbr to nbr */
/* Copy outgoing pkt in the queuing buffer for later transmit and set
the destination nbr to nbr. */
if(uip_packetqueue_alloc(&nbr->packethandle, UIP_DS6_NBR_PACKET_LIFETIME) != NULL) {
memcpy(uip_packetqueue_buf(&nbr->packethandle), UIP_IP_BUF, uip_len);
uip_packetqueue_set_buflen(&nbr->packethandle, uip_len);
}
/* memcpy(nbr->queue_buf, UIP_IP_BUF, uip_len);
nbr->queue_buf_len = uip_len;*/
#endif /*UIP_CONF_IPV6_QUEUE_PKT*/
uip_len = 0;
return;
}
/* if running NUD (nbc->state == STALE, DELAY, or PROBE ) keep
sending in parallel see rfc 4861 Node behavior in section 7.7.3*/
/* Send in parallel if we are running NUD (nbc state is either STALE,
DELAY, or PROBE). See RFC 4861, section 7.7.3 on node behavior. */
if(nbr->state == NBR_STALE) {
nbr->state = NBR_DELAY;
stimer_set(&(nbr->reachable),
UIP_ND6_DELAY_FIRST_PROBE_TIME);
stimer_set(&nbr->reachable, UIP_ND6_DELAY_FIRST_PROBE_TIME);
nbr->nscount = 0;
PRINTF("tcpip_ipv6_output: nbr cache entry stale moving to delay\n");
}
stimer_set(&(nbr->sendns),
uip_ds6_if.retrans_timer / 1000);
tcpip_output(&(nbr->lladdr));
stimer_set(&nbr->sendns, uip_ds6_if.retrans_timer / 1000);
tcpip_output(&nbr->lladdr);
#if UIP_CONF_IPV6_QUEUE_PKT
/* Send the queued packets from here, may not be 100% perfect though.
/*
* Send the queued packets from here, may not be 100% perfect though.
* This happens in a few cases, for example when instead of receiving a
* NA after sendiong a NS, you receive a NS with SLLAO: the entry moves
*to STALE, and you must both send a NA and the queued packet
* to STALE, and you must both send a NA and the queued packet.
*/
/* if(nbr->queue_buf_len != 0) {
uip_len = nbr->queue_buf_len;
memcpy(UIP_IP_BUF, nbr->queue_buf, uip_len);
nbr->queue_buf_len = 0;
tcpip_output(&(nbr->lladdr));
}*/
if(uip_packetqueue_buflen(&nbr->packethandle) != 0) {
uip_len = uip_packetqueue_buflen(&nbr->packethandle);
memcpy(UIP_IP_BUF, uip_packetqueue_buf(&nbr->packethandle), uip_len);
uip_packetqueue_free(&nbr->packethandle);
tcpip_output(&(nbr->lladdr));
tcpip_output(&nbr->lladdr);
}
#endif /*UIP_CONF_IPV6_QUEUE_PKT*/
@ -676,14 +665,13 @@ tcpip_ipv6_output(void)
return;
}
}
/*multicast IP destination address */
/* Multicast IP destination address. */
tcpip_output(NULL);
uip_len = 0;
uip_ext_len = 0;
}
#endif
#endif /* UIP_CONF_IPV6 */
/*---------------------------------------------------------------------------*/
#if UIP_UDP
void

View file

@ -5,9 +5,9 @@
/**
* \file
* IPv6 data structures handling functions
* IPv6 data structures handling functions.
* Comprises part of the Neighbor discovery (RFC 4861)
* and auto configuration (RFC 4862 )state machines
* and auto configuration (RFC 4862) state machines.
* \author Mathilde Durvy <mdurvy@cisco.com>
* \author Julien Abeille <jabeille@cisco.com>
*/
@ -148,16 +148,19 @@ uip_ds6_init(void)
void
uip_ds6_periodic(void)
{
/* Periodic processing on unicast addresses */
for(locaddr = uip_ds6_if.addr_list;
locaddr < uip_ds6_if.addr_list + UIP_DS6_ADDR_NB; locaddr++) {
if(locaddr->isused) {
if((!locaddr->isinfinite) && (stimer_expired(&locaddr->vlifetime))) {
uip_ds6_addr_rm(locaddr);
#if UIP_ND6_DEF_MAXDADNS > 0
} else if((locaddr->state == ADDR_TENTATIVE)
&& (locaddr->dadnscount <= uip_ds6_if.maxdadns)
&& (timer_expired(&locaddr->dadtimer))) {
uip_ds6_dad(locaddr);
#endif /* UIP_ND6_DEF_MAXDADNS > 0 */
}
}
}
@ -366,6 +369,24 @@ uip_ds6_nbr_lookup(uip_ipaddr_t *ipaddr)
return NULL;
}
/*---------------------------------------------------------------------------*/
uip_ds6_nbr_t *
uip_ds6_nbr_ll_lookup(uip_lladdr_t *lladdr)
{
uip_ds6_nbr_t *fin;
for(locnbr = uip_ds6_nbr_cache, fin = locnbr + UIP_DS6_NBR_NB;
locnbr < fin;
++locnbr) {
if(locnbr->isused) {
if(!memcmp(lladdr, &locnbr->lladdr, UIP_LLADDR_LEN)) {
return locnbr;
}
}
}
return NULL;
}
/*---------------------------------------------------------------------------*/
uip_ds6_defrt_t *
uip_ds6_defrt_add(uip_ipaddr_t *ipaddr, unsigned long interval)
@ -549,7 +570,6 @@ uip_ds6_addr_add(uip_ipaddr_t *ipaddr, unsigned long vlifetime, uint8_t type)
(uip_ds6_element_t **)&locaddr) == FREESPACE) {
locaddr->isused = 1;
uip_ipaddr_copy(&locaddr->ipaddr, ipaddr);
locaddr->state = ADDR_TENTATIVE;
locaddr->type = type;
if(vlifetime == 0) {
locaddr->isinfinite = 1;
@ -557,10 +577,15 @@ uip_ds6_addr_add(uip_ipaddr_t *ipaddr, unsigned long vlifetime, uint8_t type)
locaddr->isinfinite = 0;
stimer_set(&(locaddr->vlifetime), vlifetime);
}
#if UIP_ND6_DEF_MAXDADNS > 0
locaddr->state = ADDR_TENTATIVE;
timer_set(&locaddr->dadtimer,
random_rand() % (UIP_ND6_MAX_RTR_SOLICITATION_DELAY *
CLOCK_SECOND));
locaddr->dadnscount = 0;
#else /* UIP_ND6_DEF_MAXDADNS > 0 */
locaddr->state = ADDR_PREFERRED;
#endif /* UIP_ND6_DEF_MAXDADNS > 0 */
uip_create_solicited_node(ipaddr, &loc_fipaddr);
uip_ds6_maddr_add(&loc_fipaddr);
return locaddr;
@ -759,6 +784,10 @@ uip_ds6_route_add(uip_ipaddr_t *ipaddr, uint8_t length, uip_ipaddr_t *nexthop,
uip_ipaddr_copy(&(locroute->nexthop), nexthop);
locroute->metric = metric;
#ifdef UIP_DS6_ROUTE_STATE_TYPE
memset(&locroute->state, 0, sizeof(UIP_DS6_ROUTE_STATE_TYPE));
#endif
PRINTF("DS6: adding route: ");
PRINT6ADDR(ipaddr);
PRINTF(" via ");
@ -884,6 +913,7 @@ get_match_length(uip_ipaddr_t *src, uip_ipaddr_t *dst)
}
/*---------------------------------------------------------------------------*/
#if UIP_ND6_DEF_MAXDADNS > 0
void
uip_ds6_dad(uip_ds6_addr_t *addr)
{
@ -922,10 +952,11 @@ uip_ds6_dad_failed(uip_ds6_addr_t * addr)
uip_ds6_addr_rm(addr);
return 1;
}
#endif /*UIP_ND6_DEF_MAXDADNS > 0 */
/*---------------------------------------------------------------------------*/
#if UIP_CONF_ROUTER
#if UIP_ND6_SEND_RA
/*---------------------------------------------------------------------------*/
void
uip_ds6_send_ra_sollicited(void)
{

View file

@ -124,6 +124,13 @@
#endif
#define UIP_DS6_AADDR_NB UIP_DS6_AADDR_NBS + UIP_DS6_AADDR_NBU
/*--------------------------------------------------*/
/* Should we use LinkLayer acks in NUD ?*/
#ifndef UIP_CONF_DS6_LL_NUD
#define UIP_DS6_LL_NUD 0
#else
#define UIP_DS6_LL_NUD UIP_CONF_DS6_LL_NUD
#endif
/*--------------------------------------------------*/
/** \brief Possible states for the nbr cache entries */
@ -209,8 +216,10 @@ typedef struct uip_ds6_addr {
uint8_t type;
uint8_t isinfinite;
struct stimer vlifetime;
#if UIP_ND6_DEF_MAXDADNS > 0
struct timer dadtimer;
uint8_t dadnscount;
#endif /* UIP_ND6_DEF_MAXDADNS > 0 */
} uip_ds6_addr_t;
/** \brief Anycast address */
@ -310,6 +319,7 @@ uip_ds6_nbr_t *uip_ds6_nbr_add(uip_ipaddr_t *ipaddr, uip_lladdr_t *lladdr,
uint8_t isrouter, uint8_t state);
void uip_ds6_nbr_rm(uip_ds6_nbr_t *nbr);
uip_ds6_nbr_t *uip_ds6_nbr_lookup(uip_ipaddr_t *ipaddr);
uip_ds6_nbr_t *uip_ds6_nbr_ll_lookup(uip_lladdr_t *lladdr);
/** @} */
@ -385,11 +395,13 @@ void uip_ds6_set_addr_iid(uip_ipaddr_t * ipaddr, uip_lladdr_t * lladdr);
/** \brief Get the number of matching bits of two addresses */
uint8_t get_match_length(uip_ipaddr_t * src, uip_ipaddr_t * dst);
#if UIP_ND6_DEF_MAXDADNS >0
/** \brief Perform Duplicate Address Selection on one address */
void uip_ds6_dad(uip_ds6_addr_t * ifaddr);
/** \brief Callback when DAD failed */
int uip_ds6_dad_failed(uip_ds6_addr_t * ifaddr);
#endif /* UIP_ND6_DEF_MAXDADNS */
/** \brief Source address selection, see RFC 3484 */
void uip_ds6_select_src(uip_ipaddr_t * src, uip_ipaddr_t * dst);

View file

@ -60,14 +60,25 @@
#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
#define UIP_ICMP_BUF ((struct uip_icmp_hdr *)&uip_buf[uip_l2_l3_hdr_len])
#define UIP_ICMP6_ERROR_BUF ((struct uip_icmp6_error *)&uip_buf[uip_l2_l3_icmp_hdr_len])
#if UIP_CONF_IPV6_RPL
#define UIP_EXT_BUF ((struct uip_ext_hdr *)&uip_buf[uip_l2_l3_hdr_len])
#define UIP_FIRST_EXT_BUF ((struct uip_ext_hdr *)&uip_buf[UIP_LLIPH_LEN])
#endif /* UIP_CONF_IPV6_RPL */
/** \brief temporary IP address */
static uip_ipaddr_t tmp_ipaddr;
#if UIP_CONF_IPV6_RPL
#include "rpl/rpl.h"
#endif /* UIP_CONF_IPV6_RPL */
/*---------------------------------------------------------------------------*/
void
uip_icmp6_echo_request_input(void)
{
#if UIP_CONF_IPV6_RPL
u8_t temp_ext_len;
#endif /* UIP_CONF_IPV6_RPL */
/*
* we send an echo reply. It is trivial if there was no extension
* headers in the request otherwise we need to remove the extension
@ -78,7 +89,7 @@ uip_icmp6_echo_request_input(void)
PRINTF("to");
PRINT6ADDR(&UIP_IP_BUF->destipaddr);
PRINTF("\n");
/* IP header */
UIP_IP_BUF->ttl = uip_ds6_if.cur_hop_limit;
@ -92,30 +103,54 @@ uip_icmp6_echo_request_input(void)
}
if(uip_ext_len > 0) {
/* If there were extension headers*/
UIP_IP_BUF->proto = UIP_PROTO_ICMP6;
uip_len -= uip_ext_len;
UIP_IP_BUF->len[0] = ((uip_len - UIP_IPH_LEN) >> 8);
UIP_IP_BUF->len[1] = ((uip_len - UIP_IPH_LEN) & 0xff);
/* move the echo request payload (starting after the icmp header)
* to the new location in the reply.
* The shift is equal to the length of the extension headers present
* Note: UIP_ICMP_BUF still points to the echo request at this stage
*/
memmove((uint8_t *)UIP_ICMP_BUF + UIP_ICMPH_LEN - uip_ext_len,
(uint8_t *)UIP_ICMP_BUF + UIP_ICMPH_LEN,
(uip_len - UIP_IPH_LEN - UIP_ICMPH_LEN));
#if UIP_CONF_IPV6_RPL
if ((temp_ext_len=rpl_invert_header())) {
/* If there were other extension headers*/
UIP_FIRST_EXT_BUF->next = UIP_PROTO_ICMP6;
if (uip_ext_len != temp_ext_len) {
uip_len -= (uip_ext_len - temp_ext_len);
UIP_IP_BUF->len[0] = ((uip_len - UIP_IPH_LEN) >> 8);
UIP_IP_BUF->len[1] = ((uip_len - UIP_IPH_LEN) & 0xff);
/* move the echo request payload (starting after the icmp header)
* to the new location in the reply.
* The shift is equal to the length of the remaining extension headers present
* Note: UIP_ICMP_BUF still points to the echo request at this stage
*/
memmove((uint8_t *)UIP_ICMP_BUF + UIP_ICMPH_LEN - (uip_ext_len - temp_ext_len),
(uint8_t *)UIP_ICMP_BUF + UIP_ICMPH_LEN,
(uip_len - UIP_IPH_LEN - temp_ext_len - UIP_ICMPH_LEN));
}
uip_ext_len=temp_ext_len;
} else {
#endif /* UIP_CONF_IPV6_RPL */
/* If there were extension headers*/
UIP_IP_BUF->proto = UIP_PROTO_ICMP6;
uip_len -= uip_ext_len;
UIP_IP_BUF->len[0] = ((uip_len - UIP_IPH_LEN) >> 8);
UIP_IP_BUF->len[1] = ((uip_len - UIP_IPH_LEN) & 0xff);
/* move the echo request payload (starting after the icmp header)
* to the new location in the reply.
* The shift is equal to the length of the extension headers present
* Note: UIP_ICMP_BUF still points to the echo request at this stage
*/
memmove((uint8_t *)UIP_ICMP_BUF + UIP_ICMPH_LEN - uip_ext_len,
(uint8_t *)UIP_ICMP_BUF + UIP_ICMPH_LEN,
(uip_len - UIP_IPH_LEN - UIP_ICMPH_LEN));
uip_ext_len = 0;
#if UIP_CONF_IPV6_RPL
}
#endif /* UIP_CONF_IPV6_RPL */
}
/* Below is important for the correctness of UIP_ICMP_BUF and the
* checksum
*/
uip_ext_len = 0;
/* Note: now UIP_ICMP_BUF points to the beginning of the echo reply */
UIP_ICMP_BUF->type = ICMP6_ECHO_REPLY;
UIP_ICMP_BUF->icode = 0;
UIP_ICMP_BUF->icmpchksum = 0;
UIP_ICMP_BUF->icmpchksum = ~uip_icmp6chksum();
PRINTF("Sending Echo Reply to");
PRINT6ADDR(&UIP_IP_BUF->destipaddr);
PRINTF("from");
@ -127,29 +162,45 @@ uip_icmp6_echo_request_input(void)
/*---------------------------------------------------------------------------*/
void
uip_icmp6_error_output(u8_t type, u8_t code, u32_t param) {
uip_ext_len = 0;
/* check if originating packet is not an ICMP error*/
if(UIP_IP_BUF->proto == UIP_PROTO_ICMP6 && UIP_ICMP_BUF->type < 128){
uip_len = 0;
return;
if (uip_ext_len) {
if(UIP_EXT_BUF->next == UIP_PROTO_ICMP6 && UIP_ICMP_BUF->type < 128){
uip_len = 0;
return;
}
} else {
if(UIP_IP_BUF->proto == UIP_PROTO_ICMP6 && UIP_ICMP_BUF->type < 128){
uip_len = 0;
return;
}
}
/* remember data of original packet before shifting */
uip_ipaddr_copy(&tmp_ipaddr, &UIP_IP_BUF->destipaddr);
uip_len += UIP_IPICMPH_LEN + UIP_ICMP6_ERROR_LEN;
if(uip_len > UIP_LINK_MTU)
uip_len = UIP_LINK_MTU;
#if UIP_CONF_IPV6_RPL
uip_ext_len = rpl_invert_header();
#else /* UIP_CONF_IPV6_RPL */
uip_ext_len = 0;
#endif /* UIP_CONF_IPV6_RPL */
memmove((uint8_t *)UIP_ICMP6_ERROR_BUF + UIP_ICMP6_ERROR_LEN,
(void *)UIP_IP_BUF, uip_len - UIP_IPICMPH_LEN - UIP_ICMP6_ERROR_LEN);
/* remember data of original packet before shifting */
uip_ipaddr_copy(&tmp_ipaddr, &UIP_IP_BUF->destipaddr);
uip_len += UIP_IPICMPH_LEN + UIP_ICMP6_ERROR_LEN;
if(uip_len > UIP_LINK_MTU)
uip_len = UIP_LINK_MTU;
memmove((uint8_t *)UIP_ICMP6_ERROR_BUF + uip_ext_len + UIP_ICMP6_ERROR_LEN,
(void *)UIP_IP_BUF, uip_len - UIP_IPICMPH_LEN - uip_ext_len - UIP_ICMP6_ERROR_LEN);
UIP_IP_BUF->vtc = 0x60;
UIP_IP_BUF->tcflow = 0;
UIP_IP_BUF->flow = 0;
UIP_IP_BUF->proto = UIP_PROTO_ICMP6;
if (uip_ext_len) {
UIP_FIRST_EXT_BUF->next = UIP_PROTO_ICMP6;
} else {
UIP_IP_BUF->proto = UIP_PROTO_ICMP6;
}
UIP_IP_BUF->ttl = uip_ds6_if.cur_hop_limit;
/* the source should not be unspecified nor multicast, the check for
@ -158,7 +209,7 @@ uip_icmp6_error_output(u8_t type, u8_t code, u32_t param) {
uip_len = 0;
return;
}
uip_ipaddr_copy(&UIP_IP_BUF->destipaddr, &UIP_IP_BUF->srcipaddr);
if(uip_is_addr_mcast(&tmp_ipaddr)){
@ -176,7 +227,7 @@ uip_icmp6_error_output(u8_t type, u8_t code, u32_t param) {
uip_ipaddr_copy(&UIP_IP_BUF->srcipaddr, &tmp_ipaddr);
#endif
}
UIP_ICMP_BUF->type = type;
UIP_ICMP_BUF->icode = code;
UIP_ICMP6_ERROR_BUF->param = uip_htonl(param);

View file

@ -76,16 +76,7 @@
/*------------------------------------------------------------------*/
#define DEBUG 0
#if DEBUG
#include <stdio.h>
#define PRINTF(...) printf(__VA_ARGS__)
#define PRINT6ADDR(addr) PRINTF(" %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x ", ((u8_t *)addr)[0], ((u8_t *)addr)[1], ((u8_t *)addr)[2], ((u8_t *)addr)[3], ((u8_t *)addr)[4], ((u8_t *)addr)[5], ((u8_t *)addr)[6], ((u8_t *)addr)[7], ((u8_t *)addr)[8], ((u8_t *)addr)[9], ((u8_t *)addr)[10], ((u8_t *)addr)[11], ((u8_t *)addr)[12], ((u8_t *)addr)[13], ((u8_t *)addr)[14], ((u8_t *)addr)[15])
#define PRINTLLADDR(lladdr) PRINTF(" %02x:%02x:%02x:%02x:%02x:%02x ",lladdr->addr[0], lladdr->addr[1], lladdr->addr[2], lladdr->addr[3],lladdr->addr[4], lladdr->addr[5])
#else
#define PRINTF(...)
#define PRINT6ADDR(addr)
#define PRINTLLADDR(addr)
#endif
#include "net/uip-debug.h"
#if UIP_LOGGING
#include <stdio.h>
@ -154,11 +145,11 @@ create_llao(uint8_t *llao, uint8_t type) {
void
uip_nd6_ns_input(void)
{
PRINTF("Received NS from");
PRINTF("Received NS from ");
PRINT6ADDR(&UIP_IP_BUF->srcipaddr);
PRINTF("to");
PRINTF(" to ");
PRINT6ADDR(&UIP_IP_BUF->destipaddr);
PRINTF("with target address");
PRINTF(" with target address");
PRINT6ADDR((uip_ipaddr_t *) (&UIP_ND6_NS_BUF->tgtipaddr));
PRINTF("\n");
UIP_STAT(++uip_stat.nd6.recv);
@ -224,6 +215,7 @@ uip_nd6_ns_input(void)
addr = uip_ds6_addr_lookup(&UIP_ND6_NS_BUF->tgtipaddr);
if(addr != NULL) {
#if UIP_ND6_DEF_MAXDADNS > 0
if(uip_is_addr_unspecified(&UIP_IP_BUF->srcipaddr)) {
/* DAD CASE */
#if UIP_CONF_IPV6_CHECKS
@ -242,6 +234,11 @@ uip_nd6_ns_input(void)
uip_ds6_dad_failed(addr);
goto discard;
}
#else /* UIP_ND6_DEF_MAXDADNS > 0 */
if(uip_is_addr_unspecified(&UIP_IP_BUF->srcipaddr)) {
/* DAD CASE */
goto discard;
#endif /* UIP_ND6_DEF_MAXDADNS > 0 */
}
#if UIP_CONF_IPV6_CHECKS
if(uip_ds6_is_my_addr(&UIP_IP_BUF->srcipaddr)) {
@ -307,11 +304,11 @@ create_na:
UIP_IPH_LEN + UIP_ICMPH_LEN + UIP_ND6_NA_LEN + UIP_ND6_OPT_LLAO_LEN;
UIP_STAT(++uip_stat.nd6.sent);
PRINTF("Sending NA to");
PRINTF("Sending NA to ");
PRINT6ADDR(&UIP_IP_BUF->destipaddr);
PRINTF("from");
PRINTF(" from ");
PRINT6ADDR(&UIP_IP_BUF->srcipaddr);
PRINTF("with target address");
PRINTF(" with target address ");
PRINT6ADDR(&UIP_ND6_NA_BUF->tgtipaddr);
PRINTF("\n");
return;
@ -441,9 +438,11 @@ uip_nd6_na_input(void)
addr = uip_ds6_addr_lookup(&UIP_ND6_NA_BUF->tgtipaddr);
/* Message processing, including TLLAO if any */
if(addr != NULL) {
#if UIP_ND6_DEF_MAXDADNS > 0
if(addr->state == ADDR_TENTATIVE) {
uip_ds6_dad_failed(addr);
}
#endif /*UIP_ND6_DEF_MAXDADNS > 0 */
PRINTF("NA received is bad\n");
goto discard;
} else {

View file

@ -48,8 +48,8 @@
#include "net/uip.h"
#include "sys/stimer.h"
/**
* \name General
* @{
* \name General
* @{
*/
/** \brief HOP LIMIT to be used when sending ND messages (255) */
#define UIP_ND6_HOP_LIMIT 255
@ -57,29 +57,21 @@
#define UIP_ND6_INFINITE_LIFETIME 0xFFFFFFFF
/** @} */
#ifndef UIP_CONF_ND6_DEF_MAXDADNS
/** \brief Do not try DAD when using EUI-64 as allowed by draft-ietf-6lowpan-nd-15 section 8.2 */
#if UIP_CONF_LL_802154
#define UIP_ND6_DEF_MAXDADNS 0
#else /* UIP_CONF_LL_802154 */
#define UIP_ND6_DEF_MAXDADNS 1
/** \name Configuration options */
/** @{ */
#ifndef UIP_CONF_ND6_MAX_NEIGHBORS
/** \brief max number of entries in the neighbor cache */
#define UIP_CONF_ND6_MAX_NEIGHBORS 4
#endif /*UIP_CONF_ND6_MAX_NEIGHBORS*/
#ifndef UIP_CONF_ND6_MAX_DEFROUTERS
/** \brief max number of entries in the default router cache */
#define UIP_CONF_ND6_MAX_DEFROUTERS 2
#endif /*UIP_CONF_ND6_MAX_DEFROUTERS*/
#ifndef UIP_CONF_ND6_MAX_PREFIXES
/** \brief max number of entries in the prefix list */
#define UIP_CONF_ND6_MAX_PREFIXES 2
#endif /*UIP_CONF_ND6_MAX_PREFIXES*/
/** @} */
#endif /* UIP_CONF_LL_802154 */
#else /* UIP_CONF_ND6_DEF_MAXDADNS */
#define UIP_ND6_DEF_MAXDADNS UIP_CONF_ND6_DEF_MAXDADNS
#endif /* UIP_CONF_ND6_DEF_MAXDADNS */
/** \name RFC 4861 Host constant */
/** @{ */
#define UIP_ND6_MAX_RTR_SOLICITATION_DELAY 1
#define UIP_ND6_RTR_SOLICITATION_INTERVAL 4
#define UIP_ND6_MAX_RTR_SOLICITATION_DELAY 1
#define UIP_ND6_RTR_SOLICITATION_INTERVAL 4
#define UIP_ND6_MAX_RTR_SOLICITATIONS 3
/** @} */
@ -115,7 +107,7 @@
#ifdef UIP_CONF_ND6_RETRANS_TIMER
#define UIP_ND6_RETRANS_TIMER UIP_CONF_ND6_RETRANS_TIMER
#else
#define UIP_ND6_RETRANS_TIMER 1000
#define UIP_ND6_RETRANS_TIMER 1000
#endif
#define UIP_ND6_DELAY_FIRST_PROBE_TIME 5
#define UIP_ND6_MIN_RANDOM_FACTOR(x) (x / 2)
@ -140,8 +132,8 @@
/** \name ND6 message length (excluding options) */
/** @{ */
#define UIP_ND6_NA_LEN 20
#define UIP_ND6_NS_LEN 20
#define UIP_ND6_NA_LEN 20
#define UIP_ND6_NS_LEN 20
#define UIP_ND6_RA_LEN 12
#define UIP_ND6_RS_LEN 4
/** @} */
@ -160,7 +152,7 @@
#define UIP_ND6_OPT_SHORT_LLAO_LEN 8
#define UIP_ND6_OPT_LONG_LLAO_LEN 16
/** \brief length of a ND6 LLAO option for 802.15.4 */
#define UIP_ND6_OPT_LLAO_LEN UIP_ND6_OPT_LONG_LLAO_LEN
#define UIP_ND6_OPT_LLAO_LEN UIP_ND6_OPT_LONG_LLAO_LEN
#else /*UIP_CONF_LL_802154*/
#if UIP_CONF_LL_80211
/* If the interface is 802.11 */
@ -179,93 +171,18 @@
#define UIP_ND6_NA_FLAG_ROUTER 0x80
#define UIP_ND6_NA_FLAG_SOLICITED 0x40
#define UIP_ND6_NA_FLAG_OVERRIDE 0x20
#define UIP_ND6_RA_FLAG_ONLINK 0x80
#define UIP_ND6_RA_FLAG_AUTONOMOUS 0x40
#define UIP_ND6_RA_FLAG_ONLINK 0x80
#define UIP_ND6_RA_FLAG_AUTONOMOUS 0x40
/** @} */
/**
* \brief Possible states for the neighbor cache entries
*
* NO_STATE is for implementation purposes: a router entry contains a pointer
* to a neighbor entry, which holds its ip address. If we do not know the LL
* address of the router, we do not have to create a neighbor entry as per
* RFC 4861. However, we still need to have the IP of the router stored in a
* neighbor entry, hence we create an entry in the NO_STATE state
*/
typedef enum {
INCOMPLETE = 0,
REACHABLE = 1,
STALE = 2,
DELAY = 3,
PROBE = 4,
NO_STATE = 5
} uip_neighbor_state;
/**
* \name ND structures
* @{
*/
/** \brief An entry in the neighbor cache */
struct uip_nd6_neighbor {
uip_ipaddr_t ipaddr;
uip_lladdr_t lladdr;
u8_t isrouter;
uip_neighbor_state state;
struct stimer reachable;
struct stimer last_send; /**< last time a ND message was sent */
u8_t count_send; /**< how many ND message were already sent */
u8_t used; /**< brief is this neighbor currently used */
#if UIP_CONF_IPV6_QUEUE_PKT
u8_t queue_buf[UIP_BUFSIZE - UIP_LLH_LEN];
/**< buffer to hold one packet during address resolution */
u8_t queue_buf_len;
/**< length of the pkt in buffer, used as "boolean" as well*/
#endif /*UIP_CONF_QUEUE_PKT*/
};
/** \brief An entry in the default router list */
struct uip_nd6_defrouter {
struct uip_nd6_neighbor *nb;
struct stimer lifetime;
/**< the lifetime contained in RA corresponds to the interval field
* of the timer
*/
u8_t used; /**< Is this default router entry currently used */
};
/** \brief A prefix list entry */
struct uip_nd6_prefix {
uip_ipaddr_t ipaddr;
u8_t length;
/**< we do not use preferred lifetime, which is always smaller than
* valid lifetime (for addr, preferred->deprecated)
*/
struct stimer vlifetime;
u8_t is_infinite; /**< Is the prefix lifetime INFINITE */
u8_t used; /**< Is this prefix entry currently used */
};
/** @} */
extern struct etimer uip_nd6_timer_periodic;
/**
* \note
* We do not use a destination cache, do next-hop determination each time
* a packet needs to be sent. (info such as rtt, path mtu could be stored
* in uip_conn)
*
*/
/**
* \name ND message structures
* @{
*/
/**
/**
* \brief A neighbor solicitation constant part
*
*
* Possible option is: SLLAO
*/
typedef struct uip_nd6_ns {
@ -275,19 +192,19 @@ typedef struct uip_nd6_ns {
/**
* \brief A neighbor advertisement constant part.
*
*
* Possible option is: TLLAO
*/
*/
typedef struct uip_nd6_na {
uint8_t flagsreserved;
uint8_t reserved[3];
uip_ipaddr_t tgtipaddr;
} uip_nd6_na;
/**
/**
* \brief A router solicitation constant part
*
* Possible option is: SLLAO
*
* Possible option is: SLLAO
*/
typedef struct uip_nd6_rs {
uint32_t reserved;
@ -295,7 +212,7 @@ typedef struct uip_nd6_rs {
/**
* \brief A router advertisement constant part
*
*
* Possible options are: SLLAO, MTU, Prefix Information
*/
typedef struct uip_nd6_ra {
@ -308,13 +225,13 @@ typedef struct uip_nd6_ra {
/**
* \brief A redirect message constant part
*
*
* Possible options are: TLLAO, redirected header
*/
typedef struct uip_nd6_redirect {
uint32_t reserved;
uip_ipaddr_t tgtipaddress;
uip_ipaddr_t destipaddress;
uip_ipaddr_t tgtipaddress;
uip_ipaddr_t destipaddress;
} uip_nd6_redirect;
/** @} */
@ -357,102 +274,6 @@ typedef struct uip_nd6_opt_redirected_hdr {
} uip_nd6_opt_redirected_hdr;
/** @} */
/**
* \name ND Neighbor Cache, Router List and Prefix List handling functions
* @{
*/
/**
* \brief Initialize Neighbor Discovery structures
*/
void uip_nd6_init(void);
/**
* \brief Periodic processing of Neighbor Discovery Structures
*/
void uip_nd6_periodic(void);
/**
* \brief Look for a neighbor cache entry corresponding to a specific IP
* address
* \param ipaddr the specific IP address
* \return the corresponding neighbor cache entry
*/
struct uip_nd6_neighbor *uip_nd6_nbrcache_lookup(uip_ipaddr_t *ipaddr);
/**
* \brief Add a neighbor cache entry
* \param ipaddr the IP address of the entry
* \param lladdr the layer 2 address of the entry
* \param isrouter true is the entry is a router
* \param state the state of the entry
* \return the new neighbor or updated cache entry
*/
struct uip_nd6_neighbor * uip_nd6_nbrcache_add(uip_ipaddr_t *ipaddr,
uip_lladdr_t *lladdr,
u8_t isrouter,
uip_neighbor_state state);
/**
* \brief Returns a default router
*/
struct uip_nd6_defrouter * uip_nd6_choose_defrouter(void);
/**
* \brief Find a default router corresponding to a given neighbor cache entry
* \param neighbor the neighbor cache entry
* \return the corresponding router if any
*/
struct uip_nd6_defrouter *
uip_nd6_defrouter_lookup(struct uip_nd6_neighbor *neighbor);
/**
* \brief Remove a default router
* \param router to be removed
*/
void uip_nd6_defrouter_rm(struct uip_nd6_defrouter *router);
/**
* \brief Add a default router
* \param neighbor the corresponding neighbor cache entry
* \param interval the lifetime of the router
* \return the new or updated defrouter entry
*/
struct uip_nd6_defrouter *
uip_nd6_defrouter_add(struct uip_nd6_neighbor *neighbor, unsigned long interval);
/**
* \brief Check if an IP address in on-link by looking at prefix list
* \param ipaddr an IP address
* \return true if on-link
*/
u8_t uip_nd6_is_addr_onlink(uip_ipaddr_t *ipaddr);
/**
* \brief Find a given prefix
* \param ipaddr an IP address
* \return the corresponding prefix if any
*/
struct uip_nd6_prefix *
uip_nd6_prefix_lookup(uip_ipaddr_t *ipaddr);
/**
* \brief Add a prefix
* \param ipaddr the IP address of the prefix
* \param length the length of the prefix
* \param interval the lifetime of the prefix
* \return the new or updated prefix entry
*/
struct uip_nd6_prefix *
uip_nd6_prefix_add(uip_ipaddr_t *ipaddr, u8_t length, unsigned long interval);
/**
* \brief Remove a prefix from th eprefix list
* \param prefix pointer to the prefix to be removed
*/
void
uip_nd6_prefix_rm(struct uip_nd6_prefix *prefix);
/** @} */
/**
* \name ND Messages Processing and Generation
* @{
@ -467,7 +288,7 @@ void
* address)
*
* We do:
* - if the tgt belongs to me, reply, otherwise ignore
* - if the tgt belongs to me, reply, otherwise ignore
* - if i was performing DAD for the same address, two cases:
* -- I already sent a NS, hence I win
* -- I did not send a NS yet, hence I lose
@ -476,13 +297,13 @@ void
* address resolution, or DAD and there is a conflict), we do it in this
* function: set src, dst, tgt address in the three cases, then for all cases
* set the rest, including SLLAO
*
*
*/
void
uip_nd6_ns_input(void);
/**
* \brief Send a neighbor solicitation, send a Neighbor Advertisement
* \brief Send a neighbor solicitation, send a Neighbor Advertisement
* \param src pointer to the src of the NS if known
* \param dest pointer to ip address to send the NS, for DAD or ADDR Resol,
* MUST be NULL, for NUD, must be correct unicast dest
@ -496,13 +317,13 @@ uip_nd6_ns_input(void);
* solicitation. Otherwise, any one of the addresses assigned to the
* interface should be used."
* This is why we have a src ip address as argument. If NULL, we will do
* src address selection, otherwise we use the argument.
*
* src address selection, otherwise we use the argument.
*
* - we check if it is a NS for Address resolution or NUD, if yes we include
* a SLLAO option, otherwise no.
*/
void
uip_nd6_ns_output(uip_ipaddr_t *src, uip_ipaddr_t *dest, uip_ipaddr_t *tgt);
uip_nd6_ns_output(uip_ipaddr_t *src, uip_ipaddr_t *dest, uip_ipaddr_t *tgt);
/**
* \brief Process a Neighbor Advertisement
@ -528,7 +349,7 @@ uip_nd6_na_input(void);
#if UIP_ND6_SEND_RA
/**
* \brief Process a Router Solicitation
*
*
*/
void uip_nd6_rs_input(void);
@ -543,12 +364,12 @@ void uip_nd6_ra_output(uip_ipaddr_t *dest);
/**
* \brief Send a Router Solicitation
*
*
* src is chosen through the uip_netif_select_src function. If src is
* unspecified (i.e. we do not have a preferred address yet), then we do not
* put a SLLAO option (MUST NOT in RFC 4861). Otherwise we do.
*
* RS message format,
* RS message format,
* possible option is SLLAO, MUST NOT be included if source = unspecified
* SHOULD be included otherwise
*/
@ -559,7 +380,7 @@ void uip_nd6_rs_output(void);
* \brief process a Router Advertisement
*
* - Possible actions when receiving a RA: add router to router list,
* recalculate reachable time, update link hop limit, update retrans timer.
* recalculate reachable time, update link hop limit, update retrans timer.
* - If MTU option: update MTU.
* - If SLLAO option: update entry in neighbor cache
* - If prefix option: start autoconf, add prefix to prefix list
@ -570,13 +391,13 @@ uip_nd6_ra_input(void);
void
uip_appserver_addr_get(uip_ipaddr_t *ipaddr);
uip_appserver_addr_get(uip_ipaddr_t *ipaddr);
/*--------------------------------------*/
/******* ANNEX - message formats ********/
/*--------------------------------------*/
/*
* RS format. possible option is SLLAO
/*
* RS format. possible option is SLLAO
* 0 1 2 3
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
@ -644,7 +465,7 @@ uip_appserver_addr_get(uip_ipaddr_t *ipaddr);
* | Options ...
* +-+-+-+-+-+-+-+-+-+-+-+-
*
*
*
* Redirect message format. Possible options are TLLAO and Redirected header
*
* 0 1 2 3
@ -673,7 +494,7 @@ uip_appserver_addr_get(uip_ipaddr_t *ipaddr);
* | Options ...
* +-+-+-+-+-+-+-+-+-+-+-+-
*
*
*
* SLLAO/TLLAO option:
* 0 1 2 3
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
@ -681,7 +502,7 @@ uip_appserver_addr_get(uip_ipaddr_t *ipaddr);
* | Type | Length | Link-Layer Address ...
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*
*
*
* Prefix information option
* 0 1 2 3
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
@ -712,8 +533,8 @@ uip_appserver_addr_get(uip_ipaddr_t *ipaddr);
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | MTU |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*
*
*
*
* Redirected header option
*
* 0 1 2 3
@ -728,7 +549,7 @@ uip_appserver_addr_get(uip_ipaddr_t *ipaddr);
* | |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*
*/
*/
#endif /* __UIP_ND6_H__ */
/** @} */

View file

@ -1770,6 +1770,17 @@ typedef struct uip_ext_hdr_opt_padn {
u8_t opt_len;
} uip_ext_hdr_opt_padn;
#if UIP_CONF_IPV6_RPL
/* RPL option */
typedef struct uip_ext_hdr_opt_rpl {
u8_t opt_type;
u8_t opt_len;
u8_t flags;
u8_t instance;
u16_t senderrank;
} uip_ext_hdr_opt_rpl;
#endif /* UIP_CONF_IPV6_RPL */
/* TCP header */
struct uip_tcp_hdr {
u16_t srcport;
@ -1840,6 +1851,10 @@ struct uip_udp_hdr {
/** \brief Destination and Hop By Hop extension headers option types */
#define UIP_EXT_HDR_OPT_PAD1 0
#define UIP_EXT_HDR_OPT_PADN 1
#if UIP_CONF_IPV6_RPL
#define UIP_EXT_HDR_OPT_RPL 0x63
#endif /* UIP_CONF_IPV6_RPL */
/** @} */
/** @{ */
@ -1897,8 +1912,13 @@ struct uip_udp_hdr {
*/
#define uip_l2_l3_hdr_len (UIP_LLH_LEN + UIP_IPH_LEN + uip_ext_len)
#define uip_l2_l3_icmp_hdr_len (UIP_LLH_LEN + UIP_IPH_LEN + uip_ext_len + UIP_ICMPH_LEN)
#define uip_l2_l3_udp_hdr_len (UIP_LLH_LEN + UIP_IPH_LEN + uip_ext_len + UIP_UDPH_LEN)
#define uip_l2_l3_tcp_hdr_len (UIP_LLH_LEN + UIP_IPH_LEN + uip_ext_len + UIP_TCPH_LEN)
#define uip_l3_hdr_len (UIP_IPH_LEN + uip_ext_len)
#define uip_l3_icmp_hdr_len (UIP_IPH_LEN + uip_ext_len + UIP_ICMPH_LEN)
#define uip_l3_udp_hdr_len (UIP_IPH_LEN + uip_ext_len + UIP_UDPH_LEN)
#define uip_l3_tcp_hdr_len (UIP_IPH_LEN + uip_ext_len + UIP_TCPH_LEN)
#endif /*UIP_CONF_IPV6*/

View file

@ -95,7 +95,7 @@
#endif
#if UIP_CONF_IPV6_RPL
void uip_rpl_input(void);
#include "rpl/rpl.h"
#endif /* UIP_CONF_IPV6_RPL */
#if UIP_LOGGING == 1
@ -163,6 +163,9 @@ u8_t uip_ext_opt_offset = 0;
#define UIP_DESTO_BUF ((struct uip_desto_hdr *)&uip_buf[uip_l2_l3_hdr_len])
#define UIP_EXT_HDR_OPT_BUF ((struct uip_ext_hdr_opt *)&uip_buf[uip_l2_l3_hdr_len + uip_ext_opt_offset])
#define UIP_EXT_HDR_OPT_PADN_BUF ((struct uip_ext_hdr_opt_padn *)&uip_buf[uip_l2_l3_hdr_len + uip_ext_opt_offset])
#if UIP_CONF_IPV6_RPL
#define UIP_EXT_HDR_OPT_RPL_BUF ((struct uip_ext_hdr_opt_rpl *)&uip_buf[uip_l2_l3_hdr_len + uip_ext_opt_offset])
#endif /* UIP_CONF_IPV6_RPL */
#define UIP_ICMP6_ERROR_BUF ((struct uip_icmp6_error *)&uip_buf[uip_l2_l3_icmp_hdr_len])
/** @} */
/** \name Buffer variables
@ -503,6 +506,24 @@ uip_connect(uip_ipaddr_t *ripaddr, u16_t rport)
}
#endif /* UIP_TCP && UIP_ACTIVE_OPEN */
/*---------------------------------------------------------------------------*/
void
remove_ext_hdr(void)
{
/* Remove ext header before TCP/UDP processing. */
if(uip_ext_len > 0) {
PRINTF("Cutting ext-header before TCP send (%d)\n", uip_ext_len);
memmove(((uint8_t *)UIP_TCP_BUF) - uip_ext_len, (uint8_t *)UIP_TCP_BUF,
uip_len - UIP_IPH_LEN - uip_ext_len);
uip_len -= uip_ext_len;
/* Update the IP length. */
UIP_IP_BUF->len[0] = (uip_len - UIP_IPH_LEN) >> 8;
UIP_IP_BUF->len[1] = (uip_len - UIP_IPH_LEN) & 0xff;
uip_ext_len = 0;
}
}
/*---------------------------------------------------------------------------*/
#if UIP_UDP
struct uip_udp_conn *
uip_udp_new(const uip_ipaddr_t *ripaddr, u16_t rport)
@ -828,6 +849,16 @@ ext_hdr_options_process(void)
PRINTF("Processing PADN option\n");
uip_ext_opt_offset += UIP_EXT_HDR_OPT_PADN_BUF->opt_len + 2;
break;
#if UIP_CONF_IPV6_RPL
case UIP_EXT_HDR_OPT_RPL:
PRINTF("Processing RPL option\n");
if(rpl_verify_header(uip_ext_opt_offset)) {
PRINTF("RPL Option Error : Dropping Packet");
return 1;
}
uip_ext_opt_offset += (UIP_EXT_HDR_OPT_RPL_BUF->opt_len) + 2;
return 0;
#endif /* UIP_CONF_IPV6_RPL */
default:
/*
* check the two highest order bits of the option
@ -1015,7 +1046,7 @@ uip_process(u8_t flag)
if(flag == UIP_UDP_TIMER) {
if(uip_udp_conn->lport != 0) {
uip_conn = NULL;
uip_sappdata = uip_appdata = &uip_buf[UIP_LLH_LEN + UIP_IPUDPH_LEN];
uip_sappdata = uip_appdata = &uip_buf[uip_l2_l3_udp_hdr_len];
uip_len = uip_slen = 0;
uip_flags = UIP_POLL;
UIP_UDP_APPCALL();
@ -1079,6 +1110,35 @@ uip_process(u8_t flag)
}
#if UIP_CONF_ROUTER
/*
* Next header field processing. In IPv6, we can have extension headers,
* if present, the Hop-by-Hop Option must be processed before forwarding
* the packet.
*/
uip_next_hdr = &UIP_IP_BUF->proto;
uip_ext_len = 0;
uip_ext_bitmap = 0;
if(*uip_next_hdr == UIP_PROTO_HBHO) {
#if UIP_CONF_IPV6_CHECKS
uip_ext_bitmap |= UIP_EXT_HDR_BITMAP_HBHO;
#endif /*UIP_CONF_IPV6_CHECKS*/
switch(ext_hdr_options_process()) {
case 0:
/*continue*/
uip_next_hdr = &UIP_EXT_BUF->next;
uip_ext_len += (UIP_EXT_BUF->len << 3) + 8;
break;
case 1:
/*silently discard*/
goto drop;
case 2:
/* send icmp error message (created in ext_hdr_options_process)
* and discard*/
goto send;
}
}
/* TBD Some Parameter problem messages */
if(!uip_ds6_is_my_addr(&UIP_IP_BUF->destipaddr) &&
!uip_ds6_is_my_maddr(&UIP_IP_BUF->destipaddr)) {
@ -1102,6 +1162,11 @@ uip_process(u8_t flag)
UIP_STAT(++uip_stat.ip.drop);
goto send;
}
#if UIP_CONF_IPV6_RPL
rpl_update_header_empty();
#endif /* UIP_CONF_IPV6_RPL */
UIP_IP_BUF->ttl = UIP_IP_BUF->ttl - 1;
PRINTF("Forwarding packet to ");
PRINT6ADDR(&UIP_IP_BUF->destipaddr);
@ -1132,7 +1197,6 @@ uip_process(u8_t flag)
UIP_STAT(++uip_stat.ip.drop);
goto drop;
}
#endif /* UIP_CONF_ROUTER */
/*
* Next header field processing. In IPv6, we can have extension headers,
@ -1141,6 +1205,8 @@ uip_process(u8_t flag)
uip_next_hdr = &UIP_IP_BUF->proto;
uip_ext_len = 0;
uip_ext_bitmap = 0;
#endif /* UIP_CONF_ROUTER */
while(1) {
switch(*uip_next_hdr){
#if UIP_TCP
@ -1374,8 +1440,8 @@ uip_process(u8_t flag)
work. If the application sets uip_slen, it has a packet to
send. */
#if UIP_UDP_CHECKSUMS
uip_len = uip_len - UIP_IPUDPH_LEN;
uip_appdata = &uip_buf[UIP_LLH_LEN + UIP_IPUDPH_LEN];
uip_len = uip_len - uip_l3_udp_hdr_len;
uip_appdata = &uip_buf[uip_l2_l3_udp_hdr_len];
if(UIP_UDP_BUF->udpchksum != 0 && uip_udpchksum() != 0xffff) {
UIP_STAT(++uip_stat.udp.drop);
UIP_STAT(++uip_stat.udp.chkerr);
@ -1384,7 +1450,7 @@ uip_process(u8_t flag)
goto drop;
}
#else /* UIP_UDP_CHECKSUMS */
uip_len = uip_len - UIP_IPUDPH_LEN;
uip_len = uip_len - uip_l3_udp_hdr_len;
#endif /* UIP_UDP_CHECKSUMS */
/* Make sure that the UDP destination port number is not zero. */
@ -1428,7 +1494,7 @@ uip_process(u8_t flag)
uip_conn = NULL;
uip_flags = UIP_NEWDATA;
uip_sappdata = uip_appdata = &uip_buf[UIP_LLH_LEN + UIP_IPUDPH_LEN];
uip_sappdata = uip_appdata = &uip_buf[uip_l2_l3_udp_hdr_len];
uip_slen = 0;
UIP_UDP_APPCALL();
@ -1438,7 +1504,8 @@ uip_process(u8_t flag)
if(uip_slen == 0) {
goto drop;
}
uip_len = uip_slen + UIP_IPUDPH_LEN;
/* TODO: ext_header len here ? */
uip_len = uip_slen + uip_l3_udp_hdr_len; /* UIP_IPUDPH_LEN; */
/* For IPv6, the IP length field does not include the IPv6 IP header
length. */
@ -1474,6 +1541,8 @@ uip_process(u8_t flag)
/* TCP input processing. */
tcp_input:
remove_ext_hdr();
UIP_STAT(++uip_stat.tcp.recv);
PRINTF("Receiving TCP packet\n");
/* Start of TCP input header processing code. */
@ -1482,13 +1551,14 @@ uip_process(u8_t flag)
checksum. */
UIP_STAT(++uip_stat.tcp.drop);
UIP_STAT(++uip_stat.tcp.chkerr);
UIP_LOG("tcp: bad checksum.");
PRINTF("tcp: bad checksum 0x%04x 0x%04x\n", UIP_TCP_BUF->tcpchksum,
uip_tcpchksum());
goto drop;
}
/* Make sure that the TCP port number is not zero. */
if(UIP_TCP_BUF->destport == 0 || UIP_TCP_BUF->srcport == 0) {
UIP_LOG("tcp: zero port.");
PRINTF("tcp: zero port.");
goto drop;
}
@ -1636,7 +1706,7 @@ uip_process(u8_t flag)
/* Parse the TCP MSS option, if present. */
if((UIP_TCP_BUF->tcpoffset & 0xf0) > 0x50) {
for(c = 0; c < ((UIP_TCP_BUF->tcpoffset >> 4) - 5) << 2 ;) {
opt = uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + c];
opt = uip_buf[UIP_TCPIP_HLEN + uip_ext_len + UIP_LLH_LEN + c];
if(opt == TCP_OPT_END) {
/* End of options. */
break;
@ -1644,10 +1714,10 @@ uip_process(u8_t flag)
++c;
/* NOP option. */
} else if(opt == TCP_OPT_MSS &&
uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c] == TCP_OPT_MSS_LEN) {
uip_buf[UIP_TCPIP_HLEN + uip_ext_len + UIP_LLH_LEN + 1 + c] == TCP_OPT_MSS_LEN) {
/* An MSS option with the right option length. */
tmp16 = ((u16_t)uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 2 + c] << 8) |
(u16_t)uip_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN + 3 + c];
tmp16 = ((u16_t)uip_buf[UIP_TCPIP_HLEN + uip_ext_len + UIP_LLH_LEN + 2 + c] << 8) |
(u16_t)uip_buf[UIP_IPTCPH_LEN + uip_ext_len + UIP_LLH_LEN + 3 + c];
uip_connr->initialmss = uip_connr->mss =
tmp16 > UIP_TCP_MSS? UIP_TCP_MSS: tmp16;
@ -1656,12 +1726,12 @@ uip_process(u8_t flag)
} else {
/* All other options have a length field, so that we easily
can skip past them. */
if(uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c] == 0) {
if(uip_buf[UIP_TCPIP_HLEN + uip_ext_len + UIP_LLH_LEN + 1 + c] == 0) {
/* If the length field is zero, the options are malformed
and we don't process them further. */
break;
}
c += uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c];
c += uip_buf[UIP_TCPIP_HLEN + uip_ext_len + UIP_LLH_LEN + 1 + c];
}
}
}
@ -1684,7 +1754,7 @@ uip_process(u8_t flag)
UIP_TCP_BUF->optdata[1] = TCP_OPT_MSS_LEN;
UIP_TCP_BUF->optdata[2] = (UIP_TCP_MSS) / 256;
UIP_TCP_BUF->optdata[3] = (UIP_TCP_MSS) & 255;
uip_len = UIP_IPTCPH_LEN + TCP_OPT_MSS_LEN;
uip_len = UIP_IPTCPH_LEN + TCP_OPT_MSS_LEN + uip_ext_len;
UIP_TCP_BUF->tcpoffset = ((UIP_TCPH_LEN + TCP_OPT_MSS_LEN) / 4) << 4;
goto tcp_send;
@ -1710,7 +1780,7 @@ uip_process(u8_t flag)
/* uip_len will contain the length of the actual TCP data. This is
calculated by subtracing the length of the TCP header (in
c) and the length of the IP header (20 bytes). */
uip_len = uip_len - c - UIP_IPH_LEN;
uip_len = uip_len - c - UIP_IPH_LEN - uip_ext_len;
/* First, check if the sequence number of the incoming packet is
what we're expecting next. If not, we send out an ACK with the
@ -1817,7 +1887,7 @@ uip_process(u8_t flag)
/* Parse the TCP MSS option, if present. */
if((UIP_TCP_BUF->tcpoffset & 0xf0) > 0x50) {
for(c = 0; c < ((UIP_TCP_BUF->tcpoffset >> 4) - 5) << 2 ;) {
opt = uip_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN + c];
opt = uip_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN + c + uip_ext_len];
if(opt == TCP_OPT_END) {
/* End of options. */
break;
@ -1825,10 +1895,10 @@ uip_process(u8_t flag)
++c;
/* NOP option. */
} else if(opt == TCP_OPT_MSS &&
uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c] == TCP_OPT_MSS_LEN) {
uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c + uip_ext_len] == TCP_OPT_MSS_LEN) {
/* An MSS option with the right option length. */
tmp16 = (uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 2 + c] << 8) |
uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 3 + c];
tmp16 = (uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 2 + c + uip_ext_len] << 8) |
uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 3 + c + uip_ext_len];
uip_connr->initialmss =
uip_connr->mss = tmp16 > UIP_TCP_MSS? UIP_TCP_MSS: tmp16;
@ -1837,12 +1907,12 @@ uip_process(u8_t flag)
} else {
/* All other options have a length field, so that we easily
can skip past them. */
if(uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c] == 0) {
if(uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c + uip_ext_len] == 0) {
/* If the length field is zero, the options are malformed
and we don't process them further. */
break;
}
c += uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c];
c += uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 1 + c + uip_ext_len];
}
}
}
@ -2113,7 +2183,7 @@ uip_process(u8_t flag)
UIP_TCP_BUF->flags = TCP_ACK;
tcp_send_nodata:
uip_len = UIP_IPTCPH_LEN;
uip_len = UIP_IPTCPH_LEN; /* TODO: maybe ext_len??? */
tcp_send_noopts:
UIP_TCP_BUF->tcpoffset = (UIP_TCPH_LEN / 4) << 4;

View file

@ -194,12 +194,12 @@
#define UIP_CONF_IPV6_QUEUE_PKT 0
#endif
#ifndef UIP_CONF_IPV6_CHECKS
#ifndef UIP_CONF_IPV6_CHECKS
/** Do we do IPv6 consistency checks (highly recommended, default: yes) */
#define UIP_CONF_IPV6_CHECKS 1
#endif
#ifndef UIP_CONF_IPV6_REASSEMBLY
#ifndef UIP_CONF_IPV6_REASSEMBLY
/** Do we do IPv6 fragmentation (default: no) */
#define UIP_CONF_IPV6_REASSEMBLY 0
#endif
@ -209,19 +209,19 @@
#define UIP_CONF_NETIF_MAX_ADDRESSES 3
#endif
#ifndef UIP_CONF_ND6_MAX_PREFIXES
#ifndef UIP_CONF_DS6_PREFIX_NBU
/** Default number of IPv6 prefixes associated to the node's interface */
#define UIP_CONF_ND6_MAX_PREFIXES 3
#define UIP_CONF_DS6_PREFIX_NBU 2
#endif
#ifndef UIP_CONF_ND6_MAX_NEIGHBORS
#ifndef UIP_CONF_DS6_NBR_NBU
/** Default number of neighbors that can be stored in the %neighbor cache */
#define UIP_CONF_ND6_MAX_NEIGHBORS 4
#define UIP_CONF_DS6_NBR_NBU 4
#endif
#ifndef UIP_CONF_ND6_MAX_DEFROUTERS
#ifndef UIP_CONF_DS6_DEFRT_NBU
/** Minimum number of default routers */
#define UIP_CONF_ND6_MAX_DEFROUTERS 2
#define UIP_CONF_DS6_DEFRT_NBU 2
#endif
/** @} */

View file

@ -0,0 +1,6 @@
CONTIKI = ../../../
APPS += antelope
CFLAGS += -Wall -g -DPROJECT_CONF_H=\"project-conf.h\"
SMALL = 1
include $(CONTIKI)/Makefile.include

View file

@ -0,0 +1,133 @@
/*
* Copyright (c) 2011, 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.
*/
/**
* \file
* A small command-line interface for the querying remote database systems.
* \author
* Nicolas Tsiftes <nvt@sics.se>
*/
#include <stdio.h>
#include "contiki.h"
#include "dev/serial-line.h"
#include "net/rime.h"
#include "net/rime/mesh.h"
#include "antelope.h"
/*---------------------------------------------------------------------------*/
#define MAX_QUERY_SIZE 100
#define NETDB_CHANNEL 70
#ifndef SERVER_ID
#define SERVER_ID 4
#endif
/*---------------------------------------------------------------------------*/
PROCESS(netdb_process, "NetDB");
AUTOSTART_PROCESSES(&netdb_process);
static unsigned server_id = SERVER_ID;
static struct mesh_conn mesh;
/*---------------------------------------------------------------------------*/
PROCESS(shell_process, "Shell Process");
PROCESS_THREAD(shell_process, ev, data)
{
rimeaddr_t addr;
PROCESS_BEGIN();
printf("NetDB client\n");
for(;;) {
PROCESS_WAIT_EVENT_UNTIL(ev == serial_line_event_message && data != NULL);
if(strncmp(data, "server ", 7) == 0) {
server_id = atoi((char *)data + 7);
} else {
printf("%lu Transmitting query \"%s\" to node %u\n", clock_time(), (char *)data, server_id);
packetbuf_copyfrom(data, strlen(data));
addr.u8[0] = server_id;
addr.u8[1] = 0;
packetbuf_set_attr(PACKETBUF_ATTR_PACKET_TYPE,
PACKETBUF_ATTR_PACKET_TYPE_STREAM);
mesh_send(&mesh, &addr);
}
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/
static void
sent(struct mesh_conn *c)
{
}
static void
timedout(struct mesh_conn *c)
{
printf("Failed to send packet: time out\n");
}
static void
received(struct mesh_conn *c, const rimeaddr_t *from, uint8_t hops)
{
char *data;
unsigned len;
static char reply[MAX_QUERY_SIZE + 1];
data = (char *)packetbuf_dataptr();
len = packetbuf_datalen();
if(len > MAX_QUERY_SIZE) {
printf("Too long query: %d bytes\n", len);
return;
}
memcpy(reply, data, len);
reply[len] = '\0';
printf("%lu Reply received from %d.%d (%d hops): %s",
clock_time(), from->u8[0], from->u8[1], (int)hops, reply);
}
static const struct mesh_callbacks callbacks = {received, sent, timedout};
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(netdb_process, ev, data)
{
PROCESS_EXITHANDLER(mesh_close(&mesh));
PROCESS_BEGIN();
mesh_open(&mesh, NETDB_CHANNEL, &callbacks);
process_start(&shell_process, NULL);
PROCESS_END();
}

View file

@ -0,0 +1,300 @@
/*
* Copyright (c) 2011, 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.
*/
/**
* \file
* A small command-line interface for the querying remote database systems.
* \author
* Nicolas Tsiftes <nvt@sics.se>
*/
#include <stdio.h>
#include "contiki.h"
#include "dev/serial-line.h"
#include "dev/sht11.h"
#include "lib/random.h"
#include "net/rime.h"
#include "net/rime/mesh.h"
#include "antelope.h"
/*---------------------------------------------------------------------------*/
/* Sampling interval in Hz. */
#ifndef SAMPLING_INTERVAL
#define SAMPLING_INTERVAL 60
#endif
#ifndef RESPONSE_LIMIT
#define RESPONSE_LIMIT 1000
#endif
#ifndef PREPARE_DB
#define PREPARE_DB 1
#endif
#ifndef CARDINALITY
#define CARDINALITY 1000
#endif
#define MAX_BUFFER_SIZE 80
#define NETDB_CHANNEL 70
/*---------------------------------------------------------------------------*/
PROCESS(netdb_process, "NetDB");
AUTOSTART_PROCESSES(&netdb_process);
static struct mesh_conn mesh;
static rimeaddr_t reply_addr;
static uint8_t buffer_offset;
static char buffer[MAX_BUFFER_SIZE];
/*---------------------------------------------------------------------------*/
static void
send_buffered_data(void)
{
if(buffer_offset > 0) {
packetbuf_copyfrom(buffer, buffer_offset);
mesh_send(&mesh, &reply_addr);
buffer_offset = 0;
}
}
/*---------------------------------------------------------------------------*/
static int
buffer_db_data(const char *format, ...)
{
va_list ap;
size_t len;
char tmp[MAX_BUFFER_SIZE + 1];
va_start(ap, format);
len = vsnprintf(tmp, sizeof(tmp), format, ap);
va_end(ap);
if(len < 0) {
return -1;
}
if(len + buffer_offset > sizeof(buffer)) {
send_buffered_data();
}
memcpy(&buffer[buffer_offset], tmp, len);
buffer_offset += len;
return len;
}
/*---------------------------------------------------------------------------*/
static void
take_sample(void)
{
unsigned seconds;
unsigned humidity;
seconds = clock_seconds();
humidity = /*sht11_humidity()*/ random_rand();
if(DB_ERROR(db_query(NULL, "INSERT (%u, %u) INTO samples;",
seconds, humidity))) {
printf("DB insertion failed\n");
}
}
/*---------------------------------------------------------------------------*/
static void
stop_handler(void *ptr)
{
printf("END\n");
}
/*---------------------------------------------------------------------------*/
PROCESS(query_process, "Query process");
PROCESS_THREAD(query_process, ev, data)
{
static db_handle_t handle;
db_result_t result;
static tuple_id_t matching;
static tuple_id_t processed;
#if !PREPARE_DB
static struct etimer sampling_timer;
#endif
static unsigned i, errors;
PROCESS_BEGIN();
printf("NetDB host\n");
db_init();
db_set_output_function(buffer_db_data);
db_query(NULL, "REMOVE RELATION samples;");
db_query(NULL, "CREATE RELATION samples;");
db_query(NULL, "CREATE ATTRIBUTE time DOMAIN INT IN samples;");
db_query(NULL, "CREATE ATTRIBUTE hum DOMAIN INT IN samples;");
db_query(NULL, "CREATE INDEX samples.time TYPE INLINE;");
#if PREPARE_DB
printf("Preparing the DB with %d tuples...\n", CARDINALITY);
errors = 0;
for(i = 1; i <= CARDINALITY; i++) {
PROCESS_PAUSE();
result = db_query(NULL, "INSERT (%u, %u) INTO samples;",
i, (unsigned)random_rand());
if(DB_ERROR(result)) {
errors++;
}
}
printf("Done. Insertion errors: %d\n", errors);
printf("Ready to process queries\n");
#else
etimer_set(&sampling_timer, SAMPLING_INTERVAL * CLOCK_SECOND);
#endif
for(;;) {
PROCESS_WAIT_EVENT();
if(ev == serial_line_event_message && data != NULL) {
printf("START %s\n", (char *)data);
result = db_query(&handle, data);
if(DB_ERROR(result)) {
buffer_db_data("Query error: %s\n", db_get_result_message(result));
stop_handler(NULL);
db_free(&handle);
continue;
}
if(!db_processing(&handle)) {
buffer_db_data("OK\n");
send_buffered_data();
stop_handler(NULL);
continue;
}
packetbuf_set_attr(PACKETBUF_ATTR_PACKET_TYPE,
PACKETBUF_ATTR_PACKET_TYPE_STREAM);
db_print_header(&handle);
matching = 0;
processed = 0;
while(db_processing(&handle)) {
PROCESS_PAUSE();
if(matching == RESPONSE_LIMIT) {
buffer_db_data("Response suppressed at %u tuples: limit reached\n",
RESPONSE_LIMIT);
stop_handler(NULL);
db_free(&handle);
break;
}
result = db_process(&handle);
if(result == DB_GOT_ROW) {
/* The processed tuple matched the condition in the query. */
matching++;
processed++;
db_print_tuple(&handle);
} else if(result == DB_OK) {
/* A tuple was processed, but did not match the condition. */
processed++;
continue;
} else {
if(result == DB_FINISHED) {
/* The processing has finished. Wait for a new command. */
buffer_db_data("[%ld tuples returned; %ld tuples processed]\n",
(long)matching, (long)processed);
buffer_db_data("OK\n");
} else if(DB_ERROR(result)) {
buffer_db_data("Processing error: %s\n",
db_get_result_message(result));
}
stop_handler(NULL);
db_free(&handle);
}
}
send_buffered_data();
}
#if !PREPARE_DB
if(etimer_expired(&sampling_timer)) {
take_sample();
etimer_reset(&sampling_timer);
}
#endif
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/
static void
sent(struct mesh_conn *c)
{
}
static void
timedout(struct mesh_conn *c)
{
printf("packet time out\n");
}
static void
received(struct mesh_conn *c, const rimeaddr_t *from, uint8_t hops)
{
char *data;
unsigned len;
static char query[MAX_BUFFER_SIZE + 1];
data = (char *)packetbuf_dataptr();
len = packetbuf_datalen();
if(len > MAX_BUFFER_SIZE) {
buffer_db_data("Too long query: %d bytes\n", len);
return;
}
memcpy(query, data, len);
query[len] = '\0';
printf("Query received from %d.%d: %s (%d hops)\n",
from->u8[0], from->u8[1], query, (int)hops);
rimeaddr_copy(&reply_addr, from);
process_post(&query_process, serial_line_event_message, query);
}
static const struct mesh_callbacks callbacks = {received, sent, timedout};
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(netdb_process, ev, data)
{
PROCESS_EXITHANDLER(mesh_close(&mesh));
PROCESS_BEGIN();
mesh_open(&mesh, NETDB_CHANNEL, &callbacks);
process_start(&query_process, NULL);
PROCESS_END();
}

271
examples/antelope/netdb/netdb.csc Executable file
View file

@ -0,0 +1,271 @@
<?xml version="1.0" encoding="UTF-8"?>
<simconf>
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/mrm</project>
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/mspsim</project>
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/avrora</project>
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/serial_socket</project>
<project EXPORT="discard">[CONTIKI_DIR]/tools/cooja/apps/collect-view</project>
<simulation>
<title>NetDB</title>
<delaytime>0</delaytime>
<randomseed>123456</randomseed>
<motedelay_us>1000000</motedelay_us>
<radiomedium>
se.sics.cooja.radiomediums.UDGM
<transmitting_range>30.0</transmitting_range>
<interference_range>30.0</interference_range>
<success_ratio_tx>1.0</success_ratio_tx>
<success_ratio_rx>1.0</success_ratio_rx>
</radiomedium>
<events>
<logoutput>40000</logoutput>
</events>
<motetype>
se.sics.cooja.mspmote.SkyMoteType
<identifier>sky1</identifier>
<description>NetDB Server</description>
<source EXPORT="discard">[CONTIKI_DIR]/examples/antelope/netdb/netdb-server.c</source>
<commands EXPORT="discard">make netdb-server.sky TARGET=sky</commands>
<firmware EXPORT="copy">[CONTIKI_DIR]/examples/antelope/netdb/netdb-server.sky</firmware>
<moteinterface>se.sics.cooja.interfaces.Position</moteinterface>
<moteinterface>se.sics.cooja.interfaces.RimeAddress</moteinterface>
<moteinterface>se.sics.cooja.interfaces.IPAddress</moteinterface>
<moteinterface>se.sics.cooja.interfaces.Mote2MoteRelations</moteinterface>
<moteinterface>se.sics.cooja.interfaces.MoteAttributes</moteinterface>
<moteinterface>se.sics.cooja.mspmote.interfaces.MspClock</moteinterface>
<moteinterface>se.sics.cooja.mspmote.interfaces.MspMoteID</moteinterface>
<moteinterface>se.sics.cooja.mspmote.interfaces.SkyButton</moteinterface>
<moteinterface>se.sics.cooja.mspmote.interfaces.SkyFlash</moteinterface>
<moteinterface>se.sics.cooja.mspmote.interfaces.SkyCoffeeFilesystem</moteinterface>
<moteinterface>se.sics.cooja.mspmote.interfaces.SkyByteRadio</moteinterface>
<moteinterface>se.sics.cooja.mspmote.interfaces.MspSerial</moteinterface>
<moteinterface>se.sics.cooja.mspmote.interfaces.SkyLED</moteinterface>
<moteinterface>se.sics.cooja.mspmote.interfaces.MspDebugOutput</moteinterface>
<moteinterface>se.sics.cooja.mspmote.interfaces.SkyTemperature</moteinterface>
</motetype>
<motetype>
se.sics.cooja.mspmote.SkyMoteType
<identifier>sky2</identifier>
<description>NetDB Client</description>
<source EXPORT="discard">[CONTIKI_DIR]/examples/antelope/netdb/netdb-client.c</source>
<commands EXPORT="discard">make netdb-client.sky TARGET=sky</commands>
<firmware EXPORT="copy">[CONTIKI_DIR]/examples/antelope/netdb/netdb-client.sky</firmware>
<moteinterface>se.sics.cooja.interfaces.Position</moteinterface>
<moteinterface>se.sics.cooja.interfaces.RimeAddress</moteinterface>
<moteinterface>se.sics.cooja.interfaces.IPAddress</moteinterface>
<moteinterface>se.sics.cooja.interfaces.Mote2MoteRelations</moteinterface>
<moteinterface>se.sics.cooja.interfaces.MoteAttributes</moteinterface>
<moteinterface>se.sics.cooja.mspmote.interfaces.MspClock</moteinterface>
<moteinterface>se.sics.cooja.mspmote.interfaces.MspMoteID</moteinterface>
<moteinterface>se.sics.cooja.mspmote.interfaces.SkyButton</moteinterface>
<moteinterface>se.sics.cooja.mspmote.interfaces.SkyFlash</moteinterface>
<moteinterface>se.sics.cooja.mspmote.interfaces.SkyCoffeeFilesystem</moteinterface>
<moteinterface>se.sics.cooja.mspmote.interfaces.SkyByteRadio</moteinterface>
<moteinterface>se.sics.cooja.mspmote.interfaces.MspSerial</moteinterface>
<moteinterface>se.sics.cooja.mspmote.interfaces.SkyLED</moteinterface>
<moteinterface>se.sics.cooja.mspmote.interfaces.MspDebugOutput</moteinterface>
<moteinterface>se.sics.cooja.mspmote.interfaces.SkyTemperature</moteinterface>
</motetype>
<mote>
<breakpoints />
<interface_config>
se.sics.cooja.interfaces.Position
<x>23.57340748739308</x>
<y>46.80222047486912</y>
<z>0.0</z>
</interface_config>
<interface_config>
se.sics.cooja.mspmote.interfaces.MspMoteID
<id>1</id>
</interface_config>
<motetype_identifier>sky1</motetype_identifier>
</mote>
<mote>
<breakpoints />
<interface_config>
se.sics.cooja.interfaces.Position
<x>40.39130096157144</x>
<y>70.54634688655467</y>
<z>0.0</z>
</interface_config>
<interface_config>
se.sics.cooja.mspmote.interfaces.MspMoteID
<id>2</id>
</interface_config>
<motetype_identifier>sky1</motetype_identifier>
</mote>
<mote>
<breakpoints />
<interface_config>
se.sics.cooja.interfaces.Position
<x>66.04131381969006</x>
<y>36.41113701058369</y>
<z>0.0</z>
</interface_config>
<interface_config>
se.sics.cooja.mspmote.interfaces.MspMoteID
<id>3</id>
</interface_config>
<motetype_identifier>sky1</motetype_identifier>
</mote>
<mote>
<breakpoints />
<interface_config>
se.sics.cooja.interfaces.Position
<x>63.00130046120498</x>
<y>80.89331313174746</y>
<z>0.0</z>
</interface_config>
<interface_config>
se.sics.cooja.mspmote.interfaces.MspMoteID
<id>4</id>
</interface_config>
<motetype_identifier>sky1</motetype_identifier>
</mote>
<mote>
<breakpoints />
<interface_config>
se.sics.cooja.interfaces.Position
<x>40.2894982777653</x>
<y>95.14334789567525</y>
<z>0.0</z>
</interface_config>
<interface_config>
se.sics.cooja.mspmote.interfaces.MspMoteID
<id>5</id>
</interface_config>
<motetype_identifier>sky1</motetype_identifier>
</mote>
<mote>
<breakpoints />
<interface_config>
se.sics.cooja.interfaces.Position
<x>-13.168104050312492</x>
<y>40.250683112542255</y>
<z>0.0</z>
</interface_config>
<interface_config>
se.sics.cooja.mspmote.interfaces.MspMoteID
<id>6</id>
</interface_config>
<motetype_identifier>sky1</motetype_identifier>
</mote>
<mote>
<breakpoints />
<interface_config>
se.sics.cooja.interfaces.Position
<x>80.95025965975177</x>
<y>44.99507552455861</y>
<z>0.0</z>
</interface_config>
<interface_config>
se.sics.cooja.mspmote.interfaces.MspMoteID
<id>7</id>
</interface_config>
<motetype_identifier>sky1</motetype_identifier>
</mote>
<mote>
<breakpoints />
<interface_config>
se.sics.cooja.interfaces.Position
<x>6.857316697020866</x>
<y>33.24863334754029</y>
<z>0.0</z>
</interface_config>
<interface_config>
se.sics.cooja.mspmote.interfaces.MspMoteID
<id>8</id>
</interface_config>
<motetype_identifier>sky1</motetype_identifier>
</mote>
<mote>
<breakpoints />
<interface_config>
se.sics.cooja.interfaces.Position
<x>35.975659895989395</x>
<y>27.42171932830696</y>
<z>0.0</z>
</interface_config>
<interface_config>
se.sics.cooja.mspmote.interfaces.MspMoteID
<id>9</id>
</interface_config>
<motetype_identifier>sky1</motetype_identifier>
</mote>
<mote>
<breakpoints />
<interface_config>
se.sics.cooja.interfaces.Position
<x>13.672853648109518</x>
<y>68.2461872644317</y>
<z>0.0</z>
</interface_config>
<interface_config>
se.sics.cooja.mspmote.interfaces.MspMoteID
<id>10</id>
</interface_config>
<motetype_identifier>sky1</motetype_identifier>
</mote>
<mote>
<breakpoints />
<interface_config>
se.sics.cooja.interfaces.Position
<x>44.62423029692567</x>
<y>48.53691502749644</y>
<z>0.0</z>
</interface_config>
<interface_config>
se.sics.cooja.mspmote.interfaces.MspMoteID
<id>51</id>
</interface_config>
<motetype_identifier>sky2</motetype_identifier>
</mote>
</simulation>
<plugin>
se.sics.cooja.plugins.SimControl
<width>259</width>
<z>3</z>
<height>205</height>
<location_x>0</location_x>
<location_y>0</location_y>
</plugin>
<plugin>
se.sics.cooja.plugins.Visualizer
<plugin_config>
<skin>se.sics.cooja.plugins.skins.IDVisualizerSkin</skin>
<skin>se.sics.cooja.plugins.skins.MoteTypeVisualizerSkin</skin>
<skin>se.sics.cooja.plugins.skins.UDGMVisualizerSkin</skin>
<viewport>4.472125038273293 0.0 0.0 4.472125038273293 79.43486237544504 -89.06315297501011</viewport>
</plugin_config>
<width>475</width>
<z>0</z>
<height>429</height>
<location_x>644</location_x>
<location_y>9</location_y>
</plugin>
<plugin>
se.sics.cooja.plugins.LogListener
<plugin_config>
<filter>ID:4$</filter>
</plugin_config>
<width>1024</width>
<z>2</z>
<height>150</height>
<location_x>0</location_x>
<location_y>389</location_y>
</plugin>
<plugin>
se.sics.cooja.plugins.MoteInterfaceViewer
<mote_arg>10</mote_arg>
<plugin_config>
<interface>Serial port</interface>
<scrollpos>0,0</scrollpos>
</plugin_config>
<width>588</width>
<z>1</z>
<height>399</height>
<location_x>505</location_x>
<location_y>520</location_y>
</plugin>
</simconf>

View file

@ -0,0 +1,20 @@
#undef QUEUEBUF_CONF_NUM
#define QUEUEBUF_CONF_NUM 4
#undef NETSTACK_CONF_RDC
#define NETSTACK_CONF_RDC nullrdc_driver
#undef NETSTACK_CONF_RDC_CHANNEL_CHECK_RATE
#define NETSTACK_CONF_RDC_CHANNEL_CHECK_RATE 4
#undef DCOSYNC_CONF_ENABLED
#define DCOSYNC_CONF_ENABLED 0
#undef DB_FEATURE_JOIN
#define DB_FEATURE_JOIN 0
#undef RF_CHANNEL
#define RF_CHANNEL 16
#undef ROUTE_CONF_DEFAULT_LIFETIME
#define ROUTE_CONF_DEFAULT_LIFETIME 300

View file

@ -0,0 +1,8 @@
CONTIKI = ../../../
APPS += antelope unit-test
CFLAGS += -Wall -g -DPROJECT_CONF_H=\"project-conf.h\"
SMALL = 1
include $(CONTIKI)/Makefile.include

View file

@ -0,0 +1,5 @@
#undef QUEUEBUF_CONF_NUM
#define QUEUEBUF_CONF_NUM 4
#undef NETSTACK_CONF_RDC
#define NETSTACK_CONF_RDC nullrdc_driver

View file

@ -0,0 +1,109 @@
/*
* Copyright (c) 2010, 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.
*/
/**
* \file
* A small command-line interface for the database system.
* \author
* Nicolas Tsiftes <nvt@sics.se>
*/
#include <stdio.h>
#include "contiki.h"
#include "dev/serial-line.h"
#include "antelope.h"
PROCESS(db_shell, "DB shell");
AUTOSTART_PROCESSES(&db_shell);
PROCESS_THREAD(db_shell, ev, data)
{
static db_handle_t handle;
db_result_t result;
static tuple_id_t matching;
static tuple_id_t processed;
PROCESS_BEGIN();
db_init();
for(;;) {
PROCESS_WAIT_EVENT_UNTIL(ev == serial_line_event_message && data != NULL);
result = db_query(&handle, data);
if(DB_ERROR(result)) {
printf("Query \"%s\" failed: %s\n",
(char *)data, db_get_result_message(result));
db_free(&handle);
continue;
}
if(!db_processing(&handle)) {
printf("OK\n");
continue;
}
db_print_header(&handle);
matching = 0;
processed = 0;
while(db_processing(&handle)) {
PROCESS_PAUSE();
result = db_process(&handle);
switch(result) {
case DB_GOT_ROW:
/* The processed tuple matched the condition in the query. */
matching++;
processed++;
db_print_tuple(&handle);
break;
case DB_OK:
/* A tuple was processed, but did not match the condition. */
processed++;
continue;
case DB_FINISHED:
/* The processing has finished. Wait for a new command. */
printf("[%ld tuples returned; %ld tuples processed]\n",
(long)matching, (long)processed);
printf("OK\n");
default:
if(DB_ERROR(result)) {
printf("Processing error: %s\n", db_get_result_message(result));
}
db_free(&handle);
break;
}
}
}
PROCESS_END();
}

View file

@ -34,23 +34,28 @@
#define SICSLOWPAN_CONF_FRAG 1
/* Save some memory for the sky platform */
/* Disabling RDC for demo purposes. Core updates often require more memory. */
/* For projects, optimize memory and enable RDC again. */
#undef NETSTACK_CONF_RDC
#define NETSTACK_CONF_RDC nullrdc_driver
/* Save some memory for the sky platform. */
#undef UIP_CONF_DS6_NBR_NBU
#define UIP_CONF_DS6_NBR_NBU 10
#undef UIP_CONF_DS6_ROUTE_NBU
#define UIP_CONF_DS6_ROUTE_NBU 10
/* Increase rpl-border-router IP-buffer when using 128 */
/* Increase rpl-border-router IP-buffer when using 128. */
#ifndef REST_MAX_CHUNK_SIZE
#define REST_MAX_CHUNK_SIZE 64
#endif
/* Decrease to 2 if no space left for stack when using 128-byte chunks */
/* Multiplies with chunk size, be aware of memory constraints. */
#ifndef COAP_MAX_OPEN_TRANSACTIONS
#define COAP_MAX_OPEN_TRANSACTIONS 4
#endif
/* Must be <= open transaction number */
/* Must be <= open transaction number. */
#ifndef COAP_MAX_OBSERVERS
#define COAP_MAX_OBSERVERS COAP_MAX_OPEN_TRANSACTIONS
#endif

View file

@ -125,7 +125,7 @@ helloworld_handler(void* request, void* response, uint8_t *buffer, uint16_t pref
}
/* This resource mirrors the incoming request. It shows how to access the options and how to set them for the response. */
RESOURCE(mirror, METHOD_GET | METHOD_POST | METHOD_PUT | METHOD_DELETE, "mirror", "title=\"Returns your decoded message\";rt=\"Debug\"");
RESOURCE(mirror, METHOD_GET | METHOD_POST | METHOD_PUT | METHOD_DELETE, "debug/mirror", "title=\"Returns your decoded message\";rt=\"Debug\"");
void
mirror_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
@ -282,7 +282,7 @@ mirror_handler(void* request, void* response, uint8_t *buffer, uint16_t preferre
* These chunk-wise resources must set the offset value to its new position or -1 of the end is reached.
* (The offset for CoAP's blockwise transfer can go up to 2'147'481'600 = ~2047 M for block size 2048 (reduced to 1024 in observe-03.)
*/
RESOURCE(chunks, METHOD_GET, "chunks", "title=\"Blockwise demo\";rt=\"Data\"");
RESOURCE(chunks, METHOD_GET, "debug/chunks", "title=\"Blockwise demo\";rt=\"Data\"");
#define CHUNKS_TOTAL 2050
@ -335,7 +335,7 @@ chunks_handler(void* request, void* response, uint8_t *buffer, uint16_t preferre
* It takes an additional period parameter, which defines the interval to call [name]_periodic_handler().
* A default post_handler takes care of subscriptions by managing a list of subscribers to notify.
*/
PERIODIC_RESOURCE(polling, METHOD_GET, "poll", "title=\"Periodic demo\";rt=\"Observable\"", 5*CLOCK_SECOND);
PERIODIC_RESOURCE(polling, METHOD_GET, "debug/poll", "title=\"Periodic demo\";rt=\"Observable\"", 5*CLOCK_SECOND);
void
polling_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
@ -372,7 +372,7 @@ polling_periodic_handler(resource_t *r)
* Additionally takes a period parameter that defines the interval to call [name]_periodic_handler().
* A default post_handler takes care of subscriptions and manages a list of subscribers to notify.
*/
EVENT_RESOURCE(event, METHOD_GET, "event", "title=\"Event demo\";rt=\"Observable\"");
EVENT_RESOURCE(event, METHOD_GET, "sensors/button", "title=\"Event demo\";rt=\"Observable\"");
void
event_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
@ -405,7 +405,7 @@ event_event_handler(resource_t *r)
#if defined (PLATFORM_HAS_LEDS)
/*A simple actuator example, depending on the color query parameter and post variable mode, corresponding led is activated or deactivated*/
RESOURCE(led, METHOD_POST | METHOD_PUT , "leds", "title=\"LEDs: ?color=r|g|b, POST/PUT mode=on|off\";rt=\"Control\"");
RESOURCE(led, METHOD_POST | METHOD_PUT , "actuators/leds", "title=\"LEDs: ?color=r|g|b, POST/PUT mode=on|off\";rt=\"Control\"");
void
led_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
@ -452,7 +452,7 @@ led_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred_s
}
/* A simple actuator example. Toggles the red led */
RESOURCE(toggle, METHOD_GET | METHOD_PUT | METHOD_POST, "toggle", "title=\"Red LED\";rt=\"Control\"");
RESOURCE(toggle, METHOD_GET | METHOD_PUT | METHOD_POST, "actuators/toggle", "title=\"Red LED\";rt=\"Control\"");
void
toggle_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
{
@ -462,7 +462,7 @@ toggle_handler(void* request, void* response, uint8_t *buffer, uint16_t preferre
#if defined (PLATFORM_HAS_LIGHT)
/* A simple getter example. Returns the reading from light sensor with a simple etag */
RESOURCE(light, METHOD_GET, "light", "title=\"Photosynthetic and solar light (supports JSON)\";rt=\"LightSensor\"");
RESOURCE(light, METHOD_GET, "sensors/light", "title=\"Photosynthetic and solar light (supports JSON)\";rt=\"LightSensor\"");
void
light_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
{
@ -503,7 +503,7 @@ light_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred
#if defined (PLATFORM_HAS_BATTERY)
/* A simple getter example. Returns the reading from light sensor with a simple etag */
RESOURCE(battery, METHOD_GET, "battery", "title=\"Battery status\";rt=\"Battery\"");
RESOURCE(battery, METHOD_GET, "sensors/battery", "title=\"Battery status\";rt=\"Battery\"");
void
battery_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
{

View file

@ -240,7 +240,7 @@ PROCESS_THREAD(border_router_process, ev, data)
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
}
dag = rpl_set_root((uip_ip6addr_t *)dag_id);
dag = rpl_set_root(RPL_DEFAULT_INSTANCE,(uip_ip6addr_t *)dag_id);
if(dag != NULL) {
rpl_set_prefix(dag, &prefix, 64);
PRINTF("created a new RPL dag\n");
@ -258,7 +258,7 @@ PROCESS_THREAD(border_router_process, ev, data)
PROCESS_YIELD();
if (ev == sensors_event && data == &button_sensor) {
PRINTF("Initiating global repair\n");
rpl_repair_dag(rpl_get_dag(RPL_ANY_INSTANCE));
rpl_repair_root(RPL_DEFAULT_INSTANCE);
}
}

View file

@ -71,7 +71,8 @@ collect_common_net_print(void)
{
rpl_dag_t *dag;
int i;
dag = rpl_get_dag(RPL_ANY_INSTANCE);
/* Let's suppose we have only one instance */
dag = rpl_get_any_dag();
if(dag->preferred_parent != NULL) {
PRINTF("Preferred parent: ");
PRINT6ADDR(&dag->preferred_parent->addr);
@ -128,7 +129,8 @@ collect_common_send(void)
rimeaddr_copy(&parent, &rimeaddr_null);
parent_etx = 0;
dag = rpl_get_dag(RPL_DEFAULT_INSTANCE);
/* Let's suppose we have only one instance */
dag = rpl_get_any_dag();
if(dag != NULL) {
preferred_parent = dag->preferred_parent;
if(preferred_parent != NULL) {
@ -142,7 +144,7 @@ collect_common_send(void)
}
}
rtmetric = dag->rank;
beacon_interval = (uint16_t) ((2L << dag->dio_intcurrent) / 1000);
beacon_interval = (uint16_t) ((2L << dag->instance->dio_intcurrent) / 1000);
num_neighbors = RPL_PARENT_COUNT(dag);
} else {
rtmetric = 0;

View file

@ -151,8 +151,7 @@ PROCESS_THREAD(udp_server_process, ev, data)
root_if = uip_ds6_addr_lookup(&ipaddr);
if(root_if != NULL) {
rpl_dag_t *dag;
rpl_set_root((uip_ip6addr_t *)&ipaddr);
dag = rpl_get_dag(RPL_ANY_INSTANCE);
dag = rpl_set_root(RPL_DEFAULT_INSTANCE,(uip_ip6addr_t *)&ipaddr);
uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
rpl_set_prefix(dag, &ipaddr, 64);
PRINTF("created a new RPL dag\n");
@ -181,7 +180,7 @@ PROCESS_THREAD(udp_server_process, ev, data)
tcpip_handler();
} else if (ev == sensors_event && data == &button_sensor) {
PRINTF("Initiaing global repair\n");
rpl_repair_dag(rpl_get_dag(RPL_ANY_INSTANCE));
rpl_repair_root(RPL_DEFAULT_INSTANCE);
}
}

View file

@ -4,6 +4,7 @@ CONTIKI=../../..
WITH_UIP6=1
UIP_CONF_IPV6=1
CFLAGS+= -DUIP_CONF_IPV6_RPL
ifdef WITH_COMPOWER

View file

@ -135,8 +135,7 @@ PROCESS_THREAD(udp_server_process, ev, data)
root_if = uip_ds6_addr_lookup(&ipaddr);
if(root_if != NULL) {
rpl_dag_t *dag;
rpl_set_root((uip_ip6addr_t *)&ipaddr);
dag = rpl_get_dag(RPL_ANY_INSTANCE);
dag = rpl_set_root(RPL_DEFAULT_INSTANCE,(uip_ip6addr_t *)&ipaddr);
uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
rpl_set_prefix(dag, &ipaddr, 64);
PRINTF("created a new RPL dag\n");
@ -169,7 +168,7 @@ PROCESS_THREAD(udp_server_process, ev, data)
tcpip_handler();
} else if (ev == sensors_event && data == &button_sensor) {
PRINTF("Initiaing global repair\n");
rpl_repair_dag(rpl_get_dag(RPL_ANY_INSTANCE));
rpl_repair_root(RPL_DEFAULT_INSTANCE);
}
}

View file

@ -620,11 +620,11 @@ extern uip_ds6_netif_t uip_ds6_if;
}
case 'G':
PRINTF_P(PSTR("Global repair returns %d\n\r"),rpl_repair_dag(rpl_get_dag(RPL_ANY_INSTANCE)));
PRINTF_P(PSTR("Global repair returns %d\n\r"),rpl_repair_root(RPL_DEFAULT_INSTANCE));
break;
case 'L':
rpl_local_repair(rpl_get_dag(RPL_ANY_INSTANCE));
rpl_local_repair(rpl_get_any_dag());
PRINTF_P(PSTR("Local repair initiated\n\r"));
break;

View file

@ -164,7 +164,7 @@ PROCESS_THREAD(border_router_process, ev, data)
{ rpl_dag_t *dag;
char buf[sizeof(dag_id)];
memcpy_P(buf,dag_id,sizeof(dag_id));
dag = rpl_set_root((uip_ip6addr_t *)buf);
dag = rpl_set_root(RPL_DEFAULT_INSTANCE,(uip_ip6addr_t *)buf);
/* Assign separate addresses to the jackdaw uip stack and the host network interface, but with the same prefix */
/* E.g. bbbb::200 to the jackdaw and bbbb::1 to the host network interface with $ip -6 address add bbbb::1/64 dev usb0 */
@ -192,8 +192,6 @@ PROCESS_THREAD(border_router_process, ev, data)
while(1) {
PROCESS_YIELD();
/* Local and global dag repair can be done from the jackdaw menu */
// rpl_set_prefix(rpl_get_dag(RPL_ANY_INSTANCE), &ipaddr, 64);
// rpl_repair_dag(rpl_get_dag(RPL_ANY_INSTANCE));
}

View file

@ -1,121 +0,0 @@
# $Id: Makefile,v 1.7 2007/05/21 14:30:52 bg- Exp $
#
# This makefile requires GNU make!
LIB = libcontiki.a
KERNELS = gateway.ihex
PROGS = #loadable_prg.ko udpsend.ko udprecv.ko
TOOLS = tunslip scat codeprop
all: $(LIB) $(KERNELS) $(PROGS) $(TOOLS)
loadable_prg.ko: loadable_prg.o
udpsend.ko: udpsend.o
udprecv.ko: udprecv.o
test.ko: test.o
gateway.out: gateway.o $(LIB)
client.out: client.o $(LIB)
dhclient.out: dhclient.o $(LIB)
TOP=../..
INCDIRS = -I. -I$(TOP)/cpu/avr -I$(TOP)/core -I$(TOP)/apps
SRCDIRS = dev $(TOP)/cpu/avr $(TOP)/cpu/avr/dev ${addprefix $(TOP)/core/,sys dev net lib loader} $(TOP)/apps/codeprop
MCU=atmega128
ARCH=avr.o spi.o qleds.o rom.o xmem.o cle_avr.o
SYSTEM=process.o procinit.o service.o clock.o etimer.o timer.o \
sym.o cle.o elfloader_compat.o
UIP=uip.o uiplib.o tcpip.o uip-fw.o uip-fw-drv.o uipbuf.o \
tcpdump.o psock.o dhcpc.o uaodv.o uaodv-rt.o uip-udp-packet.o
UIPDRIVERS=slip.o slip_uart1.o \
cc2420.o cc2420_spi.o cc2420_send_ip.o cc2420_send_uaodv.o
LIBS=memb.o list.o rand.o assert.o crtk.o
SYSAPPS=tcp_loader.o
LIBFILES=$(SYSTEM) $(ARCH) $(UIP) $(UIPDRIVERS) $(LIBS) $(SYSAPPS)
MKNMLIST=awk -f $(TOP)/tools/mknmlist-ansi
CP=cp
LIBC=-lgcc -lc -lgcc
CC=avr-gcc
LD=avr-ld
AS=avr-as
NM=avr-nm
OBJCOPY=avr-objcopy
STRIP=avr-strip
AR=avr-ar
RANLIB=avr-ranlib
BSL=avrdude
CFLAGS=-mmcu=$(MCU) $(INCDIRS) -Wall -Os
LDFLAGS=-mmcu=$(MCU) -Wl,--section-start=.bootloader=$(BOOTLOADER_START)
# Check fuse high byte, bits BOOTSZ0 and BOOTSZ1.
BOOTLOADER_START=0x1fc00
# Setup directory search path for source files
vpath %.c $(SRCDIRS) ${filter-out CVS,${wildcard labs/*}}
# Set COM port if not already set.
# DOS: 1 => COM2, 2 => COM3, etc.
# Linux: /dev/ttyUSB0, /dev/ttyUSB1, etc.
# FreeBSD 6.2: /dev/cuaU0, /dev/cuaU1, etc.
ifndef COMPORT
COMPORT := /dev/ttyUSB0
endif
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $(notdir $(<:.c=.o))
# Combine several .o:s to one .ko and put COMMONs into the BSS segment
%.ko:
$(LD) -r -dc --strip-all --unresolved-symbols=ignore-in-object-files $^ -o $@
%.ihex: %.out
$(OBJCOPY) $^ -O ihex $@
#%.out:
# $(if $^,$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $^,$(error "NO TARGET $@"))
# Add a namelist to the kernel
%.out: $^
: | $(MKNMLIST) > $@_tmp.c && mv $@_tmp.c $@_nm.c
$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $^ $(LIBC) $@_nm.c
$(NM) $@ | $(MKNMLIST) > $@_tmp.c && mv $@_tmp.c $@_nm.c
$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $^ $(LIBC) $@_nm.c
%.u: %.ihex
$(BSL) -p $(MCU) -P $(COMPORT) -c stk500 -U flash:w:$<
$(LIB): $(LIBFILES)
$(AR) rcf $@ $^
$(RANLIB) $@
codeprop: $(TOP)/tools/codeprop.c
cc -g -Wall $< -o $@
tunslip: $(TOP)/tools/tunslip.c
cc -g -Wall -DBAUDRATE="B38400" $< -o $@
scat: $(TOP)/tools/scat.c
cc -g -Wall -DBAUDRATE="B38400" $< -o $@
### TEST ###
test.out: test.o $(LIB)
$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $^
depend: $(LIBFILES:.o=.c)
-$(CC) $(CCDEPFLAGS) -MM $(CFLAGS) $(INCDIRS) $^ *.c >Makefile.depend
tags: $(LIBFILES:.o=.c)
etags $^
clean:
rm -f *.o *.ko *~ *.core *.out *.ihex *_nm.c
rm -f $(LIB) $(KERNELS) $(TOOLS)
.PHONY: all
-include Makefile.depend

View file

@ -1,162 +0,0 @@
/* -*- C -*- */
/* @(#)$Id: contiki-conf.h,v 1.5 2010/06/22 06:39:44 joxe Exp $ */
#ifndef CONTIKI_CONF_H
#define CONTIKI_CONF_H
#include <avr/interrupt.h>
#define HAVE_STDINT_H
#include "avrdef.h"
/* #define CB_GATEWAY */
#define CCIF
#define CLIF
#define AODV_COMPLIANCE
#define AODV_NUM_RT_ENTRIES 32
void clock_delay(unsigned int us2);
void clock_wait(int ms10);
void clock_set_seconds(unsigned long s);
unsigned long clock_seconds(void);
#define WITH_UIP 1
#define WITH_ASCII 1
#define PROCESS_CONF_FASTPOLL 4
/* Our clock resolution, this is the same as Unix HZ. */
/* Fix clock.c XXX/bg */
#define CLOCK_CONF_SECOND 62
/* CPU target speed in Hz */
#define F_CPU 8000000L
/* The +1 and divide by 2 is to achieve rounding. */
#define BAUD2UBR(baud) ((u16_t)((F_CPU/baud/8uL + 1)/2 - 1))
/* UART configs */
//#define MCU_MHZ 8
//#define MCU atmega128
//#define SLIP_PORT RS232_PORT_1
#define UIP_CONF_DHCP_LIGHT
#define UIP_CONF_LLH_LEN 0
#define UIP_CONF_BUFFER_SIZE 116
#define UIP_CONF_RECEIVE_WINDOW (UIP_CONF_BUFFER_SIZE - 40)
#define UIP_CONF_MAX_CONNECTIONS 4
#define UIP_CONF_MAX_LISTENPORTS 8
#define UIP_CONF_UDP_CONNS 12
#define UIP_CONF_FWCACHE_SIZE 30
#define UIP_CONF_BROADCAST 1
//#define UIP_ARCH_IPCHKSUM 1
#define UIP_CONF_UDP_CHECKSUMS 1
#define UIP_CONF_PINGADDRCONF 0
#define UIP_CONF_LOGGING 0
/*
* Definitions below are dictated by the hardware and not really
* changeable!
*/
#ifdef CB_GATEWAY
/* LED port E */
#define LEDS_CONF_GREEN _BV(2) /* PE.2 - Output */
#define LEDS_CONF_YELLOW _BV(3) /* PE.3 - Output */
#else
#define LEDS_ORANGE 8
/* LED port B */
#define LEDS_CONF_ORANGE _BV(4) /* PB.4 - Output */
#define LEDS_CONF_GREEN _BV(7) /* PB.7 - Output */
/* LED port E */
#define LEDS_CONF_RED _BV(3) /* PE.3 - Output */
#define LEDS_CONF_YELLOW _BV(4) /* PE.4 - Output */
#endif
typedef u16_t uip_stats_t;
typedef u16_t clock_time_t;
typedef u32_t off_t;
#define ROM_ERASE_UNIT_SIZE SPM_PAGESIZE
#define XMEM_ERASE_UNIT_SIZE 8
/* Use the first 64k of external flash for codeprop. */
#define EEPROMFS_ADDR_CODEPROP (128 * XMEM_ERASE_UNIT_SIZE)
#define CC2420_RADIO
/* LOOP count for waiting 20 symbols in the CC2420 code */
#define CC2420_CONF_SYMBOL_LOOP_COUNT 500
/*
* SPI bus configuration for the CC2420DBK.
*/
/* SPI input/output registers. */
#define SPI_TXBUF SPDR
#define SPI_RXBUF SPDR
#define BV(bitno) _BV(bitno)
#define SPI_WAITFOREOTx() do { while (!(SPSR & BV(SPIF))); } while (0)
#define SPI_WAITFOREORx() do { while (!(SPSR & BV(SPIF))); } while (0)
#define SCK 1 /* - Output: SPI Serial Clock (SCLK) */
#define MOSI 2 /* - Output: SPI Master out - slave in (MOSI) */
#define MISO 3 /* - Input: SPI Master in - slave out (MISO) */
/*
* SPI bus - CC2420 pin configuration.
*/
#define FIFO_P 0 /* - Input: FIFOP from CC2420 */
#define FIFO 1 /* - Input: FIFO from CC2420 */
#define CCA 6 /* - Input: CCA from CC2420 */
#define SFD 4 /* - Input: SFD from CC2420 */
#define CSN 0 /* - Output: SPI Chip Select (CS_N) */
#define VREG_EN 5 /* - Output: VREG_EN to CC2420 */
#define RESET_N 6 /* - Output: RESET_N to CC2420 */
/* Pin status. */
#define FIFO_IS_1 (!!(PIND & BV(FIFO)))
#define CCA_IS_1 (!!(PIND & BV(CCA) ))
#define RESET_IS_1 (!!(PINB & BV(RESET_N)))
#define VREG_IS_1 (!!(PINB & BV(VREG_EN)))
#define FIFOP_IS_1 (!!(PIND & BV(FIFO_P)))
#define SFD_IS_1 (!!(PIND & BV(SFD)))
/* The CC2420 reset pin. */
#define SET_RESET_INACTIVE() ( PORTB |= BV(RESET_N) )
#define SET_RESET_ACTIVE() ( PORTB &= ~BV(RESET_N) )
/* CC2420 voltage regulator enable pin. */
#define SET_VREG_ACTIVE() ( PORTB |= BV(VREG_EN) )
#define SET_VREG_INACTIVE() ( PORTB &= ~BV(VREG_EN) )
/* CC2420 rising edge trigger for external interrupt 0 (FIFOP). */
#define FIFOP_INT_INIT() do {\
EICRA |= 0x03; \
CLEAR_FIFOP_INT(); \
} while (0)
/* FIFOP on external interrupt 0. */
#define ENABLE_FIFOP_INT() do { EIMSK |= 0x01; } while (0)
#define DISABLE_FIFOP_INT() do { EIMSK &= ~0x01; } while (0)
#define CLEAR_FIFOP_INT() do { EIFR = 0x01; } while (0)
/* Enables/disables CC2420 access to the SPI bus (not the bus).
*
* These guys should really be renamed but are compatible with the
* original Chipcon naming.
*
* SPI_CC2420_ENABLE/SPI_CC2420_DISABLE???
* CC2420_ENABLE_SPI/CC2420_DISABLE_SPI???
*/
#define SPI_ENABLE() ( PORTB &= ~BV(CSN) ) /* ENABLE CSn (active low) */
#define SPI_DISABLE() ( PORTB |= BV(CSN) ) /* DISABLE CSn (active low) */
#endif /* CONTIKI_CONF_H */

View file

@ -1,90 +0,0 @@
/*
* 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.
*
* @(#)$Id: cb_uart01.c,v 1.1 2007/02/02 14:09:06 bg- Exp $
*/
#include <stdio.h>
#include <avr/interrupt.h>
#include "contiki.h"
#include "dev/slip.h"
static int
uart0_putchar(char c, FILE *stream)
{
while (!(UCSR0A & BV(UDRE0)))
;
UDR0 = c;
return c;
}
static FILE uart0_stdout =
FDEV_SETUP_STREAM(uart0_putchar, NULL, _FDEV_SETUP_WRITE);
void
slip_arch_init(unsigned long ubr)
{
u8_t dummy;
spl_t s = splhigh();
UBRR1L = ubr;
UBRR1H = ubr >> 8;
UCSR1C = BV(UCSZ1) | BV(UCSZ0); /* 1 start bit, no parity, 1 stop bit */
UCSR1B = BV(RXEN) | BV(TXEN) | BV(RXCIE);
dummy = UDR1; /* Flush RX buffer. */
/* And now UART0. */
UBRR0L = BAUD2UBR(38400);
UBRR0H = BAUD2UBR(38400) >> 8;
UCSR0C = BV(UCSZ1) | BV(UCSZ0); /* 1 start bit, no parity, 1 stop bit */
UCSR0B = BV(TXEN); /* TX ONLY!!! */
splx(s);
stdout = &uart0_stdout;
}
void
slip_arch_writeb(unsigned char c)
{
while (!(UCSR1A & BV(UDRE1)))
;
UDR1 = c;
}
ISR(SIG_UART1_RECV)
{
/* Should deal with receive errors. */
slip_input_byte(UDR1);
}

View file

@ -1,119 +0,0 @@
/*
* 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.
*
* @(#)$Id: qleds.c,v 1.1 2007/02/02 14:07:34 bg- Exp $
*/
#include "contiki.h"
#include "dev/leds.h"
#include <avr/io.h>
void
leds_init(void)
{
#ifdef CB_GATEWAY
DDRE |= LEDS_CONF_GREEN | LEDS_CONF_YELLOW;
PORTE |= LEDS_CONF_GREEN | LEDS_CONF_YELLOW; /* LEDS off */
#else
DDRB |= LEDS_CONF_ORANGE | LEDS_CONF_GREEN;
DDRE |= LEDS_CONF_RED | LEDS_CONF_YELLOW;
PORTB &= ~(LEDS_CONF_ORANGE | LEDS_CONF_GREEN);
PORTE &= ~(LEDS_CONF_RED | LEDS_CONF_YELLOW);
#endif
}
void
leds_on(unsigned char leds)
{
#ifdef CB_GATEWAY
if (leds & LEDS_GREEN)
PORTE &= ~LEDS_CONF_GREEN;
if (leds & LEDS_YELLOW)
PORTE &= ~LEDS_CONF_YELLOW;
#else
if (leds & LEDS_ORANGE)
PORTB |= LEDS_CONF_ORANGE;
if (leds & LEDS_GREEN)
PORTB |= LEDS_CONF_GREEN;
if (leds & LEDS_RED)
PORTE |= LEDS_CONF_RED;
if (leds & LEDS_YELLOW)
PORTE |= LEDS_CONF_YELLOW;
#endif
}
void
leds_off(unsigned char leds)
{
#ifdef CB_GATEWAY
if (leds & LEDS_GREEN)
PORTE |= LEDS_CONF_GREEN;
if (leds & LEDS_YELLOW)
PORTE |= LEDS_CONF_YELLOW;
#else
if (leds & LEDS_ORANGE)
PORTB &= ~LEDS_CONF_ORANGE;
if (leds & LEDS_GREEN)
PORTB &= ~LEDS_CONF_GREEN;
if (leds & LEDS_RED)
PORTE &= ~LEDS_CONF_RED;
if (leds & LEDS_YELLOW)
PORTE &= ~LEDS_CONF_YELLOW;
#endif
}
void
leds_toggle(unsigned char leds)
{
/*
* Synonym: void leds_invert(unsigned char leds);
*/
asm(".global leds_invert\nleds_invert:\n");
#ifdef CB_GATEWAY
if (leds & LEDS_GREEN)
PORTE ^= ~LEDS_CONF_GREEN;
if (leds & LEDS_YELLOW)
PORTE ^= ~LEDS_CONF_YELLOW;
#else
if (leds & LEDS_ORANGE)
PORTB ^= LEDS_CONF_ORANGE;
if (leds & LEDS_GREEN)
PORTB ^= LEDS_CONF_GREEN;
if (leds & LEDS_RED)
PORTE ^= LEDS_CONF_RED;
if (leds & LEDS_YELLOW)
PORTE ^= LEDS_CONF_YELLOW;
#endif
}

View file

@ -1,127 +0,0 @@
/*
* 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.
*
* @(#)$Id: rom.c,v 1.1 2007/02/02 14:08:22 bg- Exp $
*/
#include <stdio.h>
#include <avr/boot.h>
#include <avr/pgmspace.h>
#include "contiki.h"
#include "lib/assert.h"
#include "dev/rom.h"
#if 0
#define PRINTF(...) printf(__VA_ARGS__)
#else
#define PRINTF(...) do {} while (0)
#endif
BOOTLOADER_SECTION
int
rom_erase(long nbytes, off_t offset)
{
long nb = nbytes;
if(nbytes % ROM_ERASE_UNIT_SIZE != 0) {
return -1;
}
if(offset % ROM_ERASE_UNIT_SIZE != 0) {
return -1;
}
PRINTF("rom_erase(%ld, %06lx)\n", nbytes, offset);
while (nbytes > 0) {
spl_t s = splhigh();
eeprom_busy_wait();
boot_page_erase(offset);
boot_spm_busy_wait();
boot_rww_enable(); /* Before return or intr. */
splx(s);
nbytes -= ROM_ERASE_UNIT_SIZE;
offset += ROM_ERASE_UNIT_SIZE;
}
return nb;
}
int
rom_pread(void *buf, int nbytes, off_t offset)
{
PRINTF("rom_pread(%p, %d, %06lx)\n", buf, nbytes, offset);
assert(offset == (uintptr_t)offset);
assert((offset + nbytes) == (uintptr_t)(offset + nbytes));
memcpy_P(buf, (PGM_P)(uintptr_t)offset, nbytes);
return nbytes;
}
BOOTLOADER_SECTION
int
rom_pwrite(const void *buf, int nbytes, off_t offset)
{
long nb = nbytes;
const unsigned char *from = buf;
PRINTF("rom_pwrite(%p, %d, %06lx)\n", buf, nbytes, offset);
while(nbytes > 0) {
int i, n = (nbytes > ROM_ERASE_UNIT_SIZE) ? ROM_ERASE_UNIT_SIZE : nbytes;
spl_t s = splhigh();
eeprom_busy_wait();
for (i = 0; i < n; i += 2) {
uint16_t w = *from++;
w |= (*from++) << 8;
boot_page_fill(offset + i, w);
}
boot_page_write(offset);
boot_spm_busy_wait();
boot_rww_enable(); /* Before return or intr. */
splx(s);
nbytes -= ROM_ERASE_UNIT_SIZE;
offset += ROM_ERASE_UNIT_SIZE;
}
return nb;
}

View file

@ -1,92 +0,0 @@
/*
* 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.
*
* @(#)$Id: xmem.c,v 1.1 2007/02/02 14:08:22 bg- Exp $
*/
/*
* External memory built from the AVR eeprom. It is incredibly slow!
*/
#include <stdio.h>
#include <avr/eeprom.h>
#include "contiki.h"
#include "dev/xmem.h"
#if 0
#define PRINTF(...) printf(__VA_ARGS__)
#else
#define PRINTF(...) do {} while (0)
#endif
/*
*/
void
xmem_init(void)
{
PRINTF("xmem_init\n");
}
int
xmem_pread(void *_p, int size, off_t offset)
{
PRINTF("xmem_pread(%p, %d, %06lx)\n", _p, size, offset);
spl_t s = splhigh();
eeprom_busy_wait();
eeprom_read_block(_p, (void *)(uintptr_t)offset, size);
splx(s);
return size;
}
int
xmem_pwrite(const void *_p, int size, off_t offset)
{
PRINTF("xmem_pwrite(%p, %d, %06lx)\n", _p, size, offset);
spl_t s = splhigh();
eeprom_busy_wait();
eeprom_write_block(_p, (void *)(uintptr_t)offset, size);
splx(s);
return size;
}
int
xmem_erase(long size, off_t offset)
{
/*
* AVR internal eeprom has a kind of auto erase, thus nothing is
* done here.
*/
PRINTF("xmem_erase(%ld, %06lx)\n", size, offset);
return size;
}

View file

@ -1,169 +0,0 @@
/*
* 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.
*
* @(#)$Id: gateway.c,v 1.4 2010/10/19 18:29:05 adamdunkels Exp $
*/
/*
* Example gateway configuration with two IP interfaces, one SLIP over
* USB and one over 802.11.4 radio.
*
* The IP address is hardcoded to 172.16.0.1 and the 172.16/16 network
* is on the radio interface.
*
* The default route is over the SLIP interface.
*
* On the SLIP host run a standard SLIP implementation or the tunslip
* program that can also view debug printfs, example:
*
* sliphost# ./tunslip 172.16.0.1 255.255.0.0
*
*
* This kernel has no application code but new modules can be uploaded
* using the codeprop program, example:
*
* datan$ ./codeprop 172.16.0.1 loadable_prg.ko
* File successfully sent (1116 bytes)
* Reply: ok
*
*/
#include <stdio.h>
#include <avr/eeprom.h>
#include "contiki.h"
/* Also IP output. */
#include "net/uip-fw-drv.h"
#include "net/uaodv.h"
#include "dev/slip.h"
#include "dev/cc2420.h"
#include "dev/leds.h"
#include "dev/xmem.h"
#include "codeprop/codeprop.h"
/* We have two IP interfaces. */
struct uip_fw_netif cc2420if =
{UIP_FW_NETIF(172,16,0,1, 255,255,0,0, cc2420_send_uaodv)};
static struct uip_fw_netif slipif =
{UIP_FW_NETIF(0,0,0,0, 255,255,255,255, slip_send)};
/* Radio stuff in network byte order. */
static u16_t panId = UIP_HTONS(0x2024);
#ifndef RF_CHANNEL
#define RF_CHANNEL 15
#endif
unsigned char ds2411_id[8] = { 0x00, 0x12, 0x4b, 0x00, 0x00, 0x00, 0x09, 0x04};
static void
ds2411_init(void)
{
u8_t i, t;
eeprom_read_block(ds2411_id, 0, 8);
for (i = 0; i < 4; i++) {
t = ds2411_id[i];
ds2411_id[i] = ds2411_id[7 - i];
ds2411_id[7 - i] = t;
}
}
int
main(int argc, char **argv)
{
/*
* Initalize hardware.
*/
cpu_init();
clock_init();
leds_init();
leds_toggle(LEDS_ALL);
slip_arch_init(BAUD2UBR(38400)); /* Must come before first printf */
printf("Starting %s "
"($Id: gateway.c,v 1.4 2010/10/19 18:29:05 adamdunkels Exp $)\n", __FILE__);
ds2411_init();
cc2420_init();
xmem_init();
clock_wait(CLOCK_SECOND/10);
leds_toggle(LEDS_ALL);
/*
* Hardware initialization done!
*/
printf("MAC %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x CHANNEL %d\n",
ds2411_id[0], ds2411_id[1], ds2411_id[2], ds2411_id[3],
ds2411_id[4], ds2411_id[5], ds2411_id[6], ds2411_id[7],
RF_CHANNEL);
uip_ipaddr_copy(&uip_hostaddr, &cc2420if.ipaddr);
uip_ipaddr_copy(&uip_netmask, &cc2420if.netmask);
printf("IP %d.%d.%d.%d netmask %d.%d.%d.%d\n",
uip_ipaddr_to_quad(&uip_hostaddr),
uip_ipaddr_to_quad(&uip_netmask));
cc2420_set_chan_pan_addr(RF_CHANNEL, panId, uip_hostaddr.u16[1], ds2411_id);
/*
* Initialize Contiki and our processes.
*/
process_init();
process_start(&etimer_process, NULL);
/* Configure IP stack. */
uip_init();
uip_fw_default(&slipif); /* Point2point, no default router. */
uip_fw_register(&cc2420if);
tcpip_set_forwarding(1);
/* Start IP stack. */
process_start(&tcpip_process, NULL);
process_start(&uip_fw_process, NULL); /* Start IP output */
process_start(&slip_process, NULL);
process_start(&cc2420_process, NULL);
cc2420_on();
process_start(&uaodv_process, NULL);
//process_start(&tcp_loader_process, NULL);
/*
* This is the scheduler loop.
*/
printf("process_run()...\n");
while (1) {
do {
/* Reset watchdog. */
} while(process_run() > 0);
/* Idle! */
}
return 0;
}

View file

@ -1,17 +0,0 @@
CONTIKI_TARGET_DIRS = . dev apps net loader
CONTIKI_TARGET_MAIN = ethernut-main.o
CONTIKI_TARGET_SOURCEFILES += slip.c rs232.c ethernut-main.c \
rtl8019-drv.c rtl8019.c rtl8019dev.c debug.c delay.c
CONTIKIAVR=$(CONTIKI)/cpu/avr
CONTIKIBOARD=.
APPS+=webserver telnetd #program-handler shell
MCU=atmega128
CONTIKI_PLAT_DEFS = -DF_CPU=14745600UL -DAUTO_CRC_PADDING=2
include $(CONTIKIAVR)/Makefile.avr
%.u: %.$(TARGET)
avrdude -P /dev/cuaa0 -c stk500 -p atmega128 -v -e
avrdude -P /dev/cuaa0 -c stk500 -p atmega128 -v -U flash:w:$<

View file

@ -1,165 +0,0 @@
#ifndef __CONTIKI_CONF_H__
#define __CONTIKI_CONF_H__
#define CC_CONF_REGISTER_ARGS 1
#define CC_CONF_FUNCTION_POINTER_ARGS 1
#define CCIF
#define CLIF
typedef unsigned short clock_time_t;
#define CLOCK_CONF_SECOND 1000
void clock_delay(unsigned int us2);
void clock_wait(int ms10);
void clock_set_seconds(unsigned long s);
unsigned long clock_seconds(void);
/*
* This file is used for setting various compile time settings for the
* CTK GUI toolkit.
*/
#include "ctk/ctk-vncarch.h"
/* Defines which key that is to be used for activating the menus */
#define CTK_CONF_MENU_KEY CH_F1
/* Defines which key that is to be used for switching the frontmost
window. */
#define CTK_CONF_WINDOWSWITCH_KEY CH_ESC
/* Defines which key that is to be used for switching to the next
widget. */
#define CTK_CONF_WIDGETDOWN_KEY CH_TAB
/* Defines which key that is to be used for switching to the prevoius
widget. */
#define CTK_CONF_WIDGETUP_KEY 1
/* Toggles support for icons. */
#define CTK_CONF_ICONS 1 /* 107 bytes */
/* Toggles support for icon bitmaps. */
#define CTK_CONF_ICON_BITMAPS 1
/* Toggles support for icon textmaps. */
#define CTK_CONF_ICON_TEXTMAPS 1
/* Toggles support for windows. */
#define CTK_CONF_WINDOWS 1
/* Toggles support for movable windows. */
#define CTK_CONF_WINDOWMOVE 1 /* 333 bytes */
/* Toggles support for closable windows. */
#define CTK_CONF_WINDOWCLOSE 1 /* 14 bytes */
/* Toggles support for menus. */
#define CTK_CONF_MENUS 1 /* 1384 bytes */
/* Toggles mouse support (must have support functions in the
architecture specific files to work). */
#define CTK_CONF_MOUSE_SUPPORT 1
/* Defines the default width of a menu. */
#define CTK_CONF_MENUWIDTH 16
/* The maximum number of menu items in each menu. */
#define CTK_CONF_MAXMENUITEMS 10
/* Maximum number of clients to the telnet server */
#define CTK_TERM_CONF_MAX_TELNET_CLIENTS 3
/* Telnet server port */
#define CTK_TERM_CONF_TELNET_PORT 23
/* Serial server output buffer size */
#define CTK_TERM_CONF_SERIAL_BUFFER_SIZE 300
/* Maximum number of clients to the terminal module.
Should be set to CTK_TERM_CONF_MAX_TELNET_CLIENTS or
CTK_TERM_CONF_MAX_TELNET_CLIENTS+1 if the serial server is used too
*/
#define CTK_TERM_CONF_MAX_CLIENTS (CTK_TERM_CONF_MAX_TELNET_CLIENTS+1)
#define CTK_VNCSERVER_CONF_NUMCONNS 8
#define CTK_VNCSERVER_CONF_MAX_ICONS 8
#define EMAIL_CONF_WIDTH 48
#define EMAIL_CONF_HEIGHT 16
#define IRC_CONF_WIDTH 78
#define IRC_CONF_HEIGHT 20
#define IRC_CONF_SYSTEM_STRING "ethernut"
#define LIBCONIO_CONF_SCREEN_WIDTH 70
#define LIBCONIO_CONF_SCREEN_HEIGHT 40
#define LOG_CONF_ENABLED 0
#define PROGRAM_HANDLER_CONF_MAX_NUMDSCS 10
/* COM port to be used for SLIP connection */
#define SLIP_PORT RS232_PORT_0
#define TELNETD_CONF_LINELEN 64
#define TELNETD_CONF_NUMLINES 16
#define UIP_CONF_MAX_CONNECTIONS 10
#define UIP_CONF_MAX_LISTENPORTS 10
#define UIP_CONF_BUFFER_SIZE 100
#define UIP_CONF_TCP_SPLIT 1
#define UIP_CONF_UDP_CONNS 6
#define UIP_CONF_FWCACHE_SIZE 1
#define UIP_CONF_BROADCAST 1
/* The size of the HTML viewing area. */
#define WWW_CONF_WEBPAGE_WIDTH 46
#define WWW_CONF_WEBPAGE_HEIGHT 25
/* The size of the "Back" history. */
#define WWW_CONF_HISTORY_SIZE 8
/* Defines the maximum length of an URL */
#define WWW_CONF_MAX_URLLEN 160
/* The maxiumum number of widgets (i.e., hyperlinks, form elements) on
a page. */
#define WWW_CONF_MAX_NUMPAGEWIDGETS 30
/* Turns <center> support on or off; must be on for forms to work. */
#define WWW_CONF_RENDERSTATE 1
/* Toggles support for HTML forms. */
#define WWW_CONF_FORMS 1
/* Maximum lengths for various HTML form parameters. */
#define WWW_CONF_MAX_FORMACTIONLEN 80
#define WWW_CONF_MAX_FORMNAMELEN 40
#define WWW_CONF_MAX_INPUTNAMELEN 40
#define WWW_CONF_MAX_INPUTVALUELEN 40
#define WWW_CONF_PAGEVIEW 1
#define HAVE_STDINT_H
#include "avrdef.h"
typedef unsigned short uip_stats_t;
#endif /* __CONTIKI_CONF_H__ */

View file

@ -1,102 +0,0 @@
/* Copyright (c) 2005, 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. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 OS
*
* $Id: ethernut-main.c,v 1.5 2010/12/03 21:39:33 dak664 Exp $
*
*/
#include "contiki.h"
#include "contiki-net.h"
#include "dev/rs232.h"
#include "dev/rtl8019-drv.h"
#include <avr/interrupt.h>
#include <avr/io.h>
#include <avr/pgmspace.h>
PROCINIT(&etimer_process, &tcpip_process, &rtl8019_process);
static const struct uip_eth_addr ethaddr = {{0x00,0x06,0x98,0x01,0x02,0x29}};
int
main(void)
{
uip_ipaddr_t addr;
/*
* GCC depends on register r1 set to 0.
*/
asm volatile ("clr r1");
/*
* No interrupts used.
*/
cli();
/*
* Enable external data and address
* bus.
*/
MCUCR = _BV(SRE) | _BV(SRW);
clock_init();
rs232_init(RS232_PORT_0, USART_BAUD_57600,USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8);
sei();
process_init();
uip_ipaddr(&addr, 193,10,67,152);
uip_sethostaddr(&addr);
uip_setethaddr(ethaddr);
procinit_init();
autostart_start(autostart_processes);
rs232_print(RS232_PORT_0, "Initialized\n");
while(1) {
process_run();
}
return 0;
}
int
putchar(int c)
{
rs232_send(RS232_PORT_0, c);
return c;
}

View file

@ -1,11 +0,0 @@
CONTIKI_TARGET_DIRS = . dev apps net loader
CONTIKI_TARGET_MAIN = ethernut-main.o
CONTIKI_SOURCEFILES += slip.c rs232.c ethernut-main.c
CONTIKIAVR=$(CONTIKI)/cpu/avr
CONTIKIBOARD=.
MCU=atmega128
CONTIKI_PLAT_DEFS = -DF_CPU=14745600UL -DAUTO_CRC_PADDING=2
include $(CONTIKIAVR)/Makefile.avr

View file

@ -1,168 +0,0 @@
#ifndef __CONTIKI_CONF_H__
#define __CONTIKI_CONF_H__
#define CC_CONF_REGISTER_ARGS 1
#define CC_CONF_FUNCTION_POINTER_ARGS 1
#define CCIF
#define CLIF
typedef unsigned short clock_time_t;
#define CLOCK_CONF_SECOND 1000
#define NUT_CPU_FREQ 14745600UL
#define AVR_CLK_COUNT (NUT_CPU_FREQ / (128L * CLOCK_CONF_SECOND) + 0.5)
void clock_delay(unsigned int us2);
void clock_wait(int ms10);
void clock_set_seconds(unsigned long s);
unsigned long clock_seconds(void);
/*
* This file is used for setting various compile time settings for the
* CTK GUI toolkit.
*/
#include "ctk/ctk-vncarch.h"
/* Defines which key that is to be used for activating the menus */
#define CTK_CONF_MENU_KEY CH_F1
/* Defines which key that is to be used for switching the frontmost
window. */
#define CTK_CONF_WINDOWSWITCH_KEY CH_ESC
/* Defines which key that is to be used for switching to the next
widget. */
#define CTK_CONF_WIDGETDOWN_KEY CH_TAB
/* Defines which key that is to be used for switching to the prevoius
widget. */
#define CTK_CONF_WIDGETUP_KEY 1
/* Toggles support for icons. */
#define CTK_CONF_ICONS 1 /* 107 bytes */
/* Toggles support for icon bitmaps. */
#define CTK_CONF_ICON_BITMAPS 1
/* Toggles support for icon textmaps. */
#define CTK_CONF_ICON_TEXTMAPS 1
/* Toggles support for windows. */
#define CTK_CONF_WINDOWS 1
/* Toggles support for movable windows. */
#define CTK_CONF_WINDOWMOVE 1 /* 333 bytes */
/* Toggles support for closable windows. */
#define CTK_CONF_WINDOWCLOSE 1 /* 14 bytes */
/* Toggles support for menus. */
#define CTK_CONF_MENUS 1 /* 1384 bytes */
/* Toggles mouse support (must have support functions in the
architecture specific files to work). */
#define CTK_CONF_MOUSE_SUPPORT 1
/* Defines the default width of a menu. */
#define CTK_CONF_MENUWIDTH 16
/* The maximum number of menu items in each menu. */
#define CTK_CONF_MAXMENUITEMS 10
/* Maximum number of clients to the telnet server */
#define CTK_TERM_CONF_MAX_TELNET_CLIENTS 3
/* Telnet server port */
#define CTK_TERM_CONF_TELNET_PORT 23
/* Serial server output buffer size */
#define CTK_TERM_CONF_SERIAL_BUFFER_SIZE 300
/* Maximum number of clients to the terminal module.
Should be set to CTK_TERM_CONF_MAX_TELNET_CLIENTS or
CTK_TERM_CONF_MAX_TELNET_CLIENTS+1 if the serial server is used too
*/
#define CTK_TERM_CONF_MAX_CLIENTS (CTK_TERM_CONF_MAX_TELNET_CLIENTS+1)
#define CTK_VNCSERVER_CONF_NUMCONNS 8
#define CTK_VNCSERVER_CONF_MAX_ICONS 8
#define EMAIL_CONF_WIDTH 48
#define EMAIL_CONF_HEIGHT 16
#define IRC_CONF_WIDTH 78
#define IRC_CONF_HEIGHT 20
#define IRC_CONF_SYSTEM_STRING "ethernut"
#define LIBCONIO_CONF_SCREEN_WIDTH 70
#define LIBCONIO_CONF_SCREEN_HEIGHT 40
#define LOG_CONF_ENABLED 0
#define PROGRAM_HANDLER_CONF_MAX_NUMDSCS 10
/* COM port to be used for SLIP connection */
#define SLIP_PORT RS232_PORT_0
#define TELNETD_CONF_LINELEN 32
#define TELNETD_CONF_NUMLINES 16
#define UIP_CONF_MAX_CONNECTIONS 10
#define UIP_CONF_MAX_LISTENPORTS 10
#define UIP_CONF_BUFFER_SIZE 100
#define UIP_CONF_TCP_SPLIT 1
#define UIP_CONF_UDP_CONNS 6
#define UIP_CONF_FWCACHE_SIZE 1
#define UIP_CONF_BROADCAST 1
/* The size of the HTML viewing area. */
#define WWW_CONF_WEBPAGE_WIDTH 46
#define WWW_CONF_WEBPAGE_HEIGHT 25
/* The size of the "Back" history. */
#define WWW_CONF_HISTORY_SIZE 8
/* Defines the maximum length of an URL */
#define WWW_CONF_MAX_URLLEN 160
/* The maxiumum number of widgets (i.e., hyperlinks, form elements) on
a page. */
#define WWW_CONF_MAX_NUMPAGEWIDGETS 30
/* Turns <center> support on or off; must be on for forms to work. */
#define WWW_CONF_RENDERSTATE 1
/* Toggles support for HTML forms. */
#define WWW_CONF_FORMS 1
/* Maximum lengths for various HTML form parameters. */
#define WWW_CONF_MAX_FORMACTIONLEN 80
#define WWW_CONF_MAX_FORMNAMELEN 40
#define WWW_CONF_MAX_INPUTNAMELEN 40
#define WWW_CONF_MAX_INPUTVALUELEN 40
#define WWW_CONF_PAGEVIEW 1
#define HAVE_STDINT_H
#include "avrdef.h"
typedef unsigned short uip_stats_t;
#endif /* __CONTIKI_CONF_H__ */

View file

@ -1,99 +0,0 @@
/* Copyright (c) 2005, 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. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 OS
*
* $Id: ethernut-main.c,v 1.4 2010/12/03 21:39:33 dak664 Exp $
*
*/
#include "contiki.h"
#include "contiki-net.h"
#include "dev/serial-line.h"
#include "dev/slip.h"
#include "dev/rs232.h"
#include <avr/interrupt.h>
/*static void setup_xram(void) __attribute__ ((naked)) \
__attribute__ ((section (".init1")));
static void
setup_xram(void)
{
outp(BV(SRE) | BV(SRW), MCUCR);
}*/
static struct uip_fw_netif slipif =
{UIP_FW_NETIF(0,0,0,0, 0,0,0,0, slip_send)};
PROCESS(serial_test, "Serial test");
PROCESS_THREAD(serial_test, ev, data)
{
PROCESS_BEGIN();
while(1) {
PROCESS_WAIT_EVENT_UNTIL(ev == serial_line_event_message);
rs232_print(RS232_PORT_0, data);
}
PROCESS_END();
}
PROCINIT(&etimer_process, &serial_line_process, &slip_process,
&uip_fw_process);
int
main(void)
{
uip_ipaddr_t addr;
clock_init();
rs232_init(RS232_PORT_0, USART_BAUD_57600,USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8);
rs232_set_input(RS232_PORT_0, slip_input_byte);
sei();
/* Initialize drivers and event kernal */
process_init();
uip_ipaddr(&addr, 172,16,0,2);
uip_sethostaddr(&addr);
procinit_init();
autostart_start(autostart_processes);
uip_fw_default(&slipif);
rs232_print_p(RS232_PORT_0, PSTR("Initialized\n"));
while(1) {
process_run();
}
return 0;
}

View file

@ -120,7 +120,7 @@ void set_net_address(void)
print_addresses();
#if RPL_BORDER_ROUTER
dag = rpl_set_root(&ipaddr);
dag = rpl_set_root(RPL_DEFAULT_INSTANCE,&ipaddr);
if(dag != NULL) {
PRINTF("This node is setted as root of a DAG.\r\n");
}
@ -133,4 +133,4 @@ void set_net_address(void)
#endif /* FIXED_GLOBAL_ADDRESS */
#endif /* UIP_CONF_IPV6 */
#endif /* UIP_CONF_IPV6 */

View file

@ -1,34 +0,0 @@
ifndef CONTIKI
$(error CONTIKI not defined! You must specify where CONTIKI resides!)
endif
CONTIKI_TARGET_DIRS = . dev apps net
SENSORS = sensors.c beep.c button-sensor.c pir-sensor.c vib-sensor.c \
radio-sensor.c irq.c eeprom.c \
dummy-sensors.c leds.c leds-arch.c esb-sensors.c
NETSIM = ether.c ethernode.c ethernode-uip.c lpm.c rs232.c flash.c \
node.c nodes.c sensor.c display.c random.c radio.c \
dlloader.c main.c netsim-init.c contiki-main.c symtab.c symbols.c tr1001.c tr1001-drv.c cfs-posix.c cfs-posix-dir.c
ifeq ($(OS),Windows_NT)
CONTIKI_TARGET_SOURCEFILES = $(NETSIM) $(SENSORS) wpcap-drv.c wpcap.c
else
CONTIKI_TARGET_SOURCEFILES = $(NETSIM) $(SENSORS) tapdev-drv.c tapdev.c
endif
CONTIKI_SOURCEFILES += $(CONTIKI_TARGET_SOURCEFILES)
.SUFFIXES:
### Define the CPU directory
CONTIKI_CPU=$(CONTIKI)/cpu/native
include $(CONTIKI)/cpu/native/Makefile.native
### Compiler definitions
CFLAGS += $(shell gtk-config --cflags) -DNETSIM=1
TARGET_LIBFILES = $(shell gtk-config --libs)
ifeq ($(OS),Windows_NT)
TARGET_LIBFILES += /lib/w32api/libws2_32.a /lib/w32api/libiphlpapi.a
endif

View file

@ -1,139 +0,0 @@
#ifndef __CONTIKI_CONF_H__
#define __CONTIKI_CONF_H__
#define NETSTACK_CONF_RADIO ethernode_driver
#define XMAC_CONF_ON_TIME RTIMER_SECOND
#define XMAC_CONF_OFF_TIME RTIMER_SECOND * 2
/*
* Copyright (c) 2003, Adam Dunkels.
* 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. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 desktop OS
*
* $Id: contiki-conf.h,v 1.13 2010/02/18 23:10:06 adamdunkels Exp $
*
*/
#define CC_CONF_REGISTER_ARGS 1
#define CC_CONF_FUNCTION_POINTER_ARGS 1
#define CC_CONF_FASTCALL
#define CC_CONF_VA_ARGS 1
#define CCIF
#define CLIF
/*------------------------------------------------------------------------------*/
/**
* \defgroup uipopttypedef uIP type definitions
* @{
*/
#include <inttypes.h>
/**
* The 8-bit unsigned data type.
*
* This may have to be tweaked for your particular compiler. "unsigned
* char" works for most compilers.
*/
typedef uint8_t u8_t;
/**
* The 16-bit unsigned data type.
*
* This may have to be tweaked for your particular compiler. "unsigned
* short" works for most compilers.
*/
typedef uint16_t u16_t;
/**
* The 32-bit unsigned data type.
*
* This may have to be tweaked for your particular compiler. "unsigned
* short" works for most compilers.
*/
typedef uint32_t u32_t;
/**
* The 32-bit signed data type.
*
* This may have to be tweaked for your particular compiler. "signed
* short" works for most compilers.
*/
typedef int32_t s32_t;
/**
* The statistics data type.
*
* This datatype determines how high the statistics counters are able
* to count.
*/
typedef unsigned short uip_stats_t;
/** @} */
/*------------------------------------------------------------------------------*/
typedef unsigned long clock_time_t;
#define CLOCK_CONF_SECOND 1000
/*------------------------------------------------------------------------------*/
#define PACKETBUF_CONF_SIZE 128
#define PACKETBUF_CONF_HDR_SIZE 32
#define QUEUEBUF_CONF_STATS 1
#define UIP_CONF_UIP_IP4ADDR_T_WITH_U32 1
#define UIP_CONF_ICMP_DEST_UNREACH 1
#define UIP_CONF_MAX_CONNECTIONS 40
#define UIP_CONF_MAX_LISTENPORTS 40
#define UIP_CONF_BUFFER_SIZE 120
#define UIP_CONF_BYTE_ORDER UIP_LITTLE_ENDIAN
#define UIP_CONF_BROADCAST 1
#define UIP_CONF_IP_FORWARD 1
/* TCP splitting does not work well with multi hop routing. */
#define UIP_CONF_TCP_SPLIT 0
#define UIP_CONF_LOGGING 1
#define UIP_CONF_UDP_CHECKSUMS 0
#define LOADER_CONF_ARCH "loader/dlloader.h"
#endif /* __CONTIKI_CONF_H__ */

View file

@ -1,65 +0,0 @@
/*
* 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: contiki-esb.h,v 1.2 2006/10/10 15:58:31 adamdunkels Exp $
*/
/**
* \file
* A brief description of what this file is.
* \author
* Adam Dunkels <adam@sics.se>
*/
#ifndef __CONTIKI_ESB_H__
#define __CONTIKI_ESB_H__
#include "contiki.h"
#include "contiki-net.h"
#include "contiki-lib.h"
#include "dev/leds.h"
#include "dev/vib-sensor.h"
#include "dev/radio-sensor.h"
#include "dev/pir-sensor.h"
#include "dev/temperature-sensor.h"
#include "dev/button-sensor.h"
#include "dev/lpm.h"
#include "dev/radio.h"
#include "dev/tr1001.h"
#include "dev/tr1001-drv.h"
#include "dev/beep.h"
#include "node-id.h"
#endif /* __CONTIKI_ESB_H__ */

View file

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

View file

@ -1,40 +0,0 @@
/*
* Copyright (c) 2004, Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: contiki-main.h,v 1.1 2006/06/17 22:41:35 adamdunkels Exp $
*/
#ifndef __CONTIKI_MAIN_H__
#define __CONTIKI_MAIN_H__
void contiki_main(int b);
#endif /* __CONTIKI_MAIN_H__ */

View file

@ -1,88 +0,0 @@
/*
* Copyright (c) 2004, Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: beep.c,v 1.1 2006/06/17 22:41:35 adamdunkels Exp $
*/
#include <stdio.h>
#include "dev/beep.h"
void
beep_down(int n)
{
printf("beep_down(%d)\n", n);
}
void
beep_beep(int n)
{
printf("beep_beep(%d)\n", n);
}
void
beep_alarm(int alarmmode, int len)
{
printf("beep_alarm(%d,%d)\n", alarmmode, len);
}
void
beep_spinup(void)
{
}
void beep(void)
{
printf("%cbeep\n", 7); /*fflush(NULL);*/
}
void
beep_off(void)
{
}
void
beep_on(void)
{
}
void
beep_long(clock_time_t len)
{
}
void
beep_quick(int n)
{
}

View file

@ -1,163 +0,0 @@
/*
* Copyright (c) 2005, 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: beep.h,v 1.2 2006/07/07 06:40:05 nifi Exp $
*/
/**
* \addtogroup esb
* @{
*/
/**
* \defgroup beeper Beeper interface
* @{
*/
/**
* \file
* Interface to the beeper.
* \author Adam Dunkels <adam@sics.se>
*
*/
#ifndef __BEEP_H__
#define __BEEP_H__
#define BEEP_ALARM1 1
#define BEEP_ALARM2 2
#include "sys/clock.h"
/**
* Beep for a specified time.
*
* This function causes the beeper to beep for the specified time. The
* time is measured in the same units as for the clock_delay()
* function.
*
* \note This function will hang the CPU during the beep.
*
* \note This function will stop any beep that was on previously when this
* function ends.
*
* \note If the beeper is turned off with beep_off() this call will still
* take the same time, though it will be silent.
*
* \param len The length of the beep.
*
*/
void beep_beep(int len);
/**
* Beep an alarm for a specified time.
*
* This function causes the beeper to beep for the specified time. The
* time is measured in the same units as for the clock_delay()
* function.
*
* \note This function will hang the CPU during the beep.
*
* \note This function will stop any beep that was on previously when this
* function ends.
*
* \note If the beeper is turned off with beep_off() this call will still
* take the same time, though it will be silent.
*
* \param alarmmode The alarm mode (BEEP_ALARM1,BEEP_ALARM2)
* \param len The length of the beep.
*
*/
void beep_alarm(int alarmmode, int len);
/**
* Produces a quick click-like beep.
*
* This function produces a short beep that sounds like a click.
*
*/
void beep(void);
/**
* A beep with a pitch-bend down.
*
* This function produces a pitch-bend sound with deecreasing
* frequency.
*
* \param len The length of the pitch-bend.
*
*/
void beep_down(int len);
/**
* Turn the beeper on.
*
* This function turns on the beeper. The beeper is turned off with
* the beep_off() function.
*/
void beep_on(void);
/**
* Turn the beeper off.
*
* This function turns the beeper off after it has been turned on with
* beep_on().
*/
void beep_off(void);
/**
* Produce a sound similar to a hard-drive spinup.
*
* This function produces a sound that is intended to be similar to
* the sound a hard-drive makes when it starts.
*
*/
void beep_spinup(void);
/**
* Beep for a long time (seconds)
*
* This function produces a beep with the specified length and will
* not return until the beep is complete. The length of the beep is
* specified using CLOCK_SECOND: a two second beep is CLOCK_SECOND *
* 2, and a quarter second beep is CLOCK_SECOND / 4.
*
* \note If the beeper is turned off with beep_off() this call will still
* take the same time, though it will be silent.
*
* \param len The length of the beep, measured in units of CLOCK_SECOND
*/
void beep_long(clock_time_t len);
void beep_quick(int num);
/** @} */
/** @} */
#endif /* __BEEP_H__ */

View file

@ -1,32 +0,0 @@
#include "dev/button-sensor.h"
const struct sensors_sensor button_sensor;
/*---------------------------------------------------------------------------*/
void
button_press(void)
{
sensors_changed(&button_sensor);
}
/*---------------------------------------------------------------------------*/
static int
value(int type)
{
return 0;
}
/*---------------------------------------------------------------------------*/
static int
configure(int type, int value)
{
return 0;
}
/*---------------------------------------------------------------------------*/
static int
status(int type)
{
return 0;
}
/*---------------------------------------------------------------------------*/
SENSORS_SENSOR(button_sensor, BUTTON_SENSOR,
value, configure, status);

View file

@ -1,12 +0,0 @@
#ifndef __BUTTON_SENSOR_H__
#define __BUTTON_SENSOR_H__
#include "lib/sensors.h"
extern const struct sensors_sensor button_sensor;
#define BUTTON_SENSOR "Button"
void button_press(void);
#endif /* __BUTTON_SENSOR_H__ */

View file

@ -1,64 +0,0 @@
/*
* Copyright (c) 2005, 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 Configurable Sensor Network Application
* Architecture for sensor nodes running the Contiki operating system.
*
* $Id: dummy-sensors.c,v 1.4 2010/01/15 10:34:36 nifi Exp $
*
* -----------------------------------------------------------------
*
* Author : Adam Dunkels, Joakim Eriksson, Niclas Finne
* Created : 2005-11-01
* Updated : $Date: 2010/01/15 10:34:36 $
* $Revision: 1.4 $
*/
#include "dev/temperature-sensor.h"
/*---------------------------------------------------------------------------*/
static int
value(int type)
{
return 0;
}
/*---------------------------------------------------------------------------*/
static int
configure(int type, int c)
{
return 0;
}
/*---------------------------------------------------------------------------*/
static int
status(int type)
{
return 0;
}
/*---------------------------------------------------------------------------*/
SENSORS_SENSOR(temperature_sensor, TEMPERATURE_SENSOR,
value, configure, status);

View file

@ -1,67 +0,0 @@
/*
* Copyright (c) 2004, Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: eeprom.c,v 1.2 2007/11/17 18:09:18 adamdunkels Exp $
*/
#include "dev/eeprom.h"
#include "node.h"
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
static unsigned char eeprom[65536];
void
eeprom_write(eeprom_addr_t addr, unsigned char *buf, int size)
{
int f;
char name[400];
sprintf(name, "eeprom.%d.%d", node_x(), node_y());
f = open(name, O_WRONLY | O_APPEND | O_CREAT, 0644);
lseek(f, addr, SEEK_SET);
write(f, buf, size);
close(f);
printf("eeprom_write(addr 0x%02x, buf %p, size %d);\n", addr, buf, size);
memcpy(&eeprom[addr], buf, size);
}
void
eeprom_read(eeprom_addr_t addr, unsigned char *buf, int size)
{
/* printf("eeprom_read(addr 0x%02x, buf %p, size %d);\n", addr, buf, size);*/
memcpy(buf, &eeprom[addr], size);
}

View file

@ -1,55 +0,0 @@
/*
* 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: esb-sensors.c,v 1.1 2006/06/17 22:41:36 adamdunkels Exp $
*/
/**
* \file
* A brief description of what this file is.
* \author
* Adam Dunkels <adam@sics.se>
*/
#include "esb-sensors.h"
#include <stdio.h>
/*---------------------------------------------------------------------------*/
void
esb_sensors_on(void)
{
printf("esb_sensors_on()\n");
}
/*---------------------------------------------------------------------------*/
void
esb_sensors_off(void)
{
printf("esb_sensors_off()\n");
}
/*---------------------------------------------------------------------------*/

View file

@ -1,47 +0,0 @@
/*
* 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: esb-sensors.h,v 1.1 2006/06/17 22:41:36 adamdunkels Exp $
*/
/**
* \file
* A brief description of what this file is.
* \author
* Adam Dunkels <adam@sics.se>
*/
#ifndef __ESB_SENSORS_H__
#define __ESB_SENSORS_H__
void esb_sensors_on(void);
void esb_sensors_off(void);
#endif /* __ESB_SENSORS_H__ */

View file

@ -1,61 +0,0 @@
/**
* \file
* Functions for reading and writing flash ROM.
* \author Adam Dunkels <adam@sics.se>
*/
/* Copyright (c) 2004 Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*
* $Id: flash.c,v 1.1 2006/06/17 22:41:36 adamdunkels Exp $
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
/*---------------------------------------------------------------------------*/
void
flash_setup(void)
{
}
/*---------------------------------------------------------------------------*/
void
flash_done(void)
{
}
/*---------------------------------------------------------------------------*/
void
flash_clear(unsigned short *ptr)
{
}
/*---------------------------------------------------------------------------*/
void
flash_write(unsigned short *ptr, unsigned short word)
{
}
/*---------------------------------------------------------------------------*/

View file

@ -1,78 +0,0 @@
/**
* \file
* Functions for reading and writing MSP430 flash ROM.
* \author Adam Dunkels <adam@sics.se>
*/
/* Copyright (c) 2004 Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*
* $Id: flash.h,v 1.1 2006/06/17 22:41:36 adamdunkels Exp $
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef __FLASH_H__
#define __FLASH_H__
/**
* Setup function to be called before any of the flash programming functions.
*
*/
void flash_setup(void);
/**
* Function that is to be called after flashing is done.
*/
void flash_done(void);
/**
* Write a 16-bit word to flash ROM.
*
* This function writes a 16-bit word to flash ROM. The function
* flash_setup() must have been called first.
*
* \param addr A pointer to the address in flash ROM which is to be
* written.
*
* \param word The 16-bit word that is to be written.
*/
void flash_write(unsigned short *addr, unsigned short word);
/**
* Clear a 16-bit word in flash ROM.
*
* This function clears a 16-bit word in flash ROM. The function
* flash_setup() must have been called first.
*
* \param addr A pointer to the address in flash ROM which is to be
* cleared.
*/
void flash_clear(unsigned short *addr);
#endif /* __FLASH_H__ */

View file

@ -1,5 +0,0 @@
void
irq_init(void)
{
}

View file

@ -1,60 +0,0 @@
/*
* Copyright (c) 2005, 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 Configurable Sensor Network Application
* Architecture for sensor nodes running the Contiki operating system.
*
* $Id: leds-arch.c,v 1.1 2006/06/17 22:41:36 adamdunkels Exp $
*
* -----------------------------------------------------------------
*
* Author : Adam Dunkels, Joakim Eriksson, Niclas Finne
* Created : 2005-11-03
* Updated : $Date: 2006/06/17 22:41:36 $
* $Revision: 1.1 $
*/
#include "dev/leds.h"
#include "ether.h"
static int cleds;
void leds_arch_init() {
cleds = 0;
}
unsigned char leds_arch_get() {
return cleds;
}
void leds_arch_set(unsigned char leds) {
if(leds != cleds) {
cleds = leds;
ether_set_leds(cleds);
}
}

View file

@ -1,55 +0,0 @@
/*
* 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: lpm.c,v 1.1 2006/06/17 22:41:36 adamdunkels Exp $
*/
/**
* \file
* A brief description of what this file is.
* \author
* Adam Dunkels <adam@sics.se>
*/
#include "lpm.h"
#include <stdio.h>
/*---------------------------------------------------------------------------*/
void
lpm_on(void)
{
printf("lpm_on()\n");
}
/*---------------------------------------------------------------------------*/
void
lpm_off(void)
{
printf("lpm_off()\n");
}
/*---------------------------------------------------------------------------*/

View file

@ -1,40 +0,0 @@
/*
* Copyright (c) 2005, 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: lpm.h,v 1.1 2006/06/17 22:41:36 adamdunkels Exp $
*/
#ifndef __LPM_H__
#define __LPM_H__
void lpm_on(void);
void lpm_off(void);
#endif /* __LPM_H__ */

View file

@ -1,35 +0,0 @@
#include "dev/pir-sensor.h"
const struct sensors_sensor pir_sensor;
static int pir_value;
/*---------------------------------------------------------------------------*/
void
pir_sensor_changed(int strength)
{
pir_value += strength;
sensors_changed(&pir_sensor);
}
/*---------------------------------------------------------------------------*/
static int
value(int type)
{
return pir_value;
}
/*---------------------------------------------------------------------------*/
static int
configure(int type, int c)
{
return 0;
}
/*---------------------------------------------------------------------------*/
static int
status(int type)
{
return 0;
}
/*---------------------------------------------------------------------------*/
SENSORS_SENSOR(pir_sensor, PIR_SENSOR,
value, configure, status);

View file

@ -1,14 +0,0 @@
#ifndef __PIR_SENSOR_H__
#define __PIR_SENSOR_H__
#include "lib/sensors.h"
extern const struct sensors_sensor pir_sensor;
#define PIR_SENSOR "PIR"
void pir_sensor_changed(int strength);
#define PIR_ENABLE_EVENT 1
#endif /* __PIR_SENSOR_H__ */

View file

@ -1,61 +0,0 @@
/*
* Copyright (c) 2005, 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: radio-sensor.c,v 1.3 2010/02/23 18:43:43 adamdunkels Exp $
*/
#include "lib/sensors.h"
#include "dev/radio-sensor.h"
const struct sensors_sensor radio_sensor;
unsigned int radio_sensor_signal = 0;
/*---------------------------------------------------------------------------*/
static int
value(int type)
{
return radio_sensor_signal;
}
/*---------------------------------------------------------------------------*/
static int
configure(int type, int c)
{
return 0;
}
/*---------------------------------------------------------------------------*/
static int
status(int type)
{
return 0;
}
/*---------------------------------------------------------------------------*/
SENSORS_SENSOR(radio_sensor, RADIO_SENSOR,
value, configure, status);

View file

@ -1,44 +0,0 @@
/*
* Copyright (c) 2005, 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: radio-sensor.h,v 1.1 2006/06/17 22:41:36 adamdunkels Exp $
*/
#ifndef __RADIO_SENSOR_H__
#define __RADIO_SENSOR_H__
#include "contiki-esb.h"
extern const struct sensors_sensor radio_sensor;
#define RADIO_SENSOR "Radio"
extern unsigned int radio_sensor_signal;
#endif /* __RADIO_SENSOR_H__ */

View file

@ -1,52 +0,0 @@
/*
* 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: radio.c,v 1.1 2006/06/17 22:41:36 adamdunkels Exp $
*/
/**
* \file
* A brief description of what this file is.
* \author
* Adam Dunkels <adam@sics.se>
*/
#include "radio.h"
/*---------------------------------------------------------------------------*/
void
radio_on(void)
{
}
/*---------------------------------------------------------------------------*/
void
radio_off(void)
{
}
/*---------------------------------------------------------------------------*/

View file

@ -1,55 +0,0 @@
/*
* 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: rs232.c,v 1.2 2006/10/10 15:58:31 adamdunkels Exp $
*/
/**
* \file
* A brief description of what this file is.
* \author
* Adam Dunkels <adam@sics.se>
*/
#include "rs232.h"
#include <stdio.h>
/*---------------------------------------------------------------------------*/
void
rs232_set_input(int (* f)(unsigned char))
{
/* printf("rs232_set_input(%p)\n", f);*/
}
/*---------------------------------------------------------------------------*/
void
slip_arch_writeb(unsigned char c)
{
printf("%c", c);
}
/*---------------------------------------------------------------------------*/

View file

@ -1,46 +0,0 @@
/*
* 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: rs232.h,v 1.1 2006/06/17 22:41:36 adamdunkels Exp $
*/
/**
* \file
* A brief description of what this file is.
* \author
* Adam Dunkels <adam@sics.se>
*/
#ifndef __RS232_H__
#define __RS232_H__
void rs232_set_input(int (* f)(unsigned char));
#endif /* __RS232_H__ */

View file

@ -1,51 +0,0 @@
/*
* Copyright (c) 2005, 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 Configurable Sensor Network Application
* Architecture for sensor nodes running the Contiki operating system.
*
* $Id: temperature-sensor.h,v 1.1 2006/06/17 22:41:36 adamdunkels Exp $
*
* -----------------------------------------------------------------
*
* Author : Adam Dunkels, Joakim Eriksson, Niclas Finne
* Created : 2005-11-01
* Updated : $Date: 2006/06/17 22:41:36 $
* $Revision: 1.1 $
*/
#ifndef __TEMPERATURE_SENSOR_H__
#define __TEMPERATURE_SENSOR_H__
#include "lib/sensors.h"
extern const struct sensors_sensor temperature_sensor;
#define TEMPERATURE_SENSOR "Temperature"
#endif /* __TEMPERATURE_SENSOR_H__ */

View file

@ -1,84 +0,0 @@
/*
* Copyright (c) 2005, 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: tr1001-drv.c,v 1.2 2006/10/10 15:58:31 adamdunkels Exp $
*/
#include "contiki-esb.h"
#include "net/hc.h"
#include <string.h>
#include <stdio.h>
PROCESS(tr1001_drv_process, "TR1001 driver");
static unsigned char slip_dump;
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(tr1001_drv_process, ev, data)
{
PROCESS_BEGIN();
tr1001_init();
while(1) {
PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_POLL);
uip_len = tr1001_poll();
if(uip_len > 0) {
uip_len = hc_inflate(&uip_buf[UIP_LLH_LEN], uip_len);
tcpip_input();
}
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/
void
tr1001_drv_request_poll(void)
{
process_poll(&tr1001_drv_process);
}
/*---------------------------------------------------------------------------*/
u8_t
tr1001_drv_send(void)
{
uip_len = hc_compress(&uip_buf[UIP_LLH_LEN], uip_len);
return tr1001_send(&uip_buf[UIP_LLH_LEN], uip_len);
}
/*---------------------------------------------------------------------------*/
void
tr1001_drv_set_slip_dump(int dump)
{
slip_dump = dump;
}
/*---------------------------------------------------------------------------*/

View file

@ -1,44 +0,0 @@
/*
* Copyright (c) 2005, 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: tr1001-drv.h,v 1.1 2006/06/17 22:41:36 adamdunkels Exp $
*/
#ifndef __TR1001_DRV_H__
#define __TR1001_DRV_H__
PROCESS_NAME(tr1001_drv_process);
void tr1001_drv_set_slip_dump(int dump);
u8_t tr1001_drv_send(void);
void tr1001_drv_request_poll(void);
#endif /* __TR1001_DRV_H__ */

View file

@ -1,112 +0,0 @@
/*
* 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: tr1001.c,v 1.2 2006/10/10 15:58:31 adamdunkels Exp $
*/
/**
* \file
* A brief description of what this file is.
* \author
* Adam Dunkels <adam@sics.se>
*/
#include <stdio.h>
#include "tr1001.h"
/*---------------------------------------------------------------------------*/
void
tr1001_init(void)
{
printf("tr1001_init()\n");
}
/*---------------------------------------------------------------------------*/
unsigned short
tr1001_poll(void)
{
printf("tr1001_poll()\n");
return 0;
}
/*---------------------------------------------------------------------------*/
u8_t
tr1001_send(u8_t *packet, u16_t len)
{
printf("tr1001_send(%p, %d)\n", packet, len);
return 0;
}
/*---------------------------------------------------------------------------*/
void
tr1001_set_txpower(unsigned char p)
{
printf("tr1001_set_txpower(%d)\n", p);
}
/*---------------------------------------------------------------------------*/
unsigned short
tr1001_sstrength(void)
{
return 0;
}
/*---------------------------------------------------------------------------*/
static unsigned short packets_ok, packets_err;
unsigned short
tr1001_packets_ok(void)
{
return packets_ok;
}
/*---------------------------------------------------------------------------*/
unsigned short
tr1001_packets_dropped(void)
{
return packets_err;
}
/*---------------------------------------------------------------------------*/
void
tr1001_clear_packets(void)
{
packets_ok = packets_err = 0;
}
/*---------------------------------------------------------------------------*/
void
tr1001_clear_active(void)
{
}
/*---------------------------------------------------------------------------*/
int
tr1001_active(void)
{
return 0;
}
/*---------------------------------------------------------------------------*/
unsigned short
tr1001_sstrength_value(unsigned int type)
{
printf("tr1001_sstrength_value(%d)\n", type);
return 0;
}
/*---------------------------------------------------------------------------*/

View file

@ -1,65 +0,0 @@
/*
* 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: tr1001.h,v 1.1 2006/06/17 22:41:36 adamdunkels Exp $
*/
/**
* \file
* A brief description of what this file is.
* \author
* Adam Dunkels <adam@sics.se>
*/
#ifndef __TR1001_H__
#define __TR1001_H__
#include "contiki-net.h"
void tr1001_init(void);
u8_t tr1001_send(u8_t *packet, u16_t len);
unsigned short tr1001_poll(void);
void tr1001_set_txpower(unsigned char p);
#define TR1001_TXPOWER_HIGHEST 100
#define TR1001_TXPOWER_LOWEST 1
unsigned short tr1001_sstrength(void);
#define TR1001_SSTRENGTH_DROPPED 1
#define TR1001_SSTRENGTH_MAX 2
#define TR1001_SSTRENGTH_MIN 3
unsigned short tr1001_packets_ok(void);
unsigned short tr1001_packets_dropped(void);
void tr1001_clear_packets(void);
unsigned short tr1001_sstrength_value(unsigned int type);
#endif /* __TR1001_H__ */

View file

@ -1,72 +0,0 @@
/*
* Copyright (c) 2005, 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 Configurable Sensor Network Application
* Architecture for sensor nodes running the Contiki operating system.
*
* $Id: vib-sensor.c,v 1.3 2010/02/23 18:43:43 adamdunkels Exp $
*
* -----------------------------------------------------------------
*
* Author : Adam Dunkels, Joakim Eriksson, Niclas Finne
* Created : 2005-11-01
* Updated : $Date: 2010/02/23 18:43:43 $
* $Revision: 1.3 $
*/
#include "dev/vib-sensor.h"
const struct sensors_sensor vib_sensor;
/*---------------------------------------------------------------------------*/
void
vib_sensor_changed(void)
{
sensors_changed(&vib_sensor);
}
/*---------------------------------------------------------------------------*/
static int
value(int type)
{
return 0;
}
/*---------------------------------------------------------------------------*/
static int
configure(int type, int c)
{
return 0;
}
/*---------------------------------------------------------------------------*/
static int
status(int type)
{
return 0;
}
/*---------------------------------------------------------------------------*/
SENSORS_SENSOR(vib_sensor, VIB_SENSOR,
value, configure, status);

View file

@ -1,55 +0,0 @@
/*
* Copyright (c) 2005, 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 Configurable Sensor Network Application
* Architecture for sensor nodes running the Contiki operating system.
*
* $Id: vib-sensor.h,v 1.2 2006/10/10 15:58:31 adamdunkels Exp $
*
* -----------------------------------------------------------------
*
* Author : Adam Dunkels, Joakim Eriksson, Niclas Finne
* Created : 2005-11-01
* Updated : $Date: 2006/10/10 15:58:31 $
* $Revision: 1.2 $
*/
#ifndef __VIB_SENSOR_H__
#define __VIB_SENSOR_H__
#include "lib/sensors.h"
extern const struct sensors_sensor vib_sensor;
#define VIB_SENSOR "Vibration"
void vib_sensor_changed(void);
#define VIB_ENABLE_EVENT 1
#endif /* __VIB_SENSOR_H__ */

View file

@ -1,738 +0,0 @@
/*
* Copyright (c) 2004 Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*
* $Id: display.c,v 1.10 2010/02/23 18:44:08 adamdunkels Exp $
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#include "dev/leds.h"
#include "display.h"
#include "nodes.h"
#include "node.h"
#include "ether.h"
#include "lib/list.h"
#include "lib/memb.h"
#include "sensor.h"
#include <gtk/gtk.h>
#include <sys/time.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
static GdkPixmap *pixmap = NULL;
static GtkWidget *drawing_area;
static GdkFont *font;
#define DISPLAY_WIDTH 400
#define DISPLAY_HEIGHT 400
#define BASESTATION_SIZE 4
#define MAPSCALE 20
#define SCALE 2
#define MARK_SIZE 8
#define RADIO_SIZE 20
#define DOT_SIZE ether_strength()
#define DOT_INTENSITY 3
struct dot {
struct dot *next;
int x, y;
int destx, desty;
int size;
int intensity;
};
MEMB(dotsmem, struct dot, 20000);
LIST(dots);
LIST(tempdots);
static int window_is_open;
static GdkGC *intensity_gcs[DOT_INTENSITY];
static GdkGC *intensity_clusterhead;
static GdkGC *intensity_clusterhead_lightgray;
static GdkGC *intensity_clusterhead_red;
static GdkGC *green, *red, *yellow, *black, *white;
static struct nodes_node *marked_node;
/*-----------------------------------------------------------------------------------*/
void
display_redraw(void)
{
int i;
struct nodes_node *n;
int x, y;
struct dot *d;
if(!window_is_open) {
return;
}
gdk_draw_rectangle(pixmap,
white,
TRUE,
0, 0,
drawing_area->allocation.width,
drawing_area->allocation.height);
for(i = 0; i < nodes_num(); ++i) {
n = nodes_node(i);
x = n->x;
y = n->y;
/* if(n->type == NODE_TYPE_CLUSTERHEAD) {
gdk_draw_arc(pixmap,
intensity_clusterhead_lightgray,
TRUE,
x * SCALE - DOT_SIZE * SCALE,
y * SCALE - DOT_SIZE * SCALE,
DOT_SIZE * 2 * SCALE, DOT_SIZE * 2 * SCALE,
0, 360 * 64);
}*/
if(n == marked_node) {
gdk_draw_arc(pixmap,
red,
FALSE,
x * SCALE - MARK_SIZE * SCALE,
y * SCALE - MARK_SIZE * SCALE,
MARK_SIZE * 2 * SCALE, MARK_SIZE * 2 * SCALE,
0, 360 * 64);
}
}
for(i = 0; i < nodes_num(); ++i) {
n = nodes_node(i);
x = n->x;
y = n->y;
/* if(n->type == NODE_TYPE_CLUSTERHEAD) {
gdk_draw_rectangle(pixmap,
intensity_clusterhead_red,
TRUE,
x * SCALE,
y * SCALE,
3, 3);
for(j = 0; j < nodes_num(); ++j) {
m = nodes_node(j);
if(m->type == NODE_TYPE_CLUSTERHEAD &&
((x - m->x) * (x - m->x) +
(y - m->y) * (y - m->y) < ether_strength() * ether_strength())) {
gdk_draw_line(pixmap,
intensity_clusterhead,
x * SCALE,
y * SCALE,
m->x * SCALE,
m->y * SCALE);
}
}
} else */ {
if(strlen(n->text) > 0) {
gdk_draw_string(pixmap,
font,
black,
x * SCALE + 10,
y * SCALE + 7,
n->text);
}
gdk_draw_rectangle(pixmap,
black,
TRUE,
x * SCALE,
y * SCALE,
2, 2);
/* gdk_draw_rectangle(pixmap,
drawing_area->style->white_gc,
TRUE,
x * SCALE,
y * SCALE,
2, 2);*/
if(n->leds & LEDS_GREEN) {
gdk_draw_rectangle(pixmap,
green,
TRUE,
x * SCALE + 2,
y * SCALE,
4, 4);
}
if(n->leds & LEDS_YELLOW) {
gdk_draw_rectangle(pixmap,
yellow,
TRUE,
x * SCALE,
y * SCALE + 2,
4, 4);
}
if(n->leds & LEDS_RED) {
gdk_draw_rectangle(pixmap,
red,
TRUE,
x * SCALE + 2,
y * SCALE + 2,
4, 4);
}
if(n->linex != 0 && n->liney != 0) {
gdk_draw_line(pixmap,
green,
x * SCALE,
y * SCALE,
n->linex * SCALE,
n->liney * SCALE);
gdk_draw_rectangle(pixmap,
green,
TRUE,
n->linex * SCALE - 2,
n->liney * SCALE - 2,
4, 4);
}
if(n->radio_status) {
gdk_draw_arc(pixmap,
green,
FALSE,
x * SCALE - RADIO_SIZE * SCALE,
y * SCALE - RADIO_SIZE * SCALE,
RADIO_SIZE * 2 * SCALE, RADIO_SIZE * 2 * SCALE,
0, 360 * 64);
}
}
}
for(d = list_head(dots); d != NULL; d = d->next) {
gdk_draw_arc(pixmap,
intensity_gcs[d->intensity - 1],
FALSE,
d->x * SCALE - d->size * SCALE,
d->y * SCALE - d->size * SCALE,
d->size * 2 * SCALE, d->size * 2 * SCALE,
0, 360 * 64);
}
gtk_widget_draw(drawing_area, NULL);
}
/*-----------------------------------------------------------------------------------*/
void
display_tick(void)
{
struct dot *d, *e;
struct ether_packet *p;
if(!window_is_open) {
return;
}
/* Fade out active dots. The intensity value of each dot is counted
downwards, and those dots that still have an intensity are placed
in a temporary list. The temporary list is then copied into the
list of all dots. */
list_init(tempdots);
for(d = list_head(dots);
d != NULL;
d = e) {
if(d != NULL) {
e = d->next;
} else {
e = NULL;
}
if(d->size > 20) {
d->size /= 2;
} else {
d->size -= 4;
}
/* --(d->intensity);*/
if(d->size > 0) {
list_push(tempdots, d);
} else {
memb_free(&dotsmem, (void *)d);
}
}
list_copy(dots, tempdots);
/* Check if there are any new dots that should be placed in the list. */
for(p = ether_packets(); p != NULL; p = p->next) {
d = (struct dot *)memb_alloc(&dotsmem);
if(d != NULL) {
d->x = p->x;
d->y = p->y;
d->size = DOT_SIZE;
d->intensity = DOT_INTENSITY;
list_push(dots, d);
}
}
}
/*-----------------------------------------------------------------------------------*/
static gint
configure_event(GtkWidget *widget, GdkEventConfigure *event)
{
if(pixmap != NULL) {
gdk_pixmap_unref(pixmap);
}
pixmap = gdk_pixmap_new(widget->window,
widget->allocation.width,
widget->allocation.height,
-1);
if(pixmap == NULL) {
printf("gdk_pixmap_new == NULL\n");
exit(1);
}
gdk_draw_rectangle(pixmap,
widget->style->black_gc,
TRUE,
0, 0,
widget->allocation.width,
widget->allocation.height);
/* draw_screen();*/
return TRUE;
}
/* Redraw the screen from the backing pixmap */
static gint
expose_event (GtkWidget * widget, GdkEventExpose * event)
{
/* draw_screen();*/
gdk_draw_pixmap(widget->window,
widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
pixmap,
event->area.x, event->area.y,
event->area.x, event->area.y,
event->area.width, event->area.height);
return FALSE;
}
static gint
key_press_event (GtkWidget * widget, GdkEventKey * event)
{
/* if(event->keyval == GDK_Shift_L ||
event->keyval == GDK_Shift_R) {
return TRUE;
}
keys[lastkey] = event->keyval;
++lastkey;
if(lastkey >= NUMKEYS) {
lastkey = 0;
}*/
if(event->keyval == 'q') {
gtk_exit(0);
/* exit(0);*/
}
if(event->keyval == 'p') {
display_output_fig();
}
return TRUE;
}
static gint
key_release_event (GtkWidget * widget, GdkEventKey * event)
{
return TRUE;
}
static gint
button_press_event (GtkWidget * widget, GdkEventKey * event)
{
struct dot *d;
struct sensor_data s;
GdkModifierType state;
int x, y;
gdk_window_get_pointer (event->window, &x, &y, &state);
x = ((GdkEventButton*)event)->x / SCALE;
y = ((GdkEventButton*)event)->y / SCALE;
if(state & GDK_BUTTON1_MASK) {
d = (struct dot *)memb_alloc(&dotsmem);
if(d != NULL) {
d->x = x;
d->y = y;
d->size = sensor_strength();
d->intensity = DOT_INTENSITY - 2;
list_push(dots, d);
}
sensor_data_init(&s);
s.pir = 1;
s.button = 0;
s.vib = 0;
ether_send_sensor_data(&s, x, y, sensor_strength());
} else if(state & GDK_BUTTON2_MASK) {
sensor_data_init(&s);
s.pir = 0;
s.button = 1;
s.vib = 0;
if(marked_node != NULL) {
ether_send_sensor_data(&s, marked_node->x, marked_node->y, 1);
}
} else if(state & GDK_BUTTON3_MASK) {
sensor_data_init(&s);
s.pir = 0;
s.button = 0;
s.vib = 1;
if(marked_node != NULL) {
ether_send_sensor_data(&s, marked_node->x, marked_node->y, 1);
}
}
return TRUE;
}
static gint
pointer_motion_event (GtkWidget * widget, GdkEventMotion * event)
{
struct dot *d;
struct sensor_data s;
GdkModifierType state;
int x, y;
struct nodes_node *node, *closest;
int nodex, nodey;
unsigned long dist;
int i;
if(event->is_hint) {
return TRUE;
}
gdk_window_get_pointer (event->window, &x, &y, &state);
x /= SCALE;
y /= SCALE;
if(state & GDK_BUTTON1_MASK) {
d = (struct dot *)memb_alloc(&dotsmem);
if(d != NULL) {
d->x = x;
d->y = y;
d->size = sensor_strength();
d->intensity = DOT_INTENSITY - 2;
list_push(dots, d);
}
sensor_data_init(&s);
s.pir = 1;
ether_send_sensor_data(&s, x, y, sensor_strength());
} else {
/* Find the closest node and mark it. */
closest = NULL;
dist = 0;
for(i = 0; i < nodes_num(); ++i) {
node = nodes_node(i);
nodex = node->x;
nodey = node->y;
if(closest == NULL ||
(x - nodex) * (x - nodex) + (y - nodey) * (y - nodey) < dist) {
dist = (x - nodex) * (x - nodex) + (y - nodey) * (y - nodey);
closest = node;
}
}
marked_node = closest;
}
return TRUE;
}
static void
quit(void)
{
gtk_exit(0);
}
/*-----------------------------------------------------------------------------------*/
static void (* idle)(void);
static gint
idle_callback(gpointer data)
{
idle();
return TRUE;
}
/*-----------------------------------------------------------------------------------*/
static GdkGC *
get_color(unsigned short r, unsigned short g, unsigned short b)
{
GdkGCValues values;
GdkColor color;
color.pixel = 0;
color.red = r;
color.green = g;
color.blue = b;
if(gdk_colormap_alloc_color(gdk_colormap_get_system(),
&color, FALSE, TRUE)) {
}
values.foreground = color;
return gdk_gc_new_with_values(drawing_area->window,
&values,
GDK_GC_FOREGROUND);
}
/*-----------------------------------------------------------------------------------*/
static void
stdin_callback(gpointer data, gint source, GdkInputCondition condition)
{
char buf[1000];
int len;
len = read(STDIN_FILENO, &buf, sizeof(buf));
printf("read len %d\n", len);
buf[len] = 0;
ether_send_serial(buf);
}
/*-----------------------------------------------------------------------------------*/
void
display_init(void (* idlefunc)(void), int time, int with_gui)
{
int i;
GtkWidget *window;
GtkWidget *vbox;
GdkGCValues values;
GdkColor color;
memb_init(&dotsmem);
list_init(dots);
list_init(tempdots);
gtk_init(NULL, NULL);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Contiki simulation display");
vbox = gtk_vbox_new(FALSE, 0);
gtk_container_add(GTK_CONTAINER (window), vbox);
gtk_widget_show(vbox);
gtk_signal_connect(GTK_OBJECT (window), "destroy",
GTK_SIGNAL_FUNC (quit), NULL);
font = gdk_font_load("-*-courier-medium-r-*-*-12-*-*-*-*-*-iso8859-1");
/* Create the drawing area */
drawing_area = gtk_drawing_area_new();
gtk_drawing_area_size(GTK_DRAWING_AREA (drawing_area),
DISPLAY_WIDTH,
DISPLAY_HEIGHT);
gtk_box_pack_start(GTK_BOX(vbox), drawing_area, TRUE, TRUE, 0);
gtk_widget_show(drawing_area);
/* Signals used to handle backing pixmap */
gtk_signal_connect(GTK_OBJECT (drawing_area), "expose_event",
(GtkSignalFunc) expose_event, NULL);
gtk_signal_connect(GTK_OBJECT (drawing_area), "configure_event",
(GtkSignalFunc) configure_event, NULL);
/* Event signals */
gtk_signal_connect(GTK_OBJECT (window), "key_press_event",
(GtkSignalFunc) key_press_event, NULL);
gtk_signal_connect(GTK_OBJECT (window), "key_release_event",
(GtkSignalFunc) key_release_event, NULL);
gtk_signal_connect(GTK_OBJECT (window), "button_press_event",
(GtkSignalFunc) button_press_event, NULL);
gtk_signal_connect(GTK_OBJECT (window), "motion_notify_event",
(GtkSignalFunc) pointer_motion_event, NULL);
gtk_widget_set_events(drawing_area,GDK_KEY_PRESS_MASK
| GDK_KEY_RELEASE_MASK | GDK_BUTTON_PRESS_MASK
| GDK_POINTER_MOTION_MASK);
/* gtk_window_iconify(window);*/
if(with_gui) {
gtk_widget_show(window);
window_is_open = with_gui;
}
idle = idlefunc;
gtk_timeout_add(time, idle_callback, NULL);
if(with_gui) {
for(i = 0; i < DOT_INTENSITY; ++i) {
color.pixel = 0;
color.red = 0;
color.green = ((DOT_INTENSITY + 1) * 0xffff) / (i + 1);
color.blue = ((DOT_INTENSITY + 1) * 0xffff) / (i + 1);
if(gdk_colormap_alloc_color(gdk_colormap_get_system(),
&color, FALSE, TRUE)) {
}
values.foreground = color;
intensity_gcs[i] = gdk_gc_new_with_values(drawing_area->window, &values,
GDK_GC_FOREGROUND);
}
color.pixel = 0;
color.red = 0xbfff;
color.green = 0xbfff;
color.blue = 0xbfff;
if(gdk_colormap_alloc_color(gdk_colormap_get_system(),
&color, FALSE, TRUE)) {
}
values.foreground = color;
intensity_clusterhead = gdk_gc_new_with_values(drawing_area->window, &values,
GDK_GC_FOREGROUND);
color.pixel = 0;
color.red = 0xefff;
color.green = 0xefff;
color.blue = 0xefff;
if(gdk_colormap_alloc_color(gdk_colormap_get_system(),
&color, FALSE, TRUE)) {
}
values.foreground = color;
intensity_clusterhead_lightgray = gdk_gc_new_with_values(drawing_area->window, &values,
GDK_GC_FOREGROUND);
color.pixel = 0;
color.red = 0xffff;
color.green = 0;
color.blue = 0;
if(gdk_colormap_alloc_color(gdk_colormap_get_system(),
&color, FALSE, TRUE)) {
}
values.foreground = color;
intensity_clusterhead_red = gdk_gc_new_with_values(drawing_area->window, &values,
GDK_GC_FOREGROUND);
red = get_color(0xffff, 0, 0);
green = get_color(0, 0xffff, 0);
yellow = get_color(0xffff, 0xffff, 0);
black = get_color(0, 0, 0);
white = get_color(0xffff, 0xffff, 0xffff);
}
gdk_input_add(STDIN_FILENO, GDK_INPUT_READ, stdin_callback, NULL);
}
/*-----------------------------------------------------------------------------------*/
void
display_run(void)
{
gtk_main();
}
/*-----------------------------------------------------------------------------------*/
void
display_output_fig(void)
{
int i;
struct nodes_node *n;
int x, y;
int dot_radius = 75;
int scale = 50;
FILE *fp;
char name[40];
struct timeval tv;
gettimeofday(&tv, NULL);
snprintf(name, sizeof(name), "network-%lu.fig", tv.tv_sec);
fp = fopen(name, "w");
fprintf(fp, "#FIG 3.2\n"
"Landscape\n"
"Center\n"
"Inches\n"
"Letter\n"
"100.00\n"
"Single\n"
"-2\n"
"1200 2\n"
);
for(i = 0; i < nodes_num(); ++i) {
n = nodes_node(i);
x = n->x * scale;
y = n->y * scale;
fprintf(fp, "1 3 1 1 0 7 50 -1 0 4.000 1 0.0000 %d %d %d %d %d %d %d %d\n",
x, y,
dot_radius, dot_radius,
x, y,
x + dot_radius, y + dot_radius);
if(strlen(n->text) > 0) {
fprintf(fp, "4 0 0 50 -1 16 18 0.0000 4 135 720 %d %d %s\\001\n",
x + 2 * scale, y, n->text);
}
if(n->linex != 0 && n->liney != 0) {
fprintf(fp, "2 1 1 1 0 7 50 -1 -1 0.000 0 0 -1 0 1 2\n"
"1 1 4.00 60.00 120.00\n"
"%d %d %d %d\n",
x, y,
n->linex * scale, n->liney * scale);
}
}
fclose(fp);
}
/*-----------------------------------------------------------------------------------*/

View file

@ -1,44 +0,0 @@
/*
* Copyright (c) 2004 Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*
* $Id: display.h,v 1.2 2008/05/14 19:22:57 adamdunkels Exp $
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef __DISPLAY_H__
#define __DISPLAY_H__
void display_redraw(void);
void display_init(void (* idle)(void), int time, int with_gui);
void display_run(void);
void display_tick(void);
void display_output_fig(void);
#endif /* __DISPLAY_H__ */

View file

@ -1,698 +0,0 @@
/*
* Copyright (c) 2004, Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: ether.c,v 1.17 2010/10/19 18:29:05 adamdunkels Exp $
*/
/**
* \file
* This module implements a simple "ether", into which datapackets can
* be injected. The packets are delivered to all nodes that are in
* transmission range.
*
* \author Adam Dunkels <adam@sics.se>
*
*/
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <errno.h>
#include "ether.h"
#include "lib/memb.h"
#include "lib/list.h"
#include "nodes.h"
#include "dev/radio-sensor.h"
#include "dev/serial-line.h"
#include "sensor.h"
#include "node.h"
#include "net/uip.h"
#include "net/uip-fw.h"
#ifndef NULL
#define NULL 0
#endif /* NULL */
MEMB(packets, struct ether_packet, 20000);
LIST(active_packets);
static u8_t rxbuffer[2048];
static clock_time_t timer;
#define BUF ((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])
#define PRINTF(...)
/*#define PRINTF(x) printf x*/
static int s, sc;
#define PTYPE_NONE 0
#define PTYPE_CLOCK 1
#define PTYPE_DATA 2
#define PTYPE_SENSOR 3
#define PTYPE_LEDS 4
#define PTYPE_TEXT 5
#define PTYPE_DONE 6
#define PTYPE_SERIAL 7
#define PTYPE_RADIO_STATUS 8
#define SERIAL_LEN 80
struct ether_hdr {
int type;
struct sensor_data sensor_data;
clock_time_t clock;
int linex, liney;
int signal;
int srcx, srcy;
int srcpid;
int srcid;
int srcnodetype;
int leds;
int radio_status;
char text[NODES_TEXTLEN + SERIAL_LEN];
};
static int strength;
static int collisions = 1;
static int num_collisions = 0;
static int num_sent = 0;
static int num_received = 0;
static int drop_probability = 0;
static int num_drops = 0;
#include <sys/time.h>
static struct timeval t1;
static int linex, liney;
/*-----------------------------------------------------------------------------------*/
void
ether_print_stats(void)
{
unsigned long time;
struct timeval t2;
gettimeofday(&t2, NULL);
time = (t2.tv_sec * 1000 + t2.tv_usec / 1000) -
(t1.tv_sec * 1000 + t1.tv_usec / 1000);
/* printf("%d, %d, %f\n", num_packets, num_collisions, time/1000.0);*/
printf("Time: %f\n", time/1000.0);
printf("Total packets sent: %d\n", num_sent);
printf("Total collisions: %d\n", num_collisions);
printf("Total packets receptions: %d\n", num_received);
printf("Total randomly dropped packets: %d\n", num_drops);
}
/*-----------------------------------------------------------------------------------*/
void
ether_set_drop_probability(double p)
{
drop_probability = p * 65536;
}
/*-----------------------------------------------------------------------------------*/
void
ether_set_collisions(int c)
{
collisions = c;
}
/*-----------------------------------------------------------------------------------*/
void
ether_set_strength(int s)
{
strength = s;
}
/*-----------------------------------------------------------------------------------*/
int
ether_strength(void)
{
return strength;
}
/*-----------------------------------------------------------------------------------*/
void
ether_server_init(void)
{
struct sockaddr_in sa;
gettimeofday(&t1, NULL);
memb_init(&packets);
list_init(active_packets);
timer = 0;
s = socket(AF_INET,SOCK_DGRAM,0);
if(s < 0) {
perror("ether_server_init: socket");
}
memset((char *)&sa, 0, sizeof(sa));
sa.sin_family = AF_INET;
sa.sin_addr.s_addr = inet_addr("127.0.0.1");/*uip_htonl(INADDR_ANY);*/
sa.sin_port = uip_htons(ETHER_PORT);
/* printf("Binding to port %d\n", ETHER_PORT);*/
if(bind(s, (struct sockaddr *)&sa, sizeof(sa)) < 0) {
printf("Bind to port %d\n", ETHER_PORT);
perror("bind");
exit(1);
}
}
/*-----------------------------------------------------------------------------------*/
void
ether_client_init(int port)
{
struct sockaddr_in sa;
sc = socket(AF_INET,SOCK_DGRAM,0);
if(sc < 0) {
perror("socket");
}
memset((char *)&sa, 0, sizeof(sa));
sa.sin_family = AF_INET;
sa.sin_addr.s_addr = inet_addr("127.0.0.1");/*uip_htonl(INADDR_ANY);*/
sa.sin_port = uip_htons(port);
/* printf("ether_client_init: binding to port %d\n", port);*/
if(bind(sc, (struct sockaddr *)&sa, sizeof(sa)) < 0) {
printf("Bind to port %d\n", port);
perror("bind");
exit(1);
}
}
/*-----------------------------------------------------------------------------------*/
int
ether_client_poll(void)
{
fd_set fdset;
struct timeval tv;
int ret;
FD_ZERO(&fdset);
FD_SET(sc, &fdset);
tv.tv_sec = 0;
tv.tv_usec = 1000;
ret = select(sc + 1, &fdset, NULL, NULL, &tv);
if(ret < 0) {
perror("ether_client_poll: select");
}
return ret == 1;
}
/*-----------------------------------------------------------------------------------*/
u16_t
ether_client_read(u8_t *buf, int bufsize)
{
int ret, len;
fd_set fdset;
struct timeval tv;
struct ether_hdr *hdr = (struct ether_hdr *)rxbuffer;
FD_ZERO(&fdset);
FD_SET(sc, &fdset);
tv.tv_sec = 0;
tv.tv_usec = 10000;
ret = select(sc + 1, &fdset, NULL, NULL, &tv);
if(ret == 0) {
/* printf("ret 0\n");*/
return 0;
}
if(FD_ISSET(sc, &fdset)) {
ret = recv(sc, &rxbuffer[0], sizeof(rxbuffer), 0);
if(ret == -1) {
perror("ether_client_poll: recv");
return 0;
}
len = ret;
if(len > bufsize) {
PRINTF("ether_client_read: packet truncated from %d to %d\n",
len, bufsize);
len = bufsize;
}
/* printf("Incoming len %d\n", len);*/
memcpy(buf, &rxbuffer[sizeof(struct ether_hdr)], len);
radio_sensor_signal = hdr->signal;
if(hdr->type == PTYPE_DATA && hdr->srcid != node.id) {
return len - sizeof(struct ether_hdr);
} else if(hdr->type == PTYPE_CLOCK) {
node_set_time(hdr->clock);
} else if(hdr->type == PTYPE_SENSOR) {
int strength = sensor_strength() -
((hdr->srcx - node_x()) * (hdr->srcx - node_x()) +
(hdr->srcy - node_y()) * (hdr->srcy - node_y())) / sensor_strength();
/* printf("Dist %d \n", strength);*/
if(strength > 0) {
sensor_input(&hdr->sensor_data, strength);
}
} else if(hdr->type == PTYPE_SERIAL) {
char *ptr = hdr->text;
printf("serial input %s\n", ptr);
for(ptr = hdr->text; *ptr != 0; ++ptr) {
serial_line_input_byte(*ptr);
}
}
}
return 0;
}
/*-----------------------------------------------------------------------------------*/
void
ether_server_poll(void)
{
int ret;
fd_set fdset;
struct timeval tv;
struct ether_hdr *hdr = (struct ether_hdr *)rxbuffer;
/* struct timeval rtime1, rtime2;
struct timespec ts;
struct timezone tz;*/
tv.tv_sec = 0;
tv.tv_usec = 100;
do {
FD_ZERO(&fdset);
FD_SET(s, &fdset);
ret = select(s + 1, &fdset, NULL, NULL, &tv);
if(ret == 0) {
return;
}
if(FD_ISSET(s, &fdset)) {
ret = recv(s, &rxbuffer[0], sizeof(rxbuffer), 0);
if(ret == -1) {
perror("ether_poll: read");
return;
}
nodes_set_line(hdr->srcx, hdr->srcy, hdr->linex, hdr->liney);
switch(hdr->type) {
case PTYPE_DATA:
PRINTF("ether_poll: read %d bytes from (%d, %d)\n",
ret, hdr->srcx, hdr->srcy);
ether_put((char *)rxbuffer, ret, hdr->srcx, hdr->srcy);
break;
case PTYPE_LEDS:
nodes_set_leds(hdr->srcx, hdr->srcy, hdr->leds);
break;
case PTYPE_TEXT:
nodes_set_text(hdr->srcx, hdr->srcy, hdr->text);
break;
case PTYPE_DONE:
nodes_done(hdr->srcid);
break;
case PTYPE_SERIAL:
break;
case PTYPE_RADIO_STATUS:
nodes_set_radio_status(hdr->srcx, hdr->srcy, hdr->radio_status);
break;
}
}
/* tv.tv_sec = 0;
tv.tv_usec = 1;*/
} while(1/*ret > 0*/);
}
/*-----------------------------------------------------------------------------------*/
void
ether_put(char *data, int len, int x, int y)
{
struct ether_packet *p;
/* printf("ether_put: packet len %d at (%d, %d)\n", len, x, y);*/
p = (struct ether_packet *)memb_alloc(&packets);
if(p != NULL) {
if(len > 1500) {
len = 1500;
}
memcpy(p->data, data, len);
p->len = len;
p->x = x;
p->y = y;
list_push(active_packets, p);
}
}
/*-----------------------------------------------------------------------------------*/
static void
send_packet(char *data, int len, int port)
{
struct sockaddr_in sa;
memset((char *)&sa, 0, sizeof(sa));
sa.sin_family = AF_INET;
sa.sin_addr.s_addr = inet_addr("127.0.0.1");
sa.sin_port = uip_htons(port);
if(sendto(s, data, len, 0, (struct sockaddr *)&sa, sizeof(sa)) == -1) {
perror("ether: send_packet: sendto");
}
}
/*-----------------------------------------------------------------------------------*/
void
ether_tick(void)
{
struct ether_packet *p, *q;
struct ether_hdr *hdr;
int port;
int x, y;
int i;
int interference;
/* Go through every node and see if there are any packets destined
to them. If two or more packets are sent in the vicinity of the
node, they interfere with each otehr and none reaches the
node. */
for(i = 0; i < nodes_num(); ++i) {
x = nodes_node(i)->x;
y = nodes_node(i)->y;
port = nodes_node(i)->port;
/* Go through all active packets to see if anyone is sent within
range of this node. */
for(p = list_head(active_packets); p != NULL; p = p->next) {
num_sent++;
/* Update the node type. */
hdr = (struct ether_hdr *)p->data;
/* nodes_node(hdr->srcid)->type = hdr->srcnodetype;*/
if(!(p->x == x && p->y == y) && /* Don't send packets back to
the sender. */
(p->x - x) * (p->x - x) +
(p->y - y) * (p->y - y) <=
ether_strength() * ether_strength()) {
hdr->signal = ether_strength() * ether_strength() -
(p->x - x) * (p->x - x) -
(p->y - y) * (p->y - y);
/* This packet was sent in the reception range of this node,
so we check against all other packets to see if there is
more than one packet sent towards this node. If so, we have
interference and the node will not be able to receive any
data. */
interference = 0;
if(collisions) {
for(q = list_head(active_packets); q != NULL; q = q->next) {
/* Compute the distance^2 and check against signal strength. */
if(p != q &&
((q->x - x) * (q->x - x) +
(q->y - y) * (q->y - y) <=
ether_strength() * ether_strength())) {
/* If the potentially interfering packets were sent from
the same node, then they don't interfere with each
other. Otherwise they interfere and we sent the
interference flag to 1. */
if(p->x != q->x ||
p->y != q->y) {
interference = 1;
}
break;
}
}
}
if(interference) {
num_collisions++;
/* printf("Collisions %d\n", num_collisions);*/
}
if(!interference) {
/* printf("ether: delivering packet from %d to %d\n",
hdr->srcid, port);*/
if((unsigned int)((rand() * 17) % 65536) >= drop_probability) {
send_packet(p->data, p->len, port);
num_received++;
} else {
num_drops++;
}
}
}
}
}
/* Remove all packets from the active packets list. */
while((p = list_pop(active_packets)) != NULL) {
memb_free(&packets, (void *) p);
}
++timer;
}
/*-----------------------------------------------------------------------------------*/
struct ether_packet *
ether_packets(void)
{
return list_head(active_packets);
}
/*-----------------------------------------------------------------------------------*/
clock_time_t
ether_time(void)
{
return timer;
}
/*-----------------------------------------------------------------------------------*/
static void
node_send_packet(char *data, int len)
{
struct sockaddr_in sa;
memset((char *)&sa, 0, sizeof(sa));
sa.sin_family = AF_INET;
sa.sin_addr.s_addr = inet_addr("127.0.0.1");
sa.sin_port = uip_htons(ETHER_PORT);
if(sendto(sc, data, len, 0,
(struct sockaddr *)&sa, sizeof(sa)) == -1) {
perror("ether.c node_send_packet: sendto");
}
}
/*-----------------------------------------------------------------------------------*/
u8_t
ether_send(char *data, int len)
{
char tmpbuf[2048];
struct ether_hdr *hdr = (struct ether_hdr *)tmpbuf;
memcpy(&tmpbuf[sizeof(struct ether_hdr)], data, len);
hdr->srcx = node.x;
hdr->srcy = node.y;
hdr->type = PTYPE_DATA;
/* hdr->srcnodetype = node.type;*/
hdr->srcid = node.id;
hdr->linex = linex;
hdr->liney = liney;
node_send_packet(tmpbuf, len + sizeof(struct ether_hdr));
return UIP_FW_OK;
}
/*-----------------------------------------------------------------------------------*/
void
ether_set_leds(int leds)
{
struct ether_hdr hdr;
memset(&hdr, 0, sizeof (hdr));
hdr.srcx = node.x;
hdr.srcy = node.y;
hdr.type = PTYPE_LEDS;
hdr.leds = leds;
/* hdr.srcnodetype = node.type;*/
hdr.srcid = node.id;
hdr.linex = linex;
hdr.liney = liney;
node_send_packet((char *)&hdr, sizeof(struct ether_hdr));
}
/*-----------------------------------------------------------------------------------*/
void
ether_set_text(char *text)
{
struct ether_hdr hdr;
hdr.srcx = node.x;
hdr.srcy = node.y;
hdr.type = PTYPE_TEXT;
strncpy(hdr.text, text, NODES_TEXTLEN);
/* hdr.srcnodetype = node.type;*/
hdr.srcid = node.id;
hdr.linex = linex;
hdr.liney = liney;
node_send_packet((char *)&hdr, sizeof(struct ether_hdr));
}
/*-----------------------------------------------------------------------------------*/
void
ether_set_radio_status(int onoroff)
{
struct ether_hdr hdr;
hdr.srcx = node.x;
hdr.srcy = node.y;
hdr.type = PTYPE_RADIO_STATUS;
hdr.radio_status = onoroff;
hdr.srcid = node.id;
hdr.linex = linex;
hdr.liney = liney;
node_send_packet((char *)&hdr, sizeof(struct ether_hdr));
}
/*-----------------------------------------------------------------------------------*/
void
ether_send_sensor_data(struct sensor_data *d, int srcx, int srcy, int strength)
{
int port;
int x, y;
int i;
struct ether_hdr hdr;
/* printf("Sensor data at (%d, %d)\n", srcx, srcy);*/
for(i = 0; i < nodes_num(); ++i) {
x = nodes_node(i)->x;
y = nodes_node(i)->y;
port = nodes_node(i)->port;
if((srcx - x) * (srcx - x) +
(srcy - y) * (srcy - y) <=
strength * strength) {
hdr.srcx = srcx;
hdr.srcy = srcy;
hdr.type = PTYPE_SENSOR;
hdr.sensor_data = *d;
send_packet((char *)&hdr, sizeof(hdr), port);
}
}
}
/*-----------------------------------------------------------------------------------*/
void
ether_send_done(void)
{
struct ether_hdr hdr;
hdr.srcx = node.x;
hdr.srcy = node.y;
hdr.type = PTYPE_DONE;
hdr.srcid = node.id;
node_send_packet((char *)&hdr, sizeof(struct ether_hdr));
}
/*-----------------------------------------------------------------------------------*/
void
ether_send_serial(char *str)
{
struct ether_hdr hdr;
int len;
hdr.srcx = node.x;
hdr.srcy = node.y;
hdr.type = PTYPE_SERIAL;
hdr.srcid = node.id;
len = strlen(str) + 1;
if(len > sizeof(hdr.text)) {
len = sizeof(hdr.text);
}
memcpy(&hdr.text, str, len);
hdr.text[len] = 0;
/* printf("ether_send_serial '%s' to %d len %d\n", str, nodes_base_node_port, sizeof(struct ether_hdr));*/
send_packet((char *)&hdr, sizeof(struct ether_hdr), nodes_base_node_port);
}
/*-----------------------------------------------------------------------------------*/
void
ether_set_line(int x, int y)
{
struct ether_hdr hdr;
linex = x;
liney = y;
hdr.srcx = node.x;
hdr.srcy = node.y;
hdr.type = PTYPE_NONE;
hdr.srcid = node.id;
hdr.linex = linex;
hdr.liney = liney;
node_send_packet((char *)&hdr, sizeof(struct ether_hdr));
}
/*-----------------------------------------------------------------------------------*/

View file

@ -1,92 +0,0 @@
/*
* Copyright (c) 2004, Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: ether.h,v 1.9 2008/05/14 19:22:58 adamdunkels Exp $
*/
#ifndef __ETHER_H__
#define __ETHER_H__
#include "contiki.h"
#include "sensor.h"
struct ether_packet {
struct ether_packet *next;
char data[1500];
int len;
int x, y;
int destx, desty;
};
void ether_send_done(void);
u8_t ether_send(char *data, int len);
void ether_set_leds(int leds);
void ether_set_text(char *text);
void ether_set_radio_status(int onoroff);
void ether_send_serial(char *text);
void ether_poll(void);
void ether_server_init(void);
void ether_client_init(int port);
void ether_tick(void);
u16_t ether_client_read(u8_t *buf, int len);
void ether_server_poll(void);
void ether_put(char *packet, int len, int src_x, int src_y);
void ether_send_sensor_data(struct sensor_data *d, int srcx, int srcy, int strength);
int ether_client_poll(void);
struct ether_packet * ether_packets(void);
clock_time_t ether_time(void);
#define ETHER_PORT 4999
/*#define ETHER_STRENGTH 24*/
int ether_strength(void);
void ether_set_strength(int s);
void ether_set_collisions(int c);
void ether_set_drop_probability(double p);
void ether_print_stats(void);
void ether_set_line(int x, int y);
#endif /* __ETHER_H__ */

View file

@ -1,70 +0,0 @@
/*
* Copyright (c) 2005, 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: init.c,v 1.1 2006/06/17 22:41:35 adamdunkels Exp $
*/
#include "init.h"
#include "random.h"
void
init(void)
{
int x, y;
ether_set_strength(21);
main_add_node(1, 1);
main_add_node(1, 20);
main_add_node(20, 1);
/*for(x = 1; x < 201; x += 20) {
for(y = 1; y < 201; y += 20) {
main_add_node(x, y);
}
}*/
/* main_add_node(10, 10);
main_add_node(11, 11);
main_add_node(12, 12);
main_add_node(13, 13);
main_add_node(14, 14);
main_add_node(15, 15);
main_add_node(16, 16); */
/* for(x = 10; x < 370; x += 20) {
for(y = 10; y < 370; y += 20) {
main_add_node(x + (random_rand() % 20) - 10,
y + (random_rand() % 20) - 10);
}
}*/
/* main_add_base(1, 1);*/
}

View file

@ -1,43 +0,0 @@
/*
* Copyright (c) 2005, 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: init.h,v 1.3 2007/11/17 18:09:18 adamdunkels Exp $
*/
#ifndef __INIT_H__
#define __INIT_H__
#include "ether.h"
void init(void);
int main_add_node(int x, int y);
void main_add_base(int x, int y);
#endif /* __INIT_H__ */

Some files were not shown because too many files have changed in this diff Show more