1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20 #include <stddef.h>
21 #include <string.h>
22 #include "testutil/testutil.h"
23 #include "controller/ble_ll_test.h"
24 #include "controller/ble_ll_conn.h"
25
TEST_CASE(ble_ll_csa2_test_1)26 TEST_CASE(ble_ll_csa2_test_1)
27 {
28 struct ble_ll_conn_sm conn;
29 uint8_t rc;
30
31 /*
32 * Note: This test only verified mapped channel. Sample data also specifies
33 * prn_e and unmapped channel values but those would require extra access
34 * to internal state of algorithm which is not exposed.
35 */
36
37 memset(&conn, 0, sizeof(conn));
38
39 CONN_F_CSA2_SUPP(&conn) = 1;
40
41 /*
42 * based on sample data from CoreSpec 5.0 Vol 6 Part C 3.1
43 * (all channels used)
44 */
45 conn.channel_id = ((0x8e89bed6 & 0xffff0000) >> 16) ^
46 (0x8e89bed6 & 0x0000ffff);
47
48 conn.num_used_chans = 37;
49 conn.chanmap[0] = 0xff;
50 conn.chanmap[1] = 0xff;
51 conn.chanmap[2] = 0xff;
52 conn.chanmap[3] = 0xff;
53 conn.chanmap[4] = 0x1f;
54
55 conn.event_cntr = 1;
56 rc = ble_ll_conn_calc_dci(&conn, 0);
57 TEST_ASSERT(rc == 20);
58
59 conn.event_cntr = 2;
60 rc = ble_ll_conn_calc_dci(&conn, 0);
61 TEST_ASSERT(rc == 6);
62
63 conn.event_cntr = 3;
64 rc = ble_ll_conn_calc_dci(&conn, 0);
65 TEST_ASSERT(rc == 21);
66 }
67
TEST_CASE(ble_ll_csa2_test_2)68 TEST_CASE(ble_ll_csa2_test_2)
69 {
70 struct ble_ll_conn_sm conn;
71 uint8_t rc;
72
73 /*
74 * Note: This test only verified mapped channel. Sample data also specifies
75 * prn_e and unmapped channel values but those would require extra access
76 * to internal state of algorithm which is not exposed.
77 */
78
79 memset(&conn, 0, sizeof(conn));
80
81 CONN_F_CSA2_SUPP(&conn) = 1;
82
83 /*
84 * based on sample data from CoreSpec 5.0 Vol 6 Part C 3.2
85 * (9 channels used)
86 */
87 conn.channel_id = ((0x8e89bed6 & 0xffff0000) >> 16) ^
88 (0x8e89bed6 & 0x0000ffff);
89
90 conn.num_used_chans = 9;
91 conn.chanmap[0] = 0x00;
92 conn.chanmap[1] = 0x06;
93 conn.chanmap[2] = 0xe0;
94 conn.chanmap[3] = 0x00;
95 conn.chanmap[4] = 0x1e;
96
97 conn.event_cntr = 6;
98 rc = ble_ll_conn_calc_dci(&conn, 0);
99 TEST_ASSERT(rc == 23);
100
101 conn.event_cntr = 7;
102 rc = ble_ll_conn_calc_dci(&conn, 0);
103 TEST_ASSERT(rc == 9);
104
105 conn.event_cntr = 8;
106 rc = ble_ll_conn_calc_dci(&conn, 0);
107 TEST_ASSERT(rc == 34);
108 }
109
TEST_SUITE(ble_ll_csa2_test_suite)110 TEST_SUITE(ble_ll_csa2_test_suite)
111 {
112 ble_ll_csa2_test_1();
113 ble_ll_csa2_test_2();
114 }
115
116 int
ble_ll_csa2_test_all(void)117 ble_ll_csa2_test_all(void)
118 {
119 ble_ll_csa2_test_1();
120 ble_ll_csa2_test_2();
121
122 return tu_any_failed;
123 }
124