From patchwork Fri Jul 28 05:31:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Mikuda X-Patchwork-Id: 13331214 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5CCCFC001DE for ; Fri, 28 Jul 2023 05:32:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233290AbjG1FcA (ORCPT ); Fri, 28 Jul 2023 01:32:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233029AbjG1Fb6 (ORCPT ); Fri, 28 Jul 2023 01:31:58 -0400 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B59DF3580 for ; Thu, 27 Jul 2023 22:31:57 -0700 (PDT) Received: by mail-ej1-x632.google.com with SMTP id a640c23a62f3a-99bed101b70so43951866b.3 for ; Thu, 27 Jul 2023 22:31:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=streamunlimited.com; s=google; t=1690522316; x=1691127116; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=q2IxCT8vJ1aWH/MtmgyRtIThU0CLjE0BMARfQcpenh0=; b=u+BXY+sQfSekC8fkizp1jKP8hIFDqskvlOzziRYARxK0cphl+mzyyca8OAurwP8Gr3 ZLE9oLHsAmHSiE696Ywqr48jTW4M58lieHbgoSxaJPm/67Tx0OgHfvubjtFZALx4nvz4 Tn8VjwoW7J7Bw+z4r3HQdhEv50gEgMLwT2OBQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690522316; x=1691127116; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=q2IxCT8vJ1aWH/MtmgyRtIThU0CLjE0BMARfQcpenh0=; b=HvXJaXHvtKMqGKEmz7WSovdhfI5ooLYQxEFB4FxW8GHXlro07zEUFqY9K8FBy+lt/g xmuFDqtryqv9zlIf4XDFW5ZFsMR2ErC+FTwQYagiAp+puDmhCU5nT7rcI+XM4VXhE6gz xheA1Vl3Y+qWEcrMLJKKSYxJsL2twdXYj95pH3o95oswzXZuWZx2MuaRrbmeIGoSZ3ee l2Y8V+JaGQdOP6WkewCjIcXc/grq81/muGlfjjzXpPLJZqPJUvaH9sjOh73v4yWhBMOe juUfIPhj/1Fsg36fKbGM1J0/xwgltZ+GysOOoj8dVCxI/19g5bcXEkVjo0Z+atwoVtgX 9YUQ== X-Gm-Message-State: ABy/qLaeZRLePyIllzAuKP5MTiuusgB75m61hz+vo0FN8kmjnVbbI4zz ZwtPN1w3nY1CKrxTDMCHDOi9b4E+r76emOrfQ1s= X-Google-Smtp-Source: APBJJlHW4B6VyGe/eMZfmQuVbUbm2aFT7Nfqn0ekVOjQ8XYgvQolbAmIlhOeWkDGDFz46VnRKbVZEw== X-Received: by 2002:a17:906:209:b0:99b:d168:41e5 with SMTP id 9-20020a170906020900b0099bd16841e5mr1285286ejd.54.1690522315893; Thu, 27 Jul 2023 22:31:55 -0700 (PDT) Received: from smi-ubuntu.sueba ([2a01:390:0:101:353d:c2fa:e0df:3251]) by smtp.gmail.com with ESMTPSA id oq26-20020a170906cc9a00b009888aa1da11sm1590113ejb.188.2023.07.27.22.31.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 22:31:55 -0700 (PDT) From: Simon Mikuda To: linux-bluetooth@vger.kernel.org Cc: Simon Mikuda Subject: [PATCH BlueZ 1/5] device: Refactor device_discover_services function Date: Fri, 28 Jul 2023 07:31:49 +0200 Message-Id: <20230728053153.584222-2-simon.mikuda@streamunlimited.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230728053153.584222-1-simon.mikuda@streamunlimited.com> References: <20230728053153.584222-1-simon.mikuda@streamunlimited.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org After refactoring we can reuse function once more in function void device_bonding_complete(...) --- profiles/input/server.c | 2 +- src/adapter.c | 2 +- src/device.c | 24 +++++++----------------- src/device.h | 3 ++- 4 files changed, 11 insertions(+), 20 deletions(-) diff --git a/profiles/input/server.c b/profiles/input/server.c index 79cf08a66..12912cae6 100644 --- a/profiles/input/server.c +++ b/profiles/input/server.c @@ -102,7 +102,7 @@ static void sixaxis_browse_sdp(const bdaddr_t *src, const bdaddr_t *dst, data->psm = psm; if (psm == L2CAP_PSM_HIDP_CTRL) - device_discover_services(device); + device_discover_services(device, BDADDR_BREDR, NULL); device_wait_for_svc_complete(device, sixaxis_sdp_cb, data); } diff --git a/src/adapter.c b/src/adapter.c index 2679d4302..b77d90c7b 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -3637,7 +3637,7 @@ static void device_connect_cb(GIOChannel *io, GError *gerr, gpointer user_data) device_attach_att(device, io); } - device_discover_services(device); + device_discover_services(device, data->dst_type, NULL); device_wait_for_svc_complete(device, device_browse_cb, NULL); g_io_channel_unref(io); diff --git a/src/device.c b/src/device.c index b43ced8b5..82740216d 100644 --- a/src/device.c +++ b/src/device.c @@ -2446,10 +2446,7 @@ static DBusMessage *connect_profiles(struct btd_device *dev, uint8_t bdaddr_type resolve_services: DBG("Resolving services for %s", dev->path); - if (bdaddr_type == BDADDR_BREDR) - err = device_browse_sdp(dev, msg); - else - err = device_browse_gatt(dev, msg); + err = device_discover_services(dev, bdaddr_type, msg); if (err < 0) { return btd_error_failed(msg, bdaddr_type == BDADDR_BREDR ? ERR_BREDR_CONN_SDP_SEARCH : ERR_LE_CONN_GATT_BROWSE); @@ -5873,14 +5870,15 @@ static int device_browse_sdp(struct btd_device *device, DBusMessage *msg) return err; } -int device_discover_services(struct btd_device *device) +int device_discover_services(struct btd_device *device, + uint8_t bdaddr_type, DBusMessage *msg) { int err; - if (device->bredr) - err = device_browse_sdp(device, NULL); + if (bdaddr_type == BDADDR_BREDR) + err = device_browse_sdp(device, msg); else - err = device_browse_gatt(device, NULL); + err = device_browse_gatt(device, msg); if (err == 0 && device->discov_timer) { timeout_remove(device->discov_timer); @@ -6353,15 +6351,7 @@ void device_bonding_complete(struct btd_device *device, uint8_t bdaddr_type, DBG("Proceeding with service discovery"); /* If we are initiators remove any discovery timer and just * start discovering services directly */ - if (device->discov_timer) { - timeout_remove(device->discov_timer); - device->discov_timer = 0; - } - - if (bdaddr_type == BDADDR_BREDR) - device_browse_sdp(device, bonding->msg); - else - device_browse_gatt(device, bonding->msg); + device_discover_services(device, bdaddr_type, bonding->msg); bonding_request_free(bonding); } else if (!state->svc_resolved) { diff --git a/src/device.h b/src/device.h index 3252e14ef..0393478df 100644 --- a/src/device.h +++ b/src/device.h @@ -176,7 +176,8 @@ bool device_remove_svc_complete_callback(struct btd_device *dev, struct btd_service *btd_device_get_service(struct btd_device *dev, const char *remote_uuid); -int device_discover_services(struct btd_device *device); +int device_discover_services(struct btd_device *device, + uint8_t bdaddr_type, DBusMessage *msg); int btd_device_connect_services(struct btd_device *dev, GSList *services); uint32_t btd_device_get_current_flags(struct btd_device *dev); From patchwork Fri Jul 28 05:31:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Mikuda X-Patchwork-Id: 13331215 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2B40DC001E0 for ; Fri, 28 Jul 2023 05:32:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233337AbjG1FcB (ORCPT ); Fri, 28 Jul 2023 01:32:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233226AbjG1Fb7 (ORCPT ); Fri, 28 Jul 2023 01:31:59 -0400 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 034D43582 for ; Thu, 27 Jul 2023 22:31:58 -0700 (PDT) Received: by mail-ed1-x533.google.com with SMTP id 4fb4d7f45d1cf-51a52a7d859so6260946a12.0 for ; Thu, 27 Jul 2023 22:31:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=streamunlimited.com; s=google; t=1690522316; x=1691127116; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Q90pg3qDzBvVPqD6CaJUpw83QakxOeK89A7ElltIbrY=; b=X2lvqdfDnvTGLn/sjIoU+lwO6TZwY4lArj4CnpAnmlxWDF5RKj6CbZpnOf1ffi/DoF rOU0gq+UzNpwXlJ+pr9HyROy+go2gsl95nhvBNvzmu8+zCRCCwzSvYRDKEdhteKJsqG/ Kuz3G0Cnsg9dBc7i9GUPr1FRJgOsKZVt29W6A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690522316; x=1691127116; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Q90pg3qDzBvVPqD6CaJUpw83QakxOeK89A7ElltIbrY=; b=g1wZQp+m8thQbQwVY0TeI8hbd0FJH6ichklqzsSzOPBOerFoqQrQ1y9SsrWdKTnsem ouAfIuA6B7LhfU5KMFV9g0bRZocEIvmZ1eVhCex2O2S0yyL29ASIAZy2zKfe7ywdMMbf wUXTM/aVNSSJf2cyD6RAq4kzAtylyqynY8hYkj8f8nEmWIGOqJqzKuwoeIEwe+YzyO/i 8DNTG5xTHh3cypKLpkGwIUz0DAzlkarDXtGsjsiegD4qvevvAK+rT5DShDgYs/aY+iPL LPJlOXNOPiPnPWOWwbxm4yhLBk/oLiKEeIKcUclvh5wPraRmt+3m2GMTrT0duIfS5Rx5 fkUQ== X-Gm-Message-State: ABy/qLY1PVGiJPHh7RfvhA2AkYlGIo6iTa6He9T6uSVSD+WqG9Bvsmg/ 0sqF2UwPEx2WuaFHpfbIbBVZMDMcTsu2nhhKUTc= X-Google-Smtp-Source: APBJJlHhcfYgwA517kaK8ZjXd1urxfnuenvPqpg+e7HmpjtxIp94tU5P9C1ZjS91ALDaX1hM5j+a8g== X-Received: by 2002:a17:906:9b85:b0:99b:f3ad:e0d6 with SMTP id dd5-20020a1709069b8500b0099bf3ade0d6mr16674ejc.2.1690522316333; Thu, 27 Jul 2023 22:31:56 -0700 (PDT) Received: from smi-ubuntu.sueba ([2a01:390:0:101:353d:c2fa:e0df:3251]) by smtp.gmail.com with ESMTPSA id oq26-20020a170906cc9a00b009888aa1da11sm1590113ejb.188.2023.07.27.22.31.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 22:31:56 -0700 (PDT) From: Simon Mikuda To: linux-bluetooth@vger.kernel.org Cc: Simon Mikuda Subject: [PATCH BlueZ 2/5] device: Rename start_discovery function Date: Fri, 28 Jul 2023 07:31:50 +0200 Message-Id: <20230728053153.584222-3-simon.mikuda@streamunlimited.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230728053153.584222-1-simon.mikuda@streamunlimited.com> References: <20230728053153.584222-1-simon.mikuda@streamunlimited.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Rename it to start_discovery_cb to indicate that it is callback function from timer. --- src/device.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/device.c b/src/device.c index 82740216d..6f28e261e 100644 --- a/src/device.c +++ b/src/device.c @@ -6203,7 +6203,7 @@ bool device_is_connectable(struct btd_device *device) return state->connectable; } -static bool start_discovery(gpointer user_data) +static bool start_discovery_cb(gpointer user_data) { struct btd_device *device = user_data; @@ -6363,7 +6363,7 @@ void device_bonding_complete(struct btd_device *device, uint8_t bdaddr_type, DBG("setting timer for reverse service discovery"); device->discov_timer = timeout_add_seconds( DISCOVERY_TIMER, - start_discovery, + start_discovery_cb, device, NULL); } } @@ -6406,7 +6406,7 @@ unsigned int device_wait_for_svc_complete(struct btd_device *dev, timeout_remove(dev->discov_timer); dev->discov_timer = timeout_add_seconds( 0, - start_discovery, + start_discovery_cb, dev, NULL); } From patchwork Fri Jul 28 05:31:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Mikuda X-Patchwork-Id: 13331216 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6546CC001DF for ; Fri, 28 Jul 2023 05:32:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233351AbjG1FcC (ORCPT ); Fri, 28 Jul 2023 01:32:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229946AbjG1Fb7 (ORCPT ); Fri, 28 Jul 2023 01:31:59 -0400 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C135E30FF for ; Thu, 27 Jul 2023 22:31:58 -0700 (PDT) Received: by mail-ej1-x636.google.com with SMTP id a640c23a62f3a-99bcc0adab4so243139566b.2 for ; Thu, 27 Jul 2023 22:31:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=streamunlimited.com; s=google; t=1690522317; x=1691127117; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=c0XUCmlKoYv3z/UHv9/Pxont4XvJxVdjohyTi4iXz0I=; b=lD7CKRzwk2kTEzpVin32UAdAlCrP2B84ngD1k6T94in0VfWfNOjYg04hgGoon/dPIK LPKXIcxzXXI54uNUhD4bUEyNo3Q9QFAMuVD63khoRsH5T8XPjnmznT8BgaukhEA4IyDg BKZyr3noW8D+VRzRjKzi9gVL6KhC/p+2N6y2w= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690522317; x=1691127117; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=c0XUCmlKoYv3z/UHv9/Pxont4XvJxVdjohyTi4iXz0I=; b=AWXOj9kKn0bGbICVQ6h6XWNIyhBfwKKs30YV/vxzVBezQZqZo6cncE4ZhIx7fyP+13 eJweeq4kLsTjnh8bHxwmyOpd/pwkwsImjqrhMw0GWdkESgUhAKqFOOn7GdQx89Km24if kmuX44DgrBUXKD1xSj0lImT3zkPLNTyB85s+NZaa+zUtTpB5ulueapi5D+U+N5T4gdAV iUrH8zXI6s4vXNEbvQgj8ttzTejG2zL1nAcG3mq5rn/gmgH04o0F56zEtcBWeGUfeqPT dAOz4QQuTiYn/L0eH3b8ed6ofzG8pLGQ7RlV5ARLEtb9JZtJhtHhKDJGXjQqU1YzlNSn zJFw== X-Gm-Message-State: ABy/qLYpiTkk25EzCNnFCqH0yWrAK1AjOwN0E7Zr+ozInz1fRo1z2tcv zlCS3ixcIO4bJrAdYxtez7hMOAI7UcvWXW+23pw= X-Google-Smtp-Source: APBJJlG+Tx5aQPBDBD6OQC78Xc1IOigsSbW3yFYKJiDlwL53oX9/eSgpdYPkG1zMJvrvWySkCmFkxw== X-Received: by 2002:a17:907:a073:b0:994:34a6:50cf with SMTP id ia19-20020a170907a07300b0099434a650cfmr376557ejc.49.1690522316958; Thu, 27 Jul 2023 22:31:56 -0700 (PDT) Received: from smi-ubuntu.sueba ([2a01:390:0:101:353d:c2fa:e0df:3251]) by smtp.gmail.com with ESMTPSA id oq26-20020a170906cc9a00b009888aa1da11sm1590113ejb.188.2023.07.27.22.31.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 22:31:56 -0700 (PDT) From: Simon Mikuda To: linux-bluetooth@vger.kernel.org Cc: Simon Mikuda Subject: [PATCH BlueZ 3/5] device: Fix returning discovery error for Device.Pair Date: Fri, 28 Jul 2023 07:31:51 +0200 Message-Id: <20230728053153.584222-4-simon.mikuda@streamunlimited.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230728053153.584222-1-simon.mikuda@streamunlimited.com> References: <20230728053153.584222-1-simon.mikuda@streamunlimited.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org If discovery was requesed from pair request we will report successfull pairing even if there was an error during discovery. --- src/device.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/device.c b/src/device.c index 6f28e261e..5a39a6f83 100644 --- a/src/device.c +++ b/src/device.c @@ -6302,6 +6302,7 @@ void device_bonding_complete(struct btd_device *device, uint8_t bdaddr_type, struct bonding_req *bonding = device->bonding; struct authentication_req *auth = device->authr; struct bearer_state *state = get_state(device, bdaddr_type); + int err; DBG("bonding %p status 0x%02x", bonding, status); @@ -6351,8 +6352,16 @@ void device_bonding_complete(struct btd_device *device, uint8_t bdaddr_type, DBG("Proceeding with service discovery"); /* If we are initiators remove any discovery timer and just * start discovering services directly */ - device_discover_services(device, bdaddr_type, bonding->msg); - + err = device_discover_services(device, bdaddr_type, bonding->msg); + if (err) { + if (device->pending_paired) { + g_dbus_emit_property_changed(dbus_conn, device->path, + DEVICE_INTERFACE, "Paired"); + device->pending_paired = false; + } + /* Disregard browse errors in case of Pair */ + g_dbus_send_reply(dbus_conn, bonding->msg, DBUS_TYPE_INVALID); + } bonding_request_free(bonding); } else if (!state->svc_resolved) { if (!device->browse && !device->discov_timer && From patchwork Fri Jul 28 05:31:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Mikuda X-Patchwork-Id: 13331217 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 49808C001DE for ; Fri, 28 Jul 2023 05:32:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233368AbjG1FcD (ORCPT ); Fri, 28 Jul 2023 01:32:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233310AbjG1FcA (ORCPT ); Fri, 28 Jul 2023 01:32:00 -0400 Received: from mail-lf1-x12c.google.com (mail-lf1-x12c.google.com [IPv6:2a00:1450:4864:20::12c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DAD103580 for ; Thu, 27 Jul 2023 22:31:59 -0700 (PDT) Received: by mail-lf1-x12c.google.com with SMTP id 2adb3069b0e04-4fb73ba3b5dso2850615e87.1 for ; Thu, 27 Jul 2023 22:31:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=streamunlimited.com; s=google; t=1690522318; x=1691127118; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3hSz18IwDLbAjbTQp0yrNtDYPqRtVUfXMwzMYfSKzBQ=; b=o0bsA7oLPQo94FcUWIGewKiTELhagrcbXpsKEtqwJVrS9tDXvtIdcx89QD7L5lbGZB UBqSVt5mA/1yWFw3Hdq99UTRARaLvQQ1UvqJ3XzSFYCFdxJL/ZcZKfxyFs4Z+EikMFiD I6xr52MZR3YNIRfzmm7l7uEtsNY3xUza9gk9s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690522318; x=1691127118; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3hSz18IwDLbAjbTQp0yrNtDYPqRtVUfXMwzMYfSKzBQ=; b=KA3FvdP2Sjw5mooY/5TQREeRHeqIpRCcJIv6cDU0fZ2x3fL3BNyK83aw7rjcOCX+uW wrWMtlN0s9xjYqOWeLhOdr1GCnQAvuTfdgclXop/DdKKokLrQL8IQnuMERDZItDuDyP/ 8dCjlG8PoRskKMovuorX5E0uaKCPVi5K2iGjEUnPW/8wX1NL9Xd7VFTdJl7EawyDMhE6 0M6qn+4fpLYRYGnBj5jCMsB4tiKfyl6LFB3VBRFGAlBZ8ZSC8uHSOwz4k03ZymLZi4gb mfGRzwI6SQUPgZG4EMHLXFiKIho31oEXe/3ecKCTVf6CGojvQc+/e5BTzt+HRyzmwdZ8 zYMw== X-Gm-Message-State: ABy/qLZCogpBt0o1LE145JKC31nqpPHkyaoMW6UPw4ddE5l/WViB4BWs fcWjTAFInVAjGB8eEcBt7Tj8zlPRO13pk6mueLA= X-Google-Smtp-Source: APBJJlFtdxJDeMp3PlFxIgv5i+xKFy1cgJppFeQVNihV/5q65yqCH8rqoenPo9vIoo/syy743Z0xWg== X-Received: by 2002:a05:6512:3e0c:b0:4fd:d08c:fa3e with SMTP id i12-20020a0565123e0c00b004fdd08cfa3emr960549lfv.42.1690522317793; Thu, 27 Jul 2023 22:31:57 -0700 (PDT) Received: from smi-ubuntu.sueba ([2a01:390:0:101:353d:c2fa:e0df:3251]) by smtp.gmail.com with ESMTPSA id oq26-20020a170906cc9a00b009888aa1da11sm1590113ejb.188.2023.07.27.22.31.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 22:31:57 -0700 (PDT) From: Simon Mikuda To: linux-bluetooth@vger.kernel.org Cc: Simon Mikuda Subject: [PATCH BlueZ 4/5] device: Fix pairing with dual mode devices Date: Fri, 28 Jul 2023 07:31:52 +0200 Message-Id: <20230728053153.584222-5-simon.mikuda@streamunlimited.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230728053153.584222-1-simon.mikuda@streamunlimited.com> References: <20230728053153.584222-1-simon.mikuda@streamunlimited.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org We'll prefer to pair services on connected bearer first. There was a problem with pairing, that select_conn_bearer returned BR/EDR even when we have connection to LE bearer only. In these situation we should pair over connected bearer, since connection to another bearer can fail. --- src/device.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/device.c b/src/device.c index 5a39a6f83..367e2f046 100644 --- a/src/device.c +++ b/src/device.c @@ -3017,6 +3017,11 @@ static DBusMessage *pair_device(DBusConnection *conn, DBusMessage *msg, bdaddr_type = device->bdaddr_type; else if (device->le_state.bonded) bdaddr_type = BDADDR_BREDR; + else if (device->bredr_state.connected && !device->le_state.connected) + bdaddr_type = BDADDR_BREDR; + else if (!device->bredr_state.connected && device->le_state.connected) + bdaddr_type = device->bdaddr_type == BDADDR_BREDR + ? BDADDR_LE_PUBLIC : device->bdaddr_type; else bdaddr_type = select_conn_bearer(device); From patchwork Fri Jul 28 05:31:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Mikuda X-Patchwork-Id: 13331218 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 47FAFC001E0 for ; Fri, 28 Jul 2023 05:32:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233374AbjG1FcE (ORCPT ); Fri, 28 Jul 2023 01:32:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233294AbjG1FcB (ORCPT ); Fri, 28 Jul 2023 01:32:01 -0400 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 225E030FF for ; Thu, 27 Jul 2023 22:32:00 -0700 (PDT) Received: by mail-ej1-x633.google.com with SMTP id a640c23a62f3a-99b9421aaebso230938266b.2 for ; Thu, 27 Jul 2023 22:32:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=streamunlimited.com; s=google; t=1690522318; x=1691127118; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gU44N8Xo8yUQnHkDliCqWo178s9KcVHtzIs9rNJ+5GA=; b=ttvvSlIsw0BMJyEw4+W84Ldq5KO/TDVNfZbT7+9hYQtt05RKpJ/p05ekxPmIu1O8K6 wnirYmmO7cpQqcZdoPGGXR/yUipGT4jzV+R2+XAng7Y5cT7UvydDr4oNYf15soGeYJBG at/T0K+KR06b9+Ne2g/6kahgY7wB9NGAely3s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690522318; x=1691127118; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gU44N8Xo8yUQnHkDliCqWo178s9KcVHtzIs9rNJ+5GA=; b=fn/180JLfEkpOQcXqyPpH5uYaGonIfwob9icO/6zOFVf7sUEcAJRHC53e52Whl94DO PJYf/4lPnxywCd0t9OJmxGEeHZH7s72jk2Z37arqtix4sndl4saufP2MoOSPi6bvSLmY AdBf+RoaI0nlrLzLKbnaoXGIuZZzRZX1MfgfsuS2kOJS2g3y5L1rFvw6RU/Os+AagzyF KlcjIlAOe6Ec//z6cBGH2kHi3Q9SPb6klhZNoevmtOX/RWqjzMJSgE/+sDuyY2RWz3wO iFCVEepRPLQy3JmS+fgAcTZkr3xQz3BsvlmORPzniQ4lLkVKxI+0357CXDDqQ2luoRma QS4w== X-Gm-Message-State: ABy/qLZMpJjmx+NRFn2KEWyC+r2HeMjLiQRdEctfoBisYfwFnK0Rr2g/ 3QQhyUHKy398xL49UN5KVD1+0agqqH/z6B/Dhew= X-Google-Smtp-Source: APBJJlEXjRqTaAxdwa1KexO7N0vtpm5rzX+AmJ636gUiEVjt/1btjA7dfM9VWovqJNhB0lewa3tGow== X-Received: by 2002:a17:907:a04b:b0:99b:c952:309a with SMTP id gz11-20020a170907a04b00b0099bc952309amr869929ejc.39.1690522318284; Thu, 27 Jul 2023 22:31:58 -0700 (PDT) Received: from smi-ubuntu.sueba ([2a01:390:0:101:353d:c2fa:e0df:3251]) by smtp.gmail.com with ESMTPSA id oq26-20020a170906cc9a00b009888aa1da11sm1590113ejb.188.2023.07.27.22.31.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 22:31:58 -0700 (PDT) From: Simon Mikuda To: linux-bluetooth@vger.kernel.org Cc: Simon Mikuda Subject: [PATCH BlueZ 5/5] device: Fix reverse service discovery handling for dual mode devices Date: Fri, 28 Jul 2023 07:31:53 +0200 Message-Id: <20230728053153.584222-6-simon.mikuda@streamunlimited.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230728053153.584222-1-simon.mikuda@streamunlimited.com> References: <20230728053153.584222-1-simon.mikuda@streamunlimited.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org There can be situation that after connection to LE bearer we will try to start reverse discovery on BR/EDR bearer even when it is not connected. This change separates SDP and GATT reverse services discoveries to their respective bearers. SDP to BR/EDR and GATT to LE. --- src/device.c | 129 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 83 insertions(+), 46 deletions(-) diff --git a/src/device.c b/src/device.c index 367e2f046..90d6a7615 100644 --- a/src/device.c +++ b/src/device.c @@ -158,6 +158,10 @@ struct bearer_state { bool initiator; bool connectable; time_t last_seen; + /* reverse service discovery timer */ + unsigned int discov_timer; + /* service discover request (SDP, GATT) */ + struct browse_req *browse; }; struct ltk_info { @@ -236,9 +240,7 @@ struct btd_device { bool temporary; bool connectable; unsigned int disconn_timer; - unsigned int discov_timer; unsigned int temporary_timer; /* Temporary/disappear timer */ - struct browse_req *browse; /* service discover request */ struct bonding_req *bonding; struct authentication_req *authr; /* authentication request */ GSList *disconnects; /* disconnects message */ @@ -684,8 +686,10 @@ static void browse_request_free(struct browse_req *req) { struct btd_device *device = req->device; - if (device->browse == req) - device->browse = NULL; + if (device->bredr_state.browse == req) + device->bredr_state.browse = NULL; + if (device->le_state.browse == req) + device->le_state.browse = NULL; if (req->listener_id) g_dbus_remove_watch(dbus_conn, req->listener_id); @@ -833,8 +837,10 @@ static void device_free(gpointer user_data) if (device->disconn_timer) timeout_remove(device->disconn_timer); - if (device->discov_timer) - timeout_remove(device->discov_timer); + if (device->bredr_state.discov_timer) + timeout_remove(device->bredr_state.discov_timer); + if (device->le_state.discov_timer) + timeout_remove(device->le_state.discov_timer); if (device->temporary_timer) timeout_remove(device->temporary_timer); @@ -1848,8 +1854,10 @@ void device_request_disconnect(struct btd_device *device, DBusMessage *msg) if (device->bonding) bonding_request_cancel(device->bonding); - if (device->browse) - browse_request_cancel(device->browse); + if (device->bredr_state.browse) + browse_request_cancel(device->bredr_state.browse); + if (device->le_state.browse) + browse_request_cancel(device->le_state.browse); if (device->att_io) { g_io_channel_shutdown(device->att_io, FALSE, NULL); @@ -2304,7 +2312,7 @@ void btd_device_update_allowed_services(struct btd_device *dev) /* If service discovery is ongoing, let the service discovery complete * callback call this function. */ - if (dev->browse) { + if (dev->bredr_state.browse) { ba2str(&dev->bdaddr, addr); DBG("service discovery of %s is ongoing. Skip updating allowed " "services", addr); @@ -2370,7 +2378,7 @@ int btd_device_connect_services(struct btd_device *dev, GSList *services) { GSList *l; - if (dev->pending || dev->connect || dev->browse) + if (dev->pending || dev->connect || dev->bredr_state.browse) return -EBUSY; if (!btd_adapter_get_powered(dev->adapter)) @@ -2401,7 +2409,7 @@ static DBusMessage *connect_profiles(struct btd_device *dev, uint8_t bdaddr_type DBG("%s %s, client %s", dev->path, uuid ? uuid : "(all)", dbus_message_get_sender(msg)); - if (dev->pending || dev->connect || dev->browse) + if (dev->pending || dev->connect || dev->bredr_state.browse) return btd_error_in_progress_str(msg, ERR_BREDR_CONN_BUSY); if (!btd_adapter_get_powered(dev->adapter)) { @@ -2784,7 +2792,7 @@ static void browse_request_complete(struct browse_req *req, uint8_t type, /* if successfully resolved services we need to free browsing request * before passing message back to connect functions, otherwise - * device->browse is set and "InProgress" error is returned instead + * device->state.browse is set and "InProgress" error is returned instead * of actually connecting services */ msg = dbus_message_ref(req->msg); @@ -2829,7 +2837,7 @@ static void device_svc_resolved(struct btd_device *dev, uint8_t browse_type, uint8_t bdaddr_type, int err) { struct bearer_state *state = get_state(dev, bdaddr_type); - struct browse_req *req = dev->browse; + struct browse_req *req = state->browse; DBG("%s err %d", dev->path, err); @@ -3060,7 +3068,7 @@ static DBusMessage *pair_device(DBusConnection *conn, DBusMessage *msg, err = device_connect_le(device); else err = adapter_create_bonding(adapter, &device->bdaddr, - device->bdaddr_type, + bdaddr_type, io_cap); } else { err = adapter_create_bonding(adapter, &device->bdaddr, @@ -4657,8 +4665,10 @@ void device_remove(struct btd_device *device, gboolean remove_stored) device_cancel_bonding(device, status); } - if (device->browse) - browse_request_cancel(device->browse); + if (device->bredr_state.browse) + browse_request_cancel(device->bredr_state.browse); + if (device->le_state.browse) + browse_request_cancel(device->le_state.browse); while (device->services != NULL) { struct btd_service *service = device->services->data; @@ -5317,7 +5327,7 @@ static void att_disconnected_cb(int err, void *user_data) DBG(""); - if (device->browse) + if (device->le_state.browse) goto done; DBG("%s (%d)", strerror(err), err); @@ -5345,7 +5355,7 @@ done: static void register_gatt_services(struct btd_device *device) { - struct browse_req *req = device->browse; + struct browse_req *req = device->le_state.browse; GSList *services = NULL; if (!bt_gatt_client_is_ready(device->client)) @@ -5636,8 +5646,8 @@ static void att_connect_cb(GIOChannel *io, GError *gerr, gpointer user_data) adapter_connect_list_add(device->adapter, device); } - if (device->browse) - browse_request_complete(device->browse, + if (device->le_state.browse) + browse_request_complete(device->le_state.browse, BROWSE_GATT, device->bdaddr_type, -ECONNABORTED); @@ -5751,15 +5761,24 @@ static struct browse_req *browse_request_new(struct btd_device *device, DBusMessage *msg) { struct browse_req *req; + struct bearer_state *state; - if (device->browse) + switch (type) { + case BROWSE_SDP: + state = get_state(device, BDADDR_BREDR); + break; + case BROWSE_GATT: + state = get_state(device, BDADDR_LE_PUBLIC); + break; + } + if (state->browse) return NULL; req = g_new0(struct browse_req, 1); req->device = device; req->type = type; - device->browse = req; + state->browse = req; if (!msg) return req; @@ -5879,15 +5898,17 @@ int device_discover_services(struct btd_device *device, uint8_t bdaddr_type, DBusMessage *msg) { int err; + struct bearer_state *state; if (bdaddr_type == BDADDR_BREDR) err = device_browse_sdp(device, msg); else err = device_browse_gatt(device, msg); - if (err == 0 && device->discov_timer) { - timeout_remove(device->discov_timer); - device->discov_timer = 0; + state = get_state(device, bdaddr_type); + if (err == 0 && state->discov_timer) { + timeout_remove(state->discov_timer); + state->discov_timer = 0; } return err; @@ -6208,16 +6229,22 @@ bool device_is_connectable(struct btd_device *device) return state->connectable; } -static bool start_discovery_cb(gpointer user_data) +static bool start_sdp_discovery_cb(gpointer user_data) { struct btd_device *device = user_data; - if (device->bredr) - device_browse_sdp(device, NULL); - else - device_browse_gatt(device, NULL); + device->bredr_state.discov_timer = 0; + device_browse_sdp(device, NULL); - device->discov_timer = 0; + return FALSE; +} + +static bool start_gatt_discovery_cb(gpointer user_data) +{ + struct btd_device *device = user_data; + + device->le_state.discov_timer = 0; + device_browse_gatt(device, NULL); return FALSE; } @@ -6368,17 +6395,27 @@ void device_bonding_complete(struct btd_device *device, uint8_t bdaddr_type, g_dbus_send_reply(dbus_conn, bonding->msg, DBUS_TYPE_INVALID); } bonding_request_free(bonding); - } else if (!state->svc_resolved) { - if (!device->browse && !device->discov_timer && - btd_opts.reverse_discovery) { - /* If we are not initiators and there is no currently - * active discovery or discovery timer, set discovery - * timer */ - DBG("setting timer for reverse service discovery"); - device->discov_timer = timeout_add_seconds( - DISCOVERY_TIMER, - start_discovery_cb, - device, NULL); + + } else if (!state->svc_resolved + && !state->browse + && !state->discov_timer + && btd_opts.reverse_discovery) { + + /* If we are not initiators and there is no currently + * active discovery or discovery timer, set discovery + * timer */ + if (bdaddr_type == BDADDR_BREDR) { + DBG("setting timer for reverse SDP service discovery"); + state->discov_timer = timeout_add_seconds( + DISCOVERY_TIMER, + start_sdp_discovery_cb, + device, NULL); + } else { + DBG("setting timer for reverse GATT service discovery"); + state->discov_timer = timeout_add_seconds( + DISCOVERY_TIMER, + start_gatt_discovery_cb, + device, NULL); } } } @@ -6416,11 +6453,11 @@ unsigned int device_wait_for_svc_complete(struct btd_device *dev, if (state->svc_resolved || !btd_opts.reverse_discovery) cb->idle_id = g_idle_add(svc_idle_cb, cb); - else if (dev->discov_timer > 0) { - timeout_remove(dev->discov_timer); - dev->discov_timer = timeout_add_seconds( + else if (dev->bredr_state.discov_timer > 0) { + timeout_remove(dev->bredr_state.discov_timer); + dev->bredr_state.discov_timer = timeout_add_seconds( 0, - start_discovery_cb, + start_sdp_discovery_cb, dev, NULL); }