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/01/27 18:55:23 UTC

[mynewt-nimble] branch master updated (439047b3 -> 6c124515)

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 439047b3 ci: Remove Travis integration
     new e72a20a1 nimble: Cleanup ISO HCI commands/events defs
     new 6e9b61b1 nimble/ll: Add few useful macros
     new a7861f3c nimble/ll: Add helper to calculate Seed AA
     new 5652310e nimble/ll: Add helper to calculate BIG AA
     new 5b87eb0b nimble/ll: Add helper to validate AA
     new 32814579 nimble/ll: Rename helper to calculate AA
     new c7381e88 nimble/ll: Add ble_ll_pdu
     new d9fbaccd nimble/ll: Remove ble_ll_pdu_tx_time_get
     new 6c124515 nimble/ll: Add some crypto functions

The 9 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      |   4 -
 .../controller/include/controller/ble_ll_crypto.h  |  32 +--
 .../include/controller/ble_ll_pdu.h}               |  16 +-
 .../controller/include/controller/ble_ll_utils.h   |  10 +-
 nimble/controller/pkg.yml                          |   1 +
 nimble/controller/src/ble_ll.c                     |  59 +----
 nimble/controller/src/ble_ll_adv.c                 |  39 ++--
 nimble/controller/src/ble_ll_conn.c                |  23 +-
 nimble/controller/src/ble_ll_crypto.c              |  62 ++++++
 nimble/controller/src/ble_ll_dtm.c                 |   3 +-
 nimble/controller/src/ble_ll_hci.c                 |   2 +-
 nimble/controller/src/ble_ll_pdu.c                 |  58 +++++
 nimble/controller/src/ble_ll_scan_aux.c            |   3 +-
 nimble/controller/src/ble_ll_sched.c               |   5 +-
 nimble/controller/src/ble_ll_utils.c               | 221 ++++++++++++-------
 nimble/include/nimble/hci_common.h                 | 240 ++++++++++++---------
 16 files changed, 480 insertions(+), 298 deletions(-)
 copy porting/nimble/include/log/log.h => nimble/controller/include/controller/ble_ll_crypto.h (60%)
 copy nimble/{drivers/fem/nrf21540/include/nrf21540/nrf21540.h => controller/include/controller/ble_ll_pdu.h} (70%)
 create mode 100644 nimble/controller/src/ble_ll_crypto.c
 create mode 100644 nimble/controller/src/ble_ll_pdu.c


[mynewt-nimble] 02/09: nimble/ll: Add few useful macros

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 6e9b61b1c8f6a715ae7fc4676eeecf2ac1fd45e4
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Sat Feb 26 21:35:48 2022 +0100

    nimble/ll: Add few useful macros
---
 nimble/controller/include/controller/ble_ll_utils.h | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/nimble/controller/include/controller/ble_ll_utils.h b/nimble/controller/include/controller/ble_ll_utils.h
index 16b91a0c..added990 100644
--- a/nimble/controller/include/controller/ble_ll_utils.h
+++ b/nimble/controller/include/controller/ble_ll_utils.h
@@ -23,6 +23,11 @@
 #define INT16_LT(_a, _b) ((int16_t)((_a) - (_b)) < 0)
 #define INT16_LTE(_a, _b) ((int16_t)((_a) - (_b)) <= 0)
 
+#define MIN(_a, _b) ((_a) < (_b) ? (_a) : (_b))
+#define MAX(_a, _b) ((_a) < (_b) ? (_a) : (_b))
+#define CLAMP(_n, _min, _max) (MAX(_min, MIN(_n, _max)))
+#define IN_RANGE(_n, _min, _max) (((_n) >= (_min)) && ((_n) <= (_max)))
+
 uint32_t ble_ll_utils_calc_access_addr(void);
 uint8_t ble_ll_utils_remapped_channel(uint8_t remap_index, const uint8_t *chanmap);
 uint8_t ble_ll_utils_dci_csa2(uint16_t counter, uint16_t chan_id,


[mynewt-nimble] 05/09: nimble/ll: Add helper to validate AA

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 5b87eb0b62ea1cdf05d6af6a8d96bcc25c2e4b83
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Fri Jan 27 00:48:06 2023 +0100

    nimble/ll: Add helper to validate AA
---
 .../controller/include/controller/ble_ll_utils.h   |   1 +
 nimble/controller/src/ble_ll_utils.c               | 162 +++++++++++----------
 2 files changed, 84 insertions(+), 79 deletions(-)

diff --git a/nimble/controller/include/controller/ble_ll_utils.h b/nimble/controller/include/controller/ble_ll_utils.h
index 3e28fcb4..4d7e7e70 100644
--- a/nimble/controller/include/controller/ble_ll_utils.h
+++ b/nimble/controller/include/controller/ble_ll_utils.h
@@ -28,6 +28,7 @@
 #define CLAMP(_n, _min, _max) (MAX(_min, MIN(_n, _max)))
 #define IN_RANGE(_n, _min, _max) (((_n) >= (_min)) && ((_n) <= (_max)))
 
+int ble_ll_utils_verify_aa(uint32_t aa);
 uint32_t ble_ll_utils_calc_access_addr(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);
diff --git a/nimble/controller/src/ble_ll_utils.c b/nimble/controller/src/ble_ll_utils.c
index 4f1c679b..1259f94d 100644
--- a/nimble/controller/src/ble_ll_utils.c
+++ b/nimble/controller/src/ble_ll_utils.c
@@ -32,10 +32,9 @@ static const uint16_t g_ble_sca_ppm_tbl[8] = {
     500, 250, 150, 100, 75, 50, 30, 20
 };
 
-uint32_t
-ble_ll_utils_calc_access_addr(void)
+int
+ble_ll_utils_verify_aa(uint32_t aa)
 {
-    uint32_t aa;
     uint16_t aa_low;
     uint16_t aa_high;
     uint32_t temp;
@@ -47,100 +46,105 @@ ble_ll_utils_calc_access_addr(void)
     uint8_t ones;
     int tmp;
 
-    /* Calculate a random access address */
-    aa = 0;
-    while (1) {
-        /* Get two, 16-bit random numbers */
-        aa_low = ble_ll_rand() & 0xFFFF;
-        aa_high = ble_ll_rand() & 0xFFFF;
+    aa_low = aa & 0xffff;
+    aa_high = aa >> 16;
 
-        /* All four bytes cannot be equal */
-        if (aa_low == aa_high) {
-            continue;
-        }
+    /* All four bytes cannot be equal */
+    if (aa_low == aa_high) {
+        return 0;
+    }
 
-        /* Upper 6 bits must have 2 transitions */
-        tmp = (int16_t)aa_high >> 10;
-        if (__builtin_popcount(tmp ^ (tmp >> 1)) < 2) {
-            continue;
-        }
+    /* Upper 6 bits must have 2 transitions */
+    tmp = (int16_t)aa_high >> 10;
+    if (__builtin_popcount(tmp ^ (tmp >> 1)) < 2) {
+        return 0;
+    }
 
-        /* Cannot be access address or be 1 bit different */
-        aa = aa_high;
-        aa = (aa << 16) | aa_low;
-        bits_diff = 0;
-        temp = aa ^ BLE_ACCESS_ADDR_ADV;
-        for (mask = 0x00000001; mask != 0; mask <<= 1) {
-            if (mask & temp) {
-                ++bits_diff;
-                if (bits_diff > 1) {
-                    break;
-                }
+    /* Cannot be access address or be 1 bit different */
+    aa = aa_high;
+    aa = (aa << 16) | aa_low;
+    bits_diff = 0;
+    temp = aa ^ BLE_ACCESS_ADDR_ADV;
+    for (mask = 0x00000001; mask != 0; mask <<= 1) {
+        if (mask & temp) {
+            ++bits_diff;
+            if (bits_diff > 1) {
+                break;
             }
         }
-        if (bits_diff <= 1) {
-            continue;
-        }
+    }
+    if (bits_diff <= 1) {
+        return 0;
+    }
 
-        /* Cannot have more than 24 transitions */
-        transitions = 0;
-        consecutive = 1;
-        ones = 0;
-        mask = 0x00000001;
-        while (mask < 0x80000000) {
-            prev_bit = aa & mask;
-            mask <<= 1;
-            if (mask & aa) {
-                if (prev_bit == 0) {
-                    ++transitions;
-                    consecutive = 1;
-                } else {
-                    ++consecutive;
-                }
+    /* Cannot have more than 24 transitions */
+    transitions = 0;
+    consecutive = 1;
+    ones = 0;
+    mask = 0x00000001;
+    while (mask < 0x80000000) {
+        prev_bit = aa & mask;
+        mask <<= 1;
+        if (mask & aa) {
+            if (prev_bit == 0) {
+                ++transitions;
+                consecutive = 1;
             } else {
-                if (prev_bit == 0) {
-                    ++consecutive;
-                } else {
-                    ++transitions;
-                    consecutive = 1;
-                }
-            }
-
-            if (prev_bit) {
-                ones++;
+                ++consecutive;
             }
-
-            /* 8 lsb should have at least three 1 */
-            if (mask == 0x00000100 && ones < 3) {
-                break;
+        } else {
+            if (prev_bit == 0) {
+                ++consecutive;
+            } else {
+                ++transitions;
+                consecutive = 1;
             }
+        }
 
-            /* 16 lsb should have no more than 11 transitions */
-            if (mask == 0x00010000 && transitions > 11) {
-                break;
-            }
+        if (prev_bit) {
+            ones++;
+        }
 
-            /* This is invalid! */
-            if (consecutive > 6) {
-                /* Make sure we always detect invalid sequence below */
-                mask = 0;
-                break;
-            }
+        /* 8 lsb should have at least three 1 */
+        if (mask == 0x00000100 && ones < 3) {
+            break;
         }
 
-        /* Invalid sequence found */
-        if (mask != 0x80000000) {
-            continue;
+        /* 16 lsb should have no more than 11 transitions */
+        if (mask == 0x00010000 && transitions > 11) {
+            break;
         }
 
-        /* Cannot be more than 24 transitions */
-        if (transitions > 24) {
-            continue;
+        /* This is invalid! */
+        if (consecutive > 6) {
+            /* Make sure we always detect invalid sequence below */
+            mask = 0;
+            break;
         }
+    }
 
-        /* We have a valid access address */
-        break;
+    /* Invalid sequence found */
+    if (mask != 0x80000000) {
+        return 0;
     }
+
+    /* Cannot be more than 24 transitions */
+    if (transitions > 24) {
+        return 0;
+    }
+
+    return 1;
+}
+
+uint32_t
+ble_ll_utils_calc_access_addr(void)
+{
+    uint32_t aa;
+
+    do {
+        aa = ble_ll_rand();
+    } while (!ble_ll_utils_verify_aa(aa));
+
     return aa;
 }
 


[mynewt-nimble] 09/09: nimble/ll: Add some crypto functions

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 6c124515b502b0956c0225fb6c7a1ab48d49111a
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Thu Jan 26 23:42:33 2023 +0100

    nimble/ll: Add some crypto functions
    
    This adds h6, h7 and h8 crypto functions that are used to derive GSK
    from broadcast code. For now we use TinyCrypt, later we may use hw
    accelerators as an option.
---
 .../controller/include/controller/ble_ll_crypto.h  | 50 +++++++++++++++++
 nimble/controller/pkg.yml                          |  1 +
 nimble/controller/src/ble_ll_crypto.c              | 62 ++++++++++++++++++++++
 3 files changed, 113 insertions(+)

diff --git a/nimble/controller/include/controller/ble_ll_crypto.h b/nimble/controller/include/controller/ble_ll_crypto.h
new file mode 100644
index 00000000..4514b0b1
--- /dev/null
+++ b/nimble/controller/include/controller/ble_ll_crypto.h
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef H_BLE_LL_CRYPTO_
+#define H_BLE_LL_CRYPTO_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int
+ble_ll_crypto_cmac(const uint8_t *key, const uint8_t *in, int len,
+                   uint8_t *out);
+
+static inline int
+ble_ll_crypto_h6(const uint8_t *w, const uint8_t *key_id, uint8_t *out)
+{
+    return ble_ll_crypto_cmac(w, key_id, 4, out);
+}
+
+static inline int
+ble_ll_crypto_h7(const uint8_t *salt, const uint8_t *w, uint8_t *out)
+{
+    return ble_ll_crypto_cmac(salt, w, 16, out);
+}
+
+int ble_ll_crypto_h8(const uint8_t *k, const uint8_t *s, const uint8_t *key_id,
+                     uint8_t *out);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* H_BLE_LL_CRYPTO_ */
diff --git a/nimble/controller/pkg.yml b/nimble/controller/pkg.yml
index 678fea17..5e43ba39 100644
--- a/nimble/controller/pkg.yml
+++ b/nimble/controller/pkg.yml
@@ -38,5 +38,6 @@ pkg.req_apis.BLE_FEM_ANTENNA:
 
 pkg.deps:
     - "@apache-mynewt-core/kernel/os"
+    - "@apache-mynewt-core/crypto/tinycrypt"
     - nimble
     - nimble/transport
diff --git a/nimble/controller/src/ble_ll_crypto.c b/nimble/controller/src/ble_ll_crypto.c
new file mode 100644
index 00000000..be3e1be3
--- /dev/null
+++ b/nimble/controller/src/ble_ll_crypto.c
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <stdint.h>
+#include <nimble/ble.h>
+#include <controller/ble_ll_crypto.h>
+#include <controller/ble_hw.h>
+#include <tinycrypt/constants.h>
+#include <tinycrypt/cmac_mode.h>
+
+int
+ble_ll_crypto_cmac(const uint8_t *key, const uint8_t *in, int len,
+                   uint8_t *out)
+{
+    struct tc_aes_key_sched_struct sched;
+    struct tc_cmac_struct state;
+
+    if (tc_cmac_setup(&state, key, &sched) == TC_CRYPTO_FAIL) {
+        return -1;
+    }
+
+    if (tc_cmac_update(&state, in, len) == TC_CRYPTO_FAIL) {
+        return -1;
+    }
+
+    if (tc_cmac_final(out, &state) == TC_CRYPTO_FAIL) {
+        return -1;
+    }
+
+    return 0;
+}
+
+int
+ble_ll_crypto_h8(const uint8_t *k, const uint8_t *s, const uint8_t *key_id,
+                 uint8_t *out)
+{
+    uint8_t ik[16];
+    int rc;
+
+    rc = ble_ll_crypto_cmac(s, k, 16, ik);
+    if (rc) {
+        return rc;
+    }
+
+    return ble_ll_crypto_cmac(ik, key_id, 4, out);
+}


[mynewt-nimble] 01/09: nimble: Cleanup ISO HCI commands/events defs

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 e72a20a1132fccd6e5d9097ff90f3617a5354133
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Fri Jan 27 12:42:19 2023 +0100

    nimble: Cleanup ISO HCI commands/events defs
    
    This updates names to conform with Core 5.3 and also makes naming
    consistent for all commands/events.
    
    Also removes #ifdefs since we do not need them for HCI defs.
---
 nimble/controller/src/ble_ll.c     |   6 +-
 nimble/controller/src/ble_ll_hci.c |   2 +-
 nimble/include/nimble/hci_common.h | 240 ++++++++++++++++++++-----------------
 3 files changed, 137 insertions(+), 111 deletions(-)

diff --git a/nimble/controller/src/ble_ll.c b/nimble/controller/src/ble_ll.c
index d193b09d..9b9fc4e0 100644
--- a/nimble/controller/src/ble_ll.c
+++ b/nimble/controller/src/ble_ll.c
@@ -1484,7 +1484,7 @@ ble_ll_read_supp_features(void)
 int
 ble_ll_set_host_feat(const uint8_t *cmdbuf, uint8_t len)
 {
-    const struct ble_hci_le_set_host_feat_cp *cmd = (const void *) cmdbuf;
+    const struct ble_hci_le_set_host_feature_cp *cmd = (const void *) cmdbuf;
     uint64_t mask;
 
     if (len != sizeof(*cmd)) {
@@ -1497,7 +1497,7 @@ ble_ll_set_host_feat(const uint8_t *cmdbuf, uint8_t len)
     }
 #endif
 
-    if ((cmd->bit_num > 0x3F) || (cmd->val > 1)) {
+    if ((cmd->bit_num > 0x3F) || (cmd->bit_val > 1)) {
         return BLE_ERR_INV_HCI_CMD_PARMS;
     }
 
@@ -1506,7 +1506,7 @@ ble_ll_set_host_feat(const uint8_t *cmdbuf, uint8_t len)
         return BLE_ERR_UNSUPPORTED;
     }
 
-    if (cmd->val == 0) {
+    if (cmd->bit_val == 0) {
         g_ble_ll_data.ll_supp_features &= ~(mask);
     } else {
         g_ble_ll_data.ll_supp_features |= mask;
diff --git a/nimble/controller/src/ble_ll_hci.c b/nimble/controller/src/ble_ll_hci.c
index dc95f0de..f36563b1 100644
--- a/nimble/controller/src/ble_ll_hci.c
+++ b/nimble/controller/src/ble_ll_hci.c
@@ -1285,7 +1285,7 @@ ble_ll_hci_le_cmd_proc(const uint8_t *cmdbuf, uint8_t len, uint16_t ocf,
         break;
 #endif
 #if MYNEWT_VAL(BLE_VERSION) >= 52
-    case BLE_HCI_OCF_LE_SET_HOST_FEAT:
+    case BLE_HCI_OCF_LE_SET_HOST_FEATURE:
         rc = ble_ll_set_host_feat(cmdbuf, len);
         break;
 #endif
diff --git a/nimble/include/nimble/hci_common.h b/nimble/include/nimble/hci_common.h
index eadb0b0e..6c9d4061 100644
--- a/nimble/include/nimble/hci_common.h
+++ b/nimble/include/nimble/hci_common.h
@@ -835,112 +835,105 @@ struct ble_hci_le_set_default_periodic_sync_transfer_params_cp {
 #define BLE_HCI_OCF_LE_GENERATE_DHKEY_V2                 (0x005E)
 #define BLE_HCI_OCF_LE_MODIFY_SCA                        (0x005F)
 
-#if MYNEWT_VAL(BLE_ISO)
 #define BLE_HCI_OCF_LE_READ_ISO_TX_SYNC                  (0x0061)
 struct ble_hci_le_read_iso_tx_sync_cp {
     uint16_t conn_handle;
 } __attribute__((packed));
-
 struct ble_hci_le_read_iso_tx_sync_rp {
     uint16_t conn_handle;
     uint16_t packet_seq_num;
-    uint32_t timestamp;
-    uint8_t timeoffset[3];
+    uint32_t tx_timestamp;
+    uint8_t time_offset[3];
 } __attribute__((packed));
 
-#define BLE_HCI_LE_SET_CIG_CIS_MAX_NUM                   (0x1F)
-#define BLE_HCI_OCF_LE_SET_CIG_PARAM                     (0x0062)
+#define BLE_HCI_OCF_LE_SET_CIG_PARAMS                    (0x0062)
 struct ble_hci_le_cis_params {
     uint8_t cis_id;
-    uint16_t max_sdu_mtos;
-    uint16_t max_sdu_stom;
-    uint8_t phy_mtos;
-    uint8_t phy_stom;
-    uint8_t rnt_mtos;
-    uint8_t rnt_stom;
+    uint16_t max_sdu_c_to_p;
+    uint16_t max_sdu_p_to_c;
+    uint8_t phy_c_to_p;
+    uint8_t phy_p_to_c;
+    uint8_t rnt_c_to_p;
+    uint8_t rnt_p_to_c;
 } __attribute__((packed));
-
 struct ble_hci_le_set_cig_params_cp {
     uint8_t cig_id;
-    uint8_t sdu_interval_mtos[3];
-    uint8_t sdu_interval_stom[3];
-    uint8_t sca;
+    uint8_t sdu_interval_c_to_p[3];
+    uint8_t sdu_interval_p_to_c[3];
+    uint8_t worst_sca;
     uint8_t packing;
     uint8_t framing;
-    uint16_t max_latency_mtos;
-    uint16_t max_latency_stom;
-    uint8_t cis_cnt;
-    struct ble_hci_le_cis_params cis_params[0];
+    uint16_t max_latency_c_to_p;
+    uint16_t max_latency_p_to_c;
+    uint8_t cis_count;
+    struct ble_hci_le_cis_params cis[0];
 } __attribute__((packed));
-
 struct ble_hci_le_set_cig_params_rp {
     uint8_t cig_id;
-    uint8_t cis_cnt;
-    uint16_t cis_handle[0];
+    uint8_t cis_count;
+    uint16_t conn_handle[0];
 } __attribute__((packed));
 
-#if MYNEWT_VAL(BLE_ISO_TEST)
-#define BLE_HCI_OCF_LE_SET_CIG_PARAM_TEST                (0x0063)
+#define BLE_HCI_OCF_LE_SET_CIG_PARAMS_TEST               (0x0063)
 struct ble_hci_le_cis_params_test {
     uint8_t cis_id;
     uint8_t nse;
-    uint16_t max_sdu_mtos;
-    uint16_t max_sdu_stom;
-    uint16_t max_pdu_mtos;
-    uint16_t max_pdu_stom;
-    uint8_t phy_mtos;
-    uint8_t phy_stom;
-    uint8_t bn_mtos;
-    uint8_t bn_stom;
+    uint16_t max_sdu_c_to_p;
+    uint16_t max_sdu_p_to_c;
+    uint16_t max_pdu_c_to_p;
+    uint16_t max_pdu_p_to_c;
+    uint8_t phy_c_to_p;
+    uint8_t phy_p_to_c;
+    uint8_t bn_c_to_p;
+    uint8_t bn_p_to_c;
 } __attribute__((packed));
-
 struct ble_hci_le_set_cig_params_test_cp {
     uint8_t cig_id;
-    uint8_t sdu_interval_mtos[3];
-    uint8_t sdu_interval_stom[3];
-    uint8_t ft_mtos;
-    uint8_t ft_stom;
+    uint8_t sdu_interval_c_to_p[3];
+    uint8_t sdu_interval_p_to_c[3];
+    uint8_t ft_c_to_p;
+    uint8_t ft_p_to_c;
     uint16_t iso_interval;
-    uint8_t sca;
+    uint8_t worst_sca;
     uint8_t packing;
     uint8_t framing;
-    uint8_t cis_cnt;
-    struct ble_hci_le_cis_params_test cis_params[0];
+    uint8_t cis_count;
+    struct ble_hci_le_cis_params_test cis[0];
+} __attribute__((packed));
+struct ble_hci_le_set_cig_params_test_rp {
+    uint8_t cig_id;
+    uint8_t cis_count;
+    uint16_t conn_handle[0];
 } __attribute__((packed));
-#endif
 
-#define BLE_HCI_LE_CREATE_CIS_MAX_CIS_NUM                (0x1F)
 #define BLE_HCI_OCF_LE_CREATE_CIS                        (0x0064)
 struct ble_hci_le_create_cis_params {
     uint16_t cis_handle;
     uint16_t conn_handle;
 } __attribute__((packed));
-
 struct ble_hci_le_create_cis_cp {
-    uint8_t cis_cnt;
-    struct ble_hci_le_create_cis_params params[0];
+    uint8_t cis_count;
+    struct ble_hci_le_create_cis_params cis[0];
 } __attribute__((packed));
 
 #define BLE_HCI_OCF_LE_REMOVE_CIG                        (0x0065)
 struct ble_hci_le_remove_cig_cp {
     uint8_t cig_id;
 } __attribute__((packed));
-
 struct ble_hci_le_remove_cig_rp {
     uint8_t cig_id;
 } __attribute__((packed));
 
 #define BLE_HCI_OCF_LE_ACCEPT_CIS_REQ                    (0x0066)
 struct ble_hci_le_accept_cis_request_cp {
-    uint16_t cis_handle;
+    uint16_t conn_handle;
 } __attribute__((packed));
 
 #define BLE_HCI_OCF_LE_REJECT_CIS_REQ                    (0x0067)
 struct ble_hci_le_reject_cis_request_cp {
-    uint16_t cis_handle;
+    uint16_t conn_handle;
     uint8_t reason;
 } __attribute__((packed));
-
 struct ble_hci_le_reject_cis_request_rp {
     uint16_t conn_handle;
 } __attribute__((packed));
@@ -949,11 +942,11 @@ struct ble_hci_le_reject_cis_request_rp {
 struct ble_hci_le_create_big_cp {
     uint8_t big_handle;
     uint8_t adv_handle;
-    uint8_t bis_cnt;
+    uint8_t num_bis;
     uint8_t sdu_interval[3];
     uint16_t max_sdu;
     uint16_t max_transport_latency;
-    uint8_t rnt;
+    uint8_t rtn;
     uint8_t phy;
     uint8_t packing;
     uint8_t framing;
@@ -961,12 +954,11 @@ struct ble_hci_le_create_big_cp {
     uint8_t broadcast_code[16];
 } __attribute__((packed));
 
-#if MYNEWT_VAL(BLE_ISO_TEST)
 #define BLE_HCI_OCF_LE_CREATE_BIG_TEST                   (0x0069)
 struct ble_hci_le_create_big_test_cp {
     uint8_t big_handle;
     uint8_t adv_handle;
-    uint8_t bis_cnt;
+    uint8_t num_bis;
     uint8_t sdu_interval[3];
     uint16_t iso_interval;
     uint8_t nse;
@@ -981,7 +973,6 @@ struct ble_hci_le_create_big_test_cp {
     uint8_t encryption;
     uint8_t broadcast_code[16];
 } __attribute__((packed));
-#endif
 
 #define BLE_HCI_OCF_LE_TERMINATE_BIG                     (0x006a)
 struct ble_hci_le_terminate_big_cp {
@@ -989,78 +980,113 @@ struct ble_hci_le_terminate_big_cp {
     uint8_t reason;
 } __attribute__((packed));
 
-#define BLE_HCI_LE_BIG_CREATE_SYNC_LEN_MIN               (25)
 #define BLE_HCI_OCF_LE_BIG_CREATE_SYNC                   (0x006b)
 struct ble_hci_le_big_create_sync_cp {
     uint8_t big_handle;
     uint16_t sync_handle;
-    uint8_t big_cnt;
     uint8_t encryption;
     uint8_t broadcast_code[16];
     uint8_t mse;
-    uint16_t timeout;
+    uint16_t sync_timeout;
+    uint8_t num_bis;
     uint8_t bis[0];
 } __attribute__((packed));
 
 #define BLE_HCI_OCF_LE_BIG_TERMINATE_SYNC                (0x006c)
-struct ble_hci_le_terminate_big_sync_cp {
+struct ble_hci_le_big_terminate_sync_cp {
+    uint8_t big_handle;
+} __attribute__((packed));
+struct ble_hci_le_big_terminate_sync_rp {
     uint8_t big_handle;
 } __attribute__((packed));
-#endif
 
 #define BLE_HCI_OCF_LE_REQ_PEER_SCA                      (0x006d)
 struct ble_hci_le_request_peer_sca_cp {
     uint16_t conn_handle;
 } __attribute__((packed));
 
-#if MYNEWT_VAL(BLE_ISO)
 #define BLE_HCI_OCF_LE_SETUP_ISO_DATA_PATH               (0x006e)
-struct ble_hci_le_iso_setup_data_path_cp {
-    uint16_t iso_handle;
-    uint8_t direction;
-    uint8_t id;
+struct ble_hci_le_setup_iso_data_path_cp {
+    uint16_t conn_handle;
+    uint8_t data_path_dir;
+    uint8_t data_path_id;
     uint8_t codec_id[5];
     uint8_t controller_delay[3];
-    uint8_t codec_conf_len;
-    uint8_t codec_conf[0];
+    uint8_t codec_config_len;
+    uint8_t codec_config[0];
+} __attribute__((packed));
+struct ble_hci_le_setup_iso_data_path_rp {
+    uint16_t conn_handle;
 } __attribute__((packed));
 
-#define BLE_HCI_LE_REMOVE_INPUT_DATA_PATH_BIT            (0x01)
-#define BLE_HCI_LE_REMOVE_OUTPUT_DATA_PATH_BIT           (0x02)
 #define BLE_HCI_OCF_LE_REMOVE_ISO_DATA_PATH              (0x006f)
-struct ble_hci_le_iso_remove_data_path_cp {
-    uint16_t iso_handle;
-    uint8_t direction;
+struct ble_hci_le_remove_iso_data_path_cp {
+    uint16_t conn_handle;
+    uint8_t data_path_dir;
+} __attribute__((packed));
+struct ble_hci_le_remove_iso_data_path_rp {
+    uint16_t conn_handle;
 } __attribute__((packed));
 
-#if MYNEWT_VAL(BLE_ISO_TEST)
 #define BLE_HCI_OCF_LE_ISO_TRANSMIT_TEST                 (0x0070)
 struct ble_hci_le_iso_transmit_test_cp {
-    uint16_t iso_handle;
+    uint16_t conn_handle;
     uint8_t payload_type;
 } __attribute__((packed));
+struct ble_hci_le_iso_transmit_test_rp {
+    uint16_t conn_handle;
+} __attribute__((packed));
 
 #define BLE_HCI_OCF_LE_ISO_RECEIVE_TEST                  (0x0071)
 struct ble_hci_le_iso_receive_test_cp {
-    uint16_t iso_handle;
+    uint16_t conn_handle;
+    uint8_t payload_type;
+} __attribute__((packed));
+struct ble_hci_le_iso_receive_test_rp {
+    uint16_t conn_handle;
 } __attribute__((packed));
 
 #define BLE_HCI_OCF_LE_ISO_READ_TEST_COUNTERS            (0x0072)
 struct ble_hci_le_iso_read_test_counters_cp {
-    uint16_t iso_handle;
+    uint16_t conn_handle;
+} __attribute__((packed));
+struct ble_hci_le_iso_read_test_counters_rp {
+    uint16_t conn_handle;
+    uint32_t received_sdu_count;
+    uint32_t missed_sdu_count;
+    uint32_t failed_sdu_count;
 } __attribute__((packed));
 
 #define BLE_HCI_OCF_LE_ISO_TEST_END                      (0x0073)
 struct ble_hci_le_iso_test_end_cp {
-    uint16_t iso_handle;
+    uint16_t conn_handle;
+} __attribute__((packed));
+struct ble_hci_le_iso_test_end_rp {
+    uint16_t conn_handle;
+    uint32_t received_sdu_count;
+    uint32_t missed_sdu_count;
+    uint32_t failed_sdu_count;
 } __attribute__((packed));
-#endif
-#endif
 
-#define BLE_HCI_OCF_LE_SET_HOST_FEAT                     (0x0074)
-struct ble_hci_le_set_host_feat_cp {
+#define BLE_HCI_OCF_LE_SET_HOST_FEATURE                  (0x0074)
+struct ble_hci_le_set_host_feature_cp {
     uint8_t bit_num;
-    uint8_t val;
+    uint8_t bit_val;
+} __attribute__((packed));
+
+#define BLE_HCI_OCF_LE_READ_ISO_LINK_QUALITY             (0x0075)
+struct ble_hci_le_read_iso_link_quality_cp {
+    uint16_t conn_handle;
+} __attribute__((packed));
+struct ble_hci_le_read_iso_link_quality_rp {
+    uint16_t conn_handle;
+    uint32_t tx_unacked_pkts;
+    uint32_t tx_flushed_pkts;
+    uint32_t tx_last_subevent_pkts;
+    uint32_t retransmitted_pkts;
+    uint32_t crc_error_pkts;
+    uint32_t rx_unreceived_pkts;
+    uint32_t duplicate_pkts;
 } __attribute__((packed));
 
 #define BLE_HCI_OCF_LE_ENH_READ_TRANSMIT_POWER_LEVEL     (0x0076)
@@ -1816,43 +1842,43 @@ struct ble_hci_ev_le_subev_periodic_adv_sync_transfer {
     uint8_t  aca;
 } __attribute__((packed));
 
-#define BLE_HCI_LE_SUBEV_CIS_ESTAB              (0x19)
+#define BLE_HCI_LE_SUBEV_CIS_ESTABLISHED        (0x19)
 struct ble_hci_ev_le_subev_cis_established {
     uint8_t subev_code;
     uint8_t status;
-    uint16_t cis_handle;
+    uint16_t conn_handle;
     uint8_t cig_sync_delay[3];
     uint8_t cis_sync_delay[3];
-    uint8_t trans_latency_mtos[3];
-    uint8_t trans_latency_stom[3];
-    uint8_t phy_mtos;
-    uint8_t phy_stom;
+    uint8_t transport_latency_c_to_p[3];
+    uint8_t transport_latency_p_to_c[3];
+    uint8_t phy_c_to_p;
+    uint8_t phy_p_to_c;
     uint8_t nse;
-    uint8_t bn_mtos;
-    uint8_t bn_stom;
-    uint8_t ft_mtos;
-    uint8_t ft_stom;
-    uint16_t max_pdu_mtos;
-    uint16_t max_pdu_stom;
+    uint8_t bn_c_to_p;
+    uint8_t bn_p_to_c;
+    uint8_t ft_c_to_p;
+    uint8_t ft_p_to_c;
+    uint16_t max_pdu_c_to_p;
+    uint16_t max_pdu_p_to_c;
     uint16_t iso_interval;
 } __attribute__((packed));
 
 #define BLE_HCI_LE_SUBEV_CIS_REQUEST            (0x1A)
 struct ble_hci_ev_le_subev_cis_request {
     uint8_t subev_code;
-    uint16_t conn_handle;
-    uint16_t cis_handle;
+    uint16_t acl_conn_handle;
+    uint16_t cis_conn_handle;
     uint8_t cig_id;
     uint8_t cis_id;
 } __attribute__((packed));
 
-#define BLE_HCI_LE_SUBEV_BIG_COMP               (0x1B)
-struct ble_hci_ev_le_subev_big_complete {
+#define BLE_HCI_LE_SUBEV_CREATE_BIG_COMPLETE    (0x1B)
+struct ble_hci_ev_le_subev_create_big_complete {
     uint8_t subev_code;
     uint8_t status;
     uint8_t big_handle;
     uint8_t big_sync_delay[3];
-    uint8_t transport_latency[3];
+    uint8_t transport_latency_big[3];
     uint8_t phy;
     uint8_t nse;
     uint8_t bn;
@@ -1860,31 +1886,31 @@ struct ble_hci_ev_le_subev_big_complete {
     uint8_t irc;
     uint16_t max_pdu;
     uint16_t iso_interval;
-    uint8_t bis_cnt;
-    uint16_t bis[0];
+    uint8_t num_bis;
+    uint16_t conn_handle[0];
 } __attribute__((packed));
 
-#define BLE_HCI_LE_SUBEV_BIG_TERMINATE_COMP     (0x1C)
-struct ble_hci_ev_le_subev_big_terminate_complete {
+#define BLE_HCI_LE_SUBEV_TERMINATE_BIG_COMPLETE (0x1C)
+struct ble_hci_ev_le_subev_terminate_big_complete {
     uint8_t subev_code;
     uint8_t big_handle;
     uint8_t reason;
 } __attribute__((packed));
 
-#define BLE_HCI_LE_SUBEV_BIG_SYNC_ESTAB         (0x1D)
+#define BLE_HCI_LE_SUBEV_BIG_SYNC_ESTABLISHED    (0x1D)
 struct ble_hci_ev_le_subev_big_sync_established {
     uint8_t subev_code;
     uint8_t status;
     uint8_t big_handle;
-    uint8_t transport_latency[3];
+    uint8_t transport_latency_big[3];
     uint8_t nse;
     uint8_t bn;
     uint8_t pto;
     uint8_t irc;
     uint16_t max_pdu;
     uint16_t iso_interval;
-    uint8_t bis_cnt;
-    uint16_t bis_handles[0];
+    uint8_t num_bis;
+    uint16_t conn_handle[0];
 } __attribute__((packed));
 
 #define BLE_HCI_LE_SUBEV_BIG_SYNC_LOST          (0x1E)


[mynewt-nimble] 08/09: nimble/ll: Remove ble_ll_pdu_tx_time_get

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 d9fbaccd3e525c625089608d24fda0e45e6bb821
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Fri Jan 27 01:08:43 2023 +0100

    nimble/ll: Remove ble_ll_pdu_tx_time_get
    
    Use ble_ll_pdu_us instead.
---
 nimble/controller/include/controller/ble_ll.h |  4 --
 nimble/controller/src/ble_ll.c                | 53 +--------------------------
 nimble/controller/src/ble_ll_adv.c            | 35 +++++++++---------
 nimble/controller/src/ble_ll_conn.c           | 21 +++++------
 nimble/controller/src/ble_ll_dtm.c            |  3 +-
 nimble/controller/src/ble_ll_scan_aux.c       |  3 +-
 nimble/controller/src/ble_ll_sched.c          |  5 ++-
 7 files changed, 37 insertions(+), 87 deletions(-)

diff --git a/nimble/controller/include/controller/ble_ll.h b/nimble/controller/include/controller/ble_ll.h
index 25a8f296..9fe3fb8f 100644
--- a/nimble/controller/include/controller/ble_ll.h
+++ b/nimble/controller/include/controller/ble_ll.h
@@ -495,10 +495,6 @@ int ble_ll_is_valid_random_addr(const uint8_t *addr);
 int ble_ll_is_valid_own_addr_type(uint8_t own_addr_type,
                                   const uint8_t *random_addr);
 
-/* Calculate the amount of time in microseconds a PDU with payload length of
- * 'payload_len' will take to transmit on a PHY 'phy_mode'. */
-uint32_t ble_ll_pdu_tx_time_get(uint16_t payload_len, int phy_mode);
-
 /* Calculate maximum octets of PDU payload which can be transmitted during
  * 'usecs' on a PHY 'phy_mode'. */
 uint16_t ble_ll_pdu_max_tx_octets_get(uint32_t usecs, int phy_mode);
diff --git a/nimble/controller/src/ble_ll.c b/nimble/controller/src/ble_ll.c
index 9b9fc4e0..913f68cf 100644
--- a/nimble/controller/src/ble_ll.c
+++ b/nimble/controller/src/ble_ll.c
@@ -33,6 +33,7 @@
 #include "controller/ble_phy.h"
 #include "controller/ble_phy_trace.h"
 #include "controller/ble_ll.h"
+#include "controller/ble_ll_pdu.h"
 #include "controller/ble_ll_adv.h"
 #include "controller/ble_ll_sched.h"
 #include "controller/ble_ll_scan.h"
@@ -377,25 +378,6 @@ uint8_t g_dev_addr[BLE_DEV_ADDR_LEN];
 /** Our random address */
 uint8_t g_random_addr[BLE_DEV_ADDR_LEN];
 
-static const uint16_t g_ble_ll_pdu_header_tx_time[BLE_PHY_NUM_MODE] =
-{
-    [BLE_PHY_MODE_1M] =
-            (BLE_LL_PREAMBLE_LEN + BLE_LL_ACC_ADDR_LEN + BLE_LL_CRC_LEN +
-                    BLE_LL_PDU_HDR_LEN) << 3,
-    [BLE_PHY_MODE_2M] =
-            (BLE_LL_PREAMBLE_LEN * 2 + BLE_LL_ACC_ADDR_LEN + BLE_LL_CRC_LEN +
-                    BLE_LL_PDU_HDR_LEN) << 2,
-    /* For Coded PHY we have exact TX times provided by specification:
-     * - Preamble, Access Address, CI, TERM1 (always coded as S=8)
-     * - PDU, CRC, TERM2 (coded as S=2 or S=8)
-     * (Vol 6, Part B, 2.2).
-     */
-    [BLE_PHY_MODE_CODED_125KBPS] =
-            (80 + 256 + 16 + 24 + 8 * (BLE_LL_PDU_HDR_LEN * 8 + 24 + 3)),
-    [BLE_PHY_MODE_CODED_500KBPS] =
-            (80 + 256 + 16 + 24 + 2 * (BLE_LL_PDU_HDR_LEN * 8 + 24 + 3)),
-};
-
 /**
  * Counts the number of advertising PDU's received, by type. For advertising
  * PDU's that contain a destination address, we still count these packets even
@@ -1700,37 +1682,6 @@ ble_ll_reset(void)
     return rc;
 }
 
-uint32_t
-ble_ll_pdu_tx_time_get(uint16_t payload_len, int phy_mode)
-{
-    uint32_t usecs;
-
-#if (BLE_LL_BT5_PHY_SUPPORTED)
-    if (phy_mode == BLE_PHY_MODE_1M) {
-        /* 8 usecs per byte */
-        usecs = payload_len << 3;
-    } else if (phy_mode == BLE_PHY_MODE_2M) {
-        /* 4 usecs per byte */
-        usecs = payload_len << 2;
-    } else if (phy_mode == BLE_PHY_MODE_CODED_125KBPS) {
-        /* S=8 => 8 * 8 = 64 usecs per byte */
-        usecs = payload_len << 6;
-    } else if (phy_mode == BLE_PHY_MODE_CODED_500KBPS) {
-        /* S=2 => 2 * 8 = 16 usecs per byte */
-        usecs = payload_len << 4;
-    } else {
-        BLE_LL_ASSERT(0);
-    }
-
-    usecs += g_ble_ll_pdu_header_tx_time[phy_mode];
-#else
-    usecs = (((payload_len) + BLE_LL_PDU_HDR_LEN + BLE_LL_ACC_ADDR_LEN
-            + BLE_LL_PREAMBLE_LEN + BLE_LL_CRC_LEN) << 3);
-#endif
-
-    return usecs;
-}
-
 uint16_t
 ble_ll_pdu_max_tx_octets_get(uint32_t usecs, int phy_mode)
 {
@@ -1739,7 +1690,7 @@ ble_ll_pdu_max_tx_octets_get(uint32_t usecs, int phy_mode)
 
     BLE_LL_ASSERT(phy_mode < BLE_PHY_NUM_MODE);
 
-    header_tx_time = g_ble_ll_pdu_header_tx_time[phy_mode];
+    header_tx_time = ble_ll_pdu_us(0, phy_mode);
 
     /*
      * Current conn max tx time can be too short to even send a packet header
diff --git a/nimble/controller/src/ble_ll_adv.c b/nimble/controller/src/ble_ll_adv.c
index 125b6247..6f35c7e5 100644
--- a/nimble/controller/src/ble_ll_adv.c
+++ b/nimble/controller/src/ble_ll_adv.c
@@ -29,6 +29,7 @@
 #include "controller/ble_phy.h"
 #include "controller/ble_hw.h"
 #include "controller/ble_ll.h"
+#include "controller/ble_ll_pdu.h"
 #include "controller/ble_ll_hci.h"
 #include "controller/ble_ll_adv.h"
 #include "controller/ble_ll_sched.h"
@@ -781,7 +782,7 @@ ble_ll_adv_aux_pdu_make(uint8_t *dptr, void *pducb_arg, uint8_t *hdr_byte)
             offset = 0;
         } else if (advsm->rx_ble_hdr) {
             offset = ble_ll_tmr_t2u(AUX_NEXT(advsm)->start_time - advsm->rx_ble_hdr->beg_cputime);
-            offset -= (advsm->rx_ble_hdr->rem_usecs + ble_ll_pdu_tx_time_get(12, advsm->sec_phy) + BLE_LL_IFS);
+            offset -= (advsm->rx_ble_hdr->rem_usecs + ble_ll_pdu_us(12, advsm->sec_phy) + BLE_LL_IFS);
         } else {
             offset = ble_ll_tmr_t2u(AUX_NEXT(advsm)->start_time - aux->start_time);
         }
@@ -1206,7 +1207,7 @@ ble_ll_adv_set_sched(struct ble_ll_adv_sm *advsm)
     /* Set end time to maximum time this schedule item may take */
 #if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_EXT_ADV)
     if (advsm->props & BLE_HCI_LE_SET_EXT_ADV_PROP_LEGACY) {
-        max_usecs = ble_ll_pdu_tx_time_get(advsm->adv_pdu_len, BLE_PHY_MODE_1M);
+        max_usecs = ble_ll_pdu_us(advsm->adv_pdu_len, BLE_PHY_MODE_1M);
 
         if (advsm->props & BLE_HCI_LE_SET_EXT_ADV_PROP_DIRECTED) {
             max_usecs += BLE_LL_SCHED_DIRECT_ADV_MAX_USECS;
@@ -1218,10 +1219,10 @@ ble_ll_adv_set_sched(struct ble_ll_adv_sm *advsm)
          * In ADV_EXT_IND we always set only ADI and AUX so the payload length
          * is always 7 bytes.
          */
-        max_usecs = ble_ll_pdu_tx_time_get(7, advsm->pri_phy);
+        max_usecs = ble_ll_pdu_us(7, advsm->pri_phy);
     }
 #else
-    max_usecs = ble_ll_pdu_tx_time_get(advsm->adv_pdu_len, BLE_PHY_MODE_1M);
+    max_usecs = ble_ll_pdu_us(advsm->adv_pdu_len, BLE_PHY_MODE_1M);
 
     if (advsm->props & BLE_HCI_LE_SET_EXT_ADV_PROP_DIRECTED) {
         max_usecs += BLE_LL_SCHED_DIRECT_ADV_MAX_USECS;
@@ -1509,7 +1510,7 @@ ble_ll_adv_aux_check_data_itvl(struct ble_ll_adv_sm *advsm, uint16_t props,
      * account, but we do not support max skip anyway for now.
      */
 
-    max_usecs = 3 * (ble_ll_pdu_tx_time_get(7, pri_phy) + 300) +
+    max_usecs = 3 * (ble_ll_pdu_us(7, pri_phy) + 300) +
                 BLE_LL_MAFS + MYNEWT_VAL(BLE_LL_SCHED_AUX_MAFS_DELAY);
 
     data_offset = 0;
@@ -1518,7 +1519,7 @@ ble_ll_adv_aux_check_data_itvl(struct ble_ll_adv_sm *advsm, uint16_t props,
         pdu_len = ble_ll_adv_aux_calculate_payload(advsm, props, data, data_offset,
                                                    &data_len, &ext_hdr_flags);
 
-        max_usecs += ble_ll_pdu_tx_time_get(pdu_len, sec_phy);
+        max_usecs += ble_ll_pdu_us(pdu_len, sec_phy);
         max_usecs += BLE_LL_MAFS + MYNEWT_VAL(BLE_LL_SCHED_AUX_CHAIN_MAFS_DELAY);
 
         data_offset += data_len;
@@ -1578,7 +1579,7 @@ ble_ll_adv_aux_schedule_next(struct ble_ll_adv_sm *advsm)
     BLE_LL_ASSERT(rem_data_len > 0);
 
     ble_ll_adv_aux_calculate(advsm, aux_next, next_data_offset);
-    max_usecs = ble_ll_pdu_tx_time_get(aux_next->payload_len, advsm->sec_phy);
+    max_usecs = ble_ll_pdu_us(aux_next->payload_len, advsm->sec_phy);
 
     aux_next->start_time = aux->sch.end_time +
                            ble_ll_tmr_u2t_up(BLE_LL_MAFS +
@@ -1623,13 +1624,13 @@ ble_ll_adv_aux_schedule_first(struct ble_ll_adv_sm *advsm)
 
     /* Set end time to maximum time this schedule item may take */
     if (advsm->props & BLE_HCI_LE_SET_EXT_ADV_PROP_CONNECTABLE) {
-        max_usecs = ble_ll_pdu_tx_time_get(aux->payload_len, advsm->sec_phy) +
+        max_usecs = ble_ll_pdu_us(aux->payload_len, advsm->sec_phy) +
                     BLE_LL_IFS +
                     /* AUX_CONN_REQ */
-                    ble_ll_pdu_tx_time_get(34 + 14, advsm->sec_phy)  +
+                    ble_ll_pdu_us(34 + 14, advsm->sec_phy)  +
                     BLE_LL_IFS +
                     /* AUX_CONN_RSP */
-                    ble_ll_pdu_tx_time_get(14, advsm->sec_phy);
+                    ble_ll_pdu_us(14, advsm->sec_phy);
     } else if (advsm->props & BLE_HCI_LE_SET_EXT_ADV_PROP_SCANNABLE) {
         /* For scannable advertising we need to calculate how much time we
          * need for AUX_ADV_IND along with AUX_SCAN_REQ, AUX_SCAN_RSP and
@@ -1641,16 +1642,16 @@ ble_ll_adv_aux_schedule_first(struct ble_ll_adv_sm *advsm)
          *  2. length of AUX_ADV_IND is calculated by special function:
          *      ble_ll_adv_aux_scannable_pdu_payload_len()
          */
-        max_usecs = ble_ll_pdu_tx_time_get(ble_ll_adv_aux_scannable_pdu_payload_len(advsm),
+        max_usecs = ble_ll_pdu_us(ble_ll_adv_aux_scannable_pdu_payload_len(advsm),
                                            advsm->sec_phy) +
                     BLE_LL_IFS +
                     /* AUX_SCAN_REQ */
-                    ble_ll_pdu_tx_time_get(12, advsm->sec_phy)  +
+                    ble_ll_pdu_us(12, advsm->sec_phy)  +
                     BLE_LL_IFS +
                     /* AUX_SCAN_RSP */
-                    ble_ll_pdu_tx_time_get(aux->payload_len, advsm->sec_phy);
+                    ble_ll_pdu_us(aux->payload_len, advsm->sec_phy);
     } else {
-        max_usecs = ble_ll_pdu_tx_time_get(aux->payload_len, advsm->sec_phy);
+        max_usecs = ble_ll_pdu_us(aux->payload_len, advsm->sec_phy);
     }
 
     sch = &aux->sch;
@@ -2385,7 +2386,7 @@ ble_ll_adv_periodic_schedule_first(struct ble_ll_adv_sm *advsm,
     ble_ll_adv_sync_calculate(advsm, sync, 0, chan);
 
     /* sync is always non-connectable and non-scannable*/
-    max_usecs = ble_ll_pdu_tx_time_get(sync->payload_len, advsm->sec_phy);
+    max_usecs = ble_ll_pdu_us(sync->payload_len, advsm->sec_phy);
 
     sch = &sync->sch;
 
@@ -2471,7 +2472,7 @@ ble_ll_adv_periodic_schedule_next(struct ble_ll_adv_sm *advsm)
                                  advsm->periodic_chanmap);
 
     ble_ll_adv_sync_calculate(advsm, sync_next, next_data_offset, chan);
-    max_usecs = ble_ll_pdu_tx_time_get(sync_next->payload_len, advsm->sec_phy);
+    max_usecs = ble_ll_pdu_us(sync_next->payload_len, advsm->sec_phy);
 
     sync_next->start_time = sync->sch.end_time +
                             ble_ll_tmr_u2t_up(BLE_LL_MAFS +
@@ -3862,7 +3863,7 @@ ble_ll_adv_periodic_check_data_itvl(uint16_t payload_len, uint16_t props,
     while (offset < payload_len) {
         pdu_len = ble_ll_adv_sync_get_pdu_len(payload_len, &offset, props);
 
-        max_usecs += ble_ll_pdu_tx_time_get(pdu_len, phy);
+        max_usecs += ble_ll_pdu_us(pdu_len, phy);
         max_usecs += BLE_LL_MAFS + MYNEWT_VAL(BLE_LL_SCHED_AUX_CHAIN_MAFS_DELAY);
     }
 
diff --git a/nimble/controller/src/ble_ll_conn.c b/nimble/controller/src/ble_ll_conn.c
index 4f12f143..379a59a7 100644
--- a/nimble/controller/src/ble_ll_conn.c
+++ b/nimble/controller/src/ble_ll_conn.c
@@ -28,6 +28,7 @@
 #include "nimble/hci_common.h"
 #include "nimble/transport.h"
 #include "controller/ble_ll.h"
+#include "controller/ble_ll_pdu.h"
 #include "controller/ble_ll_conn.h"
 #include "controller/ble_ll_hci.h"
 #include "controller/ble_ll_scan.h"
@@ -1268,8 +1269,8 @@ ble_ll_conn_tx_pdu(struct ble_ll_conn_sm *connsm)
 #endif
 
         ticks = (BLE_LL_IFS * 3) + connsm->ota_max_rx_time +
-            ble_ll_pdu_tx_time_get(next_txlen, tx_phy_mode) +
-            ble_ll_pdu_tx_time_get(cur_txlen, tx_phy_mode);
+                ble_ll_pdu_us(next_txlen, tx_phy_mode) +
+                ble_ll_pdu_us(cur_txlen, tx_phy_mode);
 
 #if MYNEWT_VAL(BLE_LL_ROLE_CENTRAL)
         if (connsm->conn_role == BLE_LL_CONN_ROLE_CENTRAL) {
@@ -1677,10 +1678,10 @@ ble_ll_conn_can_send_next_pdu(struct ble_ll_conn_sm *connsm, uint32_t begtime,
             if (rem_bytes > connsm->eff_max_tx_octets) {
                 rem_bytes = connsm->eff_max_tx_octets;
             }
-            usecs = ble_ll_pdu_tx_time_get(rem_bytes, tx_phy_mode);
+            usecs = ble_ll_pdu_us(rem_bytes, tx_phy_mode);
         } else {
             /* We will send empty pdu (just a LL header) */
-            usecs = ble_ll_pdu_tx_time_get(0, tx_phy_mode);
+            usecs = ble_ll_pdu_us(0, tx_phy_mode);
         }
         usecs += (BLE_LL_IFS * 2) + connsm->ota_max_rx_time;
 
@@ -2132,7 +2133,7 @@ ble_ll_conn_update_eff_data_len(struct ble_ll_conn_sm *connsm)
 #else
         phy_mode = BLE_PHY_MODE_1M;
 #endif
-        ota_time = ble_ll_pdu_tx_time_get(connsm->eff_max_rx_octets, phy_mode);
+        ota_time = ble_ll_pdu_us(connsm->eff_max_rx_octets, phy_mode);
         connsm->ota_max_rx_time = min(ota_time, connsm->eff_max_rx_time);
     }
 
@@ -2787,7 +2788,7 @@ ble_ll_conn_created(struct ble_ll_conn_sm *connsm, struct ble_mbuf_hdr *rxhdr)
 
         usecs = rxhdr->rem_usecs + 1250 +
                 (connsm->tx_win_off * BLE_LL_CONN_TX_WIN_USECS) +
-                ble_ll_pdu_tx_time_get(BLE_CONNECT_REQ_LEN,
+                ble_ll_pdu_us(BLE_CONNECT_REQ_LEN,
                                        rxhdr->rxinfo.phy_mode);
 
         if (rxhdr->rxinfo.channel < BLE_PHY_NUM_DATA_CHANS) {
@@ -3689,7 +3690,7 @@ ble_ll_conn_rx_isr_end(uint8_t *rxbuf, struct ble_mbuf_hdr *rxhdr)
     rx_phy_mode = BLE_PHY_MODE_1M;
 #endif
     add_usecs = rxhdr->rem_usecs +
-            ble_ll_pdu_tx_time_get(rx_pyld_len, rx_phy_mode);
+                ble_ll_pdu_us(rx_pyld_len, rx_phy_mode);
 
     /*
      * Check the packet CRC. A connection event can continue even if the
@@ -4341,11 +4342,9 @@ ble_ll_conn_subrate_set(struct ble_ll_conn_sm *connsm,
 #endif
 
 #define MAX_TIME_UNCODED(_maxbytes) \
-        ble_ll_pdu_tx_time_get(_maxbytes + BLE_LL_DATA_MIC_LEN, \
-                               BLE_PHY_MODE_1M);
+    ble_ll_pdu_us(_maxbytes + BLE_LL_DATA_MIC_LEN, BLE_PHY_MODE_1M);
 #define MAX_TIME_CODED(_maxbytes) \
-        ble_ll_pdu_tx_time_get(_maxbytes + BLE_LL_DATA_MIC_LEN, \
-                               BLE_PHY_MODE_CODED_125KBPS);
+    ble_ll_pdu_us(_maxbytes + BLE_LL_DATA_MIC_LEN, BLE_PHY_MODE_CODED_125KBPS);
 
 /**
  * Called to reset the connection module. When this function is called the
diff --git a/nimble/controller/src/ble_ll_dtm.c b/nimble/controller/src/ble_ll_dtm.c
index b1e4f6f0..07e25fe2 100644
--- a/nimble/controller/src/ble_ll_dtm.c
+++ b/nimble/controller/src/ble_ll_dtm.c
@@ -26,6 +26,7 @@
 #include "os/os.h"
 #include "stats/stats.h"
 #include "controller/ble_ll.h"
+#include "controller/ble_ll_pdu.h"
 #include "controller/ble_phy.h"
 #include "controller/ble_ll_sched.h"
 #include "controller/ble_ll_rfmgmt.h"
@@ -269,7 +270,7 @@ ble_ll_dtm_calculate_itvl(struct dtm_ctx *ctx, uint8_t len,
     uint32_t itvl_usec;
 
     /* Calculate interval as per spec Bluetooth 5.0 Vol 6. Part F, 4.1.6 */
-    l = ble_ll_pdu_tx_time_get(len + BLE_LL_PDU_HDR_LEN, phy_mode);
+    l = ble_ll_pdu_us(len, phy_mode);
     itvl_usec = ((l + 249 + 624) / 625) * 625;
 
 #if MYNEWT_VAL(BLE_LL_DTM_EXTENSIONS)
diff --git a/nimble/controller/src/ble_ll_scan_aux.c b/nimble/controller/src/ble_ll_scan_aux.c
index f7c92d53..45f9ce46 100644
--- a/nimble/controller/src/ble_ll_scan_aux.c
+++ b/nimble/controller/src/ble_ll_scan_aux.c
@@ -31,6 +31,7 @@
 #include "controller/ble_phy.h"
 #include "controller/ble_hw.h"
 #include "controller/ble_ll.h"
+#include "controller/ble_ll_pdu.h"
 #include "controller/ble_ll_sched.h"
 #include "controller/ble_ll_scan.h"
 #include "controller/ble_ll_scan_aux.h"
@@ -747,7 +748,7 @@ ble_ll_scan_aux_sched(struct ble_ll_scan_aux_data *aux, uint32_t pdu_time,
         return -1;
     }
 
-    max_aux_time_us = ble_ll_pdu_tx_time_get(MYNEWT_VAL(BLE_LL_SCHED_SCAN_AUX_PDU_LEN),
+    max_aux_time_us = ble_ll_pdu_us(MYNEWT_VAL(BLE_LL_SCHED_SCAN_AUX_PDU_LEN),
                                              ble_ll_phy_to_phy_mode(aux->sec_phy, 0));
 
     rc = ble_ll_sched_scan_aux(&aux->sch, pdu_time, pdu_time_rem, offset_us,
diff --git a/nimble/controller/src/ble_ll_sched.c b/nimble/controller/src/ble_ll_sched.c
index cf64e82f..513257db 100644
--- a/nimble/controller/src/ble_ll_sched.c
+++ b/nimble/controller/src/ble_ll_sched.c
@@ -23,6 +23,7 @@
 #include "ble/xcvr.h"
 #include "controller/ble_phy.h"
 #include "controller/ble_ll.h"
+#include "controller/ble_ll_pdu.h"
 #include "controller/ble_ll_sched.h"
 #include "controller/ble_ll_adv.h"
 #include "controller/ble_ll_scan.h"
@@ -680,7 +681,7 @@ ble_ll_sched_sync_reschedule(struct ble_ll_sched_item *sch,
 
     ble_ll_tmr_sub(&start_time, &start_time_rem_usecs, window_widening);
 
-    dur = ble_ll_pdu_tx_time_get(MYNEWT_VAL(BLE_LL_SCHED_SCAN_SYNC_PDU_LEN),
+    dur = ble_ll_pdu_us(MYNEWT_VAL(BLE_LL_SCHED_SCAN_SYNC_PDU_LEN),
                                  phy_mode);
     end_time = start_time + ble_ll_tmr_u2t(dur);
 
@@ -729,7 +730,7 @@ ble_ll_sched_sync(struct ble_ll_sched_item *sch,
 
     ble_ll_tmr_add(&start_time, &start_time_rem_usecs, offset);
 
-    dur = ble_ll_pdu_tx_time_get(MYNEWT_VAL(BLE_LL_SCHED_SCAN_SYNC_PDU_LEN),
+    dur = ble_ll_pdu_us(MYNEWT_VAL(BLE_LL_SCHED_SCAN_SYNC_PDU_LEN),
                                   phy_mode);
     end_time = start_time + ble_ll_tmr_u2t(dur);
 


[mynewt-nimble] 06/09: nimble/ll: Rename helper to calculate AA

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 32814579e6c7c98da1de0b356280f1bcf5dc3809
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Fri Jan 27 00:50:58 2023 +0100

    nimble/ll: Rename helper to calculate AA
    
    This is for consistency wither other helpers which use shorter name.
---
 nimble/controller/include/controller/ble_ll_utils.h | 2 +-
 nimble/controller/src/ble_ll_adv.c                  | 4 ++--
 nimble/controller/src/ble_ll_conn.c                 | 2 +-
 nimble/controller/src/ble_ll_utils.c                | 2 +-
 4 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/nimble/controller/include/controller/ble_ll_utils.h b/nimble/controller/include/controller/ble_ll_utils.h
index 4d7e7e70..fe1bca9f 100644
--- a/nimble/controller/include/controller/ble_ll_utils.h
+++ b/nimble/controller/include/controller/ble_ll_utils.h
@@ -29,7 +29,7 @@
 #define IN_RANGE(_n, _min, _max) (((_n) >= (_min)) && ((_n) <= (_max)))
 
 int ble_ll_utils_verify_aa(uint32_t aa);
-uint32_t ble_ll_utils_calc_access_addr(void);
+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);
diff --git a/nimble/controller/src/ble_ll_adv.c b/nimble/controller/src/ble_ll_adv.c
index 49228246..125b6247 100644
--- a/nimble/controller/src/ble_ll_adv.c
+++ b/nimble/controller/src/ble_ll_adv.c
@@ -2612,7 +2612,7 @@ ble_ll_adv_sm_start_periodic(struct ble_ll_adv_sm *advsm)
     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();
-    advsm->periodic_access_addr = ble_ll_utils_calc_access_addr();
+    advsm->periodic_access_addr = ble_ll_utils_calc_aa();
     advsm->periodic_channel_id = ((advsm->periodic_access_addr & 0xffff0000) >> 16) ^
                                  (advsm->periodic_access_addr & 0x0000ffff);
     advsm->periodic_crcinit = ble_ll_rand() & 0xffffff;
@@ -2767,7 +2767,7 @@ ble_ll_adv_sm_start(struct ble_ll_adv_sm *advsm)
 
 #if MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_CSA2)
     advsm->event_cntr = 0;
-    access_addr = ble_ll_utils_calc_access_addr();
+    access_addr = ble_ll_utils_calc_aa();
     advsm->channel_id = ((access_addr & 0xffff0000) >> 16) ^
                          (access_addr & 0x0000ffff);
 #endif
diff --git a/nimble/controller/src/ble_ll_conn.c b/nimble/controller/src/ble_ll_conn.c
index 9b926010..4f12f143 100644
--- a/nimble/controller/src/ble_ll_conn.c
+++ b/nimble/controller/src/ble_ll_conn.c
@@ -1769,7 +1769,7 @@ ble_ll_conn_central_common_init(struct ble_ll_conn_sm *connsm)
 #endif
 
     /*  Calculate random access address and crc initialization value */
-    connsm->access_addr = ble_ll_utils_calc_access_addr();
+    connsm->access_addr = ble_ll_utils_calc_aa();
     connsm->crcinit = ble_ll_rand() & 0xffffff;
 
     /* Set initial schedule callback */
diff --git a/nimble/controller/src/ble_ll_utils.c b/nimble/controller/src/ble_ll_utils.c
index 1259f94d..1921ee72 100644
--- a/nimble/controller/src/ble_ll_utils.c
+++ b/nimble/controller/src/ble_ll_utils.c
@@ -137,7 +137,7 @@ ble_ll_utils_verify_aa(uint32_t aa)
 }
 
 uint32_t
-ble_ll_utils_calc_access_addr(void)
+ble_ll_utils_calc_aa(void)
 {
     uint32_t aa;
 


[mynewt-nimble] 04/09: nimble/ll: Add helper to calculate BIG AA

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 5652310e74ff6e03e086ace9673924cfbc0d3852
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Fri Jan 27 12:58:25 2023 +0100

    nimble/ll: Add helper to calculate BIG AA
---
 .../controller/include/controller/ble_ll_utils.h   |  1 +
 nimble/controller/src/ble_ll_utils.c               | 26 ++++++++++++++++++++++
 2 files changed, 27 insertions(+)

diff --git a/nimble/controller/include/controller/ble_ll_utils.h b/nimble/controller/include/controller/ble_ll_utils.h
index 5739e046..3e28fcb4 100644
--- a/nimble/controller/include/controller/ble_ll_utils.h
+++ b/nimble/controller/include/controller/ble_ll_utils.h
@@ -30,6 +30,7 @@
 
 uint32_t ble_ll_utils_calc_access_addr(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_dci_csa2(uint16_t counter, uint16_t chan_id,
                               uint8_t num_used_chans, const uint8_t *chan_map);
diff --git a/nimble/controller/src/ble_ll_utils.c b/nimble/controller/src/ble_ll_utils.c
index 1c65a7cf..4f1c679b 100644
--- a/nimble/controller/src/ble_ll_utils.c
+++ b/nimble/controller/src/ble_ll_utils.c
@@ -183,6 +183,32 @@ ble_ll_utils_calc_seed_aa(void)
     return seed_aa;
 }
 
+uint32_t
+ble_ll_utils_calc_big_aa(uint32_t seed_aa, uint32_t n)
+{
+    uint32_t d;
+    uint32_t dw;
+
+    /* Core 5.3, Vol 6, Part B, 2.1.2 */
+    /* TODO simplify? */
+    d = ((35 * n) + 42) % 128;
+    dw = (!!(d & (1 << 0)) << 31) |
+         (!!(d & (1 << 0)) << 30) |
+         (!!(d & (1 << 0)) << 29) |
+         (!!(d & (1 << 0)) << 28) |
+         (!!(d & (1 << 0)) << 27) |
+         (!!(d & (1 << 0)) << 26) |
+         (!!(d & (1 << 1)) << 25) |
+         (!!(d & (1 << 6)) << 24) |
+         (!!(d & (1 << 1)) << 23) |
+         (!!(d & (1 << 5)) << 21) |
+         (!!(d & (1 << 4)) << 20) |
+         (!!(d & (1 << 3)) << 18) |
+         (!!(d & (1 << 2)) << 17);
+
+    return seed_aa ^ dw;
+}
+
 uint8_t
 ble_ll_utils_remapped_channel(uint8_t remap_index, const uint8_t *chanmap)
 {


[mynewt-nimble] 07/09: nimble/ll: Add ble_ll_pdu

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 c7381e887766caaaa9f7fac81fe80d3af21d2099
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Thu Jan 19 20:48:23 2023 +0100

    nimble/ll: Add ble_ll_pdu
    
    This is small step to declutter ble_ll and cleanup defs for PDU-related
    defs and helpers.
---
 nimble/controller/include/controller/ble_ll_pdu.h | 42 ++++++++++++++++
 nimble/controller/src/ble_ll_pdu.c                | 58 +++++++++++++++++++++++
 2 files changed, 100 insertions(+)

diff --git a/nimble/controller/include/controller/ble_ll_pdu.h b/nimble/controller/include/controller/ble_ll_pdu.h
new file mode 100644
index 00000000..60eef833
--- /dev/null
+++ b/nimble/controller/include/controller/ble_ll_pdu.h
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef H_BLE_LL_PDU_
+#define H_BLE_LL_PDU_
+
+#include <stdint.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define BLE_LL_PDU_PREAMBLE_1M_LEN  (1)
+#define BLE_LL_PDU_PREAMBLE_2M_LEN  (2)
+#define BLE_LL_PDU_AA_LEN           (4)
+#define BLE_LL_PDU_HEADER_LEN       (2)
+#define BLE_LL_PDU_CRC_LEN          (3)
+
+uint32_t ble_ll_pdu_syncword_us(uint8_t phy_mode);
+uint32_t ble_ll_pdu_us(uint8_t payload_len, uint8_t phy_mode);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* H_BLE_LL_PDU_ */
diff --git a/nimble/controller/src/ble_ll_pdu.c b/nimble/controller/src/ble_ll_pdu.c
new file mode 100644
index 00000000..bcbb5ff0
--- /dev/null
+++ b/nimble/controller/src/ble_ll_pdu.c
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <controller/ble_phy.h>
+#include <controller/ble_ll_pdu.h>
+
+static const uint16_t syncword_len[] = {
+    [BLE_PHY_MODE_1M] = (BLE_LL_PDU_PREAMBLE_1M_LEN + BLE_LL_PDU_AA_LEN) * 8,
+    [BLE_PHY_MODE_2M] = (BLE_LL_PDU_PREAMBLE_2M_LEN + BLE_LL_PDU_AA_LEN) * 4,
+    [BLE_PHY_MODE_CODED_125KBPS] = 80 + 256 + 16 + 24,
+    [BLE_PHY_MODE_CODED_500KBPS] = 80 + 256 + 16 + 24,
+};
+
+static const uint16_t payload0_len[] = {
+    [BLE_PHY_MODE_1M] = (BLE_LL_PDU_PREAMBLE_1M_LEN + BLE_LL_PDU_AA_LEN +
+                         BLE_LL_PDU_HEADER_LEN + BLE_LL_PDU_CRC_LEN) * 8,
+    [BLE_PHY_MODE_2M] = (BLE_LL_PDU_PREAMBLE_2M_LEN + BLE_LL_PDU_AA_LEN +
+                         BLE_LL_PDU_HEADER_LEN + BLE_LL_PDU_CRC_LEN) * 4,
+    [BLE_PHY_MODE_CODED_125KBPS] = 80 + 256 + 16 + 24 +
+                                   8 * (BLE_LL_PDU_HEADER_LEN * 8 + 24 + 3),
+    [BLE_PHY_MODE_CODED_500KBPS] = 80 + 256 + 16 + 24 +
+                                   2 * (BLE_LL_PDU_HEADER_LEN * 8 + 24 + 3),
+};
+
+static const uint8_t us_per_octet[] = {
+    [BLE_PHY_MODE_1M] = 8,
+    [BLE_PHY_MODE_2M] = 4,
+    [BLE_PHY_MODE_CODED_125KBPS] = 64,
+    [BLE_PHY_MODE_CODED_500KBPS] = 16,
+};
+
+uint32_t
+ble_ll_pdu_syncword_us(uint8_t phy_mode)
+{
+    return syncword_len[phy_mode];
+}
+
+uint32_t
+ble_ll_pdu_us(uint8_t payload_len, uint8_t phy_mode)
+{
+    return payload0_len[phy_mode] + (payload_len * us_per_octet[phy_mode]);
+}


[mynewt-nimble] 03/09: nimble/ll: Add helper to calculate Seed AA

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 a7861f3c24c67a16d24cd169454ae9904bac743c
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Sat Feb 26 21:36:21 2022 +0100

    nimble/ll: Add helper to calculate Seed AA
---
 .../controller/include/controller/ble_ll_utils.h   |  1 +
 nimble/controller/src/ble_ll_utils.c               | 39 ++++++++++++++++++++++
 2 files changed, 40 insertions(+)

diff --git a/nimble/controller/include/controller/ble_ll_utils.h b/nimble/controller/include/controller/ble_ll_utils.h
index added990..5739e046 100644
--- a/nimble/controller/include/controller/ble_ll_utils.h
+++ b/nimble/controller/include/controller/ble_ll_utils.h
@@ -29,6 +29,7 @@
 #define IN_RANGE(_n, _min, _max) (((_n) >= (_min)) && ((_n) <= (_max)))
 
 uint32_t ble_ll_utils_calc_access_addr(void);
+uint32_t ble_ll_utils_calc_seed_aa(void);
 uint8_t ble_ll_utils_remapped_channel(uint8_t remap_index, const uint8_t *chanmap);
 uint8_t ble_ll_utils_dci_csa2(uint16_t counter, uint16_t chan_id,
                               uint8_t num_used_chans, const uint8_t *chan_map);
diff --git a/nimble/controller/src/ble_ll_utils.c b/nimble/controller/src/ble_ll_utils.c
index a2507ad2..1c65a7cf 100644
--- a/nimble/controller/src/ble_ll_utils.c
+++ b/nimble/controller/src/ble_ll_utils.c
@@ -144,6 +144,45 @@ ble_ll_utils_calc_access_addr(void)
     return aa;
 }
 
+uint32_t
+ble_ll_utils_calc_seed_aa(void)
+{
+    uint32_t seed_aa;
+
+    while (1) {
+        seed_aa = ble_ll_rand();
+
+        /* saa(19) == saa(15) */
+        if (!!(seed_aa & (1 << 19)) != !!(seed_aa & (1 << 15))) {
+            continue;
+        }
+
+        /* saa(22) = saa(16) */
+        if (!!(seed_aa & (1 << 22)) != !!(seed_aa & (1 << 16))) {
+            continue;
+        }
+
+        /* saa(22) != saa(15) */
+        if (!!(seed_aa & (1 << 22)) == !!(seed_aa & (1 << 15))) {
+            continue;
+        }
+
+        /* saa(25) == 0 */
+        if (seed_aa & (1 << 25)) {
+            continue;
+        }
+
+        /* saa(23) == 1 */
+        if (!(seed_aa & (1 << 23))) {
+            continue;
+        }
+
+        break;
+    }
+
+    return seed_aa;
+}
+
 uint8_t
 ble_ll_utils_remapped_channel(uint8_t remap_index, const uint8_t *chanmap)
 {