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/24 07:45:27 UTC

[GitHub] andrzej-kaczmarek closed pull request #228: Connection request rx while already connected

andrzej-kaczmarek closed pull request #228: Connection request rx while already connected
URL: https://github.com/apache/mynewt-nimble/pull/228
 
 
   

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/src/ble_ll_adv.c b/nimble/controller/src/ble_ll_adv.c
index 943d666d..e0307bd3 100644
--- a/nimble/controller/src/ble_ll_adv.c
+++ b/nimble/controller/src/ble_ll_adv.c
@@ -2572,6 +2572,34 @@ ble_ll_adv_clear_all(void)
 }
 #endif
 
+/**
+ * Says whether the specified address is already connected or not.
+ * @param   [in]    addr        The peer address.
+ * @param   [in]    addr_type   Public address (0) or random address (1).
+ * @return  Return 1 if already connected, 0 otherwise.
+ */
+static int
+ble_ll_adv_already_connected(const uint8_t* addr, uint8_t addr_type)
+{
+    struct ble_ll_conn_sm *connsm;
+
+    /* extracted from ble_ll_conn_slave_start function */
+    SLIST_FOREACH(connsm, &g_ble_ll_conn_active_list, act_sle) {
+        if (!memcmp(&connsm->peer_addr, addr, BLE_DEV_ADDR_LEN)) {
+            if (addr_type == BLE_ADDR_RANDOM) {
+                if (connsm->peer_addr_type & 1) {
+                    return 1;
+                }
+            } else {
+                if ((connsm->peer_addr_type & 1) == 0) {
+                    return 1;
+                }
+            }
+        }
+    }
+
+    return 0;
+}
 
 /**
  * Called when the LL receives a scan request or connection request
@@ -2690,6 +2718,11 @@ ble_ll_adv_rx_req(uint8_t pdu_type, struct os_mbuf *rxpdu)
             STATS_INC(ble_ll_stats, scan_rsp_txg);
         }
     } else if (pdu_type == BLE_ADV_PDU_TYPE_AUX_CONNECT_REQ) {
+        /* See if the device is already connected */
+        if (ble_ll_adv_already_connected(peer, peer_addr_type)) {
+            return -1;
+        }
+
         /*
          * Only accept connect requests from the desired address if we
          * are doing directed advertising


 

----------------------------------------------------------------
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