summaryrefslogtreecommitdiff
path: root/src/adapter.c
Commit message (Collapse)AuthorAgeFilesLines
* adapter: Add support for experimental flagLuiz Augusto von Dentz2023-05-161-0/+6
| | | | | This adds experimental field to btd_adapter_driver so the plugin can indicate drivers that depends on experimental to be enabled.
* adapter: Use regular discovery for filters which only have discoverable setHans de Goede2023-03-311-1/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | discovery_filter_to_mgmt_cp() does not add discovery_filter.discoverable to the created mgmt_cp_start_service_discovery struct. Instead update_discovery_filter() separately checks client->discovery_filter->discoverable for all clients. This means that for discovery-filters which only have the discoverable flag set, to put the adapter in discoverable mode while discovering, the created mgmt_cp_start_service_discovery struct is empty. This empty mgmt_cp_start_service_discovery struct then gets sent to the kernel as part of a MGMT_OP_START_SERVICE_DISCOVERY msg by start_discovery_timeout(). This use of an empty filter with MGMT_OP_START_SERVICE_DISCOVERY causes some bluetooth devices to not get seen with some (most?) Broadcom bluetooth adapters. This problem has been observed with the following Broadcom models: BCM4343A0, BCM43430A1, BCM43341B0 . On these models the following 2 devices were not being discovered when starting a scan with a filter with just discoverable set in the filter (as gnome-bluetooth does): Device 09:02:01:03:0F:87 (public) Name: Bluetooth 3.0 Keyboard Alias: Bluetooth 3.0 Keyboard Class: 0x00000540 Icon: input-keyboard Paired: yes Bonded: yes Trusted: yes Blocked: no Connected: yes WakeAllowed: yes LegacyPairing: yes UUID: Service Discovery Serve.. (00001000-0000-1000-8000-00805f9b34fb) UUID: Human Interface Device... (00001124-0000-1000-8000-00805f9b34fb) UUID: PnP Information (00001200-0000-1000-8000-00805f9b34fb) Modalias: bluetooth:v05ACp022Cd011B Device 00:60:D1:00:00:34 (public) Name: Bluetooth Mouse Alias: Bluetooth Mouse Class: 0x00002580 Icon: input-mouse Paired: yes Bonded: yes Trusted: yes Blocked: no Connected: yes WakeAllowed: yes LegacyPairing: no UUID: Human Interface Device... (00001124-0000-1000-8000-00805f9b34fb) UUID: PnP Information (00001200-0000-1000-8000-00805f9b34fb) Modalias: usb:v0103p0204d001E Since setting the discoverable flag on a filter only is a way to automatically put the adapter in discoverable mode itself while it is discovering; and since this does not any device filtering at all; modify merge_discovery_filters() to treat discovery with such filters as regular unfiltered discovery. This results in start_discovery_timeout() starting regular discovery through a MGMT_OP_START_DISCOVERY message and this fixes these 2 example devices not getting discovered by the mentioned Broadcom BT adapter models. Link: https://gitlab.gnome.org/GNOME/gnome-bluetooth/-/merge_requests/163 Reviewed-by: Bastien Nocera <hadess@hadess.net>
* core: Check if device has RSILuiz Augusto von Dentz2023-03-101-2/+2
| | | | | This checks if device is advertising an RSI and if so disregards if it is not discoverable since other members can be.
* core: Add initial implementation of DeviceSet interfaceLuiz Augusto von Dentz2023-03-101-3/+3
| | | | | This adds the initial implementation of DeviceSet interface as documented in doc/set-api.rst.
* adapter: Add function for checking adapter settingsPauli Virtanen2023-02-131-0/+8
| | | | Add function for checking adapter current settings.
* main.conf: Add SecureConnections optionSimon Mikuda2022-11-211-1/+2
| | | | | | | | | | This introduces SecureConnections option to main.conf that can be used to configure this on adapter initialization. This is useful for: - disable for adapters that have a problems with SecureConnections enabled - if you want to disable CTKD (cross transport key derivation) - add option to enable only SecureConnections
* adapter: Fix typo in function nameBastien Nocera2022-09-011-2/+2
|
* adapter: Implement PowerState propertyBastien Nocera2022-09-011-11/+128
| | | | | | | | | | | | | | | | | | | | | This property should allow any program to show whether an adapter is in the process of being turned on. As turning on an adapter isn't instantaneous, it's important that the UI reflects the transitional state of the adapter's power, and doesn't assume the device is already turned on but not yet working, or still off despite having requested for it to be turned on, in both cases making the UI feel unresponsive. This can also not be implemented in front-ends directly as, then, the status of an adapter wouldn't be reflected correctly in the Settings window if it's turned on in the system menu. Implementing it in the front-ends would also preclude from having feedback about the state of the adapter when bluetoothd is the one powering up the adapter after the rfkill was unblocked. See https://gitlab.gnome.org/GNOME/gnome-bluetooth/-/issues/121 and the original https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/5773
* adapter: Keep track of whether the adapter is rfkill'edBastien Nocera2022-09-011-2/+23
| | | | | | Instead of only replying to D-Bus requests with an error saying the adapter is blocked, keep track of the rfkill being enabled or disabled so we know the rfkill state of the adapter at all times.
* adapter: Add btd_adapter_find_device_by_fdLuiz Augusto von Dentz2022-08-291-0/+33
| | | | | This adds btd_adapter_find_device_by_fd that lookup a device by a fd socket destination address.
* adapter: Reset pending settings when receiving MGMT errorArchie Pusaka2022-08-241-8/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We set the pending settings flag when sending MGMT_SETTING_* commands to the MGMT layer and clear them when receiving a successful reply, but we don't clear them when receiving an error reply. This might cause a setting to be stuck in pending state. Therefore, also clear the pending flag when receiving error. Furthermore, this patch also postpones setting the pending flag until we queue the MGMT command in order to avoid setting it too soon but we return early. This was caught during power off test, where MGMT_OP_SET_POWERED returns Authentication Failed because disconnection takes too long. Future attempts to switch power will then be ignored. < HCI Command: Disconnect (0x01|0x0006) plen 3 #17916 [hci0] 12.502908 Handle: 512 Reason: Remote Device Terminated due to Power Off (0x15) > HCI Event: Command Status (0x0f) plen 4 #17917 [hci0] 12.503185 Disconnect (0x01|0x0006) ncmd 1 Status: Success (0x00) @ MGMT Event: Command Status (0x0002) plen 3 {0x0001} [hci0] 14.519491 Set Powered (0x0005) Status: Authentication Failed (0x05) = bluetoothd: Failed to set mode: Authentication Failed (0x05) 14.520042 = bluetoothd: adapter /org/bluez/hci0 set power to 0 14.813533 > HCI Event: Disconnect Complete (0x05) plen 4 #17918 [hci0] 16.509043 Status: Success (0x00) Handle: 512 Reason: Connection Timeout (0x08) Reviewed-by: Sonny Sasaka <sonnysasaka@chromium.org>
* adapter: Check flags are supportedLuiz Augusto von Dentz2022-08-151-1/+3
| | | | This makes sure the flags are supported before attempting to set it.
* device: Add btd_ prefix to device_is_trustedLuiz Augusto von Dentz2022-08-021-1/+1
| | | | | This adds btd_ prefix to device_is_trusted so it can be used by plugins.
* adapter: Add support for setting ISO Socket experimental featureLuiz Augusto von Dentz2022-07-221-0/+44
| | | | | This adds support for setting ISO Socket experimental UUID which enables the use of BTPROTO_ISO on the system.
* adapter: Fix advertising monitor on Linux 5.12-5.17Andrew Drake2022-07-131-1/+3
| | | | | | | | | | | The existing code assumes that, if a device supports advertising monitor offload, DEVICE_FOUND events can be ignored since the kernel will send ADV_MONITOR_DEVICE_FOUND events instead. Unfortunately, these new events were added in 5.18, but offload was added in 5.12. This patch adds a check on the MGMT API version so we can process the older DEVICE_FOUND events when the new events are not supported. Fixes: https://github.com/bluez/bluez/issues/357
* core: make bt_uuid_hash() portable across archsBrian Gix2022-06-301-5/+3
| | | | | | | | | | | | | | bt_uuid_t is defined as a byte array, so it can cause alignment errors on some architectures, when the two 64 bit halves are treated as u64s. This patch ensures proper alignment across all architectures. Fixes: src/adapter.c: In function ‘bt_uuid_hash’: src/adapter.c:3617:8: error: cast increases required alignment of target type [-Werror=cast-align] val = (uint64_t *)&uuid_128.value.u128; ^ cc1: all warnings being treated as errors
* device: Fix not removing connected deviceYouwan Wang2022-06-231-1/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | [bluetooth]# connect 40:EF:4C:0C:11:F0 Attempting to connect to 40:EF:4C:0C:11:F0 [CHG] Device 40:EF:4C:0C:11:F0 Connected: yes Connection successful [CHG] Device 40:EF:4C:0C:11:F0 ServicesResolved: yes [UFO]# remove 40:EF:4C:0C:11:F0 [CHG] Device 40:EF:4C:0C:11:F0 ServicesResolved: no Device has been removed [CHG] Device 40:EF:4C:0C:11:F0 Connected: no [bluetooth]# info 40:EF:4C:0C:11:F0 Device 40:EF:4C:0C:11:F0 (public) Name: UFO Alias: UFO Class: 0x00240418 Icon: audio-headphones Paired: yes Trusted: no Blocked: no Connected: no LegacyPairing: no UUID: Headset UUID: Audio Sink UUID: A/V Remote Control Target UUID: A/V Remote Control UUID: Handsfree UUID: Phonebook Access Server
* main.conf: Split Kernel Experimental UUIDs from ExperimentalLuiz Augusto von Dentz2022-06-141-10/+18
| | | | | This splits kernel experimental UUIDs from D-Bus Experimental interface so they can be controlled indenpendetly.
* device: Add connectable flag to bearer stateLuiz Augusto von Dentz2022-06-131-3/+3
| | | | | This adds connectable flag to state so it can be used to detect which is the last seen connectable bearer.
* device: Fix enabling wake support without RPA ResolutionLuiz Augusto von Dentz2022-05-121-6/+28
| | | | | | | | If device uses RPA it shall only enable wakeup if RPA Resolution has been enabled otherwise it cannot be programmed in the acceptlist which can cause suspend to fail. Link: https://bugzilla.kernel.org/show_bug.cgi?id=215768
* storage: Add support for STATE_DIRECTORY environment variableLuiz Augusto von Dentz2022-04-181-60/+63
| | | | | | | When running as a systemd service the STATE_DIRECTORY environment variable maybe set: https://www.freedesktop.org/software/systemd/man/systemd.exec.html
* adapter: Fix check of DISCOVERABLE settingJakob hilmer2022-04-111-2/+2
| | | | | | The test for `DISCOVERABLE` should be done with `MGMT_SETTING_DISCOVERABLE` instead of `MGMT_OP_SET_DISCOVERABLE`. Acked-by: Paul Menzel <pmenzel@molgen.mpg.de>
* adapter: Fix adding SDP records when operating on LE only modeLuiz Augusto von Dentz2022-03-281-1/+15
| | | | | If mode is set to BT_MODE_LE SDP protocol won't be operational so it is useless to attempt to add records.
* adapter: Don't use DBG in mgmt_debugLuiz Augusto von Dentz2022-03-231-5/+2
| | | | | | | mgmt_debug callback is used to print debug strings from mgmt instances which includes the file and function names so using DBG would add yet another set of file and function prefixes which makes the logs confusing.
* adapter: Fix allowing multiple adapters with the same addressLuiz Augusto von Dentz2022-02-161-0/+10
| | | | | | The bdaddr of an adapter is used for its unique storage path so having multiple adapters with the same address would likely cause problems with its storage as they would be shared.
* main.conf: Introduce MaxControllersLuiz Augusto von Dentz2022-02-161-0/+7
| | | | | This introduces MaxControllers which can be used to limit the number of adapters exposed in the system.
* adapter: battery provider for non-LE controllersDaniel Trnka2022-02-151-5/+5
| | | | | | | | Enable battery provider dbus interface BatteryProviderManager1 for non-LE controllers, so external clients like pipewire can provide battery information for bluetooth headsets on non-LE controllers. Reviewed-by: Sonny Sasaka <sonnysasaka@chromium.org>
* adapter: Fix the reusing gerror without re-initializationTedd Ho-Jeong An2022-02-111-17/+17
| | | | | | | | | | | | | When the GError variable is freeed with g_error_free(), it is not set to NULL and reusing the same variable again can cause the seg_fault because it is still pointing the old memory address which is freed. This patch relaces the g_error_free() to g_clear_error() which frees the variable and set it to NULL if the variable is used in the function again. Fixes: 2287c517ca1bd ("adapter: Fix unchecked return value") Fixes: https://github.com/bluez/bluez/issues/276
* adapter: Fix crash when storing link keyLuiz Augusto von Dentz2022-02-091-2/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | The following trace can be observed sometimes when pairing 2 emulator instances: src/adapter.c:store_link_key() Unable to load key file from /var/lib/bluetooth/9C:DA:3E:F2:8E:46/9C:B6:D0:8A:A0:0C/info: (No such file or directory) GLib: g_file_set_contents: assertion 'error == NULL || *error == NULL' failed ++++++++ backtrace ++++++++ #1 btd_backtrace+0x28a (src/backtrace.c:59) [0x7f65bb5ab53a] #2 g_logv+0x21c (/usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6400.6) [0x7f65ba3f955c] #3 g_log+0x93 (/usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6400.6) [0x7f65ba3f9743] #4 g_file_set_contents+0x68 (/usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6400.6) [0x7f65ba3dca68] #5 store_link_key+0x30a (src/adapter.c:8235) [0x7f65bb61839a] #6 new_link_key_callback+0x474 (src/adapter.c:8285) [0x7f65bb62c904] #7 queue_foreach+0x164 (src/shared/queue.c:203) [0x7f65bb722e34] #8 can_read_data+0x59f (src/shared/mgmt.c:343) [0x7f65bb72e09f] #9 watch_callback+0x112 (src/shared/io-glib.c:162) [0x7f65bb78acb2] #10 g_main_context_dispatch+0x14e (/usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.6400.6) [0x7f65ba3f204e]
* adv_monitor: Fix spamming errorsLuiz Augusto von Dentz2022-02-081-1/+1
| | | | | | | | | | If advertising manager is not enabled don't log any error on btd_adapter_update_found_device, also change btd_adv_monitor_offload_supported to btd_adv_monitor_offload_enabled since that is checking if the features has been enabled rather than it is just supported. Fixes: https://github.com/bluez/bluez/issues/286
* adapter: Remove custom MGMT send/reply timeoutLuiz Augusto von Dentz2022-01-281-148/+19
| | | | | | | | This removes the custom MGMT send/reply timeout since bt_mgmt itself can handle them itself and it actually start the timer only when the command is actually sent to the kernel rather then when it is queued. Fixes: https://github.com/bluez/bluez/issues/275
* attrib: Remove gatt-service.{c,h} and attrib-server.{c,h}Luiz Augusto von Dentz2022-01-061-5/+0
| | | | | These files are not longer needed since this functionality has been moved to gatt-db.{c,h}.
* Listen and process remote name resolving failureArchie Pusaka2021-11-291-3/+13
| | | | | | | When Remote Name Resolve ends with failure, record this occurrence and prevent remote name resolving for the same device for some time. Reviewed-by: Miao-chen Chou <mcchou@chromium.org>
* adv_monitor: Receive the Device Found/Lost eventsManish Mandlik2021-11-221-20/+27
| | | | | | | | | | | | | This patch registers callback functions to receive the Advertisement Monitor Device Found and Device Lost events. It also disables software based filtering whenever controller offloading support is available. Test performed: - Verified by logs that the MSFT Monitor Device is received from the controller and the bluetoothd is notified whenever the controller starts/stops monitoring a device. Reviewed-by: Miao-chen Chou <mcchou@google.com>
* adapter: Set Device Privacy ModeLuiz Augusto von Dentz2021-11-091-42/+34
| | | | | This adds support for setting Device Privacy flag when enabled in main.conf via Privacy = device,limited-device.
* adapter: Remove "Master" entry from LTK storageArchie Pusaka2021-11-031-12/+0
| | | | | The entry has been deprecated since 2014 and it's time to remove them altogether.
* adapter: Use PeripheralLongTermKey to store LTKArchie Pusaka2021-11-031-9/+38
| | | | | | | | | Introducing PeripheralLongTermKey group for storing LTK info to replace the less inclusive term. Currently we still need to write/read from both to ensure smooth transition, but later we should deprecate the old term. Reviewed-by: Sonny Sasaka <sonnysasaka@chromium.org>
* adapter: Fix storing IRK causing invalid readLuiz Augusto von Dentz2021-10-221-2/+4
| | | | | | | | | | | | | | | | | | | | | When storing an IRK the storage file may not have been created yet since that uses the device address which is likely changed to the identity address causing the following trace: Invalid read of size 8 at 0x196452: store_irk.constprop.0 (adapter.c:8679) by 0x198C92: new_irk_callback (adapter.c:8737) by 0x1CF6DC: queue_foreach (queue.c:207) by 0x1D1394: process_notify (mgmt.c:308) by 0x1D1394: can_read_data (mgmt.c:374) by 0x1E0634: watch_callback (io-glib.c:157) by 0x4954A9E: g_main_context_dispatch (in /usr/lib64/libglib-2.0.so.0.6600.8) by 0x49A6A97: ??? (in /usr/lib64/libglib-2.0.so.0.6600.8) by 0x4954162: g_main_loop_run (in /usr/lib64/libglib-2.0.so.0.6600.8) by 0x1E0CD4: mainloop_run (mainloop-glib.c:66) by 0x1E10B1: mainloop_run_with_signal (mainloop-notify.c:188) by 0x12E3FC: main (main.c:1210) Address 0x6534418 is 8 bytes inside a block of size 16 free'd
* adapter: Fix unchecked return valueTedd Ho-Jeong An2021-10-181-38/+211
| | | | | This patch fixes the unchecked return value(CWE-252) issues reported by the Coverity.
* adapter: Truncate number of LTKs loaded if over MGMT MTULuiz Augusto von Dentz2021-09-221-14/+18
| | | | | If MGMT MTU cannot accomodate all the existing LTKs only send the ones that fit in the MTU and leave the remaining as unpaired.
* src: Inclusive language changesArchie Pusaka2021-09-211-54/+57
| | | | | | | | | | | | BT core spec 5.3 promotes the usage of inclusive languages. This CL replaces some terms with the more appropriate counterparts, such as "central", "peripheral", "accept list", and "reject list". Note that some suggestions come from https://specificationrefs.bluetooth.com/language-mapping/Appropriate_Language_Mapping_Table.pdf Also use "primary" to refer the global mgmt struct. Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
* lib: Inclusive language changesArchie Pusaka2021-09-211-2/+2
| | | | | | | | BT core spec 5.3 promotes the usage of inclusive languages. This CL replaces some terms with the more appropriate counterparts, such as "central", "peripheral", and "accept list". Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
* adv_monitor: Clear any running DeviceLost timers on power downManish Mandlik2021-09-101-0/+2
| | | | | | | | | | | | This patch clears any running Adv Monitor DeviceLost timers on bt power down. It'll also invoke DeviceLost event if the device is already found and is being tracked for the DeviceLost event. Verified this by adding a monitor using bluetoothctl and confirming that the DeviceLost event is getting triggered for already found device in case of bt power down. Reviewed-by: mcchou@google.com
* adapter: Enable codec offload when Experimental is setLuiz Augusto von Dentz2021-09-081-0/+42
| | | | | | This enables codec offload experimental feature if its UUIDs has been enabled by main.conf:Experimental or -E has been passed in the command line.
* main.conf: Allow passing a list of UUIDs to ExperimentalLuiz Augusto von Dentz2021-09-081-50/+56
| | | | | | This allows the user to enable a subset of the experimental features to be enabled instead of all of them and also change -E to work in the same way so a list of UUIDs can also be given at the command line.
* adapter: Implement ExperimentalFeatures propertyLuiz Augusto von Dentz2021-09-081-40/+109
| | | | | This implements ExperimentalFeatures property which indicates the list of UUIDs that represents the experimental features currently enabled.
* adapter: Fix warning when exitLuiz Augusto von Dentz2021-08-161-1/+4
| | | | | g_hash_table_destroy prints a warning when it is NULL so this checks if adapter->allowed_uuid_set has actually been set.
* adapter: Simplify setting of experimental debug featureLuiz Augusto von Dentz2021-08-161-1/+1
| | | | The action already indicates the value of btd_opts.experimental.
* core: block not allowed UUID connect in authYun-Hao Chung2021-08-041-0/+5
| | | | | | | | | | This ensures any incoming profile connection will be blocked if its UUID is not allowed by the following assumption: 1. Each system profile asks adapter authorization when seeing a incoming connection. 2. Each external profile checks if its UUID is allowed by adapter when seeing a incoming connection.
* core: add adapter and device allowed_uuid functionsYun-Hao Chung2021-08-041-0/+90
| | | | | | | This implements functions in src/adapter.c and src/device.c for plugins setting a list of allowed services. Reviewed-by: Miao-chen Chou <mcchou@chromium.org>