You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2018/10/23 20:54:37 UTC

[GitHub] rymanluk closed pull request #218: nimble/ll: Certification fixes part3

rymanluk closed pull request #218: nimble/ll: Certification fixes part3
URL: https://github.com/apache/mynewt-nimble/pull/218
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/nimble/controller/include/controller/ble_ll.h b/nimble/controller/include/controller/ble_ll.h
index 0be058e4..6d86e370 100644
--- a/nimble/controller/include/controller/ble_ll.h
+++ b/nimble/controller/include/controller/ble_ll.h
@@ -229,6 +229,15 @@ extern STATS_SECT_DECL(ble_ll_stats) ble_ll_stats;
 #define BLE_LL_FEAT_LE_POWER_CLASS_1 (0x00008000)
 #define BLE_LL_FEAT_MIN_USED_CHAN    (0x00010000)
 
+/* This is initial mask, so if feature exchange will not happen,
+ * but host will want to use this procedure, we will try. If not
+ * succeed, feature bit will be cleared.
+ * Look at LL Features above to find out what is allowed
+ */
+#define BLE_LL_CONN_INITIAL_FEATURES    (0x00000002)
+
+#define BLE_LL_CONN_CLEAR_FEATURE(connsm, feature)   (connsm->conn_features &= ~(feature))
+
 /* LL timing */
 #define BLE_LL_IFS                  (150)       /* usecs */
 #define BLE_LL_MAFS                 (300)       /* usecs */
diff --git a/nimble/controller/include/controller/ble_ll_conn.h b/nimble/controller/include/controller/ble_ll_conn.h
index 18219f9e..5d13b8d5 100644
--- a/nimble/controller/include/controller/ble_ll_conn.h
+++ b/nimble/controller/include/controller/ble_ll_conn.h
@@ -70,9 +70,10 @@ enum conn_enc_state {
     CONN_ENC_S_UNENCRYPTED = 1,
     CONN_ENC_S_ENCRYPTED,
     CONN_ENC_S_ENC_RSP_WAIT,
+    CONN_ENC_S_PAUSE_ENC_RSP_WAIT,
+    CONN_ENC_S_PAUSED,
     CONN_ENC_S_START_ENC_REQ_WAIT,
     CONN_ENC_S_START_ENC_RSP_WAIT,
-    CONN_ENC_S_PAUSE_ENC_RSP_WAIT,
     CONN_ENC_S_LTK_REQ_WAIT,
     CONN_ENC_S_LTK_NEG_REPLY
 };
@@ -165,6 +166,8 @@ struct ble_ll_conn_phy_data
 #define CONN_CUR_TX_PHY_MASK(csm)   (1 << ((csm)->phy_data.cur_tx_phy - 1))
 #define CONN_CUR_RX_PHY_MASK(csm)   (1 << ((csm)->phy_data.cur_rx_phy - 1))
 
+#define BLE_PHY_TRANSITION_INVALID    (0xFF)
+
 /* Connection state machine */
 struct ble_ll_conn_sm
 {
@@ -200,6 +203,7 @@ struct ble_ll_conn_sm
 #if (BLE_LL_BT5_PHY_SUPPORTED == 1)
     struct ble_ll_conn_phy_data phy_data;
     uint16_t phy_instant;
+    uint8_t phy_tx_transition;
 #endif
 
     /* Used to calculate data channel index for connection */
diff --git a/nimble/controller/include/controller/ble_ll_scan.h b/nimble/controller/include/controller/ble_ll_scan.h
index 2a9ba826..5aa52340 100644
--- a/nimble/controller/include/controller/ble_ll_scan.h
+++ b/nimble/controller/include/controller/ble_ll_scan.h
@@ -93,6 +93,7 @@ struct ble_ll_scan_params
 #define BLE_LL_AUX_INCOMPLETE_ERR_BIT   0x04
 #define BLE_LL_AUX_HAS_ADDRA            0x08
 #define BLE_LL_AUX_IGNORE_BIT           0x10
+#define BLE_LL_AUX_HAS_DIR_ADDRA        0x20
 
 #define BLE_LL_CHECK_AUX_FLAG(aux_data, flag) (!!((aux_data)->flags & flag))
 
@@ -108,6 +109,8 @@ struct ble_ll_aux_data {
     uint8_t offset_units;
     uint8_t addr[6];
     uint8_t addr_type;
+    uint8_t dir_addr[6];
+    uint8_t dir_addr_type;
     uint8_t evt_type;
     struct ble_ll_sched_item sch;
     struct ble_ll_ext_adv_report *evt;
@@ -238,7 +241,10 @@ int ble_ll_scan_ext_initiator_start(struct hci_ext_create_conn *hcc,
 
 /* Called to parse extended advertising*/
 struct ble_ll_ext_adv_report;
-int ble_ll_scan_parse_ext_hdr(struct os_mbuf *om, struct ble_mbuf_hdr *ble_hdr,
+int ble_ll_scan_parse_ext_hdr(struct os_mbuf *om,
+                              uint8_t *adva, uint8_t adva_type,
+                              uint8_t *inita, uint8_t inita_type,
+                              struct ble_mbuf_hdr *ble_hdr,
                               struct ble_ll_ext_adv_report *parsed_evt);
 
 void ble_ll_scan_aux_data_free(struct ble_ll_aux_data *aux_scan);
diff --git a/nimble/controller/src/ble_ll_conn.c b/nimble/controller/src/ble_ll_conn.c
index 726f3555..4b6704db 100644
--- a/nimble/controller/src/ble_ll_conn.c
+++ b/nimble/controller/src/ble_ll_conn.c
@@ -1038,8 +1038,18 @@ ble_ll_conn_adjust_pyld_len(struct ble_ll_conn_sm *connsm, uint16_t pyld_len)
     uint16_t ret;
 
 #if (BLE_LL_BT5_PHY_SUPPORTED == 1)
+    uint8_t phy_mode;
+
+    if (connsm->phy_tx_transition != BLE_PHY_TRANSITION_INVALID) {
+        phy_mode = ble_ll_phy_to_phy_mode(connsm->phy_tx_transition,
+                                          connsm->phy_data.phy_options);
+    } else {
+        phy_mode = connsm->phy_data.tx_phy_mode;
+    }
+
     phy_max_tx_octets = ble_ll_pdu_max_tx_octets_get(connsm->eff_max_tx_time,
-                                                     connsm->phy_data.tx_phy_mode);
+                                                     phy_mode);
+
 #else
     phy_max_tx_octets = ble_ll_pdu_max_tx_octets_get(connsm->eff_max_tx_time,
                                                      BLE_PHY_MODE_1M);
@@ -1361,7 +1371,7 @@ ble_ll_conn_tx_data_pdu(struct ble_ll_conn_sm *connsm)
             }
         } else {
             CONN_F_ENCRYPTED(connsm) = 0;
-            connsm->enc_data.enc_state = CONN_ENC_S_UNENCRYPTED;
+            connsm->enc_data.enc_state = CONN_ENC_S_PAUSED;
             connsm->enc_data.tx_encrypted = 0;
             ble_phy_encrypt_disable();
         }
@@ -1918,7 +1928,7 @@ ble_ll_conn_sm_new(struct ble_ll_conn_sm *connsm)
     connsm->event_cntr = 0;
     connsm->conn_state = BLE_LL_CONN_STATE_IDLE;
     connsm->disconnect_reason = 0;
-    connsm->conn_features = 0;
+    connsm->conn_features = BLE_LL_CONN_INITIAL_FEATURES;
     memset(connsm->remote_features, 0, sizeof(connsm->remote_features));
     connsm->vers_nr = 0;
     connsm->comp_id = 0;
@@ -1938,6 +1948,7 @@ ble_ll_conn_sm_new(struct ble_ll_conn_sm *connsm)
     connsm->phy_data.host_pref_tx_phys_mask = g_ble_ll_data.ll_pref_tx_phys;
     connsm->phy_data.host_pref_rx_phys_mask = g_ble_ll_data.ll_pref_rx_phys;
     connsm->phy_data.phy_options = 0;
+    connsm->phy_tx_transition = BLE_PHY_TRANSITION_INVALID;
 #endif
 
     /* Reset current control procedure */
@@ -2188,6 +2199,14 @@ ble_ll_conn_next_event(struct ble_ll_conn_sm *connsm)
         ble_ll_ctrl_terminate_start(connsm);
     }
 
+    if (CONN_F_TERMINATE_STARTED(connsm) && (connsm->conn_role == BLE_LL_CONN_ROLE_SLAVE)) {
+        /* Some of the devices waits whole connection interval to ACK our
+         * TERMINATE_IND sent as a Slave. Since we are here it means we are still waiting for ACK.
+         * Make sure we catch it in next connection event.
+         */
+        connsm->slave_latency = 0;
+    }
+
     /*
      * XXX: TODO Probably want to add checks to see if we need to start
      * a control procedure here as an instant may have prevented us from
@@ -3251,22 +3270,8 @@ ble_ll_init_rx_isr_end(uint8_t *rxbuf, uint8_t crcok,
         // no break
 #endif
     case BLE_ADV_PDU_TYPE_ADV_DIRECT_IND:
-        /*
-         * If we expect our address to be private and the INITA is not,
-         * we dont respond!
-         */
         inita_is_rpa = (uint8_t)ble_ll_is_rpa(init_addr, init_addr_type);
         if (!inita_is_rpa) {
-            /*
-             * If we expect our address to be private and the InitA is not,
-             * we dont respond!
-             *
-             * TODO: Probably we could not care for this if privacy is on.
-             * Leave if for now.
-             */
-            if (connsm->own_addr_type > BLE_HCI_ADV_OWN_ADDR_RANDOM) {
-                goto init_rx_isr_exit;
-            }
 
             /* Resolving will be done later. Check if identity InitA matches */
             if (!ble_ll_is_our_devaddr(init_addr, init_addr_type)) {
@@ -3306,8 +3311,9 @@ ble_ll_init_rx_isr_end(uint8_t *rxbuf, uint8_t crcok,
             resolved = 1;
 
             /* Assure privacy */
-            if ((rl->rl_priv_mode == BLE_HCI_PRIVACY_NETWORK) && init_addr &&
-                !inita_is_rpa) {
+            if ((rl->rl_priv_mode == BLE_HCI_PRIVACY_NETWORK) &&
+                                        init_addr && !inita_is_rpa &&
+                                        ble_ll_resolv_irk_nonzero(rl->rl_local_irk)) {
                 goto init_rx_isr_exit;
             }
 
@@ -3345,7 +3351,8 @@ ble_ll_init_rx_isr_end(uint8_t *rxbuf, uint8_t crcok,
          * is identity address
          */
         if (rl && !inita_is_rpa &&
-           (rl->rl_priv_mode == BLE_HCI_PRIVACY_NETWORK)) {
+           (rl->rl_priv_mode == BLE_HCI_PRIVACY_NETWORK) &&
+            ble_ll_resolv_irk_nonzero(rl->rl_local_irk)) {
             goto init_rx_isr_exit;
         }
 
@@ -3595,7 +3602,7 @@ ble_ll_conn_rx_data_pdu(struct os_mbuf *rxpdu, struct ble_mbuf_hdr *hdr)
              *
              * Reference: Core 5.0, Vol 6, Part B, 5.1.3.1
              */
-            if ((connsm->enc_data.enc_state > CONN_ENC_S_ENCRYPTED) &&
+            if ((connsm->enc_data.enc_state > CONN_ENC_S_PAUSE_ENC_RSP_WAIT) &&
                     !ble_ll_ctrl_enc_allowed_pdu_rx(rxpdu)) {
                 ble_ll_conn_timeout(connsm, BLE_ERR_CONN_TERM_MIC);
                 goto conn_rx_data_pdu_end;
@@ -3805,6 +3812,12 @@ ble_ll_conn_rx_isr_end(uint8_t *rxbuf, struct ble_mbuf_hdr *rxhdr)
         /* Set last received header byte */
         connsm->last_rxd_hdr_byte = hdr_byte;
 
+        is_ctrl = 0;
+        if ((hdr_byte & BLE_LL_DATA_HDR_LLID_MASK) == BLE_LL_LLID_CTRL) {
+            is_ctrl = 1;
+            opcode = rxbuf[2];
+        }
+
         /*
          * If SN bit from header does not match NESN in connection, this is
          * a resent PDU and should be ignored.
@@ -3886,10 +3899,16 @@ ble_ll_conn_rx_isr_end(uint8_t *rxbuf, struct ble_mbuf_hdr *rxhdr)
                         os_mbuf_free_chain(txpdu);
                         connsm->cur_tx_pdu = NULL;
                     } else {
-                        /*  XXX: TODO need to check with phy update procedure.
-                         *  There are limitations if we have started update */
                         rem_bytes = OS_MBUF_PKTLEN(txpdu) - txhdr->txinfo.offset;
                         /* Adjust payload for max TX time and octets */
+
+#if (BLE_LL_BT5_PHY_SUPPORTED == 1)
+                        if (is_ctrl && (connsm->conn_role == BLE_LL_CONN_ROLE_SLAVE)
+                                        && (opcode == BLE_LL_CTRL_PHY_UPDATE_IND)) {
+                            connsm->phy_tx_transition = rxbuf[3];
+                        }
+#endif
+
                         rem_bytes = ble_ll_conn_adjust_pyld_len(connsm, rem_bytes);
                         txhdr->txinfo.pyld_len = rem_bytes;
                     }
@@ -3900,12 +3919,6 @@ ble_ll_conn_rx_isr_end(uint8_t *rxbuf, struct ble_mbuf_hdr *rxhdr)
         /* Should we continue connection event? */
         /* If this is a TERMINATE_IND, we have to reply */
 chk_rx_terminate_ind:
-        is_ctrl = 0;
-        if ((hdr_byte & BLE_LL_DATA_HDR_LLID_MASK) == BLE_LL_LLID_CTRL) {
-            is_ctrl = 1;
-            opcode = rxbuf[2];
-        }
-
         /* If we received a terminate IND, we must set some flags */
         if (is_ctrl && (opcode == BLE_LL_CTRL_TERMINATE_IND)
                     && (rx_pyld_len == (1 + BLE_LL_CTRL_TERMINATE_IND_LEN))) {
@@ -3919,7 +3932,7 @@ ble_ll_conn_rx_isr_end(uint8_t *rxbuf, struct ble_mbuf_hdr *rxhdr)
             reply = 1;
 #if MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_ENCRYPTION)
             if (is_ctrl && (opcode == BLE_LL_CTRL_PAUSE_ENC_RSP)) {
-                connsm->enc_data.enc_state = CONN_ENC_S_UNENCRYPTED;
+                connsm->enc_data.enc_state = CONN_ENC_S_PAUSED;
             }
 #endif
         }
@@ -4013,6 +4026,15 @@ ble_ll_conn_enqueue_pkt(struct ble_ll_conn_sm *connsm, struct os_mbuf *om,
                     lifo = 1;
                 }
                 break;
+            case BLE_LL_CTRL_ENC_REQ:
+            case BLE_LL_CTRL_ENC_RSP:
+                /* If encryption has been paused, we don't want to send any packets from the
+                 * TX queue, as they would go unencrypted.
+                 */
+                if (connsm->enc_data.enc_state == CONN_ENC_S_PAUSED) {
+                    lifo = 1;
+                }
+                break;
             default:
                 break;
             }
diff --git a/nimble/controller/src/ble_ll_ctrl.c b/nimble/controller/src/ble_ll_ctrl.c
index 4ae03bb0..0dc6a785 100644
--- a/nimble/controller/src/ble_ll_ctrl.c
+++ b/nimble/controller/src/ble_ll_ctrl.c
@@ -461,14 +461,17 @@ ble_ll_ctrl_proc_unk_rsp(struct ble_ll_conn_sm *connsm, uint8_t *dptr, uint8_t *
     switch (opcode) {
     case BLE_LL_CTRL_LENGTH_REQ:
         ctrl_proc = BLE_LL_CTRL_PROC_DATA_LEN_UPD;
+        BLE_LL_CONN_CLEAR_FEATURE(connsm, BLE_LL_FEAT_DATA_LEN_EXT);
         break;
     case BLE_LL_CTRL_CONN_UPDATE_IND:
         ctrl_proc = BLE_LL_CTRL_PROC_CONN_UPDATE;
         break;
     case BLE_LL_CTRL_SLAVE_FEATURE_REQ:
         ctrl_proc = BLE_LL_CTRL_PROC_FEATURE_XCHG;
+        BLE_LL_CONN_CLEAR_FEATURE(connsm, BLE_LL_FEAT_SLAVE_INIT);
         break;
     case BLE_LL_CTRL_CONN_PARM_REQ:
+        BLE_LL_CONN_CLEAR_FEATURE(connsm, BLE_LL_FEAT_CONN_PARM_REQ);
         if (connsm->conn_role == BLE_LL_CONN_ROLE_MASTER) {
             ble_ll_ctrl_conn_upd_make(connsm, rspdata, NULL);
             connsm->reject_reason = BLE_ERR_SUCCESS;
@@ -483,6 +486,7 @@ ble_ll_ctrl_proc_unk_rsp(struct ble_ll_conn_sm *connsm, uint8_t *dptr, uint8_t *
          * support LE Ping feature.
          */
         ctrl_proc = BLE_LL_CTRL_PROC_LE_PING;
+        BLE_LL_CONN_CLEAR_FEATURE(connsm, BLE_LL_FEAT_LE_PING);
         break;
 #if (BLE_LL_BT5_PHY_SUPPORTED ==1)
     case BLE_LL_CTRL_PHY_REQ:
@@ -522,7 +526,7 @@ ble_ll_ctrl_proc_unk_rsp(struct ble_ll_conn_sm *connsm, uint8_t *dptr, uint8_t *
  *
  * @param arg Pointer to connection state machine.
  */
-void
+static void
 ble_ll_ctrl_proc_rsp_timer_cb(struct ble_npl_event *ev)
 {
     /* Control procedure has timed out. Kill the connection */
@@ -553,6 +557,8 @@ ble_ll_ctrl_phy_update_proc_complete(struct ble_ll_conn_sm *connsm)
     chk_proc_stop = 1;
     chk_host_phy = 1;
 
+    connsm->phy_tx_transition = BLE_PHY_TRANSITION_INVALID;
+
     if (CONN_F_PEER_PHY_UPDATE(connsm)) {
         CONN_F_PEER_PHY_UPDATE(connsm) = 0;
     } else if (CONN_F_CTRLR_PHY_UPDATE(connsm)) {
@@ -824,6 +830,14 @@ ble_ll_ctrl_rx_phy_req(struct ble_ll_conn_sm *connsm, uint8_t *req,
         ble_ll_ctrl_phy_req_rsp_make(connsm, rsp);
         rsp_opcode = BLE_LL_CTRL_PHY_RSP;
 
+        if (rsp[0] & BLE_PHY_MASK_1M) {
+            connsm->phy_tx_transition = BLE_PHY_1M;
+        } else if (rsp[0] & BLE_PHY_MASK_2M) {
+            connsm->phy_tx_transition = BLE_PHY_2M;
+        } else if (rsp[0] & BLE_PHY_MASK_CODED) {
+            connsm->phy_tx_transition = BLE_PHY_CODED;
+        }
+
         /* Start response timer */
         connsm->cur_ctrl_proc = BLE_LL_CTRL_PROC_PHY_UPDATE;
         ble_ll_ctrl_start_rsp_timer(connsm);
@@ -875,7 +889,7 @@ ble_ll_ctrl_rx_phy_rsp(struct ble_ll_conn_sm *connsm, uint8_t *dptr,
  * @param connsm
  * @param dptr
  */
-void
+static void
 ble_ll_ctrl_rx_phy_update_ind(struct ble_ll_conn_sm *connsm, uint8_t *dptr)
 {
     int no_change;
@@ -1580,7 +1594,7 @@ ble_ll_ctrl_rx_conn_update(struct ble_ll_conn_sm *connsm, uint8_t *dptr)
 
     /* Only a slave should receive this */
     if (connsm->conn_role == BLE_LL_CONN_ROLE_MASTER) {
-        return BLE_ERR_MAX;
+        return BLE_LL_CTRL_UNKNOWN_RSP;
     }
 
     /* Retrieve parameters */
@@ -1844,24 +1858,28 @@ ble_ll_ctrl_rx_version_ind(struct ble_ll_conn_sm *connsm, uint8_t *dptr,
  * @param connsm
  * @param dptr
  */
-static void
+static int
 ble_ll_ctrl_rx_chanmap_req(struct ble_ll_conn_sm *connsm, uint8_t *dptr)
 {
     uint16_t instant;
     uint16_t conn_events;
 
+    if (connsm->conn_role == BLE_LL_CONN_ROLE_MASTER) {
+        return BLE_LL_CTRL_UNKNOWN_RSP;
+    }
+
     /* If instant is in the past, we have to end the connection */
-    if (connsm->conn_role == BLE_LL_CONN_ROLE_SLAVE) {
-        instant = get_le16(dptr + BLE_LL_CONN_CHMAP_LEN);
-        conn_events = (instant - connsm->event_cntr) & 0xFFFF;
-        if (conn_events >= 32767) {
-            ble_ll_conn_timeout(connsm, BLE_ERR_INSTANT_PASSED);
-        } else {
-            connsm->chanmap_instant = instant;
-            memcpy(connsm->req_chanmap, dptr, BLE_LL_CONN_CHMAP_LEN);
-            connsm->csmflags.cfbit.chanmap_update_scheduled = 1;
-        }
+    instant = get_le16(dptr + BLE_LL_CONN_CHMAP_LEN);
+    conn_events = (instant - connsm->event_cntr) & 0xFFFF;
+    if (conn_events >= 32767) {
+        ble_ll_conn_timeout(connsm, BLE_ERR_INSTANT_PASSED);
+    } else {
+        connsm->chanmap_instant = instant;
+        memcpy(connsm->req_chanmap, dptr, BLE_LL_CONN_CHMAP_LEN);
+        connsm->csmflags.cfbit.chanmap_update_scheduled = 1;
     }
+
+    return BLE_ERR_MAX;
 }
 
 /**
@@ -2263,7 +2281,7 @@ ble_ll_ctrl_rx_pdu(struct ble_ll_conn_sm *connsm, struct os_mbuf *om)
         rsp_opcode = ble_ll_ctrl_rx_conn_update(connsm, dptr);
         break;
     case BLE_LL_CTRL_CHANNEL_MAP_REQ:
-        ble_ll_ctrl_rx_chanmap_req(connsm, dptr);
+        rsp_opcode = ble_ll_ctrl_rx_chanmap_req(connsm, dptr);
         break;
     case BLE_LL_CTRL_LENGTH_REQ:
         /* Extract parameters and check if valid */
@@ -2532,6 +2550,19 @@ ble_ll_ctrl_tx_done(struct os_mbuf *txpdu, struct ble_ll_conn_sm *connsm)
             connsm->enc_data.enc_state = CONN_ENC_S_PAUSE_ENC_RSP_WAIT;
         }
         break;
+#endif
+#if (BLE_LL_BT5_PHY_SUPPORTED == 1)
+    case BLE_LL_CTRL_PHY_REQ:
+        if (connsm->conn_role == BLE_LL_CONN_ROLE_SLAVE) {
+            if (connsm->phy_data.req_pref_tx_phys_mask & BLE_PHY_MASK_1M) {
+                connsm->phy_tx_transition = BLE_PHY_1M;
+            } else if (connsm->phy_data.req_pref_tx_phys_mask & BLE_PHY_MASK_2M) {
+                connsm->phy_tx_transition = BLE_PHY_2M;
+            } else if (connsm->phy_data.req_pref_tx_phys_mask & BLE_PHY_MASK_CODED) {
+                connsm->phy_tx_transition = BLE_PHY_CODED;
+            }
+        }
+        break;
 #endif
     default:
         break;
diff --git a/nimble/controller/src/ble_ll_scan.c b/nimble/controller/src/ble_ll_scan.c
index 85762fbb..16fea1ee 100644
--- a/nimble/controller/src/ble_ll_scan.c
+++ b/nimble/controller/src/ble_ll_scan.c
@@ -610,7 +610,7 @@ ble_ll_hci_send_legacy_ext_adv_report(uint8_t evtype,
                                       uint8_t addr_type, uint8_t *addr,
                                       uint8_t rssi,
                                       uint8_t adv_data_len, struct os_mbuf *adv_data,
-                                      uint8_t *inita)
+                                      uint8_t *inita, uint8_t inita_type)
 {
     struct ble_ll_ext_adv_report *evt;
 
@@ -657,7 +657,7 @@ ble_ll_hci_send_legacy_ext_adv_report(uint8_t evtype,
 
     if (inita) {
         /* TODO Really ?? */
-        evt->dir_addr_type = BLE_HCI_ADV_OWN_ADDR_RANDOM;
+        evt->dir_addr_type = inita_type;
         memcpy(evt->dir_addr, inita, BLE_DEV_ADDR_LEN);
         evt->event_len += BLE_DEV_ADDR_LEN  + 1;
     } else if (adv_data_len <= (MYNEWT_VAL(BLE_HCI_EVT_BUF_SIZE) - sizeof(*evt))) {
@@ -677,7 +677,7 @@ static int
 ble_ll_hci_send_adv_report(uint8_t subev, uint8_t evtype,uint8_t event_len,
                            uint8_t addr_type, uint8_t *addr, uint8_t rssi,
                            uint8_t adv_data_len, struct os_mbuf *adv_data,
-                           uint8_t *inita)
+                           uint8_t *inita, uint8_t inita_type)
 {
     uint8_t *evbuf;
     uint8_t *tmp;
@@ -708,7 +708,7 @@ ble_ll_hci_send_adv_report(uint8_t subev, uint8_t evtype,uint8_t event_len,
     tmp = &evbuf[12];
     if (subev == BLE_HCI_LE_SUBEV_DIRECT_ADV_RPT) {
         BLE_LL_ASSERT(inita);
-        tmp[0] = BLE_HCI_ADV_OWN_ADDR_RANDOM;
+        tmp[0] = inita_type;
         memcpy(tmp + 1, inita, BLE_DEV_ADDR_LEN);
         tmp += BLE_DEV_ADDR_LEN + 1;
     } else if (subev == BLE_HCI_LE_SUBEV_ADV_RPT) {
@@ -796,20 +796,20 @@ ble_ll_scan_send_adv_report(uint8_t pdu_type, uint8_t *adva, uint8_t adva_type,
                                                    adva_type, adva,
                                                    hdr->rxinfo.rssi,
                                                    adv_data_len, om,
-                                                   inita);
+                                                   inita, inita_type);
     } else {
         rc = ble_ll_hci_send_adv_report(subev, evtype, event_len,
                                         adva_type, adva,
                                         hdr->rxinfo.rssi,
                                         adv_data_len, om,
-                                        inita);
+                                        inita, inita_type);
     }
 #else
     rc = ble_ll_hci_send_adv_report(subev, evtype, event_len,
                                     adva_type, adva,
                                     hdr->rxinfo.rssi,
                                     adv_data_len, om,
-                                    inita);
+                                    inita, inita_type);
 #endif
     if (!rc) {
         /* If filtering, add it to list of duplicate addresses */
@@ -1628,6 +1628,7 @@ ble_ll_scan_get_aux_data(struct ble_ll_scan_sm *scansm,
     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 tmp_aux_data = { 0 };
@@ -1658,6 +1659,10 @@ ble_ll_scan_get_aux_data(struct ble_ll_scan_sm *scansm,
     }
 
     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;
     }
 
@@ -1718,6 +1723,11 @@ ble_ll_scan_get_aux_data(struct ble_ll_scan_sm *scansm,
             (*aux_data)->addr_type = tmp_aux_data.addr_type;
             (*aux_data)->flags |= BLE_LL_AUX_HAS_ADDRA;
         }
+        if (has_dir_addr) {
+            memcpy((*aux_data)->dir_addr, tmp_aux_data.dir_addr, 6);
+            (*aux_data)->dir_addr_type = tmp_aux_data.dir_addr_type;
+            (*aux_data)->flags |= BLE_LL_AUX_HAS_DIR_ADDRA;
+        }
         return 0;
     }
 
@@ -1741,7 +1751,10 @@ ble_ll_scan_get_aux_data(struct ble_ll_scan_sm *scansm,
  *
  */
 int
-ble_ll_scan_parse_ext_hdr(struct os_mbuf *om, struct ble_mbuf_hdr *ble_hdr,
+ble_ll_scan_parse_ext_hdr(struct os_mbuf *om,
+                          uint8_t *adva, uint8_t adva_type,
+                          uint8_t *inita, uint8_t inita_type,
+                          struct ble_mbuf_hdr *ble_hdr,
                           struct ble_ll_ext_adv_report *out_evt)
 {
     uint8_t pdu_len;
@@ -1786,24 +1799,22 @@ ble_ll_scan_parse_ext_hdr(struct os_mbuf *om, struct ble_mbuf_hdr *ble_hdr,
 
     i = 0;
     if (ext_hdr_flags & (1 << BLE_LL_EXT_ADV_ADVA_BIT)) {
-        memcpy(out_evt->addr, ext_hdr + i, BLE_LL_EXT_ADV_ADVA_SIZE);
-        out_evt->addr_type =
-                ble_ll_get_addr_type(rxbuf[0] & BLE_ADV_PDU_HDR_TXADD_MASK);
         i += BLE_LL_EXT_ADV_ADVA_SIZE;
-    } else {
-        if (aux_data && (aux_data->flags & BLE_LL_AUX_HAS_ADDRA)) {
-            /* Have address in aux_data */
-            memcpy(out_evt->addr, aux_data->addr, 6);
-            out_evt->addr_type = aux_data->addr_type;
-        }
+    }
+
+    if (adva) {
+        memcpy(out_evt->addr, adva, 6);
+        out_evt->addr_type = adva_type;
     }
 
     if (ext_hdr_flags & (1 << BLE_LL_EXT_ADV_TARGETA_BIT)) {
-        memcpy(out_evt->dir_addr, ext_hdr + i, BLE_LL_EXT_ADV_ADVA_SIZE);
-        out_evt->dir_addr_type =
-                ble_ll_get_addr_type(rxbuf[0] & BLE_ADV_PDU_HDR_RXADD_MASK);
         i += BLE_LL_EXT_ADV_TARGETA_SIZE;
-        out_evt->evt_type |= BLE_HCI_ADV_DIRECT_MASK;
+    }
+
+    if (inita) {
+       memcpy(out_evt->dir_addr, inita, 6);
+       out_evt->dir_addr_type = inita_type;
+       out_evt->evt_type |= BLE_HCI_ADV_DIRECT_MASK;
     }
 
     if (ext_hdr_flags & (1 << BLE_LL_EXT_ADV_RFU_BIT)) {
@@ -1923,6 +1934,18 @@ ble_ll_scan_get_addr_from_ext_adv(uint8_t *rxbuf, struct ble_mbuf_hdr *ble_hdr,
         *inita_type =
                 ble_ll_get_addr_type(rxbuf[0] & BLE_ADV_PDU_HDR_RXADD_MASK);
         i += BLE_LL_EXT_ADV_TARGETA_SIZE;
+        if (aux_data) {
+            /* Lets copy addr to aux_data. Need it for e.g. chaining */
+            memcpy(aux_data->dir_addr, *inita, 6);
+            aux_data->dir_addr_type = *inita_type;
+            aux_data->flags |= BLE_LL_AUX_HAS_DIR_ADDRA;
+        }
+    } else {
+        /* We should have address already in aux_data */
+        if (aux_data->flags & BLE_LL_AUX_HAS_DIR_ADDRA) {
+            *inita = aux_data->dir_addr;
+            *inita_type = aux_data->dir_addr_type;
+        }
     }
 
     return 0;
@@ -2302,7 +2325,9 @@ ble_ll_scan_aux_data_free(struct ble_ll_aux_data *aux_scan)
  *          1 on success (data status is not "completed")
  */
 static int
-ble_ll_hci_send_ext_adv_report(uint8_t ptype, struct os_mbuf *om,
+ble_ll_hci_send_ext_adv_report(uint8_t ptype, uint8_t *adva, uint8_t adva_type,
+                               uint8_t *inita, uint8_t inita_type,
+                               struct os_mbuf *om,
                                struct ble_mbuf_hdr *hdr)
 {
     struct ble_ll_aux_data *aux_data = hdr->rxinfo.user_data;
@@ -2331,7 +2356,7 @@ ble_ll_hci_send_ext_adv_report(uint8_t ptype, struct os_mbuf *om,
         }
     }
 
-    datalen = ble_ll_scan_parse_ext_hdr(om, hdr, evt);
+    datalen = ble_ll_scan_parse_ext_hdr(om, adva, adva_type, inita, inita_type, hdr, evt);
     if (datalen < 0) {
         /* XXX what should we do here? send some trimmed event? */
         ble_hci_trans_buf_free((uint8_t *)evt);
@@ -2566,7 +2591,8 @@ ble_ll_scan_rx_pkt_in(uint8_t ptype, struct os_mbuf *om, struct ble_mbuf_hdr *hd
             STATS_INC(ble_ll_stats, aux_chain_cnt);
         }
 
-        rc = ble_ll_hci_send_ext_adv_report(ptype, om, hdr);
+        rc = ble_ll_hci_send_ext_adv_report(ptype, ident_addr, ident_addr_type,
+                                            init_addr, init_addr_type, om, hdr);
         if (rc < 0) {
             /*
              * Data were trimmed so no need to scan this chain anymore. Also


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services