mynewt-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sterl...@apache.org
Subject [6/6] incubator-mynewt-larva git commit: rename project to app
Date Sat, 05 Mar 2016 02:39:20 GMT
rename project to app


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/dd032817
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/dd032817
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/dd032817

Branch: refs/heads/rename_project_app
Commit: dd0328178651f010266bef5e56e88a4a6654bbd2
Parents: 22c393a
Author: Sterling Hughes <sterling@apache.org>
Authored: Fri Mar 4 18:38:19 2016 -0800
Committer: Sterling Hughes <sterling@apache.org>
Committed: Fri Mar 4 18:38:19 2016 -0800

----------------------------------------------------------------------
 .gitignore                         |    3 +-
 app.yml                            |   20 -
 apps/bleprph/src/bleprph.h         |   43 +
 apps/bleprph/src/gatt_svr.c        |  342 +++++++
 apps/bleprph/src/main.c            |  299 +++++++
 apps/bletest/pkg.yml               |   40 +
 apps/bletest/src/main.c            |  969 ++++++++++++++++++++
 apps/bletiny/pkg.yml               |   33 +
 apps/bletiny/src/bletiny_priv.h    |  169 ++++
 apps/bletiny/src/cmd.c             | 1479 +++++++++++++++++++++++++++++++
 apps/bletiny/src/main.c            | 1467 ++++++++++++++++++++++++++++++
 apps/bletiny/src/parse.c           |  435 +++++++++
 apps/bletiny/src/periph.c          |  344 +++++++
 apps/blinky/pkg.yml                |   35 +
 apps/blinky/src/main.c             |  200 +++++
 apps/boot/pkg.yml                  |   37 +
 apps/boot/src/boot.c               |  110 +++
 apps/ffs2native/pkg.yml            |   32 +
 apps/ffs2native/src/main.c         |  366 ++++++++
 apps/luatest/pkg.yml               |   32 +
 apps/luatest/src/main.c            |  115 +++
 apps/slinky/pkg.yml                |   40 +
 apps/slinky/src/main.c             |  296 +++++++
 apps/test/pkg.yml                  |   40 +
 apps/test/src/test.c               |   44 +
 project.yml                        |   20 +
 project/bleprph/src/bleprph.h      |   43 -
 project/bleprph/src/gatt_svr.c     |  342 -------
 project/bleprph/src/main.c         |  299 -------
 project/bletest/pkg.yml            |   40 -
 project/bletest/src/main.c         |  969 --------------------
 project/bletiny/pkg.yml            |   33 -
 project/bletiny/src/bletiny_priv.h |  169 ----
 project/bletiny/src/cmd.c          | 1479 -------------------------------
 project/bletiny/src/main.c         | 1467 ------------------------------
 project/bletiny/src/parse.c        |  435 ---------
 project/bletiny/src/periph.c       |  344 -------
 project/blinky/pkg.yml             |   35 -
 project/blinky/src/main.c          |  200 -----
 project/boot/pkg.yml               |   37 -
 project/boot/src/boot.c            |  110 ---
 project/ffs2native/pkg.yml         |   32 -
 project/ffs2native/src/main.c      |  366 --------
 project/luatest/pkg.yml            |   32 -
 project/luatest/src/main.c         |  115 ---
 project/slinky/pkg.yml             |   40 -
 project/slinky/src/main.c          |  296 -------
 project/test/pkg.yml               |   40 -
 project/test/src/test.c            |   44 -
 49 files changed, 6988 insertions(+), 6989 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/dd032817/.gitignore
----------------------------------------------------------------------
diff --git a/.gitignore b/.gitignore
index d8910f3..1464298 100644
--- a/.gitignore
+++ b/.gitignore
@@ -17,8 +17,7 @@
 # under the License.
 #
 
-.app.db
-.app
+.project
 bin
 obj
 tags

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/dd032817/app.yml
----------------------------------------------------------------------
diff --git a/app.yml b/app.yml
deleted file mode 100644
index 7e81eba..0000000
--- a/app.yml
+++ /dev/null
@@ -1,20 +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.
-#
-
-app.name: "larva"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/dd032817/apps/bleprph/src/bleprph.h
----------------------------------------------------------------------
diff --git a/apps/bleprph/src/bleprph.h b/apps/bleprph/src/bleprph.h
new file mode 100644
index 0000000..e903fe0
--- /dev/null
+++ b/apps/bleprph/src/bleprph.h
@@ -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.
+ */
+
+#ifndef H_BLEPRPH_
+#define H_BLEPRPH_
+
+#include "log/log.h"
+
+void gatt_svr_init(void);
+
+extern struct log bleprph_log;
+
+extern const char *bleprph_device_name;
+extern const uint16_t bleprph_appearance;
+extern const uint8_t bleprph_privacy_flag;
+extern uint8_t bleprph_reconnect_addr[6];
+extern uint8_t bleprph_pref_conn_params[8];
+extern uint8_t bleprph_gatt_service_changed[4];
+
+/* bleprph uses the first "peruser" log module. */
+#define BLEPRPH_LOG_MODULE  (LOG_MODULE_PERUSER + 0)
+
+/* Convenience macro for logging to the bleprph module. */
+#define BLEPRPH_LOG(lvl, ...) \
+    LOG_ ## lvl(&bleprph_log, BLEPRPH_LOG_MODULE, __VA_ARGS__)
+
+#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/dd032817/apps/bleprph/src/gatt_svr.c
----------------------------------------------------------------------
diff --git a/apps/bleprph/src/gatt_svr.c b/apps/bleprph/src/gatt_svr.c
new file mode 100644
index 0000000..27a1433
--- /dev/null
+++ b/apps/bleprph/src/gatt_svr.c
@@ -0,0 +1,342 @@
+/**
+ * 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 "bsp/bsp.h"
+#include "console/console.h"
+#include "host/ble_hs.h"
+#include "bleprph.h"
+
+#define GATT_SVR_SVC_ALERT_UUID               0x1811
+#define GATT_SVR_CHR_SUP_NEW_ALERT_CAT_UUID   0x2A47
+#define GATT_SVR_CHR_NEW_ALERT                0x2A46
+#define GATT_SVR_CHR_SUP_UNR_ALERT_CAT_UUID   0x2A48
+#define GATT_SVR_CHR_UNR_ALERT_STAT_UUID      0x2A45
+#define GATT_SVR_CHR_ALERT_NOT_CTRL_PT        0x2A44
+
+static int
+gatt_svr_chr_access_gap(uint16_t conn_handle, uint16_t attr_handle, uint8_t op,
+                        union ble_gatt_access_ctxt *ctxt, void *arg);
+static int
+gatt_svr_chr_access_gatt(uint16_t conn_handle, uint16_t attr_handle, uint8_t op,
+                         union ble_gatt_access_ctxt *ctxt, void *arg);
+static int
+gatt_svr_chr_access_alert(uint16_t conn_handle, uint16_t attr_handle,
+                          uint8_t op, union ble_gatt_access_ctxt *ctxt,
+                          void *arg);
+
+static const struct ble_gatt_svc_def gatt_svr_svcs[] = {
+    {
+        /*** Service: GAP. */
+        .type = BLE_GATT_SVC_TYPE_PRIMARY,
+        .uuid128 = BLE_UUID16(BLE_GAP_SVC_UUID16),
+        .characteristics = (struct ble_gatt_chr_def[]) { {
+            /*** Characteristic: Device Name. */
+            .uuid128 = BLE_UUID16(BLE_GAP_CHR_UUID16_DEVICE_NAME),
+            .access_cb = gatt_svr_chr_access_gap,
+            .flags = BLE_GATT_CHR_F_READ,
+        }, {
+            /*** Characteristic: Appearance. */
+            .uuid128 = BLE_UUID16(BLE_GAP_CHR_UUID16_APPEARANCE),
+            .access_cb = gatt_svr_chr_access_gap,
+            .flags = BLE_GATT_CHR_F_READ,
+        }, {
+            /*** Characteristic: Peripheral Privacy Flag. */
+            .uuid128 = BLE_UUID16(BLE_GAP_CHR_UUID16_PERIPH_PRIV_FLAG),
+            .access_cb = gatt_svr_chr_access_gap,
+            .flags = BLE_GATT_CHR_F_READ,
+        }, {
+            /*** Characteristic: Reconnection Address. */
+            .uuid128 = BLE_UUID16(BLE_GAP_CHR_UUID16_RECONNECT_ADDR),
+            .access_cb = gatt_svr_chr_access_gap,
+            .flags = BLE_GATT_CHR_F_WRITE,
+        }, {
+            /*** Characteristic: Peripheral Preferred Connection Parameters. */
+            .uuid128 = BLE_UUID16(BLE_GAP_CHR_UUID16_PERIPH_PREF_CONN_PARAMS),
+            .access_cb = gatt_svr_chr_access_gap,
+            .flags = BLE_GATT_CHR_F_READ,
+        }, {
+            0, /* No more characteristics in this service. */
+        } },
+    },
+
+    {
+        /*** Service: GATT */
+        .type = BLE_GATT_SVC_TYPE_PRIMARY,
+        .uuid128 = BLE_UUID16(BLE_GATT_SVC_UUID16),
+        .characteristics = (struct ble_gatt_chr_def[]) { {
+            .uuid128 = BLE_UUID16(BLE_GATT_CHR_SERVICE_CHANGED_UUID16),
+            .access_cb = gatt_svr_chr_access_gatt,
+            .flags = BLE_GATT_CHR_F_INDICATE,
+        }, {
+            0, /* No more characteristics in this service. */
+        } },
+    },
+
+    {
+        /*** Alert Notification Service. */
+        .type = BLE_GATT_SVC_TYPE_PRIMARY,
+        .uuid128 = BLE_UUID16(GATT_SVR_SVC_ALERT_UUID),
+        .characteristics = (struct ble_gatt_chr_def[]) { {
+            .uuid128 = BLE_UUID16(GATT_SVR_CHR_SUP_NEW_ALERT_CAT_UUID),
+            .access_cb = gatt_svr_chr_access_alert,
+            .flags = BLE_GATT_CHR_F_READ,
+        }, {
+            .uuid128 = BLE_UUID16(GATT_SVR_CHR_NEW_ALERT),
+            .access_cb = gatt_svr_chr_access_alert,
+            .flags = BLE_GATT_CHR_F_NOTIFY,
+        }, {
+            .uuid128 = BLE_UUID16(GATT_SVR_CHR_SUP_UNR_ALERT_CAT_UUID),
+            .access_cb = gatt_svr_chr_access_alert,
+            .flags = BLE_GATT_CHR_F_READ,
+        }, {
+            .uuid128 = BLE_UUID16(GATT_SVR_CHR_UNR_ALERT_STAT_UUID),
+            .access_cb = gatt_svr_chr_access_alert,
+            .flags = BLE_GATT_CHR_F_NOTIFY,
+        }, {
+            .uuid128 = BLE_UUID16(GATT_SVR_CHR_ALERT_NOT_CTRL_PT),
+            .access_cb = gatt_svr_chr_access_alert,
+            .flags = BLE_GATT_CHR_F_WRITE,
+        }, {
+            0, /* No more characteristics in this service. */
+        } },
+    },
+
+    {
+        0, /* No more services. */
+    },
+};
+
+static int
+gatt_svr_chr_write(uint8_t op, union ble_gatt_access_ctxt *ctxt,
+                   uint16_t min_len, uint16_t max_len, void *dst,
+                   uint16_t *len)
+{
+    assert(op == BLE_GATT_ACCESS_OP_WRITE_CHR);
+    if (ctxt->chr_access.len < min_len ||
+        ctxt->chr_access.len > max_len) {
+        return BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN;
+    }
+    memcpy(dst, ctxt->chr_access.data, ctxt->chr_access.len);
+    if (len != NULL) {
+        *len = ctxt->chr_access.len;
+    }
+
+    return 0;
+}
+
+static int
+gatt_svr_chr_access_gap(uint16_t conn_handle, uint16_t attr_handle, uint8_t op,
+                        union ble_gatt_access_ctxt *ctxt, void *arg)
+{
+    uint16_t uuid16;
+
+    uuid16 = ble_uuid_128_to_16(ctxt->chr_access.chr->uuid128);
+    assert(uuid16 != 0);
+
+    switch (uuid16) {
+    case BLE_GAP_CHR_UUID16_DEVICE_NAME:
+        assert(op == BLE_GATT_ACCESS_OP_READ_CHR);
+        ctxt->chr_access.data = (void *)bleprph_device_name;
+        ctxt->chr_access.len = strlen(bleprph_device_name);
+        break;
+
+    case BLE_GAP_CHR_UUID16_APPEARANCE:
+        assert(op == BLE_GATT_ACCESS_OP_READ_CHR);
+        ctxt->chr_access.data = (void *)&bleprph_appearance;
+        ctxt->chr_access.len = sizeof bleprph_appearance;
+        break;
+
+    case BLE_GAP_CHR_UUID16_PERIPH_PRIV_FLAG:
+        assert(op == BLE_GATT_ACCESS_OP_READ_CHR);
+        ctxt->chr_access.data = (void *)&bleprph_privacy_flag;
+        ctxt->chr_access.len = sizeof bleprph_privacy_flag;
+        break;
+
+    case BLE_GAP_CHR_UUID16_RECONNECT_ADDR:
+        assert(op == BLE_GATT_ACCESS_OP_WRITE_CHR);
+        if (ctxt->chr_access.len != sizeof bleprph_reconnect_addr) {
+            return BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN;
+        }
+        memcpy(bleprph_reconnect_addr, ctxt->chr_access.data,
+               sizeof bleprph_reconnect_addr);
+        break;
+
+    case BLE_GAP_CHR_UUID16_PERIPH_PREF_CONN_PARAMS:
+        assert(op == BLE_GATT_ACCESS_OP_READ_CHR);
+        ctxt->chr_access.data = (void *)&bleprph_pref_conn_params;
+        ctxt->chr_access.len = sizeof bleprph_pref_conn_params;
+        break;
+
+    default:
+        assert(0);
+        break;
+    }
+
+    return 0;
+}
+
+static int
+gatt_svr_chr_access_gatt(uint16_t conn_handle, uint16_t attr_handle, uint8_t op,
+                         union ble_gatt_access_ctxt *ctxt, void *arg)
+{
+    uint16_t uuid16;
+
+    uuid16 = ble_uuid_128_to_16(ctxt->chr_access.chr->uuid128);
+    assert(uuid16 != 0);
+
+    switch (uuid16) {
+    case BLE_GATT_CHR_SERVICE_CHANGED_UUID16:
+        if (op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
+            if (ctxt->chr_access.len != sizeof bleprph_gatt_service_changed) {
+                return BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN;
+            }
+            memcpy(bleprph_gatt_service_changed, ctxt->chr_access.data,
+                   sizeof bleprph_gatt_service_changed);
+        } else if (op == BLE_GATT_ACCESS_OP_READ_CHR) {
+            ctxt->chr_access.data = (void *)&bleprph_gatt_service_changed;
+            ctxt->chr_access.len = sizeof bleprph_gatt_service_changed;
+        }
+        break;
+
+    default:
+        assert(0);
+        break;
+    }
+
+    return 0;
+}
+
+#define GATT_SVR_NEW_ALERT_VAL_MAX_LEN    64
+
+static const uint8_t gatt_svr_new_alert_cat = 0x01; /* Simple alert. */
+static uint8_t gatt_svr_new_alert_val[GATT_SVR_NEW_ALERT_VAL_MAX_LEN];
+static uint16_t gatt_svr_new_alert_val_len;
+static const uint8_t gatt_svr_unr_alert_cat = 0x01; /* Simple alert. */
+static uint16_t gatt_svr_unr_alert_stat;
+static uint16_t gatt_svr_alert_not_ctrl_pt;
+
+static int
+gatt_svr_chr_access_alert(uint16_t conn_handle, uint16_t attr_handle,
+                          uint8_t op, union ble_gatt_access_ctxt *ctxt,
+                          void *arg)
+{
+    uint16_t uuid16;
+    int rc;
+
+    uuid16 = ble_uuid_128_to_16(ctxt->chr_access.chr->uuid128);
+    assert(uuid16 != 0);
+
+    switch (uuid16) {
+    case GATT_SVR_CHR_SUP_NEW_ALERT_CAT_UUID:
+        assert(op == BLE_GATT_ACCESS_OP_READ_CHR);
+        ctxt->chr_access.data = (void *)&gatt_svr_new_alert_cat;
+        ctxt->chr_access.len = sizeof gatt_svr_new_alert_cat;
+        return 0;
+
+    case GATT_SVR_CHR_NEW_ALERT:
+        if (op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
+            rc = gatt_svr_chr_write(op, ctxt, 0, sizeof gatt_svr_new_alert_val,
+                                  gatt_svr_new_alert_val,
+                                  &gatt_svr_new_alert_val_len);
+            return rc;
+        } else if (op == BLE_GATT_ACCESS_OP_READ_CHR) {
+            ctxt->chr_access.data = (void *)&gatt_svr_new_alert_val;
+            ctxt->chr_access.len = sizeof gatt_svr_new_alert_val;
+            return 0;
+        }
+
+    case GATT_SVR_CHR_SUP_UNR_ALERT_CAT_UUID:
+        assert(op == BLE_GATT_ACCESS_OP_READ_CHR);
+        ctxt->chr_access.data = (void *)&gatt_svr_unr_alert_cat;
+        ctxt->chr_access.len = sizeof gatt_svr_unr_alert_cat;
+        return 0;
+
+    case GATT_SVR_CHR_UNR_ALERT_STAT_UUID:
+        if (op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
+            rc = gatt_svr_chr_write(op, ctxt, 2, 2, &gatt_svr_unr_alert_stat,
+                                    NULL);
+        } else {
+            ctxt->chr_access.data = (void *)&gatt_svr_unr_alert_stat;
+            ctxt->chr_access.len = sizeof gatt_svr_unr_alert_stat;
+            rc = 0;
+        }
+        return rc;
+
+    case GATT_SVR_CHR_ALERT_NOT_CTRL_PT:
+        if (op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
+            rc = gatt_svr_chr_write(op, ctxt, 2, 2,
+                                    &gatt_svr_alert_not_ctrl_pt, NULL);
+        } else {
+            rc = BLE_ATT_ERR_UNLIKELY;
+        }
+        return rc;
+
+    default:
+        assert(0);
+        return BLE_ATT_ERR_UNLIKELY;
+    }
+}
+
+static void
+gatt_svr_register_cb(uint8_t op, union ble_gatt_register_ctxt *ctxt, void *arg)
+{
+    uint16_t uuid16;
+
+    switch (op) {
+    case BLE_GATT_REGISTER_OP_SVC:
+        uuid16 = ble_uuid_128_to_16(ctxt->svc_reg.svc->uuid128);
+        assert(uuid16 != 0);
+        BLEPRPH_LOG(DEBUG, "registered service 0x%04x with handle=%d\n",
+                    uuid16, ctxt->svc_reg.handle);
+        break;
+
+    case BLE_GATT_REGISTER_OP_CHR:
+        uuid16 = ble_uuid_128_to_16(ctxt->chr_reg.chr->uuid128);
+        assert(uuid16 != 0);
+        BLEPRPH_LOG(DEBUG, "registering characteristic 0x%04x with "
+                           "def_handle=%d val_handle=%d\n",
+                    uuid16, ctxt->chr_reg.def_handle,
+                    ctxt->chr_reg.val_handle);
+        break;
+
+    case BLE_GATT_REGISTER_OP_DSC:
+        uuid16 = ble_uuid_128_to_16(ctxt->dsc_reg.dsc->uuid128);
+        assert(uuid16 != 0);
+        BLEPRPH_LOG(DEBUG, "registering descriptor 0x%04x with handle=%d "
+                           "chr_handle=%d\n",
+                    uuid16, ctxt->dsc_reg.dsc_handle,
+                    ctxt->dsc_reg.chr_def_handle);
+        break;
+
+    default:
+        assert(0);
+        break;
+    }
+}
+
+void
+gatt_svr_init(void)
+{
+    int rc;
+
+    rc = ble_gatts_register_svcs(gatt_svr_svcs, gatt_svr_register_cb, NULL);
+    assert(rc == 0);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/dd032817/apps/bleprph/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bleprph/src/main.c b/apps/bleprph/src/main.c
new file mode 100755
index 0000000..8824428
--- /dev/null
+++ b/apps/bleprph/src/main.c
@@ -0,0 +1,299 @@
+/**
+ * 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 "console/console.h"
+
+/* 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"
+#include "host/ble_att.h"
+#include "host/ble_gap.h"
+#include "host/ble_gatt.h"
+#include "controller/ble_ll.h"
+
+#include "bleprph.h"
+
+#define BSWAP16(x)  ((uint16_t)(((x) << 8) | (((x) & 0xff00) >> 8)))
+
+/** Mbuf settings. */
+#define MBUF_NUM_MBUFS      (8)
+#define MBUF_BUF_SIZE       OS_ALIGN(BLE_MBUF_PAYLOAD_SIZE, 4)
+#define MBUF_MEMBLOCK_SIZE  (MBUF_BUF_SIZE + BLE_MBUF_MEMBLOCK_OVERHEAD)
+#define MBUF_MEMPOOL_SIZE   OS_MEMPOOL_SIZE(MBUF_NUM_MBUFS, MBUF_MEMBLOCK_SIZE)
+
+static os_membuf_t bleprph_mbuf_mpool_data[MBUF_MEMPOOL_SIZE];
+struct os_mbuf_pool bleprph_mbuf_pool;
+struct os_mempool bleprph_mbuf_mpool;
+
+/** Log data. */
+static struct log_handler bleprph_log_console_handler;
+struct log bleprph_log;
+
+/** Priority of the nimble host task. */
+#define BLEPRPH_BLE_HS_PRIO          (1)
+
+/** bleprph task settings. */
+#define BLEPRPH_STACK_SIZE             (OS_STACK_ALIGN(200))
+#define BLEPRPH_TASK_PRIO              (BLEPRPH_BLE_HS_PRIO + 1)
+
+struct os_eventq bleprph_evq;
+struct os_task bleprph_task;
+bssnz_t os_stack_t bleprph_stack[BLEPRPH_STACK_SIZE];
+
+/** Our global device address (public) */
+uint8_t g_dev_addr[BLE_DEV_ADDR_LEN] = {0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a};
+
+/** Our random address (in case we need it) */
+uint8_t g_random_addr[BLE_DEV_ADDR_LEN];
+
+/** Device name - included in advertisements and exposed by GAP service. */
+const char *bleprph_device_name = "nimble-bleprph";
+
+/** Device properties - exposed by GAP service. */
+const uint16_t bleprph_appearance = BSWAP16(BLE_GAP_APPEARANCE_GEN_COMPUTER);
+const uint8_t bleprph_privacy_flag = 0;
+uint8_t bleprph_reconnect_addr[6];
+uint8_t bleprph_pref_conn_params[8];
+uint8_t bleprph_gatt_service_changed[4];
+
+static int bleprph_on_connect(int event, int status,
+                              struct ble_gap_conn_ctxt *ctxt, void *arg);
+
+/**
+ * Utility function to log an array of bytes.
+ */
+static void
+bleprph_print_bytes(uint8_t *bytes, int len)
+{
+    int i;
+
+    for (i = 0; i < len; i++) {
+        BLEPRPH_LOG(INFO, "%s0x%02x", i != 0 ? ":" : "", bytes[i]);
+    }
+}
+
+/**
+ * Logs information about a connection to the console.
+ */
+static void
+bleprph_print_conn_desc(struct ble_gap_conn_desc *desc)
+{
+    BLEPRPH_LOG(INFO, "handle=%d peer_addr_type=%d peer_addr=",
+                desc->conn_handle, desc->peer_addr_type);
+    bleprph_print_bytes(desc->peer_addr, 6);
+    BLEPRPH_LOG(INFO, " conn_itvl=%d conn_latency=%d supervision_timeout=%d",
+                desc->conn_itvl, desc->conn_latency,
+                desc->supervision_timeout);
+}
+
+/**
+ * Enables advertising with the following parameters:
+ *     o General discoverable mode.
+ *     o Undirected connectable mode.
+ */
+static void
+bleprph_advertise(void)
+{
+    struct ble_hs_adv_fields fields;
+    int rc;
+
+    /* Set the advertisement data included in our advertisements. */
+    memset(&fields, 0, sizeof fields);
+    fields.name = (uint8_t *)bleprph_device_name;
+    fields.name_len = strlen(bleprph_device_name);
+    fields.name_is_complete = 1;
+    rc = ble_gap_adv_set_fields(&fields);
+    if (rc != 0) {
+        BLEPRPH_LOG(ERROR, "error setting advertisement data; rc=%d\n", rc);
+        return;
+    }
+
+    /* Begin advertising. */
+    rc = ble_gap_adv_start(BLE_GAP_DISC_MODE_GEN, BLE_GAP_CONN_MODE_UND,
+                           NULL, 0, NULL, bleprph_on_connect, NULL);
+    if (rc != 0) {
+        BLEPRPH_LOG(ERROR, "error enabling advertisement; rc=%d\n", rc);
+        return;
+    }
+}
+
+static int
+bleprph_on_connect(int event, int status, struct ble_gap_conn_ctxt *ctxt,
+                   void *arg)
+{
+    switch (event) {
+    case BLE_GAP_EVENT_CONN:
+        BLEPRPH_LOG(INFO, "connection %s; status=%d ",
+                    status == 0 ? "up" : "down", status);
+        bleprph_print_conn_desc(ctxt->desc);
+        BLEPRPH_LOG(INFO, "\n");
+
+        if (status != 0) {
+            /* Connection terminated; resume advertising. */
+            bleprph_advertise();
+        }
+        break;
+
+    case BLE_GAP_EVENT_CONN_UPDATED:
+        BLEPRPH_LOG(INFO, "connection updated; status=%d ", status);
+        bleprph_print_conn_desc(ctxt->desc);
+        BLEPRPH_LOG(INFO, "\n");
+        break;
+
+    case BLE_GAP_EVENT_CONN_UPDATE_REQ:
+        BLEPRPH_LOG(INFO, "connection update request; status=%d ", status);
+        *ctxt->self_params = *ctxt->peer_params;
+        break;
+    }
+
+    return 0;
+}
+
+/**
+ * Event loop for the main bleprph task.
+ */
+static void
+bleprph_task_handler(void *unused)
+{
+    struct os_event *ev;
+    struct os_callout_func *cf;
+
+    /* Register GATT attributes (services, characteristics, and
+     * descriptors).
+     */
+    gatt_svr_init();
+
+    /* Initialize eventq */
+    os_eventq_init(&bleprph_evq);
+
+    /* Begin advertising. */
+    bleprph_advertise();
+
+    while (1) {
+        ev = os_eventq_get(&bleprph_evq);
+        switch (ev->ev_type) {
+        case OS_EVENT_T_TIMER:
+            cf = (struct os_callout_func *)ev;
+            assert(cf->cf_func);
+            cf->cf_func(cf->cf_arg);
+            break;
+        default:
+            assert(0);
+            break;
+        }
+    }
+}
+
+/**
+ * main
+ *
+ * The main function for the project. This function initializes the os, calls
+ * init_tasks to initialize tasks (and possibly other objects), then starts the
+ * OS. We should not return from os start.
+ *
+ * @return int NOTE: this function should never return!
+ */
+int
+main(void)
+{
+    struct ble_hs_cfg cfg;
+    uint32_t seed;
+    int rc;
+    int i;
+
+    /* Initialize OS */
+    os_init();
+
+    /* Set cputime to count at 1 usec increments */
+    rc = cputime_init(1000000);
+    assert(rc == 0);
+
+    /* Seed random number generator with least significant bytes of device
+     * address.
+     */
+    seed = 0;
+    for (i = 0; i < 4; ++i) {
+        seed |= g_dev_addr[i];
+        seed <<= 8;
+    }
+    srand(seed);
+
+    /* Initialize msys mbufs. */
+    rc = os_mempool_init(&bleprph_mbuf_mpool, MBUF_NUM_MBUFS, 
+                         MBUF_MEMBLOCK_SIZE, bleprph_mbuf_mpool_data, 
+                         "bleprph_mbuf_data");
+    assert(rc == 0);
+
+    rc = os_mbuf_pool_init(&bleprph_mbuf_pool, &bleprph_mbuf_mpool,
+                           MBUF_MEMBLOCK_SIZE, MBUF_NUM_MBUFS);
+    assert(rc == 0);
+
+    rc = os_msys_register(&bleprph_mbuf_pool);
+    assert(rc == 0);
+
+    /* Initialize the logging system. */
+    log_init();
+    log_console_handler_init(&bleprph_log_console_handler);
+    log_register("bleprph", &bleprph_log, &bleprph_log_console_handler);
+
+    os_task_init(&bleprph_task, "bleprph", bleprph_task_handler,
+                 NULL, BLEPRPH_TASK_PRIO, OS_WAIT_FOREVER,
+                 bleprph_stack, BLEPRPH_STACK_SIZE);
+
+    /* Initialize the BLE LL */
+    rc = ble_ll_init();
+    assert(rc == 0);
+
+    /* Initialize the BLE host. */
+    cfg = ble_hs_cfg_dflt;
+    cfg.max_hci_bufs = 3;
+    cfg.max_connections = 1;
+    cfg.max_attrs = 32;
+    cfg.max_services = 4;
+    cfg.max_client_configs = 6;
+    cfg.max_gattc_procs = 2;
+    cfg.max_l2cap_chans = 3;
+    cfg.max_l2cap_sig_procs = 2;
+
+    rc = ble_hs_init(BLEPRPH_BLE_HS_PRIO, &cfg);
+    assert(rc == 0);
+
+    /* Initialize the console (for log output). */
+    rc = console_init(NULL);
+    assert(rc == 0);
+
+    /* Start the OS */
+    os_start();
+
+    /* os start should never return. If it does, this should be an error */
+    assert(0);
+
+    return 0;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/dd032817/apps/bletest/pkg.yml
----------------------------------------------------------------------
diff --git a/apps/bletest/pkg.yml b/apps/bletest/pkg.yml
new file mode 100644
index 0000000..24cfa52
--- /dev/null
+++ b/apps/bletest/pkg.yml
@@ -0,0 +1,40 @@
+#
+# 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: apps/bletest
+pkg.vers: 0.8.0
+pkg.description: Test project for the nimble BLE controller.
+pkg.author: wes3 <will@runtime.io>
+pkg.homepage:
+pkg.repository: https://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva
+pkg.keywords:
+
+pkg.deps: 
+    - net/nimble/controller
+    - net/nimble/host
+    - libs/os 
+    - libs/console/full
+    - libs/baselibc
+    - libs/shell
+    - libs/imgmgr
+    - libs/newtmgr
+    - sys/config
+    - sys/log
+    - sys/stats
+pkg.cflags: -DBLETEST

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/dd032817/apps/bletest/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletest/src/main.c b/apps/bletest/src/main.c
new file mode 100755
index 0000000..d004aa9
--- /dev/null
+++ b/apps/bletest/src/main.c
@@ -0,0 +1,969 @@
+/**
+ * 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 "os/os.h"
+#include "bsp/bsp.h"
+#include "hal/hal_gpio.h"
+#include "hal/hal_cputime.h"
+#include "hal/hal_flash.h"
+#include "console/console.h"
+#include "shell/shell.h"
+#include "stats/stats.h"
+#include "hal/flash_map.h"
+#include "fs/fs.h"
+#include "nffs/nffs.h"
+#include "newtmgr/newtmgr.h"
+#include "imgmgr/imgmgr.h"
+
+/* BLE */
+#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"
+#include "controller/ble_ll_conn.h"
+#include "controller/ble_ll_scan.h"
+#include "controller/ble_ll_adv.h"
+
+/* Task priorities */
+/* NOTE: highest priority task (0) reserved for controller LL task */
+#define HOST_TASK_PRIO      (OS_TASK_PRI_HIGHEST + 1)
+#define BLETEST_TASK_PRIO   (HOST_TASK_PRIO + 1)
+#define SHELL_TASK_PRIO     (BLETEST_TASK_PRIO + 1)
+#define NEWTMGR_TASK_PRIO   (SHELL_TASK_PRIO + 1)
+
+/* Shell task stack */
+#define SHELL_TASK_STACK_SIZE (OS_STACK_ALIGN(256))
+os_stack_t shell_stack[SHELL_TASK_STACK_SIZE];
+
+/* Newt manager task stack */
+#define NEWTMGR_TASK_STACK_SIZE (OS_STACK_ALIGN(448))
+os_stack_t newtmgr_stack[NEWTMGR_TASK_STACK_SIZE];
+
+/* Shell maximum input line length */
+#define SHELL_MAX_INPUT_LEN     (256)
+
+/* For LED toggling */
+int g_led_pin;
+
+/* Our global device address (public) */
+uint8_t g_dev_addr[BLE_DEV_ADDR_LEN];
+
+/* Our random address (in case we need it) */
+uint8_t g_random_addr[BLE_DEV_ADDR_LEN];
+
+/* A buffer for host advertising data */
+uint8_t g_host_adv_data[BLE_HCI_MAX_ADV_DATA_LEN];
+uint8_t g_host_adv_len;
+
+/* Create a mbuf pool of BLE mbufs */
+#define MBUF_NUM_MBUFS      (42)
+#define MBUF_BUF_SIZE       OS_ALIGN(BLE_MBUF_PAYLOAD_SIZE, 4)
+#define MBUF_MEMBLOCK_SIZE  (MBUF_BUF_SIZE + BLE_MBUF_MEMBLOCK_OVERHEAD)
+#define MBUF_MEMPOOL_SIZE   OS_MEMPOOL_SIZE(MBUF_NUM_MBUFS, MBUF_MEMBLOCK_SIZE)
+
+struct os_mbuf_pool g_mbuf_pool; 
+struct os_mempool g_mbuf_mempool;
+os_membuf_t g_mbuf_buffer[MBUF_MEMPOOL_SIZE];
+
+/* Some application configurations */
+#define BLETEST_ROLE_ADVERTISER         (0)
+#define BLETEST_ROLE_SCANNER            (1)
+#define BLETEST_ROLE_INITIATOR          (2)
+#define BLETEST_CFG_ROLE                (BLETEST_ROLE_INITIATOR)
+//#define BLETEST_CFG_ROLE                (BLETEST_ROLE_ADVERTISER)
+//#define BLETEST_CFG_ROLE                (BLETEST_ROLE_SCANNER)
+#define BLETEST_CFG_ADV_OWN_ADDR_TYPE   (BLE_HCI_ADV_OWN_ADDR_PUBLIC)
+#define BLETEST_CFG_ADV_PEER_ADDR_TYPE  (BLE_HCI_ADV_PEER_ADDR_PUBLIC)
+#define BLETEST_CFG_FILT_DUP_ADV        (0)
+#define BLETEST_CFG_ADV_ITVL            (600000 / BLE_HCI_ADV_ITVL)
+#define BLETEST_CFG_ADV_TYPE            BLE_HCI_ADV_TYPE_ADV_IND
+#define BLETEST_CFG_ADV_FILT_POLICY     (BLE_HCI_ADV_FILT_NONE)
+#define BLETEST_CFG_SCAN_ITVL           (700000 / BLE_HCI_SCAN_ITVL)
+#define BLETEST_CFG_SCAN_WINDOW         (700000 / BLE_HCI_SCAN_ITVL)
+#define BLETEST_CFG_SCAN_TYPE           (BLE_HCI_SCAN_TYPE_ACTIVE)
+#define BLETEST_CFG_SCAN_FILT_POLICY    (BLE_HCI_SCAN_FILT_NO_WL)
+#define BLETEST_CFG_CONN_ITVL           (128)  /* in 1.25 msec increments */           
+#define BLETEST_CFG_SLAVE_LATENCY       (0)
+#define BLETEST_CFG_INIT_FILTER_POLICY  (BLE_HCI_CONN_FILT_NO_WL)
+#define BLETEST_CFG_CONN_SPVN_TMO       (1000)  /* 20 seconds */
+#define BLETEST_CFG_MIN_CE_LEN          (6)    
+#define BLETEST_CFG_MAX_CE_LEN          (BLETEST_CFG_CONN_ITVL)
+#define BLETEST_CFG_CONN_PEER_ADDR_TYPE (BLE_HCI_CONN_PEER_ADDR_PUBLIC)
+#define BLETEST_CFG_CONN_OWN_ADDR_TYPE  (BLE_HCI_ADV_OWN_ADDR_RANDOM)
+#define BLETEST_CFG_CONCURRENT_CONNS    (1)
+
+/* BLETEST variables */
+#undef BLETEST_ADV_PKT_NUM
+#define BLETEST_PKT_SIZE                (251)
+#define BLETEST_STACK_SIZE              (256)
+uint32_t g_next_os_time;
+int g_bletest_state;
+struct os_eventq g_bletest_evq;
+struct os_callout_func g_bletest_timer;
+struct os_task bletest_task;
+bssnz_t os_stack_t bletest_stack[BLETEST_STACK_SIZE];
+uint32_t g_bletest_conn_end;
+int g_bletest_start_update;
+uint32_t g_bletest_conn_upd_time;
+uint8_t g_bletest_current_conns;
+uint8_t g_bletest_cur_peer_addr[BLE_DEV_ADDR_LEN];
+uint8_t g_last_handle_used;
+uint8_t g_bletest_led_state;
+uint32_t g_bletest_led_rate;
+uint32_t g_bletest_next_led_time;
+
+#ifdef BLETEST_ADV_PKT_NUM
+void
+bletest_inc_adv_pkt_num(void)
+{
+    int rc;
+    uint8_t *dptr;
+    uint8_t digit;
+
+    if (g_host_adv_len != 0) {
+        dptr = &g_host_adv_data[18];
+        while (dptr >= &g_host_adv_data[13]) {
+            digit = *dptr;
+            ++digit;
+            if (digit == 58) {
+                digit = 48;
+                *dptr = digit;
+                --dptr;
+            } else {
+                *dptr = digit;
+                break;
+            }
+        }
+
+        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
+
+void
+bletest_send_conn_update(uint16_t handle)
+{
+    int rc;
+    struct hci_conn_update hcu;
+
+    hcu.conn_latency = 4;
+    hcu.supervision_timeout = 2000; 
+    hcu.conn_itvl_min = 1000;
+    hcu.conn_itvl_max = 1000;
+    hcu.handle = handle;
+    hcu.min_ce_len = 4;
+    hcu.max_ce_len = 4;
+
+    rc = host_hci_cmd_le_conn_update(&hcu);
+    assert(rc == 0);
+    host_hci_outstanding_opcode = 0;
+}
+
+/**
+ * Sets the advertising data to be sent in advertising pdu's which contain
+ * advertising data.
+ *
+ * @param dptr
+ * @return uint8_t
+ */
+uint8_t
+bletest_set_adv_data(uint8_t *dptr)
+{
+    uint8_t len;
+
+    /* Place flags in first */
+    dptr[0] = 2;
+    dptr[1] = 0x01;     /* Flags identifier */
+    dptr[2] = 0x06;
+    dptr += 3;
+    len = 3;
+
+    /* Add local name */
+    dptr[0] = 15;   /* Length of this data, not including the length */
+    dptr[1] = 0x09;
+    dptr[2] = 'r';
+    dptr[3] = 'u';
+    dptr[4] = 'n';
+    dptr[5] = 't';
+    dptr[6] = 'i';
+    dptr[7] = 'm';
+    dptr[8] = 'e';
+    dptr[9] = '-';
+    dptr[10] = '0';
+    dptr[11] = '0';
+    dptr[12] = '0';
+    dptr[13] = '0';
+    dptr[14] = '0';
+    dptr[15] = '0';
+    dptr += 16;
+    len += 16;
+
+    /* Add local device address */
+    dptr[0] = 0x08;
+    dptr[1] = 0x1B;
+    dptr[2] = 0x00;
+    memcpy(dptr + 3, g_dev_addr, BLE_DEV_ADDR_LEN);
+    len += 9;
+
+    g_host_adv_len = len;
+
+    return len;
+}
+
+#if (BLETEST_CFG_ROLE == BLETEST_ROLE_ADVERTISER)
+void
+bletest_init_advertising(void)
+{
+    int rc;
+    uint8_t adv_len;
+    uint8_t rand_addr[BLE_DEV_ADDR_LEN];
+    struct hci_adv_params adv;
+
+    /* Just zero out advertising */
+    memset(&adv, 0, sizeof(struct hci_adv_params));
+
+    /* Set advertising parameters */
+    adv.adv_type = BLETEST_CFG_ADV_TYPE;
+    adv.adv_channel_map = 0x07;
+    adv.adv_filter_policy = BLETEST_CFG_ADV_FILT_POLICY;
+    adv.own_addr_type = BLETEST_CFG_ADV_OWN_ADDR_TYPE;
+    adv.peer_addr_type = BLETEST_CFG_ADV_PEER_ADDR_TYPE;
+    if ((adv.adv_type == BLE_HCI_ADV_TYPE_ADV_DIRECT_IND_HD) ||
+        (adv.adv_type == BLE_HCI_ADV_TYPE_ADV_DIRECT_IND_LD)) {
+        memcpy(adv.peer_addr, g_bletest_cur_peer_addr, BLE_DEV_ADDR_LEN);
+        if (adv.peer_addr_type == BLE_HCI_ADV_PEER_ADDR_RANDOM) {
+            adv.peer_addr[5] |= 0xc0;
+        }
+        adv_len = 0;
+    } else {
+        adv_len = bletest_set_adv_data(&g_host_adv_data[0]);
+    }
+
+    console_printf("Trying to connect to %x.%x.%x.%x.%x.%x\n",
+                   adv.peer_addr[0], adv.peer_addr[1], adv.peer_addr[2],
+                   adv.peer_addr[3], adv.peer_addr[4], adv.peer_addr[5]);
+
+    if (adv.adv_type == BLE_HCI_ADV_TYPE_ADV_DIRECT_IND_HD) {
+        adv.adv_itvl_min = 0;
+        adv.adv_itvl_max = 0;
+    } else {
+        adv.adv_itvl_min = BLETEST_CFG_ADV_ITVL;
+        adv.adv_itvl_max = BLETEST_CFG_ADV_ITVL; /* Advertising interval */
+    }
+
+    /* 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) {
+        memcpy(rand_addr, g_dev_addr, BLE_DEV_ADDR_LEN);
+        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
+
+#if (BLETEST_CFG_ROLE == BLETEST_ROLE_SCANNER)
+void
+bletest_init_scanner(void)
+{
+    int rc;
+    uint8_t dev_addr[BLE_DEV_ADDR_LEN];
+    uint8_t filter_policy;
+
+    /* Set scanning parameters */
+    rc = host_hci_cmd_le_set_scan_params(BLETEST_CFG_SCAN_TYPE,
+                                         BLETEST_CFG_SCAN_ITVL,
+                                         BLETEST_CFG_SCAN_WINDOW,
+                                         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) {
+        /* Add some whitelist addresses */
+        dev_addr[0] = 0x00;
+        dev_addr[1] = 0x00;
+        dev_addr[2] = 0x00;
+        dev_addr[3] = 0x88;
+        dev_addr[4] = 0x88;
+        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;
+    }
+}
+
+void
+bletest_execute_scanner(void)
+{
+    int rc;
+
+    /* Enable scanning */
+    if ((int32_t)(os_time_get() - g_next_os_time) >= 0) {
+        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);
+    }
+}
+#endif
+
+#if (BLETEST_CFG_ROLE == BLETEST_ROLE_INITIATOR)
+void
+bletest_init_initiator(void)
+{
+    int rc;
+    uint8_t rand_addr[BLE_DEV_ADDR_LEN];
+    struct hci_create_conn cc;
+    struct hci_create_conn *hcc;
+
+    /* Enable initiating */
+    hcc = &cc;
+    hcc->conn_itvl_max = BLETEST_CFG_CONN_ITVL;
+    hcc->conn_itvl_min = BLETEST_CFG_CONN_ITVL;
+    hcc->conn_latency = BLETEST_CFG_SLAVE_LATENCY;
+    hcc->filter_policy = BLETEST_CFG_INIT_FILTER_POLICY;
+    hcc->supervision_timeout = BLETEST_CFG_CONN_SPVN_TMO;
+    hcc->scan_itvl = BLETEST_CFG_SCAN_ITVL;
+    hcc->scan_window = BLETEST_CFG_SCAN_WINDOW;
+    hcc->peer_addr_type = BLETEST_CFG_CONN_PEER_ADDR_TYPE;
+    memcpy(hcc->peer_addr, g_bletest_cur_peer_addr, BLE_DEV_ADDR_LEN);
+    if (hcc->peer_addr_type == BLE_HCI_CONN_PEER_ADDR_RANDOM) {
+        hcc->peer_addr[5] |= 0xc0;
+    }
+    hcc->own_addr_type = BLETEST_CFG_CONN_OWN_ADDR_TYPE;
+    hcc->min_ce_len = BLETEST_CFG_MIN_CE_LEN;
+    hcc->max_ce_len = BLETEST_CFG_MAX_CE_LEN;
+
+    console_printf("Trying to connect to %x.%x.%x.%x.%x.%x\n",
+                   hcc->peer_addr[0], hcc->peer_addr[1], hcc->peer_addr[2],
+                   hcc->peer_addr[3], hcc->peer_addr[4], hcc->peer_addr[5]);
+
+    /* If we are using a random address, we need to set it */
+    if (hcc->own_addr_type == BLE_HCI_ADV_OWN_ADDR_RANDOM) {
+        memcpy(rand_addr, g_dev_addr, BLE_DEV_ADDR_LEN);
+        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
+bletest_execute_initiator(void)
+{
+    int i;
+    int rc;
+    uint16_t handle;
+    uint8_t new_chan_map[5];
+
+    /* 
+     * Determine if there is an active connection for the current handle
+     * we are trying to create. If so, start looking for the next one
+     */
+    if (g_bletest_current_conns < BLETEST_CFG_CONCURRENT_CONNS) {
+        handle = g_bletest_current_conns + 1;
+        if (ble_ll_conn_find_active_conn(handle)) {
+            /* Set LED to slower blink rate */
+            g_bletest_led_rate = OS_TICKS_PER_SEC;
+
+            /* Ask for version information */
+            rc = host_hci_cmd_rd_rem_version(handle);
+            host_hci_outstanding_opcode = 0;
+
+            /* Scanning better be stopped! */
+            assert(ble_ll_scan_enabled() == 0);
+
+            /* Add to current connections */
+            if (!rc) {
+                ++g_bletest_current_conns;
+
+                /* Move to next connection */
+                if (g_bletest_current_conns < BLETEST_CFG_CONCURRENT_CONNS) {
+                    /* restart initiating */
+                    g_bletest_cur_peer_addr[5] += 1;
+                    g_dev_addr[5] += 1;
+                    bletest_init_initiator();
+                }
+            }
+        }
+    } else {
+        if ((int32_t)(os_time_get() - g_next_os_time) >= 0) {
+            if ((g_bletest_state == 1) || (g_bletest_state == 3)) {
+                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) {
+                new_chan_map[0] = 0;
+                new_chan_map[1] = 0x3;
+                new_chan_map[2] = 0;
+                new_chan_map[3] = 0;
+                new_chan_map[4] = 0;
+                host_hci_cmd_le_set_host_chan_class(new_chan_map);
+                host_hci_outstanding_opcode = 0;
+            } else {
+                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;
+                    }   
+                }
+            }
+            ++g_bletest_state;
+            g_next_os_time = os_time_get() + OS_TICKS_PER_SEC * 5;
+        }
+    }
+}
+#endif
+
+#if (BLETEST_CFG_ROLE == BLETEST_ROLE_ADVERTISER)
+/* 
+ * Test wrapper to get packets. Only get a packet if we have more than half
+ * left
+ */ 
+static struct os_mbuf *
+bletest_get_packet(void)
+{
+    struct os_mbuf *om;
+
+    om = NULL;
+    if (g_mbuf_pool.omp_pool->mp_num_free >= 5) {
+        om = os_msys_get_pkthdr(BLE_MBUF_PAYLOAD_SIZE, 
+                                sizeof(struct ble_mbuf_hdr));
+    }
+    return om;
+}
+
+#if 0
+void
+bletest_execute(void)
+{
+    int rc;
+
+    int i;
+    uint16_t pktlen;
+    uint16_t handle;
+    struct os_mbuf *om;
+    struct ble_ll_conn_sm *connsm;
+
+    handle = 1;
+    if ((int32_t)(os_time_get() - g_next_os_time) >= 0) {
+        if (g_bletest_state == 0) {
+            rc = host_hci_cmd_le_set_adv_enable(1);
+            host_hci_outstanding_opcode = 0;
+            assert(rc == 0);
+            g_bletest_state = 1;
+        } else if (g_bletest_state == 1) {
+            /* See if handle 1 has been created. If so, send packets */
+            connsm = ble_ll_conn_find_active_conn(handle);
+            if (connsm) {
+                /* Set connection end time */
+                g_bletest_conn_end = os_time_get() + 
+                    (OS_TICKS_PER_SEC * (60 * 15));
+                g_bletest_state = 2;
+            }
+        } else if (g_bletest_state == 2) {
+            if ((int32_t)(os_time_get() - g_bletest_conn_end) >= 0) {
+                g_bletest_state = 3;
+                host_hci_cmd_disconnect(handle, BLE_ERR_REM_USER_CONN_TERM);
+            } else {
+                om = bletest_get_packet();
+                if (om) {
+                    /* set payload length */
+                    pktlen = BLETEST_PKT_SIZE;
+                    om->om_len = BLETEST_PKT_SIZE + 4;
+
+                    /* Put the HCI header in the mbuf */
+                    htole16(om->om_data, handle);
+                    htole16(om->om_data + 2, om->om_len);
+
+                    /* Place L2CAP header in packet */
+                    htole16(om->om_data + 4, pktlen);
+                    om->om_data[6] = 0;
+                    om->om_data[7] = 0;
+
+                    /* Fill with incrementing pattern (starting from 1) */
+                    for (i = 0; i < pktlen; ++i) {
+                        om->om_data[8 + i] = (uint8_t)(i + 1);
+                    }
+
+                    /* Add length */
+                    om->om_len += 4;
+                    OS_MBUF_PKTHDR(om)->omp_len = om->om_len;
+                    ble_hci_transport_host_acl_data_send(om);
+                }
+                g_next_os_time += OS_TICKS_PER_SEC / 10;
+                return;
+            }
+        } else if (g_bletest_state == 3) {
+            /* We should be waiting for disconnect */
+            connsm = ble_ll_conn_find_active_conn(handle);
+            if (!connsm) {
+                /* Set to 0 if you want to restart advertising */
+                //g_bletest_state = 0;
+                g_bletest_state = 4;
+            }
+        }
+        g_next_os_time += OS_TICKS_PER_SEC;
+    }
+}
+#else
+static void
+bletest_execute_advertiser(void)
+{
+    int i,j;
+    int rc;
+    uint16_t handle;
+    uint16_t pktlen;
+    struct os_mbuf *om;
+
+    /* See if we should start advertising again */
+    if (g_bletest_current_conns < BLETEST_CFG_CONCURRENT_CONNS) {
+        handle = g_bletest_current_conns + 1;
+        if (ble_ll_conn_find_active_conn(handle)) {
+            /* Set LED to slower blink rate */
+            g_bletest_led_rate = OS_TICKS_PER_SEC;
+
+            /* advertising better be stopped! */
+            assert(ble_ll_adv_enabled() == 0);
+
+            /* 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;
+            }
+
+            /* set conn update time */
+            g_bletest_conn_upd_time = os_time_get() + (OS_TICKS_PER_SEC * 5);
+            g_bletest_start_update = 1;
+
+            /* Add to current connections */
+            ++g_bletest_current_conns;
+
+            /* Move to next connection */
+            if (g_bletest_current_conns < BLETEST_CFG_CONCURRENT_CONNS) {
+                /* restart initiating */
+                g_bletest_cur_peer_addr[5] += 1;
+                g_dev_addr[5] += 1;
+                bletest_init_advertising();
+                rc = host_hci_cmd_le_set_adv_enable(1);
+                host_hci_outstanding_opcode = 0;
+            }
+        }
+    }
+#if 0
+    if (g_bletest_start_update) {
+        if ((int32_t)(os_time_get() - g_bletest_conn_upd_time) >= 0) {
+            bletest_send_conn_update(1);
+            g_bletest_start_update = 0;
+        }
+    }
+#endif
+    /* See if it is time to hand a data packet to the connection */
+    if ((int32_t)(os_time_get() - g_next_os_time) >= 0) {
+        if (g_bletest_current_conns) {
+            for (i = 0; i < g_bletest_current_conns; ++i) {
+                if ((g_last_handle_used == 0) || 
+                    (g_last_handle_used > g_bletest_current_conns)) {
+                    g_last_handle_used = 1;
+                }
+                handle = g_last_handle_used;
+                if (ble_ll_conn_find_active_conn(handle)) {
+                    om = bletest_get_packet();
+                    if (om) {
+                        /* set payload length */
+                        pktlen = BLETEST_PKT_SIZE;
+                        om->om_len = BLETEST_PKT_SIZE + 4;
+
+                        /* Put the HCI header in the mbuf */
+                        htole16(om->om_data, handle);
+                        htole16(om->om_data + 2, om->om_len);
+
+                        /* Place L2CAP header in packet */
+                        htole16(om->om_data + 4, pktlen);
+                        om->om_data[6] = 0;
+                        om->om_data[7] = 0;
+                        om->om_len += 4;
+
+                        /* Fill with incrementing pattern (starting from 1) */
+                        for (j = 0; j < pktlen; ++j) {
+                            om->om_data[8 + j] = (uint8_t)(j + 1);
+                        }
+
+                        /* Add length */
+                        OS_MBUF_PKTHDR(om)->omp_len = om->om_len;
+                        ble_hci_transport_host_acl_data_send(om);
+
+                        /* Increment last handle used */
+                        ++g_last_handle_used;
+                    }
+                } else {
+                    ++g_last_handle_used;
+                }
+            }
+        }
+        g_next_os_time = os_time_get() + OS_TICKS_PER_SEC;
+    }
+}
+#endif
+#endif
+
+/**
+ * Main bletest function. Called by the task timer every 50 msecs.
+ * 
+ */
+void
+bletest_execute(void)
+{
+    /* Toggle LED at set rate */
+    if ((int32_t)(os_time_get() - g_bletest_next_led_time) >= 0) {
+        hal_gpio_toggle(LED_BLINK_PIN);
+        g_bletest_next_led_time = os_time_get() + g_bletest_led_rate;
+    }
+#if (BLETEST_CFG_ROLE == BLETEST_ROLE_ADVERTISER)
+    bletest_execute_advertiser();
+#endif
+#if (BLETEST_CFG_ROLE == BLETEST_ROLE_SCANNER)
+    bletest_execute_scanner();
+#endif
+#if (BLETEST_CFG_ROLE == BLETEST_ROLE_INITIATOR)
+    bletest_execute_initiator();
+#endif
+}
+
+/**
+ * Callback when BLE test timer expires. 
+ * 
+ * @param arg 
+ */
+void
+bletest_timer_cb(void *arg)
+{
+    /* Call the bletest code */
+    bletest_execute();
+
+    /* Re-start the timer (run every 50 msecs) */
+    os_callout_reset(&g_bletest_timer.cf_c, OS_TICKS_PER_SEC / 20);
+}
+
+/**
+ * BLE test task 
+ * 
+ * @param arg 
+ */
+void
+bletest_task_handler(void *arg)
+{
+    int rc;
+    uint64_t event_mask;
+    struct os_event *ev;
+    struct os_callout_func *cf;
+
+    /* Set LED blink rate */
+    g_bletest_led_rate = OS_TICKS_PER_SEC / 20;
+
+    /* Wait one second before starting test task */
+    os_time_delay(OS_TICKS_PER_SEC);
+
+    /* Initialize eventq */
+    os_eventq_init(&g_bletest_evq);
+
+    /* Initialize the host timer */
+    os_callout_func_init(&g_bletest_timer, &g_bletest_evq, bletest_timer_cb,
+                         NULL);
+
+    /* Send the reset command first */
+    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 */
+    console_printf("Starting BLE test task as advertiser\n");
+    bletest_init_advertising();
+#endif
+
+#if (BLETEST_CFG_ROLE == BLETEST_ROLE_SCANNER)
+    /* Initialize the scanner */
+    console_printf("Starting BLE test task as scanner\n");
+    bletest_init_scanner();
+#endif
+
+#if (BLETEST_CFG_ROLE == BLETEST_ROLE_INITIATOR)
+    /* Initialize the scanner */
+    console_printf("Starting BLE test task as initiator\n");
+    bletest_init_initiator();
+#endif
+
+    /* Set the event mask we want to display */
+    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;
+
+    /* Turn on all events */
+    rc = host_hci_cmd_rd_local_version();
+    assert(rc == 0);
+    host_hci_outstanding_opcode = 0;
+
+    /* Wait some time before starting */
+    os_time_delay(OS_TICKS_PER_SEC);
+
+    /* Init bletest variables */
+    g_bletest_state = 0;
+    g_next_os_time = os_time_get();
+
+    /* Begin advertising if we are an advertiser */
+#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);
+
+    while (1) {
+        ev = os_eventq_get(&g_bletest_evq);
+        switch (ev->ev_type) {
+        case OS_EVENT_T_TIMER:
+            cf = (struct os_callout_func *)ev;
+            assert(cf->cf_func);
+            cf->cf_func(cf->cf_arg);
+            break;
+        default:
+            assert(0);
+            break;
+        }
+    }
+}
+
+/**
+ * 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();
+    assert(rc == 0);
+
+    return 0;
+}
+
+/**
+ * main
+ *  
+ * The main function for the project. This function initializes the os, calls 
+ * init_tasks to initialize tasks (and possibly other objects), then starts the 
+ * OS. We should not return from os start. 
+ *  
+ * @return int NOTE: this function should never return!
+ */
+int
+main(void)
+{
+    int i;
+    int rc;
+    uint32_t seed;
+#if 0
+    int cnt;
+    struct nffs_area_desc descs[NFFS_AREA_MAX];
+#endif
+
+    /* Initialize OS */
+    os_init();
+
+    /* Set cputime to count at 1 usec increments */
+    rc = cputime_init(1000000);
+    assert(rc == 0);
+
+    rc = os_mempool_init(&g_mbuf_mempool, MBUF_NUM_MBUFS, 
+            MBUF_MEMBLOCK_SIZE, &g_mbuf_buffer[0], "mbuf_pool");
+    assert(rc == 0);
+
+    rc = os_mbuf_pool_init(&g_mbuf_pool, &g_mbuf_mempool, MBUF_MEMBLOCK_SIZE, 
+                           MBUF_NUM_MBUFS);
+    assert(rc == 0);
+
+    rc = os_msys_register(&g_mbuf_pool);
+    assert(rc == 0);
+
+    /* Dummy device address */
+#if BLETEST_CFG_ROLE == BLETEST_ROLE_ADVERTISER
+    g_dev_addr[0] = 0x00;
+    g_dev_addr[1] = 0x00;
+    g_dev_addr[2] = 0x00;
+    g_dev_addr[3] = 0x88;
+    g_dev_addr[4] = 0x88;
+    g_dev_addr[5] = 0x08;
+
+    g_bletest_cur_peer_addr[0] = 0x00;
+    g_bletest_cur_peer_addr[1] = 0x00;
+    g_bletest_cur_peer_addr[2] = 0x00;
+    g_bletest_cur_peer_addr[3] = 0x99;
+    g_bletest_cur_peer_addr[4] = 0x99;
+    g_bletest_cur_peer_addr[5] = 0x09;
+#else
+    g_dev_addr[0] = 0x00;
+    g_dev_addr[1] = 0x00;
+    g_dev_addr[2] = 0x00;
+    g_dev_addr[3] = 0x99;
+    g_dev_addr[4] = 0x99;
+    g_dev_addr[5] = 0x09;
+
+    g_bletest_cur_peer_addr[0] = 0x00;
+    g_bletest_cur_peer_addr[1] = 0x00;
+    g_bletest_cur_peer_addr[2] = 0x00;
+    g_bletest_cur_peer_addr[3] = 0x88;
+    g_bletest_cur_peer_addr[4] = 0x88;
+    g_bletest_cur_peer_addr[5] = 0x08;
+#endif
+
+    /* 
+     * Seed random number generator with least significant bytes of device
+     * address.
+     */ 
+    seed = 0;
+    for (i = 0; i < 4; ++i) {
+        seed |= g_dev_addr[i];
+        seed <<= 8;
+    }
+    srand(seed);
+
+    /* Set the led pin as an output */
+    g_led_pin = LED_BLINK_PIN;
+    hal_gpio_init_out(g_led_pin, 1);
+
+    /* Init the console */
+    rc = console_init(shell_console_rx_cb);
+    assert(rc == 0);
+
+#if 0
+    rc = hal_flash_init();
+    assert(rc == 0);
+
+    nffs_config.nc_num_inodes = 32;
+    nffs_config.nc_num_blocks = 64;
+    nffs_config.nc_num_files = 2;
+    nffs_config.nc_num_dirs = 2;
+    rc = nffs_init();
+    assert(rc == 0);
+
+    cnt = NFFS_AREA_MAX;
+    rc = flash_area_to_nffs_desc(FLASH_AREA_NFFS, &cnt, descs);
+    assert(rc == 0);
+    if (nffs_detect(descs) == FS_ECORRUPT) {
+        rc = nffs_format(descs);
+        assert(rc == 0);
+    }
+#endif
+
+    shell_task_init(SHELL_TASK_PRIO, shell_stack, SHELL_TASK_STACK_SIZE,
+                         SHELL_MAX_INPUT_LEN);
+
+    nmgr_task_init(NEWTMGR_TASK_PRIO, newtmgr_stack, NEWTMGR_TASK_STACK_SIZE);
+#if 0
+    imgmgr_module_init();
+#endif
+
+    /* Init statistics module */
+    stats_module_init();
+
+    /* Init tasks */
+    init_tasks();
+
+    /* Start the OS */
+    os_start();
+
+    /* os start should never return. If it does, this should be an error */
+    assert(0);
+
+    return rc;
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/dd032817/apps/bletiny/pkg.yml
----------------------------------------------------------------------
diff --git a/apps/bletiny/pkg.yml b/apps/bletiny/pkg.yml
new file mode 100644
index 0000000..b096e96
--- /dev/null
+++ b/apps/bletiny/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: apps/bletiny
+pkg.vers: 0.8.0
+pkg.description: Shell application exposing the nimble GAP and GATT.
+pkg.author: Christopher Collins <ccollins@apache.org>
+pkg.homepage:
+pkg.repository: https://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva
+pkg.keywords:
+
+pkg.deps: 
+    - libs/os 
+    - sys/log
+    - net/nimble/controller
+    - net/nimble/host
+    - libs/console/full
+    - libs/shell
+    - libs/baselibc

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/dd032817/apps/bletiny/src/bletiny_priv.h
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/bletiny_priv.h b/apps/bletiny/src/bletiny_priv.h
new file mode 100644
index 0000000..e32251b
--- /dev/null
+++ b/apps/bletiny/src/bletiny_priv.h
@@ -0,0 +1,169 @@
+/**
+ * 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_BLETINY_PRIV_
+#define H_BLETINY_PRIV_
+
+#include <inttypes.h>
+#include "nimble/nimble_opt.h"
+#include "log/log.h"
+#include "os/queue.h"
+
+#include "host/ble_gatt.h"
+struct ble_gap_white_entry;
+struct ble_hs_adv_fields;
+struct ble_gap_upd_params;
+struct ble_gap_crt_params;
+struct hci_adv_params;
+struct ble_l2cap_sig_update_req;
+struct ble_l2cap_sig_update_params;
+
+typedef int cmd_fn(int argc, char **argv);
+struct cmd_entry {
+    char *name;
+    cmd_fn *cb;
+};
+
+struct kv_pair {
+    char *key;
+    int val;
+};
+
+struct bletiny_dsc {
+    SLIST_ENTRY(bletiny_dsc) next;
+    struct ble_gatt_dsc dsc;
+};
+SLIST_HEAD(bletiny_dsc_list, bletiny_dsc);
+
+struct bletiny_chr {
+    SLIST_ENTRY(bletiny_chr) next;
+    struct ble_gatt_chr chr;
+
+    struct bletiny_dsc_list dscs;
+};
+SLIST_HEAD(bletiny_chr_list, bletiny_chr);
+
+struct bletiny_svc {
+    SLIST_ENTRY(bletiny_svc) next;
+    struct ble_gatt_service svc;
+
+    struct bletiny_chr_list chrs;
+};
+
+SLIST_HEAD(bletiny_svc_list, bletiny_svc);
+
+struct bletiny_conn {
+    uint16_t handle;
+    uint8_t addr_type;
+    uint8_t addr[6];
+
+    struct bletiny_svc_list svcs;
+};
+
+extern struct bletiny_conn bletiny_conns[NIMBLE_OPT_MAX_CONNECTIONS];
+extern int bletiny_num_conns;
+
+extern const char *bletiny_device_name;
+extern const uint16_t bletiny_appearance;
+extern const uint8_t bletiny_privacy_flag;
+extern uint8_t bletiny_reconnect_addr[6];
+extern uint8_t bletiny_pref_conn_params[8];
+extern uint8_t bletiny_gatt_service_changed[4];
+
+extern struct nmgr_transport nm_ble_transport;
+extern uint16_t nm_attr_val_handle;
+
+extern struct log bletiny_log;
+
+void print_addr(void *addr);
+void print_uuid(void *uuid128);
+const struct cmd_entry *parse_cmd_find(const struct cmd_entry *cmds,
+                                       char *name);
+struct kv_pair *parse_kv_find(struct kv_pair *kvs, char *name);
+char *parse_arg_find(char *key);
+long parse_arg_long_bounds(char *name, long min, long max, int *out_status);
+long parse_arg_long(char *name, int *staus);
+uint16_t parse_arg_uint16(char *name, int *status);
+uint16_t parse_arg_uint16_dflt(char *name, uint16_t dflt, int *out_status);
+uint32_t parse_arg_uint32(char *name, int *out_status);
+int parse_arg_kv(char *name, struct kv_pair *kvs);
+int parse_arg_byte_stream(char *name, int max_len, uint8_t *dst, int *out_len);
+int parse_arg_byte_stream_exact_length(char *name, uint8_t *dst, int len);
+int parse_arg_mac(char *name, uint8_t *dst);
+int parse_arg_uuid(char *name, uint8_t *dst_uuid128);
+int parse_err_too_few_args(char *cmd_name);
+int parse_arg_all(int argc, char **argv);
+int cmd_init(void);
+void periph_init(void);
+int nm_chr_access(uint16_t conn_handle, uint16_t attr_handle,
+                  uint8_t op, union ble_gatt_access_ctxt *ctxt,
+                  void *arg);
+int nm_rx_rsp(uint8_t *attr_val, uint16_t attr_len);
+void nm_init(void);
+void bletiny_lock(void);
+void bletiny_unlock(void);
+int bletiny_exchange_mtu(uint16_t conn_handle);
+int bletiny_disc_svcs(uint16_t conn_handle);
+int bletiny_disc_svc_by_uuid(uint16_t conn_handle, uint8_t *uuid128);
+int bletiny_disc_all_chrs(uint16_t conn_handle, uint16_t start_handle,
+                           uint16_t end_handle);
+int bletiny_disc_chrs_by_uuid(uint16_t conn_handle, uint16_t start_handle,
+                               uint16_t end_handle, uint8_t *uuid128);
+int bletiny_disc_all_dscs(uint16_t conn_handle, uint16_t chr_val_handle,
+                           uint16_t chr_end_handle);
+int bletiny_find_inc_svcs(uint16_t conn_handle, uint16_t start_handle,
+                           uint16_t end_handle);
+int bletiny_read(uint16_t conn_handle, uint16_t attr_handle);
+int bletiny_read_long(uint16_t conn_handle, uint16_t attr_handle);
+int bletiny_read_by_uuid(uint16_t conn_handle, uint16_t start_handle,
+                          uint16_t end_handle, uint8_t *uuid128);
+int bletiny_read_mult(uint16_t conn_handle, uint16_t *attr_handles,
+                       int num_attr_handles);
+int bletiny_write(uint16_t conn_handle, uint16_t attr_handle, void *value,
+                   uint16_t value_len);
+int bletiny_write_no_rsp(uint16_t conn_handle, uint16_t attr_handle,
+                          void *value, uint16_t value_len);
+int bletiny_write_long(uint16_t conn_handle, uint16_t attr_handle,
+                        void *value, uint16_t value_len);
+int bletiny_write_reliable(uint16_t conn_handle, struct ble_gatt_attr *attrs,
+                            int num_attrs);
+int bletiny_adv_start(int disc, int conn, uint8_t *peer_addr, int addr_type,
+                       struct hci_adv_params *params);
+int bletiny_adv_stop(void);
+int bletiny_conn_initiate(int addr_type, uint8_t *peer_addr,
+                           struct ble_gap_crt_params *params);
+int bletiny_conn_cancel(void);
+int bletiny_term_conn(uint16_t conn_handle);
+int bletiny_wl_set(struct ble_gap_white_entry *white_list,
+                    int white_list_count);
+int bletiny_scan(uint32_t dur_ms, uint8_t disc_mode, uint8_t scan_type,
+                  uint8_t filter_policy);
+int bletiny_set_adv_data(struct ble_hs_adv_fields *adv_fields);
+int bletiny_update_conn(uint16_t conn_handle,
+                         struct ble_gap_upd_params *params);
+void bletiny_chrup(uint16_t attr_handle);
+int bletiny_l2cap_update(uint16_t conn_handle,
+                          struct ble_l2cap_sig_update_params *params);
+int bletiny_show_rssi(uint16_t conn_handle);
+
+#define BLETINY_LOG_MODULE  (LOG_MODULE_PERUSER + 0)
+#define BLETINY_LOG(lvl, ...) \
+    LOG_ ## lvl(&bletiny_log, BLETINY_LOG_MODULE, __VA_ARGS__)
+
+#endif


Mime
View raw message