Received: by 2002:ab2:3319:0:b0:1ef:7a0f:c32d with SMTP id i25csp864917lqc; Fri, 8 Mar 2024 14:11:29 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVJwDen6meV9VrRJPEewpKEKfZH8jjLxpgaGK4LKLTXUpYSy6U3W8V/HLBx2KI62r/Oxr1eTleKUIxQY/XJRblu76nlAbNfOwmFvWdlMg== X-Google-Smtp-Source: AGHT+IELvow0kkDyMg/Ajt1JOTXlaEIuWwIEr4JjHp10+O2pPc1C0Pf3T4BN1sNziSi4KxPsOssn X-Received: by 2002:a17:902:a611:b0:1dd:1c6f:af45 with SMTP id u17-20020a170902a61100b001dd1c6faf45mr373363plq.63.1709935889676; Fri, 08 Mar 2024 14:11:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709935889; cv=pass; d=google.com; s=arc-20160816; b=uU8hUGCA8Je8W/gCRcbTjV/1r1wvj7/Te5T9lXVc0U71/DfmghEkBP1JQN3a3GvfnI SbaUYF8e87ZzcGDZ0Wwi+QP18sZ7tsYdV7YoqqWKlspel4w+nAg63PCbzQe8I8o7HSag gwOGCs5vP2Mjpbn8aPJSQwZfjXMN2gC6QmnpmIpeIF4YkOXODVECZJUwNZvp3Ma07OP5 sCWL9nm8999nP3GKExFz2UGT38iSOo4XpZVX8BwxeWTTbTtMaMXbvXntg6iX9cg1x192 yUF28eozOSf4fCZ5EkBYWNlipLaQJc7YiLXmGSVAhBnDTl+ZfSUTTbtB1EqTFwdl5ddR cX8A== 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:references:in-reply-to:message-id :date:subject:to:from:dkim-signature; bh=55wsVvcdOoB8HNtBp2fr9/iQJweKQFrRz4cdmpf3cwg=; fh=4lGQI6056MBa4/oovMyIYaKLn+Wz/24RGvUivMmQP8E=; b=WvCAXNRzvmr+8FDEXOlD6NwzqPkuxV99nbPRGcCCoUU/L4eiFXWYjxuNstyxWOCDc1 kN5XNt7Yw7F9r/S6ZLyWC0qaFD67WBZT1oyoao8lYsBHFQupAUfdFrUz96u0XP31U+/o QCwCudpT3hkmOx+8uBkILAG1HR9Skpr/kIQMa5HRgNrW2x4l2pjsSr+a38bZhQKhqOju AvF8/eliE1CPMbF7GXDWJtDw6U+xpl7MsAWO93jy5IA48dem88L1g2LR52iBggWkScna KQYuVALFTISbwb7vtjEMUOs27+5hEojoKbAWrVdeG2rpjouT1lNrQX7psFgud3iJn24/ oMZw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=mtujbaid; 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-2394-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-2394-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id e16-20020a17090301d000b001dc07b8d0a9si271913plh.109.2024.03.08.14.11.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Mar 2024 14:11:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-bluetooth+bounces-2394-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=mtujbaid; 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-2394-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-2394-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 1BB70B21CE7 for ; Fri, 8 Mar 2024 22:10:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EF4F05FDB2; Fri, 8 Mar 2024 22:10:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mtujbaid" X-Original-To: linux-bluetooth@vger.kernel.org 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 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-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 Content-Transfer-Encoding: 8bit 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 -- 2.43.0