Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp329589rdb; Mon, 29 Jan 2024 03:49:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IHcJw46wvf1yt8+3J6H9ruWswjllYP7KlJ43vzedt3qNigZSwPArkBembmDGVur/BGBfGMl X-Received: by 2002:a81:ad4b:0:b0:5ff:aa34:7c5f with SMTP id l11-20020a81ad4b000000b005ffaa347c5fmr2971524ywk.46.1706528982545; Mon, 29 Jan 2024 03:49:42 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706528982; cv=pass; d=google.com; s=arc-20160816; b=lDqDFwheHmoVesXDOKcan4/WWMqkg85ng/9IsdNPR1isogDsTdmw44a7ww2xaDBqRY 4s3Y5lcfjzFZUYJCvOLG1j6XTpjhUqDNae35efLgPqmK6z4eJ18UEeGqVbayW1a9JaTG X4h9J+57r6/QtzWLKw6EiplmtXzgHbozi8/FKMf7L8S4vHIXCQ8owcD5q4PcRP2peIz0 4+ZDkp7AtnqkU3Y+Wqcuhef8+51+271CTbRyEsMre0fauSVD1r/R2QOJY4Z0jiP1FIho EW7kQDkwprRJq0UAeH0eG65fJ9c+gbIwBRtF16EVxC5emkiD+2RIu17UUsz6zGn07u4I 6mBg== 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:cc:to:from; bh=IIT9madQutbfurIX0iU8fqz43TB0R20zdkLz4sAmFUg=; fh=c38J9zbsgHLNhWxJ8/ndjiTKtcMHSNZxa3IAP+R4egE=; b=aI+H1rMq15UCAxXBpPfG/Yt3QHs2t1XzDjjQXRLmUiZRY4oQztntndbwlSsTdbB0Lp J/86mSuC5wDCsWlvE0ANAWXf91R+rqiklVz/+TtJlV4U60Q4Je3Yk9/DAxJq0Xv39O2y +bMjjCr68/OH/IXq40KzPhR95Tb0ltrQLMY28mZdUT64srsBkQgGgXUeeFW4leB+CIaN Mmn8WSvN+Uvl2gE9wKQ4x8sftMl2XlM8Urf1rgBL9E3AuyaHgc/Ov10z075RBqbJ0f0D jhc6JAc3S1TX/f4Opqm63R2WRppdelbRs4tK2LkAmNM0IHa5pn6LAronGm7bmd7dwC11 tw0Q== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=v0yd.nl); spf=pass (google.com: domain of linux-bluetooth+bounces-1431-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-1431-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id i14-20020ac85e4e000000b0042a3360cbb6si7342406qtx.538.2024.01.29.03.49.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 03:49:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-bluetooth+bounces-1431-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=v0yd.nl); spf=pass (google.com: domain of linux-bluetooth+bounces-1431-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-1431-linux.lists.archive=gmail.com@vger.kernel.org" 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 4D53C1C21B8F for ; Mon, 29 Jan 2024 11:49:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ED2505FEF6; Mon, 29 Jan 2024 11:49:21 +0000 (UTC) X-Original-To: linux-bluetooth@vger.kernel.org Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 46DE25D8FE for ; Mon, 29 Jan 2024 11:49:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=80.241.56.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706528961; cv=none; b=Z91/1QD2g0HqjswXsD0wAi6nI31AsGuTYsYKijYrCuIU9RdN6p6lF4gZbyKMLI93rZhcwdghX4WJyLzOPpSLRdxpptxOhJMioDqZEs9G14084ydScJn/2f5XqDYOGKHNYJJJr8qE8tuTTqOvFRXh1Vaqf8ArAtxg/tHJJAN4kqg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706528961; c=relaxed/simple; bh=tJ+QG345hAeqhkWfdmnPB882FgeVkgs+i41FMpoqWHk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ip8iFpTTyMAtW1ndI6FpWfjYHMFJUk1qxOpi9FpZNpLCofxR/vTYqzjtDax1m8e+oXrHW5TYWTvNi9dVK2oG2RaC+ZLVeo8PUx7a8LlNhrXwPEjK3Nw0vdXBDyQTHcQBiDrN+zoxxIc0RcgCKuHel1GeZuwg8MDJNJnoP9DN+fk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=v0yd.nl; spf=pass smtp.mailfrom=v0yd.nl; arc=none smtp.client-ip=80.241.56.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=v0yd.nl Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=v0yd.nl Received: from smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:b231:465::202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-202.mailbox.org (Postfix) with ESMTPS id 4TNmmP1m7Xz9sPy; Mon, 29 Jan 2024 12:49:09 +0100 (CET) From: =?UTF-8?q?Jonas=20Dre=C3=9Fler?= To: linux-bluetooth@vger.kernel.org, Luiz Augusto von Dentz Cc: =?UTF-8?q?Jonas=20Dre=C3=9Fler?= Subject: [PATCH BlueZ 3/4] emulator/btdev: Send page timeout after 2 secs delay Date: Mon, 29 Jan 2024 12:48:59 +0100 Message-ID: <20240129114900.92919-4-verdre@v0yd.nl> In-Reply-To: <20240129114900.92919-1-verdre@v0yd.nl> References: <20240129114900.92919-1-verdre@v0yd.nl> Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 4TNmmP1m7Xz9sPy Real bluetooth adapters wouldn't send the page timeout immediately when trying to page a device, instead it would take a few seconds. Try to behave more realistically in the emulator and send the page timeout after two seconds. --- emulator/btdev.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/emulator/btdev.c b/emulator/btdev.c index da94f29d1..a40117400 100644 --- a/emulator/btdev.c +++ b/emulator/btdev.c @@ -1281,6 +1281,27 @@ static void conn_complete(struct btdev *btdev, send_event(btdev, BT_HCI_EVT_CONN_COMPLETE, &cc, sizeof(cc)); } +struct page_timeout_data { + struct btdev *btdev; + uint8_t bdaddr[6]; + unsigned int timeout_id; +}; + +static bool page_timeout(void *user_data) +{ + struct page_timeout_data *pt_data = user_data; + struct btdev *btdev = pt_data->btdev; + const uint8_t *bdaddr = pt_data->bdaddr; + + timeout_remove(pt_data->timeout_id); + pt_data->timeout_id = 0; + + conn_complete(btdev, bdaddr, BT_HCI_ERR_PAGE_TIMEOUT); + + free(pt_data); + return false; +} + static int cmd_create_conn_complete(struct btdev *dev, const void *data, uint8_t len) { @@ -1298,7 +1319,14 @@ static int cmd_create_conn_complete(struct btdev *dev, const void *data, send_event(remote, BT_HCI_EVT_CONN_REQUEST, &cr, sizeof(cr)); } else { - conn_complete(dev, cmd->bdaddr, BT_HCI_ERR_PAGE_TIMEOUT); + struct page_timeout_data *pt_data = new0(struct page_timeout_data, 1); + pt_data->btdev = dev; + memcpy(pt_data->bdaddr, cmd->bdaddr, 6); + + /* Send page timeout after 2 seconds to emulate real paging */ + pt_data->timeout_id = timeout_add(2000, + page_timeout, + pt_data, NULL); } return 0; -- 2.43.0