53 #define PACKET_TIMEOUT (CLOCK_SECOND * 10)
58 #define PRINTF(...) printf(__VA_ARGS__)
65 data_packet_received(
struct multihop_conn *multihop,
66 const rimeaddr_t *from,
67 const rimeaddr_t *prevhop, uint8_t hops)
69 struct mesh_conn *c = (
struct mesh_conn *)
70 ((
char *)multihop - offsetof(
struct mesh_conn, multihop));
72 struct route_entry *rt;
75 rt = route_lookup(from);
81 c->cb->recv(c, from, hops);
86 data_packet_forward(
struct multihop_conn *multihop,
87 const rimeaddr_t *originator,
88 const rimeaddr_t *dest,
89 const rimeaddr_t *prevhop, uint8_t hops)
91 struct route_entry *rt;
92 struct mesh_conn *c = (
struct mesh_conn *)
93 ((
char *)multihop - offsetof(
struct mesh_conn, multihop));
95 rt = route_lookup(dest);
97 if(c->queued_data !=
NULL) {
98 queuebuf_free(c->queued_data);
101 PRINTF(
"data_packet_forward: queueing data, sending rreq\n");
102 c->queued_data = queuebuf_new_from_packetbuf();
104 route_discovery_discover(&c->route_discovery_conn, dest, PACKET_TIMEOUT);
115 found_route(
struct route_discovery_conn *rdc,
const rimeaddr_t *dest)
117 struct route_entry *rt;
118 struct mesh_conn *c = (
struct mesh_conn *)
119 ((
char *)rdc - offsetof(
struct mesh_conn, route_discovery_conn));
121 PRINTF(
"found_route\n");
123 if(c->queued_data !=
NULL &&
125 queuebuf_to_packetbuf(c->queued_data);
126 queuebuf_free(c->queued_data);
127 c->queued_data =
NULL;
129 rt = route_lookup(dest);
131 multihop_resend(&c->multihop, &rt->nexthop);
140 route_timed_out(
struct route_discovery_conn *rdc)
142 struct mesh_conn *c = (
struct mesh_conn *)
143 ((
char *)rdc - offsetof(
struct mesh_conn, route_discovery_conn));
145 if(c->queued_data !=
NULL) {
146 queuebuf_free(c->queued_data);
147 c->queued_data =
NULL;
150 if(c->cb->timedout) {
155 static const struct multihop_callbacks data_callbacks = { data_packet_received,
156 data_packet_forward };
157 static const struct route_discovery_callbacks route_discovery_callbacks =
158 { found_route, route_timed_out };
165 multihop_open(&c->multihop, channels, &data_callbacks);
166 route_discovery_open(&c->route_discovery_conn,
169 &route_discovery_callbacks);
176 multihop_close(&c->multihop);
177 route_discovery_close(&c->route_discovery_conn);
185 PRINTF(
"%d.%d: mesh_send to %d.%d\n",
187 to->u8[0], to->u8[1]);
189 could_send = multihop_send(&c->multihop, to);
192 PRINTF(
"mesh_send: could not send\n");