device: Add btd_device_get_icon
Luiz Augusto von Dentz
maintainerPATCH v2 1/3 device: Add btd_device_get_icon
From: Luiz Augusto von Dentz <[email protected]>
This adds btd_device_get_icon which can be used to retriev the icon string of a device object.
--- src/device.c | 12 +++++------- src/device.h | 1 + 2 files changed, 6 insertions(+), 7 deletions(-)
src/device.c +5 -7
@@ -1052,16 +1052,14 @@ static gboolean dev_property_get_appearance(const GDBusPropertyTable *property,return TRUE; } -static const char *get_icon (const GDBusPropertyTable *property,void *data) +const char *btd_device_get_icon (struct btd_device *device) { -struct btd_device *device = data;const char *icon =NULL ; -uint16_t appearance;if (device->class !=0 ) icon =class_to_icon (device->class); -else if (get_appearance (property, data, &appearance)) - icon =gap_appearance_to_icon (appearance); +else if (device->appearance !=0 ) + icon =gap_appearance_to_icon (device->appearance);return icon; }
@@ -1069,7 +1067,7 @@ static const char *get_icon(const GDBusPropertyTable *property, void *data)static gboolean dev_property_exists_icon (const GDBusPropertyTable *property,void *data) { -return get_icon (property, data) !=NULL ; +return btd_device_get_icon (data) !=NULL ; } static gboolean dev_property_get_icon(const GDBusPropertyTable *property,
@@ -1077,7 +1075,7 @@ static gboolean dev_property_get_icon(const GDBusPropertyTable *property, {const char *icon; - icon =get_icon (property, data); + icon =btd_device_get_icon (data);if (icon ==NULL )return FALSE;
src/device.h +1 -0
@@ -41,6 +41,7 @@ uint16_t btd_device_get_vendor(struct btd_device *device);uint16_t btd_device_get_vendor_src (struct btd_device *device);uint16_t btd_device_get_product (struct btd_device *device);uint16_t btd_device_get_version (struct btd_device *device); +const char *btd_device_get_icon (struct btd_device *device);void device_remove_bonding (struct btd_device *device,uint8_t bdaddr_type);void device_remove (struct btd_device *device,gboolean remove_stored);int device_address_cmp (gconstpointer a,gconstpointer b);
Signature · 1 line
2.45.1
Luiz Augusto von Dentz
maintainerPATCH v2 2/3 hog-lib: Add force parameter to bt_hog_detach
From: Luiz Augusto von Dentz <[email protected]>
This adds force parameter to bt_hog_detach which indicates if the bt_uhid_destroy shall be called.
--- android/hidhost.c | 2 +- profiles/input/hog-lib.c | 9 ++++++--- profiles/input/hog-lib.h | 2 +- profiles/input/hog.c | 2 +- 4 files changed, 9 insertions(+), 6 deletions(-)
android/hidhost.c +1 -1
@@ -796,7 +796,7 @@ static void hog_conn_cb(const bdaddr_t *addr, int err, void *attrib)if (dev->hog) {bt_hid_notify_state (dev,HAL_HIDHOST_STATE_DISCONNECTED ); -bt_hog_detach (dev->hog); +bt_hog_detach (dev->hog, true);return ; } goto fail;
profiles/input/hog-lib.c +6 -3
@@ -1232,7 +1232,7 @@ static void hog_free(void *data) {struct bt_hog *hog = data; -bt_hog_detach (hog); +bt_hog_detach (hog, true);uhid_destroy (hog);queue_destroy (hog->bas, (void *) bt_bas_unref);
@@ -1747,7 +1747,7 @@ bool bt_hog_attach(struct bt_hog *hog, void *gatt)return true; } -void bt_hog_detach (struct bt_hog *hog) +void bt_hog_detach (struct bt_hog *hog,bool force) {GSList *l;
@@ -1759,7 +1759,7 @@ void bt_hog_detach(struct bt_hog *hog)for (l = hog->instances; l; l = l->next) {struct bt_hog *instance = l->data; -bt_hog_detach (instance); +bt_hog_detach (instance, force); }for (l = hog->reports; l; l = l->next) {
@@ -1780,6 +1780,9 @@ void bt_hog_detach(struct bt_hog *hog)queue_remove_all (hog->gatt_op, cancel_gatt_req, hog, destroy_gatt_req);g_attrib_unref (hog->attrib); hog->attrib =NULL ; + +if (force) +uhid_destroy (hog); }int bt_hog_set_control_point (struct bt_hog *hog,bool suspend)
profiles/input/hog-lib.h +1 -1
@@ -22,7 +22,7 @@ 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); +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 +1 -1
@@ -206,7 +206,7 @@ static int hog_disconnect(struct btd_service *service) {struct hog_device *dev =btd_service_get_user_data (service); -bt_hog_detach (dev->hog); +bt_hog_detach (dev->hog, false);btd_service_disconnecting_complete (service,0 );
Signature · 1 line
2.45.1
Luiz Augusto von Dentz
maintainerPATCH v2 3/3 shared/uhid: Add special handling for non-keyboards
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This adds special handling for non-keyboards so they are destroyed when disconnected rather than keeping their device node around.
--- android/hidhost.c | 3 ++- profiles/input/device.c | 20 +++++++++++-------- profiles/input/hog-lib.c | 43 +++++++++++++++++++++++----------------- profiles/input/hog-lib.h | 4 ++-- profiles/input/hog.c | 6 ++++-- src/shared/uhid.c | 17 ++++++++++++---- src/shared/uhid.h | 31 ++++++++++++++++++++++++++--- unit/test-hog.c | 2 +- unit/test-uhid.c | 6 +++--- 9 files changed, 90 insertions(+), 42 deletions(-)
android/hidhost.c +2 -1
@@ -808,7 +808,8 @@ static void hog_conn_cb(const bdaddr_t *addr, int err, void *attrib)if (!dev->hog) {/* TODO: Get device details and primary */ dev->hog =bt_hog_new_default ("bluez-input-device" , dev->vendor, - dev->product, dev->version,NULL ); + dev->product, dev->version, +BT_UHID_NONE ,NULL );if (!dev->hog) {error ("HoG: unable to create session" ); goto fail;
profiles/input/device.c +12 -8
@@ -84,6 +84,7 @@ struct input_device {unsigned int report_req_timer;uint32_t report_rsp_id;bool virtual_cable_unplug; +uint8_t type;unsigned int idle_timer; };
@@ -174,18 +175,19 @@ static int uhid_disconnect(struct input_device *idev, bool force)if (!bt_uhid_created (idev->uhid))return 0 ; -/* Only destroy the node if virtual cable unplug flag has been set */ -if (!idev->virtual_cable_unplug && !force) -return 0 ; +/* Force destroy the node if virtual cable unplug flag has been set */ +if (idev->virtual_cable_unplug && !force) + force = true; -bt_uhid_unregister_all (idev->uhid); - - err =bt_uhid_destroy (idev->uhid); + err =bt_uhid_destroy (idev->uhid, force);if (err <0 ) {error ("bt_uhid_destroy: %s" ,strerror (-err));return err; } +if (!bt_uhid_created (idev->uhid)) +bt_uhid_unregister_all (idev->uhid); +return err; }
@@ -989,7 +991,8 @@ static int uhid_connadd(struct input_device *idev, struct hidp_connadd_req *req) err =bt_uhid_create (idev->uhid, req->name, &idev->src, &idev->dst, req->vendor, req->product, req->version, - req->country, req->rd_data, req->rd_size); + req->country, idev->type, + req->rd_data, req->rd_size);if (err <0 ) {error ("bt_uhid_create: %s" ,strerror (-err));return err;
@@ -1078,7 +1081,7 @@ static int hidp_add_connection(struct input_device *idev)/* Some platforms may choose to require encryption for all devices */ /* Note that this only matters for pre 2.1 devices as otherwise the */ /* device is encrypted by default by the lower layers */ -if (classic_bonded_only || req->subclass &0x40 ) { +if (classic_bonded_only || idev->type ==BT_UHID_KEYBOARD ) {if (!bt_io_set (idev->intr_io, &gerr,BT_IO_OPT_SEC_LEVEL ,BT_IO_SEC_MEDIUM ,BT_IO_OPT_INVALID )) {
@@ -1468,6 +1471,7 @@ static struct input_device *input_device_new(struct btd_service *service) idev->service =btd_service_ref (service); idev->device =btd_device_ref (device); idev->path =g_strdup (path); + idev->type =bt_uhid_icon_to_type (btd_device_get_icon (device));input_device_update_rec (idev);
profiles/input/hog-lib.c +25 -18
140 lines not on this page · raw message
profiles/input/hog-lib.h +2 -2
@@ -12,11 +12,11 @@ struct bt_hog;struct bt_hog *bt_hog_new_default (const char *name,uint16_t vendor,uint16_t product,uint16_t version, -struct gatt_db *db); +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, -struct gatt_db *db); +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);
profiles/input/hog.c +4 -2
@@ -50,6 +50,7 @@struct hog_device {struct btd_device *device;struct bt_hog *hog; +uint8_t type; };static gboolean suspend_supported = FALSE;
@@ -64,7 +65,7 @@ void input_set_auto_sec(bool state)static void hog_device_accept (struct hog_device *dev,struct gatt_db *db) {char name[248 ]; -uint16_t vendor, product, version; +uint16_t vendor, product, version, type;if (dev->hog)return ;
@@ -77,11 +78,12 @@ static void hog_device_accept(struct hog_device *dev, struct gatt_db *db) vendor =btd_device_get_vendor (dev->device); product =btd_device_get_product (dev->device); version =btd_device_get_version (dev->device); + type =bt_uhid_icon_to_type (btd_device_get_icon (dev->device));DBG ("name=%s vendor=0x%X, product=0x%X, version=0x%X" , name, vendor, product, version); - dev->hog =bt_hog_new_default (name, vendor, product, version, db); + dev->hog =bt_hog_new_default (name, vendor, product, version, type, db); }static struct hog_device *hog_device_new (struct btd_device *device)
src/shared/uhid.c +13 -4
@@ -44,6 +44,7 @@ struct bt_uhid {unsigned int notify_id;struct queue *notify_list;struct queue *input; +uint8_t type;bool created;bool started;struct uhid_replay *replay;
@@ -338,8 +339,8 @@ static void uhid_start(struct uhid_event *ev, void *user_data)int bt_uhid_create (struct bt_uhid *uhid,const char *name,bdaddr_t *src,bdaddr_t *dst,uint32_t vendor,uint32_t product, -uint32_t version,uint32_t country,void *rd_data, -size_t rd_size) +uint32_t version,uint32_t country,uint8_t type, +void *rd_data,size_t rd_size) {struct uhid_event ev;int err;
@@ -381,6 +382,7 @@ int bt_uhid_create(struct bt_uhid *uhid, const char *name, bdaddr_t *src, uhid->created = true; uhid->started = false; + uhid->type = type;return 0 ; }
@@ -487,7 +489,7 @@ done:return bt_uhid_send (uhid, &ev); } -int bt_uhid_destroy (struct bt_uhid *uhid) +int bt_uhid_destroy (struct bt_uhid *uhid,bool force) {struct uhid_event ev;int err;
@@ -495,7 +497,14 @@ int bt_uhid_destroy(struct bt_uhid *uhid)if (!uhid)return -EINVAL ; -if (!uhid->created) +/* Force destroy for non-keyboard devices - keyboards are not destroyed +* on disconnect since they can glitch on reconnection losing +* keypresses. +*/ +if (!force && uhid->type !=BT_UHID_KEYBOARD ) + force = true; + +if (!uhid->created || !force)return 0 ;memset (&ev,0 ,sizeof (ev));
src/shared/uhid.h +28 -3
@@ -15,6 +15,31 @@struct bt_uhid ; +enum { +BT_UHID_NONE =0 , +BT_UHID_KEYBOARD , +BT_UHID_MOUSE , +BT_UHID_GAMING , +BT_UHID_TABLET +}; + +static inline uint8_t bt_uhid_icon_to_type (const char *icon) +{ +if (!icon) +return BT_UHID_NONE ; + +if (!strcmp (icon,"input-keyboard" )) +return BT_UHID_KEYBOARD ; +else if (!strcmp (icon,"input-mouse" )) +return BT_UHID_MOUSE ; +else if (!strcmp (icon,"input-gaming" )) +return BT_UHID_GAMING ; +else if (!strcmp (icon,"input-tablet" )) +return BT_UHID_TABLET ; +else +return BT_UHID_NONE ; +} +struct bt_uhid *bt_uhid_new_default (void );struct bt_uhid *bt_uhid_new (int fd);
@@ -32,8 +57,8 @@ bool bt_uhid_unregister_all(struct bt_uhid *uhid);int bt_uhid_send (struct bt_uhid *uhid,const struct uhid_event *ev);int bt_uhid_create (struct bt_uhid *uhid,const char *name,bdaddr_t *src,bdaddr_t *dst,uint32_t vendor,uint32_t product, -uint32_t version,uint32_t country,void *rd_data, -size_t rd_size); +uint32_t version,uint32_t country,uint8_t type, +void *rd_data,size_t rd_size);bool bt_uhid_created (struct bt_uhid *uhid);bool bt_uhid_started (struct bt_uhid *uhid); int bt_uhid_input(struct bt_uhid *uhid, uint8_t number, const void *data,
@@ -41,5 +66,5 @@ int bt_uhid_input(struct bt_uhid *uhid, uint8_t number, const void *data,int bt_uhid_set_report_reply (struct bt_uhid *uhid,uint8_t id,uint8_t status);int bt_uhid_get_report_reply (struct bt_uhid *uhid,uint8_t id,uint8_t number,uint8_t status,const void *data,size_t size); -int bt_uhid_destroy (struct bt_uhid *uhid); +int bt_uhid_destroy (struct bt_uhid *uhid,bool force);int bt_uhid_replay (struct bt_uhid *uhid);
unit/test-hog.c +1 -1
@@ -182,7 +182,7 @@ static struct context *create_context(gconstpointer data) fd =open ("/dev/null" ,O_WRONLY |O_CLOEXEC );g_assert (fd >0 ); - context->hog =bt_hog_new (fd, name, vendor, product, version,NULL ); + context->hog =bt_hog_new (fd, name, vendor, product, version,0 ,NULL );g_assert (context->hog); channel =g_io_channel_unix_new (sv[1 ]);
unit/test-uhid.c +3 -3
@@ -231,13 +231,13 @@ static void test_client(gconstpointer data)struct context *context =create_context (data);int err; - err =bt_uhid_create (context->uhid,"" ,NULL ,NULL ,0 ,0 ,0 ,0 ,NULL , -0 ); + err =bt_uhid_create (context->uhid,"" ,NULL ,NULL ,0 ,0 ,0 ,0 , +BT_UHID_NONE ,NULL ,0 );if (err <0 )tester_test_failed ();if (g_str_equal (context->data->test_name,"/uhid/command/destroy" )) { - err =bt_uhid_destroy (context->uhid); + err =bt_uhid_destroy (context->uhid, true);if (err <0 )tester_test_failed (); }
Signature · 1 line
2.45.1
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, 20 May 2024 14:14:37 -0400 you wrote:
From: Luiz Augusto von Dentz <[email protected]>
This adds
btd_device_get_iconwhich can be used to retriev the icon string of a device object.--- src/device.c | 12 +++++------- src/device.h | 1 + 2 files changed, 6 insertions(+), 7 deletions(-)
Here is the summary with links:
- [BlueZ,v2,1/3] device: Add btd_device_get_icon
https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=25d3b629e4df - [BlueZ,v2,2/3] hog-lib: Add force parameter to bt_hog_detach https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=db383a5b4a8d - [BlueZ,v2,3/3] shared/uhid: Add special handling for non-keyboards https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=e4f6c68f2a4d
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
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/project/bluetooth/list/?series=854479
---Test result---
Test Summary:
CheckPatch PASS 2.04 seconds GitLint PASS 1.00 seconds BuildEll PASS 25.00 seconds BluezMake PASS 1721.03 seconds MakeCheck PASS 13.21 seconds MakeDistcheck PASS 177.47 seconds CheckValgrind PASS 248.07 seconds CheckSmatch PASS 352.51 seconds bluezmakeextell PASS 119.33 seconds IncrementalBuild PASS 4586.72 seconds ScanBuild PASS 1004.39 seconds
---
Regards,
Linux Bluetooth