Bluetooth: Mesh: Fix relaying from GATT to Advertising

The logic for choosing to relay from the GATT bearer to the
advertising bearer was still buggy. This patch refactors the logic to
a separate helper function to make it clearer.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
Johan Hedberg 2017-12-05 12:28:28 +02:00 committed by Johan Hedberg
commit 22f3d36ba7

View file

@ -1104,6 +1104,25 @@ static bool net_find_and_decrypt(const u8_t *data, size_t data_len,
return false;
}
/* Relaying from advertising to the advertising bearer should only happen
* if the Relay state is set to enabled. Locally originated packets always
* get sent to the advertising bearer. If the packet came in through GATT,
* then we should only relay it if the GATT Proxy state is enabled.
*/
static bool relay_to_adv(enum bt_mesh_net_if net_if)
{
switch (net_if) {
case BT_MESH_NET_IF_LOCAL:
return true;
case BT_MESH_NET_IF_ADV:
return (bt_mesh_relay_get() == BT_MESH_RELAY_ENABLED);
case BT_MESH_NET_IF_PROXY:
return (bt_mesh_gatt_proxy_get() == BT_MESH_GATT_PROXY_ENABLED);
default:
return false;
}
}
static void bt_mesh_net_relay(struct net_buf_simple *sbuf,
struct bt_mesh_net_rx *rx)
{
@ -1200,12 +1219,7 @@ static void bt_mesh_net_relay(struct net_buf_simple *sbuf,
}
}
/* Relaying to the Advertising bearer should only happen if the
* Relay state is set to enabled, or if the packet has been
* received over some other bearer than Advertising.
*/
if (bt_mesh_relay_get() == BT_MESH_RELAY_ENABLED ||
rx->net_if != BT_MESH_NET_IF_ADV) {
if (relay_to_adv(rx->net_if)) {
bt_mesh_adv_send(buf, NULL, NULL);
}