From patchwork Fri Mar 8 22:10:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 779222 Received: from mail-ua1-f53.google.com (mail-ua1-f53.google.com [209.85.222.53]) (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 33706249E5 for ; Fri, 8 Mar 2024 22:10:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709935813; cv=none; b=TuWNhwtas4oFKJ6BNmuRqXaHM+K73J1akjqcL7M5Qm2qmpLQSqRgkFXKbJs/jCE1HgPBQXVq6k8wlEsC1raLp+4puUXlBhKn3lOCcIcvjQFUIseTdNMQwsg6vWATeMXvyjG7FTnSzEajQaaQaYTGMbZkcYbVB4aM/GJd+w/zoU0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709935813; c=relaxed/simple; bh=DNyP33agfGHPY+dqdalB1KLZt2pi4f8waQaBbzx6DFQ=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=A3BbT0cvQIs+y/dd5id+8FveDjhyOM6SzT5Pl9vQgD4NM2jektXzDde6nCVayDnx1Y6R1I5pf6v3hiHKo6KYj2tAHGNICunKlBz9ihgMMdqhOltpnqwRC9av65RJyHaDkuJyw73Tw08JvqqIR0PeuK88Z/SMkfkHeUu/YEOf/20= 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=EEmFi5ly; arc=none smtp.client-ip=209.85.222.53 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="EEmFi5ly" Received: by mail-ua1-f53.google.com with SMTP id a1e0cc1a2514c-7db36dbd474so672453241.2 for ; Fri, 08 Mar 2024 14:10:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709935810; x=1710540610; 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=9qN6c7ByMY6yhJzfLVBeV1zP/KZNHGV/rYowEImsJWA=; b=EEmFi5lyeEK/NF8yEwv1ZcbhaApD89GNYIMJM6JRn+bkCdEYwVaeSKVPTpgR/PLxvV MVbgk5FuN9NkLqh+fJm/6ATHiqCMvk9SXSsZ+oa4wHMCVkQQqjRG8atwLEWdwt3LkR0J UkXG1ICONBNEqC0sb2RcVXIQk3hCtVcz3pkd7HEVgKnkCUvTLuyGzJFSQsPAhel1RxtE OvJ6sUFq2pniaYOzPH7Z465NhE7SN0/ASZzpkDPtUCseIuoNQyH6NtVdI4DF2InWXsGP S3zMzctNA+MnH8So2nm34sMsKyaoiV24CCHxEdmec1bG9msYGUuaboBDU6eIzntVcwXk ujTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709935810; x=1710540610; 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=9qN6c7ByMY6yhJzfLVBeV1zP/KZNHGV/rYowEImsJWA=; b=KpfBNNIVyKj8llCukzCOvKXOyDGsruWbWpIicYH7oeNRZNGGA0IUHxmRaRA++rU+k1 S9e4L2g8b+PpCZv9+9hHhPHYMYJ3CB3GkXCCrsLTEY3t8WTlGLgi368Lu2LrcKT29uHt 7abEd3fHyPdicP9kzKPmiE1iQtkz+TXpwbGcii4eeGa8sCXAnIV8mmpoI7G8Rl4yOxet TH8OzqWrMbf01RmO2K+qEjWxsLUKq7cSt9gjmNHkReGSySckMyfTFUKf2KlDtU+f3v8/ rcT1FSvwHtQZyAJg83wX/aJk3BBKbsCuVdZHVBj+L4kd0E2JcfsCJV6evTw2KyiarG5k POxQ== X-Gm-Message-State: AOJu0YxhfV97klHvIZlBYBZbMYXbrQ6RZZPOVCDDkQGHrSgA4WFgZb8Y n19br4ZGKRGAVPpV57ajTGo1UqiB88iJCl7WzhO7JTeIzPH6/xxXNmzDlO7k X-Google-Smtp-Source: AGHT+IFBR0boDZqrEgSpDj02mcEtyUbYWOtMLIHJrHJGr5bRKCMmuNxKTGY2HlonsWozgs6peVK1Kw== X-Received: by 2002:a05:6122:c9:b0:4d3:4aad:7bf0 with SMTP id h9-20020a05612200c900b004d34aad7bf0mr573624vkc.0.1709935809848; Fri, 08 Mar 2024 14:10:09 -0800 (PST) Received: from lvondent-mobl4.. (107-146-107-067.biz.spectrum.com. [107.146.107.67]) by smtp.gmail.com with ESMTPSA id el15-20020a056122278f00b004d33d93758asm29039vkb.23.2024.03.08.14.10.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Mar 2024 14:10:09 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v1 1/4] shared/uhid: Add bt_uhid_create Date: Fri, 8 Mar 2024 17:10:04 -0500 Message-ID: <20240308221007.250681-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Luiz Augusto von Dentz This adds bt_uhid_create which uses UHID_CREATE2 and tracks progress of when the device is ready to receive events and in the meantime queues them while waiting for UHID_START. --- src/shared/uhid.c | 134 ++++++++++++++++++++++++++++++++++++++++++++-- src/shared/uhid.h | 8 +++ 2 files changed, 138 insertions(+), 4 deletions(-) diff --git a/src/shared/uhid.c b/src/shared/uhid.c index 1f15443cd6d0..65e2d018a82e 100644 --- a/src/shared/uhid.c +++ b/src/shared/uhid.c @@ -31,6 +31,9 @@ struct bt_uhid { struct io *io; unsigned int notify_id; struct queue *notify_list; + struct queue *input; + bool created; + bool started; }; struct uhid_notify { @@ -48,6 +51,9 @@ static void uhid_free(struct bt_uhid *uhid) if (uhid->notify_list) queue_destroy(uhid->notify_list, free); + if (uhid->input) + queue_destroy(uhid->input, free); + free(uhid); } @@ -215,14 +221,11 @@ bool bt_uhid_unregister_all(struct bt_uhid *uhid) return true; } -int bt_uhid_send(struct bt_uhid *uhid, const struct uhid_event *ev) +static int uhid_send(struct bt_uhid *uhid, const struct uhid_event *ev) { ssize_t len; struct iovec iov; - if (!uhid->io) - return -ENOTCONN; - iov.iov_base = (void *) ev; iov.iov_len = sizeof(*ev); @@ -233,3 +236,126 @@ int bt_uhid_send(struct bt_uhid *uhid, const struct uhid_event *ev) /* uHID kernel driver does not handle partial writes */ return len != sizeof(*ev) ? -EIO : 0; } + +int bt_uhid_send(struct bt_uhid *uhid, const struct uhid_event *ev) +{ + if (!uhid->io) + return -ENOTCONN; + + /* Queue events if uhid has not been created yet */ + if (!uhid->started) { + if (!uhid->input) + uhid->input = queue_new(); + + queue_push_tail(uhid->input, util_memdup(&ev, sizeof(ev))); + return 0; + } + + return uhid_send(uhid, ev); +} + +static bool input_dequeue(const void *data, const void *match_data) +{ + struct uhid_event *ev = (void *)data; + struct bt_uhid *uhid = (void *)match_data; + + return bt_uhid_send(uhid, ev) == 0; +} + +static void uhid_start(struct uhid_event *ev, void *user_data) +{ + struct bt_uhid *uhid = user_data; + + uhid->started = true; + + /* dequeue input events send while UHID_CREATE2 was in progress */ + queue_remove_all(uhid->input, input_dequeue, uhid, free); +} + +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) +{ + struct uhid_event ev; + int err; + + if (!uhid || !name || rd_size > sizeof(ev.u.create2.rd_data)) + return -EINVAL; + + if (uhid->created) + return 0; + + memset(&ev, 0, sizeof(ev)); + ev.type = UHID_CREATE2; + strncpy((char *) ev.u.create2.name, name, + sizeof(ev.u.create2.name) - 1); + if (src) + sprintf((char *)ev.u.create2.phys, + "%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x", + src->b[5], src->b[4], src->b[3], src->b[2], src->b[1], + src->b[0]); + if (dst) + sprintf((char *)ev.u.create2.uniq, + "%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x", + dst->b[5], dst->b[4], dst->b[3], dst->b[2], dst->b[1], + dst->b[0]); + ev.u.create2.vendor = vendor; + ev.u.create2.product = product; + ev.u.create2.version = version; + ev.u.create2.country = country; + ev.u.create2.bus = BUS_BLUETOOTH; + if (rd_size) + memcpy(ev.u.create2.rd_data, rd_data, rd_size); + ev.u.create2.rd_size = rd_size; + + err = uhid_send(uhid, &ev); + if (err) + return err; + + bt_uhid_register(uhid, UHID_START, uhid_start, uhid); + + uhid->created = true; + uhid->started = false; + + return 0; +} + +bool bt_uhid_created(struct bt_uhid *uhid) +{ + if (!uhid) + return false; + + return uhid->created; +} + +bool bt_uhid_started(struct bt_uhid *uhid) +{ + if (!uhid) + return false; + + return uhid->started; +} + +int bt_uhid_destroy(struct bt_uhid *uhid) +{ + struct uhid_event ev; + int err; + + if (!uhid) + return -EINVAL; + + if (!uhid->created) + return 0; + + memset(&ev, 0, sizeof(ev)); + ev.type = UHID_DESTROY; + + err = bt_uhid_send(uhid, &ev); + if (err < 0) + return err; + + uhid->created = false; + + return err; +} diff --git a/src/shared/uhid.h b/src/shared/uhid.h index 55ae839f3017..8d5dfd6e45c9 100644 --- a/src/shared/uhid.h +++ b/src/shared/uhid.h @@ -11,6 +11,7 @@ #include #include #include +#include struct bt_uhid; @@ -29,3 +30,10 @@ bool bt_uhid_unregister(struct bt_uhid *uhid, unsigned int id); 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); +bool bt_uhid_created(struct bt_uhid *uhid); +bool bt_uhid_started(struct bt_uhid *uhid); +int bt_uhid_destroy(struct bt_uhid *uhid); From patchwork Fri Mar 8 22:10:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 778918 Received: from mail-ua1-f43.google.com (mail-ua1-f43.google.com [209.85.222.43]) (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 B7E6C249E5 for ; Fri, 8 Mar 2024 22:10:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709935816; cv=none; b=FLaPXVE8UoeiCnunv+qxXjPWxqOmzU0SbqZJ90zAHr5Pj/FnB2LY3vCUteCks9wevVWI2YSNlm/8c1wzdjA9y2TN7Fuo+EqJ9cy594TCq3pC0GBnn6wuDv+3vHZSCrf4JXxyZnAb4zSqfuCZTy9FFhXo1vCCqbpkFBJBZ8YmgdE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709935816; c=relaxed/simple; bh=edNdKBZ5plA0LT/YHTfTHpHqn0wn8LFQAWcVbM873n0=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DEOuKwJclHLhHP7JTwGpDOYdil3GbKasxFeyofztnMdpFl2jtDRprIsV2Cpwv+s9q2jzRiJfKcUSzXdcU3/jK9+rZyG5iSfNJeyrr+u/rIwbJcDBv7zyzHD7pYfQBq1H+oSI6mkyAt+ZT8VlfjxRHzjQmPus1/IsK5XvqRsZgK4= 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=mtujbaid; arc=none smtp.client-ip=209.85.222.43 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mtujbaid" Received: by mail-ua1-f43.google.com with SMTP id a1e0cc1a2514c-7db1a2c1f96so1639918241.0 for ; Fri, 08 Mar 2024 14:10:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709935812; x=1710540612; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=55wsVvcdOoB8HNtBp2fr9/iQJweKQFrRz4cdmpf3cwg=; b=mtujbaidncX5CMBc7eYebVUKLw6cInw+fh/4lIkUNd+daottg28TpTXJdl5KiV4MHI GJLtWoqtU29sC1OoupXmrEn5J2EDt3etlZxUvkAAj6N+RZBtuhv/Fh8+c/h4Gj46VfH7 FUnglWpd4WIAHHURCP5mMg1y5QChdU7UcPY4FoHGLySu8SNMXD+s0AmkTB8/kvDty0gu fqWcWhZehor0uYzKobF6Dy2Ez9bocqv20K1kSahX4C0ZFSbJva85G9LyOHyXSKwLBL4k GABJjZ/+rtS13mGz7PtqctlKEQvhk/7mpWaniAxPtgDaVUE++7Dc/sTogrTKb/Z1rZah 8a0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709935812; x=1710540612; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=55wsVvcdOoB8HNtBp2fr9/iQJweKQFrRz4cdmpf3cwg=; b=DgqyH7/IrGCxbiXYSVoCsjXyPKoezPwZeohrBoZE1wuPBXNhGAOorq58R833J8Mz1f f0bTG22cTZSstM0hUS4Iu4B2eY1kqH/7WfXBIH5ZYL8LPLGsVeR2Dl2RwhrlYvpV5bt0 5/2Hz+bC6SGsPdw94ctwgZUR/eqspO2UW1xyw1ZAWSgeRzY6uvewJK1RBHeBk/9OtWJ4 1+Bod3mC9RAmITN7rC/4vnC/4BBagX+JlxFPbGQbuTTiS865gcdLyukoXue8lmZlXOay gCPhG0vAjVzywaueNAK78zpF7VFgKXAMVt6kGlup5BONeqM/7wwT2n8JawxDt591fjmK ZA6Q== X-Gm-Message-State: AOJu0YxXlnBYByA2j4vaNY30PcU2p5JGvQgYXoZjv7lkZTeD1OKmBW8B 5AScoCQQxZjzSNpOCqOl9+KIRm/QF18ZL620W+TshKQ194gFA9A6Cw+xjt1+ X-Google-Smtp-Source: AGHT+IHiGQb2fXCVK6QF4O4ICdtcSW+7IhTmuWK94G7KwgUpNYCGCkVHae9icmCeFNIF/teLvM6DlQ== X-Received: by 2002:a05:6122:905:b0:4c9:2540:8520 with SMTP id j5-20020a056122090500b004c925408520mr812623vka.1.1709935812356; Fri, 08 Mar 2024 14:10:12 -0800 (PST) Received: from lvondent-mobl4.. (107-146-107-067.biz.spectrum.com. [107.146.107.67]) by smtp.gmail.com with ESMTPSA id el15-20020a056122278f00b004d33d93758asm29039vkb.23.2024.03.08.14.10.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Mar 2024 14:10:10 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v1 2/4] hog-lib: Use bt_uhid_create instead of UHID_CREATE2 Date: Fri, 8 Mar 2024 17:10:05 -0500 Message-ID: <20240308221007.250681-2-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240308221007.250681-1-luiz.dentz@gmail.com> References: <20240308221007.250681-1-luiz.dentz@gmail.com> Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Luiz Augusto von Dentz This makes use of bt_uhid_create instead of directly submitting UHID_CREATE2 since it can track UHID_START by itself. --- profiles/input/hog-lib.c | 78 +++++++--------------------------------- 1 file changed, 13 insertions(+), 65 deletions(-) diff --git a/profiles/input/hog-lib.c b/profiles/input/hog-lib.c index 67492a63eca3..ef3d6aa1b1eb 100644 --- a/profiles/input/hog-lib.c +++ b/profiles/input/hog-lib.c @@ -79,8 +79,6 @@ struct bt_hog { GSList *reports; struct bt_uhid *uhid; int uhid_fd; - bool uhid_created; - bool uhid_start; uint64_t uhid_flags; uint16_t bcdhid; uint8_t bcountrycode; @@ -360,15 +358,6 @@ static void report_value_cb(const guint8 *pdu, guint16 len, gpointer user_data) ev.u.input.size = len; } - /* If uhid had not sent UHID_START yet queue up the input */ - if (!hog->uhid_created || !hog->uhid_start) { - if (!hog->input) - hog->input = queue_new(); - - queue_push_tail(hog->input, util_memdup(&ev, sizeof(ev))); - return; - } - err = bt_uhid_send(hog->uhid, &ev); if (err < 0) error("bt_uhid_send: %s (%d)", strerror(-err), -err); @@ -851,7 +840,6 @@ static void start_flags(struct uhid_event *ev, void *user_data) { struct bt_hog *hog = user_data; - hog->uhid_start = true; hog->uhid_flags = ev->u.start.dev_flags; DBG("uHID device flags: 0x%16" PRIx64, hog->uhid_flags); @@ -1037,54 +1025,26 @@ static void uhid_create(struct bt_hog *hog, uint8_t *report_map, size_t report_map_len) { uint8_t *value = report_map; - struct uhid_event ev; size_t vlen = report_map_len; - int i, err; + int err; GError *gerr = NULL; - - if (vlen > sizeof(ev.u.create2.rd_data)) { - error("Report MAP too big: %zu > %zu", vlen, - sizeof(ev.u.create2.rd_data)); - return; - } - - /* create uHID device */ - memset(&ev, 0, sizeof(ev)); - ev.type = UHID_CREATE2; + bdaddr_t src, dst; bt_io_get(g_attrib_get_channel(hog->attrib), &gerr, - BT_IO_OPT_SOURCE, ev.u.create2.phys, - BT_IO_OPT_DEST, ev.u.create2.uniq, + BT_IO_OPT_SOURCE_BDADDR, &src, + BT_IO_OPT_DEST_BDADDR, &dst, BT_IO_OPT_INVALID); - if (gerr) { error("Failed to connection details: %s", gerr->message); g_error_free(gerr); return; } - /* Phys + uniq are the same size (hw address type) */ - for (i = 0; - i < (int)sizeof(ev.u.create2.phys) && ev.u.create2.phys[i] != 0; - ++i) { - ev.u.create2.phys[i] = tolower(ev.u.create2.phys[i]); - ev.u.create2.uniq[i] = tolower(ev.u.create2.uniq[i]); - } - - strncpy((char *) ev.u.create2.name, hog->name, - sizeof(ev.u.create2.name) - 1); - ev.u.create2.vendor = hog->vendor; - ev.u.create2.product = hog->product; - ev.u.create2.version = hog->version; - ev.u.create2.country = hog->bcountrycode; - ev.u.create2.bus = BUS_BLUETOOTH; - ev.u.create2.rd_size = vlen; - - memcpy(ev.u.create2.rd_data, value, vlen); - - err = bt_uhid_send(hog->uhid, &ev); + err = bt_uhid_create(hog->uhid, hog->name, &src, &dst, + hog->vendor, hog->product, hog->version, + hog->bcountrycode, value, vlen); if (err < 0) { - error("bt_uhid_send: %s", strerror(-err)); + error("bt_uhid_create: %s", strerror(-err)); return; } @@ -1093,9 +1053,6 @@ static void uhid_create(struct bt_hog *hog, uint8_t *report_map, bt_uhid_register(hog->uhid, UHID_GET_REPORT, get_report, hog); bt_uhid_register(hog->uhid, UHID_SET_REPORT, set_report, hog); - hog->uhid_created = true; - hog->uhid_start = false; - DBG("HoG created uHID device"); } @@ -1146,7 +1103,8 @@ static void read_report_map(struct bt_hog *hog) { uint16_t handle; - if (!hog->report_map_attr || hog->uhid_created || hog->report_map_id) + if (!hog->report_map_attr || bt_uhid_created(hog->uhid) || + hog->report_map_id) return; handle = gatt_db_attribute_get_handle(hog->report_map_attr); @@ -1312,24 +1270,14 @@ static bool cancel_gatt_req(const void *data, const void *user_data) static void uhid_destroy(struct bt_hog *hog) { int err; - struct uhid_event ev; - - if (!hog->uhid_created) - return; bt_uhid_unregister_all(hog->uhid); - memset(&ev, 0, sizeof(ev)); - ev.type = UHID_DESTROY; - - err = bt_uhid_send(hog->uhid, &ev); - + err = bt_uhid_destroy(hog->uhid); if (err < 0) { error("bt_uhid_send: %s", strerror(-err)); return; } - - hog->uhid_created = false; } static void hog_free(void *data) @@ -1810,7 +1758,7 @@ bool bt_hog_attach(struct bt_hog *hog, void *gatt) bt_hog_attach(instance, gatt); } - if (!hog->uhid_created) { + if (!bt_uhid_created(hog->uhid)) { DBG("HoG discovering characteristics"); if (hog->attr) gatt_db_service_foreach_char(hog->attr, @@ -1822,7 +1770,7 @@ bool bt_hog_attach(struct bt_hog *hog, void *gatt) char_discovered_cb, hog); } - if (!hog->uhid_created) + if (!bt_uhid_created(hog->uhid)) return true; /* If UHID is already created, set up the report value handlers to From patchwork Fri Mar 8 22:10:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 779221 Received: from mail-ua1-f48.google.com (mail-ua1-f48.google.com [209.85.222.48]) (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 012F85FDB3 for ; Fri, 8 Mar 2024 22:10:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709935818; cv=none; b=JrF4p08Jh9kf7xiG5ir8HNsXiA46VSgiJSleMDZaMCNX+hwItJR/Mnipv0gMruDMu1pt9biLXwmbBCmAbrGSzuMhapk/oTbgZKclsBTPS/ndgkEs9CTVMhuKrN2rIfbWnc4/gfkwN+cZHsehJbCep1Xlr6w3/Cn0eSHVvms44YY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709935818; c=relaxed/simple; bh=28iptPzQ8GM/Czk49i40kS2ksA0YKipUYYgpTO5/15I=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ccNyhl+mXeDG+th8hmLKOOJMIBUpqce/mM2zUm2TXz/qYI+VmeMVEYkNfSEzQM5f3j0GN6nYvCFDjq6S+QQNlbN/7uRic4NC2Vcn/UIvbLiZLcozFkZkukT1CxCIbyF775h0UYQQ+WBfH7LERsE2DY1GVq8HS2JhMaI1VtDmEi8= 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=R/8MRtaH; arc=none smtp.client-ip=209.85.222.48 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="R/8MRtaH" Received: by mail-ua1-f48.google.com with SMTP id a1e0cc1a2514c-7db1a2c1f96so1639947241.0 for ; Fri, 08 Mar 2024 14:10:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709935815; x=1710540615; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=KuefABokbSsjxTGPqgZ0gA9y3X9yGv7eqCAtxoixHko=; b=R/8MRtaHnsR1zKf2tDPFrx7fQeqkxuQ66oBWEbC0PLMTDxdGHcDoJ/W4Hiq/aLNQSN ZfE+5B08aNwYnNaIDfPTsIdYnA5NVidEj0eJBgs7hccgM1C25mdJ+Z6mk/VXJ0po3yOQ ym7YdyYZYaqloFjt22ovfGx4/tvXceJViBY+fqn86F4sddB3TIkENIg/KBAX/d+khK3X p2x4YtJKkH10MkFzNOwPxFu8lwFgiy0+Uegx4LRNsDm2V09HLqAkrawhdKFymnzhUZfV Cb8BbPz8Xcmb/uUMXOJveruuO5mMe+xsnhirJYRdrNQVHphQkkc0ik+erslM2ZFZKXVx SVSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709935815; x=1710540615; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KuefABokbSsjxTGPqgZ0gA9y3X9yGv7eqCAtxoixHko=; b=FFmB67zQ8fDNSCgw+w7IBcuFFUU6xv+E+O/qDt7TGrWSbCeED8eWmMgH4OT8Bjq76x EW6I8BwnRHGAkw65bEY8C9MJ0rq9Ploa+v0xQzfZaA2fdwJUuzdGo9UsFF4Ep6tyVsy/ /m+pxDEE2i8KJNAeUv0NA0hmTH5bsbnmWstUdKHeKuaGQR+cVbut8NpQvDyU7JvxFYLl LoRNy1Gcr3nP+OTKDtHZ/Uyg74OzRtP/qdJfTZF8shMO9I0NmkvZ8eSwF7m/aSNnkd8d Rfnvcx4JUm0xVuoAmX8dbHVDS024yiG/xHH1o0s95V12vJTQNieEe53MbxawhMp62pyL Zmpg== X-Gm-Message-State: AOJu0YxF1GNsNf/cHgxwrU5El1e5z9sVTCXnprAbWxAHvw5NuL+4tkjc GtRv4IfwpA7jH2aWVUnYaNQynddh6TMzIim5y6ctrH1c/V039/sVd0FpeRQh X-Google-Smtp-Source: AGHT+IGTqSl/1IUs9ZjDlSYAJf/GB0klKfz7w1M+iHof6oNPXK3wR0ZfJlsYI5qfeCB6U6REQ1gYzQ== X-Received: by 2002:a05:6122:905:b0:4c9:2540:8520 with SMTP id j5-20020a056122090500b004c925408520mr812720vka.1.1709935814764; Fri, 08 Mar 2024 14:10:14 -0800 (PST) Received: from lvondent-mobl4.. (107-146-107-067.biz.spectrum.com. [107.146.107.67]) by smtp.gmail.com with ESMTPSA id el15-20020a056122278f00b004d33d93758asm29039vkb.23.2024.03.08.14.10.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Mar 2024 14:10:13 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v1 3/4] input: Use bt_uhid_create instead of UHID_CREATE Date: Fri, 8 Mar 2024 17:10:06 -0500 Message-ID: <20240308221007.250681-3-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240308221007.250681-1-luiz.dentz@gmail.com> References: <20240308221007.250681-1-luiz.dentz@gmail.com> Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Luiz Augusto von Dentz This makes use of bt_uhid_create instead of directly submitting UHID_CREATE since it can track UHID_START by itself. Fixes: https://github.com/bluez/bluez/issues/771 --- profiles/input/device.c | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/profiles/input/device.c b/profiles/input/device.c index 0d32b705bd00..d5b7d6728c88 100644 --- a/profiles/input/device.c +++ b/profiles/input/device.c @@ -941,28 +941,15 @@ static int ioctl_disconnect(struct input_device *idev, uint32_t flags) static int uhid_connadd(struct input_device *idev, struct hidp_connadd_req *req) { int err; - struct uhid_event ev; if (idev->uhid_created) return 0; - /* create uHID device */ - memset(&ev, 0, sizeof(ev)); - ev.type = UHID_CREATE; - strncpy((char *) ev.u.create.name, req->name, sizeof(ev.u.create.name)); - ba2strlc(&idev->src, (char *) ev.u.create.phys); - ba2strlc(&idev->dst, (char *) ev.u.create.uniq); - ev.u.create.vendor = req->vendor; - ev.u.create.product = req->product; - ev.u.create.version = req->version; - ev.u.create.country = req->country; - ev.u.create.bus = BUS_BLUETOOTH; - ev.u.create.rd_data = req->rd_data; - ev.u.create.rd_size = req->rd_size; - - err = bt_uhid_send(idev->uhid, &ev); + 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); if (err < 0) { - error("bt_uhid_send: %s", strerror(-err)); + error("bt_uhid_create: %s", strerror(-err)); return err; } From patchwork Fri Mar 8 22:10:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 778917 Received: from mail-vk1-f177.google.com (mail-vk1-f177.google.com [209.85.221.177]) (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 1A19324B5B for ; Fri, 8 Mar 2024 22:10:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709935820; cv=none; b=BCC3qEQ7Bn2S4fj8sEtPk7mwSBSUp0i5MQcQ3E9Z/7hdZGEuHWYYjpb8ViDF9sHvwOz1MkDICl9OreQ798xjSbhSUR92Y8QGQQD1GlQk0zYHpUKhjdpV6UsB86n71e0zOgyb9DaQVDqX4JzKSt2+98nQVN2p9sb0ict1kRGInDY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709935820; c=relaxed/simple; bh=j9bz+SgudFucVmm8NF9NFnS2fUl7HcnE5Kb1otyXLso=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=D8xP3Sjvgte5rogHjFy/WPVzjeEc3dOdP9GA4Gw7nma7FwTTGpVluLm2174TRFKrnLVtgUCSPmdxTLlafoIvwqiU7pJiFzUPtQ+Ul4FpakWIuvcXt9h6kSgm+B+k0RnhDkN6mZ2Vd7RJwLhtxcHPcWifhncJWBBL3y0/pt+qN+o= 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=Fl8eaK6k; arc=none smtp.client-ip=209.85.221.177 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Fl8eaK6k" Received: by mail-vk1-f177.google.com with SMTP id 71dfb90a1353d-4d34fbbd91eso811844e0c.2 for ; Fri, 08 Mar 2024 14:10:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709935817; x=1710540617; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=ac+TOeNfDBn3AAxKk7pgLTj6atTlKNmnyNll3+p4OJA=; b=Fl8eaK6kExWxK4vxLMX8ffqtrQKtSyJBZKK2RhpdHUycnjlMD6Awo7ZYEhSlS+Q81f BUBCK2Twf3aeMvki1ORcH3RLdfD3QAgQblU/vW5YZEAKVV9xBIrEkErYmlyzgMYJSiop /+C4Wik5BEtNkGHHK0G7L7AGpYNzKZu7Z2Hxo726+iEue5imH0ZrKMUfnACL853gVkji CkrUkxgc0mSQ3jlNjc8sTNYoNibr69oRsn1iGBwy8/lCvvsBQX4Ih2CZQeSCYtWIv5rh /Q8a2vIm4cbAjY+eeiiPWKWUXqRiJv+cJ4jMGZ37MQI+213D+HeXYjfCsNWts3cm/Hc9 km6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709935817; x=1710540617; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ac+TOeNfDBn3AAxKk7pgLTj6atTlKNmnyNll3+p4OJA=; b=YRFdIzvT5K/yS7aZ+8tMqqmH6jBvOgujtCUeYhf7kcP1KiM54xVj5O3L0r9XSf1ddp fV2ToA/P7VXamvuZNVROB2gAdiAlzmrgfBH4kEW2yj5ml4Z3zBIrdzp6jp0bFAjIG5SP 98fR6LvAKwYTRXM7T2hIh7QrkNKG3Ku6lWzptrPuZABCJrjpuVMrSUET4v+tfCAQ9ucs R633yz6UVdHr1FSjWH1ojZWptZrsqarTspQIA/m+ox4+mtPE6PpXoY2yFpaiavjnbTEY gwJ7ix8Ty2NaURD+JW1oxMxUU0y2PbP8bISyCzXdaSVW3OoEv+ecsipxmyF/+MghfgE/ W5pg== X-Gm-Message-State: AOJu0YzRY5+UphWERpMHKzMUA67+5Yzqq7Qas0M6QEvIedSTcKtT73gR ThTKOEFy3YgK23y3KsQrOPsaepquUbe0Yrq4m26pxREXsjKswVwTGyhy7A/C X-Google-Smtp-Source: AGHT+IG1C/QPtGYNmIiLPmoWuzzLw+EMpHGOV9A6PLigZMTSF3ZqsKqG+8E+2SV5A3WpCL9aJjpYdw== X-Received: by 2002:a05:6122:4e8f:b0:4d3:3a8c:13ad with SMTP id gf15-20020a0561224e8f00b004d33a8c13admr717854vkb.8.1709935817322; Fri, 08 Mar 2024 14:10:17 -0800 (PST) Received: from lvondent-mobl4.. (107-146-107-067.biz.spectrum.com. [107.146.107.67]) by smtp.gmail.com with ESMTPSA id el15-20020a056122278f00b004d33d93758asm29039vkb.23.2024.03.08.14.10.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Mar 2024 14:10:15 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v1 4/4] test-uhid: Test bt_uhid_create and bt_uhid_destroy Date: Fri, 8 Mar 2024 17:10:07 -0500 Message-ID: <20240308221007.250681-4-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240308221007.250681-1-luiz.dentz@gmail.com> References: <20240308221007.250681-1-luiz.dentz@gmail.com> Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Luiz Augusto von Dentz This test bt_uhid_create and bt_uhid_destroy instead of directly submitting UHID_CREATE and UHID_DESTROY. --- unit/test-uhid.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/unit/test-uhid.c b/unit/test-uhid.c index 8a8eef855bc5..f2f9cda097af 100644 --- a/unit/test-uhid.c +++ b/unit/test-uhid.c @@ -228,19 +228,31 @@ static const struct uhid_event ev_feature = { static void test_client(gconstpointer data) { struct context *context = create_context(data); + int err; - if (g_str_equal(context->data->test_name, "/uhid/command/create")) - bt_uhid_send(context->uhid, &ev_create); + err = bt_uhid_create(context->uhid, "", NULL, NULL, 0, 0, 0, 0, NULL, + 0); + if (err < 0) + tester_test_failed(); - if (g_str_equal(context->data->test_name, "/uhid/command/destroy")) - bt_uhid_send(context->uhid, &ev_destroy); + if (g_str_equal(context->data->test_name, "/uhid/command/destroy")) { + err = bt_uhid_destroy(context->uhid); + if (err < 0) + tester_test_failed(); + } if (g_str_equal(context->data->test_name, - "/uhid/command/feature_answer")) - bt_uhid_send(context->uhid, &ev_feature_answer); + "/uhid/command/feature_answer")) { + err = bt_uhid_send(context->uhid, &ev_feature_answer); + if (err < 0) + tester_test_failed(); + } - if (g_str_equal(context->data->test_name, "/uhid/command/input")) - bt_uhid_send(context->uhid, &ev_input); + if (g_str_equal(context->data->test_name, "/uhid/command/input")) { + err = bt_uhid_send(context->uhid, &ev_input); + if (err < 0) + tester_test_failed(); + } context_quit(context); }