You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by an...@apache.org on 2023/02/02 23:11:21 UTC

[mynewt-nimble] branch master updated (f5c918d1 -> 94d9faf0)

This is an automated email from the ASF dual-hosted git repository.

andk pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git


    from f5c918d1 nimble/phy/nrf5x: Add workaround to allow encrypted ISO on nRF52840
     new c995fe4f nimble/ll: Optimize num used channels calculation
     new 4cd3b3b8 nimble/ll: Use consistent chan_map naming
     new 94d9faf0 nimble/ll: Fix global chan_map handling

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 nimble/controller/include/controller/ble_ll.h      |  2 +-
 nimble/controller/include/controller/ble_ll_conn.h |  7 +-
 .../controller/include/controller/ble_ll_utils.h   | 11 ++-
 nimble/controller/src/ble_ll.c                     |  2 +-
 nimble/controller/src/ble_ll_adv.c                 |  4 +-
 nimble/controller/src/ble_ll_conn.c                | 46 ++++-------
 nimble/controller/src/ble_ll_conn_hci.c            | 34 +-------
 nimble/controller/src/ble_ll_conn_priv.h           |  1 -
 nimble/controller/src/ble_ll_hci.c                 | 33 +++++++-
 nimble/controller/src/ble_ll_sync.c                | 77 +++++++++---------
 nimble/controller/src/ble_ll_utils.c               | 35 +++------
 nimble/controller/test/src/ble_ll_csa2_test.c      | 90 +++++++++++-----------
 12 files changed, 158 insertions(+), 184 deletions(-)


[mynewt-nimble] 03/03: nimble/ll: Fix global chan_map handling

Posted by an...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit 94d9faf080c91f5e92c5f2677867a16ef94bc089
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Tue Jan 31 12:38:58 2023 +0100

    nimble/ll: Fix global chan_map handling
    
    Global channel map should be handled by common code so need to move it
    out of ble_ll_conn.
---
 nimble/controller/include/controller/ble_ll_conn.h |  3 ++
 nimble/controller/src/ble_ll_conn.c                | 20 ++-----------
 nimble/controller/src/ble_ll_conn_hci.c            | 32 ---------------------
 nimble/controller/src/ble_ll_conn_priv.h           |  1 -
 nimble/controller/src/ble_ll_hci.c                 | 33 +++++++++++++++++++++-
 5 files changed, 37 insertions(+), 52 deletions(-)

diff --git a/nimble/controller/include/controller/ble_ll_conn.h b/nimble/controller/include/controller/ble_ll_conn.h
index a44e802e..016e5abd 100644
--- a/nimble/controller/include/controller/ble_ll_conn.h
+++ b/nimble/controller/include/controller/ble_ll_conn.h
@@ -459,6 +459,9 @@ struct ble_ll_conn_sm *ble_ll_conn_find_by_handle(uint16_t handle);
 struct ble_ll_conn_sm *ble_ll_conn_find_by_peer_addr(const uint8_t* addr,
                                                      uint8_t addr_type);
 
+/* Perform channel map update on all connections (applies to central role) */
+void ble_ll_conn_chan_map_update(void);
+
 /* required for unit testing */
 uint8_t ble_ll_conn_calc_dci(struct ble_ll_conn_sm *conn, uint16_t latency);
 
diff --git a/nimble/controller/src/ble_ll_conn.c b/nimble/controller/src/ble_ll_conn.c
index 8992c386..0c6530b5 100644
--- a/nimble/controller/src/ble_ll_conn.c
+++ b/nimble/controller/src/ble_ll_conn.c
@@ -4023,29 +4023,13 @@ ble_ll_conn_tx_pkt_in(struct os_mbuf *om, uint16_t handle, uint16_t length)
     }
 }
 #endif
-/**
- * Called to set the global channel mask that we use for all connections.
- *
- * @param num_used_chans
- * @param chanmap
- */
+
 void
-ble_ll_conn_set_global_chanmap(uint8_t num_used_chans, const uint8_t *chanmap)
+ble_ll_conn_chan_map_update(void)
 {
 #if MYNEWT_VAL(BLE_LL_ROLE_CENTRAL)
     struct ble_ll_conn_sm *connsm;
-#endif
 
-    /* Do nothing if same channel map */
-    if (!memcmp(g_ble_ll_data.chan_map, chanmap, BLE_LL_CHAN_MAP_LEN)) {
-        return;
-    }
-
-    /* Change channel map and cause channel map update procedure to start */
-    g_ble_ll_data.chan_map_used = num_used_chans;
-    memcpy(g_ble_ll_data.chan_map, chanmap, BLE_LL_CHAN_MAP_LEN);
-
-#if MYNEWT_VAL(BLE_LL_ROLE_CENTRAL)
     /* Perform channel map update */
     SLIST_FOREACH(connsm, &g_ble_ll_conn_active_list, act_sle) {
         if (connsm->conn_role == BLE_LL_CONN_ROLE_CENTRAL) {
diff --git a/nimble/controller/src/ble_ll_conn_hci.c b/nimble/controller/src/ble_ll_conn_hci.c
index dbda28bb..5010dddb 100644
--- a/nimble/controller/src/ble_ll_conn_hci.c
+++ b/nimble/controller/src/ble_ll_conn_hci.c
@@ -1432,38 +1432,6 @@ ble_ll_conn_hci_rd_chan_map(const uint8_t *cmdbuf, uint8_t len,
 }
 #endif
 
-/**
- * Called when the host issues the LE command "set host channel classification"
- *
- * @param cmdbuf
- *
- * @return int
- */
-int
-ble_ll_conn_hci_set_chan_class(const uint8_t *cmdbuf, uint8_t len)
-{
-    const struct ble_hci_le_set_host_chan_class_cp *cmd = (const void *) cmdbuf;
-    uint8_t num_used_chans;
-
-    if (len != sizeof(*cmd)) {
-        return BLE_ERR_INV_HCI_CMD_PARMS;
-    }
-
-    /*
-     * The HCI command states that the host is allowed to mask in just one
-     * channel but the Link Layer needs minimum two channels to operate. So
-     * I will not allow this command if there are less than 2 channels masked.
-     */
-    num_used_chans = ble_ll_utils_chan_map_used_get(cmd->chan_map);
-    if ((num_used_chans < 2) || ((cmd->chan_map[4] & 0xe0) != 0)) {
-        return BLE_ERR_INV_HCI_CMD_PARMS;
-    }
-
-    /* Set the host channel mask */
-    ble_ll_conn_set_global_chanmap(num_used_chans, cmd->chan_map);
-    return BLE_ERR_SUCCESS;
-}
-
 #if MYNEWT_VAL(BLE_LL_ROLE_PERIPHERAL) || MYNEWT_VAL(BLE_LL_ROLE_CENTRAL)
 
 #if MYNEWT_VAL(BLE_LL_CFG_FEAT_DATA_LEN_EXT)
diff --git a/nimble/controller/src/ble_ll_conn_priv.h b/nimble/controller/src/ble_ll_conn_priv.h
index bb58e4b7..023881d0 100644
--- a/nimble/controller/src/ble_ll_conn_priv.h
+++ b/nimble/controller/src/ble_ll_conn_priv.h
@@ -182,7 +182,6 @@ int ble_ll_conn_periph_start(uint8_t *rxbuf, uint8_t pat,
 
 /* Link Layer interface */
 void ble_ll_conn_module_init(void);
-void ble_ll_conn_set_global_chanmap(uint8_t num_used_chans, const uint8_t *chanmap);
 void ble_ll_conn_module_reset(void);
 void ble_ll_conn_tx_pkt_in(struct os_mbuf *om, uint16_t handle, uint16_t len);
 int ble_ll_conn_rx_isr_start(struct ble_mbuf_hdr *rxhdr, uint32_t aa);
diff --git a/nimble/controller/src/ble_ll_hci.c b/nimble/controller/src/ble_ll_hci.c
index fab30493..695e6533 100644
--- a/nimble/controller/src/ble_ll_hci.c
+++ b/nimble/controller/src/ble_ll_hci.c
@@ -33,6 +33,7 @@
 #include "controller/ble_ll_whitelist.h"
 #include "controller/ble_ll_resolv.h"
 #include "controller/ble_ll_sync.h"
+#include <controller/ble_ll_utils.h>
 #include "controller/ble_ll_iso.h"
 #include "ble_ll_priv.h"
 #include "ble_ll_conn_priv.h"
@@ -833,6 +834,36 @@ ble_ll_write_rf_path_compensation(const uint8_t *cmdbuf, uint8_t len)
     return BLE_ERR_SUCCESS;
 }
 
+static int
+ble_ll_hci_le_set_host_chan_class(const uint8_t *cmdbuf, uint8_t len)
+{
+    const struct ble_hci_le_set_host_chan_class_cp *cmd = (const void *)cmdbuf;
+    uint8_t chan_map_used;
+
+    if (len != sizeof(*cmd)) {
+        return BLE_ERR_INV_HCI_CMD_PARMS;
+    }
+
+    /* HCI command allows only single channel to be enabled, but LL needs at
+     * least 2 channels to work so let's reject in such case.
+     */
+    chan_map_used = ble_ll_utils_chan_map_used_get(cmd->chan_map);
+    if ((chan_map_used < 2) || (cmd->chan_map[4] & 0xe0)) {
+        return BLE_ERR_INV_HCI_CMD_PARMS;
+    }
+
+    if (!memcmp(g_ble_ll_data.chan_map, cmd->chan_map, BLE_LL_CHAN_MAP_LEN)) {
+        return BLE_ERR_SUCCESS;
+    }
+
+    memcpy(g_ble_ll_data.chan_map, cmd->chan_map, BLE_LL_CHAN_MAP_LEN);
+    g_ble_ll_data.chan_map_used = chan_map_used;
+
+    ble_ll_conn_chan_map_update();
+
+    return BLE_ERR_SUCCESS;
+}
+
 /**
  * Process a LE command sent from the host to the controller. The HCI command
  * has a 3 byte command header followed by data. The header is:
@@ -957,7 +988,7 @@ ble_ll_hci_le_cmd_proc(const uint8_t *cmdbuf, uint8_t len, uint16_t ocf,
         break;
 #endif
     case BLE_HCI_OCF_LE_SET_HOST_CHAN_CLASS:
-        rc = ble_ll_conn_hci_set_chan_class(cmdbuf, len);
+        rc = ble_ll_hci_le_set_host_chan_class(cmdbuf, len);
         break;
 #if MYNEWT_VAL(BLE_LL_ROLE_PERIPHERAL) || MYNEWT_VAL(BLE_LL_ROLE_CENTRAL)
     case BLE_HCI_OCF_LE_RD_CHAN_MAP:


[mynewt-nimble] 02/03: nimble/ll: Use consistent chan_map naming

Posted by an...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit 4cd3b3b8d614482090e87d40795f0eab06ed81f2
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Tue Jan 31 12:18:04 2023 +0100

    nimble/ll: Use consistent chan_map naming
---
 nimble/controller/include/controller/ble_ll.h      |  2 +-
 nimble/controller/include/controller/ble_ll_conn.h |  4 +-
 .../controller/include/controller/ble_ll_utils.h   | 11 ++-
 nimble/controller/src/ble_ll.c                     |  2 +-
 nimble/controller/src/ble_ll_adv.c                 |  4 +-
 nimble/controller/src/ble_ll_conn.c                | 28 +++----
 nimble/controller/src/ble_ll_conn_hci.c            |  4 +-
 nimble/controller/src/ble_ll_sync.c                | 77 +++++++++---------
 nimble/controller/src/ble_ll_utils.c               | 18 ++---
 nimble/controller/test/src/ble_ll_csa2_test.c      | 90 +++++++++++-----------
 10 files changed, 121 insertions(+), 119 deletions(-)

diff --git a/nimble/controller/include/controller/ble_ll.h b/nimble/controller/include/controller/ble_ll.h
index 9fe3fb8f..35b562a9 100644
--- a/nimble/controller/include/controller/ble_ll.h
+++ b/nimble/controller/include/controller/ble_ll.h
@@ -107,8 +107,8 @@ struct ble_ll_obj
     uint8_t ll_state;
 
     /* Global channel map */
-    uint8_t chan_map_num_used;
     uint8_t chan_map[BLE_LL_CHAN_MAP_LEN];
+    uint8_t chan_map_used;
 
 #if MYNEWT_VAL(BLE_LL_ROLE_CENTRAL) || MYNEWT_VAL(BLE_LL_ROLE_PERIPHERAL)
     /* Number of ACL data packets supported */
diff --git a/nimble/controller/include/controller/ble_ll_conn.h b/nimble/controller/include/controller/ble_ll_conn.h
index c8497942..a44e802e 100644
--- a/nimble/controller/include/controller/ble_ll_conn.h
+++ b/nimble/controller/include/controller/ble_ll_conn.h
@@ -240,14 +240,14 @@ struct ble_ll_conn_sm
 #endif
 
     /* Used to calculate data channel index for connection */
-    uint8_t chanmap[BLE_LL_CHAN_MAP_LEN];
+    uint8_t chan_map[BLE_LL_CHAN_MAP_LEN];
     uint8_t req_chanmap[BLE_LL_CHAN_MAP_LEN];
     uint16_t chanmap_instant;
     uint16_t channel_id; /* TODO could be union with hop and last chan used */
     uint8_t hop_inc;
     uint8_t data_chan_index;
     uint8_t last_unmapped_chan;
-    uint8_t num_used_chans;
+    uint8_t chan_map_used;
 
     /* Ack/Flow Control */
     uint8_t tx_seqnum;          /* note: can be 1 bit */
diff --git a/nimble/controller/include/controller/ble_ll_utils.h b/nimble/controller/include/controller/ble_ll_utils.h
index 629a894b..291872bf 100644
--- a/nimble/controller/include/controller/ble_ll_utils.h
+++ b/nimble/controller/include/controller/ble_ll_utils.h
@@ -32,16 +32,19 @@ int ble_ll_utils_verify_aa(uint32_t aa);
 uint32_t ble_ll_utils_calc_aa(void);
 uint32_t ble_ll_utils_calc_seed_aa(void);
 uint32_t ble_ll_utils_calc_big_aa(uint32_t seed_aa, uint32_t n);
-uint8_t ble_ll_utils_remapped_channel(uint8_t remap_index, const uint8_t *chanmap);
+
+uint8_t ble_ll_utils_chan_map_remap(const uint8_t *chan_map, uint8_t remap_index);
+uint8_t ble_ll_utils_chan_map_used_get(const uint8_t *chan_map);
+
 uint8_t ble_ll_utils_dci_csa2(uint16_t counter, uint16_t chan_id,
                               uint8_t num_used_chans, const uint8_t *chan_map);
 uint16_t ble_ll_utils_dci_iso_event(uint16_t counter, uint16_t chan_id,
-                                    uint16_t *prn_sub_lu, uint8_t num_used_chans,
+                                    uint16_t *prn_sub_lu, uint8_t chan_map_used,
                                     const uint8_t *chan_map, uint16_t *remap_idx);
 uint16_t ble_ll_utils_dci_iso_subevent(uint16_t chan_id, uint16_t *prn_sub_lu,
-                                       uint8_t num_used_chans, const uint8_t *chan_map,
+                                       uint8_t chan_map_used, const uint8_t *chan_map,
                                        uint16_t *remap_idx);
-uint8_t ble_ll_utils_calc_num_used_chans(const uint8_t *chan_map);
+
 uint32_t ble_ll_utils_calc_window_widening(uint32_t anchor_point,
                                            uint32_t last_anchor_point,
                                            uint8_t central_sca);
diff --git a/nimble/controller/src/ble_ll.c b/nimble/controller/src/ble_ll.c
index 8b239572..4da7a1f8 100644
--- a/nimble/controller/src/ble_ll.c
+++ b/nimble/controller/src/ble_ll.c
@@ -1640,7 +1640,7 @@ ble_ll_reset(void)
     g_ble_ll_data.ll_pref_rx_phys = phy_mask;
 
     /* Enable all channels in channel map */
-    g_ble_ll_data.chan_map_num_used = BLE_PHY_NUM_DATA_CHANS;
+    g_ble_ll_data.chan_map_used = BLE_PHY_NUM_DATA_CHANS;
     memset(g_ble_ll_data.chan_map, 0xff, BLE_LL_CHAN_MAP_LEN - 1);
     g_ble_ll_data.chan_map[4] = 0x1f;
 
diff --git a/nimble/controller/src/ble_ll_adv.c b/nimble/controller/src/ble_ll_adv.c
index dfa41bc7..1173c193 100644
--- a/nimble/controller/src/ble_ll_adv.c
+++ b/nimble/controller/src/ble_ll_adv.c
@@ -1474,7 +1474,7 @@ ble_ll_adv_aux_calculate(struct ble_ll_adv_sm *advsm,
 #if MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_CSA2)
     aux->chan = ble_ll_utils_dci_csa2(advsm->event_cntr++,
                                       advsm->channel_id,
-                                      g_ble_ll_data.chan_map_num_used,
+                                      g_ble_ll_data.chan_map_used,
                                       g_ble_ll_data.chan_map);
 #else
     aux->chan = ble_ll_utils_remapped_channel(ble_ll_rand() % BLE_PHY_NUM_DATA_CHANS,
@@ -2609,7 +2609,7 @@ ble_ll_adv_sm_start_periodic(struct ble_ll_adv_sm *advsm)
 
     /* keep channel map since we cannot change it later on */
     memcpy(advsm->periodic_chanmap, g_ble_ll_data.chan_map, BLE_LL_CHAN_MAP_LEN);
-    advsm->periodic_num_used_chans = g_ble_ll_data.chan_map_num_used;
+    advsm->periodic_num_used_chans = g_ble_ll_data.chan_map_used;
     advsm->periodic_event_cntr = 0;
     /* for chaining we start with random counter as we share access addr */
     advsm->periodic_chain_event_cntr = ble_ll_rand();
diff --git a/nimble/controller/src/ble_ll_conn.c b/nimble/controller/src/ble_ll_conn.c
index 8f75ecd2..8992c386 100644
--- a/nimble/controller/src/ble_ll_conn.c
+++ b/nimble/controller/src/ble_ll_conn.c
@@ -776,14 +776,14 @@ ble_ll_conn_calc_dci_csa1(struct ble_ll_conn_sm *conn)
 
     /* Is this a valid channel? */
     bitpos = 1 << (curchan & 0x07);
-    if (conn->chanmap[curchan >> 3] & bitpos) {
+    if (conn->chan_map[curchan >> 3] & bitpos) {
         return curchan;
     }
 
     /* Calculate remap index */
-    remap_index = curchan % conn->num_used_chans;
+    remap_index = curchan % conn->chan_map_used;
 
-    return ble_ll_utils_remapped_channel(remap_index, conn->chanmap);
+    return ble_ll_utils_chan_map_remap(conn->chan_map, remap_index);
 }
 
 /**
@@ -803,7 +803,7 @@ ble_ll_conn_calc_dci(struct ble_ll_conn_sm *conn, uint16_t latency)
 #if MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_CSA2)
     if (CONN_F_CSA2_SUPP(conn)) {
         return ble_ll_utils_dci_csa2(conn->event_cntr, conn->channel_id,
-                                     conn->num_used_chans, conn->chanmap);
+                                     conn->chan_map_used, conn->chan_map);
     }
 #endif
 
@@ -1756,8 +1756,8 @@ ble_ll_conn_central_common_init(struct ble_ll_conn_sm *connsm)
     connsm->hop_inc = (ble_ll_rand() % 12) + 5;
 
     /* Set channel map to map requested by host */
-    connsm->num_used_chans = g_ble_ll_data.chan_map_num_used;
-    memcpy(connsm->chanmap, g_ble_ll_data.chan_map, BLE_LL_CHAN_MAP_LEN);
+    connsm->chan_map_used = g_ble_ll_data.chan_map_used;
+    memcpy(connsm->chan_map, g_ble_ll_data.chan_map, BLE_LL_CHAN_MAP_LEN);
 
 #if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_ENHANCED_CONN_UPDATE)
     connsm->acc_subrate_min = g_ble_ll_conn_params.acc_subrate_min;
@@ -2605,9 +2605,9 @@ ble_ll_conn_next_event(struct ble_ll_conn_sm *connsm)
          * the queue of the central. This means that we never successfully
          * transmitted update request. Would end up killing connection
            on peripheral side. Could ignore it or see if still enqueued. */
-        connsm->num_used_chans =
-            ble_ll_utils_calc_num_used_chans(connsm->req_chanmap);
-        memcpy(connsm->chanmap, connsm->req_chanmap, BLE_LL_CHAN_MAP_LEN);
+        connsm->chan_map_used =
+            ble_ll_utils_chan_map_used_get(connsm->req_chanmap);
+        memcpy(connsm->chan_map, connsm->req_chanmap, BLE_LL_CHAN_MAP_LEN);
 
         connsm->csmflags.cfbit.chanmap_update_scheduled = 0;
 
@@ -3155,7 +3155,7 @@ ble_ll_conn_tx_connect_ind_pducb(uint8_t *dptr, void *pducb_arg, uint8_t *hdr_by
     put_le16(dptr + 10, connsm->conn_itvl);
     put_le16(dptr + 12, connsm->periph_latency);
     put_le16(dptr + 14, connsm->supervision_tmo);
-    memcpy(dptr + 16, &connsm->chanmap, BLE_LL_CHAN_MAP_LEN);
+    memcpy(dptr + 16, &connsm->chan_map, BLE_LL_CHAN_MAP_LEN);
     dptr[21] = connsm->hop_inc | (connsm->central_sca << 5);
 
     *hdr_byte = pdu_data->hdr_byte;
@@ -4042,7 +4042,7 @@ ble_ll_conn_set_global_chanmap(uint8_t num_used_chans, const uint8_t *chanmap)
     }
 
     /* Change channel map and cause channel map update procedure to start */
-    g_ble_ll_data.chan_map_num_used = num_used_chans;
+    g_ble_ll_data.chan_map_used = num_used_chans;
     memcpy(g_ble_ll_data.chan_map, chanmap, BLE_LL_CHAN_MAP_LEN);
 
 #if MYNEWT_VAL(BLE_LL_ROLE_CENTRAL)
@@ -4117,7 +4117,7 @@ ble_ll_conn_periph_start(uint8_t *rxbuf, uint8_t pat, struct ble_mbuf_hdr *rxhdr
     connsm->conn_itvl = get_le16(dptr + 10);
     connsm->periph_latency = get_le16(dptr + 12);
     connsm->supervision_tmo = get_le16(dptr + 14);
-    memcpy(&connsm->chanmap, dptr + 16, BLE_LL_CHAN_MAP_LEN);
+    memcpy(&connsm->chan_map, dptr + 16, BLE_LL_CHAN_MAP_LEN);
     connsm->hop_inc = dptr[21] & 0x1F;
     connsm->central_sca = dptr[21] >> 5;
 
@@ -4155,8 +4155,8 @@ ble_ll_conn_periph_start(uint8_t *rxbuf, uint8_t pat, struct ble_mbuf_hdr *rxhdr
     connsm->peer_addr_type = pat;
 
     /* Calculate number of used channels; make sure it meets min requirement */
-    connsm->num_used_chans = ble_ll_utils_calc_num_used_chans(connsm->chanmap);
-    if (connsm->num_used_chans < 2) {
+    connsm->chan_map_used = ble_ll_utils_chan_map_used_get(connsm->chan_map);
+    if (connsm->chan_map_used < 2) {
         goto err_periph_start;
     }
 
diff --git a/nimble/controller/src/ble_ll_conn_hci.c b/nimble/controller/src/ble_ll_conn_hci.c
index d0de63ba..dbda28bb 100644
--- a/nimble/controller/src/ble_ll_conn_hci.c
+++ b/nimble/controller/src/ble_ll_conn_hci.c
@@ -1420,7 +1420,7 @@ ble_ll_conn_hci_rd_chan_map(const uint8_t *cmdbuf, uint8_t len,
         if (connsm->csmflags.cfbit.chanmap_update_scheduled) {
             memcpy(rsp->chan_map, connsm->req_chanmap, BLE_LL_CHAN_MAP_LEN);
         } else {
-            memcpy(rsp->chan_map, connsm->chanmap, BLE_LL_CHAN_MAP_LEN);
+            memcpy(rsp->chan_map, connsm->chan_map, BLE_LL_CHAN_MAP_LEN);
         }
         rc = BLE_ERR_SUCCESS;
     }
@@ -1454,7 +1454,7 @@ ble_ll_conn_hci_set_chan_class(const uint8_t *cmdbuf, uint8_t len)
      * channel but the Link Layer needs minimum two channels to operate. So
      * I will not allow this command if there are less than 2 channels masked.
      */
-    num_used_chans = ble_ll_utils_calc_num_used_chans(cmd->chan_map);
+    num_used_chans = ble_ll_utils_chan_map_used_get(cmd->chan_map);
     if ((num_used_chans < 2) || ((cmd->chan_map[4] & 0xe0) != 0)) {
         return BLE_ERR_INV_HCI_CMD_PARMS;
     }
diff --git a/nimble/controller/src/ble_ll_sync.c b/nimble/controller/src/ble_ll_sync.c
index f298ac1a..971f8799 100644
--- a/nimble/controller/src/ble_ll_sync.c
+++ b/nimble/controller/src/ble_ll_sync.c
@@ -64,7 +64,6 @@
 #define BLE_LL_SYNC_SM_FLAG_NEW_CHANMAP     0x0200
 #define BLE_LL_SYNC_SM_FLAG_CHAIN           0x0400
 
-#define BLE_LL_SYNC_CHMAP_LEN               5
 #define BLE_LL_SYNC_ITVL_USECS              1250
 
 struct ble_ll_sync_sm {
@@ -75,11 +74,11 @@ struct ble_ll_sync_sm {
     uint8_t adv_addr_type;
 
     uint8_t sca;
-    uint8_t chanmap[BLE_LL_SYNC_CHMAP_LEN];
-    uint8_t num_used_chans;
+    uint8_t chan_map[BLE_LL_CHAN_MAP_LEN];
+    uint8_t chan_map_used;
 
-    uint8_t chanmap_new[BLE_LL_SYNC_CHMAP_LEN];
-    uint16_t chanmap_new_instant;
+    uint8_t chan_map_new[BLE_LL_CHAN_MAP_LEN];
+    uint16_t chan_map_new_instant;
 
     uint8_t chan_index;
     uint8_t chan_chain;
@@ -997,18 +996,18 @@ ble_ll_sync_check_acad(struct ble_ll_sync_sm *sm,
             /* Channels Mask (37 bits)
              * TODO should we check this?
              */
-            sm->chanmap_new[0] = chmu->map[0];
-            sm->chanmap_new[1] = chmu->map[1];
-            sm->chanmap_new[2] = chmu->map[2];
-            sm->chanmap_new[3] = chmu->map[3];
-            sm->chanmap_new[4] = chmu->map[4] & 0x1f;
+            sm->chan_map_new[0] = chmu->map[0];
+            sm->chan_map_new[1] = chmu->map[1];
+            sm->chan_map_new[2] = chmu->map[2];
+            sm->chan_map_new[3] = chmu->map[3];
+            sm->chan_map_new[4] = chmu->map[4] & 0x1f;
 
             /* drop if channel map is invalid */
-            if (ble_ll_utils_calc_num_used_chans(sm->chanmap_new) == 0) {
+            if (ble_ll_utils_chan_map_used_get(sm->chan_map_new) == 0) {
                 return false;
             }
 
-            sm->chanmap_new_instant = le16toh(chmu->instant);
+            sm->chan_map_new_instant = le16toh(chmu->instant);
             sm->flags |= BLE_LL_SYNC_SM_FLAG_NEW_CHANMAP;
             break;
         default:
@@ -1165,21 +1164,21 @@ ble_ll_sync_next_event(struct ble_ll_sync_sm *sm, uint32_t cur_ww_adjust)
 
     /* update channel map if needed */
     if (sm->flags & BLE_LL_SYNC_SM_FLAG_NEW_CHANMAP) {
-        if (((int16_t)(sm->event_cntr - sm->chanmap_new_instant)) >= 0) {
+        if (((int16_t)(sm->event_cntr - sm->chan_map_new_instant)) >= 0) {
             /* map was verified on reception */
-            sm->chanmap[0] = sm->chanmap_new[0];
-            sm->chanmap[1] = sm->chanmap_new[1];
-            sm->chanmap[2] = sm->chanmap_new[2];
-            sm->chanmap[3] = sm->chanmap_new[3];
-            sm->chanmap[4] = sm->chanmap_new[4];
-            sm->num_used_chans = ble_ll_utils_calc_num_used_chans(sm->chanmap);
+            sm->chan_map[0] = sm->chan_map_new[0];
+            sm->chan_map[1] = sm->chan_map_new[1];
+            sm->chan_map[2] = sm->chan_map_new[2];
+            sm->chan_map[3] = sm->chan_map_new[3];
+            sm->chan_map[4] = sm->chan_map_new[4];
+            sm->chan_map_used = ble_ll_utils_chan_map_used_get(sm->chan_map);
             sm->flags &= ~BLE_LL_SYNC_SM_FLAG_NEW_CHANMAP;
         }
     }
 
     /* Calculate channel index of next event */
     sm->chan_index = ble_ll_utils_dci_csa2(sm->event_cntr, sm->channel_id,
-                                           sm->num_used_chans, sm->chanmap);
+                                           sm->chan_map_used, sm->chan_map);
 
     cur_ww = ble_ll_utils_calc_window_widening(sm->anchor_point,
                                                sm->last_anchor_point,
@@ -1373,12 +1372,12 @@ ble_ll_sync_info_event(struct ble_ll_scan_addr_data *addrd,
     sm->itvl_ticks = ble_ll_tmr_u2t_r(usecs, &sm->itvl_usecs);
 
     /* Channels Mask (37 bits) */
-    sm->chanmap[0] = syncinfo[4];
-    sm->chanmap[1] = syncinfo[5];
-    sm->chanmap[2] = syncinfo[6];
-    sm->chanmap[3] = syncinfo[7];
-    sm->chanmap[4] = syncinfo[8] & 0x1f;
-    sm->num_used_chans = ble_ll_utils_calc_num_used_chans(sm->chanmap);
+    sm->chan_map[0] = syncinfo[4];
+    sm->chan_map[1] = syncinfo[5];
+    sm->chan_map[2] = syncinfo[6];
+    sm->chan_map[3] = syncinfo[7];
+    sm->chan_map[4] = syncinfo[8] & 0x1f;
+    sm->chan_map_used = ble_ll_utils_chan_map_used_get(sm->chan_map);
 
     /* SCA (3 bits) */
     sm->sca = syncinfo[8] >> 5;
@@ -1410,7 +1409,7 @@ ble_ll_sync_info_event(struct ble_ll_scan_addr_data *addrd,
 
     /* Calculate channel index of first event */
     sm->chan_index = ble_ll_utils_dci_csa2(sm->event_cntr, sm->channel_id,
-                                           sm->num_used_chans, sm->chanmap);
+                                           sm->chan_map_used, sm->chan_map);
 
     if (ble_ll_sched_sync(&sm->sch, rxhdr->beg_cputime, rxhdr->rem_usecs,
                           offset, sm->phy_mode)) {
@@ -1945,12 +1944,12 @@ ble_ll_sync_periodic_ind(struct ble_ll_conn_sm *connsm,
     sm->itvl_ticks = ble_ll_tmr_u2t_r(itvl_usecs, &sm->itvl_usecs);
 
     /* Channels Mask (37 bits) */
-    sm->chanmap[0] = syncinfo[4];
-    sm->chanmap[1] = syncinfo[5];
-    sm->chanmap[2] = syncinfo[6];
-    sm->chanmap[3] = syncinfo[7];
-    sm->chanmap[4] = syncinfo[8] & 0x1f;
-    sm->num_used_chans = ble_ll_utils_calc_num_used_chans(sm->chanmap);
+    sm->chan_map[0] = syncinfo[4];
+    sm->chan_map[1] = syncinfo[5];
+    sm->chan_map[2] = syncinfo[6];
+    sm->chan_map[3] = syncinfo[7];
+    sm->chan_map[4] = syncinfo[8] & 0x1f;
+    sm->chan_map_used = ble_ll_utils_chan_map_used_get(sm->chan_map);
 
     /* SCA (3 bits) */
     sm->sca = syncinfo[8] >> 5;
@@ -1978,7 +1977,7 @@ ble_ll_sync_periodic_ind(struct ble_ll_conn_sm *connsm,
 
     /* Calculate channel index of first event */
     sm->chan_index = ble_ll_utils_dci_csa2(sm->event_cntr, sm->channel_id,
-                                           sm->num_used_chans, sm->chanmap);
+                                           sm->chan_map_used, sm->chan_map);
 
     /* get anchor for specified conn event */
     conn_event_count = get_le16(sync_ind + 20);
@@ -2075,11 +2074,11 @@ ble_ll_sync_put_syncinfo(struct ble_ll_sync_sm *syncsm,
     put_le16(&dptr[2], syncsm->itvl);
 
     /* Channels Mask (37 bits) */
-    dptr[4] = syncsm->chanmap[0];
-    dptr[5] = syncsm->chanmap[1];
-    dptr[6] = syncsm->chanmap[2];
-    dptr[7] = syncsm->chanmap[3];
-    dptr[8] = syncsm->chanmap[4] & 0x1f;
+    dptr[4] = syncsm->chan_map[0];
+    dptr[5] = syncsm->chan_map[1];
+    dptr[6] = syncsm->chan_map[2];
+    dptr[7] = syncsm->chan_map[3];
+    dptr[8] = syncsm->chan_map[4] & 0x1f;
 
     /* SCA (3 bits) */
     dptr[8] |= syncsm->sca << 5;
diff --git a/nimble/controller/src/ble_ll_utils.c b/nimble/controller/src/ble_ll_utils.c
index 5d023b11..9fa32f8f 100644
--- a/nimble/controller/src/ble_ll_utils.c
+++ b/nimble/controller/src/ble_ll_utils.c
@@ -214,7 +214,7 @@ ble_ll_utils_calc_big_aa(uint32_t seed_aa, uint32_t n)
 }
 
 uint8_t
-ble_ll_utils_remapped_channel(uint8_t remap_index, const uint8_t *chanmap)
+ble_ll_utils_chan_map_remap(const uint8_t *chan_map, uint8_t remap_index)
 {
     uint8_t cntr;
     uint8_t mask;
@@ -229,7 +229,7 @@ ble_ll_utils_remapped_channel(uint8_t remap_index, const uint8_t *chanmap)
     chan = 0;
     cntr = 0;
     for (i = 0; i < BLE_LL_CHMAP_LEN; i++) {
-        usable_chans = chanmap[i];
+        usable_chans = chan_map[i];
         if (usable_chans != 0) {
             mask = 0x01;
             for (j = 0; j < 8; j++) {
@@ -251,7 +251,7 @@ ble_ll_utils_remapped_channel(uint8_t remap_index, const uint8_t *chanmap)
 }
 
 uint8_t
-ble_ll_utils_calc_num_used_chans(const uint8_t *chan_map)
+ble_ll_utils_chan_map_used_get(const uint8_t *chan_map)
 {
     return __builtin_popcountll(((uint64_t)(chan_map[4] & 0x1f) << 32) |
                                 get_le32(chan_map));
@@ -412,7 +412,7 @@ ble_ll_utils_dci_csa2(uint16_t counter, uint16_t chan_id,
 
 uint16_t
 ble_ll_utils_dci_iso_event(uint16_t counter, uint16_t chan_id,
-                           uint16_t *prn_sub_lu, uint8_t num_used_chans,
+                           uint16_t *prn_sub_lu, uint8_t chan_map_used,
                            const uint8_t *chan_map, uint16_t *remap_idx)
 {
     uint16_t prn_s;
@@ -424,7 +424,7 @@ ble_ll_utils_dci_iso_event(uint16_t counter, uint16_t chan_id,
 
     *prn_sub_lu = prn_s;
 
-    chan_idx = ble_ll_utils_csa2_calc_chan_idx(prn_e, num_used_chans, chan_map,
+    chan_idx = ble_ll_utils_csa2_calc_chan_idx(prn_e, chan_map_used, chan_map,
                                                remap_idx);
 
     return chan_idx;
@@ -432,7 +432,7 @@ ble_ll_utils_dci_iso_event(uint16_t counter, uint16_t chan_id,
 
 uint16_t
 ble_ll_utils_dci_iso_subevent(uint16_t chan_id, uint16_t *prn_sub_lu,
-                              uint8_t num_used_chans, const uint8_t *chan_map,
+                              uint8_t chan_map_used, const uint8_t *chan_map,
                               uint16_t *remap_idx)
 {
     uint16_t prn_sub_se;
@@ -445,10 +445,10 @@ ble_ll_utils_dci_iso_subevent(uint16_t chan_id, uint16_t *prn_sub_lu,
 
     /* Core 5.3, Vol 6, Part B, 4.5.8.3.6 (enjoy!) */
     /* TODO optimize this somehow */
-    d = MAX(1, MAX(MIN(3, num_used_chans - 5),
-                   MIN(11, (num_used_chans - 10) / 2)));
+    d = MAX(1, MAX(MIN(3, chan_map_used - 5),
+                   MIN(11, (chan_map_used - 10) / 2)));
     *remap_idx = (*remap_idx + d + prn_sub_se *
-                  (num_used_chans - 2 * d + 1) / 65536) % num_used_chans;
+                  (chan_map_used - 2 * d + 1) / 65536) % chan_map_used;
 
     chan_idx = ble_ll_utils_csa2_remap2chan(*remap_idx, chan_map);
 
diff --git a/nimble/controller/test/src/ble_ll_csa2_test.c b/nimble/controller/test/src/ble_ll_csa2_test.c
index ae8f8897..d7d43dcf 100644
--- a/nimble/controller/test/src/ble_ll_csa2_test.c
+++ b/nimble/controller/test/src/ble_ll_csa2_test.c
@@ -44,12 +44,12 @@ TEST_CASE_SELF(ble_ll_csa2_test_1)
     conn.channel_id = ((0x8e89bed6 & 0xffff0000) >> 16) ^
                        (0x8e89bed6 & 0x0000ffff);
 
-    conn.num_used_chans = 37;
-    conn.chanmap[0] = 0xff;
-    conn.chanmap[1] = 0xff;
-    conn.chanmap[2] = 0xff;
-    conn.chanmap[3] = 0xff;
-    conn.chanmap[4] = 0x1f;
+    conn.chan_map_used = 37;
+    conn.chan_map[0] = 0xff;
+    conn.chan_map[1] = 0xff;
+    conn.chan_map[2] = 0xff;
+    conn.chan_map[3] = 0xff;
+    conn.chan_map[4] = 0x1f;
 
     conn.event_cntr = 1;
     rc = ble_ll_conn_calc_dci(&conn, 0);
@@ -86,12 +86,12 @@ TEST_CASE_SELF(ble_ll_csa2_test_2)
     conn.channel_id = ((0x8e89bed6 & 0xffff0000) >> 16) ^
                        (0x8e89bed6 & 0x0000ffff);
 
-    conn.num_used_chans = 9;
-    conn.chanmap[0] = 0x00;
-    conn.chanmap[1] = 0x06;
-    conn.chanmap[2] = 0xe0;
-    conn.chanmap[3] = 0x00;
-    conn.chanmap[4] = 0x1e;
+    conn.chan_map_used = 9;
+    conn.chan_map[0] = 0x00;
+    conn.chan_map[1] = 0x06;
+    conn.chan_map[2] = 0xe0;
+    conn.chan_map[3] = 0x00;
+    conn.chan_map[4] = 0x1e;
 
     conn.event_cntr = 6;
     rc = ble_ll_conn_calc_dci(&conn, 0);
@@ -109,7 +109,7 @@ TEST_CASE_SELF(ble_ll_csa2_test_2)
 TEST_CASE_SELF(ble_ll_csa2_test_3)
 {
     uint8_t chan_map[5];
-    uint8_t num_used_chans;
+    uint8_t chan_map_used;
     uint16_t chan_id;
     uint16_t prn_sub_lu;
     uint16_t chan_idx;
@@ -121,86 +121,86 @@ TEST_CASE_SELF(ble_ll_csa2_test_3)
     chan_map[2] = 0xff;
     chan_map[3] = 0xff;
     chan_map[4] = 0x1f;
-    num_used_chans = ble_ll_utils_calc_num_used_chans(chan_map);
-    TEST_ASSERT(num_used_chans == 37);
+    chan_map_used = ble_ll_utils_chan_map_used_get(chan_map);
+    TEST_ASSERT(chan_map_used == 37);
     chan_id = 0x305f;
 
-    chan_idx = ble_ll_utils_dci_iso_event(0, chan_id, &prn_sub_lu, num_used_chans, chan_map, &remap_idx);
+    chan_idx = ble_ll_utils_dci_iso_event(0, chan_id, &prn_sub_lu, chan_map_used, chan_map, &remap_idx);
     TEST_ASSERT((prn_sub_lu ^ chan_id) == 56857);
     TEST_ASSERT(chan_idx == 25);
     TEST_ASSERT(remap_idx == 25);
 
-    chan_idx = ble_ll_utils_dci_iso_subevent(chan_id, &prn_sub_lu, num_used_chans, chan_map, &remap_idx);
+    chan_idx = ble_ll_utils_dci_iso_subevent(chan_id, &prn_sub_lu, chan_map_used, chan_map, &remap_idx);
     TEST_ASSERT((prn_sub_lu ^ chan_id) == 11710);
     TEST_ASSERT(chan_idx == 1);
     TEST_ASSERT(remap_idx == 1);
 
-    chan_idx = ble_ll_utils_dci_iso_subevent(chan_id, &prn_sub_lu, num_used_chans, chan_map, &remap_idx);
+    chan_idx = ble_ll_utils_dci_iso_subevent(chan_id, &prn_sub_lu, chan_map_used, chan_map, &remap_idx);
     TEST_ASSERT((prn_sub_lu ^ chan_id) == 16649);
     TEST_ASSERT(chan_idx == 16);
     TEST_ASSERT(remap_idx == 16);
 
-    chan_idx = ble_ll_utils_dci_iso_subevent(chan_id, &prn_sub_lu, num_used_chans, chan_map, &remap_idx);
+    chan_idx = ble_ll_utils_dci_iso_subevent(chan_id, &prn_sub_lu, chan_map_used, chan_map, &remap_idx);
     TEST_ASSERT((prn_sub_lu ^ chan_id) == 38198);
     TEST_ASSERT(chan_idx == 36);
     TEST_ASSERT(remap_idx == 36);
 
-    chan_idx = ble_ll_utils_dci_iso_event(1, chan_id, &prn_sub_lu, num_used_chans, chan_map, &remap_idx);
+    chan_idx = ble_ll_utils_dci_iso_event(1, chan_id, &prn_sub_lu, chan_map_used, chan_map, &remap_idx);
     TEST_ASSERT((prn_sub_lu ^ chan_id) == 1685);
     TEST_ASSERT(chan_idx == 20);
     TEST_ASSERT(remap_idx == 20);
 
-    chan_idx = ble_ll_utils_dci_iso_subevent(chan_id, &prn_sub_lu, num_used_chans, chan_map, &remap_idx);
+    chan_idx = ble_ll_utils_dci_iso_subevent(chan_id, &prn_sub_lu, chan_map_used, chan_map, &remap_idx);
     TEST_ASSERT((prn_sub_lu ^ chan_id) == 20925);
     TEST_ASSERT(chan_idx == 36);
     TEST_ASSERT(remap_idx == 36);
 
-    chan_idx = ble_ll_utils_dci_iso_subevent(chan_id, &prn_sub_lu, num_used_chans, chan_map, &remap_idx);
+    chan_idx = ble_ll_utils_dci_iso_subevent(chan_id, &prn_sub_lu, chan_map_used, chan_map, &remap_idx);
     TEST_ASSERT((prn_sub_lu ^ chan_id) == 11081);
     TEST_ASSERT(chan_idx == 12);
     TEST_ASSERT(remap_idx == 12);
 
-    chan_idx = ble_ll_utils_dci_iso_subevent(chan_id, &prn_sub_lu, num_used_chans, chan_map, &remap_idx);
+    chan_idx = ble_ll_utils_dci_iso_subevent(chan_id, &prn_sub_lu, chan_map_used, chan_map, &remap_idx);
     TEST_ASSERT((prn_sub_lu ^ chan_id) == 48920);
     TEST_ASSERT(chan_idx == 34);
     TEST_ASSERT(remap_idx == 34);
 
-    chan_idx = ble_ll_utils_dci_iso_event(2, chan_id, &prn_sub_lu, num_used_chans, chan_map, &remap_idx);
+    chan_idx = ble_ll_utils_dci_iso_event(2, chan_id, &prn_sub_lu, chan_map_used, chan_map, &remap_idx);
     TEST_ASSERT((prn_sub_lu ^ chan_id) == 38301);
     TEST_ASSERT(chan_idx == 6);
     TEST_ASSERT(remap_idx == 6);
 
-    chan_idx = ble_ll_utils_dci_iso_subevent(chan_id, &prn_sub_lu, num_used_chans, chan_map, &remap_idx);
+    chan_idx = ble_ll_utils_dci_iso_subevent(chan_id, &prn_sub_lu, chan_map_used, chan_map, &remap_idx);
     TEST_ASSERT((prn_sub_lu ^ chan_id) == 6541);
     TEST_ASSERT(chan_idx == 18);
     TEST_ASSERT(remap_idx == 18);
 
-    chan_idx = ble_ll_utils_dci_iso_subevent(chan_id, &prn_sub_lu, num_used_chans, chan_map, &remap_idx);
+    chan_idx = ble_ll_utils_dci_iso_subevent(chan_id, &prn_sub_lu, chan_map_used, chan_map, &remap_idx);
     TEST_ASSERT((prn_sub_lu ^ chan_id) == 14597);
     TEST_ASSERT(chan_idx == 32);
     TEST_ASSERT(remap_idx == 32);
 
-    chan_idx = ble_ll_utils_dci_iso_subevent(chan_id, &prn_sub_lu, num_used_chans, chan_map, &remap_idx);
+    chan_idx = ble_ll_utils_dci_iso_subevent(chan_id, &prn_sub_lu, chan_map_used, chan_map, &remap_idx);
     TEST_ASSERT((prn_sub_lu ^ chan_id) == 62982);
     TEST_ASSERT(chan_idx == 21);
     TEST_ASSERT(remap_idx == 21);
 
-    chan_idx = ble_ll_utils_dci_iso_event(3, chan_id, &prn_sub_lu, num_used_chans, chan_map, &remap_idx);
+    chan_idx = ble_ll_utils_dci_iso_event(3, chan_id, &prn_sub_lu, chan_map_used, chan_map, &remap_idx);
     TEST_ASSERT((prn_sub_lu ^ chan_id) == 27475);
     TEST_ASSERT(chan_idx == 21);
     TEST_ASSERT(remap_idx == 21);
 
-    chan_idx = ble_ll_utils_dci_iso_subevent(chan_id, &prn_sub_lu, num_used_chans, chan_map, &remap_idx);
+    chan_idx = ble_ll_utils_dci_iso_subevent(chan_id, &prn_sub_lu, chan_map_used, chan_map, &remap_idx);
     TEST_ASSERT((prn_sub_lu ^ chan_id) == 40400);
     TEST_ASSERT(chan_idx == 4);
     TEST_ASSERT(remap_idx == 4);
 
-    chan_idx = ble_ll_utils_dci_iso_subevent(chan_id, &prn_sub_lu, num_used_chans, chan_map, &remap_idx);
+    chan_idx = ble_ll_utils_dci_iso_subevent(chan_id, &prn_sub_lu, chan_map_used, chan_map, &remap_idx);
     TEST_ASSERT((prn_sub_lu ^ chan_id) == 30015);
     TEST_ASSERT(chan_idx == 22);
     TEST_ASSERT(remap_idx == 22);
 
-    chan_idx = ble_ll_utils_dci_iso_subevent(chan_id, &prn_sub_lu, num_used_chans, chan_map, &remap_idx);
+    chan_idx = ble_ll_utils_dci_iso_subevent(chan_id, &prn_sub_lu, chan_map_used, chan_map, &remap_idx);
     TEST_ASSERT((prn_sub_lu ^ chan_id) == 49818);
     TEST_ASSERT(chan_idx == 8);
     TEST_ASSERT(remap_idx == 8);
@@ -211,66 +211,66 @@ TEST_CASE_SELF(ble_ll_csa2_test_3)
     chan_map[2] = 0xe0;
     chan_map[3] = 0x00;
     chan_map[4] = 0x1e;
-    num_used_chans = ble_ll_utils_calc_num_used_chans(chan_map);
-    TEST_ASSERT(num_used_chans == 9);
+    chan_map_used = ble_ll_utils_chan_map_used_get(chan_map);
+    TEST_ASSERT(chan_map_used == 9);
     chan_id = 0x305f;
 
-    chan_idx = ble_ll_utils_dci_iso_event(6, chan_id, &prn_sub_lu, num_used_chans, chan_map, &remap_idx);
+    chan_idx = ble_ll_utils_dci_iso_event(6, chan_id, &prn_sub_lu, chan_map_used, chan_map, &remap_idx);
     TEST_ASSERT((prn_sub_lu ^ chan_id) == 10975);
     TEST_ASSERT(chan_idx == 23);
     TEST_ASSERT(remap_idx == 4);
 
-    chan_idx = ble_ll_utils_dci_iso_subevent(chan_id, &prn_sub_lu, num_used_chans, chan_map, &remap_idx);
+    chan_idx = ble_ll_utils_dci_iso_subevent(chan_id, &prn_sub_lu, chan_map_used, chan_map, &remap_idx);
     TEST_ASSERT((prn_sub_lu ^ chan_id) == 14383);
     TEST_ASSERT(chan_idx == 35);
     TEST_ASSERT(remap_idx == 7);
 
-    chan_idx = ble_ll_utils_dci_iso_subevent(chan_id, &prn_sub_lu, num_used_chans, chan_map, &remap_idx);
+    chan_idx = ble_ll_utils_dci_iso_subevent(chan_id, &prn_sub_lu, chan_map_used, chan_map, &remap_idx);
     TEST_ASSERT((prn_sub_lu ^ chan_id) == 28946);
     TEST_ASSERT(chan_idx == 21);
     TEST_ASSERT(remap_idx == 2);
 
-    chan_idx = ble_ll_utils_dci_iso_subevent(chan_id, &prn_sub_lu, num_used_chans, chan_map, &remap_idx);
+    chan_idx = ble_ll_utils_dci_iso_subevent(chan_id, &prn_sub_lu, chan_map_used, chan_map, &remap_idx);
     TEST_ASSERT((prn_sub_lu ^ chan_id) == 61038);
     TEST_ASSERT(chan_idx == 36);
     TEST_ASSERT(remap_idx == 8);
 
-    chan_idx = ble_ll_utils_dci_iso_event(7, chan_id, &prn_sub_lu, num_used_chans, chan_map, &remap_idx);
+    chan_idx = ble_ll_utils_dci_iso_event(7, chan_id, &prn_sub_lu, chan_map_used, chan_map, &remap_idx);
     TEST_ASSERT((prn_sub_lu ^ chan_id) == 5490);
     TEST_ASSERT(chan_idx == 9);
     TEST_ASSERT(remap_idx == 0);
 
-    chan_idx = ble_ll_utils_dci_iso_subevent(chan_id, &prn_sub_lu, num_used_chans, chan_map, &remap_idx);
+    chan_idx = ble_ll_utils_dci_iso_subevent(chan_id, &prn_sub_lu, chan_map_used, chan_map, &remap_idx);
     TEST_ASSERT((prn_sub_lu ^ chan_id) == 4108);
     TEST_ASSERT(chan_idx == 22);
     TEST_ASSERT(remap_idx == 3);
 
-    chan_idx = ble_ll_utils_dci_iso_subevent(chan_id, &prn_sub_lu, num_used_chans, chan_map, &remap_idx);
+    chan_idx = ble_ll_utils_dci_iso_subevent(chan_id, &prn_sub_lu, chan_map_used, chan_map, &remap_idx);
     TEST_ASSERT((prn_sub_lu ^ chan_id) == 45462);
     TEST_ASSERT(chan_idx == 36);
     TEST_ASSERT(remap_idx == 8);
 
-    chan_idx = ble_ll_utils_dci_iso_subevent(chan_id, &prn_sub_lu, num_used_chans, chan_map, &remap_idx);
+    chan_idx = ble_ll_utils_dci_iso_subevent(chan_id, &prn_sub_lu, chan_map_used, chan_map, &remap_idx);
     TEST_ASSERT((prn_sub_lu ^ chan_id) == 64381);
     TEST_ASSERT(chan_idx == 33);
     TEST_ASSERT(remap_idx == 5);
 
-    chan_idx = ble_ll_utils_dci_iso_event(8, chan_id, &prn_sub_lu, num_used_chans, chan_map, &remap_idx);
+    chan_idx = ble_ll_utils_dci_iso_event(8, chan_id, &prn_sub_lu, chan_map_used, chan_map, &remap_idx);
     TEST_ASSERT((prn_sub_lu ^ chan_id) == 46970);
     TEST_ASSERT(chan_idx == 34);
     TEST_ASSERT(remap_idx == 6);
 
-    chan_idx = ble_ll_utils_dci_iso_subevent(chan_id, &prn_sub_lu, num_used_chans, chan_map, &remap_idx);
+    chan_idx = ble_ll_utils_dci_iso_subevent(chan_id, &prn_sub_lu, chan_map_used, chan_map, &remap_idx);
     TEST_ASSERT((prn_sub_lu ^ chan_id) == 7196);
     TEST_ASSERT(chan_idx == 9);
     TEST_ASSERT(remap_idx == 0);
 
-    chan_idx = ble_ll_utils_dci_iso_subevent(chan_id, &prn_sub_lu, num_used_chans, chan_map, &remap_idx);
+    chan_idx = ble_ll_utils_dci_iso_subevent(chan_id, &prn_sub_lu, chan_map_used, chan_map, &remap_idx);
     TEST_ASSERT((prn_sub_lu ^ chan_id) == 33054);
     TEST_ASSERT(chan_idx == 33);
     TEST_ASSERT(remap_idx == 5);
 
-    chan_idx = ble_ll_utils_dci_iso_subevent(chan_id, &prn_sub_lu, num_used_chans, chan_map, &remap_idx);
+    chan_idx = ble_ll_utils_dci_iso_subevent(chan_id, &prn_sub_lu, chan_map_used, chan_map, &remap_idx);
     TEST_ASSERT((prn_sub_lu ^ chan_id) == 42590);
     TEST_ASSERT(chan_idx == 10);
     TEST_ASSERT(remap_idx == 1);


[mynewt-nimble] 01/03: nimble/ll: Optimize num used channels calculation

Posted by an...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit c995fe4fc40cfdb0967c98bff53f7d0bcc36030e
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Tue Jan 31 11:23:20 2023 +0100

    nimble/ll: Optimize num used channels calculation
    
    popcount calculates number of bits set without loop.
---
 nimble/controller/src/ble_ll_utils.c | 17 ++---------------
 1 file changed, 2 insertions(+), 15 deletions(-)

diff --git a/nimble/controller/src/ble_ll_utils.c b/nimble/controller/src/ble_ll_utils.c
index 3603742d..5d023b11 100644
--- a/nimble/controller/src/ble_ll_utils.c
+++ b/nimble/controller/src/ble_ll_utils.c
@@ -253,21 +253,8 @@ ble_ll_utils_remapped_channel(uint8_t remap_index, const uint8_t *chanmap)
 uint8_t
 ble_ll_utils_calc_num_used_chans(const uint8_t *chan_map)
 {
-    uint32_t u32 = 0;
-    uint32_t num_used_chans = 0;
-    unsigned idx;
-
-    for (idx = 0; idx < 37; idx++) {
-        if ((idx % 8) == 0) {
-            u32 = chan_map[idx / 8];
-        }
-        if (u32 & 1) {
-            num_used_chans++;
-        }
-        u32 >>= 1;
-    }
-
-    return num_used_chans;
+    return __builtin_popcountll(((uint64_t)(chan_map[4] & 0x1f) << 32) |
+                                get_le32(chan_map));
 }
 
 #if MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_CSA2)