16 #include "net/rpl/rpl.h"
25 #define MAX_ENTRY_SIZE 12
75 static void res_get_handler(
void* request,
void* response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset);
82 void res_get_handler(
void *request,
void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) {
85 DEBUG(
"Serving routes req Offset %d, PrefSize %d\n", (
int) *offset, preferred_size);
90 DEBUG(
"First request, resetting neighbour and route\n");
93 char *error =
"No nbrs / routes\n";
95 memcpy(buffer, error, strlen(error));
96 REST.set_response_payload(response, buffer, strlen(error));
102 DEBUG(
"Printing preferred parent\n");
104 rpl_dag_t *dag = rpl_get_any_dag();
106 buffer_len += snprintf((
char *) buffer, preferred_size,
"%04x\n\n",
get_hex_ip(rpl_get_parent_ipaddr(dag->preferred_parent)));
110 *offset += preferred_size;
117 DEBUG(
"Printing nbr\n");
120 DEBUG(
"Printing route\n");
127 DEBUG(
"No more routes\n");
133 REST.set_response_payload(response, buffer, buffer_len);
137 return (ipaddr->u8[14] << 8) + ipaddr->u8[15];
158 nbr = nbr_table_head(ds6_neighbors);
160 nbr = nbr_table_next(ds6_neighbors, nbr);
163 DEBUG(
"Got nbr %p\n", nbr);
169 route = uip_ds6_route_head();
171 route = uip_ds6_route_next(route);
174 DEBUG(
"Got route %p\n", route);
175 return route !=
NULL;
static bool get_next_nbr_route()
Get the next neighbour if there is one, otherwise the next route.
static uip_ipaddr_t ipaddr
Pointer to prefix information option in uip_buf.
Header file for IPv6-related data structures.
An abstraction layer for RESTful Web services (Erbium).
static uint16_t get_hex_ip(uip_ipaddr_t *ip)
Get last 2 bytes of an IP as a uint16_t that can be hex printed.
An entry in the nbr cache.
static uip_ds6_route_t * route
The next route to use.
#define NULL
The null pointer.
static uip_ds6_nbr_t * nbr
The next neighbour to use.
static void res_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
Get handler for this resource.
static bool get_next_nbr()
Get the next neighbour if there is one.
Header file for the uIP TCP/IP stack.
RESOURCE(res_routes,"Routes", res_get_handler, NULL, NULL, NULL)
Route resource.
static void reset_nbr_route()
Reset our internal state so that subsequent calls to get_next_nbr / route return the first ones...
static bool get_next_route()
Get the next route if there is one.
static bool hasReachedRoutes
True if all the neighbors have been sent, and we should start sending routes.
An entry in the routing table.
#define MAX_ENTRY_SIZE
Maximum length of an single nbr / route entry, including terminating null byte.