Message ID | 20200610200452.107406-4-alainm@chromium.org (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | Support reading and setting default system parameters | expand |
Hi Alain, Thank you for the patch! Perhaps something to improve: [auto build test WARNING on bluetooth-next/master] [also build test WARNING on next-20200610] [cannot apply to v5.7] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982] url: https://github.com/0day-ci/linux/commits/Alain-Michaud/Support-reading-and-setting-default-system-parameters/20200611-040656 base: https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git master config: x86_64-randconfig-s021-20200607 (attached as .config) compiler: gcc-9 (Debian 9.3.0-13) 9.3.0 reproduce: # apt-get install sparse # sparse version: v0.6.1-247-gcadbd124-dirty # save the attached .config to linux build tree make W=1 C=1 ARCH=x86_64 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' If you fix the issue, kindly add following tag as appropriate Reported-by: kernel test robot <lkp@intel.com> sparse warnings: (new ones prefixed by >>) >> net/bluetooth/mgmt_config.c:35:17: sparse: sparse: incorrect type in initializer (different base types) @@ expected unsigned short [usertype] value @@ got restricted __le16 [usertype] @@ >> net/bluetooth/mgmt_config.c:35:17: sparse: expected unsigned short [usertype] value >> net/bluetooth/mgmt_config.c:35:17: sparse: got restricted __le16 [usertype] net/bluetooth/mgmt_config.c:36:17: sparse: sparse: incorrect type in initializer (different base types) @@ expected unsigned short [usertype] value @@ got restricted __le16 [usertype] @@ net/bluetooth/mgmt_config.c:36:17: sparse: expected unsigned short [usertype] value net/bluetooth/mgmt_config.c:36:17: sparse: got restricted __le16 [usertype] net/bluetooth/mgmt_config.c:37:17: sparse: sparse: incorrect type in initializer (different base types) @@ expected unsigned short [usertype] value @@ got restricted __le16 [usertype] @@ net/bluetooth/mgmt_config.c:37:17: sparse: expected unsigned short [usertype] value net/bluetooth/mgmt_config.c:37:17: sparse: got restricted __le16 [usertype] net/bluetooth/mgmt_config.c:38:17: sparse: sparse: incorrect type in initializer (different base types) @@ expected unsigned short [usertype] value @@ got restricted __le16 [usertype] @@ net/bluetooth/mgmt_config.c:38:17: sparse: expected unsigned short [usertype] value net/bluetooth/mgmt_config.c:38:17: sparse: got restricted __le16 [usertype] net/bluetooth/mgmt_config.c:39:17: sparse: sparse: incorrect type in initializer (different base types) @@ expected unsigned short [usertype] value @@ got restricted __le16 [usertype] @@ net/bluetooth/mgmt_config.c:39:17: sparse: expected unsigned short [usertype] value net/bluetooth/mgmt_config.c:39:17: sparse: got restricted __le16 [usertype] net/bluetooth/mgmt_config.c:40:17: sparse: sparse: incorrect type in initializer (different base types) @@ expected unsigned short [usertype] value @@ got restricted __le16 [usertype] @@ net/bluetooth/mgmt_config.c:40:17: sparse: expected unsigned short [usertype] value net/bluetooth/mgmt_config.c:40:17: sparse: got restricted __le16 [usertype] net/bluetooth/mgmt_config.c:41:17: sparse: sparse: incorrect type in initializer (different base types) @@ expected unsigned short [usertype] value @@ got restricted __le16 [usertype] @@ net/bluetooth/mgmt_config.c:41:17: sparse: expected unsigned short [usertype] value net/bluetooth/mgmt_config.c:41:17: sparse: got restricted __le16 [usertype] net/bluetooth/mgmt_config.c:42:17: sparse: sparse: incorrect type in initializer (different base types) @@ expected unsigned short [usertype] value @@ got restricted __le16 [usertype] @@ net/bluetooth/mgmt_config.c:42:17: sparse: expected unsigned short [usertype] value net/bluetooth/mgmt_config.c:42:17: sparse: got restricted __le16 [usertype] net/bluetooth/mgmt_config.c:43:17: sparse: sparse: incorrect type in initializer (different base types) @@ expected unsigned short [usertype] value @@ got restricted __le16 [usertype] @@ net/bluetooth/mgmt_config.c:43:17: sparse: expected unsigned short [usertype] value net/bluetooth/mgmt_config.c:43:17: sparse: got restricted __le16 [usertype] net/bluetooth/mgmt_config.c:44:17: sparse: sparse: incorrect type in initializer (different base types) @@ expected unsigned short [usertype] value @@ got restricted __le16 [usertype] @@ net/bluetooth/mgmt_config.c:44:17: sparse: expected unsigned short [usertype] value net/bluetooth/mgmt_config.c:44:17: sparse: got restricted __le16 [usertype] net/bluetooth/mgmt_config.c:45:17: sparse: sparse: incorrect type in initializer (different base types) @@ expected unsigned short [usertype] value @@ got restricted __le16 [usertype] @@ net/bluetooth/mgmt_config.c:45:17: sparse: expected unsigned short [usertype] value net/bluetooth/mgmt_config.c:45:17: sparse: got restricted __le16 [usertype] net/bluetooth/mgmt_config.c:46:17: sparse: sparse: incorrect type in initializer (different base types) @@ expected unsigned short [usertype] value @@ got restricted __le16 [usertype] @@ net/bluetooth/mgmt_config.c:46:17: sparse: expected unsigned short [usertype] value net/bluetooth/mgmt_config.c:46:17: sparse: got restricted __le16 [usertype] net/bluetooth/mgmt_config.c:47:17: sparse: sparse: incorrect type in initializer (different base types) @@ expected unsigned short [usertype] value @@ got restricted __le16 [usertype] @@ net/bluetooth/mgmt_config.c:47:17: sparse: expected unsigned short [usertype] value net/bluetooth/mgmt_config.c:47:17: sparse: got restricted __le16 [usertype] net/bluetooth/mgmt_config.c:48:17: sparse: sparse: incorrect type in initializer (different base types) @@ expected unsigned short [usertype] value @@ got restricted __le16 [usertype] @@ net/bluetooth/mgmt_config.c:48:17: sparse: expected unsigned short [usertype] value net/bluetooth/mgmt_config.c:48:17: sparse: got restricted __le16 [usertype] net/bluetooth/mgmt_config.c:49:17: sparse: sparse: incorrect type in initializer (different base types) @@ expected unsigned short [usertype] value @@ got restricted __le16 [usertype] @@ net/bluetooth/mgmt_config.c:49:17: sparse: expected unsigned short [usertype] value net/bluetooth/mgmt_config.c:49:17: sparse: got restricted __le16 [usertype] net/bluetooth/mgmt_config.c:50:17: sparse: sparse: incorrect type in initializer (different base types) @@ expected unsigned short [usertype] value @@ got restricted __le16 [usertype] @@ net/bluetooth/mgmt_config.c:50:17: sparse: expected unsigned short [usertype] value net/bluetooth/mgmt_config.c:50:17: sparse: got restricted __le16 [usertype] net/bluetooth/mgmt_config.c:51:17: sparse: sparse: incorrect type in initializer (different base types) @@ expected unsigned short [usertype] value @@ got restricted __le16 [usertype] @@ net/bluetooth/mgmt_config.c:51:17: sparse: expected unsigned short [usertype] value net/bluetooth/mgmt_config.c:51:17: sparse: got restricted __le16 [usertype] net/bluetooth/mgmt_config.c:52:17: sparse: sparse: incorrect type in initializer (different base types) @@ expected unsigned short [usertype] value @@ got restricted __le16 [usertype] @@ net/bluetooth/mgmt_config.c:52:17: sparse: expected unsigned short [usertype] value net/bluetooth/mgmt_config.c:52:17: sparse: got restricted __le16 [usertype] net/bluetooth/mgmt_config.c:53:17: sparse: sparse: incorrect type in initializer (different base types) @@ expected unsigned short [usertype] value @@ got restricted __le16 [usertype] @@ net/bluetooth/mgmt_config.c:53:17: sparse: expected unsigned short [usertype] value net/bluetooth/mgmt_config.c:53:17: sparse: got restricted __le16 [usertype] net/bluetooth/mgmt_config.c:54:17: sparse: sparse: incorrect type in initializer (different base types) @@ expected unsigned short [usertype] value @@ got restricted __le16 [usertype] @@ net/bluetooth/mgmt_config.c:54:17: sparse: expected unsigned short [usertype] value net/bluetooth/mgmt_config.c:54:17: sparse: got restricted __le16 [usertype] net/bluetooth/mgmt_config.c:55:17: sparse: sparse: incorrect type in initializer (different base types) @@ expected unsigned short [usertype] value @@ got restricted __le16 [usertype] @@ net/bluetooth/mgmt_config.c:55:17: sparse: expected unsigned short [usertype] value net/bluetooth/mgmt_config.c:55:17: sparse: got restricted __le16 [usertype] net/bluetooth/mgmt_config.c:56:17: sparse: sparse: incorrect type in initializer (different base types) @@ expected unsigned short [usertype] value @@ got restricted __le16 [usertype] @@ net/bluetooth/mgmt_config.c:56:17: sparse: expected unsigned short [usertype] value net/bluetooth/mgmt_config.c:56:17: sparse: got restricted __le16 [usertype] net/bluetooth/mgmt_config.c:57:17: sparse: sparse: incorrect type in initializer (different base types) @@ expected unsigned short [usertype] value @@ got restricted __le16 [usertype] @@ net/bluetooth/mgmt_config.c:57:17: sparse: expected unsigned short [usertype] value net/bluetooth/mgmt_config.c:57:17: sparse: got restricted __le16 [usertype] net/bluetooth/mgmt_config.c:58:17: sparse: sparse: incorrect type in initializer (different base types) @@ expected unsigned short [usertype] value @@ got restricted __le16 [usertype] @@ net/bluetooth/mgmt_config.c:58:17: sparse: expected unsigned short [usertype] value net/bluetooth/mgmt_config.c:58:17: sparse: got restricted __le16 [usertype] net/bluetooth/mgmt_config.c:59:17: sparse: sparse: incorrect type in initializer (different base types) @@ expected unsigned short [usertype] value @@ got restricted __le16 [usertype] @@ net/bluetooth/mgmt_config.c:59:17: sparse: expected unsigned short [usertype] value net/bluetooth/mgmt_config.c:59:17: sparse: got restricted __le16 [usertype] net/bluetooth/mgmt_config.c:60:17: sparse: sparse: incorrect type in initializer (different base types) @@ expected unsigned short [usertype] value @@ got restricted __le16 [usertype] @@ net/bluetooth/mgmt_config.c:60:17: sparse: expected unsigned short [usertype] value net/bluetooth/mgmt_config.c:60:17: sparse: got restricted __le16 [usertype] net/bluetooth/mgmt_config.c:61:17: sparse: sparse: incorrect type in initializer (different base types) @@ expected unsigned short [usertype] value @@ got restricted __le16 [usertype] @@ net/bluetooth/mgmt_config.c:61:17: sparse: expected unsigned short [usertype] value net/bluetooth/mgmt_config.c:61:17: sparse: got restricted __le16 [usertype] >> net/bluetooth/mgmt_config.c:92:34: sparse: sparse: cast to restricted __le16 net/bluetooth/mgmt_config.c:156:34: sparse: sparse: cast to restricted __le16 net/bluetooth/mgmt_config.c:160:52: sparse: sparse: cast to restricted __le16 net/bluetooth/mgmt_config.c:163:51: sparse: sparse: cast to restricted __le16 net/bluetooth/mgmt_config.c:166:54: sparse: sparse: cast to restricted __le16 net/bluetooth/mgmt_config.c:169:51: sparse: sparse: cast to restricted __le16 net/bluetooth/mgmt_config.c:172:50: sparse: sparse: cast to restricted __le16 net/bluetooth/mgmt_config.c:175:53: sparse: sparse: cast to restricted __le16 net/bluetooth/mgmt_config.c:178:45: sparse: sparse: cast to restricted __le16 net/bluetooth/mgmt_config.c:181:50: sparse: sparse: cast to restricted __le16 net/bluetooth/mgmt_config.c:184:52: sparse: sparse: cast to restricted __le16 net/bluetooth/mgmt_config.c:187:52: sparse: sparse: cast to restricted __le16 net/bluetooth/mgmt_config.c:190:53: sparse: sparse: cast to restricted __le16 net/bluetooth/mgmt_config.c:193:53: sparse: sparse: cast to restricted __le16 net/bluetooth/mgmt_config.c:197:60: sparse: sparse: cast to restricted __le16 net/bluetooth/mgmt_config.c:200:50: sparse: sparse: cast to restricted __le16 net/bluetooth/mgmt_config.c:203:48: sparse: sparse: cast to restricted __le16 net/bluetooth/mgmt_config.c:206:53: sparse: sparse: cast to restricted __le16 net/bluetooth/mgmt_config.c:209:56: sparse: sparse: cast to restricted __le16 net/bluetooth/mgmt_config.c:212:55: sparse: sparse: cast to restricted __le16 net/bluetooth/mgmt_config.c:215:58: sparse: sparse: cast to restricted __le16 net/bluetooth/mgmt_config.c:218:57: sparse: sparse: cast to restricted __le16 net/bluetooth/mgmt_config.c:221:60: sparse: sparse: cast to restricted __le16 net/bluetooth/mgmt_config.c:224:53: sparse: sparse: cast to restricted __le16 net/bluetooth/mgmt_config.c:227:56: sparse: sparse: cast to restricted __le16 net/bluetooth/mgmt_config.c:230:54: sparse: sparse: cast to restricted __le16 net/bluetooth/mgmt_config.c:233:54: sparse: sparse: cast to restricted __le16 net/bluetooth/mgmt_config.c:236:49: sparse: sparse: cast to restricted __le16 net/bluetooth/mgmt_config.c:239:49: sparse: sparse: cast to restricted __le16 vim +35 net/bluetooth/mgmt_config.c 19 20 int read_def_system_config(struct sock *sk, struct hci_dev *hdev, void *data, 21 u16 data_len) 22 { 23 struct { 24 struct mgmt_tlv entry; 25 union { 26 /* This is a simplification for now since all values 27 * are 16 bits. In the future, this code may need 28 * refactoring to account for variable length values 29 * and properly calculate the required buffer size. 30 */ 31 u16 value; 32 }; 33 } __packed params[] = { 34 /* Please see mgmt-api.txt for documentation of these values */ > 35 HDEV_PARAM_U16(0x0000, def_page_scan_type), 36 HDEV_PARAM_U16(0x0001, def_page_scan_int), 37 HDEV_PARAM_U16(0x0002, def_page_scan_window), 38 HDEV_PARAM_U16(0x0003, def_inq_scan_type), 39 HDEV_PARAM_U16(0x0004, def_inq_scan_int), 40 HDEV_PARAM_U16(0x0005, def_inq_scan_window), 41 HDEV_PARAM_U16(0x0006, def_br_lsto), 42 HDEV_PARAM_U16(0x0007, def_page_timeout), 43 HDEV_PARAM_U16(0x0008, sniff_min_interval), 44 HDEV_PARAM_U16(0x0009, sniff_max_interval), 45 HDEV_PARAM_U16(0x000a, le_adv_min_interval), 46 HDEV_PARAM_U16(0x000b, le_adv_max_interval), 47 HDEV_PARAM_U16(0x000c, def_multi_adv_rotation_duration), 48 HDEV_PARAM_U16(0x000d, le_scan_interval), 49 HDEV_PARAM_U16(0x000e, le_scan_window), 50 HDEV_PARAM_U16(0x000f, le_scan_int_suspend), 51 HDEV_PARAM_U16(0x0010, le_scan_window_suspend), 52 HDEV_PARAM_U16(0x0011, le_scan_int_discovery), 53 HDEV_PARAM_U16(0x0012, le_scan_window_discovery), 54 HDEV_PARAM_U16(0x0013, le_scan_int_adv_monitor), 55 HDEV_PARAM_U16(0x0014, le_scan_window_adv_monitor), 56 HDEV_PARAM_U16(0x0015, le_scan_int_connect), 57 HDEV_PARAM_U16(0x0016, le_scan_window_connect), 58 HDEV_PARAM_U16(0x0017, le_conn_min_interval), > 59 HDEV_PARAM_U16(0x0018, le_conn_max_interval), 60 HDEV_PARAM_U16(0x0019, le_conn_latency), 61 HDEV_PARAM_U16(0x001a, le_supv_timeout), 62 }; 63 struct mgmt_rp_read_def_system_config *rp = (void *)params; 64 65 bt_dev_dbg(hdev, "sock %p", sk); 66 67 return mgmt_cmd_complete(sk, hdev->id, 68 MGMT_OP_READ_DEF_SYSTEM_CONFIG, 69 0, rp, sizeof(params)); 70 } 71 72 #define TO_TLV(x) ((struct mgmt_tlv *)(x)) 73 #define TLV_GET_LE16(tlv) le16_to_cpu(*((u16 *)(TO_TLV(tlv)->value))) 74 75 int set_def_system_config(struct sock *sk, struct hci_dev *hdev, void *data, 76 u16 data_len) 77 { 78 u16 buffer_left = data_len; 79 u8 *buffer = data; 80 81 if (buffer_left < sizeof(struct mgmt_tlv)) { 82 return mgmt_cmd_status(sk, hdev->id, 83 MGMT_OP_SET_DEF_SYSTEM_CONFIG, 84 MGMT_STATUS_INVALID_PARAMS); 85 } 86 87 /* First pass to validate the tlv */ 88 while (buffer_left >= sizeof(struct mgmt_tlv)) { 89 const u8 len = TO_TLV(buffer)->length; 90 const u16 exp_len = sizeof(struct mgmt_tlv) + 91 len; > 92 const u16 type = le16_to_cpu(TO_TLV(buffer)->type); --- 0-DAY CI Kernel Test Service, Intel Corporation https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
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..f967ffc3fbb1 --- /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 <net/bluetooth/bluetooth.h> +#include <net/bluetooth/hci_core.h> +#include <net/bluetooth/mgmt.h> + +#include "mgmt_util.h" +#include "mgmt_config.h" + +#define HDEV_PARAM_U16(_param_code_, _param_name_) \ +{ \ + { _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. + */ + u16 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(*((u16 *)(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..0005db246afc --- /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);