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 <joakim.andersson@nordicsemi.no>
This commit is contained in:
Joakim Andersson 2020-02-01 20:06:35 +01:00 committed by Johan Hedberg
commit be57dfbe2a
6 changed files with 40 additions and 30 deletions

View file

@ -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)

View file

@ -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,
};

View file

@ -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,
};

View file

@ -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);

View file

@ -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;

View file

@ -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(&param, 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(&param, 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;