Skip to content

Commit

Permalink
Bluetooth: Mesh: Add bridging functionality
Browse files Browse the repository at this point in the history
Adds subnet bridging functionality to the network layer.
Also fixes brg_cfg_srv for minor issues to get it working.

Signed-off-by: Omkar Kulkarni <omkar.kulkarni@nordicsemi.no>
  • Loading branch information
omkar3141 authored and nashif committed Sep 17, 2024
1 parent 8210d2d commit fc4576c
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 4 deletions.
4 changes: 2 additions & 2 deletions include/zephyr/bluetooth/mesh/brg_cfg_srv.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ extern "C" {
NULL, NULL, &bt_mesh_brg_cfg_srv_cb)

/** @cond INTERNAL_HIDDEN */
extern const struct bt_mesh_model_op bt_mesh_brg_cfg_srv_op[];
extern const struct bt_mesh_model_cb bt_mesh_brg_cfg_srv_cb;
extern const struct bt_mesh_model_op _bt_mesh_brg_cfg_srv_op[];
extern const struct bt_mesh_model_cb _bt_mesh_brg_cfg_srv_cb;
/** @endcond */

/**
Expand Down
12 changes: 10 additions & 2 deletions subsys/bluetooth/mesh/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -664,12 +664,20 @@ menu "Replay Protection List"

config BT_MESH_CRPL
int "Maximum capacity of the replay protection list"
default 26 if BT_MESH_BRG_CFG_SRV
default 10
range 2 $(UINT16_MAX)
help
This options specifies the maximum capacity of the replay
This option specifies the maximum capacity of the replay
protection list. This option is similar to the network message
cache size, but has a different purpose.
cache size, but has a purpose of preventing replay attacks.

Note that: To ensure sufficient space in CRPL for normal node
operations and as specified by other Bluetooth specification
requirements, when subnet bridge functionality is enabled on a node,
you should increase the CRPL capacity in your project configuration
file with the number of bridging table entries
(BT_MESH_BRG_TABLE_ITEMS_MAX) specified for the project as a minimum.

choice BT_MESH_RPL_STORAGE_MODE
prompt "Replay protection list storage mode"
Expand Down
8 changes: 8 additions & 0 deletions subsys/bluetooth/mesh/brg_cfg_srv.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <zephyr/bluetooth/mesh.h>
#include <zephyr/bluetooth/mesh/brg_cfg.h>
#include "access.h"
#include "brg_cfg.h"
#include "foundation.h"
#include "subnet.h"
Expand Down Expand Up @@ -307,6 +308,13 @@ static int brg_cfg_srv_init(const struct bt_mesh_model *model)
return -EINVAL;
}

/*
* Bridge Configuration Server model security is device key based and only the local
* device key is allowed to access this model.
*/
model->keys[0] = BT_MESH_KEY_DEV_LOCAL;
model->rt->flags |= BT_MESH_MOD_DEVKEY_ONLY;

bt_mesh_model_extend(model, config_srv);

return 0;
Expand Down
43 changes: 43 additions & 0 deletions subsys/bluetooth/mesh/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "cfg.h"
#include "statistic.h"
#include "sar_cfg_internal.h"
#include "brg_cfg.h"

#define LOG_LEVEL CONFIG_BT_MESH_NET_LOG_LEVEL
#include <zephyr/logging/log.h>
Expand All @@ -54,6 +55,13 @@ LOG_MODULE_REGISTER(bt_mesh_net);
#define SRC(pdu) (sys_get_be16(&(pdu)[5]))
#define DST(pdu) (sys_get_be16(&(pdu)[7]))

/* Information needed for bridging the network PDUs */
struct pdu_ctx {
struct net_buf_simple *sbuf;
struct net_buf_simple_state *state;
struct bt_mesh_net_rx *rx;
};

/* Mesh network information for persistent storage. */
struct net_val {
uint16_t primary_addr;
Expand Down Expand Up @@ -756,6 +764,19 @@ static void bt_mesh_net_relay(struct net_buf_simple *sbuf,
bt_mesh_adv_unref(adv);
}

#if IS_ENABLED(CONFIG_BT_MESH_BRG_CFG_SRV)
static void bt_mesh_sbr_check_cb(uint16_t new_net_idx, void *user_data)
{
struct pdu_ctx *ctx = (struct pdu_ctx *)user_data;

if (new_net_idx < BT_MESH_BRG_CFG_NETIDX_NOMATCH) {
ctx->rx->ctx.net_idx = new_net_idx;
net_buf_simple_restore(ctx->sbuf, ctx->state);
bt_mesh_net_relay(ctx->sbuf, ctx->rx);
}
}
#endif

void bt_mesh_net_header_parse(struct net_buf_simple *buf,
struct bt_mesh_net_rx *rx)
{
Expand Down Expand Up @@ -893,6 +914,28 @@ void bt_mesh_net_recv(struct net_buf_simple *data, int8_t rssi,
net_buf_simple_restore(&buf, &state);
bt_mesh_net_relay(&buf, &rx);
}

#if IS_ENABLED(CONFIG_BT_MESH_BRG_CFG_SRV)
struct pdu_ctx tx_ctx = {
.sbuf = &buf,
.state = &state,
.rx = &rx,
};

/* Bridge the traffic if enabled */
if (!bt_mesh_brg_cfg_enable_get()) {
return;
}

struct bt_mesh_rpl *rpl = NULL;

if (bt_mesh_rpl_check(&rx, &rpl)) {
return;
}

bt_mesh_brg_cfg_tbl_foreach_subnet(rx.ctx.addr, rx.ctx.recv_dst, rx.ctx.net_idx,
bt_mesh_sbr_check_cb, &tx_ctx);
#endif
}

static void ivu_refresh(struct k_work *work)
Expand Down

0 comments on commit fc4576c

Please sign in to comment.