nRF Connect SDK API 0.1.0
Loading...
Searching...
No Matches
scan.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5 */
6
7#ifndef BT_SCAN_H_
8#define BT_SCAN_H_
9
28#include <zephyr/types.h>
29#include <zephyr/sys/slist.h>
30#include <zephyr/bluetooth/bluetooth.h>
31#include <zephyr/bluetooth/uuid.h>
32#include <zephyr/bluetooth/conn.h>
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
38
44#define BT_SCAN_NAME_FILTER 0x01
45
47#define BT_SCAN_ADDR_FILTER 0x02
48
50#define BT_SCAN_UUID_FILTER 0x04
51
53#define BT_SCAN_APPEARANCE_FILTER 0x08
54
56#define BT_SCAN_SHORT_NAME_FILTER 0x10
57
59#define BT_SCAN_MANUFACTURER_DATA_FILTER 0x20
60
62#define BT_SCAN_ALL_FILTER 0x3F
71
74};
75
81
84
87
90
93
96};
97
106
108 uint8_t cnt;
109};
110
116
119
122
125
128
131
134};
135
142 uint8_t adv_type;
143
145 int8_t rssi;
146};
147
152 const char *name;
153
155 uint8_t min_len;
156};
157
162 uint8_t *data;
163
165 uint8_t data_len;
166};
167
175 const struct bt_le_scan_param *scan_param;
176
177#if CONFIG_BT_CENTRAL
182#endif /* CONFIG_BT_CENTRAL */
183
187 const struct bt_le_conn_param *conn_param;
188};
189
195 bool match;
196
198 const char *name;
199
201 uint8_t len;
202};
203
209 bool match;
210
212 const bt_addr_le_t *addr;
213};
214
220 bool match;
221
223 const struct bt_uuid *uuid[CONFIG_BT_SCAN_UUID_CNT];
224
226 uint8_t count;
227};
228
234 bool match;
235
237 const uint16_t *appearance;
238};
239
245 bool match;
246
248 const uint8_t *data;
249
251 uint8_t len;
252};
253
266
269
272
275
278
281};
282
288 const struct bt_le_scan_recv_info *recv_info;
289
291 const struct bt_le_conn_param *conn_param;
292
298 struct net_buf_simple *adv_data;
299};
300
313#if CONFIG_BT_CENTRAL
314#define BT_SCAN_CB_INIT(_name, \
315 match_fun, \
316 no_match_fun, \
317 error_fun, \
318 connecting_fun) \
319 static const struct cb_data _name ## _data = { \
320 .filter_match = match_fun, \
321 .filter_no_match = no_match_fun, \
322 .connecting_error = error_fun, \
323 .connecting = connecting_fun, \
324 }; \
325 static struct bt_scan_cb _name = { \
326 .cb_addr = &_name ## _data, \
327 }
328#else
329#define BT_SCAN_CB_INIT(_name, \
330 match_fun, \
331 no_match_fun, \
332 error_fun, \
333 connecting_fun) \
334 static const struct cb_data _name ## _data = { \
335 .filter_match = match_fun, \
336 .filter_no_match = no_match_fun, \
337 }; \
338 static struct bt_scan_cb _name = { \
339 .cb_addr = &_name ## _data, \
340 }
341#endif /* CONFIG_BT_CENTRAL */
342
349struct cb_data {
357 void (*filter_match)(struct bt_scan_device_info *device_info,
359 bool connectable);
360
371 void (*filter_no_match)(struct bt_scan_device_info *device_info,
372 bool connectable);
373
374#if CONFIG_BT_CENTRAL
380 void (*connecting_error)(struct bt_scan_device_info *device_info);
381
388 void (*connecting)(struct bt_scan_device_info *device_info,
389 struct bt_conn *conn);
390#endif /* CONFIG_BT_CENTRAL */
391};
392
405 const struct cb_data *cb_addr;
406 sys_snode_t node;
407};
408
416
426void bt_scan_init(const struct bt_scan_init_param *init);
427
438int bt_scan_start(enum bt_scan_type scan_type);
439
442int bt_scan_stop(void);
443
450void bt_scan_update_init_conn_params(struct bt_le_conn_param *new_conn_param);
451
452#if CONFIG_BT_SCAN_FILTER_ENABLE
453
472int bt_scan_filter_enable(uint8_t mode, bool match_all);
473
482
494
509 const void *data);
510
518
519#endif /* CONFIG_BT_SCAN_FILTER_ENABLE */
520
535int bt_scan_params_set(struct bt_le_scan_param *scan_param);
536
543
556int bt_scan_blocklist_device_add(const bt_addr_le_t *addr);
557
564
572void bt_scan_update_connect_if_match(bool connect_if_match);
573
574#ifdef __cplusplus
575}
576#endif
577
580#endif /* BT_SCAN_H_ */
void bt_scan_filter_disable(void)
Function for disabling filtering.
bt_scan_filter_type
Types of filters.
Definition: scan.h:78
@ BT_SCAN_FILTER_TYPE_APPEARANCE
Definition: scan.h:92
@ BT_SCAN_FILTER_TYPE_SHORT_NAME
Definition: scan.h:83
@ BT_SCAN_FILTER_TYPE_NAME
Definition: scan.h:80
@ BT_SCAN_FILTER_TYPE_UUID
Definition: scan.h:89
@ BT_SCAN_FILTER_TYPE_ADDR
Definition: scan.h:86
@ BT_SCAN_FILTER_TYPE_MANUFACTURER_DATA
Definition: scan.h:95
bt_scan_type
Scan types.
Definition: scan.h:68
@ BT_SCAN_TYPE_SCAN_ACTIVE
Definition: scan.h:73
@ BT_SCAN_TYPE_SCAN_PASSIVE
Definition: scan.h:70
void bt_scan_update_init_conn_params(struct bt_le_conn_param *new_conn_param)
Function to update initial connection parameters.
int bt_scan_params_set(struct bt_le_scan_param *scan_param)
Function for changing the scanning parameters.
int bt_scan_start(enum bt_scan_type scan_type)
Function for starting scanning.
int bt_scan_filter_enable(uint8_t mode, bool match_all)
Function for enabling filtering.
int bt_scan_filter_status_get(struct bt_filter_status *status)
Function for getting filter status.
int bt_scan_blocklist_device_add(const bt_addr_le_t *addr)
Add a new device to the blocklist.
void bt_scan_blocklist_clear(void)
Clear the blocklist of the scanning module device.
void bt_scan_cb_register(struct bt_scan_cb *cb)
Register scanning callbacks.
int bt_scan_stop(void)
Function for stopping scanning.
void bt_scan_conn_attempts_filter_clear(void)
Clear connection attempts filter.
int bt_scan_filter_add(enum bt_scan_filter_type type, const void *data)
Function for adding any type of filter to the scanning.
void bt_scan_init(const struct bt_scan_init_param *init)
Function for initializing the Scanning Module.
void bt_scan_update_connect_if_match(bool connect_if_match)
Function to update the autoconnect flag after a filter match.
void bt_scan_filter_remove_all(void)
Function for removing all set filters.
struct bt_scan_filter_info manufacturer_data
Definition: scan.h:133
struct bt_scan_filter_info addr
Definition: scan.h:124
struct bt_scan_filter_info appearance
Definition: scan.h:130
struct bt_scan_filter_info uuid
Definition: scan.h:127
bool all_mode
Definition: scan.h:115
struct bt_scan_filter_info short_name
Definition: scan.h:121
struct bt_scan_filter_info name
Definition: scan.h:118
Filter status structure.
Definition: scan.h:113
bool match
Definition: scan.h:209
const bt_addr_le_t * addr
Definition: scan.h:212
Address filter status structure, used to inform the application which address filter is matched.
Definition: scan.h:207
uint8_t adv_type
Definition: scan.h:142
int8_t rssi
Definition: scan.h:145
Advertising info structure.
Definition: scan.h:138
const uint16_t * appearance
Definition: scan.h:237
bool match
Definition: scan.h:234
Appearance filter status structure, used to inform the application which appearance filter is matched...
Definition: scan.h:232
const struct cb_data * cb_addr
Definition: scan.h:405
sys_snode_t node
Definition: scan.h:406
Scanning callback structure.
Definition: scan.h:404
struct net_buf_simple * adv_data
Definition: scan.h:298
const struct bt_le_scan_recv_info * recv_info
Definition: scan.h:288
const struct bt_le_conn_param * conn_param
Definition: scan.h:291
Structure containing device data needed to establish connection and advertising information.
Definition: scan.h:286
bool enabled
Definition: scan.h:105
uint8_t cnt
Definition: scan.h:108
Filter information structure.
Definition: scan.h:103
struct bt_scan_name_filter_status short_name
Definition: scan.h:268
struct bt_scan_appearance_filter_status appearance
Definition: scan.h:277
struct bt_scan_uuid_filter_status uuid
Definition: scan.h:274
struct bt_scan_manufacturer_data_filter_status manufacturer_data
Definition: scan.h:280
struct bt_scan_name_filter_status name
Definition: scan.h:265
struct bt_scan_addr_filter_status addr
Definition: scan.h:271
Structure for setting the filter status.
Definition: scan.h:263
const struct bt_le_conn_param * conn_param
Definition: scan.h:187
const struct bt_le_scan_param * scan_param
Definition: scan.h:175
bool connect_if_match
Definition: scan.h:181
Structure for Scanning Module initialization.
Definition: scan.h:170
uint8_t len
Definition: scan.h:251
const uint8_t * data
Definition: scan.h:248
bool match
Definition: scan.h:245
Manufacturer data filter status structure, used to inform the application which manufacturer data fil...
Definition: scan.h:243
uint8_t data_len
Definition: scan.h:165
uint8_t * data
Definition: scan.h:162
A helper structure to set filters for the manufacturer data.
Definition: scan.h:160
uint8_t len
Definition: scan.h:201
bool match
Definition: scan.h:195
const char * name
Definition: scan.h:198
Name filter status structure, used to inform the application which name filter is matched.
Definition: scan.h:193
uint8_t min_len
Definition: scan.h:155
const char * name
Definition: scan.h:152
A helper structure to set filters for the name.
Definition: scan.h:150
uint8_t count
Definition: scan.h:226
const struct bt_uuid * uuid[1]
Definition: scan.h:223
bool match
Definition: scan.h:220
UUID filter status structure, used to inform the application which UUID filters are matched.
Definition: scan.h:218
void(* filter_match)(struct bt_scan_device_info *device_info, struct bt_scan_filter_match *filter_match, bool connectable)
Scan filter matched.
Definition: scan.h:357
void(* connecting)(struct bt_scan_device_info *device_info, struct bt_conn *conn)
Connecting data.
Definition: scan.h:388
void(* filter_no_match)(struct bt_scan_device_info *device_info, bool connectable)
Scan filter unmatched. The device was not found.
Definition: scan.h:371
void(* connecting_error)(struct bt_scan_device_info *device_info)
Error when connecting.
Definition: scan.h:380
Data for scanning callback structure.
Definition: scan.h:349