You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2015/11/26 02:24:56 UTC
incubator-mynewt-larva git commit: Read buffer size HCI command.
Repository: incubator-mynewt-larva
Updated Branches:
refs/heads/master b544c2a12 -> 2cf8182d0
Read buffer size HCI command.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/commit/2cf8182d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/2cf8182d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/2cf8182d
Branch: refs/heads/master
Commit: 2cf8182d05eb6b0a553fa31a7be74ea196db8dd5
Parents: b544c2a
Author: Christopher Collins <cc...@gmail.com>
Authored: Wed Nov 25 17:24:43 2015 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Wed Nov 25 17:24:43 2015 -0800
----------------------------------------------------------------------
net/nimble/host/include/host/host_hci.h | 2 ++
net/nimble/host/src/ble_hs_ack.c | 3 ++
net/nimble/host/src/ble_hs_att_svr.c | 30 +++++++++---------
net/nimble/host/src/host_hci.c | 46 ++++++++++++++++++++++++++++
net/nimble/host/src/host_hci_cmd.c | 9 ++++++
5 files changed, 74 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/2cf8182d/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 e8efbfc..154e34f 100644
--- a/net/nimble/host/include/host/host_hci.h
+++ b/net/nimble/host/include/host/host_hci.h
@@ -21,6 +21,7 @@
struct ble_hs_conn;
struct os_mbuf;
+int host_hci_read_buf_size(void);
int host_hci_os_event_proc(struct os_event *ev);
int host_hci_event_rx(uint8_t *data);
int host_hci_cmd_le_set_scan_rsp_data(uint8_t *data, uint8_t len);
@@ -28,6 +29,7 @@ int host_hci_cmd_le_set_adv_data(uint8_t *data, uint8_t len);
int host_hci_cmd_le_set_adv_params(struct hci_adv_params *adv);
int host_hci_cmd_le_set_rand_addr(uint8_t *addr);
int host_hci_cmd_le_set_event_mask(uint64_t event_mask);
+int host_hci_cmd_le_read_buffer_size(void);
int host_hci_cmd_le_set_adv_enable(uint8_t enable);
int host_hci_cmd_le_set_scan_params(uint8_t scan_type, uint16_t scan_itvl,
uint16_t scan_window, uint8_t own_addr_type,
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/2cf8182d/net/nimble/host/src/ble_hs_ack.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_ack.c b/net/nimble/host/src/ble_hs_ack.c
index 5a9e2d0..34ad280 100644
--- a/net/nimble/host/src/ble_hs_ack.c
+++ b/net/nimble/host/src/ble_hs_ack.c
@@ -42,6 +42,9 @@ ble_hs_ack_rx(struct ble_hs_ack *ack)
void
ble_hs_ack_set_callback(ble_hs_ack_fn *cb, void *arg)
{
+ /* Don't allow the current callback to be replaced with another. */
+ assert(ble_hs_ack_cb == NULL || cb == NULL);
+
ble_hs_ack_cb = cb;
ble_hs_ack_arg = arg;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/2cf8182d/net/nimble/host/src/ble_hs_att_svr.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_att_svr.c b/net/nimble/host/src/ble_hs_att_svr.c
index 721bf34..b915110 100644
--- a/net/nimble/host/src/ble_hs_att_svr.c
+++ b/net/nimble/host/src/ble_hs_att_svr.c
@@ -243,11 +243,11 @@ ble_hs_att_svr_match_handle(struct ble_hs_att_svr_entry *ha, void *arg)
/**
* Find a host attribute by handle id.
*
- * @param handle_id The handle_id to search for
- * @param ble_hs_att A pointer to a pointer to put the matching host attr into.
+ * @param handle_id The handle_id to search for
+ * @param ha_ptr A pointer to a pointer to put the matching host
+ * attr into.
*
- * @return 0 on success, BLE_ERR_ATTR_NOT_FOUND on not found, and non-zero on
- * error.
+ * @return 0 on success; ENOENT on not found.
*/
int
ble_hs_att_svr_find_by_handle(uint16_t handle_id,
@@ -282,11 +282,11 @@ ble_hs_att_svr_match_uuid(struct ble_hs_att_svr_entry *ha, void *arg)
/**
* Find a host attribute by UUID.
*
- * @param uuid The ble_uuid_t to search for
- * @param ha_ptr A pointer to a pointer to put the matching host attr into.
+ * @param uuid The ble_uuid_t to search for
+ * @param ha_ptr A pointer to a pointer to put the matching host
+ * attr into.
*
- * @return 0 on success, BLE_ERR_ATTR_NOT_FOUND on not found, and non-zero on
- * error.
+ * @return 0 on success; ENOENT on not found.
*/
int
ble_hs_att_svr_find_by_uuid(uint8_t *uuid,
@@ -297,12 +297,10 @@ ble_hs_att_svr_find_by_uuid(uint8_t *uuid,
rc = ble_hs_att_svr_walk(ble_hs_att_svr_match_uuid, uuid, ha_ptr);
if (rc == 1) {
/* Found a matching handle */
- return (0);
- } else if (rc == 0) {
- /* No match */
- return (BLE_ERR_ATTR_NOT_FOUND);
+ return 0;
} else {
- return (rc);
+ /* No match */
+ return ENOENT;
}
}
@@ -1170,13 +1168,13 @@ ble_hs_att_svr_rx_read(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan,
}
if (entry->ha_fn == NULL) {
- rc = BLE_ERR_UNSPECIFIED;
+ rc = BLE_HS_ATT_ERR_UNLIKELY;
goto err;
}
rc = entry->ha_fn(entry, BLE_HS_ATT_OP_READ_REQ, &arg);
if (rc != 0) {
- rc = BLE_ERR_UNSPECIFIED;
+ rc = BLE_HS_ATT_ERR_UNLIKELY;
goto err;
}
@@ -1255,7 +1253,7 @@ ble_hs_att_svr_rx_write(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan,
}
if (entry->ha_fn == NULL) {
- rc = BLE_ERR_UNSPECIFIED;
+ rc = BLE_HS_ATT_ERR_UNLIKELY;
goto send_err;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/2cf8182d/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 4361a9a..2b33b02 100644
--- a/net/nimble/host/src/host_hci.c
+++ b/net/nimble/host/src/host_hci.c
@@ -22,6 +22,7 @@
#include "console/console.h"
#include "nimble/hci_common.h"
#include "nimble/hci_transport.h"
+#include "host/host_hci.h"
#include "host/ble_hs.h"
#include "host_dbg.h"
#include "ble_hs_conn.h"
@@ -54,6 +55,9 @@ struct os_mempool g_hci_os_event_pool;
os_membuf_t g_hci_os_event_buf[OS_MEMPOOL_SIZE(HCI_NUM_OS_EVENTS,
HCI_OS_EVENT_BUF_SIZE)];
+static uint16_t host_hci_buffer_sz;
+static uint8_t host_hci_max_pkts;
+
/* Statistics */
struct host_hci_stats
{
@@ -299,6 +303,48 @@ host_hci_rx_le_conn_complete(uint8_t subevent, uint8_t *data, int len)
return 0;
}
+static void
+host_hci_rx_read_buf_size_ack(struct ble_hs_ack *ack, void *arg)
+{
+ uint16_t pktlen;
+ uint8_t max_pkts;
+
+ if (ack->bha_status != 0) {
+ /* XXX: Log / stat this. */
+ return;
+ }
+
+ if (ack->bha_params_len != BLE_HCI_RD_BUF_SIZE_RSPLEN + 1) {
+ /* XXX: Log / stat this. */
+ return;
+ }
+
+ pktlen = le16toh(ack->bha_params + 1);
+ max_pkts = ack->bha_params[3];
+
+ if (pktlen == 0 || max_pkts == 0) {
+ /* XXX: Send BR command instead. */
+ return;
+ }
+
+ host_hci_buffer_sz = pktlen;
+ host_hci_max_pkts = max_pkts;
+}
+
+int
+host_hci_read_buf_size(void)
+{
+ int rc;
+
+ ble_hs_ack_set_callback(host_hci_rx_read_buf_size_ack, NULL);
+ rc = host_hci_cmd_le_read_buffer_size();
+ if (rc != 0) {
+ return rc;
+ }
+
+ return 0;
+}
+
int
host_hci_event_rx(uint8_t *data)
{
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/2cf8182d/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 2b4fd36..b9f6567 100644
--- a/net/nimble/host/src/host_hci_cmd.c
+++ b/net/nimble/host/src/host_hci_cmd.c
@@ -212,6 +212,15 @@ host_hci_cmd_le_set_event_mask(uint64_t event_mask)
}
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;
+}
+
+int
host_hci_cmd_le_set_adv_enable(uint8_t enable)
{
int rc;