Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp3077510rdb; Wed, 13 Sep 2023 00:53:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFHrGRJF/3j6BB8+iYTGxP9WDX5LAsayheGKz1R6QP4MJV4lA0jwMRmKeYeRPk3lnpcm6Li X-Received: by 2002:a05:6a00:2495:b0:68f:e810:e86f with SMTP id c21-20020a056a00249500b0068fe810e86fmr2161755pfv.28.1694591635988; Wed, 13 Sep 2023 00:53:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694591635; cv=none; d=google.com; s=arc-20160816; b=Rxnaeq48CSyFdGAJpI1DOJGdPi7WdAeWqYUXYAp2m1eQqLrgJiBmrwj9zKuZSctxhG mr536BdLR1R3PcqPSGCcHxbeZJQ6gh729BGtxiS81mNtCbyqz+F0zG8ZQqpLcuo/cj3h S4RsgumPEuLeWrZIcWlwWhquFWMTyWCUeB0qbgGkE21Zpl0MbSrWXo/MB3jJnycXl1Ea zMJiJ1x0oE4BKNbxPK1sPw2jdLbwilumRMf/5RlZAYgyrlxMbotWRg4owYmYmEaN/JwS oRhYQfUj2HR7w3EEJBHKgUkGxgPZWOrbJMioVtr1BpA7kttMGMXiuq6zh/jFPNBJVJVX 1BGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:to:from:dkim-signature; bh=SPxTVKDfPnYcmDz+/Xp310u86Enj0uzeRFdQ4Ju+daI=; fh=4lGQI6056MBa4/oovMyIYaKLn+Wz/24RGvUivMmQP8E=; b=lmwD704IhEV+tUs9JBeS0lmOWbkZ3dYXFc1LYs9vqw6qYiQY3nQ7sVDpS1/m8EIii9 OwrWrEmiUdiVZQ93fa/Ftfa6oBAtjJBdvkXERnwG1xuSxEyEQxuWo1VJFV4Kj7DFgSa4 KLTvLzEY51vCn70cEixidiEqhz1Ro7KuWtGE/RlDYzF7oz9Zxdo+xMDTFvcexCkoMkSc UpfrS2VCzrFc5eb1qPVOkatd5MuAk4SJ5d8JpiYzuwHVMTM38Uj6pxZMPnYtJqvYoypY wqa+g3kvH4VdMG55F6mCbzw9hYqvTLY/9F5KpGbx6DG7gjKE4KPNQXlaG3bPTEbhnITM 6Mpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b="BI/9Vrh+"; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id s21-20020a63af55000000b00553854417d8si9478923pgo.617.2023.09.13.00.53.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 00:53:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b="BI/9Vrh+"; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id C9DEB80781D3; Mon, 11 Sep 2023 21:05:46 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.8 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241938AbjILDI2 (ORCPT + 99 others); Mon, 11 Sep 2023 23:08:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241929AbjILDIK (ORCPT ); Mon, 11 Sep 2023 23:08:10 -0400 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 160B589A95 for ; Mon, 11 Sep 2023 15:35:05 -0700 (PDT) Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-68fb46f38f9so1658481b3a.1 for ; Mon, 11 Sep 2023 15:35:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694471624; x=1695076424; 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=SPxTVKDfPnYcmDz+/Xp310u86Enj0uzeRFdQ4Ju+daI=; b=BI/9Vrh+TTF50euP88jrmSUxbABsMoZJAsLI3ysyL4+YFNRBNaKrm03bS4ZJG8nsmO 8PnGYj+lXNR6XFaeSPsGrFs6pnXpKqsb0extv673YXH4kdYZp/syd6QeAQrGts4YrBOX TolmHMc0RnYx2g3Utpjt2ZG/39KLQQtbpOQE55p3fqYrShn3ndBpdZTgAYXYk4EJpLe/ 9AC5kPHD9upyOqX9KuOmid1N4lOjQgix5kWSk/ahOK76tek8AwhyYKGHHp9N5oONieab /p2ZibdvALhmaf0/xa5ViBX4Yw3oNwrc7YtB1po98Yzb9SIDCkzRuMIm2ezpztDZssAe wxjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694471624; x=1695076424; 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=SPxTVKDfPnYcmDz+/Xp310u86Enj0uzeRFdQ4Ju+daI=; b=O6HawUYi/Fsy0Y+pY/qpqVb+6nTBmIjRfdHgA4kxM4xRyd4ttcjYDcZkEkgpkrK9pF ZsQdpfDz5Blq7rfthtmBPTzHexOBuTiXHSb51nVhgUXKdbil0zcsz/Cd/mkfzzX1W2Gi +Usc3WJTw6WBYHwU0ewSKzI6XYgMmnABM/wyYfM7X750mia9BNOBdjfowYoHTdTPix5R sfak8+afZBB3+5oNABRGCzdJMy7M/jqrjnINiZtbN9HYAnhqywr8Nh3678eBWuI0Rl90 hrfxrqkYB7LdV4CbzhZ3r+PranVpye8prZ8YW3/Fq4XKRJDfAY8gNsP/UuJk9+0Nb+xx IGJg== X-Gm-Message-State: AOJu0YyLItvmWFHFiVXyO1vRrhrMJPNNtq72HQJ8hUkKNFv3pzHQNkUI jr5PiiRI1/lr5q3GmupisBlvK7qNF/E= X-Received: by 2002:a05:6a20:842a:b0:134:9f4e:623f with SMTP id c42-20020a056a20842a00b001349f4e623fmr10639128pzd.14.1694471623775; Mon, 11 Sep 2023 15:33:43 -0700 (PDT) Received: from lvondent-mobl4.. (c-98-232-221-87.hsd1.or.comcast.net. [98.232.221.87]) by smtp.gmail.com with ESMTPSA id i11-20020a633c4b000000b005634343cd9esm4099884pgn.44.2023.09.11.15.33.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 15:33:42 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ] device: Fix not handling initiator properly Date: Mon, 11 Sep 2023 15:33:40 -0700 Message-ID: <20230911223341.2701182-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 11 Sep 2023 21:05:47 -0700 (PDT) From: Luiz Augusto von Dentz Previously initiator would be set whenever a central key was found which turns out to be unreliable besides the MGMT New Connection event does in fact inform if the connection was initiated locally or not. Fixes: https://github.com/bluez/bluez/issues/598 --- src/adapter.c | 10 ++++++---- src/device.c | 15 +++++---------- src/device.h | 3 ++- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/adapter.c b/src/adapter.c index 5ebfc4752a7e..8a7c53a9e3ce 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -5163,9 +5163,10 @@ static void adapter_remove_device(struct btd_adapter *adapter, static void adapter_add_connection(struct btd_adapter *adapter, struct btd_device *device, - uint8_t bdaddr_type) + uint8_t bdaddr_type, + uint32_t flags) { - device_add_connection(device, bdaddr_type); + device_add_connection(device, bdaddr_type, flags); if (g_slist_find(adapter->connections, device)) { btd_error(adapter->dev_id, @@ -5218,7 +5219,7 @@ static void get_connections_complete(uint8_t status, uint16_t length, device = btd_adapter_get_device(adapter, &addr->bdaddr, addr->type); if (device) - adapter_add_connection(adapter, device, addr->type); + adapter_add_connection(adapter, device, addr->type, 0); } } @@ -9426,7 +9427,8 @@ static void connected_callback(uint16_t index, uint16_t length, if (eir_data.class != 0) device_set_class(device, eir_data.class); - adapter_add_connection(adapter, device, ev->addr.type); + adapter_add_connection(adapter, device, ev->addr.type, + le32_to_cpu(ev->flags)); name_known = device_name_known(device); diff --git a/src/device.c b/src/device.c index 9b58e0c4e6c5..35ce1df0fe74 100644 --- a/src/device.c +++ b/src/device.c @@ -312,16 +312,9 @@ static struct bearer_state *get_state(struct btd_device *dev, bool btd_device_is_initiator(struct btd_device *dev) { - if (dev->le_state.connected) { - /* Mark as initiator if not set yet and auto-connect flag is - * set and LTK key is for a peripheral. - */ - if (!dev->le_state.initiator && dev->auto_connect && - dev->ltk && !dev->ltk->central) - dev->le_state.initiator = true; - + if (dev->le_state.connected) return dev->le_state.initiator; - } else if (dev->bredr_state.connected) + else if (dev->bredr_state.connected) return dev->bredr_state.initiator; return dev->att_io ? true : false; @@ -3226,7 +3219,8 @@ static void clear_temporary_timer(struct btd_device *dev) } } -void device_add_connection(struct btd_device *dev, uint8_t bdaddr_type) +void device_add_connection(struct btd_device *dev, uint8_t bdaddr_type, + uint32_t flags) { struct bearer_state *state = get_state(dev, bdaddr_type); @@ -3249,6 +3243,7 @@ void device_add_connection(struct btd_device *dev, uint8_t bdaddr_type) device_set_le_support(dev, bdaddr_type); state->connected = true; + state->initiator = flags & BIT(3); if (dev->le_state.connected && dev->bredr_state.connected) return; diff --git a/src/device.h b/src/device.h index 3252e14eff84..0a9e51533ca5 100644 --- a/src/device.h +++ b/src/device.h @@ -124,7 +124,8 @@ int device_notify_pincode(struct btd_device *device, gboolean secure, const char *pincode); void device_cancel_authentication(struct btd_device *device, gboolean aborted); gboolean device_is_authenticating(struct btd_device *device); -void device_add_connection(struct btd_device *dev, uint8_t bdaddr_type); +void device_add_connection(struct btd_device *dev, uint8_t bdaddr_type, + uint32_t flags); void device_remove_connection(struct btd_device *device, uint8_t bdaddr_type, bool *remove); void device_request_disconnect(struct btd_device *device, DBusMessage *msg); -- 2.41.0