You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2018/05/22 16:47:14 UTC

[GitHub] aditihilbert closed pull request #1116: Remove deprecated bletiny application

aditihilbert closed pull request #1116: Remove deprecated bletiny application
URL: https://github.com/apache/mynewt-core/pull/1116
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/README.md b/README.md
index 15cc5b5731..39b646166f 100644
--- a/README.md
+++ b/README.md
@@ -145,8 +145,7 @@ host-only implementation, such as Linux's BlueZ, can interface with this
 application via HCI over UART.
 * [bleprph](https://github.com/apache/mynewt-core/tree/master/apps/bleprph): An
   implementation of a minimal BLE peripheral.
-* [bletiny](https://github.com/apache/mynewt-core/tree/master/apps/bletiny): A
-  stripped down interface to the Apache Mynewt Bluetooth stack.
+* [btshell](https://github.com/apache/mynewt-core/tree/master/apps/btshell): Shell interface to the Apache Mynewt Bluetooth stack.
 * [bleuart](https://github.com/apache/mynewt-core/tree/master/apps/bleuart):
 Implements a simple BLE peripheral that supports the Nordic
 UART / Serial Port Emulation service
diff --git a/apps/bletiny/pkg.yml b/apps/bletiny/pkg.yml
deleted file mode 100644
index 540d34cb9e..0000000000
--- a/apps/bletiny/pkg.yml
+++ /dev/null
@@ -1,39 +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.
-#
-pkg.name: apps/bletiny
-pkg.type: app
-pkg.description: Shell application exposing the nimble GAP and GATT.
-pkg.author: "Apache Mynewt <de...@mynewt.apache.org>"
-pkg.homepage: "http://mynewt.apache.org/"
-pkg.keywords:
-
-pkg.deps: 
-    - kernel/os 
-    - net/nimble/controller
-    - net/nimble/host
-    - net/nimble/host/services/gap
-    - net/nimble/host/services/gatt
-    - net/nimble/host/store/ram
-    - net/nimble/transport/ram
-    - sys/console/full
-    - sys/log/full
-    - sys/stats/full
-    - sys/shell
-
-pkg.deps.BLETINY_ANS:
-    - net/nimble/host/services/ans
diff --git a/apps/bletiny/src/bletiny.h b/apps/bletiny/src/bletiny.h
deleted file mode 100644
index 05f14ef123..0000000000
--- a/apps/bletiny/src/bletiny.h
+++ /dev/null
@@ -1,238 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-#ifndef H_BLETINY_PRIV_
-#define H_BLETINY_PRIV_
-
-#include <inttypes.h>
-#include "os/mynewt.h"
-#include "nimble/ble.h"
-#include "nimble/nimble_opt.h"
-#include "log/log.h"
-
-#include "host/ble_gatt.h"
-#include "host/ble_gap.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct ble_gap_white_entry;
-struct ble_hs_adv_fields;
-struct ble_gap_upd_params;
-struct ble_gap_conn_params;
-struct hci_adv_params;
-struct ble_l2cap_sig_update_req;
-struct ble_l2cap_sig_update_params;
-union ble_store_value;
-union ble_store_key;
-struct ble_gap_adv_params;
-struct ble_gap_conn_desc;
-struct ble_gap_disc_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_svc svc;
-    struct bletiny_chr_list chrs;
-};
-
-SLIST_HEAD(bletiny_svc_list, bletiny_svc);
-
-struct bletiny_l2cap_coc {
-    SLIST_ENTRY(bletiny_l2cap_coc) next;
-    struct ble_l2cap_chan *chan;
-};
-
-SLIST_HEAD(bletiny_l2cap_coc_list, bletiny_l2cap_coc);
-
-struct bletiny_conn {
-    uint16_t handle;
-    struct bletiny_svc_list svcs;
-    struct bletiny_l2cap_coc_list coc_list;
-};
-
-extern struct bletiny_conn bletiny_conns[MYNEWT_VAL(BLE_MAX_CONNECTIONS)];
-extern int bletiny_num_conns;
-
-extern uint16_t nm_attr_val_handle;
-
-extern struct log bletiny_log;
-
-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);
-int parse_arg_find_idx(const char *key);
-char *parse_arg_extract(const char *key);
-long parse_arg_long_bounds(char *name, long min, long max, int *out_status);
-long parse_arg_long_bounds_default(char *name, long min, long max,
-                                   long dflt, int *out_status);
-uint64_t parse_arg_uint64_bounds(char *name, uint64_t min,
-                                 uint64_t max, int *out_status);
-long parse_arg_long(char *name, int *staus);
-uint8_t parse_arg_bool(char *name, int *status);
-uint8_t parse_arg_bool_default(char *name, uint8_t dflt, int *out_status);
-uint8_t parse_arg_uint8(char *name, int *status);
-uint8_t parse_arg_uint8_dflt(char *name, uint8_t dflt, int *out_status);
-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);
-uint32_t parse_arg_uint32_dflt(char *name, uint32_t dflt, int *out_status);
-uint64_t parse_arg_uint64(char *name, int *out_status);
-int parse_arg_kv(char *name, struct kv_pair *kvs, int *out_status);
-int parse_arg_kv_default(char *name, struct kv_pair *kvs, int def_val,
-                         int *out_status);
-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, ble_uuid_any_t *uuid);
-int parse_err_too_few_args(char *cmd_name);
-int parse_arg_all(int argc, char **argv);
-int cmd_init(void);
-int nm_chr_access(uint16_t conn_handle, uint16_t attr_handle,
-                  uint8_t op, struct 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, const ble_uuid_t *uuid);
-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, const ble_uuid_t *uuid);
-int bletiny_disc_all_dscs(uint16_t conn_handle, uint16_t start_handle,
-                          uint16_t end_handle);
-int bletiny_disc_full(uint16_t conn_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,
-                      uint16_t offset);
-int bletiny_read_by_uuid(uint16_t conn_handle, uint16_t start_handle,
-                          uint16_t end_handle, const ble_uuid_t *uuid);
-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,
-                  struct os_mbuf *om);
-int bletiny_write_no_rsp(uint16_t conn_handle, uint16_t attr_handle,
-                         struct os_mbuf *om);
-int bletiny_write_long(uint16_t conn_handle, uint16_t attr_handle,
-                       uint16_t offset, struct os_mbuf *om);
-int bletiny_write_reliable(uint16_t conn_handle,
-                           struct ble_gatt_attr *attrs, int num_attrs);
-int bletiny_adv_start(uint8_t own_addr_type, const ble_addr_t *direct_addr,
-                      int32_t duration_ms,
-                      const struct ble_gap_adv_params *params);
-int bletiny_adv_stop(void);
-int bletiny_conn_initiate(uint8_t own_addr_type, const ble_addr_t *peer_addr,
-                          int32_t duration_ms,
-                          struct ble_gap_conn_params *params);
-int bletiny_ext_conn_initiate(uint8_t own_addr_type, const ble_addr_t *peer_addr,
-                              int32_t duration_ms,
-                              struct ble_gap_conn_params *phy_1m_params,
-                              struct ble_gap_conn_params *phy_2m_params,
-                              struct ble_gap_conn_params *phy_coded_params);
-int bletiny_conn_cancel(void);
-int bletiny_term_conn(uint16_t conn_handle, uint8_t reason);
-int bletiny_wl_set(ble_addr_t *addrs, int addrs_count);
-int bletiny_scan(uint8_t own_addr_type, int32_t duration_ms,
-                 const struct ble_gap_disc_params *disc_params);
-int bletiny_ext_scan(uint8_t own_addr_type, uint16_t duration, uint16_t period,
-                     uint8_t filter_duplicates, uint8_t filter_policy,
-                     uint8_t limited,
-                     const struct ble_gap_ext_disc_params *uncoded_params,
-                     const struct ble_gap_ext_disc_params *coded_params);
-int bletiny_scan_cancel(void);
-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_datalen(uint16_t conn_handle, uint16_t tx_octets,
-                    uint16_t tx_time);
-int bletiny_l2cap_update(uint16_t conn_handle,
-                          struct ble_l2cap_sig_update_params *params);
-int bletiny_sec_start(uint16_t conn_handle);
-int bletiny_sec_pair(uint16_t conn_handle);
-int bletiny_sec_restart(uint16_t conn_handle, uint8_t *ltk, uint16_t ediv,
-                        uint64_t rand_val, int auth);
-int bletiny_tx_start(uint16_t handle, uint16_t len, uint16_t rate,
-                     uint16_t num);
-int bletiny_rssi(uint16_t conn_handle, int8_t *out_rssi);
-int bletiny_l2cap_create_srv(uint16_t psm);
-int bletiny_l2cap_connect(uint16_t conn, uint16_t psm);
-int bletiny_l2cap_disconnect(uint16_t conn, uint16_t idx);
-int bletiny_l2cap_send(uint16_t conn, uint16_t idx, uint16_t bytes);
-#define BLETINY_LOG_MODULE  (LOG_MODULE_PERUSER + 0)
-#define BLETINY_LOG(lvl, ...) \
-    LOG_ ## lvl(&bletiny_log, BLETINY_LOG_MODULE, __VA_ARGS__)
-
-/** GATT server. */
-#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
-
-void gatt_svr_register_cb(struct ble_gatt_register_ctxt *ctxt, void *arg);
-int gatt_svr_init(void);
-
-/** Misc. */
-void print_bytes(const uint8_t *bytes, int len);
-void print_mbuf(const struct os_mbuf *om);
-void print_addr(const void *addr);
-void print_uuid(const ble_uuid_t *uuid);
-int svc_is_empty(const struct bletiny_svc *svc);
-uint16_t chr_end_handle(const struct bletiny_svc *svc,
-                        const struct bletiny_chr *chr);
-int chr_is_empty(const struct bletiny_svc *svc, const struct bletiny_chr *chr);
-void print_conn_desc(const struct ble_gap_conn_desc *desc);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/apps/bletiny/src/cmd.c b/apps/bletiny/src/cmd.c
deleted file mode 100644
index ed1c45e1c8..0000000000
--- a/apps/bletiny/src/cmd.c
+++ /dev/null
@@ -1,4344 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-#include <errno.h>
-#include <string.h>
-#include "bsp/bsp.h"
-#include "console/console.h"
-#include "shell/shell.h"
-
-#include "nimble/ble.h"
-#include "nimble/nimble_opt.h"
-#include "nimble/hci_common.h"
-#include "host/ble_gap.h"
-#include "host/ble_hs_adv.h"
-#include "host/ble_sm.h"
-#include "host/ble_eddystone.h"
-#include "host/ble_hs_id.h"
-#include "services/gatt/ble_svc_gatt.h"
-#include "../src/ble_l2cap_priv.h"
-#include "../src/ble_hs_priv.h"
-
-#include "bletiny.h"
-
-#define CMD_BUF_SZ      256
-
-static int cmd_b_exec(int argc, char **argv);
-static struct shell_cmd cmd_b = {
-    .sc_cmd = "b",
-    .sc_cmd_func = cmd_b_exec
-};
-
-static bssnz_t uint8_t cmd_buf[CMD_BUF_SZ];
-
-static struct kv_pair cmd_own_addr_types[] = {
-    { "public",     BLE_OWN_ADDR_PUBLIC },
-    { "random",     BLE_OWN_ADDR_RANDOM },
-    { "rpa_pub",    BLE_OWN_ADDR_RPA_PUBLIC_DEFAULT },
-    { "rpa_rnd",    BLE_OWN_ADDR_RPA_RANDOM_DEFAULT },
-    { NULL }
-};
-
-static struct kv_pair cmd_peer_addr_types[] = {
-    { "public",     BLE_ADDR_PUBLIC },
-    { "random",     BLE_ADDR_RANDOM },
-    { "public_id",  BLE_ADDR_PUBLIC_ID },
-    { "random_id",  BLE_ADDR_RANDOM_ID },
-    { NULL }
-};
-
-static struct kv_pair cmd_addr_type[] = {
-    { "public",     BLE_ADDR_PUBLIC },
-    { "random",     BLE_ADDR_RANDOM },
-    { NULL }
-};
-
-/*****************************************************************************
- * $misc                                                                     *
- *****************************************************************************/
-
-static int
-cmd_exec(const struct cmd_entry *cmds, int argc, char **argv)
-{
-    const struct cmd_entry *cmd;
-    int rc;
-
-    if (argc <= 1) {
-        return parse_err_too_few_args(argv[0]);
-    }
-
-    cmd = parse_cmd_find(cmds, argv[1]);
-    if (cmd == NULL) {
-        console_printf("Error: unknown %s command: %s\n", argv[0], argv[1]);
-        return -1;
-    }
-
-    rc = cmd->cb(argc - 1, argv + 1);
-    if (rc != 0) {
-        return rc;
-    }
-
-    return 0;
-}
-
-static void
-cmd_print_dsc(struct bletiny_dsc *dsc)
-{
-    console_printf("            dsc_handle=%d uuid=", dsc->dsc.handle);
-    print_uuid(&dsc->dsc.uuid.u);
-    console_printf("\n");
-}
-
-static void
-cmd_print_chr(struct bletiny_chr *chr)
-{
-    struct bletiny_dsc *dsc;
-
-    console_printf("        def_handle=%d val_handle=%d properties=0x%02x "
-                   "uuid=", chr->chr.def_handle, chr->chr.val_handle,
-                   chr->chr.properties);
-    print_uuid(&chr->chr.uuid.u);
-    console_printf("\n");
-
-    SLIST_FOREACH(dsc, &chr->dscs, next) {
-        cmd_print_dsc(dsc);
-    }
-}
-
-static void
-cmd_print_svc(struct bletiny_svc *svc)
-{
-    struct bletiny_chr *chr;
-
-    console_printf("    start=%d end=%d uuid=", svc->svc.start_handle,
-                   svc->svc.end_handle);
-    print_uuid(&svc->svc.uuid.u);
-    console_printf("\n");
-
-    SLIST_FOREACH(chr, &svc->chrs, next) {
-        cmd_print_chr(chr);
-    }
-}
-
-static int
-cmd_parse_conn_start_end(uint16_t *out_conn, uint16_t *out_start,
-                         uint16_t *out_end)
-{
-    int rc;
-
-    *out_conn = parse_arg_uint16("conn", &rc);
-    if (rc != 0) {
-        return rc;
-    }
-
-    *out_start = parse_arg_uint16("start", &rc);
-    if (rc != 0) {
-        return rc;
-    }
-
-    *out_end = parse_arg_uint16("end", &rc);
-    if (rc != 0) {
-        return rc;
-    }
-
-    return 0;
-}
-
-static int
-cmd_parse_eddystone_url(char *full_url, uint8_t *out_scheme, char *out_body,
-                        uint8_t *out_body_len, uint8_t *out_suffix)
-{
-    static const struct {
-        char *s;
-        uint8_t scheme;
-    } schemes[] = {
-        { "http://www.", BLE_EDDYSTONE_URL_SCHEME_HTTP_WWW },
-        { "https://www.", BLE_EDDYSTONE_URL_SCHEME_HTTPS_WWW },
-        { "http://", BLE_EDDYSTONE_URL_SCHEME_HTTP },
-        { "https://", BLE_EDDYSTONE_URL_SCHEME_HTTPS },
-    };
-
-    static const struct {
-        char *s;
-        uint8_t code;
-    } suffixes[] = {
-        { ".com/", BLE_EDDYSTONE_URL_SUFFIX_COM_SLASH },
-        { ".org/", BLE_EDDYSTONE_URL_SUFFIX_ORG_SLASH },
-        { ".edu/", BLE_EDDYSTONE_URL_SUFFIX_EDU_SLASH },
-        { ".net/", BLE_EDDYSTONE_URL_SUFFIX_NET_SLASH },
-        { ".info/", BLE_EDDYSTONE_URL_SUFFIX_INFO_SLASH },
-        { ".biz/", BLE_EDDYSTONE_URL_SUFFIX_BIZ_SLASH },
-        { ".gov/", BLE_EDDYSTONE_URL_SUFFIX_GOV_SLASH },
-        { ".com", BLE_EDDYSTONE_URL_SUFFIX_COM },
-        { ".org", BLE_EDDYSTONE_URL_SUFFIX_ORG },
-        { ".edu", BLE_EDDYSTONE_URL_SUFFIX_EDU },
-        { ".net", BLE_EDDYSTONE_URL_SUFFIX_NET },
-        { ".info", BLE_EDDYSTONE_URL_SUFFIX_INFO },
-        { ".biz", BLE_EDDYSTONE_URL_SUFFIX_BIZ },
-        { ".gov", BLE_EDDYSTONE_URL_SUFFIX_GOV },
-    };
-
-    char *prefix;
-    char *suffix;
-    int full_url_len;
-    int prefix_len;
-    int suffix_len;
-    int suffix_idx;
-    int rc;
-    int i;
-
-    full_url_len = strlen(full_url);
-
-    rc = BLE_HS_EINVAL;
-    for (i = 0; i < sizeof schemes / sizeof schemes[0]; i++) {
-        prefix = schemes[i].s;
-        prefix_len = strlen(schemes[i].s);
-
-        if (full_url_len >= prefix_len &&
-            memcmp(full_url, prefix, prefix_len) == 0) {
-
-            *out_scheme = i;
-            rc = 0;
-            break;
-        }
-    }
-    if (rc != 0) {
-        return rc;
-    }
-
-    rc = BLE_HS_EINVAL;
-    for (i = 0; i < sizeof suffixes / sizeof suffixes[0]; i++) {
-        suffix = suffixes[i].s;
-        suffix_len = strlen(suffixes[i].s);
-
-        suffix_idx = full_url_len - suffix_len;
-        if (suffix_idx >= prefix_len &&
-            memcmp(full_url + suffix_idx, suffix, suffix_len) == 0) {
-
-            *out_suffix = i;
-            rc = 0;
-            break;
-        }
-    }
-    if (rc != 0) {
-        *out_suffix = BLE_EDDYSTONE_URL_SUFFIX_NONE;
-        *out_body_len = full_url_len - prefix_len;
-    } else {
-        *out_body_len = full_url_len - prefix_len - suffix_len;
-    }
-
-    memcpy(out_body, full_url + prefix_len, *out_body_len);
-
-    return 0;
-}
-
-/*****************************************************************************
- * $advertise                                                                *
- *****************************************************************************/
-
-static struct kv_pair cmd_adv_conn_modes[] = {
-    { "non", BLE_GAP_CONN_MODE_NON },
-    { "und", BLE_GAP_CONN_MODE_UND },
-    { "dir", BLE_GAP_CONN_MODE_DIR },
-    { NULL }
-};
-
-static struct kv_pair cmd_adv_disc_modes[] = {
-    { "non", BLE_GAP_DISC_MODE_NON },
-    { "ltd", BLE_GAP_DISC_MODE_LTD },
-    { "gen", BLE_GAP_DISC_MODE_GEN },
-    { NULL }
-};
-
-static struct kv_pair cmd_adv_filt_types[] = {
-    { "none", BLE_HCI_ADV_FILT_NONE },
-    { "scan", BLE_HCI_ADV_FILT_SCAN },
-    { "conn", BLE_HCI_ADV_FILT_CONN },
-    { "both", BLE_HCI_ADV_FILT_BOTH },
-    { NULL }
-};
-
-static void
-print_enumerate_options(struct kv_pair *options)
-{
-    int i;
-    for (i = 0; options[i].key != NULL; i++) {
-        if (i != 0) {
-            console_printf("|");
-        }
-        console_printf("%s(%d)", options[i].key, options[i].val);
-    }
-}
-
-static void
-help_cmd_long_bounds(const char *cmd_name, long min, long max)
-{
-    console_printf("\t%s=<%ld-%ld>\n", cmd_name, min, max);
-}
-
-static void
-help_cmd_long_bounds_dflt(const char *cmd_name, long min, long max, long dflt)
-{
-    console_printf("\t%s=[%ld-%ld] default=%ld\n", cmd_name, min, max, dflt);
-}
-
-static void
-help_cmd_val(const char *cmd_name)
-{
-    console_printf("\t%s=<val>\n", cmd_name);
-}
-
-static void
-help_cmd_long(const char *cmd_name)
-{
-    help_cmd_val(cmd_name);
-}
-
-static void
-help_cmd_bool(const char *cmd_name)
-{
-    console_printf("\t%s=<0|1>\n", cmd_name);
-}
-
-static void
-help_cmd_bool_dflt(const char *cmd_name, bool dflt)
-{
-    console_printf("\t%s=[0|1] default=%d\n", cmd_name, dflt);
-}
-
-static void
-help_cmd_uint8(const char *cmd_name)
-{
-    help_cmd_val(cmd_name);
-}
-
-static void
-help_cmd_uint8_dflt(const char *cmd_name, uint8_t dflt)
-{
-    console_printf("\t%s=[val] default=%u\n", cmd_name, dflt);
-}
-
-static void
-help_cmd_uint16(const char *cmd_name)
-{
-    help_cmd_val(cmd_name);
-}
-
-static void
-help_cmd_uint16_dflt(const char *cmd_name, uint16_t dflt)
-{
-    console_printf("\t%s=[val] default=%u\n", cmd_name, dflt);
-}
-
-static void
-help_cmd_uint32(const char *cmd_name)
-{
-    help_cmd_val(cmd_name);
-}
-
-static void
-help_cmd_uint64(const char *cmd_name)
-{
-    help_cmd_val(cmd_name);
-}
-
-static void
-help_cmd_kv(const char *cmd_name, struct kv_pair *options)
-{
-    console_printf("\t%s=<", cmd_name);
-    print_enumerate_options(options);
-    console_printf(">\n");
-}
-
-static void
-help_cmd_kv_dflt(const char *cmd_name, struct kv_pair *options, int dflt)
-{
-    console_printf("\t%s=[", cmd_name);
-    print_enumerate_options(options);
-    console_printf("] default=%d\n", dflt);
-}
-
-static void
-help_cmd_byte_stream(const char *cmd_name)
-{
-    console_printf("\t%s=<xx:xx:xx: ...>\n", cmd_name);
-}
-
-static void
-help_cmd_byte_stream_exact_length(const char *cmd_name, int len)
-{
-    console_printf("\t%s=<xx:xx:xx: ...> len=%d\n", cmd_name, len);
-}
-
-static void
-help_cmd_uuid(const char *cmd_name)
-{
-    console_printf("\t%s=<UUID>\n", cmd_name);
-}
-
-static void
-help_cmd_extract(const char *cmd_name)
-{
-    console_printf("\t%s=<str>\n", cmd_name);
-}
-
-static void
-help_cmd_conn_start_end(void)
-{
-    console_printf("\t%s=<val> %s=<val> %s=<val>\n", "conn", "start", "end");
-}
-
-#if !MYNEWT_VAL(BLETINY_HELP)
-static void
-bletiny_help_disabled(void)
-{
-    console_printf("bletiny help is disabled in this build\n");
-}
-#endif
-
-static void
-bletiny_adv_help(void)
-{
-#if !MYNEWT_VAL(BLETINY_HELP)
-    bletiny_help_disabled();
-    return;
-#endif
-
-    console_printf("Available adv commands: \n");
-    console_printf("\thelp\n");
-    console_printf("\tstop\n");
-    console_printf("Available adv params: \n");
-    help_cmd_kv_dflt("conn", cmd_adv_conn_modes, BLE_GAP_CONN_MODE_UND);
-    help_cmd_kv_dflt("disc", cmd_adv_disc_modes, BLE_GAP_DISC_MODE_GEN);
-    help_cmd_kv_dflt("peer_addr_type", cmd_peer_addr_types, BLE_ADDR_PUBLIC);
-    help_cmd_byte_stream_exact_length("peer_addr", 6);
-    help_cmd_kv_dflt("own_addr_type", cmd_own_addr_types,
-                     BLE_OWN_ADDR_PUBLIC);
-    help_cmd_long_bounds_dflt("chan_map", 0, 0xff, 0);
-    help_cmd_kv_dflt("filt", cmd_adv_filt_types, BLE_HCI_ADV_FILT_NONE);
-    help_cmd_long_bounds_dflt("itvl_min", 0, UINT16_MAX, 0);
-    help_cmd_long_bounds_dflt("itvl_max", 0, UINT16_MAX, 0);
-    help_cmd_long_bounds_dflt("hd", 0, 1, 0);
-    help_cmd_long_bounds_dflt("dur", 1, INT32_MAX, BLE_HS_FOREVER);
-}
-
-static int
-cmd_adv(int argc, char **argv)
-{
-    struct ble_gap_adv_params params;
-    int32_t duration_ms;
-    ble_addr_t peer_addr;
-    ble_addr_t *peer_addr_param = &peer_addr;
-    uint8_t own_addr_type;
-    int rc;
-
-    if (argc > 1 && strcmp(argv[1], "help") == 0) {
-        bletiny_adv_help();
-        return 0;
-    }
-
-    if (argc > 1 && strcmp(argv[1], "stop") == 0) {
-        rc = bletiny_adv_stop();
-        if (rc != 0) {
-            console_printf("advertise stop fail: %d\n", rc);
-            return rc;
-        }
-
-        return 0;
-    }
-
-    params.conn_mode = parse_arg_kv_default("conn", cmd_adv_conn_modes,
-                                            BLE_GAP_CONN_MODE_UND, &rc);
-    if (rc != 0) {
-        console_printf("invalid 'conn' parameter\n");
-        help_cmd_kv_dflt("conn", cmd_adv_conn_modes, BLE_GAP_CONN_MODE_UND);
-        return rc;
-    }
-
-    params.disc_mode = parse_arg_kv_default("disc", cmd_adv_disc_modes,
-                                            BLE_GAP_DISC_MODE_GEN, &rc);
-    if (rc != 0) {
-        console_printf("invalid 'disc' parameter\n");
-        help_cmd_kv_dflt("disc", cmd_adv_disc_modes, BLE_GAP_DISC_MODE_GEN);
-        return rc;
-    }
-
-    peer_addr.type = parse_arg_kv_default(
-        "peer_addr_type", cmd_peer_addr_types, BLE_ADDR_PUBLIC, &rc);
-    if (rc != 0) {
-        console_printf("invalid 'peer_addr_type' parameter\n");
-        help_cmd_kv_dflt("peer_addr_type", cmd_peer_addr_types,
-                         BLE_ADDR_PUBLIC);
-        return rc;
-    }
-
-    rc = parse_arg_mac("peer_addr", peer_addr.val);
-    if (rc == ENOENT) {
-        peer_addr_param = NULL;
-    } else if (rc != 0) {
-        console_printf("invalid 'peer_addr' parameter\n");
-        help_cmd_byte_stream_exact_length("peer_addr", 6);
-        return rc;
-    }
-
-    own_addr_type = parse_arg_kv_default(
-        "own_addr_type", cmd_own_addr_types, BLE_OWN_ADDR_PUBLIC, &rc);
-    if (rc != 0) {
-        console_printf("invalid 'own_addr_type' parameter\n");
-        help_cmd_kv_dflt("own_addr_type", cmd_own_addr_types,
-                         BLE_OWN_ADDR_PUBLIC);
-        return rc;
-    }
-
-    params.channel_map = parse_arg_long_bounds_default("chan_map", 0, 0xff, 0,
-                                                       &rc);
-    if (rc != 0) {
-        console_printf("invalid 'chan_map' parameter\n");
-        help_cmd_long_bounds_dflt("chan_map", 0, 0xff, 0);
-        return rc;
-    }
-
-    params.filter_policy = parse_arg_kv_default("filt", cmd_adv_filt_types,
-                                                BLE_HCI_ADV_FILT_NONE, &rc);
-    if (rc != 0) {
-        console_printf("invalid 'filt' parameter\n");
-        help_cmd_kv_dflt("filt", cmd_adv_filt_types, BLE_HCI_ADV_FILT_NONE);
-        return rc;
-    }
-
-    params.itvl_min = parse_arg_long_bounds_default("itvl_min", 0, UINT16_MAX,
-                                                    0, &rc);
-    if (rc != 0) {
-        console_printf("invalid 'itvl_min' parameter\n");
-        help_cmd_long_bounds_dflt("itvl_min", 0, UINT16_MAX, 0);
-        return rc;
-    }
-
-    params.itvl_max = parse_arg_long_bounds_default("itvl_max", 0, UINT16_MAX,
-                                                    0, &rc);
-    if (rc != 0) {
-        console_printf("invalid 'itvl_max' parameter\n");
-        help_cmd_long_bounds_dflt("itvl_max", 0, UINT16_MAX, 0);
-        return rc;
-    }
-
-    params.high_duty_cycle = parse_arg_long_bounds_default("hd", 0, 1, 0, &rc);
-    if (rc != 0) {
-        console_printf("invalid 'hd' parameter\n");
-        help_cmd_long_bounds_dflt("hd", 0, 1, 0);
-        return rc;
-    }
-
-    duration_ms = parse_arg_long_bounds_default("dur", 1, INT32_MAX,
-                                                BLE_HS_FOREVER, &rc);
-    if (rc != 0) {
-        console_printf("invalid 'dur' parameter\n");
-        help_cmd_long_bounds_dflt("dur", 1, INT32_MAX, BLE_HS_FOREVER);
-        return rc;
-    }
-
-    rc = bletiny_adv_start(own_addr_type, peer_addr_param, duration_ms,
-                           &params);
-    if (rc != 0) {
-        console_printf("advertise fail: %d\n", rc);
-        return rc;
-    }
-
-    return 0;
-}
-
-/*****************************************************************************
- * $connect                                                                  *
- *****************************************************************************/
-
-static struct kv_pair cmd_ext_phy_opts[] = {
-    { "none",        0x00 },
-    { "1M",          0x01 },
-    { "coded",       0x02 },
-    { "both",        0x03 },
-    { "all",         0x04 },
-    { NULL }
-};
-
-static void
-bletiny_conn_help(void)
-{
-#if !MYNEWT_VAL(BLETINY_HELP)
-    bletiny_help_disabled();
-    return;
-#endif
-
-    console_printf("Available conn commands: \n");
-    console_printf("\thelp\n");
-    console_printf("\tcancel\n");
-    console_printf("Available conn params: \n");
-    help_cmd_kv_dflt("ext", cmd_ext_phy_opts, 0);
-    help_cmd_kv_dflt("peer_addr_type", cmd_peer_addr_types, BLE_ADDR_PUBLIC);
-    help_cmd_byte_stream_exact_length("peer_addr", 6);
-    help_cmd_kv_dflt("own_addr_type", cmd_own_addr_types,
-                     BLE_OWN_ADDR_PUBLIC);
-    help_cmd_uint16_dflt("scan_itvl", 0x0010);
-    help_cmd_uint16_dflt("scan_window", 0x0010);
-    help_cmd_uint16_dflt("itvl_min", BLE_GAP_INITIAL_CONN_ITVL_MIN);
-    help_cmd_uint16_dflt("itvl_max", BLE_GAP_INITIAL_CONN_ITVL_MAX);
-    help_cmd_uint16_dflt("latency", 0);
-    help_cmd_uint16_dflt("timeout", 0x0100);
-    help_cmd_uint16_dflt("min_ce_len", 0x0010);
-    help_cmd_uint16_dflt("max_ce_len", 0x0300);
-    help_cmd_long_bounds_dflt("dur", 1, INT32_MAX, 0);
-    console_printf("Available conn params when ext != none: \n");
-    help_cmd_uint16_dflt("coded_scan_itvl", 0x0010);
-    help_cmd_uint16_dflt("coded_scan_window", 0x0010);
-    help_cmd_uint16_dflt("coded_itvl_min", BLE_GAP_INITIAL_CONN_ITVL_MIN);
-    help_cmd_uint16_dflt("coded_itvl_max", BLE_GAP_INITIAL_CONN_ITVL_MAX);
-    help_cmd_uint16_dflt("coded_latency", 0);
-    help_cmd_uint16_dflt("coded_timeout", 0x0100);
-    help_cmd_uint16_dflt("coded_min_ce_len", 0x0010);
-    help_cmd_uint16_dflt("coded_max_ce_len", 0x0300);
-    help_cmd_uint16_dflt("2M_itvl_min", BLE_GAP_INITIAL_CONN_ITVL_MIN);
-    help_cmd_uint16_dflt("2M_itvl_max", BLE_GAP_INITIAL_CONN_ITVL_MAX);
-    help_cmd_uint16_dflt("2M_latency", 0);
-    help_cmd_uint16_dflt("2M_timeout", 0x0100);
-    help_cmd_uint16_dflt("2M_min_ce_len", 0x0010);
-    help_cmd_uint16_dflt("2M_max_ce_len", 0x0300);
-}
-
-static int
-cmd_conn(int argc, char **argv)
-{
-    struct ble_gap_conn_params phy_1M_params = {0};
-    struct ble_gap_conn_params phy_coded_params = {0};
-    struct ble_gap_conn_params phy_2M_params = {0};
-    int32_t duration_ms;
-    ble_addr_t peer_addr;
-    ble_addr_t *peer_addr_param = &peer_addr;
-    int own_addr_type;
-    int rc;
-    uint8_t ext;
-
-    if (argc > 1 && strcmp(argv[1], "help") == 0) {
-        bletiny_conn_help();
-        return 0;
-    }
-
-    if (argc > 1 && strcmp(argv[1], "cancel") == 0) {
-        rc = bletiny_conn_cancel();
-        if (rc != 0) {
-            console_printf("connection cancel fail: %d\n", rc);
-            return rc;
-        }
-
-        return 0;
-    }
-
-    ext = parse_arg_kv_default("ext", cmd_ext_phy_opts, 0, &rc);
-    if (rc != 0) {
-        help_cmd_kv_dflt("ext", cmd_ext_phy_opts, 0);
-        console_printf("invalid 'ext' parameter\n");
-        return rc;
-    }
-
-    console_printf("Connection type: %d\n", ext);
-
-    peer_addr.type = parse_arg_kv_default("peer_addr_type", cmd_peer_addr_types,
-                                          BLE_ADDR_PUBLIC, &rc);
-    if (rc != 0) {
-        console_printf("invalid 'peer_addr_type' parameter\n");
-        help_cmd_kv_dflt("peer_addr_type", cmd_peer_addr_types,
-                         BLE_ADDR_PUBLIC);
-        return rc;
-    }
-
-    rc = parse_arg_mac("peer_addr", peer_addr.val);
-    if (rc == ENOENT) {
-        /* Allow "addr" for backwards compatibility. */
-        rc = parse_arg_mac("addr", peer_addr.val);
-    }
-
-    if (rc == ENOENT) {
-        /* With no "peer_addr" specified we'll use white list */
-        peer_addr_param = NULL;
-    } else if (rc != 0) {
-        console_printf("invalid 'peer_addr' parameter\n");
-        help_cmd_byte_stream_exact_length("peer_addr", 6);
-        return rc;
-    }
-
-    own_addr_type = parse_arg_kv_default("own_addr_type", cmd_own_addr_types,
-                                         BLE_OWN_ADDR_PUBLIC, &rc);
-    if (rc != 0) {
-        console_printf("invalid 'own_addr_type' parameter\n");
-        help_cmd_kv_dflt("own_addr_type", cmd_own_addr_types,
-                         BLE_OWN_ADDR_PUBLIC);
-        return rc;
-    }
-
-    phy_1M_params.scan_itvl = parse_arg_uint16_dflt("scan_itvl", 0x0010, &rc);
-    if (rc != 0) {
-        console_printf("invalid 'scan_itvl' parameter\n");
-        help_cmd_uint16_dflt("scan_itvl", 0x0010);
-        return rc;
-    }
-
-    phy_1M_params.scan_window = parse_arg_uint16_dflt("scan_window", 0x0010, &rc);
-    if (rc != 0) {
-        console_printf("invalid 'scan_window' parameter\n");
-        help_cmd_uint16_dflt("scan_window", 0x0010);
-        return rc;
-    }
-
-    phy_1M_params.itvl_min = parse_arg_uint16_dflt(
-        "itvl_min", BLE_GAP_INITIAL_CONN_ITVL_MIN, &rc);
-    if (rc != 0) {
-        console_printf("invalid 'itvl_min' parameter\n");
-        help_cmd_uint16_dflt("itvl_min", BLE_GAP_INITIAL_CONN_ITVL_MIN);
-        return rc;
-    }
-
-    phy_1M_params.itvl_max = parse_arg_uint16_dflt(
-        "itvl_max", BLE_GAP_INITIAL_CONN_ITVL_MAX, &rc);
-    if (rc != 0) {
-        console_printf("invalid 'itvl_max' parameter\n");
-        help_cmd_uint16_dflt("itvl_max", BLE_GAP_INITIAL_CONN_ITVL_MAX);
-        return rc;
-    }
-
-    phy_1M_params.latency = parse_arg_uint16_dflt("latency", 0, &rc);
-    if (rc != 0) {
-        console_printf("invalid 'latency' parameter\n");
-        help_cmd_uint16_dflt("latency", 0);
-        return rc;
-    }
-
-    phy_1M_params.supervision_timeout = parse_arg_uint16_dflt("timeout", 0x0100, &rc);
-    if (rc != 0) {
-        console_printf("invalid 'timeout' parameter\n");
-        help_cmd_uint16_dflt("timeout", 0x0100);
-        return rc;
-    }
-
-    phy_1M_params.min_ce_len = parse_arg_uint16_dflt("min_ce_len", 0x0010, &rc);
-    if (rc != 0) {
-        console_printf("invalid 'min_ce_len' parameter\n");
-        help_cmd_uint16_dflt("min_ce_len", 0x0010);
-        return rc;
-    }
-
-    phy_1M_params.max_ce_len = parse_arg_uint16_dflt("max_ce_len", 0x0300, &rc);
-    if (rc != 0) {
-        console_printf("invalid 'max_ce_len' parameter\n");
-        help_cmd_uint16_dflt("max_ce_len", 0x0300);
-        return rc;
-    }
-
-    duration_ms = parse_arg_long_bounds_default("dur", 1, INT32_MAX, 0, &rc);
-    if (rc != 0) {
-        console_printf("invalid 'dur' parameter\n");
-        help_cmd_long_bounds_dflt("dur", 1, INT32_MAX, 0);
-        return rc;
-    }
-
-    if (ext == 0x00) {
-        rc = bletiny_conn_initiate(own_addr_type, peer_addr_param, duration_ms,
-                                   &phy_1M_params);
-        return rc;
-    }
-
-    if (ext == 0x01) {
-        rc = bletiny_ext_conn_initiate(own_addr_type, peer_addr_param,
-                                       duration_ms, &phy_1M_params, NULL, NULL);
-        return rc;
-    }
-
-    /* Get coded params */
-    phy_coded_params.scan_itvl = parse_arg_uint16_dflt("coded_scan_itvl",
-                                                           0x0010, &rc);
-    if (rc != 0) {
-        console_printf("invalid 'coded_scan_itvl' parameter\n");
-        help_cmd_uint16_dflt("coded_scan_itvl", 0x0010);
-        return rc;
-    }
-
-    phy_coded_params.scan_window = parse_arg_uint16_dflt("coded_scan_window",
-                                                         0x0010, &rc);
-    if (rc != 0) {
-        console_printf("invalid 'coded_scan_window' parameter\n");
-        help_cmd_uint16_dflt("coded_scan_window", 0x0010);
-        return rc;
-    }
-
-    phy_coded_params.itvl_min = parse_arg_uint16_dflt("coded_itvl_min",
-                                                      BLE_GAP_INITIAL_CONN_ITVL_MIN,
-                                                      &rc);
-    if (rc != 0) {
-        console_printf("invalid 'coded_itvl_min' parameter\n");
-        help_cmd_uint16_dflt("coded_itvl_min", BLE_GAP_INITIAL_CONN_ITVL_MIN);
-        return rc;
-    }
-
-    phy_coded_params.itvl_max = parse_arg_uint16_dflt("coded_itvl_max",
-                                                      BLE_GAP_INITIAL_CONN_ITVL_MAX,
-                                                      &rc);
-    if (rc != 0) {
-        console_printf("invalid 'coded_itvl_max' parameter\n");
-        help_cmd_uint16_dflt("coded_itvl_max", BLE_GAP_INITIAL_CONN_ITVL_MAX);
-        return rc;
-    }
-
-    phy_coded_params.latency =
-            parse_arg_uint16_dflt("coded_latency", 0, &rc);
-    if (rc != 0) {
-        console_printf("invalid 'coded_latency' parameter\n");
-        help_cmd_uint16_dflt("coded_latency", 0);
-        return rc;
-    }
-
-    phy_coded_params.supervision_timeout =
-            parse_arg_uint16_dflt("coded_timeout", 0x0100, &rc);
-
-    if (rc != 0) {
-        console_printf("invalid 'coded_timeout' parameter\n");
-        help_cmd_uint16_dflt("coded_timeout", 0x0100);
-        return rc;
-    }
-
-    phy_coded_params.min_ce_len =
-            parse_arg_uint16_dflt("coded_min_ce_len", 0x0010, &rc);
-    if (rc != 0) {
-        console_printf("invalid 'coded_min_ce_len' parameter\n");
-        help_cmd_uint16_dflt("coded_min_ce_len", 0x0010);
-        return rc;
-    }
-
-    phy_coded_params.max_ce_len = parse_arg_uint16_dflt("coded_max_ce_len",
-                                                        0x0300, &rc);
-    if (rc != 0) {
-        console_printf("invalid 'coded_max_ce_len' parameter\n");
-        help_cmd_uint16_dflt("coded_max_ce_len", 0x0300);
-        return rc;
-    }
-
-    /* Get 2M params */
-    phy_2M_params.itvl_min = parse_arg_uint16_dflt("2m_itvl_min",
-                                                   BLE_GAP_INITIAL_CONN_ITVL_MIN,
-                                                   &rc);
-    if (rc != 0) {
-        console_printf("invalid '2m_itvl_min' parameter\n");
-        help_cmd_uint16_dflt("2m_itvl_min", BLE_GAP_INITIAL_CONN_ITVL_MIN);
-        return rc;
-    }
-
-    phy_2M_params.itvl_max = parse_arg_uint16_dflt("2m_itvl_max",
-                                  BLE_GAP_INITIAL_CONN_ITVL_MAX, &rc);
-    if (rc != 0) {
-        console_printf("invalid '2m_itvl_max' parameter\n");
-        help_cmd_uint16_dflt("2m_itvl_max", BLE_GAP_INITIAL_CONN_ITVL_MAX);
-        return rc;
-    }
-
-    phy_2M_params.latency =
-            parse_arg_uint16_dflt("2m_latency", 0, &rc);
-    if (rc != 0) {
-        console_printf("invalid '2m_latency' parameter\n");
-        help_cmd_uint16_dflt("2m_latency", 0);
-        return rc;
-    }
-
-    phy_2M_params.supervision_timeout = parse_arg_uint16_dflt("2m_timeout",
-                                                              0x0100, &rc);
-
-    if (rc != 0) {
-        console_printf("invalid '2m_timeout' parameter\n");
-        help_cmd_uint16_dflt("2m_timeout", 0x0100);
-        return rc;
-    }
-
-    phy_2M_params.min_ce_len = parse_arg_uint16_dflt("2m_min_ce_len", 0x0010,
-                                                     &rc);
-    if (rc != 0) {
-        console_printf("invalid '2m_min_ce_len' parameter\n");
-        help_cmd_uint16_dflt("2m_min_ce_len", 0x0010);
-        return rc;
-    }
-
-    phy_2M_params.max_ce_len = parse_arg_uint16_dflt("2m_max_ce_len",
-                                                        0x0300, &rc);
-    if (rc != 0) {
-        console_printf("invalid '2m_max_ce_len' parameter\n");
-        help_cmd_uint16_dflt("2m_max_ce_len", 0x0300);
-        return rc;
-    }
-
-    if (ext == 0x02) {
-        rc = bletiny_ext_conn_initiate(own_addr_type, peer_addr_param,
-                                       duration_ms, NULL, NULL, &phy_coded_params);
-        return rc;
-    }
-
-    if (ext == 0x03) {
-        rc = bletiny_ext_conn_initiate(own_addr_type, peer_addr_param,
-                                       duration_ms, &phy_1M_params, NULL,
-                                       &phy_coded_params);
-        return rc;
-    }
-
-    rc = bletiny_ext_conn_initiate(own_addr_type, peer_addr_param,
-                                           duration_ms, &phy_1M_params,
-                                           &phy_2M_params,
-                                           &phy_coded_params);
-    return rc;
-}
-
-/*****************************************************************************
- * $chrup                                                                    *
- *****************************************************************************/
-
-static void
-bletiny_chrup_help(void)
-{
-#if !MYNEWT_VAL(BLETINY_HELP)
-    bletiny_help_disabled();
-    return;
-#endif
-
-    console_printf("Available chrup commands: \n");
-    console_printf("\thelp\n");
-    console_printf("Available chrup params: \n");
-    help_cmd_long("attr");
-}
-
-static int
-cmd_chrup(int argc, char **argv)
-{
-    uint16_t attr_handle;
-    int rc;
-
-    if (argc > 1 && strcmp(argv[1], "help") == 0) {
-        bletiny_chrup_help();
-        return 0;
-    }
-
-    attr_handle = parse_arg_long("attr", &rc);
-    if (rc != 0) {
-        console_printf("invalid 'attr' parameter\n");
-        help_cmd_long("attr");
-        return rc;
-    }
-
-    bletiny_chrup(attr_handle);
-
-    return 0;
-}
-
-/*****************************************************************************
- * $datalen                                                                  *
- *****************************************************************************/
-
-static void
-bletiny_datalen_help(void)
-{
-#if !MYNEWT_VAL(BLETINY_HELP)
-    bletiny_help_disabled();
-    return;
-#endif
-
-    console_printf("Available datalen commands: \n");
-    console_printf("\thelp\n");
-    console_printf("Available datalen params: \n");
-    help_cmd_uint16("conn");
-    help_cmd_uint16("octets");
-    help_cmd_uint16("time");
-}
-
-static int
-cmd_datalen(int argc, char **argv)
-{
-    uint16_t conn_handle;
-    uint16_t tx_octets;
-    uint16_t tx_time;
-    int rc;
-
-    if (argc > 1 && strcmp(argv[1], "help") == 0) {
-        bletiny_datalen_help();
-        return 0;
-    }
-
-    conn_handle = parse_arg_uint16("conn", &rc);
-    if (rc != 0) {
-        console_printf("invalid 'conn' parameter\n");
-        help_cmd_uint16("conn");
-        return rc;
-    }
-
-    tx_octets = parse_arg_long("octets", &rc);
-    if (rc != 0) {
-        console_printf("invalid 'octets' parameter\n");
-        help_cmd_long("octets");
-        return rc;
-    }
-
-    tx_time = parse_arg_long("time", &rc);
-    if (rc != 0) {
-        console_printf("invalid 'time' parameter\n");
-        help_cmd_long("time");
-        return rc;
-    }
-
-    rc = bletiny_datalen(conn_handle, tx_octets, tx_time);
-    if (rc != 0) {
-        console_printf("error setting data length; rc=%d\n", rc);
-        return rc;
-    }
-
-    return 0;
-}
-
-/*****************************************************************************
- * $discover                                                                 *
- *****************************************************************************/
-
-static void
-bletiny_disc_chr_help(void)
-{
-#if !MYNEWT_VAL(BLETINY_HELP)
-    bletiny_help_disabled();
-    return;
-#endif
-
-    console_printf("Available disc chr commands: \n");
-    console_printf("\thelp\n");
-    console_printf("Available disc chr params: \n");
-    help_cmd_conn_start_end();
-    help_cmd_uuid("uuid");
-}
-
-static int
-cmd_disc_chr(int argc, char **argv)
-{
-    uint16_t start_handle;
-    uint16_t conn_handle;
-    uint16_t end_handle;
-    ble_uuid_any_t uuid;
-    int rc;
-
-    if (argc > 1 && strcmp(argv[1], "help") == 0) {
-        bletiny_disc_chr_help();
-        return 0;
-    }
-
-    rc = cmd_parse_conn_start_end(&conn_handle, &start_handle, &end_handle);
-    if (rc != 0) {
-        console_printf("invalid 'conn start end' parameter\n");
-        help_cmd_conn_start_end();
-        return rc;
-    }
-
-    rc = parse_arg_uuid("uuid", &uuid);
-    if (rc == 0) {
-        rc = bletiny_disc_chrs_by_uuid(conn_handle, start_handle, end_handle,
-                                       &uuid.u);
-    } else if (rc == ENOENT) {
-        rc = bletiny_disc_all_chrs(conn_handle, start_handle, end_handle);
-    } else  {
-        console_printf("invalid 'uuid' parameter\n");
-        help_cmd_uuid("uuid");
-        return rc;
-    }
-    if (rc != 0) {
-        console_printf("error discovering characteristics; rc=%d\n", rc);
-        return rc;
-    }
-
-    return 0;
-}
-
-static void
-bletiny_disc_dsc_help(void)
-{
-#if !MYNEWT_VAL(BLETINY_HELP)
-    bletiny_help_disabled();
-    return;
-#endif
-
-    console_printf("Available disc dsc commands: \n");
-    console_printf("\thelp\n");
-    console_printf("Available disc dsc params: \n");
-    help_cmd_conn_start_end();
-}
-
-static int
-cmd_disc_dsc(int argc, char **argv)
-{
-    uint16_t start_handle;
-    uint16_t conn_handle;
-    uint16_t end_handle;
-    int rc;
-
-    if (argc > 1 && strcmp(argv[1], "help") == 0) {
-        bletiny_disc_dsc_help();
-        return 0;
-    }
-
-    rc = cmd_parse_conn_start_end(&conn_handle, &start_handle, &end_handle);
-    if (rc != 0) {
-        console_printf("invalid 'conn start end' parameter\n");
-        help_cmd_conn_start_end();
-        return rc;
-    }
-
-    rc = bletiny_disc_all_dscs(conn_handle, start_handle, end_handle);
-    if (rc != 0) {
-        console_printf("error discovering descriptors; rc=%d\n", rc);
-        return rc;
-    }
-
-    return 0;
-}
-
-static void
-bletiny_disc_svc_help(void)
-{
-#if !MYNEWT_VAL(BLETINY_HELP)
-    bletiny_help_disabled();
-    return;
-#endif
-
-    console_printf("Available disc svc commands: \n");
-    console_printf("\thelp\n");
-    console_printf("Available disc svc params: \n");
-    help_cmd_uint16("conn");
-    help_cmd_uuid("uuid");
-}
-
-static int
-cmd_disc_svc(int argc, char **argv)
-{
-    ble_uuid_any_t uuid;
-    int conn_handle;
-    int rc;
-
-    if (argc > 1 && strcmp(argv[1], "help") == 0) {
-        bletiny_disc_svc_help();
-        return 0;
-    }
-
-    conn_handle = parse_arg_uint16("conn", &rc);
-    if (rc != 0) {
-        console_printf("invalid 'conn' parameter\n");
-        help_cmd_uint16("conn");
-        return rc;
-    }
-
-    rc = parse_arg_uuid("uuid", &uuid);
-    if (rc == 0) {
-        rc = bletiny_disc_svc_by_uuid(conn_handle, &uuid.u);
-    } else if (rc == ENOENT) {
-        rc = bletiny_disc_svcs(conn_handle);
-    } else  {
-        console_printf("invalid 'uuid' parameter\n");
-        help_cmd_uuid("uuid");
-        return rc;
-    }
-
-    if (rc != 0) {
-        console_printf("error discovering services; rc=%d\n", rc);
-        return rc;
-    }
-
-    return 0;
-}
-
-static void
-bletiny_disc_full_help(void)
-{
-#if !MYNEWT_VAL(BLETINY_HELP)
-    bletiny_help_disabled();
-    return;
-#endif
-
-    console_printf("Available disc full commands: \n");
-    console_printf("\thelp\n");
-    console_printf("Available disc full params: \n");
-    help_cmd_uint16("conn");
-}
-
-static int
-cmd_disc_full(int argc, char **argv)
-{
-    int conn_handle;
-    int rc;
-
-    if (argc > 1 && strcmp(argv[1], "help") == 0) {
-        bletiny_disc_full_help();
-        return 0;
-    }
-
-    conn_handle = parse_arg_uint16("conn", &rc);
-    if (rc != 0) {
-        console_printf("invalid 'conn' parameter\n");
-        help_cmd_uint16("conn");
-        return rc;
-    }
-
-    rc = bletiny_disc_full(conn_handle);
-    if (rc != 0) {
-        console_printf("error discovering all; rc=%d\n", rc);
-        return rc;
-    }
-
-    return 0;
-}
-
-static struct cmd_entry cmd_disc_entries[];
-
-static int
-cmd_disc_help(int argc, char **argv)
-{
-#if !MYNEWT_VAL(BLETINY_HELP)
-    bletiny_help_disabled();
-    return 0;
-#endif
-
-    int i;
-
-    console_printf("Available disc commands:\n");
-    for (i = 0; cmd_disc_entries[i].name != NULL; i++) {
-        console_printf("\t%s\n", cmd_disc_entries[i].name);
-    }
-    return 0;
-}
-
-static struct cmd_entry cmd_disc_entries[] = {
-    { "chr", cmd_disc_chr },
-    { "dsc", cmd_disc_dsc },
-    { "svc", cmd_disc_svc },
-    { "full", cmd_disc_full },
-    { "help", cmd_disc_help },
-    { NULL, NULL }
-};
-
-static int
-cmd_disc(int argc, char **argv)
-{
-    int rc;
-
-    rc = cmd_exec(cmd_disc_entries, argc, argv);
-    if (rc != 0) {
-        return rc;
-    }
-
-    return 0;
-}
-
-/*****************************************************************************
- * $find                                                                     *
- *****************************************************************************/
-
-static void
-bletiny_find_inc_svcs_help(void)
-{
-#if !MYNEWT_VAL(BLETINY_HELP)
-    bletiny_help_disabled();
-    return;
-#endif
-
-    console_printf("Available find inc svcs commands: \n");
-    console_printf("\thelp\n");
-    console_printf("Available find inc svcs params: \n");
-    help_cmd_conn_start_end();
-}
-
-static int
-cmd_find_inc_svcs(int argc, char **argv)
-{
-    uint16_t start_handle;
-    uint16_t conn_handle;
-    uint16_t end_handle;
-    int rc;
-
-    if (argc > 1 && strcmp(argv[1], "help") == 0) {
-        bletiny_find_inc_svcs_help();
-        return 0;
-    }
-
-    rc = cmd_parse_conn_start_end(&conn_handle, &start_handle, &end_handle);
-    if (rc != 0) {
-        console_printf("invalid 'conn start end' parameter\n");
-        help_cmd_conn_start_end();
-        return rc;
-    }
-
-    rc = bletiny_find_inc_svcs(conn_handle, start_handle, end_handle);
-    if (rc != 0) {
-        console_printf("error finding included services; rc=%d\n", rc);
-        return rc;
-    }
-
-    return 0;
-}
-
-static const struct cmd_entry cmd_find_entries[];
-
-static int
-cmd_find_help(int argc, char **argv)
-{
-#if !MYNEWT_VAL(BLETINY_HELP)
-    bletiny_help_disabled();
-    return 0;
-#endif
-
-    int i;
-
-    console_printf("Available find commands:\n");
-    for (i = 0; cmd_find_entries[i].name != NULL; i++) {
-        console_printf("\t%s\n", cmd_find_entries[i].name);
-    }
-    return 0;
-}
-
-static const struct cmd_entry cmd_find_entries[] = {
-    { "inc_svcs", cmd_find_inc_svcs },
-    { "help", cmd_find_help },
-    { NULL, NULL }
-};
-
-static int
-cmd_find(int argc, char **argv)
-{
-    int rc;
-
-    rc = cmd_exec(cmd_find_entries, argc, argv);
-    if (rc != 0) {
-        return rc;
-    }
-
-    return 0;
-}
-
-/*****************************************************************************
- * $l2cap                                                                    *
- *****************************************************************************/
-
-static void
-bletiny_l2cap_update_help(void)
-{
-#if !MYNEWT_VAL(BLETINY_HELP)
-    bletiny_help_disabled();
-    return;
-#endif
-
-    console_printf("Available l2cap update commands: \n");
-    console_printf("\thelp\n");
-    console_printf("Available l2cap update params: \n");
-    help_cmd_uint16("conn");
-    help_cmd_uint16_dflt("itvl_min", BLE_GAP_INITIAL_CONN_ITVL_MIN);
-    help_cmd_uint16_dflt("itvl_max", BLE_GAP_INITIAL_CONN_ITVL_MAX);
-    help_cmd_uint16_dflt("latency", 0);
-    help_cmd_uint16_dflt("timeout", 0x0100);
-}
-
-static int
-cmd_l2cap_update(int argc, char **argv)
-{
-    struct ble_l2cap_sig_update_params params;
-    uint16_t conn_handle;
-    int rc;
-
-    if (argc > 1 && strcmp(argv[1], "help") == 0) {
-        bletiny_l2cap_update_help();
-        return 0;
-    }
-
-    conn_handle = parse_arg_uint16("conn", &rc);
-    if (rc != 0) {
-        console_printf("invalid 'conn' parameter\n");
-        help_cmd_uint16("conn");
-        return rc;
-    }
-
-    params.itvl_min = parse_arg_uint16_dflt(
-        "itvl_min", BLE_GAP_INITIAL_CONN_ITVL_MIN, &rc);
-    if (rc != 0) {
-        console_printf("invalid 'itvl_min' parameter\n");
-        help_cmd_uint16_dflt("itvl_min", BLE_GAP_INITIAL_CONN_ITVL_MIN);
-        return rc;
-    }
-
-    params.itvl_max = parse_arg_uint16_dflt(
-        "itvl_max", BLE_GAP_INITIAL_CONN_ITVL_MAX, &rc);
-    if (rc != 0) {
-        console_printf("invalid 'itvl_max' parameter\n");
-        help_cmd_uint16_dflt("itvl_max", BLE_GAP_INITIAL_CONN_ITVL_MAX);
-        return rc;
-    }
-
-    params.slave_latency = parse_arg_uint16_dflt("latency", 0, &rc);
-    if (rc != 0) {
-        console_printf("invalid 'latency' parameter\n");
-        help_cmd_uint16_dflt("latency", 0);
-        return rc;
-    }
-
-    params.timeout_multiplier = parse_arg_uint16_dflt("timeout", 0x0100, &rc);
-    if (rc != 0) {
-        console_printf("invalid 'timeout' parameter\n");
-        help_cmd_uint16_dflt("timeout", 0x0100);
-        return rc;
-    }
-
-    rc = bletiny_l2cap_update(conn_handle, &params);
-    if (rc != 0) {
-        console_printf("error txing l2cap update; rc=%d\n", rc);
-        return rc;
-    }
-
-    return 0;
-}
-
-static void
-bletiny_l2cap_create_srv_help(void)
-{
-#if !MYNEWT_VAL(BLETINY_HELP)
-    bletiny_help_disabled();
-    return;
-#endif
-
-    console_printf("Available l2cap create_srv commands: \n");
-    console_printf("\thelp\n");
-    console_printf("Available l2cap create_srv params: \n");
-    help_cmd_uint16("psm");
-    help_cmd_uint16("mtu");
-}
-
-static int
-cmd_l2cap_create_srv(int argc, char **argv)
-{
-    uint16_t psm = 0;
-    int rc;
-
-    if (argc > 1 && strcmp(argv[1], "help") == 0) {
-            bletiny_l2cap_create_srv_help();
-        return 0;
-    }
-
-    psm = parse_arg_uint16("psm", &rc);
-    if (rc != 0) {
-        console_printf("invalid 'psm' parameter\n");
-        help_cmd_uint16("psm");
-        return rc;
-    }
-
-    rc = bletiny_l2cap_create_srv(psm);
-    if (rc) {
-        console_printf("Server create error: 0x%02x", rc);
-    }
-
-    return 0;
-}
-
-static void
-bletiny_l2cap_connect_help(void)
-{
-#if !MYNEWT_VAL(BLETINY_HELP)
-    bletiny_help_disabled();
-    return;
-#endif
-
-    console_printf("Available l2cap connect commands: \n");
-    console_printf("\thelp\n");
-    console_printf("Available l2cap connect params: \n");
-    help_cmd_uint16("conn");
-    help_cmd_uint16("psm");
-}
-
-static int
-cmd_l2cap_connect(int argc, char **argv)
-{
-    uint16_t conn = 0;
-    uint16_t psm = 0;
-    int rc;
-
-    if (argc > 1 && strcmp(argv[1], "help") == 0) {
-            bletiny_l2cap_connect_help();
-        return 0;
-    }
-
-    conn = parse_arg_uint16("conn", &rc);
-    if (rc != 0) {
-        console_printf("invalid 'conn' parameter\n");
-        help_cmd_uint16("conn");
-        return rc;
-    }
-
-    psm = parse_arg_uint16("psm", &rc);
-    if (rc != 0) {
-        console_printf("invalid 'psm' parameter\n");
-        help_cmd_uint16("psm");
-        return rc;
-    }
-
-    return bletiny_l2cap_connect(conn, psm);
-}
-
-static void
-bletiny_l2cap_disconnect_help(void)
-{
-#if !MYNEWT_VAL(BLETINY_HELP)
-    bletiny_help_disabled();
-    return;
-#endif
-
-    console_printf("Available l2cap disconnect commands: \n");
-    console_printf("\thelp\n");
-    console_printf("Available l2cap disconnect params: \n");
-    help_cmd_uint16("conn");
-    help_cmd_uint16("idx");
-    console_printf("\n Use 'b show coc' to get those parameters \n");
-}
-
-static int
-cmd_l2cap_disconnect(int argc, char **argv)
-{
-    uint16_t conn;
-    uint16_t idx;
-    int rc;
-
-    if (argc > 1 && strcmp(argv[1], "help") == 0) {
-        bletiny_l2cap_disconnect_help();
-        return 0;
-    }
-
-    conn = parse_arg_uint16("conn", &rc);
-    if (rc != 0) {
-        console_printf("invalid 'conn' parameter\n");
-        help_cmd_uint16("conn");
-        return rc;
-    }
-
-    idx = parse_arg_uint16("idx", &rc);
-    if (rc != 0) {
-        console_printf("invalid 'idx' parameter\n");
-        help_cmd_uint16("idx");
-        return rc;
-    }
-
-    return bletiny_l2cap_disconnect(conn, idx);
-}
-
-static void
-bletiny_l2cap_send_help(void)
-{
-#if !MYNEWT_VAL(BLETINY_HELP)
-    bletiny_help_disabled();
-    return;
-#endif
-
-    console_printf("Available l2cap send commands: \n");
-    console_printf("\thelp\n");
-    console_printf("Available l2cap disconnect params: \n");
-    help_cmd_uint16("conn");
-    help_cmd_uint16("idx");
-    help_cmd_uint16("bytes");
-    console_printf("\n Use 'b show coc' to get conn and idx parameters.\n");
-    console_printf("bytes stands for number of bytes to send .\n");
-}
-
-static int
-cmd_l2cap_send(int argc, char **argv)
-{
-    uint16_t conn;
-    uint16_t idx;
-    uint16_t bytes;
-    int rc;
-
-    if (argc > 1 && strcmp(argv[1], "help") == 0) {
-        bletiny_l2cap_send_help();
-        return 0;
-    }
-    conn = parse_arg_uint16("conn", &rc);
-    if (rc != 0) {
-       console_printf("invalid 'conn' parameter\n");
-       help_cmd_uint16("conn");
-       return rc;
-    }
-
-    idx = parse_arg_uint16("idx", &rc);
-    if (rc != 0) {
-       console_printf("invalid 'idx' parameter\n");
-       help_cmd_uint16("idx");
-       return rc;
-    }
-
-    bytes = parse_arg_uint16("bytes", &rc);
-    if (rc != 0) {
-       console_printf("invalid 'bytes' parameter\n");
-       help_cmd_uint16("bytes");
-       return rc;
-    }
-
-    return bletiny_l2cap_send(conn, idx, bytes);
-}
-
-static const struct cmd_entry cmd_l2cap_entries[];
-
-static int
-cmd_l2cap_help(int argc, char **argv)
-{
-#if !MYNEWT_VAL(BLETINY_HELP)
-    bletiny_help_disabled();
-    return 0;
-#endif
-
-    int i;
-
-    console_printf("Available l2cap commands:\n");
-    for (i = 0; cmd_l2cap_entries[i].name != NULL; i++) {
-        console_printf("\t%s\n", cmd_l2cap_entries[i].name);
-    }
-    return 0;
-}
-
-static const struct cmd_entry cmd_l2cap_entries[] = {
-    { "update", cmd_l2cap_update },
-    { "create_srv", cmd_l2cap_create_srv },
-    { "connect", cmd_l2cap_connect },
-    { "disconnect", cmd_l2cap_disconnect },
-    { "send", cmd_l2cap_send },
-    { "help", cmd_l2cap_help },
-    { NULL, NULL }
-};
-
-static int
-cmd_l2cap(int argc, char **argv)
-{
-    int rc;
-
-    rc = cmd_exec(cmd_l2cap_entries, argc, argv);
-    if (rc != 0) {
-        return rc;
-    }
-
-    return 0;
-}
-
-/*****************************************************************************
- * $mtu                                                                      *
- *****************************************************************************/
-
-static void
-bletiny_mtu_help(void)
-{
-#if !MYNEWT_VAL(BLETINY_HELP)
-    bletiny_help_disabled();
-    return;
-#endif
-
-    console_printf("Available mtu commands: \n");
-    console_printf("\thelp\n");
-    console_printf("Available mtu params: \n");
-    help_cmd_uint16("conn");
-}
-
-static int
-cmd_mtu(int argc, char **argv)
-{
-    uint16_t conn_handle;
-    int rc;
-
-    if (argc > 1 && strcmp(argv[1], "help") == 0) {
-        bletiny_mtu_help();
-        return 0;
-    }
-
-    conn_handle = parse_arg_uint16("conn", &rc);
-    if (rc != 0) {
-        console_printf("invalid 'conn' parameter\n");
-        help_cmd_uint16("conn");
-        return rc;
-    }
-
-    rc = bletiny_exchange_mtu(conn_handle);
-    if (rc != 0) {
-        console_printf("error exchanging mtu; rc=%d\n", rc);
-        return rc;
-    }
-
-    return 0;
-}
-
-/*****************************************************************************
- * $read                                                                     *
- *****************************************************************************/
-
-#define CMD_READ_MAX_ATTRS  8
-
-static void
-bletiny_read_help(void)
-{
-#if !MYNEWT_VAL(BLETINY_HELP)
-    bletiny_help_disabled();
-    return;
-#endif
-
-    console_printf("Available read commands: \n");
-    console_printf("\thelp\n");
-    console_printf("Available read params: \n");
-    help_cmd_uint16("conn");
-    help_cmd_long("long");
-    help_cmd_uint16("attr");
-    help_cmd_uuid("uuid");
-    help_cmd_uint16("start");
-    help_cmd_uint16("end");
-    help_cmd_uint16("offset");
-}
-
-static int
-cmd_read(int argc, char **argv)
-{
-    static uint16_t attr_handles[CMD_READ_MAX_ATTRS];
-    uint16_t conn_handle;
-    uint16_t start;
-    uint16_t end;
-    uint16_t offset;
-    ble_uuid_any_t uuid;
-    uint8_t num_attr_handles;
-    int is_uuid;
-    int is_long;
-    int rc;
-
-    if (argc > 1 && strcmp(argv[1], "help") == 0) {
-        bletiny_read_help();
-        return 0;
-    }
-
-    conn_handle = parse_arg_uint16("conn", &rc);
-    if (rc != 0) {
-        console_printf("invalid 'conn' parameter\n");
-        help_cmd_uint16("conn");
-        return rc;
-    }
-
-    is_long = parse_arg_long("long", &rc);
-    if (rc == ENOENT) {
-        is_long = 0;
-    } else if (rc != 0) {
-        console_printf("invalid 'long' parameter\n");
-        help_cmd_long("long");
-        return rc;
-    }
-
-    for (num_attr_handles = 0;
-         num_attr_handles < CMD_READ_MAX_ATTRS;
-         num_attr_handles++) {
-
-        attr_handles[num_attr_handles] = parse_arg_uint16("attr", &rc);
-        if (rc == ENOENT) {
-            break;
-        } else if (rc != 0) {
-            console_printf("invalid 'attr' parameter\n");
-            help_cmd_uint16("attr");
-            return rc;
-        }
-    }
-
-    rc = parse_arg_uuid("uuid", &uuid);
-    if (rc == ENOENT) {
-        is_uuid = 0;
-    } else if (rc == 0) {
-        is_uuid = 1;
-    } else {
-        console_printf("invalid 'uuid' parameter\n");
-        help_cmd_uuid("uuid");
-        return rc;
-    }
-
-    start = parse_arg_uint16("start", &rc);
-    if (rc == ENOENT) {
-        start = 0;
-    } else if (rc != 0) {
-        console_printf("invalid 'start' parameter\n");
-        help_cmd_uint16("start");
-        return rc;
-    }
-
-    end = parse_arg_uint16("end", &rc);
-    if (rc == ENOENT) {
-        end = 0;
-    } else if (rc != 0) {
-        console_printf("invalid 'end' parameter\n");
-        help_cmd_uint16("end");
-        return rc;
-    }
-
-    offset = parse_arg_uint16("offset", &rc);
-    if (rc == ENOENT) {
-        offset = 0;
-    } else if (rc != 0) {
-        console_printf("invalid 'offset' parameter\n");
-        help_cmd_uint16("offset");
-        return rc;
-    }
-
-    if (num_attr_handles == 1) {
-        if (is_long) {
-            rc = bletiny_read_long(conn_handle, attr_handles[0], offset);
-        } else {
-            rc = bletiny_read(conn_handle, attr_handles[0]);
-        }
-    } else if (num_attr_handles > 1) {
-        rc = bletiny_read_mult(conn_handle, attr_handles, num_attr_handles);
-    } else if (is_uuid) {
-        if (start == 0 || end == 0) {
-            rc = EINVAL;
-        } else {
-            rc = bletiny_read_by_uuid(conn_handle, start, end, &uuid.u);
-        }
-    } else {
-        rc = EINVAL;
-    }
-
-    if (rc != 0) {
-        console_printf("error reading characteristic; rc=%d\n", rc);
-        return rc;
-    }
-
-    return 0;
-}
-
-/*****************************************************************************
- * $rssi                                                                     *
- *****************************************************************************/
-
-static void
-bletiny_rssi_help(void)
-{
-#if !MYNEWT_VAL(BLETINY_HELP)
-    bletiny_help_disabled();
-    return;
-#endif
-
-    console_printf("Available rssi commands: \n");
-    console_printf("\thelp\n");
-    console_printf("Available rssi params: \n");
-    help_cmd_uint16("conn");
-}
-
-static int
-cmd_rssi(int argc, char **argv)
-{
-    uint16_t conn_handle;
-    int8_t rssi;
-    int rc;
-
-    if (argc > 1 && strcmp(argv[1], "help") == 0) {
-        bletiny_rssi_help();
-        return 0;
-    }
-
-    conn_handle = parse_arg_uint16("conn", &rc);
-    if (rc != 0) {
-        console_printf("invalid 'conn' parameter\n");
-        help_cmd_uint16("conn");
-        return rc;
-    }
-
-    rc = bletiny_rssi(conn_handle, &rssi);
-    if (rc != 0) {
-        console_printf("error reading rssi; rc=%d\n", rc);
-        return rc;
-    }
-
-    console_printf("conn=%d rssi=%d\n", conn_handle, rssi);
-
-    return 0;
-}
-
-/*****************************************************************************
- * $scan                                                                     *
- *****************************************************************************/
-
-static struct kv_pair cmd_scan_filt_policies[] = {
-    { "no_wl", BLE_HCI_SCAN_FILT_NO_WL },
-    { "use_wl", BLE_HCI_SCAN_FILT_USE_WL },
-    { "no_wl_inita", BLE_HCI_SCAN_FILT_NO_WL_INITA },
-    { "use_wl_inita", BLE_HCI_SCAN_FILT_USE_WL_INITA },
-    { NULL }
-};
-
-static struct kv_pair cmd_scan_ext_types[] = {
-    { "1M",         0x01 },
-    { "coded",      0x02 },
-    { "both",       0x03 },
-    { NULL }
-};
-
-static void
-bletiny_scan_help(void)
-{
-#if !MYNEWT_VAL(BLETINY_HELP)
-    bletiny_help_disabled();
-    return;
-#endif
-
-    console_printf("Available scan commands: \n");
-    console_printf("\thelp\n");
-    console_printf("\tcancel\n");
-    console_printf("Available scan params: \n");
-    help_cmd_kv_dflt("ext", cmd_scan_ext_types, 0);
-    help_cmd_long_bounds_dflt("dur_ms", 1, INT32_MAX, BLE_HS_FOREVER);
-    help_cmd_bool_dflt("ltd", 0);
-    help_cmd_bool_dflt("passive", 0);
-    help_cmd_uint16_dflt("itvl", 0);
-    help_cmd_uint16_dflt("window", 0);
-    help_cmd_kv_dflt("filt", cmd_scan_filt_policies,
-                     BLE_HCI_SCAN_FILT_NO_WL);
-    help_cmd_uint16_dflt("nodups", 0);
-    help_cmd_kv_dflt("own_addr_type", cmd_own_addr_types,
-                     BLE_OWN_ADDR_PUBLIC);
-    console_printf("Available scan params when ext != none: \n");
-    help_cmd_uint16_dflt("duration", 0);
-    help_cmd_uint16_dflt("period", 0);
-    help_cmd_bool_dflt("lr_passive", 0);
-    help_cmd_uint16_dflt("lr_itvl", 0);
-    help_cmd_uint16_dflt("lr_window", 0);
-
-}
-
-static int
-cmd_scan(int argc, char **argv)
-{
-    struct ble_gap_disc_params params = {0};
-    struct ble_gap_ext_disc_params uncoded = {0};
-    struct ble_gap_ext_disc_params coded = {0};
-    uint8_t extended;
-    int32_t duration_ms;
-    uint8_t own_addr_type;
-    uint16_t duration;
-    uint16_t period;
-    int rc;
-
-    if (argc > 1 && strcmp(argv[1], "help") == 0) {
-        bletiny_scan_help();
-        return 0;
-    }
-
-    if (argc > 1 && strcmp(argv[1], "cancel") == 0) {
-        rc = bletiny_scan_cancel();
-        if (rc != 0) {
-            console_printf("connection cancel fail: %d\n", rc);
-            return rc;
-        }
-
-        return 0;
-    }
-
-    extended = parse_arg_kv_default("ext", cmd_scan_ext_types, 0, &rc);
-    if (rc != 0) {
-        help_cmd_kv_dflt("ext", cmd_scan_ext_types, 0);
-        console_printf("invalid 'ext' parameter\n");
-        return rc;
-    }
-
-    console_printf("Scan type: %d\n", extended);
-
-    duration_ms = parse_arg_long_bounds_default("dur", 1, INT32_MAX,
-                                                BLE_HS_FOREVER, &rc);
-    if (rc != 0) {
-        console_printf("invalid 'dur' parameter\n");
-        help_cmd_long_bounds_dflt("dur", 1, INT32_MAX, BLE_HS_FOREVER);
-        return rc;
-    }
-
-    params.limited = parse_arg_bool_default("ltd", 0, &rc);
-    if (rc != 0) {
-        console_printf("invalid 'ltd' parameter\n");
-        help_cmd_bool_dflt("ltd", 0);
-        return rc;
-    }
-
-    params.passive = parse_arg_bool_default("passive", 0, &rc);
-    if (rc != 0) {
-        console_printf("invalid 'passive' parameter\n");
-        help_cmd_bool_dflt("passive", 0);
-        return rc;
-    }
-
-    params.itvl = parse_arg_uint16_dflt("itvl", 0, &rc);
-    if (rc != 0) {
-        console_printf("invalid 'itvl' parameter\n");
-        help_cmd_uint16_dflt("itvl", 0);
-        return rc;
-    }
-
-    params.window = parse_arg_uint16_dflt("window", 0, &rc);
-    if (rc != 0) {
-        console_printf("invalid 'window' parameter\n");
-        help_cmd_uint16_dflt("window", 0);
-        return rc;
-    }
-
-    params.filter_policy = parse_arg_kv_default(
-        "filt", cmd_scan_filt_policies, BLE_HCI_SCAN_FILT_NO_WL, &rc);
-    if (rc != 0) {
-        console_printf("invalid 'filt' parameter\n");
-        help_cmd_kv_dflt("filt", cmd_scan_filt_policies,
-                         BLE_HCI_SCAN_FILT_NO_WL);
-        return rc;
-    }
-
-    params.filter_duplicates = parse_arg_bool_default("nodups", 0, &rc);
-    if (rc != 0) {
-        console_printf("invalid 'nodups' parameter\n");
-        help_cmd_uint16_dflt("nodups", 0);
-        return rc;
-    }
-
-    own_addr_type = parse_arg_kv_default("own_addr_type", cmd_own_addr_types,
-                                         BLE_OWN_ADDR_PUBLIC, &rc);
-    if (rc != 0) {
-        console_printf("invalid 'own_addr_type' parameter\n");
-        help_cmd_kv_dflt("own_addr_type", cmd_own_addr_types,
-                         BLE_OWN_ADDR_PUBLIC);
-        return rc;
-    }
-
-    if (extended == 0) {
-        goto regular_scan;
-    }
-
-    /* Copy above parameters to uncoded params */
-    uncoded.passive = params.passive;
-    uncoded.itvl = params.itvl;
-    uncoded.window = params.window;
-
-    duration = parse_arg_uint16_dflt("duration", 0, &rc);
-    if (rc != 0) {
-        console_printf("invalid 'duration' parameter\n");
-        help_cmd_uint16_dflt("duration", 0);
-        return rc;
-    }
-
-    period = parse_arg_uint16_dflt("period", 0, &rc);
-    if (rc != 0) {
-        console_printf("invalid 'period' parameter\n");
-        help_cmd_uint16_dflt("period", 0);
-        return rc;
-    }
-
-    coded.itvl = parse_arg_uint16_dflt("lr_itvl", 0, &rc);
-    if (rc != 0) {
-        console_printf("invalid 'lr_itvl' parameter\n");
-        help_cmd_uint16_dflt("lr_itvl", 0);
-        return rc;
-    }
-
-    coded.window = parse_arg_uint16_dflt("lr_window", 0, &rc);
-    if (rc != 0) {
-        console_printf("invalid 'lr_window' parameter\n");
-        help_cmd_uint16_dflt("lr_window", 0);
-        return rc;
-    }
-
-    coded.passive = parse_arg_uint16_dflt("lr_passive", 0, &rc);
-    if (rc != 0) {
-        console_printf("invalid 'lr_passive' parameter\n");
-        help_cmd_uint16_dflt("lr_window", 0);
-        return rc;
-    }
-
-    switch (extended) {
-    case 0x01:
-        rc = bletiny_ext_scan(own_addr_type, duration, period,
-                         params.filter_duplicates, params.filter_policy,
-                         params.limited, &uncoded, NULL);
-        break;
-    case 0x02:
-        rc = bletiny_ext_scan(own_addr_type, duration, period,
-                              params.filter_duplicates, params.filter_policy,
-                              params.limited, NULL, &coded);
-        break;
-    case 0x03:
-        rc = bletiny_ext_scan(own_addr_type, duration, period,
-                              params.filter_duplicates, params.filter_policy,
-                              params.limited, &uncoded, &coded);
-        break;
-    default:
-        rc = -1;
-        console_printf("Something went wrong :)\n");
-        break;
-    }
-
-    return rc;
-
-regular_scan:
-    rc = bletiny_scan(own_addr_type, duration_ms, &params);
-    if (rc != 0) {
-        console_printf("error scanning; rc=%d\n", rc);
-        return rc;
-    }
-
-    return 0;
-}
-
-/*****************************************************************************
- * $show                                                                     *
- *****************************************************************************/
-
-static int
-cmd_show_addr(int argc, char **argv)
-{
-    uint8_t id_addr[6];
-    int rc;
-
-    console_printf("public_id_addr=");
-    rc = ble_hs_id_copy_addr(BLE_ADDR_PUBLIC, id_addr, NULL);
-    if (rc == 0) {
-        print_addr(id_addr);
-    } else {
-        console_printf("none");
-    }
-
-    console_printf(" random_id_addr=");
-    rc = ble_hs_id_copy_addr(BLE_ADDR_RANDOM, id_addr, NULL);
-    if (rc == 0) {
-        print_addr(id_addr);
-    } else {
-        console_printf("none");
-    }
-    console_printf("\n");
-
-    return 0;
-}
-
-static int
-cmd_show_chr(int argc, char **argv)
-{
-    struct bletiny_conn *conn;
-    struct bletiny_svc *svc;
-    int i;
-
-    for (i = 0; i < bletiny_num_conns; i++) {
-        conn = bletiny_conns + i;
-
-        console_printf("CONNECTION: handle=%d\n", conn->handle);
-
-        SLIST_FOREACH(svc, &conn->svcs, next) {
-            cmd_print_svc(svc);
-        }
-    }
-
-    return 0;
-}
-
-static int
-cmd_show_conn(int argc, char **argv)
-{
-    struct ble_gap_conn_desc conn_desc;
-    struct bletiny_conn *conn;
-    int rc;
-    int i;
-
-    for (i = 0; i < bletiny_num_conns; i++) {
-        conn = bletiny_conns + i;
-
-        rc = ble_gap_conn_find(conn->handle, &conn_desc);
-        if (rc == 0) {
-            print_conn_desc(&conn_desc);
-        }
-    }
-
-    return 0;
-}
-
-static int
-cmd_show_coc(int argc, char **argv)
-{
-    struct bletiny_conn *conn = NULL;
-    struct bletiny_l2cap_coc *coc;
-    int i, j;
-
-    for (i = 0; i < bletiny_num_conns; i++) {
-        conn = bletiny_conns + i;
-
-        if (SLIST_EMPTY(&conn->coc_list)) {
-            continue;
-        }
-
-        console_printf("conn_handle: 0x%04x\n", conn->handle);
-        j = 0;
-        SLIST_FOREACH(coc, &conn->coc_list, next) {
-            console_printf("    idx: %i, chan pointer = %p\n", j++, coc->chan);
-        }
-    }
-
-    return 0;
-}
-
-static struct cmd_entry cmd_show_entries[];
-
-static int
-cmd_show_help(int argc, char **argv)
-{
-#if !MYNEWT_VAL(BLETINY_HELP)
-    bletiny_help_disabled();
-    return 0;
-#endif
-
-    int i;
-
-    console_printf("Available show commands:\n");
-    for (i = 0; cmd_show_entries[i].name != NULL; i++) {
-        console_printf("\t%s\n", cmd_show_entries[i].name);
-    }
-    return 0;
-}
-
-static struct cmd_entry cmd_show_entries[] = {
-    { "addr", cmd_show_addr },
-    { "chr", cmd_show_chr },
-    { "conn", cmd_show_conn },
-    { "coc", cmd_show_coc },
-    { "help", cmd_show_help },
-    { NULL, NULL }
-};
-
-static int
-cmd_show(int argc, char **argv)
-{
-    int rc;
-
-    rc = cmd_exec(cmd_show_entries, argc, argv);
-    if (rc != 0) {
-        return rc;
-    }
-
-    return 0;
-}
-
-/*****************************************************************************
- * $sec                                                                      *
- *****************************************************************************/
-
-static void
-bletiny_sec_pair_help(void)
-{
-#if !MYNEWT_VAL(BLETINY_HELP)
-    bletiny_help_disabled();
-    return;
-#endif
-
-    console_printf("Available sec pair commands: \n");
-    console_printf("\thelp\n");
-    console_printf("Available sec pair params: \n");
-    help_cmd_uint16("conn");
-}
-
-static int
-cmd_sec_pair(int argc, char **argv)
-{
-    uint16_t conn_handle;
-    int rc;
-
-    if (argc > 1 && strcmp(argv[1], "help") == 0) {
-        bletiny_sec_pair_help();
-        return 0;
-    }
-
-    conn_handle = parse_arg_uint16("conn", &rc);
-    if (rc != 0) {
-        console_printf("invalid 'conn' parameter\n");
-        help_cmd_uint16("conn");
-        return rc;
-    }
-
-    rc = bletiny_sec_pair(conn_handle);
-    if (rc != 0) {
-        console_printf("error initiating pairing; rc=%d\n", rc);
-        return rc;
-    }
-
-    return 0;
-}
-
-static void
-bletiny_sec_start_help(void)
-{
-#if !MYNEWT_VAL(BLETINY_HELP)
-    bletiny_help_disabled();
-    return;
-#endif
-
-    console_printf("Available sec start commands: \n");
-    console_printf("\thelp\n");
-    console_printf("Available sec start params: \n");
-    help_cmd_uint16("conn");
-}
-
-static int
-cmd_sec_start(int argc, char **argv)
-{
-    uint16_t conn_handle;
-    int rc;
-
-    if (argc > 1 && strcmp(argv[1], "help") == 0) {
-        bletiny_sec_start_help();
-        return 0;
-    }
-
-    conn_handle = parse_arg_uint16("conn", &rc);
-    if (rc != 0) {
-        console_printf("invalid 'conn' parameter\n");
-        help_cmd_uint16("conn");
-        return rc;
-    }
-
-    rc = bletiny_sec_start(conn_handle);
-    if (rc != 0) {
-        console_printf("error starting security; rc=%d\n", rc);
-        return rc;
-    }
-
-    return 0;
-}
-
-static void
-bletiny_sec_enc_help(void)
-{
-#if !MYNEWT_VAL(BLETINY_HELP)
-    bletiny_help_disabled();
-    return;
-#endif
-
-    console_printf("Available sec enc commands: \n");
-    console_printf("\thelp\n");
-    console_printf("Available sec enc params: \n");
-    help_cmd_uint16("conn");
-    help_cmd_uint64("rand");
-    help_cmd_bool("auth");
-    help_cmd_byte_stream_exact_length("ltk", 16);
-}
-
-static int
-cmd_sec_enc(int argc, char **argv)
-{
-    uint16_t conn_handle;
-    uint16_t ediv;
-    uint64_t rand_val;
-    uint8_t ltk[16];
-    int rc;
-    int auth;
-
-    if (argc > 1 && strcmp(argv[1], "help") == 0) {
-        bletiny_sec_enc_help();
-        return 0;
-    }
-
-    conn_handle = parse_arg_uint16("conn", &rc);
-    if (rc != 0) {
-        console_printf("invalid 'conn' parameter\n");
-        help_cmd_uint16("conn");
-        return rc;
-    }
-
-    ediv = parse_arg_uint16("ediv", &rc);
-    if (rc == ENOENT) {
-        rc = bletiny_sec_restart(conn_handle, NULL, 0, 0, 0);
-    } else {
-        rand_val = parse_arg_uint64("rand", &rc);
-        if (rc != 0) {
-            console_printf("invalid 'rand' parameter\n");
-            help_cmd_uint64("rand");
-            return rc;
-        }
-
-        auth = parse_arg_bool("auth", &rc);
-        if (rc != 0) {
-            console_printf("invalid 'auth' parameter\n");
-            help_cmd_bool("auth");
-            return rc;
-        }
-
-        rc = parse_arg_byte_stream_exact_length("ltk", ltk, 16);
-        if (rc != 0) {
-            console_printf("invalid 'ltk' parameter\n");
-            help_cmd_byte_stream_exact_length("ltk", 16);
-            return rc;
-        }
-
-        rc = bletiny_sec_restart(conn_handle, ltk, ediv, rand_val, auth);
-    }
-
-    if (rc != 0) {
-        console_printf("error initiating encryption; rc=%d\n", rc);
-        return rc;
-    }
-
-    return 0;
-}
-
-static struct cmd_entry cmd_sec_entries[];
-
-static int
-cmd_sec_help(int argc, char **argv)
-{
-#if !MYNEWT_VAL(BLETINY_HELP)
-    bletiny_help_disabled();
-    return 0;
-#endif
-
-    int i;
-
-    console_printf("Available sec commands:\n");
-    for (i = 0; cmd_sec_entries[i].name != NULL; i++) {
-        console_printf("\t%s\n", cmd_sec_entries[i].name);
-    }
-    return 0;
-}
-
-static struct cmd_entry cmd_sec_entries[] = {
-    { "pair", cmd_sec_pair },
-    { "start", cmd_sec_start },
-    { "enc", cmd_sec_enc },
-    { "help", cmd_sec_help },
-    { NULL }
-};
-
-static int
-cmd_sec(int argc, char **argv)
-{
-    int rc;
-
-    rc = cmd_exec(cmd_sec_entries, argc, argv);
-    if (rc != 0) {
-        return rc;
-    }
-
-    return 0;
-}
-
-/*****************************************************************************
- * $set                                                                      *
- *****************************************************************************/
-
-#define CMD_ADV_DATA_MAX_UUIDS16                8
-#define CMD_ADV_DATA_MAX_UUIDS32                8
-#define CMD_ADV_DATA_MAX_UUIDS128               2
-#define CMD_ADV_DATA_MAX_PUBLIC_TGT_ADDRS       8
-#define CMD_ADV_DATA_SVC_DATA_UUID16_MAX_LEN    BLE_HS_ADV_MAX_FIELD_SZ
-#define CMD_ADV_DATA_SVC_DATA_UUID32_MAX_LEN    BLE_HS_ADV_MAX_FIELD_SZ
-#define CMD_ADV_DATA_SVC_DATA_UUID128_MAX_LEN   BLE_HS_ADV_MAX_FIELD_SZ
-#define CMD_ADV_DATA_URI_MAX_LEN                BLE_HS_ADV_MAX_FIELD_SZ
-#define CMD_ADV_DATA_MFG_DATA_MAX_LEN           BLE_HS_ADV_MAX_FIELD_SZ
-
-static void
-bletiny_set_adv_data_help(void)
-{
-#if !MYNEWT_VAL(BLETINY_HELP)
-    bletiny_help_disabled();
-    return;
-#endif
-
-    console_printf("Available set adv_data params: \n");
-    help_cmd_long_bounds("flags", 0, UINT8_MAX);
-    help_cmd_uint16("uuid16");
-    help_cmd_long("uuids16_is_complete");
-    help_cmd_uint32("uuid32");
-    help_cmd_long("uuids32_is_complete");
-    help_cmd_byte_stream_exact_length("uuid128", 16);
-    help_cmd_long("uuids128_is_complete");
-    help_cmd_long_bounds("tx_pwr_lvl", INT8_MIN, INT8_MAX);
-    help_cmd_byte_stream_exact_length("slave_itvl_range",
-                                      BLE_HS_ADV_SLAVE_ITVL_RANGE_LEN);
-    help_cmd_byte_stream("svc_data_uuid16");
-    help_cmd_byte_stream_exact_length("public_tgt_addr",
-                                      BLE_HS_ADV_PUBLIC_TGT_ADDR_ENTRY_LEN);
-    help_cmd_uint16("appearance");
-    help_cmd_extract("name");
-    help_cmd_uint16("adv_itvl");
-    help_cmd_byte_stream("svc_data_uuid32");
-    help_cmd_byte_stream("svc_data_uuid128");
-    help_cmd_byte_stream("uri");
-    help_cmd_byte_stream("mfg_data");
-}
-
-static int
-cmd_set_adv_data(void)
-{
-    static bssnz_t ble_uuid16_t uuids16[CMD_ADV_DATA_MAX_UUIDS16];
-    static bssnz_t ble_uuid32_t uuids32[CMD_ADV_DATA_MAX_UUIDS32];
-    static bssnz_t ble_uuid128_t uuids128[CMD_ADV_DATA_MAX_UUIDS128];
-    static bssnz_t uint8_t
-        public_tgt_addrs[CMD_ADV_DATA_MAX_PUBLIC_TGT_ADDRS]
-                        [BLE_HS_ADV_PUBLIC_TGT_ADDR_ENTRY_LEN];
-    static bssnz_t uint8_t slave_itvl_range[BLE_HS_ADV_SLAVE_ITVL_RANGE_LEN];
-    static bssnz_t uint8_t
-        svc_data_uuid16[CMD_ADV_DATA_SVC_DATA_UUID16_MAX_LEN];
-    static bssnz_t uint8_t
-        svc_data_uuid32[CMD_ADV_DATA_SVC_DATA_UUID32_MAX_LEN];
-    static bssnz_t uint8_t
-        svc_data_uuid128[CMD_ADV_DATA_SVC_DATA_UUID128_MAX_LEN];
-    static bssnz_t uint8_t uri[CMD_ADV_DATA_URI_MAX_LEN];
-    static bssnz_t uint8_t mfg_data[CMD_ADV_DATA_MFG_DATA_MAX_LEN];
-    struct ble_hs_adv_fields adv_fields;
-    uint32_t uuid32;
-    uint16_t uuid16;
-    uint8_t uuid128[16];
-    uint8_t public_tgt_addr[BLE_HS_ADV_PUBLIC_TGT_ADDR_ENTRY_LEN];
-    uint8_t eddystone_url_body_len;
-    uint8_t eddystone_url_suffix;
-    uint8_t eddystone_url_scheme;
-    char eddystone_url_body[BLE_EDDYSTONE_URL_MAX_LEN];
-    char *eddystone_url_full;
-    int svc_data_uuid16_len;
-    int svc_data_uuid32_len;
-    int svc_data_uuid128_len;
-    int uri_len;
-    int mfg_data_len;
-    int tmp;
-    int rc;
-
-    memset(&adv_fields, 0, sizeof adv_fields);
-
-    tmp = parse_arg_long_bounds("flags", 0, UINT8_MAX, &rc);
-    if (rc == 0) {
-        adv_fields.flags = tmp;
-    } else if (rc != ENOENT) {
-        console_printf("invalid 'flags' parameter\n");
-        help_cmd_long_bounds("flags", 0, UINT8_MAX);
-        return rc;
-    }
-
-    while (1) {
-        uuid16 = parse_arg_uint16("uuid16", &rc);
-        if (rc == 0) {
-            if (adv_fields.num_uuids16 >= CMD_ADV_DATA_MAX_UUIDS16) {
-                console_printf("invalid 'uuid16' parameter\n");
-                help_cmd_uint16("uuid16");
-                return EINVAL;
-            }
-            uuids16[adv_fields.num_uuids16] = (ble_uuid16_t) BLE_UUID16_INIT(uuid16);
-            adv_fields.num_uuids16++;
-        } else if (rc == ENOENT) {
-            break;
-        } else {
-            console_printf("invalid 'uuid16' parameter\n");
-            help_cmd_uint16("uuid16");
-            return rc;
-        }
-    }
-    if (adv_fields.num_uuids16 > 0) {
-        adv_fields.uuids16 = uuids16;
-    }
-
-    tmp = parse_arg_long("uuids16_is_complete", &rc);
-    if (rc == 0) {
-        adv_fields.uuids16_is_complete = !!tmp;
-    } else if (rc != ENOENT) {
-        console_printf("invalid 'uuids16_is_complete' parameter\n");
-        help_cmd_long("uuids16_is_complete");
-        return rc;
-    }
-
-    while (1) {
-        uuid32 = parse_arg_uint32("uuid32", &rc);
-        if (rc == 0) {
-            if (adv_fields.num_uuids32 >= CMD_ADV_DATA_MAX_UUIDS32) {
-                console_printf("invalid 'uuid32' parameter\n");
-                help_cmd_uint32("uuid32");
-                return EINVAL;
-            }
-            uuids32[adv_fields.num_uuids32] = (ble_uuid32_t) BLE_UUID32_INIT(uuid32);
-            adv_fields.num_uuids32++;
-        } else if (rc == ENOENT) {
-            break;
-        } else {
-            console_printf("invalid 'uuid32' parameter\n");
-            help_cmd_uint32("uuid32");
-            return rc;
-        }
-    }
-    if (adv_fields.num_uuids32 > 0) {
-        adv_fields.uuids32 = uuids32;
-    }
-
-    tmp = parse_arg_long("uuids32_is_complete", &rc);
-    if (rc == 0) {
-        adv_fields.uuids32_is_complete = !!tmp;
-    } else if (rc != ENOENT) {
-        console_printf("invalid 'uuids32_is_complete' parameter\n");
-        help_cmd_long("uuids32_is_complete");
-        return rc;
-    }
-
-    while (1) {
-        rc = parse_arg_byte_stream_exact_length("uuid128", uuid128, 16);
-        if (rc == 0) {
-            if (adv_fields.num_uuids128 >= CMD_ADV_DATA_MAX_UUIDS128) {
-                console_printf("invalid 'uuid128' parameter\n");
-                help_cmd_byte_stream_exact_length("uuid128", 16);
-                return EINVAL;
-            }
-            ble_uuid_init_from_buf((ble_uuid_any_t *) &uuids128[adv_fields.num_uuids128],
-                                   uuid128, 16);
-            adv_fields.num_uuids128++;
-        } else if (rc == ENOENT) {
-            break;
-        } else {
-            console_printf("invalid 'uuid128' parameter\n");
-            help_cmd_byte_stream_exact_length("uuid128", 16);
-            return rc;
-        }
-    }
-    if (adv_fields.num_uuids128 > 0) {
-        adv_fields.uuids128 = uuids128;
-    }
-
-    tmp = parse_arg_long("uuids128_is_complete", &rc);
-    if (rc == 0) {
-        adv_fields.uuids128_is_complete = !!tmp;
-    } else if (rc != ENOENT) {
-        console_printf("invalid 'uuids128_is_complete' parameter\n");
-        help_cmd_long("uuids128_is_complete");
-        return rc;
-    }
-
-    adv_fields.name = (uint8_t *)parse_arg_extract("name");
-    if (adv_fields.name != NULL) {
-        adv_fields.name_len = strlen((char *)adv_fields.name);
-    }
-
-    tmp = parse_arg_long_bounds("tx_pwr_lvl", INT8_MIN, INT8_MAX, &rc);
-    if (rc == 0) {
-        adv_fields.tx_pwr_lvl = tmp;
-        adv_fields.tx_pwr_lvl_is_present = 1;
-    } else if (rc != ENOENT) {
-        console_printf("invalid 'tx_pwr_lvl' parameter\n");
-        help_cmd_long_bounds("tx_pwr_lvl", INT8_MIN, INT8_MAX);
-        return rc;
-    }
-
-    rc = parse_arg_byte_stream_exact_length("slave_itvl_range",
-                                            slave_itvl_range,
-                                            BLE_HS_ADV_SLAVE_ITVL_RANGE_LEN);
-    if (rc == 0) {
-        adv_fields.slave_itvl_range = slave_itvl_range;
-    } else if (rc != ENOENT) {
-        console_printf("invalid 'slave_itvl_range' parameter\n");
-        help_cmd_byte_stream_exact_length("slave_itvl_range",
-                                          BLE_HS_ADV_SLAVE_ITVL_RANGE_LEN);
-        return rc;
-    }
-
-    rc = parse_arg_byte_stream("svc_data_uuid16",
-                               CMD_ADV_DATA_SVC_DATA_UUID16_MAX_LEN,
-                               svc_data_uuid16, &svc_data_uuid16_len);
-    if (rc == 0) {
-        adv_fields.svc_data_uuid16 = svc_data_uuid16;
-        adv_fields.svc_data_uuid16_len = svc_data_uuid16_len;
-    } else if (rc != ENOENT) {
-        console_printf("invalid 'svc_data_uuid16' parameter\n");
-        help_cmd_byte_stream("svc_data_uuid16");
-        return rc;
-    }
-
-    while (1) {
-        rc = parse_arg_byte_stream_exact_length(
-            "public_tgt_addr", public_tgt_addr,
-            BLE_HS_ADV_PUBLIC_TGT_ADDR_ENTRY_LEN);
-        if (rc == 0) {
-            if (adv_fields.num_public_tgt_addrs >=
-                CMD_ADV_DATA_MAX_PUBLIC_TGT_ADDRS) {
-
-                console_printf("invalid 'public_tgt_addr' parameter\n");
-                help_cmd_byte_stream_exact_length("public_tgt_addr",
-                                          BLE_HS_ADV_PUBLIC_TGT_ADDR_ENTRY_LEN);
-                return EINVAL;
-            }
-            memcpy(public_tgt_addrs[adv_fields.num_public_tgt_addrs],
-                   public_tgt_addr, BLE_HS_ADV_PUBLIC_TGT_ADDR_ENTRY_LEN);
-            adv_fields.num_public_tgt_addrs++;
-        } else if (rc == ENOENT) {
-            break;
-        } else {
-            console_printf("invalid 'public_tgt_addr' parameter\n");
-            help_cmd_byte_stream_exact_length("public_tgt_addr",
-                                          BLE_HS_ADV_PUBLIC_TGT_ADDR_ENTRY_LEN);
-            return rc;
-        }
-    }
-    if (adv_fields.num_public_tgt_addrs > 0) {
-        adv_fields.public_tgt_addr = (void *)public_tgt_addrs;
-    }
-
-    adv_fields.appearance = parse_arg_uint16("appearance", &rc);
-    if (rc == 0) {
-        adv_fields.appearance_is_present = 1;
-    } else if (rc != ENOENT) {
-        console_printf("invalid 'appearance' parameter\n");
-        help_cmd_uint16("appearance");
-        return rc;
-    }
-
-    adv_fields.adv_itvl = parse_arg_uint16("adv_itvl", &rc);
-    if (rc == 0) {
-        adv_fields.adv_itvl_is_present = 1;
-    } else if (rc != ENOENT) {
-        console_printf("invalid 'adv_itvl' parameter\n");
-        help_cmd_uint16("adv_itvl");
-        return rc;
-    }
-
-    rc = parse_arg_byte_stream("svc_data_uuid32",
-                               CMD_ADV_DATA_SVC_DATA_UUID32_MAX_LEN,
-                               svc_data_uuid32, &svc_data_uuid32_len);
-    if (rc == 0) {
-        adv_fields.svc_data_uuid32 = svc_data_uuid32;
-        adv_fields.svc_data_uuid32_len = svc_data_uuid32_len;
-    } else if (rc != ENOENT) {
-        console_printf("invalid 'svc_data_uuid32' parameter\n");
-        help_cmd_byte_stream("svc_data_uuid32");
-        return rc;
-    }
-
-    rc = parse_arg_byte_stream("svc_data_uuid128",
-                               CMD_ADV_DATA_SVC_DATA_UUID128_MAX_LEN,
-                               svc_data_uuid128, &svc_data_uuid128_len);
-    if (rc == 0) {
-        adv_fields.svc_data_uuid128 = svc_data_uuid128;
-        adv_fields.svc_data_uuid128_len = svc_data_uuid128_len;
-    } else if (rc != ENOENT) {
-        console_printf("invalid 'svc_data_uuid128' parameter\n");
-        help_cmd_byte_stream("svc_data_uuid128");
-        return rc;
-    }
-
-    rc = parse_arg_byte_stream("uri", CMD_ADV_DATA_URI_MAX_LEN, uri, &uri_len);
-    if (rc == 0) {
-        adv_fields.uri = uri;
-        adv_fields.uri_len = uri_len;
-    } else if (rc != ENOENT) {
-        console_printf("invalid 'uri' parameter\n");
-        help_cmd_byte_stream("uri");
-        return rc;
-    }
-
-    rc = parse_arg_byte_stream("mfg_data", CMD_ADV_DATA_MFG_DATA_MAX_LEN,
-                               mfg_data, &mfg_data_len);
-    if (rc == 0) {
-        adv_fields.mfg_data = mfg_data;
-        adv_fields.mfg_data_len = mfg_data_len;
-    } else if (rc != ENOENT) {
-        console_printf("invalid 'mfg_data' parameter\n");
-        help_cmd_byte_stream("mfg_data");
-        return rc;
-    }
-
-    eddystone_url_full = parse_arg_extract("eddystone_url");
-    if (eddystone_url_full != NULL) {
-        rc = cmd_parse_eddystone_url(eddystone_url_full, &eddystone_url_scheme,
-                                     eddystone_url_body,
-                                     &eddystone_url_body_len,
-                                     &eddystone_url_suffix);
-        if (rc != 0) {
-            return rc;
-        }
-
-        rc = ble_eddystone_set_adv_data_url(&adv_fields, eddystone_url_scheme,
-                                            eddystone_url_body,
-                                            eddystone_url_body_len,
-                                            eddystone_url_suffix);
-    } else {
-        rc = bletiny_set_adv_data(&adv_fields);
-    }
-    if (rc != 0) {
-        console_printf("error setting advertisement data; rc=%d\n", rc);
-        return rc;
-    }
-
-    return 0;
-}
-
-static void
-bletiny_set_sm_data_help(void)
-{
-#if !MYNEWT_VAL(BLETINY_HELP)
-    bletiny_help_disabled();
-    return;
-#endif
-
-    console_printf("Available set sm_data params: \n");
-    help_cmd_bool("oob_flag");
-    help_cmd_bool("mitm_flag");
-    help_cmd_uint8("io_capabilities");
-    help_cmd_uint8("our_key_dist");
-    help_cmd_uint8("their_key_dist");
-    help_cmd_bool("bonding");
-    help_cmd_bool("sc");
-}
-
-static int
-cmd_set_sm_data(void)
-{
-    uint8_t tmp;
-    int good;
-    int rc;
-
-    good = 0;
-
-    tmp = parse_arg_bool("oob_flag", &rc);
-    if (rc == 0) {
-        ble_hs_cfg.sm_oob_data_flag = tmp;
-        good++;
-    } else if (rc != ENOENT) {
-        console_printf("invalid 'oob_flag' parameter\n");
-        help_cmd_bool("oob_flag");
-        return rc;
-    }
-
-    tmp = parse_arg_bool("mitm_flag", &rc);
-    if (rc == 0) {
-        good++;
-        ble_hs_cfg.sm_mitm = tmp;
-    } else if (rc != ENOENT) {
-        console_printf("invalid 'mitm_flag' parameter\n");
-        help_cmd_bool("mitm_flag");
-        return rc;
-    }
-
-    tmp = parse_arg_uint8("io_capabilities", &rc);
-    if (rc == 0) {
-        good++;
-        ble_hs_cfg.sm_io_cap = tmp;
-    } else if (rc != ENOENT) {
-        console_printf("invalid 'io_capabilities' parameter\n");
-        help_cmd_uint8("io_capabilities");
-        return rc;
-    }
-
-    tmp = parse_arg_uint8("our_key_dist", &rc);
-    if (rc == 0) {
-        good++;
-        ble_hs_cfg.sm_our_key_dist = tmp;
-    } else if (rc != ENOENT) {
-        console_printf("invalid 'our_key_dist' parameter\n");
-        help_cmd_uint8("our_key_dist");
-        return rc;
-    }
-
-    tmp = parse_arg_uint8("their_key_dist", &rc);
-    if (rc == 0) {
-        good++;
-        ble_hs_cfg.sm_their_key_dist = tmp;
-    } else if (rc != ENOENT) {
-        console_printf("invalid 'their_key_dist' parameter\n");
-        help_cmd_uint8("their_key_dist");
-        return rc;
-    }
-
-    tmp = parse_arg_bool("bonding", &rc);
-    if (rc == 0) {
-        good++;
-        ble_hs_cfg.sm_bonding = tmp;
-    } else if (rc != ENOENT) {
-        console_printf("invalid 'bonding' parameter\n");
-        help_cmd_bool("bonding");
-        return rc;
-    }
-
-    tmp = parse_arg_bool("sc", &rc);
-    if (rc == 0) {
-        good++;
-        ble_hs_cfg.sm_sc = tmp;
-    } else if (rc != ENOENT) {
-        console_printf("invalid 'sc' parameter\n");
-        help_cmd_bool("sc");
-        return rc;
-    }
-
-    if (!good) {
-        console_printf("Error: no valid settings specified\n");
-        return -1;
-    }
-
-    return 0;
-}
-
-static struct kv_pair cmd_set_addr_types[] = {
-    { "public",         BLE_ADDR_PUBLIC },
-    { "random",         BLE_ADDR_RANDOM },
-    { NULL }
-};
-
-static void
-bletiny_set_priv_mode_help(void)
-{
-    console_printf("Available set priv_mode params: \n");
-    help_cmd_kv_dflt("addr_type", cmd_set_addr_types, BLE_ADDR_PUBLIC);
-    help_cmd_byte_stream_exact_length("addr", 6);
-    help_cmd_uint8("mode");
-}
-
-static int
-cmd_set_priv_mode(void)
-{
-    ble_addr_t addr;
-    uint8_t priv_mode;
-    int rc;
-
-    addr.type = parse_arg_kv_default("addr_type", cmd_set_addr_types,
-                                     BLE_ADDR_PUBLIC, &rc);
-    if (rc != 0) {
-        console_printf("invalid 'addr_type' parameter\n");
-        help_cmd_kv_dflt("addr_type", cmd_set_addr_types, BLE_ADDR_PUBLIC);
-        return rc;
-    }
-
-    rc = parse_arg_mac("addr", addr.val);
-    if (rc != 0) {
-        console_printf("invalid 'addr' parameter\n");
-        help_cmd_byte_stream_exact_length("addr", 6);
-        return rc;
-    }
-
-    priv_mode = parse_arg_uint8("mode", &rc);
-    if (rc != 0) {
-        console_printf("missing mode\n");
-        return rc;
-    }
-
-    return ble_gap_set_priv_mode(&addr, priv_mode);
-}
-
-static void
-bletiny_set_addr_help(void)
-{
-#if !MYNEWT_VAL(BLETINY_HELP)
-    bletiny_help_disabled();
-    return;
-#endif
-
-    console_printf("Available set addr params: \n");
-    help_cmd_kv_dflt("addr_type", cmd_set_addr_types, BLE_ADDR_PUBLIC);
-    help_cmd_byte_stream_exact_length("addr", 6);
-}
-
-static int
-cmd_set_addr(void)
-{
-    uint8_t addr[6];
-    int addr_type;
-    int rc;
-
-    addr_type = parse_arg_kv_default("addr_type", cmd_set_addr_types,
-                                     BLE_ADDR_PUBLIC, &rc);
-    if (rc != 0) {
-        console_printf("invalid 'addr_type' parameter\n");
-        help_cmd_kv_dflt("addr_type", cmd_set_addr_types, BLE_ADDR_PUBLIC);
-        return rc;
-    }
-
-    rc = parse_arg_mac("addr", addr);
-    if (rc != 0) {
-        console_printf("invalid 'addr' parameter\n");
-        help_cmd_byte_stream_exact_length("addr", 6);
-        return rc;
-    }
-
-    switch (addr_type) {
-    case BLE_ADDR_PUBLIC:
-        /* We shouldn't be writing to the controller's address (g_dev_addr).
-         * There is no standard way to set the local public address, so this is
-         * our only option at the moment.
-         */
-        memcpy(g_dev_addr, addr, 6);
-        ble_hs_id_set_pub(g_dev_addr);
-        break;
-
-    case BLE_ADDR_RANDOM:
-        rc = ble_hs_id_set_rnd(addr);
-        if (rc != 0) {
-            return rc;
-        }
-        break;
-
-    default:
-        assert(0);
-        return BLE_HS_EUNKNOWN;
-    }
-
-    return 0;
-}
-
-static void
-bletiny_set_help(void)
-{
-#if !MYNEWT_VAL(BLETINY_HELP)
-    bletiny_help_disabled();
-    return;
-#endif
-
-    console_printf("Available set commands: \n");
-    console_printf("\thelp\n");
-    console_printf("\tadv_data\n");
-    console_printf("\tsm_data\n");
-    console_printf("\taddr\n");
-    console_printf("Available set params: \n");
-    help_cmd_uint16("mtu");
-    help_cmd_byte_stream_exact_length("irk", 16);
-}
-
-static int
-cmd_set(int argc, char **argv)
-{
-    uint16_t mtu;
-    uint8_t irk[16];
-    int good;
-    int rc;
-
-    if (argc > 1 && strcmp(argv[1], "help") == 0) {
-        bletiny_set_help();
-        bletiny_set_adv_data_help();
-        bletiny_set_sm_data_help();
-        bletiny_set_addr_help();
-        bletiny_set_priv_mode_help();
-        return 0;
-    }
-
-    if (argc > 1 && strcmp(argv[1], "adv_data") == 0) {
-        rc = cmd_set_adv_data();
-        return rc;
-    }
-
-    if (argc > 1 && strcmp(argv[1], "sm_data") == 0) {
-        rc = cmd_set_sm_data();
-        return rc;
-    }
-
-    if (argc > 1 && strcmp(argv[1], "priv_mode") == 0) {
-        rc = cmd_set_priv_mode();
-        return rc;
-    }
-
-    good = 0;
-
-    rc = parse_arg_find_idx("addr");
-    if (rc != -1) {
-        rc = cmd_set_addr();
-        if (rc != 0) {
-            return rc;
-        }
-
-        good = 1;
-    }
-
-    mtu = parse_arg_uint16("mtu", &rc);
-    if (rc == 0) {
-        rc = ble_att_set_preferred_mtu(mtu);
-        if (rc == 0) {
-            good = 1;
-        }
-    } else if (rc != ENOENT) {
-        console_printf("invalid 'mtu' parameter\n");
-        help_cmd_uint16("mtu");
-        return rc;
-    }
-
-    rc = parse_arg_byte_stream_exact_length("irk", irk, 16);
-    if (rc == 0) {
-        good = 1;
-        ble_hs_pvcy_set_our_irk(irk);
-    } else if (rc != ENOENT) {
-        console_printf("invalid 'irk' parameter\n");
-        help_cmd_byte_stream_exact_length("irk", 16);
-        return rc;
-    }
-
-    if (!good) {
-        console_printf("Error: no valid settings specified\n");
-        return -1;
-    }
-
-    return 0;
-}
-
-/*****************************************************************************
- * $terminate                                                                *
- *****************************************************************************/
-
-static void
-bletiny_term_help(void)
-{
-#if !MYNEWT_VAL(BLETINY_HELP)
-    bletiny_help_disabled();
-    return;
-#endif
-
-    console_printf("Available term commands: \n");
-    console_printf("\thelp\n");
-    console_printf("Available term params: \n");
-    help_cmd_uint16("conn");
-    help_cmd_uint8_dflt("reason", BLE_ERR_REM_USER_CONN_TERM);
-}
-
-static int
-cmd_term(int argc, char **argv)
-{
-    uint16_t conn_handle;
-    uint8_t reason;
-    int rc;
-
-    if (argc > 1 && strcmp(argv[1], "help") == 0) {
-        bletiny_term_help();
-        return 0;
-    }
-
-    conn_handle = parse_arg_uint16("conn", &rc);
-    if (rc != 0) {
-        console_printf("invalid 'conn' parameter\n");
-        help_cmd_uint16("conn");
-        return rc;
-    }
-
-    reason = parse_arg_uint8_dflt("reason", BLE_ERR_REM_USER_CONN_TERM, &rc);
-    if (rc != 0) {
-        console_printf("invalid 'reason' parameter\n");
-        help_cmd_uint8_dflt("reason", BLE_ERR_REM_USER_CONN_TERM);
-        return rc;
-    }
-
-    rc = bletiny_term_conn(conn_handle, reason);
-    if (rc != 0) {
-        console_printf("error terminating connection; rc=%d\n", rc);
-        return rc;
-    }
-
-    return 0;
-}
-
-/*****************************************************************************
- * $update connection parameters                                             *
- *****************************************************************************/
-
-static void
-bletiny_update_help(void)
-{
-#if !MYNEWT_VAL(BLETINY_HELP)
-    bletiny_help_disabled();
-    return;
-#endif
-
-    console_printf("Available update commands: \n");
-    console_printf("\thelp\n");
-    console_printf("Available update params: \n");
-    help_cmd_uint16("conn");
-    help_cmd_uint16_dflt("itvl_min", BLE_GAP_INITIAL_CONN_ITVL_MIN);
-    help_cmd_uint16_dflt("itvl_max", BLE_GAP_INITIAL_CONN_ITVL_MAX);
-    help_cmd_uint16_dflt("latency", 0);
-    help_cmd_uint16_dflt("timeout", 0x0100);
-    help_cmd_uint16_dflt("min_ce_len", 0x0010);
-    help_cmd_uint16_dflt("max_ce_len", 0x0300);
-}
-
-static int
-cmd_update(int argc, char **argv)
-{
-    struct ble_gap_upd_params params;
-    uint16_t conn_handle;
-    int rc;
-
-    if (argc > 1 && strcmp(argv[1], "help") == 0) {
-        bletiny_update_help();
-        return 0;
-    }
-
-    conn_handle = parse_arg_uint16("conn", &rc);
-    if (rc != 0) {
-        console_printf("invalid 'conn' parameter\n");
-        help_cmd_uint16("conn");
-        return rc;
-    }
-
-    params.itvl_min = parse_arg_uint16_dflt(
-        "itvl_min", BLE_GAP_INITIAL_CONN_ITVL_MIN, &rc);
-    if (rc != 0) {
-        console_printf("invalid 'itvl_min' parameter\n");
-        help_cmd_uint16_dflt("itvl_min", BLE_GAP_INITIAL_CONN_ITVL_MIN);
-        return rc;
-    }
-
-    params.itvl_max = parse_arg_uint16_dflt(
-        "itvl_max", BLE_GAP_INITIAL_CONN_ITVL_MAX, &rc);
-    if (rc != 0) {
-        console_printf("invalid 'itvl_max' parameter\n");
-        help_cmd_uint16_dflt("itvl_max", BLE_GAP_INITIAL_CONN_ITVL_MAX);
-        return rc;
-    }
-
-    params.latency = parse_arg_uint16_dflt("latency", 0, &rc);
-    if (rc != 0) {
-        console_printf("invalid 'latency' parameter\n");
-        help_cmd_uint16_dflt("latency", 0);
-        return rc;
-    }
-
-    params.supervision_timeout = parse_arg_uint16_dflt("timeout", 0x0100, &rc);
-    if (rc != 0) {
-        console_printf("invalid 'timeout' parameter\n");
-        help_cmd_uint16_dflt("timeout", 0x0100);
-        return rc;
-    }
-
-    params.min_ce_len = parse_arg_uint16_dflt("min_ce_len", 0x0010, &rc);
-    if (rc != 0) {
-        console_printf("invalid 'min_ce_len' parameter\n");
-        help_cmd_uint16_dflt("min_ce_len", 0x0010);
-        return rc;
-    }
-
-    params.max_ce_len = parse_arg_uint16_dflt("max_ce_len", 0x0300, &rc);
-    if (rc != 0) {
-        console_printf("invalid 'max_ce_len' parameter\n");
-        help_cmd_uint16_dflt("max_ce_len", 0x0300);
-        return rc;
-    }
-
-    rc = bletiny_update_conn(conn_handle, &params);
-    if (rc != 0) {
-        console_printf("error updating connection; rc=%d\n", rc);
-        return rc;
-    }
-
-    return 0;
-}
-
-/*****************************************************************************
- * $white list                                                               *
- *****************************************************************************/
-
-#define CMD_WL_MAX_SZ   8
-
-static void
-bletiny_wl_help(void)
-{
-#if !MYNEWT_VAL(BLETINY_HELP)
-    bletiny_help_disabled();
-    return;
-#endif
-
-    console_printf("Available wl commands: \n");
-    console_printf("\thelp\n");
-    console_printf("Available wl params: \n");
-    console_printf("\tlist of:\n");
-    help_cmd_byte_stream_exact_length("addr", 6);
-    help_cmd_kv("addr_type", cmd_addr_type);
-}
-
-static int
-cmd_wl(int argc, char **argv)
-{
-    static ble_addr_t addrs[CMD_WL_MAX_SZ];
-    int addrs_cnt;
-    int rc;
-
-    if (argc > 1 && strcmp(argv[1], "help") == 0) {
-        bletiny_wl_help();
-        return 0;
-    }
-
-    addrs_cnt = 0;
-    while (1) {
-        if (addrs_cnt >= CMD_WL_MAX_SZ) {
-            return EINVAL;
-        }
-
-        rc = parse_arg_mac("addr", addrs[addrs_cnt].val);
-        if (rc == ENOENT) {
-            break;
-        } else if (rc != 0) {
-            console_printf("invalid 'addr' parameter\n");
-            help_cmd_byte_stream_exact_length("addr", 6);
-            return rc;
-        }
-
-        addrs[addrs_cnt].type = parse_arg_kv("addr_type", cmd_addr_type, &rc);
-        if (rc != 0) {
-            console_printf("invalid 'addr' parameter\n");
-            help_cmd_kv("addr_type", cmd_addr_type);
-            return rc;
-        }
-
-        addrs_cnt++;
-    }
-
-    if (addrs_cnt == 0) {
-        return EINVAL;
-    }
-
-    bletiny_wl_set(addrs, addrs_cnt);
-
-    return 0;
-}
-
-/*****************************************************************************
- * $write                                                                    *
- *****************************************************************************/
-
-static void
-bletiny_write_help(void)
-{
-#if !MYNEWT_VAL(BLETINY_HELP)
-    bletiny_help_disabled();
-    return;
-#endif
-
-    console_printf("Available write commands: \n");
-    console_printf("\thelp\n");
-    console_printf("Available write params: \n");
-    help_cmd_uint16("conn");
-    help_cmd_long("no_rsp");
-    help_cmd_long("long");
-    console_printf("\tlist of:\n");
-    help_cmd_long("attr");
-    help_cmd_byte_stream("value");
-    help_cmd_uint16("offset");
-}
-
-static int
-cmd_write(int argc, char **argv)
-{
-    struct ble_gatt_attr attrs[MYNEWT_VAL(BLE_GATT_WRITE_MAX_ATTRS)] = { { 0 } };
-    uint16_t attr_handle;
-    uint16_t conn_handle;
-    uint16_t offset;
-    int total_attr_len;
-    int num_attrs;
-    int attr_len;
-    int is_long;
-    int no_rsp;
-    int rc;
-    int i;
-
-    if (argc > 1 && strcmp(argv[1], "help") == 0) {
-        bletiny_write_help();
-        return 0;
-    }
-
-    conn_handle = parse_arg_uint16("conn", &rc);
-    if (rc != 0) {
-        console_printf("invalid 'conn' parameter\n");
-        help_cmd_uint16("conn");
-        return rc;
-    }
-
-    no_rsp = parse_arg_long("no_rsp", &rc);
-    if (rc == ENOENT) {
-        no_rsp = 0;
-    } else if (rc != 0) {
-        console_printf("invalid 'no_rsp' parameter\n");
-        help_cmd_long("no_rsp");
-        return rc;
-    }
-
-    is_long = parse_arg_long("long", &rc);
-    if (rc == ENOENT) {
-        is_long = 0;
-    } else if (rc != 0) {
-        console_printf("invalid 'long' parameter\n");
-        help_cmd_long("long");
-        return rc;
-    }
-
-    total_attr_len = 0;
-    num_attrs = 0;
-    while (1) {
-        attr_handle = parse_arg_long("attr", &rc);
-        if (rc == ENOENT) {
-            break;
-        } else if (rc != 0) {
-            rc = -rc;
-            console_printf("invalid 'attr' parameter\n");
-            help_cmd_long("attr");
-            goto done;
-        }
-
-        rc = parse_arg_byte_stream("value", sizeof cmd_buf - total_attr_len,
-                                   cmd_buf + total_attr_len, &attr_len);
-        if (rc == ENOENT) {
-            break;
-        } else if (rc != 0) {
-            console_printf("invalid 'value' parameter\n");
-            help_cmd_byte_stream("value");
-            goto done;
-        }
-
-        offset = parse_arg_uint16("offset", &rc);
-        if (rc == ENOENT) {
-            offset = 0;
-        } else if (rc != 0) {
-            console_printf("invalid 'offset' parameter\n");
-            help_cmd_uint16("offset");
-            return rc;
-        }
-
-        if (num_attrs >= sizeof attrs / sizeof attrs[0]) {
-            rc = -EINVAL;
-            goto done;
-        }
-
-        attrs[num_attrs].handle = attr_handle;
-        attrs[num_attrs].offset = offset;
-        attrs[num_attrs].om = ble_hs_mbuf_from_flat(cmd_buf + total_attr_len,
-                                                    attr_len);
-        if (attrs[num_attrs].om == NULL) {
-            goto done;
-        }
-
-        total_attr_len += attr_len;
-        num_attrs++;
-    }
-
-    if (no_rsp) {
-        if (num_attrs != 1) {
-            rc = -EINVAL;
-            goto done;
-        }
-        rc = bletiny_write_no_rsp(conn_handle, attrs[0].handle, attrs[0].om);
-        attrs[0].om = NULL;
-    } else if (is_long) {
-        if (num_attrs != 1) {
-            rc = -EINVAL;
-            goto done;
-        }
-        rc = bletiny_write_long(conn_handle, attrs[0].handle,
-                                attrs[0].offset, attrs[0].om);
-        attrs[0].om = NULL;
-    } else if (num_attrs > 1) {
-        rc = bletiny_write_reliable(conn_handle, attrs, num_attrs);
-    } else if (num_attrs == 1) {
-        rc = bletiny_write(conn_handle, attrs[0].handle, attrs[0].om);
-        attrs[0].om = NULL;
-    } else {
-        rc = -EINVAL;
-    }
-
-done:
-    for (i = 0; i < sizeof attrs / sizeof attrs[0]; i++) {
-        os_mbuf_free_chain(attrs[i].om);
-    }
-
-    if (rc != 0) {
-        console_printf("error writing characteristic; rc=%d\n", rc);
-    }
-
-    return rc;
-}
-
-/*****************************************************************************
- * store                                                                     *
- *****************************************************************************/
-
-static struct kv_pair cmd_keystore_entry_type[] = {
-    { "msec",       BLE_STORE_OBJ_TYPE_PEER_SEC },
-    { "ssec",       BLE_STORE_OBJ_TYPE_OUR_SEC },
-    { "cccd",       BLE_STORE_OBJ_TYPE_CCCD },
-    { NULL }
-};
-
-static void
-bletiny_keystore_parse_keydata_help(void)
-{
-#if !MYNEWT_VAL(BLETINY_HELP)
-    bletiny_help_disabled();
-    return;
-#endif
-
-    console_printf("Available keystore parse keydata params: \n");
-    help_cmd_kv("type", cmd_keystore_entry_type);
-    help_cmd_kv("addr_type", cmd_addr_type);
-    help_cmd_byte_stream_exact_length("addr", 6);
-    help_cmd_uint16("ediv");
-    help_cmd_uint64("rand");
-}
-
-static int
-cmd_keystore_parse_keydata(int argc, char **argv, union ble_store_key *out,
-                           int *obj_type)
-{
-    int rc;
-
-    memset(out, 0, sizeof(*out));
-    *obj_type = parse_arg_kv("type", cmd_keystore_entry_type, &rc);
-    if (rc != 0) {
-        console_printf("invalid 'type' parameter\n");
-        help_cmd_kv("type", cmd_keystore_entry_type);
-        return rc;
-    }
-
-    switch (*obj_type) {
-    case BLE_STORE_OBJ_TYPE_PEER_SEC:
-    case BLE_STORE_OBJ_TYPE_OUR_SEC:
-        out->sec.peer_addr.type = parse_arg_kv("addr_type", cmd_addr_type, &rc);
-        if (rc != 0) {
-            console_printf("invalid 'addr_type' parameter\n");
-            help_cmd_kv("addr_type", cmd_addr_type);
-            return rc;
-        }
-
-        rc = parse_arg_mac("addr", out->sec.peer_addr.val);
-        if (rc != 0) {
-            console_printf("invalid 'addr' parameter\n");
-            help_cmd_byte_stream_exact_length("addr", 6);
-            return rc;
-        }
-
-        out->sec.ediv = parse_arg_uint16("ediv", &rc);
-        if (rc != 0) {
-            console_printf("invalid 'ediv' parameter\n");
-            help_cmd_uint16("ediv");
-            return rc;
-        }
-
-        out->sec.rand_num = parse_arg_uint64("rand", &rc);
-        if (rc != 0) {
-            console_printf("invalid 'rand' parameter\n");
-            help_cmd_uint64("rand");
-            return rc;
-        }
-        return 0;
-
-    default:
-        return EINVAL;
-    }
-}
-
-static void
-bletiny_keystore_parse_valuedata_help(void)
-{
-#if !MYNEWT_VAL(BLETINY_HELP)
-    bletiny_help_disabled();
-    return;
-#endif
-
-    console_printf("Available keystore parse valuedata params: \n");
-    help_cmd_byte_stream_exact_length("ltk", 16);
-    help_cmd_byte_stream_exact_length("irk", 16);
-    help_cmd_byte_stream_exact_length("csrk", 16);
-}
-
-static int
-cmd_keystore_parse_valuedata(int argc, char **argv,
-                             int obj_type,
-                             union ble_store_key *key,
-                             union ble_store_value *out)
-{
-    int rc;
-    int valcnt = 0;
-    memset(out, 0, sizeof(*out));
-
-    switch (obj_type) {
-        case BLE_STORE_OBJ_TYPE_PEER_SEC:
-        case BLE_STORE_OBJ_TYPE_OUR_SEC:
-            rc = parse_arg_byte_stream_exact_length("ltk", out->sec.ltk, 16);
-            if (rc == 0) {
-                out->sec.ltk_present = 1;
-                swap_in_place(out->sec.ltk, 16);
-                valcnt++;
-            } else if (rc != ENOENT) {
-                console_printf("invalid 'ltk' parameter\n");
-                help_cmd_byte_stream_exact_length("ltk", 16);
-                return rc;
-            }
-            rc = parse_arg_byte_stream_exact_length("irk", out->sec.irk, 16);
-            if (rc == 0) {
-                out->sec.irk_present = 1;
-                swap_in_place(out->sec.irk, 16);
-                valcnt++;
-            } else if (rc != ENOENT) {
-                console_printf("invalid 'irk' parameter\n");
-                help_cmd_byte_stream_exact_length("irk", 16);
-                return rc;
-            }
-            rc = parse_arg_byte_stream_exact_length("csrk", out->sec.csrk, 16);
-            if (rc == 0) {
-                out->sec.csrk_present = 1;
-                swap_in_place(out->sec.csrk, 16);
-                valcnt++;
-            } else if (rc != ENOENT) {
-                console_printf("invalid 'csrk' parameter\n");
-                help_cmd_byte_stream_exact_length("csrk", 16);
-                return rc;
-            }
-            out->sec.peer_addr = key->sec.peer_addr;
-            out->sec.ediv = key->sec.ediv;
-            out->sec.rand_num = key->sec.rand_num;
-            break;
-    }
-
-    if (valcnt) {
-        return 0;
-    }
-    return -1;
-}
-
-static void
-bletiny_keystore_add_help(void)
-{
-#if !MYNEWT_VAL(BLETINY_HELP)
-    bletiny_help_disabled();
-    return;
-#endif
-
-    console_printf("Available keystore add commands: \n");
-    console_printf("\thelp\n");
-    bletiny_keystore_parse_keydata_help();
-    bletiny_keystore_parse_valuedata_help();
-}
-
-static int
-cmd_keystore_add(int argc, char **argv)
-{
-    union ble_store_key key;
-    union ble_store_value value;
-    int obj_type;
-    int rc;
-
-    if (argc > 1 && strcmp(argv[1], "help") == 0) {
-        bletiny_keystore_add_help();
-        return 0;
-    }
-
-    rc = cmd_keystore_parse_keydata(argc, argv, &key, &obj_type);
-
-    if (rc) {
-        return rc;
-    }
-
-    rc = cmd_keystore_parse_valuedata(argc, argv, obj_type, &key, &value);
-
-    if (rc) {
-        return rc;
-    }
-
-    switch(obj_type) {
-        case BLE_STORE_OBJ_TYPE_PEER_SEC:
-            rc = ble_store_write_peer_sec(&value.sec);
-            break;
-        case BLE_STORE_OBJ_TYPE_OUR_SEC:
-            rc = ble_store_write_our_sec(&value.sec);
-            break;
-        case BLE_STORE_OBJ_TYPE_CCCD:
-            rc = ble_store_write_cccd(&value.cccd);
-            break;
-        default:
-            rc = ble_store_write(obj_type, &value);
-    }
-    return rc;
-}
-
-static void
-bletiny_keystore_del_help(void)
-{
-#if !MYNEWT_VAL(BLETINY_HELP)
-    bletiny_help_disabled();
-    return;
-#endif
-
-    console_printf("Available keystore del commands: \n");
-    console_printf("\thelp\n");
-    bletiny_keystore_parse_keydata_help();
-}
-
-static int
-cmd_keystore_del(int argc, char **argv)
-{
-    union ble_store_key key;
-    int obj_type;
-    int rc;
-
-    if (argc > 1 && strcmp(argv[1], "help") == 0) {
-        bletiny_keystore_del_help();
-        return 0;
-    }
-
-    rc = cmd_keystore_parse_keydata(argc, argv, &key, &obj_type);
-
-    if (rc) {
-        return rc;
-    }
-    rc = ble_store_delete(obj_type, &key);
-    return rc;
-}
-
-static int
-cmd_keystore_iterator(int obj_type,
-                      union ble_store_value *val,
-                      void *cookie) {
-
-    switch (obj_type) {
-        case BLE_STORE_OBJ_TYPE_PEER_SEC:
-        case BLE_STORE_OBJ_TYPE_OUR_SEC:
-            console_printf("Key: ");
-            if (ble_addr_cmp(&val->sec.peer_addr, BLE_ADDR_ANY) == 0) {
-                console_printf("ediv=%u ", val->sec.ediv);
-                console_printf("ediv=%llu ", val->sec.rand_num);
-            } else {
-                console_printf("addr_type=%u ", val->sec.peer_addr.type);
-                print_addr(val->sec.peer_addr.val);
-            }
-            console_printf("\n");
-
-            if (val->sec.ltk_present) {
-                console_printf("    LTK: ");
-                print_bytes(val->sec.ltk, 16);
-                console_printf("\n");
-            }
-            if (val->sec.irk_present) {
-                console_printf("    IRK: ");
-                print_bytes(val->sec.irk, 16);
-                console_printf("\n");
-            }
-            if (val->sec.csrk_present) {
-                console_printf("    CSRK: ");
-                print_bytes(val->sec.csrk, 16);
-                console_printf("\n");
-            }
-            break;
-    }
-    return 0;
-}
-
-static void
-bletiny_keystore_show_help(void)
-{
-#if !MYNEWT_VAL(BLETINY_HELP)
-    bletiny_help_disabled();
-    return;
-#endif
-
-    console_printf("Available keystore show commands: \n");
-    console_printf("\thelp\n");
-    console_printf("Available keystore show params: \n");
-    help_cmd_kv("type", cmd_keystore_entry_type);
-}
-
-static int
-cmd_keystore_show(int argc, char **argv)
-{
-    int type;
-    int rc;
-
-    if (argc > 1 && strcmp(argv[1], "help") == 0) {
-        bletiny_keystore_show_help();
-        return 0;
-    }
-
-    type = parse_arg_kv("type", cmd_keystore_entry_type, &rc);
-    if (rc != 0) {
-        console_printf("invalid 'type' parameter\n");
-        help_cmd_kv("type", cmd_keystore_entry_type);
-        return rc;
-    }
-
-    ble_store_iterate(type, &cmd_keystore_iterator, NULL);
-    return 0;
-}
-
-static struct cmd_entry cmd_keystore_entries[];
-
-static int
-cmd_keystore_help(int argc, char **argv)
-{
-#if !MYNEWT_VAL(BLETINY_HELP)
-    bletiny_help_disabled();
-    return 0;
-#endif
-
-    int i;
-
-    console_printf("Available keystore commands:\n");
-    for (i = 0; cmd_keystore_entries[i].name != NULL; i++) {
-        console_printf("\t%s\n", cmd_keystore_entries[i].name);
-    }
-    return 0;
-}
-
-static struct cmd_entry cmd_keystore_entries[] = {
-    { "add", cmd_keystore_add },
-    { "del", cmd_keystore_del },
-    { "show", cmd_keystore_show },
-    { "help", cmd_keystore_help },
-    { NULL, NULL }
-};
-
-static int
-cmd_keystore(int argc, char **argv)
-{
-    int rc;
-
-    rc = cmd_exec(cmd_keystore_entries, argc, argv);
-    if (rc != 0) {
-        return rc;
-    }
-
-    return 0;
-}
-
-/*****************************************************************************
- * $passkey                                                                  *
- *****************************************************************************/
-
-static void
-bletiny_passkey_help(void)
-{
-#if !MYNEWT_VAL(BLETINY_HELP)
-    bletiny_help_disabled();
-    return;
-#endif
-
-    console_printf("Available passkey commands: \n");
-    console_printf("\thelp\n");
-    console_printf("Available passkey params: \n");
-    help_cmd_uint16("conn");
-    help_cmd_uint16("action");
-    help_cmd_long_bounds("key", 0, 999999);
-    help_cmd_byte_stream_exact_length("oob", 16);
-    help_cmd_extract("yesno");
-}
-
-static int
-cmd_passkey(int argc, char **argv)
-{
-#if !NIMBLE_BLE_SM
-    return BLE_HS_ENOTSUP;
-#endif
-
-    uint16_t conn_handle;
-    struct ble_sm_io pk;
-    char *yesno;
-    int rc;
-
-    if (argc > 1 && strcmp(argv[1], "help") == 0) {
-        bletiny_passkey_help();
-        return 0;
-    }
-
-    conn_handle = parse_arg_uint16("conn", &rc);
-    if (rc != 0) {
-        console_printf("invalid 'conn' parameter\n");
-        help_cmd_uint16("conn");
-        return rc;
-    }
-
-    pk.action = parse_arg_uint16("action", &rc);
-    if (rc != 0) {
-        console_printf("invalid 'action' parameter\n");
-        help_cmd_uint16("action");
-        return rc;
-    }
-
-    switch (pk.action) {
-        case BLE_SM_IOACT_INPUT:
-        case BLE_SM_IOACT_DISP:
-           /* passkey is 6 digit number */
-           pk.passkey = parse_arg_long_bounds("key", 0, 999999, &rc);
-           if (rc != 0) {
-               console_printf("invalid 'key' parameter\n");
-               help_cmd_long_bounds("key", 0, 999999);
-               return rc;
-           }
-           break;
-
-        case BLE_SM_IOACT_OOB:
-            rc = parse_arg_byte_stream_exact_length("oob", pk.oob, 16);
-            if (rc != 0) {
-                console_printf("invalid 'oob' parameter\n");
-                help_cmd_byte_stream_exact_length("oob", 16);
-                return rc;
-            }
-            break;
-
-        case BLE_SM_IOACT_NUMCMP:
-            yesno = parse_arg_extract("yesno");
-            if (yesno == NULL) {
-                console_printf("invalid 'yesno' parameter\n");
-                help_cmd_extract("yesno");
-                return EINVAL;
-            }
-
-            switch (yesno[0]) {
-            case 'y':
-            case 'Y':
-                pk.numcmp_accept = 1;
-                break;
-            case 'n':
-            case 'N':
-                pk.numcmp_accept = 0;
-                break;
-
-            default:
-                console_printf("invalid 'yesno' parameter\n");
-                help_cmd_extract("yesno");
-                return EINVAL;
-            }
-            break;
-
-       default:
-         console_printf("invalid passkey action action=%d\n", pk.action);
-         return EINVAL;
-    }
-
-    rc = ble_sm_inject_io(conn_handle, &pk);
-    if (rc != 0) {
-        console_printf("error providing passkey; rc=%d\n", rc);
-        return rc;
-    }
-
-    return 0;
-}
-
-/*****************************************************************************
- * $tx                                                                     *
- *                                                                         *
- * Command to transmit 'num' packets of size 'len' at rate 'r' to
- * handle 'h' Note that length must be <= 251. The rate is in msecs.
- *
- *****************************************************************************/
-
-static void
-bletiny_tx_help(void)
-{
-#if !MYNEWT_VAL(BLETINY_HELP)
-    bletiny_help_disabled();
-    return;
-#endif
-
-    console_printf("Available tx commands: \n");
-    console_printf("\thelp\n");
-    console_printf("Available tx params: \n");
-    help_cmd_uint16("r");
-    help_cmd_uint16("l");
-    help_cmd_uint16("n");
-    help_cmd_uint16("h");
-}
-
-static int
-cmd_tx(int argc, char **argv)
-{
-    int rc;
-    uint16_t rate;
-    uint16_t len;
-    uint16_t handle;
-    uint16_t num;
-
-    if (argc > 1 && strcmp(argv[1], "help") == 0) {
-        bletiny_tx_help();
-        return 0;
-    }
-
-    rate = parse_arg_uint16("r", &rc);
-    if (rc != 0) {
-        console_printf("invalid 'r' parameter\n");
-        help_cmd_uint16("r");
-        return rc;
-    }
-
-    len = parse_arg_uint16("l", &rc);
-    if (rc != 0) {
-        console_printf("invalid 'l' parameter\n");
-        help_cmd_uint16("l");
-        return rc;
-    }
-    if ((len > 251) || (len < 4)) {
-        console_printf("error: len must be between 4 and 251, inclusive");
-    }
-
-    num = parse_arg_uint16("n", &rc);
-    if (rc != 0) {
-        console_printf("invalid 'n' parameter\n");
-        help_cmd_uint16("n");
-        return rc;
-    }
-
-    handle = parse_arg_uint16("h", &rc);
-    if (rc != 0) {
-        console_printf("invalid 'h' parameter\n");
-        help_cmd_uint16("h");
-        return rc;
-    }
-
-    rc = bletiny_tx_start(handle, len, rate, num);
-    return rc;
-}
-
-static struct cmd_entry cmd_b_entries[];
-
-static int
-cmd_help(int argc, char **argv)
-{
-#if !MYNEWT_VAL(BLETINY_HELP)
-    bletiny_help_disabled();
-    return 0;
-#endif
-
-    int i;
-
-    console_printf("Available commands:\n");
-    for (i = 0; cmd_b_entries[i].name != NULL; i++) {
-        console_printf("\t%s\n", cmd_b_entries[i].name);
-    }
-    return 0;
-}
-
-/*****************************************************************************
- * $svcch                                                                    *
- *****************************************************************************/
-
-static void
-bletiny_svcchg_help(void)
-{
-#if !MYNEWT_VAL(BLETINY_HELP)
-    bletiny_help_disabled();
-    return;
-#endif
-
-    console_printf("Available svcchg params: \n");
-    help_cmd_uint16("start");
-    help_cmd_uint16("end");
-}
-
-static int
-cmd_svcchg(int argc, char **argv)
-{
-    uint16_t start;
-    uint16_t end;
-    int rc;
-
-    if (argc > 1 && strcmp(argv[1], "help") == 0) {
-        bletiny_svcchg_help();
-        return 0;
-    }
-
-    start = parse_arg_uint16("start", &rc);
-    if (rc != 0) {
-        console_printf("invalid 'start' parameter\n");
-        help_cmd_uint16("start");
-        return rc;
-    }
-
-    end = parse_arg_uint16("end", &rc);
-    if (rc != 0) {
-        console_printf("invalid 'end' parameter\n");
-        help_cmd_uint16("end");
-        return rc;
-    }
-
-    ble_svc_gatt_changed(start, end);
-
-    return 0;
-}
-
-/*****************************************************************************
- * $svcvis                                                                   *
- *****************************************************************************/
-
-static void
-bletiny_svcvis_help(void)
-{
-#if !MYNEWT_VAL(BLETINY_HELP)
-    bletiny_help_disabled();
-    return;
-#endif
-
-    console_printf("Available svcvis params: \n");
-    help_cmd_uint16("handle");
-    help_cmd_bool("vis");
-}
-
-static int
-cmd_svcvis(int argc, char **argv)
-{
-    uint16_t handle;
-    bool vis;
-    int rc;
-
-    if (argc > 1 && strcmp(argv[1], "help") == 0) {
-        bletiny_svcvis_help();
-        return 0;
-    }
-
-    handle = parse_arg_uint16("handle", &rc);
-    if (rc != 0) {
-        console_printf("invalid 'handle' parameter\n");
-        help_cmd_uint16("handle");
-        return rc;
-    }
-
-    vis = parse_arg_bool("vis", &rc);
-    if (rc != 0) {
-        console_printf("invalid 'vis' parameter\n");
-        help_cmd_bool("vis");
-        return rc;
-    }
-
-    ble_gatts_svc_set_visibility(handle, vis);
-
-    return 0;
-}
-
-static const struct cmd_entry cmd_phy_entries[];
-
-static int
-cmd_phy_help(int argc, char **argv)
-{
-    int i;
-
-    console_printf("Available PHY commands:\n");
-    for (i = 0; cmd_phy_entries[i].name != NULL; i++) {
-        console_printf("\t%s\n", cmd_phy_entries[i].name);
-    }
-    return 0;
-}
-
-static void
-bletiny_phy_set_help(void)
-{
-    console_printf("Available PHY set commands: \n");
-    console_printf("\thelp\n");
-    console_printf("Available PHY set params: \n");
-    help_cmd_uint16("conn");
-    help_cmd_uint8("tx_phys_mask");
-    help_cmd_uint8("rx_phys_mask");
-    help_cmd_uint16("phy_opts");
-}
-
-static int
-cmd_phy_set(int argc, char **argv)
-{
-    uint16_t conn;
-    uint8_t tx_phys_mask;
-    uint8_t rx_phys_mask;
-    uint16_t phy_opts;
-    int rc;
-
-    if (argc > 1 && strcmp(argv[1], "help") == 0) {
-        bletiny_phy_set_help();
-        return 0;
-    }
-
-    conn = parse_arg_uint16("conn", &rc);
-    if (rc != 0) {
-        console_printf("invalid 'conn' parameter\n");
-        help_cmd_uint16("conn");
-        return rc;
-    }
-
-    tx_phys_mask = parse_arg_uint8("tx_phys_mask", &rc);
-    if (rc != 0) {
-        console_printf("invalid 'tx_phys_mask' parameter\n");
-        help_cmd_uint8("tx_phys_mask");
-        return rc;
-    }
-
-    rx_phys_mask = parse_arg_uint8("rx_phys_mask", &rc);
-    if (rc != 0) {
-        console_printf("invalid 'rx_phys_mask' parameter\n");
-        help_cmd_uint8("rx_phys_mask");
-        return rc;
-    }
-
-    phy_opts = parse_arg_uint16("phy_opts", &rc);
-    if (rc != 0) {
-        console_printf("invalid 'phy_opts' parameter\n");
-        help_cmd_uint16("phy_opts");
-        return rc;
-    }
-
-    return ble_gap_set_prefered_le_phy(conn, tx_phys_mask, rx_phys_mask,
-                                       phy_opts);
-}
-
-static void
-bletiny_phy_set_def_help(void)
-{
-    console_printf("Available PHY set_def commands: \n");
-    console_printf("\thelp\n");
-    console_printf("Available PHY set_def params: \n");
-    help_cmd_uint8("tx_phys_mask");
-    help_cmd_uint8("rx_phys_mask");
-}
-
-static int
-cmd_phy_set_def(int argc, char **argv)
-{
-    uint8_t tx_phys_mask;
-    uint8_t rx_phys_mask;
-    int rc;
-
-    if (argc > 1 && strcmp(argv[1], "help") == 0) {
-        bletiny_phy_set_def_help();
-        return 0;
-    }
-
-    tx_phys_mask = parse_arg_uint8("tx_phys_mask", &rc);
-    if (rc != 0) {
-        console_printf("invalid 'tx_phys_mask' parameter\n");
-        help_cmd_uint8("tx_phys_mask");
-        return rc;
-    }
-
-    rx_phys_mask = parse_arg_uint8("rx_phys_mask", &rc);
-    if (rc != 0) {
-        console_printf("invalid 'rx_phys_mask' parameter\n");
-        help_cmd_uint8("rx_phys_mask");
-        return rc;
-    }
-
-    return ble_gap_set_prefered_default_le_phy(tx_phys_mask, rx_phys_mask);
-}
-
-static void
-bletiny_phy_read_help(void)
-{
-    console_printf("Available PHY read commands: \n");
-    console_printf("\thelp\n");
-    console_printf("Available PHY read params: \n");
-    help_cmd_uint16("conn");
-}
-
-static int
-cmd_phy_read(int argc, char **argv)
-{
-
-    uint16_t conn = 0;
-    uint8_t tx_phy;
-    uint8_t rx_phy;
-    int rc;
-
-    if (argc > 1 && strcmp(argv[1], "help") == 0) {
-            bletiny_phy_read_help();
-        return 0;
-    }
-
-    conn = parse_arg_uint16("conn", &rc);
-    if (rc != 0) {
-        console_printf("invalid 'conn' parameter\n");
-        help_cmd_uint16("conn");
-        return rc;
-    }
-
-    rc = ble_gap_read_le_phy(conn, &tx_phy, &rx_phy);
-    if (rc != 0) {
-        console_printf("Could not read PHY error: %d\n", rc);
-        return rc;
-    }
-
-    console_printf("TX_PHY: %d\n", tx_phy);
-    console_printf("RX_PHY: %d\n", tx_phy);
-
-    return 0;
-}
-
-static const struct cmd_entry cmd_phy_entries[] = {
-    { "read", cmd_phy_read },
-    { "set_def", cmd_phy_set_def },
-    { "set", cmd_phy_set },
-    { "help", cmd_phy_help },
-    { NULL, NULL }
-};
-
-static int
-cmd_phy(int argc, char **argv)
-{
-    int rc;
-
-    rc = cmd_exec(cmd_phy_entries, argc, argv);
-    if (rc != 0) {
-        return rc;
-    }
-
-    return 0;
-}
-
-/*****************************************************************************
- * $init                                                                     *
- *****************************************************************************/
-
-static struct cmd_entry cmd_b_entries[] = {
-    { "adv",        cmd_adv },
-    { "conn",       cmd_conn },
-    { "chrup",      cmd_chrup },
-    { "datalen",    cmd_datalen },
-    { "disc",       cmd_disc },
-    { "find",       cmd_find },
-    { "help",       cmd_help },
-    { "l2cap",      cmd_l2cap },
-    { "mtu",        cmd_mtu },
-    { "passkey",    cmd_passkey },
-    { "read",       cmd_read },
-    { "rssi",       cmd_rssi },
-    { "scan",       cmd_scan },
-    { "show",       cmd_show },
-    { "sec",        cmd_sec },
-    { "set",        cmd_set },
-    { "store",      cmd_keystore },
-    { "term",       cmd_term },
-    { "update",     cmd_update },
-    { "tx",         cmd_tx },
-    { "wl",         cmd_wl },
-    { "write",      cmd_write },
-    { "svcchg",     cmd_svcchg },
-    { "phy",        cmd_phy },
-    { "svcvis",     cmd_svcvis },
-    { NULL, NULL }
-};
-
-static int
-cmd_b_exec(int argc, char **argv)
-{
-    int rc;
-
-    rc = parse_arg_all(argc - 1, argv + 1);
-    if (rc != 0) {
-        goto done;
-    }
-
-    rc = cmd_exec(cmd_b_entries, argc, argv);
-    if (rc != 0) {
-        console_printf("error; rc=%d\n", rc);
-        goto done;
-    }
-
-    rc = 0;
-
-done:
-    return rc;
-}
-
-int
-cmd_init(void)
-{
-    int rc;
-
-    rc = shell_cmd_register(&cmd_b);
-    if (rc != 0) {
-        return rc;
-    }
-
-    return 0;
-}
diff --git a/apps/bletiny/src/gatt_svr.c b/apps/bletiny/src/gatt_svr.c
deleted file mode 100644
index a9136757ed..0000000000
--- a/apps/bletiny/src/gatt_svr.c
+++ /dev/null
@@ -1,588 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-#include <assert.h>
-#include <string.h>
-#include "bsp/bsp.h"
-#include "console/console.h"
-#include "host/ble_hs.h"
-#include "host/ble_uuid.h"
-#include "bletiny.h"
-
-/* 0000xxxx-8c26-476f-89a7-a108033a69c7 */
-#define PTS_UUID_DECLARE(uuid16)                                \
-    ((const ble_uuid_t *) (&(ble_uuid128_t) BLE_UUID128_INIT(   \
-        0xc7, 0x69, 0x3a, 0x03, 0x08, 0xa1, 0xa7, 0x89,         \
-        0x6f, 0x47, 0x26, 0x8c, uuid16, uuid16 >> 8, 0x00, 0x00 \
-    )))
-
-#define  PTS_SVC                         0x0001
-#define  PTS_CHR_READ                    0x0002
-#define  PTS_CHR_WRITE                   0x0003
-#define  PTS_CHR_RELIABLE_WRITE          0x0004
-#define  PTS_CHR_WRITE_NO_RSP            0x0005
-#define  PTS_CHR_READ_WRITE              0x0006
-#define  PTS_CHR_READ_WRITE_ENC          0x0007
-#define  PTS_CHR_READ_WRITE_AUTHEN       0x0008
-#define  PTS_DSC_READ                    0x0009
-#define  PTS_DSC_WRITE                   0x000a
-#define  PTS_DSC_READ_WRITE              0x000b
-#define  PTS_DSC_READ_WRITE_ENC          0x000c
-#define  PTS_DSC_READ_WRITE_AUTHEN       0x000d
-
-#define  PTS_LONG_SVC                    0x0011
-#define  PTS_LONG_CHR_READ               0x0012
-#define  PTS_LONG_CHR_WRITE              0x0013
-#define  PTS_LONG_CHR_RELIABLE_WRITE     0x0014
-#define  PTS_LONG_CHR_READ_WRITE         0x0015
-#define  PTS_LONG_CHR_READ_WRITE_ALT     0x0016
-#define  PTS_LONG_CHR_READ_WRITE_ENC     0x0017
-#define  PTS_LONG_CHR_READ_WRITE_AUTHEN  0x0018
-#define  PTS_LONG_DSC_READ               0x0019
-#define  PTS_LONG_DSC_WRITE              0x001a
-#define  PTS_LONG_DSC_READ_WRITE         0x001b
-#define  PTS_LONG_DSC_READ_WRITE_ENC     0x001c
-#define  PTS_LONG_DSC_READ_WRITE_AUTHEN  0x001d
-
-/**
- * The vendor specific security test service consists of two characteristics:
- *     o random-number-generator: generates a random 32-bit number each time
- *       it is read.  This characteristic can only be read over an encrypted
- *       connection.
- *     o static-value: a single-byte characteristic that can always be read,
- *       but can only be written over an encrypted connection.
- */
-
-/* 59462f12-9543-9999-12c8-58b459a2712d */
-static const ble_uuid128_t gatt_svr_svc_sec_test_uuid =
-    BLE_UUID128_INIT(0x2d, 0x71, 0xa2, 0x59, 0xb4, 0x58, 0xc8, 0x12,
-                     0x99, 0x99, 0x43, 0x95, 0x12, 0x2f, 0x46, 0x59);
-
-/* 5c3a659e-897e-45e1-b016-007107c96df6 */
-static const ble_uuid128_t gatt_svr_chr_sec_test_rand_uuid =
-    BLE_UUID128_INIT(0xf6, 0x6d, 0xc9, 0x07, 0x71, 0x00, 0x16, 0xb0,
-                     0xe1, 0x45, 0x7e, 0x89, 0x9e, 0x65, 0x3a, 0x5c);
-
-/* 5c3a659e-897e-45e1-b016-007107c96df7 */
-static const ble_uuid128_t gatt_svr_chr_sec_test_static_uuid =
-    BLE_UUID128_INIT(0xf7, 0x6d, 0xc9, 0x07, 0x71, 0x00, 0x16, 0xb0,
-                     0xe1, 0x45, 0x7e, 0x89, 0x9e, 0x65, 0x3a, 0x5c);
-
-/* 5c3a659e-897e-45e1-b016-007107c96df8 */
-static const ble_uuid128_t gatt_svr_chr_sec_test_static_auth_uuid =
-    BLE_UUID128_INIT(0xf8, 0x6d, 0xc9, 0x07, 0x71, 0x00, 0x16, 0xb0,
-                     0xe1, 0x45, 0x7e, 0x89, 0x9e, 0x65, 0x3a, 0x5c);
-
-static uint8_t gatt_svr_sec_test_static_val;
-
-static uint8_t gatt_svr_pts_static_val;
-static uint8_t gatt_svr_pts_static_long_val[30];
-static uint8_t gatt_svr_pts_static_long_val_alt[30];
-
-static int
-gatt_svr_chr_access_sec_test(uint16_t conn_handle, uint16_t attr_handle,
-                             struct ble_gatt_access_ctxt *ctxt,
-                             void *arg);
-
-static int
-gatt_svr_access_test(uint16_t conn_handle, uint16_t attr_handle,
-                     struct ble_gatt_access_ctxt *ctxt,
-                     void *arg);
-
-static int
-gatt_svr_long_access_test(uint16_t conn_handle, uint16_t attr_handle,
-                                  struct ble_gatt_access_ctxt *ctxt,
-                                  void *arg);
-
-static const struct ble_gatt_svc_def gatt_svr_svcs[] = {
-    {
-        /*** Service: PTS test. */
-        .type = BLE_GATT_SVC_TYPE_PRIMARY,
-        .uuid = PTS_UUID_DECLARE(PTS_SVC),
-        .characteristics = (struct ble_gatt_chr_def[]) { {
-                .uuid = PTS_UUID_DECLARE(PTS_CHR_READ),
-                .access_cb = gatt_svr_access_test,
-                .flags = BLE_GATT_CHR_F_READ,
-            }, {
-                .uuid = PTS_UUID_DECLARE(PTS_CHR_WRITE),
-                .access_cb = gatt_svr_access_test,
-                .flags = BLE_GATT_CHR_F_WRITE,
-            }, {
-                .uuid = PTS_UUID_DECLARE(PTS_CHR_RELIABLE_WRITE),
-                .access_cb = gatt_svr_access_test,
-                .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_RELIABLE_WRITE,
-            }, {
-                .uuid = PTS_UUID_DECLARE(PTS_CHR_WRITE_NO_RSP),
-                .access_cb = gatt_svr_access_test,
-                .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_WRITE_NO_RSP,
-            }, {
-                .uuid = PTS_UUID_DECLARE(PTS_CHR_READ_WRITE),
-                .access_cb = gatt_svr_access_test,
-                .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_WRITE,
-            }, {
-                .uuid = PTS_UUID_DECLARE(PTS_CHR_READ_WRITE_ENC),
-                .access_cb = gatt_svr_access_test,
-                .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_READ_ENC |
-                BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_WRITE_ENC,
-                .min_key_size = 16,
-            }, {
-                .uuid = PTS_UUID_DECLARE(PTS_CHR_READ_WRITE_AUTHEN),
-                .access_cb = gatt_svr_access_test,
-                .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_READ_AUTHEN |
-                BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_WRITE_AUTHEN,
-
-                .descriptors = (struct ble_gatt_dsc_def[]){ {
-                        .uuid = PTS_UUID_DECLARE(PTS_DSC_READ),
-                        .access_cb = gatt_svr_access_test,
-                        .att_flags = BLE_ATT_F_READ,
-                    }, {
-                        .uuid = PTS_UUID_DECLARE(PTS_DSC_WRITE),
-                        .access_cb = gatt_svr_access_test,
-                        .att_flags = BLE_ATT_F_WRITE,
-                    }, {
-                        .uuid = PTS_UUID_DECLARE(PTS_DSC_READ_WRITE),
-                        .access_cb = gatt_svr_access_test,
-                        .att_flags = BLE_ATT_F_READ | BLE_ATT_F_WRITE,
-                    }, {
-                        .uuid = PTS_UUID_DECLARE(PTS_DSC_READ_WRITE_ENC),
-                        .access_cb = gatt_svr_access_test,
-                        .att_flags = BLE_ATT_F_READ | BLE_ATT_F_READ_ENC |
-                        BLE_ATT_F_WRITE | BLE_ATT_F_WRITE_ENC,
-                        .min_key_size = 16,
-                    }, {
-                        .uuid = PTS_UUID_DECLARE(PTS_DSC_READ_WRITE_AUTHEN),
-                        .access_cb = gatt_svr_access_test,
-                        .att_flags = BLE_ATT_F_READ | BLE_ATT_F_READ_AUTHEN |
-                        BLE_ATT_F_WRITE | BLE_ATT_F_WRITE_AUTHEN,
-                    }, {
-                        0, /* No more descriptors in this characteristic. */
-                    } }
-            }, {
-                0, /* No more characteristics in this service. */
-            } },
-    },
-
-    {
-        /*** Service: PTS long test. */
-        .type = BLE_GATT_SVC_TYPE_PRIMARY,
-        .uuid = PTS_UUID_DECLARE(PTS_LONG_SVC),
-        .characteristics = (struct ble_gatt_chr_def[]) { {
-                .uuid = PTS_UUID_DECLARE(PTS_LONG_CHR_READ),
-                .access_cb = gatt_svr_long_access_test,
-                .flags = BLE_GATT_CHR_F_READ,
-            }, {
-                .uuid = PTS_UUID_DECLARE(PTS_LONG_CHR_WRITE),
-                .access_cb = gatt_svr_long_access_test,
-                .flags = BLE_GATT_CHR_F_WRITE,
-            }, {
-                .uuid = PTS_UUID_DECLARE(PTS_LONG_CHR_RELIABLE_WRITE),
-                .access_cb = gatt_svr_long_access_test,
-                .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_RELIABLE_WRITE,
-            }, {
-                .uuid = PTS_UUID_DECLARE(PTS_LONG_CHR_READ_WRITE),
-                .access_cb = gatt_svr_long_access_test,
-                .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_WRITE,
-            }, {
-                .uuid = PTS_UUID_DECLARE(PTS_LONG_CHR_READ_WRITE_ALT),
-                .access_cb = gatt_svr_long_access_test,
-                .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_WRITE,
-            }, {
-                .uuid = PTS_UUID_DECLARE(PTS_LONG_CHR_READ_WRITE_ENC),
-                .access_cb = gatt_svr_long_access_test,
-                .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_READ_ENC |
-                BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_WRITE_ENC,
-                .min_key_size = 16,
-            }, {
-                .uuid = PTS_UUID_DECLARE(PTS_LONG_CHR_READ_WRITE_AUTHEN),
-                .access_cb = gatt_svr_long_access_test,
-                .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_READ_AUTHEN |
-                BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_WRITE_AUTHEN,
-
-                .descriptors = (struct ble_gatt_dsc_def[]){ {
-                        .uuid = PTS_UUID_DECLARE(PTS_LONG_DSC_READ),
-                        .access_cb = gatt_svr_long_access_test,
-                        .att_flags = BLE_ATT_F_READ,
-                    }, {
-                        .uuid = PTS_UUID_DECLARE(PTS_LONG_DSC_WRITE),
-                        .access_cb = gatt_svr_long_access_test,
-                        .att_flags = BLE_ATT_F_WRITE,
-                    }, {
-                        .uuid = PTS_UUID_DECLARE(PTS_LONG_DSC_READ_WRITE),
-                        .access_cb = gatt_svr_long_access_test,
-                        .att_flags = BLE_ATT_F_READ | BLE_ATT_F_WRITE,
-                    }, {
-                        .uuid = PTS_UUID_DECLARE(PTS_LONG_DSC_READ_WRITE_ENC),
-                        .access_cb = gatt_svr_long_access_test,
-                        .att_flags = BLE_ATT_F_READ | BLE_ATT_F_READ_ENC |
-                        BLE_ATT_F_WRITE | BLE_ATT_F_WRITE_ENC,
-                        .min_key_size = 16,
-                    }, {
-                        .uuid = PTS_UUID_DECLARE(PTS_LONG_DSC_READ_WRITE_AUTHEN),
-                        .access_cb = gatt_svr_long_access_test,
-                        .att_flags = BLE_ATT_F_READ | BLE_ATT_F_READ_AUTHEN |
-                        BLE_ATT_F_WRITE | BLE_ATT_F_WRITE_AUTHEN,
-                    }, {
-                        0, /* No more descriptors in this characteristic. */
-                    } }
-            }, {
-                0, /* No more characteristics in this service. */
-            } },
-    },
-
-    {
-        /*** Service: Security test. */
-        .type = BLE_GATT_SVC_TYPE_PRIMARY,
-        .uuid = &gatt_svr_svc_sec_test_uuid.u,
-        .characteristics = (struct ble_gatt_chr_def[]) { {
-            /*** Characteristic: Random number generator. */
-            .uuid = &gatt_svr_chr_sec_test_rand_uuid.u,
-            .access_cb = gatt_svr_chr_access_sec_test,
-            .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_READ_ENC,
-        }, {
-            /*** Characteristic: Static value. */
-            .uuid = &gatt_svr_chr_sec_test_static_uuid.u,
-            .access_cb = gatt_svr_chr_access_sec_test,
-            .flags = BLE_GATT_CHR_F_READ |
-                     BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_WRITE_ENC,
-        }, {
-            /*** Characteristic: Static value. */
-            .uuid = &gatt_svr_chr_sec_test_static_auth_uuid.u,
-            .access_cb = gatt_svr_chr_access_sec_test,
-            .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_READ_AUTHEN,
-        }, {
-            0, /* No more characteristics in this service. */
-        } },
-    },
-
-    {
-        0, /* No more services. */
-    },
-};
-
-static int
-gatt_svr_chr_write(struct os_mbuf *om, uint16_t min_len, uint16_t max_len,
-                   void *dst, uint16_t *len)
-{
-    uint16_t om_len;
-    int rc;
-
-    om_len = OS_MBUF_PKTLEN(om);
-    if (om_len < min_len || om_len > max_len) {
-        return BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN;
-    }
-
-    rc = ble_hs_mbuf_to_flat(om, dst, max_len, len);
-    if (rc != 0) {
-        return BLE_ATT_ERR_UNLIKELY;
-    }
-
-    return 0;
-}
-
-static int
-gatt_svr_chr_access_sec_test(uint16_t conn_handle, uint16_t attr_handle,
-                             struct ble_gatt_access_ctxt *ctxt,
-                             void *arg)
-{
-    const ble_uuid_t *uuid;
-    int rand_num;
-    int rc;
-
-    uuid = ctxt->chr->uuid;
-
-    /* Determine which characteristic is being accessed by examining its
-     * 128-bit UUID.
-     */
-
-    if (ble_uuid_cmp(uuid, &gatt_svr_chr_sec_test_rand_uuid.u) == 0) {
-        assert(ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR);
-
-        /* Respond with a 32-bit random number. */
-        rand_num = rand();
-        rc = os_mbuf_append(ctxt->om, &rand_num, sizeof rand_num);
-        return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
-    }
-
-    if (ble_uuid_cmp(uuid, &gatt_svr_chr_sec_test_static_uuid.u) == 0 ||
-        ble_uuid_cmp(uuid, &gatt_svr_chr_sec_test_static_auth_uuid.u) == 0) {
-        switch (ctxt->op) {
-        case BLE_GATT_ACCESS_OP_READ_CHR:
-            rc = os_mbuf_append(ctxt->om, &gatt_svr_sec_test_static_val,
-                                sizeof gatt_svr_sec_test_static_val);
-            return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
-
-        case BLE_GATT_ACCESS_OP_WRITE_CHR:
-            rc = gatt_svr_chr_write(ctxt->om,
-                                    sizeof gatt_svr_sec_test_static_val,
-                                    sizeof gatt_svr_sec_test_static_val,
-                                    &gatt_svr_sec_test_static_val, NULL);
-            return rc;
-
-        default:
-            assert(0);
-            return BLE_ATT_ERR_UNLIKELY;
-        }
-    }
-
-    /* Unknown characteristic; the nimble stack should not have called this
-     * function.
-     */
-    assert(0);
-    return BLE_ATT_ERR_UNLIKELY;
-}
-
-/* This method is used for PTS testing only, to extract 16 bit value
- * from 128 bit vendor specific UUID.
- */
-static uint16_t
-extract_uuid16_from_pts_uuid128(const ble_uuid_t *uuid)
-{
-    const uint8_t *u8ptr;
-    uint16_t uuid16;
-
-    u8ptr = BLE_UUID128(uuid)->value;
-    uuid16 = u8ptr[12];
-    uuid16 |= (uint16_t)u8ptr[13] << 8;
-    return uuid16;
-}
-
-static int
-gatt_svr_access_test(uint16_t conn_handle, uint16_t attr_handle,
-                     struct ble_gatt_access_ctxt *ctxt,
-                     void *arg)
-{
-    uint16_t uuid16;
-    int rc;
-
-    uuid16 = extract_uuid16_from_pts_uuid128(ctxt->chr->uuid);
-    assert(uuid16 != 0);
-
-    switch (uuid16) {
-    case PTS_CHR_READ:
-        assert(ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR);
-        rc = os_mbuf_append(ctxt->om, &gatt_svr_pts_static_val,
-                            sizeof gatt_svr_pts_static_val);
-        return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
-
-    case PTS_CHR_WRITE:
-    case PTS_CHR_RELIABLE_WRITE:
-    case PTS_CHR_WRITE_NO_RSP:
-        if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
-            rc = gatt_svr_chr_write(ctxt->om,0,
-                                    sizeof gatt_svr_pts_static_val,
-                                    &gatt_svr_pts_static_val, NULL);
-            return rc;
-        } else if (ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR) {
-            rc = os_mbuf_append(ctxt->om, &gatt_svr_pts_static_val,
-                                sizeof gatt_svr_pts_static_val);
-            return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
-        }
-
-    case PTS_CHR_READ_WRITE:
-    case PTS_CHR_READ_WRITE_ENC:
-    case PTS_CHR_READ_WRITE_AUTHEN:
-        if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
-            rc = gatt_svr_chr_write(ctxt->om,0,
-                                    sizeof gatt_svr_pts_static_val,
-                                    &gatt_svr_pts_static_val, NULL);
-            return rc;
-        } else if (ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR) {
-            rc = os_mbuf_append(ctxt->om, &gatt_svr_pts_static_val,
-                                sizeof gatt_svr_pts_static_val);
-            return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
-        }
-
-    case PTS_DSC_READ:
-        assert(ctxt->op == BLE_GATT_ACCESS_OP_READ_DSC);
-        rc = os_mbuf_append(ctxt->om, &gatt_svr_pts_static_val,
-                            sizeof gatt_svr_pts_static_val);
-        return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
-
-    case PTS_DSC_WRITE:
-        assert(ctxt->op == BLE_GATT_ACCESS_OP_WRITE_DSC);
-        rc = gatt_svr_chr_write(ctxt->om,0,
-                                sizeof gatt_svr_pts_static_val,
-                                &gatt_svr_pts_static_val, NULL);
-        return rc;
-
-    case PTS_DSC_READ_WRITE:
-    case PTS_DSC_READ_WRITE_ENC:
-    case PTS_DSC_READ_WRITE_AUTHEN:
-        if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_DSC) {
-            rc = gatt_svr_chr_write(ctxt->om,0,
-                                    sizeof gatt_svr_pts_static_val,
-                                    &gatt_svr_pts_static_val, NULL);
-            return rc;
-        } else if (ctxt->op == BLE_GATT_ACCESS_OP_READ_DSC) {
-            rc = os_mbuf_append(ctxt->om, &gatt_svr_pts_static_val,
-                                sizeof gatt_svr_pts_static_val);
-            return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
-        }
-
-    default:
-        assert(0);
-        return BLE_ATT_ERR_UNLIKELY;
-    }
-}
-
-static int
-gatt_svr_long_access_test(uint16_t conn_handle, uint16_t attr_handle,
-                          struct ble_gatt_access_ctxt *ctxt,
-                          void *arg)
-{
-    uint16_t uuid16;
-    int rc;
-
-    uuid16 = extract_uuid16_from_pts_uuid128(ctxt->chr->uuid);
-    assert(uuid16 != 0);
-
-    switch (uuid16) {
-    case PTS_LONG_CHR_READ:
-        assert(ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR);
-        rc = os_mbuf_append(ctxt->om, &gatt_svr_pts_static_long_val,
-                            sizeof gatt_svr_pts_static_long_val);
-        return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
-
-    case PTS_LONG_CHR_WRITE:
-    case PTS_LONG_CHR_RELIABLE_WRITE:
-        assert(ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR);
-        rc = gatt_svr_chr_write(ctxt->om,0,
-                                sizeof gatt_svr_pts_static_long_val,
-                                &gatt_svr_pts_static_long_val, NULL);
-        return rc;
-
-    case PTS_LONG_CHR_READ_WRITE:
-        if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
-            rc = gatt_svr_chr_write(ctxt->om,0,
-                                    sizeof gatt_svr_pts_static_long_val,
-                                    &gatt_svr_pts_static_long_val, NULL);
-            return rc;
-        } else if (ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR) {
-            rc = os_mbuf_append(ctxt->om, &gatt_svr_pts_static_long_val,
-                                sizeof gatt_svr_pts_static_long_val);
-            return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
-        }
-
-    case PTS_LONG_CHR_READ_WRITE_ALT:
-        if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
-            rc = gatt_svr_chr_write(ctxt->om,0,
-                                    sizeof gatt_svr_pts_static_long_val_alt,
-                                    &gatt_svr_pts_static_long_val_alt, NULL);
-            return rc;
-        } else if (ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR) {
-            rc = os_mbuf_append(ctxt->om, &gatt_svr_pts_static_long_val_alt,
-                                sizeof gatt_svr_pts_static_long_val_alt);
-            return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
-        }
-
-    case PTS_LONG_CHR_READ_WRITE_ENC:
-    case PTS_LONG_CHR_READ_WRITE_AUTHEN:
-        if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
-            rc = gatt_svr_chr_write(ctxt->om,0,
-                                    sizeof gatt_svr_pts_static_long_val,
-                                    &gatt_svr_pts_static_long_val, NULL);
-            return rc;
-        } else if (ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR) {
-            rc = os_mbuf_append(ctxt->om, &gatt_svr_pts_static_long_val,
-                                sizeof gatt_svr_pts_static_long_val);
-            return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
-        }
-
-    case PTS_LONG_DSC_READ:
-        assert(ctxt->op == BLE_GATT_ACCESS_OP_READ_DSC);
-        rc = os_mbuf_append(ctxt->om, &gatt_svr_pts_static_long_val,
-                            sizeof gatt_svr_pts_static_long_val);
-        return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
-
-    case PTS_LONG_DSC_WRITE:
-        assert(ctxt->op == BLE_GATT_ACCESS_OP_WRITE_DSC);
-        rc = gatt_svr_chr_write(ctxt->om,0,
-                                sizeof gatt_svr_pts_static_long_val,
-                                &gatt_svr_pts_static_long_val, NULL);
-        return rc;
-
-    case PTS_LONG_DSC_READ_WRITE:
-    case PTS_LONG_DSC_READ_WRITE_ENC:
-    case PTS_LONG_DSC_READ_WRITE_AUTHEN:
-        if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_DSC) {
-            rc = gatt_svr_chr_write(ctxt->om,0,
-                                    sizeof gatt_svr_pts_static_long_val,
-                                    &gatt_svr_pts_static_long_val, NULL);
-            return rc;
-        } else if (ctxt->op == BLE_GATT_ACCESS_OP_READ_DSC) {
-            rc = os_mbuf_append(ctxt->om, &gatt_svr_pts_static_long_val,
-                                sizeof gatt_svr_pts_static_long_val);
-            return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
-        }
-
-    default:
-        assert(0);
-        return BLE_ATT_ERR_UNLIKELY;
-    }
-}
-
-void
-gatt_svr_register_cb(struct ble_gatt_register_ctxt *ctxt, void *arg)
-{
-    char buf[BLE_UUID_STR_LEN];
-
-    switch (ctxt->op) {
-    case BLE_GATT_REGISTER_OP_SVC:
-        BLETINY_LOG(DEBUG, "registered service %s with handle=%d\n",
-                    ble_uuid_to_str(ctxt->svc.svc_def->uuid, buf),
-                    ctxt->svc.handle);
-        break;
-
-    case BLE_GATT_REGISTER_OP_CHR:
-        BLETINY_LOG(DEBUG, "registering characteristic %s with "
-                           "def_handle=%d val_handle=%d\n",
-                    ble_uuid_to_str(ctxt->chr.chr_def->uuid, buf),
-                    ctxt->chr.def_handle,
-                    ctxt->chr.val_handle);
-        break;
-
-    case BLE_GATT_REGISTER_OP_DSC:
-        BLETINY_LOG(DEBUG, "registering descriptor %s with handle=%d\n",
-                    ble_uuid_to_str(ctxt->dsc.dsc_def->uuid, buf),
-                    ctxt->dsc.handle);
-        break;
-
-    default:
-        assert(0);
-        break;
-    }
-}
-
-int
-gatt_svr_init(void)
-{
-    int rc;
-
-    rc = ble_gatts_count_cfg(gatt_svr_svcs);
-    if (rc != 0) {
-        return rc;
-    }
-
-    rc = ble_gatts_add_svcs(gatt_svr_svcs);
-    if (rc != 0) {
-        return rc;
-    }
-
-    return 0;
-}
diff --git a/apps/bletiny/src/main.c b/apps/bletiny/src/main.c
deleted file mode 100644
index 03c115a227..0000000000
--- a/apps/bletiny/src/main.c
+++ /dev/null
@@ -1,2094 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-#include <assert.h>
-#include <string.h>
-#include <stdio.h>
-#include <errno.h>
-#include "os/mynewt.h"
-#include "bsp/bsp.h"
-#include "log/log.h"
-#include "stats/stats.h"
-#include "hal/hal_gpio.h"
-#include "console/console.h"
-#include "shell/shell.h"
-#include "bletiny.h"
-
-/* BLE */
-#include "nimble/ble.h"
-#include "nimble/nimble_opt.h"
-#include "nimble/ble_hci_trans.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 "host/ble_store.h"
-#include "host/ble_sm.h"
-
-/* Mandatory services. */
-#include "services/gap/ble_svc_gap.h"
-#include "services/gatt/ble_svc_gatt.h"
-
-/* XXX: An app should not include private headers from a library.  The bletiny
- * app uses some of nimble's internal details for logging.
- */
-#include "../src/ble_hs_conn_priv.h"
-#include "../src/ble_hs_atomic_priv.h"
-#include "../src/ble_hs_hci_priv.h"
-
-#if MYNEWT_VAL(BLE_ROLE_CENTRAL)
-#define BLETINY_MAX_SVCS               32
-#define BLETINY_MAX_CHRS               64
-#define BLETINY_MAX_DSCS               64
-#else
-#define BLETINY_MAX_SVCS               1
-#define BLETINY_MAX_CHRS               1
-#define BLETINY_MAX_DSCS               1
-#endif
-
-#if MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM)
-#define BLETINY_COC_MTU               (256)
-/* We use same pool for incoming and outgoing sdu */
-#define BLETINY_COC_BUF_COUNT         (3 * MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM))
-#endif
-
-struct log bletiny_log;
-
-bssnz_t struct bletiny_conn bletiny_conns[MYNEWT_VAL(BLE_MAX_CONNECTIONS)];
-int bletiny_num_conns;
-
-static void *bletiny_svc_mem;
-static struct os_mempool bletiny_svc_pool;
-
-static void *bletiny_chr_mem;
-static struct os_mempool bletiny_chr_pool;
-
-static void *bletiny_dsc_mem;
-static struct os_mempool bletiny_dsc_pool;
-
-#if MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM)
-static void *bletiny_coc_conn_mem;
-static struct os_mempool bletiny_coc_conn_pool;
-
-static void *bletiny_sdu_coc_mem;
-struct os_mbuf_pool sdu_os_mbuf_pool;
-static struct os_mempool sdu_coc_mbuf_mempool;
-#endif
-
-static struct os_callout bletiny_tx_timer;
-struct bletiny_tx_data_s
-{
-    uint16_t tx_num;
-    uint16_t tx_rate;
-    uint16_t tx_handle;
-    uint16_t tx_len;
-};
-static struct bletiny_tx_data_s bletiny_tx_data;
-int bletiny_full_disc_prev_chr_val;
-
-#define XSTR(s) STR(s)
-#ifndef STR
-#define STR(s) #s
-#endif
-
-
-#ifdef DEVICE_NAME
-#define BLETINY_AUTO_DEVICE_NAME    XSTR(DEVICE_NAME)
-#else
-#define BLETINY_AUTO_DEVICE_NAME    ""
-#endif
-
-static void
-bletiny_print_error(char *msg, uint16_t conn_handle,
-                    const struct ble_gatt_error *error)
-{
-    if (msg == NULL) {
-        msg = "ERROR";
-    }
-
-    console_printf("%s: conn_handle=%d status=%d att_handle=%d\n",
-                   msg, conn_handle, error->status, error->att_handle);
-}
-
-static void
-bletiny_print_adv_fields(const struct ble_hs_adv_fields *fields)
-{
-    uint8_t *u8p;
-    int i;
-
-    if (fields->flags != 0) {
-        console_printf("    flags=0x%02x:\n", fields->flags);
-
-        if (!(fields->flags & BLE_HS_ADV_F_DISC_LTD) &&
-                !(fields->flags & BLE_HS_ADV_F_DISC_GEN)) {
-                console_printf("        Non-discoverable mode\n");
-        }
-
-        if (fields->flags & BLE_HS_ADV_F_DISC_LTD) {
-                console_printf("        Limited discoverable mode\n");
-        }
-
-        if (fields->flags & BLE_HS_ADV_F_DISC_GEN) {
-                console_printf("        General discoverable mode\n");
-        }
-
-        if (fields->flags & BLE_HS_ADV_F_BREDR_UNSUP) {
-                console_printf("        BR/EDR not supported\n");
-        }
-    }
-
-    if (fields->uuids16 != NULL) {
-        console_printf("    uuids16(%scomplete)=",
-                       fields->uuids16_is_complete ? "" : "in");
-        for (i = 0; i < fields->num_uuids16; i++) {
-            print_uuid(&fields->uuids16[i].u);
-            console_printf(" ");
-        }
-        console_printf("\n");
-    }
-
-    if (fields->uuids32 != NULL) {
-        console_printf("    uuids32(%scomplete)=",
-                       fields->uuids32_is_complete ? "" : "in");
-        for (i = 0; i < fields->num_uuids32; i++) {
-            print_uuid(&fields->uuids32[i].u);
-            console_printf(" ");
-        }
-        console_printf("\n");
-    }
-
-    if (fields->uuids128 != NULL) {
-        console_printf("    uuids128(%scomplete)=",
-                       fields->uuids128_is_complete ? "" : "in");
-        for (i = 0; i < fields->num_uuids128; i++) {
-            print_uuid(&fields->uuids128[i].u);
-            console_printf(" ");
-        }
-        console_printf("\n");
-    }
-
-    if (fields->name != NULL) {
-        console_printf("    name(%scomplete)=",
-                       fields->name_is_complete ? "" : "in");
-        console_write((char *)fields->name, fields->name_len);
-        console_printf("\n");
-    }
-
-    if (fields->tx_pwr_lvl_is_present) {
-        console_printf("    tx_pwr_lvl=%d\n", fields->tx_pwr_lvl);
-    }
-
-    if (fields->slave_itvl_range != NULL) {
-        console_printf("    slave_itvl_range=");
-        print_bytes(fields->slave_itvl_range,
-                            BLE_HS_ADV_SLAVE_ITVL_RANGE_LEN);
-        console_printf("\n");
-    }
-
-    if (fields->svc_data_uuid16 != NULL) {
-        console_printf("    svc_data_uuid16=");
-        print_bytes(fields->svc_data_uuid16,
-                            fields->svc_data_uuid16_len);
-        console_printf("\n");
-    }
-
-    if (fields->public_tgt_addr != NULL) {
-        console_printf("    public_tgt_addr=");
-        u8p = fields->public_tgt_addr;
-        for (i = 0; i < fields->num_public_tgt_addrs; i++) {
-            print_addr(u8p);
-            u8p += BLE_HS_ADV_PUBLIC_TGT_ADDR_ENTRY_LEN;
-        }
-        console_printf("\n");
-    }
-
-    if (fields->appearance_is_present) {
-        console_printf("    appearance=0x%04x\n", fields->appearance);
-    }
-
-    if (fields->adv_itvl_is_present) {
-        console_printf("    adv_itvl=0x%04x\n", fields->adv_itvl);
-    }
-
-    if (fields->svc_data_uuid32 != NULL) {
-        console_printf("    svc_data_uuid32=");
-        print_bytes(fields->svc_data_uuid32,
-                             fields->svc_data_uuid32_len);
-        console_printf("\n");
-    }
-
-    if (fields->svc_data_uuid128 != NULL) {
-        console_printf("    svc_data_uuid128=");
-        print_bytes(fields->svc_data_uuid128,
-                            fields->svc_data_uuid128_len);
-        console_printf("\n");
-    }
-
-    if (fields->uri != NULL) {
-        console_printf("    uri=");
-        print_bytes(fields->uri, fields->uri_len);
-        console_printf("\n");
-    }
-
-    if (fields->mfg_data != NULL) {
-        console_printf("    mfg_data=");
-        print_bytes(fields->mfg_data, fields->mfg_data_len);
-        console_printf("\n");
-    }
-}
-
-static int
-bletiny_conn_find_idx(uint16_t handle)
-{
-    int i;
-
-    for (i = 0; i < bletiny_num_conns; i++) {
-        if (bletiny_conns[i].handle == handle) {
-            return i;
-        }
-    }
-
-    return -1;
-}
-
-static struct bletiny_conn *
-bletiny_conn_find(uint16_t handle)
-{
-    int idx;
-
-    idx = bletiny_conn_find_idx(handle);
-    if (idx == -1) {
-        return NULL;
-    } else {
-        return bletiny_conns + idx;
-    }
-}
-
-static struct bletiny_svc *
-bletiny_svc_find_prev(struct bletiny_conn *conn, uint16_t svc_start_handle)
-{
-    struct bletiny_svc *prev;
-    struct bletiny_svc *svc;
-
-    prev = NULL;
-    SLIST_FOREACH(svc, &conn->svcs, next) {
-        if (svc->svc.start_handle >= svc_start_handle) {
-            break;
-        }
-
-        prev = svc;
-    }
-
-    return prev;
-}
-
-static struct bletiny_svc *
-bletiny_svc_find(struct bletiny_conn *conn, uint16_t svc_start_handle,
-                 struct bletiny_svc **out_prev)
-{
-    struct bletiny_svc *prev;
-    struct bletiny_svc *svc;
-
-    prev = bletiny_svc_find_prev(conn, svc_start_handle);
-    if (prev == NULL) {
-        svc = SLIST_FIRST(&conn->svcs);
-    } else {
-        svc = SLIST_NEXT(prev, next);
-    }
-
-    if (svc != NULL && svc->svc.start_handle != svc_start_handle) {
-        svc = NULL;
-    }
-
-    if (out_prev != NULL) {
-        *out_prev = prev;
-    }
-    return svc;
-}
-
-static struct bletiny_svc *
-bletiny_svc_find_range(struct bletiny_conn *conn, uint16_t attr_handle)
-{
-    struct bletiny_svc *svc;
-
-    SLIST_FOREACH(svc, &conn->svcs, next) {
-        if (svc->svc.start_handle <= attr_handle &&
-            svc->svc.end_handle >= attr_handle) {
-
-            return svc;
-        }
-    }
-
-    return NULL;
-}
-
-static void
-bletiny_chr_delete(struct bletiny_chr *chr)
-{
-    struct bletiny_dsc *dsc;
-
-    while ((dsc = SLIST_FIRST(&chr->dscs)) != NULL) {
-        SLIST_REMOVE_HEAD(&chr->dscs, next);
-        os_memblock_put(&bletiny_dsc_pool, dsc);
-    }
-
-    os_memblock_put(&bletiny_chr_pool, chr);
-}
-
-static void
-bletiny_svc_delete(struct bletiny_svc *svc)
-{
-    struct bletiny_chr *chr;
-
-    while ((chr = SLIST_FIRST(&svc->chrs)) != NULL) {
-        SLIST_REMOVE_HEAD(&svc->chrs, next);
-        bletiny_chr_delete(chr);
-    }
-
-    os_memblock_put(&bletiny_svc_pool, svc);
-}
-
-static struct bletiny_svc *
-bletiny_svc_add(uint16_t conn_handle, const struct ble_gatt_svc *gatt_svc)
-{
-    struct bletiny_conn *conn;
-    struct bletiny_svc *prev;
-    struct bletiny_svc *svc;
-
-    conn = bletiny_conn_find(conn_handle);
-    if (conn == NULL) {
-        BLETINY_LOG(DEBUG, "RECEIVED SERVICE FOR UNKNOWN CONNECTION; "
-                           "HANDLE=%d\n",
-                    conn_handle);
-        return NULL;
-    }
-
-    svc = bletiny_svc_find(conn, gatt_svc->start_handle, &prev);
-    if (svc != NULL) {
-        /* Service already discovered. */
-        return svc;
-    }
-
-    svc = os_memblock_get(&bletiny_svc_pool);
-    if (svc == NULL) {
-        BLETINY_LOG(DEBUG, "OOM WHILE DISCOVERING SERVICE\n");
-        return NULL;
-    }
-    memset(svc, 0, sizeof *svc);
-
-    svc->svc = *gatt_svc;
-    SLIST_INIT(&svc->chrs);
-
-    if (prev == NULL) {
-        SLIST_INSERT_HEAD(&conn->svcs, svc, next);
-    } else {
-        SLIST_INSERT_AFTER(prev, svc, next);
-    }
-
-    return svc;
-}
-
-static struct bletiny_chr *
-bletiny_chr_find_prev(const struct bletiny_svc *svc, uint16_t chr_val_handle)
-{
-    struct bletiny_chr *prev;
-    struct bletiny_chr *chr;
-
-    prev = NULL;
-    SLIST_FOREACH(chr, &svc->chrs, next) {
-        if (chr->chr.val_handle >= chr_val_handle) {
-            break;
-        }
-
-        prev = chr;
-    }
-
-    return prev;
-}
-
-static struct bletiny_chr *
-bletiny_chr_find(const struct bletiny_svc *svc, uint16_t chr_val_handle,
-                 struct bletiny_chr **out_prev)
-{
-    struct bletiny_chr *prev;
-    struct bletiny_chr *chr;
-
-    prev = bletiny_chr_find_prev(svc, chr_val_handle);
-    if (prev == NULL) {
-        chr = SLIST_FIRST(&svc->chrs);
-    } else {
-        chr = SLIST_NEXT(prev, next);
-    }
-
-    if (chr != NULL && chr->chr.val_handle != chr_val_handle) {
-        chr = NULL;
-    }
-
-    if (out_prev != NULL) {
-        *out_prev = prev;
-    }
-    return chr;
-}
-
-static struct bletiny_chr *
-bletiny_chr_add(uint16_t conn_handle,  uint16_t svc_start_handle,
-                const struct ble_gatt_chr *gatt_chr)
-{
-    struct bletiny_conn *conn;
-    struct bletiny_chr *prev;
-    struct bletiny_chr *chr;
-    struct bletiny_svc *svc;
-
-    conn = bletiny_conn_find(conn_handle);
-    if (conn == NULL) {
-        BLETINY_LOG(DEBUG, "RECEIVED SERVICE FOR UNKNOWN CONNECTION; "
-                           "HANDLE=%d\n",
-                    conn_handle);
-        return NULL;
-    }
-
-    svc = bletiny_svc_find(conn, svc_start_handle, NULL);
-    if (svc == NULL) {
-        BLETINY_LOG(DEBUG, "CAN'T FIND SERVICE FOR DISCOVERED CHR; HANDLE=%d\n",
-                    conn_handle);
-        return NULL;
-    }
-
-    chr = bletiny_chr_find(svc, gatt_chr->val_handle, &prev);
-    if (chr != NULL) {
-        /* Characteristic already discovered. */
-        return chr;
-    }
-
-    chr = os_memblock_get(&bletiny_chr_pool);
-    if (chr == NULL) {
-        BLETINY_LOG(DEBUG, "OOM WHILE DISCOVERING CHARACTERISTIC\n");
-        return NULL;
-    }
-    memset(chr, 0, sizeof *chr);
-
-    chr->chr = *gatt_chr;
-
-    if (prev == NULL) {
-        SLIST_INSERT_HEAD(&svc->chrs, chr, next);
-    } else {
-        SLIST_NEXT(prev, next) = chr;
-    }
-
-    return chr;
-}
-
-static struct bletiny_dsc *
-bletiny_dsc_find_prev(const struct bletiny_chr *chr, uint16_t dsc_handle)
-{
-    struct bletiny_dsc *prev;
-    struct bletiny_dsc *dsc;
-
-    prev = NULL;
-    SLIST_FOREACH(dsc, &chr->dscs, next) {
-        if (dsc->dsc.handle >= dsc_handle) {
-            break;
-        }
-
-        prev = dsc;
-    }
-
-    return prev;
-}
-
-static struct bletiny_dsc *
-bletiny_dsc_find(const struct bletiny_chr *chr, uint16_t dsc_handle,
-                 struct bletiny_dsc **out_prev)
-{
-    struct bletiny_dsc *prev;
-    struct bletiny_dsc *dsc;
-
-    prev = bletiny_dsc_find_prev(chr, dsc_handle);
-    if (prev == NULL) {
-        dsc = SLIST_FIRST(&chr->dscs);
-    } else {
-        dsc = SLIST_NEXT(prev, next);
-    }
-
-    if (dsc != NULL && dsc->dsc.handle != dsc_handle) {
-        dsc = NULL;
-    }
-
-    if (out_prev != NULL) {
-        *out_prev = prev;
-    }
-    return dsc;
-}
-
-static struct bletiny_dsc *
-bletiny_dsc_add(uint16_t conn_handle, uint16_t chr_val_handle,
-                const struct ble_gatt_dsc *gatt_dsc)
-{
-    struct bletiny_conn *conn;
-    struct bletiny_dsc *prev;
-    struct bletiny_dsc *dsc;
-    struct bletiny_svc *svc;
-    struct bletiny_chr *chr;
-
-    conn = bletiny_conn_find(conn_handle);
-    if (conn == NULL) {
-        BLETINY_LOG(DEBUG, "RECEIVED SERVICE FOR UNKNOWN CONNECTION; "
-                           "HANDLE=%d\n",
-                    conn_handle);
-        return NULL;
-    }
-
-    svc = bletiny_svc_find_range(conn, chr_val_handle);
-    if (svc == NULL) {
-        BLETINY_LOG(DEBUG, "CAN'T FIND SERVICE FOR DISCOVERED DSC; HANDLE=%d\n",
-                    conn_handle);
-        return NULL;
-    }
-
-    chr = bletiny_chr_find(svc, chr_val_handle, NULL);
-    if (chr == NULL) {
-        BLETINY_LOG(DEBUG, "CAN'T FIND CHARACTERISTIC FOR DISCOVERED DSC; "
-                           "HANDLE=%d\n",
-                    conn_handle);
-        return NULL;
-    }
-
-    dsc = bletiny_dsc_find(chr, gatt_dsc->handle, &prev);
-    if (dsc != NULL) {
-        /* Descriptor already discovered. */
-        return dsc;
-    }
-
-    dsc = os_memblock_get(&bletiny_dsc_pool);
-    if (dsc == NULL) {
-        console_printf("OOM WHILE DISCOVERING DESCRIPTOR\n");
-        return NULL;
-    }
-    memset(dsc, 0, sizeof *dsc);
-
-    dsc->dsc = *gatt_dsc;
-
-    if (prev == NULL) {
-        SLIST_INSERT_HEAD(&chr->dscs, dsc, next);
-    } else {
-        SLIST_NEXT(prev, next) = dsc;
-    }
-
-    return dsc;
-}
-
-static struct bletiny_conn *
-bletiny_conn_add(struct ble_gap_conn_desc *desc)
-{
-    struct bletiny_conn *conn;
-
-    assert(bletiny_num_conns < MYNEWT_VAL(BLE_MAX_CONNECTIONS));
-
-    conn = bletiny_conns + bletiny_num_conns;
-    bletiny_num_conns++;
-
-    conn->handle = desc->conn_handle;
-    SLIST_INIT(&conn->svcs);
-    SLIST_INIT(&conn->coc_list);
-
-    return conn;
-}
-
-static void
-bletiny_conn_delete_idx(int idx)
-{
-    struct bletiny_conn *conn;
-    struct bletiny_svc *svc;
-
-    assert(idx >= 0 && idx < bletiny_num_conns);
-
-    conn = bletiny_conns + idx;
-    while ((svc = SLIST_FIRST(&conn->svcs)) != NULL) {
-        SLIST_REMOVE_HEAD(&conn->svcs, next);
-        bletiny_svc_delete(svc);
-    }
-
-    /* This '#if' is not strictly necessary.  It is here to prevent a spurious
-     * warning from being reported.
-     */
-#if MYNEWT_VAL(BLE_MAX_CONNECTIONS) > 1
-    int i;
-    for (i = idx + 1; i < bletiny_num_conns; i++) {
-        bletiny_conns[i - 1] = bletiny_conns[i];
-    }
-#endif
-
-    bletiny_num_conns--;
-}
-
-static int
-bletiny_on_mtu(uint16_t conn_handle, const struct ble_gatt_error *error,
-               uint16_t mtu, void *arg)
-{
-    switch (error->status) {
-    case 0:
-        console_printf("mtu exchange complete: conn_handle=%d mtu=%d\n",
-                       conn_handle, mtu);
-        break;
-
-    default:
-        bletiny_print_error(NULL, conn_handle, error);
-        break;
-    }
-
-    return 0;
-}
-
-static void
-bletiny_full_disc_complete(int rc)
-{
-    console_printf("full discovery complete; rc=%d\n", rc);
-    bletiny_full_disc_prev_chr_val = 0;
-}
-
-static void
-bletiny_disc_full_dscs(uint16_t conn_handle)
-{
-    struct bletiny_conn *conn;
-    struct bletiny_chr *chr;
-    struct bletiny_svc *svc;
-    int rc;
-
-    conn = bletiny_conn_find(conn_handle);
-    if (conn == NULL) {
-        BLETINY_LOG(DEBUG, "Failed to discover descriptors for conn=%d; "
-                           "not connected\n", conn_handle);
-        bletiny_full_disc_complete(BLE_HS_ENOTCONN);
-        return;
-    }
-
-    SLIST_FOREACH(svc, &conn->svcs, next) {
-        SLIST_FOREACH(chr, &svc->chrs, next) {
-            if (!chr_is_empty(svc, chr) &&
-                SLIST_EMPTY(&chr->dscs) &&
-                bletiny_full_disc_prev_chr_val <= chr->chr.def_handle) {
-
-                rc = bletiny_disc_all_dscs(conn_handle,
-                                           chr->chr.val_handle,
-                                           chr_end_handle(svc, chr));
-                if (rc != 0) {
-                    bletiny_full_disc_complete(rc);
-                }
-
-                bletiny_full_disc_prev_chr_val = chr->chr.val_handle;
-                return;
-            }
-        }
-    }
-
-    /* All descriptors discovered. */
-    bletiny_full_disc_complete(0);
-}
-
-static void
-bletiny_disc_full_chrs(uint16_t conn_handle)
-{
-    struct bletiny_conn *conn;
-    struct bletiny_svc *svc;
-    int rc;
-
-    conn = bletiny_conn_find(conn_handle);
-    if (conn == NULL) {
-        BLETINY_LOG(DEBUG, "Failed to discover characteristics for conn=%d; "
-                           "not connected\n", conn_handle);
-        bletiny_full_disc_complete(BLE_HS_ENOTCONN);
-        return;
-    }
-
-    SLIST_FOREACH(svc, &conn->svcs, next) {
-        if (!svc_is_empty(svc) && SLIST_EMPTY(&svc->chrs)) {
-            rc = bletiny_disc_all_chrs(conn_handle, svc->svc.start_handle,
-                                       svc->svc.end_handle);
-            if (rc != 0) {
-                bletiny_full_disc_complete(rc);
-            }
-            return;
-        }
-    }
-
-    /* All characteristics discovered. */
-    bletiny_disc_full_dscs(conn_handle);
-}
-
-static int
-bletiny_on_disc_s(uint16_t conn_handle, const struct ble_gatt_error *error,
-                  const struct ble_gatt_svc *service, void *arg)
-{
-    switch (error->status) {
-    case 0:
-        bletiny_svc_add(conn_handle, service);
-        break;
-
-    case BLE_HS_EDONE:
-        console_printf("service discovery successful\n");
-        if (bletiny_full_disc_prev_chr_val > 0) {
-            bletiny_disc_full_chrs(conn_handle);
-        }
-        break;
-
-    default:
-        bletiny_print_error(NULL, conn_handle, error);
-        break;
-    }
-
-    return 0;
-}
-
-static int
-bletiny_on_disc_c(uint16_t conn_handle, const struct ble_gatt_error *error,
-                  const struct ble_gatt_chr *chr, void *arg)
-{
-    intptr_t svc_start_handle;
-
-    svc_start_handle = (intptr_t)arg;
-
-    switch (error->status) {
-    case 0:
-        bletiny_chr_add(conn_handle, svc_start_handle, chr);
-        break;
-
-    case BLE_HS_EDONE:
-        console_printf("characteristic discovery successful\n");
-        if (bletiny_full_disc_prev_chr_val > 0) {
-            bletiny_disc_full_chrs(conn_handle);
-        }
-        break;
-
-    default:
-        bletiny_print_error(NULL, conn_handle, error);
-        break;
-    }
-
-    return 0;
-}
-
-static int
-bletiny_on_disc_d(uint16_t conn_handle, const struct ble_gatt_error *error,
-                  uint16_t chr_val_handle, const struct ble_gatt_dsc *dsc,
-                  void *arg)
-{
-    switch (error->status) {
-    case 0:
-        bletiny_dsc_add(conn_handle, chr_val_handle, dsc);
-        break;
-
-    case BLE_HS_EDONE:
-        console_printf("descriptor discovery successful\n");
-        if (bletiny_full_disc_prev_chr_val > 0) {
-            bletiny_disc_full_dscs(conn_handle);
-        }
-        break;
-
-    default:
-        bletiny_print_error(NULL, conn_handle, error);
-        break;
-    }
-
-    return 0;
-}
-
-static int
-bletiny_on_read(uint16_t conn_handle, const struct ble_gatt_error *error,
-                struct ble_gatt_attr *attr, void *arg)
-{
-    switch (error->status) {
-    case 0:
-        console_printf("characteristic read; conn_handle=%d "
-                       "attr_handle=%d len=%d value=", conn_handle,
-                       attr->handle, OS_MBUF_PKTLEN(attr->om));
-        print_mbuf(attr->om);
-        console_printf("\n");
-        break;
-
-    case BLE_HS_EDONE:
-        console_printf("characteristic read complete\n");
-        break;
-
-    default:
-        bletiny_print_error(NULL, conn_handle, error);
-        break;
-    }
-
-    return 0;
-}
-
-static int
-bletiny_on_write(uint16_t conn_handle, const struct ble_gatt_error *error,
-                 struct ble_gatt_attr *attr, void *arg)
-{
-    switch (error->status) {
-    case 0:
-        console_printf("characteristic write complete; conn_handle=%d "
-                       "attr_handle=%d\n", conn_handle, attr->handle);
-        break;
-
-    default:
-        bletiny_print_error(NULL, conn_handle, error);
-        break;
-    }
-
-    return 0;
-}
-
-static int
-bletiny_on_write_reliable(uint16_t conn_handle,
-                          const struct ble_gatt_error *error,
-                          struct ble_gatt_attr *attrs, uint8_t num_attrs,
-                          void *arg)
-{
-    int i;
-
-    switch (error->status) {
-    case 0:
-        console_printf("characteristic write reliable complete; "
-                       "conn_handle=%d", conn_handle);
-
-        for (i = 0; i < num_attrs; i++) {
-            console_printf(" attr_handle=%d len=%d value=", attrs[i].handle,
-                           OS_MBUF_PKTLEN(attrs[i].om));
-            print_mbuf(attrs[i].om);
-        }
-        console_printf("\n");
-        break;
-
-    default:
-        bletiny_print_error(NULL, conn_handle, error);
-        break;
-    }
-
-    return 0;
-}
-
-static void
-bletiny_decode_adv_data(uint8_t *adv_data, uint8_t adv_data_len)
-{
-    struct ble_hs_adv_fields fields;
-
-    console_printf(" length_data=%d data=", adv_data_len);
-    print_bytes(adv_data, adv_data_len);
-    console_printf(" fields:\n");
-    ble_hs_adv_parse_fields(&fields, adv_data, adv_data_len);
-    bletiny_print_adv_fields(&fields);
-    console_printf("\n");
-}
-
-#if MYNEWT_VAL(BLE_EXT_ADV)
-static void
-bletiny_decode_event_type(struct ble_gap_ext_disc_desc *desc)
-{
-    uint8_t directed = 0;
-
-    if (desc->props & BLE_HCI_ADV_LEGACY_MASK) {
-        console_printf("Legacy PDU type %d", desc->legacy_event_type);
-        if (desc->legacy_event_type == BLE_HCI_ADV_RPT_EVTYPE_DIR_IND) {
-            directed = 1;
-        }
-        goto common_data;
-    }
-
-    console_printf("Extended adv: ");
-    if (desc->props & BLE_HCI_ADV_CONN_MASK) {
-        console_printf("'conn' ");
-    }
-    if (desc->props & BLE_HCI_ADV_SCAN_MASK) {
-        console_printf("'scan' ");
-    }
-    if (desc->props & BLE_HCI_ADV_DIRECT_MASK) {
-        console_printf("'dir' ");
-        directed = 1;
-    }
-
-    if (desc->props & BLE_HCI_ADV_SCAN_RSP_MASK) {
-        console_printf("'scan rsp' ");
-    }
-
-    switch(desc->data_status) {
-    case BLE_HCI_ADV_DATA_STATUS_COMPLETE:
-        console_printf("complete");
-        break;
-    case BLE_HCI_ADV_DATA_STATUS_INCOMPLETE:
-        console_printf("incomplete");
-        break;
-    case BLE_HCI_ADV_DATA_STATUS_TRUNCATED:
-        console_printf("truncated");
-        break;
-    default:
-        console_printf("reserved %d", desc->data_status);
-        break;
-    }
-
-common_data:
-    console_printf(" rssi=%d txpower=%d, pphy=%d, sphy=%d, sid=%d,"
-                   " addr_type=%d addr=",
-                   desc->rssi, desc->tx_power, desc->prim_phy, desc->sec_phy,
-                   desc->sid, desc->addr.type);
-    print_addr(desc->addr.val);
-    if (directed) {
-        console_printf(" init_addr_type=%d inita=", desc->direct_addr.type);
-        print_addr(desc->direct_addr.val);
-    }
-
-    console_printf("\n");
-
-    if(!desc->length_data) {
-        return;
-    }
-
-    bletiny_decode_adv_data(desc->data, desc->length_data);
-}
-#endif
-
-static int
-bletiny_gap_event(struct ble_gap_event *event, void *arg)
-{
-    struct ble_gap_conn_desc desc;
-    int conn_idx;
-    int rc;
-
-    switch (event->type) {
-    case BLE_GAP_EVENT_CONNECT:
-        console_printf("connection %s; status=%d ",
-                       event->connect.status == 0 ? "established" : "failed",
-                       event->connect.status);
-
-        if (event->connect.status == 0) {
-            rc = ble_gap_conn_find(event->connect.conn_handle, &desc);
-            assert(rc == 0);
-            print_conn_desc(&desc);
-            bletiny_conn_add(&desc);
-        }
-        return 0;
-
-    case BLE_GAP_EVENT_DISCONNECT:
-        console_printf("disconnect; reason=%d ", event->disconnect.reason);
-        print_conn_desc(&event->disconnect.conn);
-
-        conn_idx = bletiny_conn_find_idx(event->disconnect.conn.conn_handle);
-        if (conn_idx != -1) {
-            bletiny_conn_delete_idx(conn_idx);
-        }
-        return 0;
-#if MYNEWT_VAL(BLE_EXT_ADV)
-    case BLE_GAP_EVENT_EXT_DISC:
-        bletiny_decode_event_type(&event->ext_disc);
-        return 0;
-#endif
-    case BLE_GAP_EVENT_DISC:
-        console_printf("received advertisement; event_type=%d rssi=%d "
-                       "addr_type=%d addr=", event->disc.event_type,
-                       event->disc.rssi, event->disc.addr.type);
-        print_addr(event->disc.addr.val);
-
-        /*
-         * There is no adv data to print in case of connectable
-         * directed advertising
-         */
-        if (event->disc.event_type == BLE_HCI_ADV_RPT_EVTYPE_DIR_IND) {
-                console_printf("\nConnectable directed advertising event\n");
-                return 0;
-        }
-
-        bletiny_decode_adv_data(event->disc.data, event->disc.length_data);
-
-        return 0;
-
-    case BLE_GAP_EVENT_CONN_UPDATE:
-        console_printf("connection updated; status=%d ",
-                       event->conn_update.status);
-        rc = ble_gap_conn_find(event->conn_update.conn_handle, &desc);
-        assert(rc == 0);
-        print_conn_desc(&desc);
-        return 0;
-
-    case BLE_GAP_EVENT_CONN_UPDATE_REQ:
-        console_printf("connection update request\n");
-        *event->conn_update_req.self_params =
-            *event->conn_update_req.peer_params;
-        return 0;
- 
-    case BLE_GAP_EVENT_PASSKEY_ACTION:
-        console_printf("passkey action event; action=%d",
-                       event->passkey.params.action);
-        if (event->passkey.params.action == BLE_SM_IOACT_NUMCMP) {
-            console_printf(" numcmp=%lu",
-                           (unsigned long)event->passkey.params.numcmp);
-        }
-        console_printf("\n");
-        return 0;
-
-    case BLE_GAP_EVENT_DISC_COMPLETE:
-        console_printf("discovery complete; reason=%d\n",
-                       event->disc_complete.reason);
-        return 0;
-
-    case BLE_GAP_EVENT_ADV_COMPLETE:
-        console_printf("advertise complete; reason=%d\n",
-                       event->adv_complete.reason);
-        return 0;
-
-    case BLE_GAP_EVENT_ENC_CHANGE:
-        console_printf("encryption change event; status=%d ",
-                       event->enc_change.status);
-        rc = ble_gap_conn_find(event->enc_change.conn_handle, &desc);
-        assert(rc == 0);
-        print_conn_desc(&desc);
-        return 0;
-
-    case BLE_GAP_EVENT_NOTIFY_RX:
-        console_printf("notification rx event; attr_handle=%d indication=%d "
-                       "len=%d data=",
-                       event->notify_rx.attr_handle,
-                       event->notify_rx.indication,
-                       OS_MBUF_PKTLEN(event->notify_rx.om));
-
-        print_mbuf(event->notify_rx.om);
-        console_printf("\n");
-        return 0;
-
-    case BLE_GAP_EVENT_NOTIFY_TX:
-        console_printf("notification tx event; status=%d attr_handle=%d "
-                       "indication=%d\n",
-                       event->notify_tx.status,
-                       event->notify_tx.attr_handle,
-                       event->notify_tx.indication);
-        return 0;
-
-    case BLE_GAP_EVENT_SUBSCRIBE:
-        console_printf("subscribe event; conn_handle=%d attr_handle=%d "
-                       "reason=%d prevn=%d curn=%d previ=%d curi=%d\n",
-                       event->subscribe.conn_handle,
-                       event->subscribe.attr_handle,
-                       event->subscribe.reason,
-                       event->subscribe.prev_notify,
-                       event->subscribe.cur_notify,
-                       event->subscribe.prev_indicate,
-                       event->subscribe.cur_indicate);
-        return 0;
-
-    case BLE_GAP_EVENT_MTU:
-        console_printf("mtu update event; conn_handle=%d cid=%d mtu=%d\n",
-                       event->mtu.conn_handle,
-                       event->mtu.channel_id,
-                       event->mtu.value);
-        return 0;
-
-    case BLE_GAP_EVENT_IDENTITY_RESOLVED:
-        console_printf("identity resolved ");
-        rc = ble_gap_conn_find(event->identity_resolved.conn_handle, &desc);
-        assert(rc == 0);
-        print_conn_desc(&desc);
-        return 0;
-    case BLE_GAP_EVENT_PHY_UPDATE_COMPLETE:
-        console_printf("PHY update complete; status=%d, conn_handle=%d "
-                       " tx_phy=%d, rx_phy=%d\n",
-                       event->phy_updated.status,
-                       event->phy_updated.conn_handle,
-                       event->phy_updated.tx_phy,
-                       event->phy_updated.rx_phy);
-        return 0;
-
-    case BLE_GAP_EVENT_REPEAT_PAIRING:
-        /* We already have a bond with the peer, but it is attempting to
-         * establish a new secure link.  This app sacrifices security for
-         * convenience: just throw away the old bond and accept the new link.
-         */
-
-        /* Delete the old bond. */
-        rc = ble_gap_conn_find(event->repeat_pairing.conn_handle, &desc);
-        assert(rc == 0);
-        ble_store_util_delete_peer(&desc.peer_id_addr);
-
-        /* Return BLE_GAP_REPEAT_PAIRING_RETRY to indicate that the host should
-         * continue with the pairing operation.
-         */
-        return BLE_GAP_REPEAT_PAIRING_RETRY;
-
-    default:
-        return 0;
-    }
-}
-
-static void
-bletiny_on_l2cap_update(uint16_t conn_handle, int status, void *arg)
-{
-    console_printf("l2cap update complete; conn_handle=%d status=%d\n",
-                   conn_handle, status);
-}
-
-static void
-bletiny_tx_timer_cb(struct os_event *ev)
-{
-    int i;
-    uint8_t len;
-    int32_t timeout;
-    uint8_t *dptr;
-    struct os_mbuf *om;
-
-    if ((bletiny_tx_data.tx_num == 0) || (bletiny_tx_data.tx_len == 0)) {
-        return;
-    }
-
-    len = bletiny_tx_data.tx_len;
-
-    om = NULL;
-    if (os_msys_num_free() >= 4) {
-        om = os_msys_get_pkthdr(len + 4, sizeof(struct ble_mbuf_hdr));
-    }
-
-    if (om) {
-        /* Put the HCI header in the mbuf */
-        om->om_len = len + 4;
-        put_le16(om->om_data, bletiny_tx_data.tx_handle);
-        put_le16(om->om_data + 2, len);
-        dptr = om->om_data + 4;
-
-        /*
-         * NOTE: first byte gets 0xff so not confused with l2cap channel.
-         * The rest of the data gets filled with incrementing pattern starting
-         * from 0.
-         */
-        put_le16(dptr, len - 4);
-        dptr[2] = 0xff;
-        dptr[3] = 0xff;
-        dptr += 4;
-        len -= 4;
-
-        for (i = 0; i < len; ++i) {
-            *dptr = i;
-            ++dptr;
-        }
-
-        /* Set packet header length */
-        OS_MBUF_PKTHDR(om)->omp_len = om->om_len;
-        ble_hci_trans_hs_acl_tx(om);
-
-        --bletiny_tx_data.tx_num;
-    }
-
-    if (bletiny_tx_data.tx_num) {
-        timeout = (int32_t)bletiny_tx_data.tx_rate;
-        timeout = (timeout * OS_TICKS_PER_SEC) / 1000;
-        os_callout_reset(&bletiny_tx_timer, timeout);
-    }
-}
-
-int
-bletiny_exchange_mtu(uint16_t conn_handle)
-{
-    int rc;
-
-    rc = ble_gattc_exchange_mtu(conn_handle, bletiny_on_mtu, NULL);
-    return rc;
-}
-
-int
-bletiny_disc_all_chrs(uint16_t conn_handle, uint16_t start_handle,
-                      uint16_t end_handle)
-{
-    intptr_t svc_start_handle;
-    int rc;
-
-    svc_start_handle = start_handle;
-    rc = ble_gattc_disc_all_chrs(conn_handle, start_handle, end_handle,
-                                 bletiny_on_disc_c, (void *)svc_start_handle);
-    return rc;
-}
-
-int
-bletiny_disc_chrs_by_uuid(uint16_t conn_handle, uint16_t start_handle,
-                           uint16_t end_handle, const ble_uuid_t *uuid)
-{
-    intptr_t svc_start_handle;
-    int rc;
-
-    svc_start_handle = start_handle;
-    rc = ble_gattc_disc_chrs_by_uuid(conn_handle, start_handle, end_handle,
-                                     uuid, bletiny_on_disc_c,
-                                     (void *)svc_start_handle);
-    return rc;
-}
-
-int
-bletiny_disc_svcs(uint16_t conn_handle)
-{
-    int rc;
-
-    rc = ble_gattc_disc_all_svcs(conn_handle, bletiny_on_disc_s, NULL);
-    return rc;
-}
-
-int
-bletiny_disc_svc_by_uuid(uint16_t conn_handle, const ble_uuid_t *uuid)
-{
-    int rc;
-
-    rc = ble_gattc_disc_svc_by_uuid(conn_handle, uuid,
-                                    bletiny_on_disc_s, NULL);
-    return rc;
-}
-
-int
-bletiny_disc_all_dscs(uint16_t conn_handle, uint16_t start_handle,
-                      uint16_t end_handle)
-{
-    int rc;
-
-    rc = ble_gattc_disc_all_dscs(conn_handle, start_handle, end_handle,
-                                 bletiny_on_disc_d, NULL);
-    return rc;
-}
-
-int
-bletiny_disc_full(uint16_t conn_handle)
-{
-    struct bletiny_conn *conn;
-    struct bletiny_svc *svc;
-
-    /* Undiscover everything first. */
-    conn = bletiny_conn_find(conn_handle);
-    if (conn == NULL) {
-        return BLE_HS_ENOTCONN;
-    }
-
-    while ((svc = SLIST_FIRST(&conn->svcs)) != NULL) {
-        SLIST_REMOVE_HEAD(&conn->svcs, next);
-        bletiny_svc_delete(svc);
-    }
-
-    bletiny_full_disc_prev_chr_val = 1;
-    bletiny_disc_svcs(conn_handle);
-
-    return 0;
-}
-
-int
-bletiny_find_inc_svcs(uint16_t conn_handle, uint16_t start_handle,
-                       uint16_t end_handle)
-{
-    int rc;
-
-    rc = ble_gattc_find_inc_svcs(conn_handle, start_handle, end_handle,
-                                 bletiny_on_disc_s, NULL);
-    return rc;
-}
-
-int
-bletiny_read(uint16_t conn_handle, uint16_t attr_handle)
-{
-    struct os_mbuf *om;
-    int rc;
-
-    if (conn_handle == BLE_HS_CONN_HANDLE_NONE) {
-        rc = ble_att_svr_read_local(attr_handle, &om);
-        if (rc == 0) {
-            console_printf("read local; attr_handle=%d len=%d value=",
-                           attr_handle, OS_MBUF_PKTLEN(om));
-            print_mbuf(om);
-            console_printf("\n");
-
-            os_mbuf_free_chain(om);
-        }
-    } else {
-        rc = ble_gattc_read(conn_handle, attr_handle, bletiny_on_read, NULL);
-    }
-    return rc;
-}
-
-int
-bletiny_read_long(uint16_t conn_handle, uint16_t attr_handle, uint16_t offset)
-{
-    int rc;
-
-    rc = ble_gattc_read_long(conn_handle, attr_handle, offset,
-                             bletiny_on_read, NULL);
-    return rc;
-}
-
-int
-bletiny_read_by_uuid(uint16_t conn_handle, uint16_t start_handle,
-                      uint16_t end_handle, const ble_uuid_t *uuid)
-{
-    int rc;
-
-    rc = ble_gattc_read_by_uuid(conn_handle, start_handle, end_handle, uuid,
-                                bletiny_on_read, NULL);
-    return rc;
-}
-
-int
-bletiny_read_mult(uint16_t conn_handle, uint16_t *attr_handles,
-                   int num_attr_handles)
-{
-    int rc;
-
-    rc = ble_gattc_read_mult(conn_handle, attr_handles, num_attr_handles,
-                             bletiny_on_read, NULL);
-    return rc;
-}
-
-int
-bletiny_write(uint16_t conn_handle, uint16_t attr_handle, struct os_mbuf *om)
-{
-    int rc;
-
-    if (conn_handle == BLE_HS_CONN_HANDLE_NONE) {
-        rc = ble_att_svr_write_local(attr_handle, om);
-    } else {
-        rc = ble_gattc_write(conn_handle, attr_handle, om,
-                             bletiny_on_write, NULL);
-    }
-
-    return rc;
-}
-
-int
-bletiny_write_no_rsp(uint16_t conn_handle, uint16_t attr_handle,
-                     struct os_mbuf *om)
-{
-    int rc;
-
-    rc = ble_gattc_write_no_rsp(conn_handle, attr_handle, om);
-
-    return rc;
-}
-
-int
-bletiny_write_long(uint16_t conn_handle, uint16_t attr_handle,
-                   uint16_t offset, struct os_mbuf *om)
-{
-    int rc;
-
-    rc = ble_gattc_write_long(conn_handle, attr_handle, offset,
-                              om, bletiny_on_write, NULL);
-    return rc;
-}
-
-int
-bletiny_write_reliable(uint16_t conn_handle,
-                       struct ble_gatt_attr *attrs,
-                       int num_attrs)
-{
-    int rc;
-
-    rc = ble_gattc_write_reliable(conn_handle, attrs, num_attrs,
-                                  bletiny_on_write_reliable, NULL);
-    return rc;
-}
-
-int
-bletiny_adv_stop(void)
-{
-    int rc;
-
-    rc = ble_gap_adv_stop();
-    return rc;
-}
-
-int
-bletiny_adv_start(uint8_t own_addr_type, const ble_addr_t *direct_addr,
-                  int32_t duration_ms, const struct ble_gap_adv_params *params)
-{
-    int rc;
-
-    rc = ble_gap_adv_start(own_addr_type, direct_addr, duration_ms, params,
-                           bletiny_gap_event, NULL);
-    return rc;
-}
-
-int
-bletiny_conn_initiate(uint8_t own_addr_type, const ble_addr_t *peer_addr,
-                      int32_t duration_ms, struct ble_gap_conn_params *params)
-{
-    int rc;
-
-    rc = ble_gap_connect(own_addr_type, peer_addr, duration_ms, params,
-                         bletiny_gap_event, NULL);
-
-    return rc;
-}
-
-int
-bletiny_ext_conn_initiate(uint8_t own_addr_type, const ble_addr_t *peer_addr,
-                          int32_t duration_ms,
-                          struct ble_gap_conn_params *phy_1m_params,
-                          struct ble_gap_conn_params *phy_2m_params,
-                          struct ble_gap_conn_params *phy_coded_params)
-{
-#if MYNEWT_VAL(BLE_EXT_ADV) == 0
-    console_printf("BLE extended advertising not supported.");
-    console_printf(" Configure nimble host to enable it\n");
-    return 0;
-#else
-    int rc;
-    uint8_t phy_mask = 0;
-
-    if (phy_1m_params) {
-        phy_mask |= BLE_GAP_LE_PHY_1M_MASK;
-    }
-
-    if (phy_2m_params) {
-        phy_mask |= BLE_GAP_LE_PHY_2M_MASK;
-    }
-
-    if (phy_coded_params) {
-        phy_mask |= BLE_GAP_LE_PHY_CODED_MASK;
-    }
-
-    rc = ble_gap_ext_connect(own_addr_type, peer_addr, duration_ms, phy_mask,
-                             phy_1m_params, phy_2m_params, phy_coded_params,
-                             bletiny_gap_event, NULL);
-
-    return rc;
-#endif
-}
-
-int
-bletiny_conn_cancel(void)
-{
-    int rc;
-
-    rc = ble_gap_conn_cancel();
-    return rc;
-}
-
-int
-bletiny_term_conn(uint16_t conn_handle, uint8_t reason)
-{
-    int rc;
-
-    rc = ble_gap_terminate(conn_handle, reason);
-    return rc;
-}
-
-int
-bletiny_wl_set(ble_addr_t *addrs, int addrs_count)
-{
-    int rc;
-
-    rc = ble_gap_wl_set(addrs, addrs_count);
-    return rc;
-}
-
-int
-bletiny_scan(uint8_t own_addr_type, int32_t duration_ms,
-             const struct ble_gap_disc_params *disc_params)
-{
-    int rc;
-
-    rc = ble_gap_disc(own_addr_type, duration_ms, disc_params,
-                      bletiny_gap_event, NULL);
-    return rc;
-}
-
-int
-bletiny_ext_scan(uint8_t own_addr_type, uint16_t duration, uint16_t period,
-                 uint8_t filter_duplicates, uint8_t filter_policy,
-                 uint8_t limited,
-                 const struct ble_gap_ext_disc_params *uncoded_params,
-                 const struct ble_gap_ext_disc_params *coded_params)
-{
-#if MYNEWT_VAL(BLE_EXT_ADV) == 0
-    console_printf("BLE extended advertising not supported.");
-    console_printf(" Configure nimble host to enable it\n");
-    return 0;
-#else
-    int rc;
-
-    rc = ble_gap_ext_disc(own_addr_type, duration, period, filter_duplicates,
-                          filter_policy, limited, uncoded_params, coded_params,
-                          bletiny_gap_event, NULL);
-    return rc;
-#endif
-}
-
-int
-bletiny_scan_cancel(void)
-{
-    int rc;
-
-    rc = ble_gap_disc_cancel();
-    return rc;
-}
-
-int
-bletiny_set_adv_data(struct ble_hs_adv_fields *adv_fields)
-{
-    int rc;
-
-    rc = ble_gap_adv_set_fields(adv_fields);
-    return rc;
-}
-
-int
-bletiny_update_conn(uint16_t conn_handle, struct ble_gap_upd_params *params)
-{
-    int rc;
-
-    rc = ble_gap_update_params(conn_handle, params);
-    return rc;
-}
-
-void
-bletiny_chrup(uint16_t attr_handle)
-{
-    ble_gatts_chr_updated(attr_handle);
-}
-
-int
-bletiny_datalen(uint16_t conn_handle, uint16_t tx_octets, uint16_t tx_time)
-{
-    int rc;
-
-    rc = ble_hs_hci_util_set_data_len(conn_handle, tx_octets, tx_time);
-    return rc;
-}
-
-int
-bletiny_l2cap_update(uint16_t conn_handle,
-                     struct ble_l2cap_sig_update_params *params)
-{
-    int rc;
-
-    rc = ble_l2cap_sig_update(conn_handle, params, bletiny_on_l2cap_update,
-                              NULL);
-    return rc;
-}
-
-int
-bletiny_sec_pair(uint16_t conn_handle)
-{
-#if !NIMBLE_BLE_SM
-    return BLE_HS_ENOTSUP;
-#endif
-
-    int rc;
-
-    rc = ble_gap_pair_initiate(conn_handle);
-    return rc;
-}
-
-int
-bletiny_sec_start(uint16_t conn_handle)
-{
-#if !NIMBLE_BLE_SM
-    return BLE_HS_ENOTSUP;
-#endif
-
-    int rc;
-
-    rc = ble_gap_security_initiate(conn_handle);
-    return rc;
-}
-
-int
-bletiny_sec_restart(uint16_t conn_handle,
-                    uint8_t *ltk,
-                    uint16_t ediv,
-                    uint64_t rand_val,
-                    int auth)
-{
-#if !NIMBLE_BLE_SM
-    return BLE_HS_ENOTSUP;
-#endif
-
-    struct ble_store_value_sec value_sec;
-    struct ble_store_key_sec key_sec;
-    struct ble_gap_conn_desc desc;
-    ble_hs_conn_flags_t conn_flags;
-    int rc;
-
-    if (ltk == NULL) {
-        /* The user is requesting a store lookup. */
-        rc = ble_gap_conn_find(conn_handle, &desc);
-        if (rc != 0) {
-            return rc;
-        }
-
-        memset(&key_sec, 0, sizeof key_sec);
-        key_sec.peer_addr = desc.peer_id_addr;
-
-        rc = ble_hs_atomic_conn_flags(conn_handle, &conn_flags);
-        if (rc != 0) {
-            return rc;
-        }
-        if (conn_flags & BLE_HS_CONN_F_MASTER) {
-            rc = ble_store_read_peer_sec(&key_sec, &value_sec);
-        } else {
-            rc = ble_store_read_our_sec(&key_sec, &value_sec);
-        }
-        if (rc != 0) {
-            return rc;
-        }
-
-        ltk = value_sec.ltk;
-        ediv = value_sec.ediv;
-        rand_val = value_sec.rand_num;
-        auth = value_sec.authenticated;
-    }
-
-    rc = ble_gap_encryption_initiate(conn_handle, ltk, ediv, rand_val, auth);
-    return rc;
-}
-
-/**
- * Called to start transmitting 'num' packets at rate 'rate' of size 'size'
- * to connection handle 'handle'
- *
- * @param handle
- * @param len
- * @param rate
- * @param num
- *
- * @return int
- */
-int
-bletiny_tx_start(uint16_t handle, uint16_t len, uint16_t rate, uint16_t num)
-{
-    /* Cannot be currently in a session */
-    if (num == 0) {
-        return 0;
-    }
-
-    /* Do not allow start if already in progress */
-    if (bletiny_tx_data.tx_num != 0) {
-        return -1;
-    }
-
-    /* XXX: for now, must have contiguous mbuf space */
-    if ((len + 4) > MYNEWT_VAL_MSYS_1_BLOCK_SIZE) {
-        return -2;
-    }
-
-    bletiny_tx_data.tx_num = num;
-    bletiny_tx_data.tx_rate = rate;
-    bletiny_tx_data.tx_len = len;
-    bletiny_tx_data.tx_handle = handle;
-
-    os_callout_reset(&bletiny_tx_timer, 0);
-
-    return 0;
-}
-
-int
-bletiny_rssi(uint16_t conn_handle, int8_t *out_rssi)
-{
-    int rc;
-
-    rc = ble_gap_conn_rssi(conn_handle, out_rssi);
-    if (rc != 0) {
-        return rc;
-    }
-
-    return 0;
-}
-
-static void
-bletiny_on_reset(int reason)
-{
-    console_printf("Error: Resetting state; reason=%d\n", reason);
-}
-
-#if MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM) != 0
-
-static int
-bletiny_l2cap_coc_add(uint16_t conn_handle, struct ble_l2cap_chan *chan)
-{
-    struct bletiny_conn *conn;
-    struct bletiny_l2cap_coc *coc;
-    struct bletiny_l2cap_coc *prev, *cur;
-
-    conn = bletiny_conn_find(conn_handle);
-    assert(conn != NULL);
-
-    coc = os_memblock_get(&bletiny_coc_conn_pool);
-    if (!coc) {
-        return ENOMEM;
-    }
-
-    coc->chan = chan;
-
-    prev = NULL;
-    SLIST_FOREACH(cur, &conn->coc_list, next) {
-        prev = cur;
-    }
-
-    if (prev == NULL) {
-        SLIST_INSERT_HEAD(&conn->coc_list, coc, next);
-    } else {
-        SLIST_INSERT_AFTER(prev, coc, next);
-    }
-
-    return 0;
-}
-
-static void
-bletiny_l2cap_coc_remove(uint16_t conn_handle, struct ble_l2cap_chan *chan)
-{
-    struct bletiny_conn *conn;
-    struct bletiny_l2cap_coc *coc;
-    struct bletiny_l2cap_coc *cur;
-
-    conn = bletiny_conn_find(conn_handle);
-    assert(conn != NULL);
-
-    coc = NULL;
-    SLIST_FOREACH(cur, &conn->coc_list, next) {
-        if (cur->chan == chan) {
-            coc = cur;
-            break;
-        }
-    }
-
-    if (!coc) {
-        return;
-    }
-
-    SLIST_REMOVE(&conn->coc_list, coc, bletiny_l2cap_coc, next);
-    os_memblock_put(&bletiny_coc_conn_pool, coc);
-}
-
-static void
-bletiny_l2cap_coc_recv(struct ble_l2cap_chan *chan, struct os_mbuf *sdu)
-{
-    console_printf("LE CoC SDU received, chan: 0x%08lx, data len %d\n",
-                   (uint32_t) chan, OS_MBUF_PKTLEN(sdu));
-
-    os_mbuf_free_chain(sdu);
-    sdu = os_mbuf_get_pkthdr(&sdu_os_mbuf_pool, 0);
-    assert(sdu != NULL);
-
-    ble_l2cap_recv_ready(chan, sdu);
-}
-
-static int
-bletiny_l2cap_coc_accept(uint16_t conn_handle, uint16_t peer_mtu,
-                           struct ble_l2cap_chan *chan)
-{
-    struct os_mbuf *sdu_rx;
-
-    console_printf("LE CoC accepting, chan: 0x%08lx, peer_mtu %d\n",
-                       (uint32_t) chan, peer_mtu);
-
-    sdu_rx = os_mbuf_get_pkthdr(&sdu_os_mbuf_pool, 0);
-    if (!sdu_rx) {
-        return BLE_HS_ENOMEM;
-    }
-
-    ble_l2cap_recv_ready(chan, sdu_rx);
-
-    return 0;
-}
-
-static int
-bletiny_l2cap_event(struct ble_l2cap_event *event, void *arg)
-{
-    switch(event->type) {
-        case BLE_L2CAP_EVENT_COC_CONNECTED:
-            if (event->connect.status) {
-                console_printf("LE COC error: %d\n", event->connect.status);
-                return 0;
-            }
-
-            console_printf("LE COC connected, conn: %d, chan: 0x%08lx\n",
-                           event->connect.conn_handle,
-                           (uint32_t) event->connect.chan);
-
-            bletiny_l2cap_coc_add(event->connect.conn_handle,
-                                  event->connect.chan);
-
-            return 0;
-        case BLE_L2CAP_EVENT_COC_DISCONNECTED:
-            console_printf("LE CoC disconnected, chan: 0x%08lx\n",
-                           (uint32_t) event->disconnect.chan);
-
-            bletiny_l2cap_coc_remove(event->disconnect.conn_handle,
-                                     event->disconnect.chan);
-            return 0;
-        case BLE_L2CAP_EVENT_COC_ACCEPT:
-            return bletiny_l2cap_coc_accept(event->accept.conn_handle,
-                                            event->accept.peer_sdu_size,
-                                            event->accept.chan);
-
-        case BLE_L2CAP_EVENT_COC_DATA_RECEIVED:
-            bletiny_l2cap_coc_recv(event->receive.chan, event->receive.sdu_rx);
-            return 0;
-        default:
-            return 0;
-    }
-}
-#endif
-
-int
-bletiny_l2cap_create_srv(uint16_t psm)
-{
-#if MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM) == 0
-    console_printf("BLE L2CAP LE COC not supported.");
-    console_printf(" Configure nimble host to enable it\n");
-    return 0;
-#else
-
-    return ble_l2cap_create_server(psm, BLETINY_COC_MTU, bletiny_l2cap_event,
-                                                                       NULL);
-#endif
-}
-
-int
-bletiny_l2cap_connect(uint16_t conn_handle, uint16_t psm)
-{
-#if MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM) == 0
-    console_printf("BLE L2CAP LE COC not supported.");
-    console_printf(" Configure nimble host to enable it\n");
-    return 0;
-#else
-
-    struct os_mbuf *sdu_rx;
-
-    sdu_rx = os_mbuf_get_pkthdr(&sdu_os_mbuf_pool, 0);
-    assert(sdu_rx != NULL);
-
-    return ble_l2cap_connect(conn_handle, psm, BLETINY_COC_MTU, sdu_rx,
-                             bletiny_l2cap_event, NULL);
-#endif
-}
-
-int
-bletiny_l2cap_disconnect(uint16_t conn_handle, uint16_t idx)
-{
-#if MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM) == 0
-    console_printf("BLE L2CAP LE COC not supported.");
-    console_printf(" Configure nimble host to enable it\n");
-    return 0;
-#else
-
-    struct bletiny_conn *conn;
-    struct bletiny_l2cap_coc *coc;
-    int i;
-    int rc = 0;
-
-    conn = bletiny_conn_find(conn_handle);
-    assert(conn != NULL);
-
-    i = 0;
-    SLIST_FOREACH(coc, &conn->coc_list, next) {
-        if (i == idx) {
-                break;
-        }
-        i++;
-    }
-    assert(coc != NULL);
-
-    rc = ble_l2cap_disconnect(coc->chan);
-    if (rc) {
-        console_printf("Could not disconnect channel rc=%d\n", rc);
-    }
-
-    return rc;
-#endif
-}
-
-int
-bletiny_l2cap_send(uint16_t conn_handle, uint16_t idx, uint16_t bytes)
-{
-#if MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM) == 0
-    console_printf("BLE L2CAP LE COC not supported.");
-    console_printf(" Configure nimble host to enable it\n");
-    return 0;
-#else
-
-    struct bletiny_conn *conn;
-    struct bletiny_l2cap_coc *coc;
-    struct os_mbuf *sdu_tx;
-    uint8_t b[] = {0x00, 0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88, 0x99};
-    int i;
-    int rc;
-
-    console_printf("conn=%d, idx=%d, bytes=%d\n", conn_handle, idx, bytes);
-
-    conn = bletiny_conn_find(conn_handle);
-    if (conn == NULL) {
-        console_printf("conn=%d does not exist\n", conn_handle);
-        return 0;
-    }
-
-    i = 0;
-    SLIST_FOREACH(coc, &conn->coc_list, next) {
-        if (i == idx) {
-            break;
-        }
-        i++;
-    }
-    if (coc == NULL) {
-        console_printf("Are you sure your channel exist?\n");
-        return 0;
-    }
-
-    sdu_tx = os_mbuf_get_pkthdr(&sdu_os_mbuf_pool, 0);
-    if (sdu_tx == NULL) {
-        console_printf("No memory in the test sdu pool\n");
-        return 0;
-    }
-
-    /* For the testing purpose we fill up buffer with known data, easy
-     * to validate on other side. In this loop we add as many full chunks as we
-     * can
-     */
-    for (i = 0; i < bytes / sizeof(b); i++) {
-        rc = os_mbuf_append(sdu_tx, b, sizeof(b));
-        if (rc) {
-            console_printf("Cannot append data %i !\n", i);
-            os_mbuf_free_chain(sdu_tx);
-            return rc;
-        }
-    }
-
-    /* Here we add the rest < sizeof(b) */
-    rc = os_mbuf_append(sdu_tx, b, bytes - (sizeof(b) * i));
-    if (rc) {
-        console_printf("Cannot append data %i !\n", i);
-        os_mbuf_free_chain(sdu_tx);
-        return rc;
-    }
-
-    rc = ble_l2cap_send(coc->chan, sdu_tx);
-    if (rc) {
-        console_printf("Could not send data rc=%d\n", rc);
-        os_mbuf_free_chain(sdu_tx);
-    }
-
-    return rc;
-
-#endif
-}
-/**
- * main
- *
- * The main task for the project. This function initializes the packages,
- * then starts serving events from default event queue.
- *
- * @return int NOTE: this function should never return!
- */
-int
-main(int argc, char **argv)
-{
-    int rc;
-
-#ifdef ARCH_sim
-    mcu_sim_parse_args(argc, argv);
-#endif
-
-    /* Initialize OS */
-    sysinit();
-
-    /* Allocate some application specific memory pools. */
-    bletiny_svc_mem = malloc(
-        OS_MEMPOOL_BYTES(BLETINY_MAX_SVCS, sizeof (struct bletiny_svc)));
-    assert(bletiny_svc_mem != NULL);
-
-    rc = os_mempool_init(&bletiny_svc_pool, BLETINY_MAX_SVCS,
-                         sizeof (struct bletiny_svc), bletiny_svc_mem,
-                         "bletiny_svc_pool");
-    assert(rc == 0);
-
-    bletiny_chr_mem = malloc(
-        OS_MEMPOOL_BYTES(BLETINY_MAX_CHRS, sizeof (struct bletiny_chr)));
-    assert(bletiny_chr_mem != NULL);
-
-    rc = os_mempool_init(&bletiny_chr_pool, BLETINY_MAX_CHRS,
-                         sizeof (struct bletiny_chr), bletiny_chr_mem,
-                         "bletiny_chr_pool");
-    assert(rc == 0);
-
-    bletiny_dsc_mem = malloc(
-        OS_MEMPOOL_BYTES(BLETINY_MAX_DSCS, sizeof (struct bletiny_dsc)));
-    assert(bletiny_dsc_mem != NULL);
-
-    rc = os_mempool_init(&bletiny_dsc_pool, BLETINY_MAX_DSCS,
-                         sizeof (struct bletiny_dsc), bletiny_dsc_mem,
-                         "bletiny_dsc_pool");
-    assert(rc == 0);
-
-#if MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM) != 0
-    /* For testing we want to support all the available channels */
-    bletiny_sdu_coc_mem = malloc(
-        OS_MEMPOOL_BYTES(BLETINY_COC_BUF_COUNT, BLETINY_COC_MTU));
-    assert(bletiny_sdu_coc_mem != NULL);
-
-    rc = os_mempool_init(&sdu_coc_mbuf_mempool, BLETINY_COC_BUF_COUNT,
-                         BLETINY_COC_MTU, bletiny_sdu_coc_mem,
-                         "bletiny_coc_sdu_pool");
-    assert(rc == 0);
-
-    rc = os_mbuf_pool_init(&sdu_os_mbuf_pool, &sdu_coc_mbuf_mempool,
-                           BLETINY_COC_MTU, BLETINY_COC_BUF_COUNT);
-    assert(rc == 0);
-
-    bletiny_coc_conn_mem = malloc(
-        OS_MEMPOOL_BYTES(MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM),
-                         sizeof (struct bletiny_l2cap_coc)));
-    assert(bletiny_coc_conn_mem != NULL);
-
-    rc = os_mempool_init(&bletiny_coc_conn_pool,
-                         MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM),
-                         sizeof (struct bletiny_l2cap_coc), bletiny_coc_conn_mem,
-                         "bletiny_coc_conn_pool");
-    assert(rc == 0);
-#endif
-
-    /* Initialize the logging system. */
-    log_register("bletiny", &bletiny_log, &log_console_handler, NULL,
-                 LOG_SYSLEVEL);
-
-    /* Initialize the NimBLE host configuration. */
-    log_register("ble_hs", &ble_hs_log, &log_console_handler, NULL,
-                 LOG_SYSLEVEL);
-    ble_hs_cfg.reset_cb = bletiny_on_reset;
-    ble_hs_cfg.gatts_register_cb = gatt_svr_register_cb;
-    ble_hs_cfg.store_status_cb = ble_store_util_status_rr;
-
-    rc = gatt_svr_init();
-    assert(rc == 0);
-
-    rc = cmd_init();
-    assert(rc == 0);
-
-    /* Set the default device name. */
-    rc = ble_svc_gap_device_name_set("nimble-bletiny");
-    assert(rc == 0);
-
-    /* Create a callout (timer).  This callout is used by the "tx" bletiny
-     * command to repeatedly send packets of sequential data bytes.
-     */
-    os_callout_init(&bletiny_tx_timer, os_eventq_dflt_get(),
-                    bletiny_tx_timer_cb, NULL);
-
-    while (1) {
-        os_eventq_run(os_eventq_dflt_get());
-    }
-    /* os start should never return. If it does, this should be an error */
-    assert(0);
-
-    return 0;
-}
diff --git a/apps/bletiny/src/misc.c b/apps/bletiny/src/misc.c
deleted file mode 100644
index 11d72e8253..0000000000
--- a/apps/bletiny/src/misc.c
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-#include "console/console.h"
-#include "host/ble_uuid.h"
-#include "host/ble_gap.h"
-
-#include "bletiny.h"
-
-/**
- * Utility function to log an array of bytes.
- */
-void
-print_bytes(const uint8_t *bytes, int len)
-{
-    int i;
-
-    for (i = 0; i < len; i++) {
-        console_printf("%s0x%02x", i != 0 ? ":" : "", bytes[i]);
-    }
-}
-
-void
-print_mbuf(const struct os_mbuf *om)
-{
-    int colon;
-
-    colon = 0;
-    while (om != NULL) {
-        if (colon) {
-            console_printf(":");
-        } else {
-            colon = 1;
-        }
-        print_bytes(om->om_data, om->om_len);
-        om = SLIST_NEXT(om, om_next);
-    }
-}
-
-void
-print_addr(const void *addr)
-{
-    const uint8_t *u8p;
-
-    u8p = addr;
-    console_printf("%02x:%02x:%02x:%02x:%02x:%02x",
-                   u8p[5], u8p[4], u8p[3], u8p[2], u8p[1], u8p[0]);
-}
-
-void
-print_uuid(const ble_uuid_t *uuid)
-{
-    char buf[BLE_UUID_STR_LEN];
-
-    ble_uuid_to_str(uuid, buf);
-
-    console_printf("%s", buf);
-}
-
-int
-svc_is_empty(const struct bletiny_svc *svc)
-{
-    return svc->svc.end_handle <= svc->svc.start_handle;
-}
-
-uint16_t
-chr_end_handle(const struct bletiny_svc *svc, const struct bletiny_chr *chr)
-{
-    const struct bletiny_chr *next_chr;
-
-    next_chr = SLIST_NEXT(chr, next);
-    if (next_chr != NULL) {
-        return next_chr->chr.def_handle - 1;
-    } else {
-        return svc->svc.end_handle;
-    }
-}
-
-int
-chr_is_empty(const struct bletiny_svc *svc, const struct bletiny_chr *chr)
-{
-    return chr_end_handle(svc, chr) <= chr->chr.val_handle;
-}
-
-void
-print_conn_desc(const struct ble_gap_conn_desc *desc)
-{
-    console_printf("handle=%d our_ota_addr_type=%d our_ota_addr=",
-                   desc->conn_handle, desc->our_ota_addr.type);
-    print_addr(desc->our_ota_addr.val);
-    console_printf(" our_id_addr_type=%d our_id_addr=",
-                   desc->our_id_addr.type);
-    print_addr(desc->our_id_addr.val);
-    console_printf(" peer_ota_addr_type=%d peer_ota_addr=",
-                   desc->peer_ota_addr.type);
-    print_addr(desc->peer_ota_addr.val);
-    console_printf(" peer_id_addr_type=%d peer_id_addr=",
-                   desc->peer_id_addr.type);
-    print_addr(desc->peer_id_addr.val);
-    console_printf(" conn_itvl=%d conn_latency=%d supervision_timeout=%d "
-                   "encrypted=%d authenticated=%d bonded=%d\n",
-                   desc->conn_itvl, desc->conn_latency,
-                   desc->supervision_timeout,
-                   desc->sec_state.encrypted,
-                   desc->sec_state.authenticated,
-                   desc->sec_state.bonded);
-}
diff --git a/apps/bletiny/src/parse.c b/apps/bletiny/src/parse.c
deleted file mode 100644
index 4cb2eb75c1..0000000000
--- a/apps/bletiny/src/parse.c
+++ /dev/null
@@ -1,520 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-#include <string.h>
-#include <stdlib.h>
-#include <limits.h>
-#include <stdarg.h>
-#include <errno.h>
-#include <assert.h>
-#include "console/console.h"
-#include "host/ble_uuid.h"
-#include "bletiny.h"
-
-#define CMD_MAX_ARGS        16
-
-static char *cmd_args[CMD_MAX_ARGS][2];
-static int cmd_num_args;
-
-int
-parse_err_too_few_args(char *cmd_name)
-{
-    console_printf("Error: too few arguments for command \"%s\"\n",
-                   cmd_name);
-    return -1;
-}
-
-const struct cmd_entry *
-parse_cmd_find(const struct cmd_entry *cmds, char *name)
-{
-    const struct cmd_entry *cmd;
-    int i;
-
-    for (i = 0; cmds[i].name != NULL; i++) {
-        cmd = cmds + i;
-        if (strcmp(name, cmd->name) == 0) {
-            return cmd;
-        }
-    }
-
-    return NULL;
-}
-
-struct kv_pair *
-parse_kv_find(struct kv_pair *kvs, char *name)
-{
-    struct kv_pair *kv;
-    int i;
-
-    for (i = 0; kvs[i].key != NULL; i++) {
-        kv = kvs + i;
-        if (strcmp(name, kv->key) == 0) {
-            return kv;
-        }
-    }
-
-    return NULL;
-}
-
-int
-parse_arg_find_idx(const char *key)
-{
-    int i;
-
-    for (i = 0; i < cmd_num_args; i++) {
-        if (strcmp(cmd_args[i][0], key) == 0) {
-            return i;
-        }
-    }
-
-    return -1;
-}
-
-char *
-parse_arg_peek(const char *key)
-{
-    int i;
-
-    for (i = 0; i < cmd_num_args; i++) {
-        if (strcmp(cmd_args[i][0], key) == 0) {
-            return cmd_args[i][1];
-        }
-    }
-
-    return NULL;
-}
-
-char *
-parse_arg_extract(const char *key)
-{
-    int i;
-
-    for (i = 0; i < cmd_num_args; i++) {
-        if (strcmp(cmd_args[i][0], key) == 0) {
-            /* Erase parameter. */
-            cmd_args[i][0][0] = '\0';
-
-            return cmd_args[i][1];
-        }
-    }
-
-    return NULL;
-}
-
-/**
- * Determines which number base to use when parsing the specified numeric
- * string.  This just avoids base '0' so that numbers don't get interpreted as
- * octal.
- */
-static int
-parse_arg_long_base(char *sval)
-{
-    if (sval[0] == '0' && sval[1] == 'x') {
-        return 0;
-    } else {
-        return 10;
-    }
-}
-
-long
-parse_long_bounds(char *sval, long min, long max, int *out_status)
-{
-    char *endptr;
-    long lval;
-
-    lval = strtol(sval, &endptr, parse_arg_long_base(sval));
-    if (sval[0] != '\0' && *endptr == '\0' &&
-        lval >= min && lval <= max) {
-
-        *out_status = 0;
-        return lval;
-    }
-
-    *out_status = EINVAL;
-    return 0;
-}
-
-long
-parse_arg_long_bounds_peek(char *name, long min, long max, int *out_status)
-{
-    char *sval;
-
-    sval = parse_arg_peek(name);
-    if (sval == NULL) {
-        *out_status = ENOENT;
-        return 0;
-    }
-    return parse_long_bounds(sval, min, max, out_status);
-}
-
-long
-parse_arg_long_bounds(char *name, long min, long max, int *out_status)
-{
-    char *sval;
-
-    sval = parse_arg_extract(name);
-    if (sval == NULL) {
-        *out_status = ENOENT;
-        return 0;
-    }
-    return parse_long_bounds(sval, min, max, out_status);
-}
-
-long
-parse_arg_long_bounds_default(char *name, long min, long max,
-                              long dflt, int *out_status)
-{
-    long val;
-    int rc;
-
-    val = parse_arg_long_bounds(name, min, max, &rc);
-    if (rc == ENOENT) {
-        rc = 0;
-        val = dflt;
-    }
-
-    *out_status = rc;
-
-    return val;
-}
-
-uint64_t
-parse_arg_uint64_bounds(char *name, uint64_t min, uint64_t max, int *out_status)
-{
-    char *endptr;
-    char *sval;
-    uint64_t lval;
-
-    sval = parse_arg_extract(name);
-    if (sval == NULL) {
-        *out_status = ENOENT;
-        return 0;
-    }
-
-    lval = strtoull(sval, &endptr, parse_arg_long_base(sval));
-    if (sval[0] != '\0' && *endptr == '\0' &&
-        lval >= min && lval <= max) {
-
-        *out_status = 0;
-        return lval;
-    }
-
-    *out_status = EINVAL;
-    return 0;
-}
-
-long
-parse_arg_long(char *name, int *out_status)
-{
-    return parse_arg_long_bounds(name, LONG_MIN, LONG_MAX, out_status);
-}
-
-uint8_t
-parse_arg_bool(char *name, int *out_status)
-{
-    return parse_arg_long_bounds(name, 0, 1, out_status);
-}
-
-uint8_t
-parse_arg_bool_default(char *name, uint8_t dflt, int *out_status)
-{
-    return parse_arg_long_bounds_default(name, 0, 1, dflt, out_status);
-}
-
-uint8_t
-parse_arg_uint8(char *name, int *out_status)
-{
-    return parse_arg_long_bounds(name, 0, UINT8_MAX, out_status);
-}
-
-uint16_t
-parse_arg_uint16(char *name, int *out_status)
-{
-    return parse_arg_long_bounds(name, 0, UINT16_MAX, out_status);
-}
-
-uint16_t
-parse_arg_uint16_peek(char *name, int *out_status)
-{
-    return parse_arg_long_bounds_peek(name, 0, UINT16_MAX, out_status);
-}
-
-uint32_t
-parse_arg_uint32(char *name, int *out_status)
-{
-    return parse_arg_uint64_bounds(name, 0, UINT32_MAX, out_status);
-}
-
-uint64_t
-parse_arg_uint64(char *name, int *out_status)
-{
-    return parse_arg_uint64_bounds(name, 0, UINT64_MAX, out_status);
-}
-
-uint8_t
-parse_arg_uint8_dflt(char *name, uint8_t dflt, int *out_status)
-{
-    uint8_t val;
-    int rc;
-
-    val = parse_arg_uint8(name, &rc);
-    if (rc == ENOENT) {
-        val = dflt;
-        rc = 0;
-    }
-
-    *out_status = rc;
-    return val;
-}
-
-uint16_t
-parse_arg_uint16_dflt(char *name, uint16_t dflt, int *out_status)
-{
-    uint16_t val;
-    int rc;
-
-    val = parse_arg_uint16(name, &rc);
-    if (rc == ENOENT) {
-        val = dflt;
-        rc = 0;
-    }
-
-    *out_status = rc;
-    return val;
-}
-
-uint32_t
-parse_arg_uint32_dflt(char *name, uint32_t dflt, int *out_status)
-{
-    uint32_t val;
-    int rc;
-
-    val = parse_arg_uint32(name, &rc);
-    if (rc == ENOENT) {
-        val = dflt;
-        rc = 0;
-    }
-
-    *out_status = rc;
-    return val;
-}
-
-int
-parse_arg_kv(char *name, struct kv_pair *kvs, int *out_status)
-{
-    struct kv_pair *kv;
-    char *sval;
-
-    sval = parse_arg_extract(name);
-    if (sval == NULL) {
-        *out_status = ENOENT;
-        return -1;
-    }
-
-    kv = parse_kv_find(kvs, sval);
-    if (kv == NULL) {
-        *out_status = EINVAL;
-        return -1;
-    }
-
-    *out_status = 0;
-    return kv->val;
-}
-
-int
-parse_arg_kv_default(char *name, struct kv_pair *kvs, int def_val,
-                     int *out_status)
-{
-    int val;
-    int rc;
-
-    val = parse_arg_kv(name, kvs, &rc);
-    if (rc == ENOENT) {
-        rc = 0;
-        val = def_val;
-    }
-
-    *out_status = rc;
-
-    return val;
-}
-
-
-static int
-parse_arg_byte_stream_delim(char *sval, char *delims, int max_len,
-                            uint8_t *dst, int *out_len)
-{
-    unsigned long ul;
-    char *endptr;
-    char *token;
-    int i;
-
-    i = 0;
-    for (token = strtok(sval, delims);
-         token != NULL;
-         token = strtok(NULL, delims)) {
-
-        if (i >= max_len) {
-            return EINVAL;
-        }
-
-        ul = strtoul(token, &endptr, 16);
-        if (sval[0] == '\0' || *endptr != '\0' || ul > UINT8_MAX) {
-            return -1;
-        }
-
-        dst[i] = ul;
-        i++;
-    }
-
-    *out_len = i;
-
-    return 0;
-}
-
-int
-parse_arg_byte_stream(char *name, int max_len, uint8_t *dst, int *out_len)
-{
-    char *sval;
-
-    sval = parse_arg_extract(name);
-    if (sval == NULL) {
-        return ENOENT;
-    }
-
-    return parse_arg_byte_stream_delim(sval, ":-", max_len, dst, out_len);
-}
-
-int
-parse_arg_byte_stream_exact_length(char *name, uint8_t *dst, int len)
-{
-    int actual_len;
-    int rc;
-
-    rc = parse_arg_byte_stream(name, len, dst, &actual_len);
-    if (rc != 0) {
-        return rc;
-    }
-
-    if (actual_len != len) {
-        return EINVAL;
-    }
-
-    return 0;
-}
-
-static void
-parse_reverse_bytes(uint8_t *bytes, int len)
-{
-    uint8_t tmp;
-    int i;
-
-    for (i = 0; i < len / 2; i++) {
-        tmp = bytes[i];
-        bytes[i] = bytes[len - i - 1];
-        bytes[len - i - 1] = tmp;
-    }
-}
-
-int
-parse_arg_mac(char *name, uint8_t *dst)
-{
-    int rc;
-
-    rc = parse_arg_byte_stream_exact_length(name, dst, 6);
-    if (rc != 0) {
-        return rc;
-    }
-
-    parse_reverse_bytes(dst, 6);
-
-    return 0;
-}
-
-int
-parse_arg_uuid(char *str, ble_uuid_any_t *uuid)
-{
-    uint16_t uuid16;
-    uint8_t val[16];
-    int len;
-    int rc;
-
-    uuid16 = parse_arg_uint16_peek(str, &rc);
-    switch (rc) {
-    case ENOENT:
-        parse_arg_extract(str);
-        return ENOENT;
-
-    case 0:
-        len = 2;
-        val[0] = uuid16;
-        val[1] = uuid16 >> 8;
-        parse_arg_extract(str);
-        break;
-
-    default:
-        len = 16;
-        rc = parse_arg_byte_stream_exact_length(str, val, 16);
-        if (rc != 0) {
-            return EINVAL;
-        }
-        parse_reverse_bytes(val, 16);
-        break;
-    }
-
-    rc = ble_uuid_init_from_buf(uuid, val, len);
-    if (rc != 0) {
-        return EINVAL;
-    } else {
-        return 0;
-    }
-}
-
-int
-parse_arg_all(int argc, char **argv)
-{
-    char *key;
-    char *val;
-    int i;
-
-    cmd_num_args = 0;
-
-    for (i = 0; i < argc; i++) {
-        key = strtok(argv[i], "=");
-        val = strtok(NULL, "=");
-
-        if (key != NULL && val != NULL) {
-            if (strlen(key) == 0) {
-                console_printf("Error: invalid argument: %s\n", argv[i]);
-                return -1;
-            }
-
-            if (cmd_num_args >= CMD_MAX_ARGS) {
-                console_printf("Error: too many arguments");
-                return -1;
-            }
-
-            cmd_args[cmd_num_args][0] = key;
-            cmd_args[cmd_num_args][1] = val;
-            cmd_num_args++;
-        }
-    }
-
-    return 0;
-}
diff --git a/apps/bletiny/syscfg.yml b/apps/bletiny/syscfg.yml
deleted file mode 100644
index 206f7fb42a..0000000000
--- a/apps/bletiny/syscfg.yml
+++ /dev/null
@@ -1,45 +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.
-#
-
-# Package: apps/bletiny
-
-syscfg.defs:
-    BLETINY_HELP:
-        description: Include usage information for bletiny shell commands.
-        value: 1
-
-    BLETINY_ANS:
-        description: Include support for the alert notification service.
-        value: 1
-
-syscfg.vals:
-    # Enable the shell task.
-    SHELL_TASK: 1
-
-    # Set log level to info (disable debug logging).
-    LOG_LEVEL: 1
-
-    # Disable security manager (pairing and bonding).
-    BLE_SM_LEGACY: 0
-    BLE_SM_SC: 0
-
-    # Default task settings
-    OS_MAIN_STACK_SIZE: 512
-
-    # Newtmgr is not supported in this app, so disable newtmgr-over-shell.
-    SHELL_NEWTMGR: 0
diff --git a/docs/network/ble/ble_intro.rst b/docs/network/ble/ble_intro.rst
index f47a78b764..3202699b0c 100644
--- a/docs/network/ble/ble_intro.rst
+++ b/docs/network/ble/ble_intro.rst
@@ -109,11 +109,11 @@ while designing a NimBLE app.
 Example NimBLE projects
 ~~~~~~~~~~~~~~~~~~~~~~~
 
-Mynewt comes with two built-in projects that allow users to play with
+Mynewt comes with few built-in projects that allow users to play with
 NimBLE, try the tutorials out with, and see how to use available
 services.
 
-1. **bletiny** : A simple shell application which provides a basic
+1. **btshell** : A simple shell application which provides a basic
    interface to the host-side of the BLE stack.
 2. **bleprph**: A basic peripheral device with no user interface. It
    advertises automatically on startup, and resumes advertising whenever
diff --git a/docs/os/tutorials/add_newtmgr.rst b/docs/os/tutorials/add_newtmgr.rst
index 5089a2915c..034493c0e5 100644
--- a/docs/os/tutorials/add_newtmgr.rst
+++ b/docs/os/tutorials/add_newtmgr.rst
@@ -39,7 +39,7 @@ Use an Existing Project
 
 We assume that you have worked through at least some of the other
 tutorials and have an existing project. In this example, we modify the
-``bletiny`` app to enable Newt Manager support. We call our target
+``btshell`` app to enable Newt Manager support. We call our target
 ``myble``. You can create the target using any name you choose.
 
 Modify Package Dependencies and Configurations
@@ -165,8 +165,8 @@ version number you choose.
 ::
 
     $ newt create-image myble 1.0.0
-    App image successfully generated: ./bin/makerbeacon/apps/bletiny/bletiny.img
-    Build manifest: ./bin/makerbeacon/apps/bletiny/manifest.json
+    App image successfully generated: ./bin/makerbeacon/apps/btshell/btshell.img
+    Build manifest: ./bin/makerbeacon/apps/btshell/manifest.json
 
 Load the Image
 ~~~~~~~~~~~~~~


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services