Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

samples: Bluetooth: Audio: Find device regardless of name type #79505

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions samples/bluetooth/bap_broadcast_sink/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1194,14 +1194,21 @@ static bool is_substring(const char *substr, const char *str)

static bool data_cb(struct bt_data *data, void *user_data)
{
char *name = user_data;
bool *device_found = user_data;
char name[NAME_LEN] = {0};

switch (data->type) {
case BT_DATA_NAME_SHORTENED:
case BT_DATA_NAME_COMPLETE:
case BT_DATA_BROADCAST_NAME:
memcpy(name, data->data, MIN(data->data_len, NAME_LEN - 1));
return false;

if (is_substring(CONFIG_TARGET_BROADCAST_NAME, name)) {
/* Device found */
*device_found = true;
return false;
}
return true;
default:
return true;
}
Expand All @@ -1217,12 +1224,13 @@ static void broadcast_scan_recv(const struct bt_le_scan_recv_info *info, struct
* our own broadcast name filter.
*/
if (req_recv_state == NULL && strlen(CONFIG_TARGET_BROADCAST_NAME) > 0U) {
bool device_found = false;
struct net_buf_simple buf_copy;
char name[NAME_LEN] = {0};

net_buf_simple_clone(ad, &buf_copy);
bt_data_parse(&buf_copy, data_cb, name);
if (!(is_substring(CONFIG_TARGET_BROADCAST_NAME, name))) {
bt_data_parse(&buf_copy, data_cb, &device_found);

if (!device_found) {
Thalley marked this conversation as resolved.
Show resolved Hide resolved
return;
}
}
Expand Down
Loading