Skip to content

Commit 23554b0

Browse files
joerchanjhedberg
authored andcommitted
Bluetooth: host: Fix whitelist for non-central bluetooth applications
Fix compilation issue when wanting to use whitelist in bluetooth applications that does not have CONFIG_BT_CENTRAL defined. These functions are useful even for broadcaster and observer roles. Signed-off-by: Joakim Andersson <[email protected]>
1 parent 5229276 commit 23554b0

File tree

2 files changed

+69
-67
lines changed

2 files changed

+69
-67
lines changed

subsys/bluetooth/host/conn.c

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -2008,73 +2008,6 @@ static void bt_conn_set_param_le(struct bt_conn *conn,
20082008
}
20092009

20102010
#if defined(CONFIG_BT_WHITELIST)
2011-
int bt_le_whitelist_add(const bt_addr_le_t *addr)
2012-
{
2013-
struct bt_hci_cp_le_add_dev_to_wl *cp;
2014-
struct net_buf *buf;
2015-
int err;
2016-
2017-
if (!(bt_dev.le.wl_entries < bt_dev.le.wl_size)) {
2018-
return -ENOMEM;
2019-
}
2020-
2021-
buf = bt_hci_cmd_create(BT_HCI_OP_LE_ADD_DEV_TO_WL, sizeof(*cp));
2022-
if (!buf) {
2023-
return -ENOBUFS;
2024-
}
2025-
2026-
cp = net_buf_add(buf, sizeof(*cp));
2027-
bt_addr_le_copy(&cp->addr, addr);
2028-
2029-
err = bt_hci_cmd_send_sync(BT_HCI_OP_LE_ADD_DEV_TO_WL, buf, NULL);
2030-
if (err) {
2031-
BT_ERR("Failed to add device to whitelist");
2032-
2033-
return err;
2034-
}
2035-
2036-
bt_dev.le.wl_entries++;
2037-
2038-
return 0;
2039-
}
2040-
2041-
int bt_le_whitelist_rem(const bt_addr_le_t *addr)
2042-
{
2043-
struct bt_hci_cp_le_rem_dev_from_wl *cp;
2044-
struct net_buf *buf;
2045-
int err;
2046-
2047-
buf = bt_hci_cmd_create(BT_HCI_OP_LE_REM_DEV_FROM_WL, sizeof(*cp));
2048-
if (!buf) {
2049-
return -ENOBUFS;
2050-
}
2051-
2052-
cp = net_buf_add(buf, sizeof(*cp));
2053-
bt_addr_le_copy(&cp->addr, addr);
2054-
2055-
err = bt_hci_cmd_send_sync(BT_HCI_OP_LE_REM_DEV_FROM_WL, buf, NULL);
2056-
if (err) {
2057-
BT_ERR("Failed to remove device from whitelist");
2058-
return err;
2059-
}
2060-
2061-
bt_dev.le.wl_entries--;
2062-
return 0;
2063-
}
2064-
2065-
int bt_le_whitelist_clear(void)
2066-
{
2067-
int err = bt_hci_cmd_send_sync(BT_HCI_OP_LE_CLEAR_WL, NULL, NULL);
2068-
2069-
if (err) {
2070-
BT_ERR("Failed to clear whitelist");
2071-
return err;
2072-
}
2073-
2074-
bt_dev.le.wl_entries = 0;
2075-
return 0;
2076-
}
2077-
20782011
int bt_conn_create_auto_le(const struct bt_le_conn_param *param)
20792012
{
20802013
struct bt_conn *conn;

subsys/bluetooth/host/hci_core.c

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5896,6 +5896,75 @@ int bt_le_scan_stop(void)
58965896
}
58975897
#endif /* CONFIG_BT_OBSERVER */
58985898

5899+
#if defined(CONFIG_BT_WHITELIST)
5900+
int bt_le_whitelist_add(const bt_addr_le_t *addr)
5901+
{
5902+
struct bt_hci_cp_le_add_dev_to_wl *cp;
5903+
struct net_buf *buf;
5904+
int err;
5905+
5906+
if (!(bt_dev.le.wl_entries < bt_dev.le.wl_size)) {
5907+
return -ENOMEM;
5908+
}
5909+
5910+
buf = bt_hci_cmd_create(BT_HCI_OP_LE_ADD_DEV_TO_WL, sizeof(*cp));
5911+
if (!buf) {
5912+
return -ENOBUFS;
5913+
}
5914+
5915+
cp = net_buf_add(buf, sizeof(*cp));
5916+
bt_addr_le_copy(&cp->addr, addr);
5917+
5918+
err = bt_hci_cmd_send_sync(BT_HCI_OP_LE_ADD_DEV_TO_WL, buf, NULL);
5919+
if (err) {
5920+
BT_ERR("Failed to add device to whitelist");
5921+
5922+
return err;
5923+
}
5924+
5925+
bt_dev.le.wl_entries++;
5926+
5927+
return 0;
5928+
}
5929+
5930+
int bt_le_whitelist_rem(const bt_addr_le_t *addr)
5931+
{
5932+
struct bt_hci_cp_le_rem_dev_from_wl *cp;
5933+
struct net_buf *buf;
5934+
int err;
5935+
5936+
buf = bt_hci_cmd_create(BT_HCI_OP_LE_REM_DEV_FROM_WL, sizeof(*cp));
5937+
if (!buf) {
5938+
return -ENOBUFS;
5939+
}
5940+
5941+
cp = net_buf_add(buf, sizeof(*cp));
5942+
bt_addr_le_copy(&cp->addr, addr);
5943+
5944+
err = bt_hci_cmd_send_sync(BT_HCI_OP_LE_REM_DEV_FROM_WL, buf, NULL);
5945+
if (err) {
5946+
BT_ERR("Failed to remove device from whitelist");
5947+
return err;
5948+
}
5949+
5950+
bt_dev.le.wl_entries--;
5951+
return 0;
5952+
}
5953+
5954+
int bt_le_whitelist_clear(void)
5955+
{
5956+
int err = bt_hci_cmd_send_sync(BT_HCI_OP_LE_CLEAR_WL, NULL, NULL);
5957+
5958+
if (err) {
5959+
BT_ERR("Failed to clear whitelist");
5960+
return err;
5961+
}
5962+
5963+
bt_dev.le.wl_entries = 0;
5964+
return 0;
5965+
}
5966+
#endif /* defined(CONFIG_BT_WHITELIST) */
5967+
58995968
int bt_le_set_chan_map(u8_t chan_map[5])
59005969
{
59015970
struct bt_hci_cp_le_set_host_chan_classif *cp;

0 commit comments

Comments
 (0)