1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

Merge pull request #2024 from OlegHahm/ccnl_802154

ccn-lite: fixes for working with IEEE 802.15.4 radios
This commit is contained in:
Oleg Hahm 2014-12-16 11:03:20 +01:00
commit e64ab2aed5
6 changed files with 82 additions and 25 deletions

View File

@ -73,7 +73,7 @@ static void riot_ccn_appserver(int argc, char **argv)
_appserver_pid = thread_create(
appserver_stack, sizeof(appserver_stack),
PRIORITY_MAIN - 1, CREATE_STACKTEST,
ccnl_riot_appserver_start, (void *) _relay_pid, "appserver");
ccnl_riot_appserver_start, (void *) &_relay_pid, "appserver");
DEBUG("ccn-lite appserver on thread_id %" PRIkernel_pid "...\n", _appserver_pid);
}
#endif

View File

@ -46,6 +46,10 @@
#include "ccnl-riot-compat.h"
#include "ccn_lite/test_data/text.txt.ccnb.h"
#if MODULE_AT86RF231 || MODULE_CC2420 || MODULE_MC1322X
#include "ieee802154_frame.h"
#endif
/** The size of the message queue between router daemon and transceiver AND clients */
#define RELAY_MSG_BUFFER_SIZE (64)
@ -87,7 +91,7 @@ ccnl_run_events(void)
return NULL;
}
// ----------------------------------------------------------------------
/* ---------------------------------------------------------------------- */
int ccnl_open_riotmsgdev(void)
{
@ -107,29 +111,33 @@ void ccnl_ll_TX(struct ccnl_relay_s *ccnl, struct ccnl_if_s *ifc,
ifc->sendfunc(buf->data, (uint16_t) buf->datalen, (uint16_t) dest->id);
}
// ----------------------------------------------------------------------
/* ---------------------------------------------------------------------- */
void ccnl_ageing(void *relay, void *aux)
{
ccnl_do_ageing(relay, aux);
ccnl_set_timer(TIMEOUT_TO_US(CCNL_CHECK_TIMEOUT_SEC, CCNL_CHECK_TIMEOUT_USEC), ccnl_ageing, relay, 0);
ccnl_set_timer(TIMEOUT_TO_US(CCNL_CHECK_TIMEOUT_SEC, CCNL_CHECK_TIMEOUT_USEC),
ccnl_ageing, relay, 0);
}
void ccnl_retransmit(void *relay, void *aux)
{
ccnl_do_retransmit(relay, aux);
ccnl_set_timer(TIMEOUT_TO_US(CCNL_CHECK_RETRANSMIT_SEC, CCNL_CHECK_RETRANSMIT_USEC), ccnl_retransmit, relay, 0);
ccnl_set_timer(TIMEOUT_TO_US(CCNL_CHECK_RETRANSMIT_SEC,
CCNL_CHECK_RETRANSMIT_USEC), ccnl_retransmit, relay, 0);
}
void ccnl_nonce_timeout(void *relay, void *aux)
{
ccnl_do_nonce_timeout(relay, aux);
ccnl_set_timer(TIMEOUT_TO_US(CCNL_NONCE_TIMEOUT_SEC, CCNL_NONCE_TIMEOUT_USEC), ccnl_nonce_timeout, relay, 0);
ccnl_set_timer(TIMEOUT_TO_US(CCNL_NONCE_TIMEOUT_SEC,
CCNL_NONCE_TIMEOUT_USEC), ccnl_nonce_timeout, relay, 0);
}
// ----------------------------------------------------------------------
/* ---------------------------------------------------------------------- */
void ccnl_relay_config(struct ccnl_relay_s *relay, int max_cache_entries, int fib_threshold_prefix, int fib_threshold_aggregate)
void ccnl_relay_config(struct ccnl_relay_s *relay, int max_cache_entries,
int fib_threshold_prefix, int fib_threshold_aggregate)
{
struct ccnl_if_s *i;
@ -194,9 +202,12 @@ void ccnl_relay_config(struct ccnl_relay_s *relay, int max_cache_entries, int fi
f->flags |= CCNL_FACE_FLAGS_STATIC;
i->broadcast_face = f;
ccnl_set_timer(TIMEOUT_TO_US(CCNL_CHECK_TIMEOUT_SEC, CCNL_CHECK_TIMEOUT_USEC), ccnl_ageing, relay, 0);
ccnl_set_timer(TIMEOUT_TO_US(CCNL_CHECK_RETRANSMIT_SEC, CCNL_CHECK_RETRANSMIT_USEC), ccnl_retransmit, relay, 0);
ccnl_set_timer(TIMEOUT_TO_US(CCNL_NONCE_TIMEOUT_SEC, CCNL_NONCE_TIMEOUT_USEC), ccnl_nonce_timeout, relay, 0);
ccnl_set_timer(TIMEOUT_TO_US(CCNL_CHECK_TIMEOUT_SEC, CCNL_CHECK_TIMEOUT_USEC),
ccnl_ageing, relay, 0);
ccnl_set_timer(TIMEOUT_TO_US(CCNL_CHECK_RETRANSMIT_SEC, CCNL_CHECK_RETRANSMIT_USEC),
ccnl_retransmit, relay, 0);
ccnl_set_timer(TIMEOUT_TO_US(CCNL_NONCE_TIMEOUT_SEC, CCNL_NONCE_TIMEOUT_USEC),
ccnl_nonce_timeout, relay, 0);
}
#if RIOT_CCNL_POPULATE
@ -213,7 +224,8 @@ void ccnl_populate_cache(struct ccnl_relay_s *ccnl, unsigned char *buf, int data
datalen -= 2;
pkt = ccnl_extract_prefix_nonce_ppkd(&data, &datalen, 0, 0,
0, 0, &prefix, &nonce, &ppkd, &content, &contlen);
0, 0, &prefix, &nonce, &ppkd,
&content, &contlen);
if (!pkt) {
DEBUGMSG(6, " parsing error\n");
@ -236,7 +248,7 @@ void ccnl_populate_cache(struct ccnl_relay_s *ccnl, unsigned char *buf, int data
c->flags |= CCNL_CONTENT_FLAGS_STATIC;
if (!ccnl_content_add2cache(ccnl, c)) {
// content store error
/* content store error */
free_content(c);
}
@ -284,7 +296,7 @@ void handle_populate_cache(struct ccnl_relay_s *ccnl)
#endif
// ----------------------------------------------------------------------
/* ---------------------------------------------------------------------- */
int ccnl_io_loop(struct ccnl_relay_s *ccnl)
{
@ -301,7 +313,11 @@ int ccnl_io_loop(struct ccnl_relay_s *ccnl)
}
msg_t in;
#if MODULE_AT86RF231 || MODULE_CC2420 || MODULE_MC1322X
ieee802154_packet_t *p;
#else
radio_packet_t *p;
#endif
riot_ccnl_msg_t *m;
while (!ccnl->halt_flag) {
@ -312,17 +328,42 @@ int ccnl_io_loop(struct ccnl_relay_s *ccnl)
switch (in.type) {
case PKT_PENDING:
/* msg from transceiver */
#if MODULE_AT86RF231 || MODULE_CC2420 || MODULE_MC1322X
p = (ieee802154_packet_t*) in.content.ptr;
DEBUGMSG(1, "\tLength:\t%u\n", p->length);
DEBUGMSG(1, "\tSrc:\t%u\n",
(p->frame.src_addr[0]) | (p->frame.src_addr[1] << 8));
DEBUGMSG(1, "\tDst:\t%u\n",
(p->frame.dest_addr[0]) | (p->frame.dest_addr[1] << 8));
#else
p = (radio_packet_t *) in.content.ptr;
DEBUGMSG(1, "\tLength:\t%u\n", p->length);
DEBUGMSG(1, "\tSrc:\t%u\n", p->src);
DEBUGMSG(1, "\tDst:\t%u\n", p->dst);
#endif
// p->src must be > 0
/* p->src must be > 0 */
#if MODULE_AT86RF231 || MODULE_CC2420 || MODULE_MC1322X
if ((!(p->frame.src_addr[0])) | (p->frame.src_addr[1] << 8)) {
p->frame.src_addr[0] = RIOT_BROADCAST >> 8;
p->frame.src_addr[1] = RIOT_BROADCAST && 0xFF;
}
#else
if (!p->src) {
p->src = RIOT_BROADCAST;
}
#endif
ccnl_core_RX(ccnl, RIOT_TRANS_IDX, (unsigned char *) p->data, (int) p->length, p->src);
#if MODULE_AT86RF231 || MODULE_CC2420 || MODULE_MC1322X
ccnl_core_RX(ccnl, RIOT_TRANS_IDX,
(unsigned char *) p->frame.payload,
(int) p->frame.payload_len,
*((uint16_t*) p->frame.src_addr));
#else
ccnl_core_RX(ccnl, RIOT_TRANS_IDX,
(unsigned char *) p->data,
(int) p->length, p->src);
#endif
p->processing--;
break;
@ -367,7 +408,8 @@ int ccnl_io_loop(struct ccnl_relay_s *ccnl)
DEBUGMSG(1, "max_cache_entries set to %d\n", ccnl->max_cache_entries);
break;
case (ENOBUFFER):
/* transceiver has not enough buffer to store incoming packets, one packet is dropped */
/* transceiver has not enough buffer to store incoming packets,
* one packet is dropped */
DEBUGMSG(1, "transceiver: one packet is dropped because buffers are full\n");
break;
default:
@ -396,13 +438,17 @@ void *ccnl_riot_relay_start(void *arg)
theRelay->riot_pid = sched_active_pid;
mutex_init(&theRelay->global_lock);
DEBUGMSG(1, "This is ccn-lite-relay, starting at %lu:%lu\n", theRelay->startup_time.tv_sec, theRelay->startup_time.tv_usec);
DEBUGMSG(1, "This is ccn-lite-relay, starting at %lu:%lu\n",
theRelay->startup_time.tv_sec, theRelay->startup_time.tv_usec);
DEBUGMSG(1, " compile time: %s %s\n", __DATE__, __TIME__);
DEBUGMSG(1, " max_cache_entries: %d\n", CCNL_DEFAULT_MAX_CACHE_ENTRIES);
DEBUGMSG(1, " threshold_prefix: %d\n", CCNL_DEFAULT_THRESHOLD_PREFIX);
DEBUGMSG(1, " threshold_aggregate: %d\n", CCNL_DEFAULT_THRESHOLD_AGGREGATE);
ccnl_relay_config(theRelay, CCNL_DEFAULT_MAX_CACHE_ENTRIES, CCNL_DEFAULT_THRESHOLD_PREFIX, CCNL_DEFAULT_THRESHOLD_AGGREGATE);
ccnl_relay_config(theRelay,
CCNL_DEFAULT_MAX_CACHE_ENTRIES,
CCNL_DEFAULT_THRESHOLD_PREFIX,
CCNL_DEFAULT_THRESHOLD_AGGREGATE);
theRelay->riot_helper_pid = riot_start_helper_thread();
@ -436,5 +482,3 @@ void *ccnl_riot_relay_helper_start(void *arg)
mutex_unlock(&theRelay->stop_lock);
return NULL;
}
// eof

View File

@ -53,11 +53,15 @@ int riot_send_transceiver(uint8_t *buf, uint16_t size, uint16_t to)
}
#if MODULE_AT86RF231 || MODULE_CC2420 || MODULE_MC1322X
memset(&p, 0, sizeof(ieee802154_packet_t));
p.frame.payload_len = size;
p.frame.fcf.frame_type = IEEE_802154_DATA_FRAME;
p.frame.fcf.dest_addr_m = IEEE_802154_SHORT_ADDR_M;
memset(p.frame.dest_addr, 0, sizeof(p.frame.dest_addr));
memcpy(&(p.frame.dest_addr[6]), &to, sizeof(uint16_t));
p.frame.fcf.src_addr_m = IEEE_802154_SHORT_ADDR_M;
p.frame.dest_addr[1] = (to & 0xff);
p.frame.dest_addr[0] = (to >> 8);
p.frame.payload = buf;
p.frame.dest_pan_id = IEEE_802154_DEFAULT_PAN_ID;
#else
p.length = size;
p.dst = (to == RIOT_BROADCAST) ? 0 : to;

View File

@ -68,7 +68,10 @@ extern "C" {
*/
# define CCNL_RIOT_CHUNK_SIZE (90)
#else
# define CCNL_RIOT_CHUNK_SIZE (PAYLOAD_SIZE - CCNL_HEADER_SIZE)
/* XXX: For (at least) IEEE 802.15.4 radios (PAYLOAD_SIZE - CCNL_HEADER_SIZE)
* is one byte too big for transmission. Therefore, we subtract one byte more.
*/
# define CCNL_RIOT_CHUNK_SIZE (PAYLOAD_SIZE - CCNL_HEADER_SIZE - 1)
#endif
/**

View File

@ -47,6 +47,12 @@ typedef enum __attribute__((packed)) {
#define IEEE_802154_SHORT_MCAST_ADDR (0xffff)
#define IEEE_802154_LONG_MCAST_ADDR {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \
0xff, 0xff}}
/**
* @brief The default PAN id to use if not specified otherwise by upper layers
*/
#define IEEE_802154_DEFAULT_PAN_ID (1)
/**
* @brief Transform 16-bit number from network order (big-endian) to
* little-endian byte order (as used by IEEE 802.15.4).

View File

@ -257,7 +257,7 @@ void _transceiver_send_handler(int argc, char **argv)
p.frame.dest_pan_id = atoi(argv[3]);
}
else {
p.frame.dest_pan_id = 1;
p.frame.dest_pan_id = IEEE_802154_DEFAULT_PAN_ID;
}
#else
p.data = (uint8_t *) text_msg;