Received: by 2002:ab2:b82:0:b0:1f3:401:3cfb with SMTP id 2csp522182lqh; Thu, 28 Mar 2024 08:33:05 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUOFR1TWQ7sE5Ec6oTcvt2Rc2GZvlo4Cf6WeKOaqW4I2OhlzWgd7WpQu+sEUk92x8B4ulESZsBjBOddekg15X981L9m10Wa412xmXmSrA== X-Google-Smtp-Source: AGHT+IFwUX1nbCbbebgVVrawiSz8QBe+kL8FZRchDxPHHWyWbje3hiaZZPLdhSG02ES6tEzVpGcf X-Received: by 2002:a50:8d14:0:b0:567:9fef:f7ee with SMTP id s20-20020a508d14000000b005679feff7eemr2547617eds.16.1711639985801; Thu, 28 Mar 2024 08:33:05 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711639985; cv=pass; d=google.com; s=arc-20160816; b=WtTTzyPyBnK0Rl4GD/2QAdKjCizMNyfj1Toe9cnxYeTG1the0cwY671h4TsSmhJssn fG9SSZhihv1ym10bo/15TbeL9dn+/Tk4HUo2kdD3uB4LHFDzY2vu0rCJ4IMpW9je2IzS ymhVaX19aS7mIECwTpqLN9TUg/x4t9NNw5gnkyCFwfni4Azns51eDFXjuD5zRS09AEgc hDWUaXKbiIPwbcCF/00nBpOW/CPWcDK2i8MqqovwAL/OILxxB300e72F3jPmdSvDtW0E zykeyJ+TrEN3v1EfXWCpfG3+rQuM3aj/Rt5qfABsGuuP/yFje06jOL7j+5qPzod/PvSg A6WQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:to:from :dkim-signature; bh=Db/DIkTVVG3EAOgN+gmvaboNMLf6YY+23htotPYKnsY=; fh=4lGQI6056MBa4/oovMyIYaKLn+Wz/24RGvUivMmQP8E=; b=FE0WIHaJ9jLGDkXlc5mzmUgmJRJFiUuPz8mS2SKlUQ2FTm2HxdT+g3YDvwMwvXXklC 1xcUH0XZUahY9341Tu9hPu/0aQzSIzOqrkMXIEO0eyoOBOC/JqNt1f5GHlSH/WWHtfwF XYBVtjpEyc6liwpkDL+HDpqE0bp0vE9Jpux15oY/zUtZ/f35DWa2r54GOIsXlKe/VNmW k6P9AJLxOz/szb88aizGSY5F3iYttjbXyN10mRuRWGmuNm5xKw7m1WMcCtwRtOhRs9ZT IUkajq3UNuajfe1hHA69YMiWg2pOfMZUkVfE4i+TIV2F62U1X/62LVkub2MadiqQjyvR dA1w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=hNggBMiz; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-bluetooth+bounces-2918-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-2918-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id y16-20020a056402271000b0056bfa9dc444si914329edd.436.2024.03.28.08.33.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 08:33:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth+bounces-2918-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=hNggBMiz; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-bluetooth+bounces-2918-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-2918-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 210731F235C8 for ; Thu, 28 Mar 2024 15:33:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A3D5812F38D; Thu, 28 Mar 2024 15:32:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hNggBMiz" X-Original-To: linux-bluetooth@vger.kernel.org Received: from mail-yw1-f181.google.com (mail-yw1-f181.google.com [209.85.128.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 83A5E12E1F9 for ; Thu, 28 Mar 2024 15:32:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711639978; cv=none; b=cAj6JbH0DSb1/k6C3KG8jp/3mZtjjVmVM5EFExfD1Uk7927AJOdPZ4VaeFDQj8Eeuk22w8+iD9zmhzHo/E+NInzMiVUbbJzJX2+dW2OrrYLcw2RowlxdDhff+9/M1LffuxqR2ZxhC3Ib6LtZOz21raEYcMWfnfOdbnsekTMoF5g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711639978; c=relaxed/simple; bh=YrEX1pFaBBCv+85Ax+FgJ0ML0ykxzPK4VpnpOYy7Xdk=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=CAPzzue5L1lormhosGIq8KP0jPwYWo5mtgZC+EsqNVsLVWgPh/rYZrUABB8RXO+KlRAyF84L05k//xM6ec/aoeOgNLMVZekVM0AiEOgABPkjh5CXXwwgPhAGSgFWFJKp0SSJsrtIqlVQAQ1OP3oLNgfJQUo/m5pvUQp8KZa1m44= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=hNggBMiz; arc=none smtp.client-ip=209.85.128.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-yw1-f181.google.com with SMTP id 00721157ae682-611248b4805so11408697b3.0 for ; Thu, 28 Mar 2024 08:32:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711639974; x=1712244774; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=Db/DIkTVVG3EAOgN+gmvaboNMLf6YY+23htotPYKnsY=; b=hNggBMiztMUzki3sH4ZtjjLfULOioBLCRSSUpxLQ048+ZcvZQpHC2j4IuNrS1gZsc5 aUdT/ZxjY+WPlr9aUeFHv1gJ0Sv2K3eNkygTVVBerDpoHH35d2QqTF4X1cD0WtaI3Oub XXx59P65Fa/2jQ4pLyTzvlCyu12T7d4RjORgeTJ136qiv+7MIdIEJBlu4P/41AEnzxIZ 5S30tAjfo2e6o8YNuIUp55n3Ja4B6yI8GjUCFI2G/aTD+kjmNsXCOSQitiWzTskWTUi5 5qWWTXNiTwfZI/M4zwzmaeg7Nray8r2E01ixR1h5ETRq1TVE158Gyga+cdJmiuQaWMZ5 h5Gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711639974; x=1712244774; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Db/DIkTVVG3EAOgN+gmvaboNMLf6YY+23htotPYKnsY=; b=whxzr0lOoX1pe7cknmSjgwyGQOz2MlN5opxJMkoyy+QG2O1E0RzAR8vzJ12U3cAT/+ IYyqEjAY77gkpG/hAEUik6jyezyeOCUv4rj5K9jA9Zinl2KWv0k8z05pFyLk3Q2ITJfT 0dgRsaediv547tqtaX9okYAmETz0x1OWN6pd3XTMRICbphaMMUVC6R9/MjeXdKwC0opC 7wqEs//zRS0ZWUCFvuij10pI93Wh0dZj0NClyCl9AlfJfquevu67OZi8qktnOZ2Vn5fy yOBigtCsXtdJRV9i5bKNdhTIpijdJ+CZBl1GHX/ju3385v+YObGWg/4a9bkTesaU3dhg qoog== X-Gm-Message-State: AOJu0YzEyIKVcyNzPNy2rqNxo5yw1CJPnEVkkFoiN+PudUN9lEE0d5G5 7iOgnQfprY67t2F74TbonxIbFdOzR6pLyf9EsA4zOkISpCFpEJOPN0+H7Duq X-Received: by 2002:a05:6902:1351:b0:dbd:c442:9e60 with SMTP id g17-20020a056902135100b00dbdc4429e60mr3390122ybu.36.1711639974256; Thu, 28 Mar 2024 08:32:54 -0700 (PDT) Received: from lvondent-mobl4.. (107-146-107-067.biz.spectrum.com. [107.146.107.67]) by smtp.gmail.com with ESMTPSA id 83-20020a250656000000b00dcd3e78d086sm347473ybg.46.2024.03.28.08.32.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 08:32:53 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v3 1/2] input/device: Fix not handling IdleTimeout when uhid is in use Date: Thu, 28 Mar 2024 11:32:51 -0400 Message-ID: <20240328153252.1752439-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.44.0 Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Luiz Augusto von Dentz When uhid is in use IdleTimeout was not taking any effect, this also attempt to force the destroy the input device node to make it useful for users that don't want to keep the input node forever. Fixes: https://github.com/bluez/bluez/issues/777 --- profiles/input/device.c | 86 +++++++++++++++++++++++++++------------ profiles/input/input.conf | 2 +- 2 files changed, 61 insertions(+), 27 deletions(-) diff --git a/profiles/input/device.c b/profiles/input/device.c index 1b28cdc174b1..b622ee8cd681 100644 --- a/profiles/input/device.c +++ b/profiles/input/device.c @@ -77,6 +77,7 @@ struct input_device { unsigned int report_req_timer; uint32_t report_rsp_id; bool virtual_cable_unplug; + unsigned int idle_timer; }; static int idle_timeout = 0; @@ -139,6 +140,9 @@ static void input_device_free(struct input_device *idev) g_free(idev->req); } + if (idev->idle_timer) + timeout_remove(idev->idle_timer); + if (idev->reconnect_timer > 0) timeout_remove(idev->reconnect_timer); @@ -156,8 +160,54 @@ static void virtual_cable_unplug(struct input_device *idev) idev->virtual_cable_unplug = false; } -static bool hidp_send_message(GIOChannel *chan, uint8_t hdr, - const uint8_t *data, size_t size) +static int uhid_disconnect(struct input_device *idev, bool force) +{ + int err; + + 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; + + bt_uhid_unregister_all(idev->uhid); + + err = bt_uhid_destroy(idev->uhid); + if (err < 0) { + error("bt_uhid_destroy: %s", strerror(-err)); + return err; + } + + return err; +} + +static bool input_device_idle_timeout(gpointer user_data) +{ + struct input_device *idev = user_data; + + idev->idle_timer = 0; + + DBG("path=%s", idev->path); + + uhid_disconnect(idev, true); + connection_disconnect(idev, 0); + + return false; +} + +static void input_device_idle_reset(struct input_device *idev) +{ + timeout_remove(idev->idle_timer); + + if (idle_timeout) + idev->idle_timer = timeout_add_seconds(idle_timeout, + input_device_idle_timeout, idev, + NULL); +} + +static bool hidp_send_message(struct input_device *idev, GIOChannel *chan, + uint8_t hdr, const uint8_t *data, size_t size) { int fd; ssize_t len; @@ -191,6 +241,8 @@ static bool hidp_send_message(GIOChannel *chan, uint8_t hdr, return false; } + input_device_idle_reset(idev); + return true; } @@ -200,13 +252,13 @@ static bool hidp_send_ctrl_message(struct input_device *idev, uint8_t hdr, if (hdr == (HIDP_TRANS_HID_CONTROL | HIDP_CTRL_VIRTUAL_CABLE_UNPLUG)) idev->virtual_cable_unplug = true; - return hidp_send_message(idev->ctrl_io, hdr, data, size); + return hidp_send_message(idev, idev->ctrl_io, hdr, data, size); } static bool hidp_send_intr_message(struct input_device *idev, uint8_t hdr, const uint8_t *data, size_t size) { - return hidp_send_message(idev->intr_io, hdr, data, size); + return hidp_send_message(idev, idev->intr_io, hdr, data, size); } static bool uhid_send_get_report_reply(struct input_device *idev, @@ -297,6 +349,8 @@ static bool hidp_recv_intr_data(GIOChannel *chan, struct input_device *idev) return true; } + input_device_idle_reset(idev); + hdr = data[0]; if (hdr != (HIDP_TRANS_DATA | HIDP_DATA_RTYPE_INPUT)) { DBG("unsupported HIDP protocol header 0x%02x", hdr); @@ -313,28 +367,6 @@ static bool hidp_recv_intr_data(GIOChannel *chan, struct input_device *idev) return true; } -static int uhid_disconnect(struct input_device *idev, bool force) -{ - int err; - - 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; - - bt_uhid_unregister_all(idev->uhid); - - err = bt_uhid_destroy(idev->uhid); - if (err < 0) { - error("bt_uhid_destroy: %s", strerror(-err)); - return err; - } - - return err; -} - static gboolean intr_watch_cb(GIOChannel *chan, GIOCondition cond, gpointer data) { struct input_device *idev = data; @@ -520,6 +552,8 @@ static bool hidp_recv_ctrl_message(GIOChannel *chan, struct input_device *idev) return true; } + input_device_idle_reset(idev); + hdr = data[0]; type = hdr & HIDP_HEADER_TRANS_MASK; param = hdr & HIDP_HEADER_PARAM_MASK; diff --git a/profiles/input/input.conf b/profiles/input/input.conf index 00a34eb63de1..fc20c58b6b32 100644 --- a/profiles/input/input.conf +++ b/profiles/input/input.conf @@ -6,7 +6,7 @@ # Set idle timeout (in minutes) before the connection will # be disconnect (defaults to 0 for no timeout) -#IdleTimeout=30 +#IdleTimeout=0 # Enable HID protocol handling in userspace input profile # Defaults to true (Use UHID instead of kernel HIDP) -- 2.44.0