Skip to content

Commit 41edd77

Browse files
ivaniushkovrlubos
authored andcommitted
[nrf fromtree] bluetooth: CS: add bt_le_cs_get_antenna_path()
added function to calculate antenna path based on the antenna permutation index and total number of antenna paths Signed-off-by: Ivan Iushkov <ivan.iushkov@nordicsemi.no> (cherry picked from commit ded9c1f44d4a537a77c0e46b77d99b1899977977)
1 parent 6dd0779 commit 41edd77

File tree

2 files changed

+121
-0
lines changed
  • include/zephyr/bluetooth
  • subsys/bluetooth/host

2 files changed

+121
-0
lines changed

include/zephyr/bluetooth/cs.h

+21
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,27 @@ int bt_le_cs_write_cached_remote_supported_capabilities(
878878
*/
879879
int bt_le_cs_write_cached_remote_fae_table(struct bt_conn *conn, int8_t remote_fae_table[72]);
880880

881+
/** @brief Get antenna path used for the CS tone exchange
882+
* when using multiple antenna paths for mode-2 or mode-3
883+
* CS procedure.
884+
*
885+
* The function implements antenna path permutation defined in
886+
* Bluetooth Core Specification 6.0, Vol. 6, Part H, Section 4.7.5.
887+
*
888+
* @note To use this API @kconfig{CONFIG_BT_CHANNEL_SOUNDING} must be set.
889+
*
890+
* @param n_ap The number of antenna paths, range: [1, 4].
891+
* @param antenna_path_permutation_index Antenna Path Permutation Index.
892+
* @param tone_index Index of the tone in the CS step, range [0, n_ap].
893+
* tone_index = n_ap corresponds to extension slot.
894+
*
895+
* @return Antenna path used to exchange CS tones, range: [0, 3].
896+
* @return -EINVAL if arguments are invalid.
897+
*/
898+
int bt_le_cs_get_antenna_path(uint8_t n_ap,
899+
uint8_t antenna_path_permutation_index,
900+
uint8_t tone_index);
901+
881902
#ifdef __cplusplus
882903
}
883904
#endif

subsys/bluetooth/host/cs.c

+100
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ LOG_MODULE_REGISTER(bt_cs);
2222
static struct bt_le_cs_test_cb cs_test_callbacks;
2323
#endif
2424

25+
#define A1 (0)
26+
#define A2 (1)
27+
#define A3 (2)
28+
#define A4 (3)
29+
2530
struct reassembly_buf_meta_data {
2631
uint16_t conn_handle;
2732
};
@@ -1344,4 +1349,99 @@ void bt_le_cs_step_data_parse(struct net_buf_simple *step_data_buf,
13441349
}
13451350
}
13461351

1352+
/* Bluetooth Core Specification 6.0, Table 4.13, Antenna Path Permutation for N_AP=2.
1353+
* The last element corresponds to extension slot
1354+
*/
1355+
static const uint8_t antenna_path_lut_n_ap_2[2][3] = {
1356+
{A1, A2, A2},
1357+
{A2, A1, A1},
1358+
};
1359+
1360+
/* Bluetooth Core Specification 6.0, Table 4.14, Antenna Path Permutation for N_AP=3.
1361+
* The last element corresponds to extension slot
1362+
*/
1363+
static const uint8_t antenna_path_lut_n_ap_3[6][4] = {
1364+
{A1, A2, A3, A3},
1365+
{A2, A1, A3, A3},
1366+
{A1, A3, A2, A2},
1367+
{A3, A1, A2, A2},
1368+
{A3, A2, A1, A1},
1369+
{A2, A3, A1, A1},
1370+
};
1371+
1372+
/* Bluetooth Core Specification 6.0, Table 4.15, Antenna Path Permutation for N_AP=4.
1373+
* The last element corresponds to extension slot
1374+
*/
1375+
static const uint8_t antenna_path_lut_n_ap_4[24][5] = {
1376+
{A1, A2, A3, A4, A4},
1377+
{A2, A1, A3, A4, A4},
1378+
{A1, A3, A2, A4, A4},
1379+
{A3, A1, A2, A4, A4},
1380+
{A3, A2, A1, A4, A4},
1381+
{A2, A3, A1, A4, A4},
1382+
{A1, A2, A4, A3, A3},
1383+
{A2, A1, A4, A3, A3},
1384+
{A1, A4, A2, A3, A3},
1385+
{A4, A1, A2, A3, A3},
1386+
{A4, A2, A1, A3, A3},
1387+
{A2, A4, A1, A3, A3},
1388+
{A1, A4, A3, A2, A2},
1389+
{A4, A1, A3, A2, A2},
1390+
{A1, A3, A4, A2, A2},
1391+
{A3, A1, A4, A2, A2},
1392+
{A3, A4, A1, A2, A2},
1393+
{A4, A3, A1, A2, A2},
1394+
{A4, A2, A3, A1, A1},
1395+
{A2, A4, A3, A1, A1},
1396+
{A4, A3, A2, A1, A1},
1397+
{A3, A4, A2, A1, A1},
1398+
{A3, A2, A4, A1, A1},
1399+
{A2, A3, A4, A1, A1},
1400+
};
1401+
1402+
int bt_le_cs_get_antenna_path(uint8_t n_ap,
1403+
uint8_t antenna_path_permutation_index,
1404+
uint8_t tone_index)
1405+
{
1406+
switch (n_ap) {
1407+
case 1:
1408+
{
1409+
uint8_t antenna_path_permutations = 1;
1410+
uint8_t num_tones = n_ap + 1; /* one additional tone extension slot */
1411+
1412+
if (antenna_path_permutation_index >= antenna_path_permutations ||
1413+
tone_index >= num_tones) {
1414+
return -EINVAL;
1415+
}
1416+
return A1;
1417+
}
1418+
case 2:
1419+
{
1420+
if (antenna_path_permutation_index >= ARRAY_SIZE(antenna_path_lut_n_ap_2) ||
1421+
tone_index >= ARRAY_SIZE(antenna_path_lut_n_ap_2[0])) {
1422+
return -EINVAL;
1423+
}
1424+
return antenna_path_lut_n_ap_2[antenna_path_permutation_index][tone_index];
1425+
}
1426+
case 3:
1427+
{
1428+
if (antenna_path_permutation_index >= ARRAY_SIZE(antenna_path_lut_n_ap_3) ||
1429+
tone_index >= ARRAY_SIZE(antenna_path_lut_n_ap_3[0])) {
1430+
return -EINVAL;
1431+
}
1432+
return antenna_path_lut_n_ap_3[antenna_path_permutation_index][tone_index];
1433+
}
1434+
case 4:
1435+
{
1436+
if (antenna_path_permutation_index >= ARRAY_SIZE(antenna_path_lut_n_ap_4) ||
1437+
tone_index >= ARRAY_SIZE(antenna_path_lut_n_ap_4[0])) {
1438+
return -EINVAL;
1439+
}
1440+
return antenna_path_lut_n_ap_4[antenna_path_permutation_index][tone_index];
1441+
}
1442+
default:
1443+
return -EINVAL;
1444+
}
1445+
}
1446+
13471447
#endif /* CONFIG_BT_CHANNEL_SOUNDING */

0 commit comments

Comments
 (0)