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:
parent
b8f48410e5
commit
be57dfbe2a
6 changed files with 40 additions and 30 deletions
|
@ -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);
|
u8_t adv_type, struct net_buf_simple *buf);
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
|
/** Convenience value when no options are specified. */
|
||||||
|
BT_LE_SCAN_OPT_NONE = 0,
|
||||||
|
|
||||||
/** Filter duplicates. */
|
/** Filter duplicates. */
|
||||||
BT_LE_SCAN_FILTER_DUPLICATE = BIT(0),
|
BT_LE_SCAN_OPT_FILTER_DUPLICATE = BIT(0),
|
||||||
|
|
||||||
/** Filter using whitelist. */
|
/** 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_DUPLICATE __deprecated =
|
||||||
BT_LE_SCAN_FILTER_EXTENDED = BIT(2),
|
BT_LE_SCAN_OPT_FILTER_DUPLICATE,
|
||||||
|
BT_LE_SCAN_FILTER_WHITELIST __deprecated =
|
||||||
|
BT_LE_SCAN_OPT_FILTER_WHITELIST,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
|
@ -731,8 +736,13 @@ struct bt_le_scan_param {
|
||||||
/** Scan type (BT_LE_SCAN_TYPE_ACTIVE or BT_LE_SCAN_TYPE_PASSIVE) */
|
/** Scan type (BT_LE_SCAN_TYPE_ACTIVE or BT_LE_SCAN_TYPE_PASSIVE) */
|
||||||
u8_t type;
|
u8_t type;
|
||||||
|
|
||||||
|
union {
|
||||||
/** Bit-field of scanning filter options. */
|
/** Bit-field of scanning filter options. */
|
||||||
u8_t filter_dup;
|
u8_t filter_dup __deprecated;
|
||||||
|
|
||||||
|
/** Bit-field of scanning options. */
|
||||||
|
u32_t options;
|
||||||
|
};
|
||||||
|
|
||||||
/** Scan interval (N * 0.625 ms) */
|
/** Scan interval (N * 0.625 ms) */
|
||||||
u16_t interval;
|
u16_t interval;
|
||||||
|
@ -771,21 +781,21 @@ struct bt_le_scan_cb {
|
||||||
*
|
*
|
||||||
* @param _type Scan Type, BT_LE_SCAN_TYPE_ACTIVE or
|
* @param _type Scan Type, BT_LE_SCAN_TYPE_ACTIVE or
|
||||||
* BT_LE_SCAN_TYPE_PASSIVE.
|
* BT_LE_SCAN_TYPE_PASSIVE.
|
||||||
* @param _filter Filter options
|
* @param _options Scan options
|
||||||
* @param _interval Scan Interval (N * 0.625 ms)
|
* @param _interval Scan Interval (N * 0.625 ms)
|
||||||
* @param _window Scan Window (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[]) { { \
|
((struct bt_le_scan_param[]) { { \
|
||||||
.type = (_type), \
|
.type = (_type), \
|
||||||
.filter_dup = (_filter), \
|
.options = (_options), \
|
||||||
.interval = (_interval), \
|
.interval = (_interval), \
|
||||||
.window = (_window), \
|
.window = (_window), \
|
||||||
} })
|
} })
|
||||||
|
|
||||||
/** Helper macro to enable active scanning to discover new devices. */
|
/** Helper macro to enable active scanning to discover new devices. */
|
||||||
#define BT_LE_SCAN_ACTIVE BT_LE_SCAN_PARAM(BT_LE_SCAN_TYPE_ACTIVE, \
|
#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_INTERVAL, \
|
||||||
BT_GAP_SCAN_FAST_WINDOW)
|
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.
|
* (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, \
|
#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_INTERVAL, \
|
||||||
BT_GAP_SCAN_FAST_WINDOW)
|
BT_GAP_SCAN_FAST_WINDOW)
|
||||||
|
|
||||||
|
|
|
@ -164,7 +164,7 @@ static void start_scan(void)
|
||||||
* devices that might update their advertising data at runtime. */
|
* devices that might update their advertising data at runtime. */
|
||||||
struct bt_le_scan_param scan_param = {
|
struct bt_le_scan_param scan_param = {
|
||||||
.type = BT_HCI_LE_SCAN_ACTIVE,
|
.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,
|
.interval = BT_GAP_SCAN_FAST_INTERVAL,
|
||||||
.window = BT_GAP_SCAN_FAST_WINDOW,
|
.window = BT_GAP_SCAN_FAST_WINDOW,
|
||||||
};
|
};
|
||||||
|
|
|
@ -30,7 +30,7 @@ void main(void)
|
||||||
{
|
{
|
||||||
struct bt_le_scan_param scan_param = {
|
struct bt_le_scan_param scan_param = {
|
||||||
.type = BT_HCI_LE_SCAN_PASSIVE,
|
.type = BT_HCI_LE_SCAN_PASSIVE,
|
||||||
.filter_dup = BT_HCI_LE_SCAN_FILTER_DUP_DISABLE,
|
.options = BT_LE_SCAN_OPT_NONE,
|
||||||
.interval = 0x0010,
|
.interval = 0x0010,
|
||||||
.window = 0x0010,
|
.window = 0x0010,
|
||||||
};
|
};
|
||||||
|
|
|
@ -6293,8 +6293,8 @@ static bool valid_le_scan_param(const struct bt_le_scan_param *param)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (param->filter_dup &
|
if (param->options & ~(BT_LE_SCAN_OPT_FILTER_DUPLICATE |
|
||||||
~(BT_LE_SCAN_FILTER_DUPLICATE | BT_LE_SCAN_FILTER_WHITELIST)) {
|
BT_LE_SCAN_OPT_FILTER_WHITELIST)) {
|
||||||
return false;
|
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,
|
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)
|
#if defined(CONFIG_BT_WHITELIST)
|
||||||
atomic_set_bit_to(bt_dev.flags, BT_DEV_SCAN_WL,
|
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) */
|
#endif /* defined(CONFIG_BT_WHITELIST) */
|
||||||
|
|
||||||
err = start_le_scan(param->type, param->interval, param->window);
|
err = start_le_scan(param->type, param->interval, param->window);
|
||||||
|
|
|
@ -316,7 +316,7 @@ int bt_mesh_scan_enable(void)
|
||||||
{
|
{
|
||||||
struct bt_le_scan_param scan_param = {
|
struct bt_le_scan_param scan_param = {
|
||||||
.type = BT_HCI_LE_SCAN_PASSIVE,
|
.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,
|
.interval = MESH_SCAN_INTERVAL,
|
||||||
.window = MESH_SCAN_WINDOW };
|
.window = MESH_SCAN_WINDOW };
|
||||||
int err;
|
int err;
|
||||||
|
|
|
@ -507,16 +507,16 @@ static int cmd_id_select(const struct shell *shell, size_t argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(CONFIG_BT_OBSERVER)
|
#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;
|
int err;
|
||||||
struct bt_le_scan_param param = {
|
struct bt_le_scan_param param = {
|
||||||
.type = BT_HCI_LE_SCAN_ACTIVE,
|
.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,
|
.interval = BT_GAP_SCAN_FAST_INTERVAL,
|
||||||
.window = BT_GAP_SCAN_FAST_WINDOW };
|
.window = BT_GAP_SCAN_FAST_WINDOW };
|
||||||
|
|
||||||
param.filter_dup = filter;
|
param.options |= options;
|
||||||
|
|
||||||
err = bt_le_scan_start(¶m, device_found);
|
err = bt_le_scan_start(¶m, device_found);
|
||||||
if (err) {
|
if (err) {
|
||||||
|
@ -530,16 +530,16 @@ static int cmd_active_scan_on(const struct shell *shell, u8_t filter)
|
||||||
return 0;
|
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 = {
|
struct bt_le_scan_param param = {
|
||||||
.type = BT_HCI_LE_SCAN_PASSIVE,
|
.type = BT_HCI_LE_SCAN_PASSIVE,
|
||||||
.filter_dup = BT_HCI_LE_SCAN_FILTER_DUP_DISABLE,
|
.options = BT_LE_SCAN_OPT_NONE,
|
||||||
.interval = 0x10,
|
.interval = 0x10,
|
||||||
.window = 0x10 };
|
.window = 0x10 };
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
param.filter_dup = filter;
|
param.options |= options;
|
||||||
|
|
||||||
err = bt_le_scan_start(¶m, device_found);
|
err = bt_le_scan_start(¶m, device_found);
|
||||||
if (err) {
|
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[])
|
static int cmd_scan(const struct shell *shell, size_t argc, char *argv[])
|
||||||
{
|
{
|
||||||
const char *action;
|
const char *action;
|
||||||
u8_t filter = 0;
|
u32_t options = 0;
|
||||||
|
|
||||||
/* Parse duplicate filtering data */
|
/* Parse duplicate filtering data */
|
||||||
for (size_t argn = 2; argn < argc; argn++) {
|
for (size_t argn = 2; argn < argc; argn++) {
|
||||||
const char *arg = argv[argn];
|
const char *arg = argv[argn];
|
||||||
|
|
||||||
if (!strcmp(arg, "dups")) {
|
if (!strcmp(arg, "dups")) {
|
||||||
filter |= BT_LE_SCAN_FILTER_DUPLICATE;
|
options |= BT_LE_SCAN_OPT_FILTER_DUPLICATE;
|
||||||
} else if (!strcmp(arg, "nodups")) {
|
} else if (!strcmp(arg, "nodups")) {
|
||||||
filter &= ~BT_LE_SCAN_FILTER_DUPLICATE;
|
options &= ~BT_LE_SCAN_OPT_FILTER_DUPLICATE;
|
||||||
} else if (!strcmp(arg, "wl")) {
|
} else if (!strcmp(arg, "wl")) {
|
||||||
filter |= BT_LE_SCAN_FILTER_WHITELIST;
|
options |= BT_LE_SCAN_OPT_FILTER_WHITELIST;
|
||||||
} else {
|
} else {
|
||||||
shell_help(shell);
|
shell_help(shell);
|
||||||
return SHELL_CMD_HELP_PRINTED;
|
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];
|
action = argv[1];
|
||||||
if (!strcmp(action, "on")) {
|
if (!strcmp(action, "on")) {
|
||||||
return cmd_active_scan_on(shell, filter);
|
return cmd_active_scan_on(shell, options);
|
||||||
} else if (!strcmp(action, "off")) {
|
} else if (!strcmp(action, "off")) {
|
||||||
return cmd_scan_off(shell);
|
return cmd_scan_off(shell);
|
||||||
} else if (!strcmp(action, "passive")) {
|
} else if (!strcmp(action, "passive")) {
|
||||||
return cmd_passive_scan_on(shell, filter);
|
return cmd_passive_scan_on(shell, options);
|
||||||
} else {
|
} else {
|
||||||
shell_help(shell);
|
shell_help(shell);
|
||||||
return SHELL_CMD_HELP_PRINTED;
|
return SHELL_CMD_HELP_PRINTED;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue