1 /*
2  * Copyright (c) 2018-2019 Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 struct lll_scan {
8 	struct lll_hdr hdr;
9 
10 #if defined(CONFIG_BT_CENTRAL)
11 	/* NOTE: conn context SHALL be after lll_hdr,
12 	 *       check ull_conn_setup how it access the connection LLL
13 	 *       context.
14 	 */
15 	struct lll_conn *volatile conn;
16 
17 	uint8_t  adv_addr[BDADDR_SIZE];
18 	uint32_t conn_win_offset_us;
19 	uint16_t conn_timeout;
20 #endif /* CONFIG_BT_CENTRAL */
21 
22 	uint8_t  state:1;
23 	uint8_t  chan:2;
24 	uint8_t  filter_policy:2;
25 	uint8_t  type:1;
26 	uint8_t  init_addr_type:1;
27 	uint8_t  is_stop:1;
28 
29 #if defined(CONFIG_BT_CTLR_ADV_EXT)
30 	/* Reference to aux context when scanning auxiliary PDU */
31 	struct lll_scan_aux *lll_aux;
32 
33 	uint16_t duration_reload;
34 	uint16_t duration_expire;
35 #if defined(CONFIG_BT_CTLR_JIT_SCHEDULING)
36 	uint8_t scan_aux_score;
37 #endif /* CONFIG_BT_CTLR_JIT_SCHEDULING */
38 	uint8_t  phy:3;
39 	uint8_t  is_adv_ind:1;
40 	uint8_t  is_aux_sched:1;
41 #if defined(CONFIG_BT_CTLR_SYNC_PERIODIC)
42 	uint8_t  is_sync:1;
43 #endif /* CONFIG_BT_CTLR_SYNC_PERIODIC */
44 #endif /* CONFIG_BT_CTLR_ADV_EXT */
45 
46 #if defined(CONFIG_BT_CENTRAL)
47 	uint8_t  adv_addr_type:1;
48 #endif /* CONFIG_BT_CENTRAL */
49 
50 #if defined(CONFIG_BT_CTLR_PRIVACY)
51 	uint8_t  rpa_gen:1;
52 	/* initiator only */
53 	uint8_t rl_idx;
54 #endif /* CONFIG_BT_CTLR_PRIVACY */
55 
56 	uint8_t  init_addr[BDADDR_SIZE];
57 
58 	uint16_t interval;
59 	uint32_t ticks_window;
60 
61 #if defined(CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL)
62 	int8_t tx_pwr_lvl;
63 #endif /* CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL */
64 };
65 
66 struct lll_scan_aux {
67 	struct lll_hdr hdr;
68 
69 	uint8_t chan:6;
70 	uint8_t state:1;
71 	uint8_t is_chain_sched:1;
72 
73 	uint8_t phy:3;
74 
75 	uint32_t window_size_us;
76 
77 #if defined(CONFIG_BT_CENTRAL)
78 	struct node_rx_pdu *node_conn_rx;
79 #endif /* CONFIG_BT_CENTRAL */
80 };
81 
82 
83 /* Define to check if filter is enabled and in addition if it is Extended Scan
84  * Filtering.
85  */
86 #define SCAN_FP_FILTER BIT(0)
87 #define SCAN_FP_EXT    BIT(1)
88 
89 int lll_scan_init(void);
90 int lll_scan_reset(void);
91 
92 void lll_scan_prepare(void *param);
93 
94 extern uint8_t ull_scan_lll_handle_get(struct lll_scan *lll);
95 extern struct lll_scan *ull_scan_lll_is_valid_get(struct lll_scan *lll);
96 extern struct lll_scan_aux *ull_scan_aux_lll_is_valid_get(struct lll_scan_aux *lll);
97