Bluetooth: Move bt_data_parse to dedicated source file

This moves bt_data_parse function outside of hci_core.c.
Having it in separate file makes unit testing easier as the
function do not use kernel objects, thus can be used in unit tests
without a need for adding any mocks.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
This commit is contained in:
Mariusz Skamra 2023-03-15 15:21:33 +01:00 committed by Carles Cufí
commit 871db2d277
3 changed files with 46 additions and 32 deletions

View file

@ -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

View file

@ -0,0 +1,45 @@
/*
* Copyright (c) 2017-2021 Nordic Semiconductor ASA
* Copyright (c) 2015-2016 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/kernel.h>
#include <zephyr/bluetooth/bluetooth.h>
#define LOG_LEVEL CONFIG_BT_HCI_CORE_LOG_LEVEL
#include <zephyr/logging/log.h>
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);
}
}

View file

@ -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)
{