1 /* 2 * Copyright (c) 2018-2019 Nordic Semiconductor ASA 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 /* NOTE: Definitions used internal to ULL implementations */ 8 9 #define SCAN_HANDLE_1M 0 10 #define SCAN_HANDLE_PHY_CODED 1 11 12 #define EXT_SCAN_DURATION_UNIT_US 10000U 13 #define EXT_SCAN_PERIOD_UNIT_US 1280000U 14 15 /* Convert period in 1.28 s units to duration of 10 ms units*/ 16 #define ULL_SCAN_PERIOD_TO_DURATION(period) \ 17 ((uint32_t)(period) * EXT_SCAN_PERIOD_UNIT_US / \ 18 EXT_SCAN_DURATION_UNIT_US) 19 20 /* Convert duration in 10 ms unit to radio events count */ 21 #define ULL_SCAN_DURATION_TO_EVENTS(duration, interval) \ 22 (((uint32_t)(duration) * EXT_SCAN_DURATION_UNIT_US / \ 23 SCAN_INT_UNIT_US) / (interval)) 24 25 /* Convert period in 1.28 s unit to radio events count */ 26 #define ULL_SCAN_PERIOD_TO_EVENTS(period, interval) \ 27 (((uint32_t)(period) * EXT_SCAN_PERIOD_UNIT_US / \ 28 SCAN_INT_UNIT_US) / (interval)) 29 30 int ull_scan_init(void); 31 int ull_scan_reset(void); 32 33 /* Set scan parameters */ 34 uint32_t ull_scan_params_set(struct lll_scan *lll, uint8_t type, 35 uint16_t interval, uint16_t window, 36 uint8_t filter_policy); 37 38 /* Enable and start scanning/initiating role */ 39 uint8_t ull_scan_enable(struct ll_scan_set *scan); 40 41 /* Disable scanning/initiating role */ 42 uint8_t ull_scan_disable(uint8_t handle, struct ll_scan_set *scan); 43 44 /* Helper function to handle scan done events */ 45 void ull_scan_done(struct node_rx_event_done *done); 46 47 /* Helper function to dequeue scan timeout event */ 48 void ull_scan_term_dequeue(uint8_t handle); 49 50 /* Return ll_scan_set context (unconditional) */ 51 struct ll_scan_set *ull_scan_set_get(uint8_t handle); 52 53 /* Return the scan set handle given the scan set instance */ 54 uint8_t ull_scan_handle_get(struct ll_scan_set *scan); 55 56 /* Helper function to check and return if a valid scan context */ 57 struct ll_scan_set *ull_scan_is_valid_get(struct ll_scan_set *scan); 58 59 /* Return ll_scan_set context if enabled */ 60 struct ll_scan_set *ull_scan_is_enabled_get(uint8_t handle); 61 62 /* Return ll_scan_set context if disabled */ 63 struct ll_scan_set *ull_scan_is_disabled_get(uint8_t handle); 64 65 /* Return flags if enabled */ 66 #define ULL_SCAN_IS_PASSIVE BIT(0) 67 #define ULL_SCAN_IS_ACTIVE BIT(1) 68 #define ULL_SCAN_IS_INITIATOR BIT(2) 69 #define ULL_SCAN_IS_SYNC BIT(3) 70 uint32_t ull_scan_is_enabled(uint8_t handle); 71 72 /* Return filter policy used */ 73 uint32_t ull_scan_filter_pol_get(uint8_t handle); 74 75 int ull_scan_aux_init(void); 76 int ull_scan_aux_reset(void); 77 78 /* Helper to setup scanning on auxiliary channel */ 79 void ull_scan_aux_setup(memq_link_t *link, struct node_rx_pdu *rx); 80 81 /* Helper to clean up auxiliary channel scanning */ 82 void ull_scan_aux_done(struct node_rx_event_done *done); 83 84 /* Return the scan aux set instance given the handle */ 85 struct ll_scan_aux_set *ull_scan_aux_set_get(uint8_t handle); 86 87 /* Helper function to check and return if a valid aux scan context */ 88 struct ll_scan_aux_set *ull_scan_aux_is_valid_get(struct ll_scan_aux_set *aux); 89 90 /* Helper function to flush and release incomplete auxiliary PDU chaining */ 91 void ull_scan_aux_release(memq_link_t *link, struct node_rx_pdu *rx); 92 93 /* Helper function to stop auxiliary scan context */ 94 int ull_scan_aux_stop(struct ll_scan_aux_set *aux); 95