53 static const struct packetbuf_attrlist attributes[] =
62 #define PRINTF(...) printf(__VA_ARGS__)
69 data_packet_received(
struct unicast_conn *uc,
const rimeaddr_t *from)
71 struct multihop_conn *c = (
struct multihop_conn *)uc;
73 rimeaddr_t sender, receiver;
78 rimeaddr_copy(&sender, packetbuf_addr(PACKETBUF_ADDR_ESENDER));
79 rimeaddr_copy(&receiver, packetbuf_addr(PACKETBUF_ADDR_ERECEIVER));
81 PRINTF(
"data_packet_received from %d.%d towards %d.%d len %d\n",
82 from->u8[0], from->u8[1],
83 packetbuf_addr(PACKETBUF_ADDR_ERECEIVER)->u8[0],
84 packetbuf_addr(PACKETBUF_ADDR_ERECEIVER)->u8[1],
87 if(
rimeaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_ERECEIVER),
91 c->cb->recv(c, &sender, from,
92 packetbuf_attr(PACKETBUF_ATTR_HOPS));
97 packetbuf_set_attr(PACKETBUF_ATTR_HOPS,
98 packetbuf_attr(PACKETBUF_ATTR_HOPS) + 1);
99 nexthop = c->cb->forward(c, &sender, &receiver,
100 from, packetbuf_attr(PACKETBUF_ATTR_HOPS) - 1);
103 PRINTF(
"forwarding to %d.%d\n", nexthop->u8[0], nexthop->u8[1]);
104 unicast_send(&c->c, nexthop);
109 static const struct unicast_callbacks data_callbacks = { data_packet_received };
112 multihop_open(
struct multihop_conn *c, uint16_t channel,
113 const struct multihop_callbacks *callbacks)
115 unicast_open(&c->c, channel, &data_callbacks);
116 channel_set_attributes(channel, attributes);
121 multihop_close(
struct multihop_conn *c)
123 unicast_close(&c->c);
127 multihop_send(
struct multihop_conn *c,
const rimeaddr_t *to)
131 if(c->cb->forward ==
NULL) {
135 packetbuf_set_addr(PACKETBUF_ADDR_ERECEIVER, to);
137 packetbuf_set_attr(PACKETBUF_ATTR_HOPS, 1);
140 if(nexthop ==
NULL) {
141 PRINTF(
"multihop_send: no route\n");
144 PRINTF(
"multihop_send: sending data towards %d.%d\n",
145 nexthop->u8[0], nexthop->u8[1]);
146 unicast_send(&c->c, nexthop);
152 multihop_resend(
struct multihop_conn *c,
const rimeaddr_t *nexthop)
154 unicast_send(&c->c, nexthop);