Bugfix: forwarding functions now have access to its packet headers. Added last hop to the arguments to the reception function
This commit is contained in:
parent
33bcc24019
commit
3d6c1c966b
|
@ -33,7 +33,7 @@
|
||||||
*
|
*
|
||||||
* This file is part of the Contiki operating system.
|
* This file is part of the Contiki operating system.
|
||||||
*
|
*
|
||||||
* $Id: mh.c,v 1.7 2008/01/08 07:55:56 adamdunkels Exp $
|
* $Id: mh.c,v 1.8 2008/02/05 20:17:43 adamdunkels Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -48,6 +48,8 @@
|
||||||
#include "net/rime/mh.h"
|
#include "net/rime/mh.h"
|
||||||
#include "net/rime/route.h"
|
#include "net/rime/route.h"
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
struct data_hdr {
|
struct data_hdr {
|
||||||
rimeaddr_t dest;
|
rimeaddr_t dest;
|
||||||
rimeaddr_t originator;
|
rimeaddr_t originator;
|
||||||
|
@ -68,28 +70,33 @@ void
|
||||||
data_packet_received(struct uc_conn *uc, rimeaddr_t *from)
|
data_packet_received(struct uc_conn *uc, rimeaddr_t *from)
|
||||||
{
|
{
|
||||||
struct mh_conn *c = (struct mh_conn *)uc;
|
struct mh_conn *c = (struct mh_conn *)uc;
|
||||||
struct data_hdr *msg = rimebuf_dataptr();
|
struct data_hdr msg;
|
||||||
rimeaddr_t *nexthop;
|
rimeaddr_t *nexthop;
|
||||||
|
|
||||||
|
memcpy(&msg, rimebuf_dataptr(), sizeof(struct data_hdr));
|
||||||
|
|
||||||
PRINTF("data_packet_received from %d towards %d len %d\n", from->u16[0],
|
PRINTF("data_packet_received from %d towards %d len %d\n", from->u16[0],
|
||||||
msg->dest.u16[0],
|
msg->dest.u16[0],
|
||||||
rimebuf_datalen());
|
rimebuf_datalen());
|
||||||
|
|
||||||
if(rimeaddr_cmp(&msg->dest, &rimeaddr_node_addr)) {
|
if(rimeaddr_cmp(&msg.dest, &rimeaddr_node_addr)) {
|
||||||
PRINTF("for us!\n");
|
PRINTF("for us!\n");
|
||||||
rimebuf_hdrreduce(sizeof(struct data_hdr));
|
rimebuf_hdrreduce(sizeof(struct data_hdr));
|
||||||
if(c->cb->recv) {
|
if(c->cb->recv) {
|
||||||
c->cb->recv(c, &msg->originator, msg->hops);
|
c->cb->recv(c, &msg.originator, from, msg.hops);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
nexthop = NULL;
|
nexthop = NULL;
|
||||||
if(c->cb->forward) {
|
if(c->cb->forward) {
|
||||||
nexthop = c->cb->forward(c, &msg->originator,
|
rimebuf_hdrreduce(sizeof(struct data_hdr));
|
||||||
&msg->dest, from, msg->hops);
|
nexthop = c->cb->forward(c, &msg.originator,
|
||||||
|
&msg.dest, from, msg.hops);
|
||||||
|
rimebuf_hdralloc(sizeof(struct data_hdr));
|
||||||
|
msg.hops++;
|
||||||
|
memcpy(rimebuf_hdrptr(), &msg, sizeof(struct data_hdr));
|
||||||
}
|
}
|
||||||
if(nexthop) {
|
if(nexthop) {
|
||||||
PRINTF("forwarding to %d.%d\n", nexthop->u8[0], nexthop->u8[1]);
|
PRINTF("forwarding to %d.%d\n", nexthop->u8[0], nexthop->u8[1]);
|
||||||
msg->hops++;
|
|
||||||
uc_send(&c->c, nexthop);
|
uc_send(&c->c, nexthop);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -120,6 +127,7 @@ mh_send(struct mh_conn *c, rimeaddr_t *to)
|
||||||
if(c->cb->forward == NULL) {
|
if(c->cb->forward == NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
rimebuf_compact();
|
||||||
nexthop = c->cb->forward(c, &rimeaddr_node_addr, to, NULL, 0);
|
nexthop = c->cb->forward(c, &rimeaddr_node_addr, to, NULL, 0);
|
||||||
|
|
||||||
if(nexthop == NULL) {
|
if(nexthop == NULL) {
|
||||||
|
|
|
@ -48,7 +48,7 @@
|
||||||
*
|
*
|
||||||
* This file is part of the Contiki operating system.
|
* This file is part of the Contiki operating system.
|
||||||
*
|
*
|
||||||
* $Id: mh.h,v 1.4 2008/01/08 07:55:56 adamdunkels Exp $
|
* $Id: mh.h,v 1.5 2008/02/05 20:17:43 adamdunkels Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -67,7 +67,10 @@
|
||||||
struct mh_conn;
|
struct mh_conn;
|
||||||
|
|
||||||
struct mh_callbacks {
|
struct mh_callbacks {
|
||||||
void (* recv)(struct mh_conn *ptr, rimeaddr_t *sender, u8_t hops);
|
void (* recv)(struct mh_conn *ptr,
|
||||||
|
rimeaddr_t *sender,
|
||||||
|
rimeaddr_t *prevhop,
|
||||||
|
u8_t hops);
|
||||||
rimeaddr_t *(* forward)(struct mh_conn *ptr,
|
rimeaddr_t *(* forward)(struct mh_conn *ptr,
|
||||||
rimeaddr_t *originator,
|
rimeaddr_t *originator,
|
||||||
rimeaddr_t *dest,
|
rimeaddr_t *dest,
|
||||||
|
|
Loading…
Reference in a new issue