48 #define ROUTE_TRICKLE_INTERVAL CLOCK_SECOND * 32
49 #define ROUTE_DISCOVERY_INTERVAL CLOCK_SECOND * 4
50 #define ROUTE_TIMEOUT CLOCK_SECOND * 4
52 static struct queuebuf *queued_packet;
53 static linkaddr_t queued_receiver;
56 static struct route_discovery_conn route_discovery;
59 static struct unicast_conn dataconn;
63 static struct trickle_conn gateway_announce_conn;
68 #define PRINTF(...) printf(__VA_ARGS__)
73 #define BUF ((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN])
76 static linkaddr_t gateway;
77 static uip_ipaddr_t netaddr,
netmask;
81 recv_data(
struct unicast_conn *c,
const linkaddr_t *from)
83 struct route_entry *e;
88 source.u8[0] = BUF->srcipaddr.u8[2];
89 source.u8[1] = BUF->srcipaddr.u8[3];
91 e = route_lookup(&source);
93 route_add(&source, from, 10, 0);
101 e = route_lookup(&gateway);
108 PRINTF(
"uip-over-mesh: %d.%d: recv_data with len %d\n",
114 send_data(linkaddr_t *next)
116 PRINTF(
"uip-over-mesh: %d.%d: send_data with len %d\n",
119 unicast_send(&dataconn, next);
123 new_route(
struct route_discovery_conn *c,
const linkaddr_t *to)
125 struct route_entry *rt;
128 PRINTF(
"uip-over-mesh: new route, sending queued packet\n");
130 queuebuf_to_packetbuf(queued_packet);
131 queuebuf_free(queued_packet);
132 queued_packet =
NULL;
134 rt = route_lookup(&queued_receiver);
137 send_data(&queued_receiver);
143 timedout(
struct route_discovery_conn *c)
145 PRINTF(
"uip-over-mesh: packet timed out\n");
147 PRINTF(
"uip-over-mesh: freeing queued packet\n");
148 queuebuf_free(queued_packet);
149 queued_packet =
NULL;
153 static const struct unicast_callbacks data_callbacks = { recv_data };
154 static const struct route_discovery_callbacks rdc = { new_route, timedout };
160 static uint8_t is_gateway;
163 gateway_announce_recv(
struct trickle_conn *c)
165 struct gateway_msg *msg;
167 PRINTF(
"%d.%d: gateway message: %d.%d\n",
169 msg->gateway.u8[0], msg->gateway.u8[1]);
172 uip_over_mesh_set_gateway(&msg->gateway);
178 uip_over_mesh_make_announced_gateway(
void)
180 struct gateway_msg msg;
184 PRINTF(
"%d.%d: making myself the gateway\n",
189 trickle_send(&gateway_announce_conn);
193 const static struct trickle_callbacks trickle_call = {gateway_announce_recv};
196 uip_over_mesh_init(uint16_t channels)
199 PRINTF(
"Our address is %d.%d (%d.%d.%d.%d)\n",
201 uip_hostaddr.u8[0], uip_hostaddr.u8[1],
202 uip_hostaddr.u8[2], uip_hostaddr.u8[3]);
204 unicast_open(&dataconn, channels, &data_callbacks);
205 route_discovery_open(&route_discovery, ROUTE_DISCOVERY_INTERVAL,
207 trickle_open(&gateway_announce_conn, ROUTE_TRICKLE_INTERVAL, channels + 3,
212 route_set_lifetime(30);
216 uip_over_mesh_send(
void)
219 struct route_entry *rt;
231 receiver.u8[0] = BUF->destipaddr.u8[2];
232 receiver.u8[1] = BUF->destipaddr.u8[3];
235 PRINTF(
"uip_over_mesh_send: I am gateway, packet to %d.%d.%d.%d to local interface\n",
237 if(gw_netif !=
NULL) {
238 return gw_netif->
output();
242 PRINTF(
"uip_over_mesh_send: No gateway setup, dropping packet\n");
245 PRINTF(
"uip_over_mesh_send: forwarding packet to %d.%d.%d.%d towards gateway %d.%d\n",
247 gateway.u8[0], gateway.u8[1]);
252 PRINTF(
"uIP over mesh send to %d.%d with len %d\n",
253 receiver.u8[0], receiver.u8[1],
262 if(BUF->proto == UIP_PROTO_TCP) {
263 packetbuf_set_attr(PACKETBUF_ATTR_ERELIABLE, 1);
264 packetbuf_set_attr(PACKETBUF_ATTR_RELIABLE, 1);
268 rt = route_lookup(&receiver);
270 PRINTF(
"uIP over mesh no route to %d.%d\n", receiver.u8[0], receiver.u8[1]);
271 if(queued_packet ==
NULL) {
272 queued_packet = queuebuf_new_from_packetbuf();
274 route_discovery_discover(&route_discovery, &receiver, ROUTE_TIMEOUT);
276 route_discovery_discover(&route_discovery, &receiver, ROUTE_TIMEOUT);
280 send_data(&rt->nexthop);
292 uip_over_mesh_set_gateway(linkaddr_t *gw)
298 uip_over_mesh_set_net(uip_ipaddr_t *addr, uip_ipaddr_t *mask)
#define UIP_FW_DROPPED
An error message that indicates that a packet that should be forwarded or output was dropped...
uip_len
The length of the packet in the uip_buf buffer.
linkaddr_t linkaddr_node_addr
The Rime address of the node.
uIP packet forwarding header file.
int packetbuf_copyfrom(const void *from, uint16_t len)
Copy from external data into the packetbuf.
#define uip_ipaddr_maskcmp(addr1, addr2, mask)
Compare two IP addresses with netmasks.
void tcpip_input(void)
Deliver an incoming packet to the TCP/IP stack.
Representation of a uIP network interface.
uint8_t(* output)(void)
A pointer to the function that sends a packet.
const linkaddr_t linkaddr_null
The null Rime address.
#define NULL
The null pointer.
Header file for tunnelling uIP over Rime mesh
uint16_t packetbuf_totlen(void)
Get the total length of the header and data in the packetbuf.
void linkaddr_copy(linkaddr_t *dest, const linkaddr_t *src)
Copy a Rime address.
#define UIP_LLH_LEN
The link level header length.
#define uip_ipaddr_copy(dest, src)
Copy an IP address from one place to another.
int packetbuf_copyto(void *to)
Copy the entire packetbuf to an external buffer.
#define uip_ipaddr_to_quad(a)
Convert an IP address to four bytes separated by commas.
Header file for the Rime mesh routing protocol
uip_ipaddr_t netmask
The netmask of the interface.
int linkaddr_cmp(const linkaddr_t *addr1, const linkaddr_t *addr2)
Compare two Rime addresses.
Header file for Trickle (reliable single source flooding) for Rime
void * packetbuf_dataptr(void)
Get a pointer to the data in the packetbuf.
#define UIP_FW_OK
A non-error message that indicates that something went OK.
Header file for the Rime route table