nimble/controller: Send LE Channel Selection Algorithm Event

If connection is created and LE Channel Selection Algorithm Event is
unmasked send it immediately after LE (Enhanced) Connection Complete
event.

< HCI Command: LE Set Event Mask (0x08|0x0001) plen 8       25.731854
        Mask: 0x000000000008045f
          LE Connection Complete
          LE Advertising Report
          LE Connection Update Complete
          LE Read Remote Used Features Complete
          LE Long Term Key Request
          LE Data Length Change
          LE Direct Advertising Report
          LE Channel Selection Algorithm

....

> HCI Event: LE Meta Event (0x3e) plen 19                   44.589758
      LE Connection Complete (0x01)
        Status: Success (0x00)
        Handle: 1
        Role: Master (0x00)
        Peer address type: Public (0x00)
        Peer address: 0A:0A:0A:0A:0A:0A (OUI 0A-0A-0A)
        Connection interval: 18.75 msec (0x000f)
        Connection latency: 0.00 msec (0x0000)
        Supervision timeout: 32000 msec (0x0c80)
        Master clock accuracy: 0x04
> HCI Event: LE Meta Event (0x3e) plen 4                    44.589780
      LE Channel Selection Algorithm (0x14)
        Handle: 1
        LE Channel Selection Algorithm #2 (0x01)


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/a7d39f92
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/a7d39f92
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/a7d39f92

Branch: refs/heads/bluetooth5
Commit: a7d39f9295576faf9f04ce89f6ee223643dd4f87
Parents: 8e0cf0d
Author: Szymon Janc <[email protected]>
Authored: Thu Apr 6 15:47:05 2017 +0200
Committer: Szymon Janc <[email protected]>
Committed: Fri Apr 7 13:59:51 2017 +0200

----------------------------------------------------------------------
 .../controller/include/controller/ble_ll_ctrl.h |  2 +-
 net/nimble/controller/src/ble_ll_adv.c          |  1 +
 net/nimble/controller/src/ble_ll_conn.c         |  1 +
 net/nimble/controller/src/ble_ll_hci_ev.c       | 23 ++++++++++++++++++++
 net/nimble/include/nimble/hci_common.h          |  3 +++
 5 files changed, 29 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a7d39f92/net/nimble/controller/include/controller/ble_ll_ctrl.h
----------------------------------------------------------------------
diff --git a/net/nimble/controller/include/controller/ble_ll_ctrl.h 
b/net/nimble/controller/include/controller/ble_ll_ctrl.h
index ab302e4..23da308 100644
--- a/net/nimble/controller/include/controller/ble_ll_ctrl.h
+++ b/net/nimble/controller/include/controller/ble_ll_ctrl.h
@@ -250,7 +250,7 @@ void ble_ll_hci_ev_encrypt_chg(struct ble_ll_conn_sm 
*connsm, uint8_t status);
 int ble_ll_hci_ev_ltk_req(struct ble_ll_conn_sm *connsm);
 int ble_ll_hci_ev_hw_err(uint8_t hw_err);
 void ble_ll_hci_ev_databuf_overflow(void);
-
+void ble_ll_hci_ev_le_csa(struct ble_ll_conn_sm *connsm);
 
 void ble_ll_calc_session_key(struct ble_ll_conn_sm *connsm);
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a7d39f92/net/nimble/controller/src/ble_ll_adv.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_adv.c 
b/net/nimble/controller/src/ble_ll_adv.c
index 19a8a49..8ce9bf3 100644
--- a/net/nimble/controller/src/ble_ll_adv.c
+++ b/net/nimble/controller/src/ble_ll_adv.c
@@ -1724,6 +1724,7 @@ ble_ll_adv_send_conn_comp_ev(struct ble_ll_conn_sm 
*connsm,
     advsm->conn_comp_ev = NULL;
 
     ble_ll_conn_comp_event_send(connsm, BLE_ERR_SUCCESS, evbuf, advsm);
+    ble_ll_hci_ev_le_csa(connsm);
 }
 
 /**

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a7d39f92/net/nimble/controller/src/ble_ll_conn.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_conn.c 
b/net/nimble/controller/src/ble_ll_conn.c
index 0e5a904..10b5cc7 100644
--- a/net/nimble/controller/src/ble_ll_conn.c
+++ b/net/nimble/controller/src/ble_ll_conn.c
@@ -2119,6 +2119,7 @@ ble_ll_conn_created(struct ble_ll_conn_sm *connsm, struct 
ble_mbuf_hdr *rxhdr)
         } else {
             evbuf = ble_ll_init_get_conn_comp_ev();
             ble_ll_conn_comp_event_send(connsm, BLE_ERR_SUCCESS, evbuf, NULL);
+            ble_ll_hci_ev_le_csa(connsm);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a7d39f92/net/nimble/controller/src/ble_ll_hci_ev.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_hci_ev.c 
b/net/nimble/controller/src/ble_ll_hci_ev.c
index e0803cd..ac9398e 100644
--- a/net/nimble/controller/src/ble_ll_hci_ev.c
+++ b/net/nimble/controller/src/ble_ll_hci_ev.c
@@ -267,3 +267,26 @@ ble_ll_hci_ev_databuf_overflow(void)
         }
     }
 }
+
+/**
+ * Send a LE Channel Selection Algorithm event.
+ *
+ * @param connsm Pointer to connection state machine
+ */
+void
+ble_ll_hci_ev_le_csa(struct ble_ll_conn_sm *connsm)
+{
+    uint8_t *evbuf;
+
+    if (ble_ll_hci_is_le_event_enabled(BLE_HCI_LE_SUBEV_CHAN_SEL_ALG)) {
+        evbuf = ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_HI);
+        if (evbuf) {
+            evbuf[0] = BLE_HCI_EVCODE_LE_META;
+            evbuf[1] = BLE_HCI_LE_SUBEV_CHAN_SEL_ALG_LEN;
+            evbuf[2] = BLE_HCI_LE_SUBEV_CHAN_SEL_ALG;
+            put_le16(evbuf + 3, connsm->conn_handle);
+            evbuf[5] = connsm->csmflags.cfbit.csa2_supp ? 0x01 : 0x00;
+            ble_ll_hci_event_send(evbuf);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a7d39f92/net/nimble/include/nimble/hci_common.h
----------------------------------------------------------------------
diff --git a/net/nimble/include/nimble/hci_common.h 
b/net/nimble/include/nimble/hci_common.h
index e9b520b..7404627 100644
--- a/net/nimble/include/nimble/hci_common.h
+++ b/net/nimble/include/nimble/hci_common.h
@@ -662,6 +662,9 @@ extern "C" {
 /* LE data length change event (sub event 0x07) */
 #define BLE_HCI_LE_DATA_LEN_CHG_LEN         (11)
 
+/* LE Channel Selection Algorithm event (sub event 0x14) */
+#define BLE_HCI_LE_SUBEV_CHAN_SEL_ALG_LEN   (4)
+
 /* Bluetooth Assigned numbers for version information.*/
 #define BLE_HCI_VER_BCS_1_0b                (0)
 #define BLE_HCI_VER_BCS_1_1                 (1)

Reply via email to