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 2019/11/05 12:49:20 UTC

[mynewt-nimble] branch master updated (9c84283 -> d2853c9)

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 9c84283  nimble/hci: Fix incorrect debug asserts
     new 2c1d977  nimble/ll: Remove duplicated defines
     new 33171fb  nimble/ll: Update RFU symbol
     new 1506488  nimble/ll: Cleaup symbols
     new 517ef32  nimble/ll: Simplify aux_data updates
     new 5afa6ef  nimble/ll: Optimize extended header parsing for scanner
     new ffc76ac  nimble/ll: Add option to extend T_MAFS
     new d2853c9  nimble/ll: Fix setting sent_to_host flag

The 7 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_scan.h |   2 +-
 nimble/controller/src/ble_ll_adv.c                 |   6 +-
 nimble/controller/src/ble_ll_conn.c                |   2 +-
 nimble/controller/src/ble_ll_scan.c                | 333 ++++++++++-----------
 nimble/controller/src/ble_ll_sync.c                |   2 +-
 nimble/controller/syscfg.yml                       |  14 +
 7 files changed, 171 insertions(+), 190 deletions(-)


[mynewt-nimble] 06/07: nimble/ll: Add option to extend T_MAFS

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 ffc76ac0e9244450c973fc57de984bdabae2b92e
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Mon Nov 4 21:47:14 2019 +0100

    nimble/ll: Add option to extend T_MAFS
    
    By default we try to schedule any AUX/SYNC/CHAIN within T_MAFS to make
    extended/periodic advertising events as short as possible. However, on
    slower MCUs like Cortex-M0 300us (T_MAFS) may be too short to schedule
    and start TX of subsequent PDU and we may drop some packets. This patch
    adds an option to extend these times in scheduler.
    
    Note that it is strongly recommended to keep these new settings at
    default values unless you know what you are doing!
---
 nimble/controller/src/ble_ll_adv.c |  6 +++---
 nimble/controller/syscfg.yml       | 14 ++++++++++++++
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/nimble/controller/src/ble_ll_adv.c b/nimble/controller/src/ble_ll_adv.c
index 541f7c6..bb59070 100644
--- a/nimble/controller/src/ble_ll_adv.c
+++ b/nimble/controller/src/ble_ll_adv.c
@@ -1411,7 +1411,7 @@ ble_ll_adv_aux_schedule_next(struct ble_ll_adv_sm *advsm)
     max_usecs = ble_ll_pdu_tx_time_get(aux_next->payload_len, advsm->sec_phy);
 
     aux_next->start_time = aux->sch.end_time +
-                          ble_ll_usecs_to_ticks_round_up(BLE_LL_MAFS);
+                           ble_ll_usecs_to_ticks_round_up(BLE_LL_MAFS + MYNEWT_VAL(BLE_LL_SCHED_AUX_CHAIN_MAFS_DELAY));
 
     sch = &aux_next->sch;
     sch->start_time = aux_next->start_time - g_ble_ll_sched_offset_ticks;
@@ -1530,7 +1530,7 @@ ble_ll_adv_aux_set_start_time(struct ble_ll_adv_sm *advsm)
     adv_event_dur = (adv_pdu_dur * chans) + (9 * (chans - 1));
 
     advsm->aux[0].start_time = advsm->adv_event_start_time + adv_event_dur +
-                               ble_ll_usecs_to_ticks_round_up(BLE_LL_MAFS);
+                               ble_ll_usecs_to_ticks_round_up(BLE_LL_MAFS + MYNEWT_VAL(BLE_LL_SCHED_AUX_MAFS_DELAY));
 }
 
 static void
@@ -2267,7 +2267,7 @@ ble_ll_adv_periodic_schedule_next(struct ble_ll_adv_sm *advsm)
     max_usecs = ble_ll_pdu_tx_time_get(sync_next->payload_len, advsm->sec_phy);
 
     sync_next->start_time = sync->sch.end_time +
-                            ble_ll_usecs_to_ticks_round_up(BLE_LL_MAFS);
+                            ble_ll_usecs_to_ticks_round_up(BLE_LL_MAFS + MYNEWT_VAL(BLE_LL_SCHED_AUX_CHAIN_MAFS_DELAY));
 
     sch = &sync_next->sch;
     sch->start_time = sync_next->start_time - g_ble_ll_sched_offset_ticks;
diff --git a/nimble/controller/syscfg.yml b/nimble/controller/syscfg.yml
index 5c834c2..0fb3ef6 100644
--- a/nimble/controller/syscfg.yml
+++ b/nimble/controller/syscfg.yml
@@ -340,6 +340,20 @@ syscfg.defs:
             was sent from controller.
         value: -1
 
+# Below settings allow to change scheduler timings. These should be left at
+# default values unless you know what you are doing!
+    BLE_LL_SCHED_AUX_MAFS_DELAY:
+        description: >
+            Additional delay [us] between last ADV_EXT_IND and AUX_ADV_IND PDUs
+            when scheduling extended advertising event. This extends T_MAFS.
+        value: 0
+    BLE_LL_SCHED_AUX_CHAIN_MAFS_DELAY:
+        description: >
+            Additional delay [us] between consecutive AUX_CHAIN_IND PDUs
+            when scheduling extended or periodic advertising event. This extends
+            T_MAFS.
+        value: 0
+
 # deprecated settings (to be defunct/removed eventually)
     BLE_LL_DIRECT_TEST_MODE:
         description: use BLE_LL_DTM instead


[mynewt-nimble] 07/07: nimble/ll: Fix setting sent_to_host flag

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 d2853c9a204ea76a51211f83026db7e6e56c3590
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Mon Nov 4 21:47:24 2019 +0100

    nimble/ll: Fix setting sent_to_host flag
    
    There's no point in setting flag only to clear it in a moment - just
    make sure we don't set it when not needed.
---
 nimble/controller/src/ble_ll_scan.c | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)

diff --git a/nimble/controller/src/ble_ll_scan.c b/nimble/controller/src/ble_ll_scan.c
index 3e8cca0..548b0e9 100644
--- a/nimble/controller/src/ble_ll_scan.c
+++ b/nimble/controller/src/ble_ll_scan.c
@@ -2735,16 +2735,9 @@ ble_ll_hci_send_ext_adv_report(uint8_t ptype, uint8_t *adva, uint8_t adva_type,
         ble_ll_hci_event_send(hci_ev);
 
         if (aux_data) {
-            BLE_LL_AUX_SET_FLAG(aux_data, BLE_LL_SENT_EVENT_TO_HOST);
-            /* In case it is scannable AUX and we are waiting for scan response,
-             * let us clear BLE_LL_SENT_EVENT_TO_HOST flag as we consider scan response
-             * as separate report even aux_data is reused.
-             * This is needed to proper detect of not completed advertising
-             * reports.
-             */
-            if ((aux_data->evt_type & BLE_HCI_ADV_SCAN_MASK) &&
-                    !(aux_data->evt_type & BLE_HCI_ADV_SCAN_RSP_MASK)) {
-                BLE_LL_AUX_CLEAR_FLAG(aux_data, BLE_LL_SENT_EVENT_TO_HOST);
+            if (!(aux_data->evt_type & BLE_HCI_ADV_SCAN_MASK) ||
+                (aux_data->evt_type & BLE_HCI_ADV_SCAN_RSP_MASK)) {
+                BLE_LL_AUX_SET_FLAG(aux_data, BLE_LL_SENT_EVENT_TO_HOST);
             }
         }
 


[mynewt-nimble] 04/07: nimble/ll: Simplify aux_data updates

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 517ef3299d61d4e2e47124b8118cde594a8c6521
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Thu Oct 31 09:07:17 2019 +0100

    nimble/ll: Simplify aux_data updates
    
    This patch refactors ble_ll_scan_get_aux_data to avoid copying data
    from/to temporary aux_data and also fixes all comments which are
    confusing since they no longer describe actual behavior of function.
---
 nimble/controller/include/controller/ble_ll_scan.h |   2 +-
 nimble/controller/src/ble_ll_conn.c                |   2 +-
 nimble/controller/src/ble_ll_scan.c                | 200 ++++++++-------------
 3 files changed, 76 insertions(+), 128 deletions(-)

diff --git a/nimble/controller/include/controller/ble_ll_scan.h b/nimble/controller/include/controller/ble_ll_scan.h
index 5a44a62..e849dd6 100644
--- a/nimble/controller/include/controller/ble_ll_scan.h
+++ b/nimble/controller/include/controller/ble_ll_scan.h
@@ -250,7 +250,7 @@ int ble_ll_scan_adv_decode_addr(uint8_t pdu_type, uint8_t *rxbuf,
 
 #if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_EXT_ADV)
 /* Get aux ptr from ext advertising */
-int ble_ll_scan_get_aux_data(struct ble_mbuf_hdr *ble_hdr, uint8_t *rxbuf);
+int ble_ll_scan_update_aux_data(struct ble_mbuf_hdr *ble_hdr, uint8_t *rxbuf);
 
 /* Initialize the extended scanner when we start initiating */
 struct hci_ext_create_conn;
diff --git a/nimble/controller/src/ble_ll_conn.c b/nimble/controller/src/ble_ll_conn.c
index 25d7abd..3b61d3a 100644
--- a/nimble/controller/src/ble_ll_conn.c
+++ b/nimble/controller/src/ble_ll_conn.c
@@ -3004,7 +3004,7 @@ ble_ll_init_rx_isr_end(uint8_t *rxbuf, uint8_t crcok,
             goto init_rx_isr_exit;
         }
 
-        rc = ble_ll_scan_get_aux_data(ble_hdr, rxbuf);
+        rc = ble_ll_scan_update_aux_data(ble_hdr, rxbuf);
         if (rc < 0) {
             /* No memory or broken packet */
             ble_hdr->rxinfo.flags |= BLE_MBUF_HDR_F_AUX_INVALID;
diff --git a/nimble/controller/src/ble_ll_scan.c b/nimble/controller/src/ble_ll_scan.c
index 2ac1f84..91f3a85 100644
--- a/nimble/controller/src/ble_ll_scan.c
+++ b/nimble/controller/src/ble_ll_scan.c
@@ -1759,176 +1759,124 @@ ble_ll_ext_scan_parse_adv_info(struct ext_adv_report *report, const uint8_t *buf
 }
 
 /**
- * ble_ll_scan_get_aux_data
+ * ble_ll_scan_update_aux_data
  *
- * Get aux data pointer. It is new allocated data for beacon or currently
- * processing aux data pointer. Aux data pointer will be attached to ble_hdr.rxinfo.user_data
+ * Update aux_data stored in ble_hdr.rxinfo.user_data. If no aux_data is present
+ * (i.e. processing ADV_EXT_IND) this will try to allocate new aux_data.
  *
  * Context: Interrupt
  *
- * @param scansm
  * @param ble_hdr
  * @param rxbuf
- * @param aux_data
  *
  * @return int
- *  0: new allocated aux data
- *  1: current processing aux data
+ *  1: do not scan for next AUX (no AuxPtr or malformed data)
+ *  0: scan for next AUX (valid AuxPtr found)
  * -1: error
  */
 int
-ble_ll_scan_get_aux_data(struct ble_mbuf_hdr *ble_hdr, uint8_t *rxbuf)
+ble_ll_scan_update_aux_data(struct ble_mbuf_hdr *ble_hdr, uint8_t *rxbuf)
 {
-    uint8_t ext_hdr_len;
+    uint8_t pdu_hdr;
     uint8_t pdu_len;
-    uint8_t ext_hdr_flags;
-    uint8_t *ext_hdr;
-    uint8_t has_addr = 0;
-    uint8_t has_dir_addr = 0;
-    uint8_t has_adi = 0;
-    int i;
-    struct ble_ll_aux_data *current_aux = ble_hdr->rxinfo.user_data;
-    struct ble_ll_aux_data *new_aux = NULL;
-    struct ble_ll_aux_data tmp_aux_data = { 0 };
-    int rc;
+    uint8_t eh_len;
+    uint8_t eh_flags;
+    uint8_t *eh;
+    struct ble_ll_aux_data *aux_data;
+    bool is_aux;
+
+    aux_data = ble_hdr->rxinfo.user_data;
+    /* aux_data is initially not set only for ADV_EXT_IND */
+    is_aux = aux_data;
 
+    pdu_hdr = rxbuf[0];
     pdu_len = rxbuf[1];
+
+    /* PDU without at least Extended Header Length is invalid */
     if (pdu_len == 0) {
         return -1;
     }
 
-    tmp_aux_data.mode = rxbuf[2] >> 6;
-
-    ext_hdr_len = rxbuf[2] & 0x3F;
-    if (ext_hdr_len < BLE_LL_EXT_ADV_AUX_PTR_SIZE && !current_aux) {
-        return -1;
-    }
+    eh_len = rxbuf[2];
+    eh_flags = rxbuf[3];
+    eh = &rxbuf[4];
 
-    if (ext_hdr_len == 0) {
-        if (current_aux) {
-            /* This is last element in the chain.
-             * Clear incomplete flag
-             */
-            BLE_LL_AUX_CLEAR_FLAG(current_aux, BLE_LL_AUX_INCOMPLETE_BIT);
+    /*
+     * PDU without Extended Header indicates end of chain so aux_data has to be
+     * already set, otherwise it's invalid.
+     */
+    if (eh_len == 0) {
+        if (aux_data) {
+            BLE_LL_AUX_CLEAR_FLAG(aux_data, BLE_LL_AUX_INCOMPLETE_BIT);
             return 1;
         }
-
         return -1;
     }
 
-    ext_hdr_flags = rxbuf[3];
-    ext_hdr = &rxbuf[4];
+    /*
+     * If aux_data is not set, this is ADV_EXT_IND which starts new extended
+     * advertising event.
+     */
+    if (!aux_data) {
+        if (ble_ll_scan_ext_adv_init(&aux_data)) {
+            return -1;
+        }
 
-    i = 0;
-    if (ext_hdr_flags & (1 << BLE_LL_EXT_ADV_ADVA_BIT)) {
-        memcpy(tmp_aux_data.addr, ext_hdr + i, 6);
-        tmp_aux_data.addr_type =
-                ble_ll_get_addr_type(rxbuf[0] & BLE_ADV_PDU_HDR_TXADD_MASK);
-        i += BLE_LL_EXT_ADV_ADVA_SIZE;
-        has_addr = 1;
+        aux_data->aux_primary_phy = ble_hdr->rxinfo.phy;
     }
 
-    if (ext_hdr_flags & (1 << BLE_LL_EXT_ADV_TARGETA_BIT)) {
-        memcpy(tmp_aux_data.dir_addr, ext_hdr + i, 6);
-               tmp_aux_data.dir_addr_type =
-                        ble_ll_get_addr_type(rxbuf[0] & BLE_ADV_PDU_HDR_RXADD_MASK);
-               has_dir_addr = 1;
-        i += BLE_LL_EXT_ADV_TARGETA_SIZE;
-    }
+    /* Now parse extended header... */
 
-    if (ext_hdr_flags & (1 << BLE_LL_EXT_ADV_CTE_INFO_BIT)) {
-        i += 1;
+    if (eh_flags & (1 << BLE_LL_EXT_ADV_ADVA_BIT)) {
+        memcpy(aux_data->addr, eh, 6);
+        aux_data->addr_type = !!(pdu_hdr & BLE_ADV_PDU_HDR_TXADD_MASK);
+        eh += BLE_LL_EXT_ADV_ADVA_SIZE;
+        BLE_LL_AUX_SET_FLAG(aux_data, BLE_LL_AUX_HAS_ADDRA);
     }
 
-    if (ext_hdr_flags & (1 << BLE_LL_EXT_ADV_DATA_INFO_BIT)) {
-        tmp_aux_data.adi = get_le16(ext_hdr + i);
-        i += BLE_LL_EXT_ADV_DATA_INFO_SIZE;
-        has_adi = 1;
+    if (eh_flags & (1 << BLE_LL_EXT_ADV_TARGETA_BIT)) {
+        memcpy(aux_data->dir_addr, eh, 6);
+        aux_data->dir_addr_type = !!(pdu_hdr & BLE_ADV_PDU_HDR_RXADD_MASK);
+        eh += BLE_LL_EXT_ADV_TARGETA_SIZE;
+        BLE_LL_AUX_SET_FLAG(aux_data, BLE_LL_AUX_HAS_DIR_ADDRA);
     }
 
-    if (ext_hdr_flags & (1 << BLE_LL_EXT_ADV_AUX_PTR_BIT)) {
-
-        if (ble_ll_ext_scan_parse_aux_ptr(&tmp_aux_data, ext_hdr + i) < 0) {
-            return -1;
-        }
-
-        if (current_aux) {
-            /* If we are here that means there is chain advertising. */
 
-            /* Lets reuse old aux_data */
-            new_aux = current_aux;
+    if (eh_flags & (1 << BLE_LL_EXT_ADV_CTE_INFO_BIT)) {
+        eh += 1;
+    }
 
-            /* TODO Collision; Do smth smart when did does not match */
-            if (!(new_aux->evt_type & (BLE_HCI_ADV_SCAN_MASK))
-                            && (tmp_aux_data.adi != new_aux->adi)) {
+    if (eh_flags & (1 << BLE_LL_EXT_ADV_DATA_INFO_BIT)) {
+        if (is_aux) {
+            if (get_le16(eh) != aux_data->adi) {
                 STATS_INC(ble_ll_stats, aux_chain_err);
-                BLE_LL_AUX_SET_FLAG(new_aux, BLE_LL_AUX_INCOMPLETE_ERR_BIT);
+                BLE_LL_AUX_SET_FLAG(aux_data, BLE_LL_AUX_INCOMPLETE_ERR_BIT);
             }
-
-            BLE_LL_AUX_SET_FLAG(new_aux, BLE_LL_AUX_CHAIN_BIT);
-            BLE_LL_AUX_SET_FLAG(new_aux, BLE_LL_AUX_INCOMPLETE_BIT);
         } else {
-            if (ble_ll_scan_ext_adv_init(&new_aux) < 0) {
-                /* Out of memory */
-                return -1;
-            }
+            aux_data->adi = get_le16(eh);
         }
+        eh += BLE_LL_EXT_ADV_DATA_INFO_SIZE;
+        BLE_LL_AUX_SET_FLAG(aux_data, BLE_LL_AUX_HAS_ADI);
+    }
 
-        new_aux->aux_phy = tmp_aux_data.aux_phy;
-
-        if (!current_aux) {
-            /* Only for first ext adv we want to keep primary phy.*/
-            new_aux->aux_primary_phy = ble_hdr->rxinfo.phy;
+    if (eh_flags & (1 << BLE_LL_EXT_ADV_AUX_PTR_BIT)) {
+        if (ble_ll_ext_scan_parse_aux_ptr(aux_data, eh)) {
+            BLE_LL_AUX_SET_FLAG(aux_data, BLE_LL_AUX_INCOMPLETE_ERR_BIT);
+        } else if (is_aux) {
+            BLE_LL_AUX_SET_FLAG(aux_data, BLE_LL_AUX_CHAIN_BIT);
+            BLE_LL_AUX_SET_FLAG(aux_data, BLE_LL_AUX_INCOMPLETE_BIT);
         }
-
-        new_aux->chan = tmp_aux_data.chan;
-        new_aux->offset = tmp_aux_data.offset;
-        new_aux->mode = tmp_aux_data.mode;
-
-        /* New aux_data or chaining */
-        rc = 0;
     } else {
-
-        /* So ext packet does not have aux ptr. It can be because
-         * a) it is empty beacon (no aux ptr at all)
-         * b) there is no chaining or chaining has just stopped. In this case we do hava aux_data */
-
-        if (!current_aux) {
-            new_aux = NULL;
-            return 1;
-        }
-
-        /*If there is no new aux ptr, just get current one */
-        new_aux = ble_hdr->rxinfo.user_data;
-
-        /* Clear incomplete flag */
-        BLE_LL_AUX_CLEAR_FLAG(new_aux, BLE_LL_AUX_INCOMPLETE_BIT);
-
-        /* Current processing aux_ptr */
-        rc = 1;
-    }
-
-    if (has_adi) {
-        new_aux->adi = tmp_aux_data.adi;
-        BLE_LL_AUX_SET_FLAG(new_aux, BLE_LL_AUX_HAS_ADI);
-    }
-
-    if (has_addr) {
-        memcpy(new_aux->addr, tmp_aux_data.addr, 6);
-        new_aux->addr_type = tmp_aux_data.addr_type;
-        BLE_LL_AUX_SET_FLAG(new_aux, BLE_LL_AUX_HAS_ADDRA);
-    }
-
-    if (has_dir_addr) {
-        memcpy(new_aux->dir_addr, tmp_aux_data.dir_addr, 6);
-        new_aux->dir_addr_type = tmp_aux_data.dir_addr_type;
-        BLE_LL_AUX_SET_FLAG(new_aux, BLE_LL_AUX_HAS_DIR_ADDRA);
+        BLE_LL_AUX_CLEAR_FLAG(aux_data, BLE_LL_AUX_INCOMPLETE_BIT);
     }
 
-    ble_hdr->rxinfo.user_data = new_aux;
+    ble_hdr->rxinfo.user_data = aux_data;
 
-    return rc;
+    /* Do not scan for next AUX if either no AuxPtr or malformed data found */
+    return !(eh_flags & (1 << BLE_LL_EXT_ADV_AUX_PTR_BIT)) ||
+           BLE_LL_AUX_CHECK_FLAG(aux_data, BLE_LL_AUX_INCOMPLETE_ERR_BIT);
 }
+
 /**
  * Called when a receive ADV_EXT PDU has ended.
  *
@@ -2285,8 +2233,8 @@ ble_ll_scan_rx_isr_end(struct os_mbuf *rxpdu, uint8_t crcok)
         if (!scansm->ext_scanning) {
             goto scan_rx_isr_exit;
         }
-        /* Create new aux data for beacon or get current processing aux ptr */
-        rc = ble_ll_scan_get_aux_data(ble_hdr, rxbuf);
+
+        rc = ble_ll_scan_update_aux_data(ble_hdr, rxbuf);
         if (rc < 0) {
             /* No memory or broken packet */
             ble_hdr->rxinfo.flags |= BLE_MBUF_HDR_F_AUX_INVALID;


[mynewt-nimble] 01/07: nimble/ll: Remove duplicated defines

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 2c1d9772c926b4ebbe739416741f80dbd9058332
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Thu Oct 31 09:09:09 2019 +0100

    nimble/ll: Remove duplicated defines
    
    These are already defined in ble_ll.h.
---
 nimble/controller/src/ble_ll_scan.c | 15 ---------------
 1 file changed, 15 deletions(-)

diff --git a/nimble/controller/src/ble_ll_scan.c b/nimble/controller/src/ble_ll_scan.c
index 3a0302d..2f545a6 100644
--- a/nimble/controller/src/ble_ll_scan.c
+++ b/nimble/controller/src/ble_ll_scan.c
@@ -72,21 +72,6 @@ static struct ble_ll_scan_params g_ble_ll_scan_params[BLE_LL_SCAN_PHY_NUMBER];
 /* The scanning state machine global object */
 static struct ble_ll_scan_sm g_ble_ll_scan_sm;
 
-#define BLE_LL_EXT_ADV_ADVA_BIT         (0)
-#define BLE_LL_EXT_ADV_TARGETA_BIT      (1)
-#define BLE_LL_EXT_ADV_RFU_BIT          (2)
-#define BLE_LL_EXT_ADV_DATA_INFO_BIT    (3)
-#define BLE_LL_EXT_ADV_AUX_PTR_BIT      (4)
-#define BLE_LL_EXT_ADV_SYNC_INFO_BIT    (5)
-#define BLE_LL_EXT_ADV_TX_POWER_BIT     (6)
-
-#define BLE_LL_EXT_ADV_ADVA_SIZE        (6)
-#define BLE_LL_EXT_ADV_TARGETA_SIZE     (6)
-#define BLE_LL_EXT_ADV_DATA_INFO_SIZE   (2)
-#define BLE_LL_EXT_ADV_AUX_PTR_SIZE     (3)
-#define BLE_LL_EXT_ADV_SYNC_INFO_SIZE   (18)
-#define BLE_LL_EXT_ADV_TX_POWER_SIZE    (1)
-
 struct ble_ll_ext_adv_hdr
 {
     uint8_t mode;


[mynewt-nimble] 02/07: nimble/ll: Update RFU symbol

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 33171fb59bad6f636f29e137917b0e0bcba66926
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Thu Oct 31 09:09:48 2019 +0100

    nimble/ll: Update RFU symbol
    
    This was added in Core 5.1.
---
 nimble/controller/include/controller/ble_ll.h | 2 +-
 nimble/controller/src/ble_ll_scan.c           | 6 +++---
 nimble/controller/src/ble_ll_sync.c           | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/nimble/controller/include/controller/ble_ll.h b/nimble/controller/include/controller/ble_ll.h
index 51e7198..06d941b 100644
--- a/nimble/controller/include/controller/ble_ll.h
+++ b/nimble/controller/include/controller/ble_ll.h
@@ -329,7 +329,7 @@ struct ble_dev_addr
 
 #define BLE_LL_EXT_ADV_ADVA_BIT         (0)
 #define BLE_LL_EXT_ADV_TARGETA_BIT      (1)
-#define BLE_LL_EXT_ADV_RFU_BIT          (2)
+#define BLE_LL_EXT_ADV_CTE_INFO_BIT     (2)
 #define BLE_LL_EXT_ADV_DATA_INFO_BIT    (3)
 #define BLE_LL_EXT_ADV_AUX_PTR_BIT      (4)
 #define BLE_LL_EXT_ADV_SYNC_INFO_BIT    (5)
diff --git a/nimble/controller/src/ble_ll_scan.c b/nimble/controller/src/ble_ll_scan.c
index 2f545a6..e6b8af9 100644
--- a/nimble/controller/src/ble_ll_scan.c
+++ b/nimble/controller/src/ble_ll_scan.c
@@ -1838,7 +1838,7 @@ ble_ll_scan_get_aux_data(struct ble_mbuf_hdr *ble_hdr, uint8_t *rxbuf)
         i += BLE_LL_EXT_ADV_TARGETA_SIZE;
     }
 
-    if (ext_hdr_flags & (1 << BLE_LL_EXT_ADV_RFU_BIT)) {
+    if (ext_hdr_flags & (1 << BLE_LL_EXT_ADV_CTE_INFO_BIT)) {
         i += 1;
     }
 
@@ -2007,7 +2007,7 @@ ble_ll_scan_parse_ext_hdr(struct os_mbuf *om,
            report->evt_type |= BLE_HCI_ADV_DIRECT_MASK;
         }
 
-        if (ext_hdr_flags & (1 << BLE_LL_EXT_ADV_RFU_BIT)) {
+        if (ext_hdr_flags & (1 << BLE_LL_EXT_ADV_CTE_INFO_BIT)) {
             /* Just skip it for now*/
             i += 1;
         }
@@ -2848,7 +2848,7 @@ check_periodic_sync(const struct os_mbuf *om, struct ble_mbuf_hdr *rxhdr,
             i += BLE_LL_EXT_ADV_TARGETA_SIZE;
         }
 
-        if (ext_hdr_flags & (1 << BLE_LL_EXT_ADV_RFU_BIT)) {
+        if (ext_hdr_flags & (1 << BLE_LL_EXT_ADV_CTE_INFO_BIT)) {
             i += 1;
         }
 
diff --git a/nimble/controller/src/ble_ll_sync.c b/nimble/controller/src/ble_ll_sync.c
index 8e32668..7e09777 100644
--- a/nimble/controller/src/ble_ll_sync.c
+++ b/nimble/controller/src/ble_ll_sync.c
@@ -448,7 +448,7 @@ ble_ll_sync_parse_ext_hdr(struct os_mbuf *om, uint8_t **aux, int8_t *tx_power)
         }
 
         /* there should be no RFU in Sync or chain, skip it */
-        if (ext_hdr_flags & (1 << BLE_LL_EXT_ADV_RFU_BIT)) {
+        if (ext_hdr_flags & (1 << BLE_LL_EXT_ADV_CTE_INFO_BIT)) {
             i += 1;
         }
 


[mynewt-nimble] 03/07: nimble/ll: Cleaup symbols

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 1506488bc4415472c1ac3d2d02595126282d50eb
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Thu Oct 31 09:17:09 2019 +0100

    nimble/ll: Cleaup symbols
    
    Not sure why valid phy mask is a variable, it can be simple #define.
---
 nimble/controller/src/ble_ll_scan.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/nimble/controller/src/ble_ll_scan.c b/nimble/controller/src/ble_ll_scan.c
index e6b8af9..2ac1f84 100644
--- a/nimble/controller/src/ble_ll_scan.c
+++ b/nimble/controller/src/ble_ll_scan.c
@@ -58,12 +58,10 @@
     #error "Cannot have more than 255 scan response entries!"
 #endif
 
-#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_EXT_ADV)
-static const uint8_t ble_ll_valid_scan_phy_mask = (BLE_HCI_LE_PHY_1M_PREF_MASK
 #if MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_CODED_PHY)
-                                | BLE_HCI_LE_PHY_CODED_PREF_MASK
-#endif
-                              );
+#define SCAN_VALID_PHY_MASK     (BLE_HCI_LE_PHY_1M_PREF_MASK | BLE_HCI_LE_PHY_CODED_PREF_MASK)
+#else
+#define SCAN_VALID_PHY_MASK     (BLE_HCI_LE_PHY_1M_PREF_MASK)
 #endif
 
 /* The scanning parameters set by host */
@@ -3412,8 +3410,8 @@ ble_ll_set_ext_scan_params(const uint8_t *cmdbuf, uint8_t len)
     /* Check if no reserved bits in PHYS are set and that at least one valid PHY
      * is set.
      */
-    if (!(cmd->phys & ble_ll_valid_scan_phy_mask) ||
-                                    (cmd->phys & ~ble_ll_valid_scan_phy_mask)) {
+    if (!(cmd->phys & SCAN_VALID_PHY_MASK) ||
+        (cmd->phys & ~SCAN_VALID_PHY_MASK)) {
          return BLE_ERR_INV_HCI_CMD_PARMS;
      }
 


[mynewt-nimble] 05/07: nimble/ll: Optimize extended header parsing for scanner

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 5afa6ef8973221cda0574a57ffd4a322659790c6
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Thu Oct 31 15:39:07 2019 +0100

    nimble/ll: Optimize extended header parsing for scanner
    
    ble_ll_scan_update_aux_data() will always store addresses in aux_data so
    there is no need to parse extended header each time we need to retrieve
    them - just assume whatever is stored in aux_data is valid.
    
    (the same should be done for ble_ll_init probably)
---
 nimble/controller/src/ble_ll_scan.c | 89 +++++++++++++++++++++++++++----------
 1 file changed, 66 insertions(+), 23 deletions(-)

diff --git a/nimble/controller/src/ble_ll_scan.c b/nimble/controller/src/ble_ll_scan.c
index 91f3a85..3e8cca0 100644
--- a/nimble/controller/src/ble_ll_scan.c
+++ b/nimble/controller/src/ble_ll_scan.c
@@ -2114,6 +2114,11 @@ ble_ll_scan_adv_decode_addr(uint8_t pdu_type, uint8_t *rxbuf,
                             uint8_t **inita, uint8_t *inita_type,
                             int *ext_mode)
 {
+    /*
+     * XXX this should be only used for legacy advertising, but need to refactor
+     *     code in ble_ll_init first so it does not call this for ext
+     */
+
     if (pdu_type != BLE_ADV_PDU_TYPE_ADV_EXT_IND &&
         pdu_type != BLE_ADV_PDU_TYPE_AUX_CONNECT_RSP) {
         /* Legacy advertising */
@@ -2182,10 +2187,12 @@ ble_ll_scan_rx_isr_end(struct os_mbuf *rxpdu, uint8_t crcok)
 #if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_EXT_ADV)
     uint8_t phy_mode;
     uint16_t adi;
+    struct ble_ll_aux_data *aux_data;
 #endif
 #if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_PRIVACY)
     struct ble_ll_resolv_entry *rl = NULL;
 #endif
+    bool is_addr_decoded = false;
 
     /* Get scanning state machine */
     scansm = &g_ble_ll_scan_sm;
@@ -2229,6 +2236,11 @@ ble_ll_scan_rx_isr_end(struct os_mbuf *rxpdu, uint8_t crcok)
     }
 
 #if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_EXT_ADV)
+    /*
+     * For extended advertising events all data are decoded to aux_data and can
+     * be retrieved from there. For legacy advertising we need to get addresses
+     * from PDU.
+     */
     if (pdu_type == BLE_ADV_PDU_TYPE_ADV_EXT_IND) {
         if (!scansm->ext_scanning) {
             goto scan_rx_isr_exit;
@@ -2236,25 +2248,38 @@ ble_ll_scan_rx_isr_end(struct os_mbuf *rxpdu, uint8_t crcok)
 
         rc = ble_ll_scan_update_aux_data(ble_hdr, rxbuf);
         if (rc < 0) {
-            /* No memory or broken packet */
             ble_hdr->rxinfo.flags |= BLE_MBUF_HDR_F_AUX_INVALID;
-
             goto scan_rx_isr_exit;
-        }
-        if (rc == 0) {
-            /* Let's tell LL to schedule aux */
+        } else if (rc == 0) {
             ble_hdr->rxinfo.flags |= BLE_MBUF_HDR_F_AUX_PTR_WAIT;
         }
 
+        ext_adv_mode = rxbuf[2] >> 6;
+
+        aux_data = ble_hdr->rxinfo.user_data;
+        if (BLE_LL_AUX_CHECK_FLAG(aux_data, BLE_LL_AUX_HAS_ADDRA)) {
+            peer = aux_data->addr;
+            peer_addr_type = aux_data->addr_type;
+        }
+        if (BLE_LL_AUX_CHECK_FLAG(aux_data, BLE_LL_AUX_HAS_DIR_ADDRA)) {
+            inita = aux_data->dir_addr;
+            inita_type = aux_data->dir_addr_type;
+        }
+
+        is_addr_decoded = true;
+
         rc = -1;
     }
 #endif
 
-    /* Lets get addresses from advertising report*/
-    if (ble_ll_scan_adv_decode_addr(pdu_type, rxbuf, ble_hdr,
-                                    &peer, &peer_addr_type,
-                                    &inita, &inita_type, &ext_adv_mode)) {
-        goto scan_rx_isr_exit;
+    if (!is_addr_decoded) {
+        /* Try to decode addresses from PDU */
+        if (ble_ll_scan_adv_decode_addr(pdu_type, rxbuf, ble_hdr, &peer,
+                                        &peer_addr_type, &inita, &inita_type,
+                                        &ext_adv_mode)) {
+            goto scan_rx_isr_exit;
+        }
+        is_addr_decoded = true;
     }
 
     /* Determine if request may be sent and if whitelist needs to be checked */
@@ -2992,16 +3017,11 @@ ble_ll_scan_rx_pkt_in(uint8_t ptype, struct os_mbuf *om, struct ble_mbuf_hdr *hd
     int backoff_success = 0;
     struct ble_ll_scan_sm *scansm = &g_ble_ll_scan_sm;
     int ext_adv_mode = -1;
+    bool is_addr_decoded = false;
 #if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_EXT_ADV)
-    struct ble_ll_aux_data *aux_data;
+    struct ble_ll_aux_data *aux_data = NULL;
     int rc;
     uint8_t evt_possibly_truncated = 0;
-
-    /* No need to ref as this is only local helper
-     * and unref on hdr->rxinfo.user_data is done in the end of this function
-     */
-    aux_data = hdr->rxinfo.user_data;
-
 #endif
 
     /* if packet is scan response */
@@ -3012,6 +3032,8 @@ ble_ll_scan_rx_pkt_in(uint8_t ptype, struct os_mbuf *om, struct ble_mbuf_hdr *hd
     }
 
 #if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_EXT_ADV)
+    aux_data = hdr->rxinfo.user_data;
+
     if (BLE_MBUF_HDR_AUX_INVALID(hdr)) {
         evt_possibly_truncated = 1;
         goto scan_continue;
@@ -3033,14 +3055,35 @@ ble_ll_scan_rx_pkt_in(uint8_t ptype, struct os_mbuf *om, struct ble_mbuf_hdr *hd
         goto scan_continue;
     }
 
-    if (ble_ll_scan_adv_decode_addr(ptype, rxbuf, hdr,
-                                    &adv_addr, &txadd,
-                                    &init_addr, &init_addr_type,
-                                    &ext_adv_mode)) {
 #if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_EXT_ADV)
-        evt_possibly_truncated = 1;
+    /*
+     * For extended advertising events all data are decoded to aux_data and can
+     * be retrieved from there. For legacy advertising we need to get addresses
+     * from PDU.
+     */
+    if (aux_data) {
+        ext_adv_mode = rxbuf[2] >> 6;
+
+        if (BLE_LL_AUX_CHECK_FLAG(aux_data, BLE_LL_AUX_HAS_ADDRA)) {
+            adv_addr = aux_data->addr;
+            txadd = aux_data->addr_type;
+        }
+        if (BLE_LL_AUX_CHECK_FLAG(aux_data, BLE_LL_AUX_HAS_DIR_ADDRA)) {
+            init_addr = aux_data->dir_addr;
+            init_addr_type = aux_data->dir_addr_type;
+        }
+
+        is_addr_decoded = true;
+    }
 #endif
-        goto scan_continue;
+
+    if (!is_addr_decoded) {
+        if (ble_ll_scan_adv_decode_addr(ptype, rxbuf, hdr, &adv_addr, &txadd,
+                                        &init_addr, &init_addr_type,
+                                        &ext_adv_mode)) {
+            goto scan_continue;
+        }
+        is_addr_decoded = true;
     }
 
     ident_addr = adv_addr;