From 2e9fd888bf49e535a5442c1475868f2bf05c5e59 Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Wed, 25 Jan 2017 14:36:49 +0200 Subject: [PATCH] net: bt: Fix not checking for valid ll addresses ll addresses need to be set properly before sending as the stack is not checking if they are NULL. Change-Id: Ia4e96240f18b53b0e32e21649a8b571c94260731 Signed-off-by: Luiz Augusto von Dentz --- subsys/net/ip/l2/bluetooth.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/subsys/net/ip/l2/bluetooth.c b/subsys/net/ip/l2/bluetooth.c index 42c945eeaea..c24b1437b20 100644 --- a/subsys/net/ip/l2/bluetooth.c +++ b/subsys/net/ip/l2/bluetooth.c @@ -32,6 +32,8 @@ #include #include +#include "ipv6.h" + #define L2CAP_IPSP_PSM 0x0023 #define L2CAP_IPSP_MTU 1280 @@ -85,6 +87,27 @@ static enum net_verdict net_bt_send(struct net_if *iface, struct net_buf *buf) return NET_DROP; } + /* TODO: Move ll address check to the stack */ + + /* If the ll address is not set at all, then we must set + * it here. + */ + if (!net_nbuf_ll_src(buf)->addr) { + net_nbuf_ll_src(buf)->addr = net_nbuf_ll_if(buf)->addr; + net_nbuf_ll_src(buf)->len = net_nbuf_ll_if(buf)->len; + } + + /* If the ll dst address is not set check if it is present in the nbr + * cache. + */ + if (!net_nbuf_ll_dst(buf)->addr && + !net_is_ipv6_addr_mcast(&NET_IPV6_BUF(buf)->dst)) { + buf = net_ipv6_prepare_for_send(buf); + if (!buf) { + return NET_CONTINUE; + } + } + if (!net_6lo_compress(buf, true, NULL)) { NET_DBG("Packet compression failed"); return NET_DROP;