52 #define PACKET_TIMEOUT (CLOCK_SECOND * 10)
57 #define PRINTF(...) printf(__VA_ARGS__)
64 data_packet_received(
struct multihop_conn *multihop,
65 const linkaddr_t *from,
66 const linkaddr_t *prevhop, uint8_t hops)
68 struct mesh_conn *c = (
struct mesh_conn *)
69 ((
char *)multihop - offsetof(
struct mesh_conn, multihop));
71 struct route_entry *rt;
74 rt = route_lookup(from);
80 c->cb->recv(c, from, hops);
85 data_packet_forward(
struct multihop_conn *multihop,
86 const linkaddr_t *originator,
87 const linkaddr_t *dest,
88 const linkaddr_t *prevhop, uint8_t hops)
90 struct route_entry *rt;
91 struct mesh_conn *c = (
struct mesh_conn *)
92 ((
char *)multihop - offsetof(
struct mesh_conn, multihop));
94 rt = route_lookup(dest);
96 if(c->queued_data !=
NULL) {
97 queuebuf_free(c->queued_data);
100 PRINTF(
"data_packet_forward: queueing data, sending rreq\n");
101 c->queued_data = queuebuf_new_from_packetbuf();
103 route_discovery_discover(&c->route_discovery_conn, dest, PACKET_TIMEOUT);
114 found_route(
struct route_discovery_conn *rdc,
const linkaddr_t *dest)
116 struct route_entry *rt;
117 struct mesh_conn *c = (
struct mesh_conn *)
118 ((
char *)rdc - offsetof(
struct mesh_conn, route_discovery_conn));
120 PRINTF(
"found_route\n");
122 if(c->queued_data !=
NULL &&
124 queuebuf_to_packetbuf(c->queued_data);
125 queuebuf_free(c->queued_data);
126 c->queued_data =
NULL;
128 rt = route_lookup(dest);
130 multihop_resend(&c->multihop, &rt->nexthop);
131 if(c->cb->sent !=
NULL) {
135 if(c->cb->timedout !=
NULL) {
143 route_timed_out(
struct route_discovery_conn *rdc)
145 struct mesh_conn *c = (
struct mesh_conn *)
146 ((
char *)rdc - offsetof(
struct mesh_conn, route_discovery_conn));
148 if(c->queued_data !=
NULL) {
149 queuebuf_free(c->queued_data);
150 c->queued_data =
NULL;
153 if(c->cb->timedout) {
158 static const struct multihop_callbacks data_callbacks = { data_packet_received,
159 data_packet_forward };
160 static const struct route_discovery_callbacks route_discovery_callbacks =
161 { found_route, route_timed_out };
168 multihop_open(&c->multihop, channels, &data_callbacks);
169 route_discovery_open(&c->route_discovery_conn,
172 &route_discovery_callbacks);
179 multihop_close(&c->multihop);
180 route_discovery_close(&c->route_discovery_conn);
188 PRINTF(
"%d.%d: mesh_send to %d.%d\n",
190 to->u8[0], to->u8[1]);
192 could_send = multihop_send(&c->multihop, to);
195 PRINTF(
"mesh_send: could not send\n");
198 if(c->cb->sent !=
NULL) {
207 return (c->queued_data ==
NULL);