Skip to content

Commit

Permalink
Apply SCO MTU workaround only for USB adapters
Browse files Browse the repository at this point in the history
Closes #512
  • Loading branch information
borine authored and arkq committed Nov 16, 2021
1 parent 7719ae9 commit ac5706f
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/ba-transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ static int transport_acquire_bt_sco(struct ba_transport *t) {

debug("New SCO link: %s: %d", batostr_(&d->addr), fd);

t->mtu_read = t->mtu_write = hci_sco_get_mtu(fd);
t->mtu_read = t->mtu_write = hci_sco_get_mtu(fd, d->a->hci.type);
t->bt_fd = fd;

return fd;
Expand Down
17 changes: 10 additions & 7 deletions src/hci.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,10 @@ int hci_sco_connect(int sco_fd, const bdaddr_t *ba, uint16_t voice) {
* Get read/write MTU for given SCO socket.
*
* @param sco_fd File descriptor of opened SCO socket.
* @param hci_type The type of the HCI returned by hci_devinfo().
* @return On success this function returns MTU value. Otherwise, 0 is returned and
* errno is set to indicate the error. */
unsigned int hci_sco_get_mtu(int sco_fd) {
unsigned int hci_sco_get_mtu(int sco_fd, int hci_type) {

struct sco_options options = { 0 };
struct bt_voice voice = { 0 };
Expand All @@ -131,12 +132,14 @@ unsigned int hci_sco_get_mtu(int sco_fd) {

debug("SCO link socket MTU: %d: %u", sco_fd, options.mtu);

/* XXX: It seems, that the MTU value returned by kernel
* is incorrect (or our interpretation of it). */

options.mtu = 48;
if (voice.setting == BT_VOICE_TRANSPARENT)
options.mtu = 24;
/* XXX: It seems, that the MTU value returned by kernel btusb driver
* is incorrect. */
if ((hci_type & 0x0F) == HCI_USB) {
options.mtu = 48;
if (voice.setting == BT_VOICE_TRANSPARENT)
options.mtu = 24;
debug("USB adjusted SCO MTU: %d: %u", sco_fd, options.mtu);
}

return options.mtu;
}
Expand Down
2 changes: 1 addition & 1 deletion src/hci.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ int hci_get_version(int dev_id, struct hci_version *ver);

int hci_sco_open(int dev_id);
int hci_sco_connect(int sco_fd, const bdaddr_t *ba, uint16_t voice);
unsigned int hci_sco_get_mtu(int sco_fd);
unsigned int hci_sco_get_mtu(int sco_fd, int hci_type);

#define BT_BCM_PARAM_ROUTING_PCM 0x0
#define BT_BCM_PARAM_ROUTING_TRANSPORT 0x1
Expand Down
2 changes: 1 addition & 1 deletion src/ofono.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ static void ofono_agent_new_connection(GDBusMethodInvocation *inv, void *userdat
debug("New oFono SCO connection (codec: %#x): %d", codec, fd);

t->bt_fd = fd;
t->mtu_read = t->mtu_write = hci_sco_get_mtu(fd);
t->mtu_read = t->mtu_write = hci_sco_get_mtu(fd, t->d->a->hci.type);
ba_transport_set_codec(t, codec);

pthread_mutex_unlock(&t->bt_fd_mtx);
Expand Down
2 changes: 1 addition & 1 deletion src/sco.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ static void *sco_dispatcher_thread(struct ba_adapter *a) {
pthread_mutex_lock(&t->bt_fd_mtx);

t->bt_fd = fd;
t->mtu_read = t->mtu_write = hci_sco_get_mtu(fd);
t->mtu_read = t->mtu_write = hci_sco_get_mtu(fd, a->hci.type);
fd = -1;

pthread_mutex_unlock(&t->bt_fd_mtx);
Expand Down

0 comments on commit ac5706f

Please sign in to comment.