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 2020/01/07 13:07:22 UTC

[GitHub] [mynewt-nimble] rymanluk commented on a change in pull request #713: nimble/ll: Simplify and cleanup PDU RX flow in scanner

rymanluk commented on a change in pull request #713: nimble/ll: Simplify and cleanup PDU RX flow in scanner
URL: https://github.com/apache/mynewt-nimble/pull/713#discussion_r363738660
 
 

 ##########
 File path: nimble/controller/src/ble_ll_scan.c
 ##########
 @@ -2055,338 +1965,458 @@ ble_ll_scan_adv_decode_addr(uint8_t pdu_type, uint8_t *rxbuf,
     return 0;
 }
 
-/**
- * Called when a receive PDU has ended.
- *
- * Context: Interrupt
- *
- * @param rxpdu
+static void
+ble_ll_scan_get_addr_data_from_legacy(uint8_t pdu_type, uint8_t *rxbuf,
+                                     struct ble_ll_scan_addr_data *addrd)
+{
+    BLE_LL_ASSERT(pdu_type < BLE_ADV_PDU_TYPE_ADV_EXT_IND);
+
+    addrd->adva_present = true;
+
+    addrd->adva = rxbuf + BLE_LL_PDU_HDR_LEN;
+    addrd->adva_type = ble_ll_get_addr_type(rxbuf[0] & BLE_ADV_PDU_HDR_TXADD_MASK);
+
+    if (pdu_type == BLE_ADV_PDU_TYPE_ADV_DIRECT_IND) {
+        addrd->targeta = rxbuf + BLE_LL_PDU_HDR_LEN + BLE_DEV_ADDR_LEN;
+        addrd->targeta_type = ble_ll_get_addr_type(rxbuf[0] & BLE_ADV_PDU_HDR_RXADD_MASK);
+    } else {
+        addrd->targeta = NULL;
+        addrd->targeta_type = 0;
+    }
+}
+
+/*
+ * Matches incoming PDU using scan filter policy and whitelist, if applicable.
+ * This will also resolve addresses and update flags/fields in header and
+ * addr_data as needed.
  *
- * @return int
- *       < 0: Disable the phy after reception.
- *      == 0: Success. Do not disable the PHY.
- *       > 0: Do not disable PHY as that has already been done.
+ * @return  0 = no match
+ *          1 = match
+ *          2 = match, but do not scan
  */
-int
-ble_ll_scan_rx_isr_end(struct os_mbuf *rxpdu, uint8_t crcok)
+static int
+ble_ll_scan_rx_filter(struct ble_mbuf_hdr *hdr, struct ble_ll_scan_addr_data *addrd)
 {
-    int rc;
-    int chk_send_req;
-    int chk_wl;
-    int rpa_index;
-    int resolved;
-    uint8_t pdu_type;
-    uint8_t adva_type = 0;
-    uint8_t *adva = NULL;       /* Original AdvA */
-    uint8_t targeta_type = 0;
-    uint8_t *targeta = NULL;    /* Original TargetA */
-    uint8_t adv_addr_type = 0;
-    uint8_t *adv_addr = NULL;   /* Actual advertiser address (AdvA or identity) */
-    uint8_t *rxbuf;
-    struct ble_mbuf_hdr *ble_hdr;
-    struct ble_ll_scan_sm *scansm;
-    struct ble_ll_scan_params *scanp;
-    int ext_adv_mode = -1;
+    struct ble_ll_scan_sm *scansm = &g_ble_ll_scan_sm;
+    struct ble_ll_scan_params *scanp = scansm->scanp;
 #if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_EXT_ADV)
-    uint8_t phy_mode;
-    uint16_t adi;
-    struct ble_ll_aux_data *aux_data = NULL;
+    struct ble_ll_aux_data *aux_data = hdr->rxinfo.user_data;
 #endif
 #if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_PRIVACY)
+    struct ble_mbuf_hdr_rxinfo *rxinfo = &hdr->rxinfo;
     struct ble_ll_resolv_entry *rl = NULL;
-    bool resolve_peer = false;
 #endif
+    bool scan_req_allowed = true;
+    bool resolved = false;
 
-    /* Get scanning state machine */
-    scansm = &g_ble_ll_scan_sm;
-    scanp = scansm->scanp;
-
-    /*
-     * The reason we do something different here (as opposed to failed CRC) is
-     * that the received PDU will not be handed up in this case. So we have
-     * to restart scanning and handle a failed scan request. Note that we
-     * return 0 in this case because we dont want the phy disabled.
-     */
-    if (rxpdu == NULL) {
-        ble_ll_scan_interrupted(scansm);
-        return 0;
-    }
+    /* Use AdvA as initial advertiser address, we may try to resolve it later */
+    addrd->adv_addr = addrd->adva;
+    addrd->adv_addr_type = addrd->adva_type;
 
-    rc = -1;
+#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_PRIVACY)
+    /* By default, assume AdvA is not resolved */
+    rxinfo->rpa_index = -1;
 
-    ble_hdr = BLE_MBUF_HDR_PTR(rxpdu);
+    switch (ble_ll_addr_subtype(addrd->adva, addrd->adva_type)) {
+    case BLE_LL_ADDR_SUBTYPE_RPA:
+        /*
+         * Only resolve if packet actually contained AdvA.
+         * In extended advertising PDUs we may use RL index from a PDU that
+         * already had AdvA (e.g. ADV_EXT_IND in case of AUX_ADV_IND without
+         * AdvA). In legacy advertising PDUs we always need to resolve AdvA.
+         */
+        if (addrd->adva_present) {
+            rxinfo->rpa_index = ble_hw_resolv_list_match();
+        } else {
+#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_EXT_ADV)
+            BLE_LL_ASSERT(aux_data);
+            rxinfo->rpa_index = aux_data->rpa_index;
+#else
+            BLE_LL_ASSERT(false);
+            rxinfo->rpa_index = -1;
+#endif
+        }
 
-    /* Get pdu type, pointer to address and address "type"  */
-    rxbuf = rxpdu->om_data;
-    pdu_type = rxbuf[0] & BLE_ADV_PDU_HDR_TYPE_MASK;
+        if (rxinfo->rpa_index < 0) {
+            break;
+        }
 
 #if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_EXT_ADV)
-    if (scansm->cur_aux_data) {
-        ble_hdr->rxinfo.user_data = scansm->cur_aux_data;
-        scansm->cur_aux_data = NULL;
-        /* If we were expecting aux/chain and it not arrived,
-         * lets just exit here.
-         */
-        if (pdu_type != BLE_ADV_PDU_TYPE_ADV_EXT_IND) {
-            goto scan_rx_isr_exit;
+        if (aux_data) {
+            aux_data->rpa_index = rxinfo->rpa_index;
         }
-    }
 #endif
 
-    /* Just leave if the CRC is not OK. */
-    if (!crcok) {
-        goto scan_rx_isr_exit;
+        /* Use resolved identity address as advertiser address */
+        rl = &g_ble_ll_resolv_list[rxinfo->rpa_index];
+        addrd->adv_addr = rl->rl_identity_addr;
+        addrd->adv_addr_type = rl->rl_addr_type;
+        addrd->rl = rl;
+
+        rxinfo->flags |= BLE_MBUF_HDR_F_RESOLVED;
+        resolved = 1;
 
 Review comment:
   resolved is a bool type.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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