1 /*
2 * Copyright (c) 2020 Demant
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <zephyr/types.h>
8 #include <zephyr/ztest.h>
9
10 #define ULL_LLCP_UNITTEST
11
12 #include <zephyr/bluetooth/hci.h>
13 #include <zephyr/sys/byteorder.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 #include "ull_llcp.h"
41 #include "ull_conn_internal.h"
42 #include "ull_llcp_internal.h"
43
44 #include "helper_pdu.h"
45 #include "helper_util.h"
46
47 /* Default connection values */
48 #define INTVL_MIN 6U /* multiple of 1.25 ms (min 6, max 3200) */
49 #define INTVL_MAX 6U /* multiple of 1.25 ms (min 6, max 3200) */
50 #define LATENCY 1U
51 #define TIMEOUT 10U /* multiple of 10 ms (min 10, max 3200) */
52
53 /* Default conn_update_ind PDU */
54 struct pdu_data_llctrl_conn_update_ind conn_update_ind = { .win_size = 1U,
55 .win_offset = 0U,
56 .interval = INTVL_MAX,
57 .latency = LATENCY,
58 .timeout = TIMEOUT,
59 .instant = 6U };
60
61 /* Default conn_param_req PDU */
62 struct pdu_data_llctrl_conn_param_req conn_param_req = { .interval_min = INTVL_MIN,
63 .interval_max = INTVL_MAX,
64 .latency = LATENCY,
65 .timeout = TIMEOUT,
66 .preferred_periodicity = 0U,
67 .reference_conn_event_count = 0u,
68 .offset0 = 0x0000U,
69 .offset1 = 0xffffU,
70 .offset2 = 0xffffU,
71 .offset3 = 0xffffU,
72 .offset4 = 0xffffU,
73 .offset5 = 0xffffU };
74
75 #if defined(CONFIG_BT_CTLR_CONN_PARAM_REQ)
76 /* Default conn_param_rsp PDU */
77 struct pdu_data_llctrl_conn_param_rsp conn_param_rsp = { .interval_min = INTVL_MIN,
78 .interval_max = INTVL_MAX,
79 .latency = LATENCY,
80 .timeout = TIMEOUT,
81 .preferred_periodicity = 0U,
82 .reference_conn_event_count = 0u,
83 .offset0 = 0x0000U,
84 .offset1 = 0xffffU,
85 .offset2 = 0xffffU,
86 .offset3 = 0xffffU,
87 .offset4 = 0xffffU,
88 .offset5 = 0xffffU };
89
90 /* Invalid conn_param_req PDU */
91 struct pdu_data_llctrl_conn_param_req conn_param_req_invalid = { .interval_min = INTVL_MIN - 1,
92 .interval_max = INTVL_MAX + 1,
93 .latency = LATENCY,
94 .timeout = TIMEOUT - 1,
95 .preferred_periodicity = 0U,
96 .reference_conn_event_count = 0u,
97 .offset0 = 0x0000U,
98 .offset1 = 0xffffU,
99 .offset2 = 0xffffU,
100 .offset3 = 0xffffU,
101 .offset4 = 0xffffU,
102 .offset5 = 0xffffU };
103 /* Invalid conn_param_rsp PDU */
104 struct pdu_data_llctrl_conn_param_rsp conn_param_rsp_invalid = { .interval_min = INTVL_MIN - 1,
105 .interval_max = INTVL_MAX + 1,
106 .latency = LATENCY,
107 .timeout = TIMEOUT - 1,
108 .preferred_periodicity = 0U,
109 .reference_conn_event_count = 0u,
110 .offset0 = 0x0000U,
111 .offset1 = 0xffffU,
112 .offset2 = 0xffffU,
113 .offset3 = 0xffffU,
114 .offset4 = 0xffffU,
115 .offset5 = 0xffffU };
116 /* Different PDU contents for (B) */
117
118 /* Default conn_param_req PDU (B) */
119 struct pdu_data_llctrl_conn_param_req conn_param_req_B = {
120 .interval_min = INTVL_MIN,
121 .interval_max = INTVL_MAX,
122 .latency = LATENCY + 1U, /* differentiate parameter */
123 .timeout = TIMEOUT + 1U, /* differentiate parameter */
124 .preferred_periodicity = 0U,
125 .reference_conn_event_count = 0u,
126 .offset0 = 0x0000U,
127 .offset1 = 0xffffU,
128 .offset2 = 0xffffU,
129 .offset3 = 0xffffU,
130 .offset4 = 0xffffU,
131 .offset5 = 0xffffU
132 };
133
134 /* Default conn_param_rsp PDU (B) */
135 struct pdu_data_llctrl_conn_param_rsp conn_param_rsp_B = {
136 .interval_min = INTVL_MIN,
137 .interval_max = INTVL_MAX,
138 .latency = LATENCY + 1U, /* differentiate parameter */
139 .timeout = TIMEOUT + 1U, /* differentiate parameter */
140 .preferred_periodicity = 0U,
141 .reference_conn_event_count = 0u,
142 .offset0 = 0x0000U,
143 .offset1 = 0xffffU,
144 .offset2 = 0xffffU,
145 .offset3 = 0xffffU,
146 .offset4 = 0xffffU,
147 .offset5 = 0xffffU
148 };
149 #endif /* CONFIG_BT_CTLR_CONN_PARAM_REQ */
150
151 /* Default conn_update_ind PDU (B) */
152 struct pdu_data_llctrl_conn_update_ind conn_update_ind_B = {
153 .win_size = 1U,
154 .win_offset = 0U,
155 .interval = INTVL_MAX,
156 .latency = LATENCY + 1U, /* differentiate parameter */
157 .timeout = TIMEOUT + 1U, /* differentiate parameter */
158 .instant = 6U
159 };
160
161 #if defined(CONFIG_BT_CTLR_CONN_PARAM_REQ)
162 struct pdu_data_llctrl_conn_param_req *req_B = &conn_param_req_B;
163 struct pdu_data_llctrl_conn_param_rsp *rsp_B = &conn_param_rsp_B;
164 #endif /* CONFIG_BT_CTLR_CONN_PARAM_REQ */
165
166 struct pdu_data_llctrl_conn_update_ind *cu_ind_B = &conn_update_ind_B;
167
168 static struct ll_conn conn;
169
170
171 #if defined(CONFIG_BT_CTLR_CONN_PARAM_REQ)
172 #if defined(CONFIG_BT_CTLR_USER_CPR_ANCHOR_POINT_MOVE)
ull_handle_cpr_anchor_point_move(struct ll_conn * conn,uint16_t * offsets,uint8_t * status)173 bool ull_handle_cpr_anchor_point_move(struct ll_conn *conn, uint16_t *offsets, uint8_t *status)
174 {
175 ztest_copy_return_data(status, 1);
176 return ztest_get_return_value();
177 }
178 #endif /* CONFIG_BT_CTLR_USER_CPR_ANCHOR_POINT_MOVE */
179
test_unmask_feature_conn_param_req(struct ll_conn * conn)180 static void test_unmask_feature_conn_param_req(struct ll_conn *conn)
181 {
182 conn->llcp.fex.features_used &= ~BIT64(BT_LE_FEAT_BIT_CONN_PARAM_REQ);
183 }
184
test_get_feature_conn_param_req(struct ll_conn * conn)185 static bool test_get_feature_conn_param_req(struct ll_conn *conn)
186 {
187 return (conn->llcp.fex.features_used & BIT64(BT_LE_FEAT_BIT_CONN_PARAM_REQ));
188 }
189 #endif /* CONFIG_BT_CTLR_CONN_PARAM_REQ */
190
conn_update_setup(void * data)191 static void conn_update_setup(void *data)
192 {
193 test_setup(&conn);
194
195 conn_param_req.reference_conn_event_count = -1;
196 #if defined(CONFIG_BT_CTLR_CONN_PARAM_REQ)
197 conn_param_rsp.reference_conn_event_count = -1;
198 #endif
199
200 /* Initialize lll conn parameters (different from new) */
201 struct lll_conn *lll = &conn.lll;
202
203 lll->interval = 0;
204 lll->latency = 0;
205 conn.supervision_timeout = 1U;
206 lll->event_counter = 0;
207 }
208
is_instant_reached(struct ll_conn * conn,uint16_t instant)209 static bool is_instant_reached(struct ll_conn *conn, uint16_t instant)
210 {
211 return ((event_counter(conn) - instant) & 0xFFFF) <= 0x7FFF;
212 }
213
214 #if defined(CONFIG_BT_CTLR_CONN_PARAM_REQ)
215 /*
216 * Central-initiated Connection Parameters Request procedure.
217 * Central requests change in LE connection parameters, peripheral’s Host accepts.
218 *
219 * +-----+ +-------+ +-----+
220 * | UT | | LL_C | | LT |
221 * +-----+ +-------+ +-----+
222 * | | |
223 * | LE Connection Update | |
224 * |-------------------------->| |
225 * | | LL_CONNECTION_PARAM_REQ |
226 * | |-------------------------->|
227 * | | |
228 * | | LL_CONNECTION_PARAM_RSP |
229 * | |<--------------------------|
230 * | | |
231 * | | LL_CONNECTION_UPDATE_IND |
232 * | |-------------------------->|
233 * | | |
234 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
235 * | | |
236 * | LE Connection Update | |
237 * | Complete | |
238 * |<--------------------------| |
239 * | | |
240 */
ZTEST(central_loc,test_conn_update_central_loc_accept)241 ZTEST(central_loc, test_conn_update_central_loc_accept)
242 {
243 uint8_t err;
244 struct node_tx *tx;
245 struct node_rx_pdu *ntf;
246 struct pdu_data *pdu;
247 uint16_t instant;
248
249 struct node_rx_pu cu = { .status = BT_HCI_ERR_SUCCESS };
250
251 /* Role */
252 test_set_role(&conn, BT_HCI_ROLE_CENTRAL);
253
254 /* Connect */
255 ull_cp_state_set(&conn, ULL_CP_CONNECTED);
256
257 /* Initiate a Connection Parameter Request Procedure */
258 err = ull_cp_conn_update(&conn, INTVL_MIN, INTVL_MAX, LATENCY, TIMEOUT, NULL);
259 zassert_equal(err, BT_HCI_ERR_SUCCESS);
260
261 /* Prepare */
262 event_prepare(&conn);
263
264 /* Tx Queue should have one LL Control PDU */
265 conn_param_req.reference_conn_event_count = event_counter(&conn);
266 lt_rx(LL_CONNECTION_PARAM_REQ, &conn, &tx, &conn_param_req);
267 lt_rx_q_is_empty(&conn);
268
269 /* Rx */
270 conn_param_rsp.reference_conn_event_count = conn_param_req.reference_conn_event_count;
271 lt_tx(LL_CONNECTION_PARAM_RSP, &conn, &conn_param_rsp);
272
273 /* Done */
274 event_done(&conn);
275
276 /* Release Tx */
277 ull_cp_release_tx(&conn, tx);
278
279 /* Prepare */
280 event_prepare(&conn);
281
282 /* Tx Queue should have one LL Control PDU */
283 conn_update_ind.instant = event_counter(&conn) + 6U;
284 lt_rx(LL_CONNECTION_UPDATE_IND, &conn, &tx, &conn_update_ind);
285 lt_rx_q_is_empty(&conn);
286
287 /* Done */
288 event_done(&conn);
289
290 /* Save Instant */
291 pdu = (struct pdu_data *)tx->pdu;
292 instant = sys_le16_to_cpu(pdu->llctrl.conn_update_ind.instant);
293
294 /* Release Tx */
295 ull_cp_release_tx(&conn, tx);
296
297 /* */
298 while (!is_instant_reached(&conn, instant)) {
299 /* Prepare */
300 event_prepare(&conn);
301
302 /* Tx Queue should NOT have a LL Control PDU */
303 lt_rx_q_is_empty(&conn);
304
305 /* Done */
306 event_done(&conn);
307
308 /* There should NOT be a host notification */
309 ut_rx_q_is_empty();
310 }
311
312 /* Prepare */
313 event_prepare(&conn);
314
315 /* Tx Queue should NOT have a LL Control PDU */
316 lt_rx_q_is_empty(&conn);
317
318 /* Done */
319 event_done(&conn);
320
321 /* There should be one host notification */
322 ut_rx_node(NODE_CONN_UPDATE, &ntf, &cu);
323 ut_rx_q_is_empty();
324
325 /* Release Ntf */
326 release_ntf(ntf);
327 zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(),
328 "Free CTX buffers %d", llcp_ctx_buffers_free());
329 }
330
331
332 /*
333 * Central-initiated Connection Parameters Request procedure.
334 * Central requests change in LE connection parameters, peripheral’s Host accepts.
335 * Parallel CPRs attemtped and rejected/cached
336 *
337 * +-----+ +-------+ +-----+
338 * | UT | | LL_C | | LT |
339 * +-----+ +-------+ +-----+
340 * | | |
341 * | LE Connection Update | |
342 * |-------------------------->| |
343 * | | LL_CONNECTION_PARAM_REQ |
344 * | |-------------------------->|
345 * | | |
346 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
347 * ~~~~~ parallel remote CPR is attempted and rejected ~~~~~~~
348 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
349 * | | |
350 * | | LL_CONNECTION_PARAM_RSP |
351 * | |<--------------------------|
352 * | | |
353 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
354 * ~~~~~ parallel remote CPR is attempted and rejected ~~~~~~~
355 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
356 * | | |
357 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
358 * ~~~~~ parallel local CPR is attempted and cached ~~~~~~~
359 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
360 * | | |
361 * | | LL_CONNECTION_UPDATE_IND |
362 * | |-------------------------->|
363 * | | |
364 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
365 * | | |
366 * | LE Connection Update | |
367 * | Complete | |
368 * |<--------------------------| |
369 * | | |
370 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
371 * ~~~~~~~~~ parallel local CPR is now started ~~~~~~~~~~~~
372 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
373 * | | |
374 */
ZTEST(central_loc,test_conn_update_central_loc_accept_reject_2nd_cpr)375 ZTEST(central_loc, test_conn_update_central_loc_accept_reject_2nd_cpr)
376 {
377 struct ll_conn conn_2nd;
378 struct ll_conn conn_3rd;
379 uint8_t err;
380 struct node_tx *tx;
381 struct node_rx_pdu *ntf;
382 struct pdu_data *pdu;
383 uint16_t instant;
384 struct pdu_data_llctrl_reject_ext_ind reject_ext_ind = {
385 .reject_opcode = PDU_DATA_LLCTRL_TYPE_CONN_PARAM_REQ,
386 .error_code = BT_HCI_ERR_UNSUPP_LL_PARAM_VAL
387 };
388 struct node_rx_pu cu = { .status = BT_HCI_ERR_SUCCESS };
389
390 /* Initialize extra connections */
391 test_setup_idx(&conn_2nd, 1);
392 test_setup_idx(&conn_3rd, 2);
393
394 /* Role */
395 test_set_role(&conn, BT_HCI_ROLE_CENTRAL);
396 /* Role */
397 test_set_role(&conn_2nd, BT_HCI_ROLE_PERIPHERAL);
398 /* Role */
399 test_set_role(&conn_3rd, BT_HCI_ROLE_PERIPHERAL);
400 /* Connect */
401 ull_cp_state_set(&conn, ULL_CP_CONNECTED);
402
403 /* Connect */
404 ull_cp_state_set(&conn_2nd, ULL_CP_CONNECTED);
405
406 /* Connect */
407 ull_cp_state_set(&conn_3rd, ULL_CP_CONNECTED);
408 /* Initiate a Connection Parameter Request Procedure */
409 err = ull_cp_conn_update(&conn, INTVL_MIN, INTVL_MAX, LATENCY, TIMEOUT, NULL);
410 zassert_equal(err, BT_HCI_ERR_SUCCESS);
411
412 /* Prepare */
413 event_prepare(&conn);
414
415 /* Tx Queue should have one LL Control PDU */
416 conn_param_req.reference_conn_event_count = event_counter(&conn);
417 lt_rx(LL_CONNECTION_PARAM_REQ, &conn, &tx, &conn_param_req);
418 lt_rx_q_is_empty(&conn);
419
420 /* Done */
421 event_done(&conn);
422
423 /* Release Tx */
424 ull_cp_release_tx(&conn, tx);
425
426 /* Now CPR is active on 'conn' so let 'conn_2nd' attempt to start a CPR */
427 /* Prepare */
428 event_prepare(&conn_2nd);
429
430 /* Tx Queue should NOT have a LL Control PDU */
431 lt_rx_q_is_empty(&conn_2nd);
432
433 /* Rx */
434 lt_tx(LL_CONNECTION_PARAM_REQ, &conn_2nd, &conn_param_req);
435
436 /* Done */
437 event_done(&conn_2nd);
438
439 /* Prepare */
440 event_prepare(&conn_2nd);
441
442 /* Tx Queue should have one LL Control PDU */
443 lt_rx(LL_REJECT_EXT_IND, &conn_2nd, &tx, &reject_ext_ind);
444 lt_rx_q_is_empty(&conn_2nd);
445
446 /* Done */
447 event_done(&conn_2nd);
448
449 /* Release Tx */
450 ull_cp_release_tx(&conn_2nd, tx);
451
452 /* Rx */
453 conn_param_rsp.reference_conn_event_count = conn_param_req.reference_conn_event_count;
454 lt_tx(LL_CONNECTION_PARAM_RSP, &conn, &conn_param_rsp);
455
456 /* Prepare */
457 event_prepare(&conn);
458
459 /* Tx Queue should NOT have a LL Control PDU */
460 lt_rx_q_is_empty(&conn);
461
462 /* Done */
463 event_done(&conn);
464
465 /* Now CPR is active on 'conn' so let 'conn_2nd' attempt to start a CPR again */
466 /* Prepare */
467 event_prepare(&conn_3rd);
468
469 /* Tx Queue should NOT have a LL Control PDU */
470 lt_rx_q_is_empty(&conn_3rd);
471
472 /* Rx */
473 lt_tx(LL_CONNECTION_PARAM_REQ, &conn_3rd, &conn_param_req);
474
475 /* Done */
476 event_done(&conn_3rd);
477
478 /* Prepare */
479 event_prepare(&conn_3rd);
480
481 /* Tx Queue should have one LL Control PDU */
482 lt_rx(LL_REJECT_EXT_IND, &conn_3rd, &tx, &reject_ext_ind);
483 lt_rx_q_is_empty(&conn_3rd);
484
485 /* Done */
486 event_done(&conn_3rd);
487
488 /* Release Tx */
489 ull_cp_release_tx(&conn_3rd, tx);
490
491 /* Initiate a parallel Connection Parameter Request Procedure */
492 err = ull_cp_conn_update(&conn_3rd, INTVL_MIN, INTVL_MAX, LATENCY, TIMEOUT, NULL);
493 zassert_equal(err, BT_HCI_ERR_SUCCESS);
494
495 /* Prepare */
496 event_prepare(&conn_3rd);
497
498 /* Tx Queue should have no LL Control PDU */
499 lt_rx_q_is_empty(&conn_3rd);
500
501 /* Done */
502 event_done(&conn_3rd);
503
504 /* Prepare */
505 event_prepare(&conn_3rd);
506
507 /* Tx Queue should have no LL Control PDU */
508 lt_rx_q_is_empty(&conn_3rd);
509
510 /* Done */
511 event_done(&conn_3rd);
512
513 /* Prepare */
514 event_prepare(&conn);
515
516 /* Tx Queue should have one LL Control PDU */
517 conn_update_ind.instant = event_counter(&conn) + 6U;
518 lt_rx(LL_CONNECTION_UPDATE_IND, &conn, &tx, &conn_update_ind);
519 lt_rx_q_is_empty(&conn);
520
521 /* Done */
522 event_done(&conn);
523
524 /* Save Instant */
525 pdu = (struct pdu_data *)tx->pdu;
526 instant = sys_le16_to_cpu(pdu->llctrl.conn_update_ind.instant);
527
528 /* Release Tx */
529 ull_cp_release_tx(&conn, tx);
530
531 /* */
532 while (!is_instant_reached(&conn, instant)) {
533 /* Prepare */
534 event_prepare(&conn);
535
536 /* Tx Queue should NOT have a LL Control PDU */
537 lt_rx_q_is_empty(&conn);
538
539 /* Done */
540 event_done(&conn);
541
542 /* There should NOT be a host notification */
543 ut_rx_q_is_empty();
544
545 /* Prepare on conn_3rd for parallel CPR */
546 event_prepare(&conn_3rd);
547
548 /* Tx Queue should have no LL Control PDU */
549 lt_rx_q_is_empty(&conn_3rd);
550
551 /* Done on conn_3rd for parallel CPR */
552 event_done(&conn_3rd);
553 }
554
555 /* Prepare */
556 event_prepare(&conn);
557
558 /* Tx Queue should NOT have a LL Control PDU */
559 lt_rx_q_is_empty(&conn);
560
561 /* Done */
562 event_done(&conn);
563
564 /* There should be one host notification */
565 ut_rx_node(NODE_CONN_UPDATE, &ntf, &cu);
566 ut_rx_q_is_empty();
567
568 /* Now the locally initiated CPR on conn_3rd should be allowed to run */
569 /* Prepare */
570 event_prepare(&conn_3rd);
571
572 /* Tx Queue should have one LL Control PDU, indicating parallel CPR is now active */
573 conn_param_req.reference_conn_event_count = event_counter(&conn_3rd);
574 lt_rx(LL_CONNECTION_PARAM_REQ, &conn_3rd, &tx, &conn_param_req);
575 lt_rx_q_is_empty(&conn_3rd);
576
577 /* Done */
578 event_done(&conn_3rd);
579
580 /* Release Tx */
581 ull_cp_release_tx(&conn_3rd, tx);
582
583 /* Release Ntf */
584 release_ntf(ntf);
585
586 /* One less CTXs as the conn_3rd CPR is still 'running' */
587 zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt()-1,
588 "Free CTX buffers %d", llcp_ctx_buffers_free());
589 }
590
591 /*
592 * Central-initiated Connection Parameters Request procedure.
593 * Central requests change in LE connection parameters, peripheral
594 * responds with invalid params
595 *
596 * +-----+ +-------+ +-----+
597 * | UT | | LL_C | | LT |
598 * +-----+ +-------+ +-----+
599 * | | |
600 * | LE Connection Update | |
601 * |-------------------------->| |
602 * | | LL_CONNECTION_PARAM_REQ |
603 * | |-------------------------->|
604 * | | |
605 * | | LL_CONNECTION_PARAM_RSP |
606 * | |<--------------------------|
607 * | | |
608 * | | LL_REJECT_EXT_IND |
609 * | |-------------------------->|
610 * | | |
611 * | | |
612 * | | |
613 */
ZTEST(central_loc,test_conn_update_central_loc_invalid_param_rsp)614 ZTEST(central_loc, test_conn_update_central_loc_invalid_param_rsp)
615 {
616 uint8_t err;
617 struct node_tx *tx;
618 struct pdu_data_llctrl_reject_ext_ind reject_ext_ind = {
619 .reject_opcode = PDU_DATA_LLCTRL_TYPE_CONN_PARAM_RSP,
620 .error_code = BT_HCI_ERR_INVALID_LL_PARAM
621 };
622
623 /* Role */
624 test_set_role(&conn, BT_HCI_ROLE_CENTRAL);
625
626 /* Connect */
627 ull_cp_state_set(&conn, ULL_CP_CONNECTED);
628
629 /* Initiate a Connection Parameter Request Procedure */
630 err = ull_cp_conn_update(&conn, INTVL_MIN, INTVL_MAX, LATENCY, TIMEOUT, NULL);
631 zassert_equal(err, BT_HCI_ERR_SUCCESS);
632
633 /* Prepare */
634 event_prepare(&conn);
635
636 /* Tx Queue should have one LL Control PDU */
637 conn_param_req.reference_conn_event_count = event_counter(&conn);
638 lt_rx(LL_CONNECTION_PARAM_REQ, &conn, &tx, &conn_param_req);
639 lt_rx_q_is_empty(&conn);
640
641 /* Rx */
642 lt_tx(LL_CONNECTION_PARAM_RSP, &conn, &conn_param_rsp_invalid);
643
644 /* Done */
645 event_done(&conn);
646
647 /* Release Tx */
648 ull_cp_release_tx(&conn, tx);
649
650 /* Prepare */
651 event_prepare(&conn);
652
653 /* Tx Queue should have one LL Control PDU */
654 lt_rx(LL_REJECT_EXT_IND, &conn, &tx, &reject_ext_ind);
655 lt_rx_q_is_empty(&conn);
656
657 /* Done */
658 event_done(&conn);
659
660 zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(),
661 "Free CTX buffers %d", llcp_ctx_buffers_free());
662 }
663
664 /*
665 * Central-initiated Connection Parameters Request procedure.
666 * Central requests change in LE connection parameters, peripheral’s Host accepts.
667 *
668 * +-----+ +-------+ +-----+
669 * | UT | | LL_C | | LT |
670 * +-----+ +-------+ +-----+
671 * | | |
672 * | LE Connection Update | |
673 * |-------------------------->| |
674 * | | LL_CONNECTION_PARAM_REQ |
675 * | |-------------------------->|
676 * | | |
677 * | | LL_REJECT_IND |
678 * | |<--------------------------|
679 * | | |
680 * ~~~~~~~~~~~~~~~~~~ TERMINATE CONNECTION ~~~~~~~~~~~~~~~~~
681 * | | |
682 * | | |
683 */
ZTEST(central_loc,test_conn_update_central_loc_invalid_rsp)684 ZTEST(central_loc, test_conn_update_central_loc_invalid_rsp)
685 {
686 uint8_t err;
687 struct node_tx *tx;
688 struct pdu_data_llctrl_reject_ind reject_ind = {
689 .error_code = BT_HCI_ERR_LL_PROC_COLLISION
690 };
691
692 /* Role */
693 test_set_role(&conn, BT_HCI_ROLE_CENTRAL);
694
695 /* Connect */
696 ull_cp_state_set(&conn, ULL_CP_CONNECTED);
697
698 /* Initiate a Connection Parameter Request Procedure */
699 err = ull_cp_conn_update(&conn, INTVL_MIN, INTVL_MAX, LATENCY, TIMEOUT, NULL);
700 zassert_equal(err, BT_HCI_ERR_SUCCESS);
701
702 /* Prepare */
703 event_prepare(&conn);
704
705 /* Tx Queue should have one LL Control PDU */
706 conn_param_req.reference_conn_event_count = event_counter(&conn);
707 lt_rx(LL_CONNECTION_PARAM_REQ, &conn, &tx, &conn_param_req);
708 lt_rx_q_is_empty(&conn);
709
710 /* Rx */
711 lt_tx(LL_REJECT_IND, &conn, &reject_ind);
712
713 /* Done */
714 event_done(&conn);
715
716 /* Release Tx */
717 ull_cp_release_tx(&conn, tx);
718
719 /* Termination 'triggered' */
720 zassert_equal(conn.llcp_terminate.reason_final, BT_HCI_ERR_LMP_PDU_NOT_ALLOWED,
721 "Terminate reason %d", conn.llcp_terminate.reason_final);
722
723 /* There should be no host notifications */
724 ut_rx_q_is_empty();
725
726 zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(),
727 "Free CTX buffers %d", llcp_ctx_buffers_free());
728
729 }
730
731 /*
732 * Central-initiated Connection Parameters Request procedure.
733 * Central requests change in LE connection parameters, peripheral’s Host rejects.
734 *
735 * +-----+ +-------+ +-----+
736 * | UT | | LL_C | | LT |
737 * +-----+ +-------+ +-----+
738 * | | |
739 * | LE Connection Update | |
740 * |-------------------------->| |
741 * | | LL_CONNECTION_PARAM_REQ |
742 * | |-------------------------->|
743 * | | |
744 * | | LL_REJECT_EXT_IND |
745 * | |<--------------------------|
746 * | | |
747 * | LE Connection Update | |
748 * | Complete | |
749 * |<--------------------------| |
750 * | | |
751 */
ZTEST(central_loc,test_conn_update_central_loc_reject)752 ZTEST(central_loc, test_conn_update_central_loc_reject)
753 {
754 uint8_t err;
755 struct node_tx *tx;
756 struct node_rx_pdu *ntf;
757
758 struct pdu_data_llctrl_reject_ext_ind reject_ext_ind = {
759 .reject_opcode = PDU_DATA_LLCTRL_TYPE_CONN_PARAM_REQ,
760 .error_code = BT_HCI_ERR_UNACCEPT_CONN_PARAM
761 };
762
763 struct node_rx_pu cu = { .status = BT_HCI_ERR_UNACCEPT_CONN_PARAM };
764
765 /* Role */
766 test_set_role(&conn, BT_HCI_ROLE_CENTRAL);
767
768 /* Connect */
769 ull_cp_state_set(&conn, ULL_CP_CONNECTED);
770
771 /* Initiate a Connection Parameter Request Procedure */
772 err = ull_cp_conn_update(&conn, INTVL_MIN, INTVL_MAX, LATENCY, TIMEOUT, NULL);
773 zassert_equal(err, BT_HCI_ERR_SUCCESS);
774
775 /* Prepare */
776 event_prepare(&conn);
777
778 /* Tx Queue should have one LL Control PDU */
779 conn_param_req.reference_conn_event_count = event_counter(&conn);
780 lt_rx(LL_CONNECTION_PARAM_REQ, &conn, &tx, &conn_param_req);
781 lt_rx_q_is_empty(&conn);
782
783 /* Rx */
784 lt_tx(LL_REJECT_EXT_IND, &conn, &reject_ext_ind);
785
786 /* Done */
787 event_done(&conn);
788
789 /* Release Tx */
790 ull_cp_release_tx(&conn, tx);
791
792 /* There should be one host notification */
793 ut_rx_node(NODE_CONN_UPDATE, &ntf, &cu);
794 ut_rx_q_is_empty();
795
796 /* Release Ntf */
797 release_ntf(ntf);
798 zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(),
799 "Free CTX buffers %d", llcp_ctx_buffers_free());
800 }
801
802 /*
803 * Central-initiated Connection Parameters Request procedure.
804 * Central requests change in LE connection parameters, peripheral’s Host is legacy.
805 *
806 * +-----+ +-------+ +-----+
807 * | UT | | LL_C | | LT |
808 * +-----+ +-------+ +-----+
809 * | | |
810 * | LE Connection Update | |
811 * |-------------------------->| |
812 * | | LL_CONNECTION_PARAM_REQ |
813 * | |-------------------------->|
814 * | | |
815 * | | LL_REJECT_EXT_IND |
816 * | |<--------------------------|
817 * | | |
818 * | | LL_CONNECTION_UPDATE_IND |
819 * | |-------------------------->|
820 * | | |
821 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
822 * | | |
823 * | LE Connection Update | |
824 * | Complete | |
825 * |<--------------------------| |
826 * | | |
827 */
ZTEST(central_loc,test_conn_update_central_loc_remote_legacy)828 ZTEST(central_loc, test_conn_update_central_loc_remote_legacy)
829 {
830 bool feature_bit_param_req;
831 uint8_t err;
832 struct node_tx *tx;
833 struct node_rx_pdu *ntf;
834 struct pdu_data *pdu;
835 uint16_t instant;
836
837 struct pdu_data_llctrl_reject_ext_ind reject_ext_ind = {
838 .reject_opcode = PDU_DATA_LLCTRL_TYPE_CONN_PARAM_REQ,
839 .error_code = BT_HCI_ERR_UNSUPP_REMOTE_FEATURE
840 };
841
842 struct node_rx_pu cu = { .status = BT_HCI_ERR_SUCCESS };
843
844 /* Role */
845 test_set_role(&conn, BT_HCI_ROLE_CENTRAL);
846
847 /* Connect */
848 ull_cp_state_set(&conn, ULL_CP_CONNECTED);
849
850 /* Initiate a Connection Parameter Request Procedure */
851 err = ull_cp_conn_update(&conn, INTVL_MIN, INTVL_MAX, LATENCY, TIMEOUT, NULL);
852 zassert_equal(err, BT_HCI_ERR_SUCCESS);
853
854 /* Prepare */
855 event_prepare(&conn);
856
857 /* Tx Queue should have one LL Control PDU */
858 conn_param_req.reference_conn_event_count = event_counter(&conn);
859 lt_rx(LL_CONNECTION_PARAM_REQ, &conn, &tx, &conn_param_req);
860 lt_rx_q_is_empty(&conn);
861
862 /* Rx */
863 lt_tx(LL_REJECT_EXT_IND, &conn, &reject_ext_ind);
864
865 /* Done */
866 event_done(&conn);
867
868 /* Release Tx */
869 ull_cp_release_tx(&conn, tx);
870
871 /* Prepare */
872 event_prepare(&conn);
873
874 /* Check that feature Param Reg. is unmasked */
875 feature_bit_param_req = test_get_feature_conn_param_req(&conn);
876 zassert_equal(feature_bit_param_req, false, "Feature bit not unmasked");
877
878 /* Tx Queue should have one LL Control PDU */
879 conn_update_ind.instant = event_counter(&conn) + 6U;
880 lt_rx(LL_CONNECTION_UPDATE_IND, &conn, &tx, &conn_update_ind);
881 lt_rx_q_is_empty(&conn);
882
883 /* Done */
884 event_done(&conn);
885
886 /* Save Instant */
887 pdu = (struct pdu_data *)tx->pdu;
888 instant = sys_le16_to_cpu(pdu->llctrl.conn_update_ind.instant);
889
890 /* Release Tx */
891 ull_cp_release_tx(&conn, tx);
892
893 /* */
894 while (!is_instant_reached(&conn, instant)) {
895 /* Prepare */
896 event_prepare(&conn);
897
898 /* Tx Queue should NOT have a LL Control PDU */
899 lt_rx_q_is_empty(&conn);
900
901 /* Done */
902 event_done(&conn);
903
904 /* There should NOT be a host notification */
905 ut_rx_q_is_empty();
906 }
907
908 /* Prepare */
909 event_prepare(&conn);
910
911 /* Tx Queue should NOT have a LL Control PDU */
912 lt_rx_q_is_empty(&conn);
913
914 /* Done */
915 event_done(&conn);
916
917 /* There should be one host notification */
918 ut_rx_node(NODE_CONN_UPDATE, &ntf, &cu);
919 ut_rx_q_is_empty();
920
921 /* Release Ntf */
922 release_ntf(ntf);
923 zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(),
924 "Free CTX buffers %d", llcp_ctx_buffers_free());
925 }
926
927 /*
928 * Central-initiated Connection Parameters Request procedure.
929 * Central requests change in LE connection parameters, peripheral’s Controller do not
930 * support Connection Parameters Request procedure, features not exchanged.
931 *
932 * +-----+ +-------+ +-----+
933 * | UT | | LL_C | | LT |
934 * +-----+ +-------+ +-----+
935 * | | |
936 * | LE Connection Update | |
937 * |-------------------------->| |
938 * | | LL_CONNECTION_PARAM_REQ |
939 * | |-------------------------->|
940 * | | |
941 * | | LL_UNKNOWN_RSP |
942 * | |<--------------------------|
943 * | | |
944 * | | LL_CONNECTION_UPDATE_IND |
945 * | |-------------------------->|
946 * | | |
947 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
948 * | | |
949 * | LE Connection Update | |
950 * | Complete | |
951 * |<--------------------------| |
952 * | | |
953 */
ZTEST(central_loc,test_conn_update_central_loc_unsupp_wo_feat_exch)954 ZTEST(central_loc, test_conn_update_central_loc_unsupp_wo_feat_exch)
955 {
956 bool feature_bit_param_req;
957 uint8_t err;
958 struct node_tx *tx;
959 struct node_rx_pdu *ntf;
960 struct pdu_data *pdu;
961 uint16_t instant;
962
963 struct pdu_data_llctrl_unknown_rsp unknown_rsp = {
964 .type = PDU_DATA_LLCTRL_TYPE_CONN_PARAM_REQ
965 };
966
967 struct node_rx_pu cu = { .status = BT_HCI_ERR_SUCCESS };
968
969 /* Role */
970 test_set_role(&conn, BT_HCI_ROLE_CENTRAL);
971
972 /* Connect */
973 ull_cp_state_set(&conn, ULL_CP_CONNECTED);
974
975 /* Initiate a Connection Parameter Request Procedure */
976 err = ull_cp_conn_update(&conn, INTVL_MIN, INTVL_MAX, LATENCY, TIMEOUT, NULL);
977 zassert_equal(err, BT_HCI_ERR_SUCCESS);
978
979 /* Prepare */
980 event_prepare(&conn);
981
982 /* Tx Queue should have one LL Control PDU */
983 conn_param_req.reference_conn_event_count = event_counter(&conn);
984 lt_rx(LL_CONNECTION_PARAM_REQ, &conn, &tx, &conn_param_req);
985 lt_rx_q_is_empty(&conn);
986
987 /* Rx */
988 lt_tx(LL_UNKNOWN_RSP, &conn, &unknown_rsp);
989
990 /* Done */
991 event_done(&conn);
992
993 /* Release Tx */
994 ull_cp_release_tx(&conn, tx);
995
996 /* Prepare */
997 event_prepare(&conn);
998
999 /* Check that feature Param Reg. is unmasked */
1000 feature_bit_param_req = test_get_feature_conn_param_req(&conn);
1001 zassert_equal(feature_bit_param_req, false, "Feature bit not unmasked");
1002
1003 /* Tx Queue should have one LL Control PDU */
1004 conn_update_ind.instant = event_counter(&conn) + 6U;
1005 lt_rx(LL_CONNECTION_UPDATE_IND, &conn, &tx, &conn_update_ind);
1006 lt_rx_q_is_empty(&conn);
1007
1008 /* Done */
1009 event_done(&conn);
1010
1011 /* Save Instant */
1012 pdu = (struct pdu_data *)tx->pdu;
1013 instant = sys_le16_to_cpu(pdu->llctrl.conn_update_ind.instant);
1014
1015 /* Release Tx */
1016 ull_cp_release_tx(&conn, tx);
1017
1018 /* */
1019 while (!is_instant_reached(&conn, instant)) {
1020 /* Prepare */
1021 event_prepare(&conn);
1022
1023 /* Tx Queue should NOT have a LL Control PDU */
1024 lt_rx_q_is_empty(&conn);
1025
1026 /* Done */
1027 event_done(&conn);
1028
1029 /* There should NOT be a host notification */
1030 ut_rx_q_is_empty();
1031 }
1032
1033 /* Prepare */
1034 event_prepare(&conn);
1035
1036 /* Tx Queue should NOT have a LL Control PDU */
1037 lt_rx_q_is_empty(&conn);
1038
1039 /* Done */
1040 event_done(&conn);
1041
1042 /* There should be one host notification */
1043 ut_rx_node(NODE_CONN_UPDATE, &ntf, &cu);
1044 ut_rx_q_is_empty();
1045
1046 /* Release Ntf */
1047 release_ntf(ntf);
1048 zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(),
1049 "Free CTX buffers %d", llcp_ctx_buffers_free());
1050 }
1051
1052 /*
1053 * Central-initiated Connection Parameters Request procedure.
1054 * Central requests change in LE connection parameters, peripheral’s Controller do not
1055 * support Connection Parameters Request procedure, features exchanged.
1056 *
1057 * +-----+ +-------+ +-----+
1058 * | UT | | LL_C | | LT |
1059 * +-----+ +-------+ +-----+
1060 * | | |
1061 * | LE Connection Update | |
1062 * |-------------------------->| |
1063 * | | LL_CONNECTION_UPDATE_IND |
1064 * | |-------------------------->|
1065 * | | |
1066 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1067 * | | |
1068 * | LE Connection Update | |
1069 * | Complete | |
1070 * |<--------------------------| |
1071 * | | |
1072 */
ZTEST(central_loc,test_conn_update_central_loc_unsupp_w_feat_exch)1073 ZTEST(central_loc, test_conn_update_central_loc_unsupp_w_feat_exch)
1074 {
1075 uint8_t err;
1076 struct node_tx *tx;
1077 struct node_rx_pdu *ntf;
1078 struct pdu_data *pdu;
1079 uint16_t instant;
1080
1081 struct node_rx_pu cu = { .status = BT_HCI_ERR_SUCCESS };
1082
1083 /* Disable feature */
1084 test_unmask_feature_conn_param_req(&conn);
1085
1086 /* Role */
1087 test_set_role(&conn, BT_HCI_ROLE_CENTRAL);
1088
1089 /* Connect */
1090 ull_cp_state_set(&conn, ULL_CP_CONNECTED);
1091
1092 /* Initiate a Connection Parameter Request Procedure */
1093 err = ull_cp_conn_update(&conn, INTVL_MIN, INTVL_MAX, LATENCY, TIMEOUT, NULL);
1094 zassert_equal(err, BT_HCI_ERR_SUCCESS);
1095
1096 /* Prepare */
1097 event_prepare(&conn);
1098
1099 /* Tx Queue should have one LL Control PDU */
1100 conn_update_ind.instant = event_counter(&conn) + 6U;
1101 lt_rx(LL_CONNECTION_UPDATE_IND, &conn, &tx, &conn_update_ind);
1102 lt_rx_q_is_empty(&conn);
1103
1104 /* Done */
1105 event_done(&conn);
1106
1107 /* Release Tx */
1108 ull_cp_release_tx(&conn, tx);
1109
1110 /* Save Instant */
1111 pdu = (struct pdu_data *)tx->pdu;
1112 instant = sys_le16_to_cpu(pdu->llctrl.conn_update_ind.instant);
1113
1114 /* */
1115 while (!is_instant_reached(&conn, instant)) {
1116 /* Prepare */
1117 event_prepare(&conn);
1118
1119 /* Tx Queue should NOT have a LL Control PDU */
1120 lt_rx_q_is_empty(&conn);
1121
1122 /* Done */
1123 event_done(&conn);
1124
1125 /* There should NOT be a host notification */
1126 ut_rx_q_is_empty();
1127 }
1128
1129 /* Prepare */
1130 event_prepare(&conn);
1131
1132 /* Tx Queue should NOT have a LL Control PDU */
1133 lt_rx_q_is_empty(&conn);
1134
1135 /* Done */
1136 event_done(&conn);
1137
1138 /* There should be one host notification */
1139 ut_rx_node(NODE_CONN_UPDATE, &ntf, &cu);
1140 ut_rx_q_is_empty();
1141
1142 /* Release Ntf */
1143 release_ntf(ntf);
1144 zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(),
1145 "Free CTX buffers %d", llcp_ctx_buffers_free());
1146 }
1147
1148 /*
1149 * (A)
1150 * Central-initiated Connection Parameters Request procedure.
1151 * Central requests change in LE connection parameters, peripheral’s Host accepts.
1152 *
1153 * and
1154 *
1155 * (B)
1156 * Peripheral-initiated Connection Parameters Request procedure.
1157 * Procedure collides and is rejected.
1158 *
1159 * +-----+ +-------+ +-----+
1160 * | UT | | LL_C | | LT |
1161 * +-----+ +-------+ +-----+
1162 * | | |
1163 * | LE Connection Update | |
1164 * |-------------------------->| |
1165 * | | LL_CONNECTION_PARAM_REQ | (A)
1166 * | |-------------------------->|
1167 * | | |
1168 * | | LL_CONNECTION_PARAM_REQ | (B)
1169 * | |<--------------------------|
1170 * | | |
1171 * | <---------------------> |
1172 * | < PROCEDURE COLLISION > |
1173 * | <---------------------> |
1174 * | | |
1175 * | | LL_REJECT_EXT_IND | (B)
1176 * | |-------------------------->|
1177 * | | |
1178 * | | LL_CONNECTION_PARAM_RSP | (A)
1179 * | |<--------------------------|
1180 * | | |
1181 * | | LL_CONNECTION_UPDATE_IND | (A)
1182 * | |-------------------------->|
1183 * | | |
1184 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1185 * | | |
1186 * | LE Connection Update | |
1187 * | Complete | |
1188 * |<--------------------------| |
1189 * | | |
1190 */
ZTEST(central_loc,test_conn_update_central_loc_collision)1191 ZTEST(central_loc, test_conn_update_central_loc_collision)
1192 {
1193 uint8_t err;
1194 struct node_tx *tx;
1195 struct node_rx_pdu *ntf;
1196 struct pdu_data *pdu;
1197 uint16_t instant;
1198
1199 struct node_rx_pu cu = { .status = BT_HCI_ERR_SUCCESS };
1200
1201 struct pdu_data_llctrl_reject_ext_ind reject_ext_ind = {
1202 .reject_opcode = PDU_DATA_LLCTRL_TYPE_CONN_PARAM_REQ,
1203 .error_code = BT_HCI_ERR_LL_PROC_COLLISION
1204 };
1205
1206 /* Role */
1207 test_set_role(&conn, BT_HCI_ROLE_CENTRAL);
1208
1209 /* Emulate valid feature exchange */
1210 conn.llcp.fex.valid = 1;
1211
1212 /* Connect */
1213 ull_cp_state_set(&conn, ULL_CP_CONNECTED);
1214
1215 /* (A) Initiate a Connection Parameter Request Procedure */
1216 err = ull_cp_conn_update(&conn, INTVL_MIN, INTVL_MAX, LATENCY, TIMEOUT, NULL);
1217 zassert_equal(err, BT_HCI_ERR_SUCCESS);
1218
1219 /* Prepare */
1220 event_prepare(&conn);
1221
1222 /* (A) Tx Queue should have one LL Control PDU */
1223 conn_param_req.reference_conn_event_count = event_counter(&conn);
1224 lt_rx(LL_CONNECTION_PARAM_REQ, &conn, &tx, &conn_param_req);
1225 lt_rx_q_is_empty(&conn);
1226
1227 /* (B) Rx */
1228 lt_tx(LL_CONNECTION_PARAM_REQ, &conn, req_B);
1229
1230 /* Done */
1231 event_done(&conn);
1232
1233 /* Release Tx */
1234 ull_cp_release_tx(&conn, tx);
1235
1236 /* Prepare */
1237 event_prepare(&conn);
1238
1239 /* (B) Tx Queue should have one LL Control PDU */
1240 lt_rx(LL_REJECT_EXT_IND, &conn, &tx, &reject_ext_ind);
1241 lt_rx_q_is_empty(&conn);
1242
1243 /* Done */
1244 event_done(&conn);
1245
1246 /* Release Tx */
1247 ull_cp_release_tx(&conn, tx);
1248
1249 /**/
1250
1251 /* Prepare */
1252 event_prepare(&conn);
1253
1254 /* (B) Tx Queue should NOT have a LL Control PDU */
1255 lt_rx_q_is_empty(&conn);
1256
1257 /* (A) Rx */
1258 lt_tx(LL_CONNECTION_PARAM_RSP, &conn, &conn_param_rsp);
1259
1260 /* Done */
1261 event_done(&conn);
1262
1263 /* Prepare */
1264 event_prepare(&conn);
1265
1266 /* (A) Tx Queue should have one LL Control PDU */
1267 conn_update_ind.instant = event_counter(&conn) + 6U;
1268 lt_rx(LL_CONNECTION_UPDATE_IND, &conn, &tx, &conn_update_ind);
1269 lt_rx_q_is_empty(&conn);
1270
1271 /* Done */
1272 event_done(&conn);
1273
1274 /* Save Instant */
1275 pdu = (struct pdu_data *)tx->pdu;
1276 instant = sys_le16_to_cpu(pdu->llctrl.conn_update_ind.instant);
1277
1278 /* Release Tx */
1279 ull_cp_release_tx(&conn, tx);
1280
1281 /* */
1282 while (!is_instant_reached(&conn, instant)) {
1283 /* Prepare */
1284 event_prepare(&conn);
1285
1286 /* (A) Tx Queue should NOT have a LL Control PDU */
1287 lt_rx_q_is_empty(&conn);
1288
1289 /* Done */
1290 event_done(&conn);
1291
1292 /* (A) There should NOT be a host notification */
1293 ut_rx_q_is_empty();
1294 }
1295
1296 /* Prepare */
1297 event_prepare(&conn);
1298
1299 /* (A) Tx Queue should NOT have a LL Control PDU */
1300 lt_rx_q_is_empty(&conn);
1301
1302 /* Done */
1303 event_done(&conn);
1304
1305 /* (A) There should be one host notification */
1306 ut_rx_node(NODE_CONN_UPDATE, &ntf, &cu);
1307 ut_rx_q_is_empty();
1308
1309 /* Release Ntf */
1310 release_ntf(ntf);
1311 zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(),
1312 "Free CTX buffers %d", llcp_ctx_buffers_free());
1313 }
1314
1315 /*
1316 * Peripheral-initiated Connection Parameters Request procedure.
1317 * Peripheral requests change in LE connection parameters, central’s Host accepts.
1318 *
1319 * +-----+ +-------+ +-----+
1320 * | UT | | LL_C | | LT |
1321 * +-----+ +-------+ +-----+
1322 * | | |
1323 * | | LL_CONNECTION_PARAM_REQ |
1324 * | |<--------------------------|
1325 * | | |
1326 * | LE Remote Connection | |
1327 * | Parameter Request | |
1328 * |<--------------------------| |
1329 * | LE Remote Connection | |
1330 * | Parameter Request | |
1331 * | Reply | |
1332 * |-------------------------->| |
1333 * | | |
1334 * | | LL_CONNECTION_UPDATE_IND |
1335 * | |-------------------------->|
1336 * | | |
1337 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1338 * | | |
1339 * | LE Connection Update | |
1340 * | Complete | |
1341 * |<--------------------------| |
1342 * | | |
1343 */
ZTEST(central_rem,test_conn_update_central_rem_accept)1344 ZTEST(central_rem, test_conn_update_central_rem_accept)
1345 {
1346 struct node_tx *tx;
1347 struct node_rx_pdu *ntf;
1348 struct pdu_data *pdu;
1349 uint16_t instant;
1350
1351 struct node_rx_pu cu = { .status = BT_HCI_ERR_SUCCESS };
1352
1353 /* Role */
1354 test_set_role(&conn, BT_HCI_ROLE_CENTRAL);
1355
1356 /* Connect */
1357 ull_cp_state_set(&conn, ULL_CP_CONNECTED);
1358
1359 /* Prepare */
1360 event_prepare(&conn);
1361
1362 /* Rx */
1363 lt_tx(LL_CONNECTION_PARAM_REQ, &conn, &conn_param_req);
1364
1365 /* Done */
1366 event_done(&conn);
1367
1368 /*******************/
1369
1370 /* There should be one host notification */
1371 ut_rx_pdu(LL_CONNECTION_PARAM_REQ, &ntf, &conn_param_req);
1372 ut_rx_q_is_empty();
1373
1374 /* Release Ntf */
1375 release_ntf(ntf);
1376
1377 /*******************/
1378
1379 ull_cp_conn_param_req_reply(&conn);
1380
1381 /*******************/
1382
1383 /* Prepare */
1384 event_prepare(&conn);
1385
1386 /* Tx Queue should have one LL Control PDU */
1387 conn_update_ind.instant = event_counter(&conn) + 6U;
1388 lt_rx(LL_CONNECTION_UPDATE_IND, &conn, &tx, &conn_update_ind);
1389 lt_rx_q_is_empty(&conn);
1390
1391 /* Done */
1392 event_done(&conn);
1393
1394 /* Save Instant */
1395 pdu = (struct pdu_data *)tx->pdu;
1396 instant = sys_le16_to_cpu(pdu->llctrl.conn_update_ind.instant);
1397
1398 /* Release Tx */
1399 ull_cp_release_tx(&conn, tx);
1400
1401 /* */
1402 while (!is_instant_reached(&conn, instant)) {
1403 /* Prepare */
1404 event_prepare(&conn);
1405
1406 /* Tx Queue should NOT have a LL Control PDU */
1407 lt_rx_q_is_empty(&conn);
1408
1409 /* Done */
1410 event_done(&conn);
1411
1412 /* There should NOT be a host notification */
1413 ut_rx_q_is_empty();
1414 }
1415
1416 /* Prepare */
1417 event_prepare(&conn);
1418
1419 /* Tx Queue should NOT have a LL Control PDU */
1420 lt_rx_q_is_empty(&conn);
1421
1422 /* Done */
1423 event_done(&conn);
1424
1425 /* There should be one host notification */
1426 ut_rx_node(NODE_CONN_UPDATE, &ntf, &cu);
1427 ut_rx_q_is_empty();
1428
1429 /* Release Ntf */
1430 release_ntf(ntf);
1431 zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(),
1432 "Free CTX buffers %d", llcp_ctx_buffers_free());
1433 }
1434
1435 /*
1436 * Peripheral-initiated Connection Parameters Request procedure.
1437 * Peripheral requests change in LE connection with invalid parameters,
1438 *
1439 * +-----+ +-------+ +-----+
1440 * | UT | | LL_C | | LT |
1441 * +-----+ +-------+ +-----+
1442 * | | |
1443 * | | LL_CONNECTION_PARAM_REQ |
1444 * | |<--------------------------|
1445 * | | |
1446 * | | |
1447 * | | LL_REJECT_EXT_IND |
1448 * | |-------------------------->|
1449 * | | |
1450 * | | |
1451 */
ZTEST(central_rem,test_conn_update_central_rem_invalid_req)1452 ZTEST(central_rem, test_conn_update_central_rem_invalid_req)
1453 {
1454 struct node_tx *tx;
1455 struct pdu_data_llctrl_reject_ext_ind reject_ext_ind = {
1456 .reject_opcode = PDU_DATA_LLCTRL_TYPE_CONN_PARAM_REQ,
1457 .error_code = BT_HCI_ERR_INVALID_LL_PARAM
1458 };
1459
1460 /* Role */
1461 test_set_role(&conn, BT_HCI_ROLE_CENTRAL);
1462
1463 /* Connect */
1464 ull_cp_state_set(&conn, ULL_CP_CONNECTED);
1465
1466 /* Prepare */
1467 event_prepare(&conn);
1468
1469 /* Rx */
1470 lt_tx(LL_CONNECTION_PARAM_REQ, &conn, &conn_param_req_invalid);
1471
1472 /* Done */
1473 event_done(&conn);
1474
1475 /* Prepare */
1476 event_prepare(&conn);
1477
1478 /* Tx Queue should have one LL Control PDU */
1479 lt_rx(LL_REJECT_EXT_IND, &conn, &tx, &reject_ext_ind);
1480 lt_rx_q_is_empty(&conn);
1481
1482 /* Done */
1483 event_done(&conn);
1484
1485 /* Release Tx */
1486 ull_cp_release_tx(&conn, tx);
1487 zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(),
1488 "Free CTX buffers %d", llcp_ctx_buffers_free());
1489
1490 }
1491
1492 /*
1493 * Peripheral-initiated Connection Parameters Request procedure.
1494 * Peripheral requests change in LE connection parameters, central’s Host rejects.
1495 *
1496 * +-----+ +-------+ +-----+
1497 * | UT | | LL_C | | LT |
1498 * +-----+ +-------+ +-----+
1499 * | | |
1500 * | | LL_CONNECTION_PARAM_REQ |
1501 * | |<--------------------------|
1502 * | | |
1503 * | LE Remote Connection | |
1504 * | Parameter Request | |
1505 * |<--------------------------| |
1506 * | LE Remote Connection | |
1507 * | Parameter Request | |
1508 * | Negative Reply | |
1509 * |-------------------------->| |
1510 * | | |
1511 * | | LL_REJECT_EXT_IND |
1512 * | |-------------------------->|
1513 * | | |
1514 */
ZTEST(central_rem,test_conn_update_central_rem_reject)1515 ZTEST(central_rem, test_conn_update_central_rem_reject)
1516 {
1517 struct node_tx *tx;
1518 struct node_rx_pdu *ntf;
1519
1520 struct pdu_data_llctrl_reject_ext_ind reject_ext_ind = {
1521 .reject_opcode = PDU_DATA_LLCTRL_TYPE_CONN_PARAM_REQ,
1522 .error_code = BT_HCI_ERR_UNACCEPT_CONN_PARAM
1523 };
1524
1525 /* Role */
1526 test_set_role(&conn, BT_HCI_ROLE_CENTRAL);
1527
1528 /* Connect */
1529 ull_cp_state_set(&conn, ULL_CP_CONNECTED);
1530
1531 /* Prepare */
1532 event_prepare(&conn);
1533
1534 /* Rx */
1535 lt_tx(LL_CONNECTION_PARAM_REQ, &conn, &conn_param_req);
1536
1537 /* Done */
1538 event_done(&conn);
1539
1540 /*******************/
1541
1542 /* There should be one host notification */
1543 ut_rx_pdu(LL_CONNECTION_PARAM_REQ, &ntf, &conn_param_req);
1544 ut_rx_q_is_empty();
1545
1546 /* Release Ntf */
1547 release_ntf(ntf);
1548
1549 /*******************/
1550
1551 ull_cp_conn_param_req_neg_reply(&conn, BT_HCI_ERR_UNACCEPT_CONN_PARAM);
1552
1553 /*******************/
1554
1555 /* Prepare */
1556 event_prepare(&conn);
1557
1558 /* Tx Queue should have one LL Control PDU */
1559 lt_rx(LL_REJECT_EXT_IND, &conn, &tx, &reject_ext_ind);
1560 lt_rx_q_is_empty(&conn);
1561
1562 /* Done */
1563 event_done(&conn);
1564
1565 zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(),
1566 "Free CTX buffers %d", llcp_ctx_buffers_free());
1567 }
1568
1569 /*
1570 * (A)
1571 * Peripheral-initiated Connection Parameters Request procedure.
1572 * Peripheral requests change in LE connection parameters, central’s Host accepts.
1573 *
1574 * and
1575 *
1576 * (B)
1577 * Central-initiated Connection Parameters Request procedure.
1578 * Central requests change in LE connection parameters, peripheral’s Host accepts.
1579 *
1580 * NOTE:
1581 * Central-initiated Connection Parameters Request procedure is paused.
1582 * Peripheral-initiated Connection Parameters Request procedure is finished.
1583 * Central-initiated Connection Parameters Request procedure is resumed.
1584 *
1585 * +-----+ +-------+ +-----+
1586 * | UT | | LL_C | | LT |
1587 * +-----+ +-------+ +-----+
1588 * | | |
1589 * | | LL_CONNECTION_PARAM_REQ |
1590 * | |<--------------------------| (A)
1591 * | | |
1592 * | LE Connection Update | |
1593 * |-------------------------->| | (B)
1594 * | | |
1595 * | <------------------------> |
1596 * | < LOCAL PROCEDURE PAUSED > |
1597 * | <------------------------> |
1598 * | | |
1599 * | LE Remote Connection | |
1600 * | Parameter Request | |
1601 * |<--------------------------| | (A)
1602 * | LE Remote Connection | |
1603 * | Parameter Request | |
1604 * | Reply | |
1605 * |-------------------------->| | (A)
1606 * | | |
1607 * | | LL_CONNECTION_UPDATE_IND |
1608 * | |-------------------------->| (A)
1609 * | | |
1610 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1611 * | | |
1612 * | LE Connection Update | |
1613 * | Complete | |
1614 * |<--------------------------| | (A)
1615 * | | |
1616 * | <-------------------------> |
1617 * | < LOCAL PROCEDURE RESUMED > |
1618 * | <-------------------------> |
1619 * | | |
1620 * | | LL_CONNECTION_PARAM_REQ |
1621 * | |-------------------------->| (B)
1622 * | | |
1623 * | | LL_CONNECTION_PARAM_RSP |
1624 * | |<--------------------------| (B)
1625 * | | |
1626 * | | LL_CONNECTION_UPDATE_IND |
1627 * | |-------------------------->| (B)
1628 * | | |
1629 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1630 * | | |
1631 * | LE Connection Update | |
1632 * | Complete | |
1633 * |<--------------------------| | (B)
1634 * | | |
1635 */
ZTEST(central_rem,test_conn_update_central_rem_collision)1636 ZTEST(central_rem, test_conn_update_central_rem_collision)
1637 {
1638 uint8_t err;
1639 struct node_tx *tx;
1640 struct node_rx_pdu *ntf;
1641 struct pdu_data *pdu;
1642 uint16_t instant;
1643
1644 struct node_rx_pu cu = { .status = BT_HCI_ERR_SUCCESS };
1645
1646 /* Role */
1647 test_set_role(&conn, BT_HCI_ROLE_CENTRAL);
1648
1649 /* Connect */
1650 ull_cp_state_set(&conn, ULL_CP_CONNECTED);
1651
1652 /*******************/
1653
1654 /* Prepare */
1655 event_prepare(&conn);
1656
1657 /* (A) Rx */
1658 lt_tx(LL_CONNECTION_PARAM_REQ, &conn, &conn_param_req);
1659
1660 /* Done */
1661 event_done(&conn);
1662
1663 /*******************/
1664
1665 /* (B) Initiate a Connection Parameter Request Procedure */
1666 err = ull_cp_conn_update(&conn, req_B->interval_min, req_B->interval_max, req_B->latency,
1667 req_B->timeout, NULL);
1668 zassert_equal(err, BT_HCI_ERR_SUCCESS);
1669
1670 /* Prepare */
1671 event_prepare(&conn);
1672
1673 /* (B) Tx Queue should NOT have a LL Control PDU */
1674 lt_rx_q_is_empty(&conn);
1675
1676 /* Done */
1677 event_done(&conn);
1678
1679 /*******************/
1680
1681 /* (A) There should be one host notification */
1682 ut_rx_pdu(LL_CONNECTION_PARAM_REQ, &ntf, &conn_param_req);
1683 ut_rx_q_is_empty();
1684
1685 /* Release Ntf */
1686 release_ntf(ntf);
1687
1688 /*******************/
1689
1690 /* (A) */
1691 ull_cp_conn_param_req_reply(&conn);
1692
1693 /*******************/
1694
1695 /* Prepare */
1696 event_prepare(&conn);
1697
1698 /* (A) Tx Queue should have one LL Control PDU */
1699 conn_update_ind.instant = event_counter(&conn) + 6U;
1700 lt_rx(LL_CONNECTION_UPDATE_IND, &conn, &tx, &conn_update_ind);
1701 lt_rx_q_is_empty(&conn);
1702
1703 /* Done */
1704 event_done(&conn);
1705
1706 /* Save Instant */
1707 pdu = (struct pdu_data *)tx->pdu;
1708 instant = sys_le16_to_cpu(pdu->llctrl.conn_update_ind.instant);
1709
1710 /* Release Tx */
1711 ull_cp_release_tx(&conn, tx);
1712
1713 /* */
1714 while (!is_instant_reached(&conn, instant)) {
1715 /* Prepare */
1716 event_prepare(&conn);
1717
1718 /* (A) Tx Queue should NOT have a LL Control PDU */
1719 lt_rx_q_is_empty(&conn);
1720
1721 /* Done */
1722 event_done(&conn);
1723
1724 /* (A) There should NOT be a host notification */
1725 ut_rx_q_is_empty();
1726 }
1727
1728 /* Prepare */
1729 event_prepare(&conn);
1730
1731 /* (B) Tx Queue should have one LL Control PDU */
1732 req_B->reference_conn_event_count = event_counter(&conn) - 1;
1733 lt_rx(LL_CONNECTION_PARAM_REQ, &conn, &tx, req_B);
1734 lt_rx_q_is_empty(&conn);
1735
1736 /* Done */
1737 event_done(&conn);
1738
1739 /* Release Tx */
1740 ull_cp_release_tx(&conn, tx);
1741
1742 /* (A) There should be one host notification */
1743 ut_rx_node(NODE_CONN_UPDATE, &ntf, &cu);
1744 ut_rx_q_is_empty();
1745
1746 /* Release Ntf */
1747 release_ntf(ntf);
1748
1749 /* Prepare */
1750 event_prepare(&conn);
1751
1752 /* (B) Rx */
1753 lt_tx(LL_CONNECTION_PARAM_RSP, &conn, rsp_B);
1754
1755 /* Done */
1756 event_done(&conn);
1757
1758 /* Prepare */
1759 event_prepare(&conn);
1760
1761 /* (B) Tx Queue should have one LL Control PDU */
1762 conn_update_ind_B.instant = event_counter(&conn) + 6U;
1763 lt_rx(LL_CONNECTION_UPDATE_IND, &conn, &tx, &conn_update_ind_B);
1764 lt_rx_q_is_empty(&conn);
1765
1766 /* Done */
1767 event_done(&conn);
1768
1769 /* Save Instant */
1770 pdu = (struct pdu_data *)tx->pdu;
1771 instant = sys_le16_to_cpu(pdu->llctrl.conn_update_ind.instant);
1772
1773 /* Release Tx */
1774 ull_cp_release_tx(&conn, tx);
1775
1776 /* */
1777 while (!is_instant_reached(&conn, instant)) {
1778 /* Prepare */
1779 event_prepare(&conn);
1780
1781 /* (B) Tx Queue should NOT have a LL Control PDU */
1782 lt_rx_q_is_empty(&conn);
1783
1784 /* Done */
1785 event_done(&conn);
1786
1787 /* (B) There should NOT be a host notification */
1788 ut_rx_q_is_empty();
1789 }
1790
1791 /* Prepare */
1792 event_prepare(&conn);
1793
1794 /* (B) Tx Queue should NOT have a LL Control PDU */
1795 lt_rx_q_is_empty(&conn);
1796
1797 /* Done */
1798 event_done(&conn);
1799
1800 /* (B) There should be one host notification */
1801 ut_rx_node(NODE_CONN_UPDATE, &ntf, &cu);
1802 ut_rx_q_is_empty();
1803
1804 /* Release Ntf */
1805 release_ntf(ntf);
1806 zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(),
1807 "Free CTX buffers %d", llcp_ctx_buffers_free());
1808 }
1809
1810 /*
1811 * Peripheral-initiated Connection Parameters Request procedure.
1812 * Peripheral requests change in LE connection parameters, central’s Host accepts.
1813 *
1814 * +-----+ +-------+ +-----+
1815 * | UT | | LL_P | | LT |
1816 * +-----+ +-------+ +-----+
1817 * | | |
1818 * | LE Connection Update | |
1819 * |-------------------------->| |
1820 * | | LL_CONNECTION_PARAM_REQ |
1821 * | |-------------------------->|
1822 * | | |
1823 * | | LL_CONNECTION_UPDATE_IND |
1824 * | |<--------------------------|
1825 * | | |
1826 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1827 * | | |
1828 * | LE Connection Update | |
1829 * | Complete | |
1830 * |<--------------------------| |
1831 * | | |
1832 */
ZTEST(periph_loc,test_conn_update_periph_loc_accept)1833 ZTEST(periph_loc, test_conn_update_periph_loc_accept)
1834 {
1835 uint8_t err;
1836 struct node_tx *tx;
1837 struct node_rx_pdu *ntf;
1838 uint16_t instant;
1839
1840 struct node_rx_pu cu = { .status = BT_HCI_ERR_SUCCESS };
1841
1842 /* Role */
1843 test_set_role(&conn, BT_HCI_ROLE_PERIPHERAL);
1844
1845 /* Connect */
1846 ull_cp_state_set(&conn, ULL_CP_CONNECTED);
1847
1848 /* Initiate a Connection Parameter Request Procedure */
1849 err = ull_cp_conn_update(&conn, INTVL_MIN, INTVL_MAX, LATENCY, TIMEOUT, NULL);
1850 zassert_equal(err, BT_HCI_ERR_SUCCESS);
1851
1852 /* Prepare */
1853 event_prepare(&conn);
1854 conn_param_req.reference_conn_event_count = event_counter(&conn);
1855
1856 /* Tx Queue should have one LL Control PDU */
1857 lt_rx(LL_CONNECTION_PARAM_REQ, &conn, &tx, &conn_param_req);
1858 lt_rx_q_is_empty(&conn);
1859
1860 /* Done */
1861 event_done(&conn);
1862
1863 /* Release Tx */
1864 ull_cp_release_tx(&conn, tx);
1865
1866 /* Prepare */
1867 event_prepare(&conn);
1868
1869 /* Tx Queue should NOT have a LL Control PDU */
1870 lt_rx_q_is_empty(&conn);
1871
1872 /* Rx */
1873 conn_update_ind.instant = event_counter(&conn) + 6U;
1874 instant = conn_update_ind.instant;
1875 lt_tx(LL_CONNECTION_UPDATE_IND, &conn, &conn_update_ind);
1876
1877 /* Done */
1878 event_done(&conn);
1879
1880 /* */
1881 while (!is_instant_reached(&conn, instant)) {
1882 /* Prepare */
1883 event_prepare(&conn);
1884
1885 /* Tx Queue should NOT have a LL Control PDU */
1886 lt_rx_q_is_empty(&conn);
1887
1888 /* Done */
1889 event_done(&conn);
1890
1891 /* There should NOT be a host notification */
1892 ut_rx_q_is_empty();
1893 }
1894
1895 /* Prepare */
1896 event_prepare(&conn);
1897
1898 /* Tx Queue should NOT have a LL Control PDU */
1899 lt_rx_q_is_empty(&conn);
1900
1901 /* Done */
1902 event_done(&conn);
1903
1904 /* There should be one host notification */
1905 ut_rx_node(NODE_CONN_UPDATE, &ntf, &cu);
1906 ut_rx_q_is_empty();
1907
1908 /* Release Ntf */
1909 release_ntf(ntf);
1910 zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(),
1911 "Free CTX buffers %d", llcp_ctx_buffers_free());
1912 }
1913
1914 /*
1915 * Peripheral-initiated Connection Parameters Request procedure.
1916 * Peripheral requests change in LE connection parameters, central’s Host rejects.
1917 *
1918 * +-----+ +-------+ +-----+
1919 * | UT | | LL_P | | LT |
1920 * +-----+ +-------+ +-----+
1921 * | | |
1922 * | LE Connection Update | |
1923 * |-------------------------->| |
1924 * | | LL_CONNECTION_PARAM_REQ |
1925 * | |-------------------------->|
1926 * | | |
1927 * | | LL_REJECT_EXT_IND |
1928 * | |<--------------------------|
1929 * | | |
1930 * | LE Connection Update | |
1931 * | Complete | |
1932 * |<--------------------------| |
1933 * | | |
1934 */
ZTEST(periph_loc,test_conn_update_periph_loc_reject)1935 ZTEST(periph_loc, test_conn_update_periph_loc_reject)
1936 {
1937 uint8_t err;
1938 struct node_tx *tx;
1939 struct node_rx_pdu *ntf;
1940
1941 struct node_rx_pu cu = { .status = BT_HCI_ERR_UNACCEPT_CONN_PARAM };
1942
1943 struct pdu_data_llctrl_reject_ext_ind reject_ext_ind = {
1944 .reject_opcode = PDU_DATA_LLCTRL_TYPE_CONN_PARAM_REQ,
1945 .error_code = BT_HCI_ERR_UNACCEPT_CONN_PARAM
1946 };
1947
1948 /* Role */
1949 test_set_role(&conn, BT_HCI_ROLE_PERIPHERAL);
1950
1951 /* Connect */
1952 ull_cp_state_set(&conn, ULL_CP_CONNECTED);
1953
1954 /* Initiate a Connection Parameter Request Procedure */
1955 err = ull_cp_conn_update(&conn, INTVL_MIN, INTVL_MAX, LATENCY, TIMEOUT, NULL);
1956 zassert_equal(err, BT_HCI_ERR_SUCCESS);
1957
1958 /* Prepare */
1959 event_prepare(&conn);
1960 conn_param_req.reference_conn_event_count = event_counter(&conn);
1961
1962 /* Tx Queue should have one LL Control PDU */
1963 lt_rx(LL_CONNECTION_PARAM_REQ, &conn, &tx, &conn_param_req);
1964 lt_rx_q_is_empty(&conn);
1965
1966 /* Done */
1967 event_done(&conn);
1968
1969 /* Release Tx */
1970 ull_cp_release_tx(&conn, tx);
1971
1972 /* Prepare */
1973 event_prepare(&conn);
1974
1975 /* Tx Queue should NOT have a LL Control PDU */
1976 lt_rx_q_is_empty(&conn);
1977
1978 /* Rx */
1979 lt_tx(LL_REJECT_EXT_IND, &conn, &reject_ext_ind);
1980
1981 /* Done */
1982 event_done(&conn);
1983
1984 /* There should be one host notification */
1985 ut_rx_node(NODE_CONN_UPDATE, &ntf, &cu);
1986 ut_rx_q_is_empty();
1987
1988 /* Release Ntf */
1989 release_ntf(ntf);
1990 zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(),
1991 "Free CTX buffers %d", llcp_ctx_buffers_free());
1992 }
1993
1994 /*
1995 * Peripheral-initiated Connection Parameters Request procedure.
1996 * Peripheral requests change in LE connection parameters, central’s Controller do not
1997 * support Connection Parameters Request procedure, features not exchanged.
1998 *
1999 * +-----+ +-------+ +-----+
2000 * | UT | | LL_P | | LT |
2001 * +-----+ +-------+ +-----+
2002 * | | |
2003 * | LE Connection Update | |
2004 * |-------------------------->| |
2005 * | | LL_CONNECTION_PARAM_REQ |
2006 * | |-------------------------->|
2007 * | | |
2008 * | | LL_UNKNOWN_RSP |
2009 * | |<--------------------------|
2010 * | | |
2011 * | LE Connection Update | |
2012 * | Complete | |
2013 * |<--------------------------| |
2014 * | | |
2015 */
ZTEST(periph_loc,test_conn_update_periph_loc_unsupp_feat_wo_feat_exch)2016 ZTEST(periph_loc, test_conn_update_periph_loc_unsupp_feat_wo_feat_exch)
2017 {
2018 uint8_t err;
2019 struct node_tx *tx;
2020 struct node_rx_pdu *ntf;
2021
2022 struct node_rx_pu cu = { .status = BT_HCI_ERR_UNSUPP_REMOTE_FEATURE };
2023
2024 struct pdu_data_llctrl_unknown_rsp unknown_rsp = {
2025 .type = PDU_DATA_LLCTRL_TYPE_CONN_PARAM_REQ
2026 };
2027
2028 /* Role */
2029 test_set_role(&conn, BT_HCI_ROLE_PERIPHERAL);
2030
2031 /* Connect */
2032 ull_cp_state_set(&conn, ULL_CP_CONNECTED);
2033
2034 /* Initiate a Connection Parameter Request Procedure */
2035 err = ull_cp_conn_update(&conn, INTVL_MIN, INTVL_MAX, LATENCY, TIMEOUT, NULL);
2036 zassert_equal(err, BT_HCI_ERR_SUCCESS);
2037
2038 /* Prepare */
2039 event_prepare(&conn);
2040 conn_param_req.reference_conn_event_count = event_counter(&conn);
2041
2042 /* Tx Queue should have one LL Control PDU */
2043 lt_rx(LL_CONNECTION_PARAM_REQ, &conn, &tx, &conn_param_req);
2044 lt_rx_q_is_empty(&conn);
2045
2046 /* Done */
2047 event_done(&conn);
2048
2049 /* Release Tx */
2050 ull_cp_release_tx(&conn, tx);
2051
2052 /* Prepare */
2053 event_prepare(&conn);
2054
2055 /* Tx Queue should NOT have a LL Control PDU */
2056 lt_rx_q_is_empty(&conn);
2057
2058 /* Rx */
2059 lt_tx(LL_UNKNOWN_RSP, &conn, &unknown_rsp);
2060
2061 /* Done */
2062 event_done(&conn);
2063
2064 /* There should be one host notification */
2065 ut_rx_node(NODE_CONN_UPDATE, &ntf, &cu);
2066 ut_rx_q_is_empty();
2067
2068 /* Release Ntf */
2069 release_ntf(ntf);
2070 zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(),
2071 "Free CTX buffers %d", llcp_ctx_buffers_free());
2072 }
2073
2074 /*
2075 * Peripheral-initiated Connection Parameters Request procedure.
2076 * Peripheral requests change in LE connection parameters, central’s Controller do not
2077 * support Connection Parameters Request procedure, features exchanged.
2078 *
2079 * +-----+ +-------+ +-----+
2080 * | UT | | LL_P | | LT |
2081 * +-----+ +-------+ +-----+
2082 * | | |
2083 * | LE Connection Update | |
2084 * |-------------------------->| |
2085 * | | LL_CONNECTION_UPDATE_IND |
2086 * | |-------------------------->|
2087 * | | |
2088 */
ZTEST(periph_loc,test_conn_update_periph_loc_unsupp_feat_w_feat_exch)2089 ZTEST(periph_loc, test_conn_update_periph_loc_unsupp_feat_w_feat_exch)
2090 {
2091 uint8_t err;
2092
2093 /* Disable feature */
2094 test_unmask_feature_conn_param_req(&conn);
2095
2096 /* Role */
2097 test_set_role(&conn, BT_HCI_ROLE_PERIPHERAL);
2098
2099 /* Connect */
2100 ull_cp_state_set(&conn, ULL_CP_CONNECTED);
2101
2102 /* Initiate a Connection Parameter Request Procedure */
2103 err = ull_cp_conn_update(&conn, INTVL_MIN, INTVL_MAX, LATENCY, TIMEOUT, NULL);
2104 zassert_equal(err, BT_HCI_ERR_UNSUPP_REMOTE_FEATURE);
2105
2106 /* Prepare */
2107 event_prepare(&conn);
2108
2109 /* Tx Queue should have no LL Control PDU */
2110 lt_rx_q_is_empty(&conn);
2111
2112 /* Done */
2113 event_done(&conn);
2114
2115 /* There should be no host notification */
2116 ut_rx_q_is_empty();
2117
2118 zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(),
2119 "Free CTX buffers %d", llcp_ctx_buffers_free());
2120 }
2121
2122 /*
2123 * (A)
2124 * Peripheral-initiated Connection Parameters Request procedure.
2125 * Procedure collides and is rejected.
2126 *
2127 * and
2128 *
2129 * (B)
2130 * Central-initiated Connection Parameters Request procedure.
2131 * Central requests change in LE connection parameters, peripheral’s Host accepts.
2132 *
2133 * +-----+ +-------+ +-----+
2134 * | UT | | LL_P | | LT |
2135 * +-----+ +-------+ +-----+
2136 * | | |
2137 * | LE Connection Update | |
2138 * |-------------------------->| | (A)
2139 * | | LL_CONNECTION_PARAM_REQ |
2140 * | |-------------------------->| (A)
2141 * | | |
2142 * | | LL_CONNECTION_PARAM_REQ |
2143 * | |<--------------------------| (B)
2144 * | | |
2145 * | <---------------------> |
2146 * | < PROCEDURE COLLISION > |
2147 * | <---------------------> |
2148 * | | |
2149 * | LE Remote Connection | |
2150 * | Parameter Request | |
2151 * |<--------------------------| | (B)
2152 * | | |
2153 * | LE Remote Connection | |
2154 * | Parameter Request | |
2155 * | Reply | |
2156 * |-------------------------->| | (B)
2157 * | | |
2158 * | | LL_REJECT_EXT_IND |
2159 * | |<--------------------------| (A)
2160 * | | |
2161 * | LE Connection Update | |
2162 * | Complete | |
2163 * |<--------------------------| | (A)
2164 * | | |
2165 * | | LL_CONNECTION_UPDATE_IND |
2166 * | |<--------------------------| (B)
2167 * | | |
2168 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2169 * | | |
2170 * | LE Connection Update | |
2171 * | Complete | |
2172 * |<--------------------------| | (B)
2173 */
ZTEST(periph_loc,test_conn_update_periph_loc_collision)2174 ZTEST(periph_loc, test_conn_update_periph_loc_collision)
2175 {
2176 uint8_t err;
2177 struct node_tx *tx;
2178 struct node_rx_pdu *ntf;
2179 uint16_t instant;
2180
2181 struct node_rx_pu cu1 = { .status = BT_HCI_ERR_LL_PROC_COLLISION };
2182
2183 struct node_rx_pu cu2 = { .status = BT_HCI_ERR_SUCCESS };
2184
2185 struct pdu_data_llctrl_reject_ext_ind reject_ext_ind = {
2186 .reject_opcode = PDU_DATA_LLCTRL_TYPE_CONN_PARAM_REQ,
2187 .error_code = BT_HCI_ERR_LL_PROC_COLLISION
2188 };
2189
2190 /* Role */
2191 test_set_role(&conn, BT_HCI_ROLE_PERIPHERAL);
2192
2193 /* Connect */
2194 ull_cp_state_set(&conn, ULL_CP_CONNECTED);
2195
2196 /* (A) Initiate a Connection Parameter Request Procedure */
2197 err = ull_cp_conn_update(&conn, INTVL_MIN, INTVL_MAX, LATENCY, TIMEOUT, NULL);
2198 zassert_equal(err, BT_HCI_ERR_SUCCESS);
2199
2200 /* Prepare */
2201 event_prepare(&conn);
2202
2203 /* (A) Tx Queue should have one LL Control PDU */
2204 conn_param_req.reference_conn_event_count = event_counter(&conn);
2205 lt_rx(LL_CONNECTION_PARAM_REQ, &conn, &tx, &conn_param_req);
2206 lt_rx_q_is_empty(&conn);
2207
2208 /* (B) Rx */
2209 lt_tx(LL_CONNECTION_PARAM_REQ, &conn, req_B);
2210
2211 /* Done */
2212 event_done(&conn);
2213
2214 /* Prepare */
2215 event_prepare(&conn);
2216
2217 /* Done */
2218 event_done(&conn);
2219
2220 /* Prepare */
2221 event_prepare(&conn);
2222
2223 /* Done */
2224 event_done(&conn);
2225
2226
2227 /* Release Tx */
2228 ull_cp_release_tx(&conn, tx);
2229
2230 /*******************/
2231
2232 /* (B) There should be one host notification */
2233 ut_rx_pdu(LL_CONNECTION_PARAM_REQ, &ntf, req_B);
2234 ut_rx_q_is_empty();
2235
2236 /* Release Ntf */
2237 release_ntf(ntf);
2238
2239 /*******************/
2240
2241 /* (B) */
2242 ull_cp_conn_param_req_reply(&conn);
2243
2244 /*******************/
2245
2246 /* Prepare */
2247 event_prepare(&conn);
2248
2249 /* (B) Tx Queue should have one LL Control PDU */
2250 rsp_B->reference_conn_event_count = req_B->reference_conn_event_count;
2251 lt_rx(LL_CONNECTION_PARAM_RSP, &conn, &tx, rsp_B);
2252 lt_rx_q_is_empty(&conn);
2253
2254 /* (A) Rx */
2255 lt_tx(LL_REJECT_EXT_IND, &conn, &reject_ext_ind);
2256
2257 /* Done */
2258 event_done(&conn);
2259
2260 /* (A) There should be one host notification */
2261 ut_rx_node(NODE_CONN_UPDATE, &ntf, &cu1);
2262 ut_rx_q_is_empty();
2263
2264 /* Release Ntf */
2265 release_ntf(ntf);
2266
2267 /* Prepare */
2268 event_prepare(&conn);
2269
2270 /* (B) Rx */
2271 cu_ind_B->instant = instant = event_counter(&conn) + 6;
2272 lt_tx(LL_CONNECTION_UPDATE_IND, &conn, cu_ind_B);
2273
2274 /* Done */
2275 event_done(&conn);
2276
2277 /* Release Tx */
2278 ull_cp_release_tx(&conn, tx);
2279
2280 /* */
2281 while (!is_instant_reached(&conn, instant)) {
2282 /* Prepare */
2283 event_prepare(&conn);
2284
2285 /* (B) Tx Queue should NOT have a LL Control PDU */
2286 lt_rx_q_is_empty(&conn);
2287
2288 /* Done */
2289 event_done(&conn);
2290
2291 /* (B) There should NOT be a host notification */
2292 ut_rx_q_is_empty();
2293 }
2294
2295 /* Prepare */
2296 event_prepare(&conn);
2297
2298 /* (B) Tx Queue should NOT have a LL Control PDU */
2299 lt_rx_q_is_empty(&conn);
2300
2301 /* Done */
2302 event_done(&conn);
2303
2304 /* (B) There should be one host notification */
2305 ut_rx_node(NODE_CONN_UPDATE, &ntf, &cu2);
2306 ut_rx_q_is_empty();
2307
2308 /* Release Ntf */
2309 release_ntf(ntf);
2310 zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(),
2311 "Free CTX buffers %d", llcp_ctx_buffers_free());
2312 }
2313
2314 /*
2315 * Central-initiated Connection Parameters Request procedure.
2316 * Central requests change in LE connection parameters, peripheral’s Host accepts.
2317 *
2318 * +-----+ +-------+ +-----+
2319 * | UT | | LL_P | | LT |
2320 * +-----+ +-------+ +-----+
2321 * | | |
2322 * | | LL_CONNECTION_PARAM_REQ |
2323 * | |<--------------------------|
2324 * | | |
2325 * | LE Remote Connection | |
2326 * | Parameter Request | |
2327 * |<--------------------------| |
2328 * | LE Remote Connection | |
2329 * | Parameter Request | |
2330 * | Reply | |
2331 * |-------------------------->| |
2332 * | | |
2333 * | | LL_CONNECTION_PARAM_RSP |
2334 * | |-------------------------->|
2335 * | | |
2336 * | | LL_CONNECTION_UPDATE_IND |
2337 * | |<--------------------------|
2338 * | | |
2339 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2340 * | | |
2341 * | LE Connection Update | |
2342 * | Complete | |
2343 * |<--------------------------| |
2344 * | | |
2345 */
ZTEST(periph_rem,test_conn_update_periph_rem_accept)2346 ZTEST(periph_rem, test_conn_update_periph_rem_accept)
2347 {
2348 struct node_tx *tx;
2349 struct node_rx_pdu *ntf;
2350 uint16_t instant;
2351
2352 struct node_rx_pu cu = { .status = BT_HCI_ERR_SUCCESS };
2353
2354 /* Role */
2355 test_set_role(&conn, BT_HCI_ROLE_PERIPHERAL);
2356
2357 /* Connect */
2358 ull_cp_state_set(&conn, ULL_CP_CONNECTED);
2359
2360 /* Prepare */
2361 event_prepare(&conn);
2362
2363 /* Tx Queue should NOT have a LL Control PDU */
2364 lt_rx_q_is_empty(&conn);
2365
2366 /* Rx */
2367 lt_tx(LL_CONNECTION_PARAM_REQ, &conn, &conn_param_req);
2368
2369 /* Done */
2370 event_done(&conn);
2371
2372 /*******************/
2373
2374 /* There should be one host notification */
2375 ut_rx_pdu(LL_CONNECTION_PARAM_REQ, &ntf, &conn_param_req);
2376 ut_rx_q_is_empty();
2377
2378 /* Release Ntf */
2379 release_ntf(ntf);
2380
2381 /*******************/
2382
2383 ull_cp_conn_param_req_reply(&conn);
2384
2385 /*******************/
2386
2387 /* Prepare */
2388 event_prepare(&conn);
2389
2390 /* Tx Queue should have one LL Control PDU */
2391 lt_rx(LL_CONNECTION_PARAM_RSP, &conn, &tx, &conn_param_rsp);
2392 lt_rx_q_is_empty(&conn);
2393
2394 /* Done */
2395 event_done(&conn);
2396
2397 /* Prepare */
2398 event_prepare(&conn);
2399
2400 /* Rx */
2401 conn_update_ind.instant = event_counter(&conn) + 6U;
2402 instant = conn_update_ind.instant;
2403 lt_tx(LL_CONNECTION_UPDATE_IND, &conn, &conn_update_ind);
2404
2405 /* Done */
2406 event_done(&conn);
2407
2408 /* Release Tx */
2409 ull_cp_release_tx(&conn, tx);
2410
2411 /* */
2412 while (!is_instant_reached(&conn, instant)) {
2413 /* Prepare */
2414 event_prepare(&conn);
2415
2416 /* Tx Queue should NOT have a LL Control PDU */
2417 lt_rx_q_is_empty(&conn);
2418
2419 /* Done */
2420 event_done(&conn);
2421
2422 /* There should NOT be a host notification */
2423 ut_rx_q_is_empty();
2424 }
2425
2426 /* Prepare */
2427 event_prepare(&conn);
2428
2429 /* Tx Queue should NOT have a LL Control PDU */
2430 lt_rx_q_is_empty(&conn);
2431
2432 /* Done */
2433 event_done(&conn);
2434
2435 /* There should be one host notification */
2436 ut_rx_node(NODE_CONN_UPDATE, &ntf, &cu);
2437 ut_rx_q_is_empty();
2438
2439 /* Release Ntf */
2440 release_ntf(ntf);
2441 zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(),
2442 "Free CTX buffers %d", llcp_ctx_buffers_free());
2443 }
2444 #define RADIO_CONN_EVENTS(x, y) ((uint16_t)DIV_ROUND_UP(x, y))
2445
2446 /*
2447 * Central-initiated Connection Parameters Request procedure - only anchor point move.
2448 * Central requests change in anchor point only on LE connection, peripheral’s Host accepts.
2449 *
2450 * +-----+ +-------+ +-----+
2451 * | UT | | LL_P | | LT |
2452 * +-----+ +-------+ +-----+
2453 * | | |
2454 * | | LL_CONNECTION_PARAM_REQ |
2455 * | | (only apm) |
2456 * | |<--------------------------|
2457 * | | |
2458 * | Defered APM disabled | |
2459 * | '<---------' | |
2460 * | So accepted right away | |
2461 * | '--------->' | |
2462 * | | |
2463 * | | LL_CONNECTION_PARAM_RSP |
2464 * | |-------------------------->|
2465 * | | |
2466 * | | LL_CONNECTION_UPDATE_IND |
2467 * | |<--------------------------|
2468 * | | |
2469 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2470 * | | |
2471 * | | |
2472 */
ZTEST(periph_rem,test_conn_update_periph_rem_apm_accept_right_away)2473 ZTEST(periph_rem, test_conn_update_periph_rem_apm_accept_right_away)
2474 {
2475 #if defined(CONFIG_BT_CTLR_USER_CPR_ANCHOR_POINT_MOVE)
2476 struct node_tx *tx;
2477 uint16_t instant;
2478 uint8_t error = 0U;
2479 /* Default conn_param_req PDU */
2480 struct pdu_data_llctrl_conn_param_req conn_param_req_apm = { .interval_min = INTVL_MIN,
2481 .interval_max = INTVL_MAX,
2482 .latency = LATENCY,
2483 .timeout = TIMEOUT,
2484 .preferred_periodicity = 0U,
2485 .reference_conn_event_count = 0u,
2486 .offset0 = 0x0008U,
2487 .offset1 = 0xffffU,
2488 .offset2 = 0xffffU,
2489 .offset3 = 0xffffU,
2490 .offset4 = 0xffffU,
2491 .offset5 = 0xffffU };
2492
2493 /* Default conn_param_rsp PDU */
2494 struct pdu_data_llctrl_conn_param_rsp conn_param_rsp_apm = { .interval_min = INTVL_MIN,
2495 .interval_max = INTVL_MAX,
2496 .latency = LATENCY,
2497 .timeout = TIMEOUT,
2498 .preferred_periodicity = 0U,
2499 .reference_conn_event_count = 0u,
2500 .offset0 = 0x008U,
2501 .offset1 = 0xffffU,
2502 .offset2 = 0xffffU,
2503 .offset3 = 0xffffU,
2504 .offset4 = 0xffffU,
2505 .offset5 = 0xffffU };
2506
2507 /* Prepare mocked call to ull_handle_cpr_anchor_point_move */
2508 /* No APM deferance, accept with error == 0 */
2509 ztest_returns_value(ull_handle_cpr_anchor_point_move, false);
2510 ztest_return_data(ull_handle_cpr_anchor_point_move, status, &error);
2511
2512 /* Role */
2513 test_set_role(&conn, BT_HCI_ROLE_PERIPHERAL);
2514
2515 /* Connect */
2516 ull_cp_state_set(&conn, ULL_CP_CONNECTED);
2517
2518 conn.lll.interval = conn_param_req_apm.interval_max;
2519 conn.lll.latency = conn_param_req_apm.latency;
2520 conn.supervision_timeout = TIMEOUT;
2521
2522 /* Prepare */
2523 event_prepare(&conn);
2524
2525 /* Tx Queue should NOT have a LL Control PDU */
2526 lt_rx_q_is_empty(&conn);
2527
2528 /* Rx */
2529 lt_tx(LL_CONNECTION_PARAM_REQ, &conn, &conn_param_req_apm);
2530
2531 /* Done */
2532 event_done(&conn);
2533
2534 /*******************/
2535
2536 /* There should be no host notification */
2537 ut_rx_q_is_empty();
2538
2539 /* Prepare */
2540 event_prepare(&conn);
2541
2542 /* Tx Queue should have one LL Control PDU */
2543 lt_rx(LL_CONNECTION_PARAM_RSP, &conn, &tx, &conn_param_rsp_apm);
2544 lt_rx_q_is_empty(&conn);
2545
2546 /* Done */
2547 event_done(&conn);
2548
2549 /* Prepare */
2550 event_prepare(&conn);
2551
2552 /* Rx */
2553 conn_update_ind.instant = event_counter(&conn) + 6U;
2554 instant = conn_update_ind.instant;
2555 lt_tx(LL_CONNECTION_UPDATE_IND, &conn, &conn_update_ind);
2556
2557 /* Done */
2558 event_done(&conn);
2559
2560 /* Release Tx */
2561 ull_cp_release_tx(&conn, tx);
2562
2563 /* */
2564 while (!is_instant_reached(&conn, instant)) {
2565 /* Prepare */
2566 event_prepare(&conn);
2567
2568 /* Tx Queue should NOT have a LL Control PDU */
2569 lt_rx_q_is_empty(&conn);
2570
2571 /* Done */
2572 event_done(&conn);
2573
2574 /* There should NOT be a host notification */
2575 ut_rx_q_is_empty();
2576 }
2577
2578 /* Prepare */
2579 event_prepare(&conn);
2580
2581 /* Tx Queue should NOT have a LL Control PDU */
2582 lt_rx_q_is_empty(&conn);
2583
2584 /* Done */
2585 event_done(&conn);
2586
2587 /* There should be no host notification */
2588 ut_rx_q_is_empty();
2589
2590 zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(),
2591 "Free CTX buffers %d", llcp_ctx_buffers_free());
2592 #endif
2593 }
2594
2595 /*
2596 * Central-initiated Connection Parameters Request procedure - only anchor point move.
2597 * Central requests change in anchor point only on LE connection, peripheral’s Host accepts.
2598 *
2599 * +-----+ +-------+ +-----+
2600 * | UT | | LL_P | | LT |
2601 * +-----+ +-------+ +-----+
2602 * | | |
2603 * | | LL_CONNECTION_PARAM_REQ |
2604 * | | (only apm) |
2605 * | |<--------------------------|
2606 * | | |
2607 * | Defered APM disabled | |
2608 * | '<---------' | |
2609 * | So accepted right away | |
2610 * | but with error | |
2611 * | '--------->' | |
2612 * | | |
2613 * | | LL_REJECT_EXT_IND |
2614 * | |-------------------------->|
2615 * | | |
2616 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2617 * | | |
2618 * | | |
2619 */
ZTEST(periph_rem,test_conn_update_periph_rem_apm_reject_right_away)2620 ZTEST(periph_rem, test_conn_update_periph_rem_apm_reject_right_away)
2621 {
2622 #if defined(CONFIG_BT_CTLR_USER_CPR_ANCHOR_POINT_MOVE)
2623 struct node_tx *tx;
2624 /* Default conn_param_req PDU */
2625 struct pdu_data_llctrl_conn_param_req conn_param_req_apm = { .interval_min = INTVL_MIN,
2626 .interval_max = INTVL_MAX,
2627 .latency = LATENCY,
2628 .timeout = TIMEOUT,
2629 .preferred_periodicity = 0U,
2630 .reference_conn_event_count = 0u,
2631 .offset0 = 0x0008U,
2632 .offset1 = 0xffffU,
2633 .offset2 = 0xffffU,
2634 .offset3 = 0xffffU,
2635 .offset4 = 0xffffU,
2636 .offset5 = 0xffffU };
2637 struct pdu_data_llctrl_reject_ext_ind reject_ext_ind = {
2638 .reject_opcode = PDU_DATA_LLCTRL_TYPE_CONN_PARAM_REQ,
2639 .error_code = BT_HCI_ERR_UNSUPP_LL_PARAM_VAL + 1
2640 };
2641 uint8_t error = reject_ext_ind.error_code;
2642
2643 /* Prepare mocked call to ull_handle_cpr_anchor_point_move */
2644 /* No APM deferance, reject with some error code */
2645 ztest_returns_value(ull_handle_cpr_anchor_point_move, false);
2646 ztest_return_data(ull_handle_cpr_anchor_point_move, status, &error);
2647
2648 /* Role */
2649 test_set_role(&conn, BT_HCI_ROLE_PERIPHERAL);
2650
2651 /* Connect */
2652 ull_cp_state_set(&conn, ULL_CP_CONNECTED);
2653
2654 conn.lll.interval = conn_param_req_apm.interval_max;
2655 conn.lll.latency = conn_param_req_apm.latency;
2656 conn.supervision_timeout = TIMEOUT;
2657
2658 /* Prepare */
2659 event_prepare(&conn);
2660
2661 /* Tx Queue should NOT have a LL Control PDU */
2662 lt_rx_q_is_empty(&conn);
2663
2664 /* Rx */
2665 lt_tx(LL_CONNECTION_PARAM_REQ, &conn, &conn_param_req_apm);
2666
2667 /* Done */
2668 event_done(&conn);
2669
2670 /*******************/
2671
2672 /* There should be no host notification */
2673 ut_rx_q_is_empty();
2674
2675 /* Prepare */
2676 event_prepare(&conn);
2677
2678 /* Tx Queue should have one LL Control PDU */
2679 lt_rx(LL_REJECT_EXT_IND, &conn, &tx, &reject_ext_ind);
2680 lt_rx_q_is_empty(&conn);
2681
2682 /* Release Tx */
2683 ull_cp_release_tx(&conn, tx);
2684
2685 /* Done */
2686 event_done(&conn);
2687
2688 /* Prepare */
2689 event_prepare(&conn);
2690
2691 /* Tx Queue should NOT have a LL Control PDU */
2692 lt_rx_q_is_empty(&conn);
2693
2694 /* Done */
2695 event_done(&conn);
2696
2697 /* There should be no host notification */
2698 ut_rx_q_is_empty();
2699
2700 zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(),
2701 "Free CTX buffers %d", llcp_ctx_buffers_free());
2702 #endif
2703 }
2704
2705 /*
2706 * Central-initiated Connection Parameters Request procedure - only anchor point move.
2707 * Central requests change in anchor point only on LE connection, peripheral’s Host accepts.
2708 *
2709 * +-----+ +-------+ +-----+
2710 * | UT | | LL_P | | LT |
2711 * +-----+ +-------+ +-----+
2712 * | | |
2713 * | | LL_CONNECTION_PARAM_REQ |
2714 * | | (only apm) |
2715 * | |<--------------------------|
2716 * | | |
2717 * | Defered APM | |
2718 * | '<---------' | |
2719 * | | |
2720 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2721 * | | |
2722 * | Defered accept | |
2723 * | '--------->' | |
2724 * | | |
2725 * | | LL_CONNECTION_PARAM_RSP |
2726 * | |-------------------------->|
2727 * | | |
2728 * | | LL_CONNECTION_UPDATE_IND |
2729 * | |<--------------------------|
2730 * | | |
2731 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2732 * | | |
2733 * | | |
2734 */
ZTEST(periph_rem,test_conn_update_periph_rem_apm_accept_defered)2735 ZTEST(periph_rem, test_conn_update_periph_rem_apm_accept_defered)
2736 {
2737 #if defined(CONFIG_BT_CTLR_USER_CPR_ANCHOR_POINT_MOVE)
2738 uint16_t offsets[6] = {
2739 0x0008U,
2740 0xffffU,
2741 0xffffU,
2742 0xffffU,
2743 0xffffU,
2744 0xffffU
2745 };
2746 struct node_tx *tx;
2747 uint16_t instant;
2748 uint8_t error = 0U;
2749 /* Default conn_param_req PDU */
2750 struct pdu_data_llctrl_conn_param_req conn_param_req_apm = { .interval_min = INTVL_MIN,
2751 .interval_max = INTVL_MAX,
2752 .latency = LATENCY,
2753 .timeout = TIMEOUT,
2754 .preferred_periodicity = 0U,
2755 .reference_conn_event_count = 0u,
2756 .offset0 = 0x0004U,
2757 .offset1 = 0xffffU,
2758 .offset2 = 0xffffU,
2759 .offset3 = 0xffffU,
2760 .offset4 = 0xffffU,
2761 .offset5 = 0xffffU };
2762
2763 /* Default conn_param_rsp PDU */
2764 struct pdu_data_llctrl_conn_param_rsp conn_param_rsp_apm = { .interval_min = INTVL_MIN,
2765 .interval_max = INTVL_MAX,
2766 .latency = LATENCY,
2767 .timeout = TIMEOUT,
2768 .preferred_periodicity = 0U,
2769 .reference_conn_event_count = 0u,
2770 .offset0 = 0x008U,
2771 .offset1 = 0xffffU,
2772 .offset2 = 0xffffU,
2773 .offset3 = 0xffffU,
2774 .offset4 = 0xffffU,
2775 .offset5 = 0xffffU };
2776
2777 /* Prepare mocked call to ull_handle_cpr_anchor_point_move */
2778 /* Defer APM */
2779 ztest_returns_value(ull_handle_cpr_anchor_point_move, true);
2780 ztest_return_data(ull_handle_cpr_anchor_point_move, status, &error);
2781
2782 /* Role */
2783 test_set_role(&conn, BT_HCI_ROLE_PERIPHERAL);
2784
2785 /* Connect */
2786 ull_cp_state_set(&conn, ULL_CP_CONNECTED);
2787
2788 conn.lll.interval = conn_param_req_apm.interval_max;
2789 conn.lll.latency = conn_param_req_apm.latency;
2790 conn.supervision_timeout = TIMEOUT;
2791
2792 /* Prepare */
2793 event_prepare(&conn);
2794
2795 /* Tx Queue should NOT have a LL Control PDU */
2796 lt_rx_q_is_empty(&conn);
2797
2798 /* Rx */
2799 lt_tx(LL_CONNECTION_PARAM_REQ, &conn, &conn_param_req_apm);
2800
2801 /* Done */
2802 event_done(&conn);
2803
2804 /* Run a few events */
2805 for (int i = 0; i < 10; i++) {
2806
2807 /* Prepare */
2808 event_prepare(&conn);
2809
2810 zassert_equal(true, ull_cp_remote_cpr_apm_awaiting_reply(&conn), NULL);
2811
2812 /* There should be no host notification */
2813 ut_rx_q_is_empty();
2814
2815 /* Done */
2816 event_done(&conn);
2817 }
2818
2819 ull_cp_remote_cpr_apm_reply(&conn, offsets);
2820
2821 /* There should be no host notification */
2822 ut_rx_q_is_empty();
2823
2824 /* Prepare */
2825 event_prepare(&conn);
2826
2827 /* Tx Queue should have one LL Control PDU */
2828 lt_rx(LL_CONNECTION_PARAM_RSP, &conn, &tx, &conn_param_rsp_apm);
2829 lt_rx_q_is_empty(&conn);
2830
2831 /* Done */
2832 event_done(&conn);
2833
2834 /* Prepare */
2835 event_prepare(&conn);
2836
2837 /* Rx */
2838 conn_update_ind.instant = event_counter(&conn) + 6U;
2839 instant = conn_update_ind.instant;
2840 lt_tx(LL_CONNECTION_UPDATE_IND, &conn, &conn_update_ind);
2841
2842 /* Done */
2843 event_done(&conn);
2844
2845 /* Release Tx */
2846 ull_cp_release_tx(&conn, tx);
2847
2848 /* */
2849 while (!is_instant_reached(&conn, instant)) {
2850 /* Prepare */
2851 event_prepare(&conn);
2852
2853 /* Tx Queue should NOT have a LL Control PDU */
2854 lt_rx_q_is_empty(&conn);
2855
2856 /* Done */
2857 event_done(&conn);
2858
2859 /* There should NOT be a host notification */
2860 ut_rx_q_is_empty();
2861 }
2862
2863 /* Prepare */
2864 event_prepare(&conn);
2865
2866 /* Tx Queue should NOT have a LL Control PDU */
2867 lt_rx_q_is_empty(&conn);
2868
2869 /* Done */
2870 event_done(&conn);
2871
2872 /* There should be no host notification */
2873 ut_rx_q_is_empty();
2874
2875 zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(),
2876 "Free CTX buffers %d", llcp_ctx_buffers_free());
2877 #endif
2878 }
2879
2880 /*
2881 * Central-initiated Connection Parameters Request procedure - only anchor point move.
2882 * Central requests change in anchor point only on LE connection, peripheral’s Host accepts.
2883 *
2884 * +-----+ +-------+ +-----+
2885 * | UT | | LL_P | | LT |
2886 * +-----+ +-------+ +-----+
2887 * | | |
2888 * | | LL_CONNECTION_PARAM_REQ |
2889 * | | (only apm) |
2890 * | |<--------------------------|
2891 * | | |
2892 * | Defered APM | |
2893 * | '<---------' | |
2894 * | | |
2895 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2896 * | | |
2897 * | Defered accept | |
2898 * | but with error | |
2899 * | '--------->' | |
2900 * | | |
2901 * | | LL_REJECT_EXT_IND |
2902 * | |-------------------------->|
2903 * | | |
2904 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2905 * | | |
2906 * | | |
2907 */
ZTEST(periph_rem,test_conn_update_periph_rem_apm_reject_defered)2908 ZTEST(periph_rem, test_conn_update_periph_rem_apm_reject_defered)
2909 {
2910 #if defined(CONFIG_BT_CTLR_USER_CPR_ANCHOR_POINT_MOVE)
2911 struct node_tx *tx;
2912 uint8_t error = 0U;
2913 /* Default conn_param_req PDU */
2914 struct pdu_data_llctrl_conn_param_req conn_param_req_apm = { .interval_min = INTVL_MIN,
2915 .interval_max = INTVL_MAX,
2916 .latency = LATENCY,
2917 .timeout = TIMEOUT,
2918 .preferred_periodicity = 0U,
2919 .reference_conn_event_count = 0u,
2920 .offset0 = 0x0008U,
2921 .offset1 = 0xffffU,
2922 .offset2 = 0xffffU,
2923 .offset3 = 0xffffU,
2924 .offset4 = 0xffffU,
2925 .offset5 = 0xffffU };
2926 struct pdu_data_llctrl_reject_ext_ind reject_ext_ind = {
2927 .reject_opcode = PDU_DATA_LLCTRL_TYPE_CONN_PARAM_REQ,
2928 .error_code = BT_HCI_ERR_UNSUPP_LL_PARAM_VAL
2929 };
2930
2931 /* Prepare mocked call to ull_handle_cpr_anchor_point_move */
2932 /* Defer APM */
2933 ztest_returns_value(ull_handle_cpr_anchor_point_move, true);
2934 ztest_return_data(ull_handle_cpr_anchor_point_move, status, &error);
2935
2936 /* Role */
2937 test_set_role(&conn, BT_HCI_ROLE_PERIPHERAL);
2938
2939 /* Connect */
2940 ull_cp_state_set(&conn, ULL_CP_CONNECTED);
2941
2942 conn.lll.interval = conn_param_req_apm.interval_max;
2943 conn.lll.latency = conn_param_req_apm.latency;
2944 conn.supervision_timeout = TIMEOUT;
2945
2946 /* Prepare */
2947 event_prepare(&conn);
2948
2949 /* Tx Queue should NOT have a LL Control PDU */
2950 lt_rx_q_is_empty(&conn);
2951
2952 /* Rx */
2953 lt_tx(LL_CONNECTION_PARAM_REQ, &conn, &conn_param_req_apm);
2954
2955 /* Done */
2956 event_done(&conn);
2957
2958 /* Run a few events */
2959 for (int i = 0; i < 10; i++) {
2960
2961 /* Prepare */
2962 event_prepare(&conn);
2963
2964 zassert_equal(true, ull_cp_remote_cpr_apm_awaiting_reply(&conn), NULL);
2965
2966 /* There should be no host notification */
2967 ut_rx_q_is_empty();
2968
2969 /* Done */
2970 event_done(&conn);
2971 }
2972
2973 ull_cp_remote_cpr_apm_neg_reply(&conn, BT_HCI_ERR_UNSUPP_LL_PARAM_VAL);
2974
2975 /* Prepare */
2976 event_prepare(&conn);
2977
2978 /* Done */
2979 event_done(&conn);
2980
2981 /*******************/
2982
2983 /* There should be no host notification */
2984 ut_rx_q_is_empty();
2985
2986 /* Prepare */
2987 event_prepare(&conn);
2988
2989 /* Tx Queue should have one LL Control PDU */
2990 lt_rx(LL_REJECT_EXT_IND, &conn, &tx, &reject_ext_ind);
2991 lt_rx_q_is_empty(&conn);
2992
2993 /* Release Tx */
2994 ull_cp_release_tx(&conn, tx);
2995
2996 /* Done */
2997 event_done(&conn);
2998
2999 /* Prepare */
3000 event_prepare(&conn);
3001
3002 /* Tx Queue should NOT have a LL Control PDU */
3003 lt_rx_q_is_empty(&conn);
3004
3005 /* Done */
3006 event_done(&conn);
3007
3008 /* There should be no host notification */
3009 ut_rx_q_is_empty();
3010
3011 zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(),
3012 "Free CTX buffers %d", llcp_ctx_buffers_free());
3013 #endif /* CONFIG_BT_CTLR_USER_CPR_ANCHOR_POINT_MOVE */
3014 }
3015
3016 /*
3017 * (A)
3018 * Peripheral-initiated Connection Parameters Request procedure.
3019 * Procedure collides and is rejected.
3020 *
3021 * and
3022 *
3023 * (B)
3024 * Central-initiated Connection Parameters Request procedure.
3025 * Central requests change in LE connection parameters, peripheral’s Host accepts.
3026 *
3027 * +-----+ +-------+ +-----+
3028 * | UT | | LL_P | | LT |
3029 * +-----+ +-------+ +-----+
3030 * | | |
3031 * | LE Connection Update | |
3032 * |-------------------------->| | (A)
3033 * | | LL_CONNECTION_PARAM_REQ |
3034 * | |-------------------------->| (A)
3035 * | | |
3036 * | | LL_CONNECTION_PARAM_REQ |
3037 * | |<--------------------------| (B)
3038 * | | |
3039 * | <---------------------> |
3040 * | < PROCEDURE COLLISION > |
3041 * | <---------------------> |
3042 * | | |
3043 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3044 * ~~~~~ parallel remote CPRs attempted and rejected ~~~~~~~
3045 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3046 * | | |
3047 * | | |
3048 * | LE Remote Connection | |
3049 * | Parameter Request | |
3050 * |<--------------------------| | (B)
3051 * | | |
3052 * | LE Remote Connection | |
3053 * | Parameter Request | |
3054 * | Reply | |
3055 * |-------------------------->| | (B)
3056 * | | |
3057 * | | LL_REJECT_EXT_IND |
3058 * | |<--------------------------| (A)
3059 * | | |
3060 * | LE Connection Update | |
3061 * | Complete | |
3062 * |<--------------------------| | (A)
3063 * | | |
3064 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3065 * ~~~~~ parallel local CPR is attempted and cached ~~~~~~~
3066 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3067 * | | LL_CONNECTION_UPDATE_IND |
3068 * | |<--------------------------| (B)
3069 * | | |
3070 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3071 * | | |
3072 * | LE Connection Update | |
3073 * | Complete | |
3074 * |<--------------------------| | (B)
3075 * | | |
3076 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3077 * ~~~~~~~~~ parallel local CPR is now started ~~~~~~~~~~~~
3078 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3079 * | | |
3080 */
ZTEST(periph_loc,test_conn_update_periph_loc_collision_reject_2nd_cpr)3081 ZTEST(periph_loc, test_conn_update_periph_loc_collision_reject_2nd_cpr)
3082 {
3083 struct ll_conn conn_2nd;
3084 struct ll_conn conn_3rd;
3085 uint8_t err;
3086 struct node_tx *tx, *tx1;
3087 struct node_rx_pdu *ntf;
3088 uint16_t instant;
3089
3090 struct node_rx_pu cu1 = { .status = BT_HCI_ERR_LL_PROC_COLLISION };
3091 struct node_rx_pu cu2 = { .status = BT_HCI_ERR_SUCCESS };
3092 struct pdu_data_llctrl_reject_ext_ind reject_ext_ind = {
3093 .reject_opcode = PDU_DATA_LLCTRL_TYPE_CONN_PARAM_REQ,
3094 .error_code = BT_HCI_ERR_LL_PROC_COLLISION
3095 };
3096 struct pdu_data_llctrl_reject_ext_ind parallel_reject_ext_ind = {
3097 .reject_opcode = PDU_DATA_LLCTRL_TYPE_CONN_PARAM_REQ,
3098 .error_code = BT_HCI_ERR_UNSUPP_LL_PARAM_VAL
3099 };
3100
3101 /* Initialize extra connections */
3102 test_setup_idx(&conn_2nd, 1);
3103 test_setup_idx(&conn_3rd, 2);
3104
3105 /* Role */
3106 test_set_role(&conn, BT_HCI_ROLE_PERIPHERAL);
3107 /* Role */
3108 test_set_role(&conn_2nd, BT_HCI_ROLE_PERIPHERAL);
3109 /* Role */
3110 test_set_role(&conn_3rd, BT_HCI_ROLE_CENTRAL);
3111
3112 /* Connect */
3113 ull_cp_state_set(&conn, ULL_CP_CONNECTED);
3114 /* Connect */
3115 ull_cp_state_set(&conn_2nd, ULL_CP_CONNECTED);
3116 /* Connect */
3117 ull_cp_state_set(&conn_3rd, ULL_CP_CONNECTED);
3118
3119 /* (A) Initiate a Connection Parameter Request Procedure */
3120 err = ull_cp_conn_update(&conn, INTVL_MIN, INTVL_MAX, LATENCY, TIMEOUT, NULL);
3121 zassert_equal(err, BT_HCI_ERR_SUCCESS);
3122
3123 /* Prepare */
3124 event_prepare(&conn);
3125 conn_param_req.reference_conn_event_count = event_counter(&conn);
3126
3127 /* (A) Tx Queue should have one LL Control PDU */
3128 lt_rx(LL_CONNECTION_PARAM_REQ, &conn, &tx1, &conn_param_req);
3129 lt_rx_q_is_empty(&conn);
3130
3131 /* (B) Rx */
3132 lt_tx(LL_CONNECTION_PARAM_REQ, &conn, req_B);
3133
3134 /* Done */
3135 event_done(&conn);
3136
3137 {
3138 zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt()-2,
3139 "Free CTX buffers %d", llcp_ctx_buffers_free());
3140 /* Parallel CPR from central */
3141 /* Now CPR is active on 'conn' so let 'conn_2nd' attempt to start a CPR */
3142 /* Prepare */
3143 event_prepare(&conn_2nd);
3144
3145 /* Tx Queue should NOT have a LL Control PDU */
3146 lt_rx_q_is_empty(&conn_2nd);
3147
3148 /* Rx */
3149 lt_tx(LL_CONNECTION_PARAM_REQ, &conn_2nd, &conn_param_req);
3150
3151 /* Done */
3152 event_done(&conn_2nd);
3153
3154 /* Tx Queue should have one LL Control PDU */
3155 lt_rx(LL_REJECT_EXT_IND, &conn_2nd, &tx, ¶llel_reject_ext_ind);
3156 lt_rx_q_is_empty(&conn_2nd);
3157
3158 /* Release Tx */
3159 ull_cp_release_tx(&conn_2nd, tx);
3160
3161 /* There should be no 'extra' procedure on acount of the parallel CPR */
3162 zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt()-2,
3163 "Free CTX buffers %d", llcp_ctx_buffers_free());
3164 }
3165
3166 /* Prepare */
3167 event_prepare(&conn);
3168
3169 /* Done */
3170 event_done(&conn);
3171
3172 {
3173 /* Parallel CPR from peripheral */
3174 /* Now CPR is active on 'conn' so let 'conn_3rd' attempt to start a CPR */
3175 /* Prepare */
3176 event_prepare(&conn_3rd);
3177
3178 /* Tx Queue should NOT have a LL Control PDU */
3179 lt_rx_q_is_empty(&conn_3rd);
3180
3181 /* Rx */
3182 lt_tx(LL_CONNECTION_PARAM_REQ, &conn_3rd, &conn_param_req);
3183
3184 /* Done */
3185 event_done(&conn_3rd);
3186
3187 /* Tx Queue should have one LL Control PDU */
3188 lt_rx(LL_REJECT_EXT_IND, &conn_3rd, &tx, ¶llel_reject_ext_ind);
3189 lt_rx_q_is_empty(&conn_3rd);
3190
3191 /* Release Tx */
3192 ull_cp_release_tx(&conn_3rd, tx);
3193
3194 /* There should be no 'extra' procedure on acount of the parallel CPR */
3195 zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt()-2,
3196 "Free CTX buffers %d", llcp_ctx_buffers_free());
3197 }
3198
3199 /* Prepare */
3200 event_prepare(&conn);
3201
3202 /* Done */
3203 event_done(&conn);
3204
3205
3206 /* Release Tx */
3207 ull_cp_release_tx(&conn, tx1);
3208
3209 /*******************/
3210
3211 /* (B) There should be one host notification */
3212 ut_rx_pdu(LL_CONNECTION_PARAM_REQ, &ntf, req_B);
3213 ut_rx_q_is_empty();
3214
3215 /* Release Ntf */
3216 release_ntf(ntf);
3217
3218 /*******************/
3219
3220 /* (B) */
3221 ull_cp_conn_param_req_reply(&conn);
3222
3223 /*******************/
3224
3225 /* Prepare */
3226 event_prepare(&conn);
3227
3228 /* (B) Tx Queue should have one LL Control PDU */
3229 rsp_B->reference_conn_event_count = req_B->reference_conn_event_count;
3230 lt_rx(LL_CONNECTION_PARAM_RSP, &conn, &tx, rsp_B);
3231 lt_rx_q_is_empty(&conn);
3232
3233 /* (A) Rx */
3234 lt_tx(LL_REJECT_EXT_IND, &conn, &reject_ext_ind);
3235
3236 /* Done */
3237 event_done(&conn);
3238
3239 /* (A) There should be one host notification */
3240 ut_rx_node(NODE_CONN_UPDATE, &ntf, &cu1);
3241 ut_rx_q_is_empty();
3242
3243 /* Release Ntf */
3244 release_ntf(ntf);
3245
3246 {
3247 /* Initiate a parallel local Connection Parameter Request Procedure */
3248 err = ull_cp_conn_update(&conn_2nd, INTVL_MIN, INTVL_MAX, LATENCY, TIMEOUT, NULL);
3249 zassert_equal(err, BT_HCI_ERR_SUCCESS);
3250
3251 /* Prepare */
3252 event_prepare(&conn_2nd);
3253
3254 /* Tx Queue should have no LL Control PDU */
3255 lt_rx_q_is_empty(&conn_2nd);
3256
3257 /* Done */
3258 event_done(&conn_2nd);
3259
3260 /* Prepare */
3261 event_prepare(&conn_2nd);
3262
3263 /* Tx Queue should have no LL Control PDU */
3264 lt_rx_q_is_empty(&conn_2nd);
3265
3266 /* Done */
3267 event_done(&conn_2nd);
3268 }
3269
3270 /* Prepare */
3271 event_prepare(&conn);
3272
3273 /* (B) Rx */
3274 cu_ind_B->instant = instant = event_counter(&conn) + 6;
3275 lt_tx(LL_CONNECTION_UPDATE_IND, &conn, cu_ind_B);
3276
3277 /* Done */
3278 event_done(&conn);
3279
3280 /* Release Tx */
3281 ull_cp_release_tx(&conn, tx);
3282
3283 /* */
3284 while (!is_instant_reached(&conn, instant)) {
3285 /* Prepare */
3286 event_prepare(&conn);
3287
3288 /* (B) Tx Queue should NOT have a LL Control PDU */
3289 lt_rx_q_is_empty(&conn);
3290
3291 /* Done */
3292 event_done(&conn);
3293
3294 /* (B) There should NOT be a host notification */
3295 ut_rx_q_is_empty();
3296 }
3297
3298 /* Prepare */
3299 event_prepare(&conn);
3300
3301 /* (B) Tx Queue should NOT have a LL Control PDU */
3302 lt_rx_q_is_empty(&conn);
3303
3304 /* Done */
3305 event_done(&conn);
3306
3307 /* (B) There should be one host notification */
3308 ut_rx_node(NODE_CONN_UPDATE, &ntf, &cu2);
3309 ut_rx_q_is_empty();
3310
3311 {
3312 /* Now the locally initiated CPR on conn_3rd should be allowed to run */
3313 /* Prepare */
3314 event_prepare(&conn_2nd);
3315
3316 /* Tx Queue should have one LL Control PDU, indicating parallel CPR is now active */
3317 conn_param_req.reference_conn_event_count = event_counter(&conn_2nd);
3318 lt_rx(LL_CONNECTION_PARAM_REQ, &conn_2nd, &tx, &conn_param_req);
3319 lt_rx_q_is_empty(&conn_2nd);
3320
3321 /* Done */
3322 event_done(&conn_2nd);
3323
3324 /* Release Tx */
3325 ull_cp_release_tx(&conn_2nd, tx);
3326 }
3327
3328 /* Release Ntf */
3329 release_ntf(ntf);
3330
3331 /* One less CTXs as the conn_2nd CPR is still 'running' */
3332 zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt()-1,
3333 "Free CTX buffers %d", llcp_ctx_buffers_free());
3334 }
3335
3336 /*
3337 * Central-initiated Connection Parameters Request procedure.
3338 * Central requests change in LE connection parameters, peripheral’s Host accepts.
3339 *
3340 * +-----+ +-------+ +-----+
3341 * | UT | | LL_P | | LT |
3342 * +-----+ +-------+ +-----+
3343 * | | |
3344 * | | LL_CONNECTION_PARAM_REQ |
3345 * | |<--------------------------|
3346 * | | |
3347 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3348 * ~~~~~ parallel remote CPR is attempted and rejected ~~~~~~~
3349 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3350 * | | |
3351 * | LE Remote Connection | |
3352 * | Parameter Request | |
3353 * |<--------------------------| |
3354 * | LE Remote Connection | |
3355 * | Parameter Request | |
3356 * | Reply | |
3357 * |-------------------------->| |
3358 * | | |
3359 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3360 * ~~~~~ parallel local CPR is attempted and cached ~~~~~~~
3361 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3362 * | | |
3363 * | | LL_CONNECTION_PARAM_RSP |
3364 * | |-------------------------->|
3365 * | | |
3366 * | | LL_CONNECTION_UPDATE_IND |
3367 * | |<--------------------------|
3368 * | | |
3369 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3370 * | | |
3371 * | LE Connection Update | |
3372 * | Complete | |
3373 * |<--------------------------| |
3374 * | | |
3375 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3376 * ~~~~~~~~~ parallel local CPR is now started ~~~~~~~~~~~~
3377 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3378 * | | |
3379 */
ZTEST(periph_rem,test_conn_update_periph_rem_accept_reject_2nd_cpr)3380 ZTEST(periph_rem, test_conn_update_periph_rem_accept_reject_2nd_cpr)
3381 {
3382 uint8_t err;
3383 struct ll_conn conn_2nd;
3384 struct ll_conn conn_3rd;
3385 struct node_tx *tx;
3386 struct node_rx_pdu *ntf;
3387 uint16_t instant;
3388 struct pdu_data_llctrl_reject_ext_ind parallel_reject_ext_ind = {
3389 .reject_opcode = PDU_DATA_LLCTRL_TYPE_CONN_PARAM_REQ,
3390 .error_code = BT_HCI_ERR_UNSUPP_LL_PARAM_VAL
3391 };
3392
3393 struct node_rx_pu cu = { .status = BT_HCI_ERR_SUCCESS };
3394
3395 /* Initialize extra connections */
3396 test_setup_idx(&conn_2nd, 1);
3397 test_setup_idx(&conn_3rd, 2);
3398
3399 /* Role */
3400 test_set_role(&conn, BT_HCI_ROLE_PERIPHERAL);
3401 /* Role */
3402 test_set_role(&conn_2nd, BT_HCI_ROLE_PERIPHERAL);
3403 /* Role */
3404 test_set_role(&conn_3rd, BT_HCI_ROLE_CENTRAL);
3405
3406 /* Connect */
3407 ull_cp_state_set(&conn, ULL_CP_CONNECTED);
3408 /* Connect */
3409 ull_cp_state_set(&conn_2nd, ULL_CP_CONNECTED);
3410 /* Connect */
3411 ull_cp_state_set(&conn_3rd, ULL_CP_CONNECTED);
3412
3413 /* Prepare */
3414 event_prepare(&conn);
3415
3416 /* Tx Queue should NOT have a LL Control PDU */
3417 lt_rx_q_is_empty(&conn);
3418
3419 /* Rx */
3420 lt_tx(LL_CONNECTION_PARAM_REQ, &conn, &conn_param_req);
3421
3422 /* Done */
3423 event_done(&conn);
3424
3425 {
3426 /* Parallel CPR from central */
3427 /* Now CPR is active on 'conn' so let 'conn_2nd' attempt to start a CPR */
3428 /* Prepare */
3429 event_prepare(&conn_2nd);
3430
3431 /* Tx Queue should NOT have a LL Control PDU */
3432 lt_rx_q_is_empty(&conn_2nd);
3433
3434 /* Rx */
3435 lt_tx(LL_CONNECTION_PARAM_REQ, &conn_2nd, &conn_param_req);
3436
3437 /* Done */
3438 event_done(&conn_2nd);
3439
3440 /* Tx Queue should have one LL Control PDU */
3441 lt_rx(LL_REJECT_EXT_IND, &conn_2nd, &tx, ¶llel_reject_ext_ind);
3442 lt_rx_q_is_empty(&conn_2nd);
3443
3444 /* Release Tx */
3445 ull_cp_release_tx(&conn_2nd, tx);
3446
3447 /* There should be no 'extra' procedure on acount of the parallel CPR */
3448 zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt()-1,
3449 "Free CTX buffers %d", llcp_ctx_buffers_free());
3450 }
3451
3452 /* Prepare */
3453 event_prepare(&conn);
3454
3455 /* Done */
3456 event_done(&conn);
3457
3458 {
3459 /* Parallel CPR from peripheral */
3460 /* Now CPR is active on 'conn' so let 'conn_3rd' attempt to start a CPR */
3461 /* Prepare */
3462 event_prepare(&conn_3rd);
3463
3464 /* Tx Queue should NOT have a LL Control PDU */
3465 lt_rx_q_is_empty(&conn_3rd);
3466
3467 /* Rx */
3468 lt_tx(LL_CONNECTION_PARAM_REQ, &conn_3rd, &conn_param_req);
3469
3470 /* Done */
3471 event_done(&conn_3rd);
3472
3473 /* Tx Queue should have one LL Control PDU */
3474 lt_rx(LL_REJECT_EXT_IND, &conn_3rd, &tx, ¶llel_reject_ext_ind);
3475 lt_rx_q_is_empty(&conn_3rd);
3476
3477 /* Release Tx */
3478 ull_cp_release_tx(&conn_3rd, tx);
3479
3480 /* There should be no 'extra' procedure on acount of the parallel CPR */
3481 zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt()-1,
3482 "Free CTX buffers %d", llcp_ctx_buffers_free());
3483 }
3484
3485 /* There should be one host notification */
3486 ut_rx_pdu(LL_CONNECTION_PARAM_REQ, &ntf, &conn_param_req);
3487 ut_rx_q_is_empty();
3488
3489 /* Release Ntf */
3490 release_ntf(ntf);
3491
3492 /*******************/
3493
3494 ull_cp_conn_param_req_reply(&conn);
3495
3496 {
3497 /* Initiate a parallel local Connection Parameter Request Procedure */
3498 err = ull_cp_conn_update(&conn_2nd, INTVL_MIN, INTVL_MAX, LATENCY, TIMEOUT, NULL);
3499 zassert_equal(err, BT_HCI_ERR_SUCCESS);
3500
3501 /* Prepare */
3502 event_prepare(&conn_2nd);
3503
3504 /* Tx Queue should have no LL Control PDU */
3505 lt_rx_q_is_empty(&conn_2nd);
3506
3507 /* Done */
3508 event_done(&conn_2nd);
3509
3510 /* Prepare */
3511 event_prepare(&conn_2nd);
3512
3513 /* Tx Queue should have no LL Control PDU */
3514 lt_rx_q_is_empty(&conn_2nd);
3515
3516 /* Done */
3517 event_done(&conn_2nd);
3518 }
3519
3520 /* Prepare */
3521 event_prepare(&conn);
3522
3523 /* Tx Queue should have one LL Control PDU */
3524 lt_rx(LL_CONNECTION_PARAM_RSP, &conn, &tx, &conn_param_rsp);
3525 lt_rx_q_is_empty(&conn);
3526
3527 /* Done */
3528 event_done(&conn);
3529
3530 /* Prepare */
3531 event_prepare(&conn);
3532
3533 /* Rx */
3534 conn_update_ind.instant = event_counter(&conn) + 6U;
3535 instant = conn_update_ind.instant;
3536 lt_tx(LL_CONNECTION_UPDATE_IND, &conn, &conn_update_ind);
3537
3538 /* Done */
3539 event_done(&conn);
3540
3541 /* Release Tx */
3542 ull_cp_release_tx(&conn, tx);
3543
3544 /* */
3545 while (!is_instant_reached(&conn, instant)) {
3546 /* Prepare */
3547 event_prepare(&conn);
3548
3549 /* Tx Queue should NOT have a LL Control PDU */
3550 lt_rx_q_is_empty(&conn);
3551
3552 /* Done */
3553 event_done(&conn);
3554
3555 /* There should NOT be a host notification */
3556 ut_rx_q_is_empty();
3557 }
3558
3559 /* Prepare */
3560 event_prepare(&conn);
3561
3562 /* Tx Queue should NOT have a LL Control PDU */
3563 lt_rx_q_is_empty(&conn);
3564
3565 /* Done */
3566 event_done(&conn);
3567
3568 /* There should be one host notification */
3569 ut_rx_node(NODE_CONN_UPDATE, &ntf, &cu);
3570 ut_rx_q_is_empty();
3571
3572 {
3573 /* Now the locally initiated CPR on conn_3rd should be allowed to run */
3574 /* Prepare */
3575 event_prepare(&conn_2nd);
3576
3577 /* Tx Queue should have one LL Control PDU, indicating parallel CPR is now active */
3578 conn_param_req.reference_conn_event_count = event_counter(&conn_2nd);
3579 lt_rx(LL_CONNECTION_PARAM_REQ, &conn_2nd, &tx, &conn_param_req);
3580 lt_rx_q_is_empty(&conn_2nd);
3581
3582 /* Done */
3583 event_done(&conn_2nd);
3584
3585 /* Release Tx */
3586 ull_cp_release_tx(&conn_2nd, tx);
3587 }
3588
3589 /* Release Ntf */
3590 release_ntf(ntf);
3591
3592 /* One less CTXs as the conn_2nd CPR is still 'running' */
3593 zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt()-1,
3594 "Free CTX buffers %d", llcp_ctx_buffers_free());
3595 }
3596
3597 /*
3598 * Central-initiated Connection Parameters Request procedure.
3599 * Central requests change in LE connection with invalid parameters,
3600 *
3601 * +-----+ +-------+ +-----+
3602 * | UT | | LL_P | | LT |
3603 * +-----+ +-------+ +-----+
3604 * | | |
3605 * | | LL_CONNECTION_PARAM_REQ |
3606 * | |<--------------------------|
3607 * | | |
3608 * | | |
3609 * | | LL_REJECT_EXT_IND |
3610 * | |-------------------------->|
3611 * | | |
3612 * | | |
3613 */
ZTEST(periph_rem,test_conn_update_periph_rem_invalid_req)3614 ZTEST(periph_rem, test_conn_update_periph_rem_invalid_req)
3615 {
3616 struct node_tx *tx;
3617 struct pdu_data_llctrl_reject_ext_ind reject_ext_ind = {
3618 .reject_opcode = PDU_DATA_LLCTRL_TYPE_CONN_PARAM_REQ,
3619 .error_code = BT_HCI_ERR_INVALID_LL_PARAM
3620 };
3621
3622 /* Role */
3623 test_set_role(&conn, BT_HCI_ROLE_PERIPHERAL);
3624
3625 /* Connect */
3626 ull_cp_state_set(&conn, ULL_CP_CONNECTED);
3627
3628 /* Prepare */
3629 event_prepare(&conn);
3630
3631 /* Rx */
3632 lt_tx(LL_CONNECTION_PARAM_REQ, &conn, &conn_param_req_invalid);
3633
3634 /* Done */
3635 event_done(&conn);
3636
3637 /* Prepare */
3638 event_prepare(&conn);
3639
3640 /* Tx Queue should have one LL Control PDU */
3641 lt_rx(LL_REJECT_EXT_IND, &conn, &tx, &reject_ext_ind);
3642 lt_rx_q_is_empty(&conn);
3643
3644 /* Done */
3645 event_done(&conn);
3646
3647 /* Release Tx */
3648 ull_cp_release_tx(&conn, tx);
3649 zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(),
3650 "Free CTX buffers %d", llcp_ctx_buffers_free());
3651
3652 }
3653
3654 /*
3655 * Central-initiated Connection Parameters Request procedure.
3656 * Central requests change in LE connection parameters, peripheral’s Host accepts.
3657 *
3658 * +-----+ +-------+ +-----+
3659 * | UT | | LL_S | | LT |
3660 * +-----+ +-------+ +-----+
3661 * | | |
3662 * | | LL_CONNECTION_PARAM_REQ |
3663 * | |<--------------------------|
3664 * | | |
3665 * | LE Remote Connection | |
3666 * | Parameter Request | |
3667 * |<--------------------------| |
3668 * | LE Remote Connection | |
3669 * | Parameter Request | |
3670 * | Reply | |
3671 * |-------------------------->| |
3672 * | | |
3673 * | | LL_CONNECTION_PARAM_RSP |
3674 * | |-------------------------->|
3675 * | | |
3676 * | | LL_<INVALID_IND> |
3677 * | |<--------------------------|
3678 * | | |
3679 * ~~~~~~~~~~~~~~~~~ TERMINATE CONNECTION ~~~~~~~~~~~~~~~~~~
3680 * | | |
3681 * | | |
3682 */
ZTEST(periph_rem,test_conn_update_periph_rem_invalid_ind)3683 ZTEST(periph_rem, test_conn_update_periph_rem_invalid_ind)
3684 {
3685 struct node_tx *tx;
3686 struct node_rx_pdu *ntf;
3687 struct pdu_data_llctrl_reject_ind reject_ind = {
3688 .error_code = BT_HCI_ERR_LL_PROC_COLLISION
3689 };
3690 struct pdu_data_llctrl_reject_ext_ind reject_ext_ind = {
3691 .reject_opcode = PDU_DATA_LLCTRL_TYPE_CONN_PARAM_RSP,
3692 .error_code = BT_HCI_ERR_LL_PROC_COLLISION
3693 };
3694 struct pdu_data_llctrl_unknown_rsp unknown_rsp = {
3695 .type = PDU_DATA_LLCTRL_TYPE_CONN_PARAM_RSP
3696 };
3697
3698 /* Role */
3699 test_set_role(&conn, BT_HCI_ROLE_PERIPHERAL);
3700
3701 /* Connect */
3702 ull_cp_state_set(&conn, ULL_CP_CONNECTED);
3703
3704 /* Prepare */
3705 event_prepare(&conn);
3706
3707 /* Tx Queue should NOT have a LL Control PDU */
3708 lt_rx_q_is_empty(&conn);
3709
3710 /* Rx */
3711 lt_tx(LL_CONNECTION_PARAM_REQ, &conn, &conn_param_req);
3712
3713 /* Done */
3714 event_done(&conn);
3715
3716 /*******************/
3717
3718 /* There should be one host notification */
3719 ut_rx_pdu(LL_CONNECTION_PARAM_REQ, &ntf, &conn_param_req);
3720 ut_rx_q_is_empty();
3721
3722 /* Release Ntf */
3723 release_ntf(ntf);
3724
3725 /*******************/
3726
3727 ull_cp_conn_param_req_reply(&conn);
3728
3729 /*******************/
3730
3731 /* Prepare */
3732 event_prepare(&conn);
3733
3734 /* Tx Queue should have one LL Control PDU */
3735 lt_rx(LL_CONNECTION_PARAM_RSP, &conn, &tx, &conn_param_rsp);
3736 lt_rx_q_is_empty(&conn);
3737
3738 /* Done */
3739 event_done(&conn);
3740
3741 /* Prepare */
3742 event_prepare(&conn);
3743
3744 /* Rx */
3745 lt_tx(LL_REJECT_IND, &conn, &reject_ind);
3746
3747 /* Done */
3748 event_done(&conn);
3749
3750 /* Release Tx */
3751 ull_cp_release_tx(&conn, tx);
3752
3753 /* Termination 'triggered' */
3754 zassert_equal(conn.llcp_terminate.reason_final, BT_HCI_ERR_LMP_PDU_NOT_ALLOWED,
3755 "Terminate reason %d", conn.llcp_terminate.reason_final);
3756
3757 /* Clear termination flag for subsequent test cycle */
3758 conn.llcp_terminate.reason_final = 0;
3759
3760 /* There should be no host notifications */
3761 ut_rx_q_is_empty();
3762
3763 zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(),
3764 "Free CTX buffers %d", llcp_ctx_buffers_free());
3765
3766 event_prepare(&conn);
3767
3768 /* Tx Queue should NOT have a LL Control PDU */
3769 lt_rx_q_is_empty(&conn);
3770
3771 /* Rx */
3772 lt_tx(LL_CONNECTION_PARAM_REQ, &conn, &conn_param_req);
3773
3774 /* Done */
3775 event_done(&conn);
3776
3777 /*******************/
3778
3779 /* There should be one host notification */
3780 ut_rx_pdu(LL_CONNECTION_PARAM_REQ, &ntf, &conn_param_req);
3781 ut_rx_q_is_empty();
3782
3783 /* Release Ntf */
3784 release_ntf(ntf);
3785
3786 /*******************/
3787
3788 ull_cp_conn_param_req_reply(&conn);
3789
3790 /*******************/
3791
3792 /* Prepare */
3793 event_prepare(&conn);
3794
3795 /* Tx Queue should have one LL Control PDU */
3796 lt_rx(LL_CONNECTION_PARAM_RSP, &conn, &tx, &conn_param_rsp);
3797 lt_rx_q_is_empty(&conn);
3798
3799 /* Done */
3800 event_done(&conn);
3801
3802 /* Prepare */
3803 event_prepare(&conn);
3804
3805 /* Rx */
3806 lt_tx(LL_REJECT_EXT_IND, &conn, &reject_ext_ind);
3807
3808 /* Done */
3809 event_done(&conn);
3810
3811 /* Release Tx */
3812 ull_cp_release_tx(&conn, tx);
3813
3814 /* Termination 'triggered' */
3815 zassert_equal(conn.llcp_terminate.reason_final, BT_HCI_ERR_LMP_PDU_NOT_ALLOWED,
3816 "Terminate reason %d", conn.llcp_terminate.reason_final);
3817
3818 /* Clear termination flag for subsequent test cycle */
3819 conn.llcp_terminate.reason_final = 0;
3820
3821 /* There should be no host notifications */
3822 ut_rx_q_is_empty();
3823
3824 zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(),
3825 "Free CTX buffers %d", llcp_ctx_buffers_free());
3826
3827 /* Prepare */
3828 event_prepare(&conn);
3829
3830 /* Tx Queue should NOT have a LL Control PDU */
3831 lt_rx_q_is_empty(&conn);
3832
3833 /* Rx */
3834 lt_tx(LL_CONNECTION_PARAM_REQ, &conn, &conn_param_req);
3835
3836 /* Done */
3837 event_done(&conn);
3838
3839 /*******************/
3840
3841 /* There should be one host notification */
3842 ut_rx_pdu(LL_CONNECTION_PARAM_REQ, &ntf, &conn_param_req);
3843 ut_rx_q_is_empty();
3844
3845 /* Release Ntf */
3846 release_ntf(ntf);
3847
3848 /*******************/
3849
3850 ull_cp_conn_param_req_reply(&conn);
3851
3852 /*******************/
3853
3854 /* Prepare */
3855 event_prepare(&conn);
3856
3857 /* Tx Queue should have one LL Control PDU */
3858 lt_rx(LL_CONNECTION_PARAM_RSP, &conn, &tx, &conn_param_rsp);
3859 lt_rx_q_is_empty(&conn);
3860
3861 /* Done */
3862 event_done(&conn);
3863
3864 /* Prepare */
3865 event_prepare(&conn);
3866
3867 /* Rx */
3868 lt_tx(LL_UNKNOWN_RSP, &conn, &unknown_rsp);
3869
3870 /* Done */
3871 event_done(&conn);
3872
3873 /* Release Tx */
3874 ull_cp_release_tx(&conn, tx);
3875
3876 /* Termination 'triggered' */
3877 zassert_equal(conn.llcp_terminate.reason_final, BT_HCI_ERR_LMP_PDU_NOT_ALLOWED,
3878 "Terminate reason %d", conn.llcp_terminate.reason_final);
3879
3880 /* There should be no host notifications */
3881 ut_rx_q_is_empty();
3882
3883 zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(),
3884 "Free CTX buffers %d", llcp_ctx_buffers_free());
3885 }
3886
3887 /*
3888 * Central-initiated Connection Parameters Request procedure.
3889 * Central requests change in LE connection parameters, peripheral’s Host rejects.
3890 *
3891 * +-----+ +-------+ +-----+
3892 * | UT | | LL_P | | LT |
3893 * +-----+ +-------+ +-----+
3894 * | | |
3895 * | | LL_CONNECTION_PARAM_REQ |
3896 * | |<--------------------------|
3897 * | | |
3898 * | LE Remote Connection | |
3899 * | Parameter Request | |
3900 * |<--------------------------| |
3901 * | LE Remote Connection | |
3902 * | Parameter Request | |
3903 * | Negative Reply | |
3904 * |-------------------------->| |
3905 * | | |
3906 * | | LL_REJECT_EXT_IND |
3907 * | |-------------------------->|
3908 * | | |
3909 */
ZTEST(periph_rem,test_conn_update_periph_rem_reject)3910 ZTEST(periph_rem, test_conn_update_periph_rem_reject)
3911 {
3912 struct node_tx *tx;
3913 struct node_rx_pdu *ntf;
3914
3915 struct pdu_data_llctrl_reject_ext_ind reject_ext_ind = {
3916 .reject_opcode = PDU_DATA_LLCTRL_TYPE_CONN_PARAM_REQ,
3917 .error_code = BT_HCI_ERR_UNACCEPT_CONN_PARAM
3918 };
3919
3920 /* Role */
3921 test_set_role(&conn, BT_HCI_ROLE_PERIPHERAL);
3922
3923 /* Connect */
3924 ull_cp_state_set(&conn, ULL_CP_CONNECTED);
3925
3926 /* Prepare */
3927 event_prepare(&conn);
3928
3929 /* Tx Queue should NOT have a LL Control PDU */
3930 lt_rx_q_is_empty(&conn);
3931
3932 /* Rx */
3933 lt_tx(LL_CONNECTION_PARAM_REQ, &conn, &conn_param_req);
3934
3935 /* Done */
3936 event_done(&conn);
3937
3938 /*******************/
3939
3940 /* There should be one host notification */
3941 ut_rx_pdu(LL_CONNECTION_PARAM_REQ, &ntf, &conn_param_req);
3942 ut_rx_q_is_empty();
3943
3944 /* Release Ntf */
3945 release_ntf(ntf);
3946
3947 /*******************/
3948
3949 ull_cp_conn_param_req_neg_reply(&conn, BT_HCI_ERR_UNACCEPT_CONN_PARAM);
3950
3951 /*******************/
3952
3953 /* Prepare */
3954 event_prepare(&conn);
3955
3956 /* Tx Queue should have one LL Control PDU */
3957 lt_rx(LL_REJECT_EXT_IND, &conn, &tx, &reject_ext_ind);
3958 lt_rx_q_is_empty(&conn);
3959
3960 /* Done */
3961 event_done(&conn);
3962
3963 zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(),
3964 "Free CTX buffers %d", llcp_ctx_buffers_free());
3965 }
3966
3967 /*
3968 * (A)
3969 * Central-initiated Connection Parameters Request procedure.
3970 * Central requests change in LE connection parameters, peripheral’s Host accepts.
3971 *
3972 * and
3973 *
3974 * (B)
3975 * Peripheral-initiated Connection Parameters Request procedure.
3976 * Peripheral requests change in LE connection parameters, central’s Host accepts.
3977 *
3978 * NOTE:
3979 * Peripheral-initiated Connection Parameters Request procedure is paused.
3980 * Central-initiated Connection Parameters Request procedure is finished.
3981 * Peripheral-initiated Connection Parameters Request procedure is resumed.
3982 *
3983 * +-----+ +-------+ +-----+
3984 * | UT | | LL_P | | LT |
3985 * +-----+ +-------+ +-----+
3986 * | | |
3987 * | | LL_CONNECTION_PARAM_REQ |
3988 * | |<--------------------------| (A)
3989 * | | |
3990 * | LE Connection Update | |
3991 * |-------------------------->| | (B)
3992 * | | |
3993 * | <------------------------> |
3994 * | < LOCAL PROCEDURE PAUSED > |
3995 * | <------------------------> |
3996 * | | |
3997 * | LE Remote Connection | |
3998 * | Parameter Request | |
3999 * |<--------------------------| | (A)
4000 * | LE Remote Connection | |
4001 * | Parameter Request | |
4002 * | Reply | |
4003 * |-------------------------->| | (A)
4004 * | | |
4005 * | | LL_CONNECTION_PARAM_RSP |
4006 * | |-------------------------->| (A)
4007 * | | |
4008 * | | LL_CONNECTION_UPDATE_IND |
4009 * | |<--------------------------| (A)
4010 * | | |
4011 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4012 * | | |
4013 * | LE Connection Update | |
4014 * | Complete | |
4015 * |<--------------------------| | (A)
4016 * | | |
4017 * | <-------------------------> |
4018 * | < LOCAL PROCEDURE RESUMED > |
4019 * | <-------------------------> |
4020 * | | |
4021 * | | LL_CONNECTION_PARAM_REQ |
4022 * | |-------------------------->| (B)
4023 * | | |
4024 * | | LL_CONNECTION_UPDATE_IND |
4025 * | |<--------------------------| (B)
4026 * | | |
4027 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4028 * | | |
4029 * | LE Connection Update | |
4030 * | Complete | |
4031 * |<--------------------------| | (B)
4032 * | | |
4033 */
ZTEST(periph_rem,test_conn_update_periph_rem_collision)4034 ZTEST(periph_rem, test_conn_update_periph_rem_collision)
4035 {
4036 uint8_t err;
4037 struct node_tx *tx;
4038 struct node_rx_pdu *ntf;
4039 uint16_t instant;
4040
4041 struct node_rx_pu cu = { .status = BT_HCI_ERR_SUCCESS };
4042
4043 /* Role */
4044 test_set_role(&conn, BT_HCI_ROLE_PERIPHERAL);
4045
4046 /* Connect */
4047 ull_cp_state_set(&conn, ULL_CP_CONNECTED);
4048
4049 /*******************/
4050
4051 /* Prepare */
4052 event_prepare(&conn);
4053
4054 /* (A) Rx */
4055 lt_tx(LL_CONNECTION_PARAM_REQ, &conn, &conn_param_req);
4056
4057 /* Done */
4058 event_done(&conn);
4059
4060 /*******************/
4061
4062 /* (B) Initiate a Connection Parameter Request Procedure */
4063 err = ull_cp_conn_update(&conn, req_B->interval_min, req_B->interval_max, req_B->latency,
4064 req_B->timeout, NULL);
4065 zassert_equal(err, BT_HCI_ERR_SUCCESS);
4066
4067 /*******************/
4068
4069 /* Prepare */
4070 event_prepare(&conn);
4071
4072 /* (B) Tx Queue should NOT have a LL Control PDU */
4073 lt_rx_q_is_empty(&conn);
4074
4075 /* Done */
4076 event_done(&conn);
4077
4078 /*******************/
4079 /* (A) There should be one host notification */
4080 ut_rx_pdu(LL_CONNECTION_PARAM_REQ, &ntf, &conn_param_req);
4081 ut_rx_q_is_empty();
4082
4083 /* Release Ntf */
4084 release_ntf(ntf);
4085
4086 /*******************/
4087
4088 /* (A) */
4089 ull_cp_conn_param_req_reply(&conn);
4090
4091 /*******************/
4092
4093 /* Prepare */
4094 event_prepare(&conn);
4095 conn_param_rsp.reference_conn_event_count = conn_param_req.reference_conn_event_count;
4096
4097 /* (A) Tx Queue should have one LL Control PDU */
4098 lt_rx(LL_CONNECTION_PARAM_RSP, &conn, &tx, &conn_param_rsp);
4099 lt_rx_q_is_empty(&conn);
4100
4101 /* Done */
4102 event_done(&conn);
4103
4104 /* Prepare */
4105 event_prepare(&conn);
4106
4107 /* (A) Rx */
4108 conn_update_ind.instant = event_counter(&conn) + 6U;
4109 instant = conn_update_ind.instant;
4110 lt_tx(LL_CONNECTION_UPDATE_IND, &conn, &conn_update_ind);
4111
4112 /* Done */
4113 event_done(&conn);
4114
4115 /* Release Tx */
4116 ull_cp_release_tx(&conn, tx);
4117
4118 /* */
4119 while (!is_instant_reached(&conn, instant)) {
4120 /* Prepare */
4121 event_prepare(&conn);
4122
4123 /* (A) Tx Queue should NOT have a LL Control PDU */
4124 lt_rx_q_is_empty(&conn);
4125
4126 /* Done */
4127 event_done(&conn);
4128
4129 /* (A) There should NOT be a host notification */
4130 ut_rx_q_is_empty();
4131 }
4132
4133 /* Prepare */
4134 event_prepare(&conn);
4135
4136 /* (B) Tx Queue should have one LL Control PDU */
4137 req_B->reference_conn_event_count = event_counter(&conn) - 1;
4138 lt_rx(LL_CONNECTION_PARAM_REQ, &conn, &tx, req_B);
4139 lt_rx_q_is_empty(&conn);
4140
4141 /* Done */
4142 event_done(&conn);
4143
4144 /* (A) There should be one host notification */
4145 ut_rx_node(NODE_CONN_UPDATE, &ntf, &cu);
4146 ut_rx_q_is_empty();
4147
4148 /* Release Ntf */
4149 release_ntf(ntf);
4150
4151 /* Prepare */
4152 event_prepare(&conn);
4153
4154 /* (B) Tx Queue should NOT have a LL Control PDU */
4155 lt_rx_q_is_empty(&conn);
4156
4157 /* (B) Rx */
4158 cu_ind_B->instant = instant = event_counter(&conn) + 6;
4159 lt_tx(LL_CONNECTION_UPDATE_IND, &conn, cu_ind_B);
4160
4161 /* Done */
4162 event_done(&conn);
4163
4164 /* */
4165 while (!is_instant_reached(&conn, instant)) {
4166 /* Prepare */
4167 event_prepare(&conn);
4168
4169 /* (B) Tx Queue should NOT have a LL Control PDU */
4170 lt_rx_q_is_empty(&conn);
4171
4172 /* Done */
4173 event_done(&conn);
4174
4175 /* (B) There should NOT be a host notification */
4176 ut_rx_q_is_empty();
4177 }
4178
4179 /* Prepare */
4180 event_prepare(&conn);
4181
4182 /* (B) Tx Queue should NOT have a LL Control PDU */
4183 lt_rx_q_is_empty(&conn);
4184
4185 /* Done */
4186 event_done(&conn);
4187
4188 /* (B) There should be one host notification */
4189 ut_rx_node(NODE_CONN_UPDATE, &ntf, &cu);
4190 ut_rx_q_is_empty();
4191
4192 /* Release Ntf */
4193 release_ntf(ntf);
4194 zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(),
4195 "Free CTX buffers %d", llcp_ctx_buffers_free());
4196 }
4197
4198 /*
4199 * (A)
4200 * Central-initiated Connection Parameters Request procedure.
4201 * Central requests change in LE connection parameters, peripheral’s Host accepts.
4202 *
4203 * and
4204 *
4205 * (B)
4206 * Peripheral-initiated Connection Parameters Request procedure.
4207 * Peripheral requests change in LE connection parameters, central’s Host accepts.
4208 *
4209 * NOTE:
4210 * Peripheral-initiated Connection Parameters Request procedure is paused.
4211 * Central-initiated Connection Parameters Request procedure is finished.
4212 * Peripheral-initiated Connection Parameters Request procedure is resumed.
4213 *
4214 * +-----+ +-------+ +-----+
4215 * | UT | | LL_P | | LT |
4216 * +-----+ +-------+ +-----+
4217 * | | |
4218 * | LE Connection Update | |
4219 * |-------------------------->| | (B)
4220 * | | LL_CONNECTION_PARAM_REQ |
4221 * | |<--------------------------| (A)
4222 * | | LL_CONNECTION_PARAM_REQ |
4223 * | |-------------------------->| (B)
4224 * | | |
4225 * | | |
4226 * | | |
4227 * | LE Remote Connection | |
4228 * | Parameter Request | |
4229 * |<--------------------------| | (A)
4230 * | LE Remote Connection | |
4231 * | Parameter Request | |
4232 * | Reply | |
4233 * |-------------------------->| | (A)
4234 * | | LL_REJECT_EXT_IND |
4235 * | |<--------------------------| (B)
4236 * | | |
4237 * | LE Connection Update | |
4238 * | Complete (collision) | |
4239 * |<--------------------------| | (B)
4240 * | | LL_CONNECTION_PARAM_RSP |
4241 * | |-------------------------->| (A)
4242 * | | |
4243 * | LE Connection Update | |
4244 * |-------------------------->| | (B)
4245 * | | |
4246 * | <------------------------> |
4247 * | < LOCAL PROCEDURE PAUSED > |
4248 * | <------------------------> |
4249 * | | |
4250 * | | LL_CONNECTION_UPDATE_IND |
4251 * | |<--------------------------| (A)
4252 * | | |
4253 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4254 * | | |
4255 * | LE Connection Update | |
4256 * | Complete | |
4257 * |<--------------------------| | (A)
4258 * | | |
4259 * | <-------------------------> |
4260 * | < LOCAL PROCEDURE RESUMED > |
4261 * | <-------------------------> |
4262 * | | |
4263 * | | LL_CONNECTION_PARAM_REQ |
4264 * | |-------------------------->| (B)
4265 * | | |
4266 * | | LL_CONNECTION_UPDATE_IND |
4267 * | |<--------------------------| (B)
4268 * | | |
4269 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4270 * | | |
4271 * | LE Connection Update | |
4272 * | Complete | |
4273 * |<--------------------------| | (B)
4274 * | | |
4275 */
ZTEST(periph_rem,test_conn_update_periph_rem_late_collision)4276 ZTEST(periph_rem, test_conn_update_periph_rem_late_collision)
4277 {
4278 uint8_t err;
4279 struct node_tx *tx;
4280 struct node_rx_pdu *ntf;
4281 uint16_t instant;
4282 struct pdu_data_llctrl_reject_ext_ind reject_ext_ind = {
4283 .reject_opcode = PDU_DATA_LLCTRL_TYPE_CONN_PARAM_REQ,
4284 .error_code = BT_HCI_ERR_LL_PROC_COLLISION
4285 };
4286 struct node_rx_pu cu1 = { .status = BT_HCI_ERR_LL_PROC_COLLISION };
4287 struct node_rx_pu cu = { .status = BT_HCI_ERR_SUCCESS };
4288
4289 /* Role */
4290 test_set_role(&conn, BT_HCI_ROLE_PERIPHERAL);
4291
4292 /* Connect */
4293 ull_cp_state_set(&conn, ULL_CP_CONNECTED);
4294
4295 /*******************/
4296
4297 /* (B) Initiate a Connection Parameter Request Procedure */
4298 err = ull_cp_conn_update(&conn, req_B->interval_min, req_B->interval_max, req_B->latency,
4299 req_B->timeout, NULL);
4300 zassert_equal(err, BT_HCI_ERR_SUCCESS);
4301
4302 /* Prepare */
4303 event_prepare(&conn);
4304
4305 /*******************/
4306
4307 /* (A) Rx */
4308 lt_tx(LL_CONNECTION_PARAM_REQ, &conn, &conn_param_req);
4309
4310 /* Done */
4311 event_done(&conn);
4312
4313 /*******************/
4314
4315 /* Prepare */
4316 event_prepare(&conn);
4317
4318 /* (B) Tx Queue should have one LL Control PDU */
4319 req_B->reference_conn_event_count = event_counter(&conn) - 1;
4320 lt_rx(LL_CONNECTION_PARAM_REQ, &conn, &tx, req_B);
4321 lt_rx_q_is_empty(&conn);
4322
4323 /* Done */
4324 event_done(&conn);
4325
4326 /*******************/
4327 /* (A) There should be one host notification */
4328 ut_rx_pdu(LL_CONNECTION_PARAM_REQ, &ntf, &conn_param_req);
4329 ut_rx_q_is_empty();
4330
4331 /* Release Ntf */
4332 release_ntf(ntf);
4333
4334 /*******************/
4335 /* Rx */
4336 lt_tx(LL_REJECT_EXT_IND, &conn, &reject_ext_ind);
4337
4338 /* (A) */
4339 ull_cp_conn_param_req_reply(&conn);
4340
4341 /*******************/
4342
4343 /* Prepare */
4344 event_prepare(&conn);
4345 conn_param_rsp.reference_conn_event_count = conn_param_req.reference_conn_event_count;
4346
4347 /* (A) Tx Queue should have one LL Control PDU */
4348 lt_rx(LL_CONNECTION_PARAM_RSP, &conn, &tx, &conn_param_rsp);
4349 lt_rx_q_is_empty(&conn);
4350
4351 /* Done */
4352 event_done(&conn);
4353
4354 /* (A) There should be one host notification */
4355 ut_rx_node(NODE_CONN_UPDATE, &ntf, &cu1);
4356 ut_rx_q_is_empty();
4357
4358 /* Release Ntf */
4359 release_ntf(ntf);
4360
4361 /* (B) Initiate a Connection Parameter Request Procedure */
4362 err = ull_cp_conn_update(&conn, req_B->interval_min, req_B->interval_max, req_B->latency,
4363 req_B->timeout, NULL);
4364
4365 /* Prepare */
4366 event_prepare(&conn);
4367 /* Done */
4368 event_done(&conn);
4369
4370
4371 /* (A) Rx */
4372 conn_update_ind.instant = event_counter(&conn) + 6U;
4373 instant = conn_update_ind.instant;
4374 lt_tx(LL_CONNECTION_UPDATE_IND, &conn, &conn_update_ind);
4375 /* Prepare */
4376 event_prepare(&conn);
4377
4378 /* Done */
4379 event_done(&conn);
4380
4381 /* Release Tx */
4382 ull_cp_release_tx(&conn, tx);
4383
4384 /* */
4385 while (!is_instant_reached(&conn, instant)) {
4386 /* Prepare */
4387 event_prepare(&conn);
4388
4389 /* (A) Tx Queue should NOT have a LL Control PDU */
4390 lt_rx_q_is_empty(&conn);
4391
4392 /* Done */
4393 event_done(&conn);
4394
4395 /* (A) There should NOT be a host notification */
4396 ut_rx_q_is_empty();
4397 }
4398
4399 /* Prepare */
4400 event_prepare(&conn);
4401
4402 /* (B) Tx Queue should have one LL Control PDU */
4403 req_B->reference_conn_event_count = event_counter(&conn) - 1;
4404 lt_rx(LL_CONNECTION_PARAM_REQ, &conn, &tx, req_B);
4405 lt_rx_q_is_empty(&conn);
4406
4407 /* Done */
4408 event_done(&conn);
4409
4410 /* (A) There should be one host notification */
4411 ut_rx_node(NODE_CONN_UPDATE, &ntf, &cu);
4412 ut_rx_q_is_empty();
4413
4414 /* Release Ntf */
4415 release_ntf(ntf);
4416
4417 /* Prepare */
4418 event_prepare(&conn);
4419
4420 /* (B) Tx Queue should NOT have a LL Control PDU */
4421 lt_rx_q_is_empty(&conn);
4422
4423 /* (B) Rx */
4424 cu_ind_B->instant = instant = event_counter(&conn) + 6;
4425 lt_tx(LL_CONNECTION_UPDATE_IND, &conn, cu_ind_B);
4426
4427 /* Done */
4428 event_done(&conn);
4429
4430 /* */
4431 while (!is_instant_reached(&conn, instant)) {
4432 /* Prepare */
4433 event_prepare(&conn);
4434
4435 /* (B) Tx Queue should NOT have a LL Control PDU */
4436 lt_rx_q_is_empty(&conn);
4437
4438 /* Done */
4439 event_done(&conn);
4440
4441 /* (B) There should NOT be a host notification */
4442 ut_rx_q_is_empty();
4443 }
4444
4445 /* Prepare */
4446 event_prepare(&conn);
4447
4448 /* (B) Tx Queue should NOT have a LL Control PDU */
4449 lt_rx_q_is_empty(&conn);
4450
4451 /* Done */
4452 event_done(&conn);
4453
4454 /* (B) There should be one host notification */
4455 ut_rx_node(NODE_CONN_UPDATE, &ntf, &cu);
4456 ut_rx_q_is_empty();
4457
4458 /* Release Ntf */
4459 release_ntf(ntf);
4460 zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(),
4461 "Free CTX buffers %d", llcp_ctx_buffers_free());
4462 }
4463 #else /* CONFIG_BT_CTLR_CONN_PARAM_REQ */
4464
4465 /*
4466 * Parameter Request Procedure not supported.
4467 * Central-initiated Connection Update procedure.
4468 * Central requests update of LE connection.
4469 *
4470 * +-----+ +-------+ +-----+
4471 * | UT | | LL_C | | LT |
4472 * +-----+ +-------+ +-----+
4473 * | | |
4474 * | LE Connection Update | |
4475 * |-------------------------->| |
4476 * | | LL_CONNECTION_UPDATE_IND |
4477 * | |-------------------------->|
4478 * | | |
4479 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4480 * | | |
4481 * | LE Connection Update | |
4482 * | Complete | |
4483 * |<--------------------------| |
4484 * | | |
4485 * | (If conn. parameters are | |
4486 * | unchanged, host should | |
4487 * | not receive a ntf.) | |
4488 * | | |
4489 */
ZTEST(central_loc_no_param_req,test_conn_update_central_loc_accept_no_param_req)4490 ZTEST(central_loc_no_param_req, test_conn_update_central_loc_accept_no_param_req)
4491 {
4492 uint8_t err;
4493 struct node_tx *tx;
4494 struct node_rx_pdu *ntf;
4495 struct pdu_data *pdu;
4496 uint16_t instant;
4497
4498 /* Test with and without parameter change */
4499 uint8_t parameters_changed = 1U;
4500
4501 struct node_rx_pu cu = { .status = BT_HCI_ERR_SUCCESS };
4502
4503 /* Role */
4504 test_set_role(&conn, BT_HCI_ROLE_CENTRAL);
4505
4506 /* Connect */
4507 ull_cp_state_set(&conn, ULL_CP_CONNECTED);
4508
4509 do {
4510 /* Initiate a Connection Update Procedure */
4511 err = ull_cp_conn_update(&conn, INTVL_MIN, INTVL_MAX, LATENCY, TIMEOUT, NULL);
4512 zassert_equal(err, BT_HCI_ERR_SUCCESS);
4513
4514 /* Prepare */
4515 event_prepare(&conn);
4516
4517 /* Tx Queue should have one LL Control PDU */
4518 conn_update_ind.instant = event_counter(&conn) + 6U;
4519 lt_rx(LL_CONNECTION_UPDATE_IND, &conn, &tx, &conn_update_ind);
4520 lt_rx_q_is_empty(&conn);
4521
4522 /* Done */
4523 event_done(&conn);
4524
4525 /* Release Tx */
4526 ull_cp_release_tx(&conn, tx);
4527
4528 /* Save Instant */
4529 pdu = (struct pdu_data *)tx->pdu;
4530 instant = sys_le16_to_cpu(pdu->llctrl.conn_update_ind.instant);
4531
4532 /* */
4533 while (!is_instant_reached(&conn, instant)) {
4534 /* Prepare */
4535 event_prepare(&conn);
4536
4537 /* Tx Queue should NOT have a LL Control PDU */
4538 lt_rx_q_is_empty(&conn);
4539
4540 /* Done */
4541 event_done(&conn);
4542
4543 /* There should NOT be a host notification */
4544 ut_rx_q_is_empty();
4545 }
4546
4547 /* Prepare */
4548 event_prepare(&conn);
4549
4550 /* Tx Queue should NOT have a LL Control PDU */
4551 lt_rx_q_is_empty(&conn);
4552
4553 /* Done */
4554 event_done(&conn);
4555
4556 if (parameters_changed == 0U) {
4557 /* There should NOT be a host notification */
4558 ut_rx_q_is_empty();
4559 } else {
4560 /* There should be one host notification */
4561 ut_rx_node(NODE_CONN_UPDATE, &ntf, &cu);
4562 ut_rx_q_is_empty();
4563
4564 /* Release Ntf */
4565 release_ntf(ntf);
4566 }
4567 } while (parameters_changed-- > 0U);
4568
4569 zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(),
4570 "Free CTX buffers %d", llcp_ctx_buffers_free());
4571 }
4572
4573 /*
4574 * Parameter Request Procedure not supported.
4575 * Peripheral-initiated Connection Update/Connection Parameter Request procedure
4576 * Central receives Connection Update parameters.
4577 *
4578 * +-----+ +-------+ +-----+
4579 * | UT | | LL_C | | LT |
4580 * +-----+ +-------+ +-----+
4581 * | | |
4582 * | | LL_CONNECTION_UPDATE_IND |
4583 * | |<--------------------------|
4584 * | | |
4585 * | | LL_UNKNOWN_RSP |
4586 * | |-------------------------->|
4587 * | | |
4588 * | | |
4589 * | | LL_CONNECTION_PARAM_REQ |
4590 * | |<--------------------------|
4591 * | | |
4592 * | | LL_UNKNOWN_RSP |
4593 * | |-------------------------->|
4594 * | | |
4595 * | | |
4596 */
ZTEST(central_rem_no_param_req,test_conn_update_central_rem_unknown_no_param_req)4597 ZTEST(central_rem_no_param_req, test_conn_update_central_rem_unknown_no_param_req)
4598 {
4599 struct node_tx *tx;
4600
4601 struct pdu_data_llctrl_unknown_rsp unknown_rsp = {
4602 .type = PDU_DATA_LLCTRL_TYPE_CONN_UPDATE_IND
4603 };
4604
4605 /* Role */
4606 test_set_role(&conn, BT_HCI_ROLE_CENTRAL);
4607
4608 /* Connect */
4609 ull_cp_state_set(&conn, ULL_CP_CONNECTED);
4610
4611 /* Prepare */
4612 event_prepare(&conn);
4613
4614 /* Rx */
4615 lt_tx(LL_CONNECTION_UPDATE_IND, &conn, &conn_update_ind);
4616
4617 /* Done */
4618 event_done(&conn);
4619
4620 /* Prepare */
4621 event_prepare(&conn);
4622
4623 /* Tx Queue should have one LL Control PDU */
4624 lt_rx(LL_UNKNOWN_RSP, &conn, &tx, &unknown_rsp);
4625 lt_rx_q_is_empty(&conn);
4626
4627 /* Done */
4628 event_done(&conn);
4629
4630 /* There should NOT be a host notification */
4631 ut_rx_q_is_empty();
4632
4633 zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(),
4634 "Free CTX buffers %d", llcp_ctx_buffers_free());
4635
4636 /* Check UNKNOWN_RSP on Connection Parameter Request */
4637 unknown_rsp.type = PDU_DATA_LLCTRL_TYPE_CONN_PARAM_REQ;
4638 /* Prepare */
4639 event_prepare(&conn);
4640
4641 /* Rx */
4642 lt_tx(LL_CONNECTION_PARAM_REQ, &conn, &conn_param_req);
4643
4644 /* Done */
4645 event_done(&conn);
4646
4647 /* Prepare */
4648 event_prepare(&conn);
4649
4650 /* Tx Queue should have one LL Control PDU */
4651 lt_rx(LL_UNKNOWN_RSP, &conn, &tx, &unknown_rsp);
4652 lt_rx_q_is_empty(&conn);
4653
4654 /* Done */
4655 event_done(&conn);
4656
4657 /* There should NOT be a host notification */
4658 ut_rx_q_is_empty();
4659
4660 zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(),
4661 "Free CTX buffers %d", llcp_ctx_buffers_free());
4662
4663 }
4664
4665 /*
4666 * Parameter Request Procedure not supported.
4667 * Peripheral-initiated Connection Update/Connection Parameter Request procedure
4668 * Central receives Connection Update parameters.
4669 *
4670 * +-----+ +-------+ +-----+
4671 * | UT | | LL_M | | LT |
4672 * +-----+ +-------+ +-----+
4673 * | | |
4674 * | | |
4675 * | | LL_CONNECTION_PARAM_REQ |
4676 * | |<--------------------------|
4677 * | | |
4678 * | | LL_UNKNOWN_RSP |
4679 * | |-------------------------->|
4680 * | | |
4681 * | | |
4682 */
ZTEST(periph_rem_no_param_req,test_conn_update_periph_rem_unknown_no_param_req)4683 ZTEST(periph_rem_no_param_req, test_conn_update_periph_rem_unknown_no_param_req)
4684 {
4685 struct node_tx *tx;
4686
4687 struct pdu_data_llctrl_unknown_rsp unknown_rsp = {
4688 .type = PDU_DATA_LLCTRL_TYPE_CONN_PARAM_REQ
4689 };
4690
4691 /* Role */
4692 test_set_role(&conn, BT_HCI_ROLE_PERIPHERAL);
4693
4694 /* Connect */
4695 ull_cp_state_set(&conn, ULL_CP_CONNECTED);
4696
4697 /* Prepare */
4698 event_prepare(&conn);
4699
4700 /* Rx */
4701 lt_tx(LL_CONNECTION_PARAM_REQ, &conn, &conn_param_req);
4702
4703 /* Done */
4704 event_done(&conn);
4705
4706 /* Prepare */
4707 event_prepare(&conn);
4708
4709 /* Tx Queue should have one LL Control PDU */
4710 lt_rx(LL_UNKNOWN_RSP, &conn, &tx, &unknown_rsp);
4711 lt_rx_q_is_empty(&conn);
4712
4713 /* Done */
4714 event_done(&conn);
4715
4716 /* There should NOT be a host notification */
4717 ut_rx_q_is_empty();
4718
4719 zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(),
4720 "Free CTX buffers %d", llcp_ctx_buffers_free());
4721
4722 }
4723
4724 /*
4725 * Parameter Request Procedure not supported.
4726 * Central-initiated Connection Update procedure.
4727 * Peripheral receives Connection Update parameters.
4728 *
4729 * +-----+ +-------+ +-----+
4730 * | UT | | LL_P | | LT |
4731 * +-----+ +-------+ +-----+
4732 * | | |
4733 * | | LL_CONNECTION_UPDATE_IND |
4734 * | |<--------------------------|
4735 * | | |
4736 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4737 * | | |
4738 * | LE Connection Update | |
4739 * | Complete | |
4740 * |<--------------------------| |
4741 * | | |
4742 * | (If conn. parameters are | |
4743 * | unchanged, host should | |
4744 * | not receive a ntf.) | |
4745 * | | |
4746 */
ZTEST(periph_rem_no_param_req,test_conn_update_periph_rem_accept_no_param_req)4747 ZTEST(periph_rem_no_param_req, test_conn_update_periph_rem_accept_no_param_req)
4748 {
4749 struct node_rx_pdu *ntf;
4750 uint16_t instant;
4751
4752 /* Test with and without parameter change */
4753 uint8_t parameters_changed = 1U;
4754
4755 struct node_rx_pu cu = { .status = BT_HCI_ERR_SUCCESS };
4756
4757 /* Role */
4758 test_set_role(&conn, BT_HCI_ROLE_PERIPHERAL);
4759
4760 /* Connect */
4761 ull_cp_state_set(&conn, ULL_CP_CONNECTED);
4762
4763 do {
4764 /* Prepare */
4765 event_prepare(&conn);
4766
4767 /* Rx */
4768 conn_update_ind.instant = event_counter(&conn) + 6U;
4769 instant = conn_update_ind.instant;
4770 lt_tx(LL_CONNECTION_UPDATE_IND, &conn, &conn_update_ind);
4771
4772 /* Done */
4773 event_done(&conn);
4774
4775 /* */
4776 while (!is_instant_reached(&conn, instant)) {
4777 /* Prepare */
4778 event_prepare(&conn);
4779
4780 /* Tx Queue should NOT have a LL Control PDU */
4781 lt_rx_q_is_empty(&conn);
4782
4783 /* Done */
4784 event_done(&conn);
4785
4786 /* There should NOT be a host notification */
4787 ut_rx_q_is_empty();
4788 }
4789
4790 /* Prepare */
4791 event_prepare(&conn);
4792
4793 /* Tx Queue should NOT have a LL Control PDU */
4794 lt_rx_q_is_empty(&conn);
4795
4796 /* Done */
4797 event_done(&conn);
4798
4799 if (parameters_changed == 0U) {
4800 /* There should NOT be a host notification */
4801 ut_rx_q_is_empty();
4802 } else {
4803 /* There should be one host notification */
4804 ut_rx_node(NODE_CONN_UPDATE, &ntf, &cu);
4805 ut_rx_q_is_empty();
4806
4807 /* Release Ntf */
4808 release_ntf(ntf);
4809 }
4810 } while (parameters_changed-- > 0U);
4811
4812 zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(),
4813 "Free CTX buffers %d", llcp_ctx_buffers_free());
4814 }
4815
4816 /*
4817 * Parameter Request Procedure not supported.
4818 * Peripheral-initiated Connection Update procedure (not allowed).
4819 *
4820 * +-----+ +-------+ +-----+
4821 * | UT | | LL_P | | LT |
4822 * +-----+ +-------+ +-----+
4823 * | | |
4824 * | LE Connection Update | |
4825 * |-------------------------->| |
4826 * | | |
4827 * | ERR CMD Disallowed | |
4828 * |<--------------------------| |
4829 * | | |
4830 */
ZTEST(periph_loc_no_param_req,test_conn_update_periph_loc_disallowed_no_param_req)4831 ZTEST(periph_loc_no_param_req, test_conn_update_periph_loc_disallowed_no_param_req)
4832 {
4833 uint8_t err;
4834
4835 /* Role */
4836 test_set_role(&conn, BT_HCI_ROLE_PERIPHERAL);
4837
4838 /* Connect */
4839 ull_cp_state_set(&conn, ULL_CP_CONNECTED);
4840
4841 /* Initiate a Connection Update Procedure */
4842 err = ull_cp_conn_update(&conn, INTVL_MIN, INTVL_MAX, LATENCY, TIMEOUT, NULL);
4843 zassert_equal(err, BT_HCI_ERR_CMD_DISALLOWED);
4844
4845 /* Prepare */
4846 event_prepare(&conn);
4847
4848 /* Tx Queue should have no LL Control PDU */
4849 lt_rx_q_is_empty(&conn);
4850
4851 /* Done */
4852 event_done(&conn);
4853
4854 /* There should be no host notification */
4855 ut_rx_q_is_empty();
4856
4857 zassert_equal(llcp_ctx_buffers_free(), test_ctx_buffers_cnt(),
4858 "Free CTX buffers %d", llcp_ctx_buffers_free());
4859 }
4860 #endif
4861
4862 /*
4863 * Central-initiated Connection Update procedure.
4864 * Peripheral receives invalid Connection Update parameters.
4865 *
4866 * +-----+ +-------+ +-----+
4867 * | UT | | LL_P | | LT |
4868 * +-----+ +-------+ +-----+
4869 * | | |
4870 * | | LL_CONNECTION_UPDATE_IND |
4871 * | |<--------------------------|
4872 * | | |
4873 * ~~~~~~~~~~~~~~~~~~ TERMINATE CONNECTION ~~~~~~~~~~~~~~~~~
4874 * | | |
4875 */
ZTEST(periph_rem_invalid,test_conn_update_periph_rem_invalid_param)4876 ZTEST(periph_rem_invalid, test_conn_update_periph_rem_invalid_param)
4877 {
4878 uint16_t interval;
4879
4880 /* Role */
4881 test_set_role(&conn, BT_HCI_ROLE_PERIPHERAL);
4882
4883 /* Connect */
4884 ull_cp_state_set(&conn, ULL_CP_CONNECTED);
4885
4886 /* Prepare */
4887 event_prepare(&conn);
4888
4889 /* Rx */
4890 interval = conn_update_ind.interval;
4891 conn_update_ind.interval = 0U;
4892 conn_update_ind.instant = event_counter(&conn) + 6U;
4893 lt_tx(LL_CONNECTION_UPDATE_IND, &conn, &conn_update_ind);
4894
4895 /* Done */
4896 event_done(&conn);
4897
4898 /* Termination 'triggered' */
4899 zassert_equal(conn.llcp_terminate.reason_final, BT_HCI_ERR_INVALID_LL_PARAM,
4900 "Terminate reason %d", conn.llcp_terminate.reason_final);
4901
4902 /* Clear termination flag for subsequent test cycle */
4903 conn.llcp_terminate.reason_final = 0;
4904
4905 /* Restore interval for other tests */
4906 conn_update_ind.interval = interval;
4907 }
4908
4909 #if defined(CONFIG_BT_CTLR_CONN_PARAM_REQ)
4910 /*
4911 * Peripheral-initiated Connection Parameters Request procedure.
4912 * Peripheral requests change in LE connection parameters, central’s Host accepts.
4913 * Peripheral receives invalid Connection Update parameters.
4914 *
4915 * +-----+ +-------+ +-----+
4916 * | UT | | LL_P | | LT |
4917 * +-----+ +-------+ +-----+
4918 * | | |
4919 * | LE Connection Update | |
4920 * |-------------------------->| |
4921 * | | LL_CONNECTION_PARAM_REQ |
4922 * | |-------------------------->|
4923 * | | |
4924 * | | LL_CONNECTION_UPDATE_IND |
4925 * | |<--------------------------|
4926 * | | |
4927 * ~~~~~~~~~~~~~~~~~~ TERMINATE CONNECTION ~~~~~~~~~~~~~~~~~
4928 * | | |
4929 */
ZTEST(periph_rem_invalid,test_conn_param_req_periph_rem_invalid_param)4930 ZTEST(periph_rem_invalid, test_conn_param_req_periph_rem_invalid_param)
4931 {
4932 struct node_tx *tx;
4933 uint16_t interval;
4934 uint8_t err;
4935
4936 /* Role */
4937 test_set_role(&conn, BT_HCI_ROLE_PERIPHERAL);
4938
4939 /* Connect */
4940 ull_cp_state_set(&conn, ULL_CP_CONNECTED);
4941
4942 /* Initiate a Connection Parameter Request Procedure */
4943 err = ull_cp_conn_update(&conn, INTVL_MIN, INTVL_MAX, LATENCY, TIMEOUT, NULL);
4944 zassert_equal(err, BT_HCI_ERR_SUCCESS);
4945
4946 /* Prepare */
4947 event_prepare(&conn);
4948 conn_param_req.reference_conn_event_count = event_counter(&conn);
4949
4950 /* Tx Queue should have one LL Control PDU */
4951 lt_rx(LL_CONNECTION_PARAM_REQ, &conn, &tx, &conn_param_req);
4952 lt_rx_q_is_empty(&conn);
4953
4954 /* Done */
4955 event_done(&conn);
4956
4957 /* Release Tx */
4958 ull_cp_release_tx(&conn, tx);
4959
4960 /* Prepare */
4961 event_prepare(&conn);
4962
4963 /* Rx */
4964 interval = conn_update_ind.interval;
4965 conn_update_ind.interval = 0U;
4966 conn_update_ind.instant = event_counter(&conn) + 6U;
4967 lt_tx(LL_CONNECTION_UPDATE_IND, &conn, &conn_update_ind);
4968
4969 /* Done */
4970 event_done(&conn);
4971
4972 /* Termination 'triggered' */
4973 zassert_equal(conn.llcp_terminate.reason_final, BT_HCI_ERR_INVALID_LL_PARAM,
4974 "Terminate reason %d", conn.llcp_terminate.reason_final);
4975
4976 /* Clear termination flag for subsequent test cycle */
4977 conn.llcp_terminate.reason_final = 0;
4978
4979 /* Restore interval for other tests */
4980 conn_update_ind.interval = interval;
4981 }
4982 #endif /* CONFIG_BT_CTLR_CONN_PARAM_REQ */
4983
4984 #if defined(CONFIG_BT_CTLR_CONN_PARAM_REQ)
4985 ZTEST_SUITE(central_loc, NULL, NULL, conn_update_setup, NULL, NULL);
4986 ZTEST_SUITE(central_rem, NULL, NULL, conn_update_setup, NULL, NULL);
4987 ZTEST_SUITE(periph_loc, NULL, NULL, conn_update_setup, NULL, NULL);
4988 ZTEST_SUITE(periph_rem, NULL, NULL, conn_update_setup, NULL, NULL);
4989 #else
4990 ZTEST_SUITE(central_loc_no_param_req, NULL, NULL, conn_update_setup, NULL, NULL);
4991 ZTEST_SUITE(central_rem_no_param_req, NULL, NULL, conn_update_setup, NULL, NULL);
4992 ZTEST_SUITE(periph_loc_no_param_req, NULL, NULL, conn_update_setup, NULL, NULL);
4993 ZTEST_SUITE(periph_rem_no_param_req, NULL, NULL, conn_update_setup, NULL, NULL);
4994 #endif /* CONFIG_BT_CTLR_CONN_PARAM_REQ */
4995
4996 ZTEST_SUITE(periph_rem_invalid, NULL, NULL, conn_update_setup, NULL, NULL);
4997