Loading...
Searching...
No Matches
nimble_scanner.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2019-2021 Freie Universität Berlin
3 *
4 * This file is subject to the terms and conditions of the GNU Lesser
5 * General Public License v2.1. See the file LICENSE in the top level
6 * directory for more details.
7 */
8
21#ifndef NIMBLE_SCANNER_H
22#define NIMBLE_SCANNER_H
23
24#include <errno.h>
25#include <stdint.h>
26#include <stdbool.h>
27
28#include "host/ble_hs.h"
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
37#define NIMBLE_SCANNER_EXT_ADV 0x80
38
42enum {
47#if IS_USED(MODULE_NIMBLE_PHY_CODED)
48 NIMBLE_SCANNER_PHY_CODED = 0x20,
49#endif
50};
51
55enum {
59 NIMBLE_SCANNER_COMPLETE = BLE_HCI_ADV_DATA_STATUS_COMPLETE,
63 NIMBLE_SCANNER_INCOMPLETE = BLE_HCI_ADV_DATA_STATUS_INCOMPLETE,
67 NIMBLE_SCANNER_TRUNCATED = BLE_HCI_ADV_DATA_STATUS_TRUNCATED,
68};
69
73typedef struct {
74 uint16_t itvl_ms;
75 uint16_t win_ms;
76 uint8_t flags;
78
82typedef struct {
89 uint8_t status;
90 uint8_t phy_pri;
91 uint8_t phy_sec;
92 int8_t rssi;
94
117typedef void(*nimble_scanner_cb)(uint8_t type, const ble_addr_t *addr,
118 const nimble_scanner_info_t *info,
119 const uint8_t *ad, size_t ad_len);
120
130 nimble_scanner_cb disc_cb);
131
142
147
154static inline bool nimble_scanner_is_active(void)
155{
156 return ble_gap_disc_active();
157}
158
167void nimble_scanner_set_scan_duration(int32_t duration_ms);
168
169#ifdef __cplusplus
170}
171#endif
172
173#endif /* NIMBLE_SCANNER_H */
int nimble_scanner_start(void)
Start scanning using timing parameters configured on initialization.
void(* nimble_scanner_cb)(uint8_t type, const ble_addr_t *addr, const nimble_scanner_info_t *info, const uint8_t *ad, size_t ad_len)
Callback signature triggered by this module for each discovered advertising packet.
static bool nimble_scanner_is_active(void)
Get the current scanning status.
void nimble_scanner_stop(void)
Stop scanning.
void nimble_scanner_set_scan_duration(int32_t duration_ms)
Set the duration for the scanning procedure.
int nimble_scanner_init(const nimble_scanner_cfg_t *params, nimble_scanner_cb disc_cb)
Initialize the scanner module.
@ NIMBLE_SCANNER_FILTER_DUPS
filter duplicates
@ NIMBLE_SCANNER_PHY_1M
scan on 1Mbit PHY
@ NIMBLE_SCANNER_LIMITED
do limited discovery
@ NIMBLE_SCANNER_PASSIVE
do a passive scan
@ NIMBLE_SCANNER_INCOMPLETE
The advertising message is incomplete.
@ NIMBLE_SCANNER_TRUNCATED
Advertising message is truncated.
@ NIMBLE_SCANNER_COMPLETE
All fragments of a advertising message were received.
Scanner configuration parameters.
uint16_t win_ms
scan window [ms]
uint8_t flags
scan configuration flags
uint16_t itvl_ms
scan interval [ms]
Additional information about received advertising packets.
uint8_t status
Status of received packet.
uint8_t phy_pri
PHY used on primary advertisement channels.
int8_t rssi
RSSI value of received advertisement.
uint8_t phy_sec
PHY used on secondary advertisement channels.