Add HoG functional tests and shared/hog
Subsystems (2)
Luiz Augusto von Dentz
maintainerv5 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 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).
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 (21):
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/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 | 21 + src/shared/hog.c | 1659 +++++++++++++++++++++++++ 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 | 1431 ++++++++++++++++------ unit/test-uhid.c | 272 +++++ 58 files changed, 4106 insertions(+), 9203 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
Luiz Augusto von Dentz
maintainerPATCH v5 1/21 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.
--- src/gatt-client.c | 7 +++++-- src/shared/gatt-client.c | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-)
src/gatt-client.c +5 -2
@@ -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
@@ -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
Luiz Augusto von Dentz
maintainerPATCH v5 2/21 client/gatt: Fix setting descriptor value from scripts
In reply to Luiz Augusto von DentzFrom: 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.
--- client/gatt.c | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-)
client/gatt.c +28 -11
@@ -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
Luiz Augusto von Dentz
maintainerPATCH v5 3/21 client/mgmt: Print Connection Subrate event
In reply to Luiz Augusto von DentzFrom: 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.
--- client/mgmt.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)
client/mgmt.c +31 -0
@@ -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) { +"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 ; + } + +"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
Luiz Augusto von Dentz
maintainerPATCH v5 4/21 emulator: Default to the latest BR/EDR+LE version
In reply to Luiz Augusto von DentzFrom: 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.
--- 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
@@ -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
@@ -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
@@ -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
Luiz Augusto von Dentz
maintainerPATCH v5 5/21 client/scripts: Add HoG device scripts
In reply to Luiz Augusto von DentzFrom: 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.
--- 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
@@ -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
@@ -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
Luiz Augusto von Dentz
maintainerPATCH v5 6/21 doc: Add functional-hog documentation
In reply to Luiz Augusto von DentzFrom: 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
--- 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
@@ -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
@@ -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
Luiz Augusto von Dentz
maintainerPATCH v5 7/21 test: functional: add HoG tests
In reply to Luiz Augusto von DentzFrom: 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.
--- 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
@@ -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
Luiz Augusto von Dentz
maintainerPATCH v5 8/21 test: functional: limit the workers by the memory available
In reply to Luiz Augusto von DentzFrom: 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.
--- Makefile.am | 7 ++++- doc/test-functional.rst | 25 ++++++++++++++++ test/functional/conftest.py | 58 +++++++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+), 1 deletion(-)
Makefile.am +6 -1
@@ -885,9 +885,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
@@ -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
Luiz Augusto von Dentz
maintainerPATCH v5 9/21 client/agent: Fix crash on Cancel with no pending request
In reply to Luiz Augusto von DentzFrom: 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.
--- client/agent.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
client/agent.c +8 -2
@@ -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
Luiz Augusto von Dentz
maintainerPATCH v5 10/21 shared/uhid: Fix size of Get Report reply with a Report ID
In reply to Luiz Augusto von DentzFrom: 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.
--- src/shared/uhid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
src/shared/uhid.c +1 -1
@@ -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
Luiz Augusto von Dentz
maintainerPATCH v5 11/21 shared/uhid: Keep reading when an event is not available
In reply to Luiz Augusto von DentzFrom: 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.
--- src/shared/uhid.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
src/shared/uhid.c +4 -1
@@ -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
Luiz Augusto von Dentz
maintainerPATCH v5 12/21 shared/tester: Allow expecting a PDU with no response
In reply to Luiz Augusto von DentzFrom: 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.
--- src/shared/tester.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
src/shared/tester.c +19 -0
@@ -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
Luiz Augusto von Dentz
maintainerPATCH v5 13/21 shared/hog: Add initial implementation
In reply to Luiz Augusto von DentzFrom: 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
- 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 with a long read once every other read is complete, so the report IDs are known before creating the uHID device
- the addresses of the uHID device are taken from the ATT socket
- pending requests are cancelled when detaching, and notifications are unregistered so they are disabled if still connected
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.
--- Makefile.am | 1 + src/shared/hog.c | 1659 ++++++++++++++++++++++++++++++++++++++++++++++ src/shared/hog.h | 67 ++ 3 files changed, 1727 insertions(+) create mode 100644 src/shared/hog.c create mode 100644 src/shared/hog.h
Makefile.am +1 -0
@@ -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 +1659 -0
1,659 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
Luiz Augusto von Dentz
maintainerPATCH v5 14/21 unit/test-hog: Use shared/hog
In reply to Luiz Augusto von DentzFrom: 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 and BV-02-C (notifications disabled when detaching)
- 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.
--- Makefile.am | 11 +- unit/test-hog.c | 1431 +++++++++++++++++++++++++++++++++++------------ 2 files changed, 1079 insertions(+), 363 deletions(-)
Makefile.am +1 -10
@@ -768,16 +768,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 +1078 -353
1,493 lines not on this page · raw message
Signature · 1 line
2.55.0
Luiz Augusto von Dentz
maintainerPATCH v5 15/21 test: functional: change the HoG SCI mode with the HID Control Point
In reply to Luiz Augusto von DentzFrom: 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.
--- 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
@@ -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
@@ -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
Luiz Augusto von Dentz
maintainerPATCH v5 16/21 input/hog: Use shared/hog
In reply to Luiz Augusto von DentzFrom: 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.
--- 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
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.
Luiz Augusto von Dentz
maintainerPATCH v5 17/21 doc: Add CONFIG_HIDRAW to the tester kernel config
In reply to Luiz Augusto von DentzFrom: 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.
--- doc/test-runner.rst | 5 +++++ doc/tester.config | 1 + 2 files changed, 6 insertions(+)
doc/test-runner.rst +5 -0
@@ -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
@@ -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
Luiz Augusto von Dentz
maintainerPATCH v5 18/21 unit/test-uhid: Add Get Report tests
In reply to Luiz Augusto von DentzFrom: 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.
--- unit/test-uhid.c | 272 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 272 insertions(+)
unit/test-uhid.c +272 -0
@@ -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
Luiz Augusto von Dentz
maintainerPATCH v5 19/21 device: Use bt_att instead of GAttrib
In reply to Luiz Augusto von DentzFrom: 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.
--- 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
@@ -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
@@ -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
@@ -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
@@ -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
Luiz Augusto von Dentz
maintainerPATCH v5 20/21 attrib: Remove GAttrib and gatttool
In reply to Luiz Augusto von DentzFrom: 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.
--- .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
@@ -45,7 +45,6 @@ tools/97-hid2hci.rules profiles/cups/bluetooth profiles/iap/iapd -attrib/gatttool tools/avinfo tools/bccmd tools/hwdb
@@ -174,7 +173,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
@@ -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
@@ -772,14 +771,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
@@ -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
@@ -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.
Luiz Augusto von Dentz
maintainerPATCH v5 21/21 attrib: Remove directory
In reply to Luiz Augusto von DentzFrom: 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.
--- 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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