From 5f98b1bea49e0c38c9e85c168482db067b78fa05 Mon Sep 17 00:00:00 2001 From: Jonathan Rico Date: Fri, 16 Dec 2022 09:06:35 +0100 Subject: [PATCH] Bluetooth: host: adv: add `adv_is_directed` helper Makes it more readable. Signed-off-by: Jonathan Rico --- subsys/bluetooth/host/adv.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/subsys/bluetooth/host/adv.c b/subsys/bluetooth/host/adv.c index 7901baf78af..b43205ebab6 100644 --- a/subsys/bluetooth/host/adv.c +++ b/subsys/bluetooth/host/adv.c @@ -900,6 +900,14 @@ static uint8_t get_adv_channel_map(uint32_t options) return channel_map; } +static inline bool adv_is_directed(const struct bt_le_ext_adv *adv) +{ + /* The advertiser is assumed to be directed when the peer address has + * been set. + */ + return !bt_addr_le_eq(&adv->target_addr, BT_ADDR_LE_ANY); +} + static int le_adv_start_add_conn(const struct bt_le_ext_adv *adv, struct bt_conn **out_conn) { @@ -907,7 +915,7 @@ static int le_adv_start_add_conn(const struct bt_le_ext_adv *adv, bt_dev.adv_conn_id = adv->id; - if (bt_addr_le_eq(&adv->target_addr, BT_ADDR_LE_ANY)) { + if (!adv_is_directed(adv)) { /* Undirected advertising */ conn = bt_conn_add_le(adv->id, BT_ADDR_LE_NONE); if (!conn) { @@ -937,7 +945,7 @@ static void le_adv_stop_free_conn(const struct bt_le_ext_adv *adv, uint8_t statu { struct bt_conn *conn; - if (bt_addr_le_eq(&adv->target_addr, BT_ADDR_LE_ANY)) { + if (!adv_is_directed(adv)) { conn = bt_conn_lookup_state_le(adv->id, BT_ADDR_LE_NONE, BT_CONN_CONNECTING_ADV); } else {