From patchwork Thu Jun 11 02:01:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alain Michaud X-Patchwork-Id: 11599119 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 82975618 for ; Thu, 11 Jun 2020 02:02:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6AC1C2072F for ; Thu, 11 Jun 2020 02:02:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="n48McVKc" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726306AbgFKCCF (ORCPT ); Wed, 10 Jun 2020 22:02:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57676 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726265AbgFKCCE (ORCPT ); Wed, 10 Jun 2020 22:02:04 -0400 Received: from mail-vs1-xe41.google.com (mail-vs1-xe41.google.com [IPv6:2607:f8b0:4864:20::e41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8955FC08C5C1 for ; Wed, 10 Jun 2020 19:02:04 -0700 (PDT) Received: by mail-vs1-xe41.google.com with SMTP id y123so2509083vsb.6 for ; Wed, 10 Jun 2020 19:02:04 -0700 (PDT) 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=4gX5gEjaAhk+Yg1HTNrJsp+Drp+hSN+9K/wcCOjy1ow=; b=n48McVKc1gbG6gCedoSb9KXhbQldd7w8g+rbDnruuJJafGw4HlJMT1q8iJ/PK8RD5l 95tGaPTZrrpMaddjnpkXvmj2ul8Fjlkx1/1kQtUMlUnMYXpPMMM5CEZoFarnfUGDxy/p l0nxttdikMSNpjxYgku7zq1+XxQLlsz4Nwi6c= 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=4gX5gEjaAhk+Yg1HTNrJsp+Drp+hSN+9K/wcCOjy1ow=; b=VIt6rt9FxQVFThmIwHCHeYkDjAGeUUM/jMKpPamG/9LTUZGjKnN15dzUGiA4jydgYa BSUPk+a2MbZFaS4OAMGFxb64Q1/oASqnKTMm/PBLIrtlkQ7PymD4We/WBxzGb7z24I78 2yK/LLq+2tawGQ6J7800qWLusLa4FHi4fgdLNHx9X6WX5XLLzoVs2Su8edPuuA6/tOgM UpwXaR/GyBVzkepih68H2TTO5Is7gWmZCnJ2qfbwVhtXAxLQz3bAQtwIDJ3+yltMvBNY sPxTB3A47rfF6BuxZzl7GhlfnIDF4mrnJNND0jZtj7H4MDCTWZseR4ZYCrsS7INdxCtR ptJg== X-Gm-Message-State: AOAM533T9B50PqFlPwQbHptU9z+1R+yUivmROJntlkN+9QG73Sy67er2 YX9ZrPNtoe6DaNHZbadhym3PuZJkxE4= X-Google-Smtp-Source: ABdhPJwXb7mBN1gnfSkpRn3XyZfzv84gmJOkhIbBRH6c86mTPBPseSrDYV7kGCId50gOMQ55cXlshA== X-Received: by 2002:a67:fc0b:: with SMTP id o11mr4820672vsq.114.1591840923496; Wed, 10 Jun 2020 19:02:03 -0700 (PDT) Received: from alain.c.googlers.com.com (252.177.243.35.bc.googleusercontent.com. [35.243.177.252]) by smtp.gmail.com with ESMTPSA id r17sm243197vsi.34.2020.06.10.19.02.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jun 2020 19:02:03 -0700 (PDT) From: Alain Michaud To: linux-bluetooth@vger.kernel.org Cc: Alain Michaud , Abhishek Pandit-Subedi , Yu Liu Subject: [PATCH v3 1/3] mgmt: read/set system parameter definitions Date: Thu, 11 Jun 2020 02:01:55 +0000 Message-Id: <20200611020157.70230-2-alainm@chromium.org> X-Mailer: git-send-email 2.27.0.290.gba653c62da-goog In-Reply-To: <20200611020157.70230-1-alainm@chromium.org> References: <20200611020157.70230-1-alainm@chromium.org> MIME-Version: 1.0 Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This patch submits the corresponding kernel definitions to mgmt.h. This is submitted before the implementation to avoid any conflicts in values allocations. Reviewed-by: Abhishek Pandit-Subedi Reviewed-by: Yu Liu Signed-off-by: Alain Michaud --- Changes in v3: - Fixed sparse errors Changes in v2: - Renamed the mgmt.h per Marcel's comments. - Addressed Marcel's comments in the implementation. include/net/bluetooth/mgmt.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/include/net/bluetooth/mgmt.h b/include/net/bluetooth/mgmt.h index 16e0d87bd8fa..09452d2ea6d3 100644 --- a/include/net/bluetooth/mgmt.h +++ b/include/net/bluetooth/mgmt.h @@ -702,6 +702,36 @@ struct mgmt_rp_set_exp_feature { __le32 flags; } __packed; +#define MGMT_OP_READ_DEF_SYSTEM_CONFIG 0x004b + +struct mgmt_tlv { + __u16 type; + __u8 length; + __u8 value[]; +} __packed; + +struct mgmt_rp_read_default_system_config { + __u8 parameters[0]; /* mgmt_tlv */ +} __packed; + +#define MGMT_OP_SET_DEF_SYSTEM_CONFIG 0x004c + +struct mgmt_cp_set_default_system_config { + __u8 parameters[0]; /* mgmt_tlv */ +} __packed; + +#define MGMT_OP_READ_DEF_RUNTIME_CONFIG 0x004d + +struct mgmt_rp_read_default_runtime_config { + __u8 parameters[0]; /* mgmt_tlv */ +} __packed; + +#define MGMT_OP_SET_DEF_RUNTIME_CONFIG 0x004e + +struct mgmt_cp_set_default_runtime_config { + __u8 parameters[0]; /* mgmt_tlv */ +} __packed; + #define MGMT_EV_CMD_COMPLETE 0x0001 struct mgmt_ev_cmd_complete { __le16 opcode; From patchwork Thu Jun 11 02:01:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alain Michaud X-Patchwork-Id: 11599121 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 26A78618 for ; Thu, 11 Jun 2020 02:02:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 076BB2074B for ; Thu, 11 Jun 2020 02:02:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="GXeWewl2" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726316AbgFKCCJ (ORCPT ); Wed, 10 Jun 2020 22:02:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726265AbgFKCCJ (ORCPT ); Wed, 10 Jun 2020 22:02:09 -0400 Received: from mail-vs1-xe43.google.com (mail-vs1-xe43.google.com [IPv6:2607:f8b0:4864:20::e43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0082C08C5C1 for ; Wed, 10 Jun 2020 19:02:08 -0700 (PDT) Received: by mail-vs1-xe43.google.com with SMTP id k13so2483306vsm.13 for ; Wed, 10 Jun 2020 19:02:08 -0700 (PDT) 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=D01zfZvVT9ayynEW2qHT1584F41pNqtWD96+bPHij7U=; b=GXeWewl2azDZ8z+kw0STlBsAtwPf/RiUjdwbzbXC+mgA0FERL+2M8+V42g/sEHs7BJ 4qIbuA2qamJpkNGHIcp2tTOxAB+8IV3bWTysMrO5zI6U7NtOW8KB21Pxd+a+L++kC/fy 4/uoGyd4/b7VsBGehda0TbOq7UifT0i64akEI= 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=D01zfZvVT9ayynEW2qHT1584F41pNqtWD96+bPHij7U=; b=IxpbYfj3ENSle5ECDnPyiJzBzwGy+mlISBp4M+NEN9tqay0rkpVJ8z+8Xaxf+JAY49 zUORrvRciHMsqo8Xk5FtonBm8zHdZfsQGgk6uMA8XJveKWCJAzoJDmeB4pM7tlm2kpFt teeunO3/B2BZQvIbLtRzThO2+2iJsZ0DftjkhVhwJMlSJVC6010gSG6TvPOQQKM1X9/B hQoeTTwSxLjfv6E64td6C3chomTQDkZm6IOzuD/Vybv/wC/Dc6z2VD1b8i5vYI9wLhS4 TckStd4vnLU+1VqtxhVQZl6Q8voSKffugGYPUcTW0CtxPWuvEBoKZIX1Q6nnGBn5EBed gGcQ== X-Gm-Message-State: AOAM5315cPdpmBo5VMiFIZuUxAUTIEK6cU+4CnUQqGZMe1eXc/muzL3G VCq8/JA6QWq7AbwdlyOzcY/azlxTQWk= X-Google-Smtp-Source: ABdhPJyGhD8qdCsvqmx5mITKah21E4cx51s6j/yKU5pAhQR0YmuiBsE/wJcVO4zP8uPaK3fjQGKNbg== X-Received: by 2002:a67:2ecc:: with SMTP id u195mr4992519vsu.32.1591840927903; Wed, 10 Jun 2020 19:02:07 -0700 (PDT) Received: from alain.c.googlers.com.com (252.177.243.35.bc.googleusercontent.com. [35.243.177.252]) by smtp.gmail.com with ESMTPSA id r17sm243197vsi.34.2020.06.10.19.02.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jun 2020 19:02:07 -0700 (PDT) From: Alain Michaud To: linux-bluetooth@vger.kernel.org Cc: Alain Michaud , Abhishek Pandit-Subedi Subject: [PATCH v3 2/3] bluetooth:centralize default value initialization. Date: Thu, 11 Jun 2020 02:01:56 +0000 Message-Id: <20200611020157.70230-3-alainm@chromium.org> X-Mailer: git-send-email 2.27.0.290.gba653c62da-goog In-Reply-To: <20200611020157.70230-1-alainm@chromium.org> References: <20200611020157.70230-1-alainm@chromium.org> MIME-Version: 1.0 Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This patch centralized the initialization of default parameters. This is required to allow clients to more easily customize the default system parameters. Reviewed-by: Abhishek Pandit-Subedi Signed-off-by: Alain Michaud --- Changes in v3: None Changes in v2: None include/net/bluetooth/hci_core.h | 18 ++++++++++++++++++ net/bluetooth/hci_conn.c | 14 ++++---------- net/bluetooth/hci_core.c | 14 +++++++++++++- net/bluetooth/hci_request.c | 15 +++++---------- 4 files changed, 40 insertions(+), 21 deletions(-) diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h index cdd4f1db8670..0d5dbb6cb5a0 100644 --- a/include/net/bluetooth/hci_core.h +++ b/include/net/bluetooth/hci_core.h @@ -295,6 +295,14 @@ struct hci_dev { __u8 le_scan_type; __u16 le_scan_interval; __u16 le_scan_window; + __u16 le_scan_int_suspend; + __u16 le_scan_window_suspend; + __u16 le_scan_int_discovery; + __u16 le_scan_window_discovery; + __u16 le_scan_int_adv_monitor; + __u16 le_scan_window_adv_monitor; + __u16 le_scan_int_connect; + __u16 le_scan_window_connect; __u16 le_conn_min_interval; __u16 le_conn_max_interval; __u16 le_conn_latency; @@ -323,6 +331,16 @@ struct hci_dev { __u16 devid_product; __u16 devid_version; + __u8 def_page_scan_type; + __u16 def_page_scan_int; + __u16 def_page_scan_window; + __u8 def_inq_scan_type; + __u16 def_inq_scan_int; + __u16 def_inq_scan_window; + __u16 def_br_lsto; + __u16 def_page_timeout; + __u16 def_multi_adv_rotation_duration; + __u16 pkt_type; __u16 esco_type; __u16 link_policy; diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c index 307800fd18e6..9bdffc4e79b0 100644 --- a/net/bluetooth/hci_conn.c +++ b/net/bluetooth/hci_conn.c @@ -789,11 +789,8 @@ static void set_ext_conn_params(struct hci_conn *conn, memset(p, 0, sizeof(*p)); - /* Set window to be the same value as the interval to - * enable continuous scanning. - */ - p->scan_interval = cpu_to_le16(hdev->le_scan_interval); - p->scan_window = p->scan_interval; + p->scan_interval = cpu_to_le16(hdev->le_scan_int_connect); + p->scan_window = cpu_to_le16(hdev->le_scan_window_connect); p->conn_interval_min = cpu_to_le16(conn->le_conn_min_interval); p->conn_interval_max = cpu_to_le16(conn->le_conn_max_interval); p->conn_latency = cpu_to_le16(conn->le_conn_latency); @@ -875,11 +872,8 @@ static void hci_req_add_le_create_conn(struct hci_request *req, memset(&cp, 0, sizeof(cp)); - /* Set window to be the same value as the interval to enable - * continuous scanning. - */ - cp.scan_interval = cpu_to_le16(hdev->le_scan_interval); - cp.scan_window = cp.scan_interval; + cp.scan_interval = cpu_to_le16(hdev->le_scan_int_connect); + cp.scan_window = cpu_to_le16(hdev->le_scan_window_connect); bacpy(&cp.peer_addr, &conn->dst); cp.peer_addr_type = conn->dst_type; diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index dbe2d79f233f..122e44a82995 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -2982,7 +2982,7 @@ int hci_add_adv_instance(struct hci_dev *hdev, u8 instance, u32 flags, adv_instance->remaining_time = timeout; if (duration == 0) - adv_instance->duration = HCI_DEFAULT_ADV_DURATION; + adv_instance->duration = hdev->def_multi_adv_rotation_duration; else adv_instance->duration = duration; @@ -3397,6 +3397,12 @@ struct hci_dev *hci_alloc_dev(void) hdev->le_adv_max_interval = 0x0800; hdev->le_scan_interval = 0x0060; hdev->le_scan_window = 0x0030; + hdev->le_scan_int_suspend = 0x0400; + hdev->le_scan_window_suspend = 0x0012; + hdev->le_scan_int_discovery = DISCOV_LE_SCAN_INT; + hdev->le_scan_window_discovery = DISCOV_LE_SCAN_WIN; + hdev->le_scan_int_connect = 0x0060; + hdev->le_scan_window_connect = 0x0060; hdev->le_conn_min_interval = 0x0018; hdev->le_conn_max_interval = 0x0028; hdev->le_conn_latency = 0x0000; @@ -3412,6 +3418,7 @@ struct hci_dev *hci_alloc_dev(void) hdev->le_tx_def_phys = HCI_LE_SET_PHY_1M; hdev->le_rx_def_phys = HCI_LE_SET_PHY_1M; hdev->le_num_of_adv_sets = HCI_MAX_ADV_INSTANCES; + hdev->def_multi_adv_rotation_duration = HCI_DEFAULT_ADV_DURATION; hdev->rpa_timeout = HCI_DEFAULT_RPA_TIMEOUT; hdev->discov_interleaved_timeout = DISCOV_INTERLEAVED_TIMEOUT; @@ -3420,6 +3427,11 @@ struct hci_dev *hci_alloc_dev(void) hdev->auth_payload_timeout = DEFAULT_AUTH_PAYLOAD_TIMEOUT; hdev->min_enc_key_size = HCI_MIN_ENC_KEY_SIZE; + /* default 1.28 sec page scan */ + hdev->def_page_scan_type = PAGE_SCAN_TYPE_STANDARD; + hdev->def_page_scan_int = 0x0800; + hdev->def_page_scan_window = 0x0012; + mutex_init(&hdev->lock); mutex_init(&hdev->req_lock); diff --git a/net/bluetooth/hci_request.c b/net/bluetooth/hci_request.c index 1acf5b8e0910..a7f572ad38ef 100644 --- a/net/bluetooth/hci_request.c +++ b/net/bluetooth/hci_request.c @@ -34,9 +34,6 @@ #define HCI_REQ_PEND 1 #define HCI_REQ_CANCELED 2 -#define LE_SUSPEND_SCAN_WINDOW 0x0012 -#define LE_SUSPEND_SCAN_INTERVAL 0x0400 - void hci_req_init(struct hci_request *req, struct hci_dev *hdev) { skb_queue_head_init(&req->cmd_q); @@ -366,13 +363,11 @@ void __hci_req_write_fast_connectable(struct hci_request *req, bool enable) /* 160 msec page scan interval */ acp.interval = cpu_to_le16(0x0100); } else { - type = PAGE_SCAN_TYPE_STANDARD; /* default */ - - /* default 1.28 sec page scan */ - acp.interval = cpu_to_le16(0x0800); + type = hdev->def_page_scan_type; + acp.interval = cpu_to_le16(hdev->def_page_scan_int); } - acp.window = cpu_to_le16(0x0012); + acp.window = cpu_to_le16(hdev->def_page_scan_window); if (__cpu_to_le16(hdev->page_scan_interval) != acp.interval || __cpu_to_le16(hdev->page_scan_window) != acp.window) @@ -927,8 +922,8 @@ void hci_req_add_le_passive_scan(struct hci_request *req) filter_policy |= 0x02; if (hdev->suspended) { - window = LE_SUSPEND_SCAN_WINDOW; - interval = LE_SUSPEND_SCAN_INTERVAL; + window = hdev->le_scan_window_suspend; + interval = hdev->le_scan_int_suspend; } else { window = hdev->le_scan_window; interval = hdev->le_scan_interval; From patchwork Thu Jun 11 02:01:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alain Michaud X-Patchwork-Id: 11599123 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B73F9618 for ; Thu, 11 Jun 2020 02:02:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9346F2074B for ; Thu, 11 Jun 2020 02:02:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="mzt80IS1" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726326AbgFKCCM (ORCPT ); Wed, 10 Jun 2020 22:02:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726265AbgFKCCL (ORCPT ); Wed, 10 Jun 2020 22:02:11 -0400 Received: from mail-ua1-x943.google.com (mail-ua1-x943.google.com [IPv6:2607:f8b0:4864:20::943]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4EA6AC08C5C1 for ; Wed, 10 Jun 2020 19:02:11 -0700 (PDT) Received: by mail-ua1-x943.google.com with SMTP id r9so1590972ual.1 for ; Wed, 10 Jun 2020 19:02:11 -0700 (PDT) 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=FLFvPEigKr9PpL6vxpEbUm6uPyP0CzOIQ7N51gILAYo=; b=mzt80IS1frNwnI9Wkeezxn4BRSCFtZK+VrjExROfvwB4W8Gz/dT2MnVsaEQUjWRhJ7 HmD2j423caTw8faEi1KMTjg532U+rAav8TsCEjL9xBrLRk0+yGiYHYe2ZmqaS3UR0/uD 5uaNPCkbRi+gZ2ras7EfFSTzULoZnX8YL4Hhw= 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=FLFvPEigKr9PpL6vxpEbUm6uPyP0CzOIQ7N51gILAYo=; b=Z+Qquo9Q3t82P93+fNco7AaqoE4Swg7No3cGfILKz0QBOtzJKi5iyCGZ97dsXh1pCw 8m7urZP2XBKd48Az9T6mJAzJ1E7qffwZdm7XIIgMvmLkR5eki2J/UUrMFQKCRUFfXyEa GmDkXnsa5kx3JQjQB32d1jv9xCJv1JA7Yxj7eaKY4wMmvsInQWLNnHAKZbX8BYHKjf/K /axkthkfFaTVhJioUfE3IyWGpOhffGdiiWIFwJCHyf/KRAUmUtHSF2/vrd/vKkavmeac 3H6TrQ3fhTC5qQO39ugWBH+OalL5fSZvamO4otCL97+1L9yAakv4h7HFcLwqIPGKIZgh NjTQ== X-Gm-Message-State: AOAM531swh9mjDLMGxfAIzS21hW2RrVFoGBrCi1O+mTrx+zUOTMW5urx 4qOYckXMBix/xnHKFWGJioOA2PYDIkw= X-Google-Smtp-Source: ABdhPJyjTlB2byU4b21TQLtEQBU9nOOOSNHcDGy0Gq0QetVkj8TSerwSMypHdDdnK8hYuannqFn70w== X-Received: by 2002:ab0:7202:: with SMTP id u2mr4447342uao.119.1591840930019; Wed, 10 Jun 2020 19:02:10 -0700 (PDT) Received: from alain.c.googlers.com.com (252.177.243.35.bc.googleusercontent.com. [35.243.177.252]) by smtp.gmail.com with ESMTPSA id r17sm243197vsi.34.2020.06.10.19.02.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jun 2020 19:02:09 -0700 (PDT) From: Alain Michaud To: linux-bluetooth@vger.kernel.org Cc: Alain Michaud , Abhishek Pandit-Subedi , kernel test robot Subject: [PATCH v3 3/3] bluetooth: implement read/set default system parameters mgmt Date: Thu, 11 Jun 2020 02:01:57 +0000 Message-Id: <20200611020157.70230-4-alainm@chromium.org> X-Mailer: git-send-email 2.27.0.290.gba653c62da-goog In-Reply-To: <20200611020157.70230-1-alainm@chromium.org> References: <20200611020157.70230-1-alainm@chromium.org> MIME-Version: 1.0 Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This patch implements the read default system parameters and the set default system parameters mgmt commands. Reviewed-by: Abhishek Pandit-Subedi Reported-by: kernel test robot Signed-off-by: Alain Michaud --- Changes in v3: -Fixing sparse errors Changes in v2: None include/net/bluetooth/mgmt.h | 2 +- net/bluetooth/Makefile | 2 +- net/bluetooth/mgmt.c | 6 + net/bluetooth/mgmt_config.c | 253 +++++++++++++++++++++++++++++++++++ net/bluetooth/mgmt_config.h | 11 ++ 5 files changed, 272 insertions(+), 2 deletions(-) create mode 100644 net/bluetooth/mgmt_config.c create mode 100644 net/bluetooth/mgmt_config.h diff --git a/include/net/bluetooth/mgmt.h b/include/net/bluetooth/mgmt.h index 09452d2ea6d3..39e849744f28 100644 --- a/include/net/bluetooth/mgmt.h +++ b/include/net/bluetooth/mgmt.h @@ -705,7 +705,7 @@ struct mgmt_rp_set_exp_feature { #define MGMT_OP_READ_DEF_SYSTEM_CONFIG 0x004b struct mgmt_tlv { - __u16 type; + __le16 type; __u8 length; __u8 value[]; } __packed; diff --git a/net/bluetooth/Makefile b/net/bluetooth/Makefile index 41dd541a44a5..1c645fba8c49 100644 --- a/net/bluetooth/Makefile +++ b/net/bluetooth/Makefile @@ -14,7 +14,7 @@ bluetooth_6lowpan-y := 6lowpan.o bluetooth-y := af_bluetooth.o hci_core.o hci_conn.o hci_event.o mgmt.o \ hci_sock.o hci_sysfs.o l2cap_core.o l2cap_sock.o smp.o lib.o \ - ecdh_helper.o hci_request.o mgmt_util.o + ecdh_helper.o hci_request.o mgmt_util.o mgmt_config.o bluetooth-$(CONFIG_BT_BREDR) += sco.o bluetooth-$(CONFIG_BT_HS) += a2mp.o amp.o diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c index 9e8a3cccc6ca..69cd4f756a0d 100644 --- a/net/bluetooth/mgmt.c +++ b/net/bluetooth/mgmt.c @@ -36,6 +36,7 @@ #include "hci_request.h" #include "smp.h" #include "mgmt_util.h" +#include "mgmt_config.h" #define MGMT_VERSION 1 #define MGMT_REVISION 17 @@ -111,6 +112,8 @@ static const u16 mgmt_commands[] = { MGMT_OP_READ_SECURITY_INFO, MGMT_OP_READ_EXP_FEATURES_INFO, MGMT_OP_SET_EXP_FEATURE, + MGMT_OP_READ_DEF_SYSTEM_CONFIG, + MGMT_OP_SET_DEF_SYSTEM_CONFIG, }; static const u16 mgmt_events[] = { @@ -162,6 +165,7 @@ static const u16 mgmt_untrusted_commands[] = { MGMT_OP_READ_EXT_INFO, MGMT_OP_READ_SECURITY_INFO, MGMT_OP_READ_EXP_FEATURES_INFO, + MGMT_OP_READ_DEF_SYSTEM_CONFIG, }; static const u16 mgmt_untrusted_events[] = { @@ -7297,6 +7301,8 @@ static const struct hci_mgmt_handler mgmt_handlers[] = { { set_exp_feature, MGMT_SET_EXP_FEATURE_SIZE, HCI_MGMT_VAR_LEN | HCI_MGMT_HDEV_OPTIONAL }, + { read_def_system_config, 0, HCI_MGMT_UNTRUSTED }, + { set_def_system_config, 0, HCI_MGMT_VAR_LEN }, }; void mgmt_index_added(struct hci_dev *hdev) diff --git a/net/bluetooth/mgmt_config.c b/net/bluetooth/mgmt_config.c new file mode 100644 index 000000000000..f6dfbe93542c --- /dev/null +++ b/net/bluetooth/mgmt_config.c @@ -0,0 +1,253 @@ +// SPDX-License-Identifier: GPL-2.0-only + +/* + * Copyright (C) 2020 Google Corporation + */ + +#include +#include +#include + +#include "mgmt_util.h" +#include "mgmt_config.h" + +#define HDEV_PARAM_U16(_param_code_, _param_name_) \ +{ \ + { cpu_to_le16(_param_code_), sizeof(__u16) }, \ + { cpu_to_le16(hdev->_param_name_) } \ +} + +int read_def_system_config(struct sock *sk, struct hci_dev *hdev, void *data, + u16 data_len) +{ + struct { + struct mgmt_tlv entry; + union { + /* This is a simplification for now since all values + * are 16 bits. In the future, this code may need + * refactoring to account for variable length values + * and properly calculate the required buffer size. + */ + __le16 value; + }; + } __packed params[] = { + /* Please see mgmt-api.txt for documentation of these values */ + HDEV_PARAM_U16(0x0000, def_page_scan_type), + HDEV_PARAM_U16(0x0001, def_page_scan_int), + HDEV_PARAM_U16(0x0002, def_page_scan_window), + HDEV_PARAM_U16(0x0003, def_inq_scan_type), + HDEV_PARAM_U16(0x0004, def_inq_scan_int), + HDEV_PARAM_U16(0x0005, def_inq_scan_window), + HDEV_PARAM_U16(0x0006, def_br_lsto), + HDEV_PARAM_U16(0x0007, def_page_timeout), + HDEV_PARAM_U16(0x0008, sniff_min_interval), + HDEV_PARAM_U16(0x0009, sniff_max_interval), + HDEV_PARAM_U16(0x000a, le_adv_min_interval), + HDEV_PARAM_U16(0x000b, le_adv_max_interval), + HDEV_PARAM_U16(0x000c, def_multi_adv_rotation_duration), + HDEV_PARAM_U16(0x000d, le_scan_interval), + HDEV_PARAM_U16(0x000e, le_scan_window), + HDEV_PARAM_U16(0x000f, le_scan_int_suspend), + HDEV_PARAM_U16(0x0010, le_scan_window_suspend), + HDEV_PARAM_U16(0x0011, le_scan_int_discovery), + HDEV_PARAM_U16(0x0012, le_scan_window_discovery), + HDEV_PARAM_U16(0x0013, le_scan_int_adv_monitor), + HDEV_PARAM_U16(0x0014, le_scan_window_adv_monitor), + HDEV_PARAM_U16(0x0015, le_scan_int_connect), + HDEV_PARAM_U16(0x0016, le_scan_window_connect), + HDEV_PARAM_U16(0x0017, le_conn_min_interval), + HDEV_PARAM_U16(0x0018, le_conn_max_interval), + HDEV_PARAM_U16(0x0019, le_conn_latency), + HDEV_PARAM_U16(0x001a, le_supv_timeout), + }; + struct mgmt_rp_read_def_system_config *rp = (void *)params; + + bt_dev_dbg(hdev, "sock %p", sk); + + return mgmt_cmd_complete(sk, hdev->id, + MGMT_OP_READ_DEF_SYSTEM_CONFIG, + 0, rp, sizeof(params)); +} + +#define TO_TLV(x) ((struct mgmt_tlv *)(x)) +#define TLV_GET_LE16(tlv) le16_to_cpu(*((__le16 *)(TO_TLV(tlv)->value))) + +int set_def_system_config(struct sock *sk, struct hci_dev *hdev, void *data, + u16 data_len) +{ + u16 buffer_left = data_len; + u8 *buffer = data; + + if (buffer_left < sizeof(struct mgmt_tlv)) { + return mgmt_cmd_status(sk, hdev->id, + MGMT_OP_SET_DEF_SYSTEM_CONFIG, + MGMT_STATUS_INVALID_PARAMS); + } + + /* First pass to validate the tlv */ + while (buffer_left >= sizeof(struct mgmt_tlv)) { + const u8 len = TO_TLV(buffer)->length; + const u16 exp_len = sizeof(struct mgmt_tlv) + + len; + const u16 type = le16_to_cpu(TO_TLV(buffer)->type); + + if (buffer_left < exp_len) { + bt_dev_warn(hdev, "invalid len left %d, exp >= %d", + buffer_left, exp_len); + + return mgmt_cmd_status(sk, hdev->id, + MGMT_OP_SET_DEF_SYSTEM_CONFIG, + MGMT_STATUS_INVALID_PARAMS); + } + + /* Please see mgmt-api.txt for documentation of these values */ + switch (type) { + case 0x0000: + case 0x0001: + case 0x0002: + case 0x0003: + case 0x0004: + case 0x0005: + case 0x0006: + case 0x0007: + case 0x0008: + case 0x0009: + case 0x000a: + case 0x000b: + case 0x000c: + case 0x000d: + case 0x000e: + case 0x000f: + case 0x0010: + case 0x0011: + case 0x0012: + case 0x0013: + case 0x0014: + case 0x0015: + case 0x0016: + case 0x0017: + case 0x0018: + case 0x0019: + case 0x001a: + if (len != sizeof(u16)) { + bt_dev_warn(hdev, "invalid length %d, exp %zu for type %d", + len, sizeof(u16), type); + + return mgmt_cmd_status(sk, hdev->id, + MGMT_OP_SET_DEF_SYSTEM_CONFIG, + MGMT_STATUS_INVALID_PARAMS); + } + break; + default: + bt_dev_warn(hdev, "unsupported parameter %u", type); + break; + } + + buffer_left -= exp_len; + buffer += exp_len; + } + + buffer_left = data_len; + buffer = data; + while (buffer_left >= sizeof(struct mgmt_tlv)) { + const u8 len = TO_TLV(buffer)->length; + const u16 exp_len = sizeof(struct mgmt_tlv) + + len; + const u16 type = le16_to_cpu(TO_TLV(buffer)->type); + + switch (type) { + case 0x0000: + hdev->def_page_scan_type = TLV_GET_LE16(buffer); + break; + case 0x0001: + hdev->def_page_scan_int = TLV_GET_LE16(buffer); + break; + case 0x0002: + hdev->def_page_scan_window = TLV_GET_LE16(buffer); + break; + case 0x0003: + hdev->def_inq_scan_type = TLV_GET_LE16(buffer); + break; + case 0x0004: + hdev->def_inq_scan_int = TLV_GET_LE16(buffer); + break; + case 0x0005: + hdev->def_inq_scan_window = TLV_GET_LE16(buffer); + break; + case 0x0006: + hdev->def_br_lsto = TLV_GET_LE16(buffer); + break; + case 0x0007: + hdev->def_page_timeout = TLV_GET_LE16(buffer); + break; + case 0x0008: + hdev->sniff_min_interval = TLV_GET_LE16(buffer); + break; + case 0x0009: + hdev->sniff_max_interval = TLV_GET_LE16(buffer); + break; + case 0x000a: + hdev->le_adv_min_interval = TLV_GET_LE16(buffer); + break; + case 0x000b: + hdev->le_adv_max_interval = TLV_GET_LE16(buffer); + break; + case 0x000c: + hdev->def_multi_adv_rotation_duration = + TLV_GET_LE16(buffer); + break; + case 0x000d: + hdev->le_scan_interval = TLV_GET_LE16(buffer); + break; + case 0x000e: + hdev->le_scan_window = TLV_GET_LE16(buffer); + break; + case 0x000f: + hdev->le_scan_int_suspend = TLV_GET_LE16(buffer); + break; + case 0x0010: + hdev->le_scan_window_suspend = TLV_GET_LE16(buffer); + break; + case 0x0011: + hdev->le_scan_int_discovery = TLV_GET_LE16(buffer); + break; + case 0x00012: + hdev->le_scan_window_discovery = TLV_GET_LE16(buffer); + break; + case 0x00013: + hdev->le_scan_int_adv_monitor = TLV_GET_LE16(buffer); + break; + case 0x00014: + hdev->le_scan_window_adv_monitor = TLV_GET_LE16(buffer); + break; + case 0x00015: + hdev->le_scan_int_connect = TLV_GET_LE16(buffer); + break; + case 0x00016: + hdev->le_scan_window_connect = TLV_GET_LE16(buffer); + break; + case 0x00017: + hdev->le_conn_min_interval = TLV_GET_LE16(buffer); + break; + case 0x00018: + hdev->le_conn_max_interval = TLV_GET_LE16(buffer); + break; + case 0x00019: + hdev->le_conn_latency = TLV_GET_LE16(buffer); + break; + case 0x0001a: + hdev->le_supv_timeout = TLV_GET_LE16(buffer); + break; + default: + bt_dev_warn(hdev, "unsupported parameter %u", type); + break; + } + + buffer_left -= exp_len; + buffer += exp_len; + } + + return mgmt_cmd_status(sk, hdev->id, + MGMT_OP_SET_DEF_SYSTEM_CONFIG, + MGMT_STATUS_SUCCESS); +} diff --git a/net/bluetooth/mgmt_config.h b/net/bluetooth/mgmt_config.h new file mode 100644 index 000000000000..51da6e63b1a0 --- /dev/null +++ b/net/bluetooth/mgmt_config.h @@ -0,0 +1,11 @@ +// SPDX-License-Identifier: GPL-2.0-only + +/* + * Copyright (C) 2020 Google Corporation + */ + +int read_def_system_config(struct sock *sk, struct hci_dev *hdev, void *data, + u16 data_len); + +int set_def_system_config(struct sock *sk, struct hci_dev *hdev, void *data, + u16 data_len);