You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by st...@apache.org on 2016/08/09 23:07:35 UTC
[01/42] incubator-mynewt-core git commit: BLE Host - Cleanup att_svr
rx prep / exec write.
Repository: incubator-mynewt-core
Updated Branches:
refs/heads/sterly_refactor 904ec76d6 -> 79922ef3b
BLE Host - Cleanup att_svr rx prep / exec write.
While debugging an mbuf leak, I noticed this code was much more
complicated than it needs to be.
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/79922ef3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/79922ef3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/79922ef3
Branch: refs/heads/sterly_refactor
Commit: 79922ef3b2f0f52721a23f4a62d0f9a34f39737d
Parents: abd5a75
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Aug 9 12:46:50 2016 -0700
Committer: Sterling Hughes <st...@apache.org>
Committed: Tue Aug 9 16:05:21 2016 -0700
----------------------------------------------------------------------
net/nimble/host/src/ble_att_svr.c | 123 +++++++++++++++------------------
1 file changed, 57 insertions(+), 66 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/79922ef3/net/nimble/host/src/ble_att_svr.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_svr.c b/net/nimble/host/src/ble_att_svr.c
index 860794d..93c57ff 100644
--- a/net/nimble/host/src/ble_att_svr.c
+++ b/net/nimble/host/src/ble_att_svr.c
@@ -2182,8 +2182,10 @@ ble_att_svr_write_local(uint16_t attr_handle, struct os_mbuf *om)
static void
ble_att_svr_prep_free(struct ble_att_prep_entry *entry)
{
- os_mbuf_free_chain(entry->bape_value);
- os_memblock_put(&ble_att_svr_prep_entry_pool, entry);
+ if (entry != NULL) {
+ os_mbuf_free_chain(entry->bape_value);
+ os_memblock_put(&ble_att_svr_prep_entry_pool, entry);
+ }
}
static struct ble_att_prep_entry *
@@ -2360,6 +2362,56 @@ ble_att_svr_prep_write(uint16_t conn_handle,
return 0;
}
+static int
+ble_att_svr_insert_prep_entry(uint16_t conn_handle,
+ const struct ble_att_prep_write_cmd *req,
+ const struct os_mbuf *rxom,
+ uint8_t *out_att_err)
+{
+ struct ble_att_prep_entry *prep_entry;
+ struct ble_att_prep_entry *prep_prev;
+ struct ble_hs_conn *conn;
+ int rc;
+
+ conn = ble_hs_conn_find(conn_handle);
+ if (conn == NULL) {
+ *out_att_err = 0;
+ return BLE_HS_ENOTCONN;
+ }
+
+ prep_entry = ble_att_svr_prep_alloc();
+ if (prep_entry == NULL) {
+ *out_att_err = BLE_ATT_ERR_PREPARE_QUEUE_FULL;
+ return BLE_HS_ENOMEM;
+ }
+ prep_entry->bape_handle = req->bapc_handle;
+ prep_entry->bape_offset = req->bapc_offset;
+
+ /* Append attribute value from request onto prep mbuf. */
+ rc = os_mbuf_appendfrom(
+ prep_entry->bape_value,
+ rxom,
+ BLE_ATT_PREP_WRITE_CMD_BASE_SZ,
+ OS_MBUF_PKTLEN(rxom) - BLE_ATT_PREP_WRITE_CMD_BASE_SZ);
+ if (rc != 0) {
+ ble_att_svr_prep_free(prep_entry);
+ *out_att_err = BLE_ATT_ERR_PREPARE_QUEUE_FULL;
+ return rc;
+ }
+
+ prep_prev = ble_att_svr_prep_find_prev(&conn->bhc_att_svr,
+ req->bapc_handle,
+ req->bapc_offset);
+ if (prep_prev == NULL) {
+ SLIST_INSERT_HEAD(&conn->bhc_att_svr.basc_prep_list, prep_entry,
+ bape_next);
+ } else {
+ SLIST_INSERT_AFTER(prep_prev, prep_entry, bape_next);
+ }
+
+ return 0;
+}
+
int
ble_att_svr_rx_prep_write(uint16_t conn_handle, struct os_mbuf **rxom)
{
@@ -2368,17 +2420,13 @@ ble_att_svr_rx_prep_write(uint16_t conn_handle, struct os_mbuf **rxom)
#endif
struct ble_att_prep_write_cmd req;
- struct ble_att_prep_entry *prep_entry;
- struct ble_att_prep_entry *prep_prev;
struct ble_att_svr_entry *attr_entry;
- struct ble_hs_conn *conn;
struct os_mbuf *txom;
uint16_t err_handle;
uint8_t att_err;
int rc;
/* Initialize some values in case of early error. */
- prep_entry = NULL;
txom = NULL;
att_err = 0;
err_handle = 0;
@@ -2419,49 +2467,16 @@ ble_att_svr_rx_prep_write(uint16_t conn_handle, struct os_mbuf **rxom)
goto done;
}
- prep_entry = ble_att_svr_prep_alloc();
- if (prep_entry == NULL) {
- att_err = BLE_ATT_ERR_PREPARE_QUEUE_FULL;
- rc = BLE_HS_ENOMEM;
- goto done;
- }
- prep_entry->bape_handle = req.bapc_handle;
- prep_entry->bape_offset = req.bapc_offset;
-
ble_hs_lock();
-
- conn = ble_hs_conn_find(conn_handle);
- if (conn == NULL) {
- rc = BLE_HS_ENOTCONN;
- } else {
- prep_prev = ble_att_svr_prep_find_prev(&conn->bhc_att_svr,
- req.bapc_handle,
- req.bapc_offset);
- if (prep_prev == NULL) {
- SLIST_INSERT_HEAD(&conn->bhc_att_svr.basc_prep_list, prep_entry,
- bape_next);
- } else {
- SLIST_INSERT_AFTER(prep_prev, prep_entry, bape_next);
- }
-
- /* Append attribute value from request onto prep mbuf. */
- rc = os_mbuf_appendfrom(prep_entry->bape_value, *rxom,
- BLE_ATT_PREP_WRITE_CMD_BASE_SZ,
- OS_MBUF_PKTLEN(*rxom) -
- BLE_ATT_PREP_WRITE_CMD_BASE_SZ);
- if (rc != 0) {
- att_err = BLE_ATT_ERR_PREPARE_QUEUE_FULL;
- }
- }
-
+ rc = ble_att_svr_insert_prep_entry(conn_handle, &req, *rxom, &att_err);
ble_hs_unlock();
if (rc != 0) {
goto done;
}
- /* Reuse rxom for response. Response is identical to request except for op
- * code.
+ /* Reuse rxom for response. Response is identical to request except for
+ * op code.
*/
txom = *rxom;
*rxom = NULL;
@@ -2473,32 +2488,8 @@ ble_att_svr_rx_prep_write(uint16_t conn_handle, struct os_mbuf **rxom)
rc = 0;
done:
- if (rc != 0 && rc != BLE_HS_ENOTCONN) {
- ble_hs_lock();
-
- conn = ble_hs_conn_find(conn_handle);
- if (conn == NULL) {
- rc = BLE_HS_ENOTCONN;
- } else {
- if (prep_entry != NULL) {
- if (prep_prev == NULL) {
- SLIST_REMOVE_HEAD(&conn->bhc_att_svr.basc_prep_list,
- bape_next);
- } else {
- SLIST_NEXT(prep_prev, bape_next) =
- SLIST_NEXT(prep_entry, bape_next);
- }
-
- ble_att_svr_prep_free(prep_entry);
- }
- }
-
- ble_hs_unlock();
- }
-
rc = ble_att_svr_tx_rsp(conn_handle, rc, txom, BLE_ATT_OP_PREP_WRITE_REQ,
att_err, err_handle);
-
return rc;
}
[17/42] incubator-mynewt-core git commit: BLE Host - Rename HCI
identifiers and files.
Posted by st...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/net/nimble/host/src/ble_hs_hci.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_hci.c b/net/nimble/host/src/ble_hs_hci.c
new file mode 100644
index 0000000..cd5cc6c
--- /dev/null
+++ b/net/nimble/host/src/ble_hs_hci.c
@@ -0,0 +1,528 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+#include <stdint.h>
+#include <string.h>
+#include <errno.h>
+#include <stdio.h>
+#include "os/os.h"
+#include "nimble/ble_hci_trans.h"
+#include "ble_hs_priv.h"
+#include "ble_hs_dbg_priv.h"
+
+#define BLE_HCI_CMD_TIMEOUT (OS_TICKS_PER_SEC)
+
+static struct os_mutex ble_hs_hci_mutex;
+static struct os_sem ble_hs_hci_sem;
+
+static uint8_t *ble_hs_hci_ack;
+static uint16_t ble_hs_hci_buf_sz;
+static uint8_t ble_hs_hci_max_pkts;
+
+#if PHONY_HCI_ACKS
+static ble_hs_hci_phony_ack_fn *ble_hs_hci_phony_ack_cb;
+#endif
+
+#if PHONY_HCI_ACKS
+void
+ble_hs_hci_set_phony_ack_cb(ble_hs_hci_phony_ack_fn *cb)
+{
+ ble_hs_hci_phony_ack_cb = cb;
+}
+#endif
+
+static void
+ble_hs_hci_lock(void)
+{
+ int rc;
+
+ rc = os_mutex_pend(&ble_hs_hci_mutex, 0xffffffff);
+ BLE_HS_DBG_ASSERT_EVAL(rc == 0 || rc == OS_NOT_STARTED);
+}
+
+static void
+ble_hs_hci_unlock(void)
+{
+ int rc;
+
+ rc = os_mutex_release(&ble_hs_hci_mutex);
+ BLE_HS_DBG_ASSERT_EVAL(rc == 0 || rc == OS_NOT_STARTED);
+}
+
+int
+ble_hs_hci_set_buf_sz(uint16_t pktlen, uint8_t max_pkts)
+{
+ if (pktlen == 0 || max_pkts == 0) {
+ return BLE_HS_EINVAL;
+ }
+
+ ble_hs_hci_buf_sz = pktlen;
+ ble_hs_hci_max_pkts = max_pkts;
+
+ return 0;
+}
+
+static int
+ble_hs_hci_rx_cmd_complete(uint8_t event_code, uint8_t *data, int len,
+ struct ble_hs_hci_ack *out_ack)
+{
+ uint16_t opcode;
+ uint8_t *params;
+ uint8_t params_len;
+ uint8_t num_pkts;
+
+ if (len < BLE_HCI_EVENT_CMD_COMPLETE_HDR_LEN) {
+ return BLE_HS_ECONTROLLER;
+ }
+
+ num_pkts = data[2];
+ opcode = le16toh(data + 3);
+ params = data + 5;
+
+ /* XXX: Process num_pkts field. */
+ (void)num_pkts;
+
+ out_ack->bha_opcode = opcode;
+
+ params_len = len - BLE_HCI_EVENT_CMD_COMPLETE_HDR_LEN;
+ if (params_len > 0) {
+ out_ack->bha_status = BLE_HS_HCI_ERR(params[0]);
+ } else if (opcode == BLE_HCI_OPCODE_NOP) {
+ out_ack->bha_status = 0;
+ } else {
+ out_ack->bha_status = BLE_HS_ECONTROLLER;
+ }
+
+ /* Don't include the status byte in the parameters blob. */
+ if (params_len > 1) {
+ out_ack->bha_params = params + 1;
+ out_ack->bha_params_len = params_len - 1;
+ } else {
+ out_ack->bha_params = NULL;
+ out_ack->bha_params_len = 0;
+ }
+
+ return 0;
+}
+
+static int
+ble_hs_hci_rx_cmd_status(uint8_t event_code, uint8_t *data, int len,
+ struct ble_hs_hci_ack *out_ack)
+{
+ uint16_t opcode;
+ uint8_t num_pkts;
+ uint8_t status;
+
+ if (len < BLE_HCI_EVENT_CMD_STATUS_LEN) {
+ return BLE_HS_ECONTROLLER;
+ }
+
+ status = data[2];
+ num_pkts = data[3];
+ opcode = le16toh(data + 4);
+
+ /* XXX: Process num_pkts field. */
+ (void)num_pkts;
+
+ out_ack->bha_opcode = opcode;
+ out_ack->bha_params = NULL;
+ out_ack->bha_params_len = 0;
+ out_ack->bha_status = BLE_HS_HCI_ERR(status);
+
+ return 0;
+}
+
+static int
+ble_hs_hci_process_ack(uint16_t expected_opcode,
+ uint8_t *params_buf, uint8_t params_buf_len,
+ struct ble_hs_hci_ack *out_ack)
+{
+ uint8_t event_code;
+ uint8_t param_len;
+ uint8_t event_len;
+ int rc;
+
+ BLE_HS_DBG_ASSERT(ble_hs_hci_ack != NULL);
+
+ /* Count events received */
+ STATS_INC(ble_hs_stats, hci_event);
+
+ /* Display to console */
+ ble_hs_dbg_event_disp(ble_hs_hci_ack);
+
+ event_code = ble_hs_hci_ack[0];
+ param_len = ble_hs_hci_ack[1];
+ event_len = param_len + 2;
+
+ /* Clear ack fields up front to silence spurious gcc warnings. */
+ memset(out_ack, 0, sizeof *out_ack);
+
+ switch (event_code) {
+ case BLE_HCI_EVCODE_COMMAND_COMPLETE:
+ rc = ble_hs_hci_rx_cmd_complete(event_code, ble_hs_hci_ack,
+ event_len, out_ack);
+ break;
+
+ case BLE_HCI_EVCODE_COMMAND_STATUS:
+ rc = ble_hs_hci_rx_cmd_status(event_code, ble_hs_hci_ack,
+ event_len, out_ack);
+ break;
+
+ default:
+ BLE_HS_DBG_ASSERT(0);
+ rc = BLE_HS_EUNKNOWN;
+ break;
+ }
+
+ if (rc == 0) {
+ if (params_buf == NULL) {
+ out_ack->bha_params_len = 0;
+ } else {
+ if (out_ack->bha_params_len > params_buf_len) {
+ out_ack->bha_params_len = params_buf_len;
+ rc = BLE_HS_ECONTROLLER;
+ }
+ memcpy(params_buf, out_ack->bha_params, out_ack->bha_params_len);
+ }
+ out_ack->bha_params = params_buf;
+
+ if (out_ack->bha_opcode != expected_opcode) {
+ rc = BLE_HS_ECONTROLLER;
+ }
+ }
+
+ if (rc != 0) {
+ STATS_INC(ble_hs_stats, hci_invalid_ack);
+ }
+
+ return rc;
+}
+
+static int
+ble_hs_hci_wait_for_ack(void)
+{
+ int rc;
+
+#if PHONY_HCI_ACKS
+ if (ble_hs_hci_phony_ack_cb == NULL) {
+ rc = BLE_HS_ETIMEOUT_HCI;
+ } else {
+ ble_hs_hci_ack =
+ ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_CMD);
+ BLE_HS_DBG_ASSERT(ble_hs_hci_ack != NULL);
+ rc = ble_hs_hci_phony_ack_cb(ble_hs_hci_ack, 260);
+ }
+#else
+ rc = os_sem_pend(&ble_hs_hci_sem, BLE_HCI_CMD_TIMEOUT);
+ switch (rc) {
+ case 0:
+ BLE_HS_DBG_ASSERT(ble_hs_hci_ack != NULL);
+ break;
+ case OS_TIMEOUT:
+ rc = BLE_HS_ETIMEOUT_HCI;
+ STATS_INC(ble_hs_stats, hci_timeout);
+ break;
+ default:
+ rc = BLE_HS_EOS;
+ break;
+ }
+#endif
+
+ return rc;
+}
+
+int
+ble_hs_hci_cmd_tx(void *cmd, void *evt_buf, uint8_t evt_buf_len,
+ uint8_t *out_evt_buf_len)
+{
+ struct ble_hs_hci_ack ack;
+ uint16_t opcode;
+ int rc;
+
+ opcode = le16toh(cmd);
+
+ BLE_HS_DBG_ASSERT(ble_hs_hci_ack == NULL);
+ ble_hs_hci_lock();
+
+ rc = ble_hs_hci_cmd_send_buf(cmd);
+ if (rc != 0) {
+ goto done;
+ }
+
+ rc = ble_hs_hci_wait_for_ack();
+ if (rc != 0) {
+ ble_hs_sched_reset(rc);
+ goto done;
+ }
+
+ rc = ble_hs_hci_process_ack(opcode, evt_buf, evt_buf_len, &ack);
+ if (rc != 0) {
+ ble_hs_sched_reset(rc);
+ goto done;
+ }
+
+ if (out_evt_buf_len != NULL) {
+ *out_evt_buf_len = ack.bha_params_len;
+ }
+
+ rc = ack.bha_status;
+
+done:
+ if (ble_hs_hci_ack != NULL) {
+ ble_hci_trans_buf_free(ble_hs_hci_ack);
+ ble_hs_hci_ack = NULL;
+ }
+
+ ble_hs_hci_unlock();
+ return rc;
+}
+
+int
+ble_hs_hci_cmd_tx_empty_ack(void *cmd)
+{
+ int rc;
+
+ rc = ble_hs_hci_cmd_tx(cmd, NULL, 0, NULL);
+ if (rc != 0) {
+ return rc;
+ }
+
+ return 0;
+}
+
+void
+ble_hs_hci_rx_ack(uint8_t *ack_ev)
+{
+ if (ble_hs_hci_sem.sem_tokens != 0) {
+ /* This ack is unexpected; ignore it. */
+ ble_hci_trans_buf_free(ack_ev);
+ return;
+ }
+ BLE_HS_DBG_ASSERT(ble_hs_hci_ack == NULL);
+
+ /* Unblock the application now that the HCI command buffer is populated
+ * with the acknowledgement.
+ */
+ ble_hs_hci_ack = ack_ev;
+ os_sem_release(&ble_hs_hci_sem);
+}
+
+int
+ble_hs_hci_rx_evt(uint8_t *hci_ev, void *arg)
+{
+ int enqueue;
+
+ BLE_HS_DBG_ASSERT(hci_ev != NULL);
+
+ switch (hci_ev[0]) {
+ case BLE_HCI_EVCODE_COMMAND_COMPLETE:
+ case BLE_HCI_EVCODE_COMMAND_STATUS:
+ if (hci_ev[3] == 0 && hci_ev[4] == 0) {
+ enqueue = 1;
+ } else {
+ ble_hs_hci_rx_ack(hci_ev);
+ enqueue = 0;
+ }
+ break;
+
+ default:
+ enqueue = 1;
+ break;
+ }
+
+ if (enqueue) {
+ ble_hs_enqueue_hci_event(hci_ev);
+ }
+
+ return 0;
+}
+
+
+/**
+ * Splits an appropriately-sized fragment from the front of an outgoing ACL
+ * data packet, if necessary. If the packet size is within the controller's
+ * buffer size requirements, no splitting is performed. The fragment data is
+ * removed from the data packet mbuf.
+ *
+ * @param om The ACL data packet.
+ * @param out_frag On success, this points to the fragment to
+ * send. If the entire packet can fit within
+ * a single fragment, this will point to the
+ * ACL data packet itself ('om').
+ *
+ * @return BLE_HS_EDONE: success; this is the final
+ * fragment.
+ * BLE_HS_EAGAIN: success; more data remains in
+ * the original mbuf.
+ * Other BLE host core return code on error.
+ */
+static int
+ble_hs_hci_split_frag(struct os_mbuf **om, struct os_mbuf **out_frag)
+{
+ struct os_mbuf *frag;
+ int rc;
+
+ if (OS_MBUF_PKTLEN(*om) <= ble_hs_hci_buf_sz) {
+ /* Final fragment. */
+ *out_frag = *om;
+ *om = NULL;
+ return BLE_HS_EDONE;
+ }
+
+ frag = ble_hs_mbuf_acm_pkt();
+ if (frag == NULL) {
+ rc = BLE_HS_ENOMEM;
+ goto err;
+ }
+
+ /* Move data from the front of the packet into the fragment mbuf. */
+ rc = os_mbuf_appendfrom(frag, *om, 0, ble_hs_hci_buf_sz);
+ if (rc != 0) {
+ rc = BLE_HS_ENOMEM;
+ goto err;
+ }
+ os_mbuf_adj(*om, ble_hs_hci_buf_sz);
+
+ /* More fragments to follow. */
+ *out_frag = frag;
+ return BLE_HS_EAGAIN;
+
+err:
+ os_mbuf_free_chain(frag);
+ return rc;
+}
+
+static struct os_mbuf *
+ble_hs_hci_acl_hdr_prepend(struct os_mbuf *om, uint16_t handle,
+ uint8_t pb_flag)
+{
+ struct hci_data_hdr hci_hdr;
+ struct os_mbuf *om2;
+
+ hci_hdr.hdh_handle_pb_bc =
+ ble_hs_hci_util_handle_pb_bc_join(handle, pb_flag, 0);
+ htole16(&hci_hdr.hdh_len, OS_MBUF_PKTHDR(om)->omp_len);
+
+ om2 = os_mbuf_prepend(om, sizeof hci_hdr);
+ if (om2 == NULL) {
+ return NULL;
+ }
+
+ om = om2;
+ om = os_mbuf_pullup(om, sizeof hci_hdr);
+ if (om == NULL) {
+ return NULL;
+ }
+
+ memcpy(om->om_data, &hci_hdr, sizeof hci_hdr);
+
+ BLE_HS_LOG(DEBUG, "host tx hci data; handle=%d length=%d\n", handle,
+ le16toh(&hci_hdr.hdh_len));
+
+ return om;
+}
+
+/**
+ * Transmits an HCI ACL data packet. This function consumes the supplied mbuf,
+ * regardless of the outcome.
+ *
+ * XXX: Ensure the controller has sufficient buffer capacity for the outgoing
+ * fragments.
+ */
+int
+ble_hs_hci_acl_tx(struct ble_hs_conn *connection, struct os_mbuf *txom)
+{
+ struct os_mbuf *frag;
+ uint8_t pb;
+ int done;
+ int rc;
+
+ /* The first fragment uses the first-non-flush packet boundary value.
+ * After sending the first fragment, pb gets set appropriately for all
+ * subsequent fragments in this packet.
+ */
+ pb = BLE_HCI_PB_FIRST_NON_FLUSH;
+
+ /* Send fragments until the entire packet has been sent. */
+ done = 0;
+ while (!done) {
+ rc = ble_hs_hci_split_frag(&txom, &frag);
+ switch (rc) {
+ case BLE_HS_EDONE:
+ /* This is the final fragment. */
+ done = 1;
+ break;
+
+ case BLE_HS_EAGAIN:
+ /* More fragments to follow. */
+ break;
+
+ default:
+ goto err;
+ }
+
+ frag = ble_hs_hci_acl_hdr_prepend(frag, connection->bhc_handle, pb);
+ if (frag == NULL) {
+ rc = BLE_HS_ENOMEM;
+ goto err;
+ }
+ pb = BLE_HCI_PB_MIDDLE;
+
+ BLE_HS_LOG(DEBUG, "ble_hs_hci_acl_tx(): ");
+ ble_hs_log_mbuf(frag);
+ BLE_HS_LOG(DEBUG, "\n");
+
+ /* XXX: Try to pullup the entire fragment. The controller currently
+ * requires the entire fragment to fit in a single buffer. When this
+ * restriction is removed from the controller, this operation can be
+ * removed.
+ */
+ frag = os_mbuf_pullup(frag, OS_MBUF_PKTLEN(frag));
+ if (frag == NULL) {
+ rc = BLE_HS_ENOMEM;
+ goto err;
+ }
+
+ rc = ble_hs_tx_data(frag);
+ if (rc != 0) {
+ goto err;
+ }
+
+ connection->bhc_outstanding_pkts++;
+ }
+
+ return 0;
+
+err:
+ BLE_HS_DBG_ASSERT(rc != 0);
+
+ os_mbuf_free_chain(txom);
+ return rc;
+}
+
+void
+ble_hs_hci_init(void)
+{
+ int rc;
+
+ rc = os_sem_init(&ble_hs_hci_sem, 0);
+ BLE_HS_DBG_ASSERT_EVAL(rc == 0);
+
+ rc = os_mutex_init(&ble_hs_hci_mutex);
+ BLE_HS_DBG_ASSERT_EVAL(rc == 0);
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/net/nimble/host/src/ble_hs_hci_cmd.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_hci_cmd.c b/net/nimble/host/src/ble_hs_hci_cmd.c
new file mode 100644
index 0000000..82b442d
--- /dev/null
+++ b/net/nimble/host/src/ble_hs_hci_cmd.c
@@ -0,0 +1,1375 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+#include <stdint.h>
+#include <assert.h>
+#include <string.h>
+#include <errno.h>
+#include <stdio.h>
+#include "os/os.h"
+#include "console/console.h"
+#include "nimble/hci_common.h"
+#include "nimble/ble_hci_trans.h"
+#include "ble_hs_dbg_priv.h"
+#include "ble_hs_priv.h"
+
+static int
+ble_hs_hci_cmd_transport(uint8_t *cmdbuf)
+{
+ int rc;
+
+ rc = ble_hci_trans_hs_cmd_tx(cmdbuf);
+ switch (rc) {
+ case 0:
+ return 0;
+
+ case BLE_ERR_MEM_CAPACITY:
+ return BLE_HS_ENOMEM_EVT;
+
+ default:
+ return BLE_HS_EUNKNOWN;
+ }
+}
+
+void
+ble_hs_hci_cmd_write_hdr(uint8_t ogf, uint8_t ocf, uint8_t len, void *buf)
+{
+ uint16_t opcode;
+ uint8_t *u8ptr;
+
+ u8ptr = buf;
+
+ opcode = (ogf << 10) | ocf;
+ htole16(u8ptr, opcode);
+ u8ptr[2] = len;
+}
+
+int
+ble_hs_hci_cmd_send(uint8_t ogf, uint8_t ocf, uint8_t len, const void *cmddata)
+{
+ uint8_t *buf;
+ int rc;
+
+ buf = ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_CMD);
+ BLE_HS_DBG_ASSERT(buf != NULL);
+
+ htole16(buf, ogf << 10 | ocf);
+ buf[2] = len;
+ if (len != 0) {
+ memcpy(buf + BLE_HCI_CMD_HDR_LEN, cmddata, len);
+ }
+
+ BLE_HS_LOG(DEBUG, "ble_hs_hci_cmd_send: ogf=0x%02x ocf=0x%02x len=%d\n",
+ ogf, ocf, len);
+ ble_hs_log_flat_buf(buf, len + BLE_HCI_CMD_HDR_LEN);
+ BLE_HS_LOG(DEBUG, "\n");
+ rc = ble_hs_hci_cmd_transport(buf);
+
+ if (rc == 0) {
+ STATS_INC(ble_hs_stats, hci_cmd);
+ } else {
+ BLE_HS_LOG(DEBUG, "ble_hs_hci_cmd_send failure; rc=%d\n", rc);
+ }
+
+ return rc;
+}
+
+int
+ble_hs_hci_cmd_send_buf(void *buf)
+{
+ uint16_t opcode;
+ uint8_t *u8ptr;
+ uint8_t len;
+ int rc;
+
+ switch (ble_hs_sync_state) {
+ case BLE_HS_SYNC_STATE_BAD:
+ return BLE_HS_ENOTSYNCED;
+
+ case BLE_HS_SYNC_STATE_BRINGUP:
+ if (!ble_hs_is_parent_task()) {
+ return BLE_HS_ENOTSYNCED;
+ }
+ break;
+
+ case BLE_HS_SYNC_STATE_GOOD:
+ break;
+
+ default:
+ BLE_HS_DBG_ASSERT(0);
+ return BLE_HS_EUNKNOWN;
+ }
+
+ u8ptr = buf;
+
+ opcode = le16toh(u8ptr + 0);
+ len = u8ptr[2];
+
+ rc = ble_hs_hci_cmd_send(BLE_HCI_OGF(opcode), BLE_HCI_OCF(opcode), len,
+ u8ptr + BLE_HCI_CMD_HDR_LEN);
+ return rc;
+}
+
+
+/**
+ * Send a LE command from the host to the controller.
+ *
+ * @param ocf
+ * @param len
+ * @param cmddata
+ *
+ * @return int
+ */
+static int
+ble_hs_hci_cmd_le_send(uint16_t ocf, uint8_t len, void *cmddata)
+{
+ int rc;
+ rc = ble_hs_hci_cmd_send(BLE_HCI_OGF_LE, ocf, len, cmddata);
+ return rc;
+}
+
+/**
+ * Read BD_ADDR
+ *
+ * OGF = 0x04 (Informational parameters)
+ * OCF = 0x0009
+ */
+void
+ble_hs_hci_cmd_build_read_bd_addr(uint8_t *dst, int dst_len)
+{
+ BLE_HS_DBG_ASSERT(dst_len >= BLE_HCI_CMD_HDR_LEN);
+ ble_hs_hci_cmd_write_hdr(BLE_HCI_OGF_INFO_PARAMS,
+ BLE_HCI_OCF_IP_RD_BD_ADDR,
+ 0, dst);
+}
+
+static int
+ble_hs_hci_cmd_body_le_whitelist_chg(const uint8_t *addr, uint8_t addr_type,
+ uint8_t *dst)
+{
+ if (addr_type > BLE_ADDR_TYPE_RANDOM) {
+ return BLE_ERR_INV_HCI_CMD_PARMS;
+ }
+
+ dst[0] = addr_type;
+ memcpy(dst + 1, addr, BLE_DEV_ADDR_LEN);
+
+ return 0;
+}
+
+static int
+ble_hs_hci_cmd_body_le_set_adv_params(const struct hci_adv_params *adv,
+ uint8_t *dst)
+{
+ uint16_t itvl;
+
+ BLE_HS_DBG_ASSERT(adv != NULL);
+
+ /* Make sure parameters are valid */
+ if ((adv->adv_itvl_min > adv->adv_itvl_max) ||
+ (adv->own_addr_type > BLE_HCI_ADV_OWN_ADDR_MAX) ||
+ (adv->peer_addr_type > BLE_HCI_ADV_PEER_ADDR_MAX) ||
+ (adv->adv_filter_policy > BLE_HCI_ADV_FILT_MAX) ||
+ (adv->adv_type > BLE_HCI_ADV_TYPE_MAX) ||
+ (adv->adv_channel_map == 0) ||
+ ((adv->adv_channel_map & 0xF8) != 0)) {
+ /* These parameters are not valid */
+ return -1;
+ }
+
+ /* Make sure interval is valid for advertising type. */
+ if ((adv->adv_type == BLE_HCI_ADV_TYPE_ADV_NONCONN_IND) ||
+ (adv->adv_type == BLE_HCI_ADV_TYPE_ADV_SCAN_IND)) {
+ itvl = BLE_HCI_ADV_ITVL_NONCONN_MIN;
+ } else {
+ itvl = BLE_HCI_ADV_ITVL_MIN;
+ }
+
+ /* Do not check if high duty-cycle directed */
+ if (adv->adv_type != BLE_HCI_ADV_TYPE_ADV_DIRECT_IND_HD) {
+ if ((adv->adv_itvl_min < itvl) ||
+ (adv->adv_itvl_min > BLE_HCI_ADV_ITVL_MAX)) {
+ return -1;
+ }
+ }
+
+ htole16(dst, adv->adv_itvl_min);
+ htole16(dst + 2, adv->adv_itvl_max);
+ dst[4] = adv->adv_type;
+ dst[5] = adv->own_addr_type;
+ dst[6] = adv->peer_addr_type;
+ memcpy(dst + 7, adv->peer_addr, BLE_DEV_ADDR_LEN);
+ dst[13] = adv->adv_channel_map;
+ dst[14] = adv->adv_filter_policy;
+
+ return 0;
+}
+
+int
+ble_hs_hci_cmd_build_le_set_adv_params(const struct hci_adv_params *adv,
+ uint8_t *dst, int dst_len)
+{
+ int rc;
+
+ BLE_HS_DBG_ASSERT(
+ dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_ADV_PARAM_LEN);
+
+ ble_hs_hci_cmd_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_SET_ADV_PARAMS,
+ BLE_HCI_SET_ADV_PARAM_LEN, dst);
+ dst += BLE_HCI_CMD_HDR_LEN;
+
+ rc = ble_hs_hci_cmd_body_le_set_adv_params(adv, dst);
+ if (rc != 0) {
+ return rc;
+ }
+
+ return 0;
+}
+
+/**
+ * Set advertising data
+ *
+ * OGF = 0x08 (LE)
+ * OCF = 0x0008
+ *
+ * @param data
+ * @param len
+ * @param dst
+ *
+ * @return int
+ */
+static int
+ble_hs_hci_cmd_body_le_set_adv_data(const uint8_t *data, uint8_t len,
+ uint8_t *dst)
+{
+ /* Check for valid parameters */
+ if (((data == NULL) && (len != 0)) || (len > BLE_HCI_MAX_ADV_DATA_LEN)) {
+ return BLE_ERR_INV_HCI_CMD_PARMS;
+ }
+
+ memset(dst, 0, BLE_HCI_SET_ADV_DATA_LEN);
+ dst[0] = len;
+ memcpy(dst + 1, data, len);
+
+ return 0;
+}
+
+/**
+ * Set advertising data
+ *
+ * OGF = 0x08 (LE)
+ * OCF = 0x0008
+ *
+ * @param data
+ * @param len
+ * @param dst
+ *
+ * @return int
+ */
+int
+ble_hs_hci_cmd_build_le_set_adv_data(const uint8_t *data, uint8_t len,
+ uint8_t *dst, int dst_len)
+{
+ int rc;
+
+ BLE_HS_DBG_ASSERT(
+ dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_ADV_DATA_LEN);
+
+ ble_hs_hci_cmd_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_SET_ADV_DATA,
+ BLE_HCI_SET_ADV_DATA_LEN, dst);
+ dst += BLE_HCI_CMD_HDR_LEN;
+
+ rc = ble_hs_hci_cmd_body_le_set_adv_data(data, len, dst);
+ if (rc != 0) {
+ return rc;
+ }
+
+ return 0;
+}
+
+static int
+ble_hs_hci_cmd_body_le_set_scan_rsp_data(const uint8_t *data, uint8_t len,
+ uint8_t *dst)
+{
+ /* Check for valid parameters */
+ if (((data == NULL) && (len != 0)) ||
+ (len > BLE_HCI_MAX_SCAN_RSP_DATA_LEN)) {
+ return BLE_ERR_INV_HCI_CMD_PARMS;
+ }
+
+ memset(dst, 0, BLE_HCI_SET_SCAN_RSP_DATA_LEN);
+ dst[0] = len;
+ memcpy(dst + 1, data, len);
+
+ return 0;
+}
+
+int
+ble_hs_hci_cmd_build_le_set_scan_rsp_data(const uint8_t *data, uint8_t len,
+ uint8_t *dst, int dst_len)
+{
+ int rc;
+
+ BLE_HS_DBG_ASSERT(
+ dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_SCAN_RSP_DATA_LEN);
+
+ ble_hs_hci_cmd_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_SET_SCAN_RSP_DATA,
+ BLE_HCI_SET_SCAN_RSP_DATA_LEN, dst);
+ dst += BLE_HCI_CMD_HDR_LEN;
+
+ rc = ble_hs_hci_cmd_body_le_set_scan_rsp_data(data, len, dst);
+ if (rc != 0) {
+ return rc;
+ }
+
+ return 0;
+}
+
+static void
+ble_hs_hci_cmd_body_set_event_mask(uint64_t event_mask, uint8_t *dst)
+{
+ htole64(dst, event_mask);
+}
+
+void
+ble_hs_hci_cmd_build_set_event_mask(uint64_t event_mask,
+ uint8_t *dst, int dst_len)
+{
+ BLE_HS_DBG_ASSERT(
+ dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_EVENT_MASK_LEN);
+
+ ble_hs_hci_cmd_write_hdr(BLE_HCI_OGF_CTLR_BASEBAND,
+ BLE_HCI_OCF_CB_SET_EVENT_MASK,
+ BLE_HCI_SET_EVENT_MASK_LEN, dst);
+ dst += BLE_HCI_CMD_HDR_LEN;
+
+ ble_hs_hci_cmd_body_set_event_mask(event_mask, dst);
+}
+
+void
+ble_hs_hci_cmd_build_set_event_mask2(uint64_t event_mask,
+ uint8_t *dst, int dst_len)
+{
+ BLE_HS_DBG_ASSERT(
+ dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_EVENT_MASK_LEN);
+
+ ble_hs_hci_cmd_write_hdr(BLE_HCI_OGF_CTLR_BASEBAND,
+ BLE_HCI_OCF_CB_SET_EVENT_MASK2,
+ BLE_HCI_SET_EVENT_MASK_LEN, dst);
+ dst += BLE_HCI_CMD_HDR_LEN;
+
+ ble_hs_hci_cmd_body_set_event_mask(event_mask, dst);
+}
+
+static void
+ble_hs_hci_cmd_body_disconnect(uint16_t handle, uint8_t reason, uint8_t *dst)
+{
+ htole16(dst + 0, handle);
+ dst[2] = reason;
+}
+
+void
+ble_hs_hci_cmd_build_disconnect(uint16_t handle, uint8_t reason,
+ uint8_t *dst, int dst_len)
+{
+ BLE_HS_DBG_ASSERT(
+ dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_DISCONNECT_CMD_LEN);
+
+ ble_hs_hci_cmd_write_hdr(BLE_HCI_OGF_LINK_CTRL, BLE_HCI_OCF_DISCONNECT_CMD,
+ BLE_HCI_DISCONNECT_CMD_LEN, dst);
+ dst += BLE_HCI_CMD_HDR_LEN;
+
+ ble_hs_hci_cmd_body_disconnect(handle, reason, dst);
+}
+
+int
+ble_hs_hci_cmd_disconnect(uint16_t handle, uint8_t reason)
+{
+ uint8_t cmd[BLE_HCI_DISCONNECT_CMD_LEN];
+ int rc;
+
+ ble_hs_hci_cmd_body_disconnect(handle, reason, cmd);
+ rc = ble_hs_hci_cmd_send(BLE_HCI_OGF_LINK_CTRL,
+ BLE_HCI_OCF_DISCONNECT_CMD,
+ BLE_HCI_DISCONNECT_CMD_LEN,
+ cmd);
+ return rc;
+}
+
+static void
+ble_hs_hci_cmd_body_le_set_event_mask(uint64_t event_mask, uint8_t *dst)
+{
+ htole64(dst, event_mask);
+}
+
+void
+ble_hs_hci_cmd_build_le_set_event_mask(uint64_t event_mask,
+ uint8_t *dst, int dst_len)
+{
+ BLE_HS_DBG_ASSERT(
+ dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_LE_EVENT_MASK_LEN);
+
+ ble_hs_hci_cmd_write_hdr(BLE_HCI_OGF_LE,
+ BLE_HCI_OCF_LE_SET_EVENT_MASK,
+ BLE_HCI_SET_LE_EVENT_MASK_LEN, dst);
+ dst += BLE_HCI_CMD_HDR_LEN;
+
+ ble_hs_hci_cmd_body_le_set_event_mask(event_mask, dst);
+}
+
+/**
+ * LE Read buffer size
+ *
+ * OGF = 0x08 (LE)
+ * OCF = 0x0002
+ *
+ * @return int
+ */
+void
+ble_hs_hci_cmd_build_le_read_buffer_size(uint8_t *dst, int dst_len)
+{
+ BLE_HS_DBG_ASSERT(dst_len >= BLE_HCI_CMD_HDR_LEN);
+ ble_hs_hci_cmd_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_RD_BUF_SIZE,
+ 0, dst);
+}
+
+/**
+ * LE Read buffer size
+ *
+ * OGF = 0x08 (LE)
+ * OCF = 0x0002
+ *
+ * @return int
+ */
+int
+ble_hs_hci_cmd_le_read_buffer_size(void)
+{
+ int rc;
+
+ rc = ble_hs_hci_cmd_le_send(BLE_HCI_OCF_LE_RD_BUF_SIZE, 0, NULL);
+ return rc;
+}
+
+/**
+ * OGF=LE, OCF=0x0003
+ */
+void
+ble_hs_hci_cmd_build_le_read_loc_supp_feat(uint8_t *dst, uint8_t dst_len)
+{
+ BLE_HS_DBG_ASSERT(dst_len >= BLE_HCI_CMD_HDR_LEN);
+ ble_hs_hci_cmd_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_RD_LOC_SUPP_FEAT,
+ 0, dst);
+}
+
+static void
+ble_hs_hci_cmd_body_le_set_adv_enable(uint8_t enable, uint8_t *dst)
+{
+ dst[0] = enable;
+}
+
+void
+ble_hs_hci_cmd_build_le_set_adv_enable(uint8_t enable, uint8_t *dst,
+ int dst_len)
+{
+ BLE_HS_DBG_ASSERT(
+ dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_ADV_ENABLE_LEN);
+
+ ble_hs_hci_cmd_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_SET_ADV_ENABLE,
+ BLE_HCI_SET_ADV_ENABLE_LEN, dst);
+ dst += BLE_HCI_CMD_HDR_LEN;
+
+ ble_hs_hci_cmd_body_le_set_adv_enable(enable, dst);
+}
+
+static int
+ble_hs_hci_cmd_body_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, uint8_t *dst) {
+
+ /* Make sure parameters are valid */
+ if ((scan_type != BLE_HCI_SCAN_TYPE_PASSIVE) &&
+ (scan_type != BLE_HCI_SCAN_TYPE_ACTIVE)) {
+ return BLE_ERR_INV_HCI_CMD_PARMS;
+ }
+
+ /* Check interval and window */
+ if ((scan_itvl < BLE_HCI_SCAN_ITVL_MIN) ||
+ (scan_itvl > BLE_HCI_SCAN_ITVL_MAX) ||
+ (scan_window < BLE_HCI_SCAN_WINDOW_MIN) ||
+ (scan_window > BLE_HCI_SCAN_WINDOW_MAX) ||
+ (scan_itvl < scan_window)) {
+ return BLE_ERR_INV_HCI_CMD_PARMS;
+ }
+
+ /* Check own addr type */
+ if (own_addr_type > BLE_HCI_ADV_OWN_ADDR_MAX) {
+ return BLE_ERR_INV_HCI_CMD_PARMS;
+ }
+
+ /* Check scanner filter policy */
+ if (filter_policy > BLE_HCI_SCAN_FILT_MAX) {
+ return BLE_ERR_INV_HCI_CMD_PARMS;
+ }
+
+ dst[0] = scan_type;
+ htole16(dst + 1, scan_itvl);
+ htole16(dst + 3, scan_window);
+ dst[5] = own_addr_type;
+ dst[6] = filter_policy;
+
+ return 0;
+}
+
+int
+ble_hs_hci_cmd_build_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,
+ uint8_t *dst, int dst_len)
+{
+ int rc;
+
+ BLE_HS_DBG_ASSERT(
+ dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_SCAN_PARAM_LEN);
+
+ ble_hs_hci_cmd_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_SET_SCAN_PARAMS,
+ BLE_HCI_SET_SCAN_PARAM_LEN, dst);
+ dst += BLE_HCI_CMD_HDR_LEN;
+
+ rc = ble_hs_hci_cmd_body_le_set_scan_params(scan_type, scan_itvl,
+ scan_window, own_addr_type,
+ filter_policy, dst);
+ if (rc != 0) {
+ return rc;
+ }
+
+ return 0;
+}
+
+static void
+ble_hs_hci_cmd_body_le_set_scan_enable(uint8_t enable, uint8_t filter_dups,
+ uint8_t *dst)
+{
+ dst[0] = enable;
+ dst[1] = filter_dups;
+}
+
+void
+ble_hs_hci_cmd_build_le_set_scan_enable(uint8_t enable, uint8_t filter_dups,
+ uint8_t *dst, uint8_t dst_len)
+{
+ BLE_HS_DBG_ASSERT(
+ dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_SCAN_ENABLE_LEN);
+
+ ble_hs_hci_cmd_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_SET_SCAN_ENABLE,
+ BLE_HCI_SET_SCAN_ENABLE_LEN, dst);
+
+ ble_hs_hci_cmd_body_le_set_scan_enable(enable, filter_dups,
+ dst + BLE_HCI_CMD_HDR_LEN);
+}
+
+static int
+ble_hs_hci_cmd_body_le_create_connection(const struct hci_create_conn *hcc,
+ uint8_t *cmd)
+{
+ /* 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_CONN_FILT_MAX) {
+ return BLE_ERR_INV_HCI_CMD_PARMS;
+ }
+
+ /* Check peer addr type */
+ if (hcc->peer_addr_type > BLE_HCI_CONN_PEER_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);
+
+ return 0;
+}
+
+int
+ble_hs_hci_cmd_build_le_create_connection(const struct hci_create_conn *hcc,
+ uint8_t *cmd, int cmd_len)
+{
+ int rc;
+
+ BLE_HS_DBG_ASSERT(
+ cmd_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_CREATE_CONN_LEN);
+
+ ble_hs_hci_cmd_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_CREATE_CONN,
+ BLE_HCI_CREATE_CONN_LEN, cmd);
+
+ rc = ble_hs_hci_cmd_body_le_create_connection(hcc,
+ cmd + BLE_HCI_CMD_HDR_LEN);
+ if (rc != 0) {
+ return rc;
+ }
+
+ return 0;
+}
+
+void
+ble_hs_hci_cmd_build_le_clear_whitelist(uint8_t *dst, int dst_len)
+{
+ BLE_HS_DBG_ASSERT(dst_len >= BLE_HCI_CMD_HDR_LEN);
+ ble_hs_hci_cmd_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_CLEAR_WHITE_LIST,
+ 0, dst);
+}
+
+int
+ble_hs_hci_cmd_build_le_add_to_whitelist(const uint8_t *addr,
+ uint8_t addr_type,
+ uint8_t *dst, int dst_len)
+{
+ int rc;
+
+ BLE_HS_DBG_ASSERT(
+ dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_CHG_WHITE_LIST_LEN);
+
+ ble_hs_hci_cmd_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_ADD_WHITE_LIST,
+ BLE_HCI_CHG_WHITE_LIST_LEN, dst);
+ dst += BLE_HCI_CMD_HDR_LEN;
+
+ rc = ble_hs_hci_cmd_body_le_whitelist_chg(addr, addr_type, dst);
+ if (rc != 0) {
+ return rc;
+ }
+
+ return 0;
+}
+
+void
+ble_hs_hci_cmd_build_reset(uint8_t *dst, int dst_len)
+{
+ BLE_HS_DBG_ASSERT(dst_len >= BLE_HCI_CMD_HDR_LEN);
+ ble_hs_hci_cmd_write_hdr(BLE_HCI_OGF_CTLR_BASEBAND, BLE_HCI_OCF_CB_RESET,
+ 0, dst);
+}
+
+/**
+ * Reset the controller and link manager.
+ *
+ * @return int
+ */
+int
+ble_hs_hci_cmd_reset(void)
+{
+ int rc;
+
+ rc = ble_hs_hci_cmd_send(BLE_HCI_OGF_CTLR_BASEBAND, BLE_HCI_OCF_CB_RESET,
+ 0, NULL);
+ return rc;
+}
+
+void
+ble_hs_hci_cmd_build_read_adv_pwr(uint8_t *dst, int dst_len)
+{
+ BLE_HS_DBG_ASSERT(dst_len >= BLE_HCI_CMD_HDR_LEN);
+ ble_hs_hci_cmd_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_RD_ADV_CHAN_TXPWR,
+ 0, dst);
+}
+
+/**
+ * Read the transmit power level used for LE advertising channel packets.
+ *
+ * @return int
+ */
+int
+ble_hs_hci_cmd_read_adv_pwr(void)
+{
+ int rc;
+
+ rc = ble_hs_hci_cmd_send(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_RD_ADV_CHAN_TXPWR,
+ 0, NULL);
+ return rc;
+}
+
+void
+ble_hs_hci_cmd_build_le_create_conn_cancel(uint8_t *dst, int dst_len)
+{
+ BLE_HS_DBG_ASSERT(dst_len >= BLE_HCI_CMD_HDR_LEN);
+ ble_hs_hci_cmd_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_CREATE_CONN_CANCEL,
+ 0, dst);
+}
+
+int
+ble_hs_hci_cmd_le_create_conn_cancel(void)
+{
+ int rc;
+
+ rc = ble_hs_hci_cmd_send(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_CREATE_CONN_CANCEL,
+ 0, NULL);
+ return rc;
+}
+
+static int
+ble_hs_hci_cmd_body_le_conn_update(const struct hci_conn_update *hcu,
+ uint8_t *dst)
+{
+ /* XXX: add parameter checking later */
+ htole16(dst + 0, hcu->handle);
+ htole16(dst + 2, hcu->conn_itvl_min);
+ htole16(dst + 4, hcu->conn_itvl_max);
+ htole16(dst + 6, hcu->conn_latency);
+ htole16(dst + 8, hcu->supervision_timeout);
+ htole16(dst + 10, hcu->min_ce_len);
+ htole16(dst + 12, hcu->max_ce_len);
+
+ return 0;
+}
+
+int
+ble_hs_hci_cmd_build_le_conn_update(const struct hci_conn_update *hcu,
+ uint8_t *dst, int dst_len)
+{
+ int rc;
+
+ BLE_HS_DBG_ASSERT(
+ dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_CONN_UPDATE_LEN);
+
+ ble_hs_hci_cmd_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_CONN_UPDATE,
+ BLE_HCI_CONN_UPDATE_LEN, dst);
+ dst += BLE_HCI_CMD_HDR_LEN;
+
+ rc = ble_hs_hci_cmd_body_le_conn_update(hcu, dst);
+ if (rc != 0) {
+ return rc;
+ }
+
+ return 0;
+}
+
+int
+ble_hs_hci_cmd_le_conn_update(const struct hci_conn_update *hcu)
+{
+ uint8_t cmd[BLE_HCI_CONN_UPDATE_LEN];
+ int rc;
+
+ rc = ble_hs_hci_cmd_body_le_conn_update(hcu, cmd);
+ if (rc != 0) {
+ return rc;
+ }
+
+ rc = ble_hs_hci_cmd_le_send(BLE_HCI_OCF_LE_CONN_UPDATE,
+ BLE_HCI_CONN_UPDATE_LEN, cmd);
+ if (rc != 0) {
+ return rc;
+ }
+
+ return 0;
+}
+
+static void
+ble_hs_hci_cmd_body_le_lt_key_req_reply(const struct hci_lt_key_req_reply *hkr,
+ uint8_t *dst)
+{
+ htole16(dst + 0, hkr->conn_handle);
+ memcpy(dst + 2, hkr->long_term_key, sizeof hkr->long_term_key);
+}
+
+/**
+ * Sends the long-term key (LTK) to the controller.
+ *
+ * Note: This function expects the 128-bit key to be in little-endian byte
+ * order.
+ *
+ * OGF = 0x08 (LE)
+ * OCF = 0x001a
+ *
+ * @param key
+ * @param pt
+ *
+ * @return int
+ */
+void
+ble_hs_hci_cmd_build_le_lt_key_req_reply(
+ const struct hci_lt_key_req_reply *hkr, uint8_t *dst, int dst_len)
+{
+ BLE_HS_DBG_ASSERT(
+ dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_LT_KEY_REQ_REPLY_LEN);
+
+ ble_hs_hci_cmd_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_LT_KEY_REQ_REPLY,
+ BLE_HCI_LT_KEY_REQ_REPLY_LEN, dst);
+ dst += BLE_HCI_CMD_HDR_LEN;
+
+ ble_hs_hci_cmd_body_le_lt_key_req_reply(hkr, dst);
+}
+
+void
+ble_hs_hci_cmd_build_le_lt_key_req_neg_reply(uint16_t conn_handle,
+ uint8_t *dst, int dst_len)
+{
+ BLE_HS_DBG_ASSERT(
+ dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_LT_KEY_REQ_NEG_REPLY_LEN);
+
+ ble_hs_hci_cmd_write_hdr(BLE_HCI_OGF_LE,
+ BLE_HCI_OCF_LE_LT_KEY_REQ_NEG_REPLY,
+ BLE_HCI_LT_KEY_REQ_NEG_REPLY_LEN, dst);
+ dst += BLE_HCI_CMD_HDR_LEN;
+
+ htole16(dst + 0, conn_handle);
+}
+
+static void
+ble_hs_hci_cmd_body_le_conn_param_reply(const struct hci_conn_param_reply *hcr,
+ uint8_t *dst)
+{
+ htole16(dst + 0, hcr->handle);
+ htole16(dst + 2, hcr->conn_itvl_min);
+ htole16(dst + 4, hcr->conn_itvl_max);
+ htole16(dst + 6, hcr->conn_latency);
+ htole16(dst + 8, hcr->supervision_timeout);
+ htole16(dst + 10, hcr->min_ce_len);
+ htole16(dst + 12, hcr->max_ce_len);
+}
+
+void
+ble_hs_hci_cmd_build_le_conn_param_reply(
+ const struct hci_conn_param_reply *hcr, uint8_t *dst, int dst_len)
+{
+ BLE_HS_DBG_ASSERT(
+ dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_CONN_PARAM_REPLY_LEN);
+
+ ble_hs_hci_cmd_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_REM_CONN_PARAM_RR,
+ BLE_HCI_CONN_PARAM_REPLY_LEN, dst);
+ dst += BLE_HCI_CMD_HDR_LEN;
+
+ ble_hs_hci_cmd_body_le_conn_param_reply(hcr, dst);
+}
+
+int
+ble_hs_hci_cmd_le_conn_param_reply(const struct hci_conn_param_reply *hcr)
+{
+ uint8_t cmd[BLE_HCI_CONN_PARAM_REPLY_LEN];
+ int rc;
+
+ htole16(cmd + 0, hcr->handle);
+ htole16(cmd + 2, hcr->conn_itvl_min);
+ htole16(cmd + 4, hcr->conn_itvl_max);
+ htole16(cmd + 6, hcr->conn_latency);
+ htole16(cmd + 8, hcr->supervision_timeout);
+ htole16(cmd + 10, hcr->min_ce_len);
+ htole16(cmd + 12, hcr->max_ce_len);
+
+ rc = ble_hs_hci_cmd_le_send(BLE_HCI_OCF_LE_REM_CONN_PARAM_RR,
+ BLE_HCI_CONN_PARAM_REPLY_LEN, cmd);
+ return rc;
+}
+
+static void
+ble_hs_hci_cmd_body_le_conn_param_neg_reply(
+ const struct hci_conn_param_neg_reply *hcn, uint8_t *dst)
+{
+ htole16(dst + 0, hcn->handle);
+ dst[2] = hcn->reason;
+}
+
+
+void
+ble_hs_hci_cmd_build_le_conn_param_neg_reply(
+ const struct hci_conn_param_neg_reply *hcn, uint8_t *dst, int dst_len)
+{
+ BLE_HS_DBG_ASSERT(
+ dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_CONN_PARAM_NEG_REPLY_LEN);
+
+ ble_hs_hci_cmd_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_REM_CONN_PARAM_NRR,
+ BLE_HCI_CONN_PARAM_NEG_REPLY_LEN, dst);
+ dst += BLE_HCI_CMD_HDR_LEN;
+
+ ble_hs_hci_cmd_body_le_conn_param_neg_reply(hcn, dst);
+}
+
+int
+ble_hs_hci_cmd_le_conn_param_neg_reply(
+ const struct hci_conn_param_neg_reply *hcn)
+{
+ uint8_t cmd[BLE_HCI_CONN_PARAM_NEG_REPLY_LEN];
+ int rc;
+
+ ble_hs_hci_cmd_body_le_conn_param_neg_reply(hcn, cmd);
+
+ rc = ble_hs_hci_cmd_le_send(BLE_HCI_OCF_LE_REM_CONN_PARAM_NRR,
+ BLE_HCI_CONN_PARAM_NEG_REPLY_LEN, cmd);
+ return rc;
+}
+
+/**
+ * Get random data
+ *
+ * OGF = 0x08 (LE)
+ * OCF = 0x0018
+ *
+ * @return int
+ */
+void
+ble_hs_hci_cmd_build_le_rand(uint8_t *dst, int dst_len)
+{
+ BLE_HS_DBG_ASSERT(dst_len >= BLE_HCI_CMD_HDR_LEN);
+ ble_hs_hci_cmd_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_RAND, 0, dst);
+}
+
+static void
+ble_hs_hci_cmd_body_le_start_encrypt(const struct hci_start_encrypt *cmd,
+ uint8_t *dst)
+{
+ htole16(dst + 0, cmd->connection_handle);
+ htole64(dst + 2, cmd->random_number);
+ htole16(dst + 10, cmd->encrypted_diversifier);
+ memcpy(dst + 12, cmd->long_term_key, sizeof cmd->long_term_key);
+}
+
+/*
+ * OGF=0x08 OCF=0x0019
+ */
+void
+ble_hs_hci_cmd_build_le_start_encrypt(const struct hci_start_encrypt *cmd,
+ uint8_t *dst, int dst_len)
+{
+ BLE_HS_DBG_ASSERT(
+ dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_LE_START_ENCRYPT_LEN);
+
+ ble_hs_hci_cmd_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_START_ENCRYPT,
+ BLE_HCI_LE_START_ENCRYPT_LEN, dst);
+ dst += BLE_HCI_CMD_HDR_LEN;
+
+ ble_hs_hci_cmd_body_le_start_encrypt(cmd, dst);
+}
+
+/**
+ * Read the RSSI for a given connection handle
+ *
+ * NOTE: OGF=0x05 OCF=0x0005
+ *
+ * @param handle
+ *
+ * @return int
+ */
+static void
+ble_hs_hci_cmd_body_read_rssi(uint16_t handle, uint8_t *dst)
+{
+ htole16(dst, handle);
+}
+
+void
+ble_hs_hci_cmd_build_read_rssi(uint16_t handle, uint8_t *dst, int dst_len)
+{
+ BLE_HS_DBG_ASSERT(
+ dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_READ_RSSI_LEN);
+
+ ble_hs_hci_cmd_write_hdr(BLE_HCI_OGF_STATUS_PARAMS, BLE_HCI_OCF_RD_RSSI,
+ BLE_HCI_READ_RSSI_LEN, dst);
+ dst += BLE_HCI_CMD_HDR_LEN;
+
+ ble_hs_hci_cmd_body_read_rssi(handle, dst);
+}
+
+static int
+ble_hs_hci_cmd_body_set_data_len(uint16_t connection_handle,
+ uint16_t tx_octets,
+ uint16_t tx_time, uint8_t *dst)
+{
+
+ if (tx_octets < BLE_HCI_SET_DATALEN_TX_OCTETS_MIN ||
+ tx_octets > BLE_HCI_SET_DATALEN_TX_OCTETS_MAX) {
+
+ return BLE_HS_EINVAL;
+ }
+
+ if (tx_time < BLE_HCI_SET_DATALEN_TX_TIME_MIN ||
+ tx_time > BLE_HCI_SET_DATALEN_TX_TIME_MAX) {
+
+ return BLE_HS_EINVAL;
+ }
+
+ htole16(dst + 0, connection_handle);
+ htole16(dst + 2, tx_octets);
+ htole16(dst + 4, tx_time);
+
+ return 0;
+}
+
+/*
+ * OGF=0x08 OCF=0x0022
+ */
+int
+ble_hs_hci_cmd_build_set_data_len(uint16_t connection_handle,
+ uint16_t tx_octets, uint16_t tx_time,
+ uint8_t *dst, int dst_len)
+{
+ int rc;
+
+ BLE_HS_DBG_ASSERT(
+ dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_DATALEN_LEN);
+
+ ble_hs_hci_cmd_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_SET_DATA_LEN,
+ BLE_HCI_SET_DATALEN_LEN, dst);
+ dst += BLE_HCI_CMD_HDR_LEN;
+
+ rc = ble_hs_hci_cmd_body_set_data_len(connection_handle, tx_octets,
+ tx_time, dst);
+ if (rc != 0) {
+ return rc;
+ }
+
+ return 0;
+}
+
+/**
+ * IRKs are in little endian.
+ */
+static int
+ble_hs_hci_cmd_body_add_to_resolv_list(uint8_t addr_type, const uint8_t *addr,
+ const uint8_t *peer_irk,
+ const uint8_t *local_irk,
+ uint8_t *dst)
+{
+ if (addr_type > BLE_ADDR_TYPE_RANDOM) {
+ return BLE_ERR_INV_HCI_CMD_PARMS;
+ }
+
+ dst[0] = addr_type;
+ memcpy(dst + 1, addr, BLE_DEV_ADDR_LEN);
+ memcpy(dst + 1 + 6, peer_irk , 16);
+ memcpy(dst + 1 + 6 + 16, local_irk , 16);
+ /* 16 + 16 + 6 + 1 == 39 */
+ return 0;
+}
+
+/**
+ * OGF=0x08 OCF=0x0027
+ *
+ * IRKs are in little endian.
+ */
+int
+ble_hs_hci_cmd_build_add_to_resolv_list(
+ const struct hci_add_dev_to_resolving_list *padd,
+ uint8_t *dst,
+ int dst_len)
+{
+ int rc;
+
+ BLE_HS_DBG_ASSERT(
+ dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_ADD_TO_RESOLV_LIST_LEN);
+
+ ble_hs_hci_cmd_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_ADD_RESOLV_LIST,
+ BLE_HCI_ADD_TO_RESOLV_LIST_LEN, dst);
+
+ rc = ble_hs_hci_cmd_body_add_to_resolv_list(
+ padd->addr_type, padd->addr, padd->peer_irk, padd->local_irk,
+ dst + BLE_HCI_CMD_HDR_LEN);
+ if (rc != 0) {
+ return rc;
+ }
+
+ return 0;
+}
+
+static int
+ble_hs_hci_cmd_body_remove_from_resolv_list(uint8_t addr_type,
+ const uint8_t *addr,
+ uint8_t *dst)
+{
+ if (addr_type > BLE_ADDR_TYPE_RANDOM) {
+ return BLE_ERR_INV_HCI_CMD_PARMS;
+ }
+
+ dst[0] = addr_type;
+ memcpy(dst + 1, addr, BLE_DEV_ADDR_LEN);
+ return 0;
+}
+
+
+int
+ble_hs_hci_cmd_build_remove_from_resolv_list(uint8_t addr_type,
+ const uint8_t *addr,
+ uint8_t *dst, int dst_len)
+{
+ int rc;
+
+ BLE_HS_DBG_ASSERT(
+ dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_RMV_FROM_RESOLV_LIST_LEN);
+
+ ble_hs_hci_cmd_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_RMV_RESOLV_LIST,
+ BLE_HCI_RMV_FROM_RESOLV_LIST_LEN, dst);
+
+ rc = ble_hs_hci_cmd_body_remove_from_resolv_list(addr_type, addr,
+ dst + BLE_HCI_CMD_HDR_LEN);
+ if (rc != 0) {
+ return rc;
+ }
+ return 0;
+}
+
+int
+ble_hs_hci_cmd_build_clear_resolv_list(uint8_t *dst, int dst_len)
+{
+ BLE_HS_DBG_ASSERT(dst_len >= BLE_HCI_CMD_HDR_LEN);
+
+ ble_hs_hci_cmd_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_CLR_RESOLV_LIST,
+ 0, dst);
+
+ return 0;
+}
+
+int
+ble_hs_hci_cmd_build_read_resolv_list_size(uint8_t *dst, int dst_len)
+{
+ BLE_HS_DBG_ASSERT(dst_len >= BLE_HCI_CMD_HDR_LEN);
+
+ ble_hs_hci_cmd_write_hdr(BLE_HCI_OGF_LE,
+ BLE_HCI_OCF_LE_RD_RESOLV_LIST_SIZE,
+ 0, dst);
+
+ return 0;
+}
+
+static int
+ble_hs_hci_cmd_body_read_peer_resolv_addr(uint8_t peer_identity_addr_type,
+ const uint8_t *peer_identity_addr,
+ uint8_t *dst)
+{
+ if (peer_identity_addr_type > BLE_ADDR_TYPE_RANDOM) {
+ return BLE_ERR_INV_HCI_CMD_PARMS;
+ }
+
+ dst[0] = peer_identity_addr_type;
+ memcpy(dst + 1, peer_identity_addr, BLE_DEV_ADDR_LEN);
+ return 0;
+}
+
+int
+ble_hs_hci_cmd_build_read_peer_resolv_addr(uint8_t peer_identity_addr_type,
+ const uint8_t *peer_identity_addr,
+ uint8_t *dst,
+ int dst_len)
+{
+ int rc;
+
+ BLE_HS_DBG_ASSERT(
+ dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_RD_PEER_RESOLV_ADDR_LEN);
+
+ ble_hs_hci_cmd_write_hdr(BLE_HCI_OGF_LE,
+ BLE_HCI_OCF_LE_RD_PEER_RESOLV_ADDR,
+ BLE_HCI_RD_PEER_RESOLV_ADDR_LEN, dst);
+
+ rc = ble_hs_hci_cmd_body_read_peer_resolv_addr(peer_identity_addr_type,
+ peer_identity_addr,
+ dst + BLE_HCI_CMD_HDR_LEN);
+ if (rc != 0) {
+ return rc;
+ }
+ return 0;
+}
+
+static int
+ble_hs_hci_cmd_body_read_lcl_resolv_addr(
+ uint8_t local_identity_addr_type,
+ const uint8_t *local_identity_addr,
+ uint8_t *dst)
+{
+ if (local_identity_addr_type > BLE_ADDR_TYPE_RANDOM) {
+ return BLE_ERR_INV_HCI_CMD_PARMS;
+ }
+
+ dst[0] = local_identity_addr_type;
+ memcpy(dst + 1, local_identity_addr, BLE_DEV_ADDR_LEN);
+ return 0;
+}
+
+/*
+ * OGF=0x08 OCF=0x002c
+ */
+int
+ble_hs_hci_cmd_build_read_lcl_resolv_addr(uint8_t local_identity_addr_type,
+ const uint8_t *local_identity_addr,
+ uint8_t *dst,
+ int dst_len)
+{
+ int rc;
+
+ BLE_HS_DBG_ASSERT(
+ dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_RD_LOC_RESOLV_ADDR_LEN);
+
+ ble_hs_hci_cmd_write_hdr(BLE_HCI_OGF_LE,
+ BLE_HCI_OCF_LE_RD_LOCAL_RESOLV_ADDR,
+ BLE_HCI_RD_LOC_RESOLV_ADDR_LEN, dst);
+
+ rc = ble_hs_hci_cmd_body_read_lcl_resolv_addr(local_identity_addr_type,
+ local_identity_addr,
+ dst + BLE_HCI_CMD_HDR_LEN);
+ if (rc != 0) {
+ return rc;
+ }
+ return 0;
+}
+
+static int
+ble_hs_hci_cmd_body_set_addr_res_en(uint8_t enable, uint8_t *dst)
+{
+ if (enable > 1) {
+ return BLE_ERR_INV_HCI_CMD_PARMS;
+ }
+
+ dst[0] = enable;
+ return 0;
+}
+
+/*
+ * OGF=0x08 OCF=0x002d
+ */
+int
+ble_hs_hci_cmd_build_set_addr_res_en(uint8_t enable, uint8_t *dst, int dst_len)
+{
+ int rc;
+
+ BLE_HS_DBG_ASSERT(
+ dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_ADDR_RESOL_ENA_LEN);
+
+ ble_hs_hci_cmd_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_SET_ADDR_RES_EN,
+ BLE_HCI_SET_ADDR_RESOL_ENA_LEN, dst);
+
+ rc = ble_hs_hci_cmd_body_set_addr_res_en(enable,
+ dst + BLE_HCI_CMD_HDR_LEN);
+ if (rc != 0) {
+ return rc;
+ }
+ return 0;
+}
+
+static int
+ble_hs_hci_cmd_body_set_resolv_priv_addr_timeout(uint16_t timeout,
+ uint8_t *dst)
+{
+ if (timeout == 0 || timeout > 0xA1B8) {
+ return BLE_ERR_INV_HCI_CMD_PARMS;
+ }
+
+ htole16(dst, timeout);
+ return 0;
+}
+
+/*
+ * OGF=0x08 OCF=0x002e
+ */
+int
+ble_hs_hci_cmd_build_set_resolv_priv_addr_timeout(
+ uint16_t timeout, uint8_t *dst, int dst_len)
+{
+ int rc;
+
+ BLE_HS_DBG_ASSERT(
+ dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_RESOLV_PRIV_ADDR_TO_LEN);
+
+ ble_hs_hci_cmd_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_SET_RPA_TMO,
+ BLE_HCI_SET_RESOLV_PRIV_ADDR_TO_LEN, dst);
+
+ rc = ble_hs_hci_cmd_body_set_resolv_priv_addr_timeout(
+ timeout, dst + BLE_HCI_CMD_HDR_LEN);
+ if (rc != 0) {
+ return rc;
+ }
+ return 0;
+}
+
+static int
+ble_hs_hci_cmd_body_set_random_addr(const struct hci_rand_addr *paddr,
+ uint8_t *dst)
+{
+ memcpy(dst, paddr->addr, BLE_DEV_ADDR_LEN);
+ return 0;
+}
+
+int
+ble_hs_hci_cmd_build_set_random_addr(const uint8_t *addr,
+ uint8_t *dst, int dst_len)
+{
+ struct hci_rand_addr r_addr;
+ int rc;
+
+ memcpy(r_addr.addr, addr, sizeof(r_addr.addr));
+
+ BLE_HS_DBG_ASSERT(
+ dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_RAND_ADDR_LEN);
+
+ ble_hs_hci_cmd_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_SET_RAND_ADDR,
+ BLE_HCI_SET_RAND_ADDR_LEN, dst);
+
+ rc = ble_hs_hci_cmd_body_set_random_addr(&r_addr,
+ dst + BLE_HCI_CMD_HDR_LEN);
+ if (rc != 0) {
+ return rc;
+ }
+
+ return 0;
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/net/nimble/host/src/ble_hs_hci_evt.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_hci_evt.c b/net/nimble/host/src/ble_hs_hci_evt.c
new file mode 100644
index 0000000..3d382dc
--- /dev/null
+++ b/net/nimble/host/src/ble_hs_hci_evt.c
@@ -0,0 +1,677 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+#include <stdint.h>
+#include <string.h>
+#include <errno.h>
+#include <stdio.h>
+#include "os/os.h"
+#include "console/console.h"
+#include "nimble/hci_common.h"
+#include "nimble/ble_hci_trans.h"
+#include "host/ble_gap.h"
+#include "ble_hs_priv.h"
+#include "ble_hs_dbg_priv.h"
+
+_Static_assert(sizeof (struct hci_data_hdr) == BLE_HCI_DATA_HDR_SZ,
+ "struct hci_data_hdr must be 4 bytes");
+
+typedef int ble_hs_hci_evt_fn(uint8_t event_code, uint8_t *data, int len);
+static ble_hs_hci_evt_fn ble_hs_hci_evt_disconn_complete;
+static ble_hs_hci_evt_fn ble_hs_hci_evt_encrypt_change;
+static ble_hs_hci_evt_fn ble_hs_hci_evt_hw_error;
+static ble_hs_hci_evt_fn ble_hs_hci_evt_num_completed_pkts;
+static ble_hs_hci_evt_fn ble_hs_hci_evt_enc_key_refresh;
+static ble_hs_hci_evt_fn ble_hs_hci_evt_le_meta;
+
+typedef int ble_hs_hci_evt_le_fn(uint8_t subevent, uint8_t *data, int len);
+static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_conn_complete;
+static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_adv_rpt;
+static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_conn_upd_complete;
+static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_lt_key_req;
+static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_conn_parm_req;
+static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_dir_adv_rpt;
+
+/* Statistics */
+struct host_hci_stats
+{
+ uint32_t events_rxd;
+ uint32_t good_acks_rxd;
+ uint32_t bad_acks_rxd;
+ uint32_t unknown_events_rxd;
+};
+
+#define BLE_HS_HCI_EVT_TIMEOUT 50 /* Milliseconds. */
+
+/** Dispatch table for incoming HCI events. Sorted by event code field. */
+struct ble_hs_hci_evt_dispatch_entry {
+ uint8_t event_code;
+ ble_hs_hci_evt_fn *cb;
+};
+
+static const struct ble_hs_hci_evt_dispatch_entry ble_hs_hci_evt_dispatch[] = {
+ { BLE_HCI_EVCODE_DISCONN_CMP, ble_hs_hci_evt_disconn_complete },
+ { BLE_HCI_EVCODE_ENCRYPT_CHG, ble_hs_hci_evt_encrypt_change },
+ { BLE_HCI_EVCODE_HW_ERROR, ble_hs_hci_evt_hw_error },
+ { BLE_HCI_EVCODE_NUM_COMP_PKTS, ble_hs_hci_evt_num_completed_pkts },
+ { BLE_HCI_EVCODE_ENC_KEY_REFRESH, ble_hs_hci_evt_enc_key_refresh },
+ { BLE_HCI_EVCODE_LE_META, ble_hs_hci_evt_le_meta },
+};
+
+#define BLE_HS_HCI_EVT_DISPATCH_SZ \
+ (sizeof ble_hs_hci_evt_dispatch / sizeof ble_hs_hci_evt_dispatch[0])
+
+/** Dispatch table for incoming LE meta events. Sorted by subevent field. */
+struct ble_hs_hci_evt_le_dispatch_entry {
+ uint8_t subevent;
+ ble_hs_hci_evt_le_fn *cb;
+};
+
+static const struct ble_hs_hci_evt_le_dispatch_entry
+ ble_hs_hci_evt_le_dispatch[] = {
+ { BLE_HCI_LE_SUBEV_CONN_COMPLETE, ble_hs_hci_evt_le_conn_complete },
+ { BLE_HCI_LE_SUBEV_ADV_RPT, ble_hs_hci_evt_le_adv_rpt },
+ { BLE_HCI_LE_SUBEV_CONN_UPD_COMPLETE,
+ ble_hs_hci_evt_le_conn_upd_complete },
+ { BLE_HCI_LE_SUBEV_LT_KEY_REQ, ble_hs_hci_evt_le_lt_key_req },
+ { BLE_HCI_LE_SUBEV_REM_CONN_PARM_REQ, ble_hs_hci_evt_le_conn_parm_req },
+ { BLE_HCI_LE_SUBEV_ENH_CONN_COMPLETE, ble_hs_hci_evt_le_conn_complete },
+ { BLE_HCI_LE_SUBEV_DIRECT_ADV_RPT, ble_hs_hci_evt_le_dir_adv_rpt },
+};
+
+#define BLE_HS_HCI_EVT_LE_DISPATCH_SZ \
+ (sizeof ble_hs_hci_evt_le_dispatch / sizeof ble_hs_hci_evt_le_dispatch[0])
+
+static const struct ble_hs_hci_evt_dispatch_entry *
+ble_hs_hci_evt_dispatch_find(uint8_t event_code)
+{
+ const struct ble_hs_hci_evt_dispatch_entry *entry;
+ int i;
+
+ for (i = 0; i < BLE_HS_HCI_EVT_DISPATCH_SZ; i++) {
+ entry = ble_hs_hci_evt_dispatch + i;
+ if (entry->event_code == event_code) {
+ return entry;
+ }
+ }
+
+ return NULL;
+}
+
+static const struct ble_hs_hci_evt_le_dispatch_entry *
+ble_hs_hci_evt_le_dispatch_find(uint8_t event_code)
+{
+ const struct ble_hs_hci_evt_le_dispatch_entry *entry;
+ int i;
+
+ for (i = 0; i < BLE_HS_HCI_EVT_LE_DISPATCH_SZ; i++) {
+ entry = ble_hs_hci_evt_le_dispatch + i;
+ if (entry->subevent == event_code) {
+ return entry;
+ }
+ }
+
+ return NULL;
+}
+
+static int
+ble_hs_hci_evt_disconn_complete(uint8_t event_code, uint8_t *data, int len)
+{
+ struct hci_disconn_complete evt;
+
+ if (len < BLE_HCI_EVENT_DISCONN_COMPLETE_LEN) {
+ return BLE_HS_ECONTROLLER;
+ }
+
+ evt.status = data[2];
+ evt.connection_handle = le16toh(data + 3);
+ evt.reason = data[5];
+
+ ble_gap_rx_disconn_complete(&evt);
+
+ return 0;
+}
+
+static int
+ble_hs_hci_evt_encrypt_change(uint8_t event_code, uint8_t *data, int len)
+{
+ struct hci_encrypt_change evt;
+
+ if (len < BLE_HCI_EVENT_ENCRYPT_CHG_LEN) {
+ return BLE_HS_ECONTROLLER;
+ }
+
+ evt.status = data[2];
+ evt.connection_handle = le16toh(data + 3);
+ evt.encryption_enabled = data[5];
+
+ ble_sm_enc_change_rx(&evt);
+
+ return 0;
+}
+
+static int
+ble_hs_hci_evt_hw_error(uint8_t event_code, uint8_t *data, int len)
+{
+ uint8_t hw_code;
+
+ if (len < BLE_HCI_EVENT_HW_ERROR_LEN) {
+ return BLE_HS_ECONTROLLER;
+ }
+
+ hw_code = data[0];
+ ble_hs_hw_error(hw_code);
+
+ return 0;
+}
+
+static int
+ble_hs_hci_evt_enc_key_refresh(uint8_t event_code, uint8_t *data, int len)
+{
+ struct hci_encrypt_key_refresh evt;
+
+ if (len < BLE_HCI_EVENT_ENC_KEY_REFRESH_LEN) {
+ return BLE_HS_ECONTROLLER;
+ }
+
+ evt.status = data[2];
+ evt.connection_handle = le16toh(data + 3);
+
+ ble_sm_enc_key_refresh_rx(&evt);
+
+ return 0;
+}
+
+static int
+ble_hs_hci_evt_num_completed_pkts(uint8_t event_code, uint8_t *data, int len)
+{
+ uint16_t num_pkts;
+ uint16_t handle;
+ uint8_t num_handles;
+ int off;
+ int i;
+
+ if (len < BLE_HCI_EVENT_HDR_LEN + BLE_HCI_EVENT_NUM_COMP_PKTS_HDR_LEN) {
+ return BLE_HS_ECONTROLLER;
+ }
+
+ off = BLE_HCI_EVENT_HDR_LEN;
+ num_handles = data[off];
+ if (len < BLE_HCI_EVENT_NUM_COMP_PKTS_HDR_LEN +
+ num_handles * BLE_HCI_EVENT_NUM_COMP_PKTS_ENT_LEN) {
+ return BLE_HS_ECONTROLLER;
+ }
+ off++;
+
+ for (i = 0; i < num_handles; i++) {
+ handle = le16toh(data + off + 2 * i);
+ num_pkts = le16toh(data + off + 2 * num_handles + 2 * i);
+
+ /* XXX: Do something with these values. */
+ (void)handle;
+ (void)num_pkts;
+ }
+
+ return 0;
+}
+
+static int
+ble_hs_hci_evt_le_meta(uint8_t event_code, uint8_t *data, int len)
+{
+ const struct ble_hs_hci_evt_le_dispatch_entry *entry;
+ uint8_t subevent;
+ int rc;
+
+ if (len < BLE_HCI_EVENT_HDR_LEN + BLE_HCI_LE_MIN_LEN) {
+ return BLE_HS_ECONTROLLER;
+ }
+
+ subevent = data[2];
+ entry = ble_hs_hci_evt_le_dispatch_find(subevent);
+ if (entry != NULL) {
+ rc = entry->cb(subevent, data + BLE_HCI_EVENT_HDR_LEN,
+ len - BLE_HCI_EVENT_HDR_LEN);
+ if (rc != 0) {
+ return rc;
+ }
+ }
+
+ return 0;
+}
+
+static int
+ble_hs_hci_evt_le_conn_complete(uint8_t subevent, uint8_t *data, int len)
+{
+ struct hci_le_conn_complete evt;
+ int extended_offset = 0;
+ int rc;
+
+ if (len < BLE_HCI_LE_CONN_COMPLETE_LEN) {
+ return BLE_HS_ECONTROLLER;
+ }
+
+ /* this code processes two different events that are really similar */
+ if ((subevent == BLE_HCI_LE_SUBEV_ENH_CONN_COMPLETE) &&
+ ( len < BLE_HCI_LE_ENH_CONN_COMPLETE_LEN)) {
+ return BLE_HS_ECONTROLLER;
+ }
+
+ evt.subevent_code = data[0];
+ evt.status = data[1];
+ evt.connection_handle = le16toh(data + 2);
+ evt.role = data[4];
+ evt.peer_addr_type = data[5];
+ memcpy(evt.peer_addr, data + 6, BLE_DEV_ADDR_LEN);
+
+ /* enhanced connection event has the same information with these
+ * extra fields stuffed into the middle */
+ if (subevent == BLE_HCI_LE_SUBEV_ENH_CONN_COMPLETE) {
+ memcpy(evt.local_rpa, data + 12, BLE_DEV_ADDR_LEN);
+ memcpy(evt.peer_rpa, data + 18, BLE_DEV_ADDR_LEN);
+ extended_offset = 12;
+ } else {
+ memset(evt.local_rpa, 0, BLE_DEV_ADDR_LEN);
+ memset(evt.peer_rpa, 0, BLE_DEV_ADDR_LEN);
+ }
+
+ evt.conn_itvl = le16toh(data + 12 + extended_offset);
+ evt.conn_latency = le16toh(data + 14 + extended_offset);
+ evt.supervision_timeout = le16toh(data + 16 + extended_offset);
+ evt.master_clk_acc = data[18 + extended_offset];
+
+ if (evt.status == 0) {
+ if (evt.role != BLE_HCI_LE_CONN_COMPLETE_ROLE_MASTER &&
+ evt.role != BLE_HCI_LE_CONN_COMPLETE_ROLE_SLAVE) {
+
+ return BLE_HS_EBADDATA;
+ }
+ }
+
+ rc = ble_gap_rx_conn_complete(&evt);
+ if (rc != 0) {
+ return rc;
+ }
+
+ return 0;
+}
+
+static int
+ble_hs_hci_evt_le_adv_rpt_first_pass(uint8_t *data, int len,
+ uint8_t *out_num_reports,
+ int *out_rssi_off)
+{
+ uint8_t num_reports;
+ int data_len;
+ int off;
+ int i;
+
+ if (len < BLE_HCI_LE_ADV_RPT_MIN_LEN) {
+ return BLE_HS_ECONTROLLER;
+ }
+
+ num_reports = data[1];
+ if (num_reports < BLE_HCI_LE_ADV_RPT_NUM_RPTS_MIN ||
+ num_reports > BLE_HCI_LE_ADV_RPT_NUM_RPTS_MAX) {
+
+ return BLE_HS_EBADDATA;
+ }
+
+ off = 2 + /* Subevent code and num reports. */
+ (1 + /* Event type. */
+ 1 + /* Address type. */
+ 6 /* Address. */
+ ) * num_reports;
+ if (off + num_reports >= len) {
+ return BLE_HS_ECONTROLLER;
+ }
+
+ data_len = 0;
+ for (i = 0; i < num_reports; i++) {
+ data_len += data[off];
+ off++;
+ }
+
+ off += data_len;
+
+ /* Check if RSSI fields fit in the packet. */
+ if (off + num_reports > len) {
+ return BLE_HS_ECONTROLLER;
+ }
+
+ *out_num_reports = num_reports;
+ *out_rssi_off = off;
+
+ return 0;
+}
+
+static int
+ble_hs_hci_evt_le_adv_rpt(uint8_t subevent, uint8_t *data, int len)
+{
+ struct ble_gap_disc_desc desc;
+ uint8_t num_reports;
+ int rssi_off;
+ int data_off;
+ int suboff;
+ int off;
+ int rc;
+ int i;
+
+ rc = ble_hs_hci_evt_le_adv_rpt_first_pass(data, len, &num_reports,
+ &rssi_off);
+ if (rc != 0) {
+ return rc;
+ }
+
+ /* Direct address fields not present in a standard advertising report. */
+ desc.direct_addr_type = BLE_GAP_ADDR_TYPE_NONE;
+ memset(desc.direct_addr, 0, sizeof desc.direct_addr);
+
+ data_off = 0;
+ for (i = 0; i < num_reports; i++) {
+ suboff = 0;
+
+ off = 2 + suboff * num_reports + i;
+ desc.event_type = data[off];
+ suboff++;
+
+ off = 2 + suboff * num_reports + i;
+ desc.addr_type = data[off];
+ suboff++;
+
+ off = 2 + suboff * num_reports + i * 6;
+ memcpy(desc.addr, data + off, 6);
+ suboff += 6;
+
+ off = 2 + suboff * num_reports + i;
+ desc.length_data = data[off];
+ suboff++;
+
+ off = 2 + suboff * num_reports + data_off;
+ desc.data = data + off;
+ data_off += desc.length_data;
+
+ off = rssi_off + 1 * i;
+ desc.rssi = data[off];
+
+ ble_gap_rx_adv_report(&desc);
+ }
+
+ return 0;
+}
+
+static int
+ble_hs_hci_evt_le_dir_adv_rpt(uint8_t subevent, uint8_t *data, int len)
+{
+ struct ble_gap_disc_desc desc;
+ uint8_t num_reports;
+ int suboff;
+ int off;
+ int i;
+
+ if (len < BLE_HCI_LE_ADV_DIRECT_RPT_LEN) {
+ return BLE_HS_ECONTROLLER;
+ }
+
+ num_reports = data[1];
+ if (len != 2 + num_reports * BLE_HCI_LE_ADV_DIRECT_RPT_SUB_LEN) {
+ return BLE_HS_ECONTROLLER;
+ }
+
+ /* Data fields not present in a direct advertising report. */
+ desc.data = NULL;
+ desc.fields = NULL;
+
+ for (i = 0; i < num_reports; i++) {
+ suboff = 0;
+
+ off = 2 + suboff * num_reports + i;
+ desc.event_type = data[off];
+ suboff++;
+
+ off = 2 + suboff * num_reports + i;
+ desc.addr_type = data[off];
+ suboff++;
+
+ off = 2 + suboff * num_reports + i * 6;
+ memcpy(desc.addr, data + off, 6);
+ suboff += 6;
+
+ off = 2 + suboff * num_reports + i;
+ desc.direct_addr_type = data[off];
+ suboff++;
+
+ off = 2 + suboff * num_reports + i * 6;
+ memcpy(desc.direct_addr, data + off, 6);
+ suboff += 6;
+
+ off = 2 + suboff * num_reports + i;
+ desc.rssi = data[off];
+ suboff++;
+
+ ble_gap_rx_adv_report(&desc);
+ }
+
+ return 0;
+}
+
+static int
+ble_hs_hci_evt_le_conn_upd_complete(uint8_t subevent, uint8_t *data, int len)
+{
+ struct hci_le_conn_upd_complete evt;
+
+ if (len < BLE_HCI_LE_CONN_UPD_LEN) {
+ return BLE_HS_ECONTROLLER;
+ }
+
+ evt.subevent_code = data[0];
+ evt.status = data[1];
+ evt.connection_handle = le16toh(data + 2);
+ evt.conn_itvl = le16toh(data + 4);
+ evt.conn_latency = le16toh(data + 6);
+ evt.supervision_timeout = le16toh(data + 8);
+
+ if (evt.status == 0) {
+ if (evt.conn_itvl < BLE_HCI_CONN_ITVL_MIN ||
+ evt.conn_itvl > BLE_HCI_CONN_ITVL_MAX) {
+
+ return BLE_HS_EBADDATA;
+ }
+ if (evt.conn_latency < BLE_HCI_CONN_LATENCY_MIN ||
+ evt.conn_latency > BLE_HCI_CONN_LATENCY_MAX) {
+
+ return BLE_HS_EBADDATA;
+ }
+ if (evt.supervision_timeout < BLE_HCI_CONN_SPVN_TIMEOUT_MIN ||
+ evt.supervision_timeout > BLE_HCI_CONN_SPVN_TIMEOUT_MAX) {
+
+ return BLE_HS_EBADDATA;
+ }
+ }
+
+ ble_gap_rx_update_complete(&evt);
+
+ return 0;
+}
+
+static int
+ble_hs_hci_evt_le_lt_key_req(uint8_t subevent, uint8_t *data, int len)
+{
+ struct hci_le_lt_key_req evt;
+
+ if (len < BLE_HCI_LE_LT_KEY_REQ_LEN) {
+ return BLE_HS_ECONTROLLER;
+ }
+
+ evt.subevent_code = data[0];
+ evt.connection_handle = le16toh(data + 1);
+ evt.random_number = le64toh(data + 3);
+ evt.encrypted_diversifier = le16toh(data + 11);
+
+ ble_sm_ltk_req_rx(&evt);
+
+ return 0;
+}
+
+static int
+ble_hs_hci_evt_le_conn_parm_req(uint8_t subevent, uint8_t *data, int len)
+{
+ struct hci_le_conn_param_req evt;
+
+ if (len < BLE_HCI_LE_REM_CONN_PARM_REQ_LEN) {
+ return BLE_HS_ECONTROLLER;
+ }
+
+ evt.subevent_code = data[0];
+ evt.connection_handle = le16toh(data + 1);
+ evt.itvl_min = le16toh(data + 3);
+ evt.itvl_max = le16toh(data + 5);
+ evt.latency = le16toh(data + 7);
+ evt.timeout = le16toh(data + 9);
+
+ if (evt.itvl_min < BLE_HCI_CONN_ITVL_MIN ||
+ evt.itvl_max > BLE_HCI_CONN_ITVL_MAX ||
+ evt.itvl_min > evt.itvl_max) {
+
+ return BLE_HS_EBADDATA;
+ }
+ if (evt.latency < BLE_HCI_CONN_LATENCY_MIN ||
+ evt.latency > BLE_HCI_CONN_LATENCY_MAX) {
+
+ return BLE_HS_EBADDATA;
+ }
+ if (evt.timeout < BLE_HCI_CONN_SPVN_TIMEOUT_MIN ||
+ evt.timeout > BLE_HCI_CONN_SPVN_TIMEOUT_MAX) {
+
+ return BLE_HS_EBADDATA;
+ }
+
+ ble_gap_rx_param_req(&evt);
+
+ return 0;
+}
+
+int
+ble_hs_hci_evt_process(uint8_t *data)
+{
+ const struct ble_hs_hci_evt_dispatch_entry *entry;
+ uint8_t event_code;
+ uint8_t param_len;
+ int event_len;
+ int rc;
+
+ /* Count events received */
+ STATS_INC(ble_hs_stats, hci_event);
+
+ /* Display to console */
+ ble_hs_dbg_event_disp(data);
+
+ /* Process the event */
+ event_code = data[0];
+ param_len = data[1];
+
+ event_len = param_len + 2;
+
+ entry = ble_hs_hci_evt_dispatch_find(event_code);
+ if (entry == NULL) {
+ STATS_INC(ble_hs_stats, hci_unknown_event);
+ rc = BLE_HS_ENOTSUP;
+ } else {
+ rc = entry->cb(event_code, data, event_len);
+ }
+
+ ble_hci_trans_buf_free(data);
+
+ return rc;
+}
+
+/**
+ * Called when a data packet is received from the controller. This function
+ * consumes the supplied mbuf, regardless of the outcome.
+ *
+ * @param om The incoming data packet, beginning with the
+ * HCI ACL data header.
+ *
+ * @return 0 on success; nonzero on failure.
+ */
+int
+ble_hs_hci_evt_acl_process(struct os_mbuf *om)
+{
+ struct hci_data_hdr hci_hdr;
+ struct ble_hs_conn *conn;
+ ble_l2cap_rx_fn *rx_cb;
+ struct os_mbuf *rx_buf;
+ uint16_t handle;
+ int rc;
+
+ rc = ble_hs_hci_util_data_hdr_strip(om, &hci_hdr);
+ if (rc != 0) {
+ goto err;
+ }
+
+#if (BLETEST_THROUGHPUT_TEST == 0)
+ BLE_HS_LOG(DEBUG, "ble_hs_hci_evt_acl_process(): handle=%u pb=%x len=%u "
+ "data=",
+ BLE_HCI_DATA_HANDLE(hci_hdr.hdh_handle_pb_bc),
+ BLE_HCI_DATA_PB(hci_hdr.hdh_handle_pb_bc),
+ hci_hdr.hdh_len);
+ ble_hs_log_mbuf(om);
+ BLE_HS_LOG(DEBUG, "\n");
+#endif
+
+ if (hci_hdr.hdh_len != OS_MBUF_PKTHDR(om)->omp_len) {
+ rc = BLE_HS_EBADDATA;
+ goto err;
+ }
+
+ handle = BLE_HCI_DATA_HANDLE(hci_hdr.hdh_handle_pb_bc);
+
+ ble_hs_lock();
+
+ conn = ble_hs_conn_find(handle);
+ if (conn == NULL) {
+ rc = BLE_HS_ENOTCONN;
+ } else {
+ rc = ble_l2cap_rx(conn, &hci_hdr, om, &rx_cb, &rx_buf);
+ om = NULL;
+ }
+
+ ble_hs_unlock();
+
+ switch (rc) {
+ case 0:
+ /* Final fragment received. */
+ BLE_HS_DBG_ASSERT(rx_cb != NULL);
+ BLE_HS_DBG_ASSERT(rx_buf != NULL);
+ rc = rx_cb(handle, &rx_buf);
+ os_mbuf_free_chain(rx_buf);
+ break;
+
+ case BLE_HS_EAGAIN:
+ /* More fragments on the way. */
+ break;
+
+ default:
+ goto err;
+ }
+
+ return 0;
+
+err:
+ os_mbuf_free_chain(om);
+ return rc;
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/net/nimble/host/src/ble_hs_hci_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_hci_priv.h b/net/nimble/host/src/ble_hs_hci_priv.h
new file mode 100644
index 0000000..7d2fb12
--- /dev/null
+++ b/net/nimble/host/src/ble_hs_hci_priv.h
@@ -0,0 +1,158 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef H_BLE_HS_HCI_PRIV_
+#define H_BLE_HS_HCI_PRIV_
+
+#include "nimble/hci_common.h"
+struct ble_hs_conn;
+struct os_mbuf;
+
+struct ble_hs_hci_ack {
+ int bha_status; /* A BLE_HS_E<...> error; NOT a naked HCI code. */
+ uint8_t *bha_params;
+ int bha_params_len;
+ uint16_t bha_opcode;
+ uint8_t bha_hci_handle;
+};
+
+int ble_hs_hci_cmd_tx(void *cmd, void *evt_buf, uint8_t evt_buf_len,
+ uint8_t *out_evt_buf_len);
+int ble_hs_hci_cmd_tx_empty_ack(void *cmd);
+void ble_hs_hci_rx_ack(uint8_t *ack_ev);
+void ble_hs_hci_init(void);
+
+#if PHONY_HCI_ACKS
+typedef int ble_hs_hci_phony_ack_fn(uint8_t *ack, int ack_buf_len);
+void ble_hs_hci_set_phony_ack_cb(ble_hs_hci_phony_ack_fn *cb);
+#endif
+
+int ble_hs_hci_util_read_adv_tx_pwr(int8_t *out_pwr);
+int ble_hs_hci_util_rand(void *dst, int len);
+int ble_hs_hci_util_read_rssi(uint16_t conn_handle, int8_t *out_rssi);
+int ble_hs_hci_util_set_random_addr(const uint8_t *addr);
+int ble_hs_hci_util_set_data_len(uint16_t conn_handle, uint16_t tx_octets,
+ uint16_t tx_time);
+int ble_hs_hci_util_data_hdr_strip(struct os_mbuf *om,
+ struct hci_data_hdr *out_hdr);
+
+int ble_hs_hci_evt_process(uint8_t *data);
+uint16_t ble_hs_hci_util_opcode_join(uint8_t ogf, uint16_t ocf);
+void ble_hs_hci_cmd_write_hdr(uint8_t ogf, uint8_t ocf, uint8_t len,
+ void *buf);
+int ble_hs_hci_cmd_send(uint8_t ogf, uint8_t ocf, uint8_t len,
+ const void *cmddata);
+int ble_hs_hci_cmd_send_buf(void *cmddata);
+void ble_hs_hci_cmd_build_read_bd_addr(uint8_t *dst, int dst_len);
+void ble_hs_hci_cmd_build_set_event_mask(uint64_t event_mask,
+ uint8_t *dst, int dst_len);
+void ble_hs_hci_cmd_build_set_event_mask2(uint64_t event_mask, uint8_t *dst,
+ int dst_len);
+void ble_hs_hci_cmd_build_disconnect(uint16_t handle, uint8_t reason,
+ uint8_t *dst, int dst_len);
+int ble_hs_hci_cmd_disconnect(uint16_t handle, uint8_t reason);
+void ble_hs_hci_cmd_build_read_rssi(uint16_t handle, uint8_t *dst,
+ int dst_len);
+int ble_hs_hci_cmd_read_rssi(uint16_t handle);
+int ble_hs_hci_cmd_build_le_set_scan_rsp_data(const uint8_t *data, uint8_t len,
+ uint8_t *dst, int dst_len);
+int ble_hs_hci_cmd_build_le_set_adv_data(const uint8_t *data, uint8_t len,
+ uint8_t *dst, int dst_len);
+int ble_hs_hci_cmd_build_le_set_adv_params(const struct hci_adv_params *adv,
+ uint8_t *dst, int dst_len);
+void ble_hs_hci_cmd_build_le_set_event_mask(uint64_t event_mask,
+ uint8_t *dst, int dst_len);
+void ble_hs_hci_cmd_build_le_read_buffer_size(uint8_t *dst, int dst_len);
+int ble_hs_hci_cmd_le_read_buffer_size(void);
+void ble_hs_hci_cmd_build_le_read_loc_supp_feat(uint8_t *dst, uint8_t dst_len);
+void ble_hs_hci_cmd_build_le_set_adv_enable(uint8_t enable, uint8_t *dst,
+ int dst_len);
+int ble_hs_hci_cmd_le_set_adv_enable(uint8_t enable);
+int ble_hs_hci_cmd_build_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,
+ uint8_t *dst, int dst_len);
+void ble_hs_hci_cmd_build_le_set_scan_enable(uint8_t enable,
+ uint8_t filter_dups,
+ uint8_t *dst, uint8_t dst_len);
+int ble_hs_hci_cmd_le_set_scan_enable(uint8_t enable, uint8_t filter_dups);
+int ble_hs_hci_cmd_build_le_create_connection(
+ const struct hci_create_conn *hcc, uint8_t *cmd, int cmd_len);
+int ble_hs_hci_cmd_le_create_connection(const struct hci_create_conn *hcc);
+void ble_hs_hci_cmd_build_le_clear_whitelist(uint8_t *dst, int dst_len);
+int ble_hs_hci_cmd_build_le_add_to_whitelist(const uint8_t *addr,
+ uint8_t addr_type,
+ uint8_t *dst, int dst_len);
+void ble_hs_hci_cmd_build_reset(uint8_t *dst, int dst_len);
+int ble_hs_hci_cmd_reset(void);
+void ble_hs_hci_cmd_build_read_adv_pwr(uint8_t *dst, int dst_len);
+int ble_hs_hci_cmd_read_adv_pwr(void);
+void ble_hs_hci_cmd_build_le_create_conn_cancel(uint8_t *dst, int dst_len);
+int ble_hs_hci_cmd_le_create_conn_cancel(void);
+int ble_hs_hci_cmd_build_le_conn_update(const struct hci_conn_update *hcu,
+ uint8_t *dst, int dst_len);
+int ble_hs_hci_cmd_le_conn_update(const struct hci_conn_update *hcu);
+void ble_hs_hci_cmd_build_le_lt_key_req_reply(
+ const struct hci_lt_key_req_reply *hkr, uint8_t *dst, int dst_len);
+void ble_hs_hci_cmd_build_le_lt_key_req_neg_reply(uint16_t conn_handle,
+ uint8_t *dst, int dst_len);
+void ble_hs_hci_cmd_build_le_conn_param_reply(
+ const struct hci_conn_param_reply *hcr, uint8_t *dst, int dst_len);
+int ble_hs_hci_cmd_le_conn_param_reply(const struct hci_conn_param_reply *hcr);
+void ble_hs_hci_cmd_build_le_conn_param_neg_reply(
+ const struct hci_conn_param_neg_reply *hcn, uint8_t *dst, int dst_len);
+int ble_hs_hci_cmd_le_conn_param_neg_reply(
+ const struct hci_conn_param_neg_reply *hcn);
+void ble_hs_hci_cmd_build_le_rand(uint8_t *dst, int dst_len);
+void ble_hs_hci_cmd_build_le_start_encrypt(const struct hci_start_encrypt *cmd,
+ uint8_t *dst, int dst_len);
+int ble_hs_hci_set_buf_sz(uint16_t pktlen, uint8_t max_pkts);
+
+uint16_t ble_hs_hci_util_handle_pb_bc_join(uint16_t handle, uint8_t pb,
+ uint8_t bc);
+
+int ble_hs_hci_acl_tx(struct ble_hs_conn *connection, struct os_mbuf *txom);
+
+int ble_hs_hci_cmd_build_set_data_len(uint16_t connection_handle,
+ uint16_t tx_octets, uint16_t tx_time,
+ uint8_t *dst, int dst_len);
+int ble_hs_hci_cmd_build_add_to_resolv_list(
+ const struct hci_add_dev_to_resolving_list *padd,
+ uint8_t *dst, int dst_len);
+int ble_hs_hci_cmd_build_remove_from_resolv_list(
+ uint8_t addr_type, const uint8_t *addr, uint8_t *dst, int dst_len);
+int ble_hs_hci_cmd_build_read_resolv_list_size(uint8_t *dst, int dst_len);
+int ble_hs_hci_cmd_build_clear_resolv_list(uint8_t *dst, int dst_len);
+int ble_hs_hci_cmd_build_read_peer_resolv_addr(
+ uint8_t peer_identity_addr_type, const uint8_t *peer_identity_addr,
+ uint8_t *dst, int dst_len);
+int ble_hs_hci_cmd_build_read_lcl_resolv_addr(
+ uint8_t local_identity_addr_type, const uint8_t *local_identity_addr,
+ uint8_t *dst, int dst_len);
+int ble_hs_hci_cmd_build_set_addr_res_en(
+ uint8_t enable, uint8_t *dst, int dst_len);
+int ble_hs_hci_cmd_build_set_resolv_priv_addr_timeout(
+ uint16_t timeout, uint8_t *dst, int dst_len);
+
+int ble_hs_hci_cmd_build_set_random_addr(const uint8_t *addr,
+ uint8_t *dst, int dst_len);
+
+#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/net/nimble/host/src/ble_hs_hci_util.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_hci_util.c b/net/nimble/host/src/ble_hs_hci_util.c
new file mode 100644
index 0000000..0d9f625
--- /dev/null
+++ b/net/nimble/host/src/ble_hs_hci_util.c
@@ -0,0 +1,196 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <string.h>
+#include "nimble/hci_common.h"
+#include "ble_hs_priv.h"
+
+uint16_t
+ble_hs_hci_util_opcode_join(uint8_t ogf, uint16_t ocf)
+{
+ return (ogf << 10) | ocf;
+}
+
+uint16_t
+ble_hs_hci_util_handle_pb_bc_join(uint16_t handle, uint8_t pb, uint8_t bc)
+{
+ BLE_HS_DBG_ASSERT(handle <= 0x0fff);
+ BLE_HS_DBG_ASSERT(pb <= 0x03);
+ BLE_HS_DBG_ASSERT(bc <= 0x03);
+
+ return (handle << 0) |
+ (pb << 12) |
+ (bc << 14);
+}
+
+int
+ble_hs_hci_util_read_adv_tx_pwr(int8_t *out_tx_pwr)
+{
+ uint8_t buf[BLE_HCI_CMD_HDR_LEN];
+ uint8_t params_len;
+ int rc;
+
+ ble_hs_hci_cmd_build_read_adv_pwr(buf, sizeof buf);
+ rc = ble_hs_hci_cmd_tx(buf, out_tx_pwr, 1, ¶ms_len);
+ if (rc != 0) {
+ return rc;
+ }
+
+ if (params_len != 1 ||
+ *out_tx_pwr < BLE_HCI_ADV_CHAN_TXPWR_MIN ||
+ *out_tx_pwr > BLE_HCI_ADV_CHAN_TXPWR_MAX) {
+
+ return BLE_HS_ECONTROLLER;
+ }
+
+ return 0;
+}
+
+int
+ble_hs_hci_util_rand(void *dst, int len)
+{
+ uint8_t rsp_buf[BLE_HCI_LE_RAND_LEN];
+ uint8_t req_buf[BLE_HCI_CMD_HDR_LEN];
+ uint8_t params_len;
+ uint8_t *u8ptr;
+ int chunk_sz;
+ int rc;
+
+ ble_hs_hci_cmd_build_le_rand(req_buf, sizeof req_buf);
+
+ u8ptr = dst;
+ while (len > 0) {
+ rc = ble_hs_hci_cmd_tx(req_buf, rsp_buf, sizeof rsp_buf, ¶ms_len);
+ if (rc != 0) {
+ return rc;
+ }
+ if (params_len != sizeof rsp_buf) {
+ return BLE_HS_ECONTROLLER;
+ }
+
+ chunk_sz = min(len, sizeof rsp_buf);
+ memcpy(u8ptr, rsp_buf, chunk_sz);
+
+ len -= chunk_sz;
+ u8ptr += chunk_sz;
+ }
+
+ return 0;
+}
+
+int
+ble_hs_hci_util_read_rssi(uint16_t conn_handle, int8_t *out_rssi)
+{
+ uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_READ_RSSI_LEN];
+ uint8_t params[BLE_HCI_READ_RSSI_ACK_PARAM_LEN];
+ uint16_t params_conn_handle;
+ uint8_t params_len;
+ int rc;
+
+ ble_hs_hci_cmd_build_read_rssi(conn_handle, buf, sizeof buf);
+ rc = ble_hs_hci_cmd_tx(buf, params, sizeof params, ¶ms_len);
+ if (rc != 0) {
+ return rc;
+ }
+
+ if (params_len != BLE_HCI_READ_RSSI_ACK_PARAM_LEN) {
+ return BLE_HS_ECONTROLLER;
+ }
+
+ params_conn_handle = le16toh(params + 0);
+ if (params_conn_handle != conn_handle) {
+ return BLE_HS_ECONTROLLER;
+ }
+
+ *out_rssi = params[2];
+
+ return 0;
+}
+
+int
+ble_hs_hci_util_set_random_addr(const uint8_t *addr)
+{
+ uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_RAND_ADDR_LEN];
+ int rc;
+
+ /* set the address in the controller */
+
+ rc = ble_hs_hci_cmd_build_set_random_addr(addr, buf, sizeof(buf));
+ if (rc != 0) {
+ return rc;
+ }
+
+ rc = ble_hs_hci_cmd_tx_empty_ack(buf);
+ return rc;
+}
+
+int
+ble_hs_hci_util_set_data_len(uint16_t conn_handle, uint16_t tx_octets,
+ uint16_t tx_time)
+{
+
+ uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_DATALEN_LEN];
+ uint8_t params[BLE_HCI_SET_DATALEN_ACK_PARAM_LEN];
+ uint16_t params_conn_handle;
+ uint8_t params_len;
+ int rc;
+
+ rc = ble_hs_hci_cmd_build_set_data_len(conn_handle, tx_octets, tx_time,
+ buf, sizeof buf);
+ if (rc != 0) {
+ return BLE_HS_HCI_ERR(rc);
+ }
+
+ rc = ble_hs_hci_cmd_tx(buf, params, BLE_HCI_SET_DATALEN_ACK_PARAM_LEN,
+ ¶ms_len);
+ if (rc != 0) {
+ return rc;
+ }
+
+ if (params_len != BLE_HCI_SET_DATALEN_ACK_PARAM_LEN) {
+ return BLE_HS_ECONTROLLER;
+ }
+
+ params_conn_handle = le16toh(params + 0);
+ if (params_conn_handle != conn_handle) {
+ return BLE_HS_ECONTROLLER;
+ }
+
+ return 0;
+}
+
+int
+ble_hs_hci_util_data_hdr_strip(struct os_mbuf *om,
+ struct hci_data_hdr *out_hdr)
+{
+ int rc;
+
+ rc = os_mbuf_copydata(om, 0, BLE_HCI_DATA_HDR_SZ, out_hdr);
+ if (rc != 0) {
+ return BLE_HS_ECONTROLLER;
+ }
+
+ /* Strip HCI ACL data header from the front of the packet. */
+ os_mbuf_adj(om, BLE_HCI_DATA_HDR_SZ);
+
+ out_hdr->hdh_handle_pb_bc = le16toh(&out_hdr->hdh_handle_pb_bc);
+ out_hdr->hdh_len = le16toh(&out_hdr->hdh_len);
+
+ return 0;
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/net/nimble/host/src/ble_hs_id.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_id.c b/net/nimble/host/src/ble_hs_id.c
index 6d7df2b..9ef384b 100644
--- a/net/nimble/host/src/ble_hs_id.c
+++ b/net/nimble/host/src/ble_hs_id.c
@@ -50,7 +50,7 @@ ble_hs_id_gen_rnd(int nrpa, uint8_t *out_addr)
{
int rc;
- rc = ble_hci_util_rand(out_addr, 6);
+ rc = ble_hs_hci_util_rand(out_addr, 6);
if (rc != 0) {
return rc;
}
@@ -91,7 +91,7 @@ ble_hs_id_set_rnd(const uint8_t *rnd_addr)
goto done;
}
- rc = ble_hci_util_set_random_addr(rnd_addr);
+ rc = ble_hs_hci_util_set_random_addr(rnd_addr);
if (rc != 0) {
goto done;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/net/nimble/host/src/ble_hs_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_priv.h b/net/nimble/host/src/ble_hs_priv.h
index d8b5e82..d61f0ba 100644
--- a/net/nimble/host/src/ble_hs_priv.h
+++ b/net/nimble/host/src/ble_hs_priv.h
@@ -26,7 +26,8 @@
#include "ble_att_priv.h"
#include "ble_gap_priv.h"
#include "ble_gatt_priv.h"
-#include "ble_hci_priv.h"
+#include "ble_hs_dbg_priv.h"
+#include "ble_hs_hci_priv.h"
#include "ble_hs_atomic_priv.h"
#include "ble_hs_conn_priv.h"
#include "ble_hs_atomic_priv.h"
@@ -82,8 +83,8 @@ int ble_hs_tx_data(struct os_mbuf *om);
void ble_hs_enqueue_hci_event(uint8_t *hci_evt);
void ble_hs_event_enqueue(struct os_event *ev);
-int host_hci_evt_rx(uint8_t *hci_ev, void *arg);
-int host_hci_acl_process(struct os_mbuf *om);
+int ble_hs_hci_rx_evt(uint8_t *hci_ev, void *arg);
+int ble_hs_hci_evt_acl_process(struct os_mbuf *om);
int ble_hs_misc_malloc_mempool(void **mem, struct os_mempool *pool,
int num_entries, int entry_size, char *name);
[34/42] incubator-mynewt-core git commit: BLE Host - Send exec-write
when prep-writes cmplt.
Posted by st...@apache.org.
BLE Host - Send exec-write when prep-writes cmplt.
This fixes a bug where the GATT client would never send the execute
write command when performing a long-write procedure. Instead, it would
repeatedly send 0-length prepare write requests.
Also, the GATT client is now more strict about when it accepts prepare
write responses and execute write responses. Some unit tests were
passing, despite the bug described in the above paragraph, because an
incoming execute write response was accepted when it should have been.
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/aadba628
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/aadba628
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/aadba628
Branch: refs/heads/sterly_refactor
Commit: aadba6283aabeacd9a4dfc7c7c3c0ddfbe8b04c1
Parents: fbdb1ba
Author: Christopher Collins <cc...@apache.org>
Authored: Sat Aug 6 16:06:06 2016 -0700
Committer: Sterling Hughes <st...@apache.org>
Committed: Tue Aug 9 16:05:21 2016 -0700
----------------------------------------------------------------------
net/nimble/host/src/ble_gattc.c | 44 ++++++-----
net/nimble/host/src/test/ble_gatt_write_test.c | 82 +++++++++++++++++----
net/nimble/host/src/test/ble_hs_test_util.c | 23 ++++++
net/nimble/host/src/test/ble_hs_test_util.h | 3 +
4 files changed, 120 insertions(+), 32 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/aadba628/net/nimble/host/src/ble_gattc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gattc.c b/net/nimble/host/src/ble_gattc.c
index 67c13d6..43d2134 100644
--- a/net/nimble/host/src/ble_gattc.c
+++ b/net/nimble/host/src/ble_gattc.c
@@ -177,7 +177,6 @@ struct ble_gattc_proc {
struct {
struct ble_gatt_attr attr;
uint16_t length;
- uint8_t exec_sent:1;
ble_gatt_attr_fn *cb;
void *cb_arg;
} write_long;
@@ -187,7 +186,6 @@ struct ble_gattc_proc {
uint8_t num_attrs;
uint8_t cur_attr;
uint16_t length;
- uint8_t exec_sent:1;
ble_gatt_reliable_attr_fn *cb;
void *cb_arg;
} write_reliable;
@@ -3370,6 +3368,7 @@ ble_gattc_write_long_go(struct ble_gattc_proc *proc, int cb_on_err)
struct ble_att_prep_write_cmd prep_req;
struct ble_att_exec_write_req exec_req;
struct os_mbuf *om;
+ int write_len;
int max_sz;
int rc;
@@ -3377,14 +3376,6 @@ ble_gattc_write_long_go(struct ble_gattc_proc *proc, int cb_on_err)
om = NULL;
- if (proc->write_long.attr.offset +
- OS_MBUF_PKTLEN(proc->write_long.attr.om) <= 0) {
-
- exec_req.baeq_flags = BLE_ATT_EXEC_WRITE_F_CONFIRM;
- rc = ble_att_clt_tx_exec_write(proc->conn_handle, &exec_req);
- goto done;
- }
-
max_sz = ble_att_mtu(proc->conn_handle) -
BLE_ATT_PREP_WRITE_CMD_BASE_SZ;
if (max_sz <= 0) {
@@ -3393,11 +3384,17 @@ ble_gattc_write_long_go(struct ble_gattc_proc *proc, int cb_on_err)
goto done;
}
- proc->write_long.length =
- min(max_sz,
- OS_MBUF_PKTLEN(proc->write_long.attr.om) -
- proc->write_long.attr.offset);
+ write_len = min(max_sz,
+ OS_MBUF_PKTLEN(proc->write_long.attr.om) -
+ proc->write_long.attr.offset);
+ if (write_len <= 0) {
+ exec_req.baeq_flags = BLE_ATT_EXEC_WRITE_F_CONFIRM;
+ rc = ble_att_clt_tx_exec_write(proc->conn_handle, &exec_req);
+ goto done;
+ }
+
+ proc->write_long.length = write_len;
om = ble_hs_mbuf_att_pkt();
if (om == NULL) {
rc = BLE_HS_ENOMEM;
@@ -3481,6 +3478,15 @@ ble_gattc_write_long_rx_prep(struct ble_gattc_proc *proc,
}
/* Verify the response. */
+ if (proc->write_long.attr.offset >=
+ OS_MBUF_PKTLEN(proc->write_long.attr.om)) {
+
+ /* Expecting a prepare write response, not an execute write
+ * response.
+ */
+ rc = BLE_HS_EBADDATA;
+ goto err;
+ }
if (rsp->bapc_handle != proc->write_long.attr.handle) {
rc = BLE_HS_EBADDATA;
goto err;
@@ -3531,9 +3537,13 @@ ble_gattc_write_long_rx_exec(struct ble_gattc_proc *proc, int status)
{
ble_gattc_dbg_assert_proc_not_inserted(proc);
- /* Ignore the response if we haven't sent the corresponding request yet. */
- if (!proc->write_long.exec_sent) {
- return 0;
+ if (proc->write_long.attr.offset <
+ OS_MBUF_PKTLEN(proc->write_long.attr.om)) {
+
+ /* Expecting an execute write response, not a prepare write
+ * response.
+ */
+ return BLE_HS_EBADDATA;
}
ble_gattc_write_long_cb(proc, status, 0);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/aadba628/net/nimble/host/src/test/ble_gatt_write_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gatt_write_test.c b/net/nimble/host/src/test/ble_gatt_write_test.c
index f145ea8..f548198 100644
--- a/net/nimble/host/src/test/ble_gatt_write_test.c
+++ b/net/nimble/host/src/test/ble_gatt_write_test.c
@@ -123,6 +123,7 @@ ble_gatt_write_test_rx_exec_rsp(uint16_t conn_handle)
static void
ble_gatt_write_test_misc_long_good(int attr_len)
{
+ uint16_t mtu;
int off;
int len;
int rc;
@@ -132,6 +133,8 @@ ble_gatt_write_test_misc_long_good(int attr_len)
ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
NULL, NULL);
+ mtu = ble_att_mtu(2);
+
rc = ble_hs_test_util_gatt_write_long_flat(
2, 100, ble_gatt_write_test_attr_value, attr_len,
ble_gatt_write_test_cb_good, &attr_len);
@@ -139,17 +142,18 @@ ble_gatt_write_test_misc_long_good(int attr_len)
off = 0;
while (off < attr_len) {
- /* Send the pending ATT Prep Write Command. */
- ble_hs_test_util_tx_all();
-
- /* Receive Prep Write response. */
- len = BLE_ATT_MTU_DFLT - BLE_ATT_PREP_WRITE_CMD_BASE_SZ;
+ len = mtu - BLE_ATT_PREP_WRITE_CMD_BASE_SZ;
if (off + len > attr_len) {
len = attr_len - off;
}
- ble_gatt_write_test_rx_prep_rsp(2, 100, off,
- ble_gatt_write_test_attr_value + off,
- len);
+
+ /* Send the pending ATT Prep Write Command. */
+ ble_hs_test_util_verify_tx_prep_write(
+ 100, off, ble_gatt_write_test_attr_value + off, len);
+
+ /* Receive Prep Write response. */
+ ble_gatt_write_test_rx_prep_rsp(
+ 2, 100, off, ble_gatt_write_test_attr_value + off, len);
/* Verify callback hasn't gotten called. */
TEST_ASSERT(!ble_gatt_write_test_cb_called);
@@ -157,6 +161,9 @@ ble_gatt_write_test_misc_long_good(int attr_len)
off += len;
}
+ /* Verify execute write request sent. */
+ ble_hs_test_util_verify_tx_exec_write(BLE_ATT_EXEC_WRITE_F_CONFIRM);
+
/* Receive Exec Write response. */
ble_hs_test_util_tx_all();
ble_gatt_write_test_rx_exec_rsp(2);
@@ -172,6 +179,7 @@ static void
ble_gatt_write_test_misc_long_bad(int attr_len,
ble_gatt_write_test_long_fail_fn *cb)
{
+ uint16_t mtu;
int fail_now;
int off;
int len;
@@ -181,6 +189,7 @@ ble_gatt_write_test_misc_long_bad(int attr_len,
ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
NULL, NULL);
+ mtu = ble_att_mtu(2);
rc = ble_hs_test_util_gatt_write_long_flat(
2, 100, ble_gatt_write_test_attr_value, attr_len,
@@ -190,9 +199,14 @@ ble_gatt_write_test_misc_long_bad(int attr_len,
fail_now = 0;
off = 0;
while (off < attr_len) {
+ len = mtu - BLE_ATT_PREP_WRITE_CMD_BASE_SZ;
+ if (off + len > attr_len) {
+ len = attr_len - off;
+ }
+
/* Send the pending ATT Prep Write Command. */
- ble_hs_test_util_tx_all();
- TEST_ASSERT(ble_hs_test_util_prev_tx_dequeue() != NULL);
+ ble_hs_test_util_verify_tx_prep_write(
+ 100, off, ble_gatt_write_test_attr_value + off, len);
/* Receive Prep Write response. */
len = BLE_ATT_MTU_DFLT - BLE_ATT_PREP_WRITE_CMD_BASE_SZ;
@@ -283,9 +297,13 @@ static void
ble_gatt_write_test_misc_reliable_good(
struct ble_hs_test_util_flat_attr *flat_attrs)
{
+ const struct ble_hs_test_util_flat_attr *attr;
struct ble_gatt_attr attrs[16];
+ uint16_t mtu;
int num_attrs;
int attr_idx;
+ int len;
+ int off;
int rc;
int i;
@@ -299,24 +317,43 @@ ble_gatt_write_test_misc_reliable_good(
ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
NULL, NULL);
+ mtu = ble_att_mtu(2);
rc = ble_gattc_write_reliable(2, attrs, num_attrs,
ble_gatt_write_test_reliable_cb_good, NULL);
TEST_ASSERT(rc == 0);
- for (attr_idx = 0; attr_idx < num_attrs; attr_idx++) {
+ attr_idx = 0;
+ off = 0;
+ while (attr_idx < num_attrs) {
+ attr = flat_attrs + attr_idx;
+
+ len = mtu - BLE_ATT_PREP_WRITE_CMD_BASE_SZ;
+ if (off + len > attr->value_len) {
+ len = attr->value_len - off;
+ }
+
/* Send the pending ATT Prep Write Command. */
- ble_hs_test_util_tx_all();
+ ble_hs_test_util_verify_tx_prep_write(attr->handle, off,
+ attr->value + off, len);
/* Receive Prep Write response. */
- ble_gatt_write_test_rx_prep_rsp(2, flat_attrs[attr_idx].handle, 0,
- flat_attrs[attr_idx].value,
- flat_attrs[attr_idx].value_len);
+ ble_gatt_write_test_rx_prep_rsp(2, attr->handle, off,
+ attr->value + off, len);
/* Verify callback hasn't gotten called. */
TEST_ASSERT(!ble_gatt_write_test_cb_called);
+
+ off += len;
+ if (off >= attr->value_len) {
+ attr_idx++;
+ off = 0;
+ }
}
+ /* Verify execute write request sent. */
+ ble_hs_test_util_verify_tx_exec_write(BLE_ATT_EXEC_WRITE_F_CONFIRM);
+
/* Receive Exec Write response. */
ble_hs_test_util_tx_all();
ble_gatt_write_test_rx_exec_rsp(2);
@@ -509,6 +546,21 @@ TEST_CASE(ble_gatt_write_test_reliable_good)
}, {
0
} }));
+
+ /*** Long attributes. */
+ ble_gatt_write_test_misc_reliable_good(
+ ((struct ble_hs_test_util_flat_attr[]) { {
+ .handle = 100,
+ .value_len = 20,
+ .value = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20 },
+ }, {
+ .handle = 144,
+ .value_len = 20,
+ .value = { 11,12,13,14,15,16,17,18,19,110,
+ 111,112,113,114,115,116,117,118,119,120 },
+ }, {
+ 0
+ } }));
}
TEST_CASE(ble_gatt_write_test_long_queue_full)
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/aadba628/net/nimble/host/src/test/ble_hs_test_util.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_test_util.c b/net/nimble/host/src/test/ble_hs_test_util.c
index 4f1c706..54a3527 100644
--- a/net/nimble/host/src/test/ble_hs_test_util.c
+++ b/net/nimble/host/src/test/ble_hs_test_util.c
@@ -1051,6 +1051,29 @@ ble_hs_test_util_tx_all(void)
}
void
+ble_hs_test_util_verify_tx_prep_write(uint16_t attr_handle, uint16_t offset,
+ const void *data, int data_len)
+{
+ struct ble_att_prep_write_cmd req;
+ struct os_mbuf *om;
+
+ ble_hs_test_util_tx_all();
+ om = ble_hs_test_util_prev_tx_dequeue();
+ TEST_ASSERT_FATAL(om != NULL);
+ TEST_ASSERT(OS_MBUF_PKTLEN(om) ==
+ BLE_ATT_PREP_WRITE_CMD_BASE_SZ + data_len);
+
+ om = os_mbuf_pullup(om, BLE_ATT_PREP_WRITE_CMD_BASE_SZ);
+ TEST_ASSERT_FATAL(om != NULL);
+
+ ble_att_prep_write_req_parse(om->om_data, om->om_len, &req);
+ TEST_ASSERT(req.bapc_handle == attr_handle);
+ TEST_ASSERT(req.bapc_offset == offset);
+ TEST_ASSERT(os_mbuf_cmpf(om, BLE_ATT_PREP_WRITE_CMD_BASE_SZ,
+ data, data_len) == 0);
+}
+
+void
ble_hs_test_util_verify_tx_exec_write(uint8_t expected_flags)
{
struct ble_att_exec_write_req req;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/aadba628/net/nimble/host/src/test/ble_hs_test_util.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_test_util.h b/net/nimble/host/src/test/ble_hs_test_util.h
index 00b090f..0ae6cf5 100644
--- a/net/nimble/host/src/test/ble_hs_test_util.h
+++ b/net/nimble/host/src/test/ble_hs_test_util.h
@@ -129,6 +129,9 @@ void ble_hs_test_util_rx_disconn_complete_event(
uint8_t *ble_hs_test_util_verify_tx_hci(uint8_t ogf, uint16_t ocf,
uint8_t *out_param_len);
void ble_hs_test_util_tx_all(void);
+void ble_hs_test_util_verify_tx_prep_write(uint16_t attr_handle,
+ uint16_t offset,
+ const void *data, int data_len);
void ble_hs_test_util_verify_tx_exec_write(uint8_t expected_flags);
void ble_hs_test_util_verify_tx_read_rsp(uint8_t *attr_data, int attr_len);
void ble_hs_test_util_verify_tx_read_blob_rsp(uint8_t *attr_data,
[05/42] incubator-mynewt-core git commit: BLE Host - Use HCI
transport API
Posted by st...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fd02e1e/net/nimble/transport/uart/src/ble_hci_uart.c
----------------------------------------------------------------------
diff --git a/net/nimble/transport/uart/src/ble_hci_uart.c b/net/nimble/transport/uart/src/ble_hci_uart.c
new file mode 100755
index 0000000..98a49b6
--- /dev/null
+++ b/net/nimble/transport/uart/src/ble_hci_uart.c
@@ -0,0 +1,775 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <assert.h>
+#include <string.h>
+#include <stdio.h>
+#include <errno.h>
+#include "bsp/bsp.h"
+#include "os/os.h"
+#include "bsp/bsp.h"
+#include "hal/hal_gpio.h"
+#include "hal/hal_cputime.h"
+#include "hal/hal_uart.h"
+
+/* BLE */
+#include "nimble/ble.h"
+#include "nimble/nimble_opt.h"
+#include "nimble/hci_common.h"
+#include "nimble/ble_hci_trans.h"
+
+#include "transport/uart/ble_hci_uart.h"
+
+/***
+ * NOTE:
+ * The UART HCI transport doesn't use event buffer priorities. All incoming
+ * and outgoing events and commands use buffers from the same pool.
+ */
+
+#define BLE_HCI_UART_H4_NONE 0x00
+#define BLE_HCI_UART_H4_CMD 0x01
+#define BLE_HCI_UART_H4_ACL 0x02
+#define BLE_HCI_UART_H4_SCO 0x03
+#define BLE_HCI_UART_H4_EVT 0x04
+
+/** Default configuration. */
+const struct ble_hci_uart_cfg ble_hci_uart_cfg_dflt = {
+ .uart_port = 0,
+ .baud = 1000000,
+ .flow_ctrl = HAL_UART_FLOW_CTL_RTS_CTS,
+ .data_bits = 8,
+ .stop_bits = 1,
+ .parity = HAL_UART_PARITY_NONE,
+
+ .num_evt_bufs = 8,
+ .evt_buf_sz = BLE_HCI_TRANS_CMD_SZ,
+};
+
+static ble_hci_trans_rx_cmd_fn *ble_hci_uart_rx_cmd_cb;
+static void *ble_hci_uart_rx_cmd_arg;
+
+static ble_hci_trans_rx_acl_fn *ble_hci_uart_rx_acl_cb;
+static void *ble_hci_uart_rx_acl_arg;
+
+static struct os_mempool ble_hci_uart_evt_pool;
+static void *ble_hci_uart_evt_buf;
+
+static struct os_mempool ble_hci_uart_pkt_pool;
+static void *ble_hci_uart_pkt_buf;
+
+#define BLE_HCI_UART_LOG_SZ 1024
+static uint8_t ble_hci_uart_tx_log[BLE_HCI_UART_LOG_SZ];
+static int ble_hci_uart_tx_log_sz;
+static uint8_t ble_hci_uart_rx_log[BLE_HCI_UART_LOG_SZ];
+static int ble_hci_uart_rx_log_sz;
+
+/**
+ * An incoming or outgoing command or event.
+ */
+struct ble_hci_uart_cmd {
+ uint8_t *data; /* Pointer to ble_hci_uart_cmd data */
+ uint16_t cur; /* Number of bytes read/written */
+ uint16_t len; /* Total number of bytes to read/write */
+};
+
+/**
+ * An incoming ACL data packet.
+ */
+struct ble_hci_uart_acl {
+ struct os_mbuf *buf; /* Buffer containing the data */
+ uint16_t len; /* Target size when buf is considered complete */
+};
+
+/**
+ * A packet to be sent over the UART. This can be a command, an event, or ACL
+ * data.
+ */
+struct ble_hci_uart_pkt {
+ STAILQ_ENTRY(ble_hci_uart_pkt) next;
+ void *data;
+ uint8_t type;
+};
+
+static struct {
+ /*** State of data received over UART. */
+ uint8_t rx_type; /* Pending packet type. 0 means nothing pending */
+ union {
+ struct ble_hci_uart_cmd rx_cmd;
+ struct ble_hci_uart_acl rx_acl;
+ };
+
+ /*** State of data transmitted over UART. */
+ uint8_t tx_type; /* Pending packet type. 0 means nothing pending */
+ union {
+ struct ble_hci_uart_cmd tx_cmd;
+ struct os_mbuf *tx_acl;
+ };
+ STAILQ_HEAD(, ble_hci_uart_pkt) tx_pkts; /* Packet queue to send to UART */
+} ble_hci_uart_state;
+
+static struct ble_hci_uart_cfg ble_hci_uart_cfg;
+
+static int
+ble_hci_uart_acl_tx(struct os_mbuf *om)
+{
+ struct ble_hci_uart_pkt *pkt;
+ os_sr_t sr;
+
+ pkt = os_memblock_get(&ble_hci_uart_pkt_pool);
+ if (pkt == NULL) {
+ os_mbuf_free_chain(om);
+ return BLE_ERR_MEM_CAPACITY;
+ }
+
+ pkt->type = BLE_HCI_UART_H4_ACL;
+ pkt->data = om;
+
+ OS_ENTER_CRITICAL(sr);
+ STAILQ_INSERT_TAIL(&ble_hci_uart_state.tx_pkts, pkt, next);
+ OS_EXIT_CRITICAL(sr);
+
+ hal_uart_start_tx(ble_hci_uart_cfg.uart_port);
+
+ return 0;
+}
+
+static int
+ble_hci_uart_cmdevt_tx(uint8_t *hci_ev, uint8_t h4_type)
+{
+ struct ble_hci_uart_pkt *pkt;
+ os_sr_t sr;
+
+ pkt = os_memblock_get(&ble_hci_uart_pkt_pool);
+ if (pkt == NULL) {
+ ble_hci_trans_buf_free(hci_ev);
+ return BLE_ERR_MEM_CAPACITY;
+ }
+
+ pkt->type = h4_type;
+ pkt->data = hci_ev;
+
+ OS_ENTER_CRITICAL(sr);
+ STAILQ_INSERT_TAIL(&ble_hci_uart_state.tx_pkts, pkt, next);
+ OS_EXIT_CRITICAL(sr);
+
+ hal_uart_start_tx(ble_hci_uart_cfg.uart_port);
+
+ return 0;
+}
+
+/**
+ * @return The packet type to transmit on success;
+ * -1 if there is nothing to send.
+ */
+static int
+ble_hci_uart_tx_pkt_type(void)
+{
+ struct ble_hci_uart_pkt *pkt;
+ os_sr_t sr;
+ int rc;
+
+ OS_ENTER_CRITICAL(sr);
+
+ pkt = STAILQ_FIRST(&ble_hci_uart_state.tx_pkts);
+ if (!pkt) {
+ OS_EXIT_CRITICAL(sr);
+ return -1;
+ }
+
+ STAILQ_REMOVE(&ble_hci_uart_state.tx_pkts, pkt, ble_hci_uart_pkt, next);
+
+ OS_EXIT_CRITICAL(sr);
+
+ rc = pkt->type;
+ switch (pkt->type) {
+ case BLE_HCI_UART_H4_CMD:
+ ble_hci_uart_state.tx_type = BLE_HCI_UART_H4_CMD;
+ ble_hci_uart_state.tx_cmd.data = pkt->data;
+ ble_hci_uart_state.tx_cmd.cur = 0;
+ ble_hci_uart_state.tx_cmd.len = ble_hci_uart_state.tx_cmd.data[2] +
+ BLE_HCI_CMD_HDR_LEN;
+ break;
+
+ case BLE_HCI_UART_H4_EVT:
+ ble_hci_uart_state.tx_type = BLE_HCI_UART_H4_EVT;
+ ble_hci_uart_state.tx_cmd.data = pkt->data;
+ ble_hci_uart_state.tx_cmd.cur = 0;
+ ble_hci_uart_state.tx_cmd.len = ble_hci_uart_state.tx_cmd.data[1] +
+ BLE_HCI_EVENT_HDR_LEN;
+ break;
+
+ case BLE_HCI_UART_H4_ACL:
+ ble_hci_uart_state.tx_type = BLE_HCI_UART_H4_ACL;
+ ble_hci_uart_state.tx_acl = pkt->data;
+ break;
+
+ default:
+ rc = -1;
+ break;
+ }
+
+ os_memblock_put(&ble_hci_uart_pkt_pool, pkt);
+
+ return rc;
+}
+
+/**
+ * @return The byte to transmit on success;
+ * -1 if there is nothing to send.
+ */
+static int
+ble_hci_uart_tx_char(void *arg)
+{
+ int rc = -1;
+
+ switch (ble_hci_uart_state.tx_type) {
+ case BLE_HCI_UART_H4_NONE: /* No pending packet, pick one from the queue */
+ rc = ble_hci_uart_tx_pkt_type();
+ break;
+
+ case BLE_HCI_UART_H4_CMD:
+ case BLE_HCI_UART_H4_EVT:
+ rc = ble_hci_uart_state.tx_cmd.data[ble_hci_uart_state.tx_cmd.cur++];
+
+ if (ble_hci_uart_state.tx_cmd.cur == ble_hci_uart_state.tx_cmd.len) {
+ ble_hci_trans_buf_free(ble_hci_uart_state.tx_cmd.data);
+ ble_hci_uart_state.tx_type = BLE_HCI_UART_H4_NONE;
+ }
+ break;
+
+ case BLE_HCI_UART_H4_ACL:
+ rc = *OS_MBUF_DATA(ble_hci_uart_state.tx_acl, uint8_t *);
+ os_mbuf_adj(ble_hci_uart_state.tx_acl, 1);
+ if (!OS_MBUF_PKTLEN(ble_hci_uart_state.tx_acl)) {
+ os_mbuf_free_chain(ble_hci_uart_state.tx_acl);
+ ble_hci_uart_state.tx_type = BLE_HCI_UART_H4_NONE;
+ }
+ break;
+ }
+
+ if (rc != -1) {
+ ble_hci_uart_tx_log[ble_hci_uart_tx_log_sz++] = rc;
+ if (ble_hci_uart_tx_log_sz == sizeof ble_hci_uart_tx_log) {
+ ble_hci_uart_tx_log_sz = 0;
+ }
+ }
+
+ return rc;
+}
+
+/**
+ * @return The type of packet to follow success;
+ * -1 if there is no valid packet to receive.
+ */
+static int
+ble_hci_uart_rx_pkt_type(uint8_t data)
+{
+ ble_hci_uart_state.rx_type = data;
+
+ /* XXX: For now we assert that buffer allocation succeeds. The correct
+ * thing to do is return -1 on allocation failure so that flow control is
+ * engaged. Then, we will need to tell the UART to start receiving again
+ * as follows:
+ * o flat buf: when we free a buffer.
+ * o mbuf: periodically? (which task executes the callout?)
+ */
+ switch (ble_hci_uart_state.rx_type) {
+ case BLE_HCI_UART_H4_CMD:
+ ble_hci_uart_state.rx_cmd.data =
+ ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_CMD);
+ assert(ble_hci_uart_state.rx_cmd.data != NULL);
+
+ ble_hci_uart_state.rx_cmd.len = 0;
+ ble_hci_uart_state.rx_cmd.cur = 0;
+ break;
+
+ case BLE_HCI_UART_H4_EVT:
+ ble_hci_uart_state.rx_cmd.data =
+ ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_HI);
+ assert(ble_hci_uart_state.rx_cmd.data != NULL);
+
+ ble_hci_uart_state.rx_cmd.len = 0;
+ ble_hci_uart_state.rx_cmd.cur = 0;
+ break;
+
+ case BLE_HCI_UART_H4_ACL:
+ ble_hci_uart_state.rx_acl.buf =
+ os_msys_get_pkthdr(BLE_HCI_DATA_HDR_SZ, 0);
+ assert(ble_hci_uart_state.rx_acl.buf != NULL);
+
+ ble_hci_uart_state.rx_acl.len = 0;
+ break;
+
+ default:
+ ble_hci_uart_state.rx_type = BLE_HCI_UART_H4_NONE;
+ return -1;
+ }
+
+ return 0;
+}
+
+static void
+ble_hci_uart_rx_cmd(uint8_t data)
+{
+ int rc;
+
+ ble_hci_uart_state.rx_cmd.data[ble_hci_uart_state.rx_cmd.cur++] = data;
+
+ if (ble_hci_uart_state.rx_cmd.cur < BLE_HCI_CMD_HDR_LEN) {
+ return;
+ }
+
+ if (ble_hci_uart_state.rx_cmd.cur == BLE_HCI_CMD_HDR_LEN) {
+ ble_hci_uart_state.rx_cmd.len = ble_hci_uart_state.rx_cmd.data[2] +
+ BLE_HCI_CMD_HDR_LEN;
+ }
+
+ if (ble_hci_uart_state.rx_cmd.cur == ble_hci_uart_state.rx_cmd.len) {
+ assert(ble_hci_uart_rx_cmd_cb != NULL);
+ rc = ble_hci_uart_rx_cmd_cb(ble_hci_uart_state.rx_cmd.data,
+ ble_hci_uart_rx_cmd_arg);
+ if (rc != 0) {
+ ble_hci_trans_buf_free(ble_hci_uart_state.rx_cmd.data);
+ }
+ ble_hci_uart_state.rx_type = BLE_HCI_UART_H4_NONE;
+ }
+}
+
+static void
+ble_hci_uart_rx_evt(uint8_t data)
+{
+ int rc;
+
+ ble_hci_uart_state.rx_cmd.data[ble_hci_uart_state.rx_cmd.cur++] = data;
+
+ if (ble_hci_uart_state.rx_cmd.cur < BLE_HCI_EVENT_HDR_LEN) {
+ return;
+ }
+
+ if (ble_hci_uart_state.rx_cmd.cur == BLE_HCI_EVENT_HDR_LEN) {
+ ble_hci_uart_state.rx_cmd.len = ble_hci_uart_state.rx_cmd.data[1] +
+ BLE_HCI_EVENT_HDR_LEN;
+ }
+
+ if (ble_hci_uart_state.rx_cmd.cur == ble_hci_uart_state.rx_cmd.len) {
+ assert(ble_hci_uart_rx_cmd_cb != NULL);
+ rc = ble_hci_uart_rx_cmd_cb(ble_hci_uart_state.rx_cmd.data,
+ ble_hci_uart_rx_cmd_arg);
+ if (rc != 0) {
+ ble_hci_trans_buf_free(ble_hci_uart_state.rx_cmd.data);
+ }
+ ble_hci_uart_state.rx_type = BLE_HCI_UART_H4_NONE;
+ }
+}
+
+static void
+ble_hci_uart_rx_acl(uint8_t data)
+{
+ uint16_t pktlen;
+
+ os_mbuf_append(ble_hci_uart_state.rx_acl.buf, &data, 1);
+
+ pktlen = OS_MBUF_PKTLEN(ble_hci_uart_state.rx_acl.buf);
+
+ if (pktlen < BLE_HCI_DATA_HDR_SZ) {
+ return;
+ }
+
+ if (pktlen == BLE_HCI_DATA_HDR_SZ) {
+ os_mbuf_copydata(ble_hci_uart_state.rx_acl.buf, 2,
+ sizeof(ble_hci_uart_state.rx_acl.len),
+ &ble_hci_uart_state.rx_acl.len);
+ ble_hci_uart_state.rx_acl.len =
+ le16toh(&ble_hci_uart_state.rx_acl.len) + BLE_HCI_DATA_HDR_SZ;
+ }
+
+ if (pktlen == ble_hci_uart_state.rx_acl.len) {
+ assert(ble_hci_uart_rx_cmd_cb != NULL);
+ ble_hci_uart_rx_acl_cb(ble_hci_uart_state.rx_acl.buf,
+ ble_hci_uart_rx_acl_arg);
+ ble_hci_uart_state.rx_type = BLE_HCI_UART_H4_NONE;
+ }
+}
+
+static int
+ble_hci_uart_rx_char(void *arg, uint8_t data)
+{
+ ble_hci_uart_rx_log[ble_hci_uart_rx_log_sz++] = data;
+ if (ble_hci_uart_rx_log_sz == sizeof ble_hci_uart_rx_log) {
+ ble_hci_uart_rx_log_sz = 0;
+ }
+
+ switch (ble_hci_uart_state.rx_type) {
+ case BLE_HCI_UART_H4_NONE:
+ return ble_hci_uart_rx_pkt_type(data);
+ case BLE_HCI_UART_H4_CMD:
+ ble_hci_uart_rx_cmd(data);
+ return 0;
+ case BLE_HCI_UART_H4_EVT:
+ ble_hci_uart_rx_evt(data);
+ return 0;
+ case BLE_HCI_UART_H4_ACL:
+ ble_hci_uart_rx_acl(data);
+ return 0;
+ default:
+ return -1;
+ }
+}
+
+static void
+ble_hci_uart_set_rx_cbs(ble_hci_trans_rx_cmd_fn *cmd_cb,
+ void *cmd_arg,
+ ble_hci_trans_rx_acl_fn *acl_cb,
+ void *acl_arg)
+{
+ ble_hci_uart_rx_cmd_cb = cmd_cb;
+ ble_hci_uart_rx_cmd_arg = cmd_arg;
+ ble_hci_uart_rx_acl_cb = acl_cb;
+ ble_hci_uart_rx_acl_arg = acl_arg;
+}
+
+static void
+ble_hci_uart_free_pkt(uint8_t type, uint8_t *cmdevt, struct os_mbuf *acl)
+{
+ switch (type) {
+ case BLE_HCI_UART_H4_NONE:
+ break;
+
+ case BLE_HCI_UART_H4_CMD:
+ case BLE_HCI_UART_H4_EVT:
+ ble_hci_trans_buf_free(cmdevt);
+ break;
+
+ case BLE_HCI_UART_H4_ACL:
+ os_mbuf_free_chain(acl);
+ break;
+
+ default:
+ assert(0);
+ break;
+ }
+}
+
+static void
+ble_hci_uart_free_mem(void)
+{
+ free(ble_hci_uart_evt_buf);
+ ble_hci_uart_evt_buf = NULL;
+
+ free(ble_hci_uart_pkt_buf);
+ ble_hci_uart_pkt_buf = NULL;
+}
+
+static int
+ble_hci_uart_config(void)
+{
+ int rc;
+
+ rc = hal_uart_init_cbs(ble_hci_uart_cfg.uart_port,
+ ble_hci_uart_tx_char, NULL,
+ ble_hci_uart_rx_char, NULL);
+ if (rc != 0) {
+ return BLE_ERR_UNSPECIFIED;
+ }
+
+ rc = hal_uart_config(ble_hci_uart_cfg.uart_port,
+ ble_hci_uart_cfg.baud,
+ ble_hci_uart_cfg.data_bits,
+ ble_hci_uart_cfg.stop_bits,
+ ble_hci_uart_cfg.parity,
+ ble_hci_uart_cfg.flow_ctrl);
+ if (rc != 0) {
+ return BLE_ERR_HW_FAIL;
+ }
+
+ return 0;
+}
+
+/**
+ * Sends an HCI event from the controller to the host.
+ *
+ * @param cmd The HCI event to send. This buffer must be
+ * allocated via ble_hci_trans_buf_alloc().
+ *
+ * @return 0 on success;
+ * A BLE_ERR_[...] error code on failure.
+ */
+int
+ble_hci_trans_ll_evt_tx(uint8_t *cmd)
+{
+ int rc;
+
+ rc = ble_hci_uart_cmdevt_tx(cmd, BLE_HCI_UART_H4_EVT);
+ return rc;
+}
+
+/**
+ * Sends ACL data from controller to host.
+ *
+ * @param om The ACL data packet to send.
+ *
+ * @return 0 on success;
+ * A BLE_ERR_[...] error code on failure.
+ */
+int
+ble_hci_trans_ll_acl_tx(struct os_mbuf *om)
+{
+ int rc;
+
+ rc = ble_hci_uart_acl_tx(om);
+ return rc;
+}
+
+/**
+ * Sends an HCI command from the host to the controller.
+ *
+ * @param cmd The HCI command to send. This buffer must be
+ * allocated via ble_hci_trans_buf_alloc().
+ *
+ * @return 0 on success;
+ * A BLE_ERR_[...] error code on failure.
+ */
+int
+ble_hci_trans_hs_cmd_tx(uint8_t *cmd)
+{
+ int rc;
+
+ rc = ble_hci_uart_cmdevt_tx(cmd, BLE_HCI_UART_H4_CMD);
+ return rc;
+}
+
+/**
+ * Sends ACL data from host to controller.
+ *
+ * @param om The ACL data packet to send.
+ *
+ * @return 0 on success;
+ * A BLE_ERR_[...] error code on failure.
+ */
+int
+ble_hci_trans_hs_acl_tx(struct os_mbuf *om)
+{
+ int rc;
+
+ rc = ble_hci_uart_acl_tx(om);
+ return rc;
+}
+
+/**
+ * Configures the HCI transport to call the specified callback upon receiving
+ * HCI packets from the controller. This function should only be called by by
+ * host.
+ *
+ * @param cmd_cb The callback to execute upon receiving an HCI
+ * event.
+ * @param cmd_arg Optional argument to pass to the command
+ * callback.
+ * @param acl_cb The callback to execute upon receiving ACL
+ * data.
+ * @param acl_arg Optional argument to pass to the ACL
+ * callback.
+ */
+void
+ble_hci_trans_cfg_hs(ble_hci_trans_rx_cmd_fn *cmd_cb,
+ void *cmd_arg,
+ ble_hci_trans_rx_acl_fn *acl_cb,
+ void *acl_arg)
+{
+ ble_hci_uart_set_rx_cbs(cmd_cb, cmd_arg, acl_cb, acl_arg);
+}
+
+/**
+ * Configures the HCI transport to operate with a host. The transport will
+ * execute specified callbacks upon receiving HCI packets from the controller.
+ *
+ * @param cmd_cb The callback to execute upon receiving an HCI
+ * event.
+ * @param cmd_arg Optional argument to pass to the command
+ * callback.
+ * @param acl_cb The callback to execute upon receiving ACL
+ * data.
+ * @param acl_arg Optional argument to pass to the ACL
+ * callback.
+ */
+void
+ble_hci_trans_cfg_ll(ble_hci_trans_rx_cmd_fn *cmd_cb,
+ void *cmd_arg,
+ ble_hci_trans_rx_acl_fn *acl_cb,
+ void *acl_arg)
+{
+ ble_hci_uart_set_rx_cbs(cmd_cb, cmd_arg, acl_cb, acl_arg);
+}
+
+/**
+ * Allocates a flat buffer of the specified type.
+ *
+ * @param type The type of buffer to allocate; one of the
+ * BLE_HCI_TRANS_BUF_[...] constants.
+ *
+ * @return The allocated buffer on success;
+ * NULL on buffer exhaustion.
+ */
+uint8_t *
+ble_hci_trans_buf_alloc(int type)
+{
+ uint8_t *buf;
+
+ switch (type) {
+ case BLE_HCI_TRANS_BUF_CMD:
+ case BLE_HCI_TRANS_BUF_EVT_LO:
+ case BLE_HCI_TRANS_BUF_EVT_HI:
+ buf = os_memblock_get(&ble_hci_uart_evt_pool);
+ break;
+
+ default:
+ assert(0);
+ buf = NULL;
+ }
+
+ return buf;
+}
+
+/**
+ * Frees the specified flat buffer. The buffer must have been allocated via
+ * ble_hci_trans_buf_alloc().
+ *
+ * @param buf The buffer to free.
+ */
+void
+ble_hci_trans_buf_free(uint8_t *buf)
+{
+ int rc;
+
+ rc = os_memblock_put(&ble_hci_uart_evt_pool, buf);
+ assert(rc == 0);
+}
+
+/**
+ * Resets the HCI UART transport to a clean state. Frees all buffers and
+ * reconfigures the UART.
+ *
+ * @return 0 on success;
+ * A BLE_ERR_[...] error code on failure.
+ */
+int
+ble_hci_trans_reset(void)
+{
+ struct ble_hci_uart_pkt *pkt;
+ int rc;
+
+ /* Close the UART to prevent race conditions as the buffers are freed. */
+ rc = hal_uart_close(ble_hci_uart_cfg.uart_port);
+ if (rc != 0) {
+ return BLE_ERR_HW_FAIL;
+ }
+
+ ble_hci_uart_free_pkt(ble_hci_uart_state.rx_type,
+ ble_hci_uart_state.rx_cmd.data,
+ ble_hci_uart_state.rx_acl.buf);
+ ble_hci_uart_state.rx_type = BLE_HCI_UART_H4_NONE;
+
+ ble_hci_uart_free_pkt(ble_hci_uart_state.tx_type,
+ ble_hci_uart_state.tx_cmd.data,
+ ble_hci_uart_state.tx_acl);
+ ble_hci_uart_state.tx_type = BLE_HCI_UART_H4_NONE;
+
+ while ((pkt = STAILQ_FIRST(&ble_hci_uart_state.tx_pkts)) != NULL) {
+ STAILQ_REMOVE(&ble_hci_uart_state.tx_pkts, pkt, ble_hci_uart_pkt,
+ next);
+ ble_hci_uart_free_pkt(pkt->type, pkt->data, pkt->data);
+ os_memblock_put(&ble_hci_uart_pkt_pool, pkt);
+ }
+
+ /* Reopen the UART. */
+ rc = ble_hci_uart_config();
+ if (rc != 0) {
+ return rc;
+ }
+
+ return 0;
+}
+
+/**
+ * Initializes the UART HCI transport module.
+ *
+ * @param cfg The settings to initialize the HCI UART
+ * transport with.
+ *
+ * @return 0 on success;
+ * A BLE_ERR_[...] error code on failure.
+ */
+int
+ble_hci_uart_init(const struct ble_hci_uart_cfg *cfg)
+{
+ int rc;
+
+ ble_hci_uart_free_mem();
+
+ ble_hci_uart_cfg = *cfg;
+
+ ble_hci_uart_evt_buf = malloc(
+ OS_MEMPOOL_BYTES(ble_hci_uart_cfg.num_evt_bufs,
+ ble_hci_uart_cfg.evt_buf_sz));
+ if (ble_hci_uart_evt_buf == NULL) {
+ rc = BLE_ERR_MEM_CAPACITY;
+ goto err;
+ }
+
+ /* Create memory pool of HCI command / event buffers */
+ rc = os_mempool_init(&ble_hci_uart_evt_pool, ble_hci_uart_cfg.num_evt_bufs,
+ ble_hci_uart_cfg.evt_buf_sz, ble_hci_uart_evt_buf,
+ "ble_hci_uart_evt_pool");
+ if (rc != 0) {
+ rc = BLE_ERR_UNSPECIFIED;
+ goto err;
+ }
+
+ ble_hci_uart_pkt_buf = malloc(
+ OS_MEMPOOL_BYTES(ble_hci_uart_cfg.num_evt_bufs,
+ sizeof (struct os_event)));
+ if (ble_hci_uart_pkt_buf == NULL) {
+ rc = BLE_ERR_MEM_CAPACITY;
+ goto err;
+ }
+
+ /* Create memory pool of packet list nodes. */
+ rc = os_mempool_init(&ble_hci_uart_pkt_pool,
+ ble_hci_uart_cfg.num_evt_bufs,
+ sizeof (struct ble_hci_uart_pkt),
+ ble_hci_uart_pkt_buf,
+ "ble_hci_uart_pkt_pool");
+ if (rc != 0) {
+ rc = BLE_ERR_UNSPECIFIED;
+ goto err;
+ }
+
+ rc = ble_hci_uart_config();
+ if (rc != 0) {
+ goto err;
+ }
+
+ memset(&ble_hci_uart_state, 0, sizeof ble_hci_uart_state);
+ STAILQ_INIT(&ble_hci_uart_state.tx_pkts);
+
+ return 0;
+
+err:
+ ble_hci_uart_free_mem();
+ return rc;
+}
[27/42] incubator-mynewt-core git commit: bletiny - Be consistent
with addr type strings.
Posted by st...@apache.org.
bletiny - Be consistent with addr type strings.
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/f5f83702
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/f5f83702
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/f5f83702
Branch: refs/heads/sterly_refactor
Commit: f5f83702cf20e8713c496d432a8ed4130b19839b
Parents: 8f4f2cb
Author: Christopher Collins <cc...@apache.org>
Authored: Thu Aug 4 18:31:32 2016 -0700
Committer: Sterling Hughes <st...@apache.org>
Committed: Tue Aug 9 16:05:21 2016 -0700
----------------------------------------------------------------------
apps/bletiny/src/cmd.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f5f83702/apps/bletiny/src/cmd.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/cmd.c b/apps/bletiny/src/cmd.c
index 1d133da..e50d6b0 100644
--- a/apps/bletiny/src/cmd.c
+++ b/apps/bletiny/src/cmd.c
@@ -363,8 +363,8 @@ cmd_adv(int argc, char **argv)
static struct kv_pair cmd_conn_peer_addr_types[] = {
{ "public", BLE_HCI_CONN_PEER_ADDR_PUBLIC },
{ "random", BLE_HCI_CONN_PEER_ADDR_RANDOM },
- { "public_ident", BLE_HCI_CONN_PEER_ADDR_PUBLIC_IDENT },
- { "random_ident", BLE_HCI_CONN_PEER_ADDR_RANDOM_IDENT },
+ { "rpa_pub", BLE_HCI_CONN_PEER_ADDR_PUBLIC_IDENT },
+ { "rpa_rnd", BLE_HCI_CONN_PEER_ADDR_RANDOM_IDENT },
{ "wl", BLE_GAP_ADDR_TYPE_WL },
{ NULL }
};
[16/42] incubator-mynewt-core git commit: BLE Host - Rename HCI
identifiers and files.
Posted by st...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/net/nimble/host/src/ble_hs_pvcy.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_pvcy.c b/net/nimble/host/src/ble_hs_pvcy.c
index 94a5586..ad3fa0c 100644
--- a/net/nimble/host/src/ble_hs_pvcy.c
+++ b/net/nimble/host/src/ble_hs_pvcy.c
@@ -36,7 +36,7 @@ ble_hs_pvcy_set_addr_timeout(uint16_t timeout)
uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_RESOLV_PRIV_ADDR_TO_LEN];
int rc;
- rc = host_hci_cmd_build_set_resolv_priv_addr_timeout(
+ rc = ble_hs_hci_cmd_build_set_resolv_priv_addr_timeout(
timeout, buf, sizeof(buf));
return rc;
@@ -48,12 +48,12 @@ ble_hs_pvcy_set_resolve_enabled(int enable)
uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_ADDR_RESOL_ENA_LEN];
int rc;
- rc = host_hci_cmd_build_set_addr_res_en(enable, buf, sizeof(buf));
+ rc = ble_hs_hci_cmd_build_set_addr_res_en(enable, buf, sizeof(buf));
if (rc != 0) {
return rc;
}
- rc = ble_hci_cmd_tx(buf, NULL, 0, NULL);
+ rc = ble_hs_hci_cmd_tx(buf, NULL, 0, NULL);
if (rc != 0) {
return rc;
}
@@ -67,13 +67,13 @@ ble_hs_pvcy_remove_entry(uint8_t addr_type, uint8_t *addr)
uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_RMV_FROM_RESOLV_LIST_LEN];
int rc;
- rc = host_hci_cmd_build_remove_from_resolv_list(
+ rc = ble_hs_hci_cmd_build_remove_from_resolv_list(
addr_type, addr, buf, sizeof(buf));
if (rc != 0) {
return rc;
}
- rc = ble_hci_cmd_tx(buf, NULL, 0, NULL);
+ rc = ble_hs_hci_cmd_tx(buf, NULL, 0, NULL);
if (rc != 0) {
return rc;
}
@@ -87,12 +87,12 @@ ble_hs_pvcy_clear_entries(void)
uint8_t buf[BLE_HCI_CMD_HDR_LEN ];
int rc;
- rc = host_hci_cmd_build_clear_resolv_list(buf, sizeof(buf));
+ rc = ble_hs_hci_cmd_build_clear_resolv_list(buf, sizeof(buf));
if (rc != 0) {
return rc;
}
- rc = ble_hci_cmd_tx(buf, NULL, 0, NULL);
+ rc = ble_hs_hci_cmd_tx(buf, NULL, 0, NULL);
if (rc != 0) {
return rc;
}
@@ -112,12 +112,12 @@ ble_hs_pvcy_add_entry(uint8_t *addr, uint8_t addr_type, uint8_t *irk)
memcpy(add.local_irk, ble_hs_pvcy_irk, 16);
memcpy(add.peer_irk, irk, 16);
- rc = host_hci_cmd_build_add_to_resolv_list(&add, buf, sizeof(buf));
+ rc = ble_hs_hci_cmd_build_add_to_resolv_list(&add, buf, sizeof(buf));
if (rc != 0) {
return rc;
}
- rc = ble_hci_cmd_tx(buf, NULL, 0, NULL);
+ rc = ble_hs_hci_cmd_tx(buf, NULL, 0, NULL);
if (rc != 0) {
return rc;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/net/nimble/host/src/ble_hs_startup.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_startup.c b/net/nimble/host/src/ble_hs_startup.c
index 1ce49a7..89cbd70 100644
--- a/net/nimble/host/src/ble_hs_startup.c
+++ b/net/nimble/host/src/ble_hs_startup.c
@@ -19,7 +19,6 @@
#include <stddef.h>
#include <string.h>
-#include "host/host_hci.h"
#include "host/ble_hs.h"
#include "ble_hs_priv.h"
@@ -31,8 +30,9 @@ ble_hs_startup_le_read_sup_f_tx(void)
uint8_t ack_params_len;
int rc;
- host_hci_cmd_build_le_read_loc_supp_feat(buf, sizeof buf);
- rc = ble_hci_cmd_tx(buf, ack_params, sizeof ack_params, &ack_params_len);
+ ble_hs_hci_cmd_build_le_read_loc_supp_feat(buf, sizeof buf);
+ rc = ble_hs_hci_cmd_tx(buf, ack_params, sizeof ack_params,
+ &ack_params_len);
if (rc != 0) {
return rc;
}
@@ -56,8 +56,9 @@ ble_hs_startup_le_read_buf_sz_tx(void)
uint8_t max_pkts;
int rc;
- host_hci_cmd_build_le_read_buffer_size(buf, sizeof buf);
- rc = ble_hci_cmd_tx(buf, ack_params, sizeof ack_params, &ack_params_len);
+ ble_hs_hci_cmd_build_le_read_buffer_size(buf, sizeof buf);
+ rc = ble_hs_hci_cmd_tx(buf, ack_params, sizeof ack_params,
+ &ack_params_len);
if (rc != 0) {
return rc;
}
@@ -69,7 +70,7 @@ ble_hs_startup_le_read_buf_sz_tx(void)
pktlen = le16toh(ack_params + 0);
max_pkts = ack_params[2];
- rc = host_hci_set_buf_size(pktlen, max_pkts);
+ rc = ble_hs_hci_set_buf_sz(pktlen, max_pkts);
if (rc != 0) {
return rc;
}
@@ -85,8 +86,9 @@ ble_hs_startup_read_bd_addr(void)
uint8_t ack_params_len;
int rc;
- host_hci_cmd_build_read_bd_addr(buf, sizeof buf);
- rc = ble_hci_cmd_tx(buf, ack_params, sizeof ack_params, &ack_params_len);
+ ble_hs_hci_cmd_build_read_bd_addr(buf, sizeof buf);
+ rc = ble_hs_hci_cmd_tx(buf, ack_params, sizeof ack_params,
+ &ack_params_len);
if (rc != 0) {
return rc;
}
@@ -116,8 +118,9 @@ ble_hs_startup_le_set_evmask_tx(void)
* 0x0000000000000040 LE Data Length Change Event
* 0x0000000000000200 LE Enhanced Connection Complete Event
*/
- host_hci_cmd_build_le_set_event_mask(0x000000000000027f, buf, sizeof buf);
- rc = ble_hci_cmd_tx_empty_ack(buf);
+ ble_hs_hci_cmd_build_le_set_event_mask(0x000000000000027f,
+ buf, sizeof buf);
+ rc = ble_hs_hci_cmd_tx_empty_ack(buf);
if (rc != 0) {
return rc;
}
@@ -173,8 +176,8 @@ ble_hs_startup_set_evmask_tx(void)
* 0x0000800000000000 Encryption Key Refresh Complete Event
* 0x2000000000000000 LE Meta-Event
*/
- host_hci_cmd_build_set_event_mask(0x20009fffffffffff, buf, sizeof buf);
- rc = ble_hci_cmd_tx_empty_ack(buf);
+ ble_hs_hci_cmd_build_set_event_mask(0x20009fffffffffff, buf, sizeof buf);
+ rc = ble_hs_hci_cmd_tx_empty_ack(buf);
if (rc != 0) {
return rc;
}
@@ -183,8 +186,8 @@ ble_hs_startup_set_evmask_tx(void)
* Enable the following events:
* 0x0000000000800000 Authenticated Payload Timeout Event
*/
- host_hci_cmd_build_set_event_mask2(0x0000000000800000, buf, sizeof buf);
- rc = ble_hci_cmd_tx_empty_ack(buf);
+ ble_hs_hci_cmd_build_set_event_mask2(0x0000000000800000, buf, sizeof buf);
+ rc = ble_hs_hci_cmd_tx_empty_ack(buf);
if (rc != 0) {
return rc;
}
@@ -198,8 +201,8 @@ ble_hs_startup_reset_tx(void)
uint8_t buf[BLE_HCI_CMD_HDR_LEN];
int rc;
- host_hci_cmd_build_reset(buf, sizeof buf);
- rc = ble_hci_cmd_tx_empty_ack(buf);
+ ble_hs_hci_cmd_build_reset(buf, sizeof buf);
+ rc = ble_hs_hci_cmd_tx_empty_ack(buf);
if (rc != 0) {
return rc;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/net/nimble/host/src/ble_ibeacon.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_ibeacon.c b/net/nimble/host/src/ble_ibeacon.c
index 68c182f..5bdb99d 100644
--- a/net/nimble/host/src/ble_ibeacon.c
+++ b/net/nimble/host/src/ble_ibeacon.c
@@ -61,7 +61,7 @@ ble_ibeacon_set_adv_data(void *uuid128, uint16_t major, uint16_t minor)
/** Last byte (tx power level) filled in after HCI exchange. */
- rc = ble_hci_util_read_adv_tx_pwr(&tx_pwr);
+ rc = ble_hs_hci_util_read_adv_tx_pwr(&tx_pwr);
if (rc != 0) {
return rc;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/net/nimble/host/src/ble_l2cap.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap.c b/net/nimble/host/src/ble_l2cap.c
index a25c364..66bad51 100644
--- a/net/nimble/host/src/ble_l2cap.c
+++ b/net/nimble/host/src/ble_l2cap.c
@@ -22,7 +22,6 @@
#include "os/os.h"
#include "nimble/ble.h"
#include "nimble/hci_common.h"
-#include "host/host_hci.h"
#include "ble_hs_priv.h"
_Static_assert(sizeof (struct ble_l2cap_hdr) == BLE_L2CAP_HDR_SZ,
@@ -287,7 +286,7 @@ ble_l2cap_tx(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan,
return BLE_HS_ENOMEM;
}
- rc = host_hci_data_tx(conn, txom);
+ rc = ble_hs_hci_acl_tx(conn, txom);
if (rc != 0) {
return rc;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/net/nimble/host/src/ble_sm.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm.c b/net/nimble/host/src/ble_sm.c
index ae2e5f8..f2a7b5c 100644
--- a/net/nimble/host/src/ble_sm.c
+++ b/net/nimble/host/src/ble_sm.c
@@ -259,7 +259,7 @@ ble_sm_gen_pair_rand(uint8_t *pair_rand)
}
#endif
- rc = ble_hci_util_rand(pair_rand, 16);
+ rc = ble_hs_hci_util_rand(pair_rand, 16);
if (rc != 0) {
return rc;
}
@@ -280,7 +280,7 @@ ble_sm_gen_ediv(uint16_t *ediv)
}
#endif
- rc = ble_hci_util_rand(ediv, sizeof *ediv);
+ rc = ble_hs_hci_util_rand(ediv, sizeof *ediv);
if (rc != 0) {
return rc;
}
@@ -301,7 +301,7 @@ ble_sm_gen_master_id_rand(uint64_t *master_id_rand)
}
#endif
- rc = ble_hci_util_rand(master_id_rand, sizeof *master_id_rand);
+ rc = ble_hs_hci_util_rand(master_id_rand, sizeof *master_id_rand);
if (rc != 0) {
return rc;
}
@@ -323,7 +323,7 @@ ble_sm_gen_ltk(struct ble_sm_proc *proc, uint8_t *ltk)
}
#endif
- rc = ble_hci_util_rand(ltk, 16);
+ rc = ble_hs_hci_util_rand(ltk, 16);
if (rc != 0) {
return rc;
}
@@ -345,7 +345,7 @@ ble_sm_gen_csrk(struct ble_sm_proc *proc, uint8_t *csrk)
}
#endif
- rc = ble_hci_util_rand(csrk, 16);
+ rc = ble_hs_hci_util_rand(csrk, 16);
if (rc != 0) {
return rc;
}
@@ -875,8 +875,8 @@ ble_sm_start_encrypt_tx(struct hci_start_encrypt *cmd)
uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_LE_START_ENCRYPT_LEN];
int rc;
- host_hci_cmd_build_le_start_encrypt(cmd, buf, sizeof buf);
- rc = ble_hci_cmd_tx_empty_ack(buf);
+ ble_hs_hci_cmd_build_le_start_encrypt(cmd, buf, sizeof buf);
+ rc = ble_hs_hci_cmd_tx_empty_ack(buf);
if (rc != 0) {
return rc;
}
@@ -1059,9 +1059,9 @@ ble_sm_ltk_req_reply_tx(uint16_t conn_handle, uint8_t *ltk)
cmd.conn_handle = conn_handle;
memcpy(cmd.long_term_key, ltk, 16);
- host_hci_cmd_build_le_lt_key_req_reply(&cmd, buf, sizeof buf);
- rc = ble_hci_cmd_tx(buf, &ack_conn_handle, sizeof ack_conn_handle,
- &ack_params_len);
+ ble_hs_hci_cmd_build_le_lt_key_req_reply(&cmd, buf, sizeof buf);
+ rc = ble_hs_hci_cmd_tx(buf, &ack_conn_handle, sizeof ack_conn_handle,
+ &ack_params_len);
if (rc != 0) {
return rc;
}
@@ -1085,9 +1085,9 @@ ble_sm_ltk_req_neg_reply_tx(uint16_t conn_handle)
uint8_t ack_params_len;
int rc;
- host_hci_cmd_build_le_lt_key_req_neg_reply(conn_handle, buf, sizeof buf);
- rc = ble_hci_cmd_tx(buf, &ack_conn_handle, sizeof ack_conn_handle,
- &ack_params_len);
+ ble_hs_hci_cmd_build_le_lt_key_req_neg_reply(conn_handle, buf, sizeof buf);
+ rc = ble_hs_hci_cmd_tx(buf, &ack_conn_handle, sizeof ack_conn_handle,
+ &ack_params_len);
if (rc != 0) {
return rc;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/net/nimble/host/src/ble_sm_alg.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm_alg.c b/net/nimble/host/src/ble_sm_alg.c
index 3aac60d..a2b0fcf 100644
--- a/net/nimble/host/src/ble_sm_alg.c
+++ b/net/nimble/host/src/ble_sm_alg.c
@@ -410,7 +410,8 @@ ble_sm_alg_f6(const uint8_t *w, const uint8_t *n1, const uint8_t *n2,
}
int
-ble_sm_alg_g2(uint8_t *u, uint8_t *v, uint8_t *x, uint8_t *y, uint32_t *passkey)
+ble_sm_alg_g2(uint8_t *u, uint8_t *v, uint8_t *x, uint8_t *y,
+ uint32_t *passkey)
{
uint8_t m[80], xs[16];
int rc;
@@ -476,7 +477,7 @@ ble_sm_alg_gen_key_pair(void *pub, uint32_t *priv)
int rc;
do {
- rc = ble_hci_util_rand(random, sizeof random);
+ rc = ble_hs_hci_util_rand(random, sizeof random);
if (rc != 0) {
return rc;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/net/nimble/host/src/ble_sm_sc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm_sc.c b/net/nimble/host/src/ble_sm_sc.c
index 455da90..539d0f9 100644
--- a/net/nimble/host/src/ble_sm_sc.c
+++ b/net/nimble/host/src/ble_sm_sc.c
@@ -221,7 +221,7 @@ ble_sm_sc_gen_ri(struct ble_sm_proc *proc)
return 0;
case BLE_SM_PAIR_ALG_OOB:
- rc = ble_hci_util_rand(&proc->ri, 1);
+ rc = ble_hs_hci_util_rand(&proc->ri, 1);
return rc;
default:
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/net/nimble/host/src/host_dbg.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/host_dbg.c b/net/nimble/host/src/host_dbg.c
deleted file mode 100644
index f5d46a3..0000000
--- a/net/nimble/host/src/host_dbg.c
+++ /dev/null
@@ -1,503 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-#include <stdint.h>
-#include <stdio.h>
-#include <assert.h>
-#include <string.h>
-#include "os/os.h"
-#include "console/console.h"
-#include "nimble/hci_common.h"
-#include "nimble/ble_hci_trans.h"
-#include "ble_hs_priv.h"
-
-static void
-host_hci_dbg_le_event_disp(uint8_t subev, uint8_t len, uint8_t *evdata)
-{
- int8_t rssi;
- uint8_t advlen;
- uint8_t status;
- int i;
- int imax;
- uint8_t *dptr;
- char *adv_ptr;
- char adv_data_buf[32];
-
- switch (subev) {
- case BLE_HCI_LE_SUBEV_ENH_CONN_COMPLETE:
- case BLE_HCI_LE_SUBEV_CONN_COMPLETE:
- status = evdata[0];
- if (status == BLE_ERR_SUCCESS) {
- BLE_HS_LOG(DEBUG, "LE connection complete. handle=%u role=%u "
- "paddrtype=%u addr=%x.%x.%x.%x.%x.%x ",
- le16toh(evdata + 1), evdata[3], evdata[4],
- evdata[10], evdata[9], evdata[8], evdata[7],
- evdata[6], evdata[5]);
-
- evdata += 11;
- if (subev == BLE_HCI_LE_SUBEV_ENH_CONN_COMPLETE) {
- BLE_HS_LOG(DEBUG, "local_rpa=%x.%x.%x.%x.%x.%x "
- "peer_rpa=%x.%x.%x.%x.%x.%x ",
- evdata[5], evdata[4], evdata[3], evdata[2],
- evdata[1], evdata[0],
- evdata[11], evdata[10], evdata[9], evdata[8],
- evdata[7], evdata[6]);
-
- evdata += 12;
- }
- BLE_HS_LOG(DEBUG, "itvl=%u latency=%u spvn_tmo=%u mca=%u\n",
- le16toh(evdata), le16toh(evdata + 2),
- le16toh(evdata + 4), evdata[6]);
- } else {
- BLE_HS_LOG(DEBUG, "LE connection complete. FAIL (status=%u)\n",
- status);
- }
- break;
- case BLE_HCI_LE_SUBEV_ADV_RPT:
- advlen = evdata[9];
- rssi = evdata[10 + advlen];
- BLE_HS_LOG(DEBUG, "LE advertising report. len=%u num=%u evtype=%u "
- "addrtype=%u addr=%x.%x.%x.%x.%x.%x advlen=%u "
- "rssi=%d\n", len, evdata[0], evdata[1], evdata[2],
- evdata[8], evdata[7], evdata[6], evdata[5],
- evdata[4], evdata[3], advlen, rssi);
- if (advlen) {
- dptr = &evdata[10];
- while (advlen > 0) {
- memset(adv_data_buf, 0, 32);
- imax = advlen;
- if (imax > 8) {
- imax = 8;
- }
- adv_ptr = &adv_data_buf[0];
- for (i = 0; i < imax; ++i) {
- snprintf(adv_ptr, 4, "%02x ", *dptr);
- adv_ptr += 3;
- ++dptr;
- }
- advlen -= imax;
- BLE_HS_LOG(DEBUG, "%s\n", adv_data_buf);
- }
- }
- break;
- case BLE_HCI_LE_SUBEV_CONN_UPD_COMPLETE:
- status = evdata[0];
- if (status == BLE_ERR_SUCCESS) {
- BLE_HS_LOG(DEBUG, "LE Connection Update Complete. handle=%u "
- "itvl=%u latency=%u timeout=%u\n",
- le16toh(evdata + 1), le16toh(evdata + 3),
- le16toh(evdata + 5), le16toh(evdata + 7));
- } else {
- BLE_HS_LOG(DEBUG, "LE Connection Update Complete. FAIL "
- "(status=%u)\n", status);
- }
- break;
-
- case BLE_HCI_LE_SUBEV_DATA_LEN_CHG:
- BLE_HS_LOG(DEBUG, "LE Data Length Change. handle=%u max_tx_bytes=%u "
- "max_tx_time=%u max_rx_bytes=%u max_rx_time=%u\n",
- le16toh(evdata), le16toh(evdata + 2),
- le16toh(evdata + 4), le16toh(evdata + 6),
- le16toh(evdata + 8));
- break;
- case BLE_HCI_LE_SUBEV_REM_CONN_PARM_REQ:
- BLE_HS_LOG(DEBUG, "LE Remote Connection Parameter Request. handle=%u "
- "min_itvl=%u max_itvl=%u latency=%u timeout=%u\n",
- le16toh(evdata), le16toh(evdata + 2),
- le16toh(evdata + 4), le16toh(evdata + 6),
- le16toh(evdata + 8));
- break;
-
- case BLE_HCI_LE_SUBEV_RD_REM_USED_FEAT:
- status = evdata[0];
- if (status == BLE_ERR_SUCCESS) {
- BLE_HS_LOG(DEBUG, "LE Remote Used Features. handle=%u feat=",
- le16toh(evdata + 1));
- for (i = 0; i < BLE_HCI_RD_LOC_SUPP_FEAT_RSPLEN; ++i) {
- BLE_HS_LOG(DEBUG, "%02x ", evdata[3 + i]);
- }
- BLE_HS_LOG(DEBUG, "\n");
- } else {
- BLE_HS_LOG(DEBUG, "LE Remote Used Features. FAIL (status=%u)\n",
- status);
- }
- break;
-
- case BLE_HCI_LE_SUBEV_LT_KEY_REQ:
- BLE_HS_LOG(DEBUG, "LE LTK Req. handle=%u rand=%lx%lx encdiv=%u\n",
- le16toh(evdata), le32toh(evdata + 6),
- le32toh(evdata + 2), le16toh(evdata + 10));
- break;
-
- default:
- BLE_HS_LOG(DEBUG, "\tUnknown LE event\n");
- break;
- }
-}
-
-/**
- * Display a disconnection complete command.
- *
- *
- * @param evdata
- * @param len
- */
-static void
-host_hci_dbg_disconn_comp_disp(uint8_t *evdata, uint8_t len)
-{
- uint8_t status;
- uint8_t reason;
- uint16_t handle;
-
- status = evdata[0];
- handle = le16toh(evdata + 1);
- /* Ignore reason if status is not success */
- if (status != BLE_ERR_SUCCESS) {
- reason = 0;
- } else {
- reason = evdata[3];
- }
- BLE_HS_LOG(DEBUG, "Disconnection Complete: status=%u handle=%u "
- "reason=%u\n", status, handle, reason);
-}
-
-/**
- * Display an encryption change event or encryption key refresh event
- *
- * @param evdata
- * @param len
- */
-static void
-host_hci_dbg_encrypt_chg_disp(uint8_t *evdata, uint8_t len)
-{
- uint8_t status;
- uint8_t enabled;
- uint16_t handle;
-
- status = evdata[0];
- handle = le16toh(evdata + 1);
-
- /* Ignore reason if status is not success */
- if (status != BLE_ERR_SUCCESS) {
- enabled = 0;
- } else {
- enabled = evdata[3];
- }
- BLE_HS_LOG(DEBUG, "Encrypt change: status=%u handle=%u state=%u\n",
- status, handle, enabled);
-}
-
-/**
- * Display an encryption encryption key refresh event
- *
- * @param evdata
- * @param len
- */
-static void
-host_hci_dbg_encrypt_refresh_disp(uint8_t *evdata, uint8_t len)
-{
- uint8_t status;
- uint16_t handle;
-
- status = evdata[0];
- handle = le16toh(evdata + 1);
-
- BLE_HS_LOG(DEBUG, "Encrypt key refresh: status=%u handle=%u\n",
- status, handle);
-}
-
-/**
- * Display a version information event
- *
- * @param evdata
- * @param len
- */
-static void
-host_hci_dbg_rd_rem_ver_disp(uint8_t *evdata, uint8_t len)
-{
- BLE_HS_LOG(DEBUG, "Remote Version Info: status=%u handle=%u vers_nr=%u "
- "compid=%u subver=%u\n",
- evdata[0], le16toh(evdata + 1), evdata[3],
- le16toh(evdata + 4), le16toh(evdata + 6));
-}
-
-/**
- * Display the number of completed packets event
- *
- * @param evdata
- * @param len
- */
-static void
-host_hci_dbg_num_comp_pkts_disp(uint8_t *evdata, uint8_t len)
-{
- uint8_t handles;
- uint8_t *handle_ptr;
- uint8_t *pkt_ptr;
- uint16_t handle;
- uint16_t pkts;
-
- handles = evdata[0];
- if (len != ((handles * 4) + 1)) {
- BLE_HS_LOG(DEBUG, "ERR: Number of Completed Packets bad length: "
- "num_handles=%u len=%u\n", handles, len);
- return;
-
- }
-
- BLE_HS_LOG(DEBUG, "Number of Completed Packets: num_handles=%u\n",
- handles);
- if (handles) {
- handle_ptr = evdata + 1;
- pkt_ptr = handle_ptr + (2 * handles);
- while (handles) {
- handle = le16toh(handle_ptr);
- handle_ptr += 2;
- pkts = le16toh(pkt_ptr);
- pkt_ptr += 2;
- BLE_HS_LOG(DEBUG, "handle:%u pkts:%u\n", handle, pkts);
- --handles;
- }
- }
-}
-
-/**
- * Display the authenticated payload timeout event
- *
- * @param evdata
- * @param len
- */
-static void
-host_hci_dbg_auth_pyld_tmo_disp(uint8_t *evdata, uint8_t len)
-{
- uint16_t handle;
-
- if (len != sizeof(uint16_t)) {
- BLE_HS_LOG(DEBUG, "ERR: AuthPyldTmoEvent bad length %u\n", len);
- return;
-
- }
-
- handle = le16toh(evdata);
- BLE_HS_LOG(DEBUG, "AuthPyldTmo: handle=%u\n", handle);
-}
-
-
-static void
-host_hci_dbg_cmd_comp_info_params(uint8_t status, uint8_t ocf, uint8_t *evdata)
-{
- int i;
- uint8_t *dptr;
-
- if (status != BLE_ERR_SUCCESS) {
- return;
- }
-
- switch (ocf) {
- case BLE_HCI_OCF_IP_RD_LOCAL_VER:
- BLE_HS_LOG(DEBUG, "hci_ver=%u hci_rev=%u lmp_ver=%u mfrg=%u "
- "lmp_subver=%u",
- evdata[0], le16toh(evdata + 1), evdata[3],
- le16toh(evdata + 4), le16toh(evdata + 6));
- break;
- case BLE_HCI_OCF_IP_RD_LOC_SUPP_CMD:
- BLE_HS_LOG(DEBUG, "supp_cmds=");
- dptr = evdata;
- for (i = 0; i < 8; ++i) {
- BLE_HS_LOG(DEBUG, "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:",
- dptr[0], dptr[1], dptr[2], dptr[3],
- dptr[4], dptr[5], dptr[6], dptr[7]);
- dptr += 8;
- }
- break;
- case BLE_HCI_OCF_IP_RD_LOC_SUPP_FEAT:
- BLE_HS_LOG(DEBUG, "supp_feat=0x%lx%08lx",
- le32toh(evdata + 4), le32toh(evdata));
- break;
- case BLE_HCI_OCF_IP_RD_BD_ADDR:
- BLE_HS_LOG(DEBUG, "bd_addr=%x:%x:%x:%x:%x:%x",
- evdata[5], evdata[4], evdata[3],
- evdata[2], evdata[1], evdata[0]);
- break;
- default:
- break;
- }
-}
-
-static void
-host_hci_dbg_cmd_complete_disp(uint8_t *evdata, uint8_t len)
-{
- uint8_t cmd_pkts;
- uint8_t ogf;
- uint8_t ocf;
- uint8_t status;
- uint16_t opcode;
-
- if (len < 3) {
- BLE_HS_LOG(DEBUG, "Invalid command complete: len=%d "
- "(expected >= 3)", len);
- goto done;
- }
-
- cmd_pkts = evdata[0];
- opcode = le16toh(evdata + 1);
- ogf = BLE_HCI_OGF(opcode);
- ocf = BLE_HCI_OCF(opcode);
-
- BLE_HS_LOG(DEBUG, "Command complete: cmd_pkts=%u ogf=0x%x ocf=0x%x",
- cmd_pkts, ogf, ocf);
-
- if (len == 3) {
- goto done;
- }
-
- status = evdata[3];
- BLE_HS_LOG(DEBUG, " status=%u ", status);
-
- /* Move past header and status */
- evdata += 4;
-
- /* Display parameters based on command. */
- switch (ogf) {
- case BLE_HCI_OGF_INFO_PARAMS:
- host_hci_dbg_cmd_comp_info_params(status, ocf, evdata);
- break;
- case BLE_HCI_OGF_STATUS_PARAMS:
- switch (ocf) {
- case BLE_HCI_OCF_RD_RSSI:
- BLE_HS_LOG(DEBUG, "handle=%u rssi=%d", le16toh(evdata),
- (int8_t)evdata[2]);
- break;
- default:
- break;
- }
- break;
- case BLE_HCI_OGF_LE:
- switch (ocf) {
- case BLE_HCI_OCF_LE_RD_CHAN_MAP:
- BLE_HS_LOG(DEBUG, "handle=%u chanmap=%x.%x.%x.%x.%x",
- le16toh(evdata), evdata[2], evdata[3], evdata[4],
- evdata[5], evdata[6]);
- break;
- case BLE_HCI_OCF_LE_RD_MAX_DATA_LEN:
- BLE_HS_LOG(DEBUG, "txoct=%u txtime=%u rxoct=%u rxtime=%u",
- le16toh(evdata), le16toh(evdata + 2),
- le16toh(evdata + 4), le16toh(evdata + 6));
- break;
- case BLE_HCI_OCF_LE_RD_SUPP_STATES:
- BLE_HS_LOG(DEBUG, "states=0x%lx%08lx", le32toh(evdata + 4),
- le32toh(evdata));
- break;
- case BLE_HCI_OCF_LE_ENCRYPT:
- BLE_HS_LOG(DEBUG, "encdata=0x%02x%02x%02x%02x%02x%02x%02x%02x",
- evdata[15], evdata[14], evdata[13], evdata[12],
- evdata[11], evdata[10], evdata[9], evdata[8]);
- BLE_HS_LOG(DEBUG, "%02x%02x%02x%02x%02x%02x%02x%02x",
- evdata[7], evdata[6], evdata[5], evdata[4],
- evdata[3], evdata[2], evdata[1], evdata[0]);
-
- break;
- case BLE_HCI_OCF_LE_RAND:
- BLE_HS_LOG(DEBUG, "rand=0x%02x%02x%02x%02x%02x%02x%02x%02x",
- evdata[0], evdata[1], evdata[2], evdata[3],
- evdata[4], evdata[5], evdata[6], evdata[7]);
- break;
- case BLE_HCI_OCF_LE_RD_SUGG_DEF_DATA_LEN:
- BLE_HS_LOG(DEBUG, "txoct=%u txtime=%u", le16toh(evdata),
- le16toh(evdata + 2));
- break;
- case BLE_HCI_OCF_LE_LT_KEY_REQ_REPLY:
- case BLE_HCI_OCF_LE_LT_KEY_REQ_NEG_REPLY:
- case BLE_HCI_OCF_LE_SET_DATA_LEN:
- BLE_HS_LOG(DEBUG, "handle=%u", le16toh(evdata));
- break;
- default:
- break;
- }
- break;
- default:
- break;
- }
-
-done:
- BLE_HS_LOG(DEBUG, "\n");
-}
-
-static void
-host_hci_dbg_cmd_status_disp(uint8_t *evdata, uint8_t len)
-{
- uint8_t ogf;
- uint8_t ocf;
- uint16_t opcode;
-
- opcode = le16toh(evdata + 2);
- ogf = BLE_HCI_OGF(opcode);
- ocf = BLE_HCI_OCF(opcode);
-
- BLE_HS_LOG(DEBUG, "Command Status: status=%u cmd_pkts=%u ocf=0x%x "
- "ogf=0x%x\n", evdata[0], evdata[1], ocf, ogf);
-}
-
-void
-host_hci_dbg_event_disp(uint8_t *evbuf)
-{
-#if LOG_LEVEL > LOG_LEVEL_DEBUG
- return;
-#endif
-
- uint8_t *evdata;
- uint8_t evcode;
- uint8_t len;
-
- /* Extract event code and length; move pointer to event parameter data */
- evcode = evbuf[0];
- len = evbuf[1];
- evdata = evbuf + BLE_HCI_EVENT_HDR_LEN;
-
- switch (evcode) {
- case BLE_HCI_EVCODE_DISCONN_CMP:
- host_hci_dbg_disconn_comp_disp(evdata, len);
- break;
- case BLE_HCI_EVCODE_ENC_KEY_REFRESH:
- host_hci_dbg_encrypt_refresh_disp(evdata, len);
- break;
- case BLE_HCI_EVCODE_ENCRYPT_CHG:
- host_hci_dbg_encrypt_chg_disp(evdata, len);
- break;
- case BLE_HCI_EVCODE_RD_REM_VER_INFO_CMP:
- host_hci_dbg_rd_rem_ver_disp(evdata, len);
- break;
- case BLE_HCI_EVCODE_COMMAND_COMPLETE:
- host_hci_dbg_cmd_complete_disp(evdata, len);
- break;
- case BLE_HCI_EVCODE_COMMAND_STATUS:
- host_hci_dbg_cmd_status_disp(evdata, len);
- break;
- case BLE_HCI_EVCODE_NUM_COMP_PKTS:
- host_hci_dbg_num_comp_pkts_disp(evdata, len);
- break;
- case BLE_HCI_EVCODE_LE_META:
- host_hci_dbg_le_event_disp(evdata[0], len, evdata + 1);
- break;
- case BLE_HCI_EVCODE_AUTH_PYLD_TMO:
- host_hci_dbg_auth_pyld_tmo_disp(evdata, len);
- break;
- default:
- BLE_HS_LOG(DEBUG, "Unknown event 0x%x len=%u\n", evcode, len);
- break;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/net/nimble/host/src/host_dbg_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/host_dbg_priv.h b/net/nimble/host/src/host_dbg_priv.h
deleted file mode 100644
index 8d548ca..0000000
--- a/net/nimble/host/src/host_dbg_priv.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-#ifndef H_HOST_DBG_
-#define H_HOST_DBG_
-
-void host_hci_dbg_event_disp(uint8_t *evbuf);
-
-#endif /* H_HOST_DBG_ */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/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
deleted file mode 100644
index b9bdaf9..0000000
--- a/net/nimble/host/src/host_hci.c
+++ /dev/null
@@ -1,899 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-#include <stdint.h>
-#include <string.h>
-#include <errno.h>
-#include <stdio.h>
-#include "os/os.h"
-#include "console/console.h"
-#include "nimble/hci_common.h"
-#include "nimble/ble_hci_trans.h"
-#include "host/host_hci.h"
-#include "host/ble_gap.h"
-#include "ble_hs_priv.h"
-#include "host_dbg_priv.h"
-
-_Static_assert(sizeof (struct hci_data_hdr) == BLE_HCI_DATA_HDR_SZ,
- "struct hci_data_hdr must be 4 bytes");
-
-typedef int host_hci_event_fn(uint8_t event_code, uint8_t *data, int len);
-static host_hci_event_fn host_hci_rx_disconn_complete;
-static host_hci_event_fn host_hci_rx_encrypt_change;
-static host_hci_event_fn host_hci_rx_hw_error;
-static host_hci_event_fn host_hci_rx_num_completed_pkts;
-static host_hci_event_fn host_hci_rx_enc_key_refresh;
-static host_hci_event_fn host_hci_rx_le_meta;
-
-typedef int host_hci_le_event_fn(uint8_t subevent, uint8_t *data, int len);
-static host_hci_le_event_fn host_hci_rx_le_conn_complete;
-static host_hci_le_event_fn host_hci_rx_le_adv_rpt;
-static host_hci_le_event_fn host_hci_rx_le_conn_upd_complete;
-static host_hci_le_event_fn host_hci_rx_le_lt_key_req;
-static host_hci_le_event_fn host_hci_rx_le_conn_parm_req;
-static host_hci_le_event_fn host_hci_rx_le_dir_adv_rpt;
-
-static uint16_t host_hci_buffer_sz;
-static uint8_t host_hci_max_pkts;
-
-/* Statistics */
-struct host_hci_stats
-{
- uint32_t events_rxd;
- uint32_t good_acks_rxd;
- uint32_t bad_acks_rxd;
- uint32_t unknown_events_rxd;
-};
-
-#define HOST_HCI_TIMEOUT 50 /* Milliseconds. */
-
-/** Dispatch table for incoming HCI events. Sorted by event code field. */
-struct host_hci_event_dispatch_entry {
- uint8_t hed_event_code;
- host_hci_event_fn *hed_fn;
-};
-
-static const struct host_hci_event_dispatch_entry host_hci_event_dispatch[] = {
- { BLE_HCI_EVCODE_DISCONN_CMP, host_hci_rx_disconn_complete },
- { BLE_HCI_EVCODE_ENCRYPT_CHG, host_hci_rx_encrypt_change },
- { BLE_HCI_EVCODE_HW_ERROR, host_hci_rx_hw_error },
- { BLE_HCI_EVCODE_NUM_COMP_PKTS, host_hci_rx_num_completed_pkts },
- { BLE_HCI_EVCODE_ENC_KEY_REFRESH, host_hci_rx_enc_key_refresh },
- { BLE_HCI_EVCODE_LE_META, host_hci_rx_le_meta },
-};
-
-#define HOST_HCI_EVENT_DISPATCH_SZ \
- (sizeof host_hci_event_dispatch / sizeof host_hci_event_dispatch[0])
-
-/** Dispatch table for incoming LE meta events. Sorted by subevent field. */
-struct host_hci_le_event_dispatch_entry {
- uint8_t hmd_subevent;
- host_hci_le_event_fn *hmd_fn;
-};
-
-static const struct host_hci_le_event_dispatch_entry
- host_hci_le_event_dispatch[] = {
- { BLE_HCI_LE_SUBEV_CONN_COMPLETE, host_hci_rx_le_conn_complete },
- { BLE_HCI_LE_SUBEV_ADV_RPT, host_hci_rx_le_adv_rpt },
- { BLE_HCI_LE_SUBEV_CONN_UPD_COMPLETE, host_hci_rx_le_conn_upd_complete },
- { BLE_HCI_LE_SUBEV_LT_KEY_REQ, host_hci_rx_le_lt_key_req },
- { BLE_HCI_LE_SUBEV_REM_CONN_PARM_REQ, host_hci_rx_le_conn_parm_req },
- { BLE_HCI_LE_SUBEV_ENH_CONN_COMPLETE, host_hci_rx_le_conn_complete },
- { BLE_HCI_LE_SUBEV_DIRECT_ADV_RPT, host_hci_rx_le_dir_adv_rpt },
-};
-
-#define HOST_HCI_LE_EVENT_DISPATCH_SZ \
- (sizeof host_hci_le_event_dispatch / sizeof host_hci_le_event_dispatch[0])
-
-uint16_t
-host_hci_opcode_join(uint8_t ogf, uint16_t ocf)
-{
- return (ogf << 10) | ocf;
-}
-
-uint16_t
-host_hci_handle_pb_bc_join(uint16_t handle, uint8_t pb, uint8_t bc)
-{
- BLE_HS_DBG_ASSERT(handle <= 0x0fff);
- BLE_HS_DBG_ASSERT(pb <= 0x03);
- BLE_HS_DBG_ASSERT(bc <= 0x03);
-
- return (handle << 0) |
- (pb << 12) |
- (bc << 14);
-}
-
-static const struct host_hci_event_dispatch_entry *
-host_hci_dispatch_entry_find(uint8_t event_code)
-{
- const struct host_hci_event_dispatch_entry *entry;
- int i;
-
- for (i = 0; i < HOST_HCI_EVENT_DISPATCH_SZ; i++) {
- entry = host_hci_event_dispatch + i;
- if (entry->hed_event_code == event_code) {
- return entry;
- }
- }
-
- return NULL;
-}
-
-static const struct host_hci_le_event_dispatch_entry *
-host_hci_le_dispatch_entry_find(uint8_t event_code)
-{
- const struct host_hci_le_event_dispatch_entry *entry;
- int i;
-
- for (i = 0; i < HOST_HCI_LE_EVENT_DISPATCH_SZ; i++) {
- entry = host_hci_le_event_dispatch + i;
- if (entry->hmd_subevent == event_code) {
- return entry;
- }
- }
-
- return NULL;
-}
-
-static int
-host_hci_rx_disconn_complete(uint8_t event_code, uint8_t *data, int len)
-{
- struct hci_disconn_complete evt;
-
- if (len < BLE_HCI_EVENT_DISCONN_COMPLETE_LEN) {
- return BLE_HS_ECONTROLLER;
- }
-
- evt.status = data[2];
- evt.connection_handle = le16toh(data + 3);
- evt.reason = data[5];
-
- ble_gap_rx_disconn_complete(&evt);
-
- return 0;
-}
-
-static int
-host_hci_rx_encrypt_change(uint8_t event_code, uint8_t *data, int len)
-{
- struct hci_encrypt_change evt;
-
- if (len < BLE_HCI_EVENT_ENCRYPT_CHG_LEN) {
- return BLE_HS_ECONTROLLER;
- }
-
- evt.status = data[2];
- evt.connection_handle = le16toh(data + 3);
- evt.encryption_enabled = data[5];
-
- ble_sm_enc_change_rx(&evt);
-
- return 0;
-}
-
-static int
-host_hci_rx_hw_error(uint8_t event_code, uint8_t *data, int len)
-{
- uint8_t hw_code;
-
- if (len < BLE_HCI_EVENT_HW_ERROR_LEN) {
- return BLE_HS_ECONTROLLER;
- }
-
- hw_code = data[0];
- ble_hs_hw_error(hw_code);
-
- return 0;
-}
-
-static int
-host_hci_rx_enc_key_refresh(uint8_t event_code, uint8_t *data, int len)
-{
- struct hci_encrypt_key_refresh evt;
-
- if (len < BLE_HCI_EVENT_ENC_KEY_REFRESH_LEN) {
- return BLE_HS_ECONTROLLER;
- }
-
- evt.status = data[2];
- evt.connection_handle = le16toh(data + 3);
-
- ble_sm_enc_key_refresh_rx(&evt);
-
- return 0;
-}
-
-static int
-host_hci_rx_num_completed_pkts(uint8_t event_code, uint8_t *data, int len)
-{
- uint16_t num_pkts;
- uint16_t handle;
- uint8_t num_handles;
- int off;
- int i;
-
- if (len < BLE_HCI_EVENT_HDR_LEN + BLE_HCI_EVENT_NUM_COMP_PKTS_HDR_LEN) {
- return BLE_HS_ECONTROLLER;
- }
-
- off = BLE_HCI_EVENT_HDR_LEN;
- num_handles = data[off];
- if (len < BLE_HCI_EVENT_NUM_COMP_PKTS_HDR_LEN +
- num_handles * BLE_HCI_EVENT_NUM_COMP_PKTS_ENT_LEN) {
- return BLE_HS_ECONTROLLER;
- }
- off++;
-
- for (i = 0; i < num_handles; i++) {
- handle = le16toh(data + off + 2 * i);
- num_pkts = le16toh(data + off + 2 * num_handles + 2 * i);
-
- /* XXX: Do something with these values. */
- (void)handle;
- (void)num_pkts;
- }
-
- return 0;
-}
-
-static int
-host_hci_rx_le_meta(uint8_t event_code, uint8_t *data, int len)
-{
- const struct host_hci_le_event_dispatch_entry *entry;
- uint8_t subevent;
- int rc;
-
- if (len < BLE_HCI_EVENT_HDR_LEN + BLE_HCI_LE_MIN_LEN) {
- /* XXX: Increment stat. */
- return BLE_HS_ECONTROLLER;
- }
-
- subevent = data[2];
- entry = host_hci_le_dispatch_entry_find(subevent);
- if (entry != NULL) {
- rc = entry->hmd_fn(subevent, data + BLE_HCI_EVENT_HDR_LEN,
- len - BLE_HCI_EVENT_HDR_LEN);
- if (rc != 0) {
- return rc;
- }
- }
-
- return 0;
-}
-
-static int
-host_hci_rx_le_conn_complete(uint8_t subevent, uint8_t *data, int len)
-{
- struct hci_le_conn_complete evt;
- int extended_offset = 0;
- int rc;
-
- if (len < BLE_HCI_LE_CONN_COMPLETE_LEN) {
- return BLE_HS_ECONTROLLER;
- }
-
- /* this code processes two different events that are really similar */
- if ((subevent == BLE_HCI_LE_SUBEV_ENH_CONN_COMPLETE) &&
- ( len < BLE_HCI_LE_ENH_CONN_COMPLETE_LEN)) {
- return BLE_HS_ECONTROLLER;
- }
-
- evt.subevent_code = data[0];
- evt.status = data[1];
- evt.connection_handle = le16toh(data + 2);
- evt.role = data[4];
- evt.peer_addr_type = data[5];
- memcpy(evt.peer_addr, data + 6, BLE_DEV_ADDR_LEN);
-
- /* enhanced connection event has the same information with these
- * extra fields stuffed into the middle */
- if (subevent == BLE_HCI_LE_SUBEV_ENH_CONN_COMPLETE) {
- memcpy(evt.local_rpa, data + 12, BLE_DEV_ADDR_LEN);
- memcpy(evt.peer_rpa, data + 18, BLE_DEV_ADDR_LEN);
- extended_offset = 12;
- } else {
- memset(evt.local_rpa, 0, BLE_DEV_ADDR_LEN);
- memset(evt.peer_rpa, 0, BLE_DEV_ADDR_LEN);
- }
-
- evt.conn_itvl = le16toh(data + 12 + extended_offset);
- evt.conn_latency = le16toh(data + 14 + extended_offset);
- evt.supervision_timeout = le16toh(data + 16 + extended_offset);
- evt.master_clk_acc = data[18 + extended_offset];
-
- if (evt.status == 0) {
- if (evt.role != BLE_HCI_LE_CONN_COMPLETE_ROLE_MASTER &&
- evt.role != BLE_HCI_LE_CONN_COMPLETE_ROLE_SLAVE) {
-
- return BLE_HS_EBADDATA;
- }
- }
-
- rc = ble_gap_rx_conn_complete(&evt);
- if (rc != 0) {
- return rc;
- }
-
- return 0;
-}
-
-static int
-host_hci_le_adv_rpt_first_pass(uint8_t *data, int len,
- uint8_t *out_num_reports, int *out_rssi_off)
-{
- uint8_t num_reports;
- int data_len;
- int off;
- int i;
-
- if (len < BLE_HCI_LE_ADV_RPT_MIN_LEN) {
- return BLE_HS_ECONTROLLER;
- }
-
- num_reports = data[1];
- if (num_reports < BLE_HCI_LE_ADV_RPT_NUM_RPTS_MIN ||
- num_reports > BLE_HCI_LE_ADV_RPT_NUM_RPTS_MAX) {
-
- return BLE_HS_EBADDATA;
- }
-
- off = 2 + /* Subevent code and num reports. */
- (1 + /* Event type. */
- 1 + /* Address type. */
- 6 /* Address. */
- ) * num_reports;
- if (off + num_reports >= len) {
- return BLE_HS_ECONTROLLER;
- }
-
- data_len = 0;
- for (i = 0; i < num_reports; i++) {
- data_len += data[off];
- off++;
- }
-
- off += data_len;
-
- /* Check if RSSI fields fit in the packet. */
- if (off + num_reports > len) {
- return BLE_HS_ECONTROLLER;
- }
-
- *out_num_reports = num_reports;
- *out_rssi_off = off;
-
- return 0;
-}
-
-static int
-host_hci_rx_le_adv_rpt(uint8_t subevent, uint8_t *data, int len)
-{
- struct ble_gap_disc_desc desc;
- uint8_t num_reports;
- int rssi_off;
- int data_off;
- int suboff;
- int off;
- int rc;
- int i;
-
- rc = host_hci_le_adv_rpt_first_pass(data, len, &num_reports, &rssi_off);
- if (rc != 0) {
- return rc;
- }
-
- /* Direct address fields not present in a standard advertising report. */
- desc.direct_addr_type = BLE_GAP_ADDR_TYPE_NONE;
- memset(desc.direct_addr, 0, sizeof desc.direct_addr);
-
- data_off = 0;
- for (i = 0; i < num_reports; i++) {
- suboff = 0;
-
- off = 2 + suboff * num_reports + i;
- desc.event_type = data[off];
- suboff++;
-
- off = 2 + suboff * num_reports + i;
- desc.addr_type = data[off];
- suboff++;
-
- off = 2 + suboff * num_reports + i * 6;
- memcpy(desc.addr, data + off, 6);
- suboff += 6;
-
- off = 2 + suboff * num_reports + i;
- desc.length_data = data[off];
- suboff++;
-
- off = 2 + suboff * num_reports + data_off;
- desc.data = data + off;
- data_off += desc.length_data;
-
- off = rssi_off + 1 * i;
- desc.rssi = data[off];
-
- ble_gap_rx_adv_report(&desc);
- }
-
- return 0;
-}
-
-static int
-host_hci_rx_le_dir_adv_rpt(uint8_t subevent, uint8_t *data, int len)
-{
- struct ble_gap_disc_desc desc;
- uint8_t num_reports;
- int suboff;
- int off;
- int i;
-
- if (len < BLE_HCI_LE_ADV_DIRECT_RPT_LEN) {
- return BLE_HS_ECONTROLLER;
- }
-
- num_reports = data[1];
- if (len != 2 + num_reports * BLE_HCI_LE_ADV_DIRECT_RPT_SUB_LEN) {
- return BLE_HS_ECONTROLLER;
- }
-
- /* Data fields not present in a direct advertising report. */
- desc.data = NULL;
- desc.fields = NULL;
-
- for (i = 0; i < num_reports; i++) {
- suboff = 0;
-
- off = 2 + suboff * num_reports + i;
- desc.event_type = data[off];
- suboff++;
-
- off = 2 + suboff * num_reports + i;
- desc.addr_type = data[off];
- suboff++;
-
- off = 2 + suboff * num_reports + i * 6;
- memcpy(desc.addr, data + off, 6);
- suboff += 6;
-
- off = 2 + suboff * num_reports + i;
- desc.direct_addr_type = data[off];
- suboff++;
-
- off = 2 + suboff * num_reports + i * 6;
- memcpy(desc.direct_addr, data + off, 6);
- suboff += 6;
-
- off = 2 + suboff * num_reports + i;
- desc.rssi = data[off];
- suboff++;
-
- ble_gap_rx_adv_report(&desc);
- }
-
- return 0;
-}
-
-static int
-host_hci_rx_le_conn_upd_complete(uint8_t subevent, uint8_t *data, int len)
-{
- struct hci_le_conn_upd_complete evt;
-
- if (len < BLE_HCI_LE_CONN_UPD_LEN) {
- return BLE_HS_ECONTROLLER;
- }
-
- evt.subevent_code = data[0];
- evt.status = data[1];
- evt.connection_handle = le16toh(data + 2);
- evt.conn_itvl = le16toh(data + 4);
- evt.conn_latency = le16toh(data + 6);
- evt.supervision_timeout = le16toh(data + 8);
-
- if (evt.status == 0) {
- if (evt.conn_itvl < BLE_HCI_CONN_ITVL_MIN ||
- evt.conn_itvl > BLE_HCI_CONN_ITVL_MAX) {
-
- return BLE_HS_EBADDATA;
- }
- if (evt.conn_latency < BLE_HCI_CONN_LATENCY_MIN ||
- evt.conn_latency > BLE_HCI_CONN_LATENCY_MAX) {
-
- return BLE_HS_EBADDATA;
- }
- if (evt.supervision_timeout < BLE_HCI_CONN_SPVN_TIMEOUT_MIN ||
- evt.supervision_timeout > BLE_HCI_CONN_SPVN_TIMEOUT_MAX) {
-
- return BLE_HS_EBADDATA;
- }
- }
-
- ble_gap_rx_update_complete(&evt);
-
- return 0;
-}
-
-static int
-host_hci_rx_le_lt_key_req(uint8_t subevent, uint8_t *data, int len)
-{
- struct hci_le_lt_key_req evt;
-
- if (len < BLE_HCI_LE_LT_KEY_REQ_LEN) {
- return BLE_HS_ECONTROLLER;
- }
-
- evt.subevent_code = data[0];
- evt.connection_handle = le16toh(data + 1);
- evt.random_number = le64toh(data + 3);
- evt.encrypted_diversifier = le16toh(data + 11);
-
- ble_sm_ltk_req_rx(&evt);
-
- return 0;
-}
-
-static int
-host_hci_rx_le_conn_parm_req(uint8_t subevent, uint8_t *data, int len)
-{
- struct hci_le_conn_param_req evt;
-
- if (len < BLE_HCI_LE_REM_CONN_PARM_REQ_LEN) {
- return BLE_HS_ECONTROLLER;
- }
-
- evt.subevent_code = data[0];
- evt.connection_handle = le16toh(data + 1);
- evt.itvl_min = le16toh(data + 3);
- evt.itvl_max = le16toh(data + 5);
- evt.latency = le16toh(data + 7);
- evt.timeout = le16toh(data + 9);
-
- if (evt.itvl_min < BLE_HCI_CONN_ITVL_MIN ||
- evt.itvl_max > BLE_HCI_CONN_ITVL_MAX ||
- evt.itvl_min > evt.itvl_max) {
-
- return BLE_HS_EBADDATA;
- }
- if (evt.latency < BLE_HCI_CONN_LATENCY_MIN ||
- evt.latency > BLE_HCI_CONN_LATENCY_MAX) {
-
- return BLE_HS_EBADDATA;
- }
- if (evt.timeout < BLE_HCI_CONN_SPVN_TIMEOUT_MIN ||
- evt.timeout > BLE_HCI_CONN_SPVN_TIMEOUT_MAX) {
-
- return BLE_HS_EBADDATA;
- }
-
- ble_gap_rx_param_req(&evt);
-
- return 0;
-}
-
-int
-host_hci_set_buf_size(uint16_t pktlen, uint8_t max_pkts)
-{
- if (pktlen == 0 || max_pkts == 0) {
- return BLE_HS_EINVAL;
- }
-
- host_hci_buffer_sz = pktlen;
- host_hci_max_pkts = max_pkts;
-
- return 0;
-}
-
-int
-host_hci_evt_process(uint8_t *data)
-{
- const struct host_hci_event_dispatch_entry *entry;
- uint8_t event_code;
- uint8_t param_len;
- int event_len;
- int rc;
-
- /* Count events received */
- STATS_INC(ble_hs_stats, hci_event);
-
- /* Display to console */
- host_hci_dbg_event_disp(data);
-
- /* Process the event */
- event_code = data[0];
- param_len = data[1];
-
- event_len = param_len + 2;
-
- entry = host_hci_dispatch_entry_find(event_code);
- if (entry == NULL) {
- STATS_INC(ble_hs_stats, hci_unknown_event);
- rc = BLE_HS_ENOTSUP;
- } else {
- rc = entry->hed_fn(event_code, data, event_len);
- }
-
- ble_hci_trans_buf_free(data);
-
- return rc;
-}
-
-int
-host_hci_evt_rx(uint8_t *hci_ev, void *arg)
-{
- int enqueue;
-
- BLE_HS_DBG_ASSERT(hci_ev != NULL);
-
- switch (hci_ev[0]) {
- case BLE_HCI_EVCODE_COMMAND_COMPLETE:
- case BLE_HCI_EVCODE_COMMAND_STATUS:
- if (hci_ev[3] == 0 && hci_ev[4] == 0) {
- enqueue = 1;
- } else {
- ble_hci_cmd_rx_ack(hci_ev);
- enqueue = 0;
- }
- break;
-
- default:
- enqueue = 1;
- break;
- }
-
- if (enqueue) {
- ble_hs_enqueue_hci_event(hci_ev);
- }
-
- return 0;
-}
-
-/**
- * Called when a data packet is received from the controller. This function
- * consumes the supplied mbuf, regardless of the outcome.
- *
- * @param om The incoming data packet, beginning with the
- * HCI ACL data header.
- *
- * @return 0 on success; nonzero on failure.
- */
-int
-host_hci_acl_process(struct os_mbuf *om)
-{
- struct hci_data_hdr hci_hdr;
- struct ble_hs_conn *conn;
- ble_l2cap_rx_fn *rx_cb;
- struct os_mbuf *rx_buf;
- uint16_t handle;
- int rc;
-
- rc = ble_hci_util_data_hdr_strip(om, &hci_hdr);
- if (rc != 0) {
- goto err;
- }
-
-#if (BLETEST_THROUGHPUT_TEST == 0)
- BLE_HS_LOG(DEBUG, "host_hci_acl_process(): handle=%u pb=%x len=%u data=",
- BLE_HCI_DATA_HANDLE(hci_hdr.hdh_handle_pb_bc),
- BLE_HCI_DATA_PB(hci_hdr.hdh_handle_pb_bc),
- hci_hdr.hdh_len);
- ble_hs_log_mbuf(om);
- BLE_HS_LOG(DEBUG, "\n");
-#endif
-
- if (hci_hdr.hdh_len != OS_MBUF_PKTHDR(om)->omp_len) {
- rc = BLE_HS_EBADDATA;
- goto err;
- }
-
- handle = BLE_HCI_DATA_HANDLE(hci_hdr.hdh_handle_pb_bc);
-
- ble_hs_lock();
-
- conn = ble_hs_conn_find(handle);
- if (conn == NULL) {
- rc = BLE_HS_ENOTCONN;
- } else {
- rc = ble_l2cap_rx(conn, &hci_hdr, om, &rx_cb, &rx_buf);
- om = NULL;
- }
-
- ble_hs_unlock();
-
- switch (rc) {
- case 0:
- /* Final fragment received. */
- BLE_HS_DBG_ASSERT(rx_cb != NULL);
- BLE_HS_DBG_ASSERT(rx_buf != NULL);
- rc = rx_cb(handle, &rx_buf);
- os_mbuf_free_chain(rx_buf);
- break;
-
- case BLE_HS_EAGAIN:
- /* More fragments on the way. */
- break;
-
- default:
- goto err;
- }
-
- return 0;
-
-err:
- os_mbuf_free_chain(om);
- return rc;
-}
-
-static struct os_mbuf *
-host_hci_data_hdr_prepend(struct os_mbuf *om, uint16_t handle, uint8_t pb_flag)
-{
- struct hci_data_hdr hci_hdr;
- struct os_mbuf *om2;
-
- hci_hdr.hdh_handle_pb_bc = host_hci_handle_pb_bc_join(handle, pb_flag, 0);
- htole16(&hci_hdr.hdh_len, OS_MBUF_PKTHDR(om)->omp_len);
-
- om2 = os_mbuf_prepend(om, sizeof hci_hdr);
- if (om2 == NULL) {
- return NULL;
- }
-
- om = om2;
- om = os_mbuf_pullup(om, sizeof hci_hdr);
- if (om == NULL) {
- return NULL;
- }
-
- memcpy(om->om_data, &hci_hdr, sizeof hci_hdr);
-
- BLE_HS_LOG(DEBUG, "host tx hci data; handle=%d length=%d\n", handle,
- le16toh(&hci_hdr.hdh_len));
-
- return om;
-}
-
-/**
- * Splits an appropriately-sized fragment from the front of an outgoing ACL
- * data packet, if necessary. If the packet size is within the controller's
- * buffer size requirements, no splitting is performed. The fragment data is
- * removed from the data packet mbuf.
- *
- * @param om The ACL data packet.
- * @param out_frag On success, this points to the fragment to
- * send. If the entire packet can fit within
- * a single fragment, this will point to the
- * ACL data packet itself ('om').
- *
- * @return BLE_HS_EDONE: success; this is the final
- * fragment.
- * BLE_HS_EAGAIN: success; more data remains in
- * the original mbuf.
- * Other BLE host core return code on error.
- */
-int
-host_hci_split_frag(struct os_mbuf **om, struct os_mbuf **out_frag)
-{
- struct os_mbuf *frag;
- int rc;
-
- if (OS_MBUF_PKTLEN(*om) <= host_hci_buffer_sz) {
- /* Final fragment. */
- *out_frag = *om;
- *om = NULL;
- return BLE_HS_EDONE;
- }
-
- frag = ble_hs_mbuf_acm_pkt();
- if (frag == NULL) {
- rc = BLE_HS_ENOMEM;
- goto err;
- }
-
- /* Move data from the front of the packet into the fragment mbuf. */
- rc = os_mbuf_appendfrom(frag, *om, 0, host_hci_buffer_sz);
- if (rc != 0) {
- rc = BLE_HS_ENOMEM;
- goto err;
- }
- os_mbuf_adj(*om, host_hci_buffer_sz);
-
- /* More fragments to follow. */
- *out_frag = frag;
- return BLE_HS_EAGAIN;
-
-err:
- os_mbuf_free_chain(frag);
- return rc;
-}
-
-/**
- * Transmits an HCI ACL data packet. This function consumes the supplied mbuf,
- * regardless of the outcome.
- *
- * XXX: Ensure the controller has sufficient buffer capacity for the outgoing
- * fragments.
- */
-int
-host_hci_data_tx(struct ble_hs_conn *connection, struct os_mbuf *txom)
-{
- struct os_mbuf *frag;
- uint8_t pb;
- int done;
- int rc;
-
- /* The first fragment uses the first-non-flush packet boundary value.
- * After sending the first fragment, pb gets set appropriately for all
- * subsequent fragments in this packet.
- */
- pb = BLE_HCI_PB_FIRST_NON_FLUSH;
-
- /* Send fragments until the entire packet has been sent. */
- done = 0;
- while (!done) {
- rc = host_hci_split_frag(&txom, &frag);
- switch (rc) {
- case BLE_HS_EDONE:
- /* This is the final fragment. */
- done = 1;
- break;
-
- case BLE_HS_EAGAIN:
- /* More fragments to follow. */
- break;
-
- default:
- goto err;
- }
-
- frag = host_hci_data_hdr_prepend(frag, connection->bhc_handle, pb);
- if (frag == NULL) {
- rc = BLE_HS_ENOMEM;
- goto err;
- }
- pb = BLE_HCI_PB_MIDDLE;
-
- BLE_HS_LOG(DEBUG, "host_hci_data_tx(): ");
- ble_hs_log_mbuf(frag);
- BLE_HS_LOG(DEBUG, "\n");
-
- /* XXX: Try to pullup the entire fragment. The controller currently
- * requires the entire fragment to fit in a single buffer. When this
- * restriction is removed from the controller, this operation can be
- * removed.
- */
- frag = os_mbuf_pullup(frag, OS_MBUF_PKTLEN(frag));
- if (frag == NULL) {
- rc = BLE_HS_ENOMEM;
- goto err;
- }
-
- rc = ble_hs_tx_data(frag);
- if (rc != 0) {
- goto err;
- }
-
- connection->bhc_outstanding_pkts++;
- }
-
- return 0;
-
-err:
- BLE_HS_DBG_ASSERT(rc != 0);
-
- os_mbuf_free_chain(txom);
- return rc;
-}
[36/42] incubator-mynewt-core git commit: BLE Host - validate write
upon rx of prep write
Posted by st...@apache.org.
BLE Host - validate write upon rx of prep write
Before, upon receiving a prepare write request, the code was only
verifying that the specified attribute existed. There are a number of
checks that need to be performed in addition to that one:
1. Insufficient authorization.
2. Insufficient authentication.
3. Insufficient encryption key size.
4. Insufficient encryption (check if persisted bond exists for
unencrypted peer).
5. Invalid handle.
6. Write not permitted.
The host does not properly handle 3 and 4 yet (for any writes).
Now the host rejects a prepare write request if any of the above issues
are detected (except for 3 and 4).
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/d6fab4dc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/d6fab4dc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/d6fab4dc
Branch: refs/heads/sterly_refactor
Commit: d6fab4dc747569d176782a056544572c0b746c72
Parents: de85f43
Author: Christopher Collins <cc...@apache.org>
Authored: Sun Aug 7 17:48:44 2016 -0700
Committer: Sterling Hughes <st...@apache.org>
Committed: Tue Aug 9 16:05:21 2016 -0700
----------------------------------------------------------------------
net/nimble/host/src/ble_att_svr.c | 69 ++++++++++++++----------
net/nimble/host/src/test/ble_att_svr_test.c | 62 +++++++++++++++++----
2 files changed, 95 insertions(+), 36 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d6fab4dc/net/nimble/host/src/ble_att_svr.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_svr.c b/net/nimble/host/src/ble_att_svr.c
index 1b420b5..f282093 100644
--- a/net/nimble/host/src/ble_att_svr.c
+++ b/net/nimble/host/src/ble_att_svr.c
@@ -237,9 +237,9 @@ ble_att_svr_get_sec_state(uint16_t conn_handle,
}
static int
-ble_att_svr_check_security(uint16_t conn_handle, int is_read,
- struct ble_att_svr_entry *entry,
- uint8_t *out_att_err)
+ble_att_svr_check_perms(uint16_t conn_handle, int is_read,
+ struct ble_att_svr_entry *entry,
+ uint8_t *out_att_err)
{
struct ble_gap_sec_state sec_state;
int author;
@@ -248,10 +248,20 @@ ble_att_svr_check_security(uint16_t conn_handle, int is_read,
int rc;
if (is_read) {
+ if (!(entry->ha_flags & BLE_ATT_F_READ)) {
+ *out_att_err = BLE_ATT_ERR_READ_NOT_PERMITTED;
+ return BLE_HS_ENOTSUP;
+ }
+
enc = entry->ha_flags & BLE_ATT_F_READ_ENC;
authen = entry->ha_flags & BLE_ATT_F_READ_AUTHEN;
author = entry->ha_flags & BLE_ATT_F_READ_AUTHOR;
} else {
+ if (!(entry->ha_flags & BLE_ATT_F_WRITE)) {
+ *out_att_err = BLE_ATT_ERR_WRITE_NOT_PERMITTED;
+ return BLE_HS_ENOTSUP;
+ }
+
enc = entry->ha_flags & BLE_ATT_F_WRITE_ENC;
authen = entry->ha_flags & BLE_ATT_F_WRITE_AUTHEN;
author = entry->ha_flags & BLE_ATT_F_WRITE_AUTHOR;
@@ -264,6 +274,8 @@ ble_att_svr_check_security(uint16_t conn_handle, int is_read,
rc = ble_att_svr_get_sec_state(conn_handle, &sec_state);
if (rc != 0) {
+ /* Peer no longer connected. */
+ *out_att_err = 0;
return rc;
}
@@ -300,13 +312,7 @@ ble_att_svr_read(uint16_t conn_handle,
att_err = 0; /* Silence gcc warning. */
if (conn_handle != BLE_HS_CONN_HANDLE_NONE) {
- if (!(entry->ha_flags & BLE_ATT_F_READ)) {
- att_err = BLE_ATT_ERR_READ_NOT_PERMITTED;
- rc = BLE_HS_ENOTSUP;
- goto err;
- }
-
- rc = ble_att_svr_check_security(conn_handle, 1, entry, &att_err);
+ rc = ble_att_svr_check_perms(conn_handle, 1, entry, &att_err);
if (rc != 0) {
goto err;
}
@@ -448,13 +454,7 @@ ble_att_svr_write(uint16_t conn_handle, struct ble_att_svr_entry *entry,
BLE_HS_DBG_ASSERT(!ble_hs_locked_by_cur_task());
if (conn_handle != BLE_HS_CONN_HANDLE_NONE) {
- if (!(entry->ha_flags & BLE_ATT_F_WRITE)) {
- att_err = BLE_ATT_ERR_WRITE_NOT_PERMITTED;
- rc = BLE_HS_ENOTSUP;
- goto done;
- }
-
- rc = ble_att_svr_check_security(conn_handle, 0, entry, &att_err);
+ rc = ble_att_svr_check_perms(conn_handle, 0, entry, &att_err);
if (rc != 0) {
goto done;
}
@@ -2341,19 +2341,17 @@ ble_att_svr_prep_write(uint16_t conn_handle,
while (!SLIST_EMPTY(prep_list)) {
ble_att_svr_prep_extract(prep_list, &attr_handle, &om);
+ /* Attribute existence was verified during prepare-write request
+ * processing.
+ */
attr = ble_att_svr_find_by_handle(attr_handle);
- *err_handle = attr_handle;
- if (attr == NULL) {
- rc = BLE_ATT_ERR_INVALID_HANDLE;
- } else {
- rc = ble_att_svr_write(conn_handle, attr, 0, &om, &att_err);
- if (rc != 0) {
- rc = att_err;
- }
- }
+ BLE_HS_DBG_ASSERT(attr != NULL);
+
+ rc = ble_att_svr_write(conn_handle, attr, 0, &om, &att_err);
os_mbuf_free_chain(om);
if (rc != 0) {
- return rc;
+ *err_handle = attr_handle;
+ return att_err;
}
}
@@ -2400,12 +2398,29 @@ ble_att_svr_rx_prep_write(uint16_t conn_handle, struct os_mbuf **rxom)
os_mbuf_adj(*rxom, BLE_ATT_PREP_WRITE_CMD_BASE_SZ);
attr_entry = ble_att_svr_find_by_handle(req.bapc_handle);
+
+ /* A prepare write request gets rejected for the following reasons:
+ * 1. Insufficient authorization.
+ * 2. Insufficient authentication.
+ * 3. Insufficient encryption key size (XXX: Not checked).
+ * 4. Insufficient encryption.
+ * 5. Invalid handle.
+ * 6. Write not permitted.
+ */
+
+ /* <5> */
if (attr_entry == NULL) {
rc = BLE_HS_ENOENT;
att_err = BLE_ATT_ERR_INVALID_HANDLE;
goto done;
}
+ /* <1>, <2>, <4>, <6> */
+ rc = ble_att_svr_check_perms(conn_handle, 0, attr_entry, &att_err);
+ if (rc != 0) {
+ goto done;
+ }
+
prep_entry = ble_att_svr_prep_alloc();
if (prep_entry == NULL) {
att_err = BLE_ATT_ERR_PREPARE_QUEUE_FULL;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d6fab4dc/net/nimble/host/src/test/ble_att_svr_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_att_svr_test.c b/net/nimble/host/src/test/ble_att_svr_test.c
index 09e7bf9..86565e3 100644
--- a/net/nimble/host/src/test/ble_att_svr_test.c
+++ b/net/nimble/host/src/test/ble_att_svr_test.c
@@ -319,6 +319,15 @@ ble_att_svr_test_misc_attr_fn_w_2(uint16_t conn_handle, uint16_t attr_handle,
}
}
+static int
+ble_att_svr_test_misc_attr_fn_w_fail(uint16_t conn_handle,
+ uint16_t attr_handle,
+ uint8_t op, uint16_t offset,
+ struct os_mbuf **om, void *arg)
+{
+ return BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN;
+}
+
static void
ble_att_svr_test_misc_verify_w_1(void *data, int data_len)
{
@@ -2071,6 +2080,7 @@ TEST_CASE(ble_att_svr_test_read_group_type)
TEST_CASE(ble_att_svr_test_prep_write)
{
+ struct ble_hs_conn *conn;
uint16_t conn_handle;
int i;
@@ -2089,9 +2099,22 @@ TEST_CASE(ble_att_svr_test_prep_write)
ble_att_svr_test_misc_register_uuid16(0x8989, HA_FLAG_PERM_RW, 2,
ble_att_svr_test_misc_attr_fn_w_2);
- /* Register a third attribute that is not writable. */
+ /* 3: not writable. */
ble_att_svr_test_misc_register_uuid16(0xabab, BLE_ATT_F_READ, 3,
ble_att_svr_test_misc_attr_fn_r_1);
+ /* 4: Encryption required. */
+ ble_att_svr_test_misc_register_uuid16(
+ 0xabac, BLE_ATT_F_WRITE | BLE_ATT_F_WRITE_ENC, 4,
+ ble_att_svr_test_misc_attr_fn_w_1);
+
+ /* 5: Encryption+authentication required. */
+ ble_att_svr_test_misc_register_uuid16(
+ 0xabad, BLE_ATT_F_WRITE | BLE_ATT_F_WRITE_ENC | BLE_ATT_F_WRITE_AUTHEN,
+ 5, ble_att_svr_test_misc_attr_fn_w_1);
+
+ /* 6: Write callback always fails. */
+ ble_att_svr_test_misc_register_uuid16(
+ 0xabae, BLE_ATT_F_WRITE, 6, ble_att_svr_test_misc_attr_fn_w_fail);
/*** Empty write succeeds. */
ble_att_svr_test_misc_exec_write(conn_handle, BLE_ATT_EXEC_WRITE_F_CONFIRM,
@@ -2104,6 +2127,28 @@ TEST_CASE(ble_att_svr_test_prep_write)
ble_att_svr_test_misc_prep_write(conn_handle, 53525, 0, data, 10,
BLE_ATT_ERR_INVALID_HANDLE);
+ /*** Failure due to write-not-permitted. */
+ ble_att_svr_test_misc_prep_write(conn_handle, 3, 0, data, 35,
+ BLE_ATT_ERR_WRITE_NOT_PERMITTED);
+
+ /*** Failure due to insufficient authentication (encryption required). */
+ ble_att_svr_test_misc_prep_write(conn_handle, 4, 0, data, 1,
+ BLE_ATT_ERR_INSUFFICIENT_AUTHEN);
+
+ /*** Encrypt connection; ensure previous prep write now succeeds. */
+ ble_hs_lock();
+ conn = ble_hs_conn_find(2);
+ TEST_ASSERT_FATAL(conn != NULL);
+ conn->bhc_sec_state.encrypted = 1;
+ ble_hs_unlock();
+
+ ble_att_svr_test_misc_prep_write(conn_handle, 4, 0, data, 1, 0);
+ ble_att_svr_test_misc_exec_write(conn_handle, 0, 0, 0);
+
+ /*** Failure due to insufficient authentication (not authenticated). */
+ ble_att_svr_test_misc_prep_write(conn_handle, 5, 0, data, 35,
+ BLE_ATT_ERR_INSUFFICIENT_AUTHEN);
+
/*** Failure for write starting at nonzero offset. */
ble_att_svr_test_misc_prep_write(conn_handle, 1, 1, data, 10, 0);
ble_att_svr_test_misc_exec_write(conn_handle, BLE_ATT_EXEC_WRITE_F_CONFIRM,
@@ -2136,14 +2181,6 @@ TEST_CASE(ble_att_svr_test_prep_write)
BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN, 1);
ble_att_svr_test_misc_verify_w_1(NULL, 0);
- /*** Failure due to attribute callback. */
- ble_att_svr_test_misc_prep_write(conn_handle, 3, 0, data, 35, 0);
- ble_att_svr_test_misc_prep_write(conn_handle, 3, 35, data + 35, 43, 0);
- ble_att_svr_test_misc_prep_write(conn_handle, 3, 78, data + 78, 1, 0);
- ble_att_svr_test_misc_exec_write(conn_handle, BLE_ATT_EXEC_WRITE_F_CONFIRM,
- BLE_ATT_ERR_WRITE_NOT_PERMITTED, 0);
- ble_att_svr_test_misc_verify_w_1(NULL, 0);
-
/*** Successful two part write. */
ble_att_svr_test_misc_prep_write(conn_handle, 1, 0, data, 20, 0);
ble_att_svr_test_misc_prep_write(conn_handle, 1, 20, data + 20, 20, 0);
@@ -2188,6 +2225,13 @@ TEST_CASE(ble_att_svr_test_prep_write)
0, 0);
ble_att_svr_test_misc_verify_w_1(data, 12);
ble_att_svr_test_misc_verify_w_2(data, 61);
+
+ /*** Fail due to attribute callback error. */
+ ble_att_svr_test_misc_prep_write(conn_handle, 6, 0, data, 35, 0);
+ ble_att_svr_test_misc_prep_write(conn_handle, 6, 35, data + 35, 43, 0);
+ ble_att_svr_test_misc_prep_write(conn_handle, 6, 78, data + 78, 1, 0);
+ ble_att_svr_test_misc_exec_write(conn_handle, BLE_ATT_EXEC_WRITE_F_CONFIRM,
+ BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN, 6);
}
TEST_CASE(ble_att_svr_test_notify)
[18/42] incubator-mynewt-core git commit: BLE Host - Rename HCI
identifiers and files.
Posted by st...@apache.org.
BLE Host - Rename HCI identifiers and files.
The HCI-related host functionality was using some really inconsistent
names. Identifiers and files have been renamed as reorganized as
follows:
* host_dbg --> ble_hs_dbg
* host_hci_cmd --> ble_hs_hci_cmd
* host_hci --> ble_hs_hci_evt / ble_hs_hci
* ble_hci_util --> ble_hs_hci_util
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/36254fc1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/36254fc1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/36254fc1
Branch: refs/heads/sterly_refactor
Commit: 36254fc19e47969cd13338ea065625c886df5881
Parents: c78db97
Author: Christopher Collins <cc...@apache.org>
Authored: Wed Aug 3 18:41:01 2016 -0700
Committer: Sterling Hughes <st...@apache.org>
Committed: Tue Aug 9 16:05:21 2016 -0700
----------------------------------------------------------------------
apps/blecent/src/main.c | 1 -
apps/bleprph/src/main.c | 1 -
apps/bletest/src/bletest_hci.c | 128 +-
apps/bletest/src/main.c | 9 +-
apps/bletiny/src/main.c | 4 +-
apps/bleuart/src/main.c | 1 -
net/nimble/host/include/host/ble_hs.h | 1 -
net/nimble/host/include/host/ble_hs_test.h | 2 +-
net/nimble/host/include/host/host_hci.h | 130 --
net/nimble/host/src/ble_eddystone.c | 2 +-
net/nimble/host/src/ble_gap.c | 85 +-
net/nimble/host/src/ble_gap_priv.h | 2 +-
net/nimble/host/src/ble_gattc.c | 4 +-
net/nimble/host/src/ble_hci_cmd.c | 320 -----
net/nimble/host/src/ble_hci_priv.h | 51 -
net/nimble/host/src/ble_hci_util.c | 178 ---
net/nimble/host/src/ble_hs.c | 9 +-
net/nimble/host/src/ble_hs_adv.c | 2 +-
net/nimble/host/src/ble_hs_conn.c | 1 -
net/nimble/host/src/ble_hs_dbg.c | 509 ++++++++
net/nimble/host/src/ble_hs_dbg_priv.h | 26 +
net/nimble/host/src/ble_hs_hci.c | 528 ++++++++
net/nimble/host/src/ble_hs_hci_cmd.c | 1375 ++++++++++++++++++++
net/nimble/host/src/ble_hs_hci_evt.c | 677 ++++++++++
net/nimble/host/src/ble_hs_hci_priv.h | 158 +++
net/nimble/host/src/ble_hs_hci_util.c | 196 +++
net/nimble/host/src/ble_hs_id.c | 4 +-
net/nimble/host/src/ble_hs_priv.h | 7 +-
net/nimble/host/src/ble_hs_pvcy.c | 18 +-
net/nimble/host/src/ble_hs_startup.c | 35 +-
net/nimble/host/src/ble_ibeacon.c | 2 +-
net/nimble/host/src/ble_l2cap.c | 3 +-
net/nimble/host/src/ble_sm.c | 26 +-
net/nimble/host/src/ble_sm_alg.c | 5 +-
net/nimble/host/src/ble_sm_sc.c | 2 +-
net/nimble/host/src/host_dbg.c | 503 -------
net/nimble/host/src/host_dbg_priv.h | 25 -
net/nimble/host/src/host_hci.c | 899 -------------
net/nimble/host/src/host_hci_cmd.c | 1364 -------------------
net/nimble/host/src/test/ble_att_clt_test.c | 9 +-
net/nimble/host/src/test/ble_gap_test.c | 49 +-
net/nimble/host/src/test/ble_gatt_read_test.c | 21 +-
net/nimble/host/src/test/ble_host_hci_test.c | 100 --
net/nimble/host/src/test/ble_hs_adv_test.c | 1 -
net/nimble/host/src/test/ble_hs_conn_test.c | 1 -
net/nimble/host/src/test/ble_hs_hci_test.c | 99 ++
net/nimble/host/src/test/ble_hs_test.c | 2 +-
net/nimble/host/src/test/ble_hs_test_util.c | 83 +-
net/nimble/host/src/test/ble_l2cap_test.c | 4 +-
net/nimble/host/src/test/ble_os_test.c | 3 +-
net/nimble/host/src/test/ble_sm_lgcy_test.c | 1 -
net/nimble/host/src/test/ble_sm_sc_test.c | 1 -
net/nimble/host/src/test/ble_sm_test.c | 1 -
net/nimble/host/src/test/ble_sm_test_util.c | 21 +-
net/nimble/host/store/ram/src/ble_store_ram.c | 3 +-
55 files changed, 3855 insertions(+), 3837 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/apps/blecent/src/main.c
----------------------------------------------------------------------
diff --git a/apps/blecent/src/main.c b/apps/blecent/src/main.c
index 3cc0f24..8f10814 100755
--- a/apps/blecent/src/main.c
+++ b/apps/blecent/src/main.c
@@ -27,7 +27,6 @@
/* BLE */
#include "nimble/ble.h"
#include "controller/ble_ll.h"
-#include "host/host_hci.h"
#include "host/ble_hs.h"
/* RAM persistence layer. */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/apps/bleprph/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bleprph/src/main.c b/apps/bleprph/src/main.c
index 3a3d64a..0e6ec14 100755
--- a/apps/bleprph/src/main.c
+++ b/apps/bleprph/src/main.c
@@ -31,7 +31,6 @@
/* BLE */
#include "nimble/ble.h"
-#include "host/host_hci.h"
#include "host/ble_hs.h"
#include "host/ble_hs_adv.h"
#include "host/ble_uuid.h"
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/apps/bletest/src/bletest_hci.c
----------------------------------------------------------------------
diff --git a/apps/bletest/src/bletest_hci.c b/apps/bletest/src/bletest_hci.c
index 9b0eacd..5e6c31e 100755
--- a/apps/bletest/src/bletest_hci.c
+++ b/apps/bletest/src/bletest_hci.c
@@ -26,7 +26,6 @@
#include "nimble/ble.h"
#include "nimble/hci_transport.h"
#include "nimble/hci_common.h"
-#include "host/host_hci.h"
#include "host/ble_hs.h"
#include "controller/ble_ll.h"
#include "controller/ble_ll_hci.h"
@@ -56,7 +55,7 @@ bletest_send_conn_update(uint16_t handle)
hcu.min_ce_len = 4;
hcu.max_ce_len = 4;
- rc = host_hci_cmd_le_conn_update(&hcu);
+ rc = ble_hs_hci_cmd_le_conn_update(&hcu);
assert(rc == 0);
}
@@ -77,12 +76,12 @@ bletest_send_ltk_req_neg_reply(uint16_t handle)
uint8_t rsplen;
dst = buf;
- host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_LT_KEY_REQ_NEG_REPLY,
+ ble_hs_hci_cmd_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_LT_KEY_REQ_NEG_REPLY,
sizeof(uint16_t), dst);
dst += BLE_HCI_CMD_HDR_LEN;
htole16(dst, handle);
- rc = ble_hci_cmd_tx(buf, &ack_conn_handle, 2, &rsplen);
+ rc = ble_hs_hci_cmd_tx(buf, &ack_conn_handle, 2, &rsplen);
if (rc == 0) {
if (rsplen != 2) {
rc = -1;
@@ -104,8 +103,8 @@ bletest_send_ltk_req_reply(uint16_t handle)
hkr.conn_handle = handle;
swap_buf(hkr.long_term_key, (uint8_t *)g_bletest_LTK, 16);
- host_hci_cmd_build_le_lt_key_req_reply(&hkr, buf, sizeof buf);
- rc = ble_hci_cmd_tx(buf, &ack_conn_handle, sizeof ack_conn_handle,
+ ble_hs_hci_cmd_build_le_lt_key_req_reply(&hkr, buf, sizeof buf);
+ rc = ble_hs_hci_cmd_tx(buf, &ack_conn_handle, sizeof ack_conn_handle,
&ack_params_len);
if (rc != 0) {
return rc;
@@ -127,8 +126,9 @@ bletest_hci_reset_ctlr(void)
{
uint8_t buf[BLE_HCI_CMD_HDR_LEN];
- host_hci_write_hdr(BLE_HCI_OGF_CTLR_BASEBAND, BLE_HCI_OCF_CB_RESET, 0, buf);
- return ble_hci_cmd_tx(buf, NULL, 0, NULL);
+ ble_hs_hci_cmd_write_hdr(BLE_HCI_OGF_CTLR_BASEBAND, BLE_HCI_OCF_CB_RESET,
+ 0, buf);
+ return ble_hs_hci_cmd_tx(buf, NULL, 0, NULL);
}
int
@@ -139,9 +139,9 @@ bletest_hci_rd_bd_addr(void)
uint8_t rspbuf[BLE_DEV_ADDR_LEN];
uint8_t rsplen;
- host_hci_write_hdr(BLE_HCI_OGF_INFO_PARAMS, BLE_HCI_OCF_IP_RD_BD_ADDR, 0,
+ ble_hs_hci_cmd_write_hdr(BLE_HCI_OGF_INFO_PARAMS, BLE_HCI_OCF_IP_RD_BD_ADDR, 0,
buf);
- rc = ble_hci_cmd_tx(buf, rspbuf, BLE_DEV_ADDR_LEN, &rsplen);
+ rc = ble_hs_hci_cmd_tx(buf, rspbuf, BLE_DEV_ADDR_LEN, &rsplen);
if (rc != 0) {
return rc;
}
@@ -164,13 +164,13 @@ bletest_hci_le_encrypt(uint8_t *key, uint8_t *pt)
uint8_t rsplen;
dst = buf;
- host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_ENCRYPT,
+ ble_hs_hci_cmd_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_ENCRYPT,
BLE_HCI_LE_ENCRYPT_LEN, dst);
dst += BLE_HCI_CMD_HDR_LEN;
swap_buf(dst, key, BLE_ENC_BLOCK_SIZE);
swap_buf(dst + BLE_ENC_BLOCK_SIZE, pt, BLE_ENC_BLOCK_SIZE);
- rc = ble_hci_cmd_tx(buf, rspbuf, 16, &rsplen);
+ rc = ble_hs_hci_cmd_tx(buf, rspbuf, 16, &rsplen);
if (rc != 0) {
return rc;
}
@@ -192,14 +192,14 @@ bletest_hci_le_set_datalen(uint16_t handle, uint16_t txoctets, uint16_t txtime)
uint8_t rsplen;
dst = buf;
- host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_SET_DATA_LEN,
+ ble_hs_hci_cmd_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_SET_DATA_LEN,
BLE_HCI_SET_DATALEN_LEN, dst);
dst += BLE_HCI_CMD_HDR_LEN;
htole16(dst, handle);
htole16(dst + 2, txoctets);
htole16(dst + 4, txtime);
- rc = ble_hci_cmd_tx(buf, rspbuf, 2, &rsplen);
+ rc = ble_hs_hci_cmd_tx(buf, rspbuf, 2, &rsplen);
if (rc != 0) {
return rc;
}
@@ -218,13 +218,13 @@ bletest_hci_le_write_sugg_datalen(uint16_t txoctets, uint16_t txtime)
uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_WR_SUGG_DATALEN_LEN];
dst = buf;
- host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_WR_SUGG_DEF_DATA_LEN,
+ ble_hs_hci_cmd_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_WR_SUGG_DEF_DATA_LEN,
BLE_HCI_WR_SUGG_DATALEN_LEN, dst);
dst += BLE_HCI_CMD_HDR_LEN;
htole16(dst, txoctets);
htole16(dst + 2, txtime);
- return ble_hci_cmd_tx(buf, NULL, 0, NULL);
+ return ble_hs_hci_cmd_tx(buf, NULL, 0, NULL);
}
int
@@ -235,10 +235,10 @@ bletest_hci_le_rd_sugg_datalen(void)
uint8_t rspbuf[BLE_HCI_RD_SUGG_DATALEN_RSPLEN];
uint8_t rsplen;
- host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_RD_SUGG_DEF_DATA_LEN, 0,
+ ble_hs_hci_cmd_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_RD_SUGG_DEF_DATA_LEN, 0,
buf);
- rc = ble_hci_cmd_tx(buf, rspbuf, BLE_HCI_RD_SUGG_DATALEN_RSPLEN, &rsplen);
+ rc = ble_hs_hci_cmd_tx(buf, rspbuf, BLE_HCI_RD_SUGG_DATALEN_RSPLEN, &rsplen);
if (rc != 0) {
return rc;
}
@@ -258,9 +258,9 @@ bletest_hci_rd_local_version(void)
uint8_t rspbuf[BLE_HCI_RD_LOC_VER_INFO_RSPLEN];
uint8_t rsplen;
- host_hci_write_hdr(BLE_HCI_OGF_INFO_PARAMS, BLE_HCI_OCF_IP_RD_LOCAL_VER, 0,
+ ble_hs_hci_cmd_write_hdr(BLE_HCI_OGF_INFO_PARAMS, BLE_HCI_OCF_IP_RD_LOCAL_VER, 0,
buf);
- rc = ble_hci_cmd_tx(buf, rspbuf, BLE_HCI_RD_LOC_VER_INFO_RSPLEN, &rsplen);
+ rc = ble_hs_hci_cmd_tx(buf, rspbuf, BLE_HCI_RD_LOC_VER_INFO_RSPLEN, &rsplen);
if (rc != 0) {
return rc;
}
@@ -279,9 +279,9 @@ bletest_hci_rd_local_feat(void)
uint8_t rspbuf[BLE_HCI_RD_LOC_SUPP_FEAT_RSPLEN];
uint8_t rsplen;
- host_hci_write_hdr(BLE_HCI_OGF_INFO_PARAMS, BLE_HCI_OCF_IP_RD_LOC_SUPP_FEAT,
+ ble_hs_hci_cmd_write_hdr(BLE_HCI_OGF_INFO_PARAMS, BLE_HCI_OCF_IP_RD_LOC_SUPP_FEAT,
0, buf);
- rc = ble_hci_cmd_tx(buf, rspbuf, BLE_HCI_RD_LOC_SUPP_FEAT_RSPLEN, &rsplen);
+ rc = ble_hs_hci_cmd_tx(buf, rspbuf, BLE_HCI_RD_LOC_SUPP_FEAT_RSPLEN, &rsplen);
if (rc != 0) {
return rc;
}
@@ -300,9 +300,9 @@ bletest_hci_rd_local_supp_cmd(void)
uint8_t rspbuf[BLE_HCI_RD_LOC_SUPP_CMD_RSPLEN];
uint8_t rsplen;
- host_hci_write_hdr(BLE_HCI_OGF_INFO_PARAMS, BLE_HCI_OCF_IP_RD_LOC_SUPP_CMD,
+ ble_hs_hci_cmd_write_hdr(BLE_HCI_OGF_INFO_PARAMS, BLE_HCI_OCF_IP_RD_LOC_SUPP_CMD,
0, buf);
- rc = ble_hci_cmd_tx(buf, rspbuf, BLE_HCI_RD_LOC_SUPP_CMD_RSPLEN, &rsplen);
+ rc = ble_hs_hci_cmd_tx(buf, rspbuf, BLE_HCI_RD_LOC_SUPP_CMD_RSPLEN, &rsplen);
if (rc != 0) {
return rc;
}
@@ -329,8 +329,8 @@ bletest_hci_le_read_supp_states(void)
uint8_t rspbuf[BLE_HCI_RD_SUPP_STATES_RSPLEN];
uint8_t rsplen;
- host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_RD_SUPP_STATES, 0, buf);
- rc = ble_hci_cmd_tx(buf, rspbuf, BLE_HCI_RD_SUPP_STATES_RSPLEN, &rsplen);
+ ble_hs_hci_cmd_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_RD_SUPP_STATES, 0, buf);
+ rc = ble_hs_hci_cmd_tx(buf, rspbuf, BLE_HCI_RD_SUPP_STATES_RSPLEN, &rsplen);
if (rc != 0) {
return rc;
}
@@ -349,8 +349,8 @@ bletest_hci_le_rd_max_datalen(void)
uint8_t rspbuf[BLE_HCI_RD_MAX_DATALEN_RSPLEN];
uint8_t rsplen;
- host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_RD_MAX_DATA_LEN, 0, buf);
- rc = ble_hci_cmd_tx(buf, rspbuf, BLE_HCI_RD_MAX_DATALEN_RSPLEN, &rsplen);
+ ble_hs_hci_cmd_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_RD_MAX_DATA_LEN, 0, buf);
+ rc = ble_hs_hci_cmd_tx(buf, rspbuf, BLE_HCI_RD_MAX_DATALEN_RSPLEN, &rsplen);
if (rc != 0) {
return rc;
}
@@ -367,9 +367,9 @@ bletest_hci_le_set_adv_data(uint8_t *data, uint8_t len)
int rc;
uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_ADV_DATA_LEN];
- rc = host_hci_cmd_build_le_set_adv_data(data, len, buf, sizeof buf);
+ rc = ble_hs_hci_cmd_build_le_set_adv_data(data, len, buf, sizeof buf);
assert(rc == 0);
- return ble_hci_cmd_tx_empty_ack(buf);
+ return ble_hs_hci_cmd_tx_empty_ack(buf);
}
#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
@@ -378,8 +378,8 @@ bletest_hci_le_start_encrypt(struct hci_start_encrypt *cmd)
{
uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_LE_START_ENCRYPT_LEN];
- host_hci_cmd_build_le_start_encrypt(cmd, buf, sizeof buf);
- return ble_hci_cmd_tx_empty_ack(buf);
+ ble_hs_hci_cmd_build_le_start_encrypt(cmd, buf, sizeof buf);
+ return ble_hs_hci_cmd_tx_empty_ack(buf);
}
#endif
@@ -390,12 +390,12 @@ bletest_hci_le_read_rem_used_feat(uint16_t handle)
uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_CONN_RD_REM_FEAT_LEN];
dst = buf;
- host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_RD_REM_FEAT,
+ ble_hs_hci_cmd_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_RD_REM_FEAT,
BLE_HCI_CONN_RD_REM_FEAT_LEN, dst);
dst += BLE_HCI_CMD_HDR_LEN;
htole16(dst, handle);
- return ble_hci_cmd_tx(buf, NULL, 0, NULL);
+ return ble_hs_hci_cmd_tx(buf, NULL, 0, NULL);
}
int
@@ -404,9 +404,9 @@ bletest_hci_le_set_adv_params(struct hci_adv_params *adv)
int rc;
uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_ADV_PARAM_LEN];
- rc = host_hci_cmd_build_le_set_adv_params(adv, buf, sizeof buf);
+ rc = ble_hs_hci_cmd_build_le_set_adv_params(adv, buf, sizeof buf);
if (!rc) {
- rc = ble_hci_cmd_tx_empty_ack(buf);
+ rc = ble_hs_hci_cmd_tx_empty_ack(buf);
}
return rc;
}
@@ -418,12 +418,12 @@ bletest_hci_le_set_rand_addr(uint8_t *addr)
uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_DATALEN_LEN];
dst = buf;
- host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_SET_RAND_ADDR,
+ ble_hs_hci_cmd_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_SET_RAND_ADDR,
BLE_DEV_ADDR_LEN, dst);
dst += BLE_HCI_CMD_HDR_LEN;
memcpy(dst, addr, BLE_DEV_ADDR_LEN);
- return ble_hci_cmd_tx(buf, NULL, 0, NULL);
+ return ble_hs_hci_cmd_tx(buf, NULL, 0, NULL);
}
int
@@ -433,12 +433,12 @@ bletest_hci_rd_rem_version(uint16_t handle)
uint8_t buf[BLE_HCI_CMD_HDR_LEN + sizeof(uint16_t)];
dst = buf;
- host_hci_write_hdr(BLE_HCI_OGF_LINK_CTRL, BLE_HCI_OCF_RD_REM_VER_INFO,
+ ble_hs_hci_cmd_write_hdr(BLE_HCI_OGF_LINK_CTRL, BLE_HCI_OCF_RD_REM_VER_INFO,
sizeof(uint16_t), dst);
dst += BLE_HCI_CMD_HDR_LEN;
htole16(dst, handle);
- return ble_hci_cmd_tx(buf, NULL, 0, NULL);
+ return ble_hs_hci_cmd_tx(buf, NULL, 0, NULL);
}
int
@@ -448,12 +448,12 @@ bletest_hci_le_set_host_chan_class(uint8_t *chanmap)
uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_HOST_CHAN_CLASS_LEN];
dst = buf;
- host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_SET_HOST_CHAN_CLASS,
+ ble_hs_hci_cmd_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_SET_HOST_CHAN_CLASS,
BLE_HCI_SET_HOST_CHAN_CLASS_LEN, dst);
dst += BLE_HCI_CMD_HDR_LEN;
memcpy(dst, chanmap, BLE_HCI_SET_HOST_CHAN_CLASS_LEN);
- return ble_hci_cmd_tx(buf, NULL, 0, NULL);
+ return ble_hs_hci_cmd_tx(buf, NULL, 0, NULL);
}
int
@@ -466,12 +466,12 @@ bletest_hci_le_rd_chanmap(uint16_t handle)
uint8_t rsplen;
dst = buf;
- host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_RD_CHAN_MAP,
+ ble_hs_hci_cmd_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_RD_CHAN_MAP,
BLE_HCI_RD_CHANMAP_LEN, dst);
dst += BLE_HCI_CMD_HDR_LEN;
htole16(dst, handle);
- rc = ble_hci_cmd_tx(buf, rspbuf, BLE_HCI_RD_CHANMAP_RSP_LEN, &rsplen);
+ rc = ble_hs_hci_cmd_tx(buf, rspbuf, BLE_HCI_RD_CHANMAP_RSP_LEN, &rsplen);
if (rc != 0) {
return rc;
}
@@ -490,12 +490,12 @@ bletest_hci_le_set_adv_enable(uint8_t enable)
uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_ADV_ENABLE_LEN];
dst = buf;
- host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_SET_ADV_ENABLE,
+ ble_hs_hci_cmd_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_SET_ADV_ENABLE,
BLE_HCI_SET_ADV_ENABLE_LEN, dst);
dst += BLE_HCI_CMD_HDR_LEN;
dst[0] = enable;
- return ble_hci_cmd_tx(buf, NULL, 0, NULL);
+ return ble_hs_hci_cmd_tx(buf, NULL, 0, NULL);
}
int
@@ -503,8 +503,8 @@ bletest_hci_le_set_event_mask(uint64_t event_mask)
{
uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_LE_EVENT_MASK_LEN];
- host_hci_cmd_build_le_set_event_mask(event_mask, buf, sizeof buf);
- return ble_hci_cmd_tx_empty_ack(buf);
+ ble_hs_hci_cmd_build_le_set_event_mask(event_mask, buf, sizeof buf);
+ return ble_hs_hci_cmd_tx_empty_ack(buf);
}
int
@@ -512,8 +512,8 @@ bletest_hci_set_event_mask(uint64_t event_mask)
{
uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_EVENT_MASK_LEN];
- host_hci_cmd_build_set_event_mask(event_mask, buf, sizeof buf);
- return ble_hci_cmd_tx_empty_ack(buf);
+ ble_hs_hci_cmd_build_set_event_mask(event_mask, buf, sizeof buf);
+ return ble_hs_hci_cmd_tx_empty_ack(buf);
}
int
@@ -522,9 +522,9 @@ bletest_hci_le_set_scan_rsp_data(uint8_t *data, uint8_t len)
int rc;
uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_SCAN_RSP_DATA_LEN];
- rc = host_hci_cmd_build_le_set_scan_rsp_data(data, len, buf, sizeof buf);
+ rc = ble_hs_hci_cmd_build_le_set_scan_rsp_data(data, len, buf, sizeof buf);
assert(rc == 0);
- return ble_hci_cmd_tx_empty_ack(buf);
+ return ble_hs_hci_cmd_tx_empty_ack(buf);
}
int
@@ -534,11 +534,11 @@ bletest_hci_cmd_le_set_scan_params(uint8_t scan_type, uint16_t scan_itvl,
int rc;
uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_SCAN_PARAM_LEN];
- rc = host_hci_cmd_build_le_set_scan_params(scan_type, scan_itvl,
+ rc = ble_hs_hci_cmd_build_le_set_scan_params(scan_type, scan_itvl,
scan_window, own_addr_type,
filter_policy, buf, sizeof buf);
if (!rc) {
- rc = ble_hci_cmd_tx_empty_ack(buf);
+ rc = ble_hs_hci_cmd_tx_empty_ack(buf);
}
return rc;
}
@@ -549,10 +549,10 @@ bletest_hci_le_add_to_whitelist(uint8_t *addr, uint8_t addr_type)
int rc;
uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_SCAN_PARAM_LEN];
- rc = host_hci_cmd_build_le_add_to_whitelist(addr, addr_type, buf,
+ rc = ble_hs_hci_cmd_build_le_add_to_whitelist(addr, addr_type, buf,
sizeof buf);
if (!rc) {
- rc = ble_hci_cmd_tx_empty_ack(buf);
+ rc = ble_hs_hci_cmd_tx_empty_ack(buf);
}
return rc;
}
@@ -562,8 +562,8 @@ bletest_hci_le_set_scan_enable(uint8_t enable, uint8_t filter_dups)
{
uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_SCAN_ENABLE_LEN];
- host_hci_cmd_build_le_set_scan_enable(enable, filter_dups, buf, sizeof buf);
- return ble_hci_cmd_tx_empty_ack(buf);
+ ble_hs_hci_cmd_build_le_set_scan_enable(enable, filter_dups, buf, sizeof buf);
+ return ble_hs_hci_cmd_tx_empty_ack(buf);
}
int
@@ -572,9 +572,9 @@ bletest_hci_le_create_connection(struct hci_create_conn *hcc)
int rc;
uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_CREATE_CONN_LEN];
- rc = host_hci_cmd_build_le_create_connection(hcc, buf, sizeof buf);
+ rc = ble_hs_hci_cmd_build_le_create_connection(hcc, buf, sizeof buf);
if (!rc) {
- rc = ble_hci_cmd_tx_empty_ack(buf);
+ rc = ble_hs_hci_cmd_tx_empty_ack(buf);
}
return rc;
}
@@ -591,9 +591,9 @@ bletest_hci_le_add_resolv_list(uint8_t *local_irk, uint8_t *peer_irk,
memcpy(padd.addr, peer_ident_addr, BLE_DEV_ADDR_LEN);
swap_buf(padd.local_irk, local_irk, 16);
swap_buf(padd.peer_irk, peer_irk, 16);
- rc = host_hci_cmd_build_add_to_resolv_list(&padd, buf, sizeof buf);
+ rc = ble_hs_hci_cmd_build_add_to_resolv_list(&padd, buf, sizeof buf);
if (!rc) {
- rc = ble_hci_cmd_tx_empty_ack(buf);
+ rc = ble_hs_hci_cmd_tx_empty_ack(buf);
}
return rc;
}
@@ -605,9 +605,9 @@ bletest_hci_le_enable_resolv_list(uint8_t enable)
uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_ADDR_RESOL_ENA_LEN];
- rc = host_hci_cmd_build_set_addr_res_en(enable, buf, sizeof buf);
+ rc = ble_hs_hci_cmd_build_set_addr_res_en(enable, buf, sizeof buf);
if (!rc) {
- rc = ble_hci_cmd_tx_empty_ack(buf);
+ rc = ble_hs_hci_cmd_tx_empty_ack(buf);
}
return rc;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/apps/bletest/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletest/src/main.c b/apps/bletest/src/main.c
index dbfa053..f6bb187 100755
--- a/apps/bletest/src/main.c
+++ b/apps/bletest/src/main.c
@@ -38,7 +38,6 @@
#include "nimble/ble.h"
#include "nimble/hci_transport.h"
#include "nimble/hci_common.h"
-#include "host/host_hci.h"
#include "host/ble_hs.h"
#include "controller/ble_ll.h"
#include "controller/ble_ll_hci.h"
@@ -420,14 +419,14 @@ bletest_init_scanner(void)
uint8_t add_whitelist;
own_addr_type = BLETEST_CFG_SCAN_OWN_ADDR_TYPE;
- rc = host_hci_cmd_build_le_set_scan_params(BLETEST_CFG_SCAN_TYPE,
+ rc = ble_hs_hci_cmd_build_le_set_scan_params(BLETEST_CFG_SCAN_TYPE,
BLETEST_CFG_SCAN_ITVL,
BLETEST_CFG_SCAN_WINDOW,
BLETEST_CFG_SCAN_OWN_ADDR_TYPE,
BLETEST_CFG_SCAN_FILT_POLICY,
buf, sizeof buf);
assert(rc == 0);
- rc = ble_hci_cmd_tx_empty_ack(buf);
+ rc = ble_hs_hci_cmd_tx_empty_ack(buf);
if (rc == 0) {
add_whitelist = BLETEST_CFG_SCAN_FILT_POLICY;
#if (BLE_LL_CFG_FEAT_LL_PRIVACY == 1)
@@ -615,7 +614,7 @@ bletest_execute_initiator(void)
} else {
for (i = 0; i < g_bletest_current_conns; ++i) {
if (ble_ll_conn_find_active_conn(i + 1)) {
- ble_hci_util_read_rssi(i+1, &rssi);
+ ble_hs_hci_util_read_rssi(i+1, &rssi);
}
}
}
@@ -989,7 +988,7 @@ bletest_task_handler(void *arg)
#endif
/* Get a random number */
- rc = ble_hci_util_rand(&rand64, 8);
+ rc = ble_hs_hci_util_rand(&rand64, 8);
assert(rc == 0);
/* Wait some time before starting */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/apps/bletiny/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/main.c b/apps/bletiny/src/main.c
index 733f8d1..2f3c474 100755
--- a/apps/bletiny/src/main.c
+++ b/apps/bletiny/src/main.c
@@ -59,7 +59,7 @@
*/
#include "../src/ble_hs_conn_priv.h"
#include "../src/ble_hs_atomic_priv.h"
-#include "../src/ble_hci_priv.h"
+#include "../src/ble_hs_hci_priv.h"
/* Nimble task priorities */
#define BLE_LL_TASK_PRI (OS_TASK_PRI_HIGHEST)
@@ -1408,7 +1408,7 @@ bletiny_datalen(uint16_t conn_handle, uint16_t tx_octets, uint16_t tx_time)
{
int rc;
- rc = ble_hci_util_set_data_len(conn_handle, tx_octets, tx_time);
+ rc = ble_hs_hci_util_set_data_len(conn_handle, tx_octets, tx_time);
return rc;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/apps/bleuart/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bleuart/src/main.c b/apps/bleuart/src/main.c
index 24f1a3b..0a5dd82 100755
--- a/apps/bleuart/src/main.c
+++ b/apps/bleuart/src/main.c
@@ -30,7 +30,6 @@
/* BLE */
#include "nimble/ble.h"
-#include "host/host_hci.h"
#include "host/ble_hs.h"
#include "host/ble_hs_adv.h"
#include "host/ble_uuid.h"
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/net/nimble/host/include/host/ble_hs.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_hs.h b/net/nimble/host/include/host/ble_hs.h
index 4a707af..954d278 100644
--- a/net/nimble/host/include/host/ble_hs.h
+++ b/net/nimble/host/include/host/ble_hs.h
@@ -34,7 +34,6 @@
#include "host/ble_sm.h"
#include "host/ble_store.h"
#include "host/ble_uuid.h"
-#include "host/host_hci.h"
struct os_eventq;
struct os_event;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/net/nimble/host/include/host/ble_hs_test.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_hs_test.h b/net/nimble/host/include/host/ble_hs_test.h
index 5d28291..3247b59 100644
--- a/net/nimble/host/include/host/ble_hs_test.h
+++ b/net/nimble/host/include/host/ble_hs_test.h
@@ -36,7 +36,7 @@ int ble_gatt_write_test_all(void);
int ble_gatts_notify_test_all(void);
int ble_gatts_read_test_suite(void);
int ble_gatts_reg_test_all(void);
-int ble_host_hci_test_all(void);
+int ble_hs_hci_test_all(void);
int ble_hs_adv_test_all(void);
int ble_hs_conn_test_all(void);
int ble_l2cap_test_all(void);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/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
deleted file mode 100644
index 79a0034..0000000
--- a/net/nimble/host/include/host/host_hci.h
+++ /dev/null
@@ -1,130 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-#ifndef H_HOST_HCI_
-#define H_HOST_HCI_
-
-#include "nimble/hci_common.h"
-struct ble_hs_conn;
-struct os_mbuf;
-
-int host_hci_evt_process(uint8_t *data);
-uint16_t host_hci_opcode_join(uint8_t ogf, uint16_t ocf);
-void host_hci_write_hdr(uint8_t ogf, uint8_t ocf, uint8_t len, void *buf);
-int host_hci_cmd_send(uint8_t ogf, uint8_t ocf, uint8_t len,
- const void *cmddata);
-int host_hci_cmd_send_buf(void *cmddata);
-void host_hci_cmd_build_read_bd_addr(uint8_t *dst, int dst_len);
-void host_hci_cmd_build_set_event_mask(uint64_t event_mask,
- uint8_t *dst, int dst_len);
-void host_hci_cmd_build_set_event_mask2(uint64_t event_mask, uint8_t *dst,
- int dst_len);
-void host_hci_cmd_build_disconnect(uint16_t handle, uint8_t reason,
- uint8_t *dst, int dst_len);
-int host_hci_cmd_disconnect(uint16_t handle, uint8_t reason);
-void host_hci_cmd_build_read_rssi(uint16_t handle, uint8_t *dst, int dst_len);
-int host_hci_cmd_read_rssi(uint16_t handle);
-int host_hci_cmd_build_le_set_scan_rsp_data(const uint8_t *data, uint8_t len,
- uint8_t *dst, int dst_len);
-int host_hci_cmd_build_le_set_adv_data(const uint8_t *data, uint8_t len,
- uint8_t *dst, int dst_len);
-int host_hci_cmd_build_le_set_adv_params(const struct hci_adv_params *adv,
- uint8_t *dst, int dst_len);
-void host_hci_cmd_build_le_set_event_mask(uint64_t event_mask,
- uint8_t *dst, int dst_len);
-void host_hci_cmd_build_le_read_buffer_size(uint8_t *dst, int dst_len);
-int host_hci_cmd_le_read_buffer_size(void);
-void host_hci_cmd_build_le_read_loc_supp_feat(uint8_t *dst, uint8_t dst_len);
-void host_hci_cmd_build_le_set_adv_enable(uint8_t enable, uint8_t *dst,
- int dst_len);
-int host_hci_cmd_le_set_adv_enable(uint8_t enable);
-int host_hci_cmd_build_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,
- uint8_t *dst, int dst_len);
-void host_hci_cmd_build_le_set_scan_enable(uint8_t enable,
- uint8_t filter_dups,
- uint8_t *dst, uint8_t dst_len);
-int host_hci_cmd_le_set_scan_enable(uint8_t enable, uint8_t filter_dups);
-int host_hci_cmd_build_le_create_connection(const struct hci_create_conn *hcc,
- uint8_t *cmd, int cmd_len);
-int host_hci_cmd_le_create_connection(const struct hci_create_conn *hcc);
-void host_hci_cmd_build_le_clear_whitelist(uint8_t *dst, int dst_len);
-int host_hci_cmd_build_le_add_to_whitelist(const uint8_t *addr,
- uint8_t addr_type,
- uint8_t *dst, int dst_len);
-void host_hci_cmd_build_reset(uint8_t *dst, int dst_len);
-int host_hci_cmd_reset(void);
-void host_hci_cmd_build_read_adv_pwr(uint8_t *dst, int dst_len);
-int host_hci_cmd_read_adv_pwr(void);
-void host_hci_cmd_build_le_create_conn_cancel(uint8_t *dst, int dst_len);
-int host_hci_cmd_le_create_conn_cancel(void);
-int host_hci_cmd_build_le_conn_update(const struct hci_conn_update *hcu,
- uint8_t *dst, int dst_len);
-int host_hci_cmd_le_conn_update(const struct hci_conn_update *hcu);
-void host_hci_cmd_build_le_lt_key_req_reply(
- const struct hci_lt_key_req_reply *hkr, uint8_t *dst, int dst_len);
-void host_hci_cmd_build_le_lt_key_req_neg_reply(uint16_t conn_handle,
- uint8_t *dst, int dst_len);
-void host_hci_cmd_build_le_conn_param_reply(
- const struct hci_conn_param_reply *hcr, uint8_t *dst, int dst_len);
-int host_hci_cmd_le_conn_param_reply(const struct hci_conn_param_reply *hcr);
-void host_hci_cmd_build_le_conn_param_neg_reply(
- const struct hci_conn_param_neg_reply *hcn, uint8_t *dst, int dst_len);
-int host_hci_cmd_le_conn_param_neg_reply(
- const struct hci_conn_param_neg_reply *hcn);
-void host_hci_cmd_build_le_rand(uint8_t *dst, int dst_len);
-void host_hci_cmd_build_le_start_encrypt(const struct hci_start_encrypt *cmd,
- uint8_t *dst, int dst_len);
-int host_hci_set_buf_size(uint16_t pktlen, uint8_t max_pkts);
-
-uint16_t host_hci_handle_pb_bc_join(uint16_t handle, uint8_t pb, uint8_t bc);
-
-int host_hci_data_rx(struct os_mbuf *om);
-int host_hci_data_tx(struct ble_hs_conn *connection, struct os_mbuf *txom);
-
-int host_hci_cmd_build_set_data_len(uint16_t connection_handle,
- uint16_t tx_octets, uint16_t tx_time,
- uint8_t *dst, int dst_len);
-int host_hci_cmd_build_add_to_resolv_list(
- const struct hci_add_dev_to_resolving_list *padd,
- uint8_t *dst, int dst_len);
-int host_hci_cmd_build_remove_from_resolv_list(
- uint8_t addr_type, const uint8_t *addr, uint8_t *dst, int dst_len);
-int host_hci_cmd_build_read_resolv_list_size(uint8_t *dst, int dst_len);
-int host_hci_cmd_build_clear_resolv_list(uint8_t *dst, int dst_len);
-int host_hci_cmd_build_read_peer_resolv_addr(
- uint8_t peer_identity_addr_type, const uint8_t *peer_identity_addr,
- uint8_t *dst, int dst_len);
-int host_hci_cmd_build_read_lcl_resolv_addr(
- uint8_t local_identity_addr_type, const uint8_t *local_identity_addr,
- uint8_t *dst, int dst_len);
-int host_hci_cmd_build_set_addr_res_en(
- uint8_t enable, uint8_t *dst, int dst_len);
-int host_hci_cmd_build_set_resolv_priv_addr_timeout(
- uint16_t timeout, uint8_t *dst, int dst_len);
-
-void host_hci_timer_set(void);
-
-int host_hci_cmd_build_set_random_addr(const uint8_t *addr,
- uint8_t *dst, int dst_len);
-
-#endif /* H_HOST_HCI_ */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/net/nimble/host/src/ble_eddystone.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_eddystone.c b/net/nimble/host/src/ble_eddystone.c
index 5e7a3f0..2ca496f 100644
--- a/net/nimble/host/src/ble_eddystone.c
+++ b/net/nimble/host/src/ble_eddystone.c
@@ -186,7 +186,7 @@ ble_eddystone_set_adv_data_url(struct ble_hs_adv_fields *adv_fields,
svc_data = ble_eddystone_set_svc_data_base(BLE_EDDYSTONE_FRAME_TYPE_URL);
- rc = ble_hci_util_read_adv_tx_pwr(&tx_pwr);
+ rc = ble_hs_hci_util_read_adv_tx_pwr(&tx_pwr);
if (rc != 0) {
return rc;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/net/nimble/host/src/ble_gap.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gap.c b/net/nimble/host/src/ble_gap.c
index 1a41956..6086c50 100644
--- a/net/nimble/host/src/ble_gap.c
+++ b/net/nimble/host/src/ble_gap.c
@@ -23,7 +23,6 @@
#include "bsp/bsp.h"
#include "os/os.h"
#include "nimble/nimble_opt.h"
-#include "host/host_hci.h"
#include "host/ble_hs_adv.h"
#include "ble_hs_priv.h"
@@ -1201,13 +1200,13 @@ ble_gap_wl_tx_add(const struct ble_gap_white_entry *entry)
uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_CHG_WHITE_LIST_LEN];
int rc;
- rc = host_hci_cmd_build_le_add_to_whitelist(entry->addr, entry->addr_type,
- buf, sizeof buf);
+ rc = ble_hs_hci_cmd_build_le_add_to_whitelist(
+ entry->addr, entry->addr_type, buf, sizeof buf);
if (rc != 0) {
return rc;
}
- rc = ble_hci_cmd_tx_empty_ack(buf);
+ rc = ble_hs_hci_cmd_tx_empty_ack(buf);
if (rc != 0) {
return rc;
}
@@ -1221,8 +1220,8 @@ ble_gap_wl_tx_clear(void)
uint8_t buf[BLE_HCI_CMD_HDR_LEN];
int rc;
- host_hci_cmd_build_le_clear_whitelist(buf, sizeof buf);
- rc = ble_hci_cmd_tx_empty_ack(buf);
+ ble_hs_hci_cmd_build_le_clear_whitelist(buf, sizeof buf);
+ rc = ble_hs_hci_cmd_tx_empty_ack(buf);
if (rc != 0) {
return rc;
}
@@ -1309,8 +1308,8 @@ ble_gap_adv_enable_tx(int enable)
uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_ADV_ENABLE_LEN];
int rc;
- host_hci_cmd_build_le_set_adv_enable(!!enable, buf, sizeof buf);
- rc = ble_hci_cmd_tx_empty_ack(buf);
+ ble_hs_hci_cmd_build_le_set_adv_enable(!!enable, buf, sizeof buf);
+ rc = ble_hs_hci_cmd_tx_empty_ack(buf);
if (rc != 0) {
return rc;
}
@@ -1377,14 +1376,14 @@ ble_gap_adv_rsp_data_tx(void)
uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_SCAN_RSP_DATA_LEN];
int rc;
- rc = host_hci_cmd_build_le_set_scan_rsp_data(ble_gap_slave.rsp_data,
- ble_gap_slave.rsp_data_len,
- buf, sizeof buf);
+ rc = ble_hs_hci_cmd_build_le_set_scan_rsp_data(ble_gap_slave.rsp_data,
+ ble_gap_slave.rsp_data_len,
+ buf, sizeof buf);
if (rc != 0) {
return rc;
}
- rc = ble_hci_cmd_tx_empty_ack(buf);
+ rc = ble_hs_hci_cmd_tx_empty_ack(buf);
if (rc != 0) {
return rc;
}
@@ -1443,14 +1442,14 @@ ble_gap_adv_data_tx(void)
ble_gap_slave.adv_auto_flags = 0;
}
- rc = host_hci_cmd_build_le_set_adv_data(ble_gap_slave.adv_data,
- ble_gap_slave.adv_data_len,
- buf, sizeof buf);
+ rc = ble_hs_hci_cmd_build_le_set_adv_data(ble_gap_slave.adv_data,
+ ble_gap_slave.adv_data_len,
+ buf, sizeof buf);
if (rc != 0) {
return rc;
}
- rc = ble_hci_cmd_tx_empty_ack(buf);
+ rc = ble_hs_hci_cmd_tx_empty_ack(buf);
if (rc != 0) {
return rc;
}
@@ -1549,13 +1548,13 @@ ble_gap_adv_params_tx(uint8_t own_addr_type,
hci_adv_params.adv_filter_policy = adv_params->filter_policy;
hci_adv_params.adv_type = ble_gap_adv_type(adv_params);
- rc = host_hci_cmd_build_le_set_adv_params(&hci_adv_params,
- buf, sizeof buf);
+ rc = ble_hs_hci_cmd_build_le_set_adv_params(&hci_adv_params,
+ buf, sizeof buf);
if (rc != 0) {
return BLE_HS_EINVAL;
}
- rc = ble_hci_cmd_tx_empty_ack(buf);
+ rc = ble_hs_hci_cmd_tx_empty_ack(buf);
if (rc != 0) {
return rc;
}
@@ -1881,9 +1880,9 @@ ble_gap_disc_enable_tx(int enable, int filter_duplicates)
uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_SCAN_ENABLE_LEN];
int rc;
- host_hci_cmd_build_le_set_scan_enable(!!enable, !!filter_duplicates,
- buf, sizeof buf);
- rc = ble_hci_cmd_tx_empty_ack(buf);
+ ble_hs_hci_cmd_build_le_set_scan_enable(!!enable, !!filter_duplicates,
+ buf, sizeof buf);
+ rc = ble_hs_hci_cmd_tx_empty_ack(buf);
if (rc != 0) {
return rc;
}
@@ -1905,17 +1904,17 @@ ble_gap_disc_tx_params(uint8_t own_addr_type,
scan_type = BLE_HCI_SCAN_TYPE_ACTIVE;
}
- rc = host_hci_cmd_build_le_set_scan_params(scan_type,
- disc_params->itvl,
- disc_params->window,
- own_addr_type,
- disc_params->filter_policy,
- buf, sizeof buf);
+ rc = ble_hs_hci_cmd_build_le_set_scan_params(scan_type,
+ disc_params->itvl,
+ disc_params->window,
+ own_addr_type,
+ disc_params->filter_policy,
+ buf, sizeof buf);
if (rc != 0) {
return BLE_HS_EINVAL;
}
- rc = ble_hci_cmd_tx_empty_ack(buf);
+ rc = ble_hs_hci_cmd_tx_empty_ack(buf);
if (rc != 0) {
return rc;
}
@@ -2164,12 +2163,12 @@ ble_gap_conn_create_tx(uint8_t own_addr_type,
hcc.min_ce_len = params->min_ce_len;
hcc.max_ce_len = params->max_ce_len;
- rc = host_hci_cmd_build_le_create_connection(&hcc, buf, sizeof buf);
+ rc = ble_hs_hci_cmd_build_le_create_connection(&hcc, buf, sizeof buf);
if (rc != 0) {
return BLE_HS_EUNKNOWN;
}
- rc = ble_hci_cmd_tx_empty_ack(buf);
+ rc = ble_hs_hci_cmd_tx_empty_ack(buf);
if (rc != 0) {
return rc;
}
@@ -2356,9 +2355,9 @@ ble_gap_terminate(uint16_t conn_handle, uint8_t hci_reason)
"conn_handle=%d hci_reason=%d\n",
conn_handle, hci_reason);
- host_hci_cmd_build_disconnect(conn_handle, hci_reason,
- buf, sizeof buf);
- rc = ble_hci_cmd_tx_empty_ack(buf);
+ ble_hs_hci_cmd_build_disconnect(conn_handle, hci_reason,
+ buf, sizeof buf);
+ rc = ble_hs_hci_cmd_tx_empty_ack(buf);
if (rc != 0) {
goto done;
}
@@ -2384,8 +2383,8 @@ ble_gap_conn_cancel_tx(void)
uint8_t buf[BLE_HCI_CMD_HDR_LEN];
int rc;
- host_hci_cmd_build_le_create_conn_cancel(buf, sizeof buf);
- rc = ble_hci_cmd_tx_empty_ack(buf);
+ ble_hs_hci_cmd_build_le_create_conn_cancel(buf, sizeof buf);
+ rc = ble_hs_hci_cmd_tx_empty_ack(buf);
if (rc != 0) {
return rc;
}
@@ -2454,8 +2453,8 @@ ble_gap_tx_param_pos_reply(uint16_t conn_handle,
pos_reply.min_ce_len = params->min_ce_len;
pos_reply.max_ce_len = params->max_ce_len;
- host_hci_cmd_build_le_conn_param_reply(&pos_reply, buf, sizeof buf);
- rc = ble_hci_cmd_tx_empty_ack(buf);
+ ble_hs_hci_cmd_build_le_conn_param_reply(&pos_reply, buf, sizeof buf);
+ rc = ble_hs_hci_cmd_tx_empty_ack(buf);
if (rc != 0) {
return rc;
}
@@ -2473,8 +2472,8 @@ ble_gap_tx_param_neg_reply(uint16_t conn_handle, uint8_t reject_reason)
neg_reply.handle = conn_handle;
neg_reply.reason = reject_reason;
- host_hci_cmd_build_le_conn_param_neg_reply(&neg_reply, buf, sizeof buf);
- rc = ble_hci_cmd_tx_empty_ack(buf);
+ ble_hs_hci_cmd_build_le_conn_param_neg_reply(&neg_reply, buf, sizeof buf);
+ rc = ble_hs_hci_cmd_tx_empty_ack(buf);
if (rc != 0) {
return rc;
}
@@ -2551,12 +2550,12 @@ ble_gap_update_tx(uint16_t conn_handle,
cmd.min_ce_len = params->min_ce_len;
cmd.max_ce_len = params->max_ce_len;
- rc = host_hci_cmd_build_le_conn_update(&cmd, buf, sizeof buf);
+ rc = ble_hs_hci_cmd_build_le_conn_update(&cmd, buf, sizeof buf);
if (rc != 0) {
return rc;
}
- rc = ble_hci_cmd_tx_empty_ack(buf);
+ rc = ble_hs_hci_cmd_tx_empty_ack(buf);
if (rc != 0) {
return rc;
}
@@ -2811,7 +2810,7 @@ ble_gap_conn_rssi(uint16_t conn_handle, int8_t *out_rssi)
{
int rc;
- rc = ble_hci_util_read_rssi(conn_handle, out_rssi);
+ rc = ble_hs_hci_util_read_rssi(conn_handle, out_rssi);
return rc;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/net/nimble/host/src/ble_gap_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gap_priv.h b/net/nimble/host/src/ble_gap_priv.h
index 3168d48..c2abbf3 100644
--- a/net/nimble/host/src/ble_gap_priv.h
+++ b/net/nimble/host/src/ble_gap_priv.h
@@ -28,7 +28,7 @@ struct hci_le_conn_param_req;
struct hci_le_conn_complete;
struct hci_disconn_complete;
struct hci_encrypt_change;
-struct ble_hci_ack;
+struct ble_hs_hci_ack;
struct ble_hs_adv;
STATS_SECT_START(ble_gap_stats)
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/net/nimble/host/src/ble_gattc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gattc.c b/net/nimble/host/src/ble_gattc.c
index 49c432f..84ecff3 100644
--- a/net/nimble/host/src/ble_gattc.c
+++ b/net/nimble/host/src/ble_gattc.c
@@ -3754,7 +3754,9 @@ ble_gattc_write_reliable_rx_prep(struct ble_gattc_proc *proc,
}
if (proc->write_reliable.cur_attr >= proc->write_reliable.num_attrs) {
- /* Expecting an execute write response, not a prepare write response. */
+ /* Expecting an execute write response, not a prepare write
+ * response.
+ */
rc = BLE_HS_EBADDATA;
goto err;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/net/nimble/host/src/ble_hci_cmd.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hci_cmd.c b/net/nimble/host/src/ble_hci_cmd.c
deleted file mode 100644
index 53fe726..0000000
--- a/net/nimble/host/src/ble_hci_cmd.c
+++ /dev/null
@@ -1,320 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-#include <stdint.h>
-#include <string.h>
-#include <errno.h>
-#include <stdio.h>
-#include "os/os.h"
-#include "nimble/ble_hci_trans.h"
-#include "ble_hs_priv.h"
-#include "host_dbg_priv.h"
-
-#define BLE_HCI_CMD_TIMEOUT (OS_TICKS_PER_SEC)
-
-static struct os_mutex ble_hci_cmd_mutex;
-static struct os_sem ble_hci_cmd_sem;
-
-static uint8_t *ble_hci_cmd_ack;
-
-#if PHONY_HCI_ACKS
-static ble_hci_cmd_phony_ack_fn *ble_hci_cmd_phony_ack_cb;
-#endif
-
-#if PHONY_HCI_ACKS
-void
-ble_hci_set_phony_ack_cb(ble_hci_cmd_phony_ack_fn *cb)
-{
- ble_hci_cmd_phony_ack_cb = cb;
-}
-#endif
-
-static void
-ble_hci_cmd_lock(void)
-{
- int rc;
-
- rc = os_mutex_pend(&ble_hci_cmd_mutex, 0xffffffff);
- BLE_HS_DBG_ASSERT_EVAL(rc == 0 || rc == OS_NOT_STARTED);
-}
-
-static void
-ble_hci_cmd_unlock(void)
-{
- int rc;
-
- rc = os_mutex_release(&ble_hci_cmd_mutex);
- BLE_HS_DBG_ASSERT_EVAL(rc == 0 || rc == OS_NOT_STARTED);
-}
-
-static int
-ble_hci_cmd_rx_cmd_complete(uint8_t event_code, uint8_t *data, int len,
- struct ble_hci_ack *out_ack)
-{
- uint16_t opcode;
- uint8_t *params;
- uint8_t params_len;
- uint8_t num_pkts;
-
- if (len < BLE_HCI_EVENT_CMD_COMPLETE_HDR_LEN) {
- return BLE_HS_ECONTROLLER;
- }
-
- num_pkts = data[2];
- opcode = le16toh(data + 3);
- params = data + 5;
-
- /* XXX: Process num_pkts field. */
- (void)num_pkts;
-
- out_ack->bha_opcode = opcode;
-
- params_len = len - BLE_HCI_EVENT_CMD_COMPLETE_HDR_LEN;
- if (params_len > 0) {
- out_ack->bha_status = BLE_HS_HCI_ERR(params[0]);
- } else if (opcode == BLE_HCI_OPCODE_NOP) {
- out_ack->bha_status = 0;
- } else {
- out_ack->bha_status = BLE_HS_ECONTROLLER;
- }
-
- /* Don't include the status byte in the parameters blob. */
- if (params_len > 1) {
- out_ack->bha_params = params + 1;
- out_ack->bha_params_len = params_len - 1;
- } else {
- out_ack->bha_params = NULL;
- out_ack->bha_params_len = 0;
- }
-
- return 0;
-}
-
-static int
-ble_hci_cmd_rx_cmd_status(uint8_t event_code, uint8_t *data, int len,
- struct ble_hci_ack *out_ack)
-{
- uint16_t opcode;
- uint8_t num_pkts;
- uint8_t status;
-
- if (len < BLE_HCI_EVENT_CMD_STATUS_LEN) {
- return BLE_HS_ECONTROLLER;
- }
-
- status = data[2];
- num_pkts = data[3];
- opcode = le16toh(data + 4);
-
- /* XXX: Process num_pkts field. */
- (void)num_pkts;
-
- out_ack->bha_opcode = opcode;
- out_ack->bha_params = NULL;
- out_ack->bha_params_len = 0;
- out_ack->bha_status = BLE_HS_HCI_ERR(status);
-
- return 0;
-}
-
-static int
-ble_hci_cmd_process_ack(uint16_t expected_opcode,
- uint8_t *params_buf, uint8_t params_buf_len,
- struct ble_hci_ack *out_ack)
-{
- uint8_t event_code;
- uint8_t param_len;
- uint8_t event_len;
- int rc;
-
- BLE_HS_DBG_ASSERT(ble_hci_cmd_ack != NULL);
-
- /* Count events received */
- STATS_INC(ble_hs_stats, hci_event);
-
- /* Display to console */
- host_hci_dbg_event_disp(ble_hci_cmd_ack);
-
- event_code = ble_hci_cmd_ack[0];
- param_len = ble_hci_cmd_ack[1];
- event_len = param_len + 2;
-
- /* Clear ack fields up front to silence spurious gcc warnings. */
- memset(out_ack, 0, sizeof *out_ack);
-
- switch (event_code) {
- case BLE_HCI_EVCODE_COMMAND_COMPLETE:
- rc = ble_hci_cmd_rx_cmd_complete(event_code, ble_hci_cmd_ack,
- event_len, out_ack);
- break;
-
- case BLE_HCI_EVCODE_COMMAND_STATUS:
- rc = ble_hci_cmd_rx_cmd_status(event_code, ble_hci_cmd_ack,
- event_len, out_ack);
- break;
-
- default:
- BLE_HS_DBG_ASSERT(0);
- rc = BLE_HS_EUNKNOWN;
- break;
- }
-
- if (rc == 0) {
- if (params_buf == NULL) {
- out_ack->bha_params_len = 0;
- } else {
- if (out_ack->bha_params_len > params_buf_len) {
- out_ack->bha_params_len = params_buf_len;
- rc = BLE_HS_ECONTROLLER;
- }
- memcpy(params_buf, out_ack->bha_params, out_ack->bha_params_len);
- }
- out_ack->bha_params = params_buf;
-
- if (out_ack->bha_opcode != expected_opcode) {
- rc = BLE_HS_ECONTROLLER;
- }
- }
-
- if (rc != 0) {
- STATS_INC(ble_hs_stats, hci_invalid_ack);
- }
-
- return rc;
-}
-
-static int
-ble_hci_cmd_wait_for_ack(void)
-{
- int rc;
-
-#if PHONY_HCI_ACKS
- if (ble_hci_cmd_phony_ack_cb == NULL) {
- rc = BLE_HS_ETIMEOUT_HCI;
- } else {
- ble_hci_cmd_ack =
- ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_CMD);
- BLE_HS_DBG_ASSERT(ble_hci_cmd_ack != NULL);
- rc = ble_hci_cmd_phony_ack_cb(ble_hci_cmd_ack, 260);
- }
-#else
- rc = os_sem_pend(&ble_hci_cmd_sem, BLE_HCI_CMD_TIMEOUT);
- switch (rc) {
- case 0:
- BLE_HS_DBG_ASSERT(ble_hci_cmd_ack != NULL);
- break;
- case OS_TIMEOUT:
- rc = BLE_HS_ETIMEOUT_HCI;
- STATS_INC(ble_hs_stats, hci_timeout);
- break;
- default:
- rc = BLE_HS_EOS;
- break;
- }
-#endif
-
- return rc;
-}
-
-int
-ble_hci_cmd_tx(void *cmd, void *evt_buf, uint8_t evt_buf_len,
- uint8_t *out_evt_buf_len)
-{
- struct ble_hci_ack ack;
- uint16_t opcode;
- int rc;
-
- opcode = le16toh((uint8_t *)cmd);
-
- BLE_HS_DBG_ASSERT(ble_hci_cmd_ack == NULL);
- ble_hci_cmd_lock();
-
- rc = host_hci_cmd_send_buf(cmd);
- if (rc != 0) {
- goto done;
- }
-
- rc = ble_hci_cmd_wait_for_ack();
- if (rc != 0) {
- ble_hs_sched_reset(rc);
- goto done;
- }
-
- rc = ble_hci_cmd_process_ack(opcode, evt_buf, evt_buf_len, &ack);
- if (rc != 0) {
- ble_hs_sched_reset(rc);
- goto done;
- }
-
- if (out_evt_buf_len != NULL) {
- *out_evt_buf_len = ack.bha_params_len;
- }
-
- rc = ack.bha_status;
-
-done:
- if (ble_hci_cmd_ack != NULL) {
- ble_hci_trans_buf_free(ble_hci_cmd_ack);
- ble_hci_cmd_ack = NULL;
- }
-
- ble_hci_cmd_unlock();
- return rc;
-}
-
-int
-ble_hci_cmd_tx_empty_ack(void *cmd)
-{
- int rc;
-
- rc = ble_hci_cmd_tx(cmd, NULL, 0, NULL);
- if (rc != 0) {
- return rc;
- }
-
- return 0;
-}
-
-void
-ble_hci_cmd_rx_ack(uint8_t *ack_ev)
-{
- if (ble_hci_cmd_sem.sem_tokens != 0) {
- /* This ack is unexpected; ignore it. */
- ble_hci_trans_buf_free(ack_ev);
- return;
- }
- BLE_HS_DBG_ASSERT(ble_hci_cmd_ack == NULL);
-
- /* Unblock the application now that the HCI command buffer is populated
- * with the acknowledgement.
- */
- ble_hci_cmd_ack = ack_ev;
- os_sem_release(&ble_hci_cmd_sem);
-}
-
-void
-ble_hci_cmd_init(void)
-{
- int rc;
-
- rc = os_sem_init(&ble_hci_cmd_sem, 0);
- BLE_HS_DBG_ASSERT_EVAL(rc == 0);
-
- rc = os_mutex_init(&ble_hci_cmd_mutex);
- BLE_HS_DBG_ASSERT_EVAL(rc == 0);
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/net/nimble/host/src/ble_hci_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hci_priv.h b/net/nimble/host/src/ble_hci_priv.h
deleted file mode 100644
index 7bc019f..0000000
--- a/net/nimble/host/src/ble_hci_priv.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-#ifndef H_BLE_HCI_PRIV_
-#define H_BLE_HCI_PRIV_
-
-struct ble_hci_ack {
- int bha_status; /* A BLE_HS_E<...> error; NOT a naked HCI code. */
- uint8_t *bha_params;
- int bha_params_len;
- uint16_t bha_opcode;
- uint8_t bha_hci_handle;
-};
-
-int ble_hci_cmd_tx(void *cmd, void *evt_buf, uint8_t evt_buf_len,
- uint8_t *out_evt_buf_len);
-int ble_hci_cmd_tx_empty_ack(void *cmd);
-void ble_hci_cmd_rx_ack(uint8_t *ack_ev);
-void ble_hci_cmd_init(void);
-
-#if PHONY_HCI_ACKS
-typedef int ble_hci_cmd_phony_ack_fn(uint8_t *ack, int ack_buf_len);
-void ble_hci_set_phony_ack_cb(ble_hci_cmd_phony_ack_fn *cb);
-#endif
-
-int ble_hci_util_read_adv_tx_pwr(int8_t *out_pwr);
-int ble_hci_util_rand(void *dst, int len);
-int ble_hci_util_read_rssi(uint16_t conn_handle, int8_t *out_rssi);
-int ble_hci_util_set_random_addr(const uint8_t *addr);
-int ble_hci_util_set_data_len(uint16_t conn_handle, uint16_t tx_octets,
- uint16_t tx_time);
-int ble_hci_util_data_hdr_strip(struct os_mbuf *om,
- struct hci_data_hdr *out_hdr);
-
-#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/net/nimble/host/src/ble_hci_util.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hci_util.c b/net/nimble/host/src/ble_hci_util.c
deleted file mode 100644
index caf36e2..0000000
--- a/net/nimble/host/src/ble_hci_util.c
+++ /dev/null
@@ -1,178 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-#include <string.h>
-#include "nimble/hci_common.h"
-#include "host/host_hci.h"
-#include "ble_hs_priv.h"
-
-int
-ble_hci_util_read_adv_tx_pwr(int8_t *out_tx_pwr)
-{
- uint8_t buf[BLE_HCI_CMD_HDR_LEN];
- uint8_t params_len;
- int rc;
-
- host_hci_cmd_build_read_adv_pwr(buf, sizeof buf);
- rc = ble_hci_cmd_tx(buf, out_tx_pwr, 1, ¶ms_len);
- if (rc != 0) {
- return rc;
- }
-
- if (params_len != 1 ||
- *out_tx_pwr < BLE_HCI_ADV_CHAN_TXPWR_MIN ||
- *out_tx_pwr > BLE_HCI_ADV_CHAN_TXPWR_MAX) {
-
- return BLE_HS_ECONTROLLER;
- }
-
- return 0;
-}
-
-int
-ble_hci_util_rand(void *dst, int len)
-{
- uint8_t rsp_buf[BLE_HCI_LE_RAND_LEN];
- uint8_t req_buf[BLE_HCI_CMD_HDR_LEN];
- uint8_t params_len;
- uint8_t *u8ptr;
- int chunk_sz;
- int rc;
-
- host_hci_cmd_build_le_rand(req_buf, sizeof req_buf);
-
- u8ptr = dst;
- while (len > 0) {
- rc = ble_hci_cmd_tx(req_buf, rsp_buf, sizeof rsp_buf, ¶ms_len);
- if (rc != 0) {
- return rc;
- }
- if (params_len != sizeof rsp_buf) {
- return BLE_HS_ECONTROLLER;
- }
-
- chunk_sz = min(len, sizeof rsp_buf);
- memcpy(u8ptr, rsp_buf, chunk_sz);
-
- len -= chunk_sz;
- u8ptr += chunk_sz;
- }
-
- return 0;
-}
-
-int
-ble_hci_util_read_rssi(uint16_t conn_handle, int8_t *out_rssi)
-{
- uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_READ_RSSI_LEN];
- uint8_t params[BLE_HCI_READ_RSSI_ACK_PARAM_LEN];
- uint16_t params_conn_handle;
- uint8_t params_len;
- int rc;
-
- host_hci_cmd_build_read_rssi(conn_handle, buf, sizeof buf);
- rc = ble_hci_cmd_tx(buf, params, sizeof params, ¶ms_len);
- if (rc != 0) {
- return rc;
- }
-
- if (params_len != BLE_HCI_READ_RSSI_ACK_PARAM_LEN) {
- return BLE_HS_ECONTROLLER;
- }
-
- params_conn_handle = le16toh(params + 0);
- if (params_conn_handle != conn_handle) {
- return BLE_HS_ECONTROLLER;
- }
-
- *out_rssi = params[2];
-
- return 0;
-}
-
-int
-ble_hci_util_set_random_addr(const uint8_t *addr)
-{
- uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_RAND_ADDR_LEN];
- int rc;
-
- /* set the address in the controller */
-
- rc = host_hci_cmd_build_set_random_addr(addr, buf, sizeof(buf));
- if (rc != 0) {
- return rc;
- }
-
- rc = ble_hci_cmd_tx_empty_ack(buf);
- return rc;
-}
-
-int
-ble_hci_util_set_data_len(uint16_t conn_handle, uint16_t tx_octets,
- uint16_t tx_time)
-{
-
- uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_DATALEN_LEN];
- uint8_t params[BLE_HCI_SET_DATALEN_ACK_PARAM_LEN];
- uint16_t params_conn_handle;
- uint8_t params_len;
- int rc;
-
- rc = host_hci_cmd_build_set_data_len(conn_handle, tx_octets, tx_time, buf,
- sizeof buf);
- if (rc != 0) {
- return BLE_HS_HCI_ERR(rc);
- }
-
- rc = ble_hci_cmd_tx(buf, params, BLE_HCI_SET_DATALEN_ACK_PARAM_LEN,
- ¶ms_len);
- if (rc != 0) {
- return rc;
- }
-
- if (params_len != BLE_HCI_SET_DATALEN_ACK_PARAM_LEN) {
- return BLE_HS_ECONTROLLER;
- }
-
- params_conn_handle = le16toh(params + 0);
- if (params_conn_handle != conn_handle) {
- return BLE_HS_ECONTROLLER;
- }
-
- return 0;
-}
-
-int
-ble_hci_util_data_hdr_strip(struct os_mbuf *om, struct hci_data_hdr *out_hdr)
-{
- int rc;
-
- rc = os_mbuf_copydata(om, 0, BLE_HCI_DATA_HDR_SZ, out_hdr);
- if (rc != 0) {
- return BLE_HS_ECONTROLLER;
- }
-
- /* Strip HCI ACL data header from the front of the packet. */
- os_mbuf_adj(om, BLE_HCI_DATA_HDR_SZ);
-
- out_hdr->hdh_handle_pb_bc = le16toh(&out_hdr->hdh_handle_pb_bc);
- out_hdr->hdh_len = le16toh(&out_hdr->hdh_len);
-
- return 0;
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/net/nimble/host/src/ble_hs.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs.c b/net/nimble/host/src/ble_hs.c
index 95befc0..8035b49 100644
--- a/net/nimble/host/src/ble_hs.c
+++ b/net/nimble/host/src/ble_hs.c
@@ -24,7 +24,6 @@
#include "util/tpq.h"
#include "os/os.h"
#include "nimble/ble_hci_trans.h"
-#include "host/host_hci.h"
#include "ble_hs_priv.h"
/**
@@ -173,7 +172,7 @@ ble_hs_process_rx_data_queue(void)
struct os_mbuf *om;
while ((om = os_mqueue_get(&ble_hs_rx_q)) != NULL) {
- host_hci_acl_process(om);
+ ble_hs_hci_evt_acl_process(om);
}
}
@@ -370,7 +369,7 @@ ble_hs_event_handle(void *unused)
rc = os_memblock_put(&ble_hs_hci_ev_pool, ev);
BLE_HS_DBG_ASSERT_EVAL(rc == 0);
- host_hci_evt_process(hci_evt);
+ ble_hs_hci_evt_process(hci_evt);
break;
case BLE_HS_EVENT_TX_NOTIFICATIONS:
@@ -579,7 +578,7 @@ ble_hs_init(struct os_eventq *app_evq, struct ble_hs_cfg *cfg)
goto err;
}
- ble_hci_cmd_init();
+ ble_hs_hci_init();
rc = ble_hs_conn_init();
if (rc != 0) {
@@ -642,7 +641,7 @@ ble_hs_init(struct os_eventq *app_evq, struct ble_hs_cfg *cfg)
#endif
/* Configure the HCI transport to communicate with a host. */
- ble_hci_trans_cfg_hs(host_hci_evt_rx, NULL, ble_hs_rx_data, NULL);
+ ble_hci_trans_cfg_hs(ble_hs_hci_rx_evt, NULL, ble_hs_rx_data, NULL);
return 0;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/net/nimble/host/src/ble_hs_adv.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_adv.c b/net/nimble/host/src/ble_hs_adv.c
index 4fdc529..da0d5c1 100644
--- a/net/nimble/host/src/ble_hs_adv.c
+++ b/net/nimble/host/src/ble_hs_adv.c
@@ -214,7 +214,7 @@ ble_hs_adv_set_fields(const struct ble_hs_adv_fields *adv_fields,
* the explicitly specified value.
*/
if (adv_fields->tx_pwr_lvl == BLE_HS_ADV_TX_PWR_LVL_AUTO) {
- rc = ble_hci_util_read_adv_tx_pwr(&tx_pwr_lvl);
+ rc = ble_hs_hci_util_read_adv_tx_pwr(&tx_pwr_lvl);
if (rc != 0) {
return rc;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/net/nimble/host/src/ble_hs_conn.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_conn.c b/net/nimble/host/src/ble_hs_conn.c
index 164cc6d..76196ef 100644
--- a/net/nimble/host/src/ble_hs_conn.c
+++ b/net/nimble/host/src/ble_hs_conn.c
@@ -20,7 +20,6 @@
#include <string.h>
#include <errno.h>
#include "os/os.h"
-#include "host/host_hci.h"
#include "host/ble_hs_id.h"
#include "ble_hs_priv.h"
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/net/nimble/host/src/ble_hs_dbg.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_dbg.c b/net/nimble/host/src/ble_hs_dbg.c
new file mode 100644
index 0000000..bb6ebdf
--- /dev/null
+++ b/net/nimble/host/src/ble_hs_dbg.c
@@ -0,0 +1,509 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+#include <stdint.h>
+#include <stdio.h>
+#include <assert.h>
+#include <string.h>
+#include "os/os.h"
+#include "console/console.h"
+#include "nimble/hci_common.h"
+#include "nimble/ble_hci_trans.h"
+#include "ble_hs_priv.h"
+
+static void
+ble_hs_dbg_le_event_disp(uint8_t subev, uint8_t len, uint8_t *evdata)
+{
+ int8_t rssi;
+ uint8_t advlen;
+ uint8_t status;
+ int i;
+ int imax;
+ uint8_t *dptr;
+ char *adv_ptr;
+ char adv_data_buf[32];
+
+ switch (subev) {
+ case BLE_HCI_LE_SUBEV_ENH_CONN_COMPLETE:
+ case BLE_HCI_LE_SUBEV_CONN_COMPLETE:
+ status = evdata[0];
+ if (status == BLE_ERR_SUCCESS) {
+ BLE_HS_LOG(DEBUG, "LE connection complete. handle=%u role=%u "
+ "paddrtype=%u addr=%x.%x.%x.%x.%x.%x ",
+ le16toh(evdata + 1), evdata[3], evdata[4],
+ evdata[10], evdata[9], evdata[8], evdata[7],
+ evdata[6], evdata[5]);
+
+ evdata += 11;
+ if (subev == BLE_HCI_LE_SUBEV_ENH_CONN_COMPLETE) {
+ BLE_HS_LOG(DEBUG, "local_rpa=%x.%x.%x.%x.%x.%x "
+ "peer_rpa=%x.%x.%x.%x.%x.%x ",
+ evdata[5], evdata[4], evdata[3], evdata[2],
+ evdata[1], evdata[0],
+ evdata[11], evdata[10], evdata[9], evdata[8],
+ evdata[7], evdata[6]);
+
+ evdata += 12;
+ }
+ BLE_HS_LOG(DEBUG, "itvl=%u latency=%u spvn_tmo=%u mca=%u\n",
+ le16toh(evdata), le16toh(evdata + 2),
+ le16toh(evdata + 4), evdata[6]);
+ } else {
+ BLE_HS_LOG(DEBUG, "LE connection complete. FAIL (status=%u)\n",
+ status);
+ }
+ break;
+ case BLE_HCI_LE_SUBEV_ADV_RPT:
+ advlen = evdata[9];
+ rssi = evdata[10 + advlen];
+ BLE_HS_LOG(DEBUG, "LE advertising report. len=%u num=%u evtype=%u "
+ "addrtype=%u addr=%x.%x.%x.%x.%x.%x advlen=%u "
+ "rssi=%d\n", len, evdata[0], evdata[1], evdata[2],
+ evdata[8], evdata[7], evdata[6], evdata[5],
+ evdata[4], evdata[3], advlen, rssi);
+ if (advlen) {
+ dptr = &evdata[10];
+ while (advlen > 0) {
+ memset(adv_data_buf, 0, 32);
+ imax = advlen;
+ if (imax > 8) {
+ imax = 8;
+ }
+ adv_ptr = &adv_data_buf[0];
+ for (i = 0; i < imax; ++i) {
+ snprintf(adv_ptr, 4, "%02x ", *dptr);
+ adv_ptr += 3;
+ ++dptr;
+ }
+ advlen -= imax;
+ BLE_HS_LOG(DEBUG, "%s\n", adv_data_buf);
+ }
+ }
+ break;
+ case BLE_HCI_LE_SUBEV_CONN_UPD_COMPLETE:
+ status = evdata[0];
+ if (status == BLE_ERR_SUCCESS) {
+ BLE_HS_LOG(DEBUG, "LE Connection Update Complete. handle=%u "
+ "itvl=%u latency=%u timeout=%u\n",
+ le16toh(evdata + 1), le16toh(evdata + 3),
+ le16toh(evdata + 5), le16toh(evdata + 7));
+ } else {
+ BLE_HS_LOG(DEBUG, "LE Connection Update Complete. FAIL "
+ "(status=%u)\n", status);
+ }
+ break;
+
+ case BLE_HCI_LE_SUBEV_DATA_LEN_CHG:
+ BLE_HS_LOG(DEBUG, "LE Data Length Change. handle=%u max_tx_bytes=%u "
+ "max_tx_time=%u max_rx_bytes=%u max_rx_time=%u\n",
+ le16toh(evdata), le16toh(evdata + 2),
+ le16toh(evdata + 4), le16toh(evdata + 6),
+ le16toh(evdata + 8));
+ break;
+ case BLE_HCI_LE_SUBEV_REM_CONN_PARM_REQ:
+ BLE_HS_LOG(DEBUG, "LE Remote Connection Parameter Request. handle=%u "
+ "min_itvl=%u max_itvl=%u latency=%u timeout=%u\n",
+ le16toh(evdata), le16toh(evdata + 2),
+ le16toh(evdata + 4), le16toh(evdata + 6),
+ le16toh(evdata + 8));
+ break;
+
+ case BLE_HCI_LE_SUBEV_RD_REM_USED_FEAT:
+ status = evdata[0];
+ if (status == BLE_ERR_SUCCESS) {
+ BLE_HS_LOG(DEBUG, "LE Remote Used Features. handle=%u feat=",
+ le16toh(evdata + 1));
+ for (i = 0; i < BLE_HCI_RD_LOC_SUPP_FEAT_RSPLEN; ++i) {
+ BLE_HS_LOG(DEBUG, "%02x ", evdata[3 + i]);
+ }
+ BLE_HS_LOG(DEBUG, "\n");
+ } else {
+ BLE_HS_LOG(DEBUG, "LE Remote Used Features. FAIL (status=%u)\n",
+ status);
+ }
+ break;
+
+ case BLE_HCI_LE_SUBEV_LT_KEY_REQ:
+ BLE_HS_LOG(DEBUG, "LE LTK Req. handle=%u rand=%lx%lx encdiv=%u\n",
+ le16toh(evdata), le32toh(evdata + 6),
+ le32toh(evdata + 2), le16toh(evdata + 10));
+ break;
+
+ default:
+ BLE_HS_LOG(DEBUG, "\tUnknown LE event\n");
+ break;
+ }
+}
+
+/**
+ * Display a disconnection complete command.
+ *
+ *
+ * @param evdata
+ * @param len
+ */
+static void
+ble_hs_dbg_disconn_comp_disp(uint8_t *evdata, uint8_t len)
+{
+ uint8_t status;
+ uint8_t reason;
+ uint16_t handle;
+
+ status = evdata[0];
+ handle = le16toh(evdata + 1);
+ /* Ignore reason if status is not success */
+ if (status != BLE_ERR_SUCCESS) {
+ reason = 0;
+ } else {
+ reason = evdata[3];
+ }
+ BLE_HS_LOG(DEBUG, "Disconnection Complete: status=%u handle=%u "
+ "reason=%u\n", status, handle, reason);
+}
+
+/**
+ * Display an encryption change event or encryption key refresh event
+ *
+ * @param evdata
+ * @param len
+ */
+static void
+ble_hs_dbg_encrypt_chg_disp(uint8_t *evdata, uint8_t len)
+{
+ uint8_t status;
+ uint8_t enabled;
+ uint16_t handle;
+
+ status = evdata[0];
+ handle = le16toh(evdata + 1);
+
+ /* Ignore reason if status is not success */
+ if (status != BLE_ERR_SUCCESS) {
+ enabled = 0;
+ } else {
+ enabled = evdata[3];
+ }
+ BLE_HS_LOG(DEBUG, "Encrypt change: status=%u handle=%u state=%u\n",
+ status, handle, enabled);
+}
+
+/**
+ * Display an encryption encryption key refresh event
+ *
+ * @param evdata
+ * @param len
+ */
+static void
+ble_hs_dbg_encrypt_refresh_disp(uint8_t *evdata, uint8_t len)
+{
+ uint8_t status;
+ uint16_t handle;
+
+ status = evdata[0];
+ handle = le16toh(evdata + 1);
+
+ BLE_HS_LOG(DEBUG, "Encrypt key refresh: status=%u handle=%u\n",
+ status, handle);
+}
+
+/**
+ * Display a version information event
+ *
+ * @param evdata
+ * @param len
+ */
+static void
+ble_hs_dbg_rd_rem_ver_disp(uint8_t *evdata, uint8_t len)
+{
+ BLE_HS_LOG(DEBUG, "Remote Version Info: status=%u handle=%u vers_nr=%u "
+ "compid=%u subver=%u\n",
+ evdata[0], le16toh(evdata + 1), evdata[3],
+ le16toh(evdata + 4), le16toh(evdata + 6));
+}
+
+/**
+ * Display the number of completed packets event
+ *
+ * @param evdata
+ * @param len
+ */
+static void
+ble_hs_dbg_num_comp_pkts_disp(uint8_t *evdata, uint8_t len)
+{
+ uint8_t handles;
+ uint8_t *handle_ptr;
+ uint8_t *pkt_ptr;
+ uint16_t handle;
+ uint16_t pkts;
+
+ handles = evdata[0];
+ if (len != ((handles * 4) + 1)) {
+ BLE_HS_LOG(DEBUG, "ERR: Number of Completed Packets bad length: "
+ "num_handles=%u len=%u\n", handles, len);
+ return;
+
+ }
+
+ BLE_HS_LOG(DEBUG, "Number of Completed Packets: num_handles=%u\n",
+ handles);
+ if (handles) {
+ handle_ptr = evdata + 1;
+ pkt_ptr = handle_ptr + (2 * handles);
+ while (handles) {
+ handle = le16toh(handle_ptr);
+ handle_ptr += 2;
+ pkts = le16toh(pkt_ptr);
+ pkt_ptr += 2;
+ BLE_HS_LOG(DEBUG, "handle:%u pkts:%u\n", handle, pkts);
+ --handles;
+ }
+ }
+}
+
+/**
+ * Display the authenticated payload timeout event
+ *
+ * @param evdata
+ * @param len
+ */
+static void
+ble_hs_dbg_auth_pyld_tmo_disp(uint8_t *evdata, uint8_t len)
+{
+ uint16_t handle;
+
+ if (len != sizeof(uint16_t)) {
+ BLE_HS_LOG(DEBUG, "ERR: AuthPyldTmoEvent bad length %u\n", len);
+ return;
+
+ }
+
+ handle = le16toh(evdata);
+ BLE_HS_LOG(DEBUG, "AuthPyldTmo: handle=%u\n", handle);
+}
+
+
+static void
+ble_hs_dbg_cmd_comp_info_params(uint8_t status, uint8_t ocf, uint8_t *evdata)
+{
+ int i;
+ uint8_t *dptr;
+
+ if (status != BLE_ERR_SUCCESS) {
+ return;
+ }
+
+ switch (ocf) {
+ case BLE_HCI_OCF_IP_RD_LOCAL_VER:
+ BLE_HS_LOG(DEBUG, "hci_ver=%u hci_rev=%u lmp_ver=%u mfrg=%u "
+ "lmp_subver=%u",
+ evdata[0], le16toh(evdata + 1), evdata[3],
+ le16toh(evdata + 4), le16toh(evdata + 6));
+ break;
+ case BLE_HCI_OCF_IP_RD_LOC_SUPP_CMD:
+ BLE_HS_LOG(DEBUG, "supp_cmds=");
+ dptr = evdata;
+ for (i = 0; i < 8; ++i) {
+ BLE_HS_LOG(DEBUG, "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:",
+ dptr[0], dptr[1], dptr[2], dptr[3],
+ dptr[4], dptr[5], dptr[6], dptr[7]);
+ dptr += 8;
+ }
+ break;
+ case BLE_HCI_OCF_IP_RD_LOC_SUPP_FEAT:
+ BLE_HS_LOG(DEBUG, "supp_feat=0x%lx%08lx",
+ le32toh(evdata + 4), le32toh(evdata));
+ break;
+ case BLE_HCI_OCF_IP_RD_BD_ADDR:
+ BLE_HS_LOG(DEBUG, "bd_addr=%x:%x:%x:%x:%x:%x",
+ evdata[5], evdata[4], evdata[3],
+ evdata[2], evdata[1], evdata[0]);
+ break;
+ default:
+ break;
+ }
+}
+
+static void
+ble_hs_dbg_cmd_complete_disp(uint8_t *evdata, uint8_t len)
+{
+ uint8_t cmd_pkts;
+ uint8_t ogf;
+ uint8_t ocf;
+ uint8_t status;
+ uint16_t opcode;
+
+ if (len < 3) {
+ BLE_HS_LOG(DEBUG, "Invalid command complete: len=%d "
+ "(expected >= 3)", len);
+ goto done;
+ }
+
+ cmd_pkts = evdata[0];
+ opcode = le16toh(evdata + 1);
+ ogf = BLE_HCI_OGF(opcode);
+ ocf = BLE_HCI_OCF(opcode);
+
+ BLE_HS_LOG(DEBUG, "Command complete: cmd_pkts=%u ogf=0x%x ocf=0x%x",
+ cmd_pkts, ogf, ocf);
+
+ if (len == 3) {
+ goto done;
+ }
+
+ status = evdata[3];
+ BLE_HS_LOG(DEBUG, " status=%u ", status);
+
+ /* Move past header and status */
+ evdata += 4;
+
+ /* Display parameters based on command. */
+ switch (ogf) {
+ case BLE_HCI_OGF_INFO_PARAMS:
+ ble_hs_dbg_cmd_comp_info_params(status, ocf, evdata);
+ break;
+ case BLE_HCI_OGF_STATUS_PARAMS:
+ switch (ocf) {
+ case BLE_HCI_OCF_RD_RSSI:
+ BLE_HS_LOG(DEBUG, "handle=%u rssi=%d", le16toh(evdata),
+ (int8_t)evdata[2]);
+ break;
+ default:
+ break;
+ }
+ break;
+ case BLE_HCI_OGF_LE:
+ switch (ocf) {
+ case BLE_HCI_OCF_LE_RD_CHAN_MAP:
+ BLE_HS_LOG(DEBUG, "handle=%u chanmap=%x.%x.%x.%x.%x",
+ le16toh(evdata), evdata[2], evdata[3], evdata[4],
+ evdata[5], evdata[6]);
+ break;
+ case BLE_HCI_OCF_LE_RD_MAX_DATA_LEN:
+ BLE_HS_LOG(DEBUG, "txoct=%u txtime=%u rxoct=%u rxtime=%u",
+ le16toh(evdata), le16toh(evdata + 2),
+ le16toh(evdata + 4), le16toh(evdata + 6));
+ break;
+ case BLE_HCI_OCF_LE_RD_SUPP_STATES:
+ BLE_HS_LOG(DEBUG, "states=0x%lx%08lx", le32toh(evdata + 4),
+ le32toh(evdata));
+ break;
+ case BLE_HCI_OCF_LE_ENCRYPT:
+ BLE_HS_LOG(DEBUG, "encdata=0x%02x%02x%02x%02x%02x%02x%02x%02x",
+ evdata[15], evdata[14], evdata[13], evdata[12],
+ evdata[11], evdata[10], evdata[9], evdata[8]);
+ BLE_HS_LOG(DEBUG, "%02x%02x%02x%02x%02x%02x%02x%02x",
+ evdata[7], evdata[6], evdata[5], evdata[4],
+ evdata[3], evdata[2], evdata[1], evdata[0]);
+
+ break;
+ case BLE_HCI_OCF_LE_RAND:
+ BLE_HS_LOG(DEBUG, "rand=0x%02x%02x%02x%02x%02x%02x%02x%02x",
+ evdata[0], evdata[1], evdata[2], evdata[3],
+ evdata[4], evdata[5], evdata[6], evdata[7]);
+ break;
+ case BLE_HCI_OCF_LE_RD_SUGG_DEF_DATA_LEN:
+ BLE_HS_LOG(DEBUG, "txoct=%u txtime=%u", le16toh(evdata),
+ le16toh(evdata + 2));
+ break;
+ case BLE_HCI_OCF_LE_LT_KEY_REQ_REPLY:
+ case BLE_HCI_OCF_LE_LT_KEY_REQ_NEG_REPLY:
+ case BLE_HCI_OCF_LE_SET_DATA_LEN:
+ BLE_HS_LOG(DEBUG, "handle=%u", le16toh(evdata));
+ break;
+ default:
+ break;
+ }
+ break;
+ default:
+ break;
+ }
+
+done:
+ BLE_HS_LOG(DEBUG, "\n");
+}
+
+static void
+ble_hs_dbg_cmd_status_disp(uint8_t *evdata, uint8_t len)
+{
+ uint8_t ogf;
+ uint8_t ocf;
+ uint16_t opcode;
+
+ opcode = le16toh(evdata + 2);
+ ogf = BLE_HCI_OGF(opcode);
+ ocf = BLE_HCI_OCF(opcode);
+
+ BLE_HS_LOG(DEBUG, "Command Status: status=%u cmd_pkts=%u ocf=0x%x "
+ "ogf=0x%x\n", evdata[0], evdata[1], ocf, ogf);
+}
+
+void
+ble_hs_dbg_event_disp(uint8_t *evbuf)
+{
+#if LOG_LEVEL > LOG_LEVEL_DEBUG
+ return;
+#endif
+
+ uint8_t *evdata;
+ uint8_t evcode;
+ uint8_t len;
+
+ /* Extract event code and length; move pointer to event parameter data */
+ evcode = evbuf[0];
+ len = evbuf[1];
+ evdata = evbuf + BLE_HCI_EVENT_HDR_LEN;
+
+ switch (evcode) {
+ case BLE_HCI_EVCODE_DISCONN_CMP:
+ ble_hs_dbg_disconn_comp_disp(evdata, len);
+ break;
+ case BLE_HCI_EVCODE_ENC_KEY_REFRESH:
+ ble_hs_dbg_encrypt_refresh_disp(evdata, len);
+ break;
+ case BLE_HCI_EVCODE_ENCRYPT_CHG:
+ ble_hs_dbg_encrypt_chg_disp(evdata, len);
+ break;
+ case BLE_HCI_EVCODE_RD_REM_VER_INFO_CMP:
+ ble_hs_dbg_rd_rem_ver_disp(evdata, len);
+ break;
+ case BLE_HCI_EVCODE_COMMAND_COMPLETE:
+ ble_hs_dbg_cmd_complete_disp(evdata, len);
+ break;
+ case BLE_HCI_EVCODE_COMMAND_STATUS:
+ ble_hs_dbg_cmd_status_disp(evdata, len);
+ break;
+ case BLE_HCI_EVCODE_NUM_COMP_PKTS:
+ ble_hs_dbg_num_comp_pkts_disp(evdata, len);
+ break;
+ case BLE_HCI_EVCODE_LE_META:
+ ble_hs_dbg_le_event_disp(evdata[0], len, evdata + 1);
+ break;
+ case BLE_HCI_EVCODE_AUTH_PYLD_TMO:
+ ble_hs_dbg_auth_pyld_tmo_disp(evdata, len);
+ break;
+ default:
+ BLE_HS_LOG(DEBUG, "Unknown event 0x%x len=%u\n", evcode, len);
+ break;
+ }
+}
+
+void
+ble_hs_dbg_set_sync_state(uint8_t sync_state)
+{
+ ble_hs_sync_state = sync_state;
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/net/nimble/host/src/ble_hs_dbg_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_dbg_priv.h b/net/nimble/host/src/ble_hs_dbg_priv.h
new file mode 100644
index 0000000..cf8d203
--- /dev/null
+++ b/net/nimble/host/src/ble_hs_dbg_priv.h
@@ -0,0 +1,26 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef H_BLE_HS_DBG_PRIV_
+#define H_BLE_HS_DBG_PRIV_
+
+void ble_hs_dbg_event_disp(uint8_t *evbuf);
+void ble_hs_dbg_set_sync_state(uint8_t sync_state);
+
+#endif /* H_HOST_DBG_ */
[38/42] incubator-mynewt-core git commit: util - Functions to alloc
mempools and mbuf pools.
Posted by st...@apache.org.
util - Functions to alloc mempools and mbuf pools.
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/2e686974
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/2e686974
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/2e686974
Branch: refs/heads/sterly_refactor
Commit: 2e686974e332820a8723920431ad66f5d605f546
Parents: 8cecd61
Author: Christopher Collins <cc...@apache.org>
Authored: Mon Aug 8 15:57:20 2016 -0700
Committer: Sterling Hughes <st...@apache.org>
Committed: Tue Aug 9 16:05:21 2016 -0700
----------------------------------------------------------------------
libs/util/include/util/mem.h | 38 ++++++++++++
libs/util/src/mem.c | 126 ++++++++++++++++++++++++++++++++++++++
2 files changed, 164 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2e686974/libs/util/include/util/mem.h
----------------------------------------------------------------------
diff --git a/libs/util/include/util/mem.h b/libs/util/include/util/mem.h
new file mode 100644
index 0000000..52ddce4
--- /dev/null
+++ b/libs/util/include/util/mem.h
@@ -0,0 +1,38 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef H_UTIL_MEM_
+#define H_UTIL_MEM_
+
+struct os_mempool;
+struct os_mbuf_pool;
+
+int mem_malloc_mempool(struct os_mempool *mempool, int num_blocks,
+ int block_size, char *name, void **out_buf);
+
+int mem_malloc_mbuf_pool(struct os_mempool *mempool,
+ struct os_mbuf_pool *mbuf_pool, int num_blocks,
+ int block_size, char *name,
+ void **out_buf);
+int mem_malloc_mbufpkt_pool(struct os_mempool *mempool,
+ struct os_mbuf_pool *mbuf_pool, int num_blocks,
+ int block_size, char *name,
+ void **out_buf);
+
+#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2e686974/libs/util/src/mem.c
----------------------------------------------------------------------
diff --git a/libs/util/src/mem.c b/libs/util/src/mem.c
new file mode 100644
index 0000000..eeca71f
--- /dev/null
+++ b/libs/util/src/mem.c
@@ -0,0 +1,126 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "os/os.h"
+
+/**
+ * Mallocs a block of memory and initializes a mempool to use it.
+ *
+ * @param mempool The mempool to initialize.
+ * @param num_blocks The total number of memory blocks in the
+ * mempool.
+ * @param block_size The size of each mempool entry.
+ * @param name The name to give the mempool.
+ * @param out_buf On success, this points to the malloced memory.
+ * Pass NULL if you don't need this
+ * information.
+ *
+ * @return 0 on success;
+ * OS_ENOMEM on malloc failure;
+ * Other OS code on unexpected error.
+ */
+int
+mem_malloc_mempool(struct os_mempool *mempool, int num_blocks, int block_size,
+ char *name, void **out_buf)
+{
+ void *buf;
+ int rc;
+
+ block_size = OS_ALIGN(block_size, OS_ALIGNMENT);
+
+ if (num_blocks > 0) {
+ buf = malloc(OS_MEMPOOL_BYTES(num_blocks, block_size));
+ if (buf == NULL) {
+ return OS_ENOMEM;
+ }
+ } else {
+ buf = NULL;
+ }
+
+ rc = os_mempool_init(mempool, num_blocks, block_size, buf, name);
+ if (rc != 0) {
+ free(buf);
+ return rc;
+ }
+
+ if (out_buf != NULL) {
+ *out_buf = buf;
+ }
+
+ return 0;
+}
+
+/**
+ * Mallocs a block of memory and initializes an mbuf pool to use it.
+ *
+ * @param mempool The mempool to initialize.
+ * @param mbuf_pool The mbuf pool to initialize.
+ * @param num_blocks The total number of mbufs in the pool.
+ * @param block_size The size of each mbuf.
+ * @param name The name to give the mempool.
+ * @param out_buf On success, this points to the malloced memory.
+ * Pass NULL if you don't need this
+ * information.
+ *
+ * @return 0 on success;
+ * OS_ENOMEM on malloc failure;
+ * Other OS code on unexpected error.
+ */
+int
+mem_malloc_mbuf_pool(struct os_mempool *mempool,
+ struct os_mbuf_pool *mbuf_pool, int num_blocks,
+ int block_size, char *name,
+ void **out_buf)
+{
+ void *buf;
+ int rc;
+
+ block_size = OS_ALIGN(block_size + sizeof (struct os_mbuf), OS_ALIGNMENT);
+
+ rc = mem_malloc_mempool(mempool, num_blocks, block_size, name, &buf);
+ if (rc != 0) {
+ return rc;
+ }
+
+ rc = os_mbuf_pool_init(mbuf_pool, mempool, block_size, num_blocks);
+ if (rc != 0) {
+ free(buf);
+ return rc;
+ }
+
+ if (out_buf != NULL) {
+ *out_buf = buf;
+ }
+
+ return 0;
+}
+
+int
+mem_malloc_mbufpkt_pool(struct os_mempool *mempool,
+ struct os_mbuf_pool *mbuf_pool, int num_blocks,
+ int block_size, char *name,
+ void **out_buf)
+{
+ int rc;
+
+ rc = mem_malloc_mbuf_pool(mempool, mbuf_pool, num_blocks,
+ block_size + sizeof (struct os_mbuf_pkthdr),
+ name, out_buf);
+ return rc;
+}
[03/42] incubator-mynewt-core git commit: BLE Host - Fix unit test
SIGSEGV.
Posted by st...@apache.org.
BLE Host - Fix unit test SIGSEGV.
An array was missing a '0' terminator.
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/8cecd61d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/8cecd61d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/8cecd61d
Branch: refs/heads/sterly_refactor
Commit: 8cecd61dfd5aa38a68bd508ed8f077b9288cca9a
Parents: 004d61d
Author: Christopher Collins <cc...@apache.org>
Authored: Sun Aug 7 18:13:26 2016 -0700
Committer: Sterling Hughes <st...@apache.org>
Committed: Tue Aug 9 16:05:21 2016 -0700
----------------------------------------------------------------------
net/nimble/host/src/test/ble_hs_test_util.c | 3 +++
1 file changed, 3 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8cecd61d/net/nimble/host/src/test/ble_hs_test_util.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_test_util.c b/net/nimble/host/src/test/ble_hs_test_util.c
index 460642e..30926b6 100644
--- a/net/nimble/host/src/test/ble_hs_test_util.c
+++ b/net/nimble/host/src/test/ble_hs_test_util.c
@@ -802,6 +802,9 @@ ble_hs_test_util_set_our_irk(const uint8_t *irk, int fail_idx,
BLE_HS_TEST_UTIL_LE_OPCODE(BLE_HCI_OCF_LE_ADD_RESOLV_LIST),
ble_hs_test_util_exp_hci_status(3, fail_idx, hci_status),
},
+ {
+ 0
+ }
}));
rc = ble_hs_pvcy_set_our_irk(irk);
[26/42] incubator-mynewt-core git commit: BLE UART HCI - Remove debug
log.
Posted by st...@apache.org.
BLE UART HCI - Remove debug log.
This was accidentally included in the initial commit!
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/8f4f2cbb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/8f4f2cbb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/8f4f2cbb
Branch: refs/heads/sterly_refactor
Commit: 8f4f2cbb98118da03e77f8f8518885c306a0a978
Parents: d3f60ae
Author: Christopher Collins <cc...@apache.org>
Authored: Fri Aug 5 10:37:27 2016 -0700
Committer: Sterling Hughes <st...@apache.org>
Committed: Tue Aug 9 16:05:21 2016 -0700
----------------------------------------------------------------------
net/nimble/transport/uart/src/ble_hci_uart.c | 18 ------------------
1 file changed, 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8f4f2cbb/net/nimble/transport/uart/src/ble_hci_uart.c
----------------------------------------------------------------------
diff --git a/net/nimble/transport/uart/src/ble_hci_uart.c b/net/nimble/transport/uart/src/ble_hci_uart.c
index 98a49b6..1285f56 100755
--- a/net/nimble/transport/uart/src/ble_hci_uart.c
+++ b/net/nimble/transport/uart/src/ble_hci_uart.c
@@ -73,12 +73,6 @@ static void *ble_hci_uart_evt_buf;
static struct os_mempool ble_hci_uart_pkt_pool;
static void *ble_hci_uart_pkt_buf;
-#define BLE_HCI_UART_LOG_SZ 1024
-static uint8_t ble_hci_uart_tx_log[BLE_HCI_UART_LOG_SZ];
-static int ble_hci_uart_tx_log_sz;
-static uint8_t ble_hci_uart_rx_log[BLE_HCI_UART_LOG_SZ];
-static int ble_hci_uart_rx_log_sz;
-
/**
* An incoming or outgoing command or event.
*/
@@ -263,13 +257,6 @@ ble_hci_uart_tx_char(void *arg)
break;
}
- if (rc != -1) {
- ble_hci_uart_tx_log[ble_hci_uart_tx_log_sz++] = rc;
- if (ble_hci_uart_tx_log_sz == sizeof ble_hci_uart_tx_log) {
- ble_hci_uart_tx_log_sz = 0;
- }
- }
-
return rc;
}
@@ -410,11 +397,6 @@ ble_hci_uart_rx_acl(uint8_t data)
static int
ble_hci_uart_rx_char(void *arg, uint8_t data)
{
- ble_hci_uart_rx_log[ble_hci_uart_rx_log_sz++] = data;
- if (ble_hci_uart_rx_log_sz == sizeof ble_hci_uart_rx_log) {
- ble_hci_uart_rx_log_sz = 0;
- }
-
switch (ble_hci_uart_state.rx_type) {
case BLE_HCI_UART_H4_NONE:
return ble_hci_uart_rx_pkt_type(data);
[42/42] incubator-mynewt-core git commit: util - Fix up mem function
comments.
Posted by st...@apache.org.
util - Fix up mem function comments.
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/229927db
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/229927db
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/229927db
Branch: refs/heads/sterly_refactor
Commit: 229927dba6388fe54f48cd18ab4f2124d4a6a50f
Parents: 2521994
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Aug 9 11:16:17 2016 -0700
Committer: Sterling Hughes <st...@apache.org>
Committed: Tue Aug 9 16:05:21 2016 -0700
----------------------------------------------------------------------
libs/util/src/mem.c | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/229927db/libs/util/src/mem.c
----------------------------------------------------------------------
diff --git a/libs/util/src/mem.c b/libs/util/src/mem.c
index eeca71f..faf8234 100644
--- a/libs/util/src/mem.c
+++ b/libs/util/src/mem.c
@@ -67,7 +67,9 @@ mem_malloc_mempool(struct os_mempool *mempool, int num_blocks, int block_size,
}
/**
- * Mallocs a block of memory and initializes an mbuf pool to use it.
+ * Mallocs a block of memory and initializes an mbuf pool to use it. The
+ * specified block_size indicates the size of an mbuf acquired from the pool if
+ * it does not contain a pkthdr.
*
* @param mempool The mempool to initialize.
* @param mbuf_pool The mbuf pool to initialize.
@@ -111,6 +113,24 @@ mem_malloc_mbuf_pool(struct os_mempool *mempool,
return 0;
}
+/**
+ * Mallocs a block of memory and initializes an mbuf pool to use it. The
+ * specified block_size indicates the size of an mbuf acquired from the pool if
+ * it contains a pkthdr.
+ *
+ * @param mempool The mempool to initialize.
+ * @param mbuf_pool The mbuf pool to initialize.
+ * @param num_blocks The total number of mbufs in the pool.
+ * @param block_size The size of each mbuf.
+ * @param name The name to give the mempool.
+ * @param out_buf On success, this points to the malloced memory.
+ * Pass NULL if you don't need this
+ * information.
+ *
+ * @return 0 on success;
+ * OS_ENOMEM on malloc failure;
+ * Other OS code on unexpected error.
+ */
int
mem_malloc_mbufpkt_pool(struct os_mempool *mempool,
struct os_mbuf_pool *mbuf_pool, int num_blocks,
[14/42] incubator-mynewt-core git commit: olimex debug script -
remove "set -x" debug flag.
Posted by st...@apache.org.
olimex debug script - remove "set -x" debug flag.
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/2a8f6e42
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/2a8f6e42
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/2a8f6e42
Branch: refs/heads/sterly_refactor
Commit: 2a8f6e42a0ce6daaba04aed740899a2054851a50
Parents: deee95e
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Aug 2 19:18:49 2016 -0700
Committer: Sterling Hughes <st...@apache.org>
Committed: Tue Aug 9 16:05:21 2016 -0700
----------------------------------------------------------------------
.../olimex_stm32-e407_devboard/olimex_stm32-e407_devboard_debug.sh | 1 -
1 file changed, 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2a8f6e42/hw/bsp/olimex_stm32-e407_devboard/olimex_stm32-e407_devboard_debug.sh
----------------------------------------------------------------------
diff --git a/hw/bsp/olimex_stm32-e407_devboard/olimex_stm32-e407_devboard_debug.sh b/hw/bsp/olimex_stm32-e407_devboard/olimex_stm32-e407_devboard_debug.sh
index d402753..2f30773 100755
--- a/hw/bsp/olimex_stm32-e407_devboard/olimex_stm32-e407_devboard_debug.sh
+++ b/hw/bsp/olimex_stm32-e407_devboard/olimex_stm32-e407_devboard_debug.sh
@@ -23,7 +23,6 @@
# - identities is the project identities string.
#
#
-set -x
if [ $# -lt 2 ]; then
echo "Need binary to debug"
exit 1
[12/42] incubator-mynewt-core git commit: olimex-e407 -
hal_uart_close().
Posted by st...@apache.org.
olimex-e407 - hal_uart_close().
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/deee95e6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/deee95e6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/deee95e6
Branch: refs/heads/sterly_refactor
Commit: deee95e61b1051f7870fcbf60b36397657d435f4
Parents: d6e6a6b
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Aug 2 12:40:46 2016 -0700
Committer: Sterling Hughes <st...@apache.org>
Committed: Tue Aug 9 16:05:21 2016 -0700
----------------------------------------------------------------------
hw/mcu/stm/stm32f4xx/src/hal_uart.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/deee95e6/hw/mcu/stm/stm32f4xx/src/hal_uart.c
----------------------------------------------------------------------
diff --git a/hw/mcu/stm/stm32f4xx/src/hal_uart.c b/hw/mcu/stm/stm32f4xx/src/hal_uart.c
index 3bc3e44..6c8d433 100644
--- a/hw/mcu/stm/stm32f4xx/src/hal_uart.c
+++ b/hw/mcu/stm/stm32f4xx/src/hal_uart.c
@@ -372,3 +372,19 @@ hal_uart_config(int port, int32_t baudrate, uint8_t databits, uint8_t stopbits,
return 0;
}
+
+int
+hal_uart_close(int port)
+{
+ struct hal_uart *u;
+
+ if (port >= UART_CNT) {
+ return -1;
+ }
+ u = &uarts[port];
+
+ u->u_open = 0;
+ u->u_regs->CR1 = 0;
+
+ return 0;
+}
[22/42] incubator-mynewt-core git commit: mempool - fn to check if
block came from pool.
Posted by st...@apache.org.
mempool - fn to check if block came from pool.
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/5c00287b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/5c00287b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/5c00287b
Branch: refs/heads/sterly_refactor
Commit: 5c00287b75d6143f2ae892c751fb67be8e71b2d2
Parents: f3d4aaa
Author: Christopher Collins <cc...@apache.org>
Authored: Thu Aug 4 16:24:14 2016 -0700
Committer: Sterling Hughes <st...@apache.org>
Committed: Tue Aug 9 16:05:21 2016 -0700
----------------------------------------------------------------------
libs/os/include/os/os_mempool.h | 3 ++
libs/os/src/os_mempool.c | 54 ++++++++++++++++++++++++------------
2 files changed, 40 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5c00287b/libs/os/include/os/os_mempool.h
----------------------------------------------------------------------
diff --git a/libs/os/include/os/os_mempool.h b/libs/os/include/os/os_mempool.h
index 6b0f24c..a731618 100644
--- a/libs/os/include/os/os_mempool.h
+++ b/libs/os/include/os/os_mempool.h
@@ -82,6 +82,9 @@ typedef uint64_t os_membuf_t;
os_error_t os_mempool_init(struct os_mempool *mp, int blocks, int block_size,
void *membuf, char *name);
+/* Checks if a memory block was allocated from the specified mempool. */
+int os_memblock_from(struct os_mempool *mp, void *block_addr);
+
/* Get a memory block from the pool */
void *os_memblock_get(struct os_mempool *mp);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5c00287b/libs/os/src/os_mempool.c
----------------------------------------------------------------------
diff --git a/libs/os/src/os_mempool.c b/libs/os/src/os_mempool.c
index 1e7428c..04a18a1 100644
--- a/libs/os/src/os_mempool.c
+++ b/libs/os/src/os_mempool.c
@@ -86,6 +86,42 @@ os_mempool_init(struct os_mempool *mp, int blocks, int block_size, void *membuf,
}
/**
+ * Checks if a memory block was allocated from the specified mempool.
+ *
+ * @param mp The mempool to check as parent.
+ * @param block_addr The memory block to check as child.
+ *
+ * @return 0 if the block does not belong to the mempool;
+ * 1 if the block does belong to the mempool.
+ */
+int
+os_memblock_from(struct os_mempool *mp, void *block_addr)
+{
+ uint32_t true_block_size;
+ uint32_t baddr32;
+ uint32_t end;
+
+ _Static_assert(sizeof block_addr == sizeof baddr32,
+ "Pointer to void must be 32-bits.");
+
+ baddr32 = (uint32_t)block_addr;
+ true_block_size = OS_MEMPOOL_TRUE_BLOCK_SIZE(mp->mp_block_size);
+ end = mp->mp_membuf_addr + (mp->mp_num_blocks * true_block_size);
+
+ /* Check that the block is in the memory buffer range. */
+ if ((baddr32 < mp->mp_membuf_addr) || (baddr32 >= end)) {
+ return 0;
+ }
+
+ /* All freed blocks should be on true block size boundaries! */
+ if (((baddr32 - mp->mp_membuf_addr) % true_block_size) != 0) {
+ return 0;
+ }
+
+ return 1;
+}
+
+/**
* os memblock get
*
* Get a memory block from a memory pool
@@ -135,9 +171,6 @@ os_error_t
os_memblock_put(struct os_mempool *mp, void *block_addr)
{
os_sr_t sr;
- uint32_t end;
- uint32_t true_block_size;
- uint32_t baddr32;
struct os_memblock *block;
/* Make sure parameters are valid */
@@ -146,23 +179,10 @@ os_memblock_put(struct os_mempool *mp, void *block_addr)
}
/* Check that the block we are freeing is a valid block! */
- baddr32 = (uint32_t)block_addr;
- true_block_size = OS_MEMPOOL_TRUE_BLOCK_SIZE(mp->mp_block_size);
- end = mp->mp_membuf_addr + (mp->mp_num_blocks * true_block_size);
- if ((baddr32 < mp->mp_membuf_addr) || (baddr32 >= end)) {
- return OS_INVALID_PARM;
- }
-
- /* All freed blocks should be on true block size boundaries! */
- if (((baddr32 - mp->mp_membuf_addr) % true_block_size) != 0) {
+ if (!os_memblock_from(mp, block_addr)) {
return OS_INVALID_PARM;
}
- /*
- * XXX: we should do boundary checks here! The block had better be within
- * the pool. If it fails, do we return an error or assert()? Add this when
- * we add the memory debug.
- */
block = (struct os_memblock *)block_addr;
OS_ENTER_CRITICAL(sr);
[33/42] incubator-mynewt-core git commit: BLE Host - Free mbufs on
exec-write-failure
Posted by st...@apache.org.
BLE Host - Free mbufs on exec-write-failure
This was an mbuf leak. If the device receives an exec-write request,
and the attribute callback fails (or the attribute doesn't allow writes
at all), the mbufs holding the data intended to be written to that
attribute never got freed.
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/fbdb1bae
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/fbdb1bae
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/fbdb1bae
Branch: refs/heads/sterly_refactor
Commit: fbdb1baee9f88899eb61470a44fea4cca06e52a3
Parents: f36fa7c
Author: Christopher Collins <cc...@apache.org>
Authored: Sat Aug 6 16:04:17 2016 -0700
Committer: Sterling Hughes <st...@apache.org>
Committed: Tue Aug 9 16:05:21 2016 -0700
----------------------------------------------------------------------
net/nimble/host/src/ble_att_svr.c | 6 ++++--
net/nimble/host/src/ble_gattc.c | 8 ++++++++
net/nimble/host/src/test/ble_att_svr_test.c | 14 +++++++++++++-
3 files changed, 25 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/fbdb1bae/net/nimble/host/src/ble_att_svr.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_svr.c b/net/nimble/host/src/ble_att_svr.c
index 2e1f158..b3dd2f3 100644
--- a/net/nimble/host/src/ble_att_svr.c
+++ b/net/nimble/host/src/ble_att_svr.c
@@ -2347,9 +2347,11 @@ ble_att_svr_prep_write(uint16_t conn_handle,
*err_handle = attr_handle;
} else {
rc = ble_att_svr_write(conn_handle, attr, 0, &om, &att_err);
+ os_mbuf_free_chain(om);
+ if (rc != 0) {
+ return att_err;
+ }
}
-
- os_mbuf_free_chain(om);
}
return 0;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/fbdb1bae/net/nimble/host/src/ble_gattc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gattc.c b/net/nimble/host/src/ble_gattc.c
index 84ecff3..67c13d6 100644
--- a/net/nimble/host/src/ble_gattc.c
+++ b/net/nimble/host/src/ble_gattc.c
@@ -177,6 +177,7 @@ struct ble_gattc_proc {
struct {
struct ble_gatt_attr attr;
uint16_t length;
+ uint8_t exec_sent:1;
ble_gatt_attr_fn *cb;
void *cb_arg;
} write_long;
@@ -186,6 +187,7 @@ struct ble_gattc_proc {
uint8_t num_attrs;
uint8_t cur_attr;
uint16_t length;
+ uint8_t exec_sent:1;
ble_gatt_reliable_attr_fn *cb;
void *cb_arg;
} write_reliable;
@@ -3528,6 +3530,12 @@ static int
ble_gattc_write_long_rx_exec(struct ble_gattc_proc *proc, int status)
{
ble_gattc_dbg_assert_proc_not_inserted(proc);
+
+ /* Ignore the response if we haven't sent the corresponding request yet. */
+ if (!proc->write_long.exec_sent) {
+ return 0;
+ }
+
ble_gattc_write_long_cb(proc, status, 0);
return BLE_HS_EDONE;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/fbdb1bae/net/nimble/host/src/test/ble_att_svr_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_att_svr_test.c b/net/nimble/host/src/test/ble_att_svr_test.c
index e5968d5..09e7bf9 100644
--- a/net/nimble/host/src/test/ble_att_svr_test.c
+++ b/net/nimble/host/src/test/ble_att_svr_test.c
@@ -2083,12 +2083,16 @@ TEST_CASE(ble_att_svr_test_prep_write)
data[i] = i;
}
- /* Register two attributes. */
+ /* Register two writable attributes. */
ble_att_svr_test_misc_register_uuid16(0x1234, HA_FLAG_PERM_RW, 1,
ble_att_svr_test_misc_attr_fn_w_1);
ble_att_svr_test_misc_register_uuid16(0x8989, HA_FLAG_PERM_RW, 2,
ble_att_svr_test_misc_attr_fn_w_2);
+ /* Register a third attribute that is not writable. */
+ ble_att_svr_test_misc_register_uuid16(0xabab, BLE_ATT_F_READ, 3,
+ ble_att_svr_test_misc_attr_fn_r_1);
+
/*** Empty write succeeds. */
ble_att_svr_test_misc_exec_write(conn_handle, BLE_ATT_EXEC_WRITE_F_CONFIRM,
0, 0);
@@ -2132,6 +2136,14 @@ TEST_CASE(ble_att_svr_test_prep_write)
BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN, 1);
ble_att_svr_test_misc_verify_w_1(NULL, 0);
+ /*** Failure due to attribute callback. */
+ ble_att_svr_test_misc_prep_write(conn_handle, 3, 0, data, 35, 0);
+ ble_att_svr_test_misc_prep_write(conn_handle, 3, 35, data + 35, 43, 0);
+ ble_att_svr_test_misc_prep_write(conn_handle, 3, 78, data + 78, 1, 0);
+ ble_att_svr_test_misc_exec_write(conn_handle, BLE_ATT_EXEC_WRITE_F_CONFIRM,
+ BLE_ATT_ERR_WRITE_NOT_PERMITTED, 0);
+ ble_att_svr_test_misc_verify_w_1(NULL, 0);
+
/*** Successful two part write. */
ble_att_svr_test_misc_prep_write(conn_handle, 1, 0, data, 20, 0);
ble_att_svr_test_misc_prep_write(conn_handle, 1, 20, data + 20, 20, 0);
[06/42] incubator-mynewt-core git commit: BLE Host - Use HCI
transport API
Posted by st...@apache.org.
BLE Host - Use HCI transport API
Prior to this change, the host assumed it was running with a combined
host-controller setup. Now it uses the available HCI transport instead.
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/0fd02e1e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/0fd02e1e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/0fd02e1e
Branch: refs/heads/sterly_refactor
Commit: 0fd02e1e719c9f296e151e89d57ac34c80a870f1
Parents: 2a8f6e4
Author: Christopher Collins <cc...@apache.org>
Authored: Wed Aug 3 19:44:39 2016 -0700
Committer: Sterling Hughes <st...@apache.org>
Committed: Tue Aug 9 16:05:21 2016 -0700
----------------------------------------------------------------------
.../controller/include/controller/ble_ll.h | 1 +
net/nimble/controller/pkg.yml | 6 +-
net/nimble/controller/src/ble_ll.c | 17 +
net/nimble/controller/src/ble_ll_conn.c | 6 +-
net/nimble/controller/src/ble_ll_conn_hci.c | 9 +-
net/nimble/controller/src/ble_ll_conn_priv.h | 7 +
net/nimble/controller/src/ble_ll_hci.c | 14 +-
net/nimble/controller/src/ble_ll_hci_ev.c | 15 +-
net/nimble/controller/src/ble_ll_scan.c | 3 +-
net/nimble/host/include/host/ble_hs.h | 28 +-
net/nimble/host/include/host/ble_hs_test.h | 3 -
net/nimble/host/include/host/host_hci.h | 8 +-
net/nimble/host/pkg.yml | 15 +-
net/nimble/host/src/ble_gap.c | 2 +-
net/nimble/host/src/ble_gap_priv.h | 2 +-
net/nimble/host/src/ble_hci_cmd.c | 58 +-
net/nimble/host/src/ble_hs.c | 224 ++++--
net/nimble/host/src/ble_hs_atomic.c | 20 +
net/nimble/host/src/ble_hs_atomic_priv.h | 1 +
net/nimble/host/src/ble_hs_priv.h | 16 +
net/nimble/host/src/ble_hs_pvcy.c | 27 +-
net/nimble/host/src/ble_hs_pvcy_priv.h | 2 +-
net/nimble/host/src/ble_hs_startup.c | 4 -
net/nimble/host/src/host_dbg.c | 2 +-
net/nimble/host/src/host_hci.c | 49 +-
net/nimble/host/src/host_hci_cmd.c | 52 +-
net/nimble/host/src/test/ble_gap_test.c | 11 +-
net/nimble/host/src/test/ble_host_hci_test.c | 8 +-
net/nimble/host/src/test/ble_hs_test.c | 16 -
net/nimble/host/src/test/ble_hs_test_util.c | 96 ++-
net/nimble/host/src/test/ble_hs_test_util.h | 2 +
net/nimble/host/src/test/ble_os_test.c | 2 +-
net/nimble/host/src/test/ble_sm_test_util.c | 20 +-
net/nimble/include/nimble/ble.h | 4 -
net/nimble/include/nimble/ble_hci_trans.h | 152 ++++
net/nimble/include/nimble/hci_transport.h | 32 -
.../ram/include/transport/ram/ble_hci_ram.h | 15 +
net/nimble/transport/ram/pkg.yml | 33 +
net/nimble/transport/ram/src/ble_hci_ram.c | 190 +++++
.../uart/include/transport/uart/ble_hci_uart.h | 19 +
net/nimble/transport/uart/pkg.yml | 34 +
net/nimble/transport/uart/src/ble_hci_uart.c | 775 +++++++++++++++++++
42 files changed, 1731 insertions(+), 269 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fd02e1e/net/nimble/controller/include/controller/ble_ll.h
----------------------------------------------------------------------
diff --git a/net/nimble/controller/include/controller/ble_ll.h b/net/nimble/controller/include/controller/ble_ll.h
index 81cba53..2be8425 100644
--- a/net/nimble/controller/include/controller/ble_ll.h
+++ b/net/nimble/controller/include/controller/ble_ll.h
@@ -22,6 +22,7 @@
#include "stats/stats.h"
#include "hal/hal_cputime.h"
+#include "os/os_eventq.h"
#include "nimble/nimble_opt.h"
/* Controller revision. */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fd02e1e/net/nimble/controller/pkg.yml
----------------------------------------------------------------------
diff --git a/net/nimble/controller/pkg.yml b/net/nimble/controller/pkg.yml
index 07a9d56..8e52aba 100644
--- a/net/nimble/controller/pkg.yml
+++ b/net/nimble/controller/pkg.yml
@@ -25,10 +25,14 @@ pkg.keywords:
- ble
- bluetooth
-pkg.req_apis: ble_driver
+pkg.req_apis:
+ - ble_driver
+ - ble_transport
+
pkg.deps:
- libs/os
- sys/stats
- net/nimble
+
pkg.features:
- BLE_DEVICE
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fd02e1e/net/nimble/controller/src/ble_ll.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll.c b/net/nimble/controller/src/ble_ll.c
index 3a09e3e..1a4f558 100644
--- a/net/nimble/controller/src/ble_ll.c
+++ b/net/nimble/controller/src/ble_ll.c
@@ -26,6 +26,7 @@
#include "nimble/ble.h"
#include "nimble/nimble_opt.h"
#include "nimble/hci_common.h"
+#include "nimble/ble_hci_trans.h"
#include "controller/ble_hw.h"
#include "controller/ble_phy.h"
#include "controller/ble_ll.h"
@@ -182,6 +183,9 @@ STATS_NAME_END(ble_ll_stats)
struct os_task g_ble_ll_task;
os_stack_t g_ble_ll_stack[BLE_LL_STACK_SIZE];
+struct os_mempool g_ble_ll_hci_ev_pool;
+static void *ble_ll_hci_os_event_buf;
+
/* XXX: temporary logging until we transition to real logging */
#ifdef BLE_LL_LOG
struct ble_ll_log
@@ -1129,6 +1133,16 @@ ble_ll_init(uint8_t ll_task_prio, uint8_t num_acl_pkts, uint16_t acl_pkt_size)
cputime_timer_init(&g_ble_ll_data.ll_wfr_timer, ble_ll_wfr_timer_exp,
NULL);
+ ble_ll_hci_os_event_buf = malloc(
+ OS_MEMPOOL_BYTES(16, sizeof (struct os_event)));
+ assert(ble_ll_hci_os_event_buf != NULL);
+
+ /* Create memory pool of OS events */
+ rc = os_mempool_init(&g_ble_ll_hci_ev_pool, 16,
+ sizeof (struct os_event), ble_ll_hci_os_event_buf,
+ "g_ble_ll_hci_ev_pool");
+ assert(rc == 0);
+
/* Initialize LL HCI */
ble_ll_hci_init();
@@ -1182,6 +1196,9 @@ ble_ll_init(uint8_t ll_task_prio, uint8_t num_acl_pkts, uint16_t acl_pkt_size)
STATS_SIZE_INIT_PARMS(ble_ll_stats, STATS_SIZE_32),
STATS_NAME_INIT_PARMS(ble_ll_stats),
"ble_ll");
+
+ ble_hci_trans_cfg_ll(ble_ll_hci_cmd_rx, NULL,
+ ble_ll_hci_acl_rx, NULL);
return rc;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fd02e1e/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 f711dfb..cb0f89b 100644
--- a/net/nimble/controller/src/ble_ll_conn.c
+++ b/net/nimble/controller/src/ble_ll_conn.c
@@ -25,6 +25,7 @@
#include "nimble/ble.h"
#include "nimble/nimble_opt.h"
#include "nimble/hci_common.h"
+#include "nimble/ble_hci_trans.h"
#include "ble/xcvr.h"
#include "controller/ble_ll.h"
#include "controller/ble_ll_hci.h"
@@ -103,9 +104,6 @@ extern void bletest_completed_pkt(uint16_t handle);
* are hosed. Well, anchor point can get really messed up!
*/
-/* XXX: this does not belong here! Move to transport? */
-extern int ble_hs_rx_data(struct os_mbuf *om);
-
/*
* The amount of time that we will wait to hear the start of a receive
* packet after we have transmitted a packet. This time is at least
@@ -2569,7 +2567,7 @@ ble_ll_conn_rx_data_pdu(struct os_mbuf *rxpdu, struct ble_mbuf_hdr *hdr)
acl_hdr = (acl_hdr << 12) | connsm->conn_handle;
htole16(rxbuf, acl_hdr);
htole16(rxbuf + 2, acl_len);
- ble_hs_rx_data(rxpdu);
+ ble_hci_trans_ll_acl_tx(rxpdu);
}
/* NOTE: we dont free the mbuf since we handed it off! */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fd02e1e/net/nimble/controller/src/ble_ll_conn_hci.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_conn_hci.c b/net/nimble/controller/src/ble_ll_conn_hci.c
index 1d6102e..f653ca6 100644
--- a/net/nimble/controller/src/ble_ll_conn_hci.c
+++ b/net/nimble/controller/src/ble_ll_conn_hci.c
@@ -25,6 +25,7 @@
#include "nimble/ble.h"
#include "nimble/nimble_opt.h"
#include "nimble/hci_common.h"
+#include "nimble/ble_hci_trans.h"
#include "controller/ble_ll.h"
#include "controller/ble_ll_hci.h"
#include "controller/ble_ll_conn.h"
@@ -140,7 +141,7 @@ ble_ll_conn_comp_event_send(struct ble_ll_conn_sm *connsm, uint8_t status)
enh_enabled = ble_ll_hci_is_le_event_enabled(BLE_HCI_LE_SUBEV_ENH_CONN_COMPLETE);
if (enabled || enh_enabled) {
- evbuf = os_memblock_get(&g_hci_evt_pool);
+ evbuf = ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_HI);
if (evbuf) {
/* Put common elements in event */
evbuf[0] = BLE_HCI_EVCODE_LE_META;
@@ -246,7 +247,7 @@ ble_ll_conn_num_comp_pkts_event_send(void)
(connsm->completed_pkts || !STAILQ_EMPTY(&connsm->conn_txq))) {
/* If no buffer, get one, If cant get one, leave. */
if (!evbuf) {
- evbuf = os_memblock_get(&g_hci_evt_pool);
+ evbuf = ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_HI);
if (!evbuf) {
break;
}
@@ -313,7 +314,7 @@ ble_ll_auth_pyld_tmo_event_send(struct ble_ll_conn_sm *connsm)
uint8_t *evbuf;
if (ble_ll_hci_is_event_enabled(BLE_HCI_EVCODE_AUTH_PYLD_TMO)) {
- evbuf = os_memblock_get(&g_hci_evt_pool);
+ evbuf = ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_HI);
if (evbuf) {
evbuf[0] = BLE_HCI_EVCODE_AUTH_PYLD_TMO;
evbuf[1] = sizeof(uint16_t);
@@ -338,7 +339,7 @@ ble_ll_disconn_comp_event_send(struct ble_ll_conn_sm *connsm, uint8_t reason)
uint8_t *evbuf;
if (ble_ll_hci_is_event_enabled(BLE_HCI_EVCODE_DISCONN_CMP)) {
- evbuf = os_memblock_get(&g_hci_evt_pool);
+ evbuf = ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_HI);
if (evbuf) {
evbuf[0] = BLE_HCI_EVCODE_DISCONN_CMP;
evbuf[1] = BLE_HCI_EVENT_DISCONN_COMPLETE_LEN;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fd02e1e/net/nimble/controller/src/ble_ll_conn_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_conn_priv.h b/net/nimble/controller/src/ble_ll_conn_priv.h
index 218ecbc..b855b22 100644
--- a/net/nimble/controller/src/ble_ll_conn_priv.h
+++ b/net/nimble/controller/src/ble_ll_conn_priv.h
@@ -81,6 +81,9 @@ extern struct ble_ll_conn_free_list g_ble_ll_conn_free_list;
/* Pointer to connection state machine we are trying to create */
extern struct ble_ll_conn_sm *g_ble_ll_conn_create_sm;
+extern struct os_mempool g_ble_ll_hci_ev_pool;
+
+
/* Generic interface */
struct ble_ll_len_req;
struct hci_create_conn;
@@ -150,4 +153,8 @@ void ble_ll_conn_auth_pyld_timer_start(struct ble_ll_conn_sm *connsm);
#else
#define ble_ll_conn_auth_pyld_timer_start(x)
#endif
+
+int ble_ll_hci_cmd_rx(uint8_t *cmd, void *arg);
+int ble_ll_hci_acl_rx(struct os_mbuf *om, void *arg);
+
#endif /* H_BLE_LL_CONN_PRIV_ */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fd02e1e/net/nimble/controller/src/ble_ll_hci.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_hci.c b/net/nimble/controller/src/ble_ll_hci.c
index 2889367..352dda2 100644
--- a/net/nimble/controller/src/ble_ll_hci.c
+++ b/net/nimble/controller/src/ble_ll_hci.c
@@ -23,7 +23,7 @@
#include "nimble/ble.h"
#include "nimble/nimble_opt.h"
#include "nimble/hci_common.h"
-#include "nimble/hci_transport.h"
+#include "nimble/ble_hci_trans.h"
#include "controller/ble_hw.h"
#include "controller/ble_ll_adv.h"
#include "controller/ble_ll_scan.h"
@@ -68,7 +68,7 @@ ble_ll_hci_event_send(uint8_t *evbuf)
STATS_INC(ble_ll_stats, hci_events_sent);
/* Send the event to the host */
- rc = ble_hci_transport_ctlr_event_send(evbuf);
+ rc = ble_hci_trans_ll_evt_tx(evbuf);
return rc;
}
@@ -86,7 +86,7 @@ ble_ll_hci_send_noop(void)
uint8_t *evbuf;
uint16_t opcode;
- evbuf = os_memblock_get(&g_hci_evt_pool);
+ evbuf = ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_HI);
if (evbuf) {
/* Create a command complete event with a NO-OP opcode */
opcode = 0;
@@ -919,7 +919,7 @@ ble_ll_hci_cmd_proc(struct os_event *ev)
assert(cmdbuf != NULL);
/* Free the event */
- err = os_memblock_put(&g_hci_os_event_pool, ev);
+ err = os_memblock_put(&g_ble_ll_hci_ev_pool, ev);
assert(err == OS_OK);
/* Get the opcode from the command buffer */
@@ -994,12 +994,12 @@ ble_ll_hci_cmd_proc(struct os_event *ev)
* BLE_ERR_MEM_CAPACITY on HCI buffer exhaustion.
*/
int
-ble_hci_transport_host_cmd_send(uint8_t *cmd)
+ble_ll_hci_cmd_rx(uint8_t *cmd, void *arg)
{
struct os_event *ev;
/* Get an event structure off the queue */
- ev = (struct os_event *)os_memblock_get(&g_hci_os_event_pool);
+ ev = (struct os_event *)os_memblock_get(&g_ble_ll_hci_ev_pool);
if (!ev) {
return BLE_ERR_MEM_CAPACITY;
}
@@ -1015,7 +1015,7 @@ ble_hci_transport_host_cmd_send(uint8_t *cmd)
/* Send ACL data from host to contoller */
int
-ble_hci_transport_host_acl_data_send(struct os_mbuf *om)
+ble_ll_hci_acl_rx(struct os_mbuf *om, void *arg)
{
ble_ll_acl_data_in(om);
return 0;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fd02e1e/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 5624c65..2548bdc 100644
--- a/net/nimble/controller/src/ble_ll_hci_ev.c
+++ b/net/nimble/controller/src/ble_ll_hci_ev.c
@@ -21,6 +21,7 @@
#include <string.h>
#include "nimble/ble.h"
#include "nimble/hci_common.h"
+#include "nimble/ble_hci_trans.h"
#include "controller/ble_ll.h"
#include "controller/ble_ll_hci.h"
#include "controller/ble_ll_ctrl.h"
@@ -41,7 +42,7 @@ ble_ll_hci_ev_datalen_chg(struct ble_ll_conn_sm *connsm)
uint8_t *evbuf;
if (ble_ll_hci_is_le_event_enabled(BLE_HCI_LE_SUBEV_DATA_LEN_CHG)) {
- evbuf = os_memblock_get(&g_hci_evt_pool);
+ 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_DATA_LEN_CHG_LEN;
@@ -68,7 +69,7 @@ ble_ll_hci_ev_rem_conn_parm_req(struct ble_ll_conn_sm *connsm,
uint8_t *evbuf;
if (ble_ll_hci_is_le_event_enabled(BLE_HCI_LE_SUBEV_REM_CONN_PARM_REQ)) {
- evbuf = os_memblock_get(&g_hci_evt_pool);
+ 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_REM_CONN_PARM_REQ_LEN;
@@ -95,7 +96,7 @@ ble_ll_hci_ev_conn_update(struct ble_ll_conn_sm *connsm, uint8_t status)
uint8_t *evbuf;
if (ble_ll_hci_is_le_event_enabled(BLE_HCI_LE_SUBEV_CONN_UPD_COMPLETE)) {
- evbuf = os_memblock_get(&g_hci_evt_pool);
+ 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_CONN_UPD_LEN;
@@ -127,7 +128,7 @@ ble_ll_hci_ev_encrypt_chg(struct ble_ll_conn_sm *connsm, uint8_t status)
}
if (ble_ll_hci_is_event_enabled(evcode)) {
- evbuf = os_memblock_get(&g_hci_evt_pool);
+ evbuf = ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_HI);
if (evbuf) {
evbuf[0] = evcode;
evbuf[1] = evlen;
@@ -158,7 +159,7 @@ ble_ll_hci_ev_ltk_req(struct ble_ll_conn_sm *connsm)
uint8_t *evbuf;
if (ble_ll_hci_is_le_event_enabled(BLE_HCI_LE_SUBEV_LT_KEY_REQ)) {
- evbuf = os_memblock_get(&g_hci_evt_pool);
+ 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_LT_KEY_REQ_LEN;
@@ -188,7 +189,7 @@ ble_ll_hci_ev_rd_rem_used_feat(struct ble_ll_conn_sm *connsm, uint8_t status)
uint8_t *evbuf;
if (ble_ll_hci_is_le_event_enabled(BLE_HCI_LE_SUBEV_RD_REM_USED_FEAT)) {
- evbuf = os_memblock_get(&g_hci_evt_pool);
+ 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_RD_REM_USED_FEAT_LEN;
@@ -208,7 +209,7 @@ ble_ll_hci_ev_rd_rem_ver(struct ble_ll_conn_sm *connsm, uint8_t status)
uint8_t *evbuf;
if (ble_ll_hci_is_event_enabled(BLE_HCI_EVCODE_RD_REM_VER_INFO_CMP)) {
- evbuf = os_memblock_get(&g_hci_evt_pool);
+ evbuf = ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_HI);
if (evbuf) {
evbuf[0] = BLE_HCI_EVCODE_RD_REM_VER_INFO_CMP;
evbuf[1] = BLE_HCI_EVENT_RD_RM_VER_LEN;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fd02e1e/net/nimble/controller/src/ble_ll_scan.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_scan.c b/net/nimble/controller/src/ble_ll_scan.c
index c926846..64c3990 100644
--- a/net/nimble/controller/src/ble_ll_scan.c
+++ b/net/nimble/controller/src/ble_ll_scan.c
@@ -25,6 +25,7 @@
#include "nimble/ble.h"
#include "nimble/nimble_opt.h"
#include "nimble/hci_common.h"
+#include "nimble/ble_hci_trans.h"
#include "controller/ble_phy.h"
#include "controller/ble_hw.h"
#include "controller/ble_ll.h"
@@ -424,7 +425,7 @@ ble_ll_hci_send_adv_report(uint8_t pdu_type, uint8_t txadd, uint8_t *rxbuf,
}
if (ble_ll_hci_is_le_event_enabled(subev)) {
- evbuf = os_memblock_get(&g_hci_evt_pool);
+ evbuf = ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_LO);
if (evbuf) {
evbuf[0] = BLE_HCI_EVCODE_LE_META;
evbuf[1] = event_len;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fd02e1e/net/nimble/host/include/host/ble_hs.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_hs.h b/net/nimble/host/include/host/ble_hs.h
index 5cdf863..faeaf14 100644
--- a/net/nimble/host/include/host/ble_hs.h
+++ b/net/nimble/host/include/host/ble_hs.h
@@ -21,6 +21,7 @@
#define H_BLE_HS_
#include <inttypes.h>
+#include "nimble/hci_common.h"
#include "host/ble_att.h"
#include "host/ble_gap.h"
#include "host/ble_gatt.h"
@@ -62,6 +63,7 @@ struct os_event;
#define BLE_HS_ETIMEOUT_HCI 19
#define BLE_HS_ENOMEM_EVT 20
#define BLE_HS_ENOADDR 21
+#define BLE_HS_ENOTSYNCED 22
#define BLE_HS_ERR_ATT_BASE 0x100 /* 256 */
#define BLE_HS_ATT_ERR(x) ((x) ? BLE_HS_ERR_ATT_BASE + (x) : 0)
@@ -85,8 +87,10 @@ struct os_event;
#define BLE_HS_IO_NO_INPUT_OUTPUT 0x03
#define BLE_HS_IO_KEYBOARD_DISPLAY 0x04
+typedef void ble_hs_reset_fn(int reason);
+typedef void ble_hs_sync_fn(void);
+
struct ble_hs_cfg {
- /*** HCI settings. */
/**
* An HCI buffer is a "flat" 260-byte buffer. HCI buffers are used by the
* controller to send unsolicited events to the host.
@@ -105,6 +109,10 @@ struct ble_hs_cfg {
* needs to be processsed. The pool of OS events is allocated with the
* same number of elements as the HCI buffer pool.
*/
+ /* XXX: This should either be renamed to indicate it is only used for OS
+ * events, or it should go away entirely (copy the number from the
+ * transport's config).
+ */
uint8_t max_hci_bufs;
/*** Connection settings. */
@@ -211,6 +219,19 @@ struct ble_hs_cfg {
uint8_t sm_our_key_dist;
uint8_t sm_their_key_dist;
+ /*** HCI settings */
+ /**
+ * This callback is executed when the host resets itself and the controller
+ * due to fatal error.
+ */
+ ble_hs_reset_fn *reset_cb;
+
+ /**
+ * This callback is executed when the host and controller become synced.
+ * This happens at startup and after a reset.
+ */
+ ble_hs_sync_fn *sync_cb;
+
/*** Store settings. */
/**
* These function callbacks handle persistence of sercurity material
@@ -220,7 +241,7 @@ struct ble_hs_cfg {
ble_store_write_fn *store_write_cb;
ble_store_delete_fn *store_delete_cb;
- /*** privacy settings */
+ /*** Privacy settings. */
/**
* The frequency at which new resovlable private addresses are generated.
* Units are seconds.
@@ -230,9 +251,8 @@ struct ble_hs_cfg {
extern const struct ble_hs_cfg ble_hs_cfg_dflt;
-int ble_hs_rx_data(struct os_mbuf *om);
+int ble_hs_synced(void);
int ble_hs_start(void);
-void ble_hs_event_enqueue(struct os_event *ev);
int ble_hs_init(struct os_eventq *app_evq, struct ble_hs_cfg *cfg);
#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fd02e1e/net/nimble/host/include/host/ble_hs_test.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_hs_test.h b/net/nimble/host/include/host/ble_hs_test.h
index a883018..5d28291 100644
--- a/net/nimble/host/include/host/ble_hs_test.h
+++ b/net/nimble/host/include/host/ble_hs_test.h
@@ -23,9 +23,6 @@
#include <inttypes.h>
struct os_mbuf;
-void ble_hs_test_pkt_txed(struct os_mbuf *om);
-void ble_hs_test_hci_txed(uint8_t *cmdbuf);
-
int ble_att_clt_test_all(void);
int ble_att_svr_test_all(void);
int ble_gap_test_all(void);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fd02e1e/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 dbe626a..79a0034 100644
--- a/net/nimble/host/include/host/host_hci.h
+++ b/net/nimble/host/include/host/host_hci.h
@@ -24,13 +24,7 @@
struct ble_hs_conn;
struct os_mbuf;
-#define HCI_CMD_BUF_SIZE 260
-#define HCI_EVT_BUF_SIZE 260
-
-extern uint8_t host_hci_cmd_buf[HCI_CMD_BUF_SIZE];
-
-int host_hci_os_event_proc(struct os_event *ev);
-int host_hci_event_rx(uint8_t *data);
+int host_hci_evt_process(uint8_t *data);
uint16_t host_hci_opcode_join(uint8_t ogf, uint16_t ocf);
void host_hci_write_hdr(uint8_t ogf, uint8_t ocf, uint8_t len, void *buf);
int host_hci_cmd_send(uint8_t ogf, uint8_t ocf, uint8_t len,
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fd02e1e/net/nimble/host/pkg.yml
----------------------------------------------------------------------
diff --git a/net/nimble/host/pkg.yml b/net/nimble/host/pkg.yml
index 0edea58..a45ba1e 100644
--- a/net/nimble/host/pkg.yml
+++ b/net/nimble/host/pkg.yml
@@ -36,20 +36,23 @@ pkg.deps:
# Tinycrypt is only required when secure connections (NIMBPLE_OPT_SM_SC)
# is enabled. It always gets built as a dependency, but not is not
# included by the linker unless SC is enabled. XXX: We should not build
- # this library if it is not requiresd.
+ # this library if it is not required.
- libs/tinycrypt
pkg.req_apis:
+ - ble_transport
- console
pkg.features:
- BLE_HOST
# Satisfy capability dependencies for the self-contained test executable.
-pkg.deps.SELFTEST: libs/console/stub
+pkg.deps.SELFTEST:
+ - libs/console/stub
+ - net/nimble/transport/ram
+
pkg.cflags.SELFTEST:
- - -DPHONY_TRANSPORT=1
- - -DPHONY_HCI_ACKS=1
- - -DNIMBLE_OPT_SM=1
- - -DNIMBLE_OPT_SM_SC=1
+ - "-DPHONY_HCI_ACKS=1"
+ - "-DNIMBLE_OPT_SM=1"
+ - "-DNIMBLE_OPT_SM_SC=1"
pkg.cflags.TEST: -DBLE_HS_DEBUG
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fd02e1e/net/nimble/host/src/ble_gap.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gap.c b/net/nimble/host/src/ble_gap.c
index a001ae3..1a41956 100644
--- a/net/nimble/host/src/ble_gap.c
+++ b/net/nimble/host/src/ble_gap.c
@@ -708,7 +708,7 @@ ble_gap_update_failed(uint16_t conn_handle, int status)
ble_gap_update_notify(conn_handle, status);
}
-static void
+void
ble_gap_conn_broken(uint16_t conn_handle, int reason)
{
struct ble_gap_snapshot snap;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fd02e1e/net/nimble/host/src/ble_gap_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gap_priv.h b/net/nimble/host/src/ble_gap_priv.h
index 449a4b0..3168d48 100644
--- a/net/nimble/host/src/ble_gap_priv.h
+++ b/net/nimble/host/src/ble_gap_priv.h
@@ -70,7 +70,6 @@ extern STATS_SECT_DECL(ble_gap_stats) ble_gap_stats;
#define BLE_GAP_CONN_MODE_MAX 3
#define BLE_GAP_DISC_MODE_MAX 3
-int ble_gap_locked_by_cur_task(void);
void ble_gap_rx_adv_report(struct ble_gap_disc_desc *desc);
int ble_gap_rx_conn_complete(struct hci_le_conn_complete *evt);
void ble_gap_rx_disconn_complete(struct hci_disconn_complete *evt);
@@ -92,6 +91,7 @@ void ble_gap_subscribe_event(uint16_t conn_handle, uint16_t attr_handle,
uint8_t prev_indicate, uint8_t cur_indicate);
int ble_gap_master_in_progress(void);
+void ble_gap_conn_broken(uint16_t conn_handle, int reason);
int32_t ble_gap_heartbeat(void);
int ble_gap_init(void);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fd02e1e/net/nimble/host/src/ble_hci_cmd.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hci_cmd.c b/net/nimble/host/src/ble_hci_cmd.c
index 23eaba3..53fe726 100644
--- a/net/nimble/host/src/ble_hci_cmd.c
+++ b/net/nimble/host/src/ble_hci_cmd.c
@@ -21,6 +21,7 @@
#include <errno.h>
#include <stdio.h>
#include "os/os.h"
+#include "nimble/ble_hci_trans.h"
#include "ble_hs_priv.h"
#include "host_dbg_priv.h"
@@ -29,6 +30,8 @@
static struct os_mutex ble_hci_cmd_mutex;
static struct os_sem ble_hci_cmd_sem;
+static uint8_t *ble_hci_cmd_ack;
+
#if PHONY_HCI_ACKS
static ble_hci_cmd_phony_ack_fn *ble_hci_cmd_phony_ack_cb;
#endif
@@ -69,7 +72,6 @@ ble_hci_cmd_rx_cmd_complete(uint8_t event_code, uint8_t *data, int len,
uint8_t num_pkts;
if (len < BLE_HCI_EVENT_CMD_COMPLETE_HDR_LEN) {
- /* XXX: Increment stat. */
return BLE_HS_ECONTROLLER;
}
@@ -112,7 +114,6 @@ ble_hci_cmd_rx_cmd_status(uint8_t event_code, uint8_t *data, int len,
uint8_t status;
if (len < BLE_HCI_EVENT_CMD_STATUS_LEN) {
- /* XXX: Increment stat. */
return BLE_HS_ECONTROLLER;
}
@@ -132,7 +133,8 @@ ble_hci_cmd_rx_cmd_status(uint8_t event_code, uint8_t *data, int len,
}
static int
-ble_hci_cmd_process_ack(uint8_t *params_buf, uint8_t params_buf_len,
+ble_hci_cmd_process_ack(uint16_t expected_opcode,
+ uint8_t *params_buf, uint8_t params_buf_len,
struct ble_hci_ack *out_ack)
{
uint8_t event_code;
@@ -140,20 +142,16 @@ ble_hci_cmd_process_ack(uint8_t *params_buf, uint8_t params_buf_len,
uint8_t event_len;
int rc;
- /***
- * The controller always reuses the command buffer for its acknowledgement
- * events. This function processes the acknowledgement event contained in
- * the command buffer.
- */
+ BLE_HS_DBG_ASSERT(ble_hci_cmd_ack != NULL);
/* Count events received */
STATS_INC(ble_hs_stats, hci_event);
/* Display to console */
- host_hci_dbg_event_disp(host_hci_cmd_buf);
+ host_hci_dbg_event_disp(ble_hci_cmd_ack);
- event_code = host_hci_cmd_buf[0];
- param_len = host_hci_cmd_buf[1];
+ event_code = ble_hci_cmd_ack[0];
+ param_len = ble_hci_cmd_ack[1];
event_len = param_len + 2;
/* Clear ack fields up front to silence spurious gcc warnings. */
@@ -161,12 +159,12 @@ ble_hci_cmd_process_ack(uint8_t *params_buf, uint8_t params_buf_len,
switch (event_code) {
case BLE_HCI_EVCODE_COMMAND_COMPLETE:
- rc = ble_hci_cmd_rx_cmd_complete(event_code, host_hci_cmd_buf,
+ rc = ble_hci_cmd_rx_cmd_complete(event_code, ble_hci_cmd_ack,
event_len, out_ack);
break;
case BLE_HCI_EVCODE_COMMAND_STATUS:
- rc = ble_hci_cmd_rx_cmd_status(event_code, host_hci_cmd_buf,
+ rc = ble_hci_cmd_rx_cmd_status(event_code, ble_hci_cmd_ack,
event_len, out_ack);
break;
@@ -187,6 +185,14 @@ ble_hci_cmd_process_ack(uint8_t *params_buf, uint8_t params_buf_len,
memcpy(params_buf, out_ack->bha_params, out_ack->bha_params_len);
}
out_ack->bha_params = params_buf;
+
+ if (out_ack->bha_opcode != expected_opcode) {
+ rc = BLE_HS_ECONTROLLER;
+ }
+ }
+
+ if (rc != 0) {
+ STATS_INC(ble_hs_stats, hci_invalid_ack);
}
return rc;
@@ -201,15 +207,20 @@ ble_hci_cmd_wait_for_ack(void)
if (ble_hci_cmd_phony_ack_cb == NULL) {
rc = BLE_HS_ETIMEOUT_HCI;
} else {
- rc = ble_hci_cmd_phony_ack_cb(host_hci_cmd_buf, 260);
+ ble_hci_cmd_ack =
+ ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_CMD);
+ BLE_HS_DBG_ASSERT(ble_hci_cmd_ack != NULL);
+ rc = ble_hci_cmd_phony_ack_cb(ble_hci_cmd_ack, 260);
}
#else
rc = os_sem_pend(&ble_hci_cmd_sem, BLE_HCI_CMD_TIMEOUT);
switch (rc) {
case 0:
+ BLE_HS_DBG_ASSERT(ble_hci_cmd_ack != NULL);
break;
case OS_TIMEOUT:
rc = BLE_HS_ETIMEOUT_HCI;
+ STATS_INC(ble_hs_stats, hci_timeout);
break;
default:
rc = BLE_HS_EOS;
@@ -225,8 +236,12 @@ ble_hci_cmd_tx(void *cmd, void *evt_buf, uint8_t evt_buf_len,
uint8_t *out_evt_buf_len)
{
struct ble_hci_ack ack;
+ uint16_t opcode;
int rc;
+ opcode = le16toh((uint8_t *)cmd);
+
+ BLE_HS_DBG_ASSERT(ble_hci_cmd_ack == NULL);
ble_hci_cmd_lock();
rc = host_hci_cmd_send_buf(cmd);
@@ -236,11 +251,13 @@ ble_hci_cmd_tx(void *cmd, void *evt_buf, uint8_t evt_buf_len,
rc = ble_hci_cmd_wait_for_ack();
if (rc != 0) {
+ ble_hs_sched_reset(rc);
goto done;
}
- rc = ble_hci_cmd_process_ack(evt_buf, evt_buf_len, &ack);
+ rc = ble_hci_cmd_process_ack(opcode, evt_buf, evt_buf_len, &ack);
if (rc != 0) {
+ ble_hs_sched_reset(rc);
goto done;
}
@@ -251,6 +268,11 @@ ble_hci_cmd_tx(void *cmd, void *evt_buf, uint8_t evt_buf_len,
rc = ack.bha_status;
done:
+ if (ble_hci_cmd_ack != NULL) {
+ ble_hci_trans_buf_free(ble_hci_cmd_ack);
+ ble_hci_cmd_ack = NULL;
+ }
+
ble_hci_cmd_unlock();
return rc;
}
@@ -271,17 +293,17 @@ ble_hci_cmd_tx_empty_ack(void *cmd)
void
ble_hci_cmd_rx_ack(uint8_t *ack_ev)
{
- /* The controller should always reuse the command buffer for its acks. */
- BLE_HS_DBG_ASSERT(ack_ev == host_hci_cmd_buf);
-
if (ble_hci_cmd_sem.sem_tokens != 0) {
/* This ack is unexpected; ignore it. */
+ ble_hci_trans_buf_free(ack_ev);
return;
}
+ BLE_HS_DBG_ASSERT(ble_hci_cmd_ack == NULL);
/* Unblock the application now that the HCI command buffer is populated
* with the acknowledgement.
*/
+ ble_hci_cmd_ack = ack_ev;
os_sem_release(&ble_hci_cmd_sem);
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fd02e1e/net/nimble/host/src/ble_hs.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs.c b/net/nimble/host/src/ble_hs.c
index aeba768..6e8a59f 100644
--- a/net/nimble/host/src/ble_hs.c
+++ b/net/nimble/host/src/ble_hs.c
@@ -23,12 +23,9 @@
#include "stats/stats.h"
#include "util/tpq.h"
#include "os/os.h"
-#include "nimble/hci_transport.h"
+#include "nimble/ble_hci_trans.h"
#include "host/host_hci.h"
#include "ble_hs_priv.h"
-#ifdef PHONY_TRANSPORT
-#include "host/ble_hs_test.h"
-#endif
/**
* The maximum number of events the host will process in a row before returning
@@ -38,27 +35,33 @@
static struct log_handler ble_hs_log_console_handler;
-struct os_mempool g_hci_evt_pool;
-static void *ble_hs_hci_evt_buf;
-
-/* XXX: this might be transport layer */
-#define HCI_OS_EVENT_BUF_SIZE (sizeof(struct os_event))
-
-struct os_mempool g_hci_os_event_pool;
+struct os_mempool ble_hs_hci_ev_pool;
static void *ble_hs_hci_os_event_buf;
+/** OS event - triggers tx of pending notifications and indications. */
static struct os_event ble_hs_event_tx_notifications = {
.ev_type = BLE_HS_EVENT_TX_NOTIFICATIONS,
.ev_arg = NULL,
};
+/** OS event - triggers a full reset. */
+static struct os_event ble_hs_event_reset = {
+ .ev_type = BLE_HS_EVENT_RESET,
+ .ev_arg = NULL,
+};
+
+uint8_t ble_hs_sync_state;
+static int ble_hs_reset_reason;
+
#if MYNEWT_SELFTEST
/** Use a higher frequency timer to allow tests to run faster. */
-#define BLE_HS_HEARTBEAT_OS_TICKS (OS_TICKS_PER_SEC / 10)
+#define BLE_HS_HEARTBEAT_OS_TICKS (OS_TICKS_PER_SEC / 10)
#else
-#define BLE_HS_HEARTBEAT_OS_TICKS OS_TICKS_PER_SEC
+#define BLE_HS_HEARTBEAT_OS_TICKS OS_TICKS_PER_SEC
#endif
+#define BLE_HS_SYNC_RETRY_RATE (OS_TICKS_PER_SEC / 10)
+
/**
* Handles unresponsive timeouts and periodic retries in case of resource
* shortage.
@@ -90,6 +93,9 @@ STATS_NAME_START(ble_hs_stats)
STATS_NAME(ble_hs_stats, hci_event)
STATS_NAME(ble_hs_stats, hci_invalid_ack)
STATS_NAME(ble_hs_stats, hci_unknown_event)
+ STATS_NAME(ble_hs_stats, hci_timeout)
+ STATS_NAME(ble_hs_stats, reset)
+ STATS_NAME(ble_hs_stats, sync)
STATS_NAME_END(ble_hs_stats)
int
@@ -157,11 +163,7 @@ ble_hs_process_tx_data_queue(void)
struct os_mbuf *om;
while ((om = os_mqueue_get(&ble_hs_tx_q)) != NULL) {
-#ifdef PHONY_TRANSPORT
- ble_hs_test_pkt_txed(om);
-#else
- ble_hci_transport_host_acl_data_send(om);
-#endif
+ ble_hci_trans_hs_acl_tx(om);
}
}
@@ -171,11 +173,22 @@ ble_hs_process_rx_data_queue(void)
struct os_mbuf *om;
while ((om = os_mqueue_get(&ble_hs_rx_q)) != NULL) {
- host_hci_data_rx(om);
+ host_hci_acl_process(om);
}
}
static void
+ble_hs_clear_data_queue(struct os_mqueue *mqueue)
+{
+ struct os_mbuf *om;
+
+ while ((om = os_mqueue_get(mqueue)) != NULL) {
+ os_mbuf_free_chain(om);
+ }
+}
+
+
+static void
ble_hs_heartbeat_timer_reset(uint32_t ticks)
{
int rc;
@@ -202,6 +215,85 @@ ble_hs_heartbeat_sched(int32_t ticks_from_now)
}
/**
+ * Indicates whether the host has synchronized with the controller.
+ * Synchronization must occur before any host procedures can be performed.
+ *
+ * @return 1 if the host and controller are in sync;
+ * 0 if the host and controller our out of sync.
+ */
+int
+ble_hs_synced(void)
+{
+ return ble_hs_sync_state == BLE_HS_SYNC_STATE_GOOD;
+}
+
+static int
+ble_hs_sync(void)
+{
+ int rc;
+
+ /* Set the sync state to "bringup." This allows the parent task to send
+ * the startup sequence to the controller. No other tasks are allowed to
+ * send any commands.
+ */
+ ble_hs_sync_state = BLE_HS_SYNC_STATE_BRINGUP;
+
+ rc = ble_hs_startup_go();
+ if (rc == 0) {
+ ble_hs_sync_state = BLE_HS_SYNC_STATE_GOOD;
+ if (ble_hs_cfg.sync_cb != NULL) {
+ ble_hs_cfg.sync_cb();
+ }
+ } else {
+ ble_hs_sync_state = BLE_HS_SYNC_STATE_BAD;
+ }
+
+ ble_hs_heartbeat_sched(BLE_HS_SYNC_RETRY_RATE);
+
+ if (rc == 0) {
+ STATS_INC(ble_hs_stats, sync);
+ }
+
+ return rc;
+}
+
+static int
+ble_hs_reset(void)
+{
+ uint16_t conn_handle;
+ int rc;
+
+ STATS_INC(ble_hs_stats, reset);
+
+ ble_hs_sync_state = 0;
+
+ rc = ble_hci_trans_reset();
+ if (rc != 0) {
+ return rc;
+ }
+
+ ble_hs_clear_data_queue(&ble_hs_tx_q);
+ ble_hs_clear_data_queue(&ble_hs_rx_q);
+
+ while (1) {
+ conn_handle = ble_hs_atomic_first_conn_handle();
+ if (conn_handle == BLE_HS_CONN_HANDLE_NONE) {
+ break;
+ }
+
+ ble_gap_conn_broken(conn_handle, ble_hs_reset_reason);
+ }
+
+ if (ble_hs_cfg.reset_cb != NULL && ble_hs_reset_reason != 0) {
+ ble_hs_cfg.reset_cb(ble_hs_reset_reason);
+ }
+ ble_hs_reset_reason = 0;
+
+ rc = ble_hs_sync();
+ return rc;
+}
+
+/**
* Called once a second by the ble_hs heartbeat timer. Handles unresponsive
* timeouts and periodic retries in case of resource shortage.
*/
@@ -210,6 +302,11 @@ ble_hs_heartbeat(void *unused)
{
int32_t ticks_until_next;
+ if (!ble_hs_sync_state) {
+ ble_hs_reset();
+ return;
+ }
+
/* Ensure the timer expires at least once in the next second.
* XXX: This is not very power efficient. We will need separate timers for
* each module.
@@ -235,7 +332,9 @@ ble_hs_event_handle(void *unused)
{
struct os_callout_func *cf;
struct os_event *ev;
+ uint8_t *hci_evt;
os_sr_t sr;
+ int rc;
int i;
i = 0;
@@ -267,10 +366,15 @@ ble_hs_event_handle(void *unused)
break;
case BLE_HOST_HCI_EVENT_CTLR_EVENT:
- host_hci_os_event_proc(ev);
+ hci_evt = ev->ev_arg;
+ rc = os_memblock_put(&ble_hs_hci_ev_pool, ev);
+ BLE_HS_DBG_ASSERT_EVAL(rc == 0);
+
+ host_hci_evt_process(hci_evt);
break;
case BLE_HS_EVENT_TX_NOTIFICATIONS:
+ BLE_HS_DBG_ASSERT(ev == &ble_hs_event_tx_notifications);
ble_gatts_tx_notifications();
case OS_EVENT_T_MQUEUE_DATA:
@@ -278,6 +382,11 @@ ble_hs_event_handle(void *unused)
ble_hs_process_rx_data_queue();
break;
+ case BLE_HS_EVENT_RESET:
+ BLE_HS_DBG_ASSERT(ev == &ble_hs_event_reset);
+ ble_hs_reset();
+ break;
+
default:
BLE_HS_DBG_ASSERT(0);
break;
@@ -292,6 +401,22 @@ ble_hs_event_enqueue(struct os_event *ev)
os_eventq_put(ble_hs_parent_evq, &ble_hs_event_co.cf_c.c_ev);
}
+void
+ble_hs_enqueue_hci_event(uint8_t *hci_evt)
+{
+ struct os_event *ev;
+
+ ev = os_memblock_get(&ble_hs_hci_ev_pool);
+ if (ev == NULL) {
+ ble_hci_trans_buf_free(ev->ev_arg);
+ } else {
+ ev->ev_queued = 0;
+ ev->ev_type = BLE_HOST_HCI_EVENT_CTLR_EVENT;
+ ev->ev_arg = hci_evt;
+ ble_hs_event_enqueue(ev);
+ }
+}
+
/**
* Schedules for all pending notifications and indications to be sent in the
* host parent task.
@@ -309,6 +434,15 @@ ble_hs_notifications_sched(void)
ble_hs_event_enqueue(&ble_hs_event_tx_notifications);
}
+void
+ble_hs_sched_reset(int reason)
+{
+ BLE_HS_DBG_ASSERT(ble_hs_reset_reason == 0);
+
+ ble_hs_reset_reason = reason;
+ ble_hs_event_enqueue(&ble_hs_event_reset);
+}
+
/**
* Synchronizes the host with the controller by sending a sequence of HCI
* commands. This function must be called before any other host functionality
@@ -316,6 +450,10 @@ ble_hs_notifications_sched(void)
* initialized. Typically, the host-parent-task calls this function at the top
* of its task routine.
*
+ * If the host fails to synchronize with the controller (if the controller is
+ * not fully booted, for example), the host will attempt to resynchronize every
+ * 100 ms. For this reason, an error return code is not necessarily fatal.
+ *
* @return 0 on success; nonzero on error.
*/
int
@@ -325,11 +463,9 @@ ble_hs_start(void)
ble_hs_parent_task = os_sched_get_current_task();
- ble_hs_heartbeat_timer_reset(BLE_HS_HEARTBEAT_OS_TICKS);
-
ble_gatts_start();
- rc = ble_hs_startup_go();
+ rc = ble_hs_sync();
return rc;
}
@@ -343,19 +479,18 @@ ble_hs_start(void)
* @return 0 on success; nonzero on failure.
*/
int
-ble_hs_rx_data(struct os_mbuf *om)
+ble_hs_rx_data(struct os_mbuf *om, void *arg)
{
int rc;
rc = os_mqueue_put(&ble_hs_rx_q, &ble_hs_evq, om);
- if (rc != 0) {
+ if (rc == 0) {
+ os_eventq_put(ble_hs_parent_evq, &ble_hs_event_co.cf_c.c_ev);
+ } else {
os_mbuf_free_chain(om);
- return BLE_HS_EOS;
+ rc = BLE_HS_EOS;
}
-
- os_eventq_put(ble_hs_parent_evq, &ble_hs_event_co.cf_c.c_ev);
-
- return 0;
+ return rc;
}
int
@@ -375,9 +510,6 @@ ble_hs_tx_data(struct os_mbuf *om)
static void
ble_hs_free_mem(void)
{
- free(ble_hs_hci_evt_buf);
- ble_hs_hci_evt_buf = NULL;
-
free(ble_hs_hci_os_event_buf);
ble_hs_hci_os_event_buf = NULL;
}
@@ -418,30 +550,17 @@ ble_hs_init(struct os_eventq *app_evq, struct ble_hs_cfg *cfg)
log_console_handler_init(&ble_hs_log_console_handler);
log_register("ble_hs", &ble_hs_log, &ble_hs_log_console_handler);
- ble_hs_hci_evt_buf = malloc(OS_MEMPOOL_BYTES(ble_hs_cfg.max_hci_bufs,
- HCI_EVT_BUF_SIZE));
- if (ble_hs_hci_evt_buf == NULL) {
- rc = BLE_HS_ENOMEM;
- goto err;
- }
-
- /* Create memory pool of command buffers */
- rc = os_mempool_init(&g_hci_evt_pool, ble_hs_cfg.max_hci_bufs,
- HCI_EVT_BUF_SIZE, ble_hs_hci_evt_buf,
- "HCICmdPool");
- assert(rc == 0);
-
- ble_hs_hci_os_event_buf = malloc(OS_MEMPOOL_BYTES(ble_hs_cfg.max_hci_bufs,
- HCI_OS_EVENT_BUF_SIZE));
+ ble_hs_hci_os_event_buf = malloc(
+ OS_MEMPOOL_BYTES(ble_hs_cfg.max_hci_bufs, sizeof (struct os_event)));
if (ble_hs_hci_os_event_buf == NULL) {
rc = BLE_HS_ENOMEM;
goto err;
}
/* Create memory pool of OS events */
- rc = os_mempool_init(&g_hci_os_event_pool, ble_hs_cfg.max_hci_bufs,
- HCI_OS_EVENT_BUF_SIZE, ble_hs_hci_os_event_buf,
- "HCIOsEventPool");
+ rc = os_mempool_init(&ble_hs_hci_ev_pool, ble_hs_cfg.max_hci_bufs,
+ sizeof (struct os_event), ble_hs_hci_os_event_buf,
+ "ble_hs_hci_ev_pool");
assert(rc == 0);
/* Initialize eventq */
@@ -516,6 +635,9 @@ ble_hs_init(struct os_eventq *app_evq, struct ble_hs_cfg *cfg)
ble_hs_dbg_mutex_locked = 0;
#endif
+ /* Configure the HCI transport to communicate with a host. */
+ ble_hci_trans_cfg_hs(host_hci_evt_rx, NULL, ble_hs_rx_data, NULL);
+
return 0;
err:
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fd02e1e/net/nimble/host/src/ble_hs_atomic.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_atomic.c b/net/nimble/host/src/ble_hs_atomic.c
index 36a603d..9c933fc 100644
--- a/net/nimble/host/src/ble_hs_atomic.c
+++ b/net/nimble/host/src/ble_hs_atomic.c
@@ -93,3 +93,23 @@ ble_hs_atomic_conn_set_flags(uint16_t conn_handle, ble_hs_conn_flags_t flags,
return rc;
}
+
+uint16_t
+ble_hs_atomic_first_conn_handle(void)
+{
+ const struct ble_hs_conn *conn;
+ uint16_t conn_handle;
+
+ ble_hs_lock();
+
+ conn = ble_hs_conn_first();
+ if (conn != NULL) {
+ conn_handle = conn->bhc_handle;
+ } else {
+ conn_handle = BLE_HS_CONN_HANDLE_NONE;
+ }
+
+ ble_hs_unlock();
+
+ return conn_handle;
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fd02e1e/net/nimble/host/src/ble_hs_atomic_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_atomic_priv.h b/net/nimble/host/src/ble_hs_atomic_priv.h
index a08b7ca..d82eeab 100644
--- a/net/nimble/host/src/ble_hs_atomic_priv.h
+++ b/net/nimble/host/src/ble_hs_atomic_priv.h
@@ -28,5 +28,6 @@ int ble_hs_atomic_conn_flags(uint16_t conn_handle,
ble_hs_conn_flags_t *out_flags);
int ble_hs_atomic_conn_set_flags(uint16_t conn_handle,
ble_hs_conn_flags_t flags, int on);
+uint16_t ble_hs_atomic_first_conn_handle(void);
#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fd02e1e/net/nimble/host/src/ble_hs_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_priv.h b/net/nimble/host/src/ble_hs_priv.h
index 79ef6b9..9e788dd 100644
--- a/net/nimble/host/src/ble_hs_priv.h
+++ b/net/nimble/host/src/ble_hs_priv.h
@@ -47,9 +47,15 @@ struct ble_hs_conn;
struct ble_l2cap_chan;
struct os_mbuf;
struct os_mempool;
+struct os_event;
#define BLE_HOST_HCI_EVENT_CTLR_EVENT (OS_EVENT_T_PERUSER + 0)
#define BLE_HS_EVENT_TX_NOTIFICATIONS (OS_EVENT_T_PERUSER + 1)
+#define BLE_HS_EVENT_RESET (OS_EVENT_T_PERUSER + 2)
+
+#define BLE_HS_SYNC_STATE_BAD 0
+#define BLE_HS_SYNC_STATE_BRINGUP 1
+#define BLE_HS_SYNC_STATE_GOOD 2
STATS_SECT_START(ble_hs_stats)
STATS_SECT_ENTRY(conn_create)
@@ -58,17 +64,26 @@ STATS_SECT_START(ble_hs_stats)
STATS_SECT_ENTRY(hci_event)
STATS_SECT_ENTRY(hci_invalid_ack)
STATS_SECT_ENTRY(hci_unknown_event)
+ STATS_SECT_ENTRY(hci_timeout)
+ STATS_SECT_ENTRY(reset)
+ STATS_SECT_ENTRY(sync)
STATS_SECT_END
extern STATS_SECT_DECL(ble_hs_stats) ble_hs_stats;
extern struct ble_hs_cfg ble_hs_cfg;
extern struct os_mbuf_pool ble_hs_mbuf_pool;
+extern uint8_t ble_hs_sync_state;
extern const uint8_t ble_hs_misc_null_addr[6];
void ble_hs_process_tx_data_queue(void);
void ble_hs_process_rx_data_queue(void);
int ble_hs_tx_data(struct os_mbuf *om);
+void ble_hs_enqueue_hci_event(uint8_t *hci_evt);
+void ble_hs_event_enqueue(struct os_event *ev);
+
+int host_hci_evt_rx(uint8_t *hci_ev, void *arg);
+int host_hci_acl_process(struct os_mbuf *om);
int ble_hs_misc_malloc_mempool(void **mem, struct os_mempool *pool,
int num_entries, int entry_size, char *name);
@@ -86,6 +101,7 @@ int ble_hs_locked_by_cur_task(void);
int ble_hs_is_parent_task(void);
void ble_hs_lock(void);
void ble_hs_unlock(void);
+void ble_hs_sched_reset(int reason);
void ble_hs_heartbeat_sched(int32_t ticks);
void ble_hs_notifications_sched(void);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fd02e1e/net/nimble/host/src/ble_hs_pvcy.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_pvcy.c b/net/nimble/host/src/ble_hs_pvcy.c
index 05f9122..94a5586 100644
--- a/net/nimble/host/src/ble_hs_pvcy.c
+++ b/net/nimble/host/src/ble_hs_pvcy.c
@@ -145,11 +145,12 @@ ble_hs_pvcy_ensure_started(void)
return 0;
}
-void
+int
ble_hs_pvcy_set_our_irk(const uint8_t *irk)
{
uint8_t tmp_addr[6];
uint8_t new_irk[16];
+ int rc;
memset(new_irk, 0, sizeof(new_irk));
@@ -163,17 +164,33 @@ ble_hs_pvcy_set_our_irk(const uint8_t *irk)
if (memcmp(ble_hs_pvcy_irk, new_irk, 16) != 0) {
memcpy(ble_hs_pvcy_irk, new_irk, 16);
- ble_hs_pvcy_set_resolve_enabled(0);
- ble_hs_pvcy_clear_entries();
- ble_hs_pvcy_set_resolve_enabled(1);
+ rc = ble_hs_pvcy_set_resolve_enabled(0);
+ if (rc != 0) {
+ return rc;
+ }
+
+ rc = ble_hs_pvcy_clear_entries();
+ if (rc != 0) {
+ return rc;
+ }
+
+ rc = ble_hs_pvcy_set_resolve_enabled(1);
+ if (rc != 0) {
+ return rc;
+ }
/* Push a null address identity to the controller. The controller uses
* this entry to generate an RPA when we do advertising with
* own-addr-type = rpa.
*/
memset(tmp_addr, 0, 6);
- ble_hs_pvcy_add_entry(tmp_addr, 0, ble_hs_pvcy_irk);
+ rc = ble_hs_pvcy_add_entry(tmp_addr, 0, ble_hs_pvcy_irk);
+ if (rc != 0) {
+ return rc;
+ }
}
+
+ return 0;
}
int
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fd02e1e/net/nimble/host/src/ble_hs_pvcy_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_pvcy_priv.h b/net/nimble/host/src/ble_hs_pvcy_priv.h
index 2635778..16ded35 100644
--- a/net/nimble/host/src/ble_hs_pvcy_priv.h
+++ b/net/nimble/host/src/ble_hs_pvcy_priv.h
@@ -22,7 +22,7 @@
#include <inttypes.h>
-void ble_hs_pvcy_set_our_irk(const uint8_t *irk);
+int ble_hs_pvcy_set_our_irk(const uint8_t *irk);
int ble_hs_pvcy_our_irk(const uint8_t **out_irk);
int ble_hs_pvcy_remove_entry(uint8_t addr_type, uint8_t *addr);
int ble_hs_pvcy_add_entry(uint8_t *addr, uint8_t addrtype, uint8_t *irk);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fd02e1e/net/nimble/host/src/ble_hs_startup.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_startup.c b/net/nimble/host/src/ble_hs_startup.c
index 45fb5ce..1ce49a7 100644
--- a/net/nimble/host/src/ble_hs_startup.c
+++ b/net/nimble/host/src/ble_hs_startup.c
@@ -222,19 +222,16 @@ ble_hs_startup_go(void)
rc = ble_hs_startup_set_evmask_tx();
if (rc != 0) {
- assert(0);
return rc;
}
rc = ble_hs_startup_le_set_evmask_tx();
if (rc != 0) {
- assert(0);
return rc;
}
rc = ble_hs_startup_le_read_buf_sz_tx();
if (rc != 0) {
- assert(0);
return rc;
}
@@ -242,7 +239,6 @@ ble_hs_startup_go(void)
rc = ble_hs_startup_le_read_sup_f_tx();
if (rc != 0) {
- assert(0);
return rc;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fd02e1e/net/nimble/host/src/host_dbg.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/host_dbg.c b/net/nimble/host/src/host_dbg.c
index 6b58624..f5d46a3 100644
--- a/net/nimble/host/src/host_dbg.c
+++ b/net/nimble/host/src/host_dbg.c
@@ -23,7 +23,7 @@
#include "os/os.h"
#include "console/console.h"
#include "nimble/hci_common.h"
-#include "nimble/hci_transport.h"
+#include "nimble/ble_hci_trans.h"
#include "ble_hs_priv.h"
static void
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fd02e1e/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 791aec2..ed5dd6a 100644
--- a/net/nimble/host/src/host_hci.c
+++ b/net/nimble/host/src/host_hci.c
@@ -23,7 +23,7 @@
#include "os/os.h"
#include "console/console.h"
#include "nimble/hci_common.h"
-#include "nimble/hci_transport.h"
+#include "nimble/ble_hci_trans.h"
#include "host/host_hci.h"
#include "host/ble_gap.h"
#include "ble_hs_priv.h"
@@ -582,7 +582,7 @@ host_hci_set_buf_size(uint16_t pktlen, uint8_t max_pkts)
}
int
-host_hci_event_rx(uint8_t *data)
+host_hci_evt_process(uint8_t *data)
{
const struct host_hci_event_dispatch_entry *entry;
uint8_t event_code;
@@ -604,40 +604,20 @@ host_hci_event_rx(uint8_t *data)
entry = host_hci_dispatch_entry_find(event_code);
if (entry == NULL) {
- STATS_INC(ble_hs_stats, hci_invalid_ack);
+ STATS_INC(ble_hs_stats, hci_unknown_event);
rc = BLE_HS_ENOTSUP;
} else {
rc = entry->hed_fn(event_code, data, event_len);
}
- return rc;
-}
-
-int
-host_hci_os_event_proc(struct os_event *ev)
-{
- os_error_t err;
- int rc;
-
- rc = host_hci_event_rx(ev->ev_arg);
-
- /* Free the command buffer */
- err = os_memblock_put(&g_hci_evt_pool, ev->ev_arg);
- BLE_HS_DBG_ASSERT_EVAL(err == OS_OK);
-
- /* Free the event */
- err = os_memblock_put(&g_hci_os_event_pool, ev);
- BLE_HS_DBG_ASSERT_EVAL(err == OS_OK);
+ ble_hci_trans_buf_free(data);
return rc;
}
-/* XXX: For now, put this here */
int
-ble_hci_transport_ctlr_event_send(uint8_t *hci_ev)
+host_hci_evt_rx(uint8_t *hci_ev, void *arg)
{
- struct os_event *ev;
- os_error_t err;
int enqueue;
BLE_HS_DBG_ASSERT(hci_ev != NULL);
@@ -659,25 +639,12 @@ ble_hci_transport_ctlr_event_send(uint8_t *hci_ev)
}
if (enqueue) {
- /* Get an event structure off the queue */
- ev = (struct os_event *)os_memblock_get(&g_hci_os_event_pool);
- if (!ev) {
- err = os_memblock_put(&g_hci_evt_pool, hci_ev);
- BLE_HS_DBG_ASSERT_EVAL(err == OS_OK);
- return -1;
- }
-
- /* Fill out the event and post to host task. */
- ev->ev_queued = 0;
- ev->ev_type = BLE_HOST_HCI_EVENT_CTLR_EVENT;
- ev->ev_arg = hci_ev;
- ble_hs_event_enqueue(ev);
+ ble_hs_enqueue_hci_event(hci_ev);
}
return 0;
}
-
/**
* Called when a data packet is received from the controller. This function
* consumes the supplied mbuf, regardless of the outcome.
@@ -688,7 +655,7 @@ ble_hci_transport_ctlr_event_send(uint8_t *hci_ev)
* @return 0 on success; nonzero on failure.
*/
int
-host_hci_data_rx(struct os_mbuf *om)
+host_hci_acl_process(struct os_mbuf *om)
{
struct hci_data_hdr hci_hdr;
struct ble_hs_conn *conn;
@@ -703,7 +670,7 @@ host_hci_data_rx(struct os_mbuf *om)
}
#if (BLETEST_THROUGHPUT_TEST == 0)
- BLE_HS_LOG(DEBUG, "host_hci_data_rx(): handle=%u pb=%x len=%u data=",
+ BLE_HS_LOG(DEBUG, "host_hci_acl_process(): handle=%u pb=%x len=%u data=",
BLE_HCI_DATA_HANDLE(hci_hdr.hdh_handle_pb_bc),
BLE_HCI_DATA_PB(hci_hdr.hdh_handle_pb_bc),
hci_hdr.hdh_len);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fd02e1e/net/nimble/host/src/host_hci_cmd.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/host_hci_cmd.c b/net/nimble/host/src/host_hci_cmd.c
index a3e021d..cce2e26 100644
--- a/net/nimble/host/src/host_hci_cmd.c
+++ b/net/nimble/host/src/host_hci_cmd.c
@@ -24,32 +24,17 @@
#include "os/os.h"
#include "console/console.h"
#include "nimble/hci_common.h"
-#include "nimble/hci_transport.h"
+#include "nimble/ble_hci_trans.h"
#include "host/host_hci.h"
#include "host_dbg_priv.h"
#include "ble_hs_priv.h"
-#ifdef PHONY_TRANSPORT
-#include "host/ble_hs_test.h"
-#endif
-
-/**
- * This buffer holds one of the following:
- * 1. The current outgoing HCI command.
- * 2. The current incoming HCI acknowledgement (command complete or command
- * status event).
- */
-uint8_t host_hci_cmd_buf[HCI_EVT_BUF_SIZE];
static int
host_hci_cmd_transport(uint8_t *cmdbuf)
{
-#ifdef PHONY_TRANSPORT
- ble_hs_test_hci_txed(cmdbuf);
- return 0;
-#else
int rc;
- rc = ble_hci_transport_host_cmd_send(cmdbuf);
+ rc = ble_hci_trans_hs_cmd_tx(cmdbuf);
switch (rc) {
case 0:
return 0;
@@ -60,7 +45,6 @@ host_hci_cmd_transport(uint8_t *cmdbuf)
default:
return BLE_HS_EUNKNOWN;
}
-#endif
}
void
@@ -79,19 +63,23 @@ host_hci_write_hdr(uint8_t ogf, uint8_t ocf, uint8_t len, void *buf)
int
host_hci_cmd_send(uint8_t ogf, uint8_t ocf, uint8_t len, const void *cmddata)
{
+ uint8_t *buf;
int rc;
- htole16(host_hci_cmd_buf, ogf << 10 | ocf);
- host_hci_cmd_buf[2] = len;
+ buf = ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_CMD);
+ BLE_HS_DBG_ASSERT(buf != NULL);
+
+ htole16(buf, ogf << 10 | ocf);
+ buf[2] = len;
if (len != 0) {
- memcpy(host_hci_cmd_buf + BLE_HCI_CMD_HDR_LEN, cmddata, len);
+ memcpy(buf + BLE_HCI_CMD_HDR_LEN, cmddata, len);
}
BLE_HS_LOG(DEBUG, "host_hci_cmd_send: ogf=0x%02x ocf=0x%02x len=%d\n",
ogf, ocf, len);
- ble_hs_log_flat_buf(host_hci_cmd_buf, len + BLE_HCI_CMD_HDR_LEN);
+ ble_hs_log_flat_buf(buf, len + BLE_HCI_CMD_HDR_LEN);
BLE_HS_LOG(DEBUG, "\n");
- rc = host_hci_cmd_transport(host_hci_cmd_buf);
+ rc = host_hci_cmd_transport(buf);
if (rc == 0) {
STATS_INC(ble_hs_stats, hci_cmd);
@@ -110,6 +98,24 @@ host_hci_cmd_send_buf(void *buf)
uint8_t len;
int rc;
+ switch (ble_hs_sync_state) {
+ case BLE_HS_SYNC_STATE_BAD:
+ return BLE_HS_ENOTSYNCED;
+
+ case BLE_HS_SYNC_STATE_BRINGUP:
+ if (!ble_hs_is_parent_task()) {
+ return BLE_HS_ENOTSYNCED;
+ }
+ break;
+
+ case BLE_HS_SYNC_STATE_GOOD:
+ break;
+
+ default:
+ BLE_HS_DBG_ASSERT(0);
+ return BLE_HS_EUNKNOWN;
+ }
+
u8ptr = buf;
opcode = le16toh(u8ptr + 0);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fd02e1e/net/nimble/host/src/test/ble_gap_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gap_test.c b/net/nimble/host/src/test/ble_gap_test.c
index faf62c3..2ae3354 100644
--- a/net/nimble/host/src/test/ble_gap_test.c
+++ b/net/nimble/host/src/test/ble_gap_test.c
@@ -1136,6 +1136,7 @@ TEST_CASE(ble_gap_test_case_conn_find)
struct ble_gap_conn_desc desc;
struct ble_hs_conn *conn;
+ uint8_t pub_addr[6];
int rc;
/*** We are master; public addresses. */
@@ -1150,6 +1151,10 @@ TEST_CASE(ble_gap_test_case_conn_find)
ble_gap_test_util_connect_cb,
NULL);
+
+ rc = ble_hs_id_copy_addr(BLE_ADDR_TYPE_PUBLIC, pub_addr, NULL);
+ TEST_ASSERT_FATAL(rc == 0);
+
rc = ble_gap_conn_find(8, &desc);
TEST_ASSERT_FATAL(rc == 0);
TEST_ASSERT(desc.conn_handle == 8);
@@ -1157,8 +1162,8 @@ TEST_CASE(ble_gap_test_case_conn_find)
TEST_ASSERT(desc.our_ota_addr_type == BLE_ADDR_TYPE_PUBLIC);
TEST_ASSERT(desc.peer_ota_addr_type == BLE_ADDR_TYPE_PUBLIC);
TEST_ASSERT(desc.role == BLE_GAP_ROLE_MASTER);
- TEST_ASSERT(memcmp(desc.our_ota_addr, g_dev_addr, 6) == 0);
- TEST_ASSERT(memcmp(desc.our_id_addr, g_dev_addr, 6) == 0);
+ TEST_ASSERT(memcmp(desc.our_ota_addr, pub_addr, 6) == 0);
+ TEST_ASSERT(memcmp(desc.our_id_addr, pub_addr, 6) == 0);
TEST_ASSERT(memcmp(desc.peer_ota_addr,
((uint8_t[6]){2,3,4,5,6,7}), 6) == 0);
TEST_ASSERT(memcmp(desc.peer_id_addr,
@@ -1203,7 +1208,7 @@ TEST_CASE(ble_gap_test_case_conn_find)
TEST_ASSERT(desc.role == BLE_GAP_ROLE_MASTER);
TEST_ASSERT(memcmp(desc.our_ota_addr,
((uint8_t[6]){0x40,1,2,3,4,5}), 6) == 0);
- TEST_ASSERT(memcmp(desc.our_id_addr, g_dev_addr, 6) == 0);
+ TEST_ASSERT(memcmp(desc.our_id_addr, pub_addr, 6) == 0);
TEST_ASSERT(memcmp(desc.peer_ota_addr,
((uint8_t[6]){0x50,1,2,3,4,5}), 6) == 0);
TEST_ASSERT(memcmp(desc.peer_id_addr,
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fd02e1e/net/nimble/host/src/test/ble_host_hci_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_host_hci_test.c b/net/nimble/host/src/test/ble_host_hci_test.c
index a8e8d82..32c5cf4 100644
--- a/net/nimble/host/src/test/ble_host_hci_test.c
+++ b/net/nimble/host/src/test/ble_host_hci_test.c
@@ -21,6 +21,7 @@
#include <errno.h>
#include <string.h>
#include "nimble/hci_common.h"
+#include "nimble/ble_hci_trans.h"
#include "host/host_hci.h"
#include "host/ble_hs_test.h"
#include "testutil/testutil.h"
@@ -28,13 +29,16 @@
TEST_CASE(ble_host_hci_test_event_bad)
{
- uint8_t buf[2];
+ uint8_t *buf;
int rc;
/*** Invalid event code. */
+ buf = ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_HI);
+ TEST_ASSERT_FATAL(buf != NULL);
+
buf[0] = 0xff;
buf[1] = 0;
- rc = host_hci_event_rx(buf);
+ rc = host_hci_evt_process(buf);
TEST_ASSERT(rc == BLE_HS_ENOTSUP);
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fd02e1e/net/nimble/host/src/test/ble_hs_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_test.c b/net/nimble/host/src/test/ble_hs_test.c
index 16ae9b9..0b89bc9 100644
--- a/net/nimble/host/src/test/ble_hs_test.c
+++ b/net/nimble/host/src/test/ble_hs_test.c
@@ -23,22 +23,6 @@
#include "testutil/testutil.h"
#include "ble_hs_test_util.h"
-/* Our global device address. */
-uint8_t g_dev_addr[BLE_DEV_ADDR_LEN] = { 0x0a, 0x54, 0xab, 0x49, 0x7f, 0x06 };
-
-void
-ble_hs_test_pkt_txed(struct os_mbuf *om)
-{
- ble_hs_test_util_prev_tx_enqueue(om);
-}
-
-void
-ble_hs_test_hci_txed(uint8_t *cmdbuf)
-{
- ble_hs_test_util_enqueue_hci_tx(cmdbuf);
- os_memblock_put(&g_hci_evt_pool, cmdbuf);
-}
-
#ifdef MYNEWT_SELFTEST
int
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fd02e1e/net/nimble/host/src/test/ble_hs_test_util.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_test_util.c b/net/nimble/host/src/test/ble_hs_test_util.c
index 1a6dd5e..831a077 100644
--- a/net/nimble/host/src/test/ble_hs_test_util.c
+++ b/net/nimble/host/src/test/ble_hs_test_util.c
@@ -23,12 +23,21 @@
#include "testutil/testutil.h"
#include "nimble/ble.h"
#include "nimble/hci_common.h"
-#include "nimble/hci_transport.h"
+#include "nimble/ble_hci_trans.h"
#include "host/ble_hs_adv.h"
#include "host/ble_hs_id.h"
#include "host/host_hci.h"
+#include "transport/ram/ble_hci_ram.h"
#include "ble_hs_test_util.h"
+/* Our global device address. */
+uint8_t g_dev_addr[BLE_DEV_ADDR_LEN];
+
+#define BLE_HS_TEST_UTIL_PUB_ADDR_VAL { 0x0a, 0x54, 0xab, 0x49, 0x7f, 0x06 }
+
+static const uint8_t ble_hs_test_util_pub_addr[BLE_DEV_ADDR_LEN] =
+ BLE_HS_TEST_UTIL_PUB_ADDR_VAL;
+
/** Use lots of small mbufs to ensure correct mbuf usage. */
#define BLE_HS_TEST_UTIL_NUM_MBUFS (100)
#define BLE_HS_TEST_UTIL_BUF_SIZE OS_ALIGN(100, 4)
@@ -246,13 +255,14 @@ ble_hs_test_util_rx_hci_evt(uint8_t *evt)
TEST_ASSERT_FATAL(totlen <= UINT8_MAX + BLE_HCI_EVENT_HDR_LEN);
if (os_started()) {
- evbuf = os_memblock_get(&g_hci_evt_pool);
+ evbuf = ble_hci_trans_buf_alloc(
+ BLE_HCI_TRANS_BUF_EVT_LO);
TEST_ASSERT_FATAL(evbuf != NULL);
memcpy(evbuf, evt, totlen);
- rc = ble_hci_transport_ctlr_event_send(evbuf);
+ rc = ble_hci_trans_ll_evt_tx(evbuf);
} else {
- rc = host_hci_event_rx(evt);
+ rc = host_hci_evt_process(evt);
}
TEST_ASSERT_FATAL(rc == 0);
@@ -679,14 +689,6 @@ ble_hs_test_util_adv_start(uint8_t own_addr_type,
if (adv_params->conn_mode != BLE_GAP_CONN_MODE_DIR) {
acks[i] = (struct ble_hs_test_util_phony_ack) {
- BLE_HS_TEST_UTIL_LE_OPCODE(BLE_HCI_OCF_LE_RD_ADV_CHAN_TXPWR),
- ble_hs_test_util_exp_hci_status(i, fail_idx, fail_status),
- { 0 },
- 1,
- };
- i++;
-
- acks[i] = (struct ble_hs_test_util_phony_ack) {
BLE_HS_TEST_UTIL_LE_OPCODE(BLE_HCI_OCF_LE_SET_ADV_DATA),
ble_hs_test_util_exp_hci_status(i, fail_idx, fail_status),
};
@@ -777,6 +779,35 @@ ble_hs_test_util_conn_update(uint16_t conn_handle,
}
int
+ble_hs_test_util_set_our_irk(const uint8_t *irk, int fail_idx,
+ uint8_t hci_status)
+{
+ int rc;
+
+ ble_hs_test_util_set_ack_seq(((struct ble_hs_test_util_phony_ack[]) {
+ {
+ BLE_HS_TEST_UTIL_LE_OPCODE(BLE_HCI_OCF_LE_SET_ADDR_RES_EN),
+ ble_hs_test_util_exp_hci_status(0, fail_idx, hci_status),
+ },
+ {
+ BLE_HS_TEST_UTIL_LE_OPCODE(BLE_HCI_OCF_LE_CLR_RESOLV_LIST),
+ ble_hs_test_util_exp_hci_status(1, fail_idx, hci_status),
+ },
+ {
+ BLE_HS_TEST_UTIL_LE_OPCODE(BLE_HCI_OCF_LE_SET_ADDR_RES_EN),
+ ble_hs_test_util_exp_hci_status(2, fail_idx, hci_status),
+ },
+ {
+ BLE_HS_TEST_UTIL_LE_OPCODE(BLE_HCI_OCF_LE_ADD_RESOLV_LIST),
+ ble_hs_test_util_exp_hci_status(3, fail_idx, hci_status),
+ },
+ }));
+
+ rc = ble_hs_pvcy_set_our_irk(irk);
+ return rc;
+}
+
+int
ble_hs_test_util_security_initiate(uint16_t conn_handle, uint8_t hci_status)
{
int rc;
@@ -906,7 +937,8 @@ ble_hs_test_util_set_startup_acks(void)
{
.opcode = host_hci_opcode_join(BLE_HCI_OGF_LE,
BLE_HCI_OCF_LE_RD_BUF_SIZE),
- .evt_params = { 0xff, 0xff, 1 },
+ /* Use a very low buffer size (16) to test fragmentation. */
+ .evt_params = { 0x10, 0x00, 0x20 },
.evt_params_len = 3,
},
{
@@ -916,6 +948,12 @@ ble_hs_test_util_set_startup_acks(void)
.evt_params_len = 8,
},
{
+ .opcode = host_hci_opcode_join(BLE_HCI_OGF_INFO_PARAMS,
+ BLE_HCI_OCF_IP_RD_BD_ADDR),
+ .evt_params = BLE_HS_TEST_UTIL_PUB_ADDR_VAL,
+ .evt_params_len = 6,
+ },
+ {
.opcode = host_hci_opcode_join(BLE_HCI_OGF_LE,
BLE_HCI_OCF_LE_SET_ADDR_RES_EN),
},
@@ -1279,9 +1317,25 @@ ble_hs_test_util_post_test(void *arg)
ble_hs_test_util_assert_mbufs_freed();
}
+static int
+ble_hs_test_util_pkt_txed(struct os_mbuf *om, void *arg)
+{
+ ble_hs_test_util_prev_tx_enqueue(om);
+ return 0;
+}
+
+static int
+ble_hs_test_util_hci_txed(uint8_t *cmdbuf, void *arg)
+{
+ ble_hs_test_util_enqueue_hci_tx(cmdbuf);
+ ble_hci_trans_buf_free(cmdbuf);
+ return 0;
+}
+
void
ble_hs_test_util_init(void)
{
+ struct ble_hci_ram_cfg hci_cfg;
struct ble_hs_cfg cfg;
int rc;
@@ -1323,10 +1377,18 @@ ble_hs_test_util_init(void)
ble_hci_set_phony_ack_cb(NULL);
- ble_hs_test_util_prev_hci_tx_clear();
+ ble_hci_trans_cfg_ll(ble_hs_test_util_hci_txed, NULL,
+ ble_hs_test_util_pkt_txed, NULL);
- ble_hs_id_set_pub(g_dev_addr);
+ hci_cfg = ble_hci_ram_cfg_dflt;
+ hci_cfg.num_evt_bufs = cfg.max_hci_bufs;
+ rc = ble_hci_ram_init(&hci_cfg);
+ TEST_ASSERT_FATAL(rc == 0);
+
+ ble_hs_test_util_set_startup_acks();
- /* Use a very low buffer size (16) to test fragmentation. */
- host_hci_set_buf_size(16, 64);
+ rc = ble_hs_start();
+ TEST_ASSERT_FATAL(rc == 0);
+
+ ble_hs_test_util_prev_hci_tx_clear();
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fd02e1e/net/nimble/host/src/test/ble_hs_test_util.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_test_util.h b/net/nimble/host/src/test/ble_hs_test_util.h
index 9c4b982..00b090f 100644
--- a/net/nimble/host/src/test/ble_hs_test_util.h
+++ b/net/nimble/host/src/test/ble_hs_test_util.h
@@ -106,6 +106,8 @@ int ble_hs_test_util_wl_set(struct ble_gap_white_entry *white_list,
int ble_hs_test_util_conn_update(uint16_t conn_handle,
struct ble_gap_upd_params *params,
uint8_t hci_status);
+int ble_hs_test_util_set_our_irk(const uint8_t *irk, int fail_idx,
+ uint8_t hci_status);
int ble_hs_test_util_security_initiate(uint16_t conn_handle,
uint8_t hci_status);
int ble_hs_test_util_l2cap_rx_first_frag(uint16_t conn_handle, uint16_t cid,
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fd02e1e/net/nimble/host/src/test/ble_os_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_os_test.c b/net/nimble/host/src/test/ble_os_test.c
index 1ab8e0a..e12e489 100644
--- a/net/nimble/host/src/test/ble_os_test.c
+++ b/net/nimble/host/src/test/ble_os_test.c
@@ -21,7 +21,7 @@
#include "os/os.h"
#include "testutil/testutil.h"
#include "nimble/hci_common.h"
-#include "nimble/hci_transport.h"
+#include "nimble/ble_hci_trans.h"
#include "host/ble_hs_test.h"
#include "host/ble_gap.h"
#include "ble_hs_test_util.h"
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fd02e1e/net/nimble/host/src/test/ble_sm_test_util.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_sm_test_util.c b/net/nimble/host/src/test/ble_sm_test_util.c
index 1c052fb..bdecde6 100644
--- a/net/nimble/host/src/test/ble_sm_test_util.c
+++ b/net/nimble/host/src/test/ble_sm_test_util.c
@@ -229,7 +229,7 @@ ble_sm_test_util_init_good(struct ble_sm_test_params *params,
ble_sm_dbg_set_next_ediv(out_us->ediv);
ble_sm_dbg_set_next_master_id_rand(out_us->rand_num);
ble_sm_dbg_set_next_ltk(out_us->ltk);
- ble_hs_pvcy_set_our_irk(out_us->id_info->irk);
+ ble_hs_test_util_set_our_irk(out_us->id_info->irk, 0, 0);
ble_sm_dbg_set_next_csrk(out_us->sign_info->sig_key);
if (out_us->public_key != NULL) {
@@ -909,8 +909,20 @@ ble_sm_test_util_verify_tx_lt_key_req_neg_reply(uint16_t conn_handle)
}
static void
-ble_sm_test_util_set_lt_key_req_reply_ack(uint8_t status,
- uint16_t conn_handle)
+ble_sm_test_util_set_lt_key_req_neg_reply_ack(uint8_t status,
+ uint16_t conn_handle)
+{
+ static uint8_t params[BLE_HCI_LT_KEY_REQ_NEG_REPLY_ACK_PARAM_LEN];
+
+ htole16(params, conn_handle);
+ ble_hs_test_util_set_ack_params(
+ host_hci_opcode_join(BLE_HCI_OGF_LE,
+ BLE_HCI_OCF_LE_LT_KEY_REQ_NEG_REPLY),
+ status, params, sizeof params);
+}
+
+static void
+ble_sm_test_util_set_lt_key_req_reply_ack(uint8_t status, uint16_t conn_handle)
{
static uint8_t params[BLE_HCI_LT_KEY_REQ_REPLY_ACK_PARAM_LEN];
@@ -1303,7 +1315,7 @@ ble_sm_test_util_peer_bonding_bad(uint16_t ediv, uint64_t rand_num)
TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
/* Receive a long term key request from the controller. */
- ble_sm_test_util_set_lt_key_req_reply_ack(0, 2);
+ ble_sm_test_util_set_lt_key_req_neg_reply_ack(0, 2);
ble_sm_test_util_rx_lt_key_req(2, rand_num, ediv);
TEST_ASSERT(!conn->bhc_sec_state.encrypted);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fd02e1e/net/nimble/include/nimble/ble.h
----------------------------------------------------------------------
diff --git a/net/nimble/include/nimble/ble.h b/net/nimble/include/nimble/ble.h
index f2041c8..4deb9f3 100644
--- a/net/nimble/include/nimble/ble.h
+++ b/net/nimble/include/nimble/ble.h
@@ -34,10 +34,6 @@ struct ble_encryption_block
uint8_t cipher_text[BLE_ENC_BLOCK_SIZE];
};
-/* Shared command pool for transort between host and controller */
-extern struct os_mempool g_hci_evt_pool;
-extern struct os_mempool g_hci_os_event_pool;
-
/*
* BLE MBUF structure:
*
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fd02e1e/net/nimble/include/nimble/ble_hci_trans.h
----------------------------------------------------------------------
diff --git a/net/nimble/include/nimble/ble_hci_trans.h b/net/nimble/include/nimble/ble_hci_trans.h
new file mode 100644
index 0000000..822da96
--- /dev/null
+++ b/net/nimble/include/nimble/ble_hci_trans.h
@@ -0,0 +1,152 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef H_HCI_TRANSPORT_
+#define H_HCI_TRANSPORT_
+
+#include <inttypes.h>
+struct os_mbuf;
+
+#define BLE_HCI_TRANS_CMD_SZ 260
+
+/*** Type of buffers for holding commands and events. */
+/**
+ * Low-priority event (advertising reports). A request to allocate a
+ * high-priority event buffer may allocate one of these instead if no
+ * high-priority buffers are available.
+ */
+#define BLE_HCI_TRANS_BUF_EVT_LO 1
+
+/* High-priority event (all events except advertising reports). */
+#define BLE_HCI_TRANS_BUF_EVT_HI 2
+
+/* Host-to-controller command. */
+#define BLE_HCI_TRANS_BUF_CMD 3
+
+/** Callback function types; executed when HCI packets are received. */
+typedef int ble_hci_trans_rx_cmd_fn(uint8_t *cmd, void *arg);
+typedef int ble_hci_trans_rx_acl_fn(struct os_mbuf *om, void *arg);
+
+/**
+ * Sends an HCI event from the controller to the host.
+ *
+ * @param cmd The HCI event to send. This buffer must be
+ * allocated via ble_hci_trans_buf_alloc().
+ *
+ * @return 0 on success;
+ * A BLE_ERR_[...] error code on failure.
+ */
+int ble_hci_trans_ll_evt_tx(uint8_t *hci_ev);
+
+/**
+ * Sends ACL data from controller to host.
+ *
+ * @param om The ACL data packet to send.
+ *
+ * @return 0 on success;
+ * A BLE_ERR_[...] error code on failure.
+ */
+int ble_hci_trans_ll_acl_tx(struct os_mbuf *om);
+
+/**
+ * Sends an HCI command from the host to the controller.
+ *
+ * @param cmd The HCI command to send. This buffer must be
+ * allocated via ble_hci_trans_buf_alloc().
+ *
+ * @return 0 on success;
+ * A BLE_ERR_[...] error code on failure.
+ */
+int ble_hci_trans_hs_cmd_tx(uint8_t *cmd);
+
+/**
+ * Sends ACL data from host to controller.
+ *
+ * @param om The ACL data packet to send.
+ *
+ * @return 0 on success;
+ * A BLE_ERR_[...] error code on failure.
+ */
+int ble_hci_trans_hs_acl_tx(struct os_mbuf *om);
+
+/**
+ * Allocates a flat buffer of the specified type.
+ *
+ * @param type The type of buffer to allocate; one of the
+ * BLE_HCI_TRANS_BUF_[...] constants.
+ *
+ * @return The allocated buffer on success;
+ * NULL on buffer exhaustion.
+ */
+uint8_t *ble_hci_trans_buf_alloc(int type);
+
+/**
+ * Frees the specified flat buffer. The buffer must have been allocated via
+ * ble_hci_trans_buf_alloc().
+ *
+ * @param buf The buffer to free.
+ */
+void ble_hci_trans_buf_free(uint8_t *buf);
+
+/**
+ * Configures the HCI transport to operate with a controller. The transport
+ * will execute specified callbacks upon receiving HCI packets from the host.
+ *
+ * @param cmd_cb The callback to execute upon receiving an HCI
+ * command.
+ * @param cmd_arg Optional argument to pass to the command
+ * callback.
+ * @param acl_cb The callback to execute upon receiving ACL
+ * data.
+ * @param acl_arg Optional argument to pass to the ACL
+ * callback.
+ */
+void ble_hci_trans_cfg_ll(ble_hci_trans_rx_cmd_fn *cmd_cb,
+ void *cmd_arg,
+ ble_hci_trans_rx_acl_fn *acl_cb,
+ void *acl_arg);
+
+/**
+ * Configures the HCI transport to operate with a host. The transport will
+ * execute specified callbacks upon receiving HCI packets from the controller.
+ *
+ * @param cmd_cb The callback to execute upon receiving an HCI
+ * event.
+ * @param cmd_arg Optional argument to pass to the command
+ * callback.
+ * @param acl_cb The callback to execute upon receiving ACL
+ * data.
+ * @param acl_arg Optional argument to pass to the ACL
+ * callback.
+ */
+void ble_hci_trans_cfg_hs(ble_hci_trans_rx_cmd_fn *cmd_cb,
+ void *cmd_arg,
+ ble_hci_trans_rx_acl_fn *acl_cb,
+ void *acl_arg);
+
+/**
+ * Resets the HCI module to a clean state. Frees all buffers and reinitializes
+ * the underlying transport.
+ *
+ * @return 0 on success;
+ * A BLE_ERR_[...] error code on failure.
+ */
+int ble_hci_trans_reset(void);
+
+#endif /* H_HCI_TRANSPORT_ */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fd02e1e/net/nimble/include/nimble/hci_transport.h
----------------------------------------------------------------------
diff --git a/net/nimble/include/nimble/hci_transport.h b/net/nimble/include/nimble/hci_transport.h
deleted file mode 100644
index 7de737c..0000000
--- a/net/nimble/include/nimble/hci_transport.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-#ifndef H_HCI_TRANSPORT_
-#define H_HCI_TRANSPORT_
-
-/* Send a HCI command from the host to the controller */
-int ble_hci_transport_host_cmd_send(uint8_t *cmd);
-
-/* Send a HCI event from the controller to the host */
-int ble_hci_transport_ctlr_event_send(uint8_t *hci_ev);
-
-/* Send ACL data from host to contoller */
-int ble_hci_transport_host_acl_data_send(struct os_mbuf *om);
-
-#endif /* H_HCI_TRANSPORT_ */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fd02e1e/net/nimble/transport/ram/include/transport/ram/ble_hci_ram.h
----------------------------------------------------------------------
diff --git a/net/nimble/transport/ram/include/transport/ram/ble_hci_ram.h b/net/nimble/transport/ram/include/transport/ram/ble_hci_ram.h
new file mode 100644
index 0000000..1c5b58e
--- /dev/null
+++ b/net/nimble/transport/ram/include/transport/ram/ble_hci_ram.h
@@ -0,0 +1,15 @@
+#ifndef H_BLE_HCI_RAM_
+#define H_BLE_HCI_RAM_
+
+#include "nimble/ble_hci_trans.h"
+
+struct ble_hci_ram_cfg {
+ uint16_t num_evt_bufs;
+ uint16_t evt_buf_sz;
+};
+
+extern const struct ble_hci_ram_cfg ble_hci_ram_cfg_dflt;
+
+int ble_hci_ram_init(const struct ble_hci_ram_cfg *cfg);
+
+#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fd02e1e/net/nimble/transport/ram/pkg.yml
----------------------------------------------------------------------
diff --git a/net/nimble/transport/ram/pkg.yml b/net/nimble/transport/ram/pkg.yml
new file mode 100644
index 0000000..a3524a1
--- /dev/null
+++ b/net/nimble/transport/ram/pkg.yml
@@ -0,0 +1,33 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+pkg.name: net/nimble/transport/ram
+pkg.description: XXX
+pkg.author: "Apache Mynewt <de...@mynewt.incubator.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.keywords:
+ - ble
+ - bluetooth
+
+pkg.deps:
+ - net/nimble
+ - libs/os
+
+pkg.apis:
+ - ble_transport
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fd02e1e/net/nimble/transport/ram/src/ble_hci_ram.c
----------------------------------------------------------------------
diff --git a/net/nimble/transport/ram/src/ble_hci_ram.c b/net/nimble/transport/ram/src/ble_hci_ram.c
new file mode 100644
index 0000000..aac5eb1
--- /dev/null
+++ b/net/nimble/transport/ram/src/ble_hci_ram.c
@@ -0,0 +1,190 @@
+#include <assert.h>
+#include <errno.h>
+#include <stddef.h>
+#include "os/os.h"
+#include "nimble/ble_hci_trans.h"
+#include "transport/ram/ble_hci_ram.h"
+
+/** Default configuration. */
+const struct ble_hci_ram_cfg ble_hci_ram_cfg_dflt = {
+ .num_evt_bufs = 3,
+ .evt_buf_sz = BLE_HCI_TRANS_CMD_SZ,
+};
+
+static ble_hci_trans_rx_cmd_fn *ble_hci_ram_rx_cmd_hs_cb;
+static void *ble_hci_ram_rx_cmd_hs_arg;
+
+static ble_hci_trans_rx_cmd_fn *ble_hci_ram_rx_cmd_ll_cb;
+static void *ble_hci_ram_rx_cmd_ll_arg;
+
+static ble_hci_trans_rx_acl_fn *ble_hci_ram_rx_acl_hs_cb;
+static void *ble_hci_ram_rx_acl_hs_arg;
+
+static ble_hci_trans_rx_acl_fn *ble_hci_ram_rx_acl_ll_cb;
+static void *ble_hci_ram_rx_acl_ll_arg;
+
+static struct os_mempool ble_hci_ram_evt_pool;
+static void *ble_hci_ram_evt_buf;
+
+static uint8_t *ble_hci_ram_hs_cmd_buf;
+static uint8_t ble_hci_ram_hs_cmd_buf_alloced;
+
+void
+ble_hci_trans_cfg_hs(ble_hci_trans_rx_cmd_fn *cmd_cb,
+ void *cmd_arg,
+ ble_hci_trans_rx_acl_fn *acl_cb,
+ void *acl_arg)
+{
+ ble_hci_ram_rx_cmd_hs_cb = cmd_cb;
+ ble_hci_ram_rx_cmd_hs_arg = cmd_arg;
+ ble_hci_ram_rx_acl_hs_cb = acl_cb;
+ ble_hci_ram_rx_acl_hs_arg = acl_arg;
+}
+
+void
+ble_hci_trans_cfg_ll(ble_hci_trans_rx_cmd_fn *cmd_cb,
+ void *cmd_arg,
+ ble_hci_trans_rx_acl_fn *acl_cb,
+ void *acl_arg)
+{
+ ble_hci_ram_rx_cmd_ll_cb = cmd_cb;
+ ble_hci_ram_rx_cmd_ll_arg = cmd_arg;
+ ble_hci_ram_rx_acl_ll_cb = acl_cb;
+ ble_hci_ram_rx_acl_ll_arg = acl_arg;
+}
+
+int
+ble_hci_trans_hs_cmd_tx(uint8_t *cmd)
+{
+ int rc;
+
+ assert(ble_hci_ram_rx_cmd_ll_cb != NULL);
+
+ rc = ble_hci_ram_rx_cmd_ll_cb(cmd, ble_hci_ram_rx_cmd_ll_arg);
+ return rc;
+}
+
+int
+ble_hci_trans_ll_evt_tx(uint8_t *hci_ev)
+{
+ int rc;
+
+ assert(ble_hci_ram_rx_cmd_hs_cb != NULL);
+
+ rc = ble_hci_ram_rx_cmd_hs_cb(hci_ev, ble_hci_ram_rx_cmd_hs_arg);
+ return rc;
+}
+
+int
+ble_hci_trans_hs_acl_tx(struct os_mbuf *om)
+{
+ int rc;
+
+ assert(ble_hci_ram_rx_acl_ll_cb != NULL);
+
+ rc = ble_hci_ram_rx_acl_ll_cb(om, ble_hci_ram_rx_acl_ll_arg);
+ return rc;
+}
+
+int
+ble_hci_trans_ll_acl_tx(struct os_mbuf *om)
+{
+ int rc;
+
+ assert(ble_hci_ram_rx_acl_hs_cb != NULL);
+
+ rc = ble_hci_ram_rx_acl_hs_cb(om, ble_hci_ram_rx_acl_hs_arg);
+ return rc;
+}
+
+uint8_t *
+ble_hci_trans_buf_alloc(int type)
+{
+ uint8_t *buf;
+
+ switch (type) {
+ case BLE_HCI_TRANS_BUF_EVT_LO:
+ case BLE_HCI_TRANS_BUF_EVT_HI:
+ buf = os_memblock_get(&ble_hci_ram_evt_pool);
+ break;
+
+ case BLE_HCI_TRANS_BUF_CMD:
+ assert(!ble_hci_ram_hs_cmd_buf_alloced);
+ ble_hci_ram_hs_cmd_buf_alloced = 1;
+ buf = ble_hci_ram_hs_cmd_buf;
+ break;
+
+ default:
+ assert(0);
+ buf = NULL;
+ }
+
+ return buf;
+}
+
+void
+ble_hci_trans_buf_free(uint8_t *buf)
+{
+ int rc;
+
+ if (buf == ble_hci_ram_hs_cmd_buf) {
+ assert(ble_hci_ram_hs_cmd_buf_alloced);
+ ble_hci_ram_hs_cmd_buf_alloced = 0;
+ } else {
+ rc = os_memblock_put(&ble_hci_ram_evt_pool, buf);
+ assert(rc == 0);
+ }
+}
+
+static void
+ble_hci_ram_free_mem(void)
+{
+ free(ble_hci_ram_evt_buf);
+ ble_hci_ram_evt_buf = NULL;
+
+ free(ble_hci_ram_hs_cmd_buf);
+ ble_hci_ram_hs_cmd_buf = NULL;
+ ble_hci_ram_hs_cmd_buf_alloced = 0;
+}
+
+int
+ble_hci_trans_reset(void)
+{
+ return 0;
+}
+
+int
+ble_hci_ram_init(const struct ble_hci_ram_cfg *cfg)
+{
+ int rc;
+
+ ble_hci_ram_free_mem();
+
+ ble_hci_ram_evt_buf = malloc(OS_MEMPOOL_BYTES(cfg->num_evt_bufs,
+ cfg->evt_buf_sz));
+ if (ble_hci_ram_evt_buf == NULL) {
+ rc = ENOMEM;
+ goto err;
+ }
+
+ /* Create memory pool of command buffers */
+ rc = os_mempool_init(&ble_hci_ram_evt_pool, cfg->num_evt_bufs,
+ cfg->evt_buf_sz, ble_hci_ram_evt_buf,
+ "ble_hci_ram_evt_pool");
+ if (rc != 0) {
+ rc = EINVAL;
+ goto err;
+ }
+
+ ble_hci_ram_hs_cmd_buf = malloc(BLE_HCI_TRANS_CMD_SZ);
+ if (ble_hci_ram_hs_cmd_buf == NULL) {
+ rc = ENOMEM;
+ goto err;
+ }
+
+ return 0;
+
+err:
+ ble_hci_ram_free_mem();
+ return rc;
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fd02e1e/net/nimble/transport/uart/include/transport/uart/ble_hci_uart.h
----------------------------------------------------------------------
diff --git a/net/nimble/transport/uart/include/transport/uart/ble_hci_uart.h b/net/nimble/transport/uart/include/transport/uart/ble_hci_uart.h
new file mode 100644
index 0000000..1fbaa74
--- /dev/null
+++ b/net/nimble/transport/uart/include/transport/uart/ble_hci_uart.h
@@ -0,0 +1,19 @@
+#ifndef H_BLE_HCI_UART_
+#define H_BLE_HCI_UART_
+
+struct ble_hci_uart_cfg {
+ uint32_t baud;
+ uint16_t num_evt_bufs;
+ uint16_t evt_buf_sz;
+ uint8_t uart_port;
+ uint8_t flow_ctrl;
+ uint8_t data_bits;
+ uint8_t stop_bits;
+ uint8_t parity;
+};
+
+extern const struct ble_hci_uart_cfg ble_hci_uart_cfg_dflt;
+
+int ble_hci_uart_init(const struct ble_hci_uart_cfg *cfg);
+
+#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fd02e1e/net/nimble/transport/uart/pkg.yml
----------------------------------------------------------------------
diff --git a/net/nimble/transport/uart/pkg.yml b/net/nimble/transport/uart/pkg.yml
new file mode 100644
index 0000000..cce429c
--- /dev/null
+++ b/net/nimble/transport/uart/pkg.yml
@@ -0,0 +1,34 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+pkg.name: net/nimble/transport/uart
+pkg.description: XXX
+pkg.author: "Apache Mynewt <de...@mynewt.incubator.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.keywords:
+ - ble
+ - bluetooth
+
+pkg.deps:
+ - hw/hal
+ - libs/os
+ - net/nimble
+
+pkg.apis:
+ - ble_transport
[08/42] incubator-mynewt-core git commit: console - Fix whitespace
issues.
Posted by st...@apache.org.
console - Fix whitespace issues.
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/3ea48819
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/3ea48819
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/3ea48819
Branch: refs/heads/sterly_refactor
Commit: 3ea488197b461ad586fb0002338e3c9abd6f18ec
Parents: 18298ea
Author: Christopher Collins <cc...@apache.org>
Authored: Mon Aug 1 14:41:00 2016 -0700
Committer: Sterling Hughes <st...@apache.org>
Committed: Tue Aug 9 16:05:21 2016 -0700
----------------------------------------------------------------------
libs/console/full/src/cons_tty.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3ea48819/libs/console/full/src/cons_tty.c
----------------------------------------------------------------------
diff --git a/libs/console/full/src/cons_tty.c b/libs/console/full/src/cons_tty.c
index fb2015c..9c576e2 100644
--- a/libs/console/full/src/cons_tty.c
+++ b/libs/console/full/src/cons_tty.c
@@ -203,13 +203,13 @@ console_read(char *str, int cnt, int *newline)
break;
}
- if ((i & (CONSOLE_RX_CHUNK - 1)) == (CONSOLE_RX_CHUNK - 1)) {
- /*
- * Make a break from blocking interrupts during the copy.
- */
- OS_EXIT_CRITICAL(sr);
- OS_ENTER_CRITICAL(sr);
- }
+ if ((i & (CONSOLE_RX_CHUNK - 1)) == (CONSOLE_RX_CHUNK - 1)) {
+ /*
+ * Make a break from blocking interrupts during the copy.
+ */
+ OS_EXIT_CRITICAL(sr);
+ OS_ENTER_CRITICAL(sr);
+ }
ch = console_pull_char(cr);
if (ch == '\n') {
[39/42] incubator-mynewt-core git commit: BLE Host - prep/exec tests:
better mbuf leak check
Posted by st...@apache.org.
BLE Host - prep/exec tests: better mbuf leak check
When ensuring no mbuf leaks at the end of the att_svr_test suite, also
ensure that each connection's prep list is empty.
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/004d61d9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/004d61d9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/004d61d9
Branch: refs/heads/sterly_refactor
Commit: 004d61d9b35c5d9a12cc83f7d1c1c01b9067ce2d
Parents: f1020d3
Author: Christopher Collins <cc...@apache.org>
Authored: Sun Aug 7 17:59:02 2016 -0700
Committer: Sterling Hughes <st...@apache.org>
Committed: Tue Aug 9 16:05:21 2016 -0700
----------------------------------------------------------------------
net/nimble/host/src/test/ble_att_svr_test.c | 9 ++++-
net/nimble/host/src/test/ble_hs_test_util.c | 46 ++++++++++++++++--------
net/nimble/host/src/test/ble_hs_test_util.h | 12 +++++--
3 files changed, 50 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/004d61d9/net/nimble/host/src/test/ble_att_svr_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_att_svr_test.c b/net/nimble/host/src/test/ble_att_svr_test.c
index 86565e3..1509b41 100644
--- a/net/nimble/host/src/test/ble_att_svr_test.c
+++ b/net/nimble/host/src/test/ble_att_svr_test.c
@@ -2282,7 +2282,14 @@ TEST_CASE(ble_att_svr_test_indicate)
TEST_SUITE(ble_att_svr_suite)
{
- tu_suite_set_post_test_cb(ble_hs_test_util_post_test, NULL);
+ /* When checking for mbuf leaks, ensure no stale prep entries. */
+ static struct ble_hs_test_util_mbuf_params mbuf_params = {
+ .prev_tx = 1,
+ .rx_queue = 1,
+ .prep_list = 0,
+ };
+
+ tu_suite_set_post_test_cb(ble_hs_test_util_post_test, &mbuf_params);
ble_att_svr_test_mtu();
ble_att_svr_test_read();
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/004d61d9/net/nimble/host/src/test/ble_hs_test_util.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_test_util.c b/net/nimble/host/src/test/ble_hs_test_util.c
index 54a3527..460642e 100644
--- a/net/nimble/host/src/test/ble_hs_test_util.c
+++ b/net/nimble/host/src/test/ble_hs_test_util.c
@@ -1286,7 +1286,7 @@ ble_hs_test_util_mbuf_chain_len(const struct os_mbuf *om)
}
int
-ble_hs_test_util_mbuf_count(void)
+ble_hs_test_util_mbuf_count(const struct ble_hs_test_util_mbuf_params *params)
{
const struct ble_att_prep_entry *prep;
const struct os_mbuf_pkthdr *omp;
@@ -1296,14 +1296,17 @@ ble_hs_test_util_mbuf_count(void)
int count;
int i;
- count = ble_hs_test_util_mbuf_mpool.mp_num_free;
- count += ble_hs_test_util_mbuf_chain_len(ble_hs_test_util_prev_tx_cur);
-
ble_hs_process_tx_data_queue();
ble_hs_process_rx_data_queue();
- STAILQ_FOREACH(omp, &ble_hs_test_util_prev_tx_queue, omp_next) {
- om = OS_MBUF_PKTHDR_TO_MBUF(omp);
- count += ble_hs_test_util_mbuf_chain_len(om);
+
+ count = ble_hs_test_util_mbuf_mpool.mp_num_free;
+
+ if (params->prev_tx) {
+ count += ble_hs_test_util_mbuf_chain_len(ble_hs_test_util_prev_tx_cur);
+ STAILQ_FOREACH(omp, &ble_hs_test_util_prev_tx_queue, omp_next) {
+ om = OS_MBUF_PKTHDR_TO_MBUF(omp);
+ count += ble_hs_test_util_mbuf_chain_len(om);
+ }
}
ble_hs_lock();
@@ -1313,12 +1316,16 @@ ble_hs_test_util_mbuf_count(void)
break;
}
- SLIST_FOREACH(chan, &conn->bhc_channels, blc_next) {
- count += ble_hs_test_util_mbuf_chain_len(chan->blc_rx_buf);
+ if (params->rx_queue) {
+ SLIST_FOREACH(chan, &conn->bhc_channels, blc_next) {
+ count += ble_hs_test_util_mbuf_chain_len(chan->blc_rx_buf);
+ }
}
- SLIST_FOREACH(prep, &conn->bhc_att_svr.basc_prep_list, bape_next) {
- count += ble_hs_test_util_mbuf_chain_len(prep->bape_value);
+ if (params->prep_list) {
+ SLIST_FOREACH(prep, &conn->bhc_att_svr.basc_prep_list, bape_next) {
+ count += ble_hs_test_util_mbuf_chain_len(prep->bape_value);
+ }
}
}
ble_hs_unlock();
@@ -1327,18 +1334,29 @@ ble_hs_test_util_mbuf_count(void)
}
void
-ble_hs_test_util_assert_mbufs_freed(void)
+ble_hs_test_util_assert_mbufs_freed(
+ const struct ble_hs_test_util_mbuf_params *params)
{
+ static const struct ble_hs_test_util_mbuf_params dflt = {
+ .prev_tx = 1,
+ .rx_queue = 1,
+ .prep_list = 1,
+ };
+
int count;
- count = ble_hs_test_util_mbuf_count();
+ if (params == NULL) {
+ params = &dflt;
+ }
+
+ count = ble_hs_test_util_mbuf_count(params);
TEST_ASSERT(count == ble_hs_test_util_mbuf_mpool.mp_num_blocks);
}
void
ble_hs_test_util_post_test(void *arg)
{
- ble_hs_test_util_assert_mbufs_freed();
+ ble_hs_test_util_assert_mbufs_freed(arg);
}
static int
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/004d61d9/net/nimble/host/src/test/ble_hs_test_util.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_test_util.h b/net/nimble/host/src/test/ble_hs_test_util.h
index 0ae6cf5..3320e9b 100644
--- a/net/nimble/host/src/test/ble_hs_test_util.h
+++ b/net/nimble/host/src/test/ble_hs_test_util.h
@@ -44,6 +44,12 @@ struct ble_hs_test_util_flat_attr {
uint16_t value_len;
};
+struct ble_hs_test_util_mbuf_params {
+ unsigned prev_tx:1;
+ unsigned rx_queue:1;
+ unsigned prep_list:1;
+};
+
void ble_hs_test_util_prev_tx_enqueue(struct os_mbuf *om);
struct os_mbuf *ble_hs_test_util_prev_tx_dequeue(void);
struct os_mbuf *ble_hs_test_util_prev_tx_dequeue_pullup(void);
@@ -160,8 +166,10 @@ int ble_hs_test_util_gatt_write_long_flat(uint16_t conn_handle,
uint16_t attr_handle,
const void *data, uint16_t data_len,
ble_gatt_attr_fn *cb, void *cb_arg);
-int ble_hs_test_util_mbuf_count(void);
-void ble_hs_test_util_assert_mbufs_freed(void);
+int ble_hs_test_util_mbuf_count(
+ const struct ble_hs_test_util_mbuf_params *params);
+void ble_hs_test_util_assert_mbufs_freed(
+ const struct ble_hs_test_util_mbuf_params *params);
void ble_hs_test_util_post_test(void *arg);
void ble_hs_test_util_init(void);
[31/42] incubator-mynewt-core git commit: BLE Host - doxy comments
for ble_gatts_count_cfg()
Posted by st...@apache.org.
BLE Host - doxy comments for ble_gatts_count_cfg()
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/f36fa7c0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/f36fa7c0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/f36fa7c0
Branch: refs/heads/sterly_refactor
Commit: f36fa7c09a2fb9a8e099fd0d06f8f63c5849de05
Parents: 1efa31f
Author: Christopher Collins <cc...@apache.org>
Authored: Sat Aug 6 14:12:03 2016 -0700
Committer: Sterling Hughes <st...@apache.org>
Committed: Tue Aug 9 16:05:21 2016 -0700
----------------------------------------------------------------------
net/nimble/host/src/ble_gatts.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f36fa7c0/net/nimble/host/src/ble_gatts.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gatts.c b/net/nimble/host/src/ble_gatts.c
index 31f3a6f..4bdc6c7 100644
--- a/net/nimble/host/src/ble_gatts.c
+++ b/net/nimble/host/src/ble_gatts.c
@@ -1979,6 +1979,23 @@ ble_gatts_count_resources(const struct ble_gatt_svc_def *svcs,
return 0;
}
+/**
+ * Adjusts a host configuration object's settings to accommodate the specified
+ * service definition array. This function adds the counts to the appropriate
+ * fields in the supplied configuration object without clearing them first, so
+ * it can be called repeatedly with different inputs to calculate totals. Be
+ * sure to zero the GATT server settings prior to the first call to this
+ * function.
+ *
+ * @param defs The service array containing the resource
+ * definitions to be counted.
+ * @param cfg The resource counts are accumulated in this
+ * configuration object.
+ *
+ * @return 0 on success;
+ * BLE_HS_EINVAL if the svcs array contains an
+ * invalid resource definition.
+ */
int
ble_gatts_count_cfg(const struct ble_gatt_svc_def *defs,
struct ble_hs_cfg *cfg)
[35/42] incubator-mynewt-core git commit: BLE Host - Free mbufs on
exec-write-failure
Posted by st...@apache.org.
BLE Host - Free mbufs on exec-write-failure
The previous fix didn't fix an mbuf leak. It added one! The real bug
was that an exec-write-response (success) gets sent when a write fails.
This commit fixes the mbuf leak that was introduced.
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/de85f43d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/de85f43d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/de85f43d
Branch: refs/heads/sterly_refactor
Commit: de85f43dec28a329d5b937936045ba840423318f
Parents: aadba62
Author: Christopher Collins <cc...@apache.org>
Authored: Sun Aug 7 02:34:00 2016 -0700
Committer: Sterling Hughes <st...@apache.org>
Committed: Tue Aug 9 16:05:21 2016 -0700
----------------------------------------------------------------------
net/nimble/host/src/ble_att_svr.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/de85f43d/net/nimble/host/src/ble_att_svr.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_svr.c b/net/nimble/host/src/ble_att_svr.c
index b3dd2f3..1b420b5 100644
--- a/net/nimble/host/src/ble_att_svr.c
+++ b/net/nimble/host/src/ble_att_svr.c
@@ -2342,16 +2342,19 @@ ble_att_svr_prep_write(uint16_t conn_handle,
ble_att_svr_prep_extract(prep_list, &attr_handle, &om);
attr = ble_att_svr_find_by_handle(attr_handle);
+ *err_handle = attr_handle;
if (attr == NULL) {
rc = BLE_ATT_ERR_INVALID_HANDLE;
- *err_handle = attr_handle;
} else {
rc = ble_att_svr_write(conn_handle, attr, 0, &om, &att_err);
- os_mbuf_free_chain(om);
if (rc != 0) {
- return att_err;
+ rc = att_err;
}
}
+ os_mbuf_free_chain(om);
+ if (rc != 0) {
+ return rc;
+ }
}
return 0;
[02/42] incubator-mynewt-core git commit: os_mbuf_appendfrom - Detect
source mbuf overrun.
Posted by st...@apache.org.
os_mbuf_appendfrom - Detect source mbuf overrun.
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/2d39d3b8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/2d39d3b8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/2d39d3b8
Branch: refs/heads/sterly_refactor
Commit: 2d39d3b86895e341d3c43bccd1b05526b529a4a5
Parents: 229927d
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Aug 9 12:29:28 2016 -0700
Committer: Sterling Hughes <st...@apache.org>
Committed: Tue Aug 9 16:05:21 2016 -0700
----------------------------------------------------------------------
libs/os/src/os_mbuf.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2d39d3b8/libs/os/src/os_mbuf.c
----------------------------------------------------------------------
diff --git a/libs/os/src/os_mbuf.c b/libs/os/src/os_mbuf.c
index eda58ef..a2302df 100644
--- a/libs/os/src/os_mbuf.c
+++ b/libs/os/src/os_mbuf.c
@@ -520,6 +520,10 @@ err:
* @param src_off The absolute offset within the source mbuf
* chain to read from.
* @param len The number of bytes to append.
+ *
+ * @return 0 on success;
+ * OS_EINVAL if the specified range extends beyond
+ * the end of the source mbuf chain.
*/
int
os_mbuf_appendfrom(struct os_mbuf *dst, const struct os_mbuf *src,
@@ -531,11 +535,11 @@ os_mbuf_appendfrom(struct os_mbuf *dst, const struct os_mbuf *src,
int rc;
src_cur_om = os_mbuf_off(src, src_off, &src_cur_off);
- if (src_cur_om == NULL) {
- return OS_EINVAL;
- }
-
while (len > 0) {
+ if (src_cur_om == NULL) {
+ return OS_EINVAL;
+ }
+
chunk_sz = min(len, src_cur_om->om_len - src_cur_off);
rc = os_mbuf_append(dst, src_cur_om->om_data + src_cur_off, chunk_sz);
if (rc != 0) {
[20/42] incubator-mynewt-core git commit: eventq - os_eventq_poll() -
Allow a timeout of 0.
Posted by st...@apache.org.
eventq - os_eventq_poll() - Allow a timeout of 0.
If the timeout is 0, don't involve the scheduler at all. Grab an event
if one is available, else return immediately.
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/a4c44d77
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/a4c44d77
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/a4c44d77
Branch: refs/heads/sterly_refactor
Commit: a4c44d77a044948d8f85a4c0b847b978345769dc
Parents: 043e0e5
Author: Christopher Collins <cc...@apache.org>
Authored: Thu Aug 4 12:41:46 2016 -0700
Committer: Sterling Hughes <st...@apache.org>
Committed: Tue Aug 9 16:05:21 2016 -0700
----------------------------------------------------------------------
libs/os/src/os_eventq.c | 33 +++++++-
libs/os/src/test/eventq_test.c | 149 +++++++++++++++++++++++-------------
2 files changed, 125 insertions(+), 57 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a4c44d77/libs/os/src/os_eventq.c
----------------------------------------------------------------------
diff --git a/libs/os/src/os_eventq.c b/libs/os/src/os_eventq.c
index b3ff26f..f9cc283 100644
--- a/libs/os/src/os_eventq.c
+++ b/libs/os/src/os_eventq.c
@@ -117,6 +117,29 @@ pull_one:
return (ev);
}
+static struct os_event *
+os_eventq_poll_0timo(struct os_eventq **evq, int nevqs)
+{
+ struct os_event *ev;
+ os_sr_t sr;
+ int i;
+
+ ev = NULL;
+
+ OS_ENTER_CRITICAL(sr);
+ for (i = 0; i < nevqs; i++) {
+ ev = STAILQ_FIRST(&evq[i]->evq_list);
+ if (ev) {
+ STAILQ_REMOVE(&evq[i]->evq_list, ev, os_event, ev_next);
+ ev->ev_queued = 0;
+ break;
+ }
+ }
+ OS_EXIT_CRITICAL(sr);
+
+ return ev;
+}
+
/**
* Poll the list of event queues specified by the evq parameter
* (size nevqs), and return the "first" event available on any of
@@ -137,6 +160,13 @@ os_eventq_poll(struct os_eventq **evq, int nevqs, os_time_t timo)
int i, j;
os_sr_t sr;
+ /* If the timeout is 0, don't involve the scheduler at all. Grab an event
+ * if one is available, else return immediately.
+ */
+ if (timo == 0) {
+ return os_eventq_poll_0timo(evq, nevqs);
+ }
+
ev = NULL;
OS_ENTER_CRITICAL(sr);
@@ -147,8 +177,7 @@ os_eventq_poll(struct os_eventq **evq, int nevqs, os_time_t timo)
if (ev) {
STAILQ_REMOVE(&evq[i]->evq_list, ev, os_event, ev_next);
ev->ev_queued = 0;
- /* Reset the items that already have an evq task set
- */
+ /* Reset the items that already have an evq task set. */
for (j = 0; j < i; j++) {
evq[j]->evq_task = NULL;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a4c44d77/libs/os/src/test/eventq_test.c
----------------------------------------------------------------------
diff --git a/libs/os/src/test/eventq_test.c b/libs/os/src/test/eventq_test.c
index f17e5e4..cb1ed94 100644
--- a/libs/os/src/test/eventq_test.c
+++ b/libs/os/src/test/eventq_test.c
@@ -17,7 +17,7 @@
* under the License.
*/
-
+#include <string.h>
#include "testutil/testutil.h"
#include "os/os.h"
#include "os_test_priv.h"
@@ -59,10 +59,6 @@ os_stack_t eventq_task_stack_poll_s[POLL_STACK_SIZE];
struct os_task eventq_task_poll_r;
os_stack_t eventq_task_stack_poll_r[POLL_STACK_SIZE ];
-struct os_eventq *poll_eventq[POLL_STACK_SIZE];
-struct os_eventq p_event[POLL_STACK_SIZE];
-struct os_event poll_event[POLL_STACK_SIZE];
-
/* Setting the data for the poll timeout */
/* Define the task stack for the eventq_task_poll_timeout_send */
#define SEND_TASK_POLL_TIMEOUT_PRIO (5)
@@ -74,10 +70,6 @@ os_stack_t eventq_task_stack_poll_timeout_s[POLL_STACK_SIZE];
struct os_task eventq_task_poll_timeout_r;
os_stack_t eventq_task_stack_poll_timeout_r[POLL_STACK_SIZE];
-struct os_eventq *poll_eventq_timeout[POLL_STACK_SIZE];
-struct os_eventq p_event_timeout[POLL_STACK_SIZE];
-struct os_event poll_event_timeout[POLL_STACK_SIZE];
-
/* Setting the data for the poll single */
/* Define the task stack for the eventq_task_poll_single_send */
#define SEND_TASK_POLL_SINGLE_PRIO (7)
@@ -89,10 +81,6 @@ os_stack_t eventq_task_stack_poll_single_s[POLL_STACK_SIZE];
struct os_task eventq_task_poll_single_r;
os_stack_t eventq_task_stack_poll_single_r[POLL_STACK_SIZE];
-struct os_eventq *poll_eventq_single[POLL_STACK_SIZE];
-struct os_eventq p_event_single[POLL_STACK_SIZE];
-struct os_event poll_event_single[POLL_STACK_SIZE];
-
/* This is the task function to send data */
void
eventq_task_send(void *arg)
@@ -143,24 +131,19 @@ eventq_task_receive(void *arg)
void
eventq_task_poll_send(void *arg)
{
+ struct os_eventq *eventqs[SIZE_MULTI_EVENT];
int i;
- /* Assigning the *poll_eventq[] */
for (i = 0; i < SIZE_MULTI_EVENT; i++){
- poll_eventq[i] = &p_event[i];
+ eventqs[i] = &multi_eventq[i];
}
- /* Initializing the *poll_eventq */
for (i = 0; i < SIZE_MULTI_EVENT; i++){
- os_eventq_init(poll_eventq[i]);
- }
-
- for (i = 0; i < SIZE_MULTI_EVENT; i++){
- poll_event[i].ev_type = i + 10;
- poll_event[i].ev_arg = NULL;
+ m_event[i].ev_type = i + 10;
+ m_event[i].ev_arg = NULL;
/* Put and send */
- os_eventq_put(poll_eventq[i], &poll_event[i]);
+ os_eventq_put(eventqs[i], &m_event[i]);
os_time_delay(OS_TICKS_PER_SEC / 2);
}
@@ -171,12 +154,17 @@ eventq_task_poll_send(void *arg)
void
eventq_task_poll_receive(void *arg)
{
+ struct os_eventq *eventqs[SIZE_MULTI_EVENT];
struct os_event *event;
int i;
+ for (i = 0; i < SIZE_MULTI_EVENT; i++){
+ eventqs[i] = &multi_eventq[i];
+ }
+
/* Recieving using the os_eventq_poll*/
for (i = 0; i < SIZE_MULTI_EVENT; i++) {
- event = os_eventq_poll(poll_eventq, SIZE_MULTI_EVENT, OS_WAIT_FOREVER);
+ event = os_eventq_poll(eventqs, SIZE_MULTI_EVENT, OS_WAIT_FOREVER);
TEST_ASSERT(event->ev_type == i +10);
}
@@ -189,26 +177,18 @@ eventq_task_poll_receive(void *arg)
void
eventq_task_poll_timeout_send(void *arg)
{
+ struct os_eventq *eventqs[SIZE_MULTI_EVENT];
int i;
- /* Assigning the *poll_eventq_timeout[] */
- for (i = 0; i < SIZE_MULTI_EVENT; i++){
- poll_eventq_timeout[i] = &p_event_timeout[i];
- }
-
- /* Initializing the *poll_eventq_timeout */
for (i = 0; i < SIZE_MULTI_EVENT; i++){
- os_eventq_init(poll_eventq_timeout[i]);
+ eventqs[i] = &multi_eventq[i];
}
for (i = 0; i < SIZE_MULTI_EVENT; i++){
os_time_delay(1000);
- poll_event_timeout[i].ev_type = i + 10;
- poll_event_timeout[i].ev_arg = NULL;
-
/* Put and send */
- os_eventq_put(poll_eventq_timeout[i], &poll_event_timeout[i]);
+ os_eventq_put(eventqs[i], &m_event[i]);
os_time_delay(OS_TICKS_PER_SEC / 2);
}
@@ -221,12 +201,17 @@ eventq_task_poll_timeout_send(void *arg)
void
eventq_task_poll_timeout_receive(void *arg)
{
- struct os_event *event;
+ struct os_eventq *eventqs[SIZE_MULTI_EVENT];
+ struct os_event *event;
int i;
+ for (i = 0; i < SIZE_MULTI_EVENT; i++){
+ eventqs[i] = &multi_eventq[i];
+ }
+
/* Recieving using the os_eventq_poll_timeout*/
for (i = 0; i < SIZE_MULTI_EVENT; i++) {
- event = os_eventq_poll(poll_eventq_timeout, SIZE_MULTI_EVENT, 200);
+ event = os_eventq_poll(eventqs, SIZE_MULTI_EVENT, 200);
TEST_ASSERT(event == NULL);
}
@@ -239,45 +224,40 @@ eventq_task_poll_timeout_receive(void *arg)
void
eventq_task_poll_single_send(void *arg)
{
+ struct os_eventq *eventqs[SIZE_MULTI_EVENT];
int i;
int position = 2;
- /* Assigning the *poll_eventq_single */
for (i = 0; i < SIZE_MULTI_EVENT; i++){
- poll_eventq_single[i] = &p_event_single[i];
+ eventqs[i] = &multi_eventq[i];
}
- /* Initializing the *poll_eventq_single */
- for (i = 0; i < SIZE_MULTI_EVENT; i++){
- os_eventq_init(poll_eventq_single[i]);
- }
-
- poll_event_single[position].ev_type = 20;
- poll_event_single[position].ev_arg = NULL;
-
- /* Put and send */
- os_eventq_put(poll_eventq_single[position],
- &poll_event_single[position]);
- os_time_delay(OS_TICKS_PER_SEC / 2);
+ /* Put and send */
+ os_eventq_put(eventqs[position], &m_event[position]);
+ os_time_delay(OS_TICKS_PER_SEC / 2);
/* This task sleeps until the receive task completes the test. */
os_time_delay(1000000);
-
}
/* Recieving the single event */
void
eventq_task_poll_single_receive(void *arg)
{
+ struct os_eventq *eventqs[SIZE_MULTI_EVENT];
struct os_event *event;
+ int i;
+
+ for (i = 0; i < SIZE_MULTI_EVENT; i++){
+ eventqs[i] = &multi_eventq[i];
+ }
/* Recieving using the os_eventq_poll*/
- event = os_eventq_poll(poll_eventq_single, SIZE_MULTI_EVENT, OS_WAIT_FOREVER);
+ event = os_eventq_poll(eventqs, SIZE_MULTI_EVENT, OS_WAIT_FOREVER);
TEST_ASSERT(event->ev_type == 20);
/* Finishes the test when OS has been started */
os_test_restart();
-
}
TEST_CASE(event_test_sr)
@@ -309,6 +289,8 @@ TEST_CASE(event_test_sr)
/* To test for the basic function of os_eventq_poll() */
TEST_CASE(event_test_poll_sr)
{
+ int i;
+
/* Initializing the OS */
os_init();
/* Initialize the task */
@@ -321,6 +303,11 @@ TEST_CASE(event_test_poll_sr)
NULL, RECEIVE_TASK_POLL_PRIO, OS_WAIT_FOREVER, eventq_task_stack_poll_r,
POLL_STACK_SIZE);
+ /* Initializing the eventqs. */
+ for (i = 0; i < SIZE_MULTI_EVENT; i++){
+ os_eventq_init(&multi_eventq[i]);
+ }
+
/* Does not return until OS_restart is called */
os_start();
@@ -329,6 +316,8 @@ TEST_CASE(event_test_poll_sr)
/* Test case for poll timeout */
TEST_CASE(event_test_poll_timeout_sr)
{
+ int i;
+
/* Initializing the OS */
os_init();
/* Initialize the task */
@@ -341,6 +330,14 @@ TEST_CASE(event_test_poll_timeout_sr)
eventq_task_poll_timeout_receive, NULL, RECEIVE_TASK_POLL_TIMEOUT_PRIO,
OS_WAIT_FOREVER, eventq_task_stack_poll_timeout_r, POLL_STACK_SIZE);
+ /* Initializing the eventqs. */
+ for (i = 0; i < SIZE_MULTI_EVENT; i++){
+ os_eventq_init(&multi_eventq[i]);
+
+ m_event[i].ev_type = i + 10;
+ m_event[i].ev_arg = NULL;
+ }
+
/* Does not return until OS_restart is called */
os_start();
@@ -350,6 +347,8 @@ TEST_CASE(event_test_poll_timeout_sr)
/* Test case for poll timeout */
TEST_CASE(event_test_poll_single_sr)
{
+ int i;
+
/* Initializing the OS */
os_init();
/* Initialize the task */
@@ -362,16 +361,56 @@ TEST_CASE(event_test_poll_single_sr)
eventq_task_poll_single_receive, NULL, RECEIVE_TASK_POLL_SINGLE_PRIO,
OS_WAIT_FOREVER, eventq_task_stack_poll_single_r, POLL_STACK_SIZE);
+ for (i = 0; i < SIZE_MULTI_EVENT; i++){
+ os_eventq_init(&multi_eventq[i]);
+
+ m_event[i].ev_type = 10 * i;
+ m_event[i].ev_arg = NULL;
+ }
+
/* Does not return until OS_restart is called */
os_start();
}
+/**
+ * Tests eventq_poll() with a timeout of 0. This should not involve the
+ * scheduler at all, so it should work without starting the OS.
+ */
+TEST_CASE(event_test_poll_0timo)
+{
+ struct os_eventq *eventqs[SIZE_MULTI_EVENT];
+ struct os_event *evp;
+ struct os_event ev;
+ int i;
+
+ for (i = 0; i < SIZE_MULTI_EVENT; i++){
+ os_eventq_init(&multi_eventq[i]);
+ eventqs[i] = &multi_eventq[i];
+ }
+
+ evp = os_eventq_poll(eventqs, SIZE_MULTI_EVENT, 0);
+ TEST_ASSERT(evp == NULL);
+
+ /* Ensure no eventq thinks a task is waiting on it. */
+ for (i = 0; i < SIZE_MULTI_EVENT; i++) {
+ TEST_ASSERT(eventqs[i]->evq_task == NULL);
+ }
+
+ /* Put an event on one of the queues. */
+ memset(&ev, 0, sizeof ev);
+ ev.ev_type = 1;
+ os_eventq_put(eventqs[3], &ev);
+
+ evp = os_eventq_poll(eventqs, SIZE_MULTI_EVENT, 0);
+ TEST_ASSERT(evp == &ev);
+}
+
TEST_SUITE(os_eventq_test_suite)
{
event_test_sr();
event_test_poll_sr();
event_test_poll_timeout_sr();
event_test_poll_single_sr();
-
+ event_test_poll_0timo();
}
[32/42] incubator-mynewt-core git commit: BLE Host - Clean up ACL tx
fragmentation.
Posted by st...@apache.org.
BLE Host - Clean up ACL tx fragmentation.
This commit does not result in a change in behavior. The fragmentation
code was overly complicated. This change just simplifies the
implementation.
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/009bb6cc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/009bb6cc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/009bb6cc
Branch: refs/heads/sterly_refactor
Commit: 009bb6cce4be2a2431d4084f630f152220abeb0d
Parents: 259f4c3
Author: Christopher Collins <cc...@apache.org>
Authored: Fri Aug 5 12:18:13 2016 -0700
Committer: Sterling Hughes <st...@apache.org>
Committed: Tue Aug 9 16:05:21 2016 -0700
----------------------------------------------------------------------
net/nimble/host/src/ble_hs_hci.c | 34 ++++++++++++----------------------
1 file changed, 12 insertions(+), 22 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/009bb6cc/net/nimble/host/src/ble_hs_hci.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_hci.c b/net/nimble/host/src/ble_hs_hci.c
index cd5cc6c..433c2e0 100644
--- a/net/nimble/host/src/ble_hs_hci.c
+++ b/net/nimble/host/src/ble_hs_hci.c
@@ -359,17 +359,16 @@ ble_hs_hci_rx_evt(uint8_t *hci_ev, void *arg)
* buffer size requirements, no splitting is performed. The fragment data is
* removed from the data packet mbuf.
*
- * @param om The ACL data packet.
+ * @param om The ACL data packet. If this constitutes a
+ * single fragment, it gets set to NULL on
+ * success.
* @param out_frag On success, this points to the fragment to
* send. If the entire packet can fit within
* a single fragment, this will point to the
* ACL data packet itself ('om').
*
- * @return BLE_HS_EDONE: success; this is the final
- * fragment.
- * BLE_HS_EAGAIN: success; more data remains in
- * the original mbuf.
- * Other BLE host core return code on error.
+ * @return 0 on success;
+ * BLE host core return code on error.
*/
static int
ble_hs_hci_split_frag(struct os_mbuf **om, struct os_mbuf **out_frag)
@@ -377,11 +376,14 @@ ble_hs_hci_split_frag(struct os_mbuf **om, struct os_mbuf **out_frag)
struct os_mbuf *frag;
int rc;
+ /* Assume failure. */
+ *out_frag = NULL;
+
if (OS_MBUF_PKTLEN(*om) <= ble_hs_hci_buf_sz) {
/* Final fragment. */
*out_frag = *om;
*om = NULL;
- return BLE_HS_EDONE;
+ return 0;
}
frag = ble_hs_mbuf_acm_pkt();
@@ -400,7 +402,7 @@ ble_hs_hci_split_frag(struct os_mbuf **om, struct os_mbuf **out_frag)
/* More fragments to follow. */
*out_frag = frag;
- return BLE_HS_EAGAIN;
+ return 0;
err:
os_mbuf_free_chain(frag);
@@ -449,7 +451,6 @@ ble_hs_hci_acl_tx(struct ble_hs_conn *connection, struct os_mbuf *txom)
{
struct os_mbuf *frag;
uint8_t pb;
- int done;
int rc;
/* The first fragment uses the first-non-flush packet boundary value.
@@ -459,20 +460,9 @@ ble_hs_hci_acl_tx(struct ble_hs_conn *connection, struct os_mbuf *txom)
pb = BLE_HCI_PB_FIRST_NON_FLUSH;
/* Send fragments until the entire packet has been sent. */
- done = 0;
- while (!done) {
+ while (txom != NULL) {
rc = ble_hs_hci_split_frag(&txom, &frag);
- switch (rc) {
- case BLE_HS_EDONE:
- /* This is the final fragment. */
- done = 1;
- break;
-
- case BLE_HS_EAGAIN:
- /* More fragments to follow. */
- break;
-
- default:
+ if (rc != 0) {
goto err;
}
[10/42] incubator-mynewt-core git commit: nrf52dk-uart - Clear state
on open.
Posted by st...@apache.org.
nrf52dk-uart - Clear state on open.
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/c09231e8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/c09231e8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/c09231e8
Branch: refs/heads/sterly_refactor
Commit: c09231e8aac8c9f067dbd51d0a1285c31e243ed7
Parents: aff82c3
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Aug 2 09:58:49 2016 -0700
Committer: Sterling Hughes <st...@apache.org>
Committed: Tue Aug 9 16:05:21 2016 -0700
----------------------------------------------------------------------
hw/mcu/nordic/nrf52xxx/src/hal_uart.c | 2 ++
1 file changed, 2 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c09231e8/hw/mcu/nordic/nrf52xxx/src/hal_uart.c
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/nrf52xxx/src/hal_uart.c b/hw/mcu/nordic/nrf52xxx/src/hal_uart.c
index 2cf62d0..b7d3154 100644
--- a/hw/mcu/nordic/nrf52xxx/src/hal_uart.c
+++ b/hw/mcu/nordic/nrf52xxx/src/hal_uart.c
@@ -316,6 +316,8 @@ hal_uart_config(int port, int32_t baudrate, uint8_t databits, uint8_t stopbits,
NRF_UARTE0->RXD.MAXCNT = sizeof(u->u_rx_buf);
NRF_UARTE0->TASKS_STARTRX = 1;
+ u->u_rx_stall = 0;
+ u->u_tx_started = 0;
u->u_open = 1;
return 0;
[30/42] incubator-mynewt-core git commit: BLE Host - Free mbuf on
os_mqueue_put() failure.
Posted by st...@apache.org.
BLE Host - Free mbuf on os_mqueue_put() failure.
This fixes a theoretical mbuf leak. In practice, the call to
os_mqueue_put() will never fail.
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/259f4c3b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/259f4c3b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/259f4c3b
Branch: refs/heads/sterly_refactor
Commit: 259f4c3bfc72afdd69c78b82ffbc43fc9d2a39d8
Parents: a449b70
Author: Christopher Collins <cc...@apache.org>
Authored: Fri Aug 5 12:16:40 2016 -0700
Committer: Sterling Hughes <st...@apache.org>
Committed: Tue Aug 9 16:05:21 2016 -0700
----------------------------------------------------------------------
net/nimble/host/src/ble_hs.c | 10 ++++++++++
1 file changed, 10 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/259f4c3b/net/nimble/host/src/ble_hs.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs.c b/net/nimble/host/src/ble_hs.c
index 225b26c..02db879 100644
--- a/net/nimble/host/src/ble_hs.c
+++ b/net/nimble/host/src/ble_hs.c
@@ -496,6 +496,15 @@ ble_hs_rx_data(struct os_mbuf *om, void *arg)
return rc;
}
+/**
+ * Enqueues an ACL data packet for transmission. This function consumes the
+ * supplied mbuf, regardless of the outcome.
+ *
+ * @param om The outgoing data packet, beginning with the
+ * HCI ACL data header.
+ *
+ * @return 0 on success; nonzero on failure.
+ */
int
ble_hs_tx_data(struct os_mbuf *om)
{
@@ -503,6 +512,7 @@ ble_hs_tx_data(struct os_mbuf *om)
rc = os_mqueue_put(&ble_hs_tx_q, &ble_hs_evq, om);
if (rc != 0) {
+ os_mbuf_free_chain(om);
return BLE_HS_EOS;
}
os_eventq_put(ble_hs_parent_evq, &ble_hs_event_co.cf_c.c_ev);
[07/42] incubator-mynewt-core git commit: fcb;
fix endless loop on corrupted FCB area.
Posted by st...@apache.org.
fcb; fix endless loop on corrupted FCB area.
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/18298ea8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/18298ea8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/18298ea8
Branch: refs/heads/sterly_refactor
Commit: 18298ea80694fab5579773e585a122dccdddc6d5
Parents: 904ec76
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Wed Aug 3 17:21:19 2016 -0700
Committer: Sterling Hughes <st...@apache.org>
Committed: Tue Aug 9 16:05:21 2016 -0700
----------------------------------------------------------------------
sys/fcb/src/fcb.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/18298ea8/sys/fcb/src/fcb.c
----------------------------------------------------------------------
diff --git a/sys/fcb/src/fcb.c b/sys/fcb/src/fcb.c
index 2779575..fb85508 100644
--- a/sys/fcb/src/fcb.c
+++ b/sys/fcb/src/fcb.c
@@ -83,11 +83,15 @@ fcb_init(struct fcb *fcb)
while (1) {
rc = fcb_getnext_in_area(fcb, &fcb->f_active);
if (rc == FCB_ERR_NOVAR) {
+ rc = FCB_OK;
+ break;
+ }
+ if (rc != 0) {
break;
}
}
os_mutex_init(&fcb->f_mtx);
- return FCB_OK;
+ return rc;
}
int
[28/42] incubator-mynewt-core git commit: BLE Host - distinguish
already/busy in conn/disc.
Posted by st...@apache.org.
BLE Host - distinguish already/busy in conn/disc.
Prior to this change, both ble_gap_connect() and ble_gap_disc() return
BLE_HS_EALREADY if any master procedure was already in progress (either
connect or discover).
Now, Each function returns:
* BLE_HS_EALREDY if the same procedure is already in progress
* BLE_HS_EBUSY if the other procedure is already in progress
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/5863ce67
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/5863ce67
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/5863ce67
Branch: refs/heads/sterly_refactor
Commit: 5863ce670c583412b951103a849497d2347907cc
Parents: f5f8370
Author: Christopher Collins <cc...@apache.org>
Authored: Sat Aug 6 14:08:59 2016 -0700
Committer: Sterling Hughes <st...@apache.org>
Committed: Tue Aug 9 16:05:21 2016 -0700
----------------------------------------------------------------------
net/nimble/host/src/ble_gap.c | 13 +++-
net/nimble/host/src/test/ble_gap_test.c | 111 +++++++++++++++++++++++----
2 files changed, 105 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5863ce67/net/nimble/host/src/ble_gap.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gap.c b/net/nimble/host/src/ble_gap.c
index 6086c50..49d678e 100644
--- a/net/nimble/host/src/ble_gap.c
+++ b/net/nimble/host/src/ble_gap.c
@@ -1994,7 +1994,11 @@ ble_gap_disc_validate(uint8_t own_addr_type,
return BLE_HS_EINVAL;
}
- if (ble_gap_master.op != BLE_GAP_OP_NULL) {
+ if (ble_gap_conn_active()) {
+ return BLE_HS_EBUSY;
+ }
+
+ if (ble_gap_disc_active()) {
return BLE_HS_EALREADY;
}
@@ -2230,11 +2234,16 @@ ble_gap_connect(uint8_t own_addr_type,
ble_hs_lock();
- if (ble_gap_master.op != BLE_GAP_OP_NULL) {
+ if (ble_gap_conn_active()) {
rc = BLE_HS_EALREADY;
goto done;
}
+ if (ble_gap_disc_active()) {
+ rc = BLE_HS_EBUSY;
+ goto done;
+ }
+
if (!ble_hs_conn_can_alloc()) {
rc = BLE_HS_ENOMEM;
goto done;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5863ce67/net/nimble/host/src/test/ble_gap_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gap_test.c b/net/nimble/host/src/test/ble_gap_test.c
index 170b8d9..2d4c551 100644
--- a/net/nimble/host/src/test/ble_gap_test.c
+++ b/net/nimble/host/src/test/ble_gap_test.c
@@ -572,15 +572,6 @@ TEST_CASE(ble_gap_test_case_disc_bad_args)
rc = ble_gap_disc(BLE_ADDR_TYPE_PUBLIC, 0, ¶ms,
ble_gap_test_util_disc_cb, NULL);
TEST_ASSERT(rc == BLE_HS_EINVAL);
-
- /*** Master operation already in progress. */
- params.filter_policy = BLE_HCI_SCAN_FILT_NO_WL;
- rc = ble_hs_test_util_connect(BLE_ADDR_TYPE_PUBLIC,
- BLE_GAP_ADDR_TYPE_WL, NULL, 0, NULL,
- ble_gap_test_util_connect_cb, NULL, 0);
- rc = ble_gap_disc(BLE_ADDR_TYPE_PUBLIC, 0, ¶ms,
- ble_gap_test_util_disc_cb, NULL);
- TEST_ASSERT(rc == BLE_HS_EALREADY);
}
TEST_CASE(ble_gap_test_case_disc_good)
@@ -763,6 +754,45 @@ TEST_CASE(ble_gap_test_case_disc_dflts)
ble_gap_test_util_disc_dflts_once(1);
}
+TEST_CASE(ble_gap_test_case_disc_already)
+{
+ static const struct ble_gap_disc_params disc_params = { 0 };
+ int rc;
+
+ ble_gap_test_util_init();
+
+ /* Start a discovery procedure. */
+ rc = ble_hs_test_util_disc(BLE_ADDR_TYPE_PUBLIC, BLE_HS_FOREVER,
+ &disc_params, ble_gap_test_util_disc_cb,
+ NULL, -1, 0);
+ TEST_ASSERT_FATAL(rc == 0);
+
+ /* Ensure host indicates BLE_HS_EALREADY if we try to discover. */
+ rc = ble_gap_disc(BLE_ADDR_TYPE_PUBLIC, BLE_HS_FOREVER, &disc_params,
+ ble_gap_test_util_disc_cb, NULL);
+ TEST_ASSERT(rc == BLE_HS_EALREADY);
+}
+
+TEST_CASE(ble_gap_test_case_disc_busy)
+{
+ static const struct ble_gap_disc_params disc_params = { 0 };
+ static const uint8_t peer_addr[6] = { 1, 2, 3, 4, 5, 6 };
+ int rc;
+
+ ble_gap_test_util_init();
+
+ /* Start a connect procedure. */
+ rc = ble_hs_test_util_connect(BLE_ADDR_TYPE_PUBLIC, BLE_ADDR_TYPE_PUBLIC,
+ peer_addr, 0, NULL,
+ ble_gap_test_util_connect_cb, NULL, 0);
+ TEST_ASSERT_FATAL(rc == 0);
+
+ /* Ensure host indicates BLE_HS_EBUSY if we try to discover. */
+ rc = ble_gap_disc(BLE_ADDR_TYPE_PUBLIC, BLE_HS_FOREVER, &disc_params,
+ ble_gap_test_util_disc_cb, NULL);
+ TEST_ASSERT(rc == BLE_HS_EBUSY);
+}
+
TEST_SUITE(ble_gap_test_suite_disc)
{
tu_suite_set_post_test_cb(ble_hs_test_util_post_test, NULL);
@@ -772,13 +802,15 @@ TEST_SUITE(ble_gap_test_suite_disc)
ble_gap_test_case_disc_ltd_mismatch();
ble_gap_test_case_disc_hci_fail();
ble_gap_test_case_disc_dflts();
+ ble_gap_test_case_disc_already();
+ ble_gap_test_case_disc_busy();
}
/*****************************************************************************
* $direct connect *
*****************************************************************************/
-TEST_CASE(ble_gap_test_case_conn_dir_good)
+TEST_CASE(ble_gap_test_case_conn_gen_good)
{
struct hci_le_conn_complete evt;
struct ble_gap_conn_params params;
@@ -831,7 +863,7 @@ TEST_CASE(ble_gap_test_case_conn_dir_good)
TEST_ASSERT(ble_hs_atomic_conn_flags(2, NULL) == 0);
}
-TEST_CASE(ble_gap_test_case_conn_dir_bad_args)
+TEST_CASE(ble_gap_test_case_conn_gen_bad_args)
{
int rc;
@@ -861,7 +893,7 @@ TEST_CASE(ble_gap_test_case_conn_dir_bad_args)
TEST_ASSERT(rc == BLE_HS_EALREADY);
}
-TEST_CASE(ble_gap_test_case_conn_dir_dflt_params)
+TEST_CASE(ble_gap_test_case_conn_gen_dflt_params)
{
static const uint8_t peer_addr[6] = { 2, 3, 8, 6, 6, 1 };
int rc;
@@ -874,13 +906,58 @@ TEST_CASE(ble_gap_test_case_conn_dir_dflt_params)
TEST_ASSERT(rc == 0);
}
-TEST_SUITE(ble_gap_test_suite_conn_dir)
+TEST_CASE(ble_gap_test_case_conn_gen_already)
+{
+ static const struct ble_gap_conn_params conn_params = { 0 };
+ static const uint8_t peer_addr[6] = { 1, 2, 3, 4, 5, 6 };
+ int rc;
+
+ ble_gap_test_util_init();
+
+ /* Start a connect procedure. */
+ rc = ble_hs_test_util_connect(BLE_ADDR_TYPE_PUBLIC, BLE_ADDR_TYPE_PUBLIC,
+ peer_addr, 0, NULL,
+ ble_gap_test_util_connect_cb, NULL, 0);
+ TEST_ASSERT_FATAL(rc == 0);
+
+ /* Ensure host indicates BLE_HS_EALREADY if we try to connect. */
+ rc = ble_gap_connect(BLE_ADDR_TYPE_PUBLIC, BLE_ADDR_TYPE_PUBLIC,
+ peer_addr, BLE_HS_FOREVER, &conn_params,
+ ble_gap_test_util_connect_cb, NULL);
+ TEST_ASSERT(rc == BLE_HS_EALREADY);
+}
+
+TEST_CASE(ble_gap_test_case_conn_gen_busy)
+{
+ static const struct ble_gap_disc_params disc_params = { 0 };
+ static const struct ble_gap_conn_params conn_params = { 0 };
+ static const uint8_t peer_addr[6] = { 1, 2, 3, 4, 5, 6 };
+ int rc;
+
+ ble_gap_test_util_init();
+
+ /* Start a discovery procedure. */
+ rc = ble_hs_test_util_disc(BLE_ADDR_TYPE_PUBLIC, BLE_HS_FOREVER,
+ &disc_params, ble_gap_test_util_disc_cb,
+ NULL, -1, 0);
+ TEST_ASSERT_FATAL(rc == 0);
+
+ /* Ensure host indicates BLE_HS_EBUSY if we try to connect. */
+ rc = ble_gap_connect(BLE_ADDR_TYPE_PUBLIC, BLE_ADDR_TYPE_PUBLIC,
+ peer_addr, BLE_HS_FOREVER, &conn_params,
+ ble_gap_test_util_connect_cb, NULL);
+ TEST_ASSERT(rc == BLE_HS_EBUSY);
+}
+
+TEST_SUITE(ble_gap_test_suite_conn_gen)
{
tu_suite_set_post_test_cb(ble_hs_test_util_post_test, NULL);
- ble_gap_test_case_conn_dir_good();
- ble_gap_test_case_conn_dir_bad_args();
- ble_gap_test_case_conn_dir_dflt_params();
+ ble_gap_test_case_conn_gen_good();
+ ble_gap_test_case_conn_gen_bad_args();
+ ble_gap_test_case_conn_gen_dflt_params();
+ ble_gap_test_case_conn_gen_already();
+ ble_gap_test_case_conn_gen_busy();
}
/*****************************************************************************
@@ -2487,7 +2564,7 @@ ble_gap_test_all(void)
{
ble_gap_test_suite_wl();
ble_gap_test_suite_disc();
- ble_gap_test_suite_conn_dir();
+ ble_gap_test_suite_conn_gen();
ble_gap_test_suite_conn_cancel();
ble_gap_test_suite_conn_terminate();
ble_gap_test_suite_conn_find();
[29/42] incubator-mynewt-core git commit: BLE Host - Use
os_mbuf_append_from, not handrolled
Posted by st...@apache.org.
BLE Host - Use os_mbuf_append_from, not handrolled
This commit does not change any behavior. Some code was re-inventing
os_mbuf_append_from(). Now it just calls the function.
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/a449b702
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/a449b702
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/a449b702
Branch: refs/heads/sterly_refactor
Commit: a449b7027cdfae7941c24c434c7cb2c713b1bf4e
Parents: 5863ce6
Author: Christopher Collins <cc...@apache.org>
Authored: Fri Aug 5 12:15:11 2016 -0700
Committer: Sterling Hughes <st...@apache.org>
Committed: Tue Aug 9 16:05:21 2016 -0700
----------------------------------------------------------------------
net/nimble/host/src/ble_att_svr.c | 17 +++++------------
1 file changed, 5 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a449b702/net/nimble/host/src/ble_att_svr.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_svr.c b/net/nimble/host/src/ble_att_svr.c
index 7ccae06..2e1f158 100644
--- a/net/nimble/host/src/ble_att_svr.c
+++ b/net/nimble/host/src/ble_att_svr.c
@@ -617,7 +617,7 @@ ble_att_svr_tx_rsp(uint16_t conn_handle, int rc, struct os_mbuf *om,
ble_hs_unlock();
}
- /* Free mbuf if it was not consumed (send failed). */
+ /* Free mbuf if it was not consumed (i.e., if the send failed). */
os_mbuf_free_chain(om);
return rc;
@@ -2367,7 +2367,6 @@ ble_att_svr_rx_prep_write(uint16_t conn_handle, struct os_mbuf **rxom)
struct ble_att_prep_entry *prep_prev;
struct ble_att_svr_entry *attr_entry;
struct ble_hs_conn *conn;
- struct os_mbuf *srcom;
struct os_mbuf *txom;
uint16_t err_handle;
uint8_t *buf;
@@ -2428,16 +2427,10 @@ ble_att_svr_rx_prep_write(uint16_t conn_handle, struct os_mbuf **rxom)
}
/* Append attribute value from request onto prep mbuf. */
- for (srcom = *rxom;
- srcom != NULL;
- srcom = SLIST_NEXT(srcom, om_next)) {
-
- rc = os_mbuf_append(prep_entry->bape_value, srcom->om_data,
- srcom->om_len);
- if (rc != 0) {
- att_err = BLE_ATT_ERR_PREPARE_QUEUE_FULL;
- break;
- }
+ rc = os_mbuf_appendfrom(prep_entry->bape_value, *rxom, 0,
+ OS_MBUF_PKTLEN(*rxom));
+ if (rc != 0) {
+ att_err = BLE_ATT_ERR_PREPARE_QUEUE_FULL;
}
}
[21/42] incubator-mynewt-core git commit: BLE Host - Use
os_eventq_poll()
Posted by st...@apache.org.
BLE Host - Use os_eventq_poll()
Before, the host code implemented an eventq "peek" operation:
* disable interrupts
* check whether anything is on the eventq
* enable interrupts
* if something was on the queue, call os_eventq_get().
Unlike os_eventq_get(), os_eventq_poll() takes a timeout parameter. Now
the host calls os_eventq_poll() with a timeout of 0 to perform a
non-blocking read of the eventq.
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/f3d4aaae
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/f3d4aaae
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/f3d4aaae
Branch: refs/heads/sterly_refactor
Commit: f3d4aaae011cc027ffa73a5a1d77d54a4e59d6d7
Parents: a4c44d7
Author: Christopher Collins <cc...@apache.org>
Authored: Thu Aug 4 13:39:25 2016 -0700
Committer: Sterling Hughes <st...@apache.org>
Committed: Tue Aug 9 16:05:21 2016 -0700
----------------------------------------------------------------------
net/nimble/host/src/ble_hs.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f3d4aaae/net/nimble/host/src/ble_hs.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs.c b/net/nimble/host/src/ble_hs.c
index 8035b49..225b26c 100644
--- a/net/nimble/host/src/ble_hs.c
+++ b/net/nimble/host/src/ble_hs.c
@@ -330,17 +330,19 @@ static void
ble_hs_event_handle(void *unused)
{
struct os_callout_func *cf;
+ struct os_eventq *evqp;
struct os_event *ev;
uint8_t *hci_evt;
- os_sr_t sr;
int rc;
int i;
+ evqp = &ble_hs_evq;
+
i = 0;
while (1) {
/* If the host has already processed several consecutive events, stop
* and return control to the parent task. Put an event on the parent
- * task's eventq so indicate that more host events are enqueued.
+ * task's eventq to indicate that more host events are enqueued.
*/
if (i >= BLE_HS_MAX_EVS_IN_A_ROW) {
os_eventq_put(ble_hs_parent_evq, &ble_hs_event_co.cf_c.c_ev);
@@ -348,15 +350,11 @@ ble_hs_event_handle(void *unused)
}
i++;
- OS_ENTER_CRITICAL(sr);
- ev = STAILQ_FIRST(&ble_hs_evq.evq_list);
- OS_EXIT_CRITICAL(sr);
-
+ ev = os_eventq_poll(&evqp, 1, 0);
if (ev == NULL) {
break;
}
- ev = os_eventq_get(&ble_hs_evq);
switch (ev->ev_type) {
case OS_EVENT_T_TIMER:
cf = (struct os_callout_func *)ev;
[23/42] incubator-mynewt-core git commit: mempool - Allow mempool
with 0 blocks.
Posted by st...@apache.org.
mempool - Allow mempool with 0 blocks.
This is useful in cases when the mempool is sized according to an
application setting. If the user wants 0 of something, it is easier to
just initialize the mempool with 0 blocks and a NULL buffer, and just
let any attempt to allocate from it to fail.
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/6d5b96d5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/6d5b96d5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/6d5b96d5
Branch: refs/heads/sterly_refactor
Commit: 6d5b96d53036256146b82e8e4126efcc661a72eb
Parents: 5c00287
Author: Christopher Collins <cc...@apache.org>
Authored: Thu Aug 4 16:24:47 2016 -0700
Committer: Sterling Hughes <st...@apache.org>
Committed: Tue Aug 9 16:05:21 2016 -0700
----------------------------------------------------------------------
libs/os/src/os_mempool.c | 20 ++++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6d5b96d5/libs/os/src/os_mempool.c
----------------------------------------------------------------------
diff --git a/libs/os/src/os_mempool.c b/libs/os/src/os_mempool.c
index 04a18a1..e940ba4 100644
--- a/libs/os/src/os_mempool.c
+++ b/libs/os/src/os_mempool.c
@@ -41,21 +41,29 @@ STAILQ_HEAD(, os_mempool) g_os_mempool_list =
* @return os_error_t
*/
os_error_t
-os_mempool_init(struct os_mempool *mp, int blocks, int block_size, void *membuf,
- char *name)
+os_mempool_init(struct os_mempool *mp, int blocks, int block_size,
+ void *membuf, char *name)
{
int true_block_size;
uint8_t *block_addr;
struct os_memblock *block_ptr;
/* Check for valid parameters */
- if ((!mp) || (!membuf) || (blocks <= 0) || (block_size <= 0)) {
+ if ((!mp) || (blocks < 0) || (block_size <= 0)) {
return OS_INVALID_PARM;
}
- /* Blocks need to be sized properly and memory buffer should be aligned */
- if (((uint32_t)membuf & (OS_ALIGNMENT - 1)) != 0) {
- return OS_MEM_NOT_ALIGNED;
+ if ((!membuf) && (blocks != 0)) {
+ return OS_INVALID_PARM;
+ }
+
+ if (membuf != NULL) {
+ /* Blocks need to be sized properly and memory buffer should be
+ * aligned
+ */
+ if (((uint32_t)membuf & (OS_ALIGNMENT - 1)) != 0) {
+ return OS_MEM_NOT_ALIGNED;
+ }
}
true_block_size = OS_MEMPOOL_TRUE_BLOCK_SIZE(block_size);
[04/42] incubator-mynewt-core git commit: BLE Host - Don't assume
leading space in l2cap tx.
Posted by st...@apache.org.
BLE Host - Don't assume leading space in l2cap tx.
Call os_mbuf_prepend_pullup() rather than calling os_mbuf_prepend() and
assuming the resulting buffer is the same as the input.
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/1efa31fc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/1efa31fc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/1efa31fc
Branch: refs/heads/sterly_refactor
Commit: 1efa31fc2ef422d804c926271516c8735b833f05
Parents: 009bb6c
Author: Christopher Collins <cc...@apache.org>
Authored: Fri Aug 5 12:19:15 2016 -0700
Committer: Sterling Hughes <st...@apache.org>
Committed: Tue Aug 9 16:05:21 2016 -0700
----------------------------------------------------------------------
net/nimble/host/src/ble_l2cap.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1efa31fc/net/nimble/host/src/ble_l2cap.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap.c b/net/nimble/host/src/ble_l2cap.c
index 66bad51..43ccd6f 100644
--- a/net/nimble/host/src/ble_l2cap.c
+++ b/net/nimble/host/src/ble_l2cap.c
@@ -119,16 +119,14 @@ struct os_mbuf *
ble_l2cap_prepend_hdr(struct os_mbuf *om, uint16_t cid, uint16_t len)
{
struct ble_l2cap_hdr hdr;
- struct os_mbuf *om2;
htole16(&hdr.blh_len, len);
htole16(&hdr.blh_cid, cid);
- om2 = os_mbuf_prepend(om, sizeof hdr);
- if (om2 == NULL) {
+ om = os_mbuf_prepend_pullup(om, sizeof hdr);
+ if (om == NULL) {
return NULL;
}
- BLE_HS_DBG_ASSERT(om2 == om);
memcpy(om->om_data, &hdr, sizeof hdr);
[15/42] incubator-mynewt-core git commit: BLE Host - Rename HCI
identifiers and files.
Posted by st...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/net/nimble/host/src/host_hci_cmd.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/host_hci_cmd.c b/net/nimble/host/src/host_hci_cmd.c
deleted file mode 100644
index cce2e26..0000000
--- a/net/nimble/host/src/host_hci_cmd.c
+++ /dev/null
@@ -1,1364 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-#include <stdint.h>
-#include <assert.h>
-#include <string.h>
-#include <errno.h>
-#include <stdio.h>
-#include "os/os.h"
-#include "console/console.h"
-#include "nimble/hci_common.h"
-#include "nimble/ble_hci_trans.h"
-#include "host/host_hci.h"
-#include "host_dbg_priv.h"
-#include "ble_hs_priv.h"
-
-static int
-host_hci_cmd_transport(uint8_t *cmdbuf)
-{
- int rc;
-
- rc = ble_hci_trans_hs_cmd_tx(cmdbuf);
- switch (rc) {
- case 0:
- return 0;
-
- case BLE_ERR_MEM_CAPACITY:
- return BLE_HS_ENOMEM_EVT;
-
- default:
- return BLE_HS_EUNKNOWN;
- }
-}
-
-void
-host_hci_write_hdr(uint8_t ogf, uint8_t ocf, uint8_t len, void *buf)
-{
- uint16_t opcode;
- uint8_t *u8ptr;
-
- u8ptr = buf;
-
- opcode = (ogf << 10) | ocf;
- htole16(u8ptr, opcode);
- u8ptr[2] = len;
-}
-
-int
-host_hci_cmd_send(uint8_t ogf, uint8_t ocf, uint8_t len, const void *cmddata)
-{
- uint8_t *buf;
- int rc;
-
- buf = ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_CMD);
- BLE_HS_DBG_ASSERT(buf != NULL);
-
- htole16(buf, ogf << 10 | ocf);
- buf[2] = len;
- if (len != 0) {
- memcpy(buf + BLE_HCI_CMD_HDR_LEN, cmddata, len);
- }
-
- BLE_HS_LOG(DEBUG, "host_hci_cmd_send: ogf=0x%02x ocf=0x%02x len=%d\n",
- ogf, ocf, len);
- ble_hs_log_flat_buf(buf, len + BLE_HCI_CMD_HDR_LEN);
- BLE_HS_LOG(DEBUG, "\n");
- rc = host_hci_cmd_transport(buf);
-
- if (rc == 0) {
- STATS_INC(ble_hs_stats, hci_cmd);
- } else {
- BLE_HS_LOG(DEBUG, "host_hci_cmd_send failure; rc=%d\n", rc);
- }
-
- return rc;
-}
-
-int
-host_hci_cmd_send_buf(void *buf)
-{
- uint16_t opcode;
- uint8_t *u8ptr;
- uint8_t len;
- int rc;
-
- switch (ble_hs_sync_state) {
- case BLE_HS_SYNC_STATE_BAD:
- return BLE_HS_ENOTSYNCED;
-
- case BLE_HS_SYNC_STATE_BRINGUP:
- if (!ble_hs_is_parent_task()) {
- return BLE_HS_ENOTSYNCED;
- }
- break;
-
- case BLE_HS_SYNC_STATE_GOOD:
- break;
-
- default:
- BLE_HS_DBG_ASSERT(0);
- return BLE_HS_EUNKNOWN;
- }
-
- u8ptr = buf;
-
- opcode = le16toh(u8ptr + 0);
- len = u8ptr[2];
-
- rc = host_hci_cmd_send(BLE_HCI_OGF(opcode), BLE_HCI_OCF(opcode), len,
- u8ptr + BLE_HCI_CMD_HDR_LEN);
- return rc;
-}
-
-
-/**
- * Send a LE command from the host to the controller.
- *
- * @param ocf
- * @param len
- * @param cmddata
- *
- * @return int
- */
-static int
-host_hci_le_cmd_send(uint16_t ocf, uint8_t len, void *cmddata)
-{
- int rc;
- rc = host_hci_cmd_send(BLE_HCI_OGF_LE, ocf, len, cmddata);
- return rc;
-}
-
-/**
- * Read BD_ADDR
- *
- * OGF = 0x04 (Informational parameters)
- * OCF = 0x0009
- */
-void
-host_hci_cmd_build_read_bd_addr(uint8_t *dst, int dst_len)
-{
- BLE_HS_DBG_ASSERT(dst_len >= BLE_HCI_CMD_HDR_LEN);
- host_hci_write_hdr(BLE_HCI_OGF_INFO_PARAMS, BLE_HCI_OCF_IP_RD_BD_ADDR,
- 0, dst);
-}
-
-static int
-host_hci_cmd_body_le_whitelist_chg(const uint8_t *addr, uint8_t addr_type,
- uint8_t *dst)
-{
- if (addr_type > BLE_ADDR_TYPE_RANDOM) {
- return BLE_ERR_INV_HCI_CMD_PARMS;
- }
-
- dst[0] = addr_type;
- memcpy(dst + 1, addr, BLE_DEV_ADDR_LEN);
-
- return 0;
-}
-
-static int
-host_hci_cmd_body_le_set_adv_params(const struct hci_adv_params *adv,
- uint8_t *dst)
-{
- uint16_t itvl;
-
- BLE_HS_DBG_ASSERT(adv != NULL);
-
- /* Make sure parameters are valid */
- if ((adv->adv_itvl_min > adv->adv_itvl_max) ||
- (adv->own_addr_type > BLE_HCI_ADV_OWN_ADDR_MAX) ||
- (adv->peer_addr_type > BLE_HCI_ADV_PEER_ADDR_MAX) ||
- (adv->adv_filter_policy > BLE_HCI_ADV_FILT_MAX) ||
- (adv->adv_type > BLE_HCI_ADV_TYPE_MAX) ||
- (adv->adv_channel_map == 0) ||
- ((adv->adv_channel_map & 0xF8) != 0)) {
- /* These parameters are not valid */
- return -1;
- }
-
- /* Make sure interval is valid for advertising type. */
- if ((adv->adv_type == BLE_HCI_ADV_TYPE_ADV_NONCONN_IND) ||
- (adv->adv_type == BLE_HCI_ADV_TYPE_ADV_SCAN_IND)) {
- itvl = BLE_HCI_ADV_ITVL_NONCONN_MIN;
- } else {
- itvl = BLE_HCI_ADV_ITVL_MIN;
- }
-
- /* Do not check if high duty-cycle directed */
- if (adv->adv_type != BLE_HCI_ADV_TYPE_ADV_DIRECT_IND_HD) {
- if ((adv->adv_itvl_min < itvl) ||
- (adv->adv_itvl_min > BLE_HCI_ADV_ITVL_MAX)) {
- return -1;
- }
- }
-
- htole16(dst, adv->adv_itvl_min);
- htole16(dst + 2, adv->adv_itvl_max);
- dst[4] = adv->adv_type;
- dst[5] = adv->own_addr_type;
- dst[6] = adv->peer_addr_type;
- memcpy(dst + 7, adv->peer_addr, BLE_DEV_ADDR_LEN);
- dst[13] = adv->adv_channel_map;
- dst[14] = adv->adv_filter_policy;
-
- return 0;
-}
-
-int
-host_hci_cmd_build_le_set_adv_params(const struct hci_adv_params *adv,
- uint8_t *dst, int dst_len)
-{
- int rc;
-
- BLE_HS_DBG_ASSERT(
- dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_ADV_PARAM_LEN);
-
- host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_SET_ADV_PARAMS,
- BLE_HCI_SET_ADV_PARAM_LEN, dst);
- dst += BLE_HCI_CMD_HDR_LEN;
-
- rc = host_hci_cmd_body_le_set_adv_params(adv, dst);
- if (rc != 0) {
- return rc;
- }
-
- return 0;
-}
-
-/**
- * Set advertising data
- *
- * OGF = 0x08 (LE)
- * OCF = 0x0008
- *
- * @param data
- * @param len
- * @param dst
- *
- * @return int
- */
-static int
-host_hci_cmd_body_le_set_adv_data(const uint8_t *data, uint8_t len,
- uint8_t *dst)
-{
- /* Check for valid parameters */
- if (((data == NULL) && (len != 0)) || (len > BLE_HCI_MAX_ADV_DATA_LEN)) {
- return BLE_ERR_INV_HCI_CMD_PARMS;
- }
-
- memset(dst, 0, BLE_HCI_SET_ADV_DATA_LEN);
- dst[0] = len;
- memcpy(dst + 1, data, len);
-
- return 0;
-}
-
-/**
- * Set advertising data
- *
- * OGF = 0x08 (LE)
- * OCF = 0x0008
- *
- * @param data
- * @param len
- * @param dst
- *
- * @return int
- */
-int
-host_hci_cmd_build_le_set_adv_data(const uint8_t *data, uint8_t len,
- uint8_t *dst, int dst_len)
-{
- int rc;
-
- BLE_HS_DBG_ASSERT(
- dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_ADV_DATA_LEN);
-
- host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_SET_ADV_DATA,
- BLE_HCI_SET_ADV_DATA_LEN, dst);
- dst += BLE_HCI_CMD_HDR_LEN;
-
- rc = host_hci_cmd_body_le_set_adv_data(data, len, dst);
- if (rc != 0) {
- return rc;
- }
-
- return 0;
-}
-
-static int
-host_hci_cmd_body_le_set_scan_rsp_data(const uint8_t *data, uint8_t len,
- uint8_t *dst)
-{
- /* Check for valid parameters */
- if (((data == NULL) && (len != 0)) ||
- (len > BLE_HCI_MAX_SCAN_RSP_DATA_LEN)) {
- return BLE_ERR_INV_HCI_CMD_PARMS;
- }
-
- memset(dst, 0, BLE_HCI_SET_SCAN_RSP_DATA_LEN);
- dst[0] = len;
- memcpy(dst + 1, data, len);
-
- return 0;
-}
-
-int
-host_hci_cmd_build_le_set_scan_rsp_data(const uint8_t *data, uint8_t len,
- uint8_t *dst, int dst_len)
-{
- int rc;
-
- BLE_HS_DBG_ASSERT(
- dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_SCAN_RSP_DATA_LEN);
-
- host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_SET_SCAN_RSP_DATA,
- BLE_HCI_SET_SCAN_RSP_DATA_LEN, dst);
- dst += BLE_HCI_CMD_HDR_LEN;
-
- rc = host_hci_cmd_body_le_set_scan_rsp_data(data, len, dst);
- if (rc != 0) {
- return rc;
- }
-
- return 0;
-}
-
-static void
-host_hci_cmd_body_set_event_mask(uint64_t event_mask, uint8_t *dst)
-{
- htole64(dst, event_mask);
-}
-
-void
-host_hci_cmd_build_set_event_mask(uint64_t event_mask,
- uint8_t *dst, int dst_len)
-{
- BLE_HS_DBG_ASSERT(
- dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_EVENT_MASK_LEN);
-
- host_hci_write_hdr(BLE_HCI_OGF_CTLR_BASEBAND,
- BLE_HCI_OCF_CB_SET_EVENT_MASK,
- BLE_HCI_SET_EVENT_MASK_LEN, dst);
- dst += BLE_HCI_CMD_HDR_LEN;
-
- host_hci_cmd_body_set_event_mask(event_mask, dst);
-}
-
-void
-host_hci_cmd_build_set_event_mask2(uint64_t event_mask,
- uint8_t *dst, int dst_len)
-{
- BLE_HS_DBG_ASSERT(
- dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_EVENT_MASK_LEN);
-
- host_hci_write_hdr(BLE_HCI_OGF_CTLR_BASEBAND,
- BLE_HCI_OCF_CB_SET_EVENT_MASK2,
- BLE_HCI_SET_EVENT_MASK_LEN, dst);
- dst += BLE_HCI_CMD_HDR_LEN;
-
- host_hci_cmd_body_set_event_mask(event_mask, dst);
-}
-
-static void
-host_hci_cmd_body_disconnect(uint16_t handle, uint8_t reason, uint8_t *dst)
-{
- htole16(dst + 0, handle);
- dst[2] = reason;
-}
-
-void
-host_hci_cmd_build_disconnect(uint16_t handle, uint8_t reason,
- uint8_t *dst, int dst_len)
-{
- BLE_HS_DBG_ASSERT(
- dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_DISCONNECT_CMD_LEN);
-
- host_hci_write_hdr(BLE_HCI_OGF_LINK_CTRL, BLE_HCI_OCF_DISCONNECT_CMD,
- BLE_HCI_DISCONNECT_CMD_LEN, dst);
- dst += BLE_HCI_CMD_HDR_LEN;
-
- host_hci_cmd_body_disconnect(handle, reason, dst);
-}
-
-int
-host_hci_cmd_disconnect(uint16_t handle, uint8_t reason)
-{
- uint8_t cmd[BLE_HCI_DISCONNECT_CMD_LEN];
- int rc;
-
- host_hci_cmd_body_disconnect(handle, reason, cmd);
- rc = host_hci_cmd_send(BLE_HCI_OGF_LINK_CTRL,
- BLE_HCI_OCF_DISCONNECT_CMD,
- BLE_HCI_DISCONNECT_CMD_LEN,
- cmd);
- return rc;
-}
-
-static void
-host_hci_cmd_body_le_set_event_mask(uint64_t event_mask, uint8_t *dst)
-{
- htole64(dst, event_mask);
-}
-
-void
-host_hci_cmd_build_le_set_event_mask(uint64_t event_mask,
- uint8_t *dst, int dst_len)
-{
- BLE_HS_DBG_ASSERT(
- dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_LE_EVENT_MASK_LEN);
-
- host_hci_write_hdr(BLE_HCI_OGF_LE,
- BLE_HCI_OCF_LE_SET_EVENT_MASK,
- BLE_HCI_SET_LE_EVENT_MASK_LEN, dst);
- dst += BLE_HCI_CMD_HDR_LEN;
-
- host_hci_cmd_body_le_set_event_mask(event_mask, dst);
-}
-
-/**
- * LE Read buffer size
- *
- * OGF = 0x08 (LE)
- * OCF = 0x0002
- *
- * @return int
- */
-void
-host_hci_cmd_build_le_read_buffer_size(uint8_t *dst, int dst_len)
-{
- BLE_HS_DBG_ASSERT(dst_len >= BLE_HCI_CMD_HDR_LEN);
- host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_RD_BUF_SIZE, 0, dst);
-}
-
-/**
- * LE Read buffer size
- *
- * OGF = 0x08 (LE)
- * OCF = 0x0002
- *
- * @return int
- */
-int
-host_hci_cmd_le_read_buffer_size(void)
-{
- int rc;
-
- rc = host_hci_le_cmd_send(BLE_HCI_OCF_LE_RD_BUF_SIZE, 0, NULL);
- return rc;
-}
-
-/**
- * OGF=LE, OCF=0x0003
- */
-void
-host_hci_cmd_build_le_read_loc_supp_feat(uint8_t *dst, uint8_t dst_len)
-{
- BLE_HS_DBG_ASSERT(dst_len >= BLE_HCI_CMD_HDR_LEN);
- host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_RD_LOC_SUPP_FEAT,
- 0, dst);
-}
-
-static void
-host_hci_cmd_body_le_set_adv_enable(uint8_t enable, uint8_t *dst)
-{
- dst[0] = enable;
-}
-
-void
-host_hci_cmd_build_le_set_adv_enable(uint8_t enable, uint8_t *dst,
- int dst_len)
-{
- BLE_HS_DBG_ASSERT(
- dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_ADV_ENABLE_LEN);
-
- host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_SET_ADV_ENABLE,
- BLE_HCI_SET_ADV_ENABLE_LEN, dst);
- dst += BLE_HCI_CMD_HDR_LEN;
-
- host_hci_cmd_body_le_set_adv_enable(enable, dst);
-}
-
-static int
-host_hci_cmd_body_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, uint8_t *dst) {
-
- /* Make sure parameters are valid */
- if ((scan_type != BLE_HCI_SCAN_TYPE_PASSIVE) &&
- (scan_type != BLE_HCI_SCAN_TYPE_ACTIVE)) {
- return BLE_ERR_INV_HCI_CMD_PARMS;
- }
-
- /* Check interval and window */
- if ((scan_itvl < BLE_HCI_SCAN_ITVL_MIN) ||
- (scan_itvl > BLE_HCI_SCAN_ITVL_MAX) ||
- (scan_window < BLE_HCI_SCAN_WINDOW_MIN) ||
- (scan_window > BLE_HCI_SCAN_WINDOW_MAX) ||
- (scan_itvl < scan_window)) {
- return BLE_ERR_INV_HCI_CMD_PARMS;
- }
-
- /* Check own addr type */
- if (own_addr_type > BLE_HCI_ADV_OWN_ADDR_MAX) {
- return BLE_ERR_INV_HCI_CMD_PARMS;
- }
-
- /* Check scanner filter policy */
- if (filter_policy > BLE_HCI_SCAN_FILT_MAX) {
- return BLE_ERR_INV_HCI_CMD_PARMS;
- }
-
- dst[0] = scan_type;
- htole16(dst + 1, scan_itvl);
- htole16(dst + 3, scan_window);
- dst[5] = own_addr_type;
- dst[6] = filter_policy;
-
- return 0;
-}
-
-int
-host_hci_cmd_build_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,
- uint8_t *dst, int dst_len)
-{
- int rc;
-
- BLE_HS_DBG_ASSERT(
- dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_SCAN_PARAM_LEN);
-
- host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_SET_SCAN_PARAMS,
- BLE_HCI_SET_SCAN_PARAM_LEN, dst);
- dst += BLE_HCI_CMD_HDR_LEN;
-
- rc = host_hci_cmd_body_le_set_scan_params(scan_type, scan_itvl,
- scan_window, own_addr_type,
- filter_policy, dst);
- if (rc != 0) {
- return rc;
- }
-
- return 0;
-}
-
-static void
-host_hci_cmd_body_le_set_scan_enable(uint8_t enable, uint8_t filter_dups,
- uint8_t *dst)
-{
- dst[0] = enable;
- dst[1] = filter_dups;
-}
-
-void
-host_hci_cmd_build_le_set_scan_enable(uint8_t enable, uint8_t filter_dups,
- uint8_t *dst, uint8_t dst_len)
-{
- BLE_HS_DBG_ASSERT(
- dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_SCAN_ENABLE_LEN);
-
- host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_SET_SCAN_ENABLE,
- BLE_HCI_SET_SCAN_ENABLE_LEN, dst);
-
- host_hci_cmd_body_le_set_scan_enable(enable, filter_dups,
- dst + BLE_HCI_CMD_HDR_LEN);
-}
-
-static int
-host_hci_cmd_body_le_create_connection(const struct hci_create_conn *hcc,
- uint8_t *cmd)
-{
- /* 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_CONN_FILT_MAX) {
- return BLE_ERR_INV_HCI_CMD_PARMS;
- }
-
- /* Check peer addr type */
- if (hcc->peer_addr_type > BLE_HCI_CONN_PEER_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);
-
- return 0;
-}
-
-int
-host_hci_cmd_build_le_create_connection(const struct hci_create_conn *hcc,
- uint8_t *cmd, int cmd_len)
-{
- int rc;
-
- BLE_HS_DBG_ASSERT(
- cmd_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_CREATE_CONN_LEN);
-
- host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_CREATE_CONN,
- BLE_HCI_CREATE_CONN_LEN, cmd);
-
- rc = host_hci_cmd_body_le_create_connection(hcc,
- cmd + BLE_HCI_CMD_HDR_LEN);
- if (rc != 0) {
- return rc;
- }
-
- return 0;
-}
-
-void
-host_hci_cmd_build_le_clear_whitelist(uint8_t *dst, int dst_len)
-{
- BLE_HS_DBG_ASSERT(dst_len >= BLE_HCI_CMD_HDR_LEN);
- host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_CLEAR_WHITE_LIST,
- 0, dst);
-}
-
-int
-host_hci_cmd_build_le_add_to_whitelist(const uint8_t *addr, uint8_t addr_type,
- uint8_t *dst, int dst_len)
-{
- int rc;
-
- BLE_HS_DBG_ASSERT(
- dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_CHG_WHITE_LIST_LEN);
-
- host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_ADD_WHITE_LIST,
- BLE_HCI_CHG_WHITE_LIST_LEN, dst);
- dst += BLE_HCI_CMD_HDR_LEN;
-
- rc = host_hci_cmd_body_le_whitelist_chg(addr, addr_type, dst);
- if (rc != 0) {
- return rc;
- }
-
- return 0;
-}
-
-void
-host_hci_cmd_build_reset(uint8_t *dst, int dst_len)
-{
- BLE_HS_DBG_ASSERT(dst_len >= BLE_HCI_CMD_HDR_LEN);
- host_hci_write_hdr(BLE_HCI_OGF_CTLR_BASEBAND, BLE_HCI_OCF_CB_RESET,
- 0, dst);
-}
-
-/**
- * Reset the controller and link manager.
- *
- * @return int
- */
-int
-host_hci_cmd_reset(void)
-{
- int rc;
-
- rc = host_hci_cmd_send(BLE_HCI_OGF_CTLR_BASEBAND, BLE_HCI_OCF_CB_RESET, 0,
- NULL);
- return rc;
-}
-
-void
-host_hci_cmd_build_read_adv_pwr(uint8_t *dst, int dst_len)
-{
- BLE_HS_DBG_ASSERT(dst_len >= BLE_HCI_CMD_HDR_LEN);
- host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_RD_ADV_CHAN_TXPWR,
- 0, dst);
-}
-
-/**
- * Read the transmit power level used for LE advertising channel packets.
- *
- * @return int
- */
-int
-host_hci_cmd_read_adv_pwr(void)
-{
- int rc;
-
- rc = host_hci_cmd_send(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_RD_ADV_CHAN_TXPWR, 0,
- NULL);
- return rc;
-}
-
-void
-host_hci_cmd_build_le_create_conn_cancel(uint8_t *dst, int dst_len)
-{
- BLE_HS_DBG_ASSERT(dst_len >= BLE_HCI_CMD_HDR_LEN);
- host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_CREATE_CONN_CANCEL,
- 0, dst);
-}
-
-int
-host_hci_cmd_le_create_conn_cancel(void)
-{
- int rc;
-
- rc = host_hci_cmd_send(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_CREATE_CONN_CANCEL,
- 0, NULL);
- return rc;
-}
-
-static int
-host_hci_cmd_body_le_conn_update(const struct hci_conn_update *hcu,
- uint8_t *dst)
-{
- /* XXX: add parameter checking later */
- htole16(dst + 0, hcu->handle);
- htole16(dst + 2, hcu->conn_itvl_min);
- htole16(dst + 4, hcu->conn_itvl_max);
- htole16(dst + 6, hcu->conn_latency);
- htole16(dst + 8, hcu->supervision_timeout);
- htole16(dst + 10, hcu->min_ce_len);
- htole16(dst + 12, hcu->max_ce_len);
-
- return 0;
-}
-
-int
-host_hci_cmd_build_le_conn_update(const struct hci_conn_update *hcu,
- uint8_t *dst, int dst_len)
-{
- int rc;
-
- BLE_HS_DBG_ASSERT(
- dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_CONN_UPDATE_LEN);
-
- host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_CONN_UPDATE,
- BLE_HCI_CONN_UPDATE_LEN, dst);
- dst += BLE_HCI_CMD_HDR_LEN;
-
- rc = host_hci_cmd_body_le_conn_update(hcu, dst);
- if (rc != 0) {
- return rc;
- }
-
- return 0;
-}
-
-int
-host_hci_cmd_le_conn_update(const struct hci_conn_update *hcu)
-{
- uint8_t cmd[BLE_HCI_CONN_UPDATE_LEN];
- int rc;
-
- rc = host_hci_cmd_body_le_conn_update(hcu, cmd);
- if (rc != 0) {
- return rc;
- }
-
- rc = host_hci_le_cmd_send(BLE_HCI_OCF_LE_CONN_UPDATE,
- BLE_HCI_CONN_UPDATE_LEN, cmd);
- if (rc != 0) {
- return rc;
- }
-
- return 0;
-}
-
-static void
-host_hci_cmd_body_le_lt_key_req_reply(const struct hci_lt_key_req_reply *hkr,
- uint8_t *dst)
-{
- htole16(dst + 0, hkr->conn_handle);
- memcpy(dst + 2, hkr->long_term_key, sizeof hkr->long_term_key);
-}
-
-/**
- * Sends the long-term key (LTK) to the controller.
- *
- * Note: This function expects the 128-bit key to be in little-endian byte
- * order.
- *
- * OGF = 0x08 (LE)
- * OCF = 0x001a
- *
- * @param key
- * @param pt
- *
- * @return int
- */
-void
-host_hci_cmd_build_le_lt_key_req_reply(const struct hci_lt_key_req_reply *hkr,
- uint8_t *dst, int dst_len)
-{
- BLE_HS_DBG_ASSERT(
- dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_LT_KEY_REQ_REPLY_LEN);
-
- host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_LT_KEY_REQ_REPLY,
- BLE_HCI_LT_KEY_REQ_REPLY_LEN, dst);
- dst += BLE_HCI_CMD_HDR_LEN;
-
- host_hci_cmd_body_le_lt_key_req_reply(hkr, dst);
-}
-
-void
-host_hci_cmd_build_le_lt_key_req_neg_reply(uint16_t conn_handle,
- uint8_t *dst, int dst_len)
-{
- BLE_HS_DBG_ASSERT(
- dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_LT_KEY_REQ_NEG_REPLY_LEN);
-
- host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_LT_KEY_REQ_NEG_REPLY,
- BLE_HCI_LT_KEY_REQ_NEG_REPLY_LEN, dst);
- dst += BLE_HCI_CMD_HDR_LEN;
-
- htole16(dst + 0, conn_handle);
-}
-
-static void
-host_hci_cmd_body_le_conn_param_reply(const struct hci_conn_param_reply *hcr,
- uint8_t *dst)
-{
- htole16(dst + 0, hcr->handle);
- htole16(dst + 2, hcr->conn_itvl_min);
- htole16(dst + 4, hcr->conn_itvl_max);
- htole16(dst + 6, hcr->conn_latency);
- htole16(dst + 8, hcr->supervision_timeout);
- htole16(dst + 10, hcr->min_ce_len);
- htole16(dst + 12, hcr->max_ce_len);
-}
-
-void
-host_hci_cmd_build_le_conn_param_reply(const struct hci_conn_param_reply *hcr,
- uint8_t *dst, int dst_len)
-{
- BLE_HS_DBG_ASSERT(
- dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_CONN_PARAM_REPLY_LEN);
-
- host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_REM_CONN_PARAM_RR,
- BLE_HCI_CONN_PARAM_REPLY_LEN, dst);
- dst += BLE_HCI_CMD_HDR_LEN;
-
- host_hci_cmd_body_le_conn_param_reply(hcr, dst);
-}
-
-int
-host_hci_cmd_le_conn_param_reply(const struct hci_conn_param_reply *hcr)
-{
- uint8_t cmd[BLE_HCI_CONN_PARAM_REPLY_LEN];
- int rc;
-
- htole16(cmd + 0, hcr->handle);
- htole16(cmd + 2, hcr->conn_itvl_min);
- htole16(cmd + 4, hcr->conn_itvl_max);
- htole16(cmd + 6, hcr->conn_latency);
- htole16(cmd + 8, hcr->supervision_timeout);
- htole16(cmd + 10, hcr->min_ce_len);
- htole16(cmd + 12, hcr->max_ce_len);
-
- rc = host_hci_le_cmd_send(BLE_HCI_OCF_LE_REM_CONN_PARAM_RR,
- BLE_HCI_CONN_PARAM_REPLY_LEN, cmd);
- return rc;
-}
-
-static void
-host_hci_cmd_body_le_conn_param_neg_reply(
- const struct hci_conn_param_neg_reply *hcn, uint8_t *dst)
-{
- htole16(dst + 0, hcn->handle);
- dst[2] = hcn->reason;
-}
-
-
-void
-host_hci_cmd_build_le_conn_param_neg_reply(
- const struct hci_conn_param_neg_reply *hcn, uint8_t *dst, int dst_len)
-{
- BLE_HS_DBG_ASSERT(
- dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_CONN_PARAM_NEG_REPLY_LEN);
-
- host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_REM_CONN_PARAM_NRR,
- BLE_HCI_CONN_PARAM_NEG_REPLY_LEN, dst);
- dst += BLE_HCI_CMD_HDR_LEN;
-
- host_hci_cmd_body_le_conn_param_neg_reply(hcn, dst);
-}
-
-int
-host_hci_cmd_le_conn_param_neg_reply(
- const struct hci_conn_param_neg_reply *hcn)
-{
- uint8_t cmd[BLE_HCI_CONN_PARAM_NEG_REPLY_LEN];
- int rc;
-
- host_hci_cmd_body_le_conn_param_neg_reply(hcn, cmd);
-
- rc = host_hci_le_cmd_send(BLE_HCI_OCF_LE_REM_CONN_PARAM_NRR,
- BLE_HCI_CONN_PARAM_NEG_REPLY_LEN, cmd);
- return rc;
-}
-
-/**
- * Get random data
- *
- * OGF = 0x08 (LE)
- * OCF = 0x0018
- *
- * @return int
- */
-void
-host_hci_cmd_build_le_rand(uint8_t *dst, int dst_len)
-{
- BLE_HS_DBG_ASSERT(dst_len >= BLE_HCI_CMD_HDR_LEN);
- host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_RAND, 0, dst);
-}
-
-static void
-host_hci_cmd_body_le_start_encrypt(const struct hci_start_encrypt *cmd,
- uint8_t *dst)
-{
- htole16(dst + 0, cmd->connection_handle);
- htole64(dst + 2, cmd->random_number);
- htole16(dst + 10, cmd->encrypted_diversifier);
- memcpy(dst + 12, cmd->long_term_key, sizeof cmd->long_term_key);
-}
-
-/*
- * OGF=0x08 OCF=0x0019
- */
-void
-host_hci_cmd_build_le_start_encrypt(const struct hci_start_encrypt *cmd,
- uint8_t *dst, int dst_len)
-{
- BLE_HS_DBG_ASSERT(
- dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_LE_START_ENCRYPT_LEN);
-
- host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_START_ENCRYPT,
- BLE_HCI_LE_START_ENCRYPT_LEN, dst);
- dst += BLE_HCI_CMD_HDR_LEN;
-
- host_hci_cmd_body_le_start_encrypt(cmd, dst);
-}
-
-/**
- * Read the RSSI for a given connection handle
- *
- * NOTE: OGF=0x05 OCF=0x0005
- *
- * @param handle
- *
- * @return int
- */
-static void
-host_hci_cmd_body_read_rssi(uint16_t handle, uint8_t *dst)
-{
- htole16(dst, handle);
-}
-
-void
-host_hci_cmd_build_read_rssi(uint16_t handle, uint8_t *dst, int dst_len)
-{
- BLE_HS_DBG_ASSERT(
- dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_READ_RSSI_LEN);
-
- host_hci_write_hdr(BLE_HCI_OGF_STATUS_PARAMS, BLE_HCI_OCF_RD_RSSI,
- BLE_HCI_READ_RSSI_LEN, dst);
- dst += BLE_HCI_CMD_HDR_LEN;
-
- host_hci_cmd_body_read_rssi(handle, dst);
-}
-
-static int
-host_hci_cmd_body_set_data_len(uint16_t connection_handle, uint16_t tx_octets,
- uint16_t tx_time, uint8_t *dst)
-{
-
- if (tx_octets < BLE_HCI_SET_DATALEN_TX_OCTETS_MIN ||
- tx_octets > BLE_HCI_SET_DATALEN_TX_OCTETS_MAX) {
-
- return BLE_HS_EINVAL;
- }
-
- if (tx_time < BLE_HCI_SET_DATALEN_TX_TIME_MIN ||
- tx_time > BLE_HCI_SET_DATALEN_TX_TIME_MAX) {
-
- return BLE_HS_EINVAL;
- }
-
- htole16(dst + 0, connection_handle);
- htole16(dst + 2, tx_octets);
- htole16(dst + 4, tx_time);
-
- return 0;
-}
-
-/*
- * OGF=0x08 OCF=0x0022
- */
-int
-host_hci_cmd_build_set_data_len(uint16_t connection_handle,
- uint16_t tx_octets, uint16_t tx_time,
- uint8_t *dst, int dst_len)
-{
- int rc;
-
- BLE_HS_DBG_ASSERT(
- dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_DATALEN_LEN);
-
- host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_SET_DATA_LEN,
- BLE_HCI_SET_DATALEN_LEN, dst);
- dst += BLE_HCI_CMD_HDR_LEN;
-
- rc = host_hci_cmd_body_set_data_len(connection_handle, tx_octets, tx_time,
- dst);
- if (rc != 0) {
- return rc;
- }
-
- return 0;
-}
-
-/**
- * IRKs are in little endian.
- */
-static int
-host_hci_cmd_body_add_to_resolv_list(uint8_t addr_type, const uint8_t *addr,
- const uint8_t *peer_irk,
- const uint8_t *local_irk,
- uint8_t *dst)
-{
- if (addr_type > BLE_ADDR_TYPE_RANDOM) {
- return BLE_ERR_INV_HCI_CMD_PARMS;
- }
-
- dst[0] = addr_type;
- memcpy(dst + 1, addr, BLE_DEV_ADDR_LEN);
- memcpy(dst + 1 + 6, peer_irk , 16);
- memcpy(dst + 1 + 6 + 16, local_irk , 16);
- /* 16 + 16 + 6 + 1 == 39 */
- return 0;
-}
-
-/**
- * OGF=0x08 OCF=0x0027
- *
- * IRKs are in little endian.
- */
-int
-host_hci_cmd_build_add_to_resolv_list(
- const struct hci_add_dev_to_resolving_list *padd,
- uint8_t *dst,
- int dst_len)
-{
- int rc;
-
- BLE_HS_DBG_ASSERT(
- dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_ADD_TO_RESOLV_LIST_LEN);
-
- host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_ADD_RESOLV_LIST,
- BLE_HCI_ADD_TO_RESOLV_LIST_LEN, dst);
-
- rc = host_hci_cmd_body_add_to_resolv_list(
- padd->addr_type, padd->addr, padd->peer_irk, padd->local_irk,
- dst + BLE_HCI_CMD_HDR_LEN);
- if (rc != 0) {
- return rc;
- }
-
- return 0;
-}
-
-static int
-host_hci_cmd_body_remove_from_resolv_list(uint8_t addr_type,
- const uint8_t *addr,
- uint8_t *dst)
-{
- if (addr_type > BLE_ADDR_TYPE_RANDOM) {
- return BLE_ERR_INV_HCI_CMD_PARMS;
- }
-
- dst[0] = addr_type;
- memcpy(dst + 1, addr, BLE_DEV_ADDR_LEN);
- return 0;
-}
-
-
-int
-host_hci_cmd_build_remove_from_resolv_list(uint8_t addr_type,
- const uint8_t *addr,
- uint8_t *dst, int dst_len)
-{
- int rc;
-
- BLE_HS_DBG_ASSERT(
- dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_RMV_FROM_RESOLV_LIST_LEN);
-
- host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_RMV_RESOLV_LIST,
- BLE_HCI_RMV_FROM_RESOLV_LIST_LEN, dst);
-
- rc = host_hci_cmd_body_remove_from_resolv_list(addr_type, addr,
- dst + BLE_HCI_CMD_HDR_LEN);
- if (rc != 0) {
- return rc;
- }
- return 0;
-}
-
-int
-host_hci_cmd_build_clear_resolv_list(uint8_t *dst, int dst_len)
-{
- BLE_HS_DBG_ASSERT(dst_len >= BLE_HCI_CMD_HDR_LEN);
-
- host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_CLR_RESOLV_LIST,
- 0, dst);
-
- return 0;
-}
-
-int
-host_hci_cmd_build_read_resolv_list_size(uint8_t *dst, int dst_len)
-{
- BLE_HS_DBG_ASSERT(dst_len >= BLE_HCI_CMD_HDR_LEN);
-
- host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_RD_RESOLV_LIST_SIZE,
- 0, dst);
-
- return 0;
-}
-
-static int
-host_hci_cmd_body_read_peer_resolv_addr(uint8_t peer_identity_addr_type,
- const uint8_t *peer_identity_addr,
- uint8_t *dst)
-{
- if (peer_identity_addr_type > BLE_ADDR_TYPE_RANDOM) {
- return BLE_ERR_INV_HCI_CMD_PARMS;
- }
-
- dst[0] = peer_identity_addr_type;
- memcpy(dst + 1, peer_identity_addr, BLE_DEV_ADDR_LEN);
- return 0;
-}
-
-int
-host_hci_cmd_build_read_peer_resolv_addr(uint8_t peer_identity_addr_type,
- const uint8_t *peer_identity_addr,
- uint8_t *dst,
- int dst_len)
-{
- int rc;
-
- BLE_HS_DBG_ASSERT(
- dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_RD_PEER_RESOLV_ADDR_LEN);
-
- host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_RD_PEER_RESOLV_ADDR,
- BLE_HCI_RD_PEER_RESOLV_ADDR_LEN, dst);
-
- rc = host_hci_cmd_body_read_peer_resolv_addr(peer_identity_addr_type,
- peer_identity_addr,
- dst + BLE_HCI_CMD_HDR_LEN);
- if (rc != 0) {
- return rc;
- }
- return 0;
-}
-
-static int
-host_hci_cmd_body_read_lcl_resolv_addr(
- uint8_t local_identity_addr_type,
- const uint8_t *local_identity_addr,
- uint8_t *dst)
-{
- if (local_identity_addr_type > BLE_ADDR_TYPE_RANDOM) {
- return BLE_ERR_INV_HCI_CMD_PARMS;
- }
-
- dst[0] = local_identity_addr_type;
- memcpy(dst + 1, local_identity_addr, BLE_DEV_ADDR_LEN);
- return 0;
-}
-
-/*
- * OGF=0x08 OCF=0x002c
- */
-int
-host_hci_cmd_build_read_lcl_resolv_addr(uint8_t local_identity_addr_type,
- const uint8_t *local_identity_addr,
- uint8_t *dst,
- int dst_len)
-{
- int rc;
-
- BLE_HS_DBG_ASSERT(
- dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_RD_LOC_RESOLV_ADDR_LEN);
-
- host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_RD_LOCAL_RESOLV_ADDR,
- BLE_HCI_RD_LOC_RESOLV_ADDR_LEN, dst);
-
- rc = host_hci_cmd_body_read_lcl_resolv_addr(local_identity_addr_type,
- local_identity_addr,
- dst + BLE_HCI_CMD_HDR_LEN);
- if (rc != 0) {
- return rc;
- }
- return 0;
-}
-
-static int
-host_hci_cmd_body_set_addr_res_en(uint8_t enable, uint8_t *dst)
-{
- if (enable > 1) {
- return BLE_ERR_INV_HCI_CMD_PARMS;
- }
-
- dst[0] = enable;
- return 0;
-}
-
-/*
- * OGF=0x08 OCF=0x002d
- */
-int
-host_hci_cmd_build_set_addr_res_en(uint8_t enable, uint8_t *dst, int dst_len)
-{
- int rc;
-
- BLE_HS_DBG_ASSERT(
- dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_ADDR_RESOL_ENA_LEN);
-
- host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_SET_ADDR_RES_EN,
- BLE_HCI_SET_ADDR_RESOL_ENA_LEN, dst);
-
- rc = host_hci_cmd_body_set_addr_res_en(enable, dst + BLE_HCI_CMD_HDR_LEN);
- if (rc != 0) {
- return rc;
- }
- return 0;
-}
-
-static int
-host_hci_cmd_body_set_resolv_priv_addr_timeout(uint16_t timeout, uint8_t *dst)
-{
- if (timeout == 0 || timeout > 0xA1B8) {
- return BLE_ERR_INV_HCI_CMD_PARMS;
- }
-
- htole16(dst, timeout);
- return 0;
-}
-
-/*
- * OGF=0x08 OCF=0x002e
- */
-int
-host_hci_cmd_build_set_resolv_priv_addr_timeout(uint16_t timeout, uint8_t *dst,
- int dst_len)
-{
- int rc;
-
- BLE_HS_DBG_ASSERT(
- dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_RESOLV_PRIV_ADDR_TO_LEN);
-
- host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_SET_RPA_TMO,
- BLE_HCI_SET_RESOLV_PRIV_ADDR_TO_LEN, dst);
-
- rc = host_hci_cmd_body_set_resolv_priv_addr_timeout(
- timeout, dst + BLE_HCI_CMD_HDR_LEN);
- if (rc != 0) {
- return rc;
- }
- return 0;
-}
-
-static int
-host_hci_cmd_body_set_random_addr(const struct hci_rand_addr *paddr,
- uint8_t *dst)
-{
- memcpy(dst, paddr->addr, BLE_DEV_ADDR_LEN);
- return 0;
-}
-
-int
-host_hci_cmd_build_set_random_addr(const uint8_t *addr,
- uint8_t *dst, int dst_len)
-{
- struct hci_rand_addr r_addr;
- int rc;
-
- memcpy(r_addr.addr, addr, sizeof(r_addr.addr));
-
- BLE_HS_DBG_ASSERT(
- dst_len >= BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_RAND_ADDR_LEN);
-
- host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_SET_RAND_ADDR,
- BLE_HCI_SET_RAND_ADDR_LEN, dst);
-
- rc = host_hci_cmd_body_set_random_addr(&r_addr, dst + BLE_HCI_CMD_HDR_LEN);
- if (rc != 0) {
- return rc;
- }
-
- return 0;
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/net/nimble/host/src/test/ble_att_clt_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_att_clt_test.c b/net/nimble/host/src/test/ble_att_clt_test.c
index 9461337..ab89e9d 100644
--- a/net/nimble/host/src/test/ble_att_clt_test.c
+++ b/net/nimble/host/src/test/ble_att_clt_test.c
@@ -412,7 +412,8 @@ TEST_CASE(ble_att_clt_test_rx_read_mult)
htole16(buf + BLE_ATT_READ_MULT_RSP_BASE_SZ + 0, 12);
rc = ble_hs_test_util_l2cap_rx_payload_flat(
- conn_handle, BLE_L2CAP_CID_ATT, buf, BLE_ATT_READ_MULT_RSP_BASE_SZ + 2);
+ conn_handle, BLE_L2CAP_CID_ATT, buf,
+ BLE_ATT_READ_MULT_RSP_BASE_SZ + 2);
TEST_ASSERT(rc == 0);
/*** Larger response. */
@@ -420,12 +421,14 @@ TEST_CASE(ble_att_clt_test_rx_read_mult)
htole16(buf + BLE_ATT_READ_MULT_RSP_BASE_SZ + 2, 43);
htole16(buf + BLE_ATT_READ_MULT_RSP_BASE_SZ + 4, 91);
rc = ble_hs_test_util_l2cap_rx_payload_flat(
- conn_handle, BLE_L2CAP_CID_ATT, buf, BLE_ATT_READ_MULT_RSP_BASE_SZ + 6);
+ conn_handle, BLE_L2CAP_CID_ATT, buf,
+ BLE_ATT_READ_MULT_RSP_BASE_SZ + 6);
TEST_ASSERT(rc == 0);
/*** Zero-length response. */
rc = ble_hs_test_util_l2cap_rx_payload_flat(
- conn_handle, BLE_L2CAP_CID_ATT, buf, BLE_ATT_READ_MULT_RSP_BASE_SZ + 0);
+ conn_handle, BLE_L2CAP_CID_ATT, buf,
+ BLE_ATT_READ_MULT_RSP_BASE_SZ + 0);
TEST_ASSERT(rc == 0);
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/net/nimble/host/src/test/ble_gap_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gap_test.c b/net/nimble/host/src/test/ble_gap_test.c
index 2ae3354..170b8d9 100644
--- a/net/nimble/host/src/test/ble_gap_test.c
+++ b/net/nimble/host/src/test/ble_gap_test.c
@@ -372,11 +372,11 @@ ble_gap_test_util_rx_param_req(struct ble_gap_upd_params *params, int pos,
evt.timeout = params->supervision_timeout;
if (pos) {
- opcode = host_hci_opcode_join(BLE_HCI_OGF_LE,
- BLE_HCI_OCF_LE_REM_CONN_PARAM_RR);
+ opcode = ble_hs_hci_util_opcode_join(
+ BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_REM_CONN_PARAM_RR);
} else {
- opcode = host_hci_opcode_join(BLE_HCI_OGF_LE,
- BLE_HCI_OCF_LE_REM_CONN_PARAM_NRR);
+ opcode = ble_hs_hci_util_opcode_join(
+ BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_REM_CONN_PARAM_NRR);
}
if (*cmd_idx == cmd_fail_idx) {
hci_status = fail_status;
@@ -825,7 +825,8 @@ TEST_CASE(ble_gap_test_case_conn_dir_good)
TEST_ASSERT(ble_gap_test_conn_event_type == BLE_GAP_EVENT_CONNECT);
TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
- TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr, peer_addr, 6) == 0);
+ TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr,
+ peer_addr, 6) == 0);
TEST_ASSERT(ble_hs_atomic_conn_flags(2, NULL) == 0);
}
@@ -1059,7 +1060,8 @@ TEST_CASE(ble_gap_test_case_conn_terminate_good)
TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
TEST_ASSERT(ble_gap_test_conn_desc.peer_id_addr_type ==
BLE_ADDR_TYPE_PUBLIC);
- TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr, peer_addr, 6) == 0);
+ TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr,
+ peer_addr, 6) == 0);
TEST_ASSERT(ble_gap_test_conn_arg == NULL);
TEST_ASSERT(ble_hs_atomic_conn_flags(2, NULL) == BLE_HS_ENOTCONN);
@@ -1099,7 +1101,8 @@ TEST_CASE(ble_gap_test_case_conn_terminate_ctlr_fail)
TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
TEST_ASSERT(ble_gap_test_conn_desc.peer_id_addr_type ==
BLE_ADDR_TYPE_PUBLIC);
- TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr, peer_addr, 6) == 0);
+ TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr,
+ peer_addr, 6) == 0);
TEST_ASSERT(ble_gap_test_conn_arg == NULL);
TEST_ASSERT(ble_hs_atomic_conn_flags(2, NULL) == 0);
@@ -1494,7 +1497,8 @@ TEST_CASE(ble_gap_test_case_adv_good)
if (c != BLE_GAP_CONN_MODE_NON) {
TEST_ASSERT(!ble_gap_adv_active());
- TEST_ASSERT(ble_gap_test_conn_event_type == BLE_GAP_EVENT_CONNECT);
+ TEST_ASSERT(ble_gap_test_conn_event_type ==
+ BLE_GAP_EVENT_CONNECT);
TEST_ASSERT(ble_gap_test_conn_status == 0);
TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr,
@@ -1689,7 +1693,8 @@ ble_gap_test_util_update(struct ble_gap_upd_params *params,
TEST_ASSERT(ble_gap_test_conn_event_type == BLE_GAP_EVENT_CONN_UPDATE);
TEST_ASSERT(ble_gap_test_conn_status == 0);
TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
- TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr, peer_addr, 6) == 0);
+ TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr,
+ peer_addr, 6) == 0);
TEST_ASSERT(ble_gap_test_conn_desc.conn_itvl == params->itvl_max);
TEST_ASSERT(ble_gap_test_conn_desc.conn_latency == params->latency);
TEST_ASSERT(ble_gap_test_conn_desc.supervision_timeout ==
@@ -1703,7 +1708,8 @@ fail:
TEST_ASSERT(ble_gap_test_conn_event_type == BLE_GAP_EVENT_CONN_UPDATE);
TEST_ASSERT(ble_gap_test_conn_status == status);
TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
- TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr, peer_addr, 6) == 0);
+ TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr,
+ peer_addr, 6) == 0);
TEST_ASSERT(ble_gap_test_conn_desc.conn_itvl ==
BLE_GAP_INITIAL_CONN_ITVL_MAX);
TEST_ASSERT(ble_gap_test_conn_desc.conn_latency ==
@@ -1789,7 +1795,8 @@ ble_gap_test_util_update_req_pos(struct ble_gap_upd_params *peer_params,
TEST_ASSERT(ble_gap_test_conn_event_type == BLE_GAP_EVENT_CONN_UPDATE);
TEST_ASSERT(ble_gap_test_conn_status == 0);
TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
- TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr, peer_addr, 6) == 0);
+ TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr,
+ peer_addr, 6) == 0);
TEST_ASSERT(ble_gap_test_conn_desc.conn_itvl == self_params->itvl_max);
TEST_ASSERT(ble_gap_test_conn_desc.conn_latency == self_params->latency);
TEST_ASSERT(ble_gap_test_conn_desc.supervision_timeout ==
@@ -1801,7 +1808,8 @@ hci_fail:
TEST_ASSERT(ble_gap_test_conn_event_type == BLE_GAP_EVENT_CONN_UPDATE);
TEST_ASSERT(ble_gap_test_conn_status == BLE_HS_HCI_ERR(hci_status));
TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
- TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr, peer_addr, 6) == 0);
+ TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr,
+ peer_addr, 6) == 0);
TEST_ASSERT(ble_gap_test_conn_desc.conn_itvl ==
BLE_GAP_INITIAL_CONN_ITVL_MAX);
TEST_ASSERT(ble_gap_test_conn_desc.conn_latency ==
@@ -1850,7 +1858,8 @@ hci_fail:
TEST_ASSERT(ble_gap_test_conn_event_type == BLE_GAP_EVENT_CONN_UPDATE);
TEST_ASSERT(ble_gap_test_conn_status == BLE_HS_HCI_ERR(hci_status));
TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
- TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr, peer_addr, 6) == 0);
+ TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr,
+ peer_addr, 6) == 0);
TEST_ASSERT(ble_gap_test_conn_desc.conn_itvl ==
BLE_GAP_INITIAL_CONN_ITVL_MAX);
TEST_ASSERT(ble_gap_test_conn_desc.conn_latency ==
@@ -1925,7 +1934,8 @@ ble_gap_test_util_update_req_concurrent(
TEST_ASSERT(ble_gap_test_conn_event_type == BLE_GAP_EVENT_CONN_UPDATE);
TEST_ASSERT(ble_gap_test_conn_status == 0);
TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
- TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr, peer_addr, 6) == 0);
+ TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr,
+ peer_addr, 6) == 0);
TEST_ASSERT(ble_gap_test_conn_desc.conn_itvl == self_params->itvl_max);
TEST_ASSERT(ble_gap_test_conn_desc.conn_latency == self_params->latency);
TEST_ASSERT(ble_gap_test_conn_desc.supervision_timeout ==
@@ -1937,7 +1947,8 @@ hci_fail:
TEST_ASSERT(ble_gap_test_conn_event_type == BLE_GAP_EVENT_CONN_UPDATE);
TEST_ASSERT(ble_gap_test_conn_status == BLE_HS_HCI_ERR(fail_status));
TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
- TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr, peer_addr, 6) == 0);
+ TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr,
+ peer_addr, 6) == 0);
TEST_ASSERT(ble_gap_test_conn_desc.conn_itvl ==
BLE_GAP_INITIAL_CONN_ITVL_MAX);
TEST_ASSERT(ble_gap_test_conn_desc.conn_latency ==
@@ -2269,8 +2280,8 @@ ble_gap_test_util_conn_timeout(int32_t duration_ms)
os_time_advance(duration_ms);
ble_hs_test_util_set_ack(
- host_hci_opcode_join(BLE_HCI_OGF_LE,
- BLE_HCI_OCF_LE_CREATE_CONN_CANCEL),
+ ble_hs_hci_util_opcode_join(BLE_HCI_OGF_LE,
+ BLE_HCI_OCF_LE_CREATE_CONN_CANCEL),
0);
TEST_ASSERT(ble_gap_test_conn_event_type == -1);
@@ -2350,8 +2361,8 @@ ble_gap_test_util_disc_timeout(int32_t duration_ms)
os_time_advance(duration_ms);
ble_hs_test_util_set_ack(
- host_hci_opcode_join(BLE_HCI_OGF_LE,
- BLE_HCI_OCF_LE_SET_SCAN_ENABLE),
+ ble_hs_hci_util_opcode_join(BLE_HCI_OGF_LE,
+ BLE_HCI_OCF_LE_SET_SCAN_ENABLE),
0);
ticks_from_now = ble_gap_heartbeat();
TEST_ASSERT(ticks_from_now == BLE_HS_FOREVER);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/net/nimble/host/src/test/ble_gatt_read_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gatt_read_test.c b/net/nimble/host/src/test/ble_gatt_read_test.c
index 0c9f1cb..822de5c 100644
--- a/net/nimble/host/src/test/ble_gatt_read_test.c
+++ b/net/nimble/host/src/test/ble_gatt_read_test.c
@@ -495,21 +495,24 @@ ble_gatt_read_test_misc_mult_verify_bad(
TEST_CASE(ble_gatt_read_test_by_handle)
{
/* Read a seven-byte attribute. */
- ble_gatt_read_test_misc_verify_good((struct ble_hs_test_util_flat_attr[]) { {
+ ble_gatt_read_test_misc_verify_good(
+ (struct ble_hs_test_util_flat_attr[]) { {
.handle = 43,
.value = { 1,2,3,4,5,6,7 },
.value_len = 7
} });
/* Read a one-byte attribute. */
- ble_gatt_read_test_misc_verify_good((struct ble_hs_test_util_flat_attr[]) { {
+ ble_gatt_read_test_misc_verify_good(
+ (struct ble_hs_test_util_flat_attr[]) { {
.handle = 0x5432,
.value = { 0xff },
.value_len = 1
} });
/* Read a 200-byte attribute. */
- ble_gatt_read_test_misc_verify_good((struct ble_hs_test_util_flat_attr[]) { {
+ ble_gatt_read_test_misc_verify_good(
+ (struct ble_hs_test_util_flat_attr[]) { {
.handle = 815,
.value = { 0 },
.value_len = 200,
@@ -669,7 +672,8 @@ TEST_CASE(ble_gatt_read_test_mult)
}
/* Read one attribute. */
- ble_gatt_read_test_misc_mult_verify_good((struct ble_hs_test_util_flat_attr[]) { {
+ ble_gatt_read_test_misc_mult_verify_good(
+ (struct ble_hs_test_util_flat_attr[]) { {
.handle = 43,
.value = { 0, 1, 2, 3, 4, 5, 6, 7 },
.value_len = 7
@@ -678,7 +682,8 @@ TEST_CASE(ble_gatt_read_test_mult)
} });
/* Read two attributes. */
- ble_gatt_read_test_misc_mult_verify_good((struct ble_hs_test_util_flat_attr[]) { {
+ ble_gatt_read_test_misc_mult_verify_good(
+ (struct ble_hs_test_util_flat_attr[]) { {
.handle = 43,
.value = { 0, 1, 2, 3, 4, 5, 6, 7 },
.value_len = 7,
@@ -691,7 +696,8 @@ TEST_CASE(ble_gatt_read_test_mult)
} });
/* Read two attributes (swap order). */
- ble_gatt_read_test_misc_mult_verify_good((struct ble_hs_test_util_flat_attr[]) { {
+ ble_gatt_read_test_misc_mult_verify_good(
+ (struct ble_hs_test_util_flat_attr[]) { {
.handle = 44,
.value = { 8, 9, 10, 11 },
.value_len = 4,
@@ -704,7 +710,8 @@ TEST_CASE(ble_gatt_read_test_mult)
} });
/* Read five attributes. */
- ble_gatt_read_test_misc_mult_verify_good((struct ble_hs_test_util_flat_attr[]) { {
+ ble_gatt_read_test_misc_mult_verify_good(
+ (struct ble_hs_test_util_flat_attr[]) { {
.handle = 43,
.value = { 0, 1, 2, 3, 4, 5, 6, 7 },
.value_len = 7,
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/net/nimble/host/src/test/ble_host_hci_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_host_hci_test.c b/net/nimble/host/src/test/ble_host_hci_test.c
deleted file mode 100644
index 32c5cf4..0000000
--- a/net/nimble/host/src/test/ble_host_hci_test.c
+++ /dev/null
@@ -1,100 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-#include <stddef.h>
-#include <errno.h>
-#include <string.h>
-#include "nimble/hci_common.h"
-#include "nimble/ble_hci_trans.h"
-#include "host/host_hci.h"
-#include "host/ble_hs_test.h"
-#include "testutil/testutil.h"
-#include "ble_hs_test_util.h"
-
-TEST_CASE(ble_host_hci_test_event_bad)
-{
- uint8_t *buf;
- int rc;
-
- /*** Invalid event code. */
- buf = ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_HI);
- TEST_ASSERT_FATAL(buf != NULL);
-
- buf[0] = 0xff;
- buf[1] = 0;
- rc = host_hci_evt_process(buf);
- TEST_ASSERT(rc == BLE_HS_ENOTSUP);
-}
-
-TEST_CASE(ble_host_hci_test_rssi)
-{
- uint8_t params[BLE_HCI_READ_RSSI_ACK_PARAM_LEN];
- uint16_t opcode;
- int8_t rssi;
- int rc;
-
- opcode = host_hci_opcode_join(BLE_HCI_OGF_STATUS_PARAMS,
- BLE_HCI_OCF_RD_RSSI);
-
- /*** Success. */
- /* Connection handle. */
- htole16(params + 0, 1);
-
- /* RSSI. */
- params[2] = -8;
-
- ble_hs_test_util_set_ack_params(opcode, 0, params, sizeof params);
-
- rc = ble_hci_util_read_rssi(1, &rssi);
- TEST_ASSERT_FATAL(rc == 0);
- TEST_ASSERT(rssi == -8);
-
- /*** Failure: incorrect connection handle. */
- htole16(params + 0, 99);
-
- ble_hs_test_util_set_ack_params(opcode, 0, params, sizeof params);
-
- rc = ble_hci_util_read_rssi(1, &rssi);
- TEST_ASSERT(rc == BLE_HS_ECONTROLLER);
-
- /*** Failure: params too short. */
- ble_hs_test_util_set_ack_params(opcode, 0, params, sizeof params - 1);
- rc = ble_hci_util_read_rssi(1, &rssi);
- TEST_ASSERT(rc == BLE_HS_ECONTROLLER);
-
- /*** Failure: params too long. */
- ble_hs_test_util_set_ack_params(opcode, 0, params, sizeof params + 1);
- rc = ble_hci_util_read_rssi(1, &rssi);
- TEST_ASSERT(rc == BLE_HS_ECONTROLLER);
-}
-
-TEST_SUITE(ble_host_hci_suite)
-{
- tu_suite_set_post_test_cb(ble_hs_test_util_post_test, NULL);
-
- ble_host_hci_test_event_bad();
- ble_host_hci_test_rssi();
-}
-
-int
-ble_host_hci_test_all(void)
-{
- ble_host_hci_suite();
- return tu_any_failed;
-}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/net/nimble/host/src/test/ble_hs_adv_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_adv_test.c b/net/nimble/host/src/test/ble_hs_adv_test.c
index 89c61a2..e99fd5b 100644
--- a/net/nimble/host/src/test/ble_hs_adv_test.c
+++ b/net/nimble/host/src/test/ble_hs_adv_test.c
@@ -24,7 +24,6 @@
#include "nimble/hci_common.h"
#include "host/ble_hs_adv.h"
#include "host/ble_hs_test.h"
-#include "host/host_hci.h"
#include "ble_hs_test_util.h"
#define BLE_ADV_TEST_DATA_OFF 4
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/net/nimble/host/src/test/ble_hs_conn_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_conn_test.c b/net/nimble/host/src/test/ble_hs_conn_test.c
index 0e896f4..c957446 100644
--- a/net/nimble/host/src/test/ble_hs_conn_test.c
+++ b/net/nimble/host/src/test/ble_hs_conn_test.c
@@ -24,7 +24,6 @@
#include "nimble/hci_common.h"
#include "host/ble_hs_adv.h"
#include "host/ble_hs_test.h"
-#include "host/host_hci.h"
#include "ble_hs_test_util.h"
static int
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/net/nimble/host/src/test/ble_hs_hci_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_hci_test.c b/net/nimble/host/src/test/ble_hs_hci_test.c
new file mode 100644
index 0000000..21184b8
--- /dev/null
+++ b/net/nimble/host/src/test/ble_hs_hci_test.c
@@ -0,0 +1,99 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <stddef.h>
+#include <errno.h>
+#include <string.h>
+#include "nimble/hci_common.h"
+#include "nimble/ble_hci_trans.h"
+#include "host/ble_hs_test.h"
+#include "testutil/testutil.h"
+#include "ble_hs_test_util.h"
+
+TEST_CASE(ble_hs_hci_test_event_bad)
+{
+ uint8_t *buf;
+ int rc;
+
+ /*** Invalid event code. */
+ buf = ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_HI);
+ TEST_ASSERT_FATAL(buf != NULL);
+
+ buf[0] = 0xff;
+ buf[1] = 0;
+ rc = ble_hs_hci_evt_process(buf);
+ TEST_ASSERT(rc == BLE_HS_ENOTSUP);
+}
+
+TEST_CASE(ble_hs_hci_test_rssi)
+{
+ uint8_t params[BLE_HCI_READ_RSSI_ACK_PARAM_LEN];
+ uint16_t opcode;
+ int8_t rssi;
+ int rc;
+
+ opcode = ble_hs_hci_util_opcode_join(BLE_HCI_OGF_STATUS_PARAMS,
+ BLE_HCI_OCF_RD_RSSI);
+
+ /*** Success. */
+ /* Connection handle. */
+ htole16(params + 0, 1);
+
+ /* RSSI. */
+ params[2] = -8;
+
+ ble_hs_test_util_set_ack_params(opcode, 0, params, sizeof params);
+
+ rc = ble_hs_hci_util_read_rssi(1, &rssi);
+ TEST_ASSERT_FATAL(rc == 0);
+ TEST_ASSERT(rssi == -8);
+
+ /*** Failure: incorrect connection handle. */
+ htole16(params + 0, 99);
+
+ ble_hs_test_util_set_ack_params(opcode, 0, params, sizeof params);
+
+ rc = ble_hs_hci_util_read_rssi(1, &rssi);
+ TEST_ASSERT(rc == BLE_HS_ECONTROLLER);
+
+ /*** Failure: params too short. */
+ ble_hs_test_util_set_ack_params(opcode, 0, params, sizeof params - 1);
+ rc = ble_hs_hci_util_read_rssi(1, &rssi);
+ TEST_ASSERT(rc == BLE_HS_ECONTROLLER);
+
+ /*** Failure: params too long. */
+ ble_hs_test_util_set_ack_params(opcode, 0, params, sizeof params + 1);
+ rc = ble_hs_hci_util_read_rssi(1, &rssi);
+ TEST_ASSERT(rc == BLE_HS_ECONTROLLER);
+}
+
+TEST_SUITE(ble_hs_hci_suite)
+{
+ tu_suite_set_post_test_cb(ble_hs_test_util_post_test, NULL);
+
+ ble_hs_hci_test_event_bad();
+ ble_hs_hci_test_rssi();
+}
+
+int
+ble_hs_hci_test_all(void)
+{
+ ble_hs_hci_suite();
+ return tu_any_failed;
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/net/nimble/host/src/test/ble_hs_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_test.c b/net/nimble/host/src/test/ble_hs_test.c
index 0b89bc9..3bc468e 100644
--- a/net/nimble/host/src/test/ble_hs_test.c
+++ b/net/nimble/host/src/test/ble_hs_test.c
@@ -46,7 +46,7 @@ main(int argc, char **argv)
ble_gatts_notify_test_all();
ble_gatts_read_test_suite();
ble_gatts_reg_test_all();
- ble_host_hci_test_all();
+ ble_hs_hci_test_all();
ble_hs_adv_test_all();
ble_hs_conn_test_all();
ble_l2cap_test_all();
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/net/nimble/host/src/test/ble_hs_test_util.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_test_util.c b/net/nimble/host/src/test/ble_hs_test_util.c
index 831a077..cfb86fa 100644
--- a/net/nimble/host/src/test/ble_hs_test_util.c
+++ b/net/nimble/host/src/test/ble_hs_test_util.c
@@ -26,7 +26,6 @@
#include "nimble/ble_hci_trans.h"
#include "host/ble_hs_adv.h"
#include "host/ble_hs_id.h"
-#include "host/host_hci.h"
#include "transport/ram/ble_hci_ram.h"
#include "ble_hs_test_util.h"
@@ -47,7 +46,7 @@ static const uint8_t ble_hs_test_util_pub_addr[BLE_DEV_ADDR_LEN] =
OS_MEMPOOL_SIZE(BLE_HS_TEST_UTIL_NUM_MBUFS, BLE_HS_TEST_UTIL_MEMBLOCK_SIZE)
#define BLE_HS_TEST_UTIL_LE_OPCODE(ocf) \
- host_hci_opcode_join(BLE_HCI_OGF_LE, (ocf))
+ ble_hs_hci_util_opcode_join(BLE_HCI_OGF_LE, (ocf))
struct os_eventq ble_hs_test_util_evq;
@@ -106,7 +105,7 @@ ble_hs_test_util_prev_tx_dequeue_once(struct hci_data_hdr *out_hci_hdr)
om = OS_MBUF_PKTHDR_TO_MBUF(omp);
- rc = ble_hci_util_data_hdr_strip(om, out_hci_hdr);
+ rc = ble_hs_hci_util_data_hdr_strip(om, out_hci_hdr);
TEST_ASSERT_FATAL(rc == 0);
TEST_ASSERT_FATAL(out_hci_hdr->hdh_len == OS_MBUF_PKTLEN(om));
@@ -262,7 +261,7 @@ ble_hs_test_util_rx_hci_evt(uint8_t *evt)
memcpy(evbuf, evt, totlen);
rc = ble_hci_trans_ll_evt_tx(evbuf);
} else {
- rc = host_hci_evt_process(evt);
+ rc = ble_hs_hci_evt_process(evt);
}
TEST_ASSERT_FATAL(rc == 0);
@@ -352,7 +351,7 @@ ble_hs_test_util_set_ack_params(uint16_t opcode, uint8_t status, void *params,
}
ble_hs_test_util_num_phony_acks = 1;
- ble_hci_set_phony_ack_cb(ble_hs_test_util_phony_ack_cb);
+ ble_hs_hci_set_phony_ack_cb(ble_hs_test_util_phony_ack_cb);
}
void
@@ -371,7 +370,7 @@ ble_hs_test_util_set_ack_seq(struct ble_hs_test_util_phony_ack *acks)
}
ble_hs_test_util_num_phony_acks = i;
- ble_hci_set_phony_ack_cb(ble_hs_test_util_phony_ack_cb);
+ ble_hs_hci_set_phony_ack_cb(ble_hs_test_util_phony_ack_cb);
}
void
@@ -500,7 +499,8 @@ ble_hs_test_util_connect(uint8_t own_addr_type, uint8_t peer_addr_type,
ble_hs_test_util_prev_hci_tx_clear();
ble_hs_test_util_set_ack(
- host_hci_opcode_join(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_CREATE_CONN),
+ ble_hs_hci_util_opcode_join(BLE_HCI_OGF_LE,
+ BLE_HCI_OCF_LE_CREATE_CONN),
ack_status);
rc = ble_gap_connect(own_addr_type, peer_addr_type, peer_addr, duration_ms,
@@ -526,8 +526,8 @@ ble_hs_test_util_conn_cancel(uint8_t ack_status)
int rc;
ble_hs_test_util_set_ack(
- host_hci_opcode_join(BLE_HCI_OGF_LE,
- BLE_HCI_OCF_LE_CREATE_CONN_CANCEL),
+ ble_hs_hci_util_opcode_join(BLE_HCI_OGF_LE,
+ BLE_HCI_OCF_LE_CREATE_CONN_CANCEL),
ack_status);
rc = ble_gap_conn_cancel();
@@ -557,8 +557,8 @@ ble_hs_test_util_conn_terminate(uint16_t conn_handle, uint8_t hci_status)
int rc;
ble_hs_test_util_set_ack(
- host_hci_opcode_join(BLE_HCI_OGF_LINK_CTRL,
- BLE_HCI_OCF_DISCONNECT_CMD),
+ ble_hs_hci_util_opcode_join(BLE_HCI_OGF_LINK_CTRL,
+ BLE_HCI_OCF_DISCONNECT_CMD),
hci_status);
rc = ble_gap_terminate(conn_handle, BLE_ERR_REM_USER_CONN_TERM);
@@ -623,8 +623,8 @@ ble_hs_test_util_disc_cancel(uint8_t ack_status)
int rc;
ble_hs_test_util_set_ack(
- host_hci_opcode_join(BLE_HCI_OGF_LE,
- BLE_HCI_OCF_LE_SET_SCAN_ENABLE),
+ ble_hs_hci_util_opcode_join(BLE_HCI_OGF_LE,
+ BLE_HCI_OCF_LE_SET_SCAN_ENABLE),
ack_status);
rc = ble_gap_disc_cancel();
@@ -654,8 +654,9 @@ ble_hs_test_util_adv_set_fields(struct ble_hs_adv_fields *adv_fields,
if (auto_pwr) {
ble_hs_test_util_set_ack_params(
- host_hci_opcode_join(BLE_HCI_OGF_LE,
- BLE_HCI_OCF_LE_RD_ADV_CHAN_TXPWR), hci_status,
+ ble_hs_hci_util_opcode_join(BLE_HCI_OGF_LE,
+ BLE_HCI_OCF_LE_RD_ADV_CHAN_TXPWR),
+ hci_status,
((uint8_t[1]){0}), 1);
}
@@ -884,8 +885,8 @@ ble_hs_test_util_l2cap_rx_payload_flat(uint16_t conn_handle, uint16_t cid,
TEST_ASSERT_FATAL(rc == 0);
hci_hdr.hdh_handle_pb_bc =
- host_hci_handle_pb_bc_join(conn_handle,
- BLE_HCI_PB_FIRST_FLUSH, 0);
+ ble_hs_hci_util_handle_pb_bc_join(conn_handle,
+ BLE_HCI_PB_FIRST_FLUSH, 0);
hci_hdr.hdh_len = OS_MBUF_PKTHDR(om)->omp_len;
rc = ble_hs_test_util_l2cap_rx_first_frag(conn_handle, cid, &hci_hdr, om);
@@ -919,55 +920,55 @@ ble_hs_test_util_set_startup_acks(void)
*/
ble_hs_test_util_set_ack_seq(((struct ble_hs_test_util_phony_ack[]) {
{
- .opcode = host_hci_opcode_join(BLE_HCI_OGF_CTLR_BASEBAND,
- BLE_HCI_OCF_CB_RESET),
+ .opcode = ble_hs_hci_util_opcode_join(BLE_HCI_OGF_CTLR_BASEBAND,
+ BLE_HCI_OCF_CB_RESET),
},
{
- .opcode = host_hci_opcode_join(BLE_HCI_OGF_CTLR_BASEBAND,
- BLE_HCI_OCF_CB_SET_EVENT_MASK),
+ .opcode = ble_hs_hci_util_opcode_join(
+ BLE_HCI_OGF_CTLR_BASEBAND, BLE_HCI_OCF_CB_SET_EVENT_MASK),
},
{
- .opcode = host_hci_opcode_join(BLE_HCI_OGF_CTLR_BASEBAND,
- BLE_HCI_OCF_CB_SET_EVENT_MASK2),
+ .opcode = ble_hs_hci_util_opcode_join(
+ BLE_HCI_OGF_CTLR_BASEBAND, BLE_HCI_OCF_CB_SET_EVENT_MASK2),
},
{
- .opcode = host_hci_opcode_join(BLE_HCI_OGF_LE,
- BLE_HCI_OCF_LE_SET_EVENT_MASK),
+ .opcode = ble_hs_hci_util_opcode_join(
+ BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_SET_EVENT_MASK),
},
{
- .opcode = host_hci_opcode_join(BLE_HCI_OGF_LE,
- BLE_HCI_OCF_LE_RD_BUF_SIZE),
+ .opcode = ble_hs_hci_util_opcode_join(
+ BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_RD_BUF_SIZE),
/* Use a very low buffer size (16) to test fragmentation. */
.evt_params = { 0x10, 0x00, 0x20 },
.evt_params_len = 3,
},
{
- .opcode = host_hci_opcode_join(BLE_HCI_OGF_LE,
- BLE_HCI_OCF_LE_RD_LOC_SUPP_FEAT),
+ .opcode = ble_hs_hci_util_opcode_join(
+ BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_RD_LOC_SUPP_FEAT),
.evt_params = { 0 },
.evt_params_len = 8,
},
{
- .opcode = host_hci_opcode_join(BLE_HCI_OGF_INFO_PARAMS,
- BLE_HCI_OCF_IP_RD_BD_ADDR),
+ .opcode = ble_hs_hci_util_opcode_join(
+ BLE_HCI_OGF_INFO_PARAMS, BLE_HCI_OCF_IP_RD_BD_ADDR),
.evt_params = BLE_HS_TEST_UTIL_PUB_ADDR_VAL,
.evt_params_len = 6,
},
{
- .opcode = host_hci_opcode_join(BLE_HCI_OGF_LE,
- BLE_HCI_OCF_LE_SET_ADDR_RES_EN),
+ .opcode = ble_hs_hci_util_opcode_join(
+ BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_SET_ADDR_RES_EN),
},
{
- .opcode = host_hci_opcode_join(BLE_HCI_OGF_LE,
- BLE_HCI_OCF_LE_CLR_RESOLV_LIST),
+ .opcode = ble_hs_hci_util_opcode_join(
+ BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_CLR_RESOLV_LIST),
},
{
- .opcode = host_hci_opcode_join(BLE_HCI_OGF_LE,
- BLE_HCI_OCF_LE_SET_ADDR_RES_EN),
+ .opcode = ble_hs_hci_util_opcode_join(
+ BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_SET_ADDR_RES_EN),
},
{
- .opcode = host_hci_opcode_join(BLE_HCI_OGF_LE,
- BLE_HCI_OCF_LE_ADD_RESOLV_LIST),
+ .opcode = ble_hs_hci_util_opcode_join(
+ BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_ADD_RESOLV_LIST),
},
{ 0 }
}));
@@ -1375,10 +1376,10 @@ ble_hs_test_util_init(void)
rc = os_msys_register(&ble_hs_test_util_mbuf_pool);
TEST_ASSERT_FATAL(rc == 0);
- ble_hci_set_phony_ack_cb(NULL);
+ ble_hs_hci_set_phony_ack_cb(NULL);
ble_hci_trans_cfg_ll(ble_hs_test_util_hci_txed, NULL,
- ble_hs_test_util_pkt_txed, NULL);
+ ble_hs_test_util_pkt_txed, NULL);
hci_cfg = ble_hci_ram_cfg_dflt;
hci_cfg.num_evt_bufs = cfg.max_hci_bufs;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/net/nimble/host/src/test/ble_l2cap_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_l2cap_test.c b/net/nimble/host/src/test/ble_l2cap_test.c
index 118d04f..69db2f8 100644
--- a/net/nimble/host/src/test/ble_l2cap_test.c
+++ b/net/nimble/host/src/test/ble_l2cap_test.c
@@ -21,7 +21,6 @@
#include <errno.h>
#include "testutil/testutil.h"
#include "nimble/hci_common.h"
-#include "host/host_hci.h"
#include "host/ble_hs_test.h"
#include "ble_hs_test_util.h"
@@ -74,7 +73,8 @@ ble_l2cap_test_util_rx_update_req(uint16_t conn_handle, uint8_t id,
ble_l2cap_sig_update_req_write(v, BLE_L2CAP_SIG_UPDATE_REQ_SZ, &req);
ble_hs_test_util_set_ack(
- host_hci_opcode_join(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_CONN_UPDATE), 0);
+ ble_hs_hci_util_opcode_join(BLE_HCI_OGF_LE,
+ BLE_HCI_OCF_LE_CONN_UPDATE), 0);
rc = ble_hs_test_util_l2cap_rx_first_frag(conn_handle, BLE_L2CAP_CID_SIG,
&hci_hdr, om);
TEST_ASSERT_FATAL(rc == 0);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/net/nimble/host/src/test/ble_os_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_os_test.c b/net/nimble/host/src/test/ble_os_test.c
index e12e489..a9c28ea 100644
--- a/net/nimble/host/src/test/ble_os_test.c
+++ b/net/nimble/host/src/test/ble_os_test.c
@@ -225,7 +225,8 @@ ble_os_disc_test_task_handler(void *arg)
TEST_ASSERT(!cb_called);
ble_hs_test_util_set_ack(
- host_hci_opcode_join(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_SET_SCAN_ENABLE),
+ ble_hs_hci_util_opcode_join(BLE_HCI_OGF_LE,
+ BLE_HCI_OCF_LE_SET_SCAN_ENABLE),
0);
/* Wait 250 more ms; verify scan completed. */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/net/nimble/host/src/test/ble_sm_lgcy_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_sm_lgcy_test.c b/net/nimble/host/src/test/ble_sm_lgcy_test.c
index 9a61087..6e451ca 100644
--- a/net/nimble/host/src/test/ble_sm_lgcy_test.c
+++ b/net/nimble/host/src/test/ble_sm_lgcy_test.c
@@ -23,7 +23,6 @@
#include "testutil/testutil.h"
#include "nimble/hci_common.h"
#include "nimble/nimble_opt.h"
-#include "host/host_hci.h"
#include "host/ble_sm.h"
#include "host/ble_hs_test.h"
#include "ble_hs_test_util.h"
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/net/nimble/host/src/test/ble_sm_sc_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_sm_sc_test.c b/net/nimble/host/src/test/ble_sm_sc_test.c
index f69c60e..518720c 100644
--- a/net/nimble/host/src/test/ble_sm_sc_test.c
+++ b/net/nimble/host/src/test/ble_sm_sc_test.c
@@ -23,7 +23,6 @@
#include "testutil/testutil.h"
#include "nimble/hci_common.h"
#include "nimble/nimble_opt.h"
-#include "host/host_hci.h"
#include "host/ble_sm.h"
#include "host/ble_hs_test.h"
#include "ble_hs_test_util.h"
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/net/nimble/host/src/test/ble_sm_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_sm_test.c b/net/nimble/host/src/test/ble_sm_test.c
index 26efea9..f139ddb 100644
--- a/net/nimble/host/src/test/ble_sm_test.c
+++ b/net/nimble/host/src/test/ble_sm_test.c
@@ -23,7 +23,6 @@
#include "testutil/testutil.h"
#include "nimble/hci_common.h"
#include "nimble/nimble_opt.h"
-#include "host/host_hci.h"
#include "host/ble_sm.h"
#include "host/ble_hs_test.h"
#include "ble_hs_test_util.h"
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/net/nimble/host/src/test/ble_sm_test_util.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_sm_test_util.c b/net/nimble/host/src/test/ble_sm_test_util.c
index bdecde6..5cb1d40 100644
--- a/net/nimble/host/src/test/ble_sm_test_util.c
+++ b/net/nimble/host/src/test/ble_sm_test_util.c
@@ -23,7 +23,6 @@
#include "testutil/testutil.h"
#include "nimble/hci_common.h"
#include "nimble/nimble_opt.h"
-#include "host/host_hci.h"
#include "host/ble_sm.h"
#include "host/ble_hs_test.h"
#include "host/ble_hs_id.h"
@@ -916,8 +915,8 @@ ble_sm_test_util_set_lt_key_req_neg_reply_ack(uint8_t status,
htole16(params, conn_handle);
ble_hs_test_util_set_ack_params(
- host_hci_opcode_join(BLE_HCI_OGF_LE,
- BLE_HCI_OCF_LE_LT_KEY_REQ_NEG_REPLY),
+ ble_hs_hci_util_opcode_join(BLE_HCI_OGF_LE,
+ BLE_HCI_OCF_LE_LT_KEY_REQ_NEG_REPLY),
status, params, sizeof params);
}
@@ -928,7 +927,8 @@ ble_sm_test_util_set_lt_key_req_reply_ack(uint8_t status, uint16_t conn_handle)
htole16(params, conn_handle);
ble_hs_test_util_set_ack_params(
- host_hci_opcode_join(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_LT_KEY_REQ_REPLY),
+ ble_hs_hci_util_opcode_join(BLE_HCI_OGF_LE,
+ BLE_HCI_OCF_LE_LT_KEY_REQ_REPLY),
status, params, sizeof params);
}
@@ -1371,7 +1371,8 @@ ble_sm_test_util_us_bonding_good(int send_enc_req, uint8_t our_addr_type,
TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
ble_hs_test_util_set_ack(
- host_hci_opcode_join(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_START_ENCRYPT),
+ ble_hs_hci_util_opcode_join(BLE_HCI_OGF_LE,
+ BLE_HCI_OCF_LE_START_ENCRYPT),
0);
if (send_enc_req) {
@@ -1656,8 +1657,8 @@ ble_sm_test_util_rx_keys(struct ble_sm_test_params *params,
}
if (peer_key_dist & BLE_SM_PAIR_KEY_DIST_ID) {
ble_hs_test_util_set_ack(
- host_hci_opcode_join(BLE_HCI_OGF_LE,
- BLE_HCI_OCF_LE_ADD_RESOLV_LIST), 0);
+ ble_hs_hci_util_opcode_join(BLE_HCI_OGF_LE,
+ BLE_HCI_OCF_LE_ADD_RESOLV_LIST), 0);
ble_sm_test_util_rx_id_info(2, peer_id_info, 0);
ble_sm_test_util_rx_id_addr_info(2, peer_id_addr_info, 0);
}
@@ -1724,7 +1725,8 @@ ble_sm_test_util_us_lgcy_good_once(struct ble_sm_test_params *params)
TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
ble_hs_test_util_set_ack(
- host_hci_opcode_join(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_START_ENCRYPT), 0);
+ ble_hs_hci_util_opcode_join(BLE_HCI_OGF_LE,
+ BLE_HCI_OCF_LE_START_ENCRYPT), 0);
if (params->sec_req.authreq != 0) {
ble_sm_test_util_rx_sec_req(2, ¶ms->sec_req, 0);
} else {
@@ -1984,7 +1986,8 @@ ble_sm_test_util_us_sc_good_once(struct ble_sm_test_params *params)
TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
ble_hs_test_util_set_ack(
- host_hci_opcode_join(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_START_ENCRYPT), 0);
+ ble_hs_hci_util_opcode_join(BLE_HCI_OGF_LE,
+ BLE_HCI_OCF_LE_START_ENCRYPT), 0);
if (params->sec_req.authreq != 0) {
ble_sm_test_util_rx_sec_req(2, ¶ms->sec_req, 0);
} else {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/36254fc1/net/nimble/host/store/ram/src/ble_store_ram.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/store/ram/src/ble_store_ram.c b/net/nimble/host/store/ram/src/ble_store_ram.c
index d1e41b4..7528f03 100644
--- a/net/nimble/host/store/ram/src/ble_store_ram.c
+++ b/net/nimble/host/store/ram/src/ble_store_ram.c
@@ -136,7 +136,8 @@ ble_store_ram_read_our_sec(struct ble_store_key_sec *key_sec,
{
int idx;
- idx = ble_store_ram_find_sec(key_sec, ble_store_ram_our_secs, ble_store_ram_num_our_secs);
+ idx = ble_store_ram_find_sec(key_sec, ble_store_ram_our_secs,
+ ble_store_ram_num_our_secs);
if (idx == -1) {
return BLE_HS_ENOENT;
}
[25/42] incubator-mynewt-core git commit: BLE apps - Update for
latest HCI transport changes
Posted by st...@apache.org.
BLE apps - Update for latest HCI transport changes
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/d3f60aeb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/d3f60aeb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/d3f60aeb
Branch: refs/heads/sterly_refactor
Commit: d3f60aebf70e3c4fdd0a5c575b65ecf3543eae74
Parents: a7f8b7a
Author: Christopher Collins <cc...@apache.org>
Authored: Thu Aug 4 16:31:33 2016 -0700
Committer: Sterling Hughes <st...@apache.org>
Committed: Tue Aug 9 16:05:21 2016 -0700
----------------------------------------------------------------------
apps/bleprph/src/main.c | 7 ++++---
apps/bletest/src/main.c | 3 +++
apps/bletiny/src/main.c | 4 ++--
apps/bleuart/src/main.c | 17 ++++++++++++-----
4 files changed, 21 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d3f60aeb/apps/bleprph/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bleprph/src/main.c b/apps/bleprph/src/main.c
index cff4763..9d75a66 100755
--- a/apps/bleprph/src/main.c
+++ b/apps/bleprph/src/main.c
@@ -390,6 +390,10 @@ main(void)
rc = ble_ll_init(BLE_LL_TASK_PRI, MBUF_NUM_MBUFS, BLE_MBUF_PAYLOAD_SIZE);
assert(rc == 0);
+ /* Initialize the RAM HCI transport. */
+ rc = ble_hci_ram_init(&ble_hci_ram_cfg_dflt);
+ assert(rc == 0);
+
/* Initialize the NimBLE host configuration. */
cfg = ble_hs_cfg_dflt;
cfg.max_gattc_procs = 2;
@@ -419,9 +423,6 @@ main(void)
rc = ble_hs_init(&bleprph_evq, &cfg);
assert(rc == 0);
- rc = ble_hci_ram_init(&ble_hci_ram_cfg_dflt);
- assert(rc == 0);
-
nmgr_task_init(NEWTMGR_TASK_PRIO, newtmgr_stack, NEWTMGR_TASK_STACK_SIZE);
imgmgr_module_init();
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d3f60aeb/apps/bletest/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletest/src/main.c b/apps/bletest/src/main.c
index be0cf6d..c2635dd 100755
--- a/apps/bletest/src/main.c
+++ b/apps/bletest/src/main.c
@@ -44,6 +44,8 @@
#include "controller/ble_ll_conn.h"
#include "controller/ble_ll_scan.h"
#include "controller/ble_ll_adv.h"
+
+/* RAM HCI transport. */
#include "transport/ram/ble_hci_ram.h"
/* XXX: An app should not include private headers from a library. The bletest
@@ -1154,6 +1156,7 @@ main(void)
rc = ble_hs_init(&g_bletest_evq, NULL);
assert(rc == 0);
+ /* Initialize the RAM HCI transport. */
rc = ble_hci_ram_init(&ble_hci_ram_cfg_dflt);
assert(rc == 0);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d3f60aeb/apps/bletiny/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/main.c b/apps/bletiny/src/main.c
index 38ee467..dbb340b 100755
--- a/apps/bletiny/src/main.c
+++ b/apps/bletiny/src/main.c
@@ -45,6 +45,8 @@
#include "host/ble_gatt.h"
#include "host/ble_store.h"
#include "host/ble_sm.h"
+
+/* RAM HCI transport. */
#include "transport/ram/ble_hci_ram.h"
/* RAM persistence layer. */
@@ -1697,13 +1699,11 @@ main(void)
/* Initialize the RAM HCI transport. */
hci_cfg = ble_hci_ram_cfg_dflt;
- hci_cfg.num_evt_bufs = 3;
rc = ble_hci_ram_init(&hci_cfg);
assert(rc == 0);
/* Initialize the NimBLE host configuration. */
cfg = ble_hs_cfg_dflt;
- cfg.max_hci_bufs = hci_cfg.num_evt_bufs;
cfg.max_gattc_procs = 2;
cfg.reset_cb = bletiny_on_reset;
cfg.store_read_cb = ble_store_ram_read;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d3f60aeb/apps/bleuart/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bleuart/src/main.c b/apps/bleuart/src/main.c
index f7c7714..a530195 100755
--- a/apps/bleuart/src/main.c
+++ b/apps/bleuart/src/main.c
@@ -39,10 +39,9 @@
#include "host/ble_l2cap.h"
#include "host/ble_sm.h"
#include "controller/ble_ll.h"
-/* Newtmgr include */
-#include "newtmgr/newtmgr.h"
-#include "nmgrble/newtmgr_ble.h"
-#include "bleuart/bleuart.h"
+
+/* RAM HCI transport. */
+#include "transport/ram/ble_hci_ram.h"
/* RAM persistence layer. */
#include "store/ram/ble_store_ram.h"
@@ -51,6 +50,11 @@
#include "services/mandatory/ble_svc_gap.h"
#include "services/mandatory/ble_svc_gatt.h"
+/* Newtmgr include */
+#include "newtmgr/newtmgr.h"
+#include "nmgrble/newtmgr_ble.h"
+#include "bleuart/bleuart.h"
+
/** Mbuf settings. */
#define MBUF_NUM_MBUFS (12)
#define MBUF_BUF_SIZE OS_ALIGN(BLE_MBUF_PAYLOAD_SIZE, 4)
@@ -292,9 +296,12 @@ main(void)
rc = ble_ll_init(BLE_LL_TASK_PRI, MBUF_NUM_MBUFS, BLE_MBUF_PAYLOAD_SIZE);
assert(rc == 0);
+ /* Initialize the RAM HCI transport. */
+ rc = ble_hci_ram_init(&ble_hci_ram_cfg_dflt);
+ assert(rc == 0);
+
/* Initialize the BLE host. */
cfg = ble_hs_cfg_dflt;
- cfg.max_hci_bufs = 3;
cfg.max_connections = 1;
cfg.max_gattc_procs = 2;
cfg.max_l2cap_chans = 3;
[09/42] incubator-mynewt-core git commit: BLE Host - Read BD_ADDR on
startup.
Posted by st...@apache.org.
BLE Host - Read BD_ADDR on startup.
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/aff82c39
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/aff82c39
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/aff82c39
Branch: refs/heads/sterly_refactor
Commit: aff82c39b896b46a4041669126bcb6e42f117be0
Parents: 3ea4881
Author: Christopher Collins <cc...@apache.org>
Authored: Mon Aug 1 13:32:25 2016 -0700
Committer: Sterling Hughes <st...@apache.org>
Committed: Tue Aug 9 16:05:21 2016 -0700
----------------------------------------------------------------------
net/nimble/host/include/host/host_hci.h | 1 +
net/nimble/host/src/ble_hs_startup.c | 30 +++++++++++++++++++++++++---
net/nimble/host/src/host_hci_cmd.c | 14 +++++++++++++
net/nimble/include/nimble/hci_common.h | 3 +++
4 files changed, 45 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/aff82c39/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 f92c1a9..dbe626a 100644
--- a/net/nimble/host/include/host/host_hci.h
+++ b/net/nimble/host/include/host/host_hci.h
@@ -36,6 +36,7 @@ void host_hci_write_hdr(uint8_t ogf, uint8_t ocf, uint8_t len, void *buf);
int host_hci_cmd_send(uint8_t ogf, uint8_t ocf, uint8_t len,
const void *cmddata);
int host_hci_cmd_send_buf(void *cmddata);
+void host_hci_cmd_build_read_bd_addr(uint8_t *dst, int dst_len);
void host_hci_cmd_build_set_event_mask(uint64_t event_mask,
uint8_t *dst, int dst_len);
void host_hci_cmd_build_set_event_mask2(uint64_t event_mask, uint8_t *dst,
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/aff82c39/net/nimble/host/src/ble_hs_startup.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_startup.c b/net/nimble/host/src/ble_hs_startup.c
index 568f1ed..45fb5ce 100644
--- a/net/nimble/host/src/ble_hs_startup.c
+++ b/net/nimble/host/src/ble_hs_startup.c
@@ -78,6 +78,28 @@ ble_hs_startup_le_read_buf_sz_tx(void)
}
static int
+ble_hs_startup_read_bd_addr(void)
+{
+ uint8_t ack_params[BLE_HCI_IP_RD_BD_ADDR_ACK_PARAM_LEN];
+ uint8_t buf[BLE_HCI_CMD_HDR_LEN];
+ uint8_t ack_params_len;
+ int rc;
+
+ host_hci_cmd_build_read_bd_addr(buf, sizeof buf);
+ rc = ble_hci_cmd_tx(buf, ack_params, sizeof ack_params, &ack_params_len);
+ if (rc != 0) {
+ return rc;
+ }
+
+ if (ack_params_len != sizeof ack_params) {
+ return BLE_HS_ECONTROLLER;
+ }
+
+ ble_hs_id_set_pub(ack_params);
+ return 0;
+}
+
+static int
ble_hs_startup_le_set_evmask_tx(void)
{
uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_LE_EVENT_MASK_LEN];
@@ -224,10 +246,12 @@ ble_hs_startup_go(void)
return rc;
}
- /* XXX: Read BD_ADDR. */
+ rc = ble_hs_startup_read_bd_addr();
+ if (rc != 0) {
+ return rc;
+ }
- ble_hs_id_set_pub(g_dev_addr);
ble_hs_pvcy_set_our_irk(NULL);
- return rc;
+ return 0;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/aff82c39/net/nimble/host/src/host_hci_cmd.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/host_hci_cmd.c b/net/nimble/host/src/host_hci_cmd.c
index 9dbb036..a3e021d 100644
--- a/net/nimble/host/src/host_hci_cmd.c
+++ b/net/nimble/host/src/host_hci_cmd.c
@@ -138,6 +138,20 @@ host_hci_le_cmd_send(uint16_t ocf, uint8_t len, void *cmddata)
return rc;
}
+/**
+ * Read BD_ADDR
+ *
+ * OGF = 0x04 (Informational parameters)
+ * OCF = 0x0009
+ */
+void
+host_hci_cmd_build_read_bd_addr(uint8_t *dst, int dst_len)
+{
+ BLE_HS_DBG_ASSERT(dst_len >= BLE_HCI_CMD_HDR_LEN);
+ host_hci_write_hdr(BLE_HCI_OGF_INFO_PARAMS, BLE_HCI_OCF_IP_RD_BD_ADDR,
+ 0, dst);
+}
+
static int
host_hci_cmd_body_le_whitelist_chg(const uint8_t *addr, uint8_t addr_type,
uint8_t *dst)
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/aff82c39/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 d5c8743..3b44b0e 100644
--- a/net/nimble/include/nimble/hci_common.h
+++ b/net/nimble/include/nimble/hci_common.h
@@ -131,6 +131,9 @@
/* --- Set event mask (OGF 0x03, OCF 0x0001 --- */
#define BLE_HCI_SET_EVENT_MASK_LEN (8)
+/* --- Read BD_ADDR (OGF 0x04, OCF 0x0009 --- */
+#define BLE_HCI_IP_RD_BD_ADDR_ACK_PARAM_LEN (6)
+
/* --- Read/Write authenticated payload timeout (ocf 0x007B/0x007C) */
#define BLE_HCI_RD_AUTH_PYLD_TMO_LEN (4)
#define BLE_HCI_WR_AUTH_PYLD_TMO_LEN (2)
[13/42] incubator-mynewt-core git commit: BLE Host - Reset on
hardware error.
Posted by st...@apache.org.
BLE Host - Reset on hardware error.
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/c78db970
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/c78db970
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/c78db970
Branch: refs/heads/sterly_refactor
Commit: c78db9702cd9b092756cabbeab6694e4f9608315
Parents: 0fd02e1
Author: Christopher Collins <cc...@apache.org>
Authored: Wed Aug 3 13:30:54 2016 -0700
Committer: Sterling Hughes <st...@apache.org>
Committed: Tue Aug 9 16:05:21 2016 -0700
----------------------------------------------------------------------
net/nimble/host/include/host/ble_hs.h | 4 ++++
net/nimble/host/src/ble_hs.c | 6 ++++++
net/nimble/host/src/ble_hs_priv.h | 1 +
net/nimble/host/src/host_hci.c | 17 +++++++++++++++++
net/nimble/include/nimble/hci_common.h | 3 +++
5 files changed, 31 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c78db970/net/nimble/host/include/host/ble_hs.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_hs.h b/net/nimble/host/include/host/ble_hs.h
index faeaf14..4a707af 100644
--- a/net/nimble/host/include/host/ble_hs.h
+++ b/net/nimble/host/include/host/ble_hs.h
@@ -80,6 +80,10 @@ struct os_event;
#define BLE_HS_ERR_SM_PEER_BASE 0x500 /* 1280 */
#define BLE_HS_SM_PEER_ERR(x) ((x) ? BLE_HS_ERR_SM_PEER_BASE + (x) : 0)
+/* Note: A hardware error of 0 is not success. */
+#define BLE_HS_ERR_HW_BASE 0x600 /* 1536 */
+#define BLE_HS_HW_ERR(x) (BLE_HS_ERR_HW_BASE + (x))
+
/* Defines the IO capabilities for the local device. */
#define BLE_HS_IO_DISPLAY_ONLY 0x00
#define BLE_HS_IO_DISPLAY_YESNO 0x01
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c78db970/net/nimble/host/src/ble_hs.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs.c b/net/nimble/host/src/ble_hs.c
index 6e8a59f..95befc0 100644
--- a/net/nimble/host/src/ble_hs.c
+++ b/net/nimble/host/src/ble_hs.c
@@ -443,6 +443,12 @@ ble_hs_sched_reset(int reason)
ble_hs_event_enqueue(&ble_hs_event_reset);
}
+void
+ble_hs_hw_error(uint8_t hw_code)
+{
+ ble_hs_sched_reset(BLE_HS_HW_ERR(hw_code));
+}
+
/**
* Synchronizes the host with the controller by sending a sequence of HCI
* commands. This function must be called before any other host functionality
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c78db970/net/nimble/host/src/ble_hs_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_priv.h b/net/nimble/host/src/ble_hs_priv.h
index 9e788dd..d8b5e82 100644
--- a/net/nimble/host/src/ble_hs_priv.h
+++ b/net/nimble/host/src/ble_hs_priv.h
@@ -102,6 +102,7 @@ int ble_hs_is_parent_task(void);
void ble_hs_lock(void);
void ble_hs_unlock(void);
void ble_hs_sched_reset(int reason);
+void ble_hs_hw_error(uint8_t hw_code);
void ble_hs_heartbeat_sched(int32_t ticks);
void ble_hs_notifications_sched(void);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c78db970/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 ed5dd6a..b9bdaf9 100644
--- a/net/nimble/host/src/host_hci.c
+++ b/net/nimble/host/src/host_hci.c
@@ -35,6 +35,7 @@ _Static_assert(sizeof (struct hci_data_hdr) == BLE_HCI_DATA_HDR_SZ,
typedef int host_hci_event_fn(uint8_t event_code, uint8_t *data, int len);
static host_hci_event_fn host_hci_rx_disconn_complete;
static host_hci_event_fn host_hci_rx_encrypt_change;
+static host_hci_event_fn host_hci_rx_hw_error;
static host_hci_event_fn host_hci_rx_num_completed_pkts;
static host_hci_event_fn host_hci_rx_enc_key_refresh;
static host_hci_event_fn host_hci_rx_le_meta;
@@ -70,6 +71,7 @@ struct host_hci_event_dispatch_entry {
static const struct host_hci_event_dispatch_entry host_hci_event_dispatch[] = {
{ BLE_HCI_EVCODE_DISCONN_CMP, host_hci_rx_disconn_complete },
{ BLE_HCI_EVCODE_ENCRYPT_CHG, host_hci_rx_encrypt_change },
+ { BLE_HCI_EVCODE_HW_ERROR, host_hci_rx_hw_error },
{ BLE_HCI_EVCODE_NUM_COMP_PKTS, host_hci_rx_num_completed_pkts },
{ BLE_HCI_EVCODE_ENC_KEY_REFRESH, host_hci_rx_enc_key_refresh },
{ BLE_HCI_EVCODE_LE_META, host_hci_rx_le_meta },
@@ -185,6 +187,21 @@ host_hci_rx_encrypt_change(uint8_t event_code, uint8_t *data, int len)
}
static int
+host_hci_rx_hw_error(uint8_t event_code, uint8_t *data, int len)
+{
+ uint8_t hw_code;
+
+ if (len < BLE_HCI_EVENT_HW_ERROR_LEN) {
+ return BLE_HS_ECONTROLLER;
+ }
+
+ hw_code = data[0];
+ ble_hs_hw_error(hw_code);
+
+ return 0;
+}
+
+static int
host_hci_rx_enc_key_refresh(uint8_t event_code, uint8_t *data, int len)
{
struct hci_encrypt_key_refresh evt;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c78db970/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 3b44b0e..f094cc7 100644
--- a/net/nimble/include/nimble/hci_common.h
+++ b/net/nimble/include/nimble/hci_common.h
@@ -480,6 +480,9 @@
/* Event encryption change (code=0x08) */
#define BLE_HCI_EVENT_ENCRYPT_CHG_LEN (4)
+/* Event hardware error (code=0x10) */
+#define BLE_HCI_EVENT_HW_ERROR_LEN (1)
+
/* Event key refresh complete (code=0x30) */
#define BLE_HCI_EVENT_ENC_KEY_REFRESH_LEN (3)
[40/42] incubator-mynewt-core git commit: ble - Transports return
BLE_ERR_ return codes.
Posted by st...@apache.org.
ble - Transports return BLE_ERR_ return codes.
Prior to this change, the HCI transports return code behavior was
inconsistent. Sometimes BLE_ERR codes were returned; other times plain
errno values were returned.
Now only BLE_ERR error codes are returned.
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/25219945
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/25219945
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/25219945
Branch: refs/heads/sterly_refactor
Commit: 2521994509555c194f1e4886f1f707f8eb59620c
Parents: 2e68697
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Aug 9 10:33:36 2016 -0700
Committer: Sterling Hughes <st...@apache.org>
Committed: Tue Aug 9 16:05:21 2016 -0700
----------------------------------------------------------------------
net/nimble/include/nimble/ble.h | 2 ++
net/nimble/src/ble_util.c | 43 +++++++++++++++++++++++
net/nimble/transport/ram/src/ble_hci_ram.c | 42 ++++++++--------------
net/nimble/transport/uart/src/ble_hci_uart.c | 40 +++++++--------------
4 files changed, 73 insertions(+), 54 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/25219945/net/nimble/include/nimble/ble.h
----------------------------------------------------------------------
diff --git a/net/nimble/include/nimble/ble.h b/net/nimble/include/nimble/ble.h
index 4deb9f3..6c4c90e 100644
--- a/net/nimble/include/nimble/ble.h
+++ b/net/nimble/include/nimble/ble.h
@@ -227,4 +227,6 @@ enum ble_error_codes
#define BLE_ADDR_TYPE_RPA_PUB_DEFAULT (2)
#define BLE_ADDR_TYPE_RPA_RND_DEFAULT (3)
+int ble_err_from_os(int os_err);
+
#endif /* H_BLE_ */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/25219945/net/nimble/src/ble_util.c
----------------------------------------------------------------------
diff --git a/net/nimble/src/ble_util.c b/net/nimble/src/ble_util.c
new file mode 100644
index 0000000..bfe7083
--- /dev/null
+++ b/net/nimble/src/ble_util.c
@@ -0,0 +1,43 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "os/os.h"
+#include "nimble/ble.h"
+
+/**
+ * Converts an OS error code to its equivalent BLE_ERR code.
+ *
+ * @param os_err The OS error code to convert.
+ *
+ * @return The equivalent BLE_ERR code.
+ */
+int
+ble_err_from_os(int os_err)
+{
+ switch (os_err) {
+ case 0:
+ return 0;
+
+ case OS_ENOMEM:
+ return BLE_ERR_MEM_CAPACITY;
+
+ default:
+ return BLE_ERR_UNSPECIFIED;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/25219945/net/nimble/transport/ram/src/ble_hci_ram.c
----------------------------------------------------------------------
diff --git a/net/nimble/transport/ram/src/ble_hci_ram.c b/net/nimble/transport/ram/src/ble_hci_ram.c
index 23a375d..2ce5fd6 100644
--- a/net/nimble/transport/ram/src/ble_hci_ram.c
+++ b/net/nimble/transport/ram/src/ble_hci_ram.c
@@ -2,6 +2,8 @@
#include <errno.h>
#include <stddef.h>
#include "os/os.h"
+#include "util/mem.h"
+#include "nimble/ble.h"
#include "nimble/ble_hci_trans.h"
#include "transport/ram/ble_hci_ram.h"
@@ -191,43 +193,29 @@ ble_hci_ram_init(const struct ble_hci_ram_cfg *cfg)
ble_hci_ram_free_mem();
- if (cfg->num_evt_hi_bufs > 0) {
- ble_hci_ram_evt_hi_buf = malloc(OS_MEMPOOL_BYTES(cfg->num_evt_hi_bufs,
- cfg->evt_buf_sz));
- if (ble_hci_ram_evt_hi_buf == NULL) {
- rc = ENOMEM;
- goto err;
- }
- }
-
- rc = os_mempool_init(&ble_hci_ram_evt_hi_pool, cfg->num_evt_hi_bufs,
- cfg->evt_buf_sz, ble_hci_ram_evt_hi_buf,
- "ble_hci_ram_evt_hi_pool");
+ rc = mem_malloc_mempool(&ble_hci_ram_evt_hi_pool,
+ cfg->num_evt_hi_bufs,
+ cfg->evt_buf_sz,
+ "ble_hci_ram_evt_hi_pool",
+ &ble_hci_ram_evt_hi_buf);
if (rc != 0) {
- rc = EINVAL;
+ rc = ble_err_from_os(rc);
goto err;
}
- if (cfg->num_evt_lo_bufs > 0) {
- ble_hci_ram_evt_lo_buf = malloc(OS_MEMPOOL_BYTES(cfg->num_evt_lo_bufs,
- cfg->evt_buf_sz));
- if (ble_hci_ram_evt_lo_buf == NULL) {
- rc = ENOMEM;
- goto err;
- }
- }
-
- rc = os_mempool_init(&ble_hci_ram_evt_lo_pool, cfg->num_evt_lo_bufs,
- cfg->evt_buf_sz, ble_hci_ram_evt_lo_buf,
- "ble_hci_ram_evt_lo_pool");
+ rc = mem_malloc_mempool(&ble_hci_ram_evt_lo_pool,
+ cfg->num_evt_lo_bufs,
+ cfg->evt_buf_sz,
+ "ble_hci_ram_evt_lo_pool",
+ &ble_hci_ram_evt_lo_buf);
if (rc != 0) {
- rc = EINVAL;
+ rc = ble_err_from_os(rc);
goto err;
}
ble_hci_ram_hs_cmd_buf = malloc(BLE_HCI_TRANS_CMD_SZ);
if (ble_hci_ram_hs_cmd_buf == NULL) {
- rc = ENOMEM;
+ rc = BLE_ERR_MEM_CAPACITY;
goto err;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/25219945/net/nimble/transport/uart/src/ble_hci_uart.c
----------------------------------------------------------------------
diff --git a/net/nimble/transport/uart/src/ble_hci_uart.c b/net/nimble/transport/uart/src/ble_hci_uart.c
index 1285f56..0fa982a 100755
--- a/net/nimble/transport/uart/src/ble_hci_uart.c
+++ b/net/nimble/transport/uart/src/ble_hci_uart.c
@@ -23,7 +23,7 @@
#include <errno.h>
#include "bsp/bsp.h"
#include "os/os.h"
-#include "bsp/bsp.h"
+#include "util/mem.h"
#include "hal/hal_gpio.h"
#include "hal/hal_cputime.h"
#include "hal/hal_uart.h"
@@ -705,39 +705,25 @@ ble_hci_uart_init(const struct ble_hci_uart_cfg *cfg)
ble_hci_uart_cfg = *cfg;
- ble_hci_uart_evt_buf = malloc(
- OS_MEMPOOL_BYTES(ble_hci_uart_cfg.num_evt_bufs,
- ble_hci_uart_cfg.evt_buf_sz));
- if (ble_hci_uart_evt_buf == NULL) {
- rc = BLE_ERR_MEM_CAPACITY;
- goto err;
- }
-
/* Create memory pool of HCI command / event buffers */
- rc = os_mempool_init(&ble_hci_uart_evt_pool, ble_hci_uart_cfg.num_evt_bufs,
- ble_hci_uart_cfg.evt_buf_sz, ble_hci_uart_evt_buf,
- "ble_hci_uart_evt_pool");
+ rc = mem_malloc_mempool(&ble_hci_uart_evt_pool,
+ cfg->num_evt_bufs,
+ cfg->evt_buf_sz,
+ "ble_hci_uart_evt_pool",
+ &ble_hci_uart_evt_buf);
if (rc != 0) {
- rc = BLE_ERR_UNSPECIFIED;
- goto err;
- }
-
- ble_hci_uart_pkt_buf = malloc(
- OS_MEMPOOL_BYTES(ble_hci_uart_cfg.num_evt_bufs,
- sizeof (struct os_event)));
- if (ble_hci_uart_pkt_buf == NULL) {
- rc = BLE_ERR_MEM_CAPACITY;
+ rc = ble_err_from_os(rc);
goto err;
}
/* Create memory pool of packet list nodes. */
- rc = os_mempool_init(&ble_hci_uart_pkt_pool,
- ble_hci_uart_cfg.num_evt_bufs,
- sizeof (struct ble_hci_uart_pkt),
- ble_hci_uart_pkt_buf,
- "ble_hci_uart_pkt_pool");
+ rc = mem_malloc_mempool(&ble_hci_uart_pkt_pool,
+ cfg->num_evt_bufs,
+ sizeof (struct ble_hci_uart_pkt),
+ "ble_hci_uart_pkt_pool",
+ &ble_hci_uart_pkt_buf);
if (rc != 0) {
- rc = BLE_ERR_UNSPECIFIED;
+ rc = ble_err_from_os(rc);
goto err;
}
[37/42] incubator-mynewt-core git commit: BLE Host - gap test needs
to hb when checking tmo.
Posted by st...@apache.org.
BLE Host - gap test needs to hb when checking tmo.
When ensuring that the passage of time causes no effects, the test node
needs to call ble_hs_heartbeat() to let the host know that time has
passed. This is only necessary because the OS is not running during
this test.
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/f1020d3e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/f1020d3e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/f1020d3e
Branch: refs/heads/sterly_refactor
Commit: f1020d3e60b743d1784a5225ae9b57a07e5cebf0
Parents: d6fab4d
Author: Christopher Collins <cc...@apache.org>
Authored: Sun Aug 7 17:58:16 2016 -0700
Committer: Sterling Hughes <st...@apache.org>
Committed: Tue Aug 9 16:05:21 2016 -0700
----------------------------------------------------------------------
net/nimble/host/src/test/ble_gap_test.c | 1 +
1 file changed, 1 insertion(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f1020d3e/net/nimble/host/src/test/ble_gap_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gap_test.c b/net/nimble/host/src/test/ble_gap_test.c
index 2d4c551..1943d01 100644
--- a/net/nimble/host/src/test/ble_gap_test.c
+++ b/net/nimble/host/src/test/ble_gap_test.c
@@ -2324,6 +2324,7 @@ ble_gap_test_util_conn_forever(void)
/* Advance 100 seconds; ensure no timeout reported. */
os_time_advance(100 * OS_TICKS_PER_SEC);
+ ble_gap_heartbeat();
TEST_ASSERT(ble_gap_test_conn_event_type == -1);
TEST_ASSERT(ble_gap_conn_active());
}
[19/42] incubator-mynewt-core git commit: Update sample BLE apps to
use transports.
Posted by st...@apache.org.
Update sample BLE apps to use transports.
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/043e0e51
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/043e0e51
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/043e0e51
Branch: refs/heads/sterly_refactor
Commit: 043e0e5166b46036d66ce444f4c724cf713fe39c
Parents: 36254fc
Author: Christopher Collins <cc...@apache.org>
Authored: Wed Aug 3 19:43:50 2016 -0700
Committer: Sterling Hughes <st...@apache.org>
Committed: Tue Aug 9 16:05:21 2016 -0700
----------------------------------------------------------------------
apps/blecent/pkg.yml | 1 +
apps/blecent/src/main.c | 25 ++-
apps/blehci/pkg.yml | 5 +-
apps/blehci/src/main.c | 312 +-----------------------------------
apps/bleprph/pkg.yml | 1 +
apps/bleprph/src/main.c | 32 +++-
apps/bletest/pkg.yml | 1 +
apps/bletest/src/bletest_hci.c | 2 +-
apps/bletest/src/main.c | 12 +-
apps/bletiny/pkg.yml | 1 +
apps/bletiny/src/main.c | 24 ++-
apps/bleuart/pkg.yml | 1 +
apps/bleuart/src/main.c | 11 +-
13 files changed, 94 insertions(+), 334 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/043e0e51/apps/blecent/pkg.yml
----------------------------------------------------------------------
diff --git a/apps/blecent/pkg.yml b/apps/blecent/pkg.yml
index b1710aa..3798fee 100644
--- a/apps/blecent/pkg.yml
+++ b/apps/blecent/pkg.yml
@@ -29,6 +29,7 @@ pkg.deps:
- net/nimble/host
- net/nimble/host/services/mandatory
- net/nimble/host/store/ram
+ - net/nimble/transport/ram
- libs/console/full
- libs/baselibc
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/043e0e51/apps/blecent/src/main.c
----------------------------------------------------------------------
diff --git a/apps/blecent/src/main.c b/apps/blecent/src/main.c
index 8f10814..66a4e3f 100755
--- a/apps/blecent/src/main.c
+++ b/apps/blecent/src/main.c
@@ -29,6 +29,9 @@
#include "controller/ble_ll.h"
#include "host/ble_hs.h"
+/* RAM HCI transport. */
+#include "transport/ram/ble_hci_ram.h"
+
/* RAM persistence layer. */
#include "store/ram/ble_store_ram.h"
@@ -448,6 +451,19 @@ blecent_gap_event(struct ble_gap_event *event, void *arg)
}
}
+static void
+blecent_on_reset(int reason)
+{
+ BLECENT_LOG(ERROR, "Resetting state; reason=%d\n", reason);
+}
+
+static void
+blecent_on_sync(void)
+{
+ /* Begin scanning for a peripheral to connect to. */
+ blecent_scan();
+}
+
/**
* Event loop for the main blecent task.
*/
@@ -464,9 +480,6 @@ blecent_task_handler(void *unused)
rc = ble_hs_start();
assert(rc == 0);
- /* Begin scanning for a peripheral to connect to. */
- blecent_scan();
-
while (1) {
ev = os_eventq_get(&blecent_evq);
switch (ev->ev_type) {
@@ -553,6 +566,10 @@ main(void)
rc = ble_ll_init(BLE_LL_TASK_PRI, MBUF_NUM_MBUFS, BLE_MBUF_PAYLOAD_SIZE);
assert(rc == 0);
+ /* Initialize the RAM HCI transport. */
+ rc = ble_hci_ram_init(&ble_hci_ram_cfg_dflt);
+ assert(rc == 0);
+
/* Configure the host. */
cfg = ble_hs_cfg_dflt;
cfg.max_hci_bufs = 3;
@@ -560,6 +577,8 @@ main(void)
cfg.sm_bonding = 1;
cfg.sm_our_key_dist = BLE_SM_PAIR_KEY_DIST_ENC;
cfg.sm_their_key_dist = BLE_SM_PAIR_KEY_DIST_ENC;
+ cfg.reset_cb = blecent_on_reset;
+ cfg.sync_cb = blecent_on_sync;
cfg.store_read_cb = ble_store_ram_read;
cfg.store_write_cb = ble_store_ram_write;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/043e0e51/apps/blehci/pkg.yml
----------------------------------------------------------------------
diff --git a/apps/blehci/pkg.yml b/apps/blehci/pkg.yml
index f36e383..198e395 100644
--- a/apps/blehci/pkg.yml
+++ b/apps/blehci/pkg.yml
@@ -23,7 +23,8 @@ pkg.homepage: "http://mynewt.apache.org/"
pkg.keywords:
pkg.deps:
- - libs/os
- - net/nimble/controller
- libs/baselibc
- libs/console/stub
+ - libs/os
+ - net/nimble/controller
+ - net/nimble/transport/uart
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/043e0e51/apps/blehci/src/main.c
----------------------------------------------------------------------
diff --git a/apps/blehci/src/main.c b/apps/blehci/src/main.c
index 09fb456..20fc4bc 100755
--- a/apps/blehci/src/main.c
+++ b/apps/blehci/src/main.c
@@ -17,24 +17,14 @@
* under the License.
*/
#include <assert.h>
-#include <string.h>
-#include <stdio.h>
-#include <errno.h>
-#include "bsp/bsp.h"
#include "os/os.h"
-#include "bsp/bsp.h"
-#include "hal/hal_gpio.h"
#include "hal/hal_cputime.h"
#include "hal/hal_uart.h"
/* BLE */
#include "nimble/ble.h"
-#include "nimble/nimble_opt.h"
-#include "nimble/hci_transport.h"
#include "controller/ble_ll.h"
-
-#define HCI_UART_SPEED 1000000
-#define HCI_UART CONSOLE_UART
+#include "transport/uart/ble_hci_uart.h"
/* Nimble task priorities */
#define BLE_LL_TASK_PRI (OS_TASK_PRI_HIGHEST)
@@ -53,291 +43,11 @@ uint8_t g_random_addr[BLE_DEV_ADDR_LEN] = { 0 };
#define HCI_MAX_BUFS (5)
-#define HCI_EVT_BUF_SIZE (260)
-struct os_mempool g_hci_evt_pool;
-static void *hci_cmd_buf;
-
-#define HCI_OS_EVENT_BUF_SIZE (sizeof(struct os_event))
-
-#define BLE_HOST_HCI_EVENT_CTLR_EVENT (OS_EVENT_T_PERUSER + 0)
-#define BLE_HOST_HCI_EVENT_CTLR_DATA (OS_EVENT_T_PERUSER + 1)
-
-struct os_mempool g_hci_os_event_pool;
-static void *hci_os_event_buf;
-
os_membuf_t default_mbuf_mpool_data[MBUF_MEMPOOL_SIZE];
struct os_mbuf_pool default_mbuf_pool;
struct os_mempool default_mbuf_mpool;
-#define H4_NONE 0x00
-#define H4_CMD 0x01
-#define H4_ACL 0x02
-#define H4_SCO 0x03
-#define H4_EVT 0x04
-
-#define HCI_CMD_HDR_LEN 3
-#define HCI_ACL_HDR_LEN 4
-#define HCI_EVT_HDR_LEN 2
-
-struct memblock {
- uint8_t *data; /* Pointer to memblock data */
- uint16_t cur; /* Number of bytes read/written */
- uint16_t len; /* Total number of bytes to read/write */
-};
-
-struct tx_acl {
- struct os_mbuf *buf; /* Buffer containing the data */
- uint16_t len; /* Target size when buf is considered complete */
-};
-
-static struct {
- /* State of data from host to controller */
- uint8_t tx_type; /* Pending packet type. 0 means nothing pending */
- union {
- struct memblock tx_cmd;
- struct tx_acl tx_acl;
- };
-
- /* State of data from controller to host */
- uint8_t rx_type; /* Pending packet type. 0 means nothing pending */
- union {
- struct memblock rx_evt;
- struct os_mbuf *rx_acl;
- };
- STAILQ_HEAD(, os_event) rx_pkts; /* Packet queue to send to UART */
-} hci;
-
-int
-ble_hs_rx_data(struct os_mbuf *om)
-{
- struct os_event *ev;
- os_sr_t sr;
-
- ev = os_memblock_get(&g_hci_os_event_pool);
- if (!ev) {
- os_mbuf_free_chain(om);
- return -1;
- }
-
- ev->ev_type = BLE_HOST_HCI_EVENT_CTLR_DATA;
- ev->ev_arg = om;
- ev->ev_queued = 1;
-
- OS_ENTER_CRITICAL(sr);
- STAILQ_INSERT_TAIL(&hci.rx_pkts, ev, ev_next);
- OS_EXIT_CRITICAL(sr);
-
- hal_uart_start_tx(HCI_UART);
-
- return 0;
-}
-
-int
-ble_hci_transport_ctlr_event_send(uint8_t *hci_ev)
-{
- struct os_event *ev;
- os_sr_t sr;
-
- ev = os_memblock_get(&g_hci_os_event_pool);
- if (!ev) {
- os_error_t err;
-
- err = os_memblock_put(&g_hci_evt_pool, hci_ev);
- assert(err == OS_OK);
-
- return -1;
- }
-
- ev->ev_type = BLE_HOST_HCI_EVENT_CTLR_EVENT;
- ev->ev_arg = hci_ev;
- ev->ev_queued = 1;
-
- OS_ENTER_CRITICAL(sr);
- STAILQ_INSERT_TAIL(&hci.rx_pkts, ev, ev_next);
- OS_EXIT_CRITICAL(sr);
-
- hal_uart_start_tx(HCI_UART);
-
- return 0;
-}
-
-static int
-uart_tx_pkt_type(void)
-{
- struct os_event *ev;
- os_sr_t sr;
- int rc;
-
- OS_ENTER_CRITICAL(sr);
-
- ev = STAILQ_FIRST(&hci.rx_pkts);
- if (!ev) {
- OS_EXIT_CRITICAL(sr);
- return -1;
- }
-
- STAILQ_REMOVE(&hci.rx_pkts, ev, os_event, ev_next);
- ev->ev_queued = 0;
-
- OS_EXIT_CRITICAL(sr);
-
- switch (ev->ev_type) {
- case BLE_HOST_HCI_EVENT_CTLR_EVENT:
- hci.rx_type = H4_EVT;
- hci.rx_evt.data = ev->ev_arg;
- hci.rx_evt.cur = 0;
- hci.rx_evt.len = hci.rx_evt.data[1] + HCI_EVT_HDR_LEN;
- rc = H4_EVT;
- break;
- case BLE_HOST_HCI_EVENT_CTLR_DATA:
- hci.rx_type = H4_ACL;
- hci.rx_acl = ev->ev_arg;
- rc = H4_ACL;
- break;
- default:
- rc = -1;
- break;
- }
-
- os_memblock_put(&g_hci_os_event_pool, ev);
-
- return rc;
-}
-
-static int
-uart_tx_char(void *arg)
-{
- int rc = -1;
-
- switch (hci.rx_type) {
- case H4_NONE: /* No pending packet, pick one from the queue */
- rc = uart_tx_pkt_type();
- break;
- case H4_EVT:
- rc = hci.rx_evt.data[hci.rx_evt.cur++];
-
- if (hci.rx_evt.cur == hci.rx_evt.len) {
- os_memblock_put(&g_hci_evt_pool, hci.rx_evt.data);
- hci.rx_type = H4_NONE;
- }
-
- break;
- case H4_ACL:
- rc = *OS_MBUF_DATA(hci.rx_acl, uint8_t *);
- os_mbuf_adj(hci.rx_acl, 1);
- if (!OS_MBUF_PKTLEN(hci.rx_acl)) {
- os_mbuf_free_chain(hci.rx_acl);
- hci.rx_type = H4_NONE;
- }
-
- break;
- }
-
- return rc;
-}
-
-static int
-uart_rx_pkt_type(uint8_t data)
-{
- hci.tx_type = data;
-
- switch (hci.tx_type) {
- case H4_CMD:
- hci.tx_cmd.data = os_memblock_get(&g_hci_evt_pool);
- hci.tx_cmd.len = 0;
- hci.tx_cmd.cur = 0;
- break;
- case H4_ACL:
- hci.tx_acl.buf = os_msys_get_pkthdr(HCI_ACL_HDR_LEN, 0);
- hci.tx_acl.len = 0;
- break;
- default:
- hci.tx_type = H4_NONE;
- return -1;
- }
-
- return 0;
-}
-
-static int
-uart_rx_cmd(uint8_t data)
-{
- int rc;
-
- hci.tx_cmd.data[hci.tx_cmd.cur++] = data;
-
- if (hci.tx_cmd.cur < HCI_CMD_HDR_LEN) {
- return 0;
- } else if (hci.tx_cmd.cur == HCI_CMD_HDR_LEN) {
- hci.tx_cmd.len = hci.tx_cmd.data[2] + HCI_CMD_HDR_LEN;
- }
-
- if (hci.tx_cmd.cur == hci.tx_cmd.len) {
- rc = ble_hci_transport_host_cmd_send(hci.tx_cmd.data);
- if (rc != 0) {
- os_memblock_put(&g_hci_evt_pool, hci.tx_cmd.data);
- }
- hci.tx_type = H4_NONE;
- }
-
- return 0;
-}
-
-static int
-uart_rx_acl(uint8_t data)
-{
- os_mbuf_append(hci.tx_acl.buf, &data, 1);
-
- if (OS_MBUF_PKTLEN(hci.tx_acl.buf) < HCI_ACL_HDR_LEN) {
- return 0;
- } else if (OS_MBUF_PKTLEN(hci.tx_acl.buf) == HCI_ACL_HDR_LEN) {
- os_mbuf_copydata(hci.tx_acl.buf, 2, sizeof(hci.tx_acl.len),
- &hci.tx_acl.len);
- hci.tx_acl.len = le16toh(&hci.tx_acl.len) + HCI_ACL_HDR_LEN;
- }
-
- if (OS_MBUF_PKTLEN(hci.tx_acl.buf) == hci.tx_acl.len) {
- ble_hci_transport_host_acl_data_send(hci.tx_acl.buf);
- hci.tx_type = H4_NONE;
- }
-
- return 0;
-}
-
-static int
-uart_rx_char(void *arg, uint8_t data)
-{
- switch (hci.tx_type) {
- case H4_NONE:
- return uart_rx_pkt_type(data);
- case H4_CMD:
- return uart_rx_cmd(data);
- case H4_ACL:
- return uart_rx_acl(data);
- default:
- return -1;
- }
-}
-
-static int
-uart_init(void)
-{
- int rc;
-
- memset(&hci, 0, sizeof(hci));
-
- STAILQ_INIT(&hci.rx_pkts);
-
- rc = hal_uart_init_cbs(HCI_UART, uart_tx_char, NULL, uart_rx_char, NULL);
- if (rc) {
- return rc;
- }
-
- return hal_uart_config(HCI_UART, HCI_UART_SPEED, 8, 1, HAL_UART_PARITY_NONE,
- HAL_UART_FLOW_CTL_RTS_CTS);
-}
-
int
main(void)
{
@@ -366,25 +76,7 @@ main(void)
rc = ble_ll_init(BLE_LL_TASK_PRI, MBUF_NUM_MBUFS, BLE_MBUF_PAYLOAD_SIZE);
assert(rc == 0);
- hci_cmd_buf = malloc(OS_MEMPOOL_BYTES(HCI_MAX_BUFS, HCI_EVT_BUF_SIZE));
- assert(hci_cmd_buf != NULL);
-
- /* Create memory pool of command buffers */
- rc = os_mempool_init(&g_hci_evt_pool, HCI_MAX_BUFS, HCI_EVT_BUF_SIZE,
- hci_cmd_buf, "HCICmdPool");
- assert(rc == 0);
-
- hci_os_event_buf = malloc(OS_MEMPOOL_BYTES(HCI_MAX_BUFS,
- HCI_OS_EVENT_BUF_SIZE));
- assert(hci_os_event_buf != NULL);
-
- /* Create memory pool of OS events */
- rc = os_mempool_init(&g_hci_os_event_pool, HCI_MAX_BUFS,
- HCI_OS_EVENT_BUF_SIZE, hci_os_event_buf,
- "HCIOsEventPool");
- assert(rc == 0);
-
- rc = uart_init();
+ rc = ble_hci_uart_init(&ble_hci_uart_cfg_dflt);
assert(rc == 0);
/* Start the OS */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/043e0e51/apps/bleprph/pkg.yml
----------------------------------------------------------------------
diff --git a/apps/bleprph/pkg.yml b/apps/bleprph/pkg.yml
index ec75359..7c45ee2 100644
--- a/apps/bleprph/pkg.yml
+++ b/apps/bleprph/pkg.yml
@@ -29,6 +29,7 @@ pkg.deps:
- net/nimble/host
- net/nimble/host/services/mandatory
- net/nimble/host/store/ram
+ - net/nimble/transport/ram
- libs/console/full
- libs/baselibc
- libs/newtmgr
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/043e0e51/apps/bleprph/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bleprph/src/main.c b/apps/bleprph/src/main.c
index 0e6ec14..cff4763 100755
--- a/apps/bleprph/src/main.c
+++ b/apps/bleprph/src/main.c
@@ -40,9 +40,9 @@
#include "host/ble_l2cap.h"
#include "host/ble_sm.h"
#include "controller/ble_ll.h"
-/* Newtmgr include */
-#include "newtmgr/newtmgr.h"
-#include "nmgrble/newtmgr_ble.h"
+
+/* RAM HCI transport. */
+#include "transport/ram/ble_hci_ram.h"
/* RAM persistence layer. */
#include "store/ram/ble_store_ram.h"
@@ -51,6 +51,10 @@
#include "services/mandatory/ble_svc_gap.h"
#include "services/mandatory/ble_svc_gatt.h"
+/* Newtmgr include */
+#include "newtmgr/newtmgr.h"
+#include "nmgrble/newtmgr_ble.h"
+
/* Application-specified header. */
#include "bleprph.h"
@@ -266,6 +270,19 @@ bleprph_gap_event(struct ble_gap_event *event, void *arg)
return 0;
}
+static void
+bleprph_on_reset(int reason)
+{
+ BLEPRPH_LOG(ERROR, "Resetting state; reason=%d\n", reason);
+}
+
+static void
+bleprph_on_sync(void)
+{
+ /* Begin advertising. */
+ bleprph_advertise();
+}
+
/**
* Event loop for the main bleprph task.
*/
@@ -280,10 +297,6 @@ bleprph_task_handler(void *unused)
* controller.
*/
rc = ble_hs_start();
- assert(rc == 0);
-
- /* Begin advertising. */
- bleprph_advertise();
while (1) {
ev = os_eventq_get(&bleprph_evq);
@@ -383,6 +396,8 @@ main(void)
cfg.sm_bonding = 1;
cfg.sm_our_key_dist = BLE_SM_PAIR_KEY_DIST_ENC;
cfg.sm_their_key_dist = BLE_SM_PAIR_KEY_DIST_ENC;
+ cfg.reset_cb = bleprph_on_reset;
+ cfg.sync_cb = bleprph_on_sync;
cfg.store_read_cb = ble_store_ram_read;
cfg.store_write_cb = ble_store_ram_write;
cfg.gatts_register_cb = gatt_svr_register_cb;
@@ -404,6 +419,9 @@ main(void)
rc = ble_hs_init(&bleprph_evq, &cfg);
assert(rc == 0);
+ rc = ble_hci_ram_init(&ble_hci_ram_cfg_dflt);
+ assert(rc == 0);
+
nmgr_task_init(NEWTMGR_TASK_PRIO, newtmgr_stack, NEWTMGR_TASK_STACK_SIZE);
imgmgr_module_init();
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/043e0e51/apps/bletest/pkg.yml
----------------------------------------------------------------------
diff --git a/apps/bletest/pkg.yml b/apps/bletest/pkg.yml
index 84b6e71..3e94ede 100644
--- a/apps/bletest/pkg.yml
+++ b/apps/bletest/pkg.yml
@@ -28,6 +28,7 @@ pkg.deps:
- fs/nffs
- net/nimble/controller
- net/nimble/host
+ - net/nimble/transport/ram
- libs/os
- libs/console/full
- libs/shell
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/043e0e51/apps/bletest/src/bletest_hci.c
----------------------------------------------------------------------
diff --git a/apps/bletest/src/bletest_hci.c b/apps/bletest/src/bletest_hci.c
index 5e6c31e..64d0270 100755
--- a/apps/bletest/src/bletest_hci.c
+++ b/apps/bletest/src/bletest_hci.c
@@ -24,7 +24,7 @@
/* BLE */
#include "nimble/ble.h"
-#include "nimble/hci_transport.h"
+#include "nimble/ble_hci_trans.h"
#include "nimble/hci_common.h"
#include "host/ble_hs.h"
#include "controller/ble_ll.h"
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/043e0e51/apps/bletest/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletest/src/main.c b/apps/bletest/src/main.c
index f6bb187..be0cf6d 100755
--- a/apps/bletest/src/main.c
+++ b/apps/bletest/src/main.c
@@ -36,7 +36,7 @@
/* BLE */
#include "nimble/ble.h"
-#include "nimble/hci_transport.h"
+#include "nimble/ble_hci_trans.h"
#include "nimble/hci_common.h"
#include "host/ble_hs.h"
#include "controller/ble_ll.h"
@@ -44,6 +44,7 @@
#include "controller/ble_ll_conn.h"
#include "controller/ble_ll_scan.h"
#include "controller/ble_ll_adv.h"
+#include "transport/ram/ble_hci_ram.h"
/* XXX: An app should not include private headers from a library. The bletest
* app uses some of nimble's internal details for logging.
@@ -767,7 +768,7 @@ bletest_execute_advertiser(void)
/* Add length */
OS_MBUF_PKTHDR(om)->omp_len = om->om_len;
- ble_hci_transport_host_acl_data_send(om);
+ ble_hci_trans_hs_acl_data_send(om);
/* Increment last handle used */
++g_last_handle_used;
@@ -823,7 +824,7 @@ bletest_execute_advertiser(void)
/* Add length */
OS_MBUF_PKTHDR(om)->omp_len = om->om_len;
- ble_hci_transport_host_acl_data_send(om);
+ ble_hci_trans_hs_acl_data_send(om);
++g_bletest_outstanding_pkts;
}
@@ -895,6 +896,8 @@ bletest_task_handler(void *arg)
os_callout_func_init(&g_bletest_timer, &g_bletest_evq, bletest_timer_cb,
NULL);
+ ble_hs_dbg_set_sync_state(BLE_HS_SYNC_STATE_GOOD);
+
/* Send the reset command first */
rc = bletest_hci_reset_ctlr();
assert(rc == 0);
@@ -1151,6 +1154,9 @@ main(void)
rc = ble_hs_init(&g_bletest_evq, NULL);
assert(rc == 0);
+ rc = ble_hci_ram_init(&ble_hci_ram_cfg_dflt);
+ assert(rc == 0);
+
rc = os_task_init(&bletest_task, "bletest", bletest_task_handler, NULL,
BLETEST_TASK_PRIO, OS_WAIT_FOREVER, bletest_stack,
BLETEST_STACK_SIZE);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/043e0e51/apps/bletiny/pkg.yml
----------------------------------------------------------------------
diff --git a/apps/bletiny/pkg.yml b/apps/bletiny/pkg.yml
index a3c6ee7..625adc6 100644
--- a/apps/bletiny/pkg.yml
+++ b/apps/bletiny/pkg.yml
@@ -29,6 +29,7 @@ pkg.deps:
- net/nimble/host
- net/nimble/host/services/mandatory
- net/nimble/host/store/ram
+ - net/nimble/transport/ram
- libs/console/full
- libs/shell
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/043e0e51/apps/bletiny/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/main.c b/apps/bletiny/src/main.c
index 2f3c474..38ee467 100755
--- a/apps/bletiny/src/main.c
+++ b/apps/bletiny/src/main.c
@@ -35,8 +35,8 @@
/* BLE */
#include "nimble/ble.h"
#include "nimble/nimble_opt.h"
-#include "nimble/hci_transport.h"
-#include "host/host_hci.h"
+#include "nimble/ble_hci_trans.h"
+#include "controller/ble_ll.h"
#include "host/ble_hs.h"
#include "host/ble_hs_adv.h"
#include "host/ble_uuid.h"
@@ -45,7 +45,7 @@
#include "host/ble_gatt.h"
#include "host/ble_store.h"
#include "host/ble_sm.h"
-#include "controller/ble_ll.h"
+#include "transport/ram/ble_hci_ram.h"
/* RAM persistence layer. */
#include "store/ram/ble_store_ram.h"
@@ -1084,7 +1084,7 @@ bletiny_tx_timer_cb(void *arg)
/* Set packet header length */
OS_MBUF_PKTHDR(om)->omp_len = om->om_len;
- ble_hci_transport_host_acl_data_send(om);
+ ble_hci_trans_hs_acl_tx(om);
--bletiny_tx_data.tx_num;
}
@@ -1552,6 +1552,12 @@ bletiny_rssi(uint16_t conn_handle, int8_t *out_rssi)
return 0;
}
+static void
+bletiny_on_reset(int reason)
+{
+ console_printf("Error: Resetting state; reason=%d\n", reason);
+}
+
/**
* BLE test task
*
@@ -1594,6 +1600,7 @@ bletiny_task_handler(void *arg)
int
main(void)
{
+ struct ble_hci_ram_cfg hci_cfg;
struct ble_hs_cfg cfg;
uint32_t seed;
int rc;
@@ -1688,10 +1695,17 @@ main(void)
rc = ble_ll_init(BLE_LL_TASK_PRI, MBUF_NUM_MBUFS, BLE_MBUF_PAYLOAD_SIZE);
assert(rc == 0);
+ /* Initialize the RAM HCI transport. */
+ hci_cfg = ble_hci_ram_cfg_dflt;
+ hci_cfg.num_evt_bufs = 3;
+ rc = ble_hci_ram_init(&hci_cfg);
+ assert(rc == 0);
+
/* Initialize the NimBLE host configuration. */
cfg = ble_hs_cfg_dflt;
- cfg.max_hci_bufs = 3;
+ cfg.max_hci_bufs = hci_cfg.num_evt_bufs;
cfg.max_gattc_procs = 2;
+ cfg.reset_cb = bletiny_on_reset;
cfg.store_read_cb = ble_store_ram_read;
cfg.store_write_cb = ble_store_ram_write;
cfg.gatts_register_cb = gatt_svr_register_cb;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/043e0e51/apps/bleuart/pkg.yml
----------------------------------------------------------------------
diff --git a/apps/bleuart/pkg.yml b/apps/bleuart/pkg.yml
index a79077f..c93011b 100644
--- a/apps/bleuart/pkg.yml
+++ b/apps/bleuart/pkg.yml
@@ -29,6 +29,7 @@ pkg.deps:
- net/nimble/host
- net/nimble/host/services/mandatory
- net/nimble/host/store/ram
+ - net/nimble/transport/ram
- libs/console/full
- libs/baselibc
- libs/newtmgr
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/043e0e51/apps/bleuart/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bleuart/src/main.c b/apps/bleuart/src/main.c
index 0a5dd82..f7c7714 100755
--- a/apps/bleuart/src/main.c
+++ b/apps/bleuart/src/main.c
@@ -195,6 +195,13 @@ bleuart_gap_event(struct ble_gap_event *event, void *arg)
return 0;
}
+static void
+bleuart_on_sync(void)
+{
+ /* Begin advertising. */
+ bleuart_advertise();
+}
+
/**
* Event loop for the main bleuart task.
*/
@@ -208,9 +215,6 @@ bleuart_task_handler(void *unused)
rc = ble_hs_start();
assert(rc == 0);
- /* Begin advertising. */
- bleuart_advertise();
-
while (1) {
ev = os_eventq_get(&bleuart_evq);
@@ -298,6 +302,7 @@ main(void)
cfg.sm_bonding = 1;
cfg.sm_our_key_dist = BLE_SM_PAIR_KEY_DIST_ENC;
cfg.sm_their_key_dist = BLE_SM_PAIR_KEY_DIST_ENC;
+ cfg.sync_cb = bleuart_on_sync;
cfg.store_read_cb = ble_store_ram_read;
cfg.store_write_cb = ble_store_ram_write;
[24/42] incubator-mynewt-core git commit: NimBLE - high / low prio
event buffers.
Posted by st...@apache.org.
NimBLE - high / low prio event buffers.
Events have one of two priorities:
o Low-priority (BLE_HCI_TRANS_BUF_EVT_LO)
o High-priority (BLE_HCI_TRANS_BUF_EVT_HI)
Low-priority event buffers are only used for advertising reports. If
there are no free low-priority event buffers, then an incoming
advertising report will get dropped.
High-priority event buffers are for everything except advertising
reports. If there are no free high-priority event buffers, a request to
allocate one will try to allocate a low-priority buffer instead.
If you want all events to be given equal treatment, then you should
allocate low-priority events only.
Event priorities solve the problem of critical events getting dropped
due to a flood of advertising reports. This solution is likely
temporary: when HCI flow control is added, event priorities may become
obsolete.
Not all transports distinguish between low and high priority events. If
the transport does not have separate settings for low and high buffer
counts, then it treats all events with equal priority.
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/a7f8b7ac
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/a7f8b7ac
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/a7f8b7ac
Branch: refs/heads/sterly_refactor
Commit: a7f8b7ac6dec6551c55fb4237b086373b15fa67b
Parents: 6d5b96d
Author: Christopher Collins <cc...@apache.org>
Authored: Thu Aug 4 16:31:05 2016 -0700
Committer: Sterling Hughes <st...@apache.org>
Committed: Tue Aug 9 16:05:21 2016 -0700
----------------------------------------------------------------------
net/nimble/host/src/test/ble_hs_test_util.c | 1 -
net/nimble/include/nimble/ble_hci_trans.h | 27 ++++--
.../ram/include/transport/ram/ble_hci_ram.h | 17 +++-
net/nimble/transport/ram/src/ble_hci_ram.c | 95 +++++++++++++++-----
4 files changed, 110 insertions(+), 30 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a7f8b7ac/net/nimble/host/src/test/ble_hs_test_util.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_test_util.c b/net/nimble/host/src/test/ble_hs_test_util.c
index cfb86fa..4f1c706 100644
--- a/net/nimble/host/src/test/ble_hs_test_util.c
+++ b/net/nimble/host/src/test/ble_hs_test_util.c
@@ -1382,7 +1382,6 @@ ble_hs_test_util_init(void)
ble_hs_test_util_pkt_txed, NULL);
hci_cfg = ble_hci_ram_cfg_dflt;
- hci_cfg.num_evt_bufs = cfg.max_hci_bufs;
rc = ble_hci_ram_init(&hci_cfg);
TEST_ASSERT_FATAL(rc == 0);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a7f8b7ac/net/nimble/include/nimble/ble_hci_trans.h
----------------------------------------------------------------------
diff --git a/net/nimble/include/nimble/ble_hci_trans.h b/net/nimble/include/nimble/ble_hci_trans.h
index 822da96..3e2ec7a 100644
--- a/net/nimble/include/nimble/ble_hci_trans.h
+++ b/net/nimble/include/nimble/ble_hci_trans.h
@@ -27,13 +27,30 @@ struct os_mbuf;
/*** Type of buffers for holding commands and events. */
/**
- * Low-priority event (advertising reports). A request to allocate a
- * high-priority event buffer may allocate one of these instead if no
- * high-priority buffers are available.
+ * Controller-to-host event buffers. Events have one of two priorities:
+ * o Low-priority (BLE_HCI_TRANS_BUF_EVT_LO)
+ * o High-priority (BLE_HCI_TRANS_BUF_EVT_HI)
+ *
+ * Low-priority event buffers are only used for advertising reports. If there
+ * are no free low-priority event buffers, then an incoming advertising report
+ * will get dropped.
+ *
+ * High-priority event buffers are for everything except advertising reports.
+ * If there are no free high-priority event buffers, a request to allocate one
+ * will try to allocate a low-priority buffer instead.
+ *
+ * If you want all events to be given equal treatment, then you should allocate
+ * low-priority events only.
+ *
+ * Event priorities solve the problem of critical events getting dropped due to
+ * a flood of advertising reports. This solution is likely temporary: when
+ * HCI flow control is added, event priorities may become obsolete.
+ *
+ * Not all transports distinguish between low and high priority events. If the
+ * transport does not have separate settings for low and high buffer counts,
+ * then it treats all events with equal priority.
*/
#define BLE_HCI_TRANS_BUF_EVT_LO 1
-
-/* High-priority event (all events except advertising reports). */
#define BLE_HCI_TRANS_BUF_EVT_HI 2
/* Host-to-controller command. */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a7f8b7ac/net/nimble/transport/ram/include/transport/ram/ble_hci_ram.h
----------------------------------------------------------------------
diff --git a/net/nimble/transport/ram/include/transport/ram/ble_hci_ram.h b/net/nimble/transport/ram/include/transport/ram/ble_hci_ram.h
index 1c5b58e..9d2d672 100644
--- a/net/nimble/transport/ram/include/transport/ram/ble_hci_ram.h
+++ b/net/nimble/transport/ram/include/transport/ram/ble_hci_ram.h
@@ -4,8 +4,23 @@
#include "nimble/ble_hci_trans.h"
struct ble_hci_ram_cfg {
- uint16_t num_evt_bufs;
+ /** Number of high-priority event buffers. */
+ uint16_t num_evt_hi_bufs;
+
+ /** Number of low-priority event buffers. */
+ uint16_t num_evt_lo_bufs;
+
+ /** Size of each event buffer, in bytes. */
uint16_t evt_buf_sz;
+
+ /* Note: For information about high-priority vs. low-priority event
+ * buffers, see net/nimble/include/nimble/ble_hci_trans.h.
+ */
+
+ /* Note: host-to-controller command buffers are not configurable. The RAM
+ * transport only allows one outstanding command, so it uses a single
+ * statically-allocated buffer.
+ */
};
extern const struct ble_hci_ram_cfg ble_hci_ram_cfg_dflt;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a7f8b7ac/net/nimble/transport/ram/src/ble_hci_ram.c
----------------------------------------------------------------------
diff --git a/net/nimble/transport/ram/src/ble_hci_ram.c b/net/nimble/transport/ram/src/ble_hci_ram.c
index aac5eb1..23a375d 100644
--- a/net/nimble/transport/ram/src/ble_hci_ram.c
+++ b/net/nimble/transport/ram/src/ble_hci_ram.c
@@ -7,7 +7,8 @@
/** Default configuration. */
const struct ble_hci_ram_cfg ble_hci_ram_cfg_dflt = {
- .num_evt_bufs = 3,
+ .num_evt_hi_bufs = 1,
+ .num_evt_lo_bufs = 2,
.evt_buf_sz = BLE_HCI_TRANS_CMD_SZ,
};
@@ -23,17 +24,19 @@ static void *ble_hci_ram_rx_acl_hs_arg;
static ble_hci_trans_rx_acl_fn *ble_hci_ram_rx_acl_ll_cb;
static void *ble_hci_ram_rx_acl_ll_arg;
-static struct os_mempool ble_hci_ram_evt_pool;
-static void *ble_hci_ram_evt_buf;
+static struct os_mempool ble_hci_ram_evt_hi_pool;
+static void *ble_hci_ram_evt_hi_buf;
+static struct os_mempool ble_hci_ram_evt_lo_pool;
+static void *ble_hci_ram_evt_lo_buf;
static uint8_t *ble_hci_ram_hs_cmd_buf;
static uint8_t ble_hci_ram_hs_cmd_buf_alloced;
void
ble_hci_trans_cfg_hs(ble_hci_trans_rx_cmd_fn *cmd_cb,
- void *cmd_arg,
- ble_hci_trans_rx_acl_fn *acl_cb,
- void *acl_arg)
+ void *cmd_arg,
+ ble_hci_trans_rx_acl_fn *acl_cb,
+ void *acl_arg)
{
ble_hci_ram_rx_cmd_hs_cb = cmd_cb;
ble_hci_ram_rx_cmd_hs_arg = cmd_arg;
@@ -43,9 +46,9 @@ ble_hci_trans_cfg_hs(ble_hci_trans_rx_cmd_fn *cmd_cb,
void
ble_hci_trans_cfg_ll(ble_hci_trans_rx_cmd_fn *cmd_cb,
- void *cmd_arg,
- ble_hci_trans_rx_acl_fn *acl_cb,
- void *acl_arg)
+ void *cmd_arg,
+ ble_hci_trans_rx_acl_fn *acl_cb,
+ void *acl_arg)
{
ble_hci_ram_rx_cmd_ll_cb = cmd_cb;
ble_hci_ram_rx_cmd_ll_arg = cmd_arg;
@@ -78,7 +81,7 @@ ble_hci_trans_ll_evt_tx(uint8_t *hci_ev)
int
ble_hci_trans_hs_acl_tx(struct os_mbuf *om)
{
- int rc;
+ int rc;
assert(ble_hci_ram_rx_acl_ll_cb != NULL);
@@ -103,9 +106,18 @@ ble_hci_trans_buf_alloc(int type)
uint8_t *buf;
switch (type) {
- case BLE_HCI_TRANS_BUF_EVT_LO:
case BLE_HCI_TRANS_BUF_EVT_HI:
- buf = os_memblock_get(&ble_hci_ram_evt_pool);
+ buf = os_memblock_get(&ble_hci_ram_evt_hi_pool);
+ if (buf == NULL) {
+ /* If no high-priority event buffers remain, try to grab a
+ * low-priority one.
+ */
+ buf = ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_LO);
+ }
+ break;
+
+ case BLE_HCI_TRANS_BUF_EVT_LO:
+ buf = os_memblock_get(&ble_hci_ram_evt_lo_pool);
break;
case BLE_HCI_TRANS_BUF_CMD:
@@ -130,8 +142,12 @@ ble_hci_trans_buf_free(uint8_t *buf)
if (buf == ble_hci_ram_hs_cmd_buf) {
assert(ble_hci_ram_hs_cmd_buf_alloced);
ble_hci_ram_hs_cmd_buf_alloced = 0;
+ } else if (os_memblock_from(&ble_hci_ram_evt_hi_pool, buf)) {
+ rc = os_memblock_put(&ble_hci_ram_evt_hi_pool, buf);
+ assert(rc == 0);
} else {
- rc = os_memblock_put(&ble_hci_ram_evt_pool, buf);
+ assert(os_memblock_from(&ble_hci_ram_evt_lo_pool, buf));
+ rc = os_memblock_put(&ble_hci_ram_evt_lo_pool, buf);
assert(rc == 0);
}
}
@@ -139,8 +155,11 @@ ble_hci_trans_buf_free(uint8_t *buf)
static void
ble_hci_ram_free_mem(void)
{
- free(ble_hci_ram_evt_buf);
- ble_hci_ram_evt_buf = NULL;
+ free(ble_hci_ram_evt_hi_buf);
+ ble_hci_ram_evt_hi_buf = NULL;
+
+ free(ble_hci_ram_evt_lo_buf);
+ ble_hci_ram_evt_lo_buf = NULL;
free(ble_hci_ram_hs_cmd_buf);
ble_hci_ram_hs_cmd_buf = NULL;
@@ -150,9 +169,21 @@ ble_hci_ram_free_mem(void)
int
ble_hci_trans_reset(void)
{
+ /* No work to do. All allocated buffers are owned by the host or
+ * controller, and they will get freed by their owners.
+ */
return 0;
}
+/**
+ * Initializes the RAM HCI transport module.
+ *
+ * @param cfg The settings to initialize the HCI RAM
+ * transport with.
+ *
+ * @return 0 on success;
+ * A BLE_ERR_[...] error code on failure.
+ */
int
ble_hci_ram_init(const struct ble_hci_ram_cfg *cfg)
{
@@ -160,17 +191,35 @@ ble_hci_ram_init(const struct ble_hci_ram_cfg *cfg)
ble_hci_ram_free_mem();
- ble_hci_ram_evt_buf = malloc(OS_MEMPOOL_BYTES(cfg->num_evt_bufs,
- cfg->evt_buf_sz));
- if (ble_hci_ram_evt_buf == NULL) {
- rc = ENOMEM;
+ if (cfg->num_evt_hi_bufs > 0) {
+ ble_hci_ram_evt_hi_buf = malloc(OS_MEMPOOL_BYTES(cfg->num_evt_hi_bufs,
+ cfg->evt_buf_sz));
+ if (ble_hci_ram_evt_hi_buf == NULL) {
+ rc = ENOMEM;
+ goto err;
+ }
+ }
+
+ rc = os_mempool_init(&ble_hci_ram_evt_hi_pool, cfg->num_evt_hi_bufs,
+ cfg->evt_buf_sz, ble_hci_ram_evt_hi_buf,
+ "ble_hci_ram_evt_hi_pool");
+ if (rc != 0) {
+ rc = EINVAL;
goto err;
}
- /* Create memory pool of command buffers */
- rc = os_mempool_init(&ble_hci_ram_evt_pool, cfg->num_evt_bufs,
- cfg->evt_buf_sz, ble_hci_ram_evt_buf,
- "ble_hci_ram_evt_pool");
+ if (cfg->num_evt_lo_bufs > 0) {
+ ble_hci_ram_evt_lo_buf = malloc(OS_MEMPOOL_BYTES(cfg->num_evt_lo_bufs,
+ cfg->evt_buf_sz));
+ if (ble_hci_ram_evt_lo_buf == NULL) {
+ rc = ENOMEM;
+ goto err;
+ }
+ }
+
+ rc = os_mempool_init(&ble_hci_ram_evt_lo_pool, cfg->num_evt_lo_bufs,
+ cfg->evt_buf_sz, ble_hci_ram_evt_lo_buf,
+ "ble_hci_ram_evt_lo_pool");
if (rc != 0) {
rc = EINVAL;
goto err;
[41/42] incubator-mynewt-core git commit: BLE Host - reuse
exec-write-req mbuf for rsp.
Posted by st...@apache.org.
BLE Host - reuse exec-write-req mbuf for rsp.
The response has the same contents as the request; only the op code is
different. By reusing the mbuf, it makes failure due to mbuf exhaustion
less likely.
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/abd5a752
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/abd5a752
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/abd5a752
Branch: refs/heads/sterly_refactor
Commit: abd5a7527234d834d1bf2bde9e1ddbf288674821
Parents: 2d39d3b
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Aug 9 12:41:53 2016 -0700
Committer: Sterling Hughes <st...@apache.org>
Committed: Tue Aug 9 16:05:21 2016 -0700
----------------------------------------------------------------------
net/nimble/host/src/ble_att_svr.c | 41 +++++++++++-----------------------
1 file changed, 13 insertions(+), 28 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/abd5a752/net/nimble/host/src/ble_att_svr.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_svr.c b/net/nimble/host/src/ble_att_svr.c
index f282093..860794d 100644
--- a/net/nimble/host/src/ble_att_svr.c
+++ b/net/nimble/host/src/ble_att_svr.c
@@ -588,6 +588,8 @@ ble_att_svr_tx_rsp(uint16_t conn_handle, int rc, struct os_mbuf *om,
rc = BLE_HS_ENOTCONN;
} else {
if (rc == 0) {
+ BLE_HS_DBG_ASSERT(om != NULL);
+
ble_att_inc_tx_stat(om->om_data[0]);
ble_att_truncate_to_mtu(chan, om);
rc = ble_l2cap_tx(conn, chan, om);
@@ -2372,7 +2374,6 @@ ble_att_svr_rx_prep_write(uint16_t conn_handle, struct os_mbuf **rxom)
struct ble_hs_conn *conn;
struct os_mbuf *txom;
uint16_t err_handle;
- uint8_t *buf;
uint8_t att_err;
int rc;
@@ -2394,16 +2395,13 @@ ble_att_svr_rx_prep_write(uint16_t conn_handle, struct os_mbuf **rxom)
ble_att_prep_write_cmd_log, &req);
err_handle = req.bapc_handle;
- /* Strip the request base from the front of the mbuf. */
- os_mbuf_adj(*rxom, BLE_ATT_PREP_WRITE_CMD_BASE_SZ);
-
attr_entry = ble_att_svr_find_by_handle(req.bapc_handle);
/* A prepare write request gets rejected for the following reasons:
* 1. Insufficient authorization.
* 2. Insufficient authentication.
* 3. Insufficient encryption key size (XXX: Not checked).
- * 4. Insufficient encryption.
+ * 4. Insufficient encryption (XXX: Not checked).
* 5. Invalid handle.
* 6. Write not permitted.
*/
@@ -2447,8 +2445,10 @@ ble_att_svr_rx_prep_write(uint16_t conn_handle, struct os_mbuf **rxom)
}
/* Append attribute value from request onto prep mbuf. */
- rc = os_mbuf_appendfrom(prep_entry->bape_value, *rxom, 0,
- OS_MBUF_PKTLEN(*rxom));
+ rc = os_mbuf_appendfrom(prep_entry->bape_value, *rxom,
+ BLE_ATT_PREP_WRITE_CMD_BASE_SZ,
+ OS_MBUF_PKTLEN(*rxom) -
+ BLE_ATT_PREP_WRITE_CMD_BASE_SZ);
if (rc != 0) {
att_err = BLE_ATT_ERR_PREPARE_QUEUE_FULL;
}
@@ -2460,27 +2460,12 @@ ble_att_svr_rx_prep_write(uint16_t conn_handle, struct os_mbuf **rxom)
goto done;
}
- txom = ble_hs_mbuf_l2cap_pkt();
- if (txom == NULL) {
- att_err = BLE_ATT_ERR_INSUFFICIENT_RES;
- rc = BLE_HS_ENOMEM;
- goto done;
- }
-
- buf = os_mbuf_extend(txom, BLE_ATT_PREP_WRITE_CMD_BASE_SZ);
- if (buf == NULL) {
- att_err = BLE_ATT_ERR_INSUFFICIENT_RES;
- rc = BLE_HS_ENOMEM;
- goto done;
- }
- ble_att_prep_write_rsp_write(buf, BLE_ATT_PREP_WRITE_CMD_BASE_SZ, &req);
-
- rc = os_mbuf_appendfrom(txom, *rxom, 0, OS_MBUF_PKTLEN(*rxom));
- if (rc != 0) {
- att_err = BLE_ATT_ERR_INSUFFICIENT_RES;
- rc = BLE_HS_ENOMEM;
- goto done;
- }
+ /* Reuse rxom for response. Response is identical to request except for op
+ * code.
+ */
+ txom = *rxom;
+ *rxom = NULL;
+ txom->om_data[0] = BLE_ATT_OP_PREP_WRITE_RSP;
BLE_ATT_LOG_CMD(1, "prep write rsp", conn_handle,
ble_att_prep_write_cmd_log, &req);
[11/42] incubator-mynewt-core git commit: olimex-e407 - UART flow
control.
Posted by st...@apache.org.
olimex-e407 - UART flow control.
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/d6e6a6b3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/d6e6a6b3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/d6e6a6b3
Branch: refs/heads/sterly_refactor
Commit: d6e6a6b305c0714688c4b60ce150ed56b37c1ba8
Parents: c09231e
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Aug 2 12:40:19 2016 -0700
Committer: Sterling Hughes <st...@apache.org>
Committed: Tue Aug 9 16:05:21 2016 -0700
----------------------------------------------------------------------
hw/bsp/olimex_stm32-e407_devboard/src/hal_bsp.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d6e6a6b3/hw/bsp/olimex_stm32-e407_devboard/src/hal_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/olimex_stm32-e407_devboard/src/hal_bsp.c b/hw/bsp/olimex_stm32-e407_devboard/src/hal_bsp.c
index b10bad9..c0020e0 100644
--- a/hw/bsp/olimex_stm32-e407_devboard/src/hal_bsp.c
+++ b/hw/bsp/olimex_stm32-e407_devboard/src/hal_bsp.c
@@ -32,8 +32,8 @@ static const struct stm32f4_uart_cfg uart_cfg[UART_CNT] = {
.suc_rcc_dev = RCC_APB2ENR_USART6EN,
.suc_pin_tx = 38,
.suc_pin_rx = 39,
- .suc_pin_rts = -1,
- .suc_pin_cts = -1,
+ .suc_pin_rts = 34,
+ .suc_pin_cts = 35,
.suc_pin_af = GPIO_AF8_USART6,
.suc_irqn = USART6_IRQn
}