From be57dfbe2a57afb6c1533e0ded0d27f9690c1bb7 Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Sat, 1 Feb 2020 20:06:35 +0100 Subject: [PATCH] Bluetooth: host: Rename and deprecate scan filter for more scan options Rename filter_dup parameters used for scanning filter options to the more generic name options, and make scan filter options follow same naming patters as advertising and initiator scan options. Signed-off-by: Joakim Andersson --- include/bluetooth/bluetooth.h | 32 ++++++++++++++++--------- samples/bluetooth/central_hr/src/main.c | 2 +- samples/bluetooth/scan_adv/src/main.c | 2 +- subsys/bluetooth/host/hci_core.c | 8 +++---- subsys/bluetooth/mesh/adv.c | 2 +- subsys/bluetooth/shell/bt.c | 24 +++++++++---------- 6 files changed, 40 insertions(+), 30 deletions(-) diff --git a/include/bluetooth/bluetooth.h b/include/bluetooth/bluetooth.h index 31c04d02f4d..f6648facdcd 100644 --- a/include/bluetooth/bluetooth.h +++ b/include/bluetooth/bluetooth.h @@ -708,14 +708,19 @@ typedef void bt_le_scan_cb_t(const bt_addr_le_t *addr, s8_t rssi, u8_t adv_type, struct net_buf_simple *buf); enum { + /** Convenience value when no options are specified. */ + BT_LE_SCAN_OPT_NONE = 0, + /** Filter duplicates. */ - BT_LE_SCAN_FILTER_DUPLICATE = BIT(0), + BT_LE_SCAN_OPT_FILTER_DUPLICATE = BIT(0), /** Filter using whitelist. */ - BT_LE_SCAN_FILTER_WHITELIST = BIT(1), + BT_LE_SCAN_OPT_FILTER_WHITELIST = BIT(1), - /** Filter using extended filter policies. */ - BT_LE_SCAN_FILTER_EXTENDED = BIT(2), + BT_LE_SCAN_FILTER_DUPLICATE __deprecated = + BT_LE_SCAN_OPT_FILTER_DUPLICATE, + BT_LE_SCAN_FILTER_WHITELIST __deprecated = + BT_LE_SCAN_OPT_FILTER_WHITELIST, }; enum { @@ -731,8 +736,13 @@ struct bt_le_scan_param { /** Scan type (BT_LE_SCAN_TYPE_ACTIVE or BT_LE_SCAN_TYPE_PASSIVE) */ u8_t type; - /** Bit-field of scanning filter options. */ - u8_t filter_dup; + union { + /** Bit-field of scanning filter options. */ + u8_t filter_dup __deprecated; + + /** Bit-field of scanning options. */ + u32_t options; + }; /** Scan interval (N * 0.625 ms) */ u16_t interval; @@ -771,21 +781,21 @@ struct bt_le_scan_cb { * * @param _type Scan Type, BT_LE_SCAN_TYPE_ACTIVE or * BT_LE_SCAN_TYPE_PASSIVE. - * @param _filter Filter options + * @param _options Scan options * @param _interval Scan Interval (N * 0.625 ms) * @param _window Scan Window (N * 0.625 ms) */ -#define BT_LE_SCAN_PARAM(_type, _filter, _interval, _window) \ +#define BT_LE_SCAN_PARAM(_type, _options, _interval, _window) \ ((struct bt_le_scan_param[]) { { \ .type = (_type), \ - .filter_dup = (_filter), \ + .options = (_options), \ .interval = (_interval), \ .window = (_window), \ } }) /** Helper macro to enable active scanning to discover new devices. */ #define BT_LE_SCAN_ACTIVE BT_LE_SCAN_PARAM(BT_LE_SCAN_TYPE_ACTIVE, \ - BT_LE_SCAN_FILTER_DUPLICATE, \ + BT_LE_SCAN_OPT_FILTER_DUPLICATE, \ BT_GAP_SCAN_FAST_INTERVAL, \ BT_GAP_SCAN_FAST_WINDOW) @@ -795,7 +805,7 @@ struct bt_le_scan_cb { * (e.g., UUID) are known to be placed in Advertising Data. */ #define BT_LE_SCAN_PASSIVE BT_LE_SCAN_PARAM(BT_LE_SCAN_TYPE_PASSIVE, \ - BT_LE_SCAN_FILTER_DUPLICATE, \ + BT_LE_SCAN_OPT_FILTER_DUPLICATE, \ BT_GAP_SCAN_FAST_INTERVAL, \ BT_GAP_SCAN_FAST_WINDOW) diff --git a/samples/bluetooth/central_hr/src/main.c b/samples/bluetooth/central_hr/src/main.c index 90b309927d6..857fd9dc343 100644 --- a/samples/bluetooth/central_hr/src/main.c +++ b/samples/bluetooth/central_hr/src/main.c @@ -164,7 +164,7 @@ static void start_scan(void) * devices that might update their advertising data at runtime. */ struct bt_le_scan_param scan_param = { .type = BT_HCI_LE_SCAN_ACTIVE, - .filter_dup = BT_HCI_LE_SCAN_FILTER_DUP_DISABLE, + .options = BT_LE_SCAN_OPT_NONE, .interval = BT_GAP_SCAN_FAST_INTERVAL, .window = BT_GAP_SCAN_FAST_WINDOW, }; diff --git a/samples/bluetooth/scan_adv/src/main.c b/samples/bluetooth/scan_adv/src/main.c index 0315e378076..3dd80c0dfae 100644 --- a/samples/bluetooth/scan_adv/src/main.c +++ b/samples/bluetooth/scan_adv/src/main.c @@ -30,7 +30,7 @@ void main(void) { struct bt_le_scan_param scan_param = { .type = BT_HCI_LE_SCAN_PASSIVE, - .filter_dup = BT_HCI_LE_SCAN_FILTER_DUP_DISABLE, + .options = BT_LE_SCAN_OPT_NONE, .interval = 0x0010, .window = 0x0010, }; diff --git a/subsys/bluetooth/host/hci_core.c b/subsys/bluetooth/host/hci_core.c index 7ca50e3da4b..f8449aaed78 100644 --- a/subsys/bluetooth/host/hci_core.c +++ b/subsys/bluetooth/host/hci_core.c @@ -6293,8 +6293,8 @@ static bool valid_le_scan_param(const struct bt_le_scan_param *param) return false; } - if (param->filter_dup & - ~(BT_LE_SCAN_FILTER_DUPLICATE | BT_LE_SCAN_FILTER_WHITELIST)) { + if (param->options & ~(BT_LE_SCAN_OPT_FILTER_DUPLICATE | + BT_LE_SCAN_OPT_FILTER_WHITELIST)) { return false; } @@ -6343,11 +6343,11 @@ int bt_le_scan_start(const struct bt_le_scan_param *param, bt_le_scan_cb_t cb) } atomic_set_bit_to(bt_dev.flags, BT_DEV_SCAN_FILTER_DUP, - param->filter_dup & BT_LE_SCAN_FILTER_DUPLICATE); + param->options & BT_LE_SCAN_OPT_FILTER_DUPLICATE); #if defined(CONFIG_BT_WHITELIST) atomic_set_bit_to(bt_dev.flags, BT_DEV_SCAN_WL, - param->filter_dup & BT_LE_SCAN_FILTER_WHITELIST); + param->options & BT_LE_SCAN_OPT_FILTER_WHITELIST); #endif /* defined(CONFIG_BT_WHITELIST) */ err = start_le_scan(param->type, param->interval, param->window); diff --git a/subsys/bluetooth/mesh/adv.c b/subsys/bluetooth/mesh/adv.c index 03eb64a3316..16cfe2ba1b6 100644 --- a/subsys/bluetooth/mesh/adv.c +++ b/subsys/bluetooth/mesh/adv.c @@ -316,7 +316,7 @@ int bt_mesh_scan_enable(void) { struct bt_le_scan_param scan_param = { .type = BT_HCI_LE_SCAN_PASSIVE, - .filter_dup = BT_HCI_LE_SCAN_FILTER_DUP_DISABLE, + .filter_dup = BT_LE_SCAN_OPT_NONE, .interval = MESH_SCAN_INTERVAL, .window = MESH_SCAN_WINDOW }; int err; diff --git a/subsys/bluetooth/shell/bt.c b/subsys/bluetooth/shell/bt.c index 9953b8ae9be..4a7450901dc 100644 --- a/subsys/bluetooth/shell/bt.c +++ b/subsys/bluetooth/shell/bt.c @@ -507,16 +507,16 @@ static int cmd_id_select(const struct shell *shell, size_t argc, char *argv[]) } #if defined(CONFIG_BT_OBSERVER) -static int cmd_active_scan_on(const struct shell *shell, u8_t filter) +static int cmd_active_scan_on(const struct shell *shell, u32_t options) { int err; struct bt_le_scan_param param = { .type = BT_HCI_LE_SCAN_ACTIVE, - .filter_dup = BT_HCI_LE_SCAN_FILTER_DUP_ENABLE, + .options = BT_LE_SCAN_OPT_FILTER_DUPLICATE, .interval = BT_GAP_SCAN_FAST_INTERVAL, .window = BT_GAP_SCAN_FAST_WINDOW }; - param.filter_dup = filter; + param.options |= options; err = bt_le_scan_start(¶m, device_found); if (err) { @@ -530,16 +530,16 @@ static int cmd_active_scan_on(const struct shell *shell, u8_t filter) return 0; } -static int cmd_passive_scan_on(const struct shell *shell, u8_t filter) +static int cmd_passive_scan_on(const struct shell *shell, u32_t options) { struct bt_le_scan_param param = { .type = BT_HCI_LE_SCAN_PASSIVE, - .filter_dup = BT_HCI_LE_SCAN_FILTER_DUP_DISABLE, + .options = BT_LE_SCAN_OPT_NONE, .interval = 0x10, .window = 0x10 }; int err; - param.filter_dup = filter; + param.options |= options; err = bt_le_scan_start(¶m, device_found); if (err) { @@ -571,18 +571,18 @@ static int cmd_scan_off(const struct shell *shell) static int cmd_scan(const struct shell *shell, size_t argc, char *argv[]) { const char *action; - u8_t filter = 0; + u32_t options = 0; /* Parse duplicate filtering data */ for (size_t argn = 2; argn < argc; argn++) { const char *arg = argv[argn]; if (!strcmp(arg, "dups")) { - filter |= BT_LE_SCAN_FILTER_DUPLICATE; + options |= BT_LE_SCAN_OPT_FILTER_DUPLICATE; } else if (!strcmp(arg, "nodups")) { - filter &= ~BT_LE_SCAN_FILTER_DUPLICATE; + options &= ~BT_LE_SCAN_OPT_FILTER_DUPLICATE; } else if (!strcmp(arg, "wl")) { - filter |= BT_LE_SCAN_FILTER_WHITELIST; + options |= BT_LE_SCAN_OPT_FILTER_WHITELIST; } else { shell_help(shell); return SHELL_CMD_HELP_PRINTED; @@ -591,11 +591,11 @@ static int cmd_scan(const struct shell *shell, size_t argc, char *argv[]) action = argv[1]; if (!strcmp(action, "on")) { - return cmd_active_scan_on(shell, filter); + return cmd_active_scan_on(shell, options); } else if (!strcmp(action, "off")) { return cmd_scan_off(shell); } else if (!strcmp(action, "passive")) { - return cmd_passive_scan_on(shell, filter); + return cmd_passive_scan_on(shell, options); } else { shell_help(shell); return SHELL_CMD_HELP_PRINTED;