52 static const struct packetbuf_attrlist attributes[] =
61 #define PRINTF(...) printf(__VA_ARGS__)
68 data_packet_received(
struct unicast_conn *uc,
const linkaddr_t *from)
70 struct multihop_conn *c = (
struct multihop_conn *)uc;
72 linkaddr_t sender, receiver;
77 linkaddr_copy(&sender, packetbuf_addr(PACKETBUF_ADDR_ESENDER));
78 linkaddr_copy(&receiver, packetbuf_addr(PACKETBUF_ADDR_ERECEIVER));
80 PRINTF(
"data_packet_received from %d.%d towards %d.%d len %d\n",
81 from->u8[0], from->u8[1],
82 packetbuf_addr(PACKETBUF_ADDR_ERECEIVER)->u8[0],
83 packetbuf_addr(PACKETBUF_ADDR_ERECEIVER)->u8[1],
86 if(
linkaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_ERECEIVER),
90 c->cb->recv(c, &sender, from,
91 packetbuf_attr(PACKETBUF_ATTR_HOPS));
96 packetbuf_set_attr(PACKETBUF_ATTR_HOPS,
97 packetbuf_attr(PACKETBUF_ATTR_HOPS) + 1);
98 nexthop = c->cb->forward(c, &sender, &receiver,
99 from, packetbuf_attr(PACKETBUF_ATTR_HOPS) - 1);
102 PRINTF(
"forwarding to %d.%d\n", nexthop->u8[0], nexthop->u8[1]);
103 unicast_send(&c->c, nexthop);
108 static const struct unicast_callbacks data_callbacks = { data_packet_received };
111 multihop_open(
struct multihop_conn *c, uint16_t channel,
112 const struct multihop_callbacks *callbacks)
114 unicast_open(&c->c, channel, &data_callbacks);
115 channel_set_attributes(channel, attributes);
120 multihop_close(
struct multihop_conn *c)
122 unicast_close(&c->c);
126 multihop_send(
struct multihop_conn *c,
const linkaddr_t *to)
130 if(c->cb->forward ==
NULL) {
134 packetbuf_set_addr(PACKETBUF_ADDR_ERECEIVER, to);
136 packetbuf_set_attr(PACKETBUF_ATTR_HOPS, 1);
139 if(nexthop ==
NULL) {
140 PRINTF(
"multihop_send: no route\n");
143 PRINTF(
"multihop_send: sending data towards %d.%d\n",
144 nexthop->u8[0], nexthop->u8[1]);
145 unicast_send(&c->c, nexthop);
151 multihop_resend(
struct multihop_conn *c,
const linkaddr_t *nexthop)
153 unicast_send(&c->c, nexthop);
linkaddr_t linkaddr_node_addr
The Rime address of the node.
#define NULL
The null pointer.
Header file for the Rime stack
uint16_t packetbuf_datalen(void)
Get the length of the data in the packetbuf.
void linkaddr_copy(linkaddr_t *dest, const linkaddr_t *src)
Copy a Rime address.
void packetbuf_compact(void)
Compact the packetbuf.
int linkaddr_cmp(const linkaddr_t *addr1, const linkaddr_t *addr2)
Compare two Rime addresses.
Multihop forwarding header file
Header file for the Rime route table