Skip to content

Commit 2357d98

Browse files
committed
Dump BT payload in case of not supported codec
1 parent 3f1d695 commit 2357d98

File tree

7 files changed

+55
-26
lines changed

7 files changed

+55
-26
lines changed

.github/iwyu.imp

+3
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,11 @@
2929

3030
{ include: [ '<glib/gtypes.h>', private, '<glib.h>', public ] },
3131
{ include: [ '"gobject/gclosure.h"', private, '<glib-object.h>', public ] },
32+
{ include: [ '"gio/gdbusinterface.h"', private, '<gio/gio.h>', public ] },
3233
{ include: [ '"gio/gdbusinterfaceskeleton.h"', private, '<gio/gio.h>', public ] },
34+
{ include: [ '"gio/gdbusobject.h"', private, '<gio/gio.h>', public ] },
3335
{ include: [ '"gio/gdbusobjectmanager.h"', private, '<gio/gio.h>', public ] },
36+
{ include: [ '"gio/gdbusobjectmanagerclient.h"', private, '<gio/gio.h>', public ] },
3437
{ include: [ '"gio/gdbusobjectmanagerserver.h"', private, '<gio/gio.h>', public ] },
3538
{ include: [ '"gio/gdbusobjectskeleton.h"', private, '<gio/gio.h>', public ] },
3639

.github/workflows/codecov-report.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
working-directory: ${{ github.workspace }}/build
4747
run: make cov
4848
- name: Upload Coverage to Codecov
49-
uses: codecov/codecov-action@v4
49+
uses: codecov/codecov-action@v5
5050
with:
5151
token: ${{ secrets.CODECOV_TOKEN }}
5252
files: build/lcov.info

configure.ac

+8-8
Original file line numberDiff line numberDiff line change
@@ -220,22 +220,22 @@ AM_COND_IF([ENABLE_LDAC], [
220220
AC_DEFINE([ENABLE_LDAC], [1], [Define to 1 if LDAC is enabled.])
221221
])
222222

223-
AC_ARG_ENABLE([midi],
224-
[AS_HELP_STRING([--enable-midi], [enable Bluetooth LE MIDI support])])
225-
AM_CONDITIONAL([ENABLE_MIDI], [test "x$enable_midi" = "xyes"])
226-
AM_COND_IF([ENABLE_MIDI], [
227-
AC_DEFINE([ENABLE_MIDI], [1], [Define to 1 if Bluetooth LE MIDI is enabled.])
228-
])
229-
230223
AC_ARG_ENABLE([lhdc],
231224
[AS_HELP_STRING([--enable-lhdc], [enable LHDC support])])
232225
AM_CONDITIONAL([ENABLE_LHDC], [test "x$enable_lhdc" = "xyes"])
233226
AM_COND_IF([ENABLE_LHDC], [
234227
AC_DEFINE([ENABLE_LHDC], [1], [Define to 1 if LHDC is enabled.])
235-
PKG_CHECK_MODULES([LHDC_DEC], [ldhcBT-dec >= 4.0.2])
228+
PKG_CHECK_MODULES([LHDC_DEC], [lhdcBT-dec >= 4.0.2])
236229
PKG_CHECK_MODULES([LHDC_ENC], [lhdcBT-enc >= 4.0.6])
237230
])
238231

232+
AC_ARG_ENABLE([midi],
233+
[AS_HELP_STRING([--enable-midi], [enable Bluetooth LE MIDI support])])
234+
AM_CONDITIONAL([ENABLE_MIDI], [test "x$enable_midi" = "xyes"])
235+
AM_COND_IF([ENABLE_MIDI], [
236+
AC_DEFINE([ENABLE_MIDI], [1], [Define to 1 if Bluetooth LE MIDI is enabled.])
237+
])
238+
239239
AC_ARG_ENABLE([mp3lame],
240240
[AS_HELP_STRING([--enable-mp3lame], [enable MP3 support])])
241241
AM_CONDITIONAL([ENABLE_MP3LAME], [test "x$enable_mp3lame" = "xyes"])

src/bluez.c

+8-6
Original file line numberDiff line numberDiff line change
@@ -359,13 +359,14 @@ static const char *bluez_get_media_endpoint_object_path(
359359
static char path[64];
360360

361361
const char *tmp;
362-
if ((tmp = a2dp_codecs_codec_id_to_string(sep->config.codec_id)) == NULL)
363-
g_assert_not_reached();
364-
365362
char codec_name[16] = "";
366-
for (size_t i = 0, j = 0; tmp[i] != '\0' && j < sizeof(codec_name); i++)
367-
if (isupper(tmp[i]) || islower(tmp[i]) || isdigit(tmp[i]))
368-
codec_name[j++] = tmp[i];
363+
if ((tmp = a2dp_codecs_codec_id_to_string(sep->config.codec_id)) == NULL)
364+
snprintf(codec_name, sizeof(codec_name), "%08x", sep->config.codec_id);
365+
else {
366+
for (size_t i = 0, j = 0; tmp[i] != '\0' && j < sizeof(codec_name); i++)
367+
if (isupper(tmp[i]) || islower(tmp[i]) || isdigit(tmp[i]))
368+
codec_name[j++] = tmp[i];
369+
}
369370

370371
snprintf(path, sizeof(path), "/org/bluez/%s/A2DP/%s/%s/%u", adapter->hci.name,
371372
codec_name, sep->config.type == A2DP_SOURCE ? "source" : "sink", index);
@@ -1367,6 +1368,7 @@ static void bluez_signal_interfaces_added(GDBusConnection *conn, const char *sen
13671368
debug("Adding new Stream End-Point: %s: %s: %s",
13681369
batostr_(&addr), sep_cfg.type == A2DP_SOURCE ? "SRC" : "SNK",
13691370
a2dp_codecs_codec_id_to_string(sep_cfg.codec_id));
1371+
hexdump("SEP capabilities blob", &sep_cfg.capabilities, sep_cfg.caps_size);
13701372

13711373
GArray *sep_cfgs = bluez_adapter_get_device_sep_configs(&bluez_adapters[dev_id], &addr);
13721374
g_array_append_val(sep_cfgs, sep_cfg);

src/shared/a2dp-codecs.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ static const struct {
3434
{ A2DP_CODEC_VENDOR_ID(LC3PLUS_VENDOR_ID, LC3PLUS_CODEC_ID), { "LC3plus" } },
3535
{ A2DP_CODEC_VENDOR_ID(LDAC_VENDOR_ID, LDAC_CODEC_ID), { "LDAC" } },
3636
{ A2DP_CODEC_VENDOR_ID(LHDC_V1_VENDOR_ID, LHDC_V1_CODEC_ID), { "LHDC-v1" } },
37-
{ A2DP_CODEC_VENDOR_ID(LHDC_V2_VENDOR_ID, LHDC_V2_CODEC_ID), { "LHDC-V2" } },
38-
{ A2DP_CODEC_VENDOR_ID(LHDC_V3_VENDOR_ID, LHDC_V3_CODEC_ID), { "LHDC-V3", "LHDC-V4", "LLAC" } },
39-
{ A2DP_CODEC_VENDOR_ID(LHDC_V5_VENDOR_ID, LHDC_V5_CODEC_ID), { "LHDC-V5" } },
37+
{ A2DP_CODEC_VENDOR_ID(LHDC_V2_VENDOR_ID, LHDC_V2_CODEC_ID), { "LHDC-v2" } },
38+
{ A2DP_CODEC_VENDOR_ID(LHDC_V3_VENDOR_ID, LHDC_V3_CODEC_ID), { "LHDC-v3", "LHDC-v4", "LLAC" } },
39+
{ A2DP_CODEC_VENDOR_ID(LHDC_V5_VENDOR_ID, LHDC_V5_CODEC_ID), { "LHDC-v5" } },
4040
{ A2DP_CODEC_VENDOR_ID(LHDC_LL_VENDOR_ID, LHDC_LL_CODEC_ID), { "LHDC-LL"} },
4141
{ A2DP_CODEC_VENDOR_ID(OPUS_VENDOR_ID, OPUS_CODEC_ID), { "Opus"} },
4242
{ A2DP_CODEC_VENDOR_ID(OPUS_PW_VENDOR_ID, OPUS_PW_CODEC_ID), { "Opus-PW"} },

test/inc/btd.inc

+16-6
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ ssize_t bt_dump_write(struct bt_dump *btd, const void *data, size_t size) {
8383
/**
8484
* Close BT dump file. */
8585
void bt_dump_close(struct bt_dump *btd) {
86+
if (btd == NULL)
87+
return;
8688
if (btd->file != NULL)
8789
fclose(btd->file);
8890
free(btd);
@@ -203,41 +205,49 @@ fail:
203205

204206
static const char *transport_to_fname(const struct ba_transport *t) {
205207

208+
const uint32_t codec_id = ba_transport_get_codec(t);
206209
const char *profile = NULL;
207210
const char *codec = NULL;
211+
208212
switch (t->profile) {
209213
case BA_TRANSPORT_PROFILE_NONE:
210214
return "none";
211215
case BA_TRANSPORT_PROFILE_A2DP_SOURCE:
212216
profile = "a2dp-source";
213-
codec = a2dp_codecs_codec_id_to_string(ba_transport_get_codec(t));
217+
codec = a2dp_codecs_codec_id_to_string(codec_id);
214218
break;
215219
case BA_TRANSPORT_PROFILE_A2DP_SINK:
216220
profile = "a2dp-sink";
217-
codec = a2dp_codecs_codec_id_to_string(ba_transport_get_codec(t));
221+
codec = a2dp_codecs_codec_id_to_string(codec_id);
218222
break;
219223
case BA_TRANSPORT_PROFILE_HFP_AG:
220224
profile = "hfp-ag";
221-
codec = hfp_codec_id_to_string(ba_transport_get_codec(t));
225+
codec = hfp_codec_id_to_string(codec_id);
222226
break;
223227
case BA_TRANSPORT_PROFILE_HFP_HF:
224228
profile = "hfp-hf";
225-
codec = hfp_codec_id_to_string(ba_transport_get_codec(t));
229+
codec = hfp_codec_id_to_string(codec_id);
226230
break;
227231
case BA_TRANSPORT_PROFILE_HSP_AG:
228232
profile = "hsp-ag";
229-
codec = hfp_codec_id_to_string(ba_transport_get_codec(t));
233+
codec = hfp_codec_id_to_string(codec_id);
230234
break;
231235
case BA_TRANSPORT_PROFILE_HSP_HS:
232236
profile = "hsp-hs";
233-
codec = hfp_codec_id_to_string(ba_transport_get_codec(t));
237+
codec = hfp_codec_id_to_string(codec_id);
234238
break;
235239
#if ENABLE_MIDI
236240
case BA_TRANSPORT_PROFILE_MIDI:
237241
return "midi";
238242
#endif
239243
}
240244

245+
char fallback[16];
246+
if (codec == NULL) {
247+
snprintf(fallback, sizeof(fallback), "%08x", codec_id);
248+
codec = fallback;
249+
}
250+
241251
static char buffer[64];
242252
snprintf(buffer, sizeof(buffer), "%s-%s", profile, codec);
243253
return buffer;

test/test-io.c

+16-2
Original file line numberDiff line numberDiff line change
@@ -531,9 +531,13 @@ static void bt_data_write(struct ba_transport *t) {
531531

532532
static pthread_cond_t test_terminate = PTHREAD_COND_INITIALIZER;
533533
static pthread_mutex_t test_mutex = PTHREAD_MUTEX_INITIALIZER;
534+
static bool test_terminated = false;
534535

535536
static void *test_terminate_timer(void *arg) {
536537
sleep((uintptr_t)arg);
538+
pthread_mutex_lock(&test_mutex);
539+
test_terminated = true;
540+
pthread_mutex_unlock(&test_mutex);
537541
pthread_cond_signal(&test_terminate);
538542
return NULL;
539543
}
@@ -704,7 +708,8 @@ static void test_io(
704708
}
705709

706710
pthread_mutex_lock(&test_mutex);
707-
pthread_cond_wait(&test_terminate, &test_mutex);
711+
while (!test_terminated)
712+
pthread_cond_wait(&test_terminate, &test_mutex);
708713
pthread_mutex_unlock(&test_mutex);
709714

710715
pthread_mutex_lock(&t_src_pcm->mutex);
@@ -1588,9 +1593,17 @@ int main(int argc, char *argv[]) {
15881593

15891594
enabled_codecs = 0;
15901595
for (size_t i = 0; i < ARRAYSIZE(codecs); i++)
1591-
if (strcmp(codec, codecs[i].name) == 0)
1596+
if (codec != NULL && strcmp(codec, codecs[i].name) == 0)
15921597
enabled_codecs |= 1 << i;
15931598

1599+
/* If we do not have a test case for the codec, dump the data here. */
1600+
if (enabled_codecs == 0) {
1601+
ssize_t len;
1602+
char buffer[4096];
1603+
while ((len = bt_dump_read(btdin, buffer, sizeof(buffer))) != -1)
1604+
hexdump("BT data", buffer, len);
1605+
}
1606+
15941607
}
15951608

15961609
ba_config_init();
@@ -1622,6 +1635,7 @@ int main(int argc, char *argv[]) {
16221635
ba_device_unref(device1);
16231636
ba_device_unref(device2);
16241637
ba_adapter_unref(adapter);
1638+
bt_dump_close(btdin);
16251639

16261640
return nf == 0 ? 0 : 1;
16271641
}

0 commit comments

Comments
 (0)