Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions subsys/bluetooth/mesh/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@ zephyr_library_sources_ifdef(CONFIG_BT_MESH_PROVISIONER provisioner.c)

zephyr_library_sources_ifdef(CONFIG_BT_MESH_PB_ADV pb_adv.c)

zephyr_library_sources_ifdef(CONFIG_BT_MESH_PB_GATT pb_gatt.c)
zephyr_library_sources_ifdef(CONFIG_BT_MESH_PB_GATT
pb_gatt.c
pb_gatt_srv.c
)

zephyr_library_sources_ifdef(CONFIG_BT_MESH_GATT_SERVER gatt_services.c)
zephyr_library_sources_ifdef(CONFIG_BT_MESH_GATT_PROXY proxy_srv.c)

zephyr_library_sources_ifdef(CONFIG_BT_MESH_GATT proxy_msg.c)

Expand Down
19 changes: 16 additions & 3 deletions subsys/bluetooth/mesh/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ config BT_MESH_PROXY
config BT_MESH_GATT
bool

config BT_MESH_PROXY_MSG_LEN
int
depends on BT_MESH_GATT
default 66 if BT_MESH_PB_GATT
default 33 if BT_MESH_GATT_PROXY

config BT_MESH_GATT_SERVER
bool
select BT_MESH_GATT
Expand All @@ -120,6 +126,14 @@ config BT_MESH_PB_GATT
Enable this option to allow the device to be provisioned over
GATT.

config BT_MESH_PB_GATT_USE_DEVICE_NAME
bool "Include Bluetooth device name in scan response"
depends on BT_MESH_PB_GATT
default y
help
This option includes GAP device name in scan response when
the PB-GATT is enabled.

config BT_MESH_GATT_PROXY
bool "GATT Proxy Service support"
select BT_MESH_GATT_SERVER
Expand Down Expand Up @@ -158,10 +172,9 @@ config BT_MESH_PROXY_USE_DEVICE_NAME

config BT_MESH_PROXY_FILTER_SIZE
int "Maximum number of filter entries per Proxy Client"
default 3 if BT_MESH_GATT_PROXY
default 1
default 3
range 1 32767
depends on BT_MESH_GATT_SERVER
depends on BT_MESH_GATT_PROXY
help
This option specifies how many Proxy Filter entries the local
node supports.
Expand Down
21 changes: 16 additions & 5 deletions subsys/bluetooth/mesh/adv_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "adv.h"
#include "net.h"
#include "proxy.h"
#include "pb_gatt_srv.h"

/* Convert from ms to 0.625ms units */
#define ADV_INT_FAST_MS 20
Expand Down Expand Up @@ -171,13 +172,23 @@ static void send_pending_adv(struct k_work *work)
}
}

if (!IS_ENABLED(CONFIG_BT_MESH_GATT_SERVER)) {
return;
}

/* No more pending buffers */
if (IS_ENABLED(CONFIG_BT_MESH_GATT_SERVER)) {
BT_DBG("Proxy Advertising");
err = bt_mesh_proxy_adv_start();
if (!err) {
atomic_set_bit(adv.flags, ADV_FLAG_PROXY);
if (bt_mesh_is_provisioned()) {
if (IS_ENABLED(CONFIG_BT_MESH_GATT_PROXY)) {
err = bt_mesh_proxy_adv_start();
BT_DBG("Proxy Advertising");
}
} else if (IS_ENABLED(CONFIG_BT_MESH_PB_GATT)) {
err = bt_mesh_pb_gatt_adv_start();
BT_DBG("PB-GATT Advertising");
}

if (!err) {
atomic_set_bit(adv.flags, ADV_FLAG_PROXY);
}
}

Expand Down
12 changes: 10 additions & 2 deletions subsys/bluetooth/mesh/adv_legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "host/ecc.h"
#include "prov.h"
#include "proxy.h"
#include "pb_gatt_srv.h"

/* Pre-5.0 controllers enforce a minimum interval of 100ms
* whereas 5.0+ controllers can go down to 20ms.
Expand Down Expand Up @@ -137,8 +138,15 @@ static void adv_thread(void *p1, void *p2, void *p3)
* to bt_mesh_adv_start:
*/
adv_timeout = SYS_FOREVER_MS;
bt_mesh_proxy_adv_start();
BT_DBG("Proxy Advertising");
if (bt_mesh_is_provisioned()) {
if (IS_ENABLED(CONFIG_BT_MESH_GATT_PROXY)) {
(void)bt_mesh_proxy_adv_start();
BT_DBG("Proxy Advertising");
}
} else if (IS_ENABLED(CONFIG_BT_MESH_PB_GATT)) {
(void)bt_mesh_pb_gatt_adv_start();
BT_DBG("PB-GATT Advertising");
}

buf = net_buf_get(&bt_mesh_adv_queue,
SYS_TIMEOUT_MS(adv_timeout));
Expand Down
37 changes: 12 additions & 25 deletions subsys/bluetooth/mesh/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@
#include "access.h"
#include "foundation.h"
#include "proxy.h"
#include "pb_gatt_srv.h"
#include "settings.h"
#include "mesh.h"

int bt_mesh_provision(const uint8_t net_key[16], uint16_t net_idx,
uint8_t flags, uint32_t iv_index, uint16_t addr,
const uint8_t dev_key[16])
{
bool pb_gatt_enabled;
int err;

BT_INFO("Primary Element: 0x%04x", addr);
Expand All @@ -54,16 +54,6 @@ int bt_mesh_provision(const uint8_t net_key[16], uint16_t net_idx,
return -EALREADY;
}

if (IS_ENABLED(CONFIG_BT_MESH_PB_GATT)) {
if (bt_mesh_proxy_prov_disable(false) == 0) {
pb_gatt_enabled = true;
} else {
pb_gatt_enabled = false;
}
} else {
pb_gatt_enabled = false;
}

/*
* FIXME:
* Should net_key and iv_index be over-ridden?
Expand Down Expand Up @@ -108,11 +98,6 @@ int bt_mesh_provision(const uint8_t net_key[16], uint16_t net_idx,
err = bt_mesh_net_create(net_idx, flags, net_key, iv_index);
if (err) {
atomic_clear_bit(bt_mesh.flags, BT_MESH_VALID);

if (IS_ENABLED(CONFIG_BT_MESH_PB_GATT) && pb_gatt_enabled) {
(void)bt_mesh_proxy_prov_enable();
}

return err;
}

Expand Down Expand Up @@ -197,7 +182,7 @@ void bt_mesh_reset(void)
}

if (IS_ENABLED(CONFIG_BT_MESH_GATT_PROXY)) {
bt_mesh_proxy_gatt_disable();
(void)bt_mesh_proxy_gatt_disable();
}

if (IS_ENABLED(CONFIG_BT_SETTINGS)) {
Expand Down Expand Up @@ -321,10 +306,6 @@ int bt_mesh_init(const struct bt_mesh_prov *prov,
return err;
}

if (IS_ENABLED(CONFIG_BT_MESH_GATT)) {
bt_mesh_proxy_init();
}

if (IS_ENABLED(CONFIG_BT_MESH_PROV)) {
err = bt_mesh_prov_init(prov);
if (err) {
Expand Down Expand Up @@ -370,10 +351,16 @@ int bt_mesh_start(void)
bt_mesh_beacon_disable();
}

if (IS_ENABLED(CONFIG_BT_MESH_GATT_PROXY) &&
bt_mesh_gatt_proxy_get() != BT_MESH_GATT_PROXY_NOT_SUPPORTED) {
bt_mesh_proxy_gatt_enable();
bt_mesh_adv_update();
if (!IS_ENABLED(CONFIG_BT_MESH_PROV) || !bt_mesh_prov_active() ||
bt_mesh_prov_link.bearer->type == BT_MESH_PROV_ADV) {
if (IS_ENABLED(CONFIG_BT_MESH_PB_GATT)) {
(void)bt_mesh_pb_gatt_disable();
}

if (IS_ENABLED(CONFIG_BT_MESH_GATT_PROXY)) {
(void)bt_mesh_proxy_gatt_enable();
bt_mesh_adv_update();
}
}

if (IS_ENABLED(CONFIG_BT_MESH_LOW_POWER)) {
Expand Down
6 changes: 2 additions & 4 deletions subsys/bluetooth/mesh/pb_gatt.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "adv.h"
#include "host/ecc.h"
#include "prov.h"
#include "pb_gatt_srv.h"

#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_MESH_DEBUG_PROV)
#define LOG_MODULE_NAME bt_mesh_pb_gatt
Expand All @@ -26,7 +27,6 @@ struct prov_link {
const struct prov_bearer_cb *cb;
void *cb_data;
struct prov_bearer_send_cb comp;
struct net_buf_simple *rx_buf;
struct k_work_delayable prot_timer;
};

Expand All @@ -41,8 +41,6 @@ static void reset_state(void)

/* If this fails, the protocol timeout handler will exit early. */
(void)k_work_cancel_delayable(&link.prot_timer);

link.rx_buf = bt_mesh_proxy_get_buf();
}

static void link_closed(enum prov_bearer_link_status status)
Expand Down Expand Up @@ -119,7 +117,7 @@ int bt_mesh_pb_gatt_close(struct bt_conn *conn)

static int link_accept(const struct prov_bearer_cb *cb, void *cb_data)
{
(void)bt_mesh_proxy_prov_enable();
(void)bt_mesh_pb_gatt_enable();
bt_mesh_adv_update();

link.cb = cb;
Expand Down
Loading