Skip to content

Commit

Permalink
Dump BT payload in case of not supported codec
Browse files Browse the repository at this point in the history
  • Loading branch information
arkq committed Dec 8, 2024
1 parent 3f1d695 commit 2357d98
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 26 deletions.
3 changes: 3 additions & 0 deletions .github/iwyu.imp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@

{ include: [ '<glib/gtypes.h>', private, '<glib.h>', public ] },
{ include: [ '"gobject/gclosure.h"', private, '<glib-object.h>', public ] },
{ include: [ '"gio/gdbusinterface.h"', private, '<gio/gio.h>', public ] },
{ include: [ '"gio/gdbusinterfaceskeleton.h"', private, '<gio/gio.h>', public ] },
{ include: [ '"gio/gdbusobject.h"', private, '<gio/gio.h>', public ] },
{ include: [ '"gio/gdbusobjectmanager.h"', private, '<gio/gio.h>', public ] },
{ include: [ '"gio/gdbusobjectmanagerclient.h"', private, '<gio/gio.h>', public ] },
{ include: [ '"gio/gdbusobjectmanagerserver.h"', private, '<gio/gio.h>', public ] },
{ include: [ '"gio/gdbusobjectskeleton.h"', private, '<gio/gio.h>', public ] },

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codecov-report.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
working-directory: ${{ github.workspace }}/build
run: make cov
- name: Upload Coverage to Codecov
uses: codecov/codecov-action@v4
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: build/lcov.info
16 changes: 8 additions & 8 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -220,22 +220,22 @@ AM_COND_IF([ENABLE_LDAC], [
AC_DEFINE([ENABLE_LDAC], [1], [Define to 1 if LDAC is enabled.])
])

AC_ARG_ENABLE([midi],
[AS_HELP_STRING([--enable-midi], [enable Bluetooth LE MIDI support])])
AM_CONDITIONAL([ENABLE_MIDI], [test "x$enable_midi" = "xyes"])
AM_COND_IF([ENABLE_MIDI], [
AC_DEFINE([ENABLE_MIDI], [1], [Define to 1 if Bluetooth LE MIDI is enabled.])
])

AC_ARG_ENABLE([lhdc],
[AS_HELP_STRING([--enable-lhdc], [enable LHDC support])])
AM_CONDITIONAL([ENABLE_LHDC], [test "x$enable_lhdc" = "xyes"])
AM_COND_IF([ENABLE_LHDC], [
AC_DEFINE([ENABLE_LHDC], [1], [Define to 1 if LHDC is enabled.])
PKG_CHECK_MODULES([LHDC_DEC], [ldhcBT-dec >= 4.0.2])
PKG_CHECK_MODULES([LHDC_DEC], [lhdcBT-dec >= 4.0.2])
PKG_CHECK_MODULES([LHDC_ENC], [lhdcBT-enc >= 4.0.6])
])

AC_ARG_ENABLE([midi],
[AS_HELP_STRING([--enable-midi], [enable Bluetooth LE MIDI support])])
AM_CONDITIONAL([ENABLE_MIDI], [test "x$enable_midi" = "xyes"])
AM_COND_IF([ENABLE_MIDI], [
AC_DEFINE([ENABLE_MIDI], [1], [Define to 1 if Bluetooth LE MIDI is enabled.])
])

AC_ARG_ENABLE([mp3lame],
[AS_HELP_STRING([--enable-mp3lame], [enable MP3 support])])
AM_CONDITIONAL([ENABLE_MP3LAME], [test "x$enable_mp3lame" = "xyes"])
Expand Down
14 changes: 8 additions & 6 deletions src/bluez.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,13 +359,14 @@ static const char *bluez_get_media_endpoint_object_path(
static char path[64];

const char *tmp;
if ((tmp = a2dp_codecs_codec_id_to_string(sep->config.codec_id)) == NULL)
g_assert_not_reached();

char codec_name[16] = "";
for (size_t i = 0, j = 0; tmp[i] != '\0' && j < sizeof(codec_name); i++)
if (isupper(tmp[i]) || islower(tmp[i]) || isdigit(tmp[i]))
codec_name[j++] = tmp[i];
if ((tmp = a2dp_codecs_codec_id_to_string(sep->config.codec_id)) == NULL)
snprintf(codec_name, sizeof(codec_name), "%08x", sep->config.codec_id);
else {
for (size_t i = 0, j = 0; tmp[i] != '\0' && j < sizeof(codec_name); i++)
if (isupper(tmp[i]) || islower(tmp[i]) || isdigit(tmp[i]))
codec_name[j++] = tmp[i];
}

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

GArray *sep_cfgs = bluez_adapter_get_device_sep_configs(&bluez_adapters[dev_id], &addr);
g_array_append_val(sep_cfgs, sep_cfg);
Expand Down
6 changes: 3 additions & 3 deletions src/shared/a2dp-codecs.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ static const struct {
{ A2DP_CODEC_VENDOR_ID(LC3PLUS_VENDOR_ID, LC3PLUS_CODEC_ID), { "LC3plus" } },
{ A2DP_CODEC_VENDOR_ID(LDAC_VENDOR_ID, LDAC_CODEC_ID), { "LDAC" } },
{ A2DP_CODEC_VENDOR_ID(LHDC_V1_VENDOR_ID, LHDC_V1_CODEC_ID), { "LHDC-v1" } },
{ A2DP_CODEC_VENDOR_ID(LHDC_V2_VENDOR_ID, LHDC_V2_CODEC_ID), { "LHDC-V2" } },
{ A2DP_CODEC_VENDOR_ID(LHDC_V3_VENDOR_ID, LHDC_V3_CODEC_ID), { "LHDC-V3", "LHDC-V4", "LLAC" } },
{ A2DP_CODEC_VENDOR_ID(LHDC_V5_VENDOR_ID, LHDC_V5_CODEC_ID), { "LHDC-V5" } },
{ A2DP_CODEC_VENDOR_ID(LHDC_V2_VENDOR_ID, LHDC_V2_CODEC_ID), { "LHDC-v2" } },
{ A2DP_CODEC_VENDOR_ID(LHDC_V3_VENDOR_ID, LHDC_V3_CODEC_ID), { "LHDC-v3", "LHDC-v4", "LLAC" } },
{ A2DP_CODEC_VENDOR_ID(LHDC_V5_VENDOR_ID, LHDC_V5_CODEC_ID), { "LHDC-v5" } },
{ A2DP_CODEC_VENDOR_ID(LHDC_LL_VENDOR_ID, LHDC_LL_CODEC_ID), { "LHDC-LL"} },
{ A2DP_CODEC_VENDOR_ID(OPUS_VENDOR_ID, OPUS_CODEC_ID), { "Opus"} },
{ A2DP_CODEC_VENDOR_ID(OPUS_PW_VENDOR_ID, OPUS_PW_CODEC_ID), { "Opus-PW"} },
Expand Down
22 changes: 16 additions & 6 deletions test/inc/btd.inc
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ ssize_t bt_dump_write(struct bt_dump *btd, const void *data, size_t size) {
/**
* Close BT dump file. */
void bt_dump_close(struct bt_dump *btd) {
if (btd == NULL)
return;
if (btd->file != NULL)
fclose(btd->file);
free(btd);
Expand Down Expand Up @@ -203,41 +205,49 @@ fail:

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

const uint32_t codec_id = ba_transport_get_codec(t);
const char *profile = NULL;
const char *codec = NULL;

switch (t->profile) {
case BA_TRANSPORT_PROFILE_NONE:
return "none";
case BA_TRANSPORT_PROFILE_A2DP_SOURCE:
profile = "a2dp-source";
codec = a2dp_codecs_codec_id_to_string(ba_transport_get_codec(t));
codec = a2dp_codecs_codec_id_to_string(codec_id);
break;
case BA_TRANSPORT_PROFILE_A2DP_SINK:
profile = "a2dp-sink";
codec = a2dp_codecs_codec_id_to_string(ba_transport_get_codec(t));
codec = a2dp_codecs_codec_id_to_string(codec_id);
break;
case BA_TRANSPORT_PROFILE_HFP_AG:
profile = "hfp-ag";
codec = hfp_codec_id_to_string(ba_transport_get_codec(t));
codec = hfp_codec_id_to_string(codec_id);
break;
case BA_TRANSPORT_PROFILE_HFP_HF:
profile = "hfp-hf";
codec = hfp_codec_id_to_string(ba_transport_get_codec(t));
codec = hfp_codec_id_to_string(codec_id);
break;
case BA_TRANSPORT_PROFILE_HSP_AG:
profile = "hsp-ag";
codec = hfp_codec_id_to_string(ba_transport_get_codec(t));
codec = hfp_codec_id_to_string(codec_id);
break;
case BA_TRANSPORT_PROFILE_HSP_HS:
profile = "hsp-hs";
codec = hfp_codec_id_to_string(ba_transport_get_codec(t));
codec = hfp_codec_id_to_string(codec_id);
break;
#if ENABLE_MIDI
case BA_TRANSPORT_PROFILE_MIDI:
return "midi";
#endif
}

char fallback[16];
if (codec == NULL) {
snprintf(fallback, sizeof(fallback), "%08x", codec_id);
codec = fallback;
}

static char buffer[64];
snprintf(buffer, sizeof(buffer), "%s-%s", profile, codec);
return buffer;
Expand Down
18 changes: 16 additions & 2 deletions test/test-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -531,9 +531,13 @@ static void bt_data_write(struct ba_transport *t) {

static pthread_cond_t test_terminate = PTHREAD_COND_INITIALIZER;
static pthread_mutex_t test_mutex = PTHREAD_MUTEX_INITIALIZER;
static bool test_terminated = false;

static void *test_terminate_timer(void *arg) {
sleep((uintptr_t)arg);
pthread_mutex_lock(&test_mutex);
test_terminated = true;
pthread_mutex_unlock(&test_mutex);
pthread_cond_signal(&test_terminate);
return NULL;
}
Expand Down Expand Up @@ -704,7 +708,8 @@ static void test_io(
}

pthread_mutex_lock(&test_mutex);
pthread_cond_wait(&test_terminate, &test_mutex);
while (!test_terminated)
pthread_cond_wait(&test_terminate, &test_mutex);
pthread_mutex_unlock(&test_mutex);

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

enabled_codecs = 0;
for (size_t i = 0; i < ARRAYSIZE(codecs); i++)
if (strcmp(codec, codecs[i].name) == 0)
if (codec != NULL && strcmp(codec, codecs[i].name) == 0)
enabled_codecs |= 1 << i;

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

}

ba_config_init();
Expand Down Expand Up @@ -1622,6 +1635,7 @@ int main(int argc, char *argv[]) {
ba_device_unref(device1);
ba_device_unref(device2);
ba_adapter_unref(adapter);
bt_dump_close(btdin);

return nf == 0 ? 0 : 1;
}

0 comments on commit 2357d98

Please sign in to comment.