From e922f4fc9f23dfb3545a96ecd06caca89491aa82 Mon Sep 17 00:00:00 2001 From: Lingao Meng Date: Thu, 18 Nov 2021 10:13:03 +0800 Subject: [PATCH] Bluetooth: Mesh: Move common gatt adv to adv.c Since gatt adv send have common logic between adv_ext.c and adv_legacy.c, so move to adv.c Signed-off-by: Lingao Meng --- subsys/bluetooth/mesh/adv.c | 16 +++++++++++++ subsys/bluetooth/mesh/adv.h | 2 ++ subsys/bluetooth/mesh/adv_ext.c | 36 +++++++++--------------------- subsys/bluetooth/mesh/adv_legacy.c | 12 +--------- 4 files changed, 29 insertions(+), 37 deletions(-) diff --git a/subsys/bluetooth/mesh/adv.c b/subsys/bluetooth/mesh/adv.c index 78e0676fdbf..04fc7e40efb 100644 --- a/subsys/bluetooth/mesh/adv.c +++ b/subsys/bluetooth/mesh/adv.c @@ -26,6 +26,7 @@ #include "host/ecc.h" #include "prov.h" #include "proxy.h" +#include "pb_gatt_srv.h" /* Window and Interval are equal for continuous scanning */ #define MESH_SCAN_INTERVAL BT_MESH_ADV_SCAN_UNIT(BT_MESH_SCAN_INTERVAL_MS) @@ -195,6 +196,21 @@ void bt_mesh_adv_send(struct net_buf *buf, const struct bt_mesh_send_cb *cb, #endif /* CONFIG_BT_MESH_RELAY_ADV_SETS */ } +int bt_mesh_adv_gatt_send(void) +{ + if (bt_mesh_is_provisioned()) { + if (IS_ENABLED(CONFIG_BT_MESH_GATT_PROXY)) { + BT_DBG("Proxy Advertising"); + return bt_mesh_proxy_adv_start(); + } + } else if (IS_ENABLED(CONFIG_BT_MESH_PB_GATT)) { + BT_DBG("PB-GATT Advertising"); + return bt_mesh_pb_gatt_adv_start(); + } + + return -ENOTSUP; +} + static void bt_mesh_scan_cb(const bt_addr_le_t *addr, int8_t rssi, uint8_t adv_type, struct net_buf_simple *buf) { diff --git a/subsys/bluetooth/mesh/adv.h b/subsys/bluetooth/mesh/adv.h index b9588320fe4..c8e30306751 100644 --- a/subsys/bluetooth/mesh/adv.h +++ b/subsys/bluetooth/mesh/adv.h @@ -73,6 +73,8 @@ void bt_mesh_adv_buf_local_ready(void); void bt_mesh_adv_buf_relay_ready(void); +int bt_mesh_adv_gatt_send(void); + int bt_mesh_adv_gatt_start(const struct bt_le_adv_param *param, int32_t duration, const struct bt_data *ad, size_t ad_len, const struct bt_data *sd, size_t sd_len); diff --git a/subsys/bluetooth/mesh/adv_ext.c b/subsys/bluetooth/mesh/adv_ext.c index 5da626d3b2a..b75215605b0 100644 --- a/subsys/bluetooth/mesh/adv_ext.c +++ b/subsys/bluetooth/mesh/adv_ext.c @@ -22,7 +22,6 @@ #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 @@ -211,27 +210,6 @@ static int buf_send(struct ext_adv *adv, struct net_buf *buf) return err; } -#if defined(CONFIG_BT_MESH_GATT_SERVER) -static void gatt_server_adv_send(struct ext_adv *adv) -{ - int err; - - 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); - } -} -#endif /* CONFIG_BT_MESH_GATT_SERVER */ - static void send_pending_adv(struct k_work *work) { struct ext_adv *adv = CONTAINER_OF(work, struct ext_adv, work.work); @@ -257,9 +235,13 @@ static void send_pending_adv(struct k_work *work) } } - if (IS_ENABLED(CONFIG_BT_MESH_GATT_SERVER) && - adv == BT_MESH_ADV_EXT_GATT_SEPARATE_INS) { - gatt_server_adv_send(adv); + if (!IS_ENABLED(CONFIG_BT_MESH_GATT_SERVER) || + adv != BT_MESH_ADV_EXT_GATT_SEPARATE_INS) { + return; + } + + if (!bt_mesh_adv_gatt_send()) { + atomic_set_bit(adv->flags, ADV_FLAG_PROXY); } } @@ -268,7 +250,9 @@ static void send_pending_adv_gatt_handler(struct k_work *work) { struct ext_adv *adv = CONTAINER_OF(work, struct ext_adv, work.work); - gatt_server_adv_send(adv); + if (!bt_mesh_adv_gatt_send()) { + atomic_set_bit(adv->flags, ADV_FLAG_PROXY); + } } #endif /* CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE */ diff --git a/subsys/bluetooth/mesh/adv_legacy.c b/subsys/bluetooth/mesh/adv_legacy.c index 0318ecde1e6..1eee6951d08 100644 --- a/subsys/bluetooth/mesh/adv_legacy.c +++ b/subsys/bluetooth/mesh/adv_legacy.c @@ -27,8 +27,6 @@ #include "beacon.h" #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. @@ -138,15 +136,7 @@ static void adv_thread(void *p1, void *p2, void *p3) * to bt_mesh_adv_gatt_start: */ adv_timeout = SYS_FOREVER_MS; - 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"); - } + (void)bt_mesh_adv_gatt_send(); buf = bt_mesh_adv_buf_get(SYS_TIMEOUT_MS(adv_timeout)); bt_le_adv_stop();