Commit graph

99 commits

Author SHA1 Message Date
Barnabás Pőcze
0a48165cff spa: bluez: backend-native: accept "=" for +VGS and +VGM
HFP 1.8 states in 4.35.1:

  Due to the small inconsistency between the GSM standard [2]) and the current
  Headset specification ([3]), the HF shall also accept the “=” symbol,
  in place of “:”, as a valid separator for this unsolicited result code.

iOS seems to use "=", so accept that as well.

See #2463
2022-09-24 02:47:58 +02:00
Barnabás Pőcze
0ee4fea03d spa: bluez: backend-native: fix HF/HS to AG message terminator
Both HFP and HSP require an AT command from HF/HS to AG to
be terminated by CR, not LF. (HFP 1.8, 4.34.1; HSP 1.2, 4.8.1)

See #2463

Fixes: 0b2d3730b6 ("bluez5: Add HFP HF support")
2022-09-24 02:45:41 +02:00
Barnabás Pőcze
2fb63f71c3 spa: bluez: backend-native: use sscanf() for parsing AT commands 2022-09-24 02:22:29 +02:00
Barnabás Pőcze
c24594a8ac spa: bluez: backend-native: fix type and add error checking 2022-09-24 02:22:19 +02:00
Barnabás Pőcze
8881030904 spa: bluez: backend-native: use strsep() instead of strtok()
`strsep()` is simpler to use than `strtok()` or `strtok_r()`
while being thread-safe and reentrant.

Although it is an extension, it is available in both glibc and musl.
2022-09-24 02:22:16 +02:00
Frédéric Danis
75ae86bf13 bluez5: backend-native: Only send one error message
When rfcomm_hfp_ag() returns false, an "ERROR" reply is sent.
When testing if the SLC is configured, 2 "ERROR" replies are sent, which
should not be done.
2022-09-16 12:32:12 +02:00
Pauli Virtanen
d82b3d6479 bluez5: backend-native: set HFP/HSP volume when connecting
The HFP/HSP HW volume on the device is not necessarily what we think it
is.

Sync the device volume to our value at connect time.
2022-07-09 18:19:45 +00:00
Barnabás Pőcze
f24250da66 spa: bluez: ignore unsupported indicators
Do not emit a warning when a known, but
otherwise unsupported indicator is received.

Fixes wireplumber#253
2022-05-10 12:09:18 +02:00
Barnabás Pőcze
15e7a61aa7 treewide: only define feature macros when the feature is available
Most feature checks already use #ifdef, and do not care about
the value of the macro. Convert all feature checks to do that,
and simplify the meson build scripts by replacing

  if cond
    cdata.set('X', 1)
  endif

with

  cdata.set('X', cond)
2022-02-04 00:15:59 +01:00
Pauli Virtanen
a2a5012cb2 bluez5: backend-native: set transport volume on create
Initial transport volume was being set incorrectly to max for new
transports. This is usually masked by route restore, but not always.
2022-01-30 22:00:32 +02:00
Pauli Virtanen
3ffc0452a7 bluez5: backend-native: fallback switch msbc->cvsd on EOPNOTSUPP
If MSBC connect() fails with EOPNOTSUPP, trigger codec renegotiation.

When PW is AG, this also removes the msbc profile.
2022-01-30 22:00:32 +02:00
Pauli Virtanen
1da23145df bluez5: probe adapter msbc capability via hci commands
Using a probe connection to determine adapter msbc capability causes
problems on some adapters (ff8c3d2, 84bc0490a5, 717004334b,
pipewire#2030) and seems to be a bad idea.

Go back to probing for transparent msbc transport capability via HCI
commands. bluetooth/hci.h may be deprecated later, but for now it's
better to go back to using it.  (In practice, adapters not supporting
esco appear to be fairly rare; kernel commit in 2013 refers to "older
devices", so if we can't use HCI, assume the adapter supports the
necessary modes.)
2022-01-30 22:00:32 +02:00
Valentin Hăloiu
483831e514
bluez: handle non-hexadecimal XAPL version strings 2022-01-29 21:13:45 +00:00
Pauli Virtanen
f2630ed6fc bluez5: require adapter before profile connect & after
All exposed bluez devices should have an adapter specified at all times.
Adapter-less devices appear in some race conditions in BlueZ interface.

Require device has non-null adapter, in all cases before adding any
profiles (which exposes the device), and reject BlueZ profile connection
attempts in that state.

If an adapter gets removed by BlueZ, remove also all its devices, so
that device->adapter pointers stay valid.
2022-01-20 18:18:09 +00:00
Pauli Virtanen
f92b0eee56 bluez5: implement basic CIND/CIEV support in backend-native
Set HFP call indicator based on whether transport is acquired or not.
2022-01-09 19:41:17 +02:00
Pauli Virtanen
55ce3d48c9 bluez5: bump up HFP codec switch timeouts
It appears some headsets (eg. Air 1 Plus) can take some tens of seconds
before replying with AT+BCS switch to CVSD.
2022-01-03 15:22:37 +00:00
Barnabás Pőcze
01de0b966a spa: bluez: simplify and move handling of some AT commands
Simplify the key-value pair parsing for AT+IPHONEACCEV commands,
and move the handling of {key,indicator}-value pairs into
dedicated functions. Furthermore, fix a comment.
2021-11-04 18:42:29 +01:00
Barnabás Pőcze
bdd7570c6f spa: bluez: simplify loop
`spa_list_for_each_safe()` is not needed as the list is not
modified during the traversal, so use `spa_list_for_each()`.
2021-11-04 17:16:14 +00:00
Barnabás Pőcze
f71910c665 spa: bluez: rename variable
The `optlen` variable holds the size of a socket address,
so rename it to `addrlen`.
2021-11-04 17:16:14 +00:00
Barnabás Pőcze
6410a2dfa4 spa: bluez: fix spelling 2021-11-04 17:16:14 +00:00
Barnabás Pőcze
1f927838e2 spa: bluez: remove unnecessary return 2021-11-04 17:16:14 +00:00
Barnabás Pőcze
4bdf495747 spa: bluez: move profile selection to function
Move the profile selection from `profile_new_connection()`
into a separate function to avoid checking the string more
than necessary.
2021-11-04 17:16:14 +00:00
Barnabás Pőcze
dd4587acef spa: bluez: change argument type
Take the `rfcomm` object directly instead of taking a `spa_source`
object and retrieving the `rfcomm` object via its `data` member.
2021-11-04 17:16:14 +00:00
Barnabás Pőcze
4cf889a5f0 spa: bluez: use switch
Use a switch statement instead of an `if` because it is more
suitable in the presence of `#ifdef`s, it avoids potential
unnecessary extra checks.
2021-11-04 17:16:14 +00:00
Barnabás Pőcze
73690d6662 spa: bluez: add missing else 2021-11-04 17:16:14 +00:00
Barnabás Pőcze
57ff7abc68 spa: bluez: use spa_startstartswith() where appropriate 2021-11-04 17:16:14 +00:00
Pauli Virtanen
d28b36bb93 bluez5: fix HFP backend behavior when BlueZ goes away
Ensure unavailable backends get unregistered.

Don't log error-level messages on HFP unregistration failures.
2021-10-09 13:03:08 +00:00
Björn Daase
10ededf5d4 bluez5: fix mSBC probing documentation 2021-10-07 15:25:29 +00:00
Pauli Virtanen
ff8c3d208e bluez5: fix msbc connect probe again
There's a report that on Intel 8086:2723 + Sony WH-1000XM4, the connect
probe shuts the device down.

So, use an invalid dst address instead, since we don't need the host to
be up.

Fixes: 84bc0490a5
Fixes: 717004334b
2021-10-06 19:33:54 +03:00
Pauli Virtanen
84bc0490a5 bluez5: tweak msbc adapter probe for Intel adapters
The msbc capability connection probe seems to cause problems on Intel
Bluetooth 8087:0a2b (Intel 8265), resulting to subsequent connections
apparently ending up with wrong altsetting.

According to testing, the problem is connecting to self, so connect to
device instead.

Fixes #1671
2021-10-03 17:27:42 +00:00
Pauli Virtanen
58c7caf1bc bluez5: use log topics
Use log topics instead of prepending NAME: to log messages.
2021-10-02 12:46:02 +03:00
Pauli Virtanen
0af3c85806 bluez5: don't probe native backend presence
Don't do a blocking probe of native backend presence, because it may
trigger DBus activation for Bluez.  If the DBus activation fails, it
ends up blocking until timeout.

ofono/hsphfpd usually don't have DBus activation configured, so they
fail instantly (which is why this problem was not encountered, even
though they do blocking calls on startup in previous pipewire versions
too).

Instead, select the backend once we have Bluez objects listed.
2021-09-25 16:24:10 +00:00
Pauli Virtanen
717004334b bluez5: backend-native: don't use libbluetooth hci commands
BlueZ 6 is planning to make most of libbluetooth private.  In
particular, the direct hci access is planned to be removed.  This is
currently used for determining adapter msbc support.

Instead of using libbluetooth API, try to determine msbc support by
a connect() attempt, which the kernel should reject when not supported.
2021-09-22 20:18:50 +03:00
Pauli Virtanen
90b4efd98d bluez5: cleanup hfp/hsp backend handling + config file option
It seems not uncommon that people have not properly configured ofono
running, which results to loss of HFP/HSP functionality. It's less
surprising if the backend selection is fixed in the configuration file,
and (by default) does not depend on running services.

Add a configuration file option for selecting HFP/HSP backend, and set
the default value to the native backend. Emit warnings if conflicting
backend services are detected to be running.

Also cleanup hfp/hsp backend handling a bit, now that it's mostly
abstracted behind an interface.
2021-09-19 17:33:32 +00:00
Peter Hutterer
e55a5441b8 spa: silence two -Wformat-nonliteral warnings
In one we can duplicate the spa_asprintf call without real drawbacks.

The second one can be split up without losing details. Note that there
is another one in backend-native.c where splitting it up will make the
code harder to understand. The warning for that one remains.
2021-09-07 08:26:54 +10:00
Zsombor Welker
f5850af4d8 bluez5: handle XAPL battery level per Apple Guidelines
Corrects the handling of AT+XAPL Apple extensions to send
`+XAPL=iPhone,2` instead of `+XAPL: iPhone,2` based on Apple's
documentation.

Replaces magic numbers with enum values.

[Accessory Design Guidelines](https://developer.apple.com/accessories/Accessory-Design-Guidelines.pdf)
2021-08-13 10:30:36 +02:00
Zsombor Welker
a1777d00e3 bluez5: correct parsing order for HF indicator 2 based battery status
Since "AT+BIND=" was before "AT+BIND=?", the seconds statement was never
matched.
2021-08-12 21:13:22 +02:00
Zsombor Welker
f87942027f bluez5: report HF indicator 2 based battery status
HF indicator 2 (see [assigned-numbers], Hands-Free Profile) is able to
report battery percentage at 1% intervals (in range [0, 100]), contrary
to the `+XAPL` `+IPHONEACCEV` extension which only supports 10%
increments.  This does not guarantee increased granularity however, as
peers may still be limited to imprecise battery measurements internally
or round to coarser percentages.
Supporting both additionally broadens the range of devices for which PW
can report its battery level.

[assigned-numbers]:
https://www.bluetooth.com/specifications/assigned-numbers/
2021-08-12 18:45:44 +00:00
Barnabás Pőcze
f5d51162c4 treewide: mark things static and const
Mark some structures, arrays static/const at various places.
In some cases this prevents unnecessary initialization
when a function is entered.

All in all, the text segments across all shared
libraries are reduced by about 2 KiB. However,
the total size increases by about 2 KiB as well.
2021-06-30 14:44:08 +02:00
Barnabás Pőcze
48dbb4da3c spa: bluez: native: do not use spa_aprintf()
Instead of spa_aprintf(), convert `rfcomm_send_{cmd,query}`
to take a printf-style format string.

Furthermore, handle overflows and return errors from
`rfcomm_send_{cmd,reply}`. And make those functions
take an rfcomm as argument instead of any spa_source.
And match conversion specifiers to the actual types
in format strings.
2021-06-30 14:44:08 +02:00
Pauli Virtanen
b98b9e0e77 bluez5: deal with old libusb versions 2021-06-22 10:58:50 +03:00
Pauli Virtanen
9d38d375d2 bluez5: add and use quirk for broken mic HW volume
Some headsets emit AT+VGM even though +VGM commands do not actually
adjust the recording volume.
2021-06-22 10:58:50 +03:00
Pauli Virtanen
5e0b63b149 bluez5: backend-native: use quirks + usb adapter caps for checking msbc
Use the quirks database to check whether to enable MSBC codec for each
device.

If quirks don't allow ALT1 mode for an USB adapter, check whether the
adapter has an usable ALT6 mode and disable MSBC if not.
2021-06-22 10:58:50 +03:00
Pauli Virtanen
b57ae8c2a6 bluez5: add support for hardware quirk/feature database
Implement hardware quirk/feature database with pattern matching.
2021-06-22 10:58:50 +03:00
Huang-Huang Bao
3433f40cd9 bluez5: fix device connection issue if profile(UUIDs) info is delayed
Keep all types of devices, only emit device info if device has audio profiles.
Heuristically add profiles based on bluez actions so device can still be connected
even without initial UUIDs info from signal InterfaceAdded for org.bluez.Device1.

Fixes #1330
2021-06-21 07:10:02 +00:00
Pauli Virtanen
b44fdf5ebb bluez5: backend-native: don't send +BCS if no codec negotiation
Fix issue with sending +BCS for CVSD even though codec negotation is not
available for the RFCOMM.
2021-06-20 19:40:00 +03:00
Peter Hutterer
cdfd50e166 spa: add spa_atob() to convert a string to a boolean
This replaces the manual check for "true" and some (inconsistent) return value
of atoi. All those instances now require either "true" or "1" to parse as
true, any other value (including NULL) is boolean false.
2021-05-18 22:18:56 +10:00
Peter Hutterer
7697ed0757 treewide: replace strcmp() == 0 with spa_streq()
This change is only done in source files for now, header files will be done
separately.
2021-05-18 22:10:27 +10:00
Andrea Gelmini
47ef2b6b09 Fix typos 2021-04-30 07:40:20 +00:00
Pauli Virtanen
34e78611ac bluez5: don't unregister HFP/HSP profiles when shutting down
This apparently causes delays in shutdown under some conditions, and
closing the DBus connection should be enought to tell BlueZ that we are
shutting down.
2021-04-26 08:23:29 +00:00