You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2015/11/09 23:11:35 UTC

incubator-mynewt-larva git commit: Add basic HCI create connection command.

Repository: incubator-mynewt-larva
Updated Branches:
  refs/heads/master 7e851280f -> 8508d9563


Add basic HCI create connection command.


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

Branch: refs/heads/master
Commit: 8508d9563d7a3eac571fe8ca7bbf3180242472a5
Parents: 7e85128
Author: Christopher Collins <cc...@gmail.com>
Authored: Mon Nov 9 14:10:54 2015 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Mon Nov 9 14:10:54 2015 -0800

----------------------------------------------------------------------
 net/nimble/host/include/host/host_hci.h |  3 +-
 net/nimble/host/src/host_hci.c          | 78 ++++++++++++++++++++++++++++
 net/nimble/include/nimble/hci_common.h  |  6 +++
 3 files changed, 86 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/8508d956/net/nimble/host/include/host/host_hci.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/host_hci.h b/net/nimble/host/include/host/host_hci.h
index aa080f2..cf629c3 100644
--- a/net/nimble/host/include/host/host_hci.h
+++ b/net/nimble/host/include/host/host_hci.h
@@ -26,10 +26,11 @@ int host_hci_cmd_le_set_adv_params(struct hci_adv_params *adv);
 int host_hci_cmd_le_set_rand_addr(uint8_t *addr);
 int host_hci_cmd_le_set_event_mask(uint64_t event_mask);
 int host_hci_cmd_le_set_adv_enable(uint8_t enable);
-int host_hci_cmd_le_set_scan_enable(uint8_t enable, uint8_t filter_dups);
 int host_hci_cmd_le_set_scan_params(uint8_t scan_type, uint16_t scan_itvl, 
                                     uint16_t scan_window, uint8_t own_addr_type,
                                     uint8_t filter_policy);
+int host_hci_cmd_le_set_scan_enable(uint8_t enable, uint8_t filter_dups);
+int host_hci_cmd_le_create_connection(struct hci_create_conn *hcc);
 int host_hci_cmd_le_clear_whitelist(void);
 int host_hci_cmd_le_read_whitelist(void);
 int host_hci_cmd_le_add_to_whitelist(uint8_t *addr, uint8_t addr_type);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/8508d956/net/nimble/host/src/host_hci.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/host_hci.c b/net/nimble/host/src/host_hci.c
index 04917d2..17b11e2 100644
--- a/net/nimble/host/src/host_hci.c
+++ b/net/nimble/host/src/host_hci.c
@@ -297,6 +297,84 @@ host_hci_cmd_le_set_scan_enable(uint8_t enable, uint8_t filter_dups)
     return rc;
 }
 
+int
+host_hci_cmd_le_create_connection(struct hci_create_conn *hcc)
+{
+    int rc;
+    uint8_t cmd[BLE_HCI_CREATE_CONN_LEN];
+
+    /* Check scan interval and scan window */
+    if ((hcc->scan_itvl < BLE_HCI_SCAN_ITVL_MIN) ||
+        (hcc->scan_itvl > BLE_HCI_SCAN_ITVL_MAX) ||
+        (hcc->scan_window < BLE_HCI_SCAN_WINDOW_MIN) ||
+        (hcc->scan_window > BLE_HCI_SCAN_WINDOW_MAX) ||
+        (hcc->scan_itvl < hcc->scan_window)) {
+        return BLE_ERR_INV_HCI_CMD_PARMS;
+    }
+
+    /* Check initiator filter policy */
+    if (hcc->filter_policy > BLE_HCI_SCAN_FILT_MAX) {
+        return BLE_ERR_INV_HCI_CMD_PARMS;
+    }
+
+    /* Check peer addr type */
+    if (hcc->peer_addr_type > BLE_HCI_ADV_OWN_ADDR_MAX) {
+        return BLE_ERR_INV_HCI_CMD_PARMS;
+    }
+
+    /* Check own addr type */
+    if (hcc->own_addr_type > BLE_HCI_ADV_OWN_ADDR_MAX) {
+        return BLE_ERR_INV_HCI_CMD_PARMS;
+    }
+
+    /* Check connection interval min */
+    if ((hcc->conn_itvl_min < BLE_HCI_CONN_ITVL_MIN) ||
+        (hcc->conn_itvl_min > BLE_HCI_CONN_ITVL_MAX)) {
+        return BLE_ERR_INV_HCI_CMD_PARMS;
+    }
+
+    /* Check connection interval max */
+    if ((hcc->conn_itvl_max < BLE_HCI_CONN_ITVL_MIN) ||
+        (hcc->conn_itvl_max > BLE_HCI_CONN_ITVL_MAX) ||
+        (hcc->conn_itvl_max < hcc->conn_itvl_min)) {
+        return BLE_ERR_INV_HCI_CMD_PARMS;
+    }
+
+    /* Check connection latency */
+    if ((hcc->conn_latency < BLE_HCI_CONN_LATENCY_MIN) ||
+        (hcc->conn_latency > BLE_HCI_CONN_LATENCY_MAX)) {
+        return BLE_ERR_INV_HCI_CMD_PARMS;
+    }
+
+    /* Check supervision timeout */
+    if ((hcc->supervision_timeout < BLE_HCI_CONN_SPVN_TIMEOUT_MIN) ||
+        (hcc->supervision_timeout > BLE_HCI_CONN_SPVN_TIMEOUT_MAX)) {
+        return BLE_ERR_INV_HCI_CMD_PARMS;
+    }
+
+    /* Check connection event length */
+    if (hcc->min_ce_len > hcc->max_ce_len) {
+        return BLE_ERR_INV_HCI_CMD_PARMS;
+    }
+
+    htole16(cmd + 0, hcc->scan_itvl);
+    htole16(cmd + 2, hcc->scan_window);
+    cmd[4] = hcc->filter_policy;
+    cmd[5] = hcc->peer_addr_type;
+    memcpy(cmd + 6, hcc->peer_addr, BLE_DEV_ADDR_LEN);
+    cmd[12] = hcc->own_addr_type;
+    htole16(cmd + 13, hcc->conn_itvl_min);
+    htole16(cmd + 15, hcc->conn_itvl_max);
+    htole16(cmd + 17, hcc->conn_latency);
+    htole16(cmd + 19, hcc->supervision_timeout);
+    htole16(cmd + 21, hcc->min_ce_len);
+    htole16(cmd + 23, hcc->max_ce_len);
+
+    rc = host_hci_le_cmd_send(BLE_HCI_OCF_LE_CREATE_CONN,
+                              BLE_HCI_CREATE_CONN_LEN, cmd);
+    return rc;
+}
+
 /**
  * Clear the whitelist.
  * 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/8508d956/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 a0f877f..69abc89 100644
--- a/net/nimble/include/nimble/hci_common.h
+++ b/net/nimble/include/nimble/hci_common.h
@@ -215,6 +215,12 @@
 
 /* Create Connection */
 #define BLE_HCI_CREATE_CONN_LEN             (25)             
+#define BLE_HCI_CONN_ITVL_MIN               (0x0006)
+#define BLE_HCI_CONN_ITVL_MAX               (0x0c80)
+#define BLE_HCI_CONN_LATENCY_MIN            (0x0000)
+#define BLE_HCI_CONN_LATENCY_MAX            (0x01f3)
+#define BLE_HCI_CONN_SPVN_TIMEOUT_MIN       (0x000a)
+#define BLE_HCI_CONN_SPVN_TIMEOUT_MAX       (0x0c80)
 
 /* Event Codes */
 #define BLE_HCI_EVCODE_INQUIRY_CMP          (0x01)