From 387e91a76b94e1deb281ee75c5362b29e419fd60 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Tue, 26 Jun 2018 21:42:10 +0300 Subject: [PATCH] Bluetooth: Mesh: cfg_srv: Ignore Prohibited element addresses The Configuration Model specification states that all non-unicast addresses given as the address of an element are Prohibited. The correct action for Prohibited parameter values is to ignore the message. As of writing this patch the PTS does not enforce this, but it might in the future (as it does for many other Prohibited values). Signed-off-by: Johan Hedberg --- subsys/bluetooth/host/mesh/cfg_srv.c | 94 ++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/subsys/bluetooth/host/mesh/cfg_srv.c b/subsys/bluetooth/host/mesh/cfg_srv.c index ad400555dc8..789b893d463 100644 --- a/subsys/bluetooth/host/mesh/cfg_srv.c +++ b/subsys/bluetooth/host/mesh/cfg_srv.c @@ -1055,6 +1055,11 @@ static void mod_pub_get(struct bt_mesh_model *model, bool vnd; elem_addr = net_buf_simple_pull_le16(buf); + if (!BT_MESH_ADDR_IS_UNICAST(elem_addr)) { + BT_WARN("Prohibited element address"); + return; + } + mod_id = buf->data; BT_DBG("elem_addr 0x%04x", elem_addr); @@ -1098,6 +1103,11 @@ static void mod_pub_set(struct bt_mesh_model *model, bool vnd; elem_addr = net_buf_simple_pull_le16(buf); + if (!BT_MESH_ADDR_IS_UNICAST(elem_addr)) { + BT_WARN("Prohibited element address"); + return; + } + pub_addr = net_buf_simple_pull_le16(buf); pub_app_idx = net_buf_simple_pull_le16(buf); cred_flag = ((pub_app_idx >> 12) & BIT_MASK(1)); @@ -1236,6 +1246,11 @@ static void mod_pub_va_set(struct bt_mesh_model *model, bool vnd; elem_addr = net_buf_simple_pull_le16(buf); + if (!BT_MESH_ADDR_IS_UNICAST(elem_addr)) { + BT_WARN("Prohibited element address"); + return; + } + label_uuid = buf->data; net_buf_simple_pull(buf, 16); @@ -1304,6 +1319,11 @@ static void mod_pub_va_set(struct bt_mesh_model *model, bool vnd; elem_addr = net_buf_simple_pull_le16(buf); + if (!BT_MESH_ADDR_IS_UNICAST(elem_addr)) { + BT_WARN("Prohibited element address"); + return; + } + net_buf_simple_pull(buf, 16); mod_id = net_buf_simple_pull(buf, 4); @@ -1378,6 +1398,11 @@ static void mod_sub_add(struct bt_mesh_model *model, int i; elem_addr = net_buf_simple_pull_le16(buf); + if (!BT_MESH_ADDR_IS_UNICAST(elem_addr)) { + BT_WARN("Prohibited element address"); + return; + } + sub_addr = net_buf_simple_pull_le16(buf); BT_DBG("elem_addr 0x%04x, sub_addr 0x%04x", elem_addr, sub_addr); @@ -1448,6 +1473,11 @@ static void mod_sub_del(struct bt_mesh_model *model, bool vnd; elem_addr = net_buf_simple_pull_le16(buf); + if (!BT_MESH_ADDR_IS_UNICAST(elem_addr)) { + BT_WARN("Prohibited element address"); + return; + } + sub_addr = net_buf_simple_pull_le16(buf); BT_DBG("elem_addr 0x%04x sub_addr 0x%04x", elem_addr, sub_addr); @@ -1508,6 +1538,11 @@ static void mod_sub_overwrite(struct bt_mesh_model *model, bool vnd; elem_addr = net_buf_simple_pull_le16(buf); + if (!BT_MESH_ADDR_IS_UNICAST(elem_addr)) { + BT_WARN("Prohibited element address"); + return; + } + sub_addr = net_buf_simple_pull_le16(buf); BT_DBG("elem_addr 0x%04x sub_addr 0x%04x", elem_addr, sub_addr); @@ -1572,6 +1607,10 @@ static void mod_sub_del_all(struct bt_mesh_model *model, bool vnd; elem_addr = net_buf_simple_pull_le16(buf); + if (!BT_MESH_ADDR_IS_UNICAST(elem_addr)) { + BT_WARN("Prohibited element address"); + return; + } BT_DBG("elem_addr 0x%04x", elem_addr); @@ -1620,6 +1659,11 @@ static void mod_sub_get(struct bt_mesh_model *model, int i; addr = net_buf_simple_pull_le16(buf); + if (!BT_MESH_ADDR_IS_UNICAST(addr)) { + BT_WARN("Prohibited element address"); + return; + } + id = net_buf_simple_pull_le16(buf); BT_DBG("addr 0x%04x id 0x%04x", addr, id); @@ -1671,6 +1715,11 @@ static void mod_sub_get_vnd(struct bt_mesh_model *model, int i; addr = net_buf_simple_pull_le16(buf); + if (!BT_MESH_ADDR_IS_UNICAST(addr)) { + BT_WARN("Prohibited element address"); + return; + } + company = net_buf_simple_pull_le16(buf); id = net_buf_simple_pull_le16(buf); @@ -1729,6 +1778,11 @@ static void mod_sub_va_add(struct bt_mesh_model *model, int i; elem_addr = net_buf_simple_pull_le16(buf); + if (!BT_MESH_ADDR_IS_UNICAST(elem_addr)) { + BT_WARN("Prohibited element address"); + return; + } + label_uuid = buf->data; net_buf_simple_pull(buf, 16); @@ -1802,6 +1856,11 @@ static void mod_sub_va_del(struct bt_mesh_model *model, bool vnd; elem_addr = net_buf_simple_pull_le16(buf); + if (!BT_MESH_ADDR_IS_UNICAST(elem_addr)) { + BT_WARN("Prohibited element address"); + return; + } + label_uuid = buf->data; net_buf_simple_pull(buf, 16); @@ -1865,6 +1924,11 @@ static void mod_sub_va_overwrite(struct bt_mesh_model *model, bool vnd; elem_addr = net_buf_simple_pull_le16(buf); + if (!BT_MESH_ADDR_IS_UNICAST(elem_addr)) { + BT_WARN("Prohibited element address"); + return; + } + label_uuid = buf->data; net_buf_simple_pull(buf, 16); @@ -1926,6 +1990,11 @@ static void mod_sub_va_add(struct bt_mesh_model *model, bool vnd; elem_addr = net_buf_simple_pull_le16(buf); + if (!BT_MESH_ADDR_IS_UNICAST(elem_addr)) { + BT_WARN("Prohibited element address"); + return; + } + net_buf_simple_pull(buf, 16); mod_id = buf->data; @@ -1962,6 +2031,11 @@ static void mod_sub_va_del(struct bt_mesh_model *model, bool vnd; elem_addr = net_buf_simple_pull_le16(buf); + if (!BT_MESH_ADDR_IS_UNICAST(elem_addr)) { + BT_WARN("Prohibited element address"); + return; + } + net_buf_simple_pull(buf, 16); mod_id = buf->data; @@ -1996,6 +2070,11 @@ static void mod_sub_va_overwrite(struct bt_mesh_model *model, bool vnd; elem_addr = net_buf_simple_pull_le16(buf); + if (!BT_MESH_ADDR_IS_UNICAST(elem_addr)) { + BT_WARN("Prohibited element address"); + return; + } + net_buf_simple_pull(buf, 18); mod_id = buf->data; @@ -2397,6 +2476,11 @@ static void mod_app_bind(struct bt_mesh_model *model, bool vnd; elem_addr = net_buf_simple_pull_le16(buf); + if (!BT_MESH_ADDR_IS_UNICAST(elem_addr)) { + BT_WARN("Prohibited element address"); + return; + } + key_app_idx = net_buf_simple_pull_le16(buf); mod_id = buf->data; @@ -2449,6 +2533,11 @@ static void mod_app_unbind(struct bt_mesh_model *model, bool vnd; elem_addr = net_buf_simple_pull_le16(buf); + if (!BT_MESH_ADDR_IS_UNICAST(elem_addr)) { + BT_WARN("Prohibited element address"); + return; + } + key_app_idx = net_buf_simple_pull_le16(buf); mod_id = buf->data; @@ -2496,6 +2585,11 @@ static void mod_app_get(struct bt_mesh_model *model, bool vnd; elem_addr = net_buf_simple_pull_le16(buf); + if (!BT_MESH_ADDR_IS_UNICAST(elem_addr)) { + BT_WARN("Prohibited element address"); + return; + } + mod_id = buf->data; BT_DBG("elem_addr 0x%04x", elem_addr);