From patchwork Fri May 10 15:09:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 13661723 Received: from mail-vs1-f48.google.com (mail-vs1-f48.google.com [209.85.217.48]) (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 0A1D212C461 for ; Fri, 10 May 2024 15:09:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.217.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715353783; cv=none; b=bId96yj9vCPfx6V0Dzo2yosVXpQyNT199PS08CJhakQkxsWAoJMEwpew8otPUB2MIzb6RjF2/AIikosk4fxv1KzDsAGrgvZUBe6dnWBpQeb/G5Awh0X0WbSSZ0d3c+a5sHsBEHTZsHbZeyVCcQf1fc0uORY6XXY8K5vInDR0AQs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715353783; c=relaxed/simple; bh=pKT4XZRJiT2XEYiakeoujvfG6MFJfdzhucZn7yPT3y8=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=WzIYtlaGaBCOyISh3C0O/4Z9MPzsMbkxCIq4IAZmKyUook1KHvokbBzcNxNcoxAU58z8Vcw1wBgaH/FBpAzoCp3yox2DoulxIAAePAsyHFc9AK3hvm1gg4oGEC9n4yg9NrfA35HNLme6oY68uDSGqDrWuWog6hy7w6xeMqpty7o= 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=PtqkewZq; arc=none smtp.client-ip=209.85.217.48 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PtqkewZq" Received: by mail-vs1-f48.google.com with SMTP id ada2fe7eead31-47eff2a6699so736841137.3 for ; Fri, 10 May 2024 08:09:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715353780; x=1715958580; 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=TKr1PFTun9Ztejswu5ybhumSHAh4M/2Oe9Hkl89jau8=; b=PtqkewZqMl7vOwIYo8LeU5hlM192wRoNAUgA40zrMDCdgmHRejwHHo/buCx2Pnt/b1 7Y8QJ2N1bfkLrdmwYmojVvKh3u5Q0mlF9nW1GSBSFiry3uYas/KaD2drYWxtHJbJC4Ev QmqOyb/T/zAat7xcLjiusEnrGFwQr5RYZgXU6D+XeqbtAezPd9EALuemhpYgufRNf1PQ k9/xLbkbnrZSgkmz0IVBbnHonFKPOXZh7c4eJYs5cCzNLtYlbks96sLolU5nEc0Ryt0N dYca8iw/jw7xlMVXC2KcZAks0x+FdTVo5j1IROWm6x5K4uJv8YBUYCy/YUrEwLzfKzHX 6dKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715353780; x=1715958580; 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=TKr1PFTun9Ztejswu5ybhumSHAh4M/2Oe9Hkl89jau8=; b=wpKMHA7sepdatlSTkbDGgZHbzwJhoL3/TFAzAJRT62ODDGJ+g5GkxNuETMK5603hnU GeTHB0QGHAlty5gS0Ynii6BO9nOgJTrOvm+8f7qKhw+ThdJ8z62HrhuVeWYQWuykIsw5 +F0Ic75CqtqQHdeLWHL2wDtf1BlzyutkYExM5xUwFejeDWmT5zxTtDhSayUk7skGI4W7 b/jO65iO4KMI0fhC2R8/s/0FmXZJywxikmVODq7f8AZl2jw4RL/DDx8KdP7gjWmPUjJ6 KRS927xlq9XLnnwBArMQuASd5+EbpKtnpV/PaivSswD1hZrk6nW4+Jy/BbH4aZYHTN0o rcsA== X-Gm-Message-State: AOJu0YyMFAdduu7B2hrwyLGd6Eu/haH6FMnmECH/JKf8nUhrrZS5zIIy 5ay+6lz69RYHwHVVaGm7AB41FqXtTBenEvpEY1gDuoEAJf87O7z4K9sgFg== X-Google-Smtp-Source: AGHT+IF4tIWdLjw1Ciyg7vOq6+2L3NgEM7PDPvlMwejk/WEtRZ70NFxmpr4QbvmCM0EdIEP9MCkNQg== X-Received: by 2002:a05:6102:3e86:b0:47c:2599:9d99 with SMTP id ada2fe7eead31-48077ea51cdmr3124743137.31.1715353780176; Fri, 10 May 2024 08:09:40 -0700 (PDT) Received: from lvondent-mobl4.. (syn-107-146-107-067.res.spectrum.com. [107.146.107.67]) by smtp.gmail.com with ESMTPSA id ada2fe7eead31-4806cb008d2sm510050137.2.2024.05.10.08.09.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 May 2024 08:09:39 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v3 1/4] profiles/gap: Some code cleanup Date: Fri, 10 May 2024 11:09:35 -0400 Message-ID: <20240510150938.1492169-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.44.0 Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: "Felipe F. Tonello" Just removing unecessary function and code duplication. --- profiles/gap/gas.c | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/profiles/gap/gas.c b/profiles/gap/gas.c index 400818d67591..713b9aaf28f2 100644 --- a/profiles/gap/gas.c +++ b/profiles/gap/gas.c @@ -50,10 +50,18 @@ struct gas { struct gatt_db_attribute *attr; }; +static void gas_reset(struct gas *gas) +{ + gas->attr = NULL; + gatt_db_unref(gas->db); + gas->db = NULL; + bt_gatt_client_unref(gas->client); + gas->client = NULL; +} + static void gas_free(struct gas *gas) { - gatt_db_unref(gas->db); - bt_gatt_client_unref(gas->client); + gas_reset(gas); btd_device_unref(gas->device); g_free(gas); } @@ -152,7 +160,7 @@ static void handle_appearance(struct gas *gas, uint16_t value_handle) DBG("Failed to send request to read appearance"); } -static bool uuid_cmp(uint16_t u16, const bt_uuid_t *uuid) +static inline bool uuid_cmp(uint16_t u16, const bt_uuid_t *uuid) { bt_uuid_t lhs; @@ -188,11 +196,6 @@ static void handle_characteristic(struct gatt_db_attribute *attr, } } -static void handle_gap_service(struct gas *gas) -{ - gatt_db_service_foreach_char(gas->attr, handle_characteristic, gas); -} - static int gap_probe(struct btd_service *service) { struct btd_device *device = btd_service_get_device(service); @@ -246,16 +249,7 @@ static void foreach_gap_service(struct gatt_db_attribute *attr, void *user_data) } gas->attr = attr; - handle_gap_service(gas); -} - -static void gas_reset(struct gas *gas) -{ - gas->attr = NULL; - gatt_db_unref(gas->db); - gas->db = NULL; - bt_gatt_client_unref(gas->client); - gas->client = NULL; + gatt_db_service_foreach_char(gas->attr, handle_characteristic, gas); } static int gap_accept(struct btd_service *service) @@ -266,13 +260,15 @@ static int gap_accept(struct btd_service *service) struct gas *gas = btd_service_get_user_data(service); char addr[18]; bt_uuid_t gap_uuid; + int err = 0; ba2str(device_get_address(device), addr); DBG("GAP profile accept (%s)", addr); if (!gas) { error("GAP service not handled by profile"); - return -1; + err = -1; + goto _finish; } gas->db = gatt_db_ref(db); @@ -285,12 +281,14 @@ static int gap_accept(struct btd_service *service) if (!gas->attr) { error("GAP attribute not found"); gas_reset(gas); - return -1; + err = -1; } - btd_service_connecting_complete(service, 0); +_finish: - return 0; + btd_service_connecting_complete(service, err); + + return err; } static int gap_disconnect(struct btd_service *service) From patchwork Fri May 10 15:09:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 13661724 Received: from mail-yb1-f174.google.com (mail-yb1-f174.google.com [209.85.219.174]) (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 BBFDC17108A for ; Fri, 10 May 2024 15:09:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715353785; cv=none; b=XEuOulRu10FHg+Oapn5Of5rWsQIhMh2fnPUplRWEuSueo9D+zcsHZuPJCTbARUF7EsZrnz0bWkz0QLUcv/T/xjL5eV8rUu+VmrtzluOyeL5LxX3Z9LDtzeSfE7ypQ758/lblCTQeUwflE1NWdaiw2+baFBTALm2ws8ke/rPUHgc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715353785; c=relaxed/simple; bh=rlrNutOX/JtzQ2vvYouzl+ju8rzQd9ExsU6WNCQAOKQ=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QipZMLZ+GlzDJV+owmUoyk0Cm4cc3vThm7FjSs77ecyDu7X1JpJND4/tn6IokPKr/5EbNS1hhqU8XUm9Iezkgon/VSCfw1ZhgBiYbtibpInCEyHsCcYqtIsCKibNHnFiGthsIQ0fFonm+Q3YBweGfaU6KLwozehZACPu/7R6GQc= 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=COloPPDO; arc=none smtp.client-ip=209.85.219.174 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="COloPPDO" Received: by mail-yb1-f174.google.com with SMTP id 3f1490d57ef6-dcd7c526cc0so2339356276.1 for ; Fri, 10 May 2024 08:09:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715353782; x=1715958582; 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=+NYPamNuvUWNaKXtsTZIVx1vuT1dcpKc6L70cng3uqM=; b=COloPPDOFfzze7ik19N28aVRjxl5Mnlp16V80gVpf6OW9JPqJdCp0mNMlnzQEhtQCW vtegHRwiCd2E9s3Hfsp8/96HyM0BeKIzYQn2YQ7x3iY9H6XtHogk0FdiWTI214bw9cQ9 IP9NZlX3P3L2yPyc9hIDCPWb7pF+Dni0R5k7mrdh1OS92aT7aPLUz6XI/pK5fs6RFImT PnV5kazNdAglBW5AipNq6AfVz6EorKrwMSR6/Y0KEeKv+EOLXil5ClQvK6e0i7oAaEQB zhH7f8V5h/GxcAiGBFm6PbsxObCzzrNBIavufP/1TPeaXXe0WkwIABO87oGJIgaI4OBe Hfjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715353782; x=1715958582; 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=+NYPamNuvUWNaKXtsTZIVx1vuT1dcpKc6L70cng3uqM=; b=JDQlTz7Sx1rNnHEEZFZASjgB6dSjXZFddV6xs4esfXFFSCMZz/MgXB4X6Tc1CNhr02 d2uMjjBwNYEOI3HwDkIS/tGldQdNTwwdPOG5Q0p+wZTqehcLf+UTOinwodf7C7JR+60Y 30k7toRfeE2peRlaZSAl+cL/rLOkfXdEjaIubz6geofSgzbiRq+M619ZSeWCx0PdFFQi I4dAvrJCrlyTzgg/cQU/eTGy1dy8klBvd4vdVaeDuY7VlcPVCapWR0ATbW7t4Ajf928h nHv6xPugrBh/DUgM5kKjN9wJbxXZ1lOzn1osGrm54NyNQ2SoUZxG+1kFtnudWFdeJ0Zx 8XQw== X-Gm-Message-State: AOJu0YyWKO/OV2Tz7gC3dqcGOdXesPavAPqEufsoWmPZ5wQDAvfexCXU KgVC+ND5pjJxy16P+8FvYPXQUc+8+a6XoI4OVRtiMVcUgv8kksIqa99yqg== X-Google-Smtp-Source: AGHT+IF4o0wpXSuGWG8Y59SAyEPgZD2rs8AZ79lpjOK39mjjUACda6H5Uw0s67r4FCvVL5lLdb6rdw== X-Received: by 2002:a25:b985:0:b0:de6:168f:f2d7 with SMTP id 3f1490d57ef6-dee4f4ee845mr3064185276.55.1715353781886; Fri, 10 May 2024 08:09:41 -0700 (PDT) Received: from lvondent-mobl4.. (syn-107-146-107-067.res.spectrum.com. [107.146.107.67]) by smtp.gmail.com with ESMTPSA id ada2fe7eead31-4806cb008d2sm510050137.2.2024.05.10.08.09.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 May 2024 08:09:40 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v3 2/4] src/adapter: Added connection parameter load/store functions Date: Fri, 10 May 2024 11:09:36 -0400 Message-ID: <20240510150938.1492169-2-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240510150938.1492169-1-luiz.dentz@gmail.com> References: <20240510150938.1492169-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 From: "Felipe F. Tonello" It is interesting to let other parts of bluetoothd to access these functions since there are few different use-cases where this updating and loading connection parameters can happen. --- src/adapter.c | 34 +++++++++++++++++++++++++++++----- src/adapter.h | 10 ++++++++++ 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/src/adapter.c b/src/adapter.c index 5505edbb29c1..4943e5e88e70 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -4635,6 +4635,30 @@ static void load_conn_params(struct btd_adapter *adapter, GSList *params) btd_error(adapter->dev_id, "Load connection parameters failed"); } +void btd_adapter_load_conn_param(struct btd_adapter *adapter, + const bdaddr_t *peer, uint8_t bdaddr_type, + uint16_t min_interval, uint16_t max_interval, + uint16_t latency, uint16_t timeout) +{ + GSList *params = NULL; + struct conn_param param; + + /* Only versions >= 1.23 support updating connection parameters */ + if (MGMT_VERSION(mgmt_version, mgmt_revision) >= MGMT_VERSION(1, 23)) + return; + + bacpy(¶m.bdaddr, peer); + param.bdaddr_type = bdaddr_type; + param.max_interval = max_interval; + param.min_interval = min_interval; + param.latency = latency; + param.timeout = timeout; + + params = g_slist_append(params, ¶m); + load_conn_params(adapter, params); + g_slist_free(params); +} + static uint8_t get_addr_type(GKeyFile *keyfile) { uint8_t addr_type; @@ -8919,10 +8943,10 @@ static void new_irk_callback(uint16_t index, uint16_t length, btd_device_set_temporary(device, false); } -static void store_conn_param(struct btd_adapter *adapter, const bdaddr_t *peer, - uint8_t bdaddr_type, uint16_t min_interval, - uint16_t max_interval, uint16_t latency, - uint16_t timeout) +void btd_adapter_store_conn_param(struct btd_adapter *adapter, + const bdaddr_t *peer, uint8_t bdaddr_type, + uint16_t min_interval, uint16_t max_interval, + uint16_t latency, uint16_t timeout) { char device_addr[18]; char filename[PATH_MAX]; @@ -9002,7 +9026,7 @@ static void new_conn_param(uint16_t index, uint16_t length, if (!ev->store_hint) return; - store_conn_param(adapter, &ev->addr.bdaddr, ev->addr.type, + btd_adapter_store_conn_param(adapter, &ev->addr.bdaddr, ev->addr.type, ev->min_interval, ev->max_interval, ev->latency, ev->timeout); } diff --git a/src/adapter.h b/src/adapter.h index 2ca045539ec0..3534986f5a72 100644 --- a/src/adapter.h +++ b/src/adapter.h @@ -289,3 +289,13 @@ bool btd_adapter_set_allowed_uuids(struct btd_adapter *adapter, struct queue *uuids); bool btd_adapter_is_uuid_allowed(struct btd_adapter *adapter, const char *uuid_str); + +void btd_adapter_load_conn_param(struct btd_adapter *adapter, + const bdaddr_t *peer, uint8_t bdaddr_type, + uint16_t min_interval, uint16_t max_interval, + uint16_t latency, uint16_t timeout); + +void btd_adapter_store_conn_param(struct btd_adapter *adapter, + const bdaddr_t *peer, uint8_t bdaddr_type, + uint16_t min_interval, uint16_t max_interval, + uint16_t latency, uint16_t timeout); From patchwork Fri May 10 15:09:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 13661725 Received: from mail-vs1-f42.google.com (mail-vs1-f42.google.com [209.85.217.42]) (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 E70CA12C461 for ; Fri, 10 May 2024 15:09:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.217.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715353788; cv=none; b=JbcMWP7J6imV5Rm+alOnLNfMsqJV1mz9Z8M/RKIL+kjuZsTEeS9mqH+JHEnvpSClWUufZeUrWiDB+1sPZVgMepApUHzw0EazZ3F99BZ7hHizpKapwFJ8zPJqo3BQFxnpMW/nOzxbb4BvNxL5GqeOZCKonGScCtcb/Pzp0TGhz3A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715353788; c=relaxed/simple; bh=r1e3m+SC67CxdbKKtB6zGOqy77llkSSYc1HvO0DmPto=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VL6dhFVXfZadVCRzS0M0gK1We1qYBEHDtLG8dYqIUbBV9/L261Pyb0NqJWNgFWTwouB37d9jiEbcsjB5S1HbiJiOCPfd+smCWXNOWVv7BYjMOaAq7n3/brGjWmZDTeOyYiDvlf9vzN8JKjW9RnaBrhtGVuwanymY2S6LS0k8mLw= 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=NgV6mV7k; arc=none smtp.client-ip=209.85.217.42 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NgV6mV7k" Received: by mail-vs1-f42.google.com with SMTP id ada2fe7eead31-47ef8c9991dso693185137.0 for ; Fri, 10 May 2024 08:09:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715353785; x=1715958585; 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=cxLUKbT3DbD9tsa3QsZdPm56fC8E9csEVljefspOnh4=; b=NgV6mV7kbVa1F+YqpgA5ygikH+Dpy+thllgLFLgrQDUjKmV+HXvX+zDNcns8syjcYq PCbKXe9bxqPsEvjaFm3gdPkmLUTBEChi+eaPd7kFS1C0V510jfycyapTSJHXSCaDQrYy V1jbWNvHsVXPddCG7ojad2OJZua/8xqHxuq+W5w30deGvA85WKK4u8R2ib0zUCw3XSl9 uNSbJwbc7Nm6SxJLKKrZjqYGQxmq+i07Tb0JMj3t2fvDX1m7nd4K7fMlaCDRLsLzJPCt xjBdLHQcYfQdSO2EpP8jC6TnsiXgL4nM1j61du+QwfDLpYmFxuEVzSz7tsXQW/n+OgfQ Ptdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715353785; x=1715958585; 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=cxLUKbT3DbD9tsa3QsZdPm56fC8E9csEVljefspOnh4=; b=BRXBYNgMibywxopKGSCPPkaw7ZzNd2BXIH49RbwtPzGUc3QbMbWaqIpdoZKW18tzcO fQKzRCcTQbDihgPR1I3e8zEJ4DeYqEYXtq7WtOZNIIOiCMVoYXguiyRGqzv0bf8qbs2M rbKJfiwjgjMxS/xVxmKwYOGFLziHN5iaOEk4WAbnDJoVyH7vgv5s3vWB6MkxvoQcWYS6 FPG+7/nQIACPEJTDbvH0O6ZKqv8aX4igbTOdPUIKA7Q6UK5IUe+21fuj52YDd1sXyvsv wgrVEvlkMsj8k7cPaZTJbe/Jx/q8KtcJZ1HzJvZvP+KlhOelToJVsqFKXIpAR2ITbvBS Thtg== X-Gm-Message-State: AOJu0YxDX5DJUGBv9gAHBBwU/kn5TS0M6YG4ald1DJhcdsKPTvSaKNp6 FzYIPa00x4r87gxc3+kKCTGQbAyqa1SGzBdfDkNs9l0kdgSthbDoFS+kpg== X-Google-Smtp-Source: AGHT+IFAGh3XqAAitM8u4Be9+vccYVwww+04UhHx5mf+HSAdc7TsRELGsTu32RM+DbnlpY/CCAFwsA== X-Received: by 2002:a05:6102:1628:b0:47f:251c:61df with SMTP id ada2fe7eead31-48077e5d7abmr3496928137.27.1715353783736; Fri, 10 May 2024 08:09:43 -0700 (PDT) Received: from lvondent-mobl4.. (syn-107-146-107-067.res.spectrum.com. [107.146.107.67]) by smtp.gmail.com with ESMTPSA id ada2fe7eead31-4806cb008d2sm510050137.2.2024.05.10.08.09.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 May 2024 08:09:42 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v3 3/4] src/device: Added function to set connection parameters Date: Fri, 10 May 2024 11:09:37 -0400 Message-ID: <20240510150938.1492169-3-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240510150938.1492169-1-luiz.dentz@gmail.com> References: <20240510150938.1492169-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 From: "Felipe F. Tonello" This function allows plugins to set the connection parameters of the respective btd_device object. It is useful for GAP Peripheral Preferred Connection Parameters characteristic for example. --- src/device.c | 14 ++++++++++++++ src/device.h | 3 +++ 2 files changed, 17 insertions(+) diff --git a/src/device.c b/src/device.c index 1d4b8ab36720..79d8bb7ebc9b 100644 --- a/src/device.c +++ b/src/device.c @@ -7322,3 +7322,17 @@ void btd_device_foreach_ad(struct btd_device *dev, bt_ad_func_t func, { bt_ad_foreach_data(dev->ad, func, data); } + +void btd_device_set_conn_param(struct btd_device *device, uint16_t min_interval, + uint16_t max_interval, uint16_t latency, + uint16_t timeout) +{ + btd_adapter_store_conn_param(device->adapter, &device->bdaddr, + device->bdaddr_type, min_interval, + max_interval, latency, + timeout); + btd_adapter_load_conn_param(device->adapter, &device->bdaddr, + device->bdaddr_type, min_interval, + max_interval, latency, + timeout); +} diff --git a/src/device.h b/src/device.h index 5722ca9cafe0..1a9f7e72a00f 100644 --- a/src/device.h +++ b/src/device.h @@ -204,3 +204,6 @@ typedef void (*bt_device_ad_func_t)(void *data, void *user_data); void btd_device_foreach_ad(struct btd_device *dev, bt_device_ad_func_t func, void *data); +void btd_device_set_conn_param(struct btd_device *device, uint16_t min_interval, + uint16_t max_interval, uint16_t latency, + uint16_t timeout); From patchwork Fri May 10 15:09:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 13661726 Received: from mail-vk1-f182.google.com (mail-vk1-f182.google.com [209.85.221.182]) (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 A40FE17108A for ; Fri, 10 May 2024 15:09:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715353789; cv=none; b=MZUEI7xU3Vu3Hp07HdQb1BxWcAvgG1pPxt9SLfi1k2p7cZdPWJIOgmJ6+l5Q5wuE2v2ZoeY+80MPVJ1wEoaji/8I4j6VnDmDBCycyBgHstnRnySVaRkdH4NVyE/BuixzHstT+4D4pPmiw1gvv1QhQjMpixLZTDOSuT/zJtZCTnw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715353789; c=relaxed/simple; bh=VpBIqUpo+QLnRCHMR8h3+FEQs4JEgsZ6vfhrhHL9L2M=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EC2APF6LKcavv2bR+mkrp8g6/NvgF4012O7ot0N484Anv4ZYYbUsJcSwO+T9W08wE9Ulw32Ul/NVyAbwxgjXo7fJD+BLPzD5T6c1IYN1BiR91opapNuFPUux4Q6top08PXGO0C8IeXQA8Rngm/+sxJHX+fadCohLtKQeGr4lfGI= 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=W+XAT2LC; arc=none smtp.client-ip=209.85.221.182 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="W+XAT2LC" Received: by mail-vk1-f182.google.com with SMTP id 71dfb90a1353d-4df76f2e3easo646415e0c.2 for ; Fri, 10 May 2024 08:09:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715353786; x=1715958586; 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=5niJWmnTMJaWwLIzMOhrQKyuU/mu4Trq6xMfwRJ+dDA=; b=W+XAT2LCAeLHwOVSKjWmgoATYUvmDt7rNThcMatSnpeeTCvH4TDA3dzRpZJn2ZxiDy sjU4oQIzCJoRfzBo3WxfJj0dFoZPyHgrpKyv9kV7VpzLaYMAV1/sDjSxZoGqf48K4Jez lbSd1kNy7keAZ8nfM1mwnE8hzd7G1EllVGEeTJmDPatn9M/8hxt5R+4EeQZG8LyCs+OJ 7aDFHUsFAUY0bzPm42GUIQiTG/SqDxmU+Wk72MXtW3ruV7Iac0Y+Kk3M/l6U/h/nic3V nOfBLkBGjVRG6gGpKogwyBMACZT3oiabF/p7VcvCtVVSB61orkJRg3DBh/sF0+7HYfy3 18IA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715353786; x=1715958586; 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=5niJWmnTMJaWwLIzMOhrQKyuU/mu4Trq6xMfwRJ+dDA=; b=Q7oY/ymvgcmgld+pCf1lVx93B4Otl0hXcTTd+EfPzws0OHj/upmITKUkgHRtvITr2e pLd+vSEtdGUjkXI/khIIE9qxkrCtERxoWEC/PdE5+QIrcGqLfVSuPqA8kD1g3yVTR4Tc DsPrP9CxE7sRs/kabjspxz89mHM2kQoRIIRarRM4/xF4i6/OlKlnEkCfCY1HTCO/JHD1 lDQYERsKQkTjcHfgvoHqziWc1do3yGahZoQouY78ZDi98o33zoluDlZdmSH6Jq7Etq5d aMIiEyOs8llf75wyy9UbQ6VW9U8pDIaaBeY5juCWykvib2GfW+wXTC22nfE4SRlpy8MR mEsg== X-Gm-Message-State: AOJu0YxO3WusypDPbPksxh2iluxFCG6cFfG71eAx3DRD9NfsRaxb0k99 le86iL6bxQC7ahALkqm++gAaRZwrx/rKiat7wxWIzk1QQdKovC93Ugnbdw== X-Google-Smtp-Source: AGHT+IEj3cVFgL2UsPrOHIojk91SymtWmIru7PSpq7Q+eVK58+pCVFho7XH7Kae2Kv6uysSkj6GEIg== X-Received: by 2002:a05:6102:e14:b0:47c:1cce:c465 with SMTP id ada2fe7eead31-48077ce81e1mr3370077137.0.1715353784960; Fri, 10 May 2024 08:09:44 -0700 (PDT) Received: from lvondent-mobl4.. (syn-107-146-107-067.res.spectrum.com. [107.146.107.67]) by smtp.gmail.com with ESMTPSA id ada2fe7eead31-4806cb008d2sm510050137.2.2024.05.10.08.09.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 May 2024 08:09:44 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v3 4/4] profiles/gap: Added support for PPCP characteristic Date: Fri, 10 May 2024 11:09:38 -0400 Message-ID: <20240510150938.1492169-4-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240510150938.1492169-1-luiz.dentz@gmail.com> References: <20240510150938.1492169-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 From: "Felipe F. Tonello" The Peripheral Preferred Connection Parameters (PPCP) characteristic contains the preferred connection parameters of a peripheral device. These parameters are stored in the info file and loaded to Kernel using MGMT's respective command. --- profiles/gap/gas.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/profiles/gap/gas.c b/profiles/gap/gas.c index 713b9aaf28f2..b50a9c03acd1 100644 --- a/profiles/gap/gas.c +++ b/profiles/gap/gas.c @@ -160,6 +160,75 @@ static void handle_appearance(struct gas *gas, uint16_t value_handle) DBG("Failed to send request to read appearance"); } +static void read_ppcp_cb(bool success, uint8_t att_ecode, + const uint8_t *value, uint16_t length, + void *user_data) +{ + struct gas *gas = user_data; + uint16_t min_interval, max_interval, latency, timeout, max_latency; + + if (!success) { + DBG("Reading PPCP failed with ATT error: %u", att_ecode); + return; + } + + if (length != 8) { + DBG("Malformed PPCP value"); + return; + } + + min_interval = get_le16(&value[0]); + max_interval = get_le16(&value[2]); + latency = get_le16(&value[4]); + timeout = get_le16(&value[6]); + + DBG("GAP Peripheral Preferred Connection Parameters:"); + DBG("\tMinimum connection interval: %u", min_interval); + DBG("\tMaximum connection interval: %u", max_interval); + DBG("\tSlave latency: %u", latency); + DBG("\tConnection Supervision timeout multiplier: %u", timeout); + + /* 0xffff indicates no specific min/max */ + if (min_interval == 0xffff) + min_interval = 6; + + if (max_interval == 0xffff) + max_interval = 3200; + + /* avoid persisting connection parameters that are not valid */ + if (min_interval > max_interval || + min_interval < 6 || max_interval > 3200) { + warn("GAS PPCP: Invalid Connection Parameters values"); + return; + } + + if (timeout < 10 || timeout > 3200) { + warn("GAS PPCP: Invalid Connection Parameters values"); + return; + } + + if (max_interval >= timeout * 8) { + warn("GAS PPCP: Invalid Connection Parameters values"); + return; + } + + max_latency = (timeout * 4 / max_interval) - 1; + if (latency > 499 || latency > max_latency) { + warn("GAS PPCP: Invalid Connection Parameters values"); + return; + } + + btd_device_set_conn_param(gas->device, min_interval, max_interval, + latency, timeout); +} + +static void handle_ppcp(struct gas *gas, uint16_t value_handle) +{ + if (!bt_gatt_client_read_value(gas->client, value_handle, + read_ppcp_cb, gas, NULL)) + DBG("Failed to send request to read PPCP"); +} + static inline bool uuid_cmp(uint16_t u16, const bt_uuid_t *uuid) { bt_uuid_t lhs; @@ -186,6 +255,8 @@ static void handle_characteristic(struct gatt_db_attribute *attr, handle_device_name(gas, value_handle); else if (uuid_cmp(GATT_CHARAC_APPEARANCE, &uuid)) handle_appearance(gas, value_handle); + else if (uuid_cmp(GATT_CHARAC_PERIPHERAL_PREF_CONN, &uuid)) + handle_ppcp(gas, value_handle); else { char uuid_str[MAX_LEN_UUID_STR];