23#include "ble_ll_sched.h"
24#include "ble_ll_tmr.h"
25#include "nimble/porting/nimble/include/syscfg/syscfg.h"
26#include "nimble/nimble/include/nimble/nimble_npl.h"
43#define BLE_SCAN_REQ_LEN (12)
56#define BLE_SCAN_RSP_LEGACY_DATA_MAX_LEN (31)
57#define BLE_SCAN_LEGACY_MAX_PKT_LEN (37)
59#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_EXT_ADV)
60#define BLE_SCAN_RSP_DATA_MAX_LEN MYNEWT_VAL(BLE_EXT_ADV_MAX_SIZE)
63#define BLE_LL_SCAN_PHY_NUMBER (2)
65#define BLE_LL_SCAN_PHY_NUMBER (1)
66#define BLE_SCAN_RSP_DATA_MAX_LEN BLE_SCAN_RSP_LEGACY_DATA_MAX_LEN
69#define PHY_UNCODED (0)
72#define BLE_LL_EXT_ADV_MODE_NON_CONN (0x00)
73#define BLE_LL_EXT_ADV_MODE_CONN (0x01)
74#define BLE_LL_EXT_ADV_MODE_SCAN (0x02)
77struct ble_ll_scan_timing {
89 struct ble_ll_scan_timing timing;
92struct ble_ll_scan_pdu_data {
96 uint8_t scana[BLE_DEV_ADDR_LEN];
97 uint8_t inita[BLE_DEV_ADDR_LEN];
99 uint8_t adva[BLE_DEV_ADDR_LEN];
102struct ble_ll_scan_addr_data {
106 uint8_t adva_type : 1;
107 uint8_t targeta_type : 1;
108 uint8_t adv_addr_type : 1;
109#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_PRIVACY)
110 uint8_t adva_resolved : 1;
111 uint8_t targeta_resolved : 1;
118 uint8_t scan_enabled;
120 uint8_t own_addr_type;
121 uint8_t scan_filt_policy;
122 uint8_t scan_filt_dups;
123 uint8_t scan_rsp_pending;
124 uint8_t scan_rsp_cons_fails;
125 uint8_t scan_rsp_cons_ok;
126 uint8_t scan_peer_rpa[BLE_DEV_ADDR_LEN];
127#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_PRIVACY)
128 ble_npl_time_t scan_nrpa_timer;
129 uint8_t scan_nrpa[BLE_DEV_ADDR_LEN];
131 struct ble_ll_scan_pdu_data pdu_data;
134 uint16_t upper_limit;
135 uint16_t backoff_count;
136 uint32_t scan_win_start_time;
137 struct ble_npl_event scan_sched_ev;
138 struct ble_ll_tmr scan_timer;
139 struct ble_npl_event scan_interrupted_ev;
141#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_EXT_ADV)
142 struct ble_npl_callout duration_timer;
143 struct ble_npl_callout period_timer;
144 ble_npl_time_t duration_ticks;
145 ble_npl_time_t period_ticks;
146 uint8_t ext_scanning;
149 uint8_t restart_timer_needed;
151 struct ble_ll_scan_phy *scanp;
152 struct ble_ll_scan_phy *scanp_next;
153 struct ble_ll_scan_phy scan_phys[BLE_LL_SCAN_PHY_NUMBER];
155#if MYNEWT_VAL(BLE_LL_ROLE_CENTRAL)
157 struct ble_ll_conn_sm *connsm;
162#define BLE_SCAN_TYPE_PASSIVE (BLE_HCI_SCAN_TYPE_PASSIVE)
163#define BLE_SCAN_TYPE_ACTIVE (BLE_HCI_SCAN_TYPE_ACTIVE)
164#if MYNEWT_VAL(BLE_LL_ROLE_CENTRAL)
165#define BLE_SCAN_TYPE_INITIATE (2)
170int ble_ll_scan_hci_set_params(
const uint8_t *cmdbuf, uint8_t len);
173int ble_ll_scan_hci_set_enable(
const uint8_t *cmdbuf, uint8_t len);
174int ble_ll_scan_hci_set_ext_enable(
const uint8_t *cmdbuf, uint8_t len);
176#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_EXT_ADV)
177int ble_ll_scan_hci_set_ext_params(
const uint8_t *cmdbuf, uint8_t len);
182void ble_ll_scan_init(
void);
185void ble_ll_scan_reset(
void);
188int ble_ll_scan_rx_isr_start(uint8_t pdu_type, uint16_t *rxflags);
191int ble_ll_scan_rx_isr_end(
struct os_mbuf *rxpdu, uint8_t crcok);
194void ble_ll_scan_rx_pkt_in(uint8_t pdu_type,
struct os_mbuf *om,
195 struct ble_mbuf_hdr *hdr);
198int ble_ll_scan_can_chg_whitelist(
void);
201int ble_ll_scan_enabled(
void);
204struct ble_ll_conn_create_scan;
205struct ble_ll_conn_create_params;
207ble_ll_scan_initiator_start(
struct ble_ll_conn_sm *connsm, uint8_t ext,
208 struct ble_ll_conn_create_scan *cc_scan);
211struct ble_ll_scan_pdu_data *ble_ll_scan_get_pdu_data(
void);
214void ble_ll_scan_set_peer_rpa(uint8_t *rpa);
217uint8_t *ble_ll_scan_get_peer_rpa(
void);
220uint8_t *ble_ll_scan_get_local_rpa(
void);
223void ble_ll_scan_sm_stop(
int chk_disable);
226#if MYNEWT_VAL(BLE_LL_ROLE_OBSERVER)
227void ble_ll_scan_chk_resume(
void);
229static inline void ble_ll_scan_chk_resume(
void) { };
233void ble_ll_scan_wfr_timer_exp(
void);
236void ble_ll_scan_interrupted(
struct ble_ll_scan_sm *scansm);
238#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_EXT_ADV)
240void ble_ll_scan_end_adv_evt(
struct ble_ll_aux_data *aux_data);
244void ble_ll_scan_halt(
void);
246uint8_t *ble_ll_get_scan_nrpa(
void);
247uint8_t ble_ll_scan_get_own_addr_type(
void);
248uint8_t ble_ll_scan_get_filt_policy(
void);
249uint8_t ble_ll_scan_get_filt_dups(
void);
250uint8_t ble_ll_scan_backoff_kick(
void);
251void ble_ll_scan_backoff_update(
int success);
253int ble_ll_scan_dup_check_ext(uint8_t addr_type, uint8_t *addr,
bool has_aux,
255int ble_ll_scan_dup_update_ext(uint8_t addr_type, uint8_t *addr,
bool has_aux,
257int ble_ll_scan_have_rxd_scan_rsp(uint8_t *addr, uint8_t txadd, uint8_t ext_adv,
259void ble_ll_scan_add_scan_rsp_adv(uint8_t *addr, uint8_t txadd, uint8_t ext_adv,
263ble_ll_scan_rx_filter(uint8_t own_addr_type, uint8_t scan_filt_policy,
264 struct ble_ll_scan_addr_data *addrd, uint8_t *scan_ok);
265int ble_ll_scan_rx_check_init(
struct ble_ll_scan_addr_data *addrd);