diff --git a/subsys/bluetooth/host/CMakeLists.txt b/subsys/bluetooth/host/CMakeLists.txt index e67f7181798..a9810c8af32 100644 --- a/subsys/bluetooth/host/CMakeLists.txt +++ b/subsys/bluetooth/host/CMakeLists.txt @@ -34,6 +34,7 @@ if(CONFIG_BT_HCI_HOST) uuid.c addr.c buf.c + data.c hci_core.c hci_common.c id.c diff --git a/subsys/bluetooth/host/data.c b/subsys/bluetooth/host/data.c new file mode 100644 index 00000000000..151dba18129 --- /dev/null +++ b/subsys/bluetooth/host/data.c @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2017-2021 Nordic Semiconductor ASA + * Copyright (c) 2015-2016 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +#define LOG_LEVEL CONFIG_BT_HCI_CORE_LOG_LEVEL +#include +LOG_MODULE_REGISTER(bt_data); + +void bt_data_parse(struct net_buf_simple *ad, + bool (*func)(struct bt_data *data, void *user_data), + void *user_data) +{ + while (ad->len > 1) { + struct bt_data data; + uint8_t len; + + len = net_buf_simple_pull_u8(ad); + if (len == 0U) { + /* Early termination */ + return; + } + + if (len > ad->len) { + LOG_WRN("malformed advertising data %u / %u", + len, ad->len); + return; + } + + data.type = net_buf_simple_pull_u8(ad); + data.data_len = len - 1; + data.data = ad->data; + + if (!func(&data, user_data)) { + return; + } + + net_buf_simple_pull(ad, len - 1); + } +} diff --git a/subsys/bluetooth/host/hci_core.c b/subsys/bluetooth/host/hci_core.c index 45509edb17a..465e454e806 100644 --- a/subsys/bluetooth/host/hci_core.c +++ b/subsys/bluetooth/host/hci_core.c @@ -4059,38 +4059,6 @@ int bt_le_set_rpa_timeout(uint16_t new_rpa_timeout) } #endif -void bt_data_parse(struct net_buf_simple *ad, - bool (*func)(struct bt_data *data, void *user_data), - void *user_data) -{ - while (ad->len > 1) { - struct bt_data data; - uint8_t len; - - len = net_buf_simple_pull_u8(ad); - if (len == 0U) { - /* Early termination */ - return; - } - - if (len > ad->len) { - LOG_WRN("malformed advertising data %u / %u", - len, ad->len); - return; - } - - data.type = net_buf_simple_pull_u8(ad); - data.data_len = len - 1; - data.data = ad->data; - - if (!func(&data, user_data)) { - return; - } - - net_buf_simple_pull(ad, len - 1); - } -} - int bt_configure_data_path(uint8_t dir, uint8_t id, uint8_t vs_config_len, const uint8_t *vs_config) {