From patchwork Fri Jan 22 00:13:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sonny Sasaka X-Patchwork-Id: 12038047 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DF45EC433E0 for ; Fri, 22 Jan 2021 00:14:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B48D723A53 for ; Fri, 22 Jan 2021 00:14:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726222AbhAVAOc (ORCPT ); Thu, 21 Jan 2021 19:14:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725868AbhAVAOV (ORCPT ); Thu, 21 Jan 2021 19:14:21 -0500 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F37A3C0613D6 for ; Thu, 21 Jan 2021 16:13:40 -0800 (PST) Received: by mail-pl1-x630.google.com with SMTP id g3so2258746plp.2 for ; Thu, 21 Jan 2021 16:13:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=3nnF+bkgtjz25uaf0FNhzS1otuiCUw75IC3zjjwwTtA=; b=bpWQKD+UXxBwSgv3lf2TKYmhZF9IHnWZI4BVzjS7M6V0umMcNcee0I+XPoKQnRS0KD D+UH1gOMCV7XPEbeSr3FfYP+qYhLiwP4zKSXiFxPqWzzxmYBzNUo4XDoI1Vp/BcwJbwr zG7lbjQclOEreobob8o0ntIYlsjVPX7Strd+0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=3nnF+bkgtjz25uaf0FNhzS1otuiCUw75IC3zjjwwTtA=; b=DFVsIX2Us50pRGSBEBBnq+ADxMyLacjsKPtUlghDiSwQzJ1fBX+xrLUqrJpk/RM3LA 0xnZydbXJ2Inwe8VCvxugdmHGRiECOT/Iwit9PQyu8VANsPucJjyApnhJHpz01MXvjKf At3WcuKvElxkLr0N5hjIHB9fRvQFD8CmHlT6Abr9HIQpru2lHtw44IZsNYCfMCcn1GPO yy076HRu7+c0lKx0n5mUgEGrtHwrVMuatDUiMVjnYdO2kIE9BAbucblZu1S7BulPLRfs Bn1v0H13pAWAubC9RuKMTBiMuB1XRdGvkSNkdIibovsJ2T/C9JQhsJcG9e9Kc+Ur9cJY nIzw== X-Gm-Message-State: AOAM532ZBAelyNp/EJvajNe+ABtcJQdYyTWsIvjOlIEwDP3DkHnry+I6 HXh4BZxwSwPh6aMQiL46bu3eYS/xz0VBzw== X-Google-Smtp-Source: ABdhPJwOLecPTgoWzp4+RsorSQVE8vUorN3Be1pHAJBN9cXSpy9YSU7Eq7eii9tThnH+kb7BqNDxvg== X-Received: by 2002:a17:90a:4314:: with SMTP id q20mr2209139pjg.87.1611274420230; Thu, 21 Jan 2021 16:13:40 -0800 (PST) Received: from sonnysasaka-chrome.mtv.corp.google.com ([2620:15c:202:201:4a0f:cfff:fe66:e60c]) by smtp.gmail.com with ESMTPSA id b13sm6941900pfi.162.2021.01.21.16.13.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Jan 2021 16:13:39 -0800 (PST) From: Sonny Sasaka To: linux-bluetooth@vger.kernel.org Cc: Sonny Sasaka Subject: [PATCH BlueZ v2 1/2] input/hog: Fix double registering report value callbacks Date: Thu, 21 Jan 2021 16:13:25 -0800 Message-Id: <20210122001326.14263-1-sonnysasaka@chromium.org> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org In commit 23b69ab3e484 ("input/hog: Cache the HID report map"), we optimized HOG reconnection by registering report value callbacks early, but there was a bug where we also re-register the same report value callbacks after at CCC write callback. We should handle this case by avoiding the second callback register if we know we have done it earlier. --- profiles/input/hog-lib.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/profiles/input/hog-lib.c b/profiles/input/hog-lib.c index 1f132aa4c..089f42826 100644 --- a/profiles/input/hog-lib.c +++ b/profiles/input/hog-lib.c @@ -80,6 +80,7 @@ struct bt_hog { struct bt_uhid *uhid; int uhid_fd; bool uhid_created; + bool report_value_cb_registered; gboolean has_report_id; uint16_t bcdhid; uint8_t bcountrycode; @@ -336,6 +337,13 @@ static void report_ccc_written_cb(guint8 status, const guint8 *pdu, return; } + /* If we already had the report map cache, we must have registered UHID + * and the report value callbacks. In that case, don't re-register the + * report value callbacks here. + */ + if (hog->report_value_cb_registered) + return; + report->notifyid = g_attrib_register(hog->attrib, ATT_OP_HANDLE_NOTIFY, report->value_handle, @@ -1703,6 +1711,8 @@ bool bt_hog_attach(struct bt_hog *hog, void *gatt) report_value_cb, r, NULL); } + hog->report_value_cb_registered = true; + return true; } @@ -1753,6 +1763,8 @@ void bt_hog_detach(struct bt_hog *hog) } } + hog->report_value_cb_registered = false; + if (hog->scpp) bt_scpp_detach(hog->scpp); From patchwork Fri Jan 22 00:13:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sonny Sasaka X-Patchwork-Id: 12038049 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C216DC433DB for ; Fri, 22 Jan 2021 00:15:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8F8A323A53 for ; Fri, 22 Jan 2021 00:15:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726094AbhAVAO6 (ORCPT ); Thu, 21 Jan 2021 19:14:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37676 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725868AbhAVAOo (ORCPT ); Thu, 21 Jan 2021 19:14:44 -0500 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BBCA5C061756 for ; Thu, 21 Jan 2021 16:14:04 -0800 (PST) Received: by mail-pl1-x62f.google.com with SMTP id u11so2213372plg.13 for ; Thu, 21 Jan 2021 16:14:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=aTK20JXNui2K+RAm+4b/YyNZYouO/7e0ncNZ2MlMaX0=; b=RBDedLT8uNz/UeL20Jf8KcnnI47Zhi1rdjNtGPPFDUT/eXxRnwH8oVlZPwgE8Yh5Re KZkOIhNzDD+8bM1K6OELfy0wg0UmJRugJbECS9NZTBqU5ALNgJjqs1tPft7mht3CmfaF lSEhZvuqy/dOY9jY93/CiOs0KUUyCNVGoMwJM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=aTK20JXNui2K+RAm+4b/YyNZYouO/7e0ncNZ2MlMaX0=; b=rEiILZUfrKUBmOtCkgPLFEZZSYozqybjcL4WgGz5NfiC1BGrjUNBznvY2tlZkUsbs3 oU5XF5SZTvQpMFBCTfWYVTdvTWviAdzHAEpTiM8TAAaEzD1Nn52ZDMMPdQXQLLpl14kX /4sqlX9NQsLULMyo49+3y4NjNEhsa6dB4kQHCm6NWHz+7vskdcCQzTeaRPr6exdlLoS7 jeqbC9KhmzymaraMTR1XVo9N4/S5oLshhNVAAuhChxsyJN8UAmbsi7JWa2q1AyOrjFkW MYJyKkTspyQrjeXF93Pdlma+4ISF7FoEGddePw7fR/JXGXrskHcIuTyLM7eEqdgoL4Ih eaCA== X-Gm-Message-State: AOAM5322FRNRy36PJMGMNnH7ZNQYYuVx8Ou7PjHOOj78xzrbqsCdT4SW WYzURc/30+P0jHlwCa0mm0Ylg2Z8/dqaGQ== X-Google-Smtp-Source: ABdhPJyrn2Gg7o+kJfDmq8HanyNHQAECgM0PHSXzo22x7WXqs97Z5yR/LAiewLDWBQdk42PX1++fFA== X-Received: by 2002:a17:902:9a86:b029:dc:104:1902 with SMTP id w6-20020a1709029a86b02900dc01041902mr2344622plp.50.1611274444044; Thu, 21 Jan 2021 16:14:04 -0800 (PST) Received: from sonnysasaka-chrome.mtv.corp.google.com ([2620:15c:202:201:4a0f:cfff:fe66:e60c]) by smtp.gmail.com with ESMTPSA id b13sm6941900pfi.162.2021.01.21.16.14.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Jan 2021 16:14:03 -0800 (PST) From: Sonny Sasaka To: linux-bluetooth@vger.kernel.org Cc: Sonny Sasaka Subject: [PATCH BlueZ v2 2/2] input/hog: Do not create UHID if report map is broken Date: Thu, 21 Jan 2021 16:13:26 -0800 Message-Id: <20210122001326.14263-2-sonnysasaka@chromium.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210122001326.14263-1-sonnysasaka@chromium.org> References: <20210122001326.14263-1-sonnysasaka@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org The report map in the cache could be dirty, for example when reading a report map from peer was cancelled, we should be able to detect it and not try to create UHID. Instead we will read it again from the peer. --- profiles/input/hog-lib.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/profiles/input/hog-lib.c b/profiles/input/hog-lib.c index 089f42826..d6a3bda4d 100644 --- a/profiles/input/hog-lib.c +++ b/profiles/input/hog-lib.c @@ -946,7 +946,7 @@ static void uhid_create(struct bt_hog *hog, uint8_t *report_map, struct uhid_event ev; ssize_t vlen = report_map_len; char itemstr[20]; /* 5x3 (data) + 4 (continuation) + 1 (null) */ - int i, err; + int i, err, collection_depth = 0; GError *gerr = NULL; DBG("Report MAP:"); @@ -960,6 +960,14 @@ static void uhid_create(struct bt_hog *hog, uint8_t *report_map, if (!long_item && (value[i] & 0xfc) == 0x84) hog->has_report_id = TRUE; + // Start Collection + if (value[i] == 0xa1) + collection_depth++; + + // End Collection + if (value[i] == 0xc0) + collection_depth--; + DBG("\t%s", item2string(itemstr, &value[i], ilen)); i += ilen; @@ -968,10 +976,15 @@ static void uhid_create(struct bt_hog *hog, uint8_t *report_map, /* Just print remaining items at once and break */ DBG("\t%s", item2string(itemstr, &value[i], vlen - i)); - break; + return; } } + if (collection_depth != 0) { + error("Report Map error: unbalanced collection"); + return; + } + /* create uHID device */ memset(&ev, 0, sizeof(ev)); ev.type = UHID_CREATE; @@ -1365,7 +1378,9 @@ static void foreach_hog_chrc(struct gatt_db_attribute *attr, void *user_data) * UHID to optimize reconnection. */ uhid_create(hog, report_map.value, report_map.length); - } else { + } + + if (!hog->uhid_created) { read_char(hog, hog->attrib, value_handle, report_map_read_cb, hog); }