Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3030627pxb; Mon, 9 Nov 2020 00:00:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJw5EtljTgA2Dnl/mU4CtA3mnSHgnJ60AJUKHee/0aZjatndLPrTb7oWv9Sx7tgq0Sn+xbh9 X-Received: by 2002:a17:906:3a55:: with SMTP id a21mr13652446ejf.357.1604908816293; Mon, 09 Nov 2020 00:00:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604908816; cv=none; d=google.com; s=arc-20160816; b=mCUYzIOewPNhFeIAS81+0It5VBj2FYDGKCD2NRNErjpnhMvUsL+J5Z19SnmNVSowu4 m752rHaofH31D/N0sEmte0CM7Fq8yP/kFSm2uWcSSGQZMcXoOg3IPn4tWDp9EJP2bdmJ zhGLfcQrLL0OrPZK6bhMRShOEKliYEcSU7/giNlrE5QrfAkEW9Ulx6a0Mf+rpT9fCbZQ /ICxCi+6mDUABVJyLgGj/LlgTDDQrVa0S+VSjzHo+4FGdBvnw3htTXdAYux2BBNDdZYi ufa/o79K0eR78Ktr4Xh552tfFYAs064m1/icN1OYV1Tx0a5AhV+Oj7wwZbYpONV0TngM Arhw== 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=O4Vdvs4gs6fv/dABG14CW8ji62lq3ZykXhH4Ino64SY=; b=eRR6CycFcShiZcwPh1hc9akhnF20SnUpxj6PybYblHRWX2aCbcADNtEPdQUb3trP6C 4CQu4MpUNzQ7tnmmmzPQJ/osd1rK5ssVmUmihOwle+jcWHjs3OgnSnuG1VvAwBDFImlr XPHVWa+9cq1aUcpigMGGXPBia+AvumkWtKxvk18bI97diOw5Qig+vIuaFLTrhDkylQ7a 3OKH7Qe9S4u0JyCGpfkJ3aQewOoGPA6mJndOVgxBfaYWzyOMJISeXY/X3avbjVxKbE64 0tbA0NYGTC3x/dwjbQ/qsUkMb8l+xV34t3eVV6S8WiqnSh3MCz9ZOZP2gjQ0Sf0MOcyE +vsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="H/kwDC0p"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-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 k25si7600767ejk.65.2020.11.08.23.59.53; Mon, 09 Nov 2020 00:00:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-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="H/kwDC0p"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-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 S1729738AbgKIH5s (ORCPT + 99 others); Mon, 9 Nov 2020 02:57:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729777AbgKIH5r (ORCPT ); Mon, 9 Nov 2020 02:57:47 -0500 Received: from mail-qv1-xf49.google.com (mail-qv1-xf49.google.com [IPv6:2607:f8b0:4864:20::f49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F36EC0613CF for ; Sun, 8 Nov 2020 23:57:47 -0800 (PST) Received: by mail-qv1-xf49.google.com with SMTP id 12so5012343qvr.8 for ; Sun, 08 Nov 2020 23:57:47 -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=O4Vdvs4gs6fv/dABG14CW8ji62lq3ZykXhH4Ino64SY=; b=H/kwDC0pmsvgy052BOqSSz6q89DPMl+Ot3RC7ktvClnghvtiLyt/avgoi/RHbj4aqU C6gZH+5TWtFcCosSn8dhTPvJUB89nr9H+ITCz8jX/8OfRM/O5TYP4e86ZI1BNfT32ur+ jEL7rNULoFUq/3IBXVb9opDbqQWktpi87iDAruwOYwQFOs38Bsf+84w8HaaFEnTiSY0R dl31fPXX4dS64nd2bl9P4SPW1ayDJyRIMvlj+NejdFY60UwzVm9LqrXTEixHfgqWkgwI Q4dQkvVnkOw12cqYMc/KULqgDA0+SzmjGa1O2rLYXNE9MOPGT0XrUeESq9GZhkxyFZl2 DAEw== 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=O4Vdvs4gs6fv/dABG14CW8ji62lq3ZykXhH4Ino64SY=; b=U2UpFdLA2dy1zoUy2SYJAdwuFkXB1seYnobBZcKPnJD8OS6OEp0Pz4T/1CvIEMdcRQ dyT+LJgwz5imStxA1rsczNem/PHgv2Q0jnRAs74yj9+jNsZAd1B0Tt1JoSRMUd++sQFr /a44XFyqMyLBtJnqN9RAlB8E0yaUPEhmiGTjlCy3uz+3rlS1FjeFjscgJ8WqX41sLauU sTsPxcQIqByR/AHWME0uId7aTFoDeWA/i6uir1LziA+kI3XXWy/gPWeZH+m6bFlPsWKk hyWLWH7cZQQYQZG/CgNpqitXTz4Mj8LB846654msbWxJh0t5aY1GTgiVRXTkV4cDKQ1s qurg== X-Gm-Message-State: AOAM530tCygiQ1v2lreM4qhlgyAEn1pDEtJmI6TnzXsa96dqzyB/6DmF GEl9Gc7UHH3LXBgqXrPhPMBYS7P5u4UMuCge+A== 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:4105:: with SMTP id i5mr12882317qvp.47.1604908666286; Sun, 08 Nov 2020 23:57:46 -0800 (PST) Date: Mon, 9 Nov 2020 15:57:25 +0800 In-Reply-To: <20201109155659.v7.1.Ib75f58e90c477f9b82c5598f00c59f0e95a1a352@changeid> Message-Id: <20201109155659.v7.4.I9231b35b0be815c32c3a3ec48dcd1d68fa65daf4@changeid> Mime-Version: 1.0 References: <20201109155659.v7.1.Ib75f58e90c477f9b82c5598f00c59f0e95a1a352@changeid> X-Mailer: git-send-email 2.29.2.222.g5d2a92d10f8-goog Subject: [PATCH v7 4/5] mgmt: Add supports of variable length parameter in mgmt_config From: Howard Chung To: linux-bluetooth@vger.kernel.org, marcel@holtmann.org, luiz.dentz@gmail.com Cc: mmandlik@chromium.org, alainm@chromium.org, mcchou@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-kernel@vger.kernel.org This adds support of variable length parameter in mgmt_config. Signed-off-by: Howard Chung --- (no changes since v1) 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..b735e59c7fd51 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