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 2016/04/20 03:17:49 UTC

[7/7] incubator-mynewt-core git commit: Update example apps to account for blehost changes

Update example apps to account for blehost 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/7235e90a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/7235e90a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/7235e90a

Branch: refs/heads/develop
Commit: 7235e90ad0fdbe44faa2afce0130c3f1cdc782d7
Parents: e32f9f9
Author: Christopher Collins <cc...@apache.org>
Authored: Fri Apr 15 21:04:28 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Apr 19 18:11:03 2016 -0700

----------------------------------------------------------------------
 apps/bleprph/src/main.c                 |   8 +-
 apps/bletest/src/main.c                 |  92 +++++----------------
 apps/bletiny/src/main.c                 | 114 ++++++---------------------
 net/nimble/host/include/host/host_hci.h |   1 +
 net/nimble/host/src/ble_hci_util.c      |  29 +++++++
 net/nimble/host/src/ble_hci_util.h      |   1 +
 net/nimble/host/src/host_hci_cmd.c      |  32 +++++++-
 net/nimble/include/nimble/hci_common.h  |   3 +-
 8 files changed, 110 insertions(+), 170 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7235e90a/apps/bleprph/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bleprph/src/main.c b/apps/bleprph/src/main.c
index e99c624..a9d8657 100755
--- a/apps/bleprph/src/main.c
+++ b/apps/bleprph/src/main.c
@@ -191,9 +191,6 @@ bleprph_task_handler(void *unused)
      */
     gatt_svr_init();
 
-    /* Initialize eventq */
-    os_eventq_init(&bleprph_evq);
-
     /* Begin advertising. */
     bleprph_advertise();
 
@@ -283,7 +280,10 @@ main(void)
     cfg.max_l2cap_chans = 3;
     cfg.max_l2cap_sig_procs = 2;
 
-    rc = ble_hs_init(BLEPRPH_BLE_HS_PRIO, &cfg);
+    /* Initialize eventq */
+    os_eventq_init(&bleprph_evq);
+
+    rc = ble_hs_init(&bleprph_evq, &cfg);
     assert(rc == 0);
 
     /* Initialize the console (for log output). */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7235e90a/apps/bletest/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletest/src/main.c b/apps/bletest/src/main.c
index 254abcb..d66a91a 100755
--- a/apps/bletest/src/main.c
+++ b/apps/bletest/src/main.c
@@ -223,7 +223,6 @@ bletest_inc_adv_pkt_num(void)
 
         rc = host_hci_cmd_le_set_adv_data(g_host_adv_data, g_host_adv_len);
         assert(rc == 0);
-        host_hci_outstanding_opcode = 0;
     }
 }
 #endif
@@ -244,7 +243,6 @@ bletest_send_conn_update(uint16_t handle)
 
     rc = host_hci_cmd_le_conn_update(&hcu);
     assert(rc == 0);
-    host_hci_outstanding_opcode = 0;
 }
 
 #ifdef BLE_LL_CFG_FEAT_LE_ENCRYPTION
@@ -258,7 +256,6 @@ void
 bletest_send_ltk_req_neg_reply(uint16_t handle)
 {
     host_hci_cmd_le_lt_key_req_neg_reply(handle);
-    host_hci_outstanding_opcode = 0;
 }
 
 void
@@ -269,7 +266,6 @@ 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_le_lt_key_req_reply(&hkr);
-    host_hci_outstanding_opcode = 0;
 }
 #endif
 
@@ -368,7 +364,6 @@ bletest_init_advertising(void)
     /* Set the advertising parameters */
     rc = host_hci_cmd_le_set_adv_params(&adv);
     assert(rc == 0);
-    host_hci_outstanding_opcode = 0;
 
     /* If we are using a random address, we need to set it */
     if (adv.own_addr_type == BLE_HCI_ADV_OWN_ADDR_RANDOM) {
@@ -376,19 +371,16 @@ bletest_init_advertising(void)
         rand_addr[5] |= 0xc0;
         rc = host_hci_cmd_le_set_rand_addr(rand_addr);
         assert(rc == 0);
-        host_hci_outstanding_opcode = 0;
     }
 
     /* Set advertising data */
     if (adv_len != 0) {
         rc = host_hci_cmd_le_set_adv_data(&g_host_adv_data[0], adv_len);
         assert(rc == 0);
-        host_hci_outstanding_opcode = 0;
 
         /* Set scan response data */
         rc = host_hci_cmd_le_set_scan_rsp_data(&g_host_adv_data[0], adv_len);
         assert(rc == 0);
-        host_hci_outstanding_opcode = 0;
     }
 }
 #endif
@@ -408,7 +400,6 @@ bletest_init_scanner(void)
                                          BLE_HCI_ADV_OWN_ADDR_PUBLIC,
                                          BLETEST_CFG_SCAN_FILT_POLICY);
     assert(rc == 0);
-    host_hci_outstanding_opcode = 0;
 
     filter_policy = BLETEST_CFG_SCAN_FILT_POLICY;
     if (filter_policy & 1) {
@@ -421,7 +412,6 @@ bletest_init_scanner(void)
         dev_addr[5] = 0x08;
         rc = host_hci_cmd_le_add_to_whitelist(dev_addr, BLE_ADDR_TYPE_PUBLIC);
         assert(rc == 0);
-        host_hci_outstanding_opcode = 0;
     }
 }
 
@@ -435,12 +425,10 @@ bletest_execute_scanner(void)
         if (g_bletest_state) {
             rc = host_hci_cmd_le_set_scan_enable(0, BLETEST_CFG_FILT_DUP_ADV);
             assert(rc == 0);
-            host_hci_outstanding_opcode = 0;
             g_bletest_state = 0;
         } else {
             rc = host_hci_cmd_le_set_scan_enable(1, BLETEST_CFG_FILT_DUP_ADV);
             assert(rc == 0);
-            host_hci_outstanding_opcode = 0;
             g_bletest_state = 1;
         }
         g_next_os_time += (OS_TICKS_PER_SEC * 60);
@@ -485,12 +473,10 @@ bletest_init_initiator(void)
         rand_addr[5] |= 0xc0;
         rc = host_hci_cmd_le_set_rand_addr(rand_addr);
         assert(rc == 0);
-        host_hci_outstanding_opcode = 0;
     }
 
     rc = host_hci_cmd_le_create_connection(hcc);
     assert(rc == 0);
-    host_hci_outstanding_opcode = 0;
 }
 
 void
@@ -513,11 +499,9 @@ bletest_execute_initiator(void)
 
             /* Ask for version information */
             rc = host_hci_cmd_rd_rem_version(handle);
-            host_hci_outstanding_opcode = 0;
 
             /* Ask for remote used features */
             rc = host_hci_cmd_le_read_rem_used_feat(handle);
-            host_hci_outstanding_opcode = 0;
 
             /* Scanning better be stopped! */
             assert(ble_ll_scan_enabled() == 0);
@@ -541,7 +525,6 @@ bletest_execute_initiator(void)
                 for (i = 0; i < g_bletest_current_conns; ++i) {
                     if (ble_ll_conn_find_active_conn(i + 1)) {
                         host_hci_cmd_le_rd_chanmap(i+1);
-                        host_hci_outstanding_opcode = 0;
                     }
                 }
             } else if (g_bletest_state == 2) {
@@ -551,7 +534,6 @@ bletest_execute_initiator(void)
                 new_chan_map[3] = 0x1F;
                 new_chan_map[4] = 0;
                 host_hci_cmd_le_set_host_chan_class(new_chan_map);
-                host_hci_outstanding_opcode = 0;
             } else if (g_bletest_state == 4) {
 #ifdef BLE_LL_CFG_FEAT_LE_ENCRYPTION
                 struct hci_start_encrypt hsle;
@@ -563,7 +545,6 @@ bletest_execute_initiator(void)
                         swap_buf(hsle.long_term_key, (uint8_t *)g_bletest_LTK,
                                  16);
                         host_hci_cmd_le_start_encrypt(&hsle);
-                        host_hci_outstanding_opcode = 0;
                     }
                 }
 #endif
@@ -571,7 +552,6 @@ bletest_execute_initiator(void)
                 for (i = 0; i < g_bletest_current_conns; ++i) {
                     if (ble_ll_conn_find_active_conn(i + 1)) {
                         host_hci_cmd_read_rssi(i+1);
-                        host_hci_outstanding_opcode = 0;
                     }
                 }
             }
@@ -639,14 +619,12 @@ bletest_execute_advertiser(void)
 
             /* Send the remote used features command */
             rc = host_hci_cmd_le_read_rem_used_feat(handle);
-            host_hci_outstanding_opcode = 0;
             if (rc) {
                 return;
             }
 
             /* Send the remote read version command */
             rc = host_hci_cmd_rd_rem_version(handle);
-            host_hci_outstanding_opcode = 0;
             if (rc) {
                 return;
             }
@@ -665,7 +643,6 @@ bletest_execute_advertiser(void)
                 g_dev_addr[5] += 1;
                 bletest_init_advertising();
                 rc = host_hci_cmd_le_set_adv_enable(1);
-                host_hci_outstanding_opcode = 0;
             }
         }
     }
@@ -860,7 +837,6 @@ bletest_task_handler(void *arg)
     rc = host_hci_cmd_send(BLE_HCI_OGF_CTLR_BASEBAND, BLE_HCI_OCF_CB_RESET,
                            0, NULL);
     assert(rc == 0);
-    host_hci_outstanding_opcode = 0;
 
 #if (BLETEST_CFG_ROLE == BLETEST_ROLE_ADVERTISER)
     /* Initialize the advertiser */
@@ -884,78 +860,64 @@ bletest_task_handler(void *arg)
     event_mask = 0x7FF;
     rc = host_hci_cmd_le_set_event_mask(event_mask);
     assert(rc == 0);
-    host_hci_outstanding_opcode = 0;
 
     /* Turn on all events */
     event_mask = 0xffffffffffffffff;
     rc = host_hci_cmd_set_event_mask(event_mask);
     assert(rc == 0);
-    host_hci_outstanding_opcode = 0;
 
     /* Read device address */
     rc = host_hci_cmd_rd_bd_addr();
     assert(rc == 0);
-    host_hci_outstanding_opcode = 0;
 
     /* Read local features */
     rc = host_hci_cmd_rd_local_feat();
     assert(rc == 0);
-    host_hci_outstanding_opcode = 0;
 
     /* Read local commands */
     rc = host_hci_cmd_rd_local_cmd();
     assert(rc == 0);
-    host_hci_outstanding_opcode = 0;
 
     /* Read version */
     rc = host_hci_cmd_rd_local_version();
     assert(rc == 0);
-    host_hci_outstanding_opcode = 0;
 
     /* Read supported states */
     rc = host_hci_cmd_le_read_supp_states();
     assert(rc == 0);
-    host_hci_outstanding_opcode = 0;
 
     /* Read maximum data length */
     rc = host_hci_cmd_le_read_max_datalen();
     assert(rc == 0);
-    host_hci_outstanding_opcode = 0;
 
     /* Read suggested data length */
     rc = host_hci_cmd_le_read_sugg_datalen();
     assert(rc == 0);
-    host_hci_outstanding_opcode = 0;
 
     /* write suggested default data length */
     rc = host_hci_cmd_le_write_sugg_datalen(BLETEST_CFG_SUGG_DEF_TXOCTETS,
                                             BLETEST_CFG_SUGG_DEF_TXTIME);
     assert(rc == 0);
-    host_hci_outstanding_opcode = 0;
 
     /* Read suggested data length */
     rc = host_hci_cmd_le_read_sugg_datalen();
     assert(rc == 0);
-    host_hci_outstanding_opcode = 0;
 
     /* Set data length (note: we know there is no connection; just a test) */
     rc = host_hci_cmd_le_set_datalen(0x1234,
                                      BLETEST_CFG_SUGG_DEF_TXOCTETS,
                                      BLETEST_CFG_SUGG_DEF_TXTIME);
     assert(rc == 0);
-    host_hci_outstanding_opcode = 0;
 
 
     /* Encrypt a block */
     rc = host_hci_cmd_le_encrypt((uint8_t *)g_ble_ll_encrypt_test_key,
                                  (uint8_t *)g_ble_ll_encrypt_test_plain_text);
     assert(rc == 0);
-    host_hci_outstanding_opcode = 0;
 
     /* Get a random number */
     rc = host_hci_cmd_le_rand();
     assert(rc == 0);
-    host_hci_outstanding_opcode = 0;
 
     /* Wait some time before starting */
     os_time_delay(OS_TICKS_PER_SEC);
@@ -967,7 +929,6 @@ bletest_task_handler(void *arg)
 #if (BLETEST_CFG_ROLE == BLETEST_ROLE_ADVERTISER)
     rc = host_hci_cmd_le_set_adv_enable(1);
     assert(rc == 0);
-    host_hci_outstanding_opcode = 0;
 #endif
 
     bletest_timer_cb(NULL);
@@ -988,34 +949,6 @@ bletest_task_handler(void *arg)
 }
 
 /**
- * init_tasks
- *
- * Called by main.c after os_init(). This function performs initializations
- * that are required before tasks are running.
- *
- * @return int 0 success; error otherwise.
- */
-static int
-init_tasks(void)
-{
-    int rc;
-
-    os_task_init(&bletest_task, "bletest", bletest_task_handler, NULL,
-                 BLETEST_TASK_PRIO, OS_WAIT_FOREVER, bletest_stack,
-                 BLETEST_STACK_SIZE);
-
-    /* Initialize host HCI */
-    rc = ble_hs_init(HOST_TASK_PRIO, NULL);
-    assert(rc == 0);
-
-    /* Initialize the BLE LL */
-    rc = ble_ll_init(BLE_LL_TASK_PRI, MBUF_NUM_MBUFS, BLE_MBUF_PAYLOAD_SIZE);
-    assert(rc == 0);
-
-    return 0;
-}
-
-/**
  * main
  *
  * The main function for the project. This function initializes the os, calls
@@ -1123,19 +1056,34 @@ main(void)
     }
 #endif
 
-    shell_task_init(SHELL_TASK_PRIO, shell_stack, SHELL_TASK_STACK_SIZE,
+    rc = shell_task_init(SHELL_TASK_PRIO, shell_stack, SHELL_TASK_STACK_SIZE,
                          SHELL_MAX_INPUT_LEN);
+    assert(rc == 0);
+
+    rc = nmgr_task_init(NEWTMGR_TASK_PRIO, newtmgr_stack,
+                        NEWTMGR_TASK_STACK_SIZE);
+    assert(rc == 0);
 
-    nmgr_task_init(NEWTMGR_TASK_PRIO, newtmgr_stack, NEWTMGR_TASK_STACK_SIZE);
 #if 0
     imgmgr_module_init();
 #endif
 
     /* Init statistics module */
-    stats_module_init();
+    rc = stats_module_init();
+    assert(rc == 0);
 
-    /* Init tasks */
-    init_tasks();
+    /* Initialize the BLE LL */
+    rc = ble_ll_init(BLE_LL_TASK_PRI, MBUF_NUM_MBUFS, BLE_MBUF_PAYLOAD_SIZE);
+    assert(rc == 0);
+
+    /* Initialize host */
+    rc = ble_hs_init(&g_bletest_evq, NULL);
+    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);
+    assert(rc == 0);
 
     /* Start the OS */
     os_start();

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7235e90a/apps/bletiny/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/main.c b/apps/bletiny/src/main.c
index 2cec311..70193fc 100755
--- a/apps/bletiny/src/main.c
+++ b/apps/bletiny/src/main.c
@@ -47,16 +47,16 @@
  * app uses some of nimble's internal details for logging.
  */
 #include "../src/ble_hs_conn.h"
+#include "../src/ble_hci_util.h"
 
 #define BSWAP16(x)  ((uint16_t)(((x) << 8) | (((x) & 0xff00) >> 8)))
 
 /* Nimble task priorities */
 #define BLE_LL_TASK_PRI         (OS_TASK_PRI_HIGHEST)
-#define HOST_TASK_PRIO          (1)
 
 #define SHELL_TASK_PRIO         (3)
 #define SHELL_MAX_INPUT_LEN     (64)
-#define SHELL_TASK_STACK_SIZE   (OS_STACK_ALIGN(210))
+#define SHELL_TASK_STACK_SIZE   (OS_STACK_ALIGN(288))
 static bssnz_t os_stack_t shell_stack[SHELL_TASK_STACK_SIZE];
 
 static struct os_mutex bletiny_mutex;
@@ -85,8 +85,8 @@ struct os_mbuf_pool default_mbuf_pool;
 struct os_mempool default_mbuf_mpool;
 
 /* BLETINY variables */
-#define BLETINY_STACK_SIZE             (OS_STACK_ALIGN(210))
-#define BLETINY_TASK_PRIO              (HOST_TASK_PRIO + 1)
+#define BLETINY_STACK_SIZE             (OS_STACK_ALIGN(288))
+#define BLETINY_TASK_PRIO              1
 
 #if NIMBLE_OPT_ROLE_CENTRAL
 #define BLETINY_MAX_SVCS               32
@@ -98,7 +98,7 @@ struct os_mempool default_mbuf_mpool;
 #define BLETINY_MAX_DSCS               1
 #endif
 
-struct os_eventq g_bletiny_evq;
+struct os_eventq bletiny_evq;
 struct os_task bletiny_task;
 bssnz_t os_stack_t bletiny_stack[BLETINY_STACK_SIZE];
 
@@ -136,7 +136,7 @@ uint8_t bletiny_gatt_service_changed[4];
 #ifdef DEVICE_NAME
 #define BLETINY_AUTO_DEVICE_NAME    XSTR(DEVICE_NAME)
 #else
-#define BLETINY_AUTO_DEVICE_NAME    NULL
+#define BLETINY_AUTO_DEVICE_NAME    ""
 #endif
 
 void
@@ -684,11 +684,10 @@ bletiny_dsc_add(uint16_t conn_handle, uint16_t chr_def_handle,
 static void
 bletiny_start_auto_advertise(void)
 {
-#if 0
     struct ble_hs_adv_fields fields;
     int rc;
 
-    if (BLETINY_AUTO_DEVICE_NAME != NULL) {
+    if (BLETINY_AUTO_DEVICE_NAME[0] != '\0') {
         memset(&fields, 0, sizeof fields);
 
         fields.name = (uint8_t *)BLETINY_AUTO_DEVICE_NAME;
@@ -705,7 +704,6 @@ bletiny_start_auto_advertise(void)
             return;
         }
     }
-#endif
 }
 
 static int
@@ -805,32 +803,6 @@ bletiny_on_read(uint16_t conn_handle, struct ble_gatt_error *error,
 }
 
 static int
-bletiny_on_read_mult(uint16_t conn_handle, struct ble_gatt_error *error,
-                      uint16_t *attr_handles, uint8_t num_attr_handles,
-                      uint8_t *attr_data, uint16_t attr_data_len, void *arg)
-{
-    int i;
-
-    if (error != NULL) {
-        bletiny_print_error("ERROR READING CHARACTERISTICS", conn_handle,
-                             error);
-    } else {
-        console_printf("multiple characteristic read complete; conn_handle=%d "
-                       "attr_handles=", conn_handle);
-        for (i = 0; i < num_attr_handles; i++) {
-            console_printf("%s%d", i != 0 ? "," : "", attr_handles[i]);
-        }
-
-        console_printf(" len=%d value=", attr_data_len);
-        bletiny_print_bytes(attr_data, attr_data_len);
-        console_printf("\n");
-    }
-
-    return 0;
-
-}
-
-static int
 bletiny_on_write(uint16_t conn_handle, struct ble_gatt_error *error,
                   struct ble_gatt_attr *attr, void *arg)
 {
@@ -977,27 +949,6 @@ bletiny_on_scan(int event, int status, struct ble_gap_disc_desc *desc,
     }
 }
 
-#if 0
-static void
-bletiny_on_rx_rssi(struct ble_hci_ack *ack, void *unused)
-{
-    struct hci_read_rssi_ack_params params;
-
-    if (ack->bha_params_len != BLE_HCI_READ_RSSI_ACK_PARAM_LEN) {
-        console_printf("invalid rssi response; len=%d\n",
-                       ack->bha_params_len);
-        return;
-    }
-
-    params.status = ack->bha_params[0];
-    params.connection_handle = le16toh(ack->bha_params + 1);
-    params.rssi = ack->bha_params[3];
-
-    console_printf("rssi response received; status=%d conn=%d rssi=%d\n",
-                   params.status, params.connection_handle, params.rssi);
-}
-#endif
-
 int
 bletiny_exchange_mtu(uint16_t conn_handle)
 {
@@ -1111,7 +1062,7 @@ bletiny_read_mult(uint16_t conn_handle, uint16_t *attr_handles,
     int rc;
 
     rc = ble_gattc_read_mult(conn_handle, attr_handles, num_attr_handles,
-                             bletiny_on_read_mult, NULL);
+                             bletiny_on_read, NULL);
     return rc;
 }
 
@@ -1137,8 +1088,8 @@ bletiny_write_no_rsp(uint16_t conn_handle, uint16_t attr_handle, void *value,
 {
     int rc;
 
-    rc = ble_gattc_write_no_rsp(conn_handle, attr_handle, value, value_len,
-                                bletiny_on_write, NULL);
+    rc = ble_gattc_write_no_rsp(conn_handle, attr_handle, value, value_len);
+
     return rc;
 }
 
@@ -1268,41 +1219,20 @@ bletiny_l2cap_update(uint16_t conn_handle,
     return rc;
 }
 
-#if 0
-static int
-bletiny_tx_rssi_req(void *arg)
-{
-    intptr_t conn_handle;
-    int rc;
-
-    conn_handle = (intptr_t)arg;
-
-    ble_hci_sched_set_ack_cb(bletiny_on_rx_rssi, NULL);
-
-    rc = host_hci_cmd_read_rssi(conn_handle);
-    if (rc != 0) {
-        console_printf("failure to send rssi hci cmd; rc=%d\n", rc);
-        return rc;
-    }
-
-    return 0;
-}
-#endif
-
 int
 bletiny_show_rssi(uint16_t conn_handle)
 {
-#if 0
+    int8_t rssi;
     int rc;
 
-    rc = ble_hci_sched_enqueue(bletiny_tx_rssi_req,
-                               (void *)(intptr_t)conn_handle, NULL);
+    rc = ble_hci_util_read_rssi(conn_handle, &rssi);
     if (rc != 0) {
-        console_printf("failure to enqueue rssi hci cmd; rc=%d\n", rc);
+        console_printf("failure to read rssi; rc=%d\n", rc);
         return rc;
     }
 
-#endif
+    console_printf("rssi=%d\n", rssi);
+
     return 0;
 }
 
@@ -1327,20 +1257,21 @@ bletiny_sec_start(uint16_t conn_handle)
 static void
 bletiny_task_handler(void *arg)
 {
-    struct os_event *ev;
     struct os_callout_func *cf;
+    struct os_event *ev;
+    int rc;
+
+    rc = ble_hs_start();
+    assert(rc == 0);
 
     periph_init();
 
     ble_att_set_notify_cb(bletiny_on_notify, NULL);
 
-    /* Initialize eventq */
-    os_eventq_init(&g_bletiny_evq);
-
     bletiny_start_auto_advertise();
 
     while (1) {
-        ev = os_eventq_get(&g_bletiny_evq);
+        ev = os_eventq_get(&bletiny_evq);
         switch (ev->ev_type) {
         case OS_EVENT_T_TIMER:
             cf = (struct os_callout_func *)ev;
@@ -1435,6 +1366,7 @@ main(void)
     log_console_handler_init(&bletiny_log_console_handler);
     log_register("bletiny", &bletiny_log, &bletiny_log_console_handler);
 
+    os_eventq_init(&bletiny_evq);
     os_task_init(&bletiny_task, "bletiny", bletiny_task_handler,
                  NULL, BLETINY_TASK_PRIO, OS_WAIT_FOREVER,
                  bletiny_stack, BLETINY_STACK_SIZE);
@@ -1460,7 +1392,7 @@ main(void)
     cfg.max_l2cap_chans = 3;
     cfg.max_l2cap_sig_procs = 2;
 
-    rc = ble_hs_init(HOST_TASK_PRIO, &cfg);
+    rc = ble_hs_init(&bletiny_evq, &cfg);
     assert(rc == 0);
 
     /* Initialize the BLE LL */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7235e90a/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 1a15f01..1b8d61f 100644
--- a/net/nimble/host/include/host/host_hci.h
+++ b/net/nimble/host/include/host/host_hci.h
@@ -41,6 +41,7 @@ int host_hci_cmd_rd_local_version(void);
 int host_hci_cmd_rd_local_feat(void);
 int host_hci_cmd_rd_local_cmd(void);
 int host_hci_cmd_rd_bd_addr(void);
+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_le_set_host_chan_class(uint8_t *new_chan_map);
 int host_hci_cmd_le_rd_chanmap(uint16_t handle);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7235e90a/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
index 2ff159d..9216377 100644
--- a/net/nimble/host/src/ble_hci_util.c
+++ b/net/nimble/host/src/ble_hci_util.c
@@ -76,3 +76,32 @@ ble_hci_util_rand(void *dst, int len)
 
     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_tx_cmd(buf, params, 1, &params_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;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7235e90a/net/nimble/host/src/ble_hci_util.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hci_util.h b/net/nimble/host/src/ble_hci_util.h
index c259d6d..f73dd47 100644
--- a/net/nimble/host/src/ble_hci_util.h
+++ b/net/nimble/host/src/ble_hci_util.h
@@ -22,5 +22,6 @@
 
 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);
 
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7235e90a/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 180571d..8ed0395 100644
--- a/net/nimble/host/src/host_hci_cmd.c
+++ b/net/nimble/host/src/host_hci_cmd.c
@@ -1508,14 +1508,42 @@ host_hci_cmd_le_start_encrypt(struct hci_start_encrypt *cmd)
  *
  * @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);
+}
+
+/**
+ * Read the RSSI for a given connection handle
+ *
+ * NOTE: OGF=0x05 OCF=0x0005
+ *
+ * @param handle
+ *
+ * @return int
+ */
 int
 host_hci_cmd_read_rssi(uint16_t handle)
 {
+    uint8_t cmd[BLE_HCI_READ_RSSI_LEN];
     int rc;
-    uint8_t cmd[sizeof(uint16_t)];
 
     htole16(cmd, handle);
     rc = host_hci_cmd_send(BLE_HCI_OGF_STATUS_PARAMS, BLE_HCI_OCF_RD_RSSI,
-                           sizeof(uint16_t), cmd);
+                           BLE_HCI_READ_RSSI_LEN, cmd);
     return rc;
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7235e90a/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 2d43652..499a898 100644
--- a/net/nimble/include/nimble/hci_common.h
+++ b/net/nimble/include/nimble/hci_common.h
@@ -135,7 +135,8 @@
 #define BLE_HCI_RD_LOC_SUPP_CMD_RSPLEN      (64)
 
 /* --- Read RSSI (OGF 0x05, OCF 0x0005) --- */
-#define BLE_HCI_READ_RSSI_ACK_PARAM_LEN     (4)  /* Includes status byte. */
+#define BLE_HCI_READ_RSSI_LEN               (2)
+#define BLE_HCI_READ_RSSI_ACK_PARAM_LEN     (3)  /* No status byte. */
 
 /* --- LE set event mask (OCF 0x0001) --- */
 #define BLE_HCI_SET_LE_EVENT_MASK_LEN       (8)