From 2d369f16e420f01f0fc5cbc168ccc662d3328a43 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Thu, 21 Mar 2013 03:07:51 +0100 Subject: Implement ACK request handling --- src/babel.h | 2 ++ src/send.c | 24 ++++++++++++++++++++++++ src/tlv_types.c | 26 ++++++++++++++++++++++++++ 3 files changed, 52 insertions(+) (limited to 'src') diff --git a/src/babel.h b/src/babel.h index d6224ff..4e78ca0 100644 --- a/src/babel.h +++ b/src/babel.h @@ -87,6 +87,8 @@ static inline gp_babel_iface_t* gp_babel_get_iface(gmrf_context_t *ctx, gmrf_ifa void gp_babel_handle_packet(gmrf_t *gmrf, gmrf_context_t *ctx, gp_babel_iface_t *iface, const gmrf_addr_t *source, const gp_babel_packet_t *packet); + +void gp_babel_send_ack(gmrf_t *gmrf, gmrf_context_t *ctx, gp_babel_neigh_t *neigh, uint16_t nonce); void gp_babel_send_hellos(gmrf_t *gmrf, gmrf_context_t *ctx); #endif /* _GMRF_PROTO_BABEL_BABEL_H_ */ diff --git a/src/send.c b/src/send.c index 7fc9453..fd3f9d7 100644 --- a/src/send.c +++ b/src/send.c @@ -31,6 +31,30 @@ #include "tlv_types.h" +static inline bool send_neigh(gmrf_t *gmrf, const gp_babel_neigh_t *neigh, const gp_babel_packet_t *packet) { + if (!neigh->iface) + return false; + + if (!gmrf_iface_send(gmrf, neigh->iface->gmrf_iface, packet, gp_babel_packet_size(packet), &neigh->addr)) { + gmrf_logf(gmrf, LOG_WARNING, "gmrf_iface_send: %m"); + return false; + } + + return true; +} + +void gp_babel_send_ack(gmrf_t *gmrf, gmrf_context_t *ctx, gp_babel_neigh_t *neigh, uint16_t nonce) { + gp_babel_packet_t *packet = alloca_packet(GP_BABEL_PACKET_MAX); + + gp_babel_tlv_ack_t *ack = gp_babel_tlv_add(packet, GP_BABEL_PACKET_MAX, TLV_ACK, sizeof(gp_babel_tlv_ack_t)); + if (!ack) + return; + + ack->nonce = htons(nonce); + + send_neigh(gmrf, neigh, packet); +} + static void add_ihus(gmrf_t *gmrf, gp_babel_packet_t *packet, size_t max_len, const gp_babel_iface_t *iface) { const gp_babel_neigh_t *neigh; diff --git a/src/tlv_types.c b/src/tlv_types.c index a3f1fbb..9c485f2 100644 --- a/src/tlv_types.c +++ b/src/tlv_types.c @@ -43,6 +43,24 @@ static inline gp_babel_neigh_t* get_tlv_neigh(handle_tlv_arg_t *arg) { return gp_babel_neigh_get(arg->iface, arg->source); } +static void handle_tlv_ack_req(gmrf_t *gmrf, gmrf_context_t *ctx, const gp_babel_tlv_ack_req_t *tlv_req, size_t len, handle_tlv_arg_t *arg) { + if (len < sizeof(gp_babel_tlv_ack_req_t)) { + gmrf_logf(gmrf, LOG_WARNING, "received short acknowledement request TLV."); + return; + } + + gp_babel_send_ack(gmrf, ctx, get_tlv_neigh(arg), ntohs(tlv_req->nonce)); +} + +static void handle_tlv_ack(gmrf_t *gmrf, gmrf_context_t *ctx, const gp_babel_tlv_ack_t *tlv_ack, size_t len, handle_tlv_arg_t *arg) { + if (len < sizeof(gp_babel_tlv_ack_t)) { + gmrf_logf(gmrf, LOG_WARNING, "received short acknowledement TLV."); + return; + } + + //gp_babel_ack_handle(ntohs(tlv_ack->nonce)); +} + static void handle_tlv_hello(gmrf_t *gmrf, gmrf_context_t *ctx, const gp_babel_tlv_hello_t *tlv_hello, size_t len, handle_tlv_arg_t *arg) { if (len < sizeof(gp_babel_tlv_hello_t)) { gmrf_logf(gmrf, LOG_WARNING, "received short hello TLV."); @@ -122,6 +140,14 @@ static void handle_tlv(gmrf_t *gmrf, gmrf_context_t *ctx, gp_babel_tlv_type_t ty handle_tlv_arg_t *tlv_arg = arg; switch (type) { + case TLV_ACK_REQ: + handle_tlv_ack_req(gmrf, ctx, data, len, tlv_arg); + return; + + case TLV_ACK: + handle_tlv_ack(gmrf, ctx, data, len, tlv_arg); + return; + case TLV_HELLO: handle_tlv_hello(gmrf, ctx, data, len, tlv_arg); return; -- cgit v1.2.3