1 /* 2 * Copyright (c) 2020 Demant 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 /* Temporary data structure to avoid change ll_conn/lll_conn to much 8 * and having to update all the dependencies 9 */ 10 11 enum { ULL_CP_CONNECTED, ULL_CP_DISCONNECTED }; 12 13 /** 14 * @brief Initialize the LL Control Procedure system. 15 */ 16 void ull_cp_init(void); 17 18 /** 19 * @brief Initialize the LL Control Procedure connection data. 20 */ 21 void ull_llcp_init(struct ll_conn *conn); 22 23 /** 24 * @brief XXX 25 */ 26 void ull_cp_state_set(struct ll_conn *conn, uint8_t state); 27 28 void ull_cp_release_nodes(struct ll_conn *conn); 29 30 /* 31 * @brief Update 'global' tx buffer allowance 32 */ 33 void ull_cp_update_tx_buffer_queue(struct ll_conn *conn); 34 35 /** 36 * 37 */ 38 void ull_cp_release_tx(struct ll_conn *conn, struct node_tx *tx); 39 40 /** 41 * @brief Procedure Response Timeout Check 42 * @param elapsed_event The number of elapsed events. 43 * @param[out] error_code The error code for this timeout. 44 * @return 0 on success, -ETIMEDOUT if timer expired. 45 */ 46 int ull_cp_prt_elapse(struct ll_conn *conn, uint16_t elapsed_event, uint8_t *error_code); 47 48 void ull_cp_prt_reload_set(struct ll_conn *conn, uint32_t conn_intv); 49 50 /** 51 * @brief Run pending LL Control Procedures. 52 */ 53 void ull_cp_run(struct ll_conn *conn); 54 55 /** 56 * @brief Handle TX ack PDU. 57 */ 58 void ull_cp_tx_ack(struct ll_conn *conn, struct node_tx *tx); 59 60 /** 61 * @brief Handle TX procedures notifications towards Host. 62 */ 63 void ull_cp_tx_ntf(struct ll_conn *conn); 64 65 /** 66 * @brief Handle received LL Control PDU. 67 */ 68 void ull_cp_rx(struct ll_conn *conn, memq_link_t *link, struct node_rx_pdu *rx); 69 70 #if defined(CONFIG_BT_CTLR_LE_PING) 71 /** 72 * @brief Initiate a LE Ping Procedure. 73 */ 74 uint8_t ull_cp_le_ping(struct ll_conn *conn); 75 #endif /* CONFIG_BT_CTLR_LE_PING */ 76 77 /** 78 * @brief Initiate a Version Exchange Procedure. 79 */ 80 uint8_t ull_cp_version_exchange(struct ll_conn *conn); 81 82 /** 83 * @brief Initiate a Feature Exchange Procedure. 84 */ 85 uint8_t ull_cp_feature_exchange(struct ll_conn *conn, uint8_t host_initiated); 86 87 #if defined(CONFIG_BT_CTLR_MIN_USED_CHAN) 88 /** 89 * @brief Initiate a Minimum used channels Procedure. 90 */ 91 uint8_t ull_cp_min_used_chans(struct ll_conn *conn, uint8_t phys, uint8_t min_used_chans); 92 #endif /* CONFIG_BT_CTLR_MIN_USED_CHAN */ 93 94 /** 95 * @brief Initiate a Encryption Start Procedure. 96 */ 97 uint8_t ull_cp_encryption_start(struct ll_conn *conn, const uint8_t rand[8], const uint8_t ediv[2], 98 const uint8_t ltk[16]); 99 100 /** 101 * @brief Initiate a Encryption Pause Procedure. 102 */ 103 uint8_t ull_cp_encryption_pause(struct ll_conn *conn, const uint8_t rand[8], const uint8_t ediv[2], 104 const uint8_t ltk[16]); 105 106 /** 107 * @brief Check if an encryption pause procedure is active. 108 */ 109 uint8_t ull_cp_encryption_paused(struct ll_conn *conn); 110 111 /** 112 */ 113 uint8_t ull_cp_ltk_req_reply(struct ll_conn *conn, const uint8_t ltk[16]); 114 115 /** 116 */ 117 uint8_t ull_cp_ltk_req_neq_reply(struct ll_conn *conn); 118 119 /** 120 * @brief Initiate a PHY Update Procedure. 121 */ 122 uint8_t ull_cp_phy_update(struct ll_conn *conn, uint8_t tx, uint8_t flags, uint8_t rx, 123 uint8_t host_initiated); 124 125 /** 126 * @brief Initiate a Connection Parameter Request Procedure or Connection Update Procedure 127 */ 128 uint8_t ull_cp_conn_update(struct ll_conn *conn, uint16_t interval_min, uint16_t interval_max, 129 uint16_t latency, uint16_t timeout, uint16_t *offsets); 130 131 /** 132 * @brief Accept the remote device’s request to change connection parameters. 133 */ 134 void ull_cp_conn_param_req_reply(struct ll_conn *conn); 135 136 /** 137 * @brief Reject the remote device’s request to change connection parameters. 138 */ 139 void ull_cp_conn_param_req_neg_reply(struct ll_conn *conn, uint8_t error_code); 140 141 /** 142 * @brief Check if a remote data length update is in the works. 143 */ 144 uint8_t ull_cp_remote_dle_pending(struct ll_conn *conn); 145 146 /** 147 * @brief Check if a remote connection param reg is in the 148 * works. 149 */ 150 uint8_t ull_cp_remote_cpr_pending(struct ll_conn *conn); 151 152 /** 153 * @brief Check if a remote connection param reg is expecting an 154 * anchor point move response. 155 */ 156 bool ull_cp_remote_cpr_apm_awaiting_reply(struct ll_conn *conn); 157 158 /** 159 * @brief Repsond to anchor point move of remote connection 160 * param reg. 161 */ 162 void ull_cp_remote_cpr_apm_reply(struct ll_conn *conn, uint16_t *offsets); 163 164 /** 165 * @brief Reject anchor point move of remote connection param 166 * reg. 167 */ 168 void ull_cp_remote_cpr_apm_neg_reply(struct ll_conn *conn, uint8_t error_code); 169 170 /** 171 * @brief Initiate a Termination Procedure. 172 */ 173 uint8_t ull_cp_terminate(struct ll_conn *conn, uint8_t error_code); 174 175 /** 176 * @brief Initiate a CIS Termination Procedure. 177 */ 178 uint8_t ull_cp_cis_terminate(struct ll_conn *conn, struct ll_conn_iso_stream *cis, 179 uint8_t error_code); 180 181 /** 182 * @brief Initiate a CIS Create Procedure. 183 */ 184 uint8_t ull_cp_cis_create(struct ll_conn *conn, struct ll_conn_iso_stream *cis); 185 186 /** 187 * @brief Resume CIS create after CIS offset calculation. 188 */ 189 void ull_cp_cc_offset_calc_reply(struct ll_conn *conn, uint32_t cis_offset_min, 190 uint32_t cis_offset_max); 191 192 /** 193 * @brief Is ongoing create cis procedure expecting a reply? 194 */ 195 bool ull_cp_cc_awaiting_reply(struct ll_conn *conn); 196 197 /** 198 * @brief Is ongoing create cis procedure expecting an established event? 199 */ 200 bool ull_cp_cc_awaiting_established(struct ll_conn *conn); 201 202 /** 203 * @brief Cancel ongoing create cis procedure 204 */ 205 bool ull_cp_cc_cancel(struct ll_conn *conn); 206 207 /** 208 * @brief Get handle of ongoing create cis procedure. 209 * @return 0xFFFF if none 210 */ 211 uint16_t ull_cp_cc_ongoing_handle(struct ll_conn *conn); 212 213 /** 214 * @brief Accept the remote device’s request to create cis. 215 */ 216 void ull_cp_cc_accept(struct ll_conn *conn, uint32_t cis_offset_min); 217 218 /** 219 * @brief Reject the remote device’s request to create cis. 220 */ 221 void ull_cp_cc_reject(struct ll_conn *conn, uint8_t error_code); 222 223 /** 224 * @brief CIS was established. 225 */ 226 void ull_cp_cc_established(struct ll_conn *conn, uint8_t error_code); 227 228 /** 229 * @brief CIS creation ongoing. 230 */ 231 bool ull_lp_cc_is_active(struct ll_conn *conn); 232 233 /** 234 * @brief CIS creation ongoing or enqueued. 235 */ 236 bool ull_lp_cc_is_enqueued(struct ll_conn *conn); 237 238 /** 239 * @brief Initiate a Channel Map Update Procedure. 240 */ 241 uint8_t ull_cp_chan_map_update(struct ll_conn *conn, const uint8_t chm[5]); 242 243 /** 244 * @brief Check if Channel Map Update Procedure is pending 245 */ 246 const uint8_t *ull_cp_chan_map_update_pending(struct ll_conn *conn); 247 248 #if defined(CONFIG_BT_CTLR_DATA_LENGTH) 249 /** 250 * @brief Initiate a Data Length Update Procedure. 251 */ 252 uint8_t ull_cp_data_length_update(struct ll_conn *conn, uint16_t max_tx_octets, 253 uint16_t max_tx_time); 254 #endif /* CONFIG_BT_CTLR_DATA_LENGTH */ 255 /** 256 * @brief Initiate a CTE Request Procedure. 257 */ 258 uint8_t ull_cp_cte_req(struct ll_conn *conn, uint8_t min_cte_len, uint8_t cte_type); 259 260 /** 261 * @brief Set a CTE Request Procedure disabled. 262 */ 263 void ull_cp_cte_req_set_disable(struct ll_conn *conn); 264 265 /** 266 * @brief Enable or disable response to CTE Request Procedure. 267 */ 268 void ull_cp_cte_rsp_enable(struct ll_conn *conn, bool enable, uint8_t max_cte_len, 269 uint8_t cte_types); 270 271 #if defined(CONFIG_BT_CTLR_SCA_UPDATE) 272 /** 273 * @brief Initiate a Sleep Clock Accuracy Update Procedure. 274 */ 275 uint8_t ull_cp_req_peer_sca(struct ll_conn *conn); 276 #endif /* CONFIG_BT_CTLR_SCA_UPDATE */ 277