Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3878696pxb; Tue, 10 Nov 2020 02:22:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJxv9iFXSXnVmMRxIt8xt7l6VXALBlqLPLEyIzeZ4QlOruyUHVfmmk89JOlw74U6OkuO+j8L X-Received: by 2002:a05:6402:1115:: with SMTP id u21mr6657164edv.148.1605003734933; Tue, 10 Nov 2020 02:22:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605003734; cv=none; d=google.com; s=arc-20160816; b=Iau7AvFkybZdNUT/vVfcZNvhcCPGhDe53by8gNoyZNf9IEutyQSfINSGbxNjfAnwyD eIv9Q7dKWoObnJ5lt9KhxLzhVWGdAT4jk57tNKjIfSMUPRFr+5nXjO5gq4+Vb44W2ql7 /2NFsZK/wKS7Zlaf7AvPBx8g5yCIyjpS1jwDmjeqyn6TvtcOHlOVjAUQ8Nv62p/ZhJ5K /HswoURoVmfDTRtzzN4HdRbehGilX1m9vBMPF6ttJimESysS5P/WnIDcD7pue9shi2pp kQQ/pkM0K8ihE2NAl0sGgEPubU0izRuFJfFfxZVyumPGkLXRi3KerOxgBg471Sqo/ylv zAhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:sender:dkim-signature; bh=ng9DznihbQUkFPdna2vLl5VrTCi12IJEIBLO5x+5mHI=; b=faFXaUjYm8S/si3ZxRVXg/ZiIFlEK0xKyDDHem1gkj93+3y7lWwqTl4f1tiXmMbDYP H50x1S6hQUhDBVB0vuyPKhP704BxaYbxAVYYSMm9WhOPQmZH9ONbJmLUSUHVnPzELThL VCvAxk82fb44bn6G3evhDqTAJZzdnXjKD1qbqa9X6fNwB7O1Mw0SSUC2snQ+WTV8tRJV kphLcavBclEryOlwvCQ1/zvCoAjX2hGM+LzyzLmTCGO/SlXnOuFYYsc3y0aR688/Gsgb qUVzWW8byzn9QKrb+OmS4ujD5F2PSYfJ/n1pZTbDsX0zHR2TwLFUKiNl1qYENyBTJTcg 01Vw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ETGfwhm8; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m8si9268254edj.357.2020.11.10.02.21.50; Tue, 10 Nov 2020 02:22:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ETGfwhm8; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730893AbgKJKS6 (ORCPT + 99 others); Tue, 10 Nov 2020 05:18:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730505AbgKJKS5 (ORCPT ); Tue, 10 Nov 2020 05:18:57 -0500 Received: from mail-qt1-x84a.google.com (mail-qt1-x84a.google.com [IPv6:2607:f8b0:4864:20::84a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 12016C0613D1 for ; Tue, 10 Nov 2020 02:18:57 -0800 (PST) Received: by mail-qt1-x84a.google.com with SMTP id i20so7115986qtr.0 for ; Tue, 10 Nov 2020 02:18:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=ng9DznihbQUkFPdna2vLl5VrTCi12IJEIBLO5x+5mHI=; b=ETGfwhm8wmwbQFEBMthnHCpx0/T6RBXir36T/twL1eQvmmwlBFOyl2GvqYgtXuFSxH nfQXo1G92+RA9xV9/OH2AYDQLjQ8Z4qWZCMjuV0F1/JB0MCVboeY0VUxnNAUxXftVjbU +Yf+d+XZB9lVv+134lRRzPX/nHZHi4kxdmram0TzOB3ZSEX4qB0EWr8YPmQXwj76a/50 E0WylOARkbriv3UzNeuwnHCXj6lVEEDFO3Zme/YsupPyKtlfAdAU26sz5/8RyYo3Nsus bRcdYqO1HlxLJo03E72oLLqrE/h2Q5knZvw6mdkI9HvYgvshqGTcvwVr6DFYXEscQLzp mzXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=ng9DznihbQUkFPdna2vLl5VrTCi12IJEIBLO5x+5mHI=; b=GZaqZhR76Abm0KtlDk/OPnCMHMfqayaiF+6YZAkC6PZ57Wlmi+fwyU9cl/sxUShE9o CkFps/awsV087nWIifXmd5x/8Awjh88vpPO4eapGZfLKXbflS7fYT8EP4A82z9Slwmxk T30VeN0VToN9/OKjGG//ZyGoWULXU47wSlqGq7n92h5mrCyex94BKSGj2A5gbtd1IrWB Zb/j7FLHQ0I4Hn8OLavyXcPKgbmRUNpvi5nG+JBbivfIjgc9vkLso4RuncceTrIas5i5 rWeDohu3eqKnIBkCOmjoqLKwrxVAEptXsGvdewXwHD+MfV0PZFfKTdsVxQzLmq+qAKEr YZGA== X-Gm-Message-State: AOAM532trazQv6qCu0EVRkCBCFE0TcHJpdL6DYOeSO0KIn1OpPXhO2yh c9G2Me9cnV06/I7pqU00WDCXt96qso2cu+vNCGWqMgrL5A/ORMD9PSxK6bwGHdIgiCr9v78bIMz CvaRsOcDEhLr8lPp+X3LLHpfMJeL09InTtDW1mvY4OISnC11xhks2Dja4IXGr6OGEqnAvaQfvNH 373dGS2A8jbxc= Sender: "howardchung via sendgmr" X-Received: from howardchung-p920.tpe.corp.google.com ([2401:fa00:1:10:f693:9fff:fef4:4e45]) (user=howardchung job=sendgmr) by 2002:ad4:5807:: with SMTP id dd7mr18821000qvb.35.1605003535685; Tue, 10 Nov 2020 02:18:55 -0800 (PST) Date: Tue, 10 Nov 2020 18:17:54 +0800 In-Reply-To: <20201110181740.v8.1.I55fa38874edc240d726c1de6e82b2ce57b64f5eb@changeid> Message-Id: <20201110181740.v8.5.I9231b35b0be815c32c3a3ec48dcd1d68fa65daf4@changeid> Mime-Version: 1.0 References: <20201110181740.v8.1.I55fa38874edc240d726c1de6e82b2ce57b64f5eb@changeid> X-Mailer: git-send-email 2.29.2.222.g5d2a92d10f8-goog Subject: [PATCH v8 5/6] Bluetooth: Refactor read default sys config for various types From: Howard Chung To: linux-bluetooth@vger.kernel.org, marcel@holtmann.org, luiz.dentz@gmail.com Cc: mmandlik@chromium.org, mcchou@chromium.org, alainm@chromium.org, Howard Chung , "David S. Miller" , Jakub Kicinski , Johan Hedberg , linux-kernel@vger.kernel.org, netdev@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Refactor read default system configuration function so that it's capable of returning different types than u16 Signed-off-by: Howard Chung --- Changes in v8: - Update the commit title and message net/bluetooth/mgmt_config.c | 140 +++++++++++++++++++++--------------- 1 file changed, 84 insertions(+), 56 deletions(-) diff --git a/net/bluetooth/mgmt_config.c b/net/bluetooth/mgmt_config.c index 2d3ad288c78ac..282fbf82f3192 100644 --- a/net/bluetooth/mgmt_config.c +++ b/net/bluetooth/mgmt_config.c @@ -11,72 +11,100 @@ #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_) } \ -} +#define HDEV_PARAM_U16(_param_name_) \ + struct {\ + struct mgmt_tlv entry; \ + __le16 value; \ + } __packed _param_name_ -#define HDEV_PARAM_U16_JIFFIES_TO_MSECS(_param_code_, _param_name_) \ -{ \ - { cpu_to_le16(_param_code_), sizeof(__u16) }, \ - { cpu_to_le16(jiffies_to_msecs(hdev->_param_name_)) } \ -} +#define TLV_SET_U16(_param_code_, _param_name_) \ + { \ + { cpu_to_le16(_param_code_), sizeof(__u16) }, \ + cpu_to_le16(hdev->_param_name_) \ + } + +#define TLV_SET_U16_JIFFIES_TO_MSECS(_param_code_, _param_name_) \ + { \ + { cpu_to_le16(_param_code_), sizeof(__u16) }, \ + cpu_to_le16(jiffies_to_msecs(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[] = { + int ret; + struct mgmt_rp_read_def_system_config { /* 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), - HDEV_PARAM_U16_JIFFIES_TO_MSECS(0x001b, - def_le_autoconnect_timeout), - HDEV_PARAM_U16(0x001d, advmon_allowlist_duration), - HDEV_PARAM_U16(0x001e, advmon_no_filter_duration), + HDEV_PARAM_U16(def_page_scan_type); + HDEV_PARAM_U16(def_page_scan_int); + HDEV_PARAM_U16(def_page_scan_window); + HDEV_PARAM_U16(def_inq_scan_type); + HDEV_PARAM_U16(def_inq_scan_int); + HDEV_PARAM_U16(def_inq_scan_window); + HDEV_PARAM_U16(def_br_lsto); + HDEV_PARAM_U16(def_page_timeout); + HDEV_PARAM_U16(sniff_min_interval); + HDEV_PARAM_U16(sniff_max_interval); + HDEV_PARAM_U16(le_adv_min_interval); + HDEV_PARAM_U16(le_adv_max_interval); + HDEV_PARAM_U16(def_multi_adv_rotation_duration); + HDEV_PARAM_U16(le_scan_interval); + HDEV_PARAM_U16(le_scan_window); + HDEV_PARAM_U16(le_scan_int_suspend); + HDEV_PARAM_U16(le_scan_window_suspend); + HDEV_PARAM_U16(le_scan_int_discovery); + HDEV_PARAM_U16(le_scan_window_discovery); + HDEV_PARAM_U16(le_scan_int_adv_monitor); + HDEV_PARAM_U16(le_scan_window_adv_monitor); + HDEV_PARAM_U16(le_scan_int_connect); + HDEV_PARAM_U16(le_scan_window_connect); + HDEV_PARAM_U16(le_conn_min_interval); + HDEV_PARAM_U16(le_conn_max_interval); + HDEV_PARAM_U16(le_conn_latency); + HDEV_PARAM_U16(le_supv_timeout); + HDEV_PARAM_U16(def_le_autoconnect_timeout); + HDEV_PARAM_U16(advmon_allowlist_duration); + HDEV_PARAM_U16(advmon_no_filter_duration); + } __packed rp = { + TLV_SET_U16(0x0000, def_page_scan_type), + TLV_SET_U16(0x0001, def_page_scan_int), + TLV_SET_U16(0x0002, def_page_scan_window), + TLV_SET_U16(0x0003, def_inq_scan_type), + TLV_SET_U16(0x0004, def_inq_scan_int), + TLV_SET_U16(0x0005, def_inq_scan_window), + TLV_SET_U16(0x0006, def_br_lsto), + TLV_SET_U16(0x0007, def_page_timeout), + TLV_SET_U16(0x0008, sniff_min_interval), + TLV_SET_U16(0x0009, sniff_max_interval), + TLV_SET_U16(0x000a, le_adv_min_interval), + TLV_SET_U16(0x000b, le_adv_max_interval), + TLV_SET_U16(0x000c, def_multi_adv_rotation_duration), + TLV_SET_U16(0x000d, le_scan_interval), + TLV_SET_U16(0x000e, le_scan_window), + TLV_SET_U16(0x000f, le_scan_int_suspend), + TLV_SET_U16(0x0010, le_scan_window_suspend), + TLV_SET_U16(0x0011, le_scan_int_discovery), + TLV_SET_U16(0x0012, le_scan_window_discovery), + TLV_SET_U16(0x0013, le_scan_int_adv_monitor), + TLV_SET_U16(0x0014, le_scan_window_adv_monitor), + TLV_SET_U16(0x0015, le_scan_int_connect), + TLV_SET_U16(0x0016, le_scan_window_connect), + TLV_SET_U16(0x0017, le_conn_min_interval), + TLV_SET_U16(0x0018, le_conn_max_interval), + TLV_SET_U16(0x0019, le_conn_latency), + TLV_SET_U16(0x001a, le_supv_timeout), + TLV_SET_U16_JIFFIES_TO_MSECS(0x001b, + def_le_autoconnect_timeout), + TLV_SET_U16(0x001d, advmon_allowlist_duration), + TLV_SET_U16(0x001e, advmon_no_filter_duration), }; - 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)); + ret = mgmt_cmd_complete(sk, hdev->id, + MGMT_OP_READ_DEF_SYSTEM_CONFIG, + 0, &rp, sizeof(rp)); + return ret; } #define TO_TLV(x) ((struct mgmt_tlv *)(x)) -- 2.29.2.222.g5d2a92d10f8-goog