mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Merge branch 'mac'
This commit is contained in:
commit
984e2e5dde
@ -8,12 +8,19 @@
|
||||
|
||||
void hard_reset_to_bootloader(void)
|
||||
{
|
||||
printf("Reset CPU (into bootloader)\r\n");
|
||||
/* Use this lines for flashing a node with interrupted DTR line
|
||||
* printf("Press Reset - confirm with anykey\n");
|
||||
getchar();
|
||||
*/
|
||||
printf("Reset CPU (into bootloader)\r\n");
|
||||
set_rts(1); // RTS (ttl level) connects to P0.14
|
||||
/* the next two lines should be commented for the prepared node */
|
||||
set_dtr(1); // DTR (ttl level) connects to RST
|
||||
send_break_signal(); // or break detect circuit to RST
|
||||
usleep(75000);
|
||||
set_dtr(0); // allow the CPU to run
|
||||
printf("Release Reset - confirm with anykey\n");
|
||||
getchar();
|
||||
set_dtr(0); // allow the CPU to run:
|
||||
set_baud(baud_rate);
|
||||
set_rts(1); // set RTS again (as it has been reset by set_baudrate)
|
||||
usleep(40000);
|
||||
|
@ -31,5 +31,5 @@ HDRS += $(TOP)/drivers/cc110x ;
|
||||
|
||||
Module cc110x : cc1100.c cc1100-csmaca-mac.c cc1100-defaultSettings.c
|
||||
cc1100_phy.c cc1100_spi.c
|
||||
: board_cc110x swtimer protocol_multiplex gpioint ;
|
||||
: board_cc110x vtimer protocol_multiplex gpioint ;
|
||||
|
||||
|
@ -47,7 +47,7 @@ and the mailinglist (subscription via web site)
|
||||
#include "protocol-multiplex.h"
|
||||
|
||||
#include "hwtimer.h"
|
||||
#include <swtimer.h>
|
||||
#include <vtimer.h>
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
@ -102,26 +102,31 @@ int cc1100_send_csmaca(radio_address_t address, protocol_t protocol, int priorit
|
||||
|
||||
// Calculate collisions per second
|
||||
if (collision_state == COLLISION_STATE_INITIAL) {
|
||||
collision_measurement_start = swtimer_now();
|
||||
timex_t now = vtimer_now();
|
||||
collision_measurement_start = now.microseconds;
|
||||
collision_count = 0;
|
||||
collisions_per_sec = 0;
|
||||
collision_state = COLLISION_STATE_MEASURE;
|
||||
} else if (collision_state == COLLISION_STATE_MEASURE) {
|
||||
uint64_t timespan = swtimer_now() - collision_measurement_start;
|
||||
timex_t now = vtimer_now();
|
||||
uint64_t timespan = now.microseconds - collision_measurement_start;
|
||||
if (timespan > 1000000) {
|
||||
collisions_per_sec = (collision_count * 1000000) / (double) timespan;
|
||||
if (collisions_per_sec > 0.5 && collisions_per_sec <= 2.2) {
|
||||
collision_measurement_start = swtimer_now();
|
||||
timex_t now = vtimer_now();
|
||||
collision_measurement_start = now.microseconds;
|
||||
collision_state = COLLISION_STATE_KEEP;
|
||||
} else if (collisions_per_sec > 2.2) {
|
||||
collision_measurement_start = swtimer_now();
|
||||
timex_t now = vtimer_now();
|
||||
collision_measurement_start = now.microseconds;
|
||||
collision_state = COLLISION_STATE_KEEP;
|
||||
} else {
|
||||
collision_state = COLLISION_STATE_INITIAL;
|
||||
}
|
||||
}
|
||||
} else if (collision_state == COLLISION_STATE_KEEP) {
|
||||
uint64_t timespan = swtimer_now() - collision_measurement_start;
|
||||
timex_t now = vtimer_now();
|
||||
uint64_t timespan = now.microseconds - collision_measurement_start;
|
||||
if (timespan > 5000000) {
|
||||
collision_state = COLLISION_STATE_INITIAL;
|
||||
}
|
||||
|
@ -61,10 +61,12 @@ and the mailinglist (subscription via web site)
|
||||
#define CC1100_MODE_WOR (0) ///< Usable radio mode: Wake-On-Radio
|
||||
#define CC1100_MODE_CONSTANT_RX (1) ///< Usable radio mode: Constant receive
|
||||
|
||||
#define CC1100_MAX_DATA_LENGTH (58)
|
||||
|
||||
// Define default radio mode to constant RX if no
|
||||
// project specific setting is available.
|
||||
#ifndef CC1100_RADIO_MODE
|
||||
#define CC1100_RADIO_MODE CC1100_MODE_CONSTANT_RX
|
||||
#define CC1100_RADIO_MODE CC1100_MODE_WOR
|
||||
#endif
|
||||
|
||||
/// CC1100 radio interface
|
||||
|
@ -305,7 +305,7 @@ static void wakeup_from_wor(void)
|
||||
*/
|
||||
void switch_to_wor2(void)
|
||||
{
|
||||
if (cc110x_get_gdo2()) return; // If incoming packet, then don't go to WOR now
|
||||
// if (cc110x_get_gdo2()) return; // If incoming packet, then don't go to WOR now
|
||||
cc1100_spi_strobe(CC1100_SIDLE); // Put CC1100 to IDLE
|
||||
radio_state = RADIO_IDLE; // Radio state now IDLE
|
||||
cc1100_spi_write_reg(CC1100_MCSM2,
|
||||
@ -865,7 +865,7 @@ void cc1100_cs_init(void)
|
||||
}
|
||||
cc1100_spi_write_reg(CC1100_MCSM0, 0x08); // Turn off FS-Autocal
|
||||
cc1100_spi_strobe(CC1100_SCAL); // Calibrate manually (721 us)
|
||||
hwtimer_wait(MANUAL_FS_CAL_TIME); // Wait for calibration to finish before packet burst can start
|
||||
hwtimer_wait(MANUAL_FS_CAL_TIME); // Wait for calibration to finish before packet burst can start
|
||||
radio_state = RADIO_AIR_FREE_WAITING; // Set status "waiting for air free"
|
||||
cc1100_spi_write_reg(CC1100_MCSM2, 0x07); // Configure RX_TIME = Until end of packet (no timeout)
|
||||
cc1100_spi_strobe(CC1100_SRX); // Switch to RX (88.4 us) (Carrier Sense)
|
||||
|
@ -45,7 +45,7 @@ and the mailinglist (subscription via web site)
|
||||
#include <string.h>
|
||||
|
||||
#include "hwtimer.h"
|
||||
#include <swtimer.h>
|
||||
#include <vtimer.h>
|
||||
|
||||
#include "cc1100.h"
|
||||
#include "cc1100_spi.h"
|
||||
@ -96,8 +96,8 @@ static const pm_table_t handler_table;
|
||||
static const char *cc1100_event_handler_name = "cc1100_event_handler";
|
||||
static mutex_t cc1100_mutex;
|
||||
volatile int cc1100_mutex_pid;
|
||||
static swtimer_t cc1100_watch_dog;
|
||||
static swtime_t cc1100_watch_dog_period = 0;
|
||||
static vtimer_t cc1100_watch_dog;
|
||||
static timex_t cc1100_watch_dog_period;
|
||||
|
||||
static uint16_t cc1100_event_handler_pid;
|
||||
static void cc1100_event_handler_function(void);
|
||||
@ -198,9 +198,10 @@ void cc1100_phy_init()
|
||||
|
||||
// Active watchdog for the first time
|
||||
if (radio_mode == CC1100_MODE_CONSTANT_RX) {
|
||||
cc1100_watch_dog_period = CC1100_WATCHDOG_PERIOD;
|
||||
if (cc1100_watch_dog_period != 0) {
|
||||
swtimer_set_msg(&cc1100_watch_dog, 5000000L, cc1100_event_handler_pid, NULL);
|
||||
cc1100_watch_dog_period.microseconds = CC1100_WATCHDOG_PERIOD;
|
||||
if (cc1100_watch_dog_period.microseconds != 0) {
|
||||
timex_t temp = timex_set(0, 5000000L);
|
||||
vtimer_set_msg(&cc1100_watch_dog, temp, cc1100_event_handler_pid, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -374,7 +375,8 @@ static bool contains_seq_entry(uint8_t src, uint8_t id)
|
||||
{
|
||||
int i;
|
||||
uint32_t cmp;
|
||||
uint64_t now = swtimer_now();
|
||||
timex_t now_timex = vtimer_now();
|
||||
uint64_t now = now_timex.microseconds;
|
||||
|
||||
for (i = 0; i < MAX_SEQ_BUFFER_SIZE; i++)
|
||||
{
|
||||
@ -412,7 +414,8 @@ static void add_seq_entry(uint8_t src, uint8_t id)
|
||||
// Add new entry
|
||||
seq_buffer[seq_buffer_pos].source = src;
|
||||
seq_buffer[seq_buffer_pos].identification = id;
|
||||
seq_buffer[seq_buffer_pos].m_ticks = swtimer_now();
|
||||
timex_t now = vtimer_now();
|
||||
seq_buffer[seq_buffer_pos].m_ticks = now.microseconds;
|
||||
|
||||
// Store 16 bit sequence number of layer 0 for speedup
|
||||
last_seq_num = src;
|
||||
@ -466,7 +469,7 @@ static bool send_burst(cc1100_packet_layer0_t *packet, uint8_t retries, uint8_t
|
||||
|
||||
cc1100_statistic.raw_packets_out++;
|
||||
|
||||
// Delay until predefined "send" interval has passed
|
||||
// Delay until predefined "send" interval has passed
|
||||
timer_tick_t now = hwtimer_now();
|
||||
if (t > now)
|
||||
{
|
||||
@ -568,7 +571,9 @@ int cc1100_send(radio_address_t addr, protocol_t protocol, int priority, char *p
|
||||
|
||||
memset(tx_buffer.data, 0, MAX_DATA_LENGTH); // Clean data
|
||||
|
||||
tx_buffer.length = 3 + MAX_DATA_LENGTH; // 3 bytes (A&PS&F) + data length
|
||||
/* TODO: when packets are shoreter than max packet size, WOR interval is too long.
|
||||
* This must be solved in some way. */
|
||||
tx_buffer.length = 3 + payload_len; // 3 bytes (A&PS&F) + data length
|
||||
tx_buffer.address = address; // Copy destination address
|
||||
tx_buffer.flags = 0x00; // Set clean state
|
||||
tx_buffer.flags = W_FLAGS_PROTOCOL(protocol); // Copy protocol identifier
|
||||
@ -628,8 +633,8 @@ static void cc1100_event_handler_function(void)
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (cc1100_watch_dog_period != 0) {
|
||||
swtimer_remove(&cc1100_watch_dog);
|
||||
if (cc1100_watch_dog_period.microseconds != 0) {
|
||||
vtimer_remove(&cc1100_watch_dog);
|
||||
}
|
||||
// Test if any resource error has occurred
|
||||
if (rflags.KT_RES_ERR)
|
||||
@ -659,7 +664,7 @@ static void cc1100_event_handler_function(void)
|
||||
{
|
||||
rx_buffer_t* packet = &rx_buffer[rx_buffer_head];
|
||||
protocol_t p = R_FLAGS_PROTOCOL(packet->packet.flags);
|
||||
if (packet_monitor != NULL) packet_monitor((void*)&packet->packet.data, MAX_DATA_LENGTH, p, &packet->info);
|
||||
if (packet_monitor != NULL) packet_monitor((void*)&packet->packet.data, packet->packet.length, p, &packet->info);
|
||||
pm_invoke(&handler_table, p, (void*)&packet->packet.data, MAX_DATA_LENGTH, &packet->info);
|
||||
dINT();
|
||||
rx_buffer_size--;
|
||||
@ -670,8 +675,9 @@ static void cc1100_event_handler_function(void)
|
||||
dINT();
|
||||
if (rx_buffer_size == 0)
|
||||
{
|
||||
if (cc1100_watch_dog_period != 0) {
|
||||
swtimer_set_msg(&cc1100_watch_dog, cc1100_watch_dog_period * 1000000L,
|
||||
if (cc1100_watch_dog_period.microseconds != 0) {
|
||||
timex_t temp = timex_set(0, cc1100_watch_dog_period.microseconds * 1000000L);
|
||||
vtimer_set_msg(&cc1100_watch_dog, temp,
|
||||
cc1100_event_handler_pid, NULL);
|
||||
}
|
||||
msg_receive(&m);
|
||||
@ -711,6 +717,8 @@ void cc1100_phy_rx_handler(void)
|
||||
// Get packet pointer and store additional data in packet info structure
|
||||
cc1100_packet_layer0_t* p = &(rx_buffer[rx_buffer_tail].packet);
|
||||
rx_buffer[rx_buffer_tail].info.phy_src = p->phy_src;
|
||||
rx_buffer[rx_buffer_tail].info.source = p->phy_src;
|
||||
rx_buffer[rx_buffer_tail].info.destination = p->address;
|
||||
rx_buffer[rx_buffer_tail].info.rssi = rflags.RSSI;
|
||||
rx_buffer[rx_buffer_tail].info.lqi = rflags.LQI;
|
||||
rx_buffer[rx_buffer_tail].info.promiscuous = false;
|
||||
|
@ -1,5 +1,5 @@
|
||||
SubDir TOP projects test_rpl ;
|
||||
|
||||
Module test_rpl : main.c : shell posix_io uart0 auto_init vtimer 6lowpan uart0 posix_io cc110x_ng rpl ;
|
||||
Module test_rpl : main.c : shell shell_commands ps posix_io uart0 auto_init vtimer 6lowpan uart0 posix_io cc110x rpl ;
|
||||
|
||||
UseModule test_rpl ;
|
||||
|
@ -5,6 +5,7 @@
|
||||
|
||||
#include <posix_io.h>
|
||||
#include <shell.h>
|
||||
#include <shell_commands.h>
|
||||
#include <board_uart0.h>
|
||||
|
||||
#include "sys/net/sixlowpan/sixlowip.h"
|
||||
@ -13,10 +14,31 @@
|
||||
#include "sys/net/sixlowpan/rpl/rpl.h"
|
||||
#include "sys/net/sixlowpan/rpl/rpl_dodag.h"
|
||||
|
||||
#define TR_WD_STACKSIZE (256)
|
||||
|
||||
char tr_wd_stack[TR_WD_STACKSIZE];
|
||||
|
||||
void wakeup_thread(void) {
|
||||
while (1) {
|
||||
if (thread_getstatus(transceiver_pid) == STATUS_SLEEPING) {
|
||||
vtimer_usleep(500 * 1000);
|
||||
if (thread_getstatus(transceiver_pid) == STATUS_SLEEPING) {
|
||||
//puts("WAKEUP!");
|
||||
thread_wakeup(transceiver_pid);
|
||||
}
|
||||
}
|
||||
vtimer_usleep(1000 * 1000);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void init(char *str){
|
||||
transceiver_command_t tcmd;
|
||||
msg_t m;
|
||||
uint8_t chan = 10;
|
||||
|
||||
char command;
|
||||
uint16_t r_addr;
|
||||
ipv6_addr_t std_addr;
|
||||
|
||||
int res = sscanf(str, "init %c %hu", &command, &r_addr);
|
||||
|
||||
@ -27,38 +49,81 @@ void init(char *str){
|
||||
printf("\taddress must be an 8 bit integer\n");
|
||||
}
|
||||
|
||||
ipv6_init_address(&std_addr, 0xABCD,0,0,0,0x1234,0xFFFF,0xFEDC,r_addr);
|
||||
uint8_t state;
|
||||
switch (command) {
|
||||
case 'r':
|
||||
printf("INFO: Initialize as root on address \n");
|
||||
ipv6_print_addr(&std_addr);
|
||||
printf("INFO: Initialize as root on address %d\n", r_addr);
|
||||
if (r_addr > 255) {
|
||||
printf("ERROR: address not an 8 bit integer\n");
|
||||
return;
|
||||
}
|
||||
state = rpl_init(TRANSCEIVER_CC1100, &std_addr);
|
||||
state = rpl_init(TRANSCEIVER_CC1100, r_addr);
|
||||
if(state != SUCCESS){
|
||||
printf("Error initializing RPL\n");
|
||||
}
|
||||
rpl_init_root();
|
||||
break;
|
||||
case 'n':
|
||||
printf("INFO: Initialize as node on address \n");
|
||||
ipv6_print_addr(&std_addr);
|
||||
printf("INFO: Initialize as node on address %d\n", r_addr);
|
||||
if (r_addr > 255) {
|
||||
printf("ERROR: address not an 8 bit integer\n");
|
||||
return;
|
||||
}
|
||||
state = rpl_init(TRANSCEIVER_CC1100, &std_addr);
|
||||
state = rpl_init(TRANSCEIVER_CC1100, r_addr);
|
||||
if(state != SUCCESS){
|
||||
printf("Error initializing RPL\n");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
printf("ERROR: Unknown command '%c'\n", command);
|
||||
break;
|
||||
return;
|
||||
}
|
||||
|
||||
/* set channel to 10 */
|
||||
tcmd.transceivers = TRANSCEIVER_CC1100;
|
||||
tcmd.data = &chan;
|
||||
m.type = SET_CHANNEL;
|
||||
m.content.ptr = (void*) &tcmd;
|
||||
|
||||
msg_send_receive(&m, &m, transceiver_pid);
|
||||
|
||||
/* start transceiver watchdog */
|
||||
thread_create(tr_wd_stack, TR_WD_STACKSIZE, PRIORITY_MAIN-3, CREATE_STACKTEST, wakeup_thread, "TX/RX WD");
|
||||
|
||||
}
|
||||
void loop(char *str){
|
||||
rpl_routing_entry_t * rtable;
|
||||
while(1){
|
||||
rtable = rpl_get_routing_table();
|
||||
rpl_dodag_t * mydodag = rpl_get_my_dodag();
|
||||
if(mydodag == NULL){
|
||||
vtimer_usleep(20 * 1000 * 1000);
|
||||
continue;
|
||||
}
|
||||
printf("---------------------------\n");
|
||||
printf("OUTPUT\n");
|
||||
printf("my rank: %d\n", mydodag->my_rank);
|
||||
printf("my preferred parent:\n");
|
||||
ipv6_print_addr(&mydodag->my_preferred_parent->addr);
|
||||
printf("parent lifetime: %d\n",mydodag->my_preferred_parent->lifetime);
|
||||
printf("---------------------------$\n");
|
||||
for(int i=0;i<RPL_MAX_ROUTING_ENTRIES;i++){
|
||||
if(rtable[i].used){
|
||||
ipv6_print_addr(&rtable[i].address);
|
||||
puts("next hop");
|
||||
ipv6_print_addr(&rtable[i].next_hop);
|
||||
printf("entry %d lifetime %d\n",i,rtable[i].lifetime);
|
||||
if(!rpl_equal_id(&rtable[i].address, &rtable[i].next_hop)){
|
||||
puts("multi-hop");
|
||||
}
|
||||
printf("---------------------------$\n");
|
||||
}
|
||||
}
|
||||
printf("########################\n");
|
||||
vtimer_usleep(20 * 1000 * 1000);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void table(char *str){
|
||||
@ -70,9 +135,14 @@ void table(char *str){
|
||||
for(int i=0;i<RPL_MAX_ROUTING_ENTRIES;i++){
|
||||
if(rtable[i].used){
|
||||
ipv6_print_addr(&rtable[i].address);
|
||||
printf("entry %d lifetime %d\n",i,rtable[i].lifetime);
|
||||
if(!rpl_equal_id(&rtable[i].address, &rtable[i].next_hop)){
|
||||
puts("multi-hop");
|
||||
}
|
||||
printf("--------------\n");
|
||||
}
|
||||
}
|
||||
printf("$\n");
|
||||
}
|
||||
|
||||
void dodag(char *str){
|
||||
@ -80,7 +150,7 @@ void dodag(char *str){
|
||||
rpl_dodag_t * mydodag = rpl_get_my_dodag();
|
||||
if(mydodag == NULL){
|
||||
printf("Not part of a dodag\n");
|
||||
printf("---------------------------\n");
|
||||
printf("---------------------------$\n");
|
||||
return;
|
||||
}
|
||||
printf("Part of Dodag:\n");
|
||||
@ -88,19 +158,36 @@ void dodag(char *str){
|
||||
printf("my rank: %d\n", mydodag->my_rank);
|
||||
printf("my preferred parent:\n");
|
||||
ipv6_print_addr(&mydodag->my_preferred_parent->addr);
|
||||
printf("---------------------------\n");
|
||||
printf("---------------------------$\n");
|
||||
}
|
||||
|
||||
extern void cc1100_print_config(void);
|
||||
extern void cc1100_print_statistic(void);
|
||||
|
||||
void cc1100_cfg(char* unused) {
|
||||
cc1100_print_config();
|
||||
puts("=============================================");
|
||||
cc1100_print_statistic();
|
||||
}
|
||||
|
||||
|
||||
void wakeup(char* unused) {
|
||||
thread_wakeup(10);
|
||||
}
|
||||
|
||||
const shell_command_t shell_commands[] = {
|
||||
{"init", "", init},
|
||||
{"table", "", table},
|
||||
{"dodag", "", dodag},
|
||||
{"cc1100", "", cc1100_cfg},
|
||||
{"wakeup", "", wakeup},
|
||||
{"loop", "", loop},
|
||||
{NULL, NULL, NULL}
|
||||
};
|
||||
|
||||
int main(void) {
|
||||
printf("RPL Test Application\n");
|
||||
vtimer_init();
|
||||
|
||||
|
||||
posix_open(uart0_handler_pid, 0);
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
SubDir TOP projects wiselib ;
|
||||
|
||||
Module wiseleb : main.c : cc110x_ng shell shell_commands transceiver ps rtc posix_io uart0 auto_init swtimer config ltc4150 ;
|
||||
Module wiselib : main.c : shell posix_io vtimer timex shell_commands ps rtc sht11 ltc4150 cc110x gpioint config mci ps transceiver swtimer ;
|
||||
|
||||
UseModule wiseleb ;
|
||||
UseModule wiselib ;
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include <string.h>
|
||||
#include <vtimer.h>
|
||||
#include <thread.h>
|
||||
#include <mutex.h>
|
||||
#include "msg.h"
|
||||
#include "rpl.h"
|
||||
#include "of0.h"
|
||||
@ -19,54 +20,115 @@ rpl_of_t *objective_functions[NUMBER_IMPLEMENTED_OFS];
|
||||
rpl_routing_entry_t routing_table[RPL_MAX_ROUTING_ENTRIES];
|
||||
unsigned int rpl_process_pid;
|
||||
ipv6_addr_t my_address;
|
||||
mutex_t rpl_send_mutex;
|
||||
mutex_t rpl_recv_mutex;
|
||||
//receive buffer without LL_HDR
|
||||
uint8_t rpl_buffer[BUFFER_SIZE - LL_HDR_LEN];
|
||||
//in send buffer we need space fpr LL_HDR
|
||||
uint8_t rpl_send_buffer[BUFFER_SIZE];
|
||||
|
||||
msg_t msg_queue[RPL_PKT_RECV_BUF_SIZE];
|
||||
//SEND BUFFERS
|
||||
static struct ipv6_hdr_t* ipv6_send_buf;
|
||||
static struct icmpv6_hdr_t* icmp_send_buf;
|
||||
static struct rpl_dio_t *rpl_send_dio_buf;
|
||||
static struct rpl_dis_t *rpl_send_dis_buf;
|
||||
static struct rpl_dao_t *rpl_send_dao_buf;
|
||||
static struct rpl_dao_ack_t * rpl_send_dao_ack_buf;
|
||||
static struct rpl_opt_dodag_conf_t * rpl_send_opt_dodag_conf_buf;
|
||||
//static struct rpl_opt_solicited_t * rpl_send_opt_solicited_buf;
|
||||
static struct rpl_opt_target_t * rpl_send_opt_target_buf;
|
||||
static struct rpl_opt_transit_t * rpl_send_opt_transit_buf;
|
||||
|
||||
//RECEIVE BUFFERS
|
||||
//Unbenutzter dao_ack buffer auskommentiert, damit keine warnings erscheinen
|
||||
static struct ipv6_hdr_t* ipv6_buf;
|
||||
static struct icmpv6_hdr_t* icmp_buf;
|
||||
static struct rpl_dio_t *rpl_dio_buf;
|
||||
static struct rpl_dis_t *rpl_dis_buf;
|
||||
static struct rpl_dao_t *rpl_dao_buf;
|
||||
//static struct rpl_dao_ack_t * rpl_dao_ack_buf;
|
||||
static struct rpl_dao_ack_t * rpl_dao_ack_buf;
|
||||
static struct rpl_opt_t *rpl_opt_buf;
|
||||
static struct rpl_opt_dodag_conf_t * rpl_opt_dodag_conf_buf;
|
||||
static struct rpl_opt_solicited_t * rpl_opt_solicited_buf;
|
||||
static struct rpl_opt_target_t * rpl_opt_target_buf;
|
||||
static struct rpl_opt_transit_t * rpl_opt_transit_buf;
|
||||
|
||||
// SEND BUFFERS
|
||||
static struct ipv6_hdr_t * get_rpl_send_ipv6_buf(void){
|
||||
return ((struct ipv6_hdr_t*)&(rpl_send_buffer[0]));
|
||||
}
|
||||
static uint8_t * get_rpl_send_payload_buf(uint8_t ext_len){
|
||||
//return &(rpl_send_buffer[LLHDR_IPV6HDR_LEN + ext_len]);
|
||||
return &(rpl_send_buffer[IPV6_HDR_LEN + ext_len]);
|
||||
}
|
||||
static struct icmpv6_hdr_t * get_rpl_send_icmpv6_buf(uint8_t ext_len){
|
||||
//return ((struct icmpv6_hdr_t*)&(rpl_send_buffer[LLHDR_IPV6HDR_LEN + ext_len]));
|
||||
return ((struct icmpv6_hdr_t*)&(rpl_send_buffer[IPV6_HDR_LEN + ext_len]));
|
||||
}
|
||||
static struct rpl_dio_t* get_rpl_send_dio_buf(){
|
||||
//return ((struct rpl_dio_t*)&(rpl_send_buffer[LLHDR_ICMPV6HDR_LEN]));
|
||||
return ((struct rpl_dio_t*)&(rpl_send_buffer[IPV6HDR_ICMPV6HDR_LEN]));
|
||||
}
|
||||
static struct rpl_dao_t* get_rpl_send_dao_buf(){
|
||||
//return ((struct rpl_dao_t*)&(rpl_send_buffer[LLHDR_ICMPV6HDR_LEN]));
|
||||
return ((struct rpl_dao_t*)&(rpl_send_buffer[IPV6HDR_ICMPV6HDR_LEN]));
|
||||
}
|
||||
static struct rpl_dao_ack_t* get_rpl_send_dao_ack_buf(){
|
||||
return ((struct rpl_dao_ack_t*)&(rpl_send_buffer[IPV6HDR_ICMPV6HDR_LEN]));
|
||||
}
|
||||
static struct rpl_dis_t* get_rpl_send_dis_buf(){
|
||||
//return ((struct rpl_dis_t*)&(rpl_send_buffer[LLHDR_ICMPV6HDR_LEN]));
|
||||
return ((struct rpl_dis_t*)&(rpl_send_buffer[IPV6HDR_ICMPV6HDR_LEN]));
|
||||
}
|
||||
static struct rpl_opt_dodag_conf_t* get_rpl_send_opt_dodag_conf_buf(uint8_t rpl_msg_len){
|
||||
//return ((struct rpl_opt_dodag_conf_t*)&(rpl_send_buffer[LLHDR_ICMPV6HDR_LEN + rpl_msg_len]));
|
||||
return ((struct rpl_opt_dodag_conf_t*)&(rpl_send_buffer[IPV6HDR_ICMPV6HDR_LEN + rpl_msg_len]));
|
||||
}
|
||||
static struct rpl_opt_target_t* get_rpl_send_opt_target_buf(uint8_t rpl_msg_len){
|
||||
//return ((struct rpl_opt_target_t*)&(rpl_send_buffer[LLHDR_ICMPV6HDR_LEN + rpl_msg_len]));
|
||||
return ((struct rpl_opt_target_t*)&(rpl_send_buffer[IPV6HDR_ICMPV6HDR_LEN + rpl_msg_len]));
|
||||
}
|
||||
|
||||
static struct rpl_opt_transit_t* get_rpl_send_opt_transit_buf(uint8_t rpl_msg_len){
|
||||
//return ((struct rpl_opt_transit_t*)&(rpl_send_buffer[LLHDR_ICMPV6HDR_LEN + rpl_msg_len]));
|
||||
return ((struct rpl_opt_transit_t*)&(rpl_send_buffer[IPV6HDR_ICMPV6HDR_LEN + rpl_msg_len]));
|
||||
}
|
||||
|
||||
//RECEIVE BUFFERS
|
||||
static struct ipv6_hdr_t * get_rpl_ipv6_buf(void){
|
||||
return ((struct ipv6_hdr_t*)&(rpl_buffer[0]));
|
||||
}
|
||||
static struct rpl_dio_t* get_rpl_dio_buf(){
|
||||
return ((struct rpl_dio_t*)&(buffer[LLHDR_ICMPV6HDR_LEN]));
|
||||
return ((struct rpl_dio_t*)&(rpl_buffer[IPV6HDR_ICMPV6HDR_LEN]));
|
||||
}
|
||||
|
||||
static struct rpl_dao_t* get_rpl_dao_buf(){
|
||||
return ((struct rpl_dao_t*)&(buffer[LLHDR_ICMPV6HDR_LEN]));
|
||||
return ((struct rpl_dao_t*)&(rpl_buffer[IPV6HDR_ICMPV6HDR_LEN]));
|
||||
}
|
||||
/*static struct rpl_dao_ack_t* get_rpl_dao_ack_buf(){
|
||||
static struct rpl_dao_ack_t* get_rpl_dao_ack_buf(){
|
||||
return ((struct rpl_dao_ack_t*)&(buffer[LLHDR_ICMPV6HDR_LEN]));
|
||||
}*/
|
||||
}
|
||||
static struct rpl_dis_t* get_rpl_dis_buf(){
|
||||
return ((struct rpl_dis_t*)&(buffer[LLHDR_ICMPV6HDR_LEN]));
|
||||
return ((struct rpl_dis_t*)&(rpl_buffer[IPV6HDR_ICMPV6HDR_LEN]));
|
||||
}
|
||||
static struct rpl_opt_t* get_rpl_opt_buf(uint8_t rpl_msg_len){
|
||||
return ((struct rpl_opt_t*)&(buffer[LLHDR_ICMPV6HDR_LEN + rpl_msg_len]));
|
||||
return ((struct rpl_opt_t*)&(rpl_buffer[IPV6HDR_ICMPV6HDR_LEN + rpl_msg_len]));
|
||||
}
|
||||
|
||||
static struct rpl_opt_dodag_conf_t* get_rpl_opt_dodag_conf_buf(uint8_t rpl_msg_len){
|
||||
return ((struct rpl_opt_dodag_conf_t*)&(buffer[LLHDR_ICMPV6HDR_LEN + rpl_msg_len]));
|
||||
return ((struct rpl_opt_dodag_conf_t*)&(rpl_buffer[IPV6HDR_ICMPV6HDR_LEN + rpl_msg_len]));
|
||||
}
|
||||
|
||||
static struct rpl_opt_solicited_t* get_rpl_opt_solicited_buf(uint8_t rpl_msg_len){
|
||||
return ((struct rpl_opt_solicited_t*)&(buffer[LLHDR_ICMPV6HDR_LEN + rpl_msg_len]));
|
||||
return ((struct rpl_opt_solicited_t*)&(rpl_buffer[IPV6HDR_ICMPV6HDR_LEN + rpl_msg_len]));
|
||||
}
|
||||
|
||||
static struct rpl_opt_target_t* get_rpl_opt_target_buf(uint8_t rpl_msg_len){
|
||||
return ((struct rpl_opt_target_t*)&(buffer[LLHDR_ICMPV6HDR_LEN + rpl_msg_len]));
|
||||
return ((struct rpl_opt_target_t*)&(rpl_buffer[IPV6HDR_ICMPV6HDR_LEN + rpl_msg_len]));
|
||||
}
|
||||
|
||||
static struct rpl_opt_transit_t* get_rpl_opt_transit_buf(uint8_t rpl_msg_len){
|
||||
return ((struct rpl_opt_transit_t*)&(buffer[LLHDR_ICMPV6HDR_LEN + rpl_msg_len]));
|
||||
return ((struct rpl_opt_transit_t*)&(rpl_buffer[IPV6HDR_ICMPV6HDR_LEN + rpl_msg_len]));
|
||||
}
|
||||
|
||||
//Diese Funktion findet eine implementierte OF anhand des Objective Code Point
|
||||
@ -79,15 +141,12 @@ rpl_of_t *rpl_get_of_for_ocp(uint16_t ocp){
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uint8_t rpl_init(transceiver_type_t trans, ipv6_addr_t *rpl_address){
|
||||
if(rpl_address == NULL){
|
||||
uint8_t rpl_init(transceiver_type_t trans, uint16_t rpl_address){
|
||||
mutex_init(&rpl_send_mutex);
|
||||
mutex_init(&rpl_recv_mutex);
|
||||
if(rpl_address == 0){
|
||||
return SIXLOWERROR_ADDRESS;
|
||||
}
|
||||
//radio-address is 8-bit
|
||||
if(rpl_address->uint8[14] != 0){
|
||||
return SIXLOWERROR_ADDRESS;
|
||||
}
|
||||
my_address = *rpl_address;
|
||||
//initialize routing table
|
||||
rpl_clear_routing_table();
|
||||
init_trickle();
|
||||
@ -99,8 +158,32 @@ uint8_t rpl_init(transceiver_type_t trans, ipv6_addr_t *rpl_address){
|
||||
objective_functions[0] = rpl_get_of0();
|
||||
//objective_functions[1] = rpl_get_of_ETX()
|
||||
|
||||
sixlowpan_init(trans,rpl_address->uint8[15],0);
|
||||
sixlowpan_init(trans,rpl_address,0);
|
||||
//Wir benötigen einen Link Local prefix, um unsere entsprechende Addresse im Netz abzufragen
|
||||
ipv6_addr_t ll_address;
|
||||
ipv6_set_ll_prefix(&ll_address);
|
||||
ipv6_get_saddr(&my_address, &ll_address);
|
||||
set_rpl_process_pid(rpl_process_pid);
|
||||
|
||||
//some fake routing entries...
|
||||
/*if(rpl_address != 1){
|
||||
ll_address.uint8[15]=1;
|
||||
rpl_add_routing_entry(&ll_address, &ll_address, 9000);
|
||||
ll_address.uint8[15]=2;
|
||||
rpl_add_routing_entry(&ll_address, &ll_address, 8000);
|
||||
ll_address.uint8[15]=3;
|
||||
rpl_add_routing_entry(&ll_address, &ll_address, 7000);
|
||||
ll_address.uint8[15]=4;
|
||||
rpl_add_routing_entry(&ll_address, &ll_address, 6000);
|
||||
ll_address.uint8[15]=5;
|
||||
rpl_add_routing_entry(&ll_address, &ll_address, 5000);
|
||||
ll_address.uint8[15]=6;
|
||||
rpl_add_routing_entry(&ll_address, &ll_address, 4000);
|
||||
ll_address.uint8[15]=7;
|
||||
rpl_add_routing_entry(&ll_address, &ll_address, 4000);
|
||||
ll_address.uint8[15]=8;
|
||||
rpl_add_routing_entry(&ll_address, &ll_address, 4000);
|
||||
} */
|
||||
return SUCCESS;
|
||||
|
||||
}
|
||||
@ -116,7 +199,7 @@ void rpl_init_root(){
|
||||
}
|
||||
inst->id = RPL_DEFAULT_INSTANCE;
|
||||
inst->joined = 1;
|
||||
|
||||
|
||||
dodag = rpl_new_dodag(RPL_DEFAULT_INSTANCE, &my_address);
|
||||
if(dodag != NULL) {
|
||||
dodag->of = rpl_get_of_for_ocp(RPL_DEFAULT_OCP);
|
||||
@ -129,7 +212,7 @@ void rpl_init_root(){
|
||||
dodag->dio_redundancy = DEFAULT_DIO_REDUNDANCY_CONSTANT;
|
||||
dodag->maxrankincrease = 0;
|
||||
dodag->minhoprankincrease = (uint16_t)DEFAULT_MIN_HOP_RANK_INCREASE;
|
||||
dodag->default_lifetime = (uint16_t)RPL_DEFAULT_LIFETIME;
|
||||
dodag->default_lifetime = (uint8_t)RPL_DEFAULT_LIFETIME;
|
||||
dodag->lifetime_unit = RPL_LIFETIME_UNIT;
|
||||
dodag->version = RPL_COUNTER_INIT;
|
||||
dodag->grounded = RPL_GROUNDED;
|
||||
@ -143,144 +226,197 @@ void rpl_init_root(){
|
||||
}
|
||||
i_am_root = 1;
|
||||
start_trickle(dodag->dio_min, dodag->dio_interval_doubling, dodag->dio_redundancy);
|
||||
puts("ROOT INIT FINISHED");
|
||||
|
||||
}
|
||||
|
||||
|
||||
void send_DIO(ipv6_addr_t* destination){
|
||||
//puts("\nSEND DIO");
|
||||
mutex_lock(&rpl_send_mutex);
|
||||
rpl_dodag_t * mydodag;
|
||||
icmp_buf = get_icmpv6_buf(ipv6_ext_hdr_len);
|
||||
icmp_send_buf = get_rpl_send_icmpv6_buf(ipv6_ext_hdr_len);
|
||||
|
||||
mydodag = rpl_get_my_dodag();
|
||||
if(mydodag == NULL){
|
||||
printf("Error, trying to send DIO without being part of a dodag. This should not happen\n");
|
||||
mutex_unlock(&rpl_send_mutex, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
icmp_buf->type = ICMP_RPL_CONTROL;
|
||||
icmp_buf->code = ICMP_CODE_DIO;
|
||||
icmp_buf->checksum = ~icmpv6_csum(PROTO_NUM_ICMPV6);
|
||||
icmp_send_buf->type = ICMP_RPL_CONTROL;
|
||||
icmp_send_buf->code = ICMP_CODE_DIO;
|
||||
icmp_send_buf->checksum = ~icmpv6_csum(PROTO_NUM_ICMPV6);
|
||||
|
||||
rpl_dio_buf = get_rpl_dio_buf();
|
||||
memset(rpl_dio_buf, 0, sizeof(*rpl_dio_buf));
|
||||
rpl_dio_buf->rpl_instanceid = mydodag->instance->id;
|
||||
rpl_dio_buf->version_number = mydodag->version;
|
||||
rpl_dio_buf->rank = mydodag->my_rank;
|
||||
rpl_dio_buf->g_mop_prf = (mydodag->grounded << RPL_GROUNDED_SHIFT) | (mydodag->mop << RPL_MOP_SHIFT) | mydodag->prf;
|
||||
rpl_dio_buf->dtsn = mydodag->dtsn;
|
||||
rpl_dio_buf->flags = 0;
|
||||
rpl_dio_buf->reserved = 0;
|
||||
rpl_dio_buf->dodagid = mydodag->dodag_id;
|
||||
rpl_send_dio_buf = get_rpl_send_dio_buf();
|
||||
memset(rpl_send_dio_buf, 0, sizeof(*rpl_send_dio_buf));
|
||||
rpl_send_dio_buf->rpl_instanceid = mydodag->instance->id;
|
||||
rpl_send_dio_buf->version_number = mydodag->version;
|
||||
rpl_send_dio_buf->rank = mydodag->my_rank;
|
||||
rpl_send_dio_buf->g_mop_prf = (mydodag->grounded << RPL_GROUNDED_SHIFT) | (mydodag->mop << RPL_MOP_SHIFT) | mydodag->prf;
|
||||
rpl_send_dio_buf->dtsn = mydodag->dtsn;
|
||||
rpl_send_dio_buf->flags = 0;
|
||||
rpl_send_dio_buf->reserved = 0;
|
||||
rpl_send_dio_buf->dodagid = mydodag->dodag_id;
|
||||
//printf("Send DIO with DODAGID: \n");
|
||||
//ipv6_print_addr(&rpl_dio_buf->dodagid);
|
||||
|
||||
int opt_hdr_len = 0;
|
||||
//DODAG Configuration Option!
|
||||
rpl_opt_dodag_conf_buf = get_rpl_opt_dodag_conf_buf(DIO_BASE_LEN);
|
||||
rpl_opt_dodag_conf_buf->type = RPL_OPT_DODAG_CONF;
|
||||
rpl_opt_dodag_conf_buf->length = RPL_OPT_DODAG_CONF_LEN;
|
||||
rpl_opt_dodag_conf_buf->flags_a_pcs = 0;
|
||||
rpl_opt_dodag_conf_buf->DIOIntDoubl = mydodag->dio_interval_doubling;
|
||||
rpl_opt_dodag_conf_buf->DIOIntMin = mydodag->dio_min;
|
||||
rpl_opt_dodag_conf_buf->DIORedun = mydodag->dio_redundancy;
|
||||
rpl_opt_dodag_conf_buf->MaxRankIncrease = mydodag->maxrankincrease;
|
||||
rpl_opt_dodag_conf_buf->MinHopRankIncrease = mydodag->minhoprankincrease;
|
||||
rpl_opt_dodag_conf_buf->ocp = mydodag->of->ocp;
|
||||
rpl_opt_dodag_conf_buf->reserved = 0;
|
||||
rpl_opt_dodag_conf_buf->default_lifetime = mydodag->default_lifetime;
|
||||
rpl_opt_dodag_conf_buf->lifetime_unit = mydodag->lifetime_unit;
|
||||
rpl_send_opt_dodag_conf_buf = get_rpl_send_opt_dodag_conf_buf(DIO_BASE_LEN);
|
||||
rpl_send_opt_dodag_conf_buf->type = RPL_OPT_DODAG_CONF;
|
||||
rpl_send_opt_dodag_conf_buf->length = RPL_OPT_DODAG_CONF_LEN;
|
||||
rpl_send_opt_dodag_conf_buf->flags_a_pcs = 0;
|
||||
rpl_send_opt_dodag_conf_buf->DIOIntDoubl = mydodag->dio_interval_doubling;
|
||||
rpl_send_opt_dodag_conf_buf->DIOIntMin = mydodag->dio_min;
|
||||
rpl_send_opt_dodag_conf_buf->DIORedun = mydodag->dio_redundancy;
|
||||
rpl_send_opt_dodag_conf_buf->MaxRankIncrease = mydodag->maxrankincrease;
|
||||
rpl_send_opt_dodag_conf_buf->MinHopRankIncrease = mydodag->minhoprankincrease;
|
||||
rpl_send_opt_dodag_conf_buf->ocp = mydodag->of->ocp;
|
||||
rpl_send_opt_dodag_conf_buf->reserved = 0;
|
||||
rpl_send_opt_dodag_conf_buf->default_lifetime = mydodag->default_lifetime;
|
||||
rpl_send_opt_dodag_conf_buf->lifetime_unit = mydodag->lifetime_unit;
|
||||
|
||||
|
||||
opt_hdr_len += RPL_OPT_LEN + RPL_OPT_DODAG_CONF_LEN;
|
||||
|
||||
|
||||
uint16_t plen = ICMPV6_HDR_LEN + DIO_BASE_LEN + opt_hdr_len;
|
||||
rpl_send(destination,(uint8_t*)icmp_buf, plen, PROTO_NUM_ICMPV6, NULL);
|
||||
rpl_send(destination,(uint8_t*)icmp_send_buf, plen, PROTO_NUM_ICMPV6, NULL);
|
||||
mutex_unlock(&rpl_send_mutex, 0);
|
||||
}
|
||||
|
||||
void send_DIS(ipv6_addr_t *destination){
|
||||
//puts("Send DIS");
|
||||
|
||||
icmp_buf = get_icmpv6_buf(ipv6_ext_hdr_len);
|
||||
mutex_lock(&rpl_send_mutex);
|
||||
icmp_send_buf = get_rpl_send_icmpv6_buf(ipv6_ext_hdr_len);
|
||||
|
||||
icmp_buf->type = ICMP_RPL_CONTROL;
|
||||
icmp_buf->code = ICMP_CODE_DIO;
|
||||
icmp_buf->checksum = ~icmpv6_csum(PROTO_NUM_ICMPV6);
|
||||
icmp_send_buf->type = ICMP_RPL_CONTROL;
|
||||
icmp_send_buf->code = ICMP_CODE_DIO;
|
||||
icmp_send_buf->checksum = ~icmpv6_csum(PROTO_NUM_ICMPV6);
|
||||
|
||||
rpl_dis_buf = get_rpl_dis_buf();
|
||||
rpl_send_dis_buf = get_rpl_send_dis_buf();
|
||||
|
||||
uint16_t plen = ICMPV6_HDR_LEN + DIS_BASE_LEN;
|
||||
rpl_send(destination,(uint8_t*)icmp_buf, plen, PROTO_NUM_ICMPV6, NULL);
|
||||
rpl_send(destination,(uint8_t*)icmp_send_buf, plen, PROTO_NUM_ICMPV6, NULL);
|
||||
mutex_unlock(&rpl_send_mutex, 0);
|
||||
}
|
||||
|
||||
|
||||
void send_DAO(ipv6_addr_t *destination, uint8_t lifetime){
|
||||
void send_DAO(ipv6_addr_t *destination, uint8_t lifetime, bool default_lifetime, uint8_t start_index){
|
||||
if(i_am_root){
|
||||
return;
|
||||
}
|
||||
mutex_lock(&rpl_send_mutex);
|
||||
rpl_dodag_t * my_dodag;
|
||||
my_dodag = rpl_get_my_dodag();
|
||||
|
||||
if(destination == NULL){
|
||||
destination = &my_dodag->my_preferred_parent->addr;
|
||||
}
|
||||
printf("Sending DAO to\n");
|
||||
ipv6_print_addr(destination);
|
||||
if(default_lifetime){
|
||||
lifetime=my_dodag->default_lifetime;
|
||||
}
|
||||
//puts("sending DAO");
|
||||
|
||||
icmp_buf = get_icmpv6_buf(ipv6_ext_hdr_len);
|
||||
icmp_send_buf = get_rpl_send_icmpv6_buf(ipv6_ext_hdr_len);
|
||||
|
||||
icmp_buf->type = ICMP_RPL_CONTROL;
|
||||
icmp_buf->code = ICMP_CODE_DAO;
|
||||
icmp_buf->checksum = ~icmpv6_csum(PROTO_NUM_ICMPV6);
|
||||
icmp_send_buf->type = ICMP_RPL_CONTROL;
|
||||
icmp_send_buf->code = ICMP_CODE_DAO;
|
||||
icmp_send_buf->checksum = ~icmpv6_csum(PROTO_NUM_ICMPV6);
|
||||
|
||||
if(my_dodag == NULL){
|
||||
mutex_unlock(&rpl_send_mutex, 0);
|
||||
return;
|
||||
}
|
||||
rpl_dao_buf = get_rpl_dao_buf();
|
||||
memset(rpl_dao_buf,0,sizeof(*rpl_dao_buf));
|
||||
rpl_dao_buf->rpl_instanceid = my_dodag->instance->id;
|
||||
rpl_dao_buf->k_d_flags = 0x00;
|
||||
rpl_dao_buf->dao_sequence = my_dodag->dao_seq;
|
||||
rpl_send_dao_buf = get_rpl_send_dao_buf();
|
||||
memset(rpl_send_dao_buf,0,sizeof(*rpl_send_dao_buf));
|
||||
rpl_send_dao_buf->rpl_instanceid = my_dodag->instance->id;
|
||||
rpl_send_dao_buf->k_d_flags = 0x00;
|
||||
rpl_send_dao_buf->dao_sequence = my_dodag->dao_seq;
|
||||
uint16_t opt_len = 0;
|
||||
rpl_opt_target_buf = get_rpl_opt_target_buf(DAO_BASE_LEN);
|
||||
rpl_send_opt_target_buf = get_rpl_send_opt_target_buf(DAO_BASE_LEN);
|
||||
//Alle Ziele aus der Routing Tabelle als Target eintragen
|
||||
for(uint8_t i=0; i<RPL_MAX_ROUTING_ENTRIES;i++){
|
||||
uint8_t entries = 0;
|
||||
uint8_t continue_index = 0;
|
||||
for(uint8_t i=start_index; i<RPL_MAX_ROUTING_ENTRIES;i++){
|
||||
if(routing_table[i].used){
|
||||
rpl_opt_target_buf->type=RPL_OPT_TARGET;
|
||||
rpl_opt_target_buf->length=RPL_OPT_TARGET_LEN;
|
||||
rpl_opt_target_buf->flags=0x00;
|
||||
rpl_opt_target_buf->prefix_length= RPL_DODAG_ID_LEN;
|
||||
memcpy(&rpl_opt_target_buf->target,&routing_table[i].address,sizeof(ipv6_addr_t));
|
||||
rpl_send_opt_target_buf->type=RPL_OPT_TARGET;
|
||||
rpl_send_opt_target_buf->length=RPL_OPT_TARGET_LEN;
|
||||
rpl_send_opt_target_buf->flags=0x00;
|
||||
rpl_send_opt_target_buf->prefix_length= RPL_DODAG_ID_LEN;
|
||||
memcpy(&rpl_send_opt_target_buf->target,&routing_table[i].address,sizeof(ipv6_addr_t));
|
||||
opt_len += RPL_OPT_TARGET_LEN +2;
|
||||
rpl_opt_transit_buf = get_rpl_opt_transit_buf(DAO_BASE_LEN + opt_len);
|
||||
rpl_opt_transit_buf->type=RPL_OPT_TRANSIT;
|
||||
rpl_opt_transit_buf->length=RPL_OPT_TRANSIT_LEN;
|
||||
rpl_opt_transit_buf->e_flags=0x00;
|
||||
rpl_opt_transit_buf->path_control=0x00;//not used
|
||||
rpl_opt_transit_buf->path_sequence=0x00;//not used
|
||||
rpl_opt_transit_buf->path_lifetime=lifetime;
|
||||
rpl_send_opt_transit_buf = get_rpl_send_opt_transit_buf(DAO_BASE_LEN + opt_len);
|
||||
rpl_send_opt_transit_buf->type=RPL_OPT_TRANSIT;
|
||||
rpl_send_opt_transit_buf->length=RPL_OPT_TRANSIT_LEN;
|
||||
rpl_send_opt_transit_buf->e_flags=0x00;
|
||||
rpl_send_opt_transit_buf->path_control=0x00;//not used
|
||||
rpl_send_opt_transit_buf->path_sequence=0x00;//not used
|
||||
rpl_send_opt_transit_buf->path_lifetime=lifetime;
|
||||
opt_len += RPL_OPT_TRANSIT_LEN +2;
|
||||
rpl_opt_target_buf = get_rpl_opt_target_buf(DAO_BASE_LEN + opt_len);
|
||||
rpl_send_opt_target_buf = get_rpl_send_opt_target_buf(DAO_BASE_LEN + opt_len);
|
||||
entries++;
|
||||
}
|
||||
if(entries >= 5){
|
||||
//split DAO, so packages dont get too big.
|
||||
//The value 5 is based on experience
|
||||
continue_index = i+1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
//Add own address
|
||||
rpl_opt_target_buf->type=RPL_OPT_TARGET;
|
||||
rpl_opt_target_buf->length=RPL_OPT_TARGET_LEN;
|
||||
rpl_opt_target_buf->flags=0x00;
|
||||
rpl_opt_target_buf->prefix_length= RPL_DODAG_ID_LEN;
|
||||
memcpy(&rpl_opt_target_buf->target,&my_address,sizeof(ipv6_addr_t));
|
||||
rpl_send_opt_target_buf->type=RPL_OPT_TARGET;
|
||||
rpl_send_opt_target_buf->length=RPL_OPT_TARGET_LEN;
|
||||
rpl_send_opt_target_buf->flags=0x00;
|
||||
rpl_send_opt_target_buf->prefix_length= RPL_DODAG_ID_LEN;
|
||||
memcpy(&rpl_send_opt_target_buf->target,&my_address,sizeof(ipv6_addr_t));
|
||||
opt_len += RPL_OPT_TARGET_LEN +2;
|
||||
|
||||
rpl_opt_transit_buf = get_rpl_opt_transit_buf(DAO_BASE_LEN + opt_len);
|
||||
rpl_opt_transit_buf->type=RPL_OPT_TRANSIT;
|
||||
rpl_opt_transit_buf->length=RPL_OPT_TRANSIT_LEN;
|
||||
rpl_opt_transit_buf->e_flags=0x00;
|
||||
rpl_opt_transit_buf->path_control=0x00;
|
||||
rpl_opt_transit_buf->path_sequence=0x00;
|
||||
rpl_opt_transit_buf->path_lifetime=lifetime;
|
||||
rpl_send_opt_transit_buf = get_rpl_send_opt_transit_buf(DAO_BASE_LEN + opt_len);
|
||||
rpl_send_opt_transit_buf->type=RPL_OPT_TRANSIT;
|
||||
rpl_send_opt_transit_buf->length=RPL_OPT_TRANSIT_LEN;
|
||||
rpl_send_opt_transit_buf->e_flags=0x00;
|
||||
rpl_send_opt_transit_buf->path_control=0x00;
|
||||
rpl_send_opt_transit_buf->path_sequence=0x00;
|
||||
rpl_send_opt_transit_buf->path_lifetime=lifetime;
|
||||
opt_len += RPL_OPT_TRANSIT_LEN +2;
|
||||
|
||||
uint16_t plen = ICMPV6_HDR_LEN + DAO_BASE_LEN + opt_len;
|
||||
rpl_send(destination,(uint8_t*)icmp_buf, plen, PROTO_NUM_ICMPV6, NULL);
|
||||
rpl_send(destination,(uint8_t*)icmp_send_buf, plen, PROTO_NUM_ICMPV6, NULL);
|
||||
mutex_unlock(&rpl_send_mutex, 0);
|
||||
if(continue_index > 1){
|
||||
send_DAO(destination, lifetime, default_lifetime, continue_index);
|
||||
}
|
||||
}
|
||||
|
||||
void send_DAO_ACK(ipv6_addr_t *destination){
|
||||
//puts("Send DAO_ACK to");
|
||||
ipv6_print_addr(destination);
|
||||
rpl_dodag_t * my_dodag;
|
||||
my_dodag = rpl_get_my_dodag();
|
||||
if(my_dodag == NULL){
|
||||
return;
|
||||
}
|
||||
mutex_lock(&rpl_send_mutex);
|
||||
icmp_send_buf = get_rpl_send_icmpv6_buf(ipv6_ext_hdr_len);
|
||||
|
||||
icmp_send_buf->type = ICMP_RPL_CONTROL;
|
||||
icmp_send_buf->code = ICMP_CODE_DAO_ACK;
|
||||
icmp_send_buf->checksum = ~icmpv6_csum(PROTO_NUM_ICMPV6);
|
||||
|
||||
rpl_send_dao_ack_buf = get_rpl_send_dao_ack_buf();
|
||||
rpl_send_dao_ack_buf->rpl_instanceid = my_dodag->instance->id;
|
||||
rpl_send_dao_ack_buf->d_reserved = 0;
|
||||
rpl_send_dao_ack_buf->dao_sequence = my_dodag->dao_seq;
|
||||
rpl_send_dao_ack_buf->status = 0;
|
||||
|
||||
uint16_t plen = ICMPV6_HDR_LEN + DIS_BASE_LEN;
|
||||
rpl_send(destination,(uint8_t*)icmp_send_buf, plen, PROTO_NUM_ICMPV6, NULL);
|
||||
mutex_unlock(&rpl_send_mutex, 0);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void rpl_process(void){
|
||||
@ -293,23 +429,39 @@ void rpl_process(void){
|
||||
uint8_t *code;
|
||||
code = ((uint8_t*)m_recv.content.ptr);
|
||||
//pakettypen unterscheiden
|
||||
ipv6_buf = get_ipv6_buf();
|
||||
//mutex_lock(&rpl_recv_mutex);
|
||||
//mutex_lock(&rpl_send_mutex);
|
||||
memcpy(&rpl_buffer,ipv6_buf,ipv6_buf->length+IPV6_HDR_LEN);
|
||||
switch(*code) {
|
||||
case(ICMP_CODE_DIS):{
|
||||
recv_rpl_dis();
|
||||
mutex_unlock(&rpl_recv_mutex, 0);
|
||||
//mutex_unlock(&rpl_send_mutex, 0);
|
||||
break;
|
||||
}
|
||||
case(ICMP_CODE_DIO):{
|
||||
recv_rpl_dio();
|
||||
mutex_unlock(&rpl_recv_mutex, 0);
|
||||
//mutex_unlock(&rpl_send_mutex, 0);
|
||||
break;
|
||||
}
|
||||
case(ICMP_CODE_DAO):{
|
||||
recv_rpl_dao();
|
||||
mutex_unlock(&rpl_recv_mutex, 0);
|
||||
//mutex_unlock(&rpl_send_mutex, 0);
|
||||
break;
|
||||
}
|
||||
case(ICMP_CODE_DAO_ACK):{
|
||||
recv_rpl_dao_ack();
|
||||
mutex_unlock(&rpl_recv_mutex, 0);
|
||||
//mutex_unlock(&rpl_send_mutex, 0);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
mutex_unlock(&rpl_recv_mutex, 0);
|
||||
//mutex_unlock(&rpl_send_mutex, 0);
|
||||
puts("default unlock");
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -317,13 +469,14 @@ void rpl_process(void){
|
||||
|
||||
|
||||
void recv_rpl_dio(void){
|
||||
ipv6_buf = get_ipv6_buf();
|
||||
ipv6_buf = get_rpl_ipv6_buf();
|
||||
|
||||
rpl_dio_buf = get_rpl_dio_buf();
|
||||
int len = DIO_BASE_LEN;
|
||||
|
||||
rpl_instance_t * dio_inst = rpl_get_instance(rpl_dio_buf->rpl_instanceid);
|
||||
rpl_instance_t * my_inst = rpl_get_my_instance();
|
||||
|
||||
if(dio_inst == NULL){
|
||||
if(my_inst != NULL){
|
||||
//Dieser Knoten ist schon Teil eines DODAGS -> kein beitritt zu anderer Instanz moeglich
|
||||
@ -356,7 +509,12 @@ void recv_rpl_dio(void){
|
||||
uint8_t has_dodag_conf_opt = 0;
|
||||
//So lange das Paket größer ist, als die DIO Größe + Größe der bisher verarbeiteten Optionen,
|
||||
//sind noch weitere Optionen zu bearbeiten
|
||||
|
||||
//dabei müssen wir jedoch von der ipv6_buf->length die Größe des ICMP Headers abziehen
|
||||
//weil get_rpl_opt_buf die Paketlänge OHNE ipv6 und icmpv6 header übergeben werden muss
|
||||
//in ipv6_buf->length ist die IPV6_HDR_LEN nicht enthalten, also muss nur noch die ICMPV6_HDR_LEN
|
||||
//abgezogen werden
|
||||
|
||||
while(len < (ipv6_buf->length - ICMPV6_HDR_LEN) ){
|
||||
rpl_opt_buf = get_rpl_opt_buf(len);
|
||||
switch(rpl_opt_buf->type){
|
||||
@ -405,7 +563,7 @@ void recv_rpl_dio(void){
|
||||
}
|
||||
default:
|
||||
printf("[Error] Unsupported DIO option\n");
|
||||
break;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@ -413,6 +571,7 @@ void recv_rpl_dio(void){
|
||||
rpl_dodag_t *my_dodag = rpl_get_my_dodag();
|
||||
if(my_dodag == NULL){
|
||||
if(!has_dodag_conf_opt){
|
||||
puts("send DIS");
|
||||
send_DIS(&ipv6_buf->srcaddr);
|
||||
return;
|
||||
}
|
||||
@ -430,7 +589,8 @@ void recv_rpl_dio(void){
|
||||
return;
|
||||
}
|
||||
if(rpl_dio_buf->rank != INFINITE_RANK){
|
||||
printf("Will join DODAG\n");
|
||||
puts("Will join DODAG\n");
|
||||
ipv6_print_addr(&dio_dodag.dodag_id);
|
||||
rpl_join_dodag(&dio_dodag, &ipv6_buf->srcaddr, rpl_dio_buf->rank);
|
||||
}
|
||||
else{
|
||||
@ -508,7 +668,7 @@ void recv_rpl_dis(void){
|
||||
if(my_dodag == NULL){
|
||||
return;
|
||||
}
|
||||
ipv6_buf = get_ipv6_buf();
|
||||
ipv6_buf = get_rpl_ipv6_buf();
|
||||
rpl_dis_buf = get_rpl_dis_buf();
|
||||
int len = DIS_BASE_LEN;
|
||||
while(len < (ipv6_buf->length - ICMPV6_HDR_LEN) ){
|
||||
@ -548,7 +708,7 @@ void recv_rpl_dis(void){
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
return;
|
||||
}
|
||||
}
|
||||
send_DIO(&ipv6_buf->srcaddr);
|
||||
@ -556,13 +716,12 @@ void recv_rpl_dis(void){
|
||||
}
|
||||
|
||||
void recv_rpl_dao(void){
|
||||
printf("Receiving DAO\n");
|
||||
rpl_dodag_t *my_dodag = rpl_get_my_dodag();
|
||||
if(my_dodag == NULL){
|
||||
printf("[Error] got DAO without beeing part of a Dodag\n");
|
||||
return;
|
||||
}
|
||||
ipv6_buf = get_ipv6_buf();
|
||||
ipv6_buf = get_rpl_ipv6_buf();
|
||||
rpl_dao_buf = get_rpl_dao_buf();
|
||||
int len = DAO_BASE_LEN;
|
||||
uint8_t increment_seq = 0;
|
||||
@ -588,16 +747,17 @@ void recv_rpl_dao(void){
|
||||
printf("prefixes are not supported yet");
|
||||
break;
|
||||
}
|
||||
increment_seq = 1;
|
||||
len += rpl_opt_buf->length +2;
|
||||
len += rpl_opt_target_buf->length +2;
|
||||
rpl_opt_transit_buf = get_rpl_opt_transit_buf(len);
|
||||
if(rpl_opt_transit_buf->type != RPL_OPT_TRANSIT){
|
||||
printf("[Error] - no Transit Inforamtion to Target Option\n");
|
||||
printf("[Error] - no Transit Inforamtion to Target Option, type = %d\n", rpl_opt_transit_buf->type);
|
||||
break;
|
||||
}
|
||||
len += rpl_opt_transit_buf->length +2;
|
||||
//Die eigentliche Lebenszeit einer Route errechnet sich aus (Lifetime aus DAO) * (Lifetime Unit) Sekunden
|
||||
rpl_add_routing_entry(&rpl_opt_target_buf->target, &ipv6_buf->srcaddr, rpl_opt_transit_buf->path_lifetime * my_dodag->lifetime_unit);
|
||||
//puts("Updated route \n");
|
||||
increment_seq = 1;
|
||||
break;
|
||||
}
|
||||
case(RPL_OPT_TRANSIT):{
|
||||
@ -610,55 +770,64 @@ void recv_rpl_dao(void){
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
return;
|
||||
}
|
||||
}
|
||||
send_DAO_ACK(&ipv6_buf->srcaddr);
|
||||
if(increment_seq){
|
||||
RPL_COUNTER_INCREMENT(my_dodag->dao_seq);
|
||||
delay_dao();
|
||||
}
|
||||
}
|
||||
|
||||
void recv_rpl_dao_ack(void){
|
||||
rpl_dodag_t *my_dodag = rpl_get_my_dodag();
|
||||
if(my_dodag == NULL){
|
||||
return;
|
||||
}
|
||||
rpl_dao_ack_buf = get_rpl_dao_ack_buf();
|
||||
if(rpl_dao_ack_buf->rpl_instanceid != my_dodag->instance->id){
|
||||
return;
|
||||
}
|
||||
if(rpl_dao_ack_buf->status != 0){
|
||||
return;
|
||||
}
|
||||
//puts("Received DAO ACK");
|
||||
dao_ack_received();
|
||||
|
||||
}
|
||||
|
||||
void rpl_send(ipv6_addr_t *destination, uint8_t *payload, uint16_t p_len, uint8_t next_header, void *tcp_socket){
|
||||
uint8_t *p_ptr;
|
||||
/*if (next_header == IPPROTO_TCP)
|
||||
{
|
||||
p_ptr = get_payload_buf_send(ipv6_ext_hdr_len);
|
||||
ipv6_buf = get_ipv6_buf_send();
|
||||
}
|
||||
else
|
||||
{*/
|
||||
ipv6_buf = get_ipv6_buf();
|
||||
p_ptr = get_payload_buf(ipv6_ext_hdr_len);
|
||||
//}
|
||||
icmp_buf = get_icmpv6_buf(ipv6_ext_hdr_len);
|
||||
ipv6_send_buf = get_rpl_send_ipv6_buf();
|
||||
p_ptr = get_rpl_send_payload_buf(ipv6_ext_hdr_len);
|
||||
packet_length = 0;
|
||||
|
||||
ipv6_buf->version_trafficclass = IPV6_VER;
|
||||
ipv6_buf->trafficclass_flowlabel = 0;
|
||||
ipv6_buf->flowlabel = 0;
|
||||
ipv6_buf->nextheader = next_header;
|
||||
ipv6_buf->hoplimit = MULTIHOP_HOPLIMIT;
|
||||
ipv6_buf->length = p_len;
|
||||
ipv6_send_buf->version_trafficclass = IPV6_VER;
|
||||
ipv6_send_buf->trafficclass_flowlabel = 0;
|
||||
ipv6_send_buf->flowlabel = 0;
|
||||
ipv6_send_buf->nextheader = next_header;
|
||||
ipv6_send_buf->hoplimit = MULTIHOP_HOPLIMIT;
|
||||
ipv6_send_buf->length = p_len;
|
||||
|
||||
memcpy(&(ipv6_buf->destaddr), destination, 16);
|
||||
ipv6_get_saddr(&(ipv6_buf->srcaddr), &(ipv6_buf->destaddr));
|
||||
memcpy(&(ipv6_send_buf->destaddr), destination, 16);
|
||||
ipv6_get_saddr(&(ipv6_send_buf->srcaddr), &(ipv6_send_buf->destaddr));
|
||||
|
||||
memcpy(p_ptr,payload,p_len);
|
||||
//Wenn das Paket in der rpl.c "zusammegebaut" wurde, wurde dafür ohnehin der rpl_send_buf verwendet.
|
||||
//In diesem Fall muss also keine memcopy Aktion durchgeführt werden, da sich der payload bereits
|
||||
//im richtigen Speicherbereich befindet.
|
||||
if(p_ptr != payload){
|
||||
memcpy(p_ptr,payload,p_len);
|
||||
}
|
||||
|
||||
packet_length = IPV6_HDR_LEN + p_len;
|
||||
|
||||
#ifdef MODULE_DESTINY
|
||||
if (next_header == IPPROTO_TCP) {
|
||||
print_tcp_status(OUT_PACKET, ipv6_buf, (tcp_hdr_t *)(payload), (socket_t *)tcp_socket);
|
||||
}
|
||||
#endif
|
||||
if(ipv6_prefix_mcast_match(&ipv6_buf->destaddr)){
|
||||
lowpan_init((ieee_802154_long_t*)&(ipv6_buf->destaddr.uint16[4]),(uint8_t*)ipv6_buf);
|
||||
if(ipv6_prefix_mcast_match(&ipv6_send_buf->destaddr)){
|
||||
lowpan_init((ieee_802154_long_t*)&(ipv6_send_buf->destaddr.uint16[4]),(uint8_t*)ipv6_send_buf);
|
||||
}
|
||||
else{
|
||||
//find right next hop before sending
|
||||
ipv6_addr_t *next_hop = rpl_get_next_hop(&ipv6_buf->destaddr);
|
||||
ipv6_addr_t *next_hop = rpl_get_next_hop(&ipv6_send_buf->destaddr);
|
||||
if(next_hop == NULL){
|
||||
if(i_am_root){
|
||||
//oops... ich bin root und weiß nicht wohin mit dem paketn
|
||||
@ -668,13 +837,13 @@ void rpl_send(ipv6_addr_t *destination, uint8_t *payload, uint16_t p_len, uint8_
|
||||
else{
|
||||
next_hop = rpl_get_my_preferred_parent();
|
||||
if(next_hop == NULL){
|
||||
//kein preferred parent eingetragen, was nicht passieren sollte.
|
||||
printf("[Error] no preferred parent\n");
|
||||
//kein preferred parent eingetragen
|
||||
puts("[Error] no preferred parent, dropping package");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
lowpan_init((ieee_802154_long_t*)&(next_hop->uint16[4]),(uint8_t*)ipv6_buf);
|
||||
lowpan_init((ieee_802154_long_t*)&(next_hop->uint16[4]),(uint8_t*)ipv6_send_buf);
|
||||
}
|
||||
|
||||
}
|
||||
@ -688,11 +857,17 @@ ipv6_addr_t *rpl_get_next_hop(ipv6_addr_t * addr){
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void rpl_add_routing_entry(ipv6_addr_t *addr, ipv6_addr_t *next_hop, uint8_t lifetime){
|
||||
void rpl_add_routing_entry(ipv6_addr_t *addr, ipv6_addr_t *next_hop, uint16_t lifetime){
|
||||
rpl_routing_entry_t * entry = rpl_find_routing_entry(addr);
|
||||
if(entry != NULL){
|
||||
entry->lifetime = lifetime;
|
||||
return;
|
||||
}
|
||||
for(uint8_t i=0; i<RPL_MAX_ROUTING_ENTRIES; i++){
|
||||
if(!routing_table[i].used){
|
||||
routing_table[i].address = *addr;
|
||||
routing_table[i].next_hop = *next_hop;
|
||||
routing_table[i].lifetime = lifetime;
|
||||
routing_table[i].used = 1;
|
||||
break;
|
||||
}
|
||||
@ -708,9 +883,18 @@ void rpl_del_routing_entry(ipv6_addr_t *addr){
|
||||
}
|
||||
}
|
||||
|
||||
rpl_routing_entry_t *rpl_find_routing_entry(ipv6_addr_t *addr){
|
||||
for(uint8_t i=0; i<RPL_MAX_ROUTING_ENTRIES; i++){
|
||||
if(routing_table[i].used && rpl_equal_id(&routing_table[i].address, addr)){
|
||||
return &routing_table[i];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void rpl_clear_routing_table(){
|
||||
for(uint8_t i=0; i<RPL_MAX_ROUTING_ENTRIES; i++){
|
||||
routing_table[i].used = 0;
|
||||
memset(&routing_table[i], 0, sizeof(routing_table[i]));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,20 +8,23 @@
|
||||
#define RPL_PKT_RECV_BUF_SIZE 20
|
||||
#define RPL_PROCESS_STACKSIZE 4096
|
||||
|
||||
uint8_t rpl_init(transceiver_type_t trans, ipv6_addr_t *rpl_address);
|
||||
uint8_t rpl_init(transceiver_type_t trans, uint16_t rpl_address);
|
||||
void rpl_init_root();
|
||||
rpl_of_t *rpl_get_of_for_ocp(uint16_t ocp);
|
||||
|
||||
void send_DIO(ipv6_addr_t *destination);
|
||||
void send_DIS(ipv6_addr_t *destination);
|
||||
void send_DAO(ipv6_addr_t *destination, uint8_t lifetime);
|
||||
void send_DAO(ipv6_addr_t *destination, uint8_t lifetime, bool default_lifetime, uint8_t start_index);
|
||||
void send_DAO_ACK(ipv6_addr_t *destination);
|
||||
void rpl_process(void);
|
||||
void recv_rpl_dio(void);
|
||||
void recv_rpl_dis(void);
|
||||
void recv_rpl_dao(void);
|
||||
void recv_rpl_dao_ack(void);
|
||||
void rpl_send(ipv6_addr_t *destination, uint8_t *payload, uint16_t p_len, uint8_t next_header, void *tcp_socket);
|
||||
ipv6_addr_t *rpl_get_next_hop(ipv6_addr_t * addr);
|
||||
void rpl_add_routing_entry(ipv6_addr_t *addr, ipv6_addr_t *next_hop, uint8_t lifetime);
|
||||
void rpl_add_routing_entry(ipv6_addr_t *addr, ipv6_addr_t *next_hop, uint16_t lifetime);
|
||||
void rpl_del_routing_entry(ipv6_addr_t *addr);
|
||||
rpl_routing_entry_t * rpl_find_routing_entry(ipv6_addr_t *addr);
|
||||
void rpl_clear_routing_table();
|
||||
rpl_routing_entry_t *rpl_get_routing_table(void);
|
||||
|
@ -172,10 +172,12 @@ rpl_parent_t * rpl_find_preferred_parent(void){
|
||||
|
||||
for(uint8_t i=0;i<RPL_MAX_PARENTS;i++){
|
||||
if(parents[i].used){
|
||||
if(parents[i].rank == INFINITE_RANK){
|
||||
if((parents[i].rank == INFINITE_RANK) || (parents[i].lifetime <= 1)){
|
||||
puts("bad parent");
|
||||
continue;
|
||||
}
|
||||
else if(best == NULL){
|
||||
puts("parent");
|
||||
best = &parents[i];
|
||||
} else{
|
||||
best = my_dodag->of->which_parent(best, &parents[i]);
|
||||
@ -191,7 +193,7 @@ rpl_parent_t * rpl_find_preferred_parent(void){
|
||||
if(!rpl_equal_id(&my_dodag->my_preferred_parent->addr, &best->addr)){
|
||||
if(my_dodag->mop != NO_DOWNWARD_ROUTES){
|
||||
//send DAO with ZERO_LIFETIME to old parent
|
||||
send_DAO(&my_dodag->my_preferred_parent->addr, 0);
|
||||
send_DAO(&my_dodag->my_preferred_parent->addr, 0, false, 0);
|
||||
}
|
||||
my_dodag->my_preferred_parent = best;
|
||||
if(my_dodag->mop != NO_DOWNWARD_ROUTES){
|
||||
@ -207,6 +209,11 @@ void rpl_parent_update(rpl_parent_t * parent){
|
||||
rpl_dodag_t * my_dodag = rpl_get_my_dodag();
|
||||
uint16_t old_rank = my_dodag->my_rank;
|
||||
|
||||
//update Parent lifetime
|
||||
if(parent != NULL){
|
||||
parent->lifetime = my_dodag->default_lifetime * my_dodag->lifetime_unit;
|
||||
}
|
||||
|
||||
if(rpl_find_preferred_parent() == NULL){
|
||||
rpl_local_repair();
|
||||
}
|
||||
@ -256,6 +263,7 @@ void rpl_join_dodag(rpl_dodag_t *dodag, ipv6_addr_t *parent, uint16_t parent_ran
|
||||
}
|
||||
|
||||
void rpl_global_repair(rpl_dodag_t *dodag, ipv6_addr_t * p_addr, uint16_t rank){
|
||||
puts("[INFO] Global repair started");
|
||||
rpl_dodag_t * my_dodag = rpl_get_my_dodag();
|
||||
if(my_dodag == NULL){
|
||||
printf("[Error] - no global repair possible, if not part of a DODAG\n");
|
||||
@ -281,6 +289,7 @@ void rpl_global_repair(rpl_dodag_t *dodag, ipv6_addr_t * p_addr, uint16_t rank){
|
||||
}
|
||||
|
||||
void rpl_local_repair(void){
|
||||
puts("[INFO] Local Repair started");
|
||||
rpl_dodag_t * my_dodag = rpl_get_my_dodag();
|
||||
if(my_dodag == NULL){
|
||||
printf("[Error] - no local repair possible, if not part of a DODAG\n");
|
||||
|
@ -63,12 +63,19 @@
|
||||
#define INFINITE_RANK 0xFFFF
|
||||
#define RPL_DEFAULT_INSTANCE 0
|
||||
#define DEFAULT_PATH_CONTROL_SIZE 0
|
||||
#define DEFAULT_DIO_INTERVAL_MIN 3
|
||||
#define DEFAULT_DIO_INTERVAL_DOUBLINGS 20
|
||||
#define DEFAULT_DIO_INTERVAL_MIN 11
|
||||
//standard value:
|
||||
//#define DEFAULT_DIO_INTERVAL_MIN 3
|
||||
#define DEFAULT_DIO_INTERVAL_DOUBLINGS 7
|
||||
//standard value:
|
||||
//#define DEFAULT_DIO_INTERVAL_DOUBLINGS 20
|
||||
#define DEFAULT_DIO_REDUNDANCY_CONSTANT 10
|
||||
#define DEFAULT_MIN_HOP_RANK_INCREASE 256
|
||||
//DAO_DELAY is in seconds
|
||||
#define DEFAULT_DAO_DELAY 1
|
||||
#define DEFAULT_DAO_DELAY 3
|
||||
#define REGULAR_DAO_INTERVAL 300
|
||||
#define DAO_SEND_RETRIES 4
|
||||
#define DEFAULT_WAIT_FOR_DAO_ACK 15
|
||||
#define RPL_DODAG_ID_LEN 16
|
||||
|
||||
//others
|
||||
@ -77,10 +84,10 @@
|
||||
#define RPL_MAX_DODAGS 3
|
||||
#define RPL_MAX_INSTANCES 1
|
||||
#define RPL_MAX_PARENTS 5
|
||||
#define RPL_MAX_ROUTING_ENTRIES 20
|
||||
#define RPL_MAX_ROUTING_ENTRIES 128
|
||||
#define RPL_ROOT_RANK 1
|
||||
#define RPL_DEFAULT_LIFETIME 0xff
|
||||
#define RPL_LIFETIME_UNIT 0x0001
|
||||
#define RPL_LIFETIME_UNIT 2
|
||||
#define RPL_GROUNDED 1
|
||||
#define RPL_PRF_MASK 0x7
|
||||
#define RPL_MOP_SHIFT 3
|
||||
@ -179,6 +186,7 @@ typedef struct rpl_parent_t {
|
||||
uint16_t rank;
|
||||
uint8_t dtsn;
|
||||
struct rpl_dodag_t *dodag;
|
||||
uint16_t lifetime;
|
||||
uint8_t used;
|
||||
} rpl_parent_t;
|
||||
|
||||
@ -230,7 +238,7 @@ typedef struct rpl_routing_entry_t {
|
||||
uint8_t used;
|
||||
ipv6_addr_t address;
|
||||
ipv6_addr_t next_hop;
|
||||
uint8_t lifetime;
|
||||
uint16_t lifetime;
|
||||
|
||||
} rpl_routing_entry_t;
|
||||
|
||||
|
@ -14,6 +14,9 @@ int interval_over_pid;
|
||||
int dao_delay_over_pid;
|
||||
int rt_timer_over_pid;
|
||||
|
||||
bool ack_received;
|
||||
uint8_t dao_counter;
|
||||
|
||||
uint8_t k;
|
||||
uint32_t Imin;
|
||||
uint8_t Imax;
|
||||
@ -37,6 +40,8 @@ void reset_trickletimer(void){
|
||||
t = (I/2) + ( rand() % ( I - (I/2) + 1 ) );
|
||||
t_time = timex_set(0,t*1000);
|
||||
I_time = timex_set(0,I*1000);
|
||||
timex_normalize(&t_time);
|
||||
timex_normalize(&I_time);
|
||||
vtimer_remove(&trickle_t_timer);
|
||||
vtimer_remove(&trickle_I_timer);
|
||||
vtimer_set_wakeup(&trickle_t_timer, t_time, timer_over_pid);
|
||||
@ -46,32 +51,37 @@ void reset_trickletimer(void){
|
||||
|
||||
void init_trickle(void){
|
||||
//Create threads
|
||||
ack_received = true;
|
||||
timer_over_pid = thread_create(timer_over_buf, TRICKLE_TIMER_STACKSIZE,
|
||||
PRIORITY_MAIN-1,CREATE_SLEEPING,
|
||||
PRIORITY_MAIN-1,CREATE_STACKTEST,
|
||||
trickle_timer_over, "trickle_timer_over");
|
||||
|
||||
interval_over_pid = thread_create(interval_over_buf, TRICKLE_INTERVAL_STACKSIZE,
|
||||
PRIORITY_MAIN-1, CREATE_SLEEPING,
|
||||
PRIORITY_MAIN-1, CREATE_STACKTEST,
|
||||
trickle_interval_over, "trickle_interval_over");
|
||||
dao_delay_over_pid = thread_create(dao_delay_over_buf, DAO_DELAY_STACKSIZE,
|
||||
PRIORITY_MAIN-1, CREATE_SLEEPING,
|
||||
PRIORITY_MAIN-1, CREATE_STACKTEST,
|
||||
dao_delay_over, "dao_delay_over");
|
||||
rt_timer_over_pid = thread_create(routing_table_buf, RT_STACKSIZE,
|
||||
PRIORITY_MAIN-1, CREATE_SLEEPING,
|
||||
PRIORITY_MAIN-1, CREATE_STACKTEST,
|
||||
rt_timer_over, "rt_timer_over");
|
||||
|
||||
}
|
||||
|
||||
void start_trickle(uint8_t DIOIntMin, uint8_t DIOIntDoubl, uint8_t DIORedundancyConstant){
|
||||
c = 0;
|
||||
k = DIORedundancyConstant;
|
||||
Imin = pow(2, DIOIntMin);
|
||||
Imax = DIOIntDoubl;
|
||||
//Eigentlich laut Spezifikation erste Bestimmung von I wie auskommentiert:
|
||||
//I = Imin + ( rand() % ( (Imin << Imax) - Imin + 1 ) );
|
||||
I = Imin + ( rand() % ( (4*Imin) - Imin + 1 ) );
|
||||
I = Imin + ( rand() % (4*Imin) ) ;
|
||||
|
||||
t = (I/2) + ( rand() % ( I - (I/2) + 1 ) );
|
||||
t_time = timex_set(0,t*1000);
|
||||
timex_normalize(&t_time);
|
||||
I_time = timex_set(0,I*1000);
|
||||
timex_normalize(&I_time);
|
||||
vtimer_remove(&trickle_t_timer);
|
||||
vtimer_remove(&trickle_I_timer);
|
||||
vtimer_set_wakeup(&trickle_t_timer, t_time, timer_over_pid);
|
||||
@ -89,18 +99,26 @@ void trickle_timer_over(void)
|
||||
ipv6_addr_t mcast;
|
||||
ipv6_set_all_nds_mcast_addr(&mcast);
|
||||
while(1){
|
||||
thread_sleep();
|
||||
//Laut RPL Spezifikation soll k=0 wie k= Unendlich behandelt werden, also immer gesendet werden
|
||||
if( (c < k) || (k == 0)){
|
||||
send_DIO(&mcast);
|
||||
}
|
||||
thread_sleep();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void trickle_interval_over(void){
|
||||
while(1){
|
||||
thread_sleep();
|
||||
I = I*2;
|
||||
printf("TRICKLE new Interval %lu\n",I);
|
||||
if( I == 0 ){
|
||||
puts("[WARNING] Interval was 0");
|
||||
if( Imax == 0){
|
||||
puts("[WARNING] Imax == 0");
|
||||
}
|
||||
I = (Imin << Imax);
|
||||
}
|
||||
if(I > (Imin << Imax)){
|
||||
I=(Imin << Imax);
|
||||
}
|
||||
@ -108,45 +126,86 @@ void trickle_interval_over(void){
|
||||
t = (I/2) + ( rand() % ( I - (I/2) + 1 ) );
|
||||
//start timer
|
||||
t_time = timex_set(0,t*1000);
|
||||
timex_normalize(&t_time);
|
||||
I_time = timex_set(0,I*1000);
|
||||
vtimer_remove(&trickle_t_timer);
|
||||
vtimer_remove(&trickle_I_timer);
|
||||
vtimer_set_wakeup(&trickle_t_timer, t_time, timer_over_pid);
|
||||
vtimer_set_wakeup(&trickle_I_timer, I_time, interval_over_pid);
|
||||
thread_sleep();
|
||||
timex_normalize(&I_time);
|
||||
//vtimer_remove(&trickle_t_timer);
|
||||
//vtimer_remove(&trickle_I_timer);
|
||||
if(vtimer_set_wakeup(&trickle_t_timer, t_time, timer_over_pid) != 0){
|
||||
puts("[ERROR] setting Wakeup");
|
||||
}
|
||||
if(vtimer_set_wakeup(&trickle_I_timer, I_time, interval_over_pid) != 0){
|
||||
puts("[ERROR] setting Wakeup");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void delay_dao(void){
|
||||
dao_time = timex_set(DEFAULT_DAO_DELAY,0);
|
||||
dao_counter = 0;
|
||||
ack_received = false;
|
||||
vtimer_remove(&dao_timer);
|
||||
vtimer_set_wakeup(&dao_timer, dao_time, dao_delay_over_pid);
|
||||
}
|
||||
|
||||
//This function is used for regular update of the routes. The Timer can be overwritten, as the normal delay_dao function gets called
|
||||
void long_delay_dao(void){
|
||||
dao_time = timex_set(REGULAR_DAO_INTERVAL,0);
|
||||
dao_counter = 0;
|
||||
ack_received = false;
|
||||
vtimer_remove(&dao_timer);
|
||||
vtimer_set_wakeup(&dao_timer, dao_time, dao_delay_over_pid);
|
||||
}
|
||||
|
||||
void dao_delay_over(void){
|
||||
while(1){
|
||||
send_DAO(NULL, false);
|
||||
thread_sleep();
|
||||
if((ack_received == false) && (dao_counter < DAO_SEND_RETRIES)){
|
||||
dao_counter++;
|
||||
send_DAO(NULL, 0, true, 0);
|
||||
dao_time = timex_set(DEFAULT_WAIT_FOR_DAO_ACK,0);
|
||||
vtimer_set_wakeup(&dao_timer, dao_time, dao_delay_over_pid);
|
||||
}
|
||||
else if(ack_received == false){
|
||||
long_delay_dao();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void dao_ack_received(){
|
||||
ack_received = true;
|
||||
long_delay_dao();
|
||||
}
|
||||
|
||||
void rt_timer_over(void){
|
||||
rpl_routing_entry_t * rt;
|
||||
while(1){
|
||||
rpl_routing_entry_t * rt = rpl_get_routing_table();
|
||||
for(uint8_t i=0; i<RPL_MAX_ROUTING_ENTRIES;i++){
|
||||
if(rt[i].used){
|
||||
if(rt[i].lifetime <= 1){
|
||||
memset(&rt[i], 0,sizeof(rt[i]));
|
||||
rpl_dodag_t * my_dodag = rpl_get_my_dodag();
|
||||
if(my_dodag != NULL){
|
||||
rt = rpl_get_routing_table();
|
||||
for(uint8_t i=0; i<RPL_MAX_ROUTING_ENTRIES;i++){
|
||||
if(rt[i].used){
|
||||
if(rt[i].lifetime <= 1){
|
||||
memset(&rt[i], 0,sizeof(rt[i]));
|
||||
}
|
||||
else{
|
||||
rt[i].lifetime--;
|
||||
}
|
||||
}
|
||||
}
|
||||
//Parent is NULL for root too
|
||||
if(my_dodag->my_preferred_parent != NULL){
|
||||
if(my_dodag->my_preferred_parent->lifetime <= 1){
|
||||
puts("parent lifetime timeout");
|
||||
rpl_parent_update(NULL);
|
||||
}
|
||||
else{
|
||||
rt[i].lifetime--;
|
||||
my_dodag->my_preferred_parent->lifetime--;
|
||||
}
|
||||
}
|
||||
}
|
||||
//Wake up every second
|
||||
rt_time = timex_set(1,0);
|
||||
vtimer_set_wakeup(&rt_timer, rt_time, rt_timer_over_pid);
|
||||
thread_sleep();
|
||||
vtimer_usleep(1000000);
|
||||
}
|
||||
}
|
||||
|
@ -2,12 +2,12 @@
|
||||
#include <thread.h>
|
||||
|
||||
#define TRICKLE_TIMER_STACKSIZE 3072
|
||||
//#define TRICKLE_TIMER_STACKSIZE 4096
|
||||
#define TRICKLE_INTERVAL_STACKSIZE 3072
|
||||
//#define DAO_DELAY_STACKSIZE 2048
|
||||
//#define DAO_DELAY_STACKSIZE 3072
|
||||
#define DAO_DELAY_STACKSIZE 4096
|
||||
//#define RT_STACKSIZE 2048
|
||||
#define RT_STACKSIZE 3072
|
||||
#define DAO_DELAY_STACKSIZE 3072
|
||||
//#define DAO_DELAY_STACKSIZE 4096
|
||||
#define RT_STACKSIZE 512
|
||||
|
||||
void reset_trickletimer(void);
|
||||
void init_trickle(void);
|
||||
@ -17,4 +17,5 @@ void trickle_timer_over(void);
|
||||
void trickle_interval_over(void);
|
||||
void delay_dao(void);
|
||||
void dao_delay_over(void);
|
||||
void dao_ack_received(void);
|
||||
void rt_timer_over(void);
|
||||
|
@ -86,38 +86,38 @@ void sixlowpan_send(ipv6_addr_t *addr, uint8_t *payload, uint16_t p_len, uint8_t
|
||||
int icmpv6_demultiplex(const struct icmpv6_hdr_t *hdr) {
|
||||
switch(hdr->type) {
|
||||
case(ICMP_RTR_SOL):{
|
||||
printf("INFO: packet type: icmp router solicitation\n");
|
||||
puts("INFO: packet type: icmp router solicitation");
|
||||
/* processing router solicitation */
|
||||
recv_rtr_sol();
|
||||
/* init solicited router advertisment*/
|
||||
break;
|
||||
}
|
||||
case(ICMP_RTR_ADV):{
|
||||
printf("INFO: packet type: icmp router advertisment\n");
|
||||
puts("INFO: packet type: icmp router advertisment");
|
||||
/* processing router advertisment */
|
||||
recv_rtr_adv();
|
||||
/* init neighbor solicitation */
|
||||
break;
|
||||
}
|
||||
case(ICMP_NBR_SOL):{
|
||||
printf("INFO: packet type: icmp neighbor solicitation\n");
|
||||
puts("INFO: packet type: icmp neighbor solicitation");
|
||||
recv_nbr_sol();
|
||||
break;
|
||||
}
|
||||
case(ICMP_NBR_ADV):{
|
||||
printf("INFO: packet type: icmp neighbor advertisment\n");
|
||||
puts("INFO: packet type: icmp neighbor advertisment");
|
||||
recv_nbr_adv();
|
||||
break;
|
||||
}
|
||||
case(ICMP_RPL_CONTROL):{
|
||||
printf("INFO: packet type: RPL message\n");
|
||||
puts("INFO: packet type: RPL message");
|
||||
if(rpl_process_pid != 0){
|
||||
msg_t m_send;
|
||||
m_send.content.ptr = (char*) &hdr->code;
|
||||
msg_send(&m_send, rpl_process_pid, 1);
|
||||
}
|
||||
else{
|
||||
printf("INFO: no RPL handler registered\n");
|
||||
puts("INFO: no RPL handler registered");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ char radio_stack_buffer[RADIO_STACK_SIZE];
|
||||
msg_t msg_q[RADIO_RCV_BUF_SIZE];
|
||||
uint8_t snd_buffer[RADIO_SND_BUF_SIZE][PAYLOAD_SIZE];
|
||||
|
||||
uint8_t r_src_addr;
|
||||
static uint8_t r_src_addr;
|
||||
uint8_t buf[PAYLOAD_SIZE];
|
||||
uint16_t packet_length;
|
||||
static uint8_t macdsn;
|
||||
@ -151,6 +151,8 @@ void set_ieee802154_frame_values(ieee802154_frame_t *frame){
|
||||
void send_ieee802154_frame(ieee_802154_long_t *addr, uint8_t *payload,
|
||||
uint8_t length, uint8_t mcast){
|
||||
uint16_t daddr;
|
||||
/* TODO: check if dedicated response struct is necessary */
|
||||
msg_t transceiver_rsp;
|
||||
r_src_addr = local_address;
|
||||
mesg.type = SND_PKT;
|
||||
mesg.content.ptr = (char*) &tcmd;
|
||||
@ -188,7 +190,8 @@ void send_ieee802154_frame(ieee_802154_long_t *addr, uint8_t *payload,
|
||||
}
|
||||
|
||||
p.data = buf;
|
||||
msg_send(&mesg, transceiver_pid, 1);
|
||||
msg_send_receive(&mesg, &transceiver_rsp, transceiver_pid);
|
||||
printf("%s, %u: %lu\n", __FILE__, __LINE__, transceiver_rsp.content.value);
|
||||
|
||||
hwtimer_wait(5000);
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ void lowpan_init(ieee_802154_long_t *addr, uint8_t *data){
|
||||
mcast = 1;
|
||||
}
|
||||
|
||||
lowpan_iphc_encoding(&laddr, ipv6_buf);
|
||||
lowpan_iphc_encoding(&laddr, ipv6_buf, data);
|
||||
data = &comp_buf[0];
|
||||
packet_length = comp_len;
|
||||
|
||||
@ -667,7 +667,7 @@ void lowpan_ipv6_set_dispatch(uint8_t *data){
|
||||
}
|
||||
|
||||
/* draft-ietf-6lowpan-hc-13#section-3.1 */
|
||||
void lowpan_iphc_encoding(ieee_802154_long_t *dest, ipv6_hdr_t *ipv6_buf_extra){
|
||||
void lowpan_iphc_encoding(ieee_802154_long_t *dest, ipv6_hdr_t *ipv6_buf_extra, uint8_t * ptr){
|
||||
ipv6_buf = ipv6_buf_extra;
|
||||
|
||||
uint16_t payload_length = ipv6_buf->length;
|
||||
@ -929,7 +929,7 @@ void lowpan_iphc_encoding(ieee_802154_long_t *dest, ipv6_hdr_t *ipv6_buf_extra){
|
||||
comp_buf[0] = lowpan_iphc[0];
|
||||
comp_buf[1] = lowpan_iphc[1];
|
||||
|
||||
uint8_t *ptr;
|
||||
/*uint8_t *ptr;
|
||||
if (ipv6_buf->nextheader == IPPROTO_TCP)
|
||||
{
|
||||
ptr = get_payload_buf_send(ipv6_ext_hdr_len);
|
||||
@ -938,8 +938,8 @@ void lowpan_iphc_encoding(ieee_802154_long_t *dest, ipv6_hdr_t *ipv6_buf_extra){
|
||||
{
|
||||
ptr = get_payload_buf(ipv6_ext_hdr_len);
|
||||
}
|
||||
|
||||
memcpy(&ipv6_hdr_fields[hdr_pos],ptr,ipv6_buf->length);
|
||||
*/
|
||||
memcpy(&ipv6_hdr_fields[hdr_pos],&ptr[IPV6_HDR_LEN],ipv6_buf->length);
|
||||
|
||||
comp_len = 2 + hdr_pos + payload_length;
|
||||
}
|
||||
|
@ -23,7 +23,7 @@
|
||||
#define LOWPAN_IPV6_DISPATCH 0x41
|
||||
#define LOWPAN_CONTEXT_MAX 16
|
||||
|
||||
#define LOWPAN_REAS_BUF_TIMEOUT 3 * 1000 * 1000 // TODO: Set back to 3 * 1000 * 1000
|
||||
#define LOWPAN_REAS_BUF_TIMEOUT 15 * 1000 * 1000 // TODO: Set back to 3 * 1000 * 1000
|
||||
|
||||
#include "transceiver.h"
|
||||
#include "sixlowip.h"
|
||||
@ -68,7 +68,7 @@ void sixlowpan_adhoc_init(transceiver_type_t trans, ipv6_addr_t *prefix, uint8_t
|
||||
void lowpan_init(ieee_802154_long_t *addr, uint8_t *data);
|
||||
void lowpan_read(uint8_t *data, uint8_t length, ieee_802154_long_t *s_laddr,
|
||||
ieee_802154_long_t *d_laddr);
|
||||
void lowpan_iphc_encoding(ieee_802154_long_t *dest, ipv6_hdr_t *ipv6_buf_extra);
|
||||
void lowpan_iphc_encoding(ieee_802154_long_t *dest, ipv6_hdr_t *ipv6_buf_extra, uint8_t * ptr);
|
||||
void lowpan_iphc_decoding(uint8_t *data, uint8_t length,
|
||||
ieee_802154_long_t *s_laddr,
|
||||
ieee_802154_long_t *d_laddr);
|
||||
|
@ -4,7 +4,85 @@
|
||||
#include <cc1100-interface.h>
|
||||
|
||||
#ifdef MODULE_CC110X
|
||||
#include <msg.h>
|
||||
#include <transceiver.h>
|
||||
|
||||
#ifdef MODULE_TRANSCEIVER
|
||||
#define TEXT_SIZE CC1100_MAX_DATA_LENGTH
|
||||
|
||||
char text_msg[TEXT_SIZE];
|
||||
msg_t mesg;
|
||||
transceiver_command_t tcmd;
|
||||
|
||||
void _cc1100_get_set_address_handler(char *addr) {
|
||||
int16_t a;
|
||||
|
||||
tcmd.transceivers = TRANSCEIVER_CC1100;
|
||||
tcmd.data = &a;
|
||||
mesg.content.ptr = (char*) &tcmd;
|
||||
a = atoi(addr+5);
|
||||
if (strlen(addr) > 5) {
|
||||
printf("[cc110x] Trying to set address %i\n", a);
|
||||
mesg.type = SET_ADDRESS;
|
||||
}
|
||||
else {
|
||||
mesg.type = GET_ADDRESS;
|
||||
}
|
||||
msg_send_receive(&mesg, &mesg, transceiver_pid);
|
||||
printf("[cc110x] Got address: %i\n", a);
|
||||
}
|
||||
|
||||
void _cc1100_get_set_channel_handler(char *chan) {
|
||||
int16_t c;
|
||||
|
||||
tcmd.transceivers = TRANSCEIVER_CC1100;
|
||||
tcmd.data = &c;
|
||||
mesg.content.ptr = (char*) &tcmd;
|
||||
c = atoi(chan+5);
|
||||
if (strlen(chan) > 5) {
|
||||
printf("[cc110x] Trying to set channel %i\n", c);
|
||||
mesg.type = SET_CHANNEL;
|
||||
}
|
||||
else {
|
||||
mesg.type = GET_CHANNEL;
|
||||
}
|
||||
msg_send_receive(&mesg, &mesg, transceiver_pid);
|
||||
printf("[cc110x] Got channel: %i\n", c);
|
||||
}
|
||||
|
||||
void _cc1100_send_handler(char *pkt) {
|
||||
radio_packet_t p;
|
||||
uint32_t response;
|
||||
uint16_t addr;
|
||||
char *tok;
|
||||
|
||||
tcmd.transceivers = TRANSCEIVER_CC1100;
|
||||
tcmd.data = &p;
|
||||
|
||||
tok = strtok(pkt+7, " ");
|
||||
if (tok) {
|
||||
addr = atoi(tok);
|
||||
tok = strtok(NULL, " ");
|
||||
if (tok) {
|
||||
memset(text_msg, 0, TEXT_SIZE);
|
||||
memcpy(text_msg, tok, strlen(tok));
|
||||
/* if (sscanf(pkt, "txtsnd %hu %s", &(addr), text_msg) == 2) {*/
|
||||
p.data = (uint8_t*) text_msg;
|
||||
p.length = strlen(text_msg) + 1;
|
||||
p.dst = addr;
|
||||
mesg.type = SND_PKT;
|
||||
mesg.content.ptr = (char*) &tcmd;
|
||||
printf("[cc110x] Sending packet of length %u to %hu: %s\n", p.length, p.dst, (char*) p.data);
|
||||
msg_send_receive(&mesg, &mesg, transceiver_pid);
|
||||
response = mesg.content.value;
|
||||
printf("[cc110x] Packet sent: %lu\n", response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
puts("Usage:\ttxtsnd <ADDR> <MSG>");
|
||||
}
|
||||
|
||||
#else
|
||||
void _cc110x_get_set_address_handler(char *addr) {
|
||||
int16_t a;
|
||||
|
||||
@ -41,3 +119,4 @@ void _cc110x_get_set_channel_handler(char *addr) {
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
@ -24,9 +24,15 @@ extern void _reset_current_handler(char* unused);
|
||||
#endif
|
||||
|
||||
#ifdef MODULE_CC110X
|
||||
#ifdef MODULE_TRANSCEIVER
|
||||
extern void _cc1100_get_set_address_handler(char *addr);
|
||||
extern void _cc1100_get_set_channel_handler(char *chan);
|
||||
extern void _cc1100_send_handler(char *pkt);
|
||||
#else
|
||||
extern void _cc110x_get_set_address_handler(char *addr);
|
||||
extern void _cc110x_get_set_channel_handler(char *addr);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef MODULE_TRANSCEIVER
|
||||
#ifdef MODULE_CC110X_NG
|
||||
@ -65,9 +71,15 @@ const shell_command_t _shell_command_list[] = {
|
||||
{"rstcur", "Resets coulomb counter.", _reset_current_handler},
|
||||
#endif
|
||||
#ifdef MODULE_CC110X
|
||||
#ifdef MODULE_TRANSCEIVER
|
||||
{"addr", "Gets or sets the address for the CC1100 transceiver", _cc1100_get_set_address_handler},
|
||||
{"chan", "Gets or sets the channel for the CC1100 transceiver", _cc1100_get_set_channel_handler},
|
||||
{"txtsnd", "Sends a text message to a given node via the CC1100 transceiver", _cc1100_send_handler},
|
||||
#else
|
||||
{"addr", "Gets or sets the address for the CC1100 transceiver", _cc110x_get_set_address_handler},
|
||||
{"chan", "Gets or sets the channel for the CC1100 transceiver", _cc110x_get_set_channel_handler},
|
||||
#endif
|
||||
#endif
|
||||
#ifdef MODULE_TRANSCEIVER
|
||||
#ifdef MODULE_CC110X_NG
|
||||
{"addr", "Gets or sets the address for the CC1100 transceiver", _cc110x_ng_get_set_address_handler},
|
||||
|
@ -9,6 +9,14 @@
|
||||
#include <radio/types.h>
|
||||
|
||||
/* supported transceivers */
|
||||
#ifdef MODULE_CC110X
|
||||
#include <cc1100-interface.h>
|
||||
#if (CC1100_MAX_DATA_LENGTH > PAYLOAD_SIZE)
|
||||
#undef PAYLOAD_SIZE
|
||||
#define PAYLOAD_SIZE (CC1100_MAX_DATA_LENGTH)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef MODULE_CC110X_NG
|
||||
#include <cc110x_ng.h>
|
||||
#if (CC1100_MAX_DATA_LENGTH > PAYLOAD_SIZE)
|
||||
@ -41,6 +49,14 @@ int transceiver_pid; ///< the transceiver thread's pid
|
||||
static volatile uint8_t rx_buffer_pos = 0;
|
||||
static volatile uint8_t transceiver_buffer_pos = 0;
|
||||
|
||||
#ifdef MODULE_CC110X
|
||||
void *cc1100_payload;
|
||||
int cc1100_payload_size;
|
||||
packet_info_t *cc1100_packet_info;
|
||||
uint8_t cc1100_pkt[CC1100_MAX_DATA_LENGTH];
|
||||
#endif
|
||||
|
||||
|
||||
/* transceiver stack */
|
||||
char transceiver_stack[TRANSCEIVER_STACK_SIZE];
|
||||
|
||||
@ -48,7 +64,12 @@ char transceiver_stack[TRANSCEIVER_STACK_SIZE];
|
||||
/* function prototypes */
|
||||
static void run(void);
|
||||
static void receive_packet(uint16_t type, uint8_t pos);
|
||||
#ifdef MODULE_CC110X_NG
|
||||
static void receive_cc110x_packet(radio_packet_t *trans_p);
|
||||
#elif MODULE_CC110X
|
||||
void cc1100_packet_monitor(void* payload, int payload_size, protocol_t protocol, packet_info_t* packet_info);
|
||||
void receive_cc1100_packet(radio_packet_t *trans_p);
|
||||
#endif
|
||||
static uint8_t send_packet(transceiver_type_t t, void *pkt);
|
||||
static int16_t get_channel(transceiver_type_t t);
|
||||
static int16_t set_channel(transceiver_type_t t, void *channel);
|
||||
@ -91,7 +112,12 @@ int transceiver_start(void) {
|
||||
}
|
||||
else if (transceivers & TRANSCEIVER_CC1100) {
|
||||
DEBUG("Transceiver started for CC1100\n");
|
||||
#ifdef MODULE_CC110X_NG
|
||||
cc110x_init(transceiver_pid);
|
||||
#else
|
||||
cc1100_init();
|
||||
cc1100_set_packet_monitor(cc1100_packet_monitor);
|
||||
#endif
|
||||
}
|
||||
return transceiver_pid;
|
||||
}
|
||||
@ -181,6 +207,15 @@ void run(void) {
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef MODULE_CC110X
|
||||
void cc1100_packet_monitor(void* payload, int payload_size, protocol_t protocol, packet_info_t* packet_info) {
|
||||
cc1100_payload = payload;
|
||||
cc1100_payload_size = payload_size - 3;
|
||||
cc1100_packet_info = packet_info;
|
||||
receive_packet(TRANSCEIVER_CC1100, 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*------------------------------------------------------------------------------------*/
|
||||
/*
|
||||
* @brief Processes a packet received by any transceiver device
|
||||
@ -226,7 +261,11 @@ static void receive_packet(uint16_t type, uint8_t pos) {
|
||||
m.type = PKT_PENDING;
|
||||
|
||||
if (type == RCV_PKT_CC1100) {
|
||||
#ifdef MODULE_CC110X_NG
|
||||
receive_cc110x_packet(trans_p);
|
||||
#else
|
||||
receive_cc1100_packet(trans_p);
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
puts("Invalid transceiver type");
|
||||
@ -249,6 +288,7 @@ static void receive_packet(uint16_t type, uint8_t pos) {
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef MODULE_CC110X_NG
|
||||
/*
|
||||
* @brief process packets from CC1100
|
||||
*
|
||||
@ -271,6 +311,23 @@ static void receive_cc110x_packet(radio_packet_t *trans_p) {
|
||||
DEBUG("Packet %p was from %hu to %hu, size: %u\n", trans_p, trans_p->src, trans_p->dst, trans_p->length);
|
||||
trans_p->data = (uint8_t*) &(data_buffer[transceiver_buffer_pos * CC1100_MAX_DATA_LENGTH]);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef MODULE_CC110X
|
||||
void receive_cc1100_packet(radio_packet_t *trans_p) {
|
||||
dINT();
|
||||
trans_p->src = cc1100_packet_info->source;
|
||||
trans_p->dst = cc1100_packet_info->destination;
|
||||
trans_p->rssi = cc1100_packet_info->rssi;
|
||||
trans_p->lqi = cc1100_packet_info->lqi;
|
||||
trans_p->length = cc1100_payload_size;
|
||||
memcpy((void*) &(data_buffer[transceiver_buffer_pos * PAYLOAD_SIZE]), cc1100_payload, CC1100_MAX_DATA_LENGTH);
|
||||
eINT();
|
||||
|
||||
trans_p->data = (uint8_t*) &(data_buffer[transceiver_buffer_pos * CC1100_MAX_DATA_LENGTH]);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------------*/
|
||||
/*
|
||||
@ -283,16 +340,31 @@ static void receive_cc110x_packet(radio_packet_t *trans_p) {
|
||||
*/
|
||||
static uint8_t send_packet(transceiver_type_t t, void *pkt) {
|
||||
uint8_t res = 0;
|
||||
int snd_ret;
|
||||
radio_packet_t p = *((radio_packet_t*) pkt);
|
||||
|
||||
#ifdef MODULE_CC110X_NG
|
||||
cc110x_packet_t cc110x_pkt;
|
||||
#endif
|
||||
|
||||
switch (t) {
|
||||
case TRANSCEIVER_CC1100:
|
||||
#ifdef MODULE_CC110X_NG
|
||||
cc110x_pkt.length = p.length + CC1100_HEADER_LENGTH;
|
||||
cc110x_pkt.address = p.dst;
|
||||
cc110x_pkt.flags = 0;
|
||||
memcpy(cc110x_pkt.data, p.data, p.length);
|
||||
res = cc110x_send(&cc110x_pkt);
|
||||
#else
|
||||
memcpy(cc1100_pkt, p.data, p.length);
|
||||
if ((snd_ret = cc1100_send_csmaca(p.dst, 4, 0, (char*) cc1100_pkt, p.length)) < 0) {
|
||||
//printf("snd_ret (%u) = %i\n", p.length, snd_ret);
|
||||
res = 0;
|
||||
}
|
||||
else {
|
||||
res = 1;
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
puts("Unknown transceiver");
|
||||
@ -314,7 +386,11 @@ static int16_t set_channel(transceiver_type_t t, void *channel) {
|
||||
uint8_t c = *((uint8_t*) channel);
|
||||
switch (t) {
|
||||
case TRANSCEIVER_CC1100:
|
||||
#ifdef MODULE_CC110X_NG
|
||||
return cc110x_set_channel(c);
|
||||
#else
|
||||
return cc1100_set_channel(c);
|
||||
#endif
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
@ -330,7 +406,11 @@ static int16_t set_channel(transceiver_type_t t, void *channel) {
|
||||
static int16_t get_channel(transceiver_type_t t) {
|
||||
switch (t) {
|
||||
case TRANSCEIVER_CC1100:
|
||||
#ifdef MODULE_CC110X_NG
|
||||
return cc110x_get_channel();
|
||||
#else
|
||||
return cc1100_get_channel();
|
||||
#endif
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
@ -346,7 +426,11 @@ static int16_t get_channel(transceiver_type_t t) {
|
||||
static int16_t get_address(transceiver_type_t t) {
|
||||
switch (t) {
|
||||
case TRANSCEIVER_CC1100:
|
||||
#ifdef MODULE_CC110X_NG
|
||||
return cc110x_get_address();
|
||||
#else
|
||||
return cc1100_get_address();
|
||||
#endif
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
@ -364,7 +448,11 @@ static int16_t set_address(transceiver_type_t t, void *address) {
|
||||
radio_address_t addr = *((radio_address_t*) address);
|
||||
switch (t) {
|
||||
case TRANSCEIVER_CC1100:
|
||||
#ifdef MODULE_CC110X_NG
|
||||
return cc110x_set_address(addr);
|
||||
#else
|
||||
return cc1100_set_address(addr);
|
||||
#endif
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
@ -379,7 +467,9 @@ static int16_t set_address(transceiver_type_t t, void *address) {
|
||||
static void set_monitor(transceiver_type_t t, void *mode) {
|
||||
switch (t) {
|
||||
case TRANSCEIVER_CC1100:
|
||||
#ifdef MODULE_CC110X_NG
|
||||
cc110x_set_monitor(*((uint8_t*) mode));
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -389,7 +479,9 @@ static void set_monitor(transceiver_type_t t, void *mode) {
|
||||
static void powerdown(transceiver_type_t t) {
|
||||
switch (t) {
|
||||
case TRANSCEIVER_CC1100:
|
||||
#ifdef MODULE_CC110X_NG
|
||||
cc110x_switch_to_pwd();
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -400,7 +492,9 @@ static void powerdown(transceiver_type_t t) {
|
||||
static void switch_to_rx(transceiver_type_t t) {
|
||||
switch (t) {
|
||||
case TRANSCEIVER_CC1100:
|
||||
#ifdef MODULE_CC110X_NG
|
||||
cc110x_switch_to_rx();
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -39,13 +39,13 @@ build_binutils() {
|
||||
fi
|
||||
if [[ $HOST_GCC_VER == 4.6* || $HOST_GCC_VER == 4.7* ]]
|
||||
then
|
||||
CFLAGS="-Wno-error=unused-but-set-variable"
|
||||
CFLAGS="-Wno-error=unused-but-set-variable -Wno-error=unused-but-set-parameter"
|
||||
else
|
||||
CFLAGS="-Wno-error=unused"
|
||||
fi
|
||||
rm -rf binutils-build && mkdir -p binutils-build && cd binutils-build &&
|
||||
../binutils-${BINUTILS_VER}/configure --target=arm-elf --prefix=${PREFIX} --enable-interwork --enable-multilib &&
|
||||
make ${MAKE_THREADS} all CFLAGS=${CFLAGS} &&
|
||||
make ${MAKE_THREADS} all CFLAGS="${CFLAGS}" &&
|
||||
make install &&
|
||||
cd ${GNUARM_BUILDDIR}
|
||||
}
|
||||
@ -109,7 +109,7 @@ build_gdb() {
|
||||
rm -rf gdb-build && mkdir -p gdb-build && cd gdb-build &&
|
||||
../gdb-${GDB_VER}/configure --target=arm-elf --prefix=${PREFIX} --enable-interwork --enable-multilib &&
|
||||
|
||||
make ${MAKE_THREADS} all CFLAGS=-D_FORTIFY_SOURCE=0 &&
|
||||
make ${MAKE_THREADS} all CFLAGS="-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0" &&
|
||||
make install &&
|
||||
|
||||
cd ${GNUARM_BUILDDIR}
|
||||
|
Loading…
Reference in New Issue
Block a user