1 /*
2  * Copyright (c) 2020 Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <zephyr/types.h>
8 #include <zephyr/sys/byteorder.h>
9 #include <zephyr/ztest.h>
10 
11 #define ULL_LLCP_UNITTEST
12 
13 #include <zephyr/bluetooth/hci.h>
14 #include <zephyr/sys/slist.h>
15 #include <zephyr/sys/util.h>
16 #include "hal/ccm.h"
17 
18 #include "util/util.h"
19 #include "util/mem.h"
20 #include "util/memq.h"
21 #include "util/dbuf.h"
22 
23 #include "pdu_df.h"
24 #include "lll/pdu_vendor.h"
25 #include "pdu.h"
26 #include "ll.h"
27 #include "ll_settings.h"
28 
29 #include "lll.h"
30 #include "lll/lll_df_types.h"
31 #include "lll_conn.h"
32 #include "lll_conn_iso.h"
33 
34 #include "ull_tx_queue.h"
35 
36 #include "isoal.h"
37 #include "ull_iso_types.h"
38 #include "ull_conn_iso_types.h"
39 #include "ull_conn_types.h"
40 
41 #include "ull_llcp.h"
42 #include "ull_conn_internal.h"
43 #include "ull_llcp_internal.h"
44 
45 #include "ll_feat.h"
46 
47 #include "helper_pdu.h"
48 #include "helper_util.h"
49 #include "helper_features.h"
50 
51 static struct ll_conn *conn_from_pool;
52 
hci_setup(void * data)53 static void hci_setup(void *data)
54 {
55 	ull_conn_init();
56 
57 	conn_from_pool = ll_conn_acquire();
58 	zassert_not_null(conn_from_pool, "Could not allocate connection memory");
59 
60 	test_setup(conn_from_pool);
61 }
62 
63 /*
64  * +-----+                     +-------+            +-----+
65  * | UT  |                     | LL_A  |            | LT  |
66  * +-----+                     +-------+            +-----+
67  *    |                            |                   |
68  *    | Start                      |                   |
69  *    | Feature Exchange Proc.     |                   |
70  *    |--------------------------->|                   |
71  *    |                            |                   |
72  *    |                            | LL_FEATURE_REQ    |
73  *    |                            |------------------>|
74  *    |                            |                   |
75  *    |                            |    LL_FEATURE_RSP |
76  *    |                            |<------------------|
77  *    |                            |                   |
78  *    |     Feature Exchange Proc. |                   |
79  *    |                   Complete |                   |
80  *    |<---------------------------|                   |
81  *    |                            |                   |
82  */
ZTEST(hci_fex,test_hci_feature_exchange)83 ZTEST(hci_fex, test_hci_feature_exchange)
84 {
85 	uint8_t err;
86 	uint64_t set_feature = DEFAULT_FEATURE;
87 	uint64_t rsp_feature = ((LL_FEAT_BIT_MASK_VALID & FEAT_FILTER_OCTET0) | DEFAULT_FEATURE) &
88 			       LL_FEAT_BIT_MASK_VALID;
89 
90 	struct node_tx *tx;
91 	struct node_rx_pdu *ntf;
92 
93 	struct pdu_data_llctrl_feature_req local_feature_req;
94 	struct pdu_data_llctrl_feature_rsp remote_feature_rsp;
95 
96 	uint16_t conn_handle;
97 
98 	conn_handle = ll_conn_handle_get(conn_from_pool);
99 
100 	test_set_role(conn_from_pool, BT_HCI_ROLE_CENTRAL);
101 	/* Connect */
102 	ull_cp_state_set(conn_from_pool, ULL_CP_CONNECTED);
103 
104 	sys_put_le64(set_feature, local_feature_req.features);
105 	sys_put_le64(rsp_feature, remote_feature_rsp.features);
106 
107 	/* Initiate a Feature Exchange Procedure via HCI */
108 	err = ll_feature_req_send(conn_handle);
109 	zassert_equal(err, BT_HCI_ERR_SUCCESS, "Error: %u", err);
110 
111 	/* basically copied from unit-test for feature exchange */
112 	event_prepare(conn_from_pool);
113 	lt_rx(LL_FEATURE_REQ, conn_from_pool, &tx, &local_feature_req);
114 	lt_rx_q_is_empty(conn_from_pool);
115 	lt_tx(LL_FEATURE_RSP, conn_from_pool, &remote_feature_rsp);
116 	event_done(conn_from_pool);
117 	ut_rx_pdu(LL_FEATURE_RSP, &ntf, &remote_feature_rsp);
118 	ut_rx_q_is_empty();
119 	zassert_equal(conn_from_pool->lll.event_counter, 1, "Wrong event count %d\n",
120 		      conn_from_pool->lll.event_counter);
121 	ull_cp_release_tx(conn_from_pool, tx);
122 	release_ntf(ntf);
123 
124 	ll_conn_release(conn_from_pool);
125 }
126 
ZTEST(hci_fex,test_hci_feature_exchange_wrong_handle)127 ZTEST(hci_fex, test_hci_feature_exchange_wrong_handle)
128 {
129 	uint16_t conn_handle;
130 	uint8_t err;
131 	int ctx_counter;
132 	struct proc_ctx *ctx;
133 
134 	conn_handle = ll_conn_handle_get(conn_from_pool);
135 
136 	err = ll_feature_req_send(conn_handle + 1);
137 
138 	zassert_equal(err, BT_HCI_ERR_UNKNOWN_CONN_ID, "Wrong reply for wrong handle\n");
139 
140 	/* Use up all local procedure contexts */
141 	ctx_counter = 0;
142 	do {
143 		ctx = llcp_create_local_procedure(PROC_FEATURE_EXCHANGE);
144 		ctx_counter++;
145 	} while (ctx != NULL);
146 
147 	err = ll_feature_req_send(conn_handle);
148 	zassert_equal(err, BT_HCI_ERR_CMD_DISALLOWED, "Wrong reply for no-resource condition\n");
149 }
150 
ZTEST(hci_version,test_hci_version_ind)151 ZTEST(hci_version, test_hci_version_ind)
152 {
153 	uint8_t err;
154 	uint16_t conn_handle;
155 	struct node_tx *tx;
156 	struct node_rx_pdu *ntf;
157 	struct pdu_data_llctrl_version_ind local_pdu = {
158 		.version_number = LL_VERSION_NUMBER,
159 		.company_id = CONFIG_BT_CTLR_COMPANY_ID,
160 		.sub_version_number = CONFIG_BT_CTLR_SUBVERSION_NUMBER,
161 	};
162 
163 	struct pdu_data_llctrl_version_ind remote_pdu = {
164 		.version_number = 0x55,
165 		.company_id = 0xABCD,
166 		.sub_version_number = 0x1234,
167 	};
168 
169 	conn_handle = ll_conn_handle_get(conn_from_pool);
170 
171 	test_set_role(conn_from_pool, BT_HCI_ROLE_CENTRAL);
172 	/* Connect */
173 	ull_cp_state_set(conn_from_pool, ULL_CP_CONNECTED);
174 
175 	err = ll_version_ind_send(conn_handle);
176 	zassert_equal(err, BT_HCI_ERR_SUCCESS, "Error: %u", err);
177 
178 	event_prepare(conn_from_pool);
179 	lt_rx(LL_VERSION_IND, conn_from_pool, &tx, &local_pdu);
180 	lt_rx_q_is_empty(conn_from_pool);
181 	lt_tx(LL_VERSION_IND, conn_from_pool, &remote_pdu);
182 	event_done(conn_from_pool);
183 	ut_rx_pdu(LL_VERSION_IND, &ntf, &remote_pdu);
184 	ut_rx_q_is_empty();
185 	zassert_equal(conn_from_pool->lll.event_counter, 1, "Wrong event count %d\n",
186 		      conn_from_pool->lll.event_counter);
187 	ull_cp_release_tx(conn_from_pool, tx);
188 	release_ntf(ntf);
189 
190 	ll_conn_release(conn_from_pool);
191 }
192 
ZTEST(hci_version,test_hci_version_ind_wrong_handle)193 ZTEST(hci_version, test_hci_version_ind_wrong_handle)
194 {
195 	uint16_t conn_handle;
196 	uint64_t err;
197 	int ctx_counter;
198 	struct proc_ctx *ctx;
199 
200 	conn_handle = ll_conn_handle_get(conn_from_pool);
201 
202 	err = ll_version_ind_send(conn_handle + 1);
203 
204 	zassert_equal(err, BT_HCI_ERR_UNKNOWN_CONN_ID, "Wrong reply for wrong handle\n");
205 
206 	ctx_counter = 0;
207 	do {
208 		ctx = llcp_create_local_procedure(PROC_VERSION_EXCHANGE);
209 		ctx_counter++;
210 	} while (ctx != NULL);
211 
212 	err = ll_version_ind_send(conn_handle);
213 	zassert_equal(err, BT_HCI_ERR_CMD_DISALLOWED, "Wrong reply for no-resource condition\n");
214 }
215 
ZTEST(hci_apto,test_hci_apto)216 ZTEST(hci_apto, test_hci_apto)
217 {
218 	uint16_t conn_handle;
219 	uint64_t err;
220 
221 	uint16_t apto;
222 
223 	conn_handle = ll_conn_handle_get(conn_from_pool);
224 
225 	test_set_role(conn_from_pool, BT_HCI_ROLE_CENTRAL);
226 	/* Connect */
227 	ull_cp_state_set(conn_from_pool, ULL_CP_CONNECTED);
228 
229 	conn_from_pool->apto_reload = 100;
230 	conn_from_pool->lll.interval = 10;
231 	err = ll_apto_get(conn_handle, &apto);
232 	zassert_equal(err, BT_HCI_ERR_SUCCESS);
233 	zassert_equal(apto, 125, "Apto is %d", apto);
234 
235 	err = ll_apto_get(conn_handle + 1, &apto);
236 	zassert_equal(err, BT_HCI_ERR_UNKNOWN_CONN_ID);
237 
238 	err = ll_apto_set(conn_handle, 1000);
239 	zassert_equal(err, BT_HCI_ERR_SUCCESS);
240 	zassert_equal(conn_from_pool->apto_reload, 800, "Apto reload is %d",
241 		      conn_from_pool->apto_reload);
242 
243 	err = ll_apto_get(conn_handle + 1, 0x00);
244 	zassert_equal(err, BT_HCI_ERR_UNKNOWN_CONN_ID);
245 }
246 
ZTEST(hci_phy,test_hci_phy)247 ZTEST(hci_phy, test_hci_phy)
248 {
249 	uint16_t conn_handle;
250 	uint8_t err;
251 
252 	uint8_t phy_tx, phy_rx;
253 
254 	conn_handle = ll_conn_handle_get(conn_from_pool);
255 
256 	test_set_role(conn_from_pool, BT_HCI_ROLE_CENTRAL);
257 	/* Connect */
258 	ull_cp_state_set(conn_from_pool, ULL_CP_CONNECTED);
259 
260 	err = ll_phy_req_send(conn_handle + 1, 0x00, 0x00, 0x00);
261 	zassert_equal(err, BT_HCI_ERR_UNKNOWN_CONN_ID);
262 	conn_from_pool->llcp.fex.features_used = 0x00;
263 	conn_from_pool->llcp.fex.valid = 1;
264 	err = ll_phy_req_send(conn_handle, 0x03, 0xFF, 0x03);
265 	zassert_equal(err, BT_HCI_ERR_UNSUPP_REMOTE_FEATURE, "Errorcode %u", err);
266 
267 	conn_from_pool->llcp.fex.features_used = 0xFFFF;
268 	err = ll_phy_req_send(conn_handle, 0x03, 0xFF, 0x03);
269 	zassert_equal(err, BT_HCI_ERR_SUCCESS, "Errorcode %u", err);
270 	err = ll_phy_get(conn_handle + 1, &phy_tx, &phy_rx);
271 	zassert_equal(err, BT_HCI_ERR_UNKNOWN_CONN_ID);
272 
273 	conn_from_pool->lll.phy_rx = 0x3;
274 	conn_from_pool->lll.phy_tx = 0x7;
275 	err = ll_phy_get(conn_handle, &phy_tx, &phy_rx);
276 	zassert_equal(err, BT_HCI_ERR_SUCCESS);
277 	zassert_equal(phy_tx, 0x07);
278 	zassert_equal(phy_rx, 0x03);
279 
280 	err = ll_phy_default_set(0x00, 0x00);
281 	zassert_equal(err, BT_HCI_ERR_SUCCESS);
282 	phy_tx = ull_conn_default_phy_tx_get();
283 	phy_rx = ull_conn_default_phy_rx_get();
284 	zassert_equal(phy_tx, 0x00);
285 	zassert_equal(phy_rx, 0x00);
286 	err = ll_phy_default_set(0x01, 0x03);
287 	zassert_equal(err, BT_HCI_ERR_SUCCESS);
288 	phy_tx = ull_conn_default_phy_tx_get();
289 	phy_rx = ull_conn_default_phy_rx_get();
290 	zassert_equal(phy_tx, 0x01);
291 	zassert_equal(phy_rx, 0x03);
292 }
293 
ZTEST(hci_dle,test_hci_dle)294 ZTEST(hci_dle, test_hci_dle)
295 {
296 	uint16_t conn_handle;
297 	uint8_t err;
298 
299 	uint16_t tx_octets, tx_time;
300 	uint16_t max_tx_octets, max_tx_time;
301 	uint16_t max_rx_octets, max_rx_time;
302 
303 	conn_handle = ll_conn_handle_get(conn_from_pool);
304 
305 	test_set_role(conn_from_pool, BT_HCI_ROLE_CENTRAL);
306 	/* Connect */
307 	ull_cp_state_set(conn_from_pool, ULL_CP_CONNECTED);
308 
309 	tx_octets = 251;
310 	tx_time = 2400;
311 
312 	conn_from_pool->llcp.fex.features_used = 0x00;
313 	err = ll_length_req_send(conn_handle, tx_octets, tx_time);
314 	zassert_equal(err, BT_HCI_ERR_UNSUPP_REMOTE_FEATURE, "Errorcode %u", err);
315 	conn_from_pool->llcp.fex.features_used = 0xFFFFFFFF;
316 	err = ll_length_req_send(conn_handle + 1, tx_octets, tx_time);
317 	zassert_equal(err, BT_HCI_ERR_UNKNOWN_CONN_ID, "Errorcode %u", err);
318 
319 	ll_length_max_get(&max_tx_octets, &max_tx_time, &max_rx_octets, &max_rx_time);
320 	zassert_equal(max_tx_octets, LL_LENGTH_OCTETS_RX_MAX);
321 	zassert_equal(max_rx_octets, LL_LENGTH_OCTETS_RX_MAX);
322 	zassert_equal(max_tx_time, 17040, "Actual time is %d", max_tx_time);
323 	zassert_equal(max_rx_time, 17040, "Actual time is %d", max_rx_time);
324 
325 	err = ll_length_default_set(0x00, 0x00);
326 	ll_length_default_get(&max_tx_octets, &max_tx_time);
327 	zassert_equal(err, 00);
328 	zassert_equal(max_tx_octets, 0x00);
329 	zassert_equal(max_tx_time, 0x00);
330 	err = ll_length_default_set(0x10, 0x3FF);
331 	ll_length_default_get(&max_tx_octets, &max_tx_time);
332 	zassert_equal(err, 00);
333 	zassert_equal(max_tx_octets, 0x10);
334 	zassert_equal(max_tx_time, 0x3FF);
335 	max_tx_octets = ull_conn_default_tx_octets_get();
336 	max_tx_time = ull_conn_default_tx_time_get();
337 	zassert_equal(max_tx_octets, 0x10);
338 	zassert_equal(max_tx_time, 0x3FF);
339 }
340 
ZTEST(hci_terminate,test_hci_terminate)341 ZTEST(hci_terminate, test_hci_terminate)
342 {
343 	uint16_t conn_handle;
344 	uint8_t err;
345 
346 	uint8_t reason;
347 
348 	conn_handle = ll_conn_handle_get(conn_from_pool);
349 
350 	test_set_role(conn_from_pool, BT_HCI_ROLE_CENTRAL);
351 	/* Connect */
352 	ull_cp_state_set(conn_from_pool, ULL_CP_CONNECTED);
353 
354 	reason = 0x01;
355 	err = ll_terminate_ind_send(conn_handle + 1, reason);
356 	zassert_equal(err, BT_HCI_ERR_CMD_DISALLOWED, "Errorcode %u", err);
357 	err = ll_terminate_ind_send(conn_handle, reason);
358 	zassert_equal(err, BT_HCI_ERR_INVALID_PARAM, "Errorcode %u", err);
359 	reason = BT_HCI_ERR_REMOTE_USER_TERM_CONN;
360 	err = ll_terminate_ind_send(conn_handle, reason);
361 	zassert_equal(err, BT_HCI_ERR_SUCCESS, "Errorcode %u", err);
362 }
363 
ZTEST(hci_conn_update,test_hci_conn_update)364 ZTEST(hci_conn_update, test_hci_conn_update)
365 {
366 	uint16_t conn_handle;
367 	uint8_t err;
368 
369 	uint8_t cmd, status;
370 	uint16_t interval_min, interval_max, latency, timeout, *offsets;
371 
372 	uint8_t unknown_cmds[3U] = { 1U, 3U, 255U };
373 
374 	cmd = 0x00;
375 	status = 0x00;
376 	interval_min = 10U;
377 	interval_max = 100U;
378 	latency = 5U;
379 	timeout = 1000U;
380 	offsets = NULL;
381 
382 	conn_handle = ll_conn_handle_get(conn_from_pool);
383 
384 	test_set_role(conn_from_pool, BT_HCI_ROLE_CENTRAL);
385 	/* Connect */
386 	ull_cp_state_set(conn_from_pool, ULL_CP_CONNECTED);
387 
388 	/* Unknown Connection ID */
389 	err = ll_conn_update(conn_handle + 1, cmd, status, interval_min, interval_max, latency,
390 			     timeout, offsets);
391 	zassert_equal(err, BT_HCI_ERR_UNKNOWN_CONN_ID, "Errorcode %u", err);
392 
393 	/* Unknown commands */
394 	for (uint8_t i = 0U; i < sizeof(unknown_cmds); i++) {
395 		err = ll_conn_update(conn_handle, unknown_cmds[i], status, interval_min,
396 				     interval_max, latency, timeout, offsets);
397 		zassert_equal(err, BT_HCI_ERR_UNKNOWN_CMD, "Errorcode %u", err);
398 	}
399 
400 	/* Connection Update or Connection Parameter Req. */
401 	conn_from_pool->llcp.fex.features_used |= BIT64(BT_LE_FEAT_BIT_CONN_PARAM_REQ);
402 	err = ll_conn_update(conn_handle, cmd, status, interval_min, interval_max, latency,
403 			     timeout, offsets);
404 	zassert_equal(err, BT_HCI_ERR_SUCCESS, "Errorcode %u", err);
405 
406 	conn_from_pool->llcp.fex.features_used &= ~BIT64(BT_LE_FEAT_BIT_CONN_PARAM_REQ);
407 	err = ll_conn_update(conn_handle, cmd, status, interval_min, interval_max, latency,
408 			     timeout, offsets);
409 	zassert_equal(err, BT_HCI_ERR_SUCCESS, "Errorcode %u", err);
410 
411 	/* Connection Parameter Req. Reply */
412 	cmd = 2U;
413 	conn_from_pool->llcp.fex.features_used |= BIT64(BT_LE_FEAT_BIT_CONN_PARAM_REQ);
414 	err = ll_conn_update(conn_handle, cmd, status, interval_min, interval_max, latency,
415 			     timeout, offsets);
416 	zassert_equal(err, BT_HCI_ERR_SUCCESS, "Errorcode %u", err);
417 
418 	/* Connection Parameter Req. Neg. Reply */
419 	status = 0x01;
420 	conn_from_pool->llcp.fex.features_used |= BIT64(BT_LE_FEAT_BIT_CONN_PARAM_REQ);
421 	err = ll_conn_update(conn_handle, cmd, status, 0U, 0U, 0U, 0U, NULL);
422 	zassert_equal(err, BT_HCI_ERR_SUCCESS, "Errorcode %u", err);
423 }
424 
425 /* 'Define' out Central API tests because ull_central.c is mock'ed, so API is not supported */
426 #define ULL_CENTRAL_MOCKED
427 
ZTEST(hci_channelmap,test_hci_chmap)428 ZTEST(hci_channelmap, test_hci_chmap)
429 {
430 #ifndef ULL_CENTRAL_MOCKED
431 	uint16_t conn_handle;
432 	uint8_t err;
433 	uint8_t chmap[5] = {0};
434 	uint8_t chmap_default[5] = { 0x12, 0x34, 0x56, 0x78, 0x9a };
435 	uint8_t chmap_test[5] = { 0x42, 0x00, 0x42, 0x00, 0x00 };
436 
437 	err = ll_chm_update(chmap);
438 	zassert_equal(err, BT_HCI_ERR_INVALID_PARAM, "Errorcode %u", err);
439 
440 	conn_handle = ll_conn_handle_get(conn_from_pool);
441 	memcpy(conn_from_pool->lll.data_chan_map, chmap_default,
442 	       sizeof(conn_from_pool->lll.data_chan_map));
443 
444 	test_set_role(conn_from_pool, BT_HCI_ROLE_PERIPHERAL);
445 	ull_cp_state_set(conn_from_pool, ULL_CP_CONNECTED);
446 
447 	err = ll_chm_get(conn_handle + 1, chmap);
448 	zassert_equal(err, BT_HCI_ERR_UNKNOWN_CONN_ID, "Errorcode %u", err);
449 
450 	err = ll_chm_get(conn_handle, chmap);
451 	zassert_equal(err, BT_HCI_ERR_SUCCESS, "Errorcode %u", err);
452 	zassert_mem_equal(chmap, chmap_default, sizeof(chmap), "Channel map invalid");
453 
454 	test_set_role(conn_from_pool, BT_HCI_ROLE_CENTRAL);
455 
456 	err = ll_chm_get(conn_handle, chmap);
457 	zassert_equal(err, BT_HCI_ERR_SUCCESS, "Errorcode %u", err);
458 	zassert_mem_equal(chmap, chmap_default, sizeof(chmap), "Channel map invalid");
459 
460 	err = ll_chm_update(chmap_test);
461 	zassert_equal(err, BT_HCI_ERR_SUCCESS, "Errorcode %u", err);
462 
463 	err = ll_chm_get(conn_handle, chmap);
464 	zassert_equal(err, BT_HCI_ERR_SUCCESS, "Errorcode %u", err);
465 	zassert_mem_equal(chmap, chmap_test, sizeof(chmap), "Channel map invalid");
466 #endif /* !defined(ULL_CENTRAL_MOCKED) */
467 }
468 
ZTEST(hci_rssi,test_hci_rssi)469 ZTEST(hci_rssi, test_hci_rssi)
470 {
471 	uint16_t conn_handle;
472 	uint8_t err;
473 
474 	uint8_t rssi;
475 
476 	conn_handle = ll_conn_handle_get(conn_from_pool);
477 
478 	conn_from_pool->lll.rssi_latest = 0xcd;
479 
480 	test_set_role(conn_from_pool, BT_HCI_ROLE_CENTRAL);
481 	/* Connect */
482 	ull_cp_state_set(conn_from_pool, ULL_CP_CONNECTED);
483 
484 	err = ll_rssi_get(conn_handle + 1, &rssi);
485 	zassert_equal(err, BT_HCI_ERR_UNKNOWN_CONN_ID, "Errorcode %u", err);
486 
487 	err = ll_rssi_get(conn_handle, &rssi);
488 	zassert_equal(err, BT_HCI_ERR_SUCCESS, "Errorcode %u", err);
489 	zassert_equal(rssi, 0xcd, "RSSI %d", rssi);
490 }
491 
ZTEST(hci_encryption,test_hci_enc)492 ZTEST(hci_encryption, test_hci_enc)
493 {
494 #ifndef ULL_CENTRAL_MOCKED
495 	uint16_t conn_handle;
496 	uint8_t err;
497 
498 	uint8_t rand_nr;
499 	uint8_t ediv;
500 	uint8_t error_code;
501 	uint8_t ltk[5];
502 
503 	conn_handle = ll_conn_handle_get(conn_from_pool);
504 
505 	test_set_role(conn_from_pool, BT_HCI_ROLE_CENTRAL);
506 	/* Connect */
507 	ull_cp_state_set(conn_from_pool, ULL_CP_CONNECTED);
508 
509 	error_code = 0;
510 
511 	err = ll_enc_req_send(conn_handle + 1, &rand_nr, &ediv, &ltk[0]);
512 	zassert_equal(err, BT_HCI_ERR_UNKNOWN_CONN_ID, "Errorcode %u", err);
513 	err = ll_enc_req_send(conn_handle, &rand_nr, &ediv, &ltk[0]);
514 	zassert_equal(err, BT_HCI_ERR_SUCCESS, "Errorcode %u", err);
515 
516 	test_set_role(conn_from_pool, BT_HCI_ROLE_PERIPHERAL);
517 	err = ll_start_enc_req_send(conn_handle + 1, error_code, &ltk[0]);
518 	zassert_equal(err, BT_HCI_ERR_UNKNOWN_CONN_ID, "Errorcode %u", err);
519 	err = ll_start_enc_req_send(conn_handle, error_code, &ltk[0]);
520 	zassert_equal(err, BT_HCI_ERR_SUCCESS, "Errorcode %u", err);
521 #endif /* !defined(ULL_CENTRAL_MOCKED) */
522 }
523 
524 ZTEST_SUITE(hci_fex, NULL, NULL, hci_setup, NULL, NULL);
525 ZTEST_SUITE(hci_version, NULL, NULL, hci_setup, NULL, NULL);
526 ZTEST_SUITE(hci_apto, NULL, NULL, hci_setup, NULL, NULL);
527 ZTEST_SUITE(hci_phy, NULL, NULL, hci_setup, NULL, NULL);
528 ZTEST_SUITE(hci_dle, NULL, NULL, hci_setup, NULL, NULL);
529 ZTEST_SUITE(hci_terminate, NULL, NULL, hci_setup, NULL, NULL);
530 ZTEST_SUITE(hci_conn_update, NULL, NULL, hci_setup, NULL, NULL);
531 ZTEST_SUITE(hci_channelmap, NULL, NULL, hci_setup, NULL, NULL);
532 ZTEST_SUITE(hci_rssi, NULL, NULL, hci_setup, NULL, NULL);
533 ZTEST_SUITE(hci_encryption, NULL, NULL, hci_setup, NULL, NULL);
534