Skip to contentSkip to conversation

Add HoG functional tests and shared/hog

PATCH In review Luiz Augusto von Dentz 3 participants 27 messages Sep 28 – Oct 13

Subsystems (2)
lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

v6 cover Add HoG functional tests and shared/hog

From: Luiz Augusto von Dentz <[email protected]>

This adds functional tests for HID over GATT (HoG), with bluetoothctl registering a HID Service acting as a keyboard, with and without Shorter Connection Interval (SCI) support, using the new client/scripts/hog-device*.bt scripts, and the HID host:

- checking HID Information, HID SCI Mode and HID SCI Information over GATT with gatt.select-attribute/gatt.read
- receiving a few Input Reports notified by the HID device
- with SCI support, requesting SCI Fast mode with the HID Control Point, as specified by HOGP.TS 4.6.1, followed by the connection rate with mgmt.conn-subrate, and receiving the notification of HID SCI Mode from the HID device confirming the mode has been changed

The tests are documented in doc/functional-hog.rst.

The input plugin is also moved away from GAttrib: the new src/shared/hog implements HID over GATT on top of bt_gatt_client and gatt_db, as a
drop-in replacement of profiles/input/hog-lib, which is removed along
with the GAttrib based Battery, Device Information and Scan Parameters implementations only used by it, these services being handled by their
own plugins. src/shared/hog uses a clone of the bt_gatt_client, so its requests are tracked on their own, caches the static values in the
gatt_db so they are not read again when reconnecting, and creates the
uHID device once the client is idle. src/shared/hog supports HID SCI, requesting a mode with the HID Control Point and enabling the notifications of HID SCI Mode.

With that GAttrib has no users left in bluetoothd, which now creates the bt_att of the connection directly, so GAttrib is removed along with the deprecated gatttool, its only other user, and then the attrib directory, moving what bluetoothd still uses to src/shared/att and src/device.

unit/test-hog is ported to src/shared/hog, with the test cases renamed after HOGP.TS p13 and the missing ones for the Report Host added, except HID ISO which is not supported, including the HID SCI test cases HGWF/BV-08-C to BV-11-C.

To support this:

- bluetoothctl can now set descriptor values from scripts, prints the MGMT Connection Subrate event, and no longer crashes when the auto agent is canceled
- btvirt defaults to the latest BR/EDR+LE version (6.2), so Shorter Connection Intervals are supported by the emulated controllers, with the new -C/--core option to emulate older versions
- the tester can expect a PDU with no response, e.g. Write Command
- unit/test-uhid tests the replies to Get Report, including through hidraw when run as root, which requires CONFIG_HIDRAW now added to the tester kernel config

Also, with -n auto, the number of functional test workers is now limited by the memory available instead of one per CPU, since running out of memory with so many VM instances made tests fail at random, and check-functional uses -n auto by default (override with CHECK_FUNCTIONAL_JOBS).

v6:
- shared/hog: use a clone of the bt_gatt_client, freed when detaching, instead of tracking each request, cache HID Information, Report Reference, External Report Reference and HID SCI Information in the gatt_db, read the Report Map along with the other characteristics and create the uHID device once the client is idle
- Add "shared/gatt-client: Fix calling idle callbacks again while notifying" and "shared/gatt-client: Add bt_gatt_client_is_idle"
- unit/test-hog: drop HGCF/BV-02-C, as notifications are no longer disabled when detaching, the requests of the clone being cancelled when freed

v5:
- Add "attrib: Remove directory", moving att_ecode2str to src/shared/att as bt_att_ecode2str, and struct gatt_primary and gatt_parse_record to src/device

v4:
- Fix a use-after-free in bluetoothd introduced by "shared/gatt-client:
Fix calling destroy after unregistering notify", when enabling notifications with StartNotify fails, and hold a reference to the client while calling destroy
- Drop "attrib: Fix unregistering notifications registered with bt_gatt_client", as GAttrib is now removed
- client/gatt: fix use-after-free on invalid values set from scripts, uninitialized bytes when parsing values with consecutive separators, and reject negative values
- Add "client/agent: Fix crash on Cancel with no pending request", reported by TestFunctional with v3
- Add src/shared/hog, replacing hog-lib in the input plugin, and port unit/test-hog to it with HOGP.TS p13 test cases, including HID SCI
- Change the HID SCI mode with the HID Control Point in the functional test, HID SCI Mode being Read and Notify only as specified
- Fix the size of the reply to Get Report with a Report ID in shared/uhid, and add unit/test-uhid Get Report tests along with CONFIG_HIDRAW in the tester kernel config
- Add "device: Use bt_att instead of GAttrib" and "attrib: Remove GAttrib and gatttool"
- Honour PYTEST_XDIST_AUTO_NUM_WORKERS and the CPU affinity when limiting the functional test workers
- Add Assisted-by tags

v3:
- Add "shared/gatt-client: Fix calling destroy after unregistering notify", fixing the heap-use-after-free in report_notify_destroy still reported by TestFunctional on the HoG tests with v2: once unregistered, the destroy callback of the notification was still called later if the write of the CCC disabling it was pending, after HoG had freed its reports.

v2:
- Add "attrib: Fix unregistering notifications registered with bt_gatt_client", fixing the heap-use-after-free in report_notify_destroy reported by TestFunctional on the HoG tests:
g_attrib_unregister did not unregister the notifications registered with bt_gatt_client, so their destroy callback was called after HoG had freed its reports.

Luiz Augusto von Dentz (23):
shared/gatt-client: Fix calling destroy after unregistering notify client/gatt: Fix setting descriptor value from scripts client/mgmt: Print Connection Subrate event
emulator: Default to the latest BR/EDR+LE version client/scripts: Add HoG device scripts
doc: Add functional-hog documentation
test: functional: add HoG tests
test: functional: limit the workers by the memory available client/agent: Fix crash on Cancel with no pending request shared/uhid: Fix size of Get Report reply with a Report ID shared/uhid: Keep reading when an event is not available shared/tester: Allow expecting a PDU with no response shared/gatt-client: Fix calling idle callbacks again while notifying shared/gatt-client: Add bt_gatt_client_is_idle shared/hog: Add initial implementation
unit/test-hog: Use shared/hog
test: functional: change the HoG SCI mode with the HID Control Point input/hog: Use shared/hog
doc: Add CONFIG_HIDRAW to the tester kernel config unit/test-uhid: Add Get Report tests
device: Use bt_att instead of GAttrib
attrib: Remove GAttrib and gatttool
attrib: Remove directory

 .gitignore                       |    2 -
 Makefile.am                      |   33 +-
 Makefile.plugins                 |    4 -
 Makefile.tools                   |   12 -
 attrib/att-database.h            |   30 -
 attrib/att.c                     | 1238 -------------------
 attrib/att.h                     |  186 ---
 attrib/gatt.c                    | 1249 -------------------
 attrib/gatt.h                    |  109 --
 attrib/gattrib.c                 |  473 -------
 attrib/gattrib.h                 |   65 -
 attrib/gatttool.c                |  612 ----------
 attrib/gatttool.h                |   17 -
 attrib/interactive.c             | 1020 ----------------
 attrib/utils.c                   |  110 --
 client/agent.c                   |   10 +-
 client/gatt.c                    |   39 +-
 client/mgmt.c                    |   31 +
 client/scripts/hog-device-sci.bt |   49 +
 client/scripts/hog-device.bt     |   38 +
 doc/functional-hog.rst           |  204 ++++
 doc/functional-testing.rst       |    1 +
 doc/test-functional.rst          |   29 +-
 doc/test-runner.rst              |    5 +
 doc/tester.config                |    1 +
 emulator/main.c                  |   55 +-
 emulator/server.c                |   15 +-
 emulator/server.h                |    2 +
 profiles/battery/bas.c           |  327 -----
 profiles/battery/bas.h           |   19 -
 profiles/battery/battery.c       |    3 +-
 profiles/deviceinfo/deviceinfo.c |    5 +-
 profiles/deviceinfo/dis.c        |  340 ------
 profiles/deviceinfo/dis.h        |   27 -
 profiles/input/hog-lib.c         | 1966 ------------------------------
 profiles/input/hog-lib.h         |   28 -
 profiles/input/hog.c             |   31 +-
 profiles/midi/midi.c             |    3 +-
 profiles/ranging/rap.c           |    2 -
 profiles/scanparam/scan.c        |    3 +-
 profiles/scanparam/scpp.c        |  342 ------
 profiles/scanparam/scpp.h        |   22 -
 src/adapter.c                    |    4 +-
 src/device.c                     |  122 +-
 src/device.h                     |   14 +-
 src/gatt-client.c                |    7 +-
 src/shared/att.c                 |   48 +
 src/shared/att.h                 |    2 +
 src/shared/gatt-client.c         |   41 +-
 src/shared/gatt-client.h         |    1 +
 src/shared/hog.c                 | 1563 ++++++++++++++++++++++++
 src/shared/hog.h                 |   67 +
 src/shared/tester.c              |   19 +
 src/shared/uhid.c                |    7 +-
 test/functional/conftest.py      |   58 +
 test/functional/test_hog.py      |  269 ++++
 unit/test-gattrib.c              |  552 ---------
 unit/test-hog.c                  | 1420 +++++++++++++++------
 unit/test-uhid.c                 |  272 +++++
 59 files changed, 4019 insertions(+), 9204 deletions(-)
 delete mode 100644 attrib/att-database.h
 delete mode 100644 attrib/att.c
 delete mode 100644 attrib/att.h
 delete mode 100644 attrib/gatt.c
 delete mode 100644 attrib/gatt.h
 delete mode 100644 attrib/gattrib.c
 delete mode 100644 attrib/gattrib.h
 delete mode 100644 attrib/gatttool.c
 delete mode 100644 attrib/gatttool.h
 delete mode 100644 attrib/interactive.c
 delete mode 100644 attrib/utils.c
 create mode 100644 client/scripts/hog-device-sci.bt
 create mode 100644 client/scripts/hog-device.bt
 create mode 100644 doc/functional-hog.rst
 delete mode 100644 profiles/battery/bas.c
 delete mode 100644 profiles/battery/bas.h
 delete mode 100644 profiles/deviceinfo/dis.c
 delete mode 100644 profiles/deviceinfo/dis.h
 delete mode 100644 profiles/input/hog-lib.c
 delete mode 100644 profiles/input/hog-lib.h
 delete mode 100644 profiles/scanparam/scpp.c
 delete mode 100644 profiles/scanparam/scpp.h
 create mode 100644 src/shared/hog.c
 create mode 100644 src/shared/hog.h
 create mode 100644 test/functional/test_hog.py
 delete mode 100644 unit/test-gattrib.c
Signature · 1 line
2.55.0
author maintainer
#1 lore raw

PATCH v6 1/23 shared/gatt-client: Fix calling destroy after unregistering notify

From: Luiz Augusto von Dentz <[email protected]>

bt_gatt_client_unregister_notify resets the callbacks of the notification but not its destroy callback, which is called once the notify_data is freed. If a procedure is still pending at that point, e.g. the write of the CCC to disable the notifications, it holds a reference to notify_data so destroy is called later, once the user data may have been freed, e.g. the reports of HoG:

ERROR: AddressSanitizer: heap-use-after-free
#11 report_notify_destroy profiles/input/hog-lib.c:359 #12 attrib_callbacks_destroy attrib/gattrib.c:130 #13 notify_data_unref src/shared/gatt-client.c:256 #15 destroy_write_op src/shared/gatt-client.c:3189 #16 request_unref src/shared/gatt-client.c:201 #17 destroy_att_send_op src/shared/att.c:215
#18 bt_att_cancel src/shared/att.c:1925
#19 cancel_request src/shared/gatt-client.c:2783
...
#21 bt_gatt_client_cancel_all src/shared/gatt-client.c:2811 #22 bt_gatt_client_free src/shared/gatt-client.c:2290

Call destroy when unregistering instead, once done with notify_data and holding a reference to the client in case destroy drops the last one.

As destroy is now called when unregistering, reply to StartNotify before freeing the notify client when enabling the notifications fails, since it frees the operation the reply is for.

Assisted-by OpenCode:claude-opus-5.5
---
 src/gatt-client.c        |  7 +++++--
 src/shared/gatt-client.c | 21 +++++++++++++++++++++
 2 files changed, 26 insertions(+), 2 deletions(-)
src/gatt-client.c +5 -2
index 3baf95c4f79c..d94dc9d7fbf6 100644
@@ -1488,12 +1488,15 @@ static void register_notify_cb(uint16_t att_ecode, void *user_data)
 	struct characteristic *chrc = client->chrc;
 
 	if (att_ecode) {
+		/* Reply first, as freeing the client unregisters the
+		 * notification, which frees op with its destroy callback.
+		 */
+		create_notify_reply(op, false, att_ecode);
+
 		queue_remove(chrc->notify_clients, client);
 		queue_remove(chrc->service->client->all_notify_clients, client);
 		notify_client_free(client);
 
-		create_notify_reply(op, false, att_ecode);
-
 		return;
 	}
 
src/shared/gatt-client.c +21 -0
index 92ad7c39c115..b3bc62220e16 100644
@@ -3842,6 +3842,8 @@ bool bt_gatt_client_unregister_notify(struct bt_gatt_client *client,
 							unsigned int id)
 {
 	struct notify_data *notify_data;
+	bt_gatt_client_destroy_func_t destroy;
+	void *user_data;
 
 	if (!client || !id)
 		return false;
@@ -3858,7 +3860,26 @@ bool bt_gatt_client_unregister_notify(struct bt_gatt_client *client,
 	notify_data->callback = NULL;
 	notify_data->notify = NULL;
 
+	/* Call destroy once unregistered, as the user data may be freed then,
+	 * while notify_data may still be referenced by a pending procedure,
+	 * e.g. the write of the CCC, which would otherwise call it later.
+	 */
+	destroy = notify_data->destroy;
+	user_data = notify_data->user_data;
+	notify_data->destroy = NULL;
+
+	/* The client may be freed by destroy, e.g. if the user data holds
+	 * its last reference.
+	 */
+	bt_gatt_client_ref(client);
+
 	complete_unregister_notify(notify_data);
+
+	if (destroy)
+		destroy(user_data);
+
+	bt_gatt_client_unref(client);
+
 	return true;
 }
 
Signature · 1 line
2.55.0
#2 lore raw

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/series/1175561/

---Test result---

Test Summary:

CheckPatch                    FAIL      15.02 seconds
GitLint                       FAIL      8.34 seconds
BuildEll                      PASS      19.16 seconds
BluezMake                     PASS      368.71 seconds
MakeCheck                     PASS      14.32 seconds
MakeDistcheck                 PASS      137.33 seconds
CheckValgrind                 PASS      228.40 seconds
CheckSmatch                   PASS      288.22 seconds
bluezmakeextell               PASS      92.65 seconds
TestFunctional                PASS      1112.78 seconds
IncrementalBuild              FAIL      748.63 seconds
ScanBuild                     FAIL      150.39 seconds

Details
##############################
Test: CheckPatch - FAIL
Desc: Run checkpatch.pl script
Output:
[BlueZ,v6,09/23] client/agent: Fix crash on Cancel with no pending request WARNING:COMMIT_LOG_LONG_LINE: Prefer a maximum 75 chars per line (possible unwrapped commit description?) #108:
#6 _dbus_warn_check_failed () from /usr/lib/x86_64-linux-gnu/libdbus-1.so.3

/home/runner/work/bluez/bluez/src/patch/14853402.patch total: 0 errors, 1 warnings, 16 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.

/home/runner/work/bluez/bluez/src/patch/14853402.patch has style problems, please review.

NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPDX_LICENSE_TAG SPLIT_STRING SSCANF_TO_KSTRTO

NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.

[BlueZ,v6,23/23] attrib: Remove directory WARNING:LINE_SPACING: Missing a blank line after declarations #1911: FILE: src/device.c:6488:
+ sdp_list_t *p;
+ for (p = list->data; p; p = p->next) {

WARNING:LINE_SPACING: Missing a blank line after declarations #1913: FILE: src/device.c:6490:
+ sdp_data_t *seq = p->data;
+ if (seq && seq->dtd == SDP_UUID16 &&

/home/runner/work/bluez/bluez/src/patch/14853415.patch total: 0 errors, 2 warnings, 278 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.

/home/runner/work/bluez/bluez/src/patch/14853415.patch has style problems, please review.

NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPDX_LICENSE_TAG SPLIT_STRING SSCANF_TO_KSTRTO

NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.

##############################
Test: GitLint - FAIL
Desc: Run gitlint
Output:
[BlueZ,v6,01/23] shared/gatt-client: Fix calling destroy after unregistering notify

1: T1 Title exceeds max length (83>80): "[BlueZ,v6,01/23] shared/gatt-client: Fix calling destroy after unregistering notify" [BlueZ,v6,13/23] shared/gatt-client: Fix calling idle callbacks again while notifying

1: T1 Title exceeds max length (85>80): "[BlueZ,v6,13/23] shared/gatt-client: Fix calling idle callbacks again while notifying" [BlueZ,v6,17/23] test: functional: change the HoG SCI mode with the HID Control Point

1: T1 Title exceeds max length (85>80): "[BlueZ,v6,17/23] test: functional: change the HoG SCI mode with the HID Control Point"
##############################
Test: IncrementalBuild - FAIL
Desc: Incremental build with the patches in the series
Output:

In file included from src/adapter.c:63:
./attrib/gatt.h:61:29: error: unknown type name ‘GAttrib’
61 | guint gatt_discover_primary(GAttrib *attrib, bt_uuid_t *uuid, gatt_cb_t func,
| ^~~~~~~
./attrib/gatt.h:64:33: error: unknown type name ‘GAttrib’
64 | unsigned int gatt_find_included(GAttrib *attrib, uint16_t start, uint16_t end,
| ^~~~~~~
./attrib/gatt.h:67:26: error: unknown type name ‘GAttrib’
67 | guint gatt_discover_char(GAttrib *attrib, uint16_t start, uint16_t end,
| ^~~~~~~
./attrib/gatt.h:71:22: error: unknown type name ‘GAttrib’
71 | guint gatt_read_char(GAttrib *attrib, uint16_t handle, GAttribResultFunc func,

      |                      ^~~~~~~

./attrib/gatt.h:71:56: error: unknown type name ‘GAttribResultFunc’
71 | guint gatt_read_char(GAttrib *attrib, uint16_t handle, GAttribResultFunc func,
| ^~~~~~~~~~~~~~~~~
./attrib/gatt.h:74:23: error: unknown type name ‘GAttrib’
74 | guint gatt_write_char(GAttrib *attrib, uint16_t handle, const uint8_t *value,

      |                       ^~~~~~~

./attrib/gatt.h:75:54: error: unknown type name ‘GAttribResultFunc’
75 | size_t vlen, GAttribResultFunc func,
| ^~~~~~~~~~~~~~~~~
./attrib/gatt.h:78:26: error: unknown type name ‘GAttrib’
78 | guint gatt_discover_desc(GAttrib *attrib, uint16_t start, uint16_t end,
| ^~~~~~~
./attrib/gatt.h:82:32: error: unknown type name ‘GAttrib’
82 | guint gatt_reliable_write_char(GAttrib *attrib, uint16_t handle,
| ^~~~~~~
./attrib/gatt.h:84:41: error: unknown type name ‘GAttribResultFunc’

   84 |                                         GAttribResultFunc func,
      |                                         ^~~~~~~~~~~~~~~~~

./attrib/gatt.h:87:26: error: unknown type name ‘GAttrib’
87 | guint gatt_execute_write(GAttrib *attrib, uint8_t flags,
| ^~~~~~~
./attrib/gatt.h:88:33: error: unknown type name ‘GAttribResultFunc’

   88 |                                 GAttribResultFunc func, gpointer user_data);
      |                                 ^~~~~~~~~~~~~~~~~
./attrib/gatt.h:90:22: error: unknown type name ‘GAttrib’
   90 | guint gatt_write_cmd(GAttrib *attrib, uint16_t handle, const uint8_t *value,
      |                      ^~~~~~~

./attrib/gatt.h:93:29: error: unknown type name ‘GAttrib’
93 | guint gatt_signed_write_cmd(GAttrib *attrib, uint16_t handle,
| ^~~~~~~
./attrib/gatt.h:100:30: error: unknown type name ‘GAttrib’
100 | guint gatt_read_char_by_uuid(GAttrib *attrib, uint16_t start, uint16_t end,
| ^~~~~~~
./attrib/gatt.h:101:50: error: unknown type name ‘GAttribResultFunc’
101 | bt_uuid_t *uuid, GAttribResultFunc func,

      |                                                  ^~~~~~~~~~~~~~~~~

./attrib/gatt.h:104:25: error: unknown type name ‘GAttrib’
104 | guint gatt_exchange_mtu(GAttrib *attrib, uint16_t mtu, GAttribResultFunc func,
| ^~~~~~~
./attrib/gatt.h:104:56: error: unknown type name ‘GAttribResultFunc’
104 | guint gatt_exchange_mtu(GAttrib *attrib, uint16_t mtu, GAttribResultFunc func,
| ^~~~~~~~~~~~~~~~~
make[1]: *** [Makefile:7232: src/adapter.o] Error 1
make[1]: *** Waiting for unfinished jobs....
make: *** [Makefile:4303: all] Error 2
[BlueZ,v6,21/23] device: Use bt_att instead of GAttrib

In file included from src/adapter.c:63:
./attrib/gatt.h:61:29: error: unknown type name ‘GAttrib’
61 | guint gatt_discover_primary(GAttrib *attrib, bt_uuid_t *uuid, gatt_cb_t func,
| ^~~~~~~
./attrib/gatt.h:64:33: error: unknown type name ‘GAttrib’
64 | unsigned int gatt_find_included(GAttrib *attrib, uint16_t start, uint16_t end,
| ^~~~~~~
./attrib/gatt.h:67:26: error: unknown type name ‘GAttrib’
67 | guint gatt_discover_char(GAttrib *attrib, uint16_t start, uint16_t end,
| ^~~~~~~
./attrib/gatt.h:71:22: error: unknown type name ‘GAttrib’
71 | guint gatt_read_char(GAttrib *attrib, uint16_t handle, GAttribResultFunc func,

      |                      ^~~~~~~

./attrib/gatt.h:71:56: error: unknown type name ‘GAttribResultFunc’
71 | guint gatt_read_char(GAttrib *attrib, uint16_t handle, GAttribResultFunc func,
| ^~~~~~~~~~~~~~~~~
./attrib/gatt.h:74:23: error: unknown type name ‘GAttrib’
74 | guint gatt_write_char(GAttrib *attrib, uint16_t handle, const uint8_t *value,

      |                       ^~~~~~~

./attrib/gatt.h:75:54: error: unknown type name ‘GAttribResultFunc’
75 | size_t vlen, GAttribResultFunc func,
| ^~~~~~~~~~~~~~~~~
./attrib/gatt.h:78:26: error: unknown type name ‘GAttrib’
78 | guint gatt_discover_desc(GAttrib *attrib, uint16_t start, uint16_t end,
| ^~~~~~~
./attrib/gatt.h:82:32: error: unknown type name ‘GAttrib’
82 | guint gatt_reliable_write_char(GAttrib *attrib, uint16_t handle,
| ^~~~~~~
./attrib/gatt.h:84:41: error: unknown type name ‘GAttribResultFunc’

   84 |                                         GAttribResultFunc func,
      |                                         ^~~~~~~~~~~~~~~~~

./attrib/gatt.h:87:26: error: unknown type name ‘GAttrib’
87 | guint gatt_execute_write(GAttrib *attrib, uint8_t flags,
| ^~~~~~~
./attrib/gatt.h:88:33: error: unknown type name ‘GAttribResultFunc’

   88 |                                 GAttribResultFunc func, gpointer user_data);
      |                                 ^~~~~~~~~~~~~~~~~
./attrib/gatt.h:90:22: error: unknown type name ‘GAttrib’
   90 | guint gatt_write_cmd(GAttrib *attrib, uint16_t handle, const uint8_t *value,
      |                      ^~~~~~~

./attrib/gatt.h:93:29: error: unknown type name ‘GAttrib’
93 | guint gatt_signed_write_cmd(GAttrib *attrib, uint16_t handle,
| ^~~~~~~
./attrib/gatt.h:100:30: error: unknown type name ‘GAttrib’
100 | guint gatt_read_char_by_uuid(GAttrib *attrib, uint16_t start, uint16_t end,
| ^~~~~~~
./attrib/gatt.h:101:50: error: unknown type name ‘GAttribResultFunc’
101 | bt_uuid_t *uuid, GAttribResultFunc func,

      |                                                  ^~~~~~~~~~~~~~~~~

./attrib/gatt.h:104:25: error: unknown type name ‘GAttrib’
104 | guint gatt_exchange_mtu(GAttrib *attrib, uint16_t mtu, GAttribResultFunc func,
| ^~~~~~~
./attrib/gatt.h:104:56: error: unknown type name ‘GAttribResultFunc’
104 | guint gatt_exchange_mtu(GAttrib *attrib, uint16_t mtu, GAttribResultFunc func,
| ^~~~~~~~~~~~~~~~~
make[1]: *** [Makefile:7232: src/adapter.o] Error 1
make[1]: *** Waiting for unfinished jobs....
make: *** [Makefile:4303: all] Error 2
##############################
Test: ScanBuild - FAIL
Desc: Run Scan Build
Output:

src/shared/gatt-client.c:457:21: warning: Use of memory after it is freed [unix.Malloc]

  457 |         gatt_db_unregister(op->client->db, op->db_id);
      |                            ^~~~~~~~~~
src/shared/gatt-client.c:702:2: warning: Use of memory after it is freed [unix.Malloc]
  702 |         discovery_op_complete(op, false, att_ecode);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/shared/gatt-client.c:1108:2: warning: Use of memory after it is freed [unix.Malloc]
 1108 |         discovery_op_complete(op, success, att_ecode);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/shared/gatt-client.c:1302:2: warning: Use of memory after it is freed [unix.Malloc]
 1302 |         discovery_op_complete(op, success, att_ecode);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/shared/gatt-client.c:1367:2: warning: Use of memory after it is freed [unix.Malloc]
 1367 |         discovery_op_complete(op, success, att_ecode);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/shared/gatt-client.c:1642:6: warning: Use of memory after it is freed [unix.Malloc]
 1642 |         if (read_db_hash(op)) {
      |             ^~~~~~~~~~~~~~~~
src/shared/gatt-client.c:1647:2: warning: Use of memory after it is freed [unix.Malloc]
 1647 |         discover_all(op);
      |         ^~~~~~~~~~~~~~~~
src/shared/gatt-client.c:1703:56: warning: Use of memory after it is freed [unix.Malloc]
 1703 |         notify_data->chrc->ccc_write_id = notify_data->att_id = att_id;
      |                                           ~~~~~~~~~~~~~~~~~~~ ^
src/shared/gatt-client.c:2156:6: warning: Use of memory after it is freed [unix.Malloc]
 2156 |         if (read_db_hash(op)) {
      |             ^~~~~~~~~~~~~~~~
src/shared/gatt-client.c:2164:8: warning: Use of memory after it is freed [unix.Malloc]
 2164 |                                                         discovery_op_ref(op),
      |                                                         ^~~~~~~~~~~~~~~~~~~~
src/shared/gatt-client.c:3350:2: warning: Use of memory after it is freed [unix.Malloc]
 3350 |         complete_write_long_op(req, success, 0, false);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/shared/gatt-client.c:3372:2: warning: Use of memory after it is freed [unix.Malloc]
 3372 |         request_unref(req);
      |         ^~~~~~~~~~~~~~~~~~

12 warnings generated.
src/shared/rap.c:3322:30: warning: Assigned value is uninitialized [core.uninitialized.Assign]
3322 | out->tone_pct[k].i_sample = tone_pct_i[k];
| ^ ~~~~~~~~~~~~~
src/shared/rap.c:4269:13: warning: Use of memory after it is freed [unix.Malloc]

 4269 |         attached = queue_find(sessions, NULL, rap);
      |                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 warnings generated.
src/shared/bap.c:1543:8: warning: Use of memory after it is freed [unix.Malloc]
 1543 |         bap = bt_bap_ref_safe(bap);
      |               ^~~~~~~~~~~~~~~~~~~~
src/shared/bap.c:2359:20: warning: Use of memory after it is freed [unix.Malloc]
 2359 |         return queue_find(stream->bap->streams, NULL, stream);
      |                           ^~~~~~~~~~~~~~~~~~~~
2 warnings generated.
src/shared/gatt-client.c:457:21: warning: Use of memory after it is freed [unix.Malloc]
  457 |         gatt_db_unregister(op->client->db, op->db_id);
      |                            ^~~~~~~~~~
src/shared/gatt-client.c:702:2: warning: Use of memory after it is freed [unix.Malloc]
  702 |         discovery_op_complete(op, false, att_ecode);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/shared/gatt-client.c:1108:2: warning: Use of memory after it is freed [unix.Malloc]
 1108 |         discovery_op_complete(op, success, att_ecode);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/shared/gatt-client.c:1302:2: warning: Use of memory after it is freed [unix.Malloc]
 1302 |         discovery_op_complete(op, success, att_ecode);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/shared/gatt-client.c:1367:2: warning: Use of memory after it is freed [unix.Malloc]
 1367 |         discovery_op_complete(op, success, att_ecode);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/shared/gatt-client.c:1642:6: warning: Use of memory after it is freed [unix.Malloc]
 1642 |         if (read_db_hash(op)) {
      |             ^~~~~~~~~~~~~~~~
src/shared/gatt-client.c:1647:2: warning: Use of memory after it is freed [unix.Malloc]
 1647 |         discover_all(op);
      |         ^~~~~~~~~~~~~~~~
src/shared/gatt-client.c:1703:56: warning: Use of memory after it is freed [unix.Malloc]
 1703 |         notify_data->chrc->ccc_write_id = notify_data->att_id = att_id;
      |                                           ~~~~~~~~~~~~~~~~~~~ ^
src/shared/gatt-client.c:2156:6: warning: Use of memory after it is freed [unix.Malloc]
 2156 |         if (read_db_hash(op)) {
      |             ^~~~~~~~~~~~~~~~
src/shared/gatt-client.c:2164:8: warning: Use of memory after it is freed [unix.Malloc]
 2164 |                                                         discovery_op_ref(op),
      |                                                         ^~~~~~~~~~~~~~~~~~~~
src/shared/gatt-client.c:3350:2: warning: Use of memory after it is freed [unix.Malloc]
 3350 |         complete_write_long_op(req, success, 0, false);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/shared/gatt-client.c:3372:2: warning: Use of memory after it is freed [unix.Malloc]
 3372 |         request_unref(req);
      |         ^~~~~~~~~~~~~~~~~~

12 warnings generated.
src/shared/rap.c:3322:30: warning: Assigned value is uninitialized [core.uninitialized.Assign]
3322 | out->tone_pct[k].i_sample = tone_pct_i[k];
| ^ ~~~~~~~~~~~~~
src/shared/rap.c:4269:13: warning: Use of memory after it is freed [unix.Malloc]

 4269 |         attached = queue_find(sessions, NULL, rap);
      |                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 warnings generated.
tools/hciattach_ath3k.c:530:9: warning: File position of the stream might be 'indeterminate' after a failed operation. Can cause undefined behavior [unix.Stream]
  530 |                         if (!fgets(byte, 3, stream))
      |                              ^~~~~~~~~~~~~~~~~~~~~~
tools/hciattach_ath3k.c:530:9: warning: Read function called when stream is in EOF state. Function has no effect [unix.Stream]
  530 |                         if (!fgets(byte, 3, stream))
      |                              ^~~~~~~~~~~~~~~~~~~~~~
2 warnings generated.
tools/hciattach.c:817:7: warning: Although the value stored to 'n' is used in the enclosing expression, the value is never actually read from 'n' [deadcode.DeadStores]
  817 |         if ((n = read_hci_event(fd, resp, 10)) < 0) {
      |              ^   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tools/hciattach.c:865:7: warning: Although the value stored to 'n' is used in the enclosing expression, the value is never actually read from 'n' [deadcode.DeadStores]
  865 |         if ((n = read_hci_event(fd, resp, 4)) < 0) {
      |              ^   ~~~~~~~~~~~~~~~~~~~~~~~~~~~
tools/hciattach.c:887:8: warning: Although the value stored to 'n' is used in the enclosing expression, the value is never actually read from 'n' [deadcode.DeadStores]
  887 |                 if ((n = read_hci_event(fd, resp, 10)) < 0) {
      |                      ^   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tools/hciattach.c:909:7: warning: Although the value stored to 'n' is used in the enclosing expression, the value is never actually read from 'n' [deadcode.DeadStores]
  909 |         if ((n = read_hci_event(fd, resp, 4)) < 0) {
      |              ^   ~~~~~~~~~~~~~~~~~~~~~~~~~~~
tools/hciattach.c:930:7: warning: Although the value stored to 'n' is used in the enclosing expression, the value is never actually read from 'n' [deadcode.DeadStores]
  930 |         if ((n = read_hci_event(fd, resp, 4)) < 0) {
      |              ^   ~~~~~~~~~~~~~~~~~~~~~~~~~~~
tools/hciattach.c:974:7: warning: Although the value stored to 'n' is used in the enclosing expression, the value is never actually read from 'n' [deadcode.DeadStores]
  974 |         if ((n = read_hci_event(fd, resp, 6)) < 0) {
      |              ^   ~~~~~~~~~~~~~~~~~~~~~~~~~~~
6 warnings generated.
src/shared/bap.c:1543:8: warning: Use of memory after it is freed [unix.Malloc]
 1543 |         bap = bt_bap_ref_safe(bap);
      |               ^~~~~~~~~~~~~~~~~~~~
src/shared/bap.c:2359:20: warning: Use of memory after it is freed [unix.Malloc]
 2359 |         return queue_find(stream->bap->streams, NULL, stream);
      |                           ^~~~~~~~~~~~~~~~~~~~
2 warnings generated.
src/oui.c:50:2: warning: Value stored to 'hwdb' is never read [deadcode.DeadStores]
   50 |         hwdb = udev_hwdb_unref(hwdb);
      |         ^      ~~~~~~~~~~~~~~~~~~~~~
src/oui.c:53:2: warning: Value stored to 'udev' is never read [deadcode.DeadStores]
   53 |         udev = udev_unref(udev);
      |         ^      ~~~~~~~~~~~~~~~~
2 warnings generated.
tools/rfcomm.c:234:3: warning: Value stored to 'i' is never read [deadcode.DeadStores]
  234 |                 i = execvp(cmdargv[0], cmdargv);
      |                 ^   ~~~~~~~~~~~~~~~~~~~~~~~~~~~
tools/rfcomm.c:234:7: warning: Null pointer passed to 1st parameter expecting 'nonnull' [core.NonNullParamChecker]
  234 |                 i = execvp(cmdargv[0], cmdargv);
      |                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~
tools/rfcomm.c:354:8: warning: Although the value stored to 'fd' is used in the enclosing expression, the value is never actually read from 'fd' [deadcode.DeadStores]
  354 |                 if ((fd = open(devname, O_RDONLY | O_NOCTTY)) < 0) {
      |                      ^    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tools/rfcomm.c:473:6: warning: The 1st argument to 'getsockname' is -1 but should be >= 0 [unix.StdCLibraryFunctions]
  473 |         if (getsockname(nsk, (struct sockaddr *)&laddr, &alen) < 0) {
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tools/rfcomm.c:497:14: warning: Assigned value is uninitialized [core.uninitialized.Assign]
  497 |         req.channel = raddr.rc_channel;
      |                     ^ ~~~~~~~~~~~~~~~~
tools/rfcomm.c:515:8: warning: Although the value stored to 'fd' is used in the enclosing expression, the value is never actually read from 'fd' [deadcode.DeadStores]
  515 |                 if ((fd = open(devname, O_RDONLY | O_NOCTTY)) < 0) {
      |                      ^    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6 warnings generated.
tools/ciptool.c:351:7: warning: 5th function call argument is an uninitialized value [core.CallAndMessage]
  351 |         sk = do_connect(ctl, dev_id, &src, &dst, psm, (1 << CMTP_LOOPBACK));
      |              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
tools/sdptool.c:941:26: warning: Result of 'malloc' is converted to a pointer of type 'uint32_t', which is incompatible with sizeof operand type 'int' [unix.MallocSizeof]
  941 |                         uint32_t *value_int = malloc(sizeof(int));
      |                         ~~~~~~~~~~            ^~~~~~ ~~~~~~~~~~~
tools/sdptool.c:980:4: warning: 1st function call argument is an uninitialized value [core.CallAndMessage]
  980 |                         free(allocArray[i]);
      |                         ^~~~~~~~~~~~~~~~~~~
tools/sdptool.c:3777:2: warning: Potential leak of memory pointed to by 'si.name' [unix.Malloc]
 3777 |         return add_service(0, &si);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~
tools/sdptool.c:4112:4: warning: Potential leak of memory pointed to by 'context.svc' [unix.Malloc]
 4112 |                         return -1;
      |                         ^~~~~~~~~
4 warnings generated.
src/sdp-xml.c:129:10: warning: Assigned value is uninitialized [core.uninitialized.Assign]
  129 |                 buf[1] = data[i + 1];
      |                        ^ ~~~~~~~~~~~
src/sdp-xml.c:309:11: warning: Assigned value is uninitialized [core.uninitialized.Assign]
  309 |                         buf[1] = data[i + 1];
      |                                ^ ~~~~~~~~~~~
src/sdp-xml.c:347:11: warning: Assigned value is uninitialized [core.uninitialized.Assign]
  347 |                         buf[1] = data[i + 1];
      |                                ^ ~~~~~~~~~~~
3 warnings generated.
tools/rfcomm-tester.c:410:6: warning: The 1st argument to 'bind' is -1 but should be >= 0 [unix.StdCLibraryFunctions]
  410 |         if (bind(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tools/rfcomm-tester.c:428:8: warning: The 1st argument to 'connect' is -1 but should be >= 0 [unix.StdCLibraryFunctions]
  428 |         err = connect(sk, (struct sockaddr *) &addr, sizeof(addr));
      |               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 warnings generated.
tools/avtest.c:243:5: warning: Value stored to 'len' is never read [deadcode.DeadStores]
  243 |                                 len = write(sk, buf, 3);
      |                                 ^     ~~~~~~~~~~~~~~~~~
tools/avtest.c:253:5: warning: Value stored to 'len' is never read [deadcode.DeadStores]
  253 |                                 len = write(sk, buf, 4);
      |                                 ^     ~~~~~~~~~~~~~~~~~
tools/avtest.c:262:5: warning: Value stored to 'len' is never read [deadcode.DeadStores]
  262 |                                 len = write(sk, buf, 3);
      |                                 ^     ~~~~~~~~~~~~~~~~~
tools/avtest.c:276:5: warning: Value stored to 'len' is never read [deadcode.DeadStores]
  276 |                                 len = write(sk, buf,
      |                                 ^     ~~~~~~~~~~~~~~
  277 |                                                 3 + sizeof(media_transport));
      |                                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tools/avtest.c:283:5: warning: Value stored to 'len' is never read [deadcode.DeadStores]
  283 |                                 len = write(sk, buf,
      |                                 ^     ~~~~~~~~~~~~~~
  284 |                                                 1 + media_transport_size);
      |                                                 ~~~~~~~~~~~~~~~~~~~~~~~~~
tools/avtest.c:290:5: warning: Value stored to 'len' is never read [deadcode.DeadStores]
  290 |                                 len = write(sk, buf,
      |                                 ^     ~~~~~~~~~~~~~~
  291 |                                                 1 + media_transport_size);
      |                                                 ~~~~~~~~~~~~~~~~~~~~~~~~~
tools/avtest.c:297:5: warning: Value stored to 'len' is never read [deadcode.DeadStores]
  297 |                                 len = write(sk, buf,
      |                                 ^     ~~~~~~~~~~~~~~
  298 |                                                 2 + media_transport_size);
      |                                                 ~~~~~~~~~~~~~~~~~~~~~~~~~
tools/avtest.c:309:5: warning: Value stored to 'len' is never read [deadcode.DeadStores]
  309 |                                 len = write(sk, buf, 4);
      |                                 ^     ~~~~~~~~~~~~~~~~~
tools/avtest.c:313:5: warning: Value stored to 'len' is never read [deadcode.DeadStores]
  313 |                                 len = write(sk, buf, 2);
      |                                 ^     ~~~~~~~~~~~~~~~~~
tools/avtest.c:322:5: warning: Value stored to 'len' is never read [deadcode.DeadStores]
  322 |                                 len = write(sk, buf, 3);
      |                                 ^     ~~~~~~~~~~~~~~~~~
tools/avtest.c:326:5: warning: Value stored to 'len' is never read [deadcode.DeadStores]
  326 |                                 len = write(sk, buf, 2);
      |                                 ^     ~~~~~~~~~~~~~~~~~
tools/avtest.c:335:5: warning: Value stored to 'len' is never read [deadcode.DeadStores]
  335 |                                 len = write(sk, buf, 3);
      |                                 ^     ~~~~~~~~~~~~~~~~~
tools/avtest.c:342:5: warning: Value stored to 'len' is never read [deadcode.DeadStores]
  342 |                                 len = write(sk, buf, 2);
      |                                 ^     ~~~~~~~~~~~~~~~~~
tools/avtest.c:364:5: warning: Value stored to 'len' is never read [deadcode.DeadStores]
  364 |                                 len = write(sk, buf, 4);
      |                                 ^     ~~~~~~~~~~~~~~~~~
tools/avtest.c:368:5: warning: Value stored to 'len' is never read [deadcode.DeadStores]
  368 |                                 len = write(sk, buf, 2);
      |                                 ^     ~~~~~~~~~~~~~~~~~
tools/avtest.c:377:5: warning: Value stored to 'len' is never read [deadcode.DeadStores]
  377 |                                 len = write(sk, buf, 3);
      |                                 ^     ~~~~~~~~~~~~~~~~~
tools/avtest.c:381:5: warning: Value stored to 'len' is never read [deadcode.DeadStores]
  381 |                                 len = write(sk, buf, 2);
      |                                 ^     ~~~~~~~~~~~~~~~~~
tools/avtest.c:394:5: warning: Value stored to 'len' is never read [deadcode.DeadStores]
  394 |                                 len = write(sk, buf, 4);
      |                                 ^     ~~~~~~~~~~~~~~~~~
tools/avtest.c:398:5: warning: Value stored to 'len' is never read [deadcode.DeadStores]
  398 |                                 len = write(sk, buf, 2);
      |                                 ^     ~~~~~~~~~~~~~~~~~
tools/avtest.c:405:4: warning: Value stored to 'len' is never read [deadcode.DeadStores]
  405 |                         len = write(sk, buf, 2);
      |                         ^     ~~~~~~~~~~~~~~~~~
tools/avtest.c:415:4: warning: Value stored to 'len' is never read [deadcode.DeadStores]
  415 |                         len = write(sk, buf, 2);
      |                         ^     ~~~~~~~~~~~~~~~~~
tools/avtest.c:580:3: warning: Value stored to 'len' is never read [deadcode.DeadStores]
  580 |                 len = write(sk, buf, 2);
      |                 ^     ~~~~~~~~~~~~~~~~~
tools/avtest.c:588:3: warning: Value stored to 'len' is never read [deadcode.DeadStores]
  588 |                 len = write(sk, buf, invalid ? 2 : 3);
      |                 ^     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tools/avtest.c:602:3: warning: Value stored to 'len' is never read [deadcode.DeadStores]
  602 |                 len = write(sk, buf, 4 + media_transport_size);
      |                 ^     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tools/avtest.c:615:3: warning: Value stored to 'len' is never read [deadcode.DeadStores]
  615 |                 len = write(sk, buf, 3);
      |                 ^     ~~~~~~~~~~~~~~~~~
tools/avtest.c:625:3: warning: Value stored to 'len' is never read [deadcode.DeadStores]
  625 |                 len = write(sk, buf, 3);
      |                 ^     ~~~~~~~~~~~~~~~~~
tools/avtest.c:637:3: warning: Value stored to 'len' is never read [deadcode.DeadStores]
  637 |                 len = write(sk, buf, 3);
      |                 ^     ~~~~~~~~~~~~~~~~~
tools/avtest.c:652:3: warning: Value stored to 'len' is never read [deadcode.DeadStores]
  652 |                 len = write(sk, buf, 3);
      |                 ^     ~~~~~~~~~~~~~~~~~
tools/avtest.c:664:3: warning: Value stored to 'len' is never read [deadcode.DeadStores]
  664 |                 len = write(sk, buf, 3);
      |                 ^     ~~~~~~~~~~~~~~~~~
tools/avtest.c:673:3: warning: Value stored to 'len' is never read [deadcode.DeadStores]
  673 |                 len = write(sk, buf, 3);
      |                 ^     ~~~~~~~~~~~~~~~~~
tools/avtest.c:680:3: warning: Value stored to 'len' is never read [deadcode.DeadStores]
  680 |                 len = write(sk, buf, 2);
      |                 ^     ~~~~~~~~~~~~~~~~~
tools/avtest.c:716:2: warning: Value stored to 'len' is never read [deadcode.DeadStores]
  716 |         len = write(sk, buf, AVCTP_HEADER_LENGTH + sizeof(play_pressed));
      |         ^     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
32 warnings generated.
tools/create-image.c:76:3: warning: Value stored to 'fd' is never read [deadcode.DeadStores]
   76 |                 fd = -1;
      |                 ^    ~~
tools/create-image.c:84:3: warning: Value stored to 'fd' is never read [deadcode.DeadStores]
   84 |                 fd = -1;
      |                 ^    ~~
tools/create-image.c:92:3: warning: Value stored to 'fd' is never read [deadcode.DeadStores]
   92 |                 fd = -1;
      |                 ^    ~~
tools/create-image.c:105:2: warning: Value stored to 'fd' is never read [deadcode.DeadStores]
  105 |         fd = -1;
      |         ^    ~~
tools/create-image.c:108:2: warning: Null pointer passed to 1st parameter expecting 'nonnull' [core.NonNullParamChecker]
  108 |         fprintf(fp, HDR_FMT, HDR_MAGIC, ino, mode, 0, 0, 1, 0,
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  109 |                 (uintmax_t) st.st_size, 0, 0, 0, 0, namelen + 1, 0, name);
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tools/create-image.c:188:2: warning: Null pointer passed to 1st parameter expecting 'nonnull' [core.NonNullParamChecker]
  188 |         fclose(fp);
      |         ^~~~~~~~~~
6 warnings generated.
tools/btgatt-client.c:1822:2: warning: Value stored to 'argv' is never read [deadcode.DeadStores]
 1822 |         argv += optind;
      |         ^       ~~~~~~
1 warning generated.
tools/btgatt-server.c:1204:2: warning: Value stored to 'argv' is never read [deadcode.DeadStores]
 1204 |         argv -= optind;
      |         ^       ~~~~~~
1 warning generated.
tools/check-selftest.c:42:3: warning: Value stored to 'ptr' is never read [deadcode.DeadStores]
   42 |                 ptr = fgets(result, sizeof(result), fp);
      |                 ^     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
tools/gatt-service.c:294:2: warning: 2nd function call argument is an uninitialized value [core.CallAndMessage]
  294 |         chr_write(chr, value, len);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~

1 warning generated.
In file included from tools/obex-server-tool.c:17:
In file included from /usr/include/fcntl.h:342:
/usr/include/x86_64-linux-gnu/bits/fcntl2.h:76:10: warning: Null pointer passed to 1st parameter expecting 'nonnull' [core.NonNullParamChecker]

   76 |   return __open_alias (__path, __oflag, __mode);
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
client/btpclient/btpclientctl.c:402:3: warning: Value stored to 'bit' is never read [deadcode.DeadStores]
  402 |                 bit = 0;
      |                 ^     ~
client/btpclient/btpclientctl.c:1655:2: warning: Null pointer passed to 2nd parameter expecting 'nonnull' [core.NonNullParamChecker]
 1655 |         memcpy(cp->data, ad_data, ad_len);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 warnings generated.
src/sdp-client.c:353:14: warning: Access to field 'cb' results in a dereference of a null pointer [core.NullDereference]
  353 |         (*ctxt)->cb = cb;
      |         ~~~~~~~~~~~~^~~~
1 warning generated.
src/sdpd-request.c:209:13: warning: Result of 'malloc' is converted to a pointer of type 'char', which is incompatible with sizeof operand type 'uint16_t' [unix.MallocSizeof]
  209 |                                 pElem = malloc(sizeof(uint16_t));
      |                                         ^~~~~~ ~~~~~~~~~~~~~~~~
src/sdpd-request.c:237:13: warning: Result of 'malloc' is converted to a pointer of type 'char', which is incompatible with sizeof operand type 'uint32_t' [unix.MallocSizeof]
  237 |                                 pElem = malloc(sizeof(uint32_t));
      |                                         ^~~~~~ ~~~~~~~~~~~~~~~~

2 warnings generated.
In file included from src/adapter.c:63:
./attrib/gatt.h:61:29: error: unknown type name ‘GAttrib’
61 | guint gatt_discover_primary(GAttrib *attrib, bt_uuid_t *uuid, gatt_cb_t func,
| ^~~~~~~
./attrib/gatt.h:64:33: error: unknown type name ‘GAttrib’
64 | unsigned int gatt_find_included(GAttrib *attrib, uint16_t start, uint16_t end,
| ^~~~~~~
./attrib/gatt.h:67:26: error: unknown type name ‘GAttrib’
67 | guint gatt_discover_char(GAttrib *attrib, uint16_t start, uint16_t end,
| ^~~~~~~
./attrib/gatt.h:71:22: error: unknown type name ‘GAttrib’
71 | guint gatt_read_char(GAttrib *attrib, uint16_t handle, GAttribResultFunc func,

      |                      ^~~~~~~

./attrib/gatt.h:71:56: error: unknown type name ‘GAttribResultFunc’
71 | guint gatt_read_char(GAttrib *attrib, uint16_t handle, GAttribResultFunc func,
| ^~~~~~~~~~~~~~~~~
./attrib/gatt.h:74:23: error: unknown type name ‘GAttrib’
74 | guint gatt_write_char(GAttrib *attrib, uint16_t handle, const uint8_t *value,

      |                       ^~~~~~~

./attrib/gatt.h:75:54: error: unknown type name ‘GAttribResultFunc’
75 | size_t vlen, GAttribResultFunc func,
| ^~~~~~~~~~~~~~~~~
./attrib/gatt.h:78:26: error: unknown type name ‘GAttrib’
78 | guint gatt_discover_desc(GAttrib *attrib, uint16_t start, uint16_t end,
| ^~~~~~~
./attrib/gatt.h:82:32: error: unknown type name ‘GAttrib’
82 | guint gatt_reliable_write_char(GAttrib *attrib, uint16_t handle,
| ^~~~~~~
./attrib/gatt.h:84:41: error: unknown type name ‘GAttribResultFunc’

   84 |                                         GAttribResultFunc func,
      |                                         ^~~~~~~~~~~~~~~~~

./attrib/gatt.h:87:26: error: unknown type name ‘GAttrib’
87 | guint gatt_execute_write(GAttrib *attrib, uint8_t flags,
| ^~~~~~~
./attrib/gatt.h:88:33: error: unknown type name ‘GAttribResultFunc’

   88 |                                 GAttribResultFunc func, gpointer user_data);
      |                                 ^~~~~~~~~~~~~~~~~
./attrib/gatt.h:90:22: error: unknown type name ‘GAttrib’
   90 | guint gatt_write_cmd(GAttrib *attrib, uint16_t handle, const uint8_t *value,
      |                      ^~~~~~~

./attrib/gatt.h:93:29: error: unknown type name ‘GAttrib’
93 | guint gatt_signed_write_cmd(GAttrib *attrib, uint16_t handle,
| ^~~~~~~
./attrib/gatt.h:100:30: error: unknown type name ‘GAttrib’
100 | guint gatt_read_char_by_uuid(GAttrib *attrib, uint16_t start, uint16_t end,
| ^~~~~~~
./attrib/gatt.h:101:50: error: unknown type name ‘GAttribResultFunc’
101 | bt_uuid_t *uuid, GAttribResultFunc func,

      |                                                  ^~~~~~~~~~~~~~~~~

./attrib/gatt.h:104:25: error: unknown type name ‘GAttrib’
104 | guint gatt_exchange_mtu(GAttrib *attrib, uint16_t mtu, GAttribResultFunc func,
| ^~~~~~~
./attrib/gatt.h:104:56: error: unknown type name ‘GAttribResultFunc’
104 | guint gatt_exchange_mtu(GAttrib *attrib, uint16_t mtu, GAttribResultFunc func,
| ^~~~~~~~~~~~~~~~~
make[1]: *** [Makefile:7232: src/adapter.o] Error 1
make[1]: *** Waiting for unfinished jobs....
make: *** [Makefile:4303: all] Error 2

https://github.com/bluez/bluez/pull/2600

---
Regards,
Linux Bluetooth

#3 lore raw
In reply to Luiz Augusto von Dentz

This is an automated email and please do not reply to this email.

Dear Submitter,

This series was picked up by the CI more than 2 weeks ago and the pull request created for it is still open, which means the series was never applied to the tree.

Series: Add HoG functional tests and shared/hog
Pull Request: https://github.com/bluez/bluez/pull/2600
Created: 2026-09-28 21:31:18+00:00

The pull request has been closed and no further action is taken on this series.

If the change should still be considered, it must be resent to the Linux Bluetooth mailing list ([email protected]) so that it is picked up again.

---
Regards,
Linux Bluetooth

author maintainer
#4 lore raw

PATCH v6 2/23 client/gatt: Fix setting descriptor value from scripts

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

gatt.register-descriptor completed the command right after prompting for the value, so when run from a script the line with the value was executed as a command instead of being passed to the prompt, causing the descriptor to be unregistered.

Complete the command once the value is set, as done for characteristics, and parse a copy of the value so the input line is not truncated by strsep while still in use by the shell.

As invalid values can now come from scripts, fix handling them: the attribute is no longer used once unregistered, which frees it, nor kept in the list of its parent, and the command fails. Also stop counting the empty entries between the values, which left bytes uninitialized, and reject negative values.

Assisted-by OpenCode:claude-opus-5.5
---
 client/gatt.c | 39 ++++++++++++++++++++++++++++-----------
 1 file changed, 28 insertions(+), 11 deletions(-)
client/gatt.c +28 -11
index 6dc80e2a31cd..a85f6003d9b8 100644
@@ -700,13 +700,21 @@ void gatt_read_local_attribute(char *data, int argc, char *argv[])
 	return bt_shell_noninteractive_quit(EXIT_FAILURE);
 }
 
-static uint8_t *str2bytearray(char *arg, size_t *val_len)
+static uint8_t *str2bytearray(const char *arg, size_t *val_len)
 {
 	uint8_t value[MAX_ATTR_VAL_LEN];
-	char *entry;
+	char *str, *next, *entry;
 	unsigned int i;
 
-	for (i = 0; (entry = strsep(&arg, " \t")) != NULL; i++) {
+	/* Parse a copy as strsep modifies the string, which may still be
+	 * in use by the caller, e.g. the shell printing the input line.
+	 */
+	str = next = strdup(arg);
+	if (!str)
+		return NULL;
+
+	/* Only count the values, not the empty entries in between */
+	for (i = 0; (entry = strsep(&next, " \t")) != NULL;) {
 		long val;
 		char *endptr = NULL;
 
@@ -715,18 +723,22 @@ static uint8_t *str2bytearray(char *arg, size_t *val_len)
 
 		if (i >= G_N_ELEMENTS(value)) {
 			bt_shell_printf("Too much data\n");
+			free(str);
 			return NULL;
 		}
 
 		val = strtol(entry, &endptr, 0);
-		if (!endptr || *endptr != '\0' || val > UINT8_MAX) {
+		if (!endptr || *endptr != '\0' || val < 0 || val > UINT8_MAX) {
 			bt_shell_printf("Invalid value at index %d\n", i);
+			free(str);
 			return NULL;
 		}
 
-		value[i] = val;
+		value[i++] = val;
 	}
 
+	free(str);
+
 	*val_len = i;
 
 	return util_memdup(value, i);
@@ -2788,11 +2800,14 @@ static void chrc_set_value(const char *input, void *user_data)
 
 	g_free(chrc->value);
 
-	chrc->value = str2bytearray((char *) input, &chrc->value_len);
+	chrc->value = str2bytearray(input, &chrc->value_len);
 
 	if (!chrc->value) {
-		print_chrc(chrc, COLORED_DEL);
+		/* Unregistering frees chrc, so it is removed first */
+		chrc->service->chrcs = g_list_remove(chrc->service->chrcs,
+									chrc);
 		chrc_unregister(chrc);
+		return bt_shell_noninteractive_quit(EXIT_FAILURE);
 	}
 
 	chrc->max_val_len = chrc->value_len;
@@ -3078,14 +3093,18 @@ static void desc_set_value(const char *input, void *user_data)
 
 	g_free(desc->value);
 
-	desc->value = str2bytearray((char *) input, &desc->value_len);
+	desc->value = str2bytearray(input, &desc->value_len);
 
 	if (!desc->value) {
-		print_desc(desc, COLORED_DEL);
+		/* Unregistering frees desc, so it is removed first */
+		desc->chrc->descs = g_list_remove(desc->chrc->descs, desc);
 		desc_unregister(desc);
+		return bt_shell_noninteractive_quit(EXIT_FAILURE);
 	}
 
 	desc->max_val_len = desc->value_len;
+
+	return bt_shell_noninteractive_quit(EXIT_SUCCESS);
 }
 
 void gatt_register_desc(DBusConnection *conn, GDBusProxy *proxy,
@@ -3134,8 +3153,6 @@ void gatt_register_desc(DBusConnection *conn, GDBusProxy *proxy,
 	print_desc(desc, COLORED_NEW);
 
 	bt_shell_prompt_input(desc->path, "Enter value:", desc_set_value, desc);
-
-	return bt_shell_noninteractive_quit(EXIT_SUCCESS);
 }
 
 static struct desc *desc_find(const char *pattern)
Signature · 1 line
2.55.0
author maintainer
#5 lore raw

PATCH v6 3/23 client/mgmt: Print Connection Subrate event

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

Print the MGMT Connection Subrate event, generated as a result of a LE Connection Rate Request, e.g. after mgmt.conn-subrate, or a change initiated by the remote device, so the new connection rate can be confirmed.

Assisted-by OpenCode:claude-opus-5.5
---
 client/mgmt.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
client/mgmt.c +31 -0
index cd2ef80221ad..a7069e5bbb37 100644
@@ -499,6 +499,35 @@ static void disconnected(uint16_t index, uint16_t len, const void *param,
 			index, addr, typestr(ev->addr.type), reason);
 }
 
+static void conn_subrate(uint16_t index, uint16_t len, const void *param,
+							void *user_data)
+{
+	const struct mgmt_ev_conn_subrate *ev = param;
+	char addr[18];
+
+	if (len < sizeof(*ev)) {
+		error("Invalid connection subrate event length (%u bytes)",
+									len);
+		return;
+	}
+
+	ba2str(&ev->addr.bdaddr, addr);
+
+	if (ev->status) {
+		print("hci%u %s type %s connection subrate failed status "
+			"0x%02x (%s)", index, addr, typestr(ev->addr.type),
+			ev->status, mgmt_errstr(ev->status));
+		return;
+	}
+
+	print("hci%u %s type %s connection subrate interval 0x%04x "
+		"subrate 0x%04x latency 0x%04x cont_num 0x%04x timeout 0x%04x",
+		index, addr, typestr(ev->addr.type),
+		le16_to_cpu(ev->interval), le16_to_cpu(ev->subrate),
+		le16_to_cpu(ev->latency), le16_to_cpu(ev->cont_num),
+		le16_to_cpu(ev->supv_timeout));
+}
+
 static void conn_failed(uint16_t index, uint16_t len, const void *param,
 							void *user_data)
 {
@@ -6006,6 +6035,8 @@ static void register_mgmt_callbacks(struct mgmt *mgmt, uint16_t index)
 								NULL, NULL);
 	mgmt_register(mgmt, MGMT_EV_CONNECT_FAILED, index, conn_failed,
 								NULL, NULL);
+	mgmt_register(mgmt, MGMT_EV_CONN_SUBRATE, index, conn_subrate,
+								NULL, NULL);
 	mgmt_register(mgmt, MGMT_EV_AUTH_FAILED, index, auth_failed,
 								NULL, NULL);
 	mgmt_register(mgmt, MGMT_EV_CLASS_OF_DEV_CHANGED, index,
Signature · 1 line
2.55.0
author maintainer
#6 lore raw

PATCH v6 4/23 emulator: Default to the latest BR/EDR+LE version

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

Emulate BR/EDR+LE 6.2 controllers by default, for both local (-l) and server (--server, --tcp) controllers, so the latest features such as Shorter Connection Intervals (LE Connection Rate Request) are supported, e.g. by test-functional which uses --server.

Add the -C/--core=<version> option to emulate older versions instead:
5.0, 5.2, 6.0 or 6.2.

Assisted-by OpenCode:claude-opus-5.5
---
 doc/test-functional.rst |  4 ++-
 emulator/main.c         | 55 ++++++++++++++++++++++++++++++++++++++---
 emulator/server.c       | 15 ++++++++++-
 emulator/server.h       |  2 ++
 4 files changed, 71 insertions(+), 5 deletions(-)
doc/test-functional.rst +3 -1
index 3ffcbf6dec5c..826210b73ce7 100644
@@ -227,7 +227,9 @@ Controllers
 
 By default a single ``btvirt`` process runs on the developer machine and
 provides an emulated BR/EDR/LE controller to every VM host over a UNIX
-socket, also bridging the air interface between them::
+socket, also bridging the air interface between them. The controllers
+emulate the latest Core Specification version supported by ``btvirt``,
+6.2, older ones can be emulated with its ``-C/--core`` option::
 
     VM host #0                 developer machine              VM host #1
     ┌────────────┐            ┌─────────────────┐            ┌────────────┐
emulator/main.c +52 -3

122 lines not on this page · raw message

emulator/server.c +14 -1
index e3eda8458ae0..5a827b24531e 100644
@@ -38,6 +38,7 @@
 
 struct server {
 	enum server_type type;
+	enum btdev_type bredrle_type;
 	uint16_t id;
 	int fd;
 	struct queue *clients;
@@ -281,7 +282,7 @@ static void server_accept_callback(int fd, uint32_t events, void *user_data)
 
 	switch (server->type) {
 	case SERVER_TYPE_BREDRLE:
-		type = BTDEV_TYPE_BREDRLE52;
+		type = server->bredrle_type;
 		break;
 	case SERVER_TYPE_BREDR:
 		type = BTDEV_TYPE_BREDR;
@@ -361,6 +362,7 @@ struct server *server_open_unix(enum server_type type, const char *path)
 
 	memset(server, 0, sizeof(*server));
 	server->type = type;
+	server->bredrle_type = BTDEV_TYPE_BREDRLE62;
 	server->id = 0x42;
 
 	server->fd = open_unix(path);
@@ -429,6 +431,7 @@ struct server *server_open_tcp(enum server_type type, uint16_t port)
 
 	memset(server, 0, sizeof(*server));
 	server->type = type;
+	server->bredrle_type = BTDEV_TYPE_BREDRLE62;
 	server->id = 0x43;
 
 	server->fd = open_tcp(port);
@@ -455,6 +458,16 @@ void server_close(struct server *server)
 	mainloop_remove_fd(server->fd);
 }
 
+bool server_set_bredrle_type(struct server *server, enum btdev_type type)
+{
+	if (!server || server->type != SERVER_TYPE_BREDRLE)
+		return false;
+
+	server->bredrle_type = type;
+
+	return true;
+}
+
 bool server_set_debug(struct server *server, server_debug_func_t callback,
 			void *user_data, server_destroy_func_t destroy)
 {
emulator/server.h +2 -0
index 1844a9871af1..5fc3a284f53f 100644
@@ -25,6 +25,8 @@ struct server *server_open_unix(enum server_type type, const char *path);
 struct server *server_open_tcp(enum server_type type, uint16_t port);
 void server_close(struct server *server);
 
+bool server_set_bredrle_type(struct server *server, enum btdev_type type);
+
 typedef void (*server_debug_func_t)(const char *str, void *user_data);
 typedef void (*server_destroy_func_t)(void *user_data);
 bool server_set_debug(struct server *server, server_debug_func_t callback,
Signature · 1 line
2.55.0
author maintainer
#7 lore raw

PATCH v6 5/23 client/scripts: Add HoG device scripts

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

Add scripts registering a HID Service (HIDS) acting as a HID over GATT keyboard, with and without Shorter Connection Interval (SCI) support.

HID SCI Mode can be notified so the device can confirm a mode change.

Assisted-by OpenCode:claude-opus-5.5
---
 client/scripts/hog-device-sci.bt | 49 ++++++++++++++++++++++++++++++++
 client/scripts/hog-device.bt     | 38 +++++++++++++++++++++++++
 2 files changed, 87 insertions(+)
 create mode 100644 client/scripts/hog-device-sci.bt
 create mode 100644 client/scripts/hog-device.bt
client/scripts/hog-device-sci.bt new file +49 -0
new file mode 100644
index 000000000000..1bf3a0a90db7
@@ -0,0 +1,49 @@
+#
+# Register a HID Service (HIDS) acting as a HID over GATT (HoG) keyboard
+# with Shorter Connection Interval (SCI) support.
+#
+gatt.register-service 0x1812
+# Primary
+yes
+#
+# HID Information: bcdHID 1.11, bCountryCode 0x00,
+# Flags: NormallyConnectable and SCI Supported
+gatt.register-characteristic 0x2a4a read
+0x11 0x01 0x00 0x06
+#
+# Report Map: keyboard with Report ID 1
+gatt.register-characteristic 0x2a4b read
+0x05 0x01 0x09 0x06 0xa1 0x01 0x85 0x01 0x05 0x07 0x19 0xe0 0x29 0xe7 0x15 0x00 0x25 0x01 0x75 0x01 0x95 0x08 0x81 0x02 0x95 0x01 0x75 0x08 0x81 0x01 0x95 0x06 0x75 0x08 0x15 0x00 0x25 0x65 0x05 0x07 0x19 0x00 0x29 0x65 0x81 0x00 0xc0
+#
+# Report: Input Report ID 1
+gatt.register-characteristic 0x2a4d read,notify
+0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
+# Report Reference: Report ID 1, Input
+gatt.register-descriptor 0x2908 read
+0x01 0x01
+#
+# Protocol Mode: Report Protocol Mode
+gatt.register-characteristic 0x2a4e read,write-without-response
+0x01
+#
+# HID Control Point
+gatt.register-characteristic 0x2a4c write-without-response
+0x00
+#
+# HID SCI Mode: None (0x00), notified when changed
+gatt.register-characteristic 0x2c39 read,write,notify
+0x00
+#
+# HID SCI Information (intervals in units of 0.125 ms):
+# Minimum Supported Connection Interval: 0x08 (1 ms)
+# Number of Supported Subgroups: 1
+# Subgroup[0]: Min 0x0008 (1 ms) Max 0x0050 (10 ms) Stride 0x0008 (1 ms)
+gatt.register-characteristic 0x2c3a read
+0x08 0x01 0x08 0x00 0x50 0x00 0x08 0x00
+#
+gatt.register-application
+#
+# Advertise as a keyboard with HIDS
+advertise.uuids 0x1812
+advertise.appearance 0x03c1
+power on
client/scripts/hog-device.bt new file +38 -0
new file mode 100644
index 000000000000..42b324eda020
@@ -0,0 +1,38 @@
+#
+# Register a HID Service (HIDS) acting as a HID over GATT (HoG) keyboard
+# without Shorter Connection Interval (SCI) support.
+#
+gatt.register-service 0x1812
+# Primary
+yes
+#
+# HID Information: bcdHID 1.11, bCountryCode 0x00,
+# Flags: NormallyConnectable
+gatt.register-characteristic 0x2a4a read
+0x11 0x01 0x00 0x02
+#
+# Report Map: keyboard with Report ID 1
+gatt.register-characteristic 0x2a4b read
+0x05 0x01 0x09 0x06 0xa1 0x01 0x85 0x01 0x05 0x07 0x19 0xe0 0x29 0xe7 0x15 0x00 0x25 0x01 0x75 0x01 0x95 0x08 0x81 0x02 0x95 0x01 0x75 0x08 0x81 0x01 0x95 0x06 0x75 0x08 0x15 0x00 0x25 0x65 0x05 0x07 0x19 0x00 0x29 0x65 0x81 0x00 0xc0
+#
+# Report: Input Report ID 1
+gatt.register-characteristic 0x2a4d read,notify
+0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
+# Report Reference: Report ID 1, Input
+gatt.register-descriptor 0x2908 read
+0x01 0x01
+#
+# Protocol Mode: Report Protocol Mode
+gatt.register-characteristic 0x2a4e read,write-without-response
+0x01
+#
+# HID Control Point
+gatt.register-characteristic 0x2a4c write-without-response
+0x00
+#
+gatt.register-application
+#
+# Advertise as a keyboard with HIDS
+advertise.uuids 0x1812
+advertise.appearance 0x03c1
+power on
Signature · 1 line
2.55.0
author maintainer
#8 lore raw

PATCH v6 6/23 doc: Add functional-hog documentation

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

Document the HoG functional tests, where bluetoothctl registers a HID Service with and without Shorter Connection Interval (SCI) support using client/scripts/hog-device*.bt, and the HID host:

- checks HID Information, HID SCI Mode and HID SCI Information with gatt.select-attribute/gatt.read
- receives a few Input Reports notified by the HID device
- changes the SCI mode, followed by the connection rate with mgmt.conn-subrate, and receives the notification from the HID device confirming the mode has been changed

Assisted-by OpenCode:claude-opus-5.5
---
 Makefile.am                |   1 +
 doc/functional-hog.rst     | 188 +++++++++++++++++++++++++++++++++++++
 doc/functional-testing.rst |   1 +
 3 files changed, 190 insertions(+)
 create mode 100644 doc/functional-hog.rst
Makefile.am +1 -0
index 53a3a15c3f8b..c88e81f937ff 100644
@@ -501,6 +501,7 @@ EXTRA_DIST += doc/assigned-numbers.rst doc/supported-features.txt \
 				doc/functional-a2dp.rst \
 				doc/functional-avrcp.rst \
 				doc/functional-bap.rst \
+				doc/functional-hog.rst \
 				doc/functional-mpris-proxy.rst \
 				doc/functional-obex.rst \
 				doc/settings-storage.txt
doc/functional-hog.rst new file +188 -0

188 lines not on this page · raw message

doc/functional-testing.rst +1 -0
index ca7bfa672a76..7b3cad1c66b1 100644
@@ -15,6 +15,7 @@ are documented separately:
 - **functional-a2dp(7)**: `test/functional/test_a2dp.py`
 - **functional-avrcp(7)**: `test/functional/test_avrcp.py`
 - **functional-bap(7)**: `test/functional/test_bap.py`
+- **functional-hog(7)**: `test/functional/test_hog.py`
 - **functional-mpris-proxy(7)**: `test/functional/test_mpris_proxy.py`
 - **functional-obex(7)**: `test/functional/test_obex.py`
 
Signature · 1 line
2.55.0
author maintainer
#9 lore raw

PATCH v6 7/23 test: functional: add HoG tests

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

Add tests where bluetoothctl registers a HID Service, with and without SCI support, using client/scripts/hog-device*.bt, and the HID host checks the service, receives Input Reports and, with SCI support, changes the SCI mode and the connection rate.

See doc/functional-hog.rst for details.

Assisted-by OpenCode:claude-opus-5.5
---
 test/functional/test_hog.py | 252 ++++++++++++++++++++++++++++++++++++
 1 file changed, 252 insertions(+)
 create mode 100644 test/functional/test_hog.py
test/functional/test_hog.py new file +252 -0
new file mode 100644
index 000000000000..ea54882d059d
@@ -0,0 +1,252 @@
+# -*- coding: utf-8; mode: python; eval: (blacken-mode); -*-
+# SPDX-License-Identifier: GPL-2.0-or-later
+"""
+Tests for HID over GATT (HoG) using bluetoothctl in VM instances
+
+The HID device (host1) registers a HID Service (HIDS) with bluetoothctl,
+using client/scripts/hog-device.bt or client/scripts/hog-device-sci.bt,
+and the HID host (host0) pairs with it and checks the service over GATT.
+"""
+
+import warnings
+
+import pytest
+
+from pytest_bluezenv import Bluetoothd, Pexpect, find_exe, host_config
+from pytest_bluezenv.utils import bluez_src_dir
+
+pytestmark = [pytest.mark.vm]
+
+# The HID Service is claimed by the input plugin of the HID host, so it
+# has to be exported read-write for bluetoothctl to write HID SCI Mode
+HOG_CONF = """[General]
+ControllerMode = le
+
+[GATT]
+ExportClaimedServices = read-write
+"""
+
+HIDS_UUID = "00001812-0000-1000-8000-00805f9b34fb"
+
+# Local attributes registered by client/scripts/hog-device*.bt
+LOCAL_REPORT = "/org/bluez/app/service0/chrc2"
+LOCAL_SCI_MODE = "/org/bluez/app/service0/chrc5"
+
+# Keyboard Input Reports: Modifiers, Reserved, then 6 Key Codes
+REPORTS = [
+    "00 00 04 00 00 00 00 00",  # a pressed
+    "02 00 05 00 00 00 00 00",  # Left Shift + b pressed
+    "00 00 00 00 00 00 00 00",  # released
+]
+
+# HID SCI Mode: Fast Mode
+SCI_FAST_MODE = "03"
+
+# LE Connection Rate parameters requested with mgmt.conn-subrate once in
+# SCI Fast Mode: interval 1 ms to 2 ms (units of 0.125 ms), within the
+# range given in HID SCI Information, no subrating, no latency and 5 s
+# supervision timeout (units of 10 ms)
+SCI_RATE = ["0x0008", "0x0010", "1", "1", "0", "0", "0x01f4"]
+
+# Reported when an operation cannot complete, so a test does not have to
+# wait for its timeout to know it is not going to
+FAILURES = [
+    r"(Failed to \w+[^\r\n]*)",
+    r"(Device \S+ not available)",
+    r"(No device connected)",
+    r"(No attribute selected)",
+]
+
+# What a command reports is printed as it runs, unlike what the peers
+# report over the air, so waiting the default timeout for it only makes
+# a failure slower
+REPLY_TIMEOUT = 5
+
+
+def script(name):
+    src = bluez_src_dir()
+    if src is None:
+        pytest.skip("BlueZ source directory not known")
+
+    path = src / "client" / "scripts" / name
+    if not path.exists():
+        pytest.skip(f"{path} not found")
+
+    return str(path)
+
+
+def spawn_bluetoothctl(host, init_script=None):
+    exe = find_exe("client", "bluetoothctl")
+    # Accept pairing and authorize services without prompting, with a
+    # capability pairing Just Works, as there is no one to answer the
+    # entry of a passkey
+    args = [exe, "-a", "auto:NoInputNoOutput"]
+    if init_script:
+        args += ["--init-script", script(init_script)]
+    return host.pexpect.spawn(args)
+
+
+def expect(ctl, patterns, **kwargs):
+    """
+    Expect one of the patterns, failing as soon as one of the failures
+    shows up. Return the index of the pattern matched and its groups.
+    """
+    if isinstance(patterns, str):
+        patterns = [patterns]
+
+    idx, m = ctl.expect(FAILURES + list(patterns), **kwargs)
+    if idx < len(FAILURES):
+        raise AssertionError(m[0].decode("utf-8") if m else "failed")
+
+    return idx - len(FAILURES), m
+
+
+def expect_all(ctl, patterns, **kwargs):
+    """Expect all the given patterns, in any order."""
+    pending = list(patterns)
+
+    while pending:
+        idx, _ = expect(ctl, pending, **kwargs)
+        pending.pop(idx)
+
+
+def pair_le(host0, ctl0, host1, ctl1):
+    ctl0.send("scan on\n")
+    expect(ctl0, f"Controller {host0.bdaddr.upper()} Discovering: yes")
+
+    ctl1.send("advertise on\n")
+    expect(ctl1, "Advertising object registered")
+
+    expect(ctl0, f"Device {host1.bdaddr.upper()}")
+    ctl0.send(f"pair {host1.bdaddr.upper()}\n")
+
+    # See test_bluetoothctl_pair_le: passkey confirmation is handled by
+    # the auto agent, but legacy passkey entry still needs an answer
+    legacy = r"\[agent\].*Passkey:.*m(\d+)"
+    pending = [
+        r"Pairing successful",
+        f"Device {host1.bdaddr.upper()} ServicesResolved: yes",
+    ]
+
+    while pending:
+        idx, m = expect(ctl0, [legacy] + pending)
+        if idx == 0:
+            warnings.warn(
+                "BUG: we got passkey authentication, bluetoothd/kernel "
+                "should be fixed"
+            )
+            ctl1.expect(r"\[agent\] Enter passkey \(number in 0-999999\):")
+            ctl1.send(f"{m[0].decode('utf-8')}\n")
+            continue
+        pending.pop(idx - 1)
+
+    ctl0.send("scan off\n")
+
+
+def read_attribute(ctl, uuid):
+    """Read the given remote attribute, returning its value as hex string."""
+    ctl.send(f"gatt.select-attribute {uuid}\n")
+    ctl.send("gatt.read\n")
+    expect(ctl, r"Attempting to read \S+", timeout=REPLY_TIMEOUT)
+    return expect_hexdump(ctl)
+
+
+def hexbytes(value):
+    """Turn a hex string into the format taken by gatt.write."""
+    return " ".join(f"0x{byte}" for byte in value.split())
+
+
+def expect_hexdump(ctl, **kwargs):
+    """Expect a value printed by bluetoothctl, returning it as hex string."""
+    _, m = expect(ctl, r"((?: [0-9a-f]{2})+)  ", **kwargs)
+    return m[0].decode("utf-8").strip()
+
+
+def expect_notification(ctl):
+    """Expect a notification of the remote attribute, returning its value."""
+    expect(ctl, rf"CHG.*? Attribute /\S+ Value:")
+    return expect_hexdump(ctl)
+
+
+def enable_notifications(ctl, device, uuid, local):
+    """Enable notifications of the given attribute, on the HID host."""
+    ctl.send(f"gatt.select-attribute {uuid}\n")
+    ctl.send("gatt.notify on\n")
+    expect(ctl, r"Notify started", timeout=REPLY_TIMEOUT)
+    # Either subscribed with StartNotify, or with AcquireNotify as done by
+    # the input plugin of the HID host for the Input Reports
+    expect(
+        device,
+        rf"Attribute {local} (\S+ )?(notifications enabled|Notify sock acquired)",
+    )
+
+
+def notify(device, local, value):
+    """Notify the given value of a local attribute, on the HID device."""
+    device.send(f"gatt.select-attribute local {local}\n")
+    device.send(f'gatt.write "{hexbytes(value)}"\n')
+    expect(device, rf"Attribute {local} .*written", timeout=REPLY_TIMEOUT)
+
+
+@host_config(
+    [Bluetoothd(conf=HOG_CONF), Pexpect()],
+    [Bluetoothd(conf=HOG_CONF), Pexpect()],
+)
[email protected](
+    "init_script, flags, sci",
+    [
+        ("hog-device.bt", "02", None),
+        ("hog-device-sci.bt", "06", ("00", "08 01 08 00 50 00 08 00")),
+    ],
+    ids=["no-sci", "sci"],
+)
+def test_hog(hosts, init_script, flags, sci):
+    host0, host1 = hosts
+
+    device = spawn_bluetoothctl(host1, init_script)
+    expect(device, "Application registered")
+
+    ctl = spawn_bluetoothctl(host0)
+    pair_le(host0, ctl, host1, device)
+
+    ctl.send(f"info {host1.bdaddr.upper()}\n")
+    expect(ctl, rf"Human Interface Device\s+\({HIDS_UUID}\)", timeout=REPLY_TIMEOUT)
+
+    # HID Information: bcdHID 1.11, bCountryCode 0x00 and Flags
+    assert read_attribute(ctl, "2a4a") == f"11 01 00 {flags}"
+
+    # Input Reports: the HID device notifies a few key presses
+    enable_notifications(ctl, device, "2a4d", LOCAL_REPORT)
+
+    for report in REPORTS:
+        notify(device, LOCAL_REPORT, report)
+        assert expect_notification(ctl) == report
+
+    if sci is None:
+        return
+
+    mode, info = sci
+    assert read_attribute(ctl, "2c39") == mode
+    assert read_attribute(ctl, "2c3a") == info
+
+    # SCI mode change: the HID host writes the new mode to the HID device
+    enable_notifications(ctl, device, "2c39", LOCAL_SCI_MODE)
+
+    ctl.send(f'gatt.write "{hexbytes(SCI_FAST_MODE)}"\n')
+    expect(device, rf"\[{LOCAL_SCI_MODE} .*\] WriteValue:")
+    assert expect_hexdump(device) == SCI_FAST_MODE
+
+    # The HID host, as central, changes the connection rate accordingly
+    ctl.send(f"mgmt.conn-subrate {host1.bdaddr} {' '.join(SCI_RATE)}\n")
+    # The connection rate may change before the command completes, so the
+    # event may be printed before the reply
+    rate = rf"{{}} type .* connection subrate interval {SCI_RATE[0]}"
+    expect_all(
+        ctl,
+        [r"Connection Subrate loaded successfully", rate.format(host1.bdaddr.upper())],
+    )
+    expect(device, rate.format(host0.bdaddr.upper()))
+
+    # Then the HID device confirms the mode has been changed
+    notify(device, LOCAL_SCI_MODE, SCI_FAST_MODE)
+    assert expect_notification(ctl) == SCI_FAST_MODE
Signature · 1 line
2.55.0
author maintainer
#10 lore raw

PATCH v6 8/23 test: functional: limit the workers by the memory available

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

Each worker of pytest-xdist runs VM instances, so using one worker per CPU could run out of memory, with the OOM killer terminating some of them and tests failing at random.

With -n auto, limit the number of workers by the memory available, estimating each worker needs memory for 3 VM instances of 256M of guest memory plus the overhead of qemu, and use -n auto for check-functional by default, which can be overridden with CHECK_FUNCTIONAL_JOBS.

Assisted-by OpenCode:claude-opus-5.5
---
 Makefile.am                 |  7 ++++-
 doc/test-functional.rst     | 25 ++++++++++++++++
 test/functional/conftest.py | 58 +++++++++++++++++++++++++++++++++++++
 3 files changed, 89 insertions(+), 1 deletion(-)
Makefile.am +6 -1
index c88e81f937ff..439811492216 100644
@@ -890,9 +890,14 @@ check-TESTS recheck: AM_MAKEFLAGS += -j$(CHECK_JOBS)
 
 # The functional tests are parallelized by pytest-xdist, loadgroup is required
 # since pytest-bluezenv groups the tests sharing a host/VM setup together.
+# Each worker runs VM instances, so by default the number of workers is limited
+# by the memory available (see test/functional/conftest.py), override with e.g.
+# CHECK_FUNCTIONAL_JOBS=4.
+CHECK_FUNCTIONAL_JOBS ?= auto
+
 check-functional: all
 	python3 -m pytest "$(srcdir)/test/functional" -v \
-		-n $(CHECK_JOBS) --dist loadgroup \
+		-n $(CHECK_FUNCTIONAL_JOBS) --dist loadgroup \
 		-m "not tester" \
 		--kernel="$(FUNCTIONAL_TESTING_KERNEL)" \
 		--bluez-build-dir="$(top_builddir)" \
doc/test-functional.rst +25 -0
index 826210b73ce7..e2fcf34138b3 100644
@@ -474,6 +474,31 @@ pytest-xdist is required for parallel execution. To run:
 
 	$ test/test-functional -n auto --dist loadgroup
 
+With ``-n auto`` the number of workers is limited by the memory
+available, rather than using one worker per CPU, as each worker runs
+VM instances and running out of memory makes the OOM killer terminate
+some of them, failing tests at random. Each worker is estimated to need
+memory for 3 VM instances (the maximum used by a test) of 256M of guest
+memory plus the overhead of qemu, see `test/functional/conftest.py`.
+The estimate is printed when starting:
+
+.. code-block::
+
+	Using 9 workers: 22 CPUs, 12159 MiB available, 1218 MiB per worker (3 VMs of 406 MiB)
+
+To use a given number of workers instead:
+
+.. code-block::
+
+	$ test/test-functional -n 4 --dist loadgroup
+
+``make check-functional`` uses ``-n auto`` as well, which can be
+overridden with ``CHECK_FUNCTIONAL_JOBS``:
+
+.. code-block::
+
+	$ make check-functional CHECK_FUNCTIONAL_JOBS=4
+
 Logging in to a test VM instance
 --------------------------------
 
test/functional/conftest.py +58 -0

64 lines not on this page · raw message

Signature · 1 line
2.55.0
author maintainer
#11 lore raw

PATCH v6 9/23 client/agent: Fix crash on Cancel with no pending request

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

The auto agent replies to the requests right away, so there is no pending request when bluetoothd cancels one, e.g. when pairing fails, and dbus_message_unref is then called with NULL, which libdbus aborts on:

 #5  ?? () from /usr/lib/x86_64-linux-gnu/libdbus-1.so.3
 #6  _dbus_warn_check_failed () from /usr/lib/x86_64-linux-gnu/libdbus-1.so.3
 #7  cancel_request (...) at client/agent.c:258
 #8  process_message (...) at gdbus/object.c:293

Only release the pending request if there is one, as done when the agent is released.

Assisted-by OpenCode:claude-opus-5.5
---
 client/agent.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
client/agent.c +8 -2
index a678d5f785a9..2dd0113dc624 100644
@@ -255,8 +255,14 @@ static DBusMessage *cancel_request(DBusConnection *conn,
 	bt_shell_printf("Request canceled\n");
 
 	agent_release_prompt();
-	dbus_message_unref(pending_message);
-	pending_message = NULL;
+
+	/* There is no pending request with the auto agent, which replies
+	 * right away, or if it has already been replied.
+	 */
+	if (pending_message) {
+		dbus_message_unref(pending_message);
+		pending_message = NULL;
+	}
 
 	return dbus_message_new_method_return(msg);
 }
Signature · 1 line
2.55.0
author maintainer
#12 lore raw

PATCH v6 10/23 shared/uhid: Fix size of Get Report reply with a Report ID

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

The size of the reply did not account for the Report ID prepended to the data of numbered reports, dropping the last byte of the report, unlike Input Reports which already account for it.

Assisted-by OpenCode:claude-opus-5.5
---
 src/shared/uhid.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/shared/uhid.c +1 -1
index 919618a71b00..36a16c331e83 100644
@@ -530,7 +530,7 @@ int bt_uhid_get_report_reply(struct bt_uhid *uhid, uint32_t id, uint8_t number,
 
 	if (number) {
 		rsp->data[len++] = number;
-		rsp->size += MIN(size, sizeof(rsp->data) - 1);
+		rsp->size = 1 + MIN(size, sizeof(rsp->data) - 1);
 	} else
 		rsp->size = MIN(size, sizeof(ev.u.input.data));
 
Signature · 1 line
2.55.0
author maintainer
#13 lore raw

PATCH v6 11/23 shared/uhid: Keep reading when an event is not available

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

When the fd is non-blocking an event may have been consumed by another reader of the same fd, e.g. multiple instances of HID over GATT sharing the fd of the uHID device in unit tests, so keep reading on EAGAIN instead of stopping.

Assisted-by OpenCode:claude-opus-5.5
---
 src/shared/uhid.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
src/shared/uhid.c +4 -1
index 36a16c331e83..20c55f63b82a 100644
@@ -169,7 +169,10 @@ static bool uhid_read_handler(struct io *io, void *user_data)
 
 	len = read(fd, &ev, sizeof(ev));
 	if (len < 0)
-		return false;
+		/* Keep reading if the event was consumed by another reader of
+		 * a non-blocking fd.
+		 */
+		return errno == EAGAIN || errno == EINTR;
 
 	if ((size_t) len < sizeof(ev.type))
 		return false;
Signature · 1 line
2.55.0
author maintainer
#14 lore raw

PATCH v6 12/23 shared/tester: Allow expecting a PDU with no response

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

IOV_NULL following an expected PDU used to send an empty PDU, unless followed by another IOV_NULL chaining the PDUs to send, so it was not possible to expect a PDU with no response, e.g. a Write Command, followed by another expected PDU.

Wait for the next PDU instead of sending an empty one in that case.

Assisted-by OpenCode:claude-opus-5.5
---
 src/shared/tester.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
src/shared/tester.c +19 -0
index e99cc452cd07..eb2e923fd790 100644
@@ -948,6 +948,25 @@ static bool test_io_send(struct io *io, void *user_data)
 	if (!iov)
 		return false;
 
+	/* IOV_NULL following an expected PDU means there is no response to
+	 * it, e.g. a Write Command: wait for the next PDU instead, unless
+	 * followed by another IOV_NULL chaining the PDUs to send.
+	 */
+	if (!iov->iov_base) {
+		/* Nothing left to send or to expect */
+		if (!test->iovcnt) {
+			if (test->io_complete_func)
+				test->io_complete_func(test->test_data);
+			return false;
+		}
+
+		if (test->iov->iov_base)
+			return false;
+
+		test_get_iov(test);
+		return test_io_send(io, user_data);
+	}
+
 	len = io_send(io, iov, 1);
 
 	tester_monitor('<', 0x0004, 0x0000, iov->iov_base, len);
Signature · 1 line
2.55.0
author maintainer
#15 lore raw

PATCH v6 13/23 shared/gatt-client: Fix calling idle callbacks again while notifying

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

The idle callbacks are called while being removed from the queue, so if one of them makes the client idle again, e.g. if a request it sends fails right away, they are called again while the queue is being iterated, corrupting it:

Invalid read of size 8

    at queue_remove_if (queue.c:285)
    by queue_remove_all (queue.c:321)
    by notify_client_idle (gatt-client.c:187)
    ...
  Address is 8 bytes inside a block of size 16 free'd
    at free
    by queue_remove_if (queue.c:292)
    by queue_remove_all (queue.c:321)
    by notify_client_idle (gatt-client.c:187)
    by request_unref (gatt-client.c:206)
    by bt_gatt_client_read_long_value (gatt-client.c:3140)

Detach the callbacks from the client before calling them.

Assisted-by OpenCode:claude-opus-5.5
---
 src/shared/gatt-client.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
src/shared/gatt-client.c +11 -1
index b3bc62220e16..5135283e4526 100644
@@ -180,11 +180,21 @@ bt_gatt_client_ref_safe(struct bt_gatt_client *client)
 
 static void notify_client_idle(struct bt_gatt_client *client)
 {
+	struct queue *idle_cbs;
+
 	client = bt_gatt_client_ref_safe(client);
 	if (!client)
 		return;
 
-	queue_remove_all(client->idle_cbs, idle_notify, NULL, idle_destroy);
+	/* Detach the callbacks before calling them, as a callback may make
+	 * the client idle again, e.g. if a request it sends fails right away,
+	 * which would otherwise call them again while being removed.
+	 */
+	idle_cbs = client->idle_cbs;
+	client->idle_cbs = queue_new();
+
+	queue_remove_all(idle_cbs, idle_notify, NULL, idle_destroy);
+	queue_destroy(idle_cbs, NULL);
 
 	bt_gatt_client_unref(client);
 }
Signature · 1 line
2.55.0
author maintainer
#16 lore raw

PATCH v6 14/23 shared/gatt-client: Add bt_gatt_client_is_idle

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

Add bt_gatt_client_is_idle to tell if there are no pending requests, so it is known whether the callbacks registered with bt_gatt_client_idle_register will be called.

Assisted-by OpenCode:claude-opus-5.5
---
 src/shared/gatt-client.c | 8 ++++++++
 src/shared/gatt-client.h | 1 +
 2 files changed, 9 insertions(+)
src/shared/gatt-client.c +8 -0
index 5135283e4526..95f83fa3ee8c 100644
@@ -2620,6 +2620,14 @@ bool bt_gatt_client_is_ready(struct bt_gatt_client *client)
 	return (client && client->ready);
 }
 
+/* Whether there are no pending requests, e.g. to know if the callbacks
+ * registered with bt_gatt_client_idle_register would be called.
+ */
+bool bt_gatt_client_is_idle(struct bt_gatt_client *client)
+{
+	return (client && queue_isempty(client->pending_requests));
+}
+
 unsigned int bt_gatt_client_ready_register(struct bt_gatt_client *client,
 					bt_gatt_client_callback_t callback,
 					void *user_data,
src/shared/gatt-client.h +1 -0
index 63cf99500e9e..ff90fd8eae38 100644
@@ -46,6 +46,7 @@ typedef void (*bt_gatt_client_service_changed_callback_t)(uint16_t start_handle,
 							void *user_data);
 
 bool bt_gatt_client_is_ready(struct bt_gatt_client *client);
+bool bt_gatt_client_is_idle(struct bt_gatt_client *client);
 unsigned int bt_gatt_client_ready_register(struct bt_gatt_client *client,
 					bt_gatt_client_callback_t callback,
 					void *user_data,
Signature · 1 line
2.55.0
author maintainer
#17 lore raw

PATCH v6 15/23 shared/hog: Add initial implementation

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

Add a HID over GATT implementation based on bt_gatt_client and gatt_db, meant as a drop-in replacement of profiles/input/hog-lib which is based on GAttrib:

- bt_hog_attach takes a bt_gatt_client, which is cloned so the requests of HoG are tracked and cancelled on their own
- the services and characteristics are only looked up in the gatt_db, the one given to bt_hog_new or otherwise the one of the client
- notifications of the Input Reports are enabled with bt_gatt_client_register_notify, once their CCC has been read
- the Report Map is read along with the other characteristics, with a long read, and the uHID device is created once the client is idle, i.e. every request is complete, so the report IDs are known by then
- the addresses of the uHID device are taken from the ATT socket
- the clone is freed when detaching, which cancels its pending requests and unregisters its notifications
- static values, i.e. HID Information, Report Reference, External Report Reference and HID SCI Information, are cached in the gatt_db, along with the Report Map, so they are not read again when reconnecting

Unlike hog-lib, the Scan Parameters, Device Information and Battery services are not handled, as they are by the scanparam, deviceinfo and battery plugins, so bt_hog_set_ids is added to set the vendor, product and version once known, e.g. from the PnP ID. A debug callback can be set with bt_hog_set_debug.

HID SCI is supported as specified by the HIDS/HOGP SCI FIPD:
bt_hog_set_sci_mode requests the HID Device to enable a HID SCI mode by writing it to the HID Control Point, and the notifications of HID SCI Mode, with which the HID Device confirms the mode once the connection rate has been changed, are enabled and reported with the callback set with bt_hog_set_sci_mode_callback.

Assisted-by OpenCode:claude-opus-5.5
---
 Makefile.am      |    1 +
 src/shared/hog.c | 1563 ++++++++++++++++++++++++++++++++++++++++++++++
 src/shared/hog.h |   67 ++
 3 files changed, 1631 insertions(+)
 create mode 100644 src/shared/hog.c
 create mode 100644 src/shared/hog.h
Makefile.am +1 -0
index 439811492216..3a496389ba88 100644
@@ -239,6 +239,7 @@ shared_sources = src/shared/io.h src/shared/timeout.h \
 			src/shared/mcs.h src/shared/mcp.h src/shared/mcp.c \
 			src/shared/vcp.c src/shared/vcp.h \
 			src/shared/micp.c src/shared/micp.h \
+			src/shared/hog.c src/shared/hog.h \
 			src/shared/csip.c src/shared/csip.h \
 			src/shared/bass.h src/shared/bass.c \
 			src/shared/ccp.h src/shared/ccp.c \
src/shared/hog.c new file +1563 -0

1,563 lines not on this page · raw message

src/shared/hog.h new file +67 -0

67 lines not on this page · raw message

Signature · 1 line
2.55.0
author maintainer
#18 lore raw

PATCH v6 16/23 unit/test-hog: Use shared/hog

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

Port the tests to src/shared/hog, with the discovery done by bt_gatt_client, and the uHID device emulated with a socket pair so the events are checked.

The test cases are renamed after HOGP.TS p13, and the missing ones for the Report Host are added, except for HID ISO which is not supported:

- Discovery: HGDC/BV-03-C (two instances of the HID Service), HGDC/BV-04-C and HGDC/BV-05-C
- Read: HGRF/BV-02-C to BV-08-C, BV-18-C and BV-19-C, with the Report values also read with UHID_GET_REPORT
- Write: HGWF/BV-01-C, BV-02-C and BV-04-C with UHID_SET_REPORT and UHID_OUTPUT, BV-05-C and BV-06-C (Suspend and Exit Suspend), BV-07-C (Set Report Protocol Mode)
- HID SCI: HGWF/BV-08-C to BV-11-C, writing each mode to the HID Control Point with two instances of the HID Service, then changing to another mode once notified with HID SCI Mode
- Configuration: HGCF/BV-01-C
- Notifications: HGNF/BV-01-C, forwarded as UHID_INPUT2, and BI-01-C and BI-02-C, ignoring the Boot Keyboard and Boot Mouse Input Reports, and HGNF/BV-01-C once reconnected, with the reports already known and the Report Map cached
- Characteristic GGIT: CHA/BV-01-C to BV-04-C, BV-09-C, BV-10-C and DES/BV-01-C

The Battery Level and PnP ID GGIT test cases are left to the battery and deviceinfo plugins which handle these services.

Assisted-by OpenCode:claude-opus-5.5
---
 Makefile.am     |   11 +-
 unit/test-hog.c | 1420 +++++++++++++++++++++++++++++++++++------------
 2 files changed, 1068 insertions(+), 363 deletions(-)
Makefile.am +1 -10
index 3a496389ba88..015c3c318528 100644
@@ -773,16 +773,7 @@ unit_test_gatt_LDADD = src/libshared-glib.la \
 
 unit_tests += unit/test-hog
 
-unit_test_hog_SOURCES = unit/test-hog.c \
-			$(btio_sources) \
-			profiles/input/hog-lib.h profiles/input/hog-lib.c \
-			profiles/scanparam/scpp.h profiles/scanparam/scpp.c \
-			profiles/battery/bas.h profiles/battery/bas.c \
-			profiles/deviceinfo/dis.h profiles/deviceinfo/dis.c \
-			src/log.h src/log.c \
-			attrib/att.h attrib/att.c \
-			attrib/gatt.h attrib/gatt.c \
-			attrib/gattrib.h attrib/gattrib.c
+unit_test_hog_SOURCES = unit/test-hog.c
 unit_test_hog_LDADD = src/libshared-glib.la \
 				lib/libbluetooth-internal.la $(GLIB_LIBS)
 
unit/test-hog.c +1067 -353

1,482 lines not on this page · raw message

Signature · 1 line
2.55.0
author maintainer
#19 lore raw

PATCH v6 17/23 test: functional: change the HoG SCI mode with the HID Control Point

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

As specified by HOGP.TS 4.6.1 and the HIDS/HOGP SCI FIPD, the HID host requests a HID SCI mode by writing it to the HID Control Point, the HID device then confirming it with a notification of HID SCI Mode, which is Read and Notify only.

Write the mode to the HID Control Point instead of HID SCI Mode, which is no longer writable, and don't expect HID SCI Mode notifications to be subscribed by bluetoothctl as the input plugin of the HID host may already have done it.

The connection rate is still changed by the HID host, as the kernel only issues the LE Connection Rate Request as central.

Assisted-by OpenCode:claude-opus-5.5
---
 client/scripts/hog-device-sci.bt |  6 ++--
 doc/functional-hog.rst           | 52 +++++++++++++++++++++-----------
 test/functional/test_hog.py      | 29 ++++++++++++++----
 3 files changed, 60 insertions(+), 27 deletions(-)
client/scripts/hog-device-sci.bt +3 -3
index 1bf3a0a90db7..7500eeb105bf 100644
@@ -26,12 +26,12 @@ gatt.register-descriptor 0x2908 read
 gatt.register-characteristic 0x2a4e read,write-without-response
 0x01
 #
-# HID Control Point
+# HID Control Point: Suspend, Exit Suspend and Enable SCI modes
 gatt.register-characteristic 0x2a4c write-without-response
 0x00
 #
-# HID SCI Mode: None (0x00), notified when changed
-gatt.register-characteristic 0x2c39 read,write,notify
+# HID SCI Mode: None (0x00), notified once changed with the HID Control Point
+gatt.register-characteristic 0x2c39 read,notify
 0x00
 #
 # HID SCI Information (intervals in units of 0.125 ms):
doc/functional-hog.rst +34 -18

110 lines not on this page · raw message

test/functional/test_hog.py +23 -6
index ea54882d059d..7ff0965275d1 100644
@@ -18,7 +18,8 @@ from pytest_bluezenv.utils import bluez_src_dir
 pytestmark = [pytest.mark.vm]
 
 # The HID Service is claimed by the input plugin of the HID host, so it
-# has to be exported read-write for bluetoothctl to write HID SCI Mode
+# has to be exported read-write for bluetoothctl to write the HID Control
+# Point
 HOG_CONF = """[General]
 ControllerMode = le
 
@@ -30,6 +31,7 @@ HIDS_UUID = "00001812-0000-1000-8000-00805f9b34fb"
 
 # Local attributes registered by client/scripts/hog-device*.bt
 LOCAL_REPORT = "/org/bluez/app/service0/chrc2"
+LOCAL_CP = "/org/bluez/app/service0/chrc4"
 LOCAL_SCI_MODE = "/org/bluez/app/service0/chrc5"
 
 # Keyboard Input Reports: Modifiers, Reserved, then 6 Key Codes
@@ -39,7 +41,8 @@ REPORTS = [
     "00 00 00 00 00 00 00 00",  # released
 ]
 
-# HID SCI Mode: Fast Mode
+# HID Control Point: Enable SCI Fast mode, the value then notified with
+# HID SCI Mode
 SCI_FAST_MODE = "03"
 
 # LE Connection Rate parameters requested with mgmt.conn-subrate once in
@@ -229,14 +232,27 @@ def test_hog(hosts, init_script, flags, sci):
     assert read_attribute(ctl, "2c39") == mode
     assert read_attribute(ctl, "2c3a") == info
 
-    # SCI mode change: the HID host writes the new mode to the HID device
-    enable_notifications(ctl, device, "2c39", LOCAL_SCI_MODE)
+    # The input plugin of the HID host enables the notifications of HID
+    # SCI Mode on its own, so they only have to be started on bluetoothctl
+    # to be printed
+    ctl.send("gatt.select-attribute 2c39\n")
+    ctl.send("gatt.notify on\n")
+    expect(ctl, r"Notify started", timeout=REPLY_TIMEOUT)
 
+    # SCI mode change, see HOGP.TS 4.6.1: the HID host writes the mode to
+    # enable to the HID Control Point, with Write Without Response
+    ctl.send("gatt.select-attribute 2a4c\n")
     ctl.send(f'gatt.write "{hexbytes(SCI_FAST_MODE)}"\n')
-    expect(device, rf"\[{LOCAL_SCI_MODE} .*\] WriteValue:")
+    # Received with WriteValue, or over the socket acquired with
+    # AcquireWrite
+    expect(
+        device,
+        rf"\[{LOCAL_CP} .*\] WriteValue:|Attribute {LOCAL_CP} .*written:",
+    )
     assert expect_hexdump(device) == SCI_FAST_MODE
 
-    # The HID host, as central, changes the connection rate accordingly
+    # The HID device is meant to change the connection rate, but the kernel
+    # only requests it as central, so the HID host does it instead
     ctl.send(f"mgmt.conn-subrate {host1.bdaddr} {' '.join(SCI_RATE)}\n")
     # The connection rate may change before the command completes, so the
     # event may be printed before the reply
@@ -248,5 +264,6 @@ def test_hog(hosts, init_script, flags, sci):
     expect(device, rate.format(host0.bdaddr.upper()))
 
     # Then the HID device confirms the mode has been changed
+    ctl.send("gatt.select-attribute 2c39\n")
     notify(device, LOCAL_SCI_MODE, SCI_FAST_MODE)
     assert expect_notification(ctl) == SCI_FAST_MODE
Signature · 1 line
2.55.0
author maintainer
#20 lore raw

PATCH v6 18/23 input/hog: Use shared/hog

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

Use src/shared/hog, based on bt_gatt_client, instead of hog-lib which is based on GAttrib, and remove it along with the GAttrib based Battery, Device Information and Scan Parameters implementations only used by it.

These services are handled by the battery, deviceinfo and scanparam plugins, so the vendor, product and version of the uHID device are set from the device, which gets them from the PnP ID, when accepting the connection.

With shared/hog the notifications of HID SCI Mode are enabled when the HID device supports SCI, so the mode is known once changed with the HID Control Point.

Assisted-by OpenCode:claude-opus-5.5
---
 Makefile.plugins          |    4 -
 profiles/battery/bas.c    |  327 ------
 profiles/battery/bas.h    |   19 -
 profiles/deviceinfo/dis.c |  340 -------
 profiles/deviceinfo/dis.h |   27 -
 profiles/input/hog-lib.c  | 1966 -------------------------------------
 profiles/input/hog-lib.h  |   28 -
 profiles/input/hog.c      |   31 +-
 profiles/scanparam/scpp.c |  342 -------
 profiles/scanparam/scpp.h |   22 -
 10 files changed, 21 insertions(+), 3085 deletions(-)
 delete mode 100644 profiles/battery/bas.c
 delete mode 100644 profiles/battery/bas.h
 delete mode 100644 profiles/deviceinfo/dis.c
 delete mode 100644 profiles/deviceinfo/dis.h
 delete mode 100644 profiles/input/hog-lib.c
 delete mode 100644 profiles/input/hog-lib.h
 delete mode 100644 profiles/scanparam/scpp.c
 delete mode 100644 profiles/scanparam/scpp.h
Makefile.plugins +0 -4
index edc93e8e9705..a492784418b7 100644
@@ -62,10 +62,6 @@ endif
 if HOG
 builtin_modules += hog
 builtin_sources += profiles/input/hog.c \
-			profiles/input/hog-lib.c profiles/input/hog-lib.h \
-			profiles/deviceinfo/dis.c profiles/deviceinfo/dis.h \
-			profiles/battery/bas.c profiles/battery/bas.h \
-			profiles/scanparam/scpp.c profiles/scanparam/scpp.h \
 			profiles/input/suspend.h profiles/input/suspend-none.c
 endif
 
profiles/battery/bas.c deleted +0 -327

327 lines not on this page · raw message

profiles/battery/bas.h deleted +0 -19
deleted file mode 100644
index cd503a498673..000000000000
@@ -1,19 +0,0 @@
-/* SPDX-License-Identifier: LGPL-2.1-or-later */
-/*
- *
- *  BlueZ - Bluetooth protocol stack for Linux
- *
- *  Copyright (C) 2014  Intel Corporation. All rights reserved.
- *
- *
- */
-
-struct bt_bas;
-
-struct bt_bas *bt_bas_new(void *primary);
-
-struct bt_bas *bt_bas_ref(struct bt_bas *bas);
-void bt_bas_unref(struct bt_bas *bas);
-
-bool bt_bas_attach(struct bt_bas *bas, void *gatt);
-void bt_bas_detach(struct bt_bas *bas);
profiles/deviceinfo/dis.c deleted +0 -340

340 lines not on this page · raw message

profiles/deviceinfo/dis.h deleted +0 -27
deleted file mode 100644
index 7b6f4f123c76..000000000000
@@ -1,27 +0,0 @@
-/* SPDX-License-Identifier: LGPL-2.1-or-later */
-/*
- *
- *  BlueZ - Bluetooth protocol stack for Linux
- *
- *  Copyright (C) 2014  Intel Corporation. All rights reserved.
- *
- *
- */
-
-struct bt_dis;
-
-struct bt_dis *bt_dis_new(struct gatt_db *db);
-struct bt_dis *bt_dis_new_primary(void *primary);
-
-struct bt_dis *bt_dis_ref(struct bt_dis *dis);
-void bt_dis_unref(struct bt_dis *dis);
-
-bool bt_dis_attach(struct bt_dis *dis, void *gatt);
-void bt_dis_detach(struct bt_dis *dis);
-
-typedef void (*bt_dis_notify) (uint8_t source, uint16_t vendor,
-					uint16_t product, uint16_t version,
-					void *user_data);
-
-bool bt_dis_set_notification(struct bt_dis *dis, bt_dis_notify func,
-							void *user_data);
profiles/input/hog-lib.c deleted +0 -1966

1,966 lines not on this page · raw message

profiles/input/hog-lib.h deleted +0 -28
deleted file mode 100644
index 41e454642705..000000000000
@@ -1,28 +0,0 @@
-/* SPDX-License-Identifier: LGPL-2.1-or-later */
-/*
- *
- *  BlueZ - Bluetooth protocol stack for Linux
- *
- *  Copyright (C) 2014  Intel Corporation. All rights reserved.
- *
- *
- */
-
-struct bt_hog;
-
-struct bt_hog *bt_hog_new_default(const char *name, uint16_t vendor,
-					uint16_t product, uint16_t version,
-					uint8_t type, struct gatt_db *db);
-
-struct bt_hog *bt_hog_new(int fd, const char *name, uint16_t vendor,
-					uint16_t product, uint16_t version,
-					uint8_t type, struct gatt_db *db);
-
-struct bt_hog *bt_hog_ref(struct bt_hog *hog);
-void bt_hog_unref(struct bt_hog *hog);
-
-bool bt_hog_attach(struct bt_hog *hog, void *gatt);
-void bt_hog_detach(struct bt_hog *hog, bool force);
-
-int bt_hog_set_control_point(struct bt_hog *hog, bool suspend);
-int bt_hog_send_report(struct bt_hog *hog, void *data, size_t size, int type);
profiles/input/hog.c +21 -10
index f50a0f217f7f..0f6224990e07 100644
@@ -38,13 +38,10 @@
 #include "src/shared/queue.h"
 #include "src/shared/att.h"
 #include "src/shared/gatt-client.h"
+#include "src/shared/hog.h"
 #include "src/plugin.h"
 
 #include "suspend.h"
-#include "attrib/att.h"
-#include "attrib/gattrib.h"
-#include "attrib/gatt.h"
-#include "hog-lib.h"
 
 struct hog_device {
 	struct btd_device	*device;
@@ -57,6 +54,11 @@ static bool auto_sec = true;
 static bool uhid_state_persist = false;
 static struct queue *devices = NULL;
 
+static void hog_debug(const char *str, void *user_data)
+{
+	DBG_IDX(0xffff, "%s", str);
+}
+
 static void hog_device_accept(struct hog_device *dev, struct gatt_db *db)
 {
 	char name[248];
@@ -79,6 +81,8 @@ static void hog_device_accept(struct hog_device *dev, struct gatt_db *db)
 							product, version);
 
 	dev->hog = bt_hog_new_default(name, vendor, product, version, type, db);
+	if (dev->hog)
+		bt_hog_set_debug(dev->hog, hog_debug, NULL, NULL);
 }
 
 static struct hog_device *hog_device_new(struct btd_device *device)
@@ -170,7 +174,10 @@ static int hog_accept(struct btd_service *service)
 	struct hog_device *dev = btd_service_get_user_data(service);
 	struct btd_device *device = btd_service_get_device(service);
 	struct gatt_db *db = btd_device_get_gatt_db(device);
-	GAttrib *attrib = btd_device_get_attrib(device);
+	struct bt_gatt_client *client = btd_device_get_gatt_client(device);
+
+	if (!client)
+		return -ENOTCONN;
 
 	if (!dev->hog) {
 		hog_device_accept(dev, db);
@@ -180,19 +187,23 @@ static int hog_accept(struct btd_service *service)
 
 	/* HOGP 1.0 Section 6.1 requires bonding */
 	if (!device_is_bonded(device, btd_device_get_bdaddr_type(device))) {
-		struct bt_gatt_client *client;
-
 		if (!auto_sec)
 			return -ECONNREFUSED;
 
-		client = btd_device_get_gatt_client(device);
 		if (!bt_gatt_client_set_security(client,
 						BT_ATT_SECURITY_MEDIUM))
 			return -ECONNREFUSED;
 	}
 
-	/* TODO: Replace GAttrib with bt_gatt_client */
-	bt_hog_attach(dev->hog, attrib);
+	/* The PnP ID may have been read by the deviceinfo plugin since the
+	 * HoG instance was created, the uHID device is only created once
+	 * the Report Map is read.
+	 */
+	bt_hog_set_ids(dev->hog, btd_device_get_vendor(device),
+					btd_device_get_product(device),
+					btd_device_get_version(device));
+
+	bt_hog_attach(dev->hog, client);
 
 	btd_service_connecting_complete(service, 0);
 
profiles/scanparam/scpp.c deleted +0 -342

211 lines not on this page · raw message

profiles/scanparam/scpp.h deleted +0 -22
deleted file mode 100644
index c3cc5f156d9e..000000000000

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.55.0

Part of the diff is not shown here. View the raw message.

author maintainer
#21 lore raw

PATCH v6 19/23 doc: Add CONFIG_HIDRAW to the tester kernel config

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

Enable hidraw so unit/test-uhid, when run as root e.g. with test-runner, can request reports through a hidraw device, as HIDIOCGFEATURE does, and check the replies to the requests the kernel sends to the uHID device.

Assisted-by OpenCode:claude-opus-5.5
---
 doc/test-runner.rst | 5 +++++
 doc/tester.config   | 1 +
 2 files changed, 6 insertions(+)
doc/test-runner.rst +5 -0
index dc1e51305c51..52178244fce8 100644
@@ -205,6 +205,11 @@ Bluetooth
 	CONFIG_UNIX=y
 
 	CONFIG_UHID=y
+	CONFIG_HIDRAW=y
+
+CONFIG_HIDRAW is used by unit/test-uhid, when run as root e.g. with
+test-runner, to check the replies to the reports requested by the kernel
+through a hidraw device, as HIDIOCGFEATURE does.
 
 For 6lowpan-tester, the following are required:
 
doc/tester.config +1 -0
index e68740dc0f44..34f1530e174c 100644
@@ -54,6 +54,7 @@ CONFIG_CRYPTO_USER_API_SKCIPHER=y
 CONFIG_UNIX=y
 
 CONFIG_UHID=y
+CONFIG_HIDRAW=y
 
 CONFIG_DEBUG_KERNEL=y
 CONFIG_LOCKDEP_SUPPORT=y
Signature · 1 line
2.55.0
author maintainer
#22 lore raw

PATCH v6 20/23 unit/test-uhid: Add Get Report tests

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

Add tests replying to UHID_GET_REPORT for a numbered Feature Report:

- /uhid/command/get_report_reply checks the reply contains the Report ID followed by the report data, with its size accounting for both
- /uhid/device/get_report creates a uHID device, requests the report through hidraw with HIDIOCGFEATURE and checks it returns the Report ID followed by the report data, as documented in Documentation/hid/hidraw.rst, since uhid copies the reply to the buffer of hid_hw_raw_request. It requires root and CONFIG_HIDRAW, otherwise it is not run.

Assisted-by OpenCode:claude-opus-5.5
---
 unit/test-uhid.c | 272 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 272 insertions(+)
unit/test-uhid.c +272 -0
index c5848bef97f9..7ccfe8f375ff 100644
@@ -18,7 +18,12 @@
 #include <inttypes.h>
 #include <string.h>
 #include <fcntl.h>
+#include <limits.h>
+#include <dirent.h>
+#include <errno.h>
+#include <sys/ioctl.h>
 #include <sys/socket.h>
+#include <linux/hidraw.h>
 
 #include <glib.h>
 
@@ -56,6 +61,14 @@ struct context {
 	int fd;
 	unsigned int pdu_offset;
 	const struct test_data *data;
+	/* Get Report through hidraw, see test_get_report */
+	guint poll;
+	unsigned int poll_count;
+	GThread *thread;
+	guint done;
+	uint8_t report[64];
+	int report_len;
+	int report_err;
 };
 
 #define event(args...)						\
@@ -100,6 +113,20 @@ static void destroy_context(struct context *context)
 	if (context->source > 0)
 		g_source_remove(context->source);
 
+	if (context->poll > 0)
+		g_source_remove(context->poll);
+
+	if (context->thread) {
+		/* Destroying the device fails the pending request, if any, so
+		 * the thread returns.
+		 */
+		bt_uhid_destroy(context->uhid, true);
+		g_thread_join(context->thread);
+	}
+
+	if (context->done > 0)
+		g_source_remove(context->done);
+
 	bt_uhid_unregister_all(context->uhid);
 	bt_uhid_unref(context->uhid);
 
@@ -331,6 +358,245 @@ static void test_server(gconstpointer data)
 }
 
 
+/* Feature Report 1: 8 bytes, which is numbered since the Report Map uses a
+ * Report ID.
+ */
+#define FEATURE_REPORT_ID	0x01
+#define FEATURE_REPORT		0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08
+
+static const uint8_t feature_report[] = { FEATURE_REPORT };
+
+static const struct uhid_event ev_get_report = {
+	.type = UHID_GET_REPORT,
+	.u.get_report = {
+		.id = 0x42,
+		.rnum = FEATURE_REPORT_ID,
+		.rtype = UHID_FEATURE_REPORT,
+	},
+};
+
+/* The reply contains the Report ID, followed by the report data, as the
+ * buffer returned by hid_hw_raw_request which uhid copies the reply to.
+ */
+static const struct uhid_event ev_get_report_reply = {
+	.type = UHID_GET_REPORT_REPLY,
+	.u.get_report_reply = {
+		.id = 0x42,
+		.err = 0,
+		.size = 1 + sizeof(feature_report),
+		.data = { FEATURE_REPORT_ID, FEATURE_REPORT },
+	},
+};
+
+static void handle_get_report(struct uhid_event *ev, void *user_data)
+{
+	struct context *context = user_data;
+	int err;
+
+	g_assert_cmpint(ev->type, ==, UHID_GET_REPORT);
+	g_assert_cmpint(ev->u.get_report.rnum, ==, FEATURE_REPORT_ID);
+	g_assert_cmpint(ev->u.get_report.rtype, ==, UHID_FEATURE_REPORT);
+
+	err = bt_uhid_get_report_reply(context->uhid, ev->u.get_report.id,
+					FEATURE_REPORT_ID, 0, feature_report,
+					sizeof(feature_report));
+	g_assert_cmpint(err, ==, 0);
+}
+
+static void test_get_report_reply(gconstpointer data)
+{
+	struct context *context = create_context(data);
+
+	bt_uhid_register(context->uhid, UHID_GET_REPORT, handle_get_report,
+								context);
+
+	g_idle_add(send_pdu, context);
+}
+
+static struct test_device get_report_device = {
+	.name = "BlueZ uHID Get Report",
+	.type = BT_UHID_NONE,
+	/* Vendor defined collection with Feature Report 1 of 8 bytes */
+	.map = UTIL_IOV_INIT(0x06, 0x00, 0xff, 0x09, 0x01, 0xa1, 0x01, 0x85,
+				FEATURE_REPORT_ID, 0x09, 0x01, 0x15, 0x00,
+				0x26, 0xff, 0x00, 0x75, 0x08, 0x95, 0x08,
+				0xb1, 0x02, 0xc0),
+};
+
+static gboolean get_report_done(gpointer user_data)
+{
+	struct context *context = user_data;
+	uint8_t expected[] = { FEATURE_REPORT_ID, FEATURE_REPORT };
+
+	g_thread_join(context->thread);
+	context->thread = NULL;
+	context->done = 0;
+
+	if (context->report_len < 0) {
+		tester_warn("HIDIOCGFEATURE: %s",
+					strerror(context->report_err));
+		tester_test_failed();
+		return FALSE;
+	}
+
+	if (tester_use_debug())
+		util_hexdump('>', context->report, context->report_len,
+						test_debug, "hidraw: ");
+
+	/* hidraw returns the Report ID in the first byte for numbered
+	 * reports, see Documentation/hid/hidraw.rst, followed by the data
+	 * of the reply.
+	 */
+	g_assert_cmpint(context->report_len, ==, sizeof(expected));
+	g_assert(!memcmp(context->report, expected, sizeof(expected)));
+
+	bt_uhid_destroy(context->uhid, true);
+	context_quit(context);
+
+	return FALSE;
+}
+
+static bool find_hidraw(const char *name, char *path, size_t len)
+{
+	DIR *dir;
+	struct dirent *d;
+	bool found = false;
+
+	dir = opendir("/sys/class/hidraw");
+	if (!dir)
+		return false;
+
+	while (!found && (d = readdir(dir))) {
+		char uevent[PATH_MAX], buf[1024];
+		ssize_t n;
+		int fd;
+
+		if (d->d_name[0] == '.')
+			continue;
+
+		snprintf(uevent, sizeof(uevent),
+				"/sys/class/hidraw/%s/device/uevent",
+				d->d_name);
+
+		fd = open(uevent, O_RDONLY);
+		if (fd < 0)
+			continue;
+
+		/* Start with a new line so every line can be matched in full */
+		buf[0] = '\n';
+
+		n = read(fd, buf + 1, sizeof(buf) - 2);
+		close(fd);
+		if (n <= 0)
+			continue;
+
+		buf[n + 1] = '\0';
+
+		if (strstr(buf, name)) {
+			snprintf(path, len, "/dev/%s", d->d_name);
+			found = true;
+		}
+	}
+
+	closedir(dir);
+
+	return found;
+}
+
+static char hidraw_path[PATH_MAX];
+
+static gpointer hidraw_get_feature(gpointer user_data)
+{
+	struct context *context = user_data;
+	int fd;
+
+	fd = open(hidraw_path, O_RDWR);
+	if (fd < 0) {
+		context->report_len = -1;
+		context->report_err = errno;
+		goto done;
+	}
+
+	/* The first byte is the Report ID of the requested report */
+	context->report[0] = FEATURE_REPORT_ID;
+
+	/* Blocks until the reply to UHID_GET_REPORT, which is handled by the
+	 * main loop.
+	 */
+	context->report_len = ioctl(fd, HIDIOCGFEATURE(sizeof(context->report)),
+							context->report);
+	context->report_err = errno;
+
+	close(fd);
+
+done:
+	/* Read by the main thread once joined */
+	context->done = g_idle_add(get_report_done, context);
+
+	return NULL;
+}
+
+static gboolean poll_hidraw(gpointer user_data)
+{
+	struct context *context = user_data;
+	char name[128];
+
+	/* Match the whole line, not another device named with a prefix */
+	snprintf(name, sizeof(name), "\nHID_NAME=%s\n",
+						get_report_device.name);
+
+	/* The hidraw device is created once the HID device is started */
+	if (!find_hidraw(name, hidraw_path, sizeof(hidraw_path))) {
+		if (++context->poll_count < 40)
+			return TRUE;
+
+		tester_warn("hidraw device not found, is CONFIG_HIDRAW set?");
+		context->poll = 0;
+		tester_test_failed();
+		return FALSE;
+	}
+
+	context->poll = 0;
+	context->thread = g_thread_new("hidraw", hidraw_get_feature, context);
+
+	return FALSE;
+}
+
+static void test_get_report(gconstpointer data)
+{
+	struct context *context;
+	struct test_device *device = ((struct test_data *) data)->test_device;
+	int err;
+
+	/* Requires the permissions to create uHID devices, and the kernel
+	 * to support hidraw.
+	 */
+	if (getuid() || access("/sys/class/hidraw", F_OK)) {
+		tester_test_abort();
+		return;
+	}
+
+	context = create_context(data);
+	if (!context)
+		return;
+
+	bt_uhid_register(context->uhid, UHID_GET_REPORT, handle_get_report,
+								context);
+
+	err = bt_uhid_create(context->uhid, device->name, BDADDR_ANY,
+				BDADDR_ANY, device->vendor, device->product,
+				device->version, device->country, device->type,
+				device->map.iov_base, device->map.iov_len);
+	if (err < 0) {
+		tester_warn("create failed: %s", strerror(-err));
+		destroy_context(context);
+		tester_test_failed();
+		return;
+	}
+
+	context->poll = g_timeout_add(50, poll_hidraw, context);
+}
+
 static struct test_device mx_anywhere_3 = {
 	.name = "MX Anywhere 3",
 	.vendor = 0x46D,
@@ -366,8 +632,14 @@ int main(int argc, char *argv[])
 	define_test("/uhid/event/output", test_server, event(&ev_output));
 	define_test("/uhid/event/feature", test_server, event(&ev_feature));
 
+	define_test("/uhid/command/get_report_reply", test_get_report_reply,
+					event(&ev_get_report),
+					event(&ev_get_report_reply));
+
 	define_test_device("/uhid/device/mx_anywhere_3", test_client,
 					&mx_anywhere_3, event(&ev_create));
+	define_test_device("/uhid/device/get_report", test_get_report,
+					&get_report_device, event(&ev_create));
 
 	return tester_run();
 }
Signature · 1 line
2.55.0
author maintainer
#23 lore raw

PATCH v6 21/23 device: Use bt_att instead of GAttrib

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

GAttrib is no longer used other than to create the bt_att of the connection, so create it directly, and remove btd_device_get_attrib as there are no users left.

Assisted-by OpenCode:claude-opus-5.5
---
 profiles/deviceinfo/deviceinfo.c |  2 +-
 profiles/ranging/rap.c           |  1 -
 src/adapter.c                    |  1 -
 src/device.c                     | 46 ++++++++++++--------------------
 src/device.h                     |  1 -
 5 files changed, 18 insertions(+), 33 deletions(-)
profiles/deviceinfo/deviceinfo.c +1 -1
index e77bb50b457a..b1f6fb3ff749 100644
@@ -26,9 +26,9 @@
 #include "src/device.h"
 #include "src/profile.h"
 #include "src/service.h"
-#include "attrib/gattrib.h"
 #include "src/shared/util.h"
 #include "src/shared/queue.h"
+#include "src/shared/att.h"
 #include "src/shared/gatt-db.h"
 #include "src/shared/gatt-client.h"
 #include "attrib/att.h"
profiles/ranging/rap.c +0 -1
index b494d188c9c0..f3f677c4b4bb 100644
@@ -27,7 +27,6 @@
 #include "src/profile.h"
 #include "src/service.h"
 #include "src/gatt-database.h"
-#include "attrib/gattrib.h"
 #include "src/shared/util.h"
 #include "src/shared/queue.h"
 #include "src/shared/att.h"
src/adapter.c +0 -1
index 33e1ff07ab24..4131c4431dc6 100644
@@ -59,7 +59,6 @@
 #include "uuid-helper.h"
 #include "agent.h"
 #include "storage.h"
-#include "attrib/gattrib.h"
 #include "attrib/att.h"
 #include "attrib/gatt.h"
 #include "gatt-database.h"
src/device.c +17 -29

107 lines not on this page · raw message

src/device.h +0 -1
index 2ed369856d3d..f18fa5b2119f 100644
@@ -75,7 +75,6 @@ bool btd_device_set_gatt_db(struct btd_device *device, struct gatt_db *db);
 struct bt_gatt_client *btd_device_get_gatt_client(struct btd_device *device);
 struct bt_gatt_server *btd_device_get_gatt_server(struct btd_device *device);
 bool btd_device_is_initiator(struct btd_device *device);
-void *btd_device_get_attrib(struct btd_device *device);
 void btd_device_gatt_set_service_changed(struct btd_device *device,
 						uint16_t start, uint16_t end);
 bool device_attach_att(struct btd_device *dev, GIOChannel *io);
Signature · 1 line
2.55.0
author maintainer
#24 lore raw

PATCH v6 22/23 attrib: Remove GAttrib and gatttool

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

GAttrib has no users left besides the deprecated gatttool, which is replaced by the gatt submenu of bluetoothctl and btgatt-client, so remove both along with unit/test-gattrib and what is left unused of attrib/gatt.c, only keeping struct gatt_primary and gatt_parse_record which are still used by bluetoothd.

Assisted-by OpenCode:claude-opus-5.5
---
 .gitignore           |    2 -
 Makefile.am          |   11 +-
 Makefile.tools       |   12 -
 attrib/gatt.c        | 1150 +-----------------------------------------
 attrib/gatt.h        |   89 ----
 attrib/gattrib.c     |  473 -----------------
 attrib/gattrib.h     |   65 ---
 attrib/gatttool.c    |  612 ----------------------
 attrib/gatttool.h    |   17 -
 attrib/interactive.c | 1020 -------------------------------------
 attrib/utils.c       |  110 ----
 unit/test-gattrib.c  |  552 --------------------
 12 files changed, 3 insertions(+), 4110 deletions(-)
 delete mode 100644 attrib/gattrib.c
 delete mode 100644 attrib/gattrib.h
 delete mode 100644 attrib/gatttool.c
 delete mode 100644 attrib/gatttool.h
 delete mode 100644 attrib/interactive.c
 delete mode 100644 attrib/utils.c
 delete mode 100644 unit/test-gattrib.c
.gitignore +0 -2
index a52e6eb1b9d8..06b24735df45 100644
@@ -45,7 +45,6 @@ tools/97-hid2hci.rules
 profiles/cups/bluetooth
 profiles/iap/iapd
 
-attrib/gatttool
 tools/avinfo
 tools/bccmd
 tools/hwdb
@@ -175,7 +174,6 @@ unit/test-avctp
 unit/test-avrcp
 unit/test-gatt
 unit/test-midi
-unit/test-gattrib
 unit/test-mesh-crypto
 unit/test-micp
 unit/test-vcp
Makefile.am +1 -10
index 015c3c318528..4ce15dbf083a 100644
@@ -287,8 +287,7 @@ src_libshared_ell_la_CFLAGS = $(AM_CFLAGS)
 endif
 
 attrib_sources = attrib/att.h attrib/att-database.h attrib/att.c \
-		attrib/gatt.h attrib/gatt.c \
-		attrib/gattrib.h attrib/gattrib.c
+		attrib/gatt.h attrib/gatt.c
 
 btio_sources = btio/btio.h btio/btio.c
 
@@ -777,14 +776,6 @@ unit_test_hog_SOURCES = unit/test-hog.c
 unit_test_hog_LDADD = src/libshared-glib.la \
 				lib/libbluetooth-internal.la $(GLIB_LIBS)
 
-unit_tests += unit/test-gattrib
-
-unit_test_gattrib_SOURCES = unit/test-gattrib.c attrib/gattrib.c \
-					$(btio_sources) src/log.h src/log.c
-unit_test_gattrib_LDADD = src/libshared-glib.la \
-				lib/libbluetooth-internal.la \
-				$(GLIB_LIBS) $(DBUS_LIBS) -ldl -lrt
-
 unit_tests += unit/test-bap
 
 unit_test_bap_SOURCES = unit/test-bap.c
Makefile.tools +0 -12
index 671b40fb0e42..f0ed20969e7e 100644
@@ -514,18 +514,6 @@ tools_btmgmt_SOURCES = tools/btmgmt.c src/uuid-helper.c client/display.c \
 			client/mgmt.c
 tools_btmgmt_LDADD = lib/libbluetooth-internal.la src/libshared-glib.la \
 				$(GLIB_LIBS) -lreadline
-if DEPRECATED
-noinst_PROGRAMS += attrib/gatttool
-
-attrib_gatttool_SOURCES = attrib/gatttool.c attrib/att.c attrib/gatt.c \
-				attrib/gattrib.c btio/btio.c \
-				attrib/gatttool.h attrib/interactive.c \
-				attrib/utils.c src/log.c client/display.c \
-				client/display.h
-attrib_gatttool_LDADD = lib/libbluetooth-internal.la \
-			src/libshared-glib.la $(GLIB_LIBS) -lreadline
-
-endif
 endif
 
 if CUPS
attrib/gatt.c +2 -1148

1,166 lines not on this page · raw message

attrib/gatt.h +0 -89

101 lines not on this page · raw message

attrib/gattrib.c deleted +0 -473

473 lines not on this page · raw message

attrib/gattrib.h deleted +0 -65

65 lines not on this page · raw message

attrib/gatttool.c deleted +0 -612

612 lines not on this page · raw message

attrib/gatttool.h deleted +0 -17
deleted file mode 100644
index 20cb42417e34..000000000000
@@ -1,17 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-or-later */
-/*
- *
- *  BlueZ - Bluetooth protocol stack for Linux
- *
- *  Copyright (C) 2011  Nokia Corporation
- *
- *
- */
-
-int interactive(const char *src, const char *dst, const char *dst_type,
-								int psm);
-GIOChannel *gatt_connect(const char *src, const char *dst,
-			const char *dst_type, const char *sec_level,
-			int psm, int mtu, BtIOConnect connect_cb,
-			GError **gerr);
-size_t gatt_attr_data_from_string(const char *str, uint8_t **data);
attrib/interactive.c deleted +0 -1020

511 lines not on this page · raw message

attrib/utils.c deleted +0 -110

110 lines not on this page · raw message

unit/test-gattrib.c deleted +0 -552

552 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.55.0

Part of the diff is not shown here. View the raw message.

author maintainer
#25 lore raw

PATCH v6 23/23 attrib: Remove directory

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

What is left of attrib is only used by bluetoothd: att_ecode2str, which is moved to src/shared/att as bt_att_ecode2str, and struct gatt_primary along with gatt_parse_record, which are moved to src/device, so remove the attrib directory.

Assisted-by OpenCode:claude-opus-5.5
---
 Makefile.am                      |    4 +-
 attrib/att-database.h            |   30 -
 attrib/att.c                     | 1238 ------------------------------
 attrib/att.h                     |  186 -----
 attrib/gatt.c                    |  103 ---
 attrib/gatt.h                    |   20 -
 profiles/battery/battery.c       |    3 +-
 profiles/deviceinfo/deviceinfo.c |    3 +-
 profiles/midi/midi.c             |    3 +-
 profiles/ranging/rap.c           |    1 -
 profiles/scanparam/scan.c        |    3 +-
 src/adapter.c                    |    3 +-
 src/device.c                     |   78 +-
 src/device.h                     |   13 +
 src/shared/att.c                 |   48 ++
 src/shared/att.h                 |    2 +
 16 files changed, 145 insertions(+), 1593 deletions(-)
 delete mode 100644 attrib/att-database.h
 delete mode 100644 attrib/att.c
 delete mode 100644 attrib/att.h
 delete mode 100644 attrib/gatt.c
 delete mode 100644 attrib/gatt.h
Makefile.am +1 -3
index 4ce15dbf083a..305c05df5ab5 100644
@@ -286,8 +286,6 @@ src_libshared_ell_la_LDFLAGS = $(AM_LDFLAGS)
 src_libshared_ell_la_CFLAGS = $(AM_CFLAGS)
 endif
 
-attrib_sources = attrib/att.h attrib/att-database.h attrib/att.c \
-		attrib/gatt.h attrib/gatt.c
 
 btio_sources = btio/btio.h btio/btio.c
 
@@ -308,7 +306,7 @@ include Makefile.plugins
 pkglibexec_PROGRAMS += src/bluetoothd
 
 bluetoothd_internal_sources = \
-			$(attrib_sources) $(btio_sources) \
+			$(btio_sources) \
 			src/log.h src/log.c \
 			src/backtrace.h src/backtrace.c \
 			src/rfkill.c src/btd.h src/sdpd.h \
attrib/att-database.h deleted +0 -30
deleted file mode 100644
index bb30933eaf04..000000000000
@@ -1,30 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-or-later */
-/*
- *
- *  BlueZ - Bluetooth protocol stack for Linux
- *
- *  Copyright (C) 2012 Texas Instruments Corporation
- *
- */
-
-/* Requirements for read/write operations */
-enum {
-	ATT_NONE,		/* No restrictions */
-	ATT_AUTHENTICATION,	/* Authentication required */
-	ATT_AUTHORIZATION,	/* Authorization required */
-	ATT_NOT_PERMITTED,	/* Operation not permitted */
-};
-
-struct attribute {
-	uint16_t handle;
-	bt_uuid_t uuid;
-	int read_req;		/* Read requirement */
-	int write_req;		/* Write requirement */
-	uint8_t (*read_cb)(struct attribute *a, struct btd_device *device,
-							gpointer user_data);
-	uint8_t (*write_cb)(struct attribute *a, struct btd_device *device,
-							gpointer user_data);
-	gpointer cb_user_data;
-	size_t len;
-	uint8_t *data;
-};
attrib/att.c deleted +0 -1238

1,238 lines not on this page · raw message

attrib/att.h deleted +0 -186

186 lines not on this page · raw message

attrib/gatt.c deleted +0 -103

103 lines not on this page · raw message

attrib/gatt.h deleted +0 -20
deleted file mode 100644
index 0fe81db06fe6..000000000000
@@ -1,20 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-or-later */
-/*
- *
- *  BlueZ - Bluetooth protocol stack for Linux
- *
- *  Copyright (C) 2010  Nokia Corporation
- *  Copyright (C) 2010  Marcel Holtmann <[email protected]>
- *
- *
- */
-
-struct gatt_primary {
-	char uuid[MAX_LEN_UUID_STR + 1];
-	gboolean changed;
-	struct att_range range;
-};
-
-gboolean gatt_parse_record(const sdp_record_t *rec,
-					uuid_t *prim_uuid, uint16_t *psm,
-					uint16_t *start, uint16_t *end);
profiles/battery/battery.c +1 -2
index 2fe1f4aca2cf..ce4564356c33 100644
@@ -40,7 +40,6 @@
 #include "src/service.h"
 #include "src/log.h"
 #include "src/battery.h"
-#include "attrib/att.h"
 
 #define BATTERY_INTERFACE "org.bluez.Battery1"
 
@@ -128,7 +127,7 @@ static void batt_io_ccc_written_cb(uint16_t att_ecode, void *user_data)
 
 	if (att_ecode != 0) {
 		error("Battery Level: notifications not enabled %s",
-		      att_ecode2str(att_ecode));
+		      bt_att_ecode2str(att_ecode));
 		return;
 	}
 
profiles/deviceinfo/deviceinfo.c +1 -2
index b1f6fb3ff749..2aaec84a8a4b 100644
@@ -31,7 +31,6 @@
 #include "src/shared/att.h"
 #include "src/shared/gatt-db.h"
 #include "src/shared/gatt-client.h"
-#include "attrib/att.h"
 #include "src/log.h"
 
 #define PNP_ID_SIZE	7
@@ -43,7 +42,7 @@ static void read_pnpid_cb(bool success, uint8_t att_ecode, const uint8_t *value,
 
 	if (!success) {
 		error("Error reading PNP_ID value: %s",
-						att_ecode2str(att_ecode));
+						bt_att_ecode2str(att_ecode));
 		return;
 	}
 
profiles/midi/midi.c +1 -2
index ea4719b95b23..f432ccde92f8 100644
@@ -31,7 +31,6 @@
 #include "src/shared/gatt-client.h"
 #include "src/shared/io.h"
 #include "src/log.h"
-#include "attrib/att.h"
 
 #include "libmidi.h"
 
@@ -134,7 +133,7 @@ static void midi_io_ccc_written_cb(uint16_t att_ecode, void *user_data)
 {
 	if (att_ecode != 0) {
 		error("MIDI I/O: notifications not enabled %s",
-		      att_ecode2str(att_ecode));
+		      bt_att_ecode2str(att_ecode));
 		return;
 	}
 
profiles/ranging/rap.c +0 -1
index f3f677c4b4bb..0fffd3e032b7 100644
@@ -33,7 +33,6 @@
 #include "src/shared/gatt-db.h"
 #include "src/shared/gatt-client.h"
 #include "src/shared/rap.h"
-#include "attrib/att.h"
 #include "src/log.h"
 #include "src/shared/cs-types.h"
 #include "src/btd.h"
profiles/scanparam/scan.c +1 -2
index a66f80eabf3e..d3c0809042be 100644
@@ -31,7 +31,6 @@
 #include "src/shared/queue.h"
 #include "src/shared/gatt-db.h"
 #include "src/shared/gatt-client.h"
-#include "attrib/att.h"
 #include "src/btd.h"
 
 #define SCAN_INTERVAL_WIN_UUID		0x2A4F
@@ -91,7 +90,7 @@ static void refresh_ccc_written_cb(uint16_t att_ecode, void *user_data)
 {
 	if (att_ecode != 0) {
 		error("Scan Refresh: notifications not enabled %s",
-						att_ecode2str(att_ecode));
+						bt_att_ecode2str(att_ecode));
 		return;
 	}
 
src/adapter.c +1 -2
index 4131c4431dc6..b33192641047 100644
@@ -45,6 +45,7 @@
 #include "src/shared/util.h"
 #include "src/shared/queue.h"
 #include "src/shared/att.h"
+#include "src/shared/crypto.h"
 #include "src/shared/gatt-db.h"
 #include "src/shared/timeout.h"
 
@@ -59,8 +60,6 @@
 #include "uuid-helper.h"
 #include "agent.h"
 #include "storage.h"
-#include "attrib/att.h"
-#include "attrib/gatt.h"
 #include "gatt-database.h"
 #include "advertising.h"
 #include "adv_monitor.h"
src/device.c +76 -2

96 lines not on this page · raw message

src/device.h +13 -0
index f18fa5b2119f..fdc036ec4dae 100644
@@ -9,6 +9,7 @@
  *
  */
 
+#include "bluetooth/uuid.h"
 #include "src/shared/queue.h"
 
 #define DEVICE_INTERFACE	"org.bluez.Device1"
@@ -67,6 +68,18 @@ void btd_device_set_record(struct btd_device *device, const char *uuid,
 							const char *record);
 const sdp_record_t *btd_device_get_record(struct btd_device *device,
 						const char *uuid);
+struct gatt_primary {
+	char uuid[MAX_LEN_UUID_STR + 1];
+	gboolean changed;
+	struct {
+		uint16_t start;
+		uint16_t end;
+	} range;
+};
+
+gboolean gatt_parse_record(const sdp_record_t *rec, uuid_t *prim_uuid,
+				uint16_t *psm, uint16_t *start, uint16_t *end);
+
 struct gatt_primary *btd_device_get_primary(struct btd_device *device,
 							const char *uuid);
 GSList *btd_device_get_primaries(struct btd_device *device);
src/shared/att.c +48 -0

51 lines not on this page · raw message

src/shared/att.h +2 -0
index ba1f846777dc..5b5cd4fbab2c 100644
@@ -29,6 +29,8 @@ bool bt_att_set_close_on_unref(struct bt_att *att, bool do_close);
 
 int bt_att_get_fd(struct bt_att *att);
 
+const char *bt_att_ecode2str(uint8_t ecode);
+
 int bt_att_attach_fd(struct bt_att *att, int fd);
 
 int bt_att_get_channels(struct bt_att *att);
Signature · 1 line
2.55.0
#26 lore raw
In reply to Luiz Augusto von Dentz
This series was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:

Hello:

This series was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:

Quoted 8 lines · On Mon, 28 Sep 2026 16:00:06 -0400 you wrote:

From: Luiz Augusto von Dentz <[email protected]>

This adds functional tests for HID over GATT (HoG), with bluetoothctl registering a HID Service acting as a keyboard, with and without Shorter Connection Interval (SCI) support, using the new client/scripts/hog-device*.bt scripts, and the HID host:

[...]

Here is the summary with links:
- [BlueZ,v6,01/23] shared/gatt-client: Fix calling destroy after unregistering notify

    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=65f8a8b60a70
  - [BlueZ,v6,02/23] client/gatt: Fix setting descriptor value from scripts
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=f14171908901
  - [BlueZ,v6,03/23] client/mgmt: Print Connection Subrate event
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=e96e1d7e6db8
  - [BlueZ,v6,04/23] emulator: Default to the latest BR/EDR+LE version
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=6b304a7dd2ac
  - [BlueZ,v6,05/23] client/scripts: Add HoG device scripts
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=2604ba5035cd
  - [BlueZ,v6,06/23] doc: Add functional-hog documentation
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=7b68fecf0599
  - [BlueZ,v6,07/23] test: functional: add HoG tests
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=c7a2a63a02d6
  - [BlueZ,v6,08/23] test: functional: limit the workers by the memory available
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=044404ccbf91
  - [BlueZ,v6,09/23] client/agent: Fix crash on Cancel with no pending request
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=67a794ff4048
  - [BlueZ,v6,10/23] shared/uhid: Fix size of Get Report reply with a Report ID
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=dc2eb1394f4f
  - [BlueZ,v6,11/23] shared/uhid: Keep reading when an event is not available
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=4efaf7ed188b
  - [BlueZ,v6,12/23] shared/tester: Allow expecting a PDU with no response
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=7104e632672b
  - [BlueZ,v6,13/23] shared/gatt-client: Fix calling idle callbacks again while notifying
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=326a0000ac02
  - [BlueZ,v6,14/23] shared/gatt-client: Add bt_gatt_client_is_idle
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=06053830b71c
  - [BlueZ,v6,15/23] shared/hog: Add initial implementation
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=c2f56f58b8b7
  - [BlueZ,v6,16/23] unit/test-hog: Use shared/hog
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=7af5798ddb42
  - [BlueZ,v6,17/23] test: functional: change the HoG SCI mode with the HID Control Point
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=c2f53b034348
  - [BlueZ,v6,18/23] input/hog: Use shared/hog
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=96f1201f5ac2
  - [BlueZ,v6,19/23] doc: Add CONFIG_HIDRAW to the tester kernel config
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=bb69738a1206
  - [BlueZ,v6,20/23] unit/test-uhid: Add Get Report tests
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=ed0b991aa5b2
  - [BlueZ,v6,21/23] device: Use bt_att instead of GAttrib
    (no matching commit)
  - [BlueZ,v6,22/23] attrib: Remove GAttrib and gatttool
    (no matching commit)
  - [BlueZ,v6,23/23] attrib: Remove directory
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=dbc6102ccdee

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html