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