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
9#pragma once
10
22
23#include <errno.h>
24#include <stdint.h>
25#include <stdbool.h>
26
27#include "host/ble_hs.h"
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
36#define NIMBLE_SCANNER_EXT_ADV 0x80
37
41enum {
46#if IS_USED(MODULE_NIMBLE_PHY_CODED)
47 NIMBLE_SCANNER_PHY_CODED = 0x20,
48#endif
49};
50
54enum {
58 NIMBLE_SCANNER_COMPLETE = BLE_HCI_ADV_DATA_STATUS_COMPLETE,
62 NIMBLE_SCANNER_INCOMPLETE = BLE_HCI_ADV_DATA_STATUS_INCOMPLETE,
66 NIMBLE_SCANNER_TRUNCATED = BLE_HCI_ADV_DATA_STATUS_TRUNCATED,
67};
68
72typedef struct {
73 uint16_t itvl_ms;
74 uint16_t win_ms;
75 uint8_t flags;
77
81typedef struct {
88 uint8_t status;
89 uint8_t phy_pri;
90 uint8_t phy_sec;
91 int8_t rssi;
93
116typedef void(*nimble_scanner_cb)(uint8_t type, const ble_addr_t *addr,
117 const nimble_scanner_info_t *info,
118 const uint8_t *ad, size_t ad_len);
119
129 nimble_scanner_cb disc_cb);
130
141
146
153static inline bool nimble_scanner_is_active(void)
154{
155 return ble_gap_disc_active();
156}
157
166void nimble_scanner_set_scan_duration(int32_t duration_ms);
167
168#ifdef __cplusplus
169}
170#endif
171
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_INCOMPLETE
The advertising message is incomplete.
@ NIMBLE_SCANNER_TRUNCATED
Advertising message is truncated.
@ NIMBLE_SCANNER_COMPLETE
All fragments of a advertising message were received.
@ 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
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.