Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp97143pxu; Wed, 14 Oct 2020 21:36:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxDLgDk9/ijye5lnl2XI9vzrmgpTGuh0iLY6vOLQ4eJWZym9mGKkCAHMA5JoFGJzxJHFNtA X-Received: by 2002:a50:d517:: with SMTP id u23mr2404696edi.338.1602736603618; Wed, 14 Oct 2020 21:36:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602736603; cv=none; d=google.com; s=arc-20160816; b=fpxCW7OHepKBec77GdB+xZUkAq3S4NJ8nvhSZwaZptv1ZRXKlKyDPZWNSejLu74yo7 3HzE0oyMLZsuN6A+TXysLgMS3saOLaGat4I0Hvj7/OAivByX3dWBKUvrcoGFTfet+AQj 120GpfCtWTICHo8gBSdBkTj0C3Ugm7KCcfQwEFPzy+rUk2Ch/WwPywtNqjUPi4EFQEx+ xRwDDrdi2hdqAuXH33cobUAdmN5vqqPyqpKSm6NCudHfVjs34VO4UHVeDcDlfmGd6AL2 eYbjSd1Rcyo2ME1tw/xyK7BPE9ZusQZncm8LuYoEgECfFD62lf0a7Qmo3g9AYOuLtuFG BzYA== 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:mime-version:message-id:date :sender:dkim-signature; bh=VddAilhiX9vbfsCCLvwTZsI/t6AmhTB8NhYP+fqRMC4=; b=P0XRgwW/V1TbpNyV4z9hWS0OTT369CLv4dwXhdOieZwSm47IsDu6uwfsElWW/46wYo iYMYdkmZv+qVScaSkVwWT2FfMk1WFsiH6M1Kzy0ox9LMifLrtuPwVvlWHc6uFCqp6nKC hrvUbhP+AY9nuG54AXRLXvtge10jbqFZkO4GJaBou1W284+CjhYlJHABG9ATkXTxlMw9 C2jhTWbpSqlzo0rEKuq2djmKDD+brCKkhal9KCVgW8IVqsTkREPkmnamFkFNS7zKy2bQ eMOfkhQaMoreJ4o5vw/URuPWiscKyuX1brhxkzg1zJGetXdi7Va0gn5bFZzLqYgGeIMi 74cA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="byyeEQ/B"; 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 cy11si1152490edb.227.2020.10.14.21.36.18; Wed, 14 Oct 2020 21:36:43 -0700 (PDT) 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="byyeEQ/B"; 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 S1729521AbgJODYy (ORCPT + 99 others); Wed, 14 Oct 2020 23:24:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727200AbgJODYy (ORCPT ); Wed, 14 Oct 2020 23:24:54 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E21C5C0613D3 for ; Wed, 14 Oct 2020 20:24:53 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id k9so1574175ybf.18 for ; Wed, 14 Oct 2020 20:24:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:message-id:mime-version:subject:from:to:cc; bh=VddAilhiX9vbfsCCLvwTZsI/t6AmhTB8NhYP+fqRMC4=; b=byyeEQ/BwJD64Hq3awYswDEdd4+hAdWL1ML4N/BrWZkvy07RQcEQ1RtIrjaEcu+CPc Q557ftnirgKfn8KkUDp0hJKfF+bjPbC1EdYXUHRdJs2ew5vaMzje9exq4yEyliqlzpz+ x6HGtyDN/3YZCplY5oVrsneHeCDJHvhEt0gXHGA4jM1XrmpFqEy+8pL7dTf4UXfz6PsU AbXtezkBpcld7em1xOXmSp7WF5NV7Pk78PxLkcjEL66XXH3HyKPNYMSWT3MGneSq1+Mg 6AKviOWXrHJn4WYl5iLqt3i1RJ9cebEl0LL+tTljiUYveGlqoP5/uYPerUil3842YTaf 07Gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:message-id:mime-version:subject:from :to:cc; bh=VddAilhiX9vbfsCCLvwTZsI/t6AmhTB8NhYP+fqRMC4=; b=URi7HAiHImj67X2BNDgzhPNUgmsy8lgZ9qy+5QtDLtsw8PYdIBPUzqafmtQv/Ym9u8 m7/pSDyADI9lTE2f36Qn83oIEYWDQIGnuYLPaONo6gOKMV7DJIdeicxLNXOqVKx0zWnz pQ80cy+co189/kpCDk1WfwR49uEM2yWwt+IehPOtmtu0UpzGKxA9wbnAfOqfnC5HTjFU 3YqdswDeBtRqcftg1htXcxow69qu3jUu5WfRtYIu036oTmVqUWhKabuLeu2EFvMnAV/l +dl97J+GFkIcirByJBpK+GR1IUbBAd214rN3RjmyhZr2iWzRvBETJtm+WF3Bq0fNYHyI EeEg== X-Gm-Message-State: AOAM530LEwtYfBg2rlnRg+X2ty9fYPOn/yJAK3y+AD6AgrOQYSzaG2BG iW1tSf8ZT39SvUubwAFOUYXVeuXaiOSaaN4eXDE7KNAL4oYl8HhQR+t0IMeL9Yl2cx9kwXUM+0+ ernS2RTpA+wZTZqsQt3BiSEJWr0KdqICJchgOtctt71ed/EQIiaIhfn/uNht/UtPZ7VSyZxdB/g APfLB6SvCigWY= 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:a25:6c46:: with SMTP id h67mr563767ybc.171.1602732292966; Wed, 14 Oct 2020 20:24:52 -0700 (PDT) Date: Thu, 15 Oct 2020 11:24:47 +0800 Message-Id: <20201015112443.1.I9231b35b0be815c32c3a3ec48dcd1d68fa65daf4@changeid> Mime-Version: 1.0 X-Mailer: git-send-email 2.29.0.rc1.297.gfa9743e501-goog Subject: [PATCH] mgmt: Add supports of variable length parameter in mgmt_config From: Howard Chung To: linux-bluetooth@vger.kernel.org Cc: mcchou@chromium.org, marcel@holtmann.org, mmandlik@chromium.org, alainm@chromium.org, apusaka@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 This adds support of variable length parameter in mgmt_config. Signed-off-by: Howard Chung Reviewed-by: Alain Michaud --- net/bluetooth/mgmt_config.c | 134 +++++++++++++++++++++--------------- 1 file changed, 80 insertions(+), 54 deletions(-) diff --git a/net/bluetooth/mgmt_config.c b/net/bluetooth/mgmt_config.c index b30b571f8caf8..1e3cbeacb09b4 100644 --- a/net/bluetooth/mgmt_config.c +++ b/net/bluetooth/mgmt_config.c @@ -11,70 +11,96 @@ #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(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); + } __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), }; - 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.0.rc1.297.gfa9743e501-goog