You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2015/12/03 19:55:12 UTC

[1/3] incubator-mynewt-larva git commit: Rename ble_hs_att_* to ble_att_*

Repository: incubator-mynewt-larva
Updated Branches:
  refs/heads/master 8598e84fb -> 31f0c10b6


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/31f0c10b/net/nimble/host/src/test/ble_hs_att_svr_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_att_svr_test.c b/net/nimble/host/src/test/ble_hs_att_svr_test.c
index 4cd7045..c7fff45 100644
--- a/net/nimble/host/src/test/ble_hs_att_svr_test.c
+++ b/net/nimble/host/src/test/ble_hs_att_svr_test.c
@@ -24,19 +24,19 @@
 #include "ble_l2cap.h"
 #include "ble_hs_test_util.h"
 #include "ble_hs_conn.h"
-#include "ble_hs_att.h"
-#include "ble_hs_att_cmd.h"
+#include "ble_att.h"
+#include "ble_att_cmd.h"
 
-static uint8_t *ble_hs_att_svr_test_attr_r_1;
-static int ble_hs_att_svr_test_attr_r_1_len;
-static uint8_t *ble_hs_att_svr_test_attr_r_2;
-static int ble_hs_att_svr_test_attr_r_2_len;
+static uint8_t *ble_att_svr_test_attr_r_1;
+static int ble_att_svr_test_attr_r_1_len;
+static uint8_t *ble_att_svr_test_attr_r_2;
+static int ble_att_svr_test_attr_r_2_len;
 
-static uint8_t ble_hs_att_svr_test_attr_w_1[1024];
-static int ble_hs_att_svr_test_attr_w_1_len;
+static uint8_t ble_att_svr_test_attr_w_1[1024];
+static int ble_att_svr_test_attr_w_1_len;
 
 static void
-ble_hs_att_svr_test_misc_init(struct ble_hs_conn **conn,
+ble_att_svr_test_misc_init(struct ble_hs_conn **conn,
                               struct ble_l2cap_chan **att_chan)
 {
     ble_hs_test_util_init();
@@ -50,14 +50,14 @@ ble_hs_att_svr_test_misc_init(struct ble_hs_conn **conn,
 }
 
 static int
-ble_hs_att_svr_test_misc_attr_fn_r_1(struct ble_hs_att_svr_entry *entry,
+ble_att_svr_test_misc_attr_fn_r_1(struct ble_att_svr_entry *entry,
                                      uint8_t op,
-                                     union ble_hs_att_svr_handle_arg *arg)
+                                     union ble_att_svr_handle_arg *arg)
 {
     switch (op) {
-    case BLE_HS_ATT_OP_READ_REQ:
-        arg->aha_read.attr_data = ble_hs_att_svr_test_attr_r_1;
-        arg->aha_read.attr_len = ble_hs_att_svr_test_attr_r_1_len;
+    case BLE_ATT_OP_READ_REQ:
+        arg->aha_read.attr_data = ble_att_svr_test_attr_r_1;
+        arg->aha_read.attr_len = ble_att_svr_test_attr_r_1_len;
         return 0;
 
     default:
@@ -66,14 +66,14 @@ ble_hs_att_svr_test_misc_attr_fn_r_1(struct ble_hs_att_svr_entry *entry,
 }
 
 static int
-ble_hs_att_svr_test_misc_attr_fn_r_2(struct ble_hs_att_svr_entry *entry,
+ble_att_svr_test_misc_attr_fn_r_2(struct ble_att_svr_entry *entry,
                                      uint8_t op,
-                                     union ble_hs_att_svr_handle_arg *arg)
+                                     union ble_att_svr_handle_arg *arg)
 {
     switch (op) {
-    case BLE_HS_ATT_OP_READ_REQ:
-        arg->aha_read.attr_data = ble_hs_att_svr_test_attr_r_2;
-        arg->aha_read.attr_len = ble_hs_att_svr_test_attr_r_2_len;
+    case BLE_ATT_OP_READ_REQ:
+        arg->aha_read.attr_data = ble_att_svr_test_attr_r_2;
+        arg->aha_read.attr_len = ble_att_svr_test_attr_r_2_len;
         return 0;
 
     default:
@@ -82,20 +82,20 @@ ble_hs_att_svr_test_misc_attr_fn_r_2(struct ble_hs_att_svr_entry *entry,
 }
 
 static int
-ble_hs_att_svr_test_misc_attr_fn_w_1(struct ble_hs_att_svr_entry *entry,
+ble_att_svr_test_misc_attr_fn_w_1(struct ble_att_svr_entry *entry,
                                      uint8_t op,
-                                     union ble_hs_att_svr_handle_arg *arg)
+                                     union ble_att_svr_handle_arg *arg)
 {
     struct os_mbuf_pkthdr *omp;
     int rc;
 
     switch (op) {
-    case BLE_HS_ATT_OP_WRITE_REQ:
+    case BLE_ATT_OP_WRITE_REQ:
         omp = OS_MBUF_PKTHDR(arg->aha_write.om);
         rc = os_mbuf_copydata(arg->aha_write.om, 0, arg->aha_write.attr_len,
-                              ble_hs_att_svr_test_attr_w_1);
+                              ble_att_svr_test_attr_w_1);
         TEST_ASSERT(rc == 0);
-        ble_hs_att_svr_test_attr_w_1_len = arg->aha_write.attr_len;
+        ble_att_svr_test_attr_w_1_len = arg->aha_write.attr_len;
         return 0;
 
     default:
@@ -106,18 +106,18 @@ ble_hs_att_svr_test_misc_attr_fn_w_1(struct ble_hs_att_svr_entry *entry,
 }
 
 static void
-ble_hs_att_svr_test_misc_verify_tx_err_rsp(struct ble_l2cap_chan *chan,
+ble_att_svr_test_misc_verify_tx_err_rsp(struct ble_l2cap_chan *chan,
                                            uint8_t req_op, uint16_t handle,
                                            uint8_t error_code)
 {
-    struct ble_hs_att_error_rsp rsp;
-    uint8_t buf[BLE_HS_ATT_ERROR_RSP_SZ];
+    struct ble_att_error_rsp rsp;
+    uint8_t buf[BLE_ATT_ERROR_RSP_SZ];
     int rc;
 
     rc = os_mbuf_copydata(ble_hs_test_util_prev_tx, 0, sizeof buf, buf);
     TEST_ASSERT(rc == 0);
 
-    rc = ble_hs_att_error_rsp_parse(buf, sizeof buf, &rsp);
+    rc = ble_att_error_rsp_parse(buf, sizeof buf, &rsp);
     TEST_ASSERT(rc == 0);
 
     TEST_ASSERT(rsp.bhaep_req_op == req_op);
@@ -126,11 +126,11 @@ ble_hs_att_svr_test_misc_verify_tx_err_rsp(struct ble_l2cap_chan *chan,
 
     /* Remove the error response from the buffer. */
     os_mbuf_adj(ble_hs_test_util_prev_tx,
-                BLE_HS_ATT_ERROR_RSP_SZ);
+                BLE_ATT_ERROR_RSP_SZ);
 }
 
 static void
-ble_hs_att_svr_test_misc_verify_tx_read_rsp(struct ble_l2cap_chan *chan,
+ble_att_svr_test_misc_verify_tx_read_rsp(struct ble_l2cap_chan *chan,
                                             uint8_t *attr_data, int attr_len)
 {
     uint8_t u8;
@@ -139,7 +139,7 @@ ble_hs_att_svr_test_misc_verify_tx_read_rsp(struct ble_l2cap_chan *chan,
 
     rc = os_mbuf_copydata(ble_hs_test_util_prev_tx, 0, 1, &u8);
     TEST_ASSERT(rc == 0);
-    TEST_ASSERT(u8 == BLE_HS_ATT_OP_READ_RSP);
+    TEST_ASSERT(u8 == BLE_ATT_OP_READ_RSP);
 
     for (i = 0; i < attr_len; i++) {
         rc = os_mbuf_copydata(ble_hs_test_util_prev_tx, i + 1, 1, &u8);
@@ -155,56 +155,56 @@ ble_hs_att_svr_test_misc_verify_tx_read_rsp(struct ble_l2cap_chan *chan,
 }
 
 static void
-ble_hs_att_svr_test_misc_verify_tx_write_rsp(struct ble_l2cap_chan *chan)
+ble_att_svr_test_misc_verify_tx_write_rsp(struct ble_l2cap_chan *chan)
 {
     uint8_t u8;
     int rc;
 
     rc = os_mbuf_copydata(ble_hs_test_util_prev_tx, 0, 1, &u8);
     TEST_ASSERT(rc == 0);
-    TEST_ASSERT(u8 == BLE_HS_ATT_OP_WRITE_RSP);
+    TEST_ASSERT(u8 == BLE_ATT_OP_WRITE_RSP);
 
     /* Remove the write response from the buffer. */
     os_mbuf_adj(ble_hs_test_util_prev_tx,
-                BLE_HS_ATT_WRITE_RSP_SZ);
+                BLE_ATT_WRITE_RSP_SZ);
 }
 
 static void
-ble_hs_att_svr_test_misc_verify_tx_mtu_rsp(struct ble_l2cap_chan *chan)
+ble_att_svr_test_misc_verify_tx_mtu_rsp(struct ble_l2cap_chan *chan)
 {
-    struct ble_hs_att_mtu_cmd rsp;
-    uint8_t buf[BLE_HS_ATT_MTU_CMD_SZ];
+    struct ble_att_mtu_cmd rsp;
+    uint8_t buf[BLE_ATT_MTU_CMD_SZ];
     int rc;
 
     rc = os_mbuf_copydata(ble_hs_test_util_prev_tx, 0, sizeof buf, buf);
     TEST_ASSERT(rc == 0);
 
-    rc = ble_hs_att_mtu_cmd_parse(buf, sizeof buf, &rsp);
+    rc = ble_att_mtu_cmd_parse(buf, sizeof buf, &rsp);
     TEST_ASSERT(rc == 0);
 
     TEST_ASSERT(rsp.bhamc_mtu == chan->blc_my_mtu);
 
     /* Remove the write response from the buffer. */
     os_mbuf_adj(ble_hs_test_util_prev_tx,
-                BLE_HS_ATT_MTU_CMD_SZ);
+                BLE_ATT_MTU_CMD_SZ);
 }
 
-struct ble_hs_att_svr_test_info_entry {
+struct ble_att_svr_test_info_entry {
     uint16_t handle;        /* 0 on last entry */
     uint16_t uuid16;        /* 0 if not present. */
     uint8_t uuid128[16];
 };
 
 static void
-ble_hs_att_svr_test_misc_verify_tx_find_info_rsp(
+ble_att_svr_test_misc_verify_tx_find_info_rsp(
     struct ble_l2cap_chan *chan,
-    struct ble_hs_att_svr_test_info_entry *entries)
+    struct ble_att_svr_test_info_entry *entries)
 {
-    struct ble_hs_att_svr_test_info_entry *entry;
-    struct ble_hs_att_find_info_rsp rsp;
+    struct ble_att_svr_test_info_entry *entry;
+    struct ble_att_find_info_rsp rsp;
     uint16_t handle;
     uint16_t uuid16;
-    uint8_t buf[BLE_HS_ATT_FIND_INFO_RSP_MIN_SZ];
+    uint8_t buf[BLE_ATT_FIND_INFO_RSP_MIN_SZ];
     uint8_t uuid128[16];
     int off;
     int rc;
@@ -215,7 +215,7 @@ ble_hs_att_svr_test_misc_verify_tx_find_info_rsp(
     TEST_ASSERT(rc == 0);
     off += sizeof buf;
 
-    rc = ble_hs_att_find_info_rsp_parse(buf, sizeof buf, &rsp);
+    rc = ble_att_find_info_rsp_parse(buf, sizeof buf, &rsp);
     TEST_ASSERT(rc == 0);
 
     for (entry = entries; entry->handle != 0; entry++) {
@@ -228,7 +228,7 @@ ble_hs_att_svr_test_misc_verify_tx_find_info_rsp(
 
         if (entry->uuid16 != 0) {
             TEST_ASSERT(rsp.bhafp_format ==
-                        BLE_HS_ATT_FIND_INFO_RSP_FORMAT_16BIT);
+                        BLE_ATT_FIND_INFO_RSP_FORMAT_16BIT);
             rc = os_mbuf_copydata(ble_hs_test_util_prev_tx, off, 2, &uuid16);
             TEST_ASSERT(rc == 0);
             off += 2;
@@ -237,7 +237,7 @@ ble_hs_att_svr_test_misc_verify_tx_find_info_rsp(
             TEST_ASSERT(uuid16 == entry->uuid16);
         } else {
             TEST_ASSERT(rsp.bhafp_format ==
-                        BLE_HS_ATT_FIND_INFO_RSP_FORMAT_128BIT);
+                        BLE_ATT_FIND_INFO_RSP_FORMAT_128BIT);
             rc = os_mbuf_copydata(ble_hs_test_util_prev_tx, off, 16, uuid128);
             TEST_ASSERT(rc == 0);
             off += 16;
@@ -253,17 +253,17 @@ ble_hs_att_svr_test_misc_verify_tx_find_info_rsp(
     os_mbuf_adj(ble_hs_test_util_prev_tx, off);
 }
 
-struct ble_hs_att_svr_test_type_value_entry {
+struct ble_att_svr_test_type_value_entry {
     uint16_t first;        /* 0 on last entry */
     uint16_t last;
 };
 
 static void
-ble_hs_att_svr_test_misc_verify_tx_find_type_value_rsp(
+ble_att_svr_test_misc_verify_tx_find_type_value_rsp(
     struct ble_l2cap_chan *chan,
-    struct ble_hs_att_svr_test_type_value_entry *entries)
+    struct ble_att_svr_test_type_value_entry *entries)
 {
-    struct ble_hs_att_svr_test_type_value_entry *entry;
+    struct ble_att_svr_test_type_value_entry *entry;
     uint16_t u16;
     uint8_t op;
     int off;
@@ -275,7 +275,7 @@ ble_hs_att_svr_test_misc_verify_tx_find_type_value_rsp(
     TEST_ASSERT(rc == 0);
     off += 1;
 
-    TEST_ASSERT(op == BLE_HS_ATT_OP_FIND_TYPE_VALUE_RSP);
+    TEST_ASSERT(op == BLE_ATT_OP_FIND_TYPE_VALUE_RSP);
 
     for (entry = entries; entry->first != 0; entry++) {
         rc = os_mbuf_copydata(ble_hs_test_util_prev_tx, off, 2, &u16);
@@ -299,21 +299,21 @@ ble_hs_att_svr_test_misc_verify_tx_find_type_value_rsp(
 }
 
 static void
-ble_hs_att_svr_test_misc_mtu_exchange(uint16_t my_mtu, uint16_t peer_sent,
+ble_att_svr_test_misc_mtu_exchange(uint16_t my_mtu, uint16_t peer_sent,
                                       uint16_t peer_actual, uint16_t chan_mtu)
 {
-    struct ble_hs_att_mtu_cmd req;
+    struct ble_att_mtu_cmd req;
     struct ble_l2cap_chan *chan;
     struct ble_hs_conn *conn;
-    uint8_t buf[BLE_HS_ATT_MTU_CMD_SZ];
+    uint8_t buf[BLE_ATT_MTU_CMD_SZ];
     int rc;
 
-    ble_hs_att_svr_test_misc_init(&conn, &chan);
+    ble_att_svr_test_misc_init(&conn, &chan);
 
     chan->blc_my_mtu = my_mtu;
 
     req.bhamc_mtu = peer_sent;
-    rc = ble_hs_att_mtu_req_write(buf, sizeof buf, &req);
+    rc = ble_att_mtu_req_write(buf, sizeof buf, &req);
     TEST_ASSERT(rc == 0);
 
     rc = ble_hs_test_util_l2cap_rx_payload_flat(conn, chan, buf, sizeof buf);
@@ -322,134 +322,134 @@ ble_hs_att_svr_test_misc_mtu_exchange(uint16_t my_mtu, uint16_t peer_sent,
 
     TEST_ASSERT(chan->blc_peer_mtu == peer_actual);
 
-    ble_hs_att_svr_test_misc_verify_tx_mtu_rsp(chan);
+    ble_att_svr_test_misc_verify_tx_mtu_rsp(chan);
 
     TEST_ASSERT(ble_l2cap_chan_mtu(chan) == chan_mtu);
 }
 
-TEST_CASE(ble_hs_att_svr_test_mtu)
+TEST_CASE(ble_att_svr_test_mtu)
 {
     /*** MTU too low; should pretend peer sent default value instead. */
-    ble_hs_att_svr_test_misc_mtu_exchange(BLE_HS_ATT_MTU_DFLT, 5,
-                                          BLE_HS_ATT_MTU_DFLT,
-                                          BLE_HS_ATT_MTU_DFLT);
+    ble_att_svr_test_misc_mtu_exchange(BLE_ATT_MTU_DFLT, 5,
+                                          BLE_ATT_MTU_DFLT,
+                                          BLE_ATT_MTU_DFLT);
 
     /*** MTUs equal. */
-    ble_hs_att_svr_test_misc_mtu_exchange(50, 50, 50, 50);
+    ble_att_svr_test_misc_mtu_exchange(50, 50, 50, 50);
 
     /*** Peer's higher than mine. */
-    ble_hs_att_svr_test_misc_mtu_exchange(50, 100, 100, 50);
+    ble_att_svr_test_misc_mtu_exchange(50, 100, 100, 50);
 
     /*** Mine higher than peer's. */
-    ble_hs_att_svr_test_misc_mtu_exchange(100, 50, 50, 50);
+    ble_att_svr_test_misc_mtu_exchange(100, 50, 50, 50);
 }
 
-TEST_CASE(ble_hs_att_svr_test_read)
+TEST_CASE(ble_att_svr_test_read)
 {
-    struct ble_hs_att_read_req req;
+    struct ble_att_read_req req;
     struct ble_l2cap_chan *chan;
     struct ble_hs_conn *conn;
-    uint8_t buf[BLE_HS_ATT_READ_REQ_SZ];
+    uint8_t buf[BLE_ATT_READ_REQ_SZ];
     uint8_t uuid[16] = {0};
     int rc;
 
-    ble_hs_att_svr_test_misc_init(&conn, &chan);
+    ble_att_svr_test_misc_init(&conn, &chan);
 
     /*** Nonexistent attribute. */
     req.bharq_handle = 0;
-    rc = ble_hs_att_read_req_write(buf, sizeof buf, &req);
+    rc = ble_att_read_req_write(buf, sizeof buf, &req);
     TEST_ASSERT(rc == 0);
 
     rc = ble_hs_test_util_l2cap_rx_payload_flat(conn, chan, buf, sizeof buf);
     TEST_ASSERT(rc != 0);
     ble_hs_process_tx_data_queue();
-    ble_hs_att_svr_test_misc_verify_tx_err_rsp(chan, BLE_HS_ATT_OP_READ_REQ, 0,
-                                               BLE_HS_ATT_ERR_INVALID_HANDLE);
+    ble_att_svr_test_misc_verify_tx_err_rsp(chan, BLE_ATT_OP_READ_REQ, 0,
+                                               BLE_ATT_ERR_INVALID_HANDLE);
 
     /*** Successful read. */
-    ble_hs_att_svr_test_attr_r_1 = (uint8_t[]){0,1,2,3,4,5,6,7};
-    ble_hs_att_svr_test_attr_r_1_len = 8;
-    rc = ble_hs_att_svr_register(uuid, 0, &req.bharq_handle,
-                                 ble_hs_att_svr_test_misc_attr_fn_r_1);
+    ble_att_svr_test_attr_r_1 = (uint8_t[]){0,1,2,3,4,5,6,7};
+    ble_att_svr_test_attr_r_1_len = 8;
+    rc = ble_att_svr_register(uuid, 0, &req.bharq_handle,
+                                 ble_att_svr_test_misc_attr_fn_r_1);
     TEST_ASSERT(rc == 0);
 
-    rc = ble_hs_att_read_req_write(buf, sizeof buf, &req);
+    rc = ble_att_read_req_write(buf, sizeof buf, &req);
     TEST_ASSERT(rc == 0);
 
     rc = ble_hs_test_util_l2cap_rx_payload_flat(conn, chan, buf, sizeof buf);
     TEST_ASSERT(rc == 0);
     ble_hs_process_tx_data_queue();
 
-    ble_hs_att_svr_test_misc_verify_tx_read_rsp(
-        chan, ble_hs_att_svr_test_attr_r_1, ble_hs_att_svr_test_attr_r_1_len);
+    ble_att_svr_test_misc_verify_tx_read_rsp(
+        chan, ble_att_svr_test_attr_r_1, ble_att_svr_test_attr_r_1_len);
 
     /*** Partial read. */
-    ble_hs_att_svr_test_attr_r_1 =
+    ble_att_svr_test_attr_r_1 =
         (uint8_t[]){0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,
                     22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39};
-    ble_hs_att_svr_test_attr_r_1_len = 40;
+    ble_att_svr_test_attr_r_1_len = 40;
 
-    rc = ble_hs_att_read_req_write(buf, sizeof buf, &req);
+    rc = ble_att_read_req_write(buf, sizeof buf, &req);
     TEST_ASSERT(rc == 0);
 
     rc = ble_hs_test_util_l2cap_rx_payload_flat(conn, chan, buf, sizeof buf);
     TEST_ASSERT(rc == 0);
     ble_hs_process_tx_data_queue();
 
-    ble_hs_att_svr_test_misc_verify_tx_read_rsp(chan,
-                                                ble_hs_att_svr_test_attr_r_1,
-                                                BLE_HS_ATT_MTU_DFLT - 1);
+    ble_att_svr_test_misc_verify_tx_read_rsp(chan,
+                                                ble_att_svr_test_attr_r_1,
+                                                BLE_ATT_MTU_DFLT - 1);
 }
 
-TEST_CASE(ble_hs_att_svr_test_write)
+TEST_CASE(ble_att_svr_test_write)
 {
-    struct ble_hs_att_write_req req;
+    struct ble_att_write_req req;
     struct ble_l2cap_chan *chan;
     struct ble_hs_conn *conn;
-    uint8_t buf[BLE_HS_ATT_READ_REQ_SZ + 8];
+    uint8_t buf[BLE_ATT_READ_REQ_SZ + 8];
     uint8_t uuid[16] = {0};
     int rc;
 
-    ble_hs_att_svr_test_misc_init(&conn, &chan);
+    ble_att_svr_test_misc_init(&conn, &chan);
 
     /*** Nonexistent attribute. */
     req.bhawq_handle = 0;
-    rc = ble_hs_att_write_req_write(buf, sizeof buf, &req);
+    rc = ble_att_write_req_write(buf, sizeof buf, &req);
     TEST_ASSERT(rc == 0);
-    memcpy(buf + BLE_HS_ATT_READ_REQ_SZ, ((uint8_t[]){0,1,2,3,4,5,6,7}), 8);
+    memcpy(buf + BLE_ATT_READ_REQ_SZ, ((uint8_t[]){0,1,2,3,4,5,6,7}), 8);
 
     rc = ble_hs_test_util_l2cap_rx_payload_flat(conn, chan, buf, sizeof buf);
     TEST_ASSERT(rc != 0);
     ble_hs_process_tx_data_queue();
-    ble_hs_att_svr_test_misc_verify_tx_err_rsp(
-        chan, BLE_HS_ATT_OP_WRITE_REQ, 0, BLE_HS_ATT_ERR_INVALID_HANDLE);
+    ble_att_svr_test_misc_verify_tx_err_rsp(
+        chan, BLE_ATT_OP_WRITE_REQ, 0, BLE_ATT_ERR_INVALID_HANDLE);
 
     /*** Successful write. */
-    rc = ble_hs_att_svr_register(uuid, 0, &req.bhawq_handle,
-                                 ble_hs_att_svr_test_misc_attr_fn_w_1);
+    rc = ble_att_svr_register(uuid, 0, &req.bhawq_handle,
+                                 ble_att_svr_test_misc_attr_fn_w_1);
     TEST_ASSERT(rc == 0);
 
-    rc = ble_hs_att_write_req_write(buf, sizeof buf, &req);
+    rc = ble_att_write_req_write(buf, sizeof buf, &req);
     TEST_ASSERT(rc == 0);
-    memcpy(buf + BLE_HS_ATT_WRITE_REQ_MIN_SZ,
+    memcpy(buf + BLE_ATT_WRITE_REQ_MIN_SZ,
            ((uint8_t[]){0,1,2,3,4,5,6,7}), 8);
 
     rc = ble_hs_test_util_l2cap_rx_payload_flat(conn, chan, buf, sizeof buf);
     TEST_ASSERT(rc == 0);
     ble_hs_process_tx_data_queue();
 
-    ble_hs_att_svr_test_misc_verify_tx_write_rsp(chan);
+    ble_att_svr_test_misc_verify_tx_write_rsp(chan);
 }
 
-TEST_CASE(ble_hs_att_svr_test_find_info)
+TEST_CASE(ble_att_svr_test_find_info)
 {
-    struct ble_hs_att_find_info_req req;
+    struct ble_att_find_info_req req;
     struct ble_l2cap_chan *chan;
     struct ble_hs_conn *conn;
     uint16_t handle1;
     uint16_t handle2;
     uint16_t handle3;
-    uint8_t buf[BLE_HS_ATT_FIND_INFO_REQ_SZ];
+    uint8_t buf[BLE_ATT_FIND_INFO_REQ_SZ];
     uint8_t uuid1[16] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
     uint8_t uuid2[16] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};
     uint8_t uuid3[16] = {
@@ -458,7 +458,7 @@ TEST_CASE(ble_hs_att_svr_test_find_info)
     };
     int rc;
 
-    ble_hs_att_svr_test_misc_init(&conn, &chan);
+    ble_att_svr_test_misc_init(&conn, &chan);
 
     /* Increase the MTU to 128 bytes to allow testing of long responses. */
     chan->blc_my_mtu = 128;
@@ -469,75 +469,75 @@ TEST_CASE(ble_hs_att_svr_test_find_info)
     req.bhafq_start_handle = 0;
     req.bhafq_end_handle = 0;
 
-    rc = ble_hs_att_find_info_req_write(buf, sizeof buf, &req);
+    rc = ble_att_find_info_req_write(buf, sizeof buf, &req);
     TEST_ASSERT(rc == 0);
 
     rc = ble_hs_test_util_l2cap_rx_payload_flat(conn, chan, buf, sizeof buf);
     TEST_ASSERT(rc != 0);
     ble_hs_process_tx_data_queue();
 
-    ble_hs_att_svr_test_misc_verify_tx_err_rsp(
-        chan, BLE_HS_ATT_OP_FIND_INFO_REQ, 0, BLE_HS_ATT_ERR_INVALID_HANDLE);
+    ble_att_svr_test_misc_verify_tx_err_rsp(
+        chan, BLE_ATT_OP_FIND_INFO_REQ, 0, BLE_ATT_ERR_INVALID_HANDLE);
 
     /*** Start handle > end handle. */
     req.bhafq_start_handle = 101;
     req.bhafq_end_handle = 100;
 
-    rc = ble_hs_att_find_info_req_write(buf, sizeof buf, &req);
+    rc = ble_att_find_info_req_write(buf, sizeof buf, &req);
     TEST_ASSERT(rc == 0);
 
     rc = ble_hs_test_util_l2cap_rx_payload_flat(conn, chan, buf, sizeof buf);
     TEST_ASSERT(rc != 0);
     ble_hs_process_tx_data_queue();
 
-    ble_hs_att_svr_test_misc_verify_tx_err_rsp(
-        chan, BLE_HS_ATT_OP_FIND_INFO_REQ, 101, BLE_HS_ATT_ERR_INVALID_HANDLE);
+    ble_att_svr_test_misc_verify_tx_err_rsp(
+        chan, BLE_ATT_OP_FIND_INFO_REQ, 101, BLE_ATT_ERR_INVALID_HANDLE);
 
     /*** No attributes. */
     req.bhafq_start_handle = 200;
     req.bhafq_end_handle = 300;
 
-    rc = ble_hs_att_find_info_req_write(buf, sizeof buf, &req);
+    rc = ble_att_find_info_req_write(buf, sizeof buf, &req);
     TEST_ASSERT(rc == 0);
 
     rc = ble_hs_test_util_l2cap_rx_payload_flat(conn, chan, buf, sizeof buf);
     TEST_ASSERT(rc != 0);
     ble_hs_process_tx_data_queue();
 
-    ble_hs_att_svr_test_misc_verify_tx_err_rsp(
-        chan, BLE_HS_ATT_OP_FIND_INFO_REQ, 200, BLE_HS_ATT_ERR_ATTR_NOT_FOUND);
+    ble_att_svr_test_misc_verify_tx_err_rsp(
+        chan, BLE_ATT_OP_FIND_INFO_REQ, 200, BLE_ATT_ERR_ATTR_NOT_FOUND);
 
     /*** Range too late. */
-    rc = ble_hs_att_svr_register(uuid1, 0, &handle1,
-                                 ble_hs_att_svr_test_misc_attr_fn_r_1);
+    rc = ble_att_svr_register(uuid1, 0, &handle1,
+                                 ble_att_svr_test_misc_attr_fn_r_1);
     TEST_ASSERT(rc == 0);
 
     req.bhafq_start_handle = 200;
     req.bhafq_end_handle = 300;
 
-    rc = ble_hs_att_find_info_req_write(buf, sizeof buf, &req);
+    rc = ble_att_find_info_req_write(buf, sizeof buf, &req);
     TEST_ASSERT(rc == 0);
 
     rc = ble_hs_test_util_l2cap_rx_payload_flat(conn, chan, buf, sizeof buf);
     TEST_ASSERT(rc != 0);
     ble_hs_process_tx_data_queue();
 
-    ble_hs_att_svr_test_misc_verify_tx_err_rsp(
-        chan, BLE_HS_ATT_OP_FIND_INFO_REQ, 200, BLE_HS_ATT_ERR_ATTR_NOT_FOUND);
+    ble_att_svr_test_misc_verify_tx_err_rsp(
+        chan, BLE_ATT_OP_FIND_INFO_REQ, 200, BLE_ATT_ERR_ATTR_NOT_FOUND);
 
     /*** One 128-bit entry. */
     req.bhafq_start_handle = handle1;
     req.bhafq_end_handle = handle1;
 
-    rc = ble_hs_att_find_info_req_write(buf, sizeof buf, &req);
+    rc = ble_att_find_info_req_write(buf, sizeof buf, &req);
     TEST_ASSERT(rc == 0);
 
     rc = ble_hs_test_util_l2cap_rx_payload_flat(conn, chan, buf, sizeof buf);
     TEST_ASSERT(rc == 0);
     ble_hs_process_tx_data_queue();
 
-    ble_hs_att_svr_test_misc_verify_tx_find_info_rsp(chan,
-        ((struct ble_hs_att_svr_test_info_entry[]) { {
+    ble_att_svr_test_misc_verify_tx_find_info_rsp(chan,
+        ((struct ble_att_svr_test_info_entry[]) { {
             .handle = handle1,
             .uuid128 = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15},
         }, {
@@ -545,23 +545,23 @@ TEST_CASE(ble_hs_att_svr_test_find_info)
         } }));
 
     /*** Two 128-bit entries. */
-    rc = ble_hs_att_svr_register(uuid2, 0,
+    rc = ble_att_svr_register(uuid2, 0,
                                  &handle2,
-                                 ble_hs_att_svr_test_misc_attr_fn_r_1);
+                                 ble_att_svr_test_misc_attr_fn_r_1);
     TEST_ASSERT(rc == 0);
 
     req.bhafq_start_handle = handle1;
     req.bhafq_end_handle = handle2;
 
-    rc = ble_hs_att_find_info_req_write(buf, sizeof buf, &req);
+    rc = ble_att_find_info_req_write(buf, sizeof buf, &req);
     TEST_ASSERT(rc == 0);
 
     rc = ble_hs_test_util_l2cap_rx_payload_flat(conn, chan, buf, sizeof buf);
     TEST_ASSERT(rc == 0);
     ble_hs_process_tx_data_queue();
 
-    ble_hs_att_svr_test_misc_verify_tx_find_info_rsp(chan,
-        ((struct ble_hs_att_svr_test_info_entry[]) { {
+    ble_att_svr_test_misc_verify_tx_find_info_rsp(chan,
+        ((struct ble_att_svr_test_info_entry[]) { {
             .handle = handle1,
             .uuid128 = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15},
         }, {
@@ -572,23 +572,23 @@ TEST_CASE(ble_hs_att_svr_test_find_info)
         } }));
 
     /*** Two 128-bit entries; 16-bit entry doesn't get sent. */
-    rc = ble_hs_att_svr_register(uuid3, 0,
+    rc = ble_att_svr_register(uuid3, 0,
                                  &handle3,
-                                 ble_hs_att_svr_test_misc_attr_fn_r_1);
+                                 ble_att_svr_test_misc_attr_fn_r_1);
     TEST_ASSERT(rc == 0);
 
     req.bhafq_start_handle = handle1;
     req.bhafq_end_handle = handle3;
 
-    rc = ble_hs_att_find_info_req_write(buf, sizeof buf, &req);
+    rc = ble_att_find_info_req_write(buf, sizeof buf, &req);
     TEST_ASSERT(rc == 0);
 
     rc = ble_hs_test_util_l2cap_rx_payload_flat(conn, chan, buf, sizeof buf);
     TEST_ASSERT(rc == 0);
     ble_hs_process_tx_data_queue();
 
-    ble_hs_att_svr_test_misc_verify_tx_find_info_rsp(chan,
-        ((struct ble_hs_att_svr_test_info_entry[]) { {
+    ble_att_svr_test_misc_verify_tx_find_info_rsp(chan,
+        ((struct ble_att_svr_test_info_entry[]) { {
             .handle = handle1,
             .uuid128 = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15},
         }, {
@@ -602,15 +602,15 @@ TEST_CASE(ble_hs_att_svr_test_find_info)
     req.bhafq_start_handle = handle3;
     req.bhafq_end_handle = handle3;
 
-    rc = ble_hs_att_find_info_req_write(buf, sizeof buf, &req);
+    rc = ble_att_find_info_req_write(buf, sizeof buf, &req);
     TEST_ASSERT(rc == 0);
 
     rc = ble_hs_test_util_l2cap_rx_payload_flat(conn, chan, buf, sizeof buf);
     TEST_ASSERT(rc == 0);
     ble_hs_process_tx_data_queue();
 
-    ble_hs_att_svr_test_misc_verify_tx_find_info_rsp(chan,
-        ((struct ble_hs_att_svr_test_info_entry[]) { {
+    ble_att_svr_test_misc_verify_tx_find_info_rsp(chan,
+        ((struct ble_att_svr_test_info_entry[]) { {
             .handle = handle3,
             .uuid16 = 0x000f,
         }, {
@@ -618,12 +618,12 @@ TEST_CASE(ble_hs_att_svr_test_find_info)
         } }));
 }
 
-TEST_CASE(ble_hs_att_svr_test_find_type_value)
+TEST_CASE(ble_att_svr_test_find_type_value)
 {
-    struct ble_hs_att_find_type_value_req req;
+    struct ble_att_find_type_value_req req;
     struct ble_l2cap_chan *chan;
     struct ble_hs_conn *conn;
-    uint8_t buf[BLE_HS_ATT_FIND_TYPE_VALUE_REQ_MIN_SZ + 2];
+    uint8_t buf[BLE_ATT_FIND_TYPE_VALUE_REQ_MIN_SZ + 2];
     uint16_t handle1;
     uint16_t handle2;
     uint16_t handle3;
@@ -640,7 +640,7 @@ TEST_CASE(ble_hs_att_svr_test_find_type_value)
     };
     int rc;
 
-    ble_hs_att_svr_test_misc_init(&conn, &chan);
+    ble_att_svr_test_misc_init(&conn, &chan);
 
     /* Increase the MTU to 128 bytes to allow testing of long responses. */
     chan->blc_my_mtu = 128;
@@ -648,90 +648,90 @@ TEST_CASE(ble_hs_att_svr_test_find_type_value)
     chan->blc_flags |= BLE_L2CAP_CHAN_F_TXED_MTU;
 
     /* One-time write of the attribute value at the end of the request. */
-    ble_hs_att_svr_test_attr_r_1 = (uint8_t[]){0x99, 0x99};
-    ble_hs_att_svr_test_attr_r_1_len = 2;
-    memcpy(buf + BLE_HS_ATT_FIND_TYPE_VALUE_REQ_MIN_SZ,
-           ble_hs_att_svr_test_attr_r_1,
-           ble_hs_att_svr_test_attr_r_1_len);
+    ble_att_svr_test_attr_r_1 = (uint8_t[]){0x99, 0x99};
+    ble_att_svr_test_attr_r_1_len = 2;
+    memcpy(buf + BLE_ATT_FIND_TYPE_VALUE_REQ_MIN_SZ,
+           ble_att_svr_test_attr_r_1,
+           ble_att_svr_test_attr_r_1_len);
 
     /*** Start handle of 0. */
     req.bhavq_start_handle = 0;
     req.bhavq_end_handle = 0;
     req.bhavq_attr_type = 0x0001;
 
-    rc = ble_hs_att_find_type_value_req_write(buf, sizeof buf, &req);
+    rc = ble_att_find_type_value_req_write(buf, sizeof buf, &req);
     TEST_ASSERT(rc == 0);
 
     rc = ble_hs_test_util_l2cap_rx_payload_flat(conn, chan, buf, sizeof buf);
     TEST_ASSERT(rc != 0);
     ble_hs_process_tx_data_queue();
 
-    ble_hs_att_svr_test_misc_verify_tx_err_rsp(
-        chan, BLE_HS_ATT_OP_FIND_TYPE_VALUE_REQ, 0,
-        BLE_HS_ATT_ERR_INVALID_HANDLE);
+    ble_att_svr_test_misc_verify_tx_err_rsp(
+        chan, BLE_ATT_OP_FIND_TYPE_VALUE_REQ, 0,
+        BLE_ATT_ERR_INVALID_HANDLE);
 
     /*** Start handle > end handle. */
     req.bhavq_start_handle = 101;
     req.bhavq_end_handle = 100;
 
-    rc = ble_hs_att_find_type_value_req_write(buf, sizeof buf, &req);
+    rc = ble_att_find_type_value_req_write(buf, sizeof buf, &req);
     TEST_ASSERT(rc == 0);
 
     rc = ble_hs_test_util_l2cap_rx_payload_flat(conn, chan, buf, sizeof buf);
     TEST_ASSERT(rc != 0);
     ble_hs_process_tx_data_queue();
 
-    ble_hs_att_svr_test_misc_verify_tx_err_rsp(
-        chan, BLE_HS_ATT_OP_FIND_TYPE_VALUE_REQ, 101,
-        BLE_HS_ATT_ERR_INVALID_HANDLE);
+    ble_att_svr_test_misc_verify_tx_err_rsp(
+        chan, BLE_ATT_OP_FIND_TYPE_VALUE_REQ, 101,
+        BLE_ATT_ERR_INVALID_HANDLE);
 
     /*** No attributes. */
     req.bhavq_start_handle = 200;
     req.bhavq_end_handle = 300;
 
-    rc = ble_hs_att_find_type_value_req_write(buf, sizeof buf, &req);
+    rc = ble_att_find_type_value_req_write(buf, sizeof buf, &req);
     TEST_ASSERT(rc == 0);
 
     rc = ble_hs_test_util_l2cap_rx_payload_flat(conn, chan, buf, sizeof buf);
     TEST_ASSERT(rc != 0);
     ble_hs_process_tx_data_queue();
 
-    ble_hs_att_svr_test_misc_verify_tx_err_rsp(
-        chan, BLE_HS_ATT_OP_FIND_TYPE_VALUE_REQ, 200,
-        BLE_HS_ATT_ERR_ATTR_NOT_FOUND);
+    ble_att_svr_test_misc_verify_tx_err_rsp(
+        chan, BLE_ATT_OP_FIND_TYPE_VALUE_REQ, 200,
+        BLE_ATT_ERR_ATTR_NOT_FOUND);
 
     /*** Range too late. */
-    rc = ble_hs_att_svr_register(uuid1, 0, &handle1,
-                                 ble_hs_att_svr_test_misc_attr_fn_r_1);
+    rc = ble_att_svr_register(uuid1, 0, &handle1,
+                                 ble_att_svr_test_misc_attr_fn_r_1);
     TEST_ASSERT(rc == 0);
 
     req.bhavq_start_handle = 200;
     req.bhavq_end_handle = 300;
 
-    rc = ble_hs_att_find_type_value_req_write(buf, sizeof buf, &req);
+    rc = ble_att_find_type_value_req_write(buf, sizeof buf, &req);
     TEST_ASSERT(rc == 0);
 
     rc = ble_hs_test_util_l2cap_rx_payload_flat(conn, chan, buf, sizeof buf);
     TEST_ASSERT(rc != 0);
     ble_hs_process_tx_data_queue();
 
-    ble_hs_att_svr_test_misc_verify_tx_err_rsp(
-        chan, BLE_HS_ATT_OP_FIND_TYPE_VALUE_REQ, 200,
-        BLE_HS_ATT_ERR_ATTR_NOT_FOUND);
+    ble_att_svr_test_misc_verify_tx_err_rsp(
+        chan, BLE_ATT_OP_FIND_TYPE_VALUE_REQ, 200,
+        BLE_ATT_ERR_ATTR_NOT_FOUND);
 
     /*** One entry, one attribute. */
     req.bhavq_start_handle = handle1;
     req.bhavq_end_handle = handle1;
 
-    rc = ble_hs_att_find_type_value_req_write(buf, sizeof buf, &req);
+    rc = ble_att_find_type_value_req_write(buf, sizeof buf, &req);
     TEST_ASSERT(rc == 0);
 
     rc = ble_hs_test_util_l2cap_rx_payload_flat(conn, chan, buf, sizeof buf);
     TEST_ASSERT(rc == 0);
     ble_hs_process_tx_data_queue();
 
-    ble_hs_att_svr_test_misc_verify_tx_find_type_value_rsp(chan,
-        ((struct ble_hs_att_svr_test_type_value_entry[]) { {
+    ble_att_svr_test_misc_verify_tx_find_type_value_rsp(chan,
+        ((struct ble_att_svr_test_type_value_entry[]) { {
             .first = handle1,
             .last = handle1,
         }, {
@@ -739,22 +739,22 @@ TEST_CASE(ble_hs_att_svr_test_find_type_value)
         } }));
 
     /*** One entry, two attributes. */
-    rc = ble_hs_att_svr_register(uuid1, 0, &handle2,
-                                 ble_hs_att_svr_test_misc_attr_fn_r_1);
+    rc = ble_att_svr_register(uuid1, 0, &handle2,
+                                 ble_att_svr_test_misc_attr_fn_r_1);
     TEST_ASSERT(rc == 0);
 
     req.bhavq_start_handle = handle1;
     req.bhavq_end_handle = handle2;
 
-    rc = ble_hs_att_find_type_value_req_write(buf, sizeof buf, &req);
+    rc = ble_att_find_type_value_req_write(buf, sizeof buf, &req);
     TEST_ASSERT(rc == 0);
 
     rc = ble_hs_test_util_l2cap_rx_payload_flat(conn, chan, buf, sizeof buf);
     TEST_ASSERT(rc == 0);
     ble_hs_process_tx_data_queue();
 
-    ble_hs_att_svr_test_misc_verify_tx_find_type_value_rsp(chan,
-        ((struct ble_hs_att_svr_test_type_value_entry[]) { {
+    ble_att_svr_test_misc_verify_tx_find_type_value_rsp(chan,
+        ((struct ble_att_svr_test_type_value_entry[]) { {
             .first = handle1,
             .last = handle2,
         }, {
@@ -762,26 +762,26 @@ TEST_CASE(ble_hs_att_svr_test_find_type_value)
         } }));
 
     /*** Entry 1: two attributes; entry 2: one attribute. */
-    rc = ble_hs_att_svr_register(uuid2, 0, &handle3,
-                                 ble_hs_att_svr_test_misc_attr_fn_r_2);
+    rc = ble_att_svr_register(uuid2, 0, &handle3,
+                                 ble_att_svr_test_misc_attr_fn_r_2);
     TEST_ASSERT(rc == 0);
 
-    rc = ble_hs_att_svr_register(uuid1, 0, &handle4,
-                                 ble_hs_att_svr_test_misc_attr_fn_r_1);
+    rc = ble_att_svr_register(uuid1, 0, &handle4,
+                                 ble_att_svr_test_misc_attr_fn_r_1);
     TEST_ASSERT(rc == 0);
 
     req.bhavq_start_handle = 0x0001;
     req.bhavq_end_handle = 0xffff;
 
-    rc = ble_hs_att_find_type_value_req_write(buf, sizeof buf, &req);
+    rc = ble_att_find_type_value_req_write(buf, sizeof buf, &req);
     TEST_ASSERT(rc == 0);
 
     rc = ble_hs_test_util_l2cap_rx_payload_flat(conn, chan, buf, sizeof buf);
     TEST_ASSERT(rc == 0);
     ble_hs_process_tx_data_queue();
 
-    ble_hs_att_svr_test_misc_verify_tx_find_type_value_rsp(chan,
-        ((struct ble_hs_att_svr_test_type_value_entry[]) { {
+    ble_att_svr_test_misc_verify_tx_find_type_value_rsp(chan,
+        ((struct ble_att_svr_test_type_value_entry[]) { {
             .first = handle1,
             .last = handle2,
         }, {
@@ -792,21 +792,21 @@ TEST_CASE(ble_hs_att_svr_test_find_type_value)
         } }));
 
     /*** Ensure attribute with wrong value is not included. */
-    ble_hs_att_svr_test_attr_r_2 = (uint8_t[]){0x00, 0x00};
-    ble_hs_att_svr_test_attr_r_2_len = 2;
+    ble_att_svr_test_attr_r_2 = (uint8_t[]){0x00, 0x00};
+    ble_att_svr_test_attr_r_2_len = 2;
 
     req.bhavq_start_handle = 0x0001;
     req.bhavq_end_handle = 0xffff;
 
-    rc = ble_hs_att_find_type_value_req_write(buf, sizeof buf, &req);
+    rc = ble_att_find_type_value_req_write(buf, sizeof buf, &req);
     TEST_ASSERT(rc == 0);
 
     rc = ble_hs_test_util_l2cap_rx_payload_flat(conn, chan, buf, sizeof buf);
     TEST_ASSERT(rc == 0);
     ble_hs_process_tx_data_queue();
 
-    ble_hs_att_svr_test_misc_verify_tx_find_type_value_rsp(chan,
-        ((struct ble_hs_att_svr_test_type_value_entry[]) { {
+    ble_att_svr_test_misc_verify_tx_find_type_value_rsp(chan,
+        ((struct ble_att_svr_test_type_value_entry[]) { {
             .first = handle1,
             .last = handle2,
         }, {
@@ -817,21 +817,21 @@ TEST_CASE(ble_hs_att_svr_test_find_type_value)
         } }));
 
     /*** Ensure attribute with wrong type is not included. */
-    rc = ble_hs_att_svr_register(uuid3, 0, &handle5,
-                                 ble_hs_att_svr_test_misc_attr_fn_r_1);
+    rc = ble_att_svr_register(uuid3, 0, &handle5,
+                                 ble_att_svr_test_misc_attr_fn_r_1);
 
     req.bhavq_start_handle = 0x0001;
     req.bhavq_end_handle = 0xffff;
 
-    rc = ble_hs_att_find_type_value_req_write(buf, sizeof buf, &req);
+    rc = ble_att_find_type_value_req_write(buf, sizeof buf, &req);
     TEST_ASSERT(rc == 0);
 
     rc = ble_hs_test_util_l2cap_rx_payload_flat(conn, chan, buf, sizeof buf);
     TEST_ASSERT(rc == 0);
     ble_hs_process_tx_data_queue();
 
-    ble_hs_att_svr_test_misc_verify_tx_find_type_value_rsp(chan,
-        ((struct ble_hs_att_svr_test_type_value_entry[]) { {
+    ble_att_svr_test_misc_verify_tx_find_type_value_rsp(chan,
+        ((struct ble_att_svr_test_type_value_entry[]) { {
             .first = handle1,
             .last = handle2,
         }, {
@@ -842,19 +842,19 @@ TEST_CASE(ble_hs_att_svr_test_find_type_value)
         } }));
 }
 
-TEST_SUITE(ble_hs_att_svr_suite)
+TEST_SUITE(ble_att_svr_suite)
 {
-    ble_hs_att_svr_test_mtu();
-    ble_hs_att_svr_test_read();
-    ble_hs_att_svr_test_write();
-    ble_hs_att_svr_test_find_info();
-    ble_hs_att_svr_test_find_type_value();
+    ble_att_svr_test_mtu();
+    ble_att_svr_test_read();
+    ble_att_svr_test_write();
+    ble_att_svr_test_find_info();
+    ble_att_svr_test_find_type_value();
 }
 
 int
-ble_hs_att_svr_test_all(void)
+ble_att_svr_test_all(void)
 {
-    ble_hs_att_svr_suite();
+    ble_att_svr_suite();
 
     return tu_any_failed;
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/31f0c10b/net/nimble/host/src/test/ble_hs_conn_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_conn_test.c b/net/nimble/host/src/test/ble_hs_conn_test.c
index 5dc46d5..0a876de 100644
--- a/net/nimble/host/src/test/ble_hs_conn_test.c
+++ b/net/nimble/host/src/test/ble_hs_conn_test.c
@@ -22,7 +22,7 @@
 #include "host/ble_hs_test.h"
 #include "host/host_hci.h"
 #include "ble_l2cap.h"
-#include "ble_hs_att.h"
+#include "ble_att.h"
 #include "ble_hs_conn.h"
 #include "ble_hs_ack.h"
 #include "ble_hs_hci_batch.h"
@@ -73,9 +73,9 @@ TEST_CASE(ble_hs_conn_test_master_direct_success)
 
     chan = ble_hs_conn_chan_find(conn, BLE_L2CAP_CID_ATT);
     TEST_ASSERT_FATAL(chan != NULL);
-    TEST_ASSERT(chan->blc_my_mtu == BLE_HS_ATT_MTU_DFLT);
+    TEST_ASSERT(chan->blc_my_mtu == BLE_ATT_MTU_DFLT);
     TEST_ASSERT(chan->blc_peer_mtu == 0);
-    TEST_ASSERT(chan->blc_default_mtu == BLE_HS_ATT_MTU_DFLT);
+    TEST_ASSERT(chan->blc_default_mtu == BLE_ATT_MTU_DFLT);
 }
 
 TEST_CASE(ble_hs_conn_test_master_direct_hci_errors)
@@ -172,9 +172,9 @@ TEST_CASE(ble_hs_conn_test_slave_direct_success)
 
     chan = ble_hs_conn_chan_find(conn, BLE_L2CAP_CID_ATT);
     TEST_ASSERT_FATAL(chan != NULL);
-    TEST_ASSERT(chan->blc_my_mtu == BLE_HS_ATT_MTU_DFLT);
+    TEST_ASSERT(chan->blc_my_mtu == BLE_ATT_MTU_DFLT);
     TEST_ASSERT(chan->blc_peer_mtu == 0);
-    TEST_ASSERT(chan->blc_default_mtu == BLE_HS_ATT_MTU_DFLT);
+    TEST_ASSERT(chan->blc_default_mtu == BLE_ATT_MTU_DFLT);
 }
 
 TEST_SUITE(conn_suite)

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/31f0c10b/net/nimble/host/src/test/ble_hs_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_test.c b/net/nimble/host/src/test/ble_hs_test.c
index 6bccf5f..81a5a5a 100644
--- a/net/nimble/host/src/test/ble_hs_test.c
+++ b/net/nimble/host/src/test/ble_hs_test.c
@@ -40,8 +40,8 @@ main(void)
     tu_init();
 
     l2cap_test_all();
-    ble_hs_att_svr_test_all();
-    ble_hs_att_clt_test_all();
+    ble_att_svr_test_all();
+    ble_att_clt_test_all();
     ble_host_hci_test_all();
     ble_hs_conn_test_all();
     ble_gap_test_all();



[2/3] incubator-mynewt-larva git commit: Rename ble_hs_att_* to ble_att_*

Posted by cc...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/31f0c10b/net/nimble/host/src/ble_hs_att.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_att.h b/net/nimble/host/src/ble_hs_att.h
deleted file mode 100644
index d0d0032..0000000
--- a/net/nimble/host/src/ble_hs_att.h
+++ /dev/null
@@ -1,171 +0,0 @@
-/**
- * Copyright (c) 2015 Runtime Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef H_BLE_HS_ATT_
-#define H_BLE_HS_ATT_
-
-#include <inttypes.h>
-#include "os/queue.h"
-struct os_mbuf;
-struct ble_hs_conn;
-struct ble_l2cap_chan;
-struct ble_hs_att_find_info_req;
-struct ble_hs_att_error_rsp;
-struct ble_hs_att_mtu_cmd;
-struct ble_hs_att_read_req;
-struct ble_hs_att_read_group_type_req;
-struct ble_hs_att_read_group_type_rsp;
-
-#define BLE_HS_ATT_MTU_DFLT         23  /* Also the minimum. */
-#define BLE_HS_ATT_MTU_MAX          256 /* XXX: I'm making this up! */
-
-#define BLE_HS_ATT_ERR_INVALID_HANDLE       0x01
-#define BLE_HS_ATT_ERR_INVALID_PDU          0x04
-#define BLE_HS_ATT_ERR_REQ_NOT_SUPPORTED    0x06
-#define BLE_HS_ATT_ERR_ATTR_NOT_FOUND       0x0a
-#define BLE_HS_ATT_ERR_UNLIKELY             0x0e
-#define BLE_HS_ATT_ERR_INSUFFICIENT_RES     0x11
-
-union ble_hs_att_svr_handle_arg {
-    struct {
-        void *attr_data;
-        int attr_len;
-    } aha_read;
-
-    struct {
-        struct os_mbuf *om;
-        int attr_len;
-    } aha_write;
-};
-
-struct ble_hs_att_svr_entry;
-
-/**
- * Called from ble_hs_att_svr_walk().  Called on each entry in the 
- * ble_hs_att_svr_list.
- *
- * @param Contains the current ble_hs_att being iterated through
- * @param The user supplied argument to ble_hs_att_svr_walk()
- *
- * @return 0 on continue, 1 on stop
- */
-typedef int (*ble_hs_att_svr_walk_func_t)(struct ble_hs_att_svr_entry *entry,
-                                          void *arg);
-
-/**
- * Handles a host attribute request.
- *
- * @param entry                 The host attribute being requested.
- * @param op                    The operation being performed on the attribute.
- * @param arg                   The request data associated with that host
- *                                  attribute.
- *
- * @return                      0 on success;
- *                              One of the BLE_HS_ATT_ERR_[...] codes on
- *                                  failure.
- */
-typedef int ble_hs_att_svr_handle_func(struct ble_hs_att_svr_entry *entry,
-                                       uint8_t op,
-                                       union ble_hs_att_svr_handle_arg *arg);
-
-#define HA_FLAG_PERM_READ            (1 << 0)
-#define HA_FLAG_PERM_WRITE           (1 << 1) 
-#define HA_FLAG_PERM_RW              (1 << 2)
-#define HA_FLAG_ENC_REQ              (1 << 3)
-#define HA_FLAG_AUTHENTICATION_REQ   (1 << 4)
-#define HA_FLAG_AUTHORIZATION_REQ    (1 << 5)
-
-struct ble_hs_att_svr_entry {
-    STAILQ_ENTRY(ble_hs_att_svr_entry) ha_next;
-
-    uint8_t ha_uuid[16];
-    uint8_t ha_flags;
-    uint8_t ha_pad1;
-    uint16_t ha_handle_id;
-    ble_hs_att_svr_handle_func *ha_fn;
-};
-
-#define HA_OPCODE_METHOD_START (0)
-#define HA_OPCODE_METHOD_END (5)
-#define HA_OPCODE_COMMAND_FLAG (1 << 6) 
-#define HA_OPCODE_AUTH_SIG_FLAG (1 << 7) 
-
-struct ble_hs_att_clt_entry {
-    SLIST_ENTRY(ble_hs_att_clt_entry) bhac_next;
-    uint16_t bhac_handle_id;
-    uint8_t bhac_uuid[16];
-};
-
-SLIST_HEAD(ble_hs_att_clt_entry_list, ble_hs_att_clt_entry);
-
-/*** @gen */
-struct ble_l2cap_chan *ble_hs_att_create_chan(void);
-void ble_hs_att_set_peer_mtu(struct ble_l2cap_chan *chan, uint16_t peer_mtu);
-
-/*** @svr */
-int ble_hs_att_svr_register(uint8_t *uuid, uint8_t flags, uint16_t *handle_id,
-                            ble_hs_att_svr_handle_func *fn);
-
-
-int ble_hs_att_svr_rx_mtu(struct ble_hs_conn *conn,
-                          struct ble_l2cap_chan *chan,
-                          struct os_mbuf *om);
-int ble_hs_att_svr_rx_find_info(struct ble_hs_conn *conn,
-                                struct ble_l2cap_chan *chan,
-                                struct os_mbuf *om);
-int ble_hs_att_svr_rx_find_type_value(struct ble_hs_conn *conn,
-                                      struct ble_l2cap_chan *chan,
-                                      struct os_mbuf *om);
-int ble_hs_att_svr_rx_read_type(struct ble_hs_conn *conn,
-                                struct ble_l2cap_chan *chan,
-                                struct os_mbuf *om);
-int ble_hs_att_svr_rx_read(struct ble_hs_conn *conn,
-                           struct ble_l2cap_chan *chan,
-                           struct os_mbuf *om);
-int ble_hs_att_svr_rx_write(struct ble_hs_conn *conn,
-                            struct ble_l2cap_chan *chan,
-                            struct os_mbuf *om);
-int ble_hs_att_svr_init(void);
-
-/*** @clt */
-void ble_hs_att_clt_entry_list_free(struct ble_hs_att_clt_entry_list *list);
-int ble_hs_att_clt_entry_insert(struct ble_hs_conn *conn, uint16_t handle_id,
-                                uint8_t *uuid);
-uint16_t ble_hs_att_clt_find_entry_uuid128(struct ble_hs_conn *conn,
-                                           void *uuid128);
-uint16_t ble_hs_att_clt_find_entry_uuid16(struct ble_hs_conn *conn,
-                                          uint16_t uuid16);
-int ble_hs_att_clt_tx_mtu(struct ble_hs_conn *conn,
-                          struct ble_hs_att_mtu_cmd *req);
-int ble_hs_att_clt_rx_mtu(struct ble_hs_conn *conn,
-                          struct ble_l2cap_chan *chan,
-                          struct os_mbuf *om);
-int ble_hs_att_clt_tx_read(struct ble_hs_conn *conn,
-                           struct ble_hs_att_read_req *req);
-int ble_hs_att_clt_tx_find_info(struct ble_hs_conn *conn,
-                                struct ble_hs_att_find_info_req *req);
-int ble_hs_att_clt_rx_find_info(struct ble_hs_conn *conn,
-                                struct ble_l2cap_chan *chan,
-                                struct os_mbuf *om);
-int ble_hs_att_clt_tx_read_group_type(
-    struct ble_hs_conn *conn, struct ble_hs_att_read_group_type_req *req,
-    void *uuid128);
-int ble_hs_att_clt_rx_read_group_type_rsp(struct ble_hs_conn *conn,
-                                          struct ble_l2cap_chan *chan,
-                                          struct os_mbuf *om);
-int ble_hs_att_clt_init(void);
-
-#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/31f0c10b/net/nimble/host/src/ble_hs_att_clt.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_att_clt.c b/net/nimble/host/src/ble_hs_att_clt.c
deleted file mode 100644
index fb73971..0000000
--- a/net/nimble/host/src/ble_hs_att_clt.c
+++ /dev/null
@@ -1,514 +0,0 @@
-/**
- * Copyright (c) 2015 Runtime Inc.
- *
- * Licensed 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 <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <assert.h>
-#include "os/os_mempool.h"
-#include "nimble/ble.h"
-#include "host/ble_gatt.h"
-#include "host/ble_hs.h"
-#include "ble_hs_uuid.h"
-#include "ble_hs_conn.h"
-#include "ble_hs_att_cmd.h"
-#include "ble_hs_att.h"
-
-#define BLE_HS_ATT_CLT_NUM_ENTRIES  128
-static void *ble_hs_att_clt_entry_mem;
-static struct os_mempool ble_hs_att_clt_entry_pool;
-
-static struct ble_hs_att_clt_entry *
-ble_hs_att_clt_entry_alloc(void)
-{
-    struct ble_hs_att_clt_entry *entry;
-
-    entry = os_memblock_get(&ble_hs_att_clt_entry_pool);
-    if (entry != NULL) {
-        memset(entry, 0, sizeof *entry);
-    }
-
-    return entry;
-}
-
-static void
-ble_hs_att_clt_entry_free(struct ble_hs_att_clt_entry *entry)
-{
-    int rc;
-
-    rc = os_memblock_put(&ble_hs_att_clt_entry_pool, entry);
-    assert(rc == 0);
-}
-
-void
-ble_hs_att_clt_entry_list_free(struct ble_hs_att_clt_entry_list *list)
-{
-    struct ble_hs_att_clt_entry *entry;
-
-    while ((entry = SLIST_FIRST(list)) != NULL) {
-        SLIST_REMOVE_HEAD(list, bhac_next);
-        ble_hs_att_clt_entry_free(entry);
-    }
-}
-
-int
-ble_hs_att_clt_entry_insert(struct ble_hs_conn *conn, uint16_t handle_id,
-                            uint8_t *uuid)
-{
-    struct ble_hs_att_clt_entry *entry;
-    struct ble_hs_att_clt_entry *prev;
-    struct ble_hs_att_clt_entry *cur;
-
-    /* XXX: Probably need to lock a semaphore here. */
-
-    entry = ble_hs_att_clt_entry_alloc();
-    if (entry == NULL) {
-        return ENOMEM;
-    }
-
-    entry->bhac_handle_id = handle_id;
-    memcpy(entry->bhac_uuid, uuid, sizeof entry->bhac_uuid);
-
-    prev = NULL;
-    SLIST_FOREACH(cur, &conn->bhc_att_clt_list, bhac_next) {
-        if (cur->bhac_handle_id == handle_id) {
-            return EEXIST;
-        }
-        if (cur->bhac_handle_id > handle_id) {
-            break;
-        }
-
-        prev = cur;
-    }
-
-    if (prev == NULL) {
-        SLIST_INSERT_HEAD(&conn->bhc_att_clt_list, entry, bhac_next);
-    } else {
-        SLIST_INSERT_AFTER(prev, entry, bhac_next);
-    }
-
-    return 0;
-}
-
-uint16_t
-ble_hs_att_clt_find_entry_uuid128(struct ble_hs_conn *conn, void *uuid128)
-{
-    struct ble_hs_att_clt_entry *entry;
-    int rc;
-
-    SLIST_FOREACH(entry, &conn->bhc_att_clt_list, bhac_next) {
-        rc = memcmp(entry->bhac_uuid, uuid128, 16);
-        if (rc == 0) {
-            return entry->bhac_handle_id;
-        }
-    }
-
-    return 0;
-}
-
-static int
-ble_hs_att_clt_prep_req(struct ble_hs_conn *conn, struct ble_l2cap_chan **chan,
-                        struct os_mbuf **txom, uint16_t initial_sz)
-{
-    void *buf;
-    int rc;
-
-    *chan = ble_hs_conn_chan_find(conn, BLE_L2CAP_CID_ATT);
-    assert(*chan != NULL);
-
-    *txom = os_mbuf_get_pkthdr(&ble_hs_mbuf_pool, 0);
-    if (*txom == NULL) {
-        rc = ENOMEM;
-        goto err;
-    }
-
-    buf = os_mbuf_extend(*txom, initial_sz);
-    if (buf == NULL) {
-        rc = ENOMEM;
-        goto err;
-    }
-
-    /* The caller expects the initial buffer to be at the start of the mbuf. */
-    assert(buf == (*txom)->om_data);
-
-    return 0;
-
-err:
-    os_mbuf_free_chain(*txom);
-    *txom = NULL;
-    return rc;
-}
-
-uint16_t
-ble_hs_att_clt_find_entry_uuid16(struct ble_hs_conn *conn, uint16_t uuid16)
-{
-    uint8_t uuid128[16];
-    uint16_t handle_id;
-    int rc;
-
-    rc = ble_hs_uuid_from_16bit(uuid16, uuid128);
-    if (rc != 0) {
-        return 0;
-    }
-
-    handle_id = ble_hs_att_clt_find_entry_uuid128(conn, uuid128);
-    return handle_id;
-}
-
-int
-ble_hs_att_clt_tx_mtu(struct ble_hs_conn *conn, struct ble_hs_att_mtu_cmd *req)
-{
-    struct ble_l2cap_chan *chan;
-    struct os_mbuf *txom;
-    int rc;
-
-    txom = NULL;
-
-    if (req->bhamc_mtu < BLE_HS_ATT_MTU_DFLT) {
-        rc = EINVAL;
-        goto err;
-    }
-
-    rc = ble_hs_att_clt_prep_req(conn, &chan, &txom, BLE_HS_ATT_MTU_CMD_SZ);
-    if (rc != 0) {
-        goto err;
-    }
-
-    rc = ble_hs_att_mtu_req_write(txom->om_data, txom->om_len, req);
-    if (rc != 0) {
-        goto err;
-    }
-
-    rc = ble_l2cap_tx(chan, txom);
-    txom = NULL;
-    if (rc != 0) {
-        goto err;
-    }
-
-    return 0;
-
-err:
-    os_mbuf_free_chain(txom);
-    return rc;
-}
-
-int
-ble_hs_att_clt_rx_mtu(struct ble_hs_conn *conn,
-                      struct ble_l2cap_chan *chan,
-                      struct os_mbuf *om)
-{
-    struct ble_hs_att_mtu_cmd rsp;
-    int rc;
-
-    /* XXX: Pull up om */
-
-    rc = ble_hs_att_mtu_cmd_parse(om->om_data, om->om_len, &rsp);
-    if (rc != 0) {
-        return rc;
-    }
-
-    ble_hs_att_set_peer_mtu(chan, rsp.bhamc_mtu);
-
-    ble_gatt_rx_mtu(conn, ble_l2cap_chan_mtu(chan));
-
-    return 0;
-}
-
-int
-ble_hs_att_clt_tx_find_info(struct ble_hs_conn *conn,
-                            struct ble_hs_att_find_info_req *req)
-{
-    struct ble_l2cap_chan *chan;
-    struct os_mbuf *txom;
-    int rc;
-
-    txom = NULL;
-
-    if (req->bhafq_start_handle == 0 ||
-        req->bhafq_start_handle > req->bhafq_end_handle) {
-
-        rc = EINVAL;
-        goto err;
-    }
-
-    rc = ble_hs_att_clt_prep_req(conn, &chan, &txom,
-                                 BLE_HS_ATT_FIND_INFO_REQ_SZ);
-    if (rc != 0) {
-        goto err;
-    }
-
-    rc = ble_hs_att_find_info_req_write(txom->om_data, txom->om_len, req);
-    if (rc != 0) {
-        goto err;
-    }
-
-    rc = ble_l2cap_tx(chan, txom);
-    txom = NULL;
-    if (rc != 0) {
-        goto err;
-    }
-
-    return 0;
-
-err:
-    os_mbuf_free_chain(txom);
-    return rc;
-}
-
-int
-ble_hs_att_clt_rx_find_info(struct ble_hs_conn *conn,
-                            struct ble_l2cap_chan *chan,
-                            struct os_mbuf *om)
-{
-    struct ble_hs_att_find_info_rsp rsp;
-    uint16_t handle_id;
-    uint16_t uuid16;
-    uint8_t uuid128[16];
-    int off;
-    int rc;
-
-    /* XXX: Pull up om */
-
-    rc = ble_hs_att_find_info_rsp_parse(om->om_data, om->om_len, &rsp);
-    if (rc != 0) {
-        return rc;
-    }
-
-    handle_id = 0;
-    off = BLE_HS_ATT_FIND_INFO_RSP_MIN_SZ;
-    while (off < OS_MBUF_PKTHDR(om)->omp_len) {
-        rc = os_mbuf_copydata(om, off, 2, &handle_id);
-        if (rc != 0) {
-            rc = EINVAL;
-            goto done;
-        }
-        off += 2;
-        handle_id = le16toh(&handle_id);
-
-        switch (rsp.bhafp_format) {
-        case BLE_HS_ATT_FIND_INFO_RSP_FORMAT_16BIT:
-            rc = os_mbuf_copydata(om, off, 2, &uuid16);
-            if (rc != 0) {
-                rc = EINVAL;
-                goto done;
-            }
-            off += 2;
-            uuid16 = le16toh(&uuid16);
-
-            rc = ble_hs_uuid_from_16bit(uuid16, uuid128);
-            if (rc != 0) {
-                rc = EINVAL;
-                goto done;
-            }
-            break;
-
-        case BLE_HS_ATT_FIND_INFO_RSP_FORMAT_128BIT:
-            rc = os_mbuf_copydata(om, off, 16, &uuid128);
-            if (rc != 0) {
-                rc = EINVAL;
-                goto done;
-            }
-            off += 16;
-            break;
-
-        default:
-            rc = EINVAL;
-            goto done;
-        }
-
-        rc = ble_hs_att_clt_entry_insert(conn, handle_id, uuid128);
-        if (rc != 0) {
-            return rc;
-        }
-    }
-
-    rc = 0;
-
-done:
-    ble_gatt_rx_find_info(conn, -rc, handle_id);
-    return rc;
-}
-
-int
-ble_hs_att_clt_tx_read(struct ble_hs_conn *conn,
-                       struct ble_hs_att_read_req *req)
-{
-    struct ble_l2cap_chan *chan;
-    struct os_mbuf *txom;
-    int rc;
-
-    txom = NULL;
-
-    if (req->bharq_handle == 0) {
-        rc = EINVAL;
-        goto err;
-    }
-
-    rc = ble_hs_att_clt_prep_req(conn, &chan, &txom, BLE_HS_ATT_READ_REQ_SZ);
-    if (rc != 0) {
-        goto err;
-    }
-
-    rc = ble_hs_att_read_req_write(txom->om_data, txom->om_len, req);
-    if (rc != 0) {
-        goto err;
-    }
-
-    rc = ble_l2cap_tx(chan, txom);
-    txom = NULL;
-    if (rc != 0) {
-        goto err;
-    }
-
-    return 0;
-
-err:
-    os_mbuf_free_chain(txom);
-    return rc;
-}
-
-int
-ble_hs_att_clt_tx_read_group_type(struct ble_hs_conn *conn,
-                                  struct ble_hs_att_read_group_type_req *req,
-                                  void *uuid128)
-{
-    struct ble_l2cap_chan *chan;
-    struct os_mbuf *txom;
-    int rc;
-
-    txom = NULL;
-
-    if (req->bhagq_start_handle == 0 ||
-        req->bhagq_start_handle > req->bhagq_end_handle) {
-
-        rc = EINVAL;
-        goto err;
-    }
-
-    rc = ble_hs_att_clt_prep_req(conn, &chan, &txom,
-                                 BLE_HS_ATT_READ_GROUP_TYPE_REQ_BASE_SZ);
-    if (rc != 0) {
-        goto err;
-    }
-
-    rc = ble_hs_att_read_group_type_req_write(txom->om_data, txom->om_len,
-                                              req);
-    if (rc != 0) {
-        goto err;
-    }
-
-    rc = ble_hs_uuid_append(txom, uuid128);
-    if (rc != 0) {
-        goto err;
-    }
-
-    rc = ble_l2cap_tx(chan, txom);
-    txom = NULL;
-    if (rc != 0) {
-        goto err;
-    }
-
-    return 0;
-
-err:
-    os_mbuf_free_chain(txom);
-    return rc;
-}
-
-struct ble_hs_att_clt_adata {
-    uint16_t att_handle;
-    uint16_t end_group_handle;
-    void *value;
-};
-
-static int
-ble_hs_att_clt_parse_attribute_data(struct os_mbuf *om, int data_len,
-                                    struct ble_hs_att_clt_adata *adata)
-{
-    /* XXX: Pull up om */
-
-    adata->att_handle = le16toh(om->om_data + 0);
-    adata->end_group_handle = le16toh(om->om_data + 2);
-    adata->value = om->om_data + 6;
-
-    return 0;
-}
-
-int
-ble_hs_att_clt_rx_read_group_type_rsp(struct ble_hs_conn *conn,
-                                      struct ble_l2cap_chan *chan,
-                                      struct os_mbuf *om)
-{
-    struct ble_hs_att_read_group_type_rsp rsp;
-    struct ble_hs_att_clt_adata adata;
-    int rc;
-
-    /* XXX: Pull up om */
-
-    rc = ble_hs_att_read_group_type_rsp_parse(om->om_data, om->om_len, &rsp);
-    if (rc != 0) {
-        return rc;
-    }
-
-    /* XXX: Verify group handle is valid. */
-
-    while (OS_MBUF_PKTHDR(om)->omp_len > 0) {
-        rc = ble_hs_att_clt_parse_attribute_data(om, rsp.bhagp_length, &adata);
-        if (rc != 0) {
-            break;
-        }
-
-        /* Save attribute mapping? */
-
-        /* XXX: Pass adata to GATT callback. */
-
-        os_mbuf_adj(om, rsp.bhagp_length);
-    }
-
-    return 0;
-}
-
-int
-ble_hs_att_clt_init(void)
-{
-    int rc;
-
-    free(ble_hs_att_clt_entry_mem);
-    ble_hs_att_clt_entry_mem = malloc(
-        OS_MEMPOOL_BYTES(BLE_HS_ATT_CLT_NUM_ENTRIES,
-                         sizeof (struct ble_hs_att_clt_entry)));
-    if (ble_hs_att_clt_entry_mem == NULL) {
-        rc = ENOMEM;
-        goto err;
-    }
-
-    rc = os_mempool_init(&ble_hs_att_clt_entry_pool,
-                         BLE_HS_ATT_CLT_NUM_ENTRIES,
-                         sizeof (struct ble_hs_att_clt_entry),
-                         ble_hs_att_clt_entry_mem,
-                         "ble_hs_att_clt_entry_pool");
-    if (rc != 0) {
-        goto err;
-    }
-
-    return 0;
-
-err:
-    free(ble_hs_att_clt_entry_mem);
-    ble_hs_att_clt_entry_mem = NULL;
-
-    return rc;
-}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/31f0c10b/net/nimble/host/src/ble_hs_att_cmd.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_att_cmd.c b/net/nimble/host/src/ble_hs_att_cmd.c
deleted file mode 100644
index 5cd5746..0000000
--- a/net/nimble/host/src/ble_hs_att_cmd.c
+++ /dev/null
@@ -1,482 +0,0 @@
-/**
- * Copyright (c) 2015 Runtime Inc.
- *
- * Licensed 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 "os/os.h"
-#include "nimble/ble.h"
-#include "ble_hs_uuid.h"
-#include "ble_l2cap.h"
-#include "ble_hs_att_cmd.h"
-
-int
-ble_hs_att_error_rsp_parse(void *payload, int len,
-                           struct ble_hs_att_error_rsp *rsp)
-{
-    uint8_t *u8ptr;
-
-    if (len < BLE_HS_ATT_ERROR_RSP_SZ) {
-        return EMSGSIZE;
-    }
-
-    u8ptr = payload;
-
-    if (u8ptr[0] != BLE_HS_ATT_OP_ERROR_RSP) {
-        return EINVAL;
-    }
-
-    rsp->bhaep_req_op = u8ptr[1];
-    rsp->bhaep_handle = le16toh(u8ptr + 2);
-    rsp->bhaep_error_code = u8ptr[4];
-
-    return 0;
-}
-
-int
-ble_hs_att_error_rsp_write(void *payload, int len,
-                           struct ble_hs_att_error_rsp *rsp)
-{
-    uint8_t *u8ptr;
-
-    if (len < BLE_HS_ATT_ERROR_RSP_SZ) {
-        return EMSGSIZE;
-    }
-
-    u8ptr = payload;
-
-    u8ptr[0] = BLE_HS_ATT_OP_ERROR_RSP;
-    u8ptr[1] = rsp->bhaep_req_op;
-    htole16(u8ptr + 2, rsp->bhaep_handle);
-    u8ptr[4] = rsp->bhaep_error_code;
-
-    return 0;
-}
-
-int
-ble_hs_att_mtu_cmd_parse(void *payload, int len,
-                         struct ble_hs_att_mtu_cmd *cmd)
-{
-    uint8_t *u8ptr;
-
-    if (len < BLE_HS_ATT_MTU_CMD_SZ) {
-        return EMSGSIZE;
-    }
-
-    u8ptr = payload;
-
-    if (u8ptr[0] != BLE_HS_ATT_OP_MTU_REQ &&
-        u8ptr[0] != BLE_HS_ATT_OP_MTU_RSP) {
-
-        return EINVAL;
-    }
-
-    cmd->bhamc_mtu = le16toh(u8ptr + 1);
-
-    return 0;
-}
-
-int
-ble_hs_att_mtu_req_write(void *payload, int len,
-                         struct ble_hs_att_mtu_cmd *cmd)
-{
-    uint8_t *u8ptr;
-
-    if (len < BLE_HS_ATT_MTU_CMD_SZ) {
-        return EMSGSIZE;
-    }
-
-    u8ptr = payload;
-
-    u8ptr[0] = BLE_HS_ATT_OP_MTU_REQ;
-    htole16(u8ptr + 1, cmd->bhamc_mtu);
-
-    return 0;
-}
-
-int
-ble_hs_att_mtu_rsp_write(void *payload, int len,
-                         struct ble_hs_att_mtu_cmd *cmd)
-{
-    uint8_t *u8ptr;
-
-    if (len < BLE_HS_ATT_MTU_CMD_SZ) {
-        return EMSGSIZE;
-    }
-
-    u8ptr = payload;
-
-    u8ptr[0] = BLE_HS_ATT_OP_MTU_RSP;
-    htole16(u8ptr + 1, cmd->bhamc_mtu);
-
-    return 0;
-}
-
-int
-ble_hs_att_find_info_req_parse(void *payload, int len,
-                               struct ble_hs_att_find_info_req *req)
-{
-    uint8_t *u8ptr;
-
-    if (len < BLE_HS_ATT_FIND_INFO_REQ_SZ) {
-        return EMSGSIZE;
-    }
-
-    u8ptr = payload;
-
-    if (u8ptr[0] != BLE_HS_ATT_OP_FIND_INFO_REQ) {
-        return EINVAL;
-    }
-
-    req->bhafq_start_handle = le16toh(u8ptr + 1);
-    req->bhafq_end_handle = le16toh(u8ptr + 3);
-
-    return 0;
-}
-
-int
-ble_hs_att_find_info_req_write(void *payload, int len,
-                               struct ble_hs_att_find_info_req *req)
-{
-    uint8_t *u8ptr;
-
-    if (len < BLE_HS_ATT_FIND_INFO_REQ_SZ) {
-        return EMSGSIZE;
-    }
-
-    u8ptr = payload;
-
-    u8ptr[0] = BLE_HS_ATT_OP_FIND_INFO_REQ;
-    htole16(u8ptr + 1, req->bhafq_start_handle);
-    htole16(u8ptr + 3, req->bhafq_end_handle);
-
-    return 0;
-}
-
-int
-ble_hs_att_find_info_rsp_parse(void *payload, int len,
-                               struct ble_hs_att_find_info_rsp *rsp)
-{
-    uint8_t *u8ptr;
-
-    if (len < BLE_HS_ATT_FIND_INFO_RSP_MIN_SZ) {
-        return EMSGSIZE;
-    }
-
-    u8ptr = payload;
-
-    if (u8ptr[0] != BLE_HS_ATT_OP_FIND_INFO_RSP) {
-        return EINVAL;
-    }
-
-    rsp->bhafp_format = u8ptr[1];
-
-    return 0;
-}
-
-int
-ble_hs_att_find_info_rsp_write(void *payload, int len,
-                               struct ble_hs_att_find_info_rsp *rsp)
-{
-    uint8_t *u8ptr;
-
-    if (len < BLE_HS_ATT_FIND_INFO_RSP_MIN_SZ) {
-        return EMSGSIZE;
-    }
-
-    u8ptr = payload;
-
-    u8ptr[0] = BLE_HS_ATT_OP_FIND_INFO_RSP;
-    u8ptr[1] = rsp->bhafp_format;
-
-    return 0;
-}
-
-int
-ble_hs_att_find_type_value_req_parse(
-    void *payload, int len, struct ble_hs_att_find_type_value_req *req)
-{
-    uint8_t *u8ptr;
-
-    if (len < BLE_HS_ATT_FIND_TYPE_VALUE_REQ_MIN_SZ) {
-        return EMSGSIZE;
-    }
-
-    u8ptr = payload;
-
-    if (u8ptr[0] != BLE_HS_ATT_OP_FIND_TYPE_VALUE_REQ) {
-        return EINVAL;
-    }
-
-    req->bhavq_start_handle = le16toh(u8ptr + 1);
-    req->bhavq_end_handle = le16toh(u8ptr + 3);
-    req->bhavq_attr_type = le16toh(u8ptr + 5);
-
-    return 0;
-}
-
-int
-ble_hs_att_find_type_value_req_write(
-    void *payload, int len, struct ble_hs_att_find_type_value_req *req)
-{
-    uint8_t *u8ptr;
-
-    if (len < BLE_HS_ATT_FIND_TYPE_VALUE_REQ_MIN_SZ) {
-        return EMSGSIZE;
-    }
-
-    u8ptr = payload;
-
-    u8ptr[0] = BLE_HS_ATT_OP_FIND_TYPE_VALUE_REQ;
-    htole16(u8ptr + 1, req->bhavq_start_handle);
-    htole16(u8ptr + 3, req->bhavq_end_handle);
-    htole16(u8ptr + 5, req->bhavq_attr_type);
-
-    return 0;
-}
-
-int
-ble_hs_att_read_type_req_parse(void *payload, int len,
-                               struct ble_hs_att_read_type_req *req)
-{
-    uint8_t *u8ptr;
-
-    if (len < BLE_HS_ATT_READ_TYPE_REQ_MIN_SZ) {
-        return EMSGSIZE;
-    }
-
-    u8ptr = payload;
-
-    if (u8ptr[0] != BLE_HS_ATT_OP_READ_TYPE_REQ) {
-        return EINVAL;
-    }
-
-    req->bhatq_start_handle = le16toh(u8ptr + 1);
-    req->bhatq_end_handle = le16toh(u8ptr + 3);
-
-    return 0;
-}
-
-int
-ble_hs_att_read_type_req_write(void *payload, int len,
-                               struct ble_hs_att_read_type_req *req)
-{
-    uint8_t *u8ptr;
-
-    if (len < BLE_HS_ATT_READ_TYPE_REQ_MIN_SZ) {
-        return EMSGSIZE;
-    }
-
-    u8ptr = payload;
-
-    u8ptr[0] = BLE_HS_ATT_OP_READ_TYPE_REQ;
-    htole16(u8ptr + 1, req->bhatq_start_handle);
-    htole16(u8ptr + 3, req->bhatq_end_handle);
-
-    return 0;
-}
-
-int
-ble_hs_att_read_type_rsp_parse(void *payload, int len,
-                               struct ble_hs_att_read_type_rsp *rsp)
-{
-    uint8_t *u8ptr;
-
-    if (len < BLE_HS_ATT_READ_TYPE_RSP_MIN_SZ) {
-        return EMSGSIZE;
-    }
-
-    u8ptr = payload;
-
-    rsp->bhatp_len = u8ptr[1];
-
-    return 0;
-}
-
-int
-ble_hs_att_read_type_rsp_write(void *payload, int len,
-                               struct ble_hs_att_read_type_rsp *rsp)
-{
-    uint8_t *u8ptr;
-
-    if (len < BLE_HS_ATT_READ_TYPE_RSP_MIN_SZ) {
-        return EMSGSIZE;
-    }
-
-    u8ptr = payload;
-
-    u8ptr[0] = BLE_HS_ATT_OP_READ_TYPE_RSP;
-    u8ptr[1] = rsp->bhatp_len;
-
-    return 0;
-}
-
-int
-ble_hs_att_read_req_parse(void *payload, int len,
-                          struct ble_hs_att_read_req *req)
-{
-    uint8_t *u8ptr;
-
-    if (len < BLE_HS_ATT_READ_REQ_SZ) {
-        return EMSGSIZE;
-    }
-
-    u8ptr = payload;
-
-    if (u8ptr[0] != BLE_HS_ATT_OP_READ_REQ) {
-        return EINVAL;
-    }
-
-    req->bharq_handle = le16toh(u8ptr + 1);
-
-    return 0;
-}
-
-int
-ble_hs_att_read_req_write(void *payload, int len,
-                          struct ble_hs_att_read_req *req)
-{
-    uint8_t *u8ptr;
-
-    if (len < BLE_HS_ATT_READ_REQ_SZ) {
-        return EMSGSIZE;
-    }
-
-    u8ptr = payload;
-
-    u8ptr[0] = BLE_HS_ATT_OP_READ_REQ;
-    htole16(u8ptr + 1, req->bharq_handle);
-
-    return 0;
-}
-
-int
-ble_hs_att_read_group_type_req_parse(
-    void *payload, int len, struct ble_hs_att_read_group_type_req *req)
-{
-    uint8_t *u8ptr;
-
-    if (len < BLE_HS_ATT_READ_GROUP_TYPE_REQ_BASE_SZ) {
-        return EMSGSIZE;
-    }
-
-    u8ptr = payload;
-
-    if (u8ptr[0] != BLE_HS_ATT_OP_READ_GROUP_TYPE_REQ) {
-        return EINVAL;
-    }
-
-    req->bhagq_start_handle = le16toh(u8ptr + 1);
-    req->bhagq_end_handle = le16toh(u8ptr + 3);
-
-    return 0;
-}
-
-int
-ble_hs_att_read_group_type_req_write(
-    void *payload, int len, struct ble_hs_att_read_group_type_req *req)
-{
-    uint8_t *u8ptr;
-
-    if (len < BLE_HS_ATT_READ_GROUP_TYPE_REQ_BASE_SZ) {
-        return EMSGSIZE;
-    }
-
-    u8ptr = payload;
-
-    u8ptr[0] = BLE_HS_ATT_OP_READ_GROUP_TYPE_REQ;
-    htole16(u8ptr + 1, req->bhagq_start_handle);
-    htole16(u8ptr + 3, req->bhagq_end_handle);
-
-    return 0;
-}
-
-int
-ble_hs_att_read_group_type_rsp_parse(
-    void *payload, int len, struct ble_hs_att_read_group_type_rsp *rsp)
-{
-    uint8_t *u8ptr;
-
-    if (len < BLE_HS_ATT_READ_GROUP_TYPE_RSP_BASE_SZ) {
-        return EMSGSIZE;
-    }
-
-    u8ptr = payload;
-
-    if (u8ptr[0] != BLE_HS_ATT_OP_READ_GROUP_TYPE_RSP) {
-        return EINVAL;
-    }
-
-    rsp->bhagp_length = u8ptr[1];
-
-    return 0;
-}
-
-int
-ble_hs_att_read_group_type_rsp_write(
-    void *payload, int len, struct ble_hs_att_read_group_type_rsp *rsp)
-{
-    uint8_t *u8ptr;
-
-    if (len < BLE_HS_ATT_READ_GROUP_TYPE_RSP_BASE_SZ) {
-        return EMSGSIZE;
-    }
-
-    u8ptr = payload;
-
-    u8ptr[0] = BLE_HS_ATT_OP_READ_GROUP_TYPE_RSP;
-    u8ptr[1] = rsp->bhagp_length;
-
-    return 0;
-}
-
-int
-ble_hs_att_write_req_parse(void *payload, int len,
-                           struct ble_hs_att_write_req *req)
-{
-    uint8_t *u8ptr;
-
-    if (len < BLE_HS_ATT_WRITE_REQ_MIN_SZ) {
-        return EMSGSIZE;
-    }
-
-    u8ptr = payload;
-
-    if (u8ptr[0] != BLE_HS_ATT_OP_WRITE_REQ) {
-        return EINVAL;
-    }
-
-    req->bhawq_handle = le16toh(u8ptr + 1);
-
-    return 0;
-}
-
-int
-ble_hs_att_write_req_write(void *payload, int len,
-                           struct ble_hs_att_write_req *req)
-{
-    uint8_t *u8ptr;
-
-    if (len < BLE_HS_ATT_WRITE_REQ_MIN_SZ) {
-        return EMSGSIZE;
-    }
-
-    u8ptr = payload;
-
-    u8ptr[0] = BLE_HS_ATT_OP_WRITE_REQ;
-    htole16(u8ptr + 1, req->bhawq_handle);
-
-    return 0;
-}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/31f0c10b/net/nimble/host/src/ble_hs_att_cmd.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_att_cmd.h b/net/nimble/host/src/ble_hs_att_cmd.h
deleted file mode 100644
index 828cb11..0000000
--- a/net/nimble/host/src/ble_hs_att_cmd.h
+++ /dev/null
@@ -1,249 +0,0 @@
-/**
- * Copyright (c) 2015 Runtime Inc.
- *
- * Licensed 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 <inttypes.h>
-struct ble_l2cap_chan;
-
-#define BLE_HS_ATT_OP_ERROR_RSP             0x01
-#define BLE_HS_ATT_OP_MTU_REQ               0x02
-#define BLE_HS_ATT_OP_MTU_RSP               0x03
-#define BLE_HS_ATT_OP_FIND_INFO_REQ         0x04
-#define BLE_HS_ATT_OP_FIND_INFO_RSP         0x05
-#define BLE_HS_ATT_OP_FIND_TYPE_VALUE_REQ   0x06
-#define BLE_HS_ATT_OP_FIND_TYPE_VALUE_RSP   0x07
-#define BLE_HS_ATT_OP_READ_TYPE_REQ         0x08
-#define BLE_HS_ATT_OP_READ_TYPE_RSP         0x09
-#define BLE_HS_ATT_OP_READ_REQ              0x0a
-#define BLE_HS_ATT_OP_READ_RSP              0x0b
-#define BLE_HS_ATT_OP_READ_GROUP_TYPE_REQ   0x10
-#define BLE_HS_ATT_OP_READ_GROUP_TYPE_RSP   0x11
-#define BLE_HS_ATT_OP_WRITE_REQ             0x12
-#define BLE_HS_ATT_OP_WRITE_RSP             0x13
-
-/**
- * | Parameter                          | Size (octets)     |
- * +------------------------------------+-------------------+
- * | Attribute Opcode                   | 1                 |
- * | Request Opcode In Error            | 1                 |
- * | Attribute Handle In Error          | 2                 |
- * | Error Code                         | 1                 |
- */
-#define BLE_HS_ATT_ERROR_RSP_SZ             5
-struct ble_hs_att_error_rsp {
-    uint8_t bhaep_req_op;
-    uint16_t bhaep_handle;
-    uint8_t bhaep_error_code;
-};
-
-/**
- * | Parameter                          | Size (octets)     |
- * +------------------------------------+-------------------+
- * | Attribute Opcode                   | 1                 |
- * | Server Rx MTU                      | 2                 |
- */
-#define BLE_HS_ATT_MTU_CMD_SZ               3
-struct ble_hs_att_mtu_cmd {
-    uint16_t bhamc_mtu;
-};
-
-/**
- * | Parameter                          | Size (octets)     |
- * +------------------------------------+-------------------+
- * | Attribute Opcode                   | 1                 |
- * | Starting Handle                    | 2                 |
- * | Ending Handle                      | 2                 |
- */
-#define BLE_HS_ATT_FIND_INFO_REQ_SZ         5
-struct ble_hs_att_find_info_req {
-    uint16_t bhafq_start_handle;
-    uint16_t bhafq_end_handle;
-};
-
-/**
- * | Parameter                          | Size (octets)     |
- * +------------------------------------+-------------------+
- * | Attribute Opcode                   | 1                 |
- * | Format                             | 1                 |
- * | Information Data                   | 4 to (ATT_MTU-2)  |
- */
-#define BLE_HS_ATT_FIND_INFO_RSP_MIN_SZ     2
-struct ble_hs_att_find_info_rsp {
-    uint8_t bhafp_format;
-    /* Followed by information data. */
-};
-
-#define BLE_HS_ATT_FIND_INFO_RSP_FORMAT_16BIT   1
-#define BLE_HS_ATT_FIND_INFO_RSP_FORMAT_128BIT  2
-
-/**
- * | Parameter                          | Size (octets)     |
- * +------------------------------------+-------------------+
- * | Attribute Opcode                   | 1                 |
- * | Starting Handle                    | 2                 |
- * | Ending Handle                      | 2                 |
- * | Attribute Type                     | 2                 |
- * | Attribute Value                    | 0 to (ATT_MTU-7)  |
- */
-#define BLE_HS_ATT_FIND_TYPE_VALUE_REQ_MIN_SZ   7
-struct ble_hs_att_find_type_value_req {
-    uint16_t bhavq_start_handle;
-    uint16_t bhavq_end_handle;
-    uint16_t bhavq_attr_type;
-};
-
-/**
- * | Parameter                          | Size (octets)     |
- * +------------------------------------+-------------------+
- * | Attribute Opcode                   | 1                 |
- * | Information Data                   | 4 to (ATT_MTU-1)  |
- */
-#define BLE_HS_ATT_FIND_TYPE_VALUE_RSP_MIN_SZ   1
-
-/**
- * | Parameter                          | Size (octets)     |
- * +------------------------------------+-------------------+
- * | Attribute Opcode                   | 1                 |
- * | Starting Handle                    | 2                 |
- * | Ending Handle                      | 2                 |
- * | Attribute Type                     | 2 or 16           |
- */
-#define BLE_HS_ATT_READ_TYPE_REQ_MIN_SZ     7
-#define BLE_HS_ATT_READ_TYPE_REQ_SZ_16      7
-#define BLE_HS_ATT_READ_TYPE_REQ_SZ_128     21
-struct ble_hs_att_read_type_req {
-    uint16_t bhatq_start_handle;
-    uint16_t bhatq_end_handle;
-};
-
-/**
- * | Parameter                          | Size (octets)     |
- * +------------------------------------+-------------------+
- * | Attribute Opcode                   | 1                 |
- * | Length                             | 1                 |
- * | Attribute Data List                | 2 to (ATT_MTU-2)  |
- */
-#define BLE_HS_ATT_READ_TYPE_RSP_MIN_SZ     2
-struct ble_hs_att_read_type_rsp {
-    uint8_t bhatp_len;
-};
-
-/**
- * | Parameter                          | Size (octets)     |
- * +------------------------------------+-------------------+
- * | Attribute Opcode                   | 1                 |
- * | Attribute Handle                   | 2                 |
- */
-#define BLE_HS_ATT_READ_REQ_SZ              3
-struct ble_hs_att_read_req {
-    uint16_t bharq_handle;
-};
-
-/**
- * | Parameter                          | Size (octets)     |
- * +------------------------------------+-------------------+
- * | Attribute Opcode                   | 1                 |
- * | Attribute Value                    | 0 to (ATT_MTU-1)  |
- */
-#define BLE_HS_ATT_READ_RSP_MIN_SZ          1
-
-/**
- * | Parameter                          | Size (octets)     |
- * +------------------------------------+-------------------+
- * | Attribute Opcode                   | 1                 |
- * | Starting Handle                    | 2                 |
- * | Ending Handle                      | 2                 |
- * | Attribute Group Type               | 2 or 16           |
- */
-#define BLE_HS_ATT_READ_GROUP_TYPE_REQ_BASE_SZ  5
-#define BLE_HS_ATT_READ_GROUP_TYPE_REQ_SZ_16    7
-#define BLE_HS_ATT_READ_GROUP_TYPE_REQ_SZ_128   21
-struct ble_hs_att_read_group_type_req {
-    uint16_t bhagq_start_handle;
-    uint16_t bhagq_end_handle;
-};
-
-/**
- * | Parameter                          | Size (octets)     |
- * +------------------------------------+-------------------+
- * | Attribute Opcode                   | 1                 |
- * | Length                             | 1                 |
- * | Attribute Data List                | 2 to (ATT_MTU-2)  |
- */
-#define BLE_HS_ATT_READ_GROUP_TYPE_RSP_BASE_SZ  2
-struct ble_hs_att_read_group_type_rsp {
-    uint8_t bhagp_length;
-};
-
-/**
- * | Parameter                          | Size (octets)     |
- * +------------------------------------+-------------------+
- * | Attribute Opcode                   | 1                 |
- * | Attribute Handle                   | 2                 |
- * | Attribute Value                    | 0 to (ATT_MTU-3)  |
- */
-#define BLE_HS_ATT_WRITE_REQ_MIN_SZ         3
-struct ble_hs_att_write_req {
-    uint16_t bhawq_handle;
-};
-
-#define BLE_HS_ATT_WRITE_RSP_SZ             1
-
-int ble_hs_att_error_rsp_parse(void *payload, int len,
-                               struct ble_hs_att_error_rsp *rsp);
-int ble_hs_att_error_rsp_write(void *payload, int len,
-                               struct ble_hs_att_error_rsp *rsp);
-int ble_hs_att_mtu_cmd_parse(void *payload, int len,
-                             struct ble_hs_att_mtu_cmd *cmd);
-int ble_hs_att_mtu_req_write(void *payload, int len,
-                             struct ble_hs_att_mtu_cmd *cmd);
-int ble_hs_att_mtu_rsp_write(void *payload, int len,
-                             struct ble_hs_att_mtu_cmd *cmd);
-int ble_hs_att_find_info_req_parse(void *payload, int len,
-                                   struct ble_hs_att_find_info_req *req);
-int ble_hs_att_find_info_req_write(void *payload, int len,
-                                   struct ble_hs_att_find_info_req *req);
-int ble_hs_att_find_info_rsp_parse(void *payload, int len,
-                                   struct ble_hs_att_find_info_rsp *rsp);
-int ble_hs_att_find_info_rsp_write(void *payload, int len,
-                                   struct ble_hs_att_find_info_rsp *rsp);
-int ble_hs_att_find_type_value_req_parse(
-    void *payload, int len, struct ble_hs_att_find_type_value_req *req);
-int ble_hs_att_find_type_value_req_write(
-    void *payload, int len, struct ble_hs_att_find_type_value_req *req);
-int ble_hs_att_read_req_parse(void *payload, int len,
-                              struct ble_hs_att_read_req *req);
-int ble_hs_att_read_req_write(void *payload, int len,
-                              struct ble_hs_att_read_req *req);
-int ble_hs_att_read_type_req_parse(void *payload, int len,
-                                   struct ble_hs_att_read_type_req *req);
-int ble_hs_att_read_type_req_write(void *payload, int len,
-                                   struct ble_hs_att_read_type_req *req);
-int ble_hs_att_read_type_rsp_parse(void *payload, int len,
-                                   struct ble_hs_att_read_type_rsp *rsp);
-int ble_hs_att_read_type_rsp_write(void *payload, int len,
-                                   struct ble_hs_att_read_type_rsp *rsp);
-int ble_hs_att_read_group_type_req_parse(
-    void *payload, int len, struct ble_hs_att_read_group_type_req *req);
-int ble_hs_att_read_group_type_req_write(
-    void *payload, int len, struct ble_hs_att_read_group_type_req *req);
-int ble_hs_att_read_group_type_rsp_parse(
-    void *payload, int len, struct ble_hs_att_read_group_type_rsp *rsp);
-int ble_hs_att_read_group_type_rsp_write(
-    void *payload, int len, struct ble_hs_att_read_group_type_rsp *rsp);
-int ble_hs_att_write_req_parse(void *payload, int len,
-                               struct ble_hs_att_write_req *req);
-int ble_hs_att_write_req_write(void *payload, int len,
-                               struct ble_hs_att_write_req *req);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/31f0c10b/net/nimble/host/src/ble_hs_att_svr.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_att_svr.c b/net/nimble/host/src/ble_hs_att_svr.c
deleted file mode 100644
index 8b9dcb3..0000000
--- a/net/nimble/host/src/ble_hs_att_svr.c
+++ /dev/null
@@ -1,1230 +0,0 @@
-/**
- * Copyright (c) 2015 Runtime Inc.
- *
- * Licensed 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 <errno.h>
-#include <assert.h>
-#include "os/os.h"
-#include "nimble/ble.h"
-#include "host/ble_hs.h"
-#include "ble_l2cap.h"
-#include "ble_hs_conn.h"
-#include "ble_hs_uuid.h"
-#include "ble_hs_att_cmd.h"
-#include "ble_hs_att.h"
-
-static STAILQ_HEAD(, ble_hs_att_svr_entry) ble_hs_att_svr_list;
-static uint16_t ble_hs_att_svr_id;
-
-static struct os_mutex ble_hs_att_svr_list_mutex;
-
-#define BLE_HS_ATT_SVR_NUM_ENTRIES          32
-static void *ble_hs_att_svr_entry_mem;
-static struct os_mempool ble_hs_att_svr_entry_pool;
-
-/**
- * Locks the host attribute list.
- *
- * @return 0 on success, non-zero error code on failure.
- */
-static void
-ble_hs_att_svr_list_lock(void)
-{
-    int rc;
-
-    rc = os_mutex_pend(&ble_hs_att_svr_list_mutex, OS_WAIT_FOREVER);
-    assert(rc == 0 || rc == OS_NOT_STARTED);
-}
-
-/**
- * Unlocks the host attribute list
- *
- * @return 0 on success, non-zero error code on failure.
- */
-static void
-ble_hs_att_svr_list_unlock(void)
-{
-    int rc;
-
-    rc = os_mutex_release(&ble_hs_att_svr_list_mutex);
-    assert(rc == 0 || rc == OS_NOT_STARTED);
-}
-
-static struct ble_hs_att_svr_entry *
-ble_hs_att_svr_entry_alloc(void)
-{
-    struct ble_hs_att_svr_entry *entry;
-
-    entry = os_memblock_get(&ble_hs_att_svr_entry_pool);
-    if (entry != NULL) {
-        memset(entry, 0, sizeof *entry);
-    }
-
-    return entry;
-}
-
-#if 0
-static void
-ble_hs_att_svr_entry_free(struct ble_hs_att_svr_entry *entry)
-{
-    int rc;
-
-    rc = os_memblock_put(&ble_hs_att_svr_entry_pool, entry);
-    assert(rc == 0);
-}
-#endif
-
-/**
- * Allocate the next handle id and return it.
- *
- * @return A new 16-bit handle ID.
- */
-static uint16_t
-ble_hs_att_svr_next_id(void)
-{
-    /* Rollover is fatal. */
-    assert(ble_hs_att_svr_id != UINT16_MAX);
-
-    return (++ble_hs_att_svr_id);
-}
-
-/**
- * Register a host attribute with the BLE stack.
- *
- * @param ha                    A filled out ble_hs_att structure to register
- * @param handle_id             A pointer to a 16-bit handle ID, which will be
- *                                  the handle that is allocated.
- * @param fn                    The callback function that gets executed when
- *                                  the attribute is operated on.
- *
- * @return 0 on success, non-zero error code on failure.
- */
-int
-ble_hs_att_svr_register(uint8_t *uuid, uint8_t flags, uint16_t *handle_id,
-                        ble_hs_att_svr_handle_func *fn)
-{
-    struct ble_hs_att_svr_entry *entry;
-
-    entry = ble_hs_att_svr_entry_alloc();
-    if (entry == NULL) {
-        return ENOMEM;
-    }
-
-    memcpy(&entry->ha_uuid, uuid, sizeof entry->ha_uuid);
-    entry->ha_flags = flags;
-    entry->ha_handle_id = ble_hs_att_svr_next_id();
-    entry->ha_fn = fn;
-
-    ble_hs_att_svr_list_lock();
-    STAILQ_INSERT_TAIL(&ble_hs_att_svr_list, entry, ha_next);
-    ble_hs_att_svr_list_unlock();
-
-    if (handle_id != NULL) {
-        *handle_id = entry->ha_handle_id;
-    }
-
-    return 0;
-}
-
-/**
- * Walk the host attribute list, calling walk_func on each entry with argument.
- * If walk_func wants to stop iteration, it returns 1.  To continue iteration
- * it returns 0.
- *
- * @param walk_func The function to call for each element in the host attribute
- *                  list.
- * @param arg       The argument to provide to walk_func
- * @param ha_ptr    On input: Indicates the starting point of the walk;
- *                      null means start at the beginning of the list,
- *                      non-null means start at the following entry.
- *                  On output: Indicates the last ble_hs_att element processed,
- *                      or NULL if the entire list has been processed.
- *
- * @return 1 on stopped, 0 on fully processed and an error code otherwise.
- */
-int
-ble_hs_att_svr_walk(ble_hs_att_svr_walk_func_t walk_func, void *arg,
-        struct ble_hs_att_svr_entry **ha_ptr)
-{
-    struct ble_hs_att_svr_entry *ha;
-    int rc;
-
-    assert(ha_ptr != NULL);
-
-    ble_hs_att_svr_list_lock();
-
-    if (*ha_ptr == NULL) {
-        ha = STAILQ_FIRST(&ble_hs_att_svr_list);
-    } else {
-        ha = STAILQ_NEXT(*ha_ptr, ha_next);
-    }
-
-    while (ha != NULL) {
-        rc = walk_func(ha, arg);
-        if (rc == 1) {
-            *ha_ptr = ha;
-            goto done;
-        }
-
-        ha = STAILQ_NEXT(ha, ha_next);
-    }
-
-    rc = 0;
-
-done:
-    ble_hs_att_svr_list_unlock();
-    return rc;
-}
-
-static int
-ble_hs_att_svr_match_handle(struct ble_hs_att_svr_entry *ha, void *arg)
-{
-    if (ha->ha_handle_id == *(uint16_t *) arg) {
-        return (1);
-    } else {
-        return (0);
-    }
-}
-
-
-/**
- * Find a host attribute by handle id.
- *
- * @param handle_id             The handle_id to search for
- * @param ha_ptr                A pointer to a pointer to put the matching host
- *                                  attr into.
- *
- * @return                      0 on success; ENOENT on not found.
- */
-int
-ble_hs_att_svr_find_by_handle(uint16_t handle_id,
-                              struct ble_hs_att_svr_entry **ha_ptr)
-{
-    int rc;
-
-    rc = ble_hs_att_svr_walk(ble_hs_att_svr_match_handle, &handle_id, ha_ptr);
-    if (rc == 1) {
-        /* Found a matching handle */
-        return 0;
-    } else {
-        /* Not found */
-        return ENOENT;
-    }
-}
-
-static int
-ble_hs_att_svr_match_uuid(struct ble_hs_att_svr_entry *ha, void *arg)
-{
-    uint8_t *uuid;
-
-    uuid = arg;
-
-    if (memcmp(ha->ha_uuid, uuid, sizeof ha->ha_uuid) == 0) {
-        return (1);
-    } else {
-        return (0);
-    }
-}
-
-/**
- * Find a host attribute by UUID.
- *
- * @param uuid                  The ble_uuid_t to search for
- * @param ha_ptr                A pointer to a pointer to put the matching host
- *                                  attr into.
- *
- * @return                      0 on success; ENOENT on not found.
- */
-int
-ble_hs_att_svr_find_by_uuid(uint8_t *uuid,
-                            struct ble_hs_att_svr_entry **ha_ptr)
-{
-    int rc;
-
-    rc = ble_hs_att_svr_walk(ble_hs_att_svr_match_uuid, uuid, ha_ptr);
-    if (rc == 1) {
-        /* Found a matching handle */
-        return 0;
-    } else {
-        /* No match */
-        return ENOENT;
-    }
-}
-
-static int
-ble_hs_att_svr_tx_error_rsp(struct ble_l2cap_chan *chan, uint8_t req_op,
-                            uint16_t handle, uint8_t error_code)
-{
-    struct ble_hs_att_error_rsp rsp;
-    struct os_mbuf *txom;
-    void *dst;
-    int rc;
-
-    txom = os_mbuf_get_pkthdr(&ble_hs_mbuf_pool, 0);
-    if (txom == NULL) {
-        rc = BLE_HS_ATT_ERR_INSUFFICIENT_RES;
-        goto err;
-    }
-
-    dst = os_mbuf_extend(txom, BLE_HS_ATT_ERROR_RSP_SZ);
-    if (dst == NULL) {
-        rc = BLE_HS_ATT_ERR_INSUFFICIENT_RES;
-        goto err;
-    }
-
-    rsp.bhaep_req_op = req_op;
-    rsp.bhaep_handle = handle;
-    rsp.bhaep_error_code = error_code;
-
-    rc = ble_hs_att_error_rsp_write(dst, BLE_HS_ATT_ERROR_RSP_SZ, &rsp);
-    assert(rc == 0);
-
-    rc = ble_l2cap_tx(chan, txom);
-    txom = NULL;
-    if (rc != 0) {
-        rc = BLE_HS_ATT_ERR_UNLIKELY;
-        goto err;
-    }
-
-    return 0;
-
-err:
-    os_mbuf_free_chain(txom);
-    return rc;
-}
-
-static int
-ble_hs_att_svr_tx_mtu_rsp(struct ble_l2cap_chan *chan, uint8_t op,
-                          uint16_t mtu)
-{
-    struct ble_hs_att_mtu_cmd cmd;
-    struct os_mbuf *txom;
-    void *dst;
-    int rc;
-
-    assert(op == BLE_HS_ATT_OP_MTU_REQ || op == BLE_HS_ATT_OP_MTU_RSP);
-    assert(mtu >= BLE_HS_ATT_MTU_DFLT);
-
-    txom = os_mbuf_get_pkthdr(&ble_hs_mbuf_pool, 0);
-    if (txom == NULL) {
-        rc = BLE_HS_ATT_ERR_INSUFFICIENT_RES;
-        goto err;
-    }
-
-    dst = os_mbuf_extend(txom, BLE_HS_ATT_MTU_CMD_SZ);
-    if (dst == NULL) {
-        rc = BLE_HS_ATT_ERR_INSUFFICIENT_RES;
-        goto err;
-    }
-
-    cmd.bhamc_mtu = mtu;
-
-    rc = ble_hs_att_mtu_rsp_write(dst, BLE_HS_ATT_MTU_CMD_SZ, &cmd);
-    assert(rc == 0);
-
-    rc = ble_l2cap_tx(chan, txom);
-    txom = NULL;
-    if (rc != 0) {
-        rc = BLE_HS_ATT_ERR_UNLIKELY;
-        goto err;
-    }
-
-    chan->blc_flags |= BLE_L2CAP_CHAN_F_TXED_MTU;
-    return 0;
-
-err:
-    os_mbuf_free_chain(txom);
-    return rc;
-}
-
-int
-ble_hs_att_svr_rx_mtu(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan,
-                      struct os_mbuf *om)
-{
-    struct ble_hs_att_mtu_cmd cmd;
-    int rc;
-
-    /* XXX: Pull up om. */
-
-    rc = ble_hs_att_mtu_cmd_parse(om->om_data, om->om_len, &cmd);
-    assert(rc == 0);
-
-    ble_hs_att_set_peer_mtu(chan, cmd.bhamc_mtu);
-    rc = ble_hs_att_svr_tx_mtu_rsp(chan, BLE_HS_ATT_OP_MTU_RSP,
-                                   chan->blc_my_mtu);
-    if (rc != 0) {
-        return rc;
-    }
-
-    return 0;
-}
-
-/**
- * Fills the supplied mbuf with the variable length Information Data field of a
- * Find Information ATT response.
- *
- * @param req                   The Find Information request being responded
- *                                  to.
- * @param om                    The destination mbuf where the Information
- *                                  Data field gets written.
- * @param mtu                   The ATT L2CAP channel MTU.
- * @param format                On success, the format field of the response
- *                                  gets stored here.  One of:
- *                                     o BLE_HS_ATT_FIND_INFO_RSP_FORMAT_16BIT
- *                                     o BLE_HS_ATT_FIND_INFO_RSP_FORMAT_128BIT
- *
- * @return                      0 on success; an ATT error code on failure.
- */
-static int
-ble_hs_att_svr_fill_info(struct ble_hs_att_find_info_req *req,
-                         struct os_mbuf *om, uint16_t mtu, uint8_t *format)
-{
-    struct ble_hs_att_svr_entry *ha;
-    uint16_t handle_id;
-    uint16_t uuid16;
-    int num_entries;
-    int rsp_sz;
-    int rc;
-
-    *format = 0;
-    num_entries = 0;
-    rc = 0;
-
-    ble_hs_att_svr_list_lock();
-
-    STAILQ_FOREACH(ha, &ble_hs_att_svr_list, ha_next) {
-        if (ha->ha_handle_id > req->bhafq_end_handle) {
-            rc = 0;
-            goto done;
-        }
-        if (ha->ha_handle_id >= req->bhafq_start_handle) {
-            uuid16 = ble_hs_uuid_16bit(ha->ha_uuid);
-
-            if (*format == 0) {
-                if (uuid16 != 0) {
-                    *format = BLE_HS_ATT_FIND_INFO_RSP_FORMAT_16BIT;
-                } else {
-                    *format = BLE_HS_ATT_FIND_INFO_RSP_FORMAT_128BIT;
-                }
-            }
-
-            switch (*format) {
-            case BLE_HS_ATT_FIND_INFO_RSP_FORMAT_16BIT:
-                if (uuid16 == 0) {
-                    rc = 0;
-                    goto done;
-                }
-
-                rsp_sz = OS_MBUF_PKTHDR(om)->omp_len + 4;
-                if (rsp_sz > mtu) {
-                    rc = 0;
-                    goto done;
-                }
-
-                htole16(&handle_id, ha->ha_handle_id);
-                rc = os_mbuf_append(om, &handle_id, 2);
-                if (rc != 0) {
-                    goto done;
-                }
-
-                htole16(&uuid16, uuid16);
-                rc = os_mbuf_append(om, &uuid16, 2);
-                if (rc != 0) {
-                    goto done;
-                }
-                break;
-
-            case BLE_HS_ATT_FIND_INFO_RSP_FORMAT_128BIT:
-                if (uuid16 != 0) {
-                    rc = 0;
-                    goto done;
-                }
-
-                rsp_sz = OS_MBUF_PKTHDR(om)->omp_len + 18;
-                if (rsp_sz > mtu) {
-                    rc = 0;
-                    goto done;
-                }
-
-                htole16(&handle_id, ha->ha_handle_id);
-                rc = os_mbuf_append(om, &handle_id, 2);
-                if (rc != 0) {
-                    goto done;
-                }
-
-                rc = os_mbuf_append(om, &ha->ha_uuid,
-                                    16);
-                if (rc != 0) {
-                    goto done;
-                }
-                break;
-
-            default:
-                assert(0);
-                break;
-            }
-
-            num_entries++;
-        }
-    }
-
-done:
-    ble_hs_att_svr_list_unlock();
-
-    if (rc == 0 && num_entries == 0) {
-        return ENOENT;
-    } else {
-        return rc;
-    }
-}
-
-int
-ble_hs_att_svr_rx_find_info(struct ble_hs_conn *conn,
-                            struct ble_l2cap_chan *chan,
-                            struct os_mbuf *rxom)
-{
-    struct ble_hs_att_find_info_req req;
-    struct ble_hs_att_find_info_rsp rsp;
-    struct os_mbuf *txom;
-    void *buf;
-    int rc;
-
-    txom = NULL;
-
-    /* XXX: Pull up rxom. */
-
-    rc = ble_hs_att_find_info_req_parse(rxom->om_data, rxom->om_len, &req);
-    if (rc != 0) {
-        req.bhafq_start_handle = 0;
-        rc = BLE_HS_ATT_ERR_INVALID_PDU;
-        goto err;
-    }
-
-    /* Tx error response if start handle is greater than end handle or is equal
-     * to 0 (Vol. 3, Part F, 3.4.3.1).
-     */
-    if (req.bhafq_start_handle > req.bhafq_end_handle ||
-        req.bhafq_start_handle == 0) {
-
-        rc = BLE_HS_ATT_ERR_INVALID_HANDLE;
-        goto err;
-    }
-
-    txom = os_mbuf_get_pkthdr(&ble_hs_mbuf_pool, 0);
-    if (txom == NULL) {
-        rc = BLE_HS_ATT_ERR_INSUFFICIENT_RES;
-        goto err;
-    }
-
-    /* Write the response base at the start of the buffer.  The format field is
-     * unknown at this point; it will be filled in later.
-     */
-    buf = os_mbuf_extend(txom, BLE_HS_ATT_FIND_INFO_RSP_MIN_SZ);
-    if (buf == NULL) {
-        rc = BLE_HS_ATT_ERR_INSUFFICIENT_RES;
-        goto err;
-    }
-
-    rc = ble_hs_att_find_info_rsp_write(buf, BLE_HS_ATT_FIND_INFO_RSP_MIN_SZ,
-                                        &rsp);
-    assert(rc == 0);
-
-    /* Write the variable length Information Data field, populating the format
-     * field as appropriate.
-     */
-    rc = ble_hs_att_svr_fill_info(&req, txom, ble_l2cap_chan_mtu(chan),
-                                  txom->om_data + 1);
-    if (rc != 0) {
-        rc = BLE_HS_ATT_ERR_ATTR_NOT_FOUND;
-        goto err;
-    }
-
-    rc = ble_l2cap_tx(chan, txom);
-    txom = NULL;
-    if (rc != 0) {
-        goto err;
-    }
-
-    return 0;
-
-err:
-    os_mbuf_free_chain(txom);
-    ble_hs_att_svr_tx_error_rsp(chan, BLE_HS_ATT_OP_FIND_INFO_REQ,
-                                req.bhafq_start_handle, rc);
-
-    return rc;
-}
-
-/**
- * Processes a single non-matching attribute entry while filling a
- * Find-By-Type-Value-Response.
- *
- * @param om                    The response mbuf.
- * @param first                 Pointer to the first matching handle ID in the
- *                                  current group of IDs.  0 if there is not a
- *                                  current group.
- * @param prev                  Pointer to the most recent matching handle ID
- *                                  in the current group of IDs.  0 if there is
- *                                  not a current group.
- * @param mtu                   The ATT L2CAP channel MTU.
- *
- * @return                      0 if the response should be sent;
- *                              EAGAIN if the entry was successfully processed
- *                                  and subsequent entries can be inspected.
- *                              Other nonzero on error.
- */
-static int
-ble_hs_att_svr_fill_type_value_no_match(struct os_mbuf *om, uint16_t *first,
-                                        uint16_t *prev, int mtu)
-{
-    uint16_t u16;
-    int rsp_sz;
-    int rc;
-
-    /* If there is no current group, then there is nothing to do. */
-    if (*first == 0) {
-        return EAGAIN;
-    }
-
-    rsp_sz = OS_MBUF_PKTHDR(om)->omp_len + 4;
-    if (rsp_sz > mtu) {
-        return 0;
-    }
-
-    u16 = *first;
-    htole16(&u16, u16);
-    rc = os_mbuf_append(om, &u16, 2);
-    if (rc != 0) {
-        return ENOMEM;
-    }
-
-    u16 = *prev;
-    htole16(&u16, u16);
-    rc = os_mbuf_append(om, &u16, 2);
-    if (rc != 0) {
-        return ENOMEM;
-    }
-
-    *first = 0;
-    *prev = 0;
-
-    return EAGAIN;
-}
-
-/**
- * Processes a single matching attribute entry while filling a
- * Find-By-Type-Value-Response.
- *
- * @param om                    The response mbuf.
- * @param first                 Pointer to the first matching handle ID in the
- *                                  current group of IDs.  0 if there is not a
- *                                  current group.
- * @param prev                  Pointer to the most recent matching handle ID
- *                                  in the current group of IDs.  0 if there is
- *                                  not a current group.
- * @param handle_id             The matching handle ID to process.
- * @param mtu                   The ATT L2CAP channel MTU.
- *
- * @return                      0 if the response should be sent;
- *                              EAGAIN if the entry was successfully processed
- *                                  and subsequent entries can be inspected.
- *                              Other nonzero on error.
- */
-static int
-ble_hs_att_svr_fill_type_value_match(struct os_mbuf *om, uint16_t *first,
-                                     uint16_t *prev, uint16_t handle_id,
-                                     int mtu)
-{
-    int rc;
-
-    /* If this is the start of a group, record it as the first ID and keep
-     * searching.
-     */
-    if (*first == 0) {
-        *first = handle_id;
-        *prev = handle_id;
-        return EAGAIN;
-    }
-
-    /* If this is the continuation of a group, keep searching. */
-    if (handle_id == *prev + 1) {
-        *prev = handle_id;
-        return EAGAIN;
-    }
-
-    /* Otherwise, this handle is not a part of the previous group.  Write the
-     * previous group to the response, and remember this ID as the start of the
-     * next group.
-     */
-    rc = ble_hs_att_svr_fill_type_value_no_match(om, first, prev, mtu);
-    *first = handle_id;
-    *prev = handle_id;
-    return rc;
-}
-
-/**
- * Fills the supplied mbuf with the variable length Handles-Information-List
- * field of a Find-By-Type-Value ATT response.
- *
- * @param req                   The Find-By-Type-Value-Request being responded
- *                                  to.
- * @param rxom                  The mbuf containing the received request.
- * @param txom                  The destination mbuf where the
- *                                  Handles-Information-List field gets
- *                                  written.
- * @param mtu                   The ATT L2CAP channel MTU.
- *
- * @return                      0 on success; an ATT error code on failure.
- */
-static int
-ble_hs_att_svr_fill_type_value(struct ble_hs_att_find_type_value_req *req,
-                               struct os_mbuf *rxom, struct os_mbuf *txom,
-                               uint16_t mtu)
-{
-    union ble_hs_att_svr_handle_arg arg;
-    struct ble_hs_att_svr_entry *ha;
-    uint16_t uuid16;
-    uint16_t first;
-    uint16_t prev;
-    int any_entries;
-    int match;
-    int rc;
-
-    first = 0;
-    prev = 0;
-    rc = 0;
-
-    ble_hs_att_svr_list_lock();
-
-    /* Iterate through the attribute list, keeping track of the current
-     * matching group.  For each attribute entry, determine if data needs to be
-     * written to the response.
-     */
-    STAILQ_FOREACH(ha, &ble_hs_att_svr_list, ha_next) {
-        match = 0;
-
-        if (ha->ha_handle_id > req->bhavq_end_handle) {
-            break;
-        }
-
-        if (ha->ha_handle_id >= req->bhavq_start_handle) {
-            /* Compare the attribute type and value to the request fields to
-             * determine if this attribute matches.
-             */
-            uuid16 = ble_hs_uuid_16bit(ha->ha_uuid);
-            if (uuid16 == req->bhavq_attr_type) {
-                rc = ha->ha_fn(ha, BLE_HS_ATT_OP_READ_REQ, &arg);
-                if (rc != 0) {
-                    rc = BLE_HS_ATT_ERR_UNLIKELY;
-                    goto done;
-                }
-                rc = os_mbuf_memcmp(rxom,
-                                    BLE_HS_ATT_FIND_TYPE_VALUE_REQ_MIN_SZ,
-                                    arg.aha_read.attr_data,
-                                    arg.aha_read.attr_len);
-                if (rc == 0) {
-                    match = 1;
-                }
-            }
-        }
-
-        if (match) {
-            rc = ble_hs_att_svr_fill_type_value_match(txom, &first, &prev,
-                                                      ha->ha_handle_id, mtu);
-        } else {
-            rc = ble_hs_att_svr_fill_type_value_no_match(txom, &first, &prev,
-                                                         mtu);
-        }
-
-        if (rc == 0) {
-            goto done;
-        }
-        if (rc != EAGAIN) {
-            rc = BLE_HS_ATT_ERR_UNLIKELY;
-            goto done;
-        }
-    }
-
-    /* Process one last non-matching ID in case a group was in progress when
-     * the end of the attribute list was reached.
-     */
-    rc = ble_hs_att_svr_fill_type_value_no_match(txom, &first, &prev, mtu);
-    if (rc == EAGAIN) {
-        rc = 0;
-    } else if (rc != 0) {
-        rc = BLE_HS_ATT_ERR_UNLIKELY;
-    }
-
-done:
-    ble_hs_att_svr_list_unlock();
-
-    any_entries = OS_MBUF_PKTHDR(txom)->omp_len >
-                  BLE_HS_ATT_FIND_TYPE_VALUE_RSP_MIN_SZ;
-    if (rc == 0 && !any_entries) {
-        return BLE_HS_ATT_ERR_ATTR_NOT_FOUND;
-    } else {
-        return rc;
-    }
-}
-
-int
-ble_hs_att_svr_rx_find_type_value(struct ble_hs_conn *conn,
-                                  struct ble_l2cap_chan *chan,
-                                  struct os_mbuf *rxom)
-{
-    struct ble_hs_att_find_type_value_req req;
-    struct os_mbuf *txom;
-    uint8_t *buf;
-    int rc;
-
-    txom = NULL;
-
-    /* XXX: Pull up rx_om. */
-
-    rc = ble_hs_att_find_type_value_req_parse(rxom->om_data, rxom->om_len,
-                                              &req);
-    assert(rc == 0);
-
-    /* Tx error response if start handle is greater than end handle or is equal
-     * to 0 (Vol. 3, Part F, 3.4.3.3).
-     */
-    if (req.bhavq_start_handle > req.bhavq_end_handle ||
-        req.bhavq_start_handle == 0) {
-
-        rc = BLE_HS_ATT_ERR_INVALID_HANDLE;
-        goto err;
-    }
-
-    txom = os_mbuf_get_pkthdr(&ble_hs_mbuf_pool, 0);
-    if (txom == NULL) {
-        rc = BLE_HS_ATT_ERR_INSUFFICIENT_RES;
-        goto err;
-    }
-
-    /* Write the response base at the start of the buffer. */
-    buf = os_mbuf_extend(txom, BLE_HS_ATT_FIND_TYPE_VALUE_RSP_MIN_SZ);
-    if (buf == NULL) {
-        rc = BLE_HS_ATT_ERR_INSUFFICIENT_RES;
-        goto err;
-    }
-    buf[0] = BLE_HS_ATT_OP_FIND_TYPE_VALUE_RSP;
-
-    /* Write the variable length Information Data field. */
-    rc = ble_hs_att_svr_fill_type_value(&req, rxom, txom,
-                                        ble_l2cap_chan_mtu(chan));
-    if (rc != 0) {
-        goto err;
-    }
-
-    rc = ble_l2cap_tx(chan, txom);
-    txom = NULL;
-    if (rc != 0) {
-        rc = BLE_HS_ATT_ERR_UNLIKELY;
-        goto err;
-    }
-
-    return 0;
-
-err:
-    os_mbuf_free_chain(txom);
-    ble_hs_att_svr_tx_error_rsp(chan, BLE_HS_ATT_OP_FIND_TYPE_VALUE_REQ,
-                            req.bhavq_start_handle, rc);
-    return rc;
-}
-
-static int
-ble_hs_att_svr_tx_read_type_rsp(struct ble_hs_conn *conn,
-                                struct ble_l2cap_chan *chan,
-                                struct ble_hs_att_read_type_req *req,
-                                uint8_t *uuid128)
-{
-    struct ble_hs_att_read_type_rsp rsp;
-    union ble_hs_att_svr_handle_arg arg;
-    struct ble_hs_att_svr_entry *entry;
-    struct os_mbuf *txom;
-    uint8_t *dptr;
-    int txomlen;
-    int prev_attr_len;
-    int attr_len;
-    int rc;
-
-    txom = os_mbuf_get_pkthdr(&ble_hs_mbuf_pool, 0);
-    if (txom == NULL) {
-        rc = BLE_HS_ATT_ERR_INSUFFICIENT_RES;
-        goto err;
-    }
-
-    /* Allocate space for the respose base, but don't fill in the fields.  They
-     * get filled in at the end, when we know the value of the length field.
-     */
-    dptr = os_mbuf_extend(txom,
-                          BLE_HS_ATT_READ_TYPE_RSP_MIN_SZ);
-    if (dptr == NULL) {
-        rc = BLE_HS_ATT_ERR_INSUFFICIENT_RES;
-        goto err;
-    }
-
-    /* Find all matching attributes, writing a record for each. */
-    prev_attr_len = 0;
-    entry = NULL;
-    while (1) {
-        rc = ble_hs_att_svr_find_by_uuid(uuid128, &entry);
-        if (rc == ENOENT) {
-            break;
-        } else if (rc != 0) {
-            rc = BLE_HS_ATT_ERR_UNLIKELY;
-            goto err;
-        }
-
-        if (entry->ha_handle_id > req->bhatq_end_handle) {
-            break;
-        }
-
-        if (entry->ha_handle_id >= req->bhatq_start_handle &&
-            entry->ha_handle_id <= req->bhatq_end_handle) {
-
-            rc = entry->ha_fn(entry, BLE_HS_ATT_OP_READ_REQ, &arg);
-            if (rc != 0) {
-                rc = BLE_HS_ATT_ERR_UNLIKELY;
-                goto err;
-            }
-
-            if (arg.aha_read.attr_len > ble_l2cap_chan_mtu(chan) - 4) {
-                attr_len = ble_l2cap_chan_mtu(chan) - 4;
-            } else {
-                attr_len = arg.aha_read.attr_len;
-            }
-
-            if (prev_attr_len == 0) {
-                prev_attr_len = attr_len;
-            } else if (prev_attr_len != attr_len) {
-                break;
-            }
-
-            txomlen = OS_MBUF_PKTHDR(txom)->omp_len + 2 + attr_len;
-            if (txomlen > ble_l2cap_chan_mtu(chan)) {
-                break;
-            }
-
-            dptr = os_mbuf_extend(txom, 2 + attr_len);
-            if (dptr == NULL) {
-                rc = BLE_HS_ATT_ERR_INSUFFICIENT_RES;
-                goto err;
-            }
-
-            htole16(dptr + 0, entry->ha_handle_id);
-            memcpy(dptr + 2, arg.aha_read.attr_data, attr_len);
-        }
-    }
-
-    if (prev_attr_len == 0) {
-        /* No matching attributes. */
-        rc = BLE_HS_ATT_ERR_ATTR_NOT_FOUND;
-        goto err;
-    }
-
-    /* Fill the response base. */
-    rsp.bhatp_len = prev_attr_len;
-    rc = ble_hs_att_read_type_rsp_write(txom->om_data, txom->om_len, &rsp);
-    assert(rc == 0);
-
-    /* Transmit the response. */
-    rc = ble_l2cap_tx(chan, txom);
-    txom = NULL;
-    if (rc != 0) {
-        rc = BLE_HS_ATT_ERR_UNLIKELY;
-        goto err;
-    }
-
-    return 0;
-
-err:
-    os_mbuf_free_chain(txom);
-    ble_hs_att_svr_tx_error_rsp(chan, BLE_HS_ATT_OP_READ_TYPE_REQ,
-                                req->bhatq_start_handle, rc);
-    return rc;
-}
-
-int
-ble_hs_att_svr_rx_read_type(struct ble_hs_conn *conn,
-                            struct ble_l2cap_chan *chan, struct os_mbuf *rx_om)
-{
-    struct ble_hs_att_read_type_req req;
-    uint16_t uuid16;
-    uint8_t uuid128[16];
-    int rc;
-
-    /* XXX: Pull up mbuf. */
-
-    rc = ble_hs_att_read_type_req_parse(rx_om->om_data, rx_om->om_len, &req);
-    if (rc != 0) {
-        goto done;
-    }
-
-    switch (rx_om->om_len) {
-    case BLE_HS_ATT_READ_TYPE_REQ_SZ_16:
-        uuid16 = le16toh(rx_om->om_data + 5);
-        rc = ble_hs_uuid_from_16bit(uuid16, uuid128);
-        if (rc != 0) {
-            goto done;
-        }
-        break;
-
-    case BLE_HS_ATT_READ_TYPE_REQ_SZ_128:
-        memcpy(uuid128, rx_om->om_data + 5, 16);
-        break;
-
-    default:
-        rc = EMSGSIZE;
-        goto done;
-    }
-
-    rc = ble_hs_att_svr_tx_read_type_rsp(conn, chan, &req, uuid128);
-    if (rc != 0) {
-        goto done;
-    }
-
-    rc = 0;
-
-done:
-    os_mbuf_free_chain(rx_om);
-    return rc;
-}
-
-static int
-ble_hs_att_svr_tx_read_rsp(struct ble_hs_conn *conn,
-                           struct ble_l2cap_chan *chan,
-                           void *attr_data, int attr_len)
-{
-    struct os_mbuf *txom;
-    uint16_t data_len;
-    uint8_t op;
-    int rc;
-
-    txom = os_mbuf_get_pkthdr(&ble_hs_mbuf_pool, 0);
-    if (txom == NULL) {
-        rc = BLE_HS_ATT_ERR_INSUFFICIENT_RES;
-        goto err;
-    }
-
-    op = BLE_HS_ATT_OP_READ_RSP;
-    rc = os_mbuf_append(txom, &op, 1);
-    if (rc != 0) {
-        rc = BLE_HS_ATT_ERR_INSUFFICIENT_RES;
-        goto err;
-    }
-
-    /* Vol. 3, part F, 3.2.9; don't send more than ATT_MTU-1 bytes of data. */
-    if (attr_len > ble_l2cap_chan_mtu(chan) - 1) {
-        data_len = ble_l2cap_chan_mtu(chan) - 1;
-    } else {
-        data_len = attr_len;
-    }
-
-    rc = os_mbuf_append(txom, attr_data, data_len);
-    if (rc != 0) {
-        rc = BLE_HS_ATT_ERR_INSUFFICIENT_RES;
-        goto err;
-    }
-
-    rc = ble_l2cap_tx(chan, txom);
-    if (rc != 0) {
-        rc = BLE_HS_ATT_ERR_UNLIKELY;
-        goto err;
-    }
-
-    return 0;
-
-err:
-    os_mbuf_free_chain(txom);
-    return rc;
-}
-
-int
-ble_hs_att_svr_rx_read(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan,
-                       struct os_mbuf *om)
-{
-    union ble_hs_att_svr_handle_arg arg;
-    struct ble_hs_att_svr_entry *entry;
-    struct ble_hs_att_read_req req;
-    uint8_t buf[BLE_HS_ATT_READ_REQ_SZ];
-    int rc;
-
-    rc = os_mbuf_copydata(om, 0, sizeof buf, buf);
-    if (rc != 0) {
-        req.bharq_handle = 0;
-        rc = BLE_HS_ATT_ERR_INVALID_PDU;
-        goto err;
-    }
-
-    rc = ble_hs_att_read_req_parse(buf, sizeof buf, &req);
-    assert(rc == 0);
-
-    entry = NULL;
-    rc = ble_hs_att_svr_find_by_handle(req.bharq_handle, &entry);
-    if (rc != 0) {
-        rc = BLE_HS_ATT_ERR_INVALID_HANDLE;
-        goto err;
-    }
-
-    if (entry->ha_fn == NULL) {
-        rc = BLE_HS_ATT_ERR_UNLIKELY;
-        goto err;
-    }
-
-    rc = entry->ha_fn(entry, BLE_HS_ATT_OP_READ_REQ, &arg);
-    if (rc != 0) {
-        rc = BLE_HS_ATT_ERR_UNLIKELY;
-        goto err;
-    }
-
-    rc = ble_hs_att_svr_tx_read_rsp(conn, chan, arg.aha_read.attr_data,
-                                arg.aha_read.attr_len);
-    if (rc != 0) {
-        goto err;
-    }
-
-    return 0;
-
-err:
-    ble_hs_att_svr_tx_error_rsp(chan, BLE_HS_ATT_OP_READ_REQ,
-                            req.bharq_handle, rc);
-    return rc;
-}
-
-static int
-ble_hs_att_svr_tx_write_rsp(struct ble_hs_conn *conn,
-                            struct ble_l2cap_chan *chan)
-{
-    struct os_mbuf *txom;
-    uint8_t *dst;
-    int rc;
-
-    txom = os_mbuf_get_pkthdr(&ble_hs_mbuf_pool, 0);
-    if (txom == NULL) {
-        rc = BLE_HS_ATT_ERR_INSUFFICIENT_RES;
-        goto err;
-    }
-
-    dst = os_mbuf_extend(txom, BLE_HS_ATT_WRITE_RSP_SZ);
-    if (dst == NULL) {
-        rc = BLE_HS_ATT_ERR_INSUFFICIENT_RES;
-        goto err;
-    }
-
-    *dst = BLE_HS_ATT_OP_WRITE_RSP;
-    rc = ble_l2cap_tx(chan, txom);
-    txom = NULL;
-    if (rc != 0) {
-        rc = BLE_HS_ATT_ERR_UNLIKELY;
-        goto err;
-    }
-
-    return 0;
-
-err:
-    os_mbuf_free_chain(txom);
-    return rc;
-}
-
-int
-ble_hs_att_svr_rx_write(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan,
-                        struct os_mbuf *om)
-{
-    union ble_hs_att_svr_handle_arg arg;
-    struct ble_hs_att_svr_entry *entry;
-    struct ble_hs_att_write_req req;
-    uint8_t buf[BLE_HS_ATT_WRITE_REQ_MIN_SZ];
-    int rc;
-
-    rc = os_mbuf_copydata(om, 0, sizeof buf, buf);
-    if (rc != 0) {
-        return rc;
-    }
-
-    rc = ble_hs_att_write_req_parse(buf, sizeof buf, &req);
-    assert(rc == 0);
-
-    entry = NULL;
-    rc = ble_hs_att_svr_find_by_handle(req.bhawq_handle, &entry);
-    if (rc != 0) {
-        rc = BLE_HS_ATT_ERR_INVALID_HANDLE;
-        goto send_err;
-    }
-
-    if (entry->ha_fn == NULL) {
-        rc = BLE_HS_ATT_ERR_UNLIKELY;
-        goto send_err;
-    }
-
-    arg.aha_write.om = om;
-    arg.aha_write.attr_len = OS_MBUF_PKTHDR(om)->omp_len;
-    rc = entry->ha_fn(entry, BLE_HS_ATT_OP_WRITE_REQ, &arg);
-    if (rc != 0) {
-        goto send_err;
-    }
-
-    rc = ble_hs_att_svr_tx_write_rsp(conn, chan);
-    if (rc != 0) {
-        goto send_err;
-    }
-
-    return 0;
-
-send_err:
-    ble_hs_att_svr_tx_error_rsp(chan, BLE_HS_ATT_OP_WRITE_REQ,
-                                req.bhawq_handle, rc);
-    return rc;
-}
-
-int
-ble_hs_att_svr_init(void)
-{
-    int rc;
-
-    STAILQ_INIT(&ble_hs_att_svr_list);
-
-    rc = os_mutex_init(&ble_hs_att_svr_list_mutex);
-    if (rc != 0) {
-        goto err;
-    }
-
-    free(ble_hs_att_svr_entry_mem);
-    ble_hs_att_svr_entry_mem = malloc(
-        OS_MEMPOOL_BYTES(BLE_HS_ATT_SVR_NUM_ENTRIES,
-                         sizeof (struct ble_hs_att_svr_entry)));
-    if (ble_hs_att_svr_entry_mem == NULL) {
-        rc = ENOMEM;
-        goto err;
-    }
-
-    rc = os_mempool_init(&ble_hs_att_svr_entry_pool,
-                         BLE_HS_ATT_SVR_NUM_ENTRIES,
-                         sizeof (struct ble_hs_att_svr_entry),
-                         ble_hs_att_svr_entry_mem,
-                         "ble_hs_att_svr_entry_pool");
-    if (rc != 0) {
-        goto err;
-    }
-
-    return 0;
-
-err:
-    free(ble_hs_att_svr_entry_mem);
-    ble_hs_att_svr_entry_mem = NULL;
-
-    return rc;
-}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/31f0c10b/net/nimble/host/src/ble_hs_conn.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_conn.c b/net/nimble/host/src/ble_hs_conn.c
index 64b44a7..405a3d7 100644
--- a/net/nimble/host/src/ble_hs_conn.c
+++ b/net/nimble/host/src/ble_hs_conn.c
@@ -23,7 +23,7 @@
 #include "ble_l2cap.h"
 #include "ble_l2cap_sig.h"
 #include "ble_hs_conn.h"
-#include "ble_hs_att.h"
+#include "ble_att.h"
 
 #define BLE_HS_CONN_MAX         16
 
@@ -45,7 +45,7 @@ ble_hs_conn_alloc(void)
 
     SLIST_INIT(&conn->bhc_channels);
 
-    chan = ble_hs_att_create_chan();
+    chan = ble_att_create_chan();
     if (chan == NULL) {
         goto err;
     }
@@ -85,7 +85,7 @@ ble_hs_conn_free(struct ble_hs_conn *conn)
 
     /* XXX: Free contents of rx and tx queues. */
 
-    ble_hs_att_clt_entry_list_free(&conn->bhc_att_clt_list);
+    ble_att_clt_entry_list_free(&conn->bhc_att_clt_list);
 
     rc = os_memblock_put(&ble_hs_conn_pool, conn);
     assert(rc == 0);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/31f0c10b/net/nimble/host/src/ble_hs_conn.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_conn.h b/net/nimble/host/src/ble_hs_conn.h
index 776dbe8..fef560f 100644
--- a/net/nimble/host/src/ble_hs_conn.h
+++ b/net/nimble/host/src/ble_hs_conn.h
@@ -19,7 +19,7 @@
 
 #include "os/queue.h"
 #include "ble_l2cap.h"
-#include "ble_hs_att.h"
+#include "ble_att.h"
 struct hci_le_conn_complete;
 struct hci_create_conn;
 struct ble_l2cap_chan;
@@ -32,7 +32,7 @@ struct ble_hs_conn {
     struct ble_l2cap_chan_list bhc_channels;
 
     /** Mapping of peer's ATT attributes to handle IDs. */
-    struct ble_hs_att_clt_entry_list bhc_att_clt_list;
+    struct ble_att_clt_entry_list bhc_att_clt_list;
 };
 
 struct ble_hs_conn *ble_hs_conn_alloc(void);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/31f0c10b/net/nimble/host/src/test/ble_host_hci_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_host_hci_test.c b/net/nimble/host/src/test/ble_host_hci_test.c
index 0b50e3c..a536d78 100644
--- a/net/nimble/host/src/test/ble_host_hci_test.c
+++ b/net/nimble/host/src/test/ble_host_hci_test.c
@@ -24,8 +24,8 @@
 #include "testutil/testutil.h"
 #include "ble_l2cap.h"
 #include "ble_hs_conn.h"
-#include "ble_hs_att.h"
-#include "ble_hs_att_cmd.h"
+#include "ble_att.h"
+#include "ble_att_cmd.h"
 #include "ble_hs_test_util.h"
 
 TEST_CASE(ble_host_hci_test_event_bad)

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/31f0c10b/net/nimble/host/src/test/ble_hs_att_clt_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_att_clt_test.c b/net/nimble/host/src/test/ble_hs_att_clt_test.c
index 4a59b44..45a7a14 100644
--- a/net/nimble/host/src/test/ble_hs_att_clt_test.c
+++ b/net/nimble/host/src/test/ble_hs_att_clt_test.c
@@ -20,12 +20,12 @@
 #include "nimble/ble.h"
 #include "host/ble_hs_test.h"
 #include "ble_hs_conn.h"
-#include "ble_hs_att.h"
-#include "ble_hs_att_cmd.h"
+#include "ble_att.h"
+#include "ble_att_cmd.h"
 #include "ble_hs_test_util.h"
 
 static void
-ble_hs_att_clt_test_misc_init(struct ble_hs_conn **conn,
+ble_att_clt_test_misc_init(struct ble_hs_conn **conn,
                               struct ble_l2cap_chan **att_chan)
 {
     ble_hs_test_util_init();
@@ -38,43 +38,43 @@ ble_hs_att_clt_test_misc_init(struct ble_hs_conn **conn,
     TEST_ASSERT_FATAL(*att_chan != NULL);
 }
 
-TEST_CASE(ble_hs_att_clt_test_tx_find_info)
+TEST_CASE(ble_att_clt_test_tx_find_info)
 {
-    struct ble_hs_att_find_info_req req;
+    struct ble_att_find_info_req req;
     struct ble_l2cap_chan *chan;
     struct ble_hs_conn *conn;
     int rc;
 
-    ble_hs_att_clt_test_misc_init(&conn, &chan);
+    ble_att_clt_test_misc_init(&conn, &chan);
 
     /*** Success. */
     req.bhafq_start_handle = 1;
     req.bhafq_end_handle = 0xffff;
-    rc = ble_hs_att_clt_tx_find_info(conn, &req);
+    rc = ble_att_clt_tx_find_info(conn, &req);
     TEST_ASSERT(rc == 0);
 
     /*** Error: start handle of 0. */
     req.bhafq_start_handle = 0;
     req.bhafq_end_handle = 0xffff;
-    rc = ble_hs_att_clt_tx_find_info(conn, &req);
+    rc = ble_att_clt_tx_find_info(conn, &req);
     TEST_ASSERT(rc == EINVAL);
 
     /*** Error: start handle greater than end handle. */
     req.bhafq_start_handle = 500;
     req.bhafq_end_handle = 499;
-    rc = ble_hs_att_clt_tx_find_info(conn, &req);
+    rc = ble_att_clt_tx_find_info(conn, &req);
     TEST_ASSERT(rc == EINVAL);
 
     /*** Success; start and end handles equal. */
     req.bhafq_start_handle = 500;
     req.bhafq_end_handle = 500;
-    rc = ble_hs_att_clt_tx_find_info(conn, &req);
+    rc = ble_att_clt_tx_find_info(conn, &req);
     TEST_ASSERT(rc == 0);
 }
 
-TEST_CASE(ble_hs_att_clt_test_rx_find_info)
+TEST_CASE(ble_att_clt_test_rx_find_info)
 {
-    struct ble_hs_att_find_info_rsp rsp;
+    struct ble_att_find_info_rsp rsp;
     struct ble_l2cap_chan *chan;
     struct ble_hs_conn *conn;
     uint16_t handle_id;
@@ -83,19 +83,19 @@ TEST_CASE(ble_hs_att_clt_test_rx_find_info)
     int off;
     int rc;
 
-    ble_hs_att_clt_test_misc_init(&conn, &chan);
+    ble_att_clt_test_misc_init(&conn, &chan);
 
     /*** One 128-bit UUID. */
     /* Ensure attribute mapping is not initially present. */
-    handle_id = ble_hs_att_clt_find_entry_uuid128(conn, uuid128_1);
+    handle_id = ble_att_clt_find_entry_uuid128(conn, uuid128_1);
     TEST_ASSERT_FATAL(handle_id == 0);
 
     /* Receive response with attribute mapping. */
     off = 0;
-    rsp.bhafp_format = BLE_HS_ATT_FIND_INFO_RSP_FORMAT_128BIT;
-    rc = ble_hs_att_find_info_rsp_write(buf + off, sizeof buf - off, &rsp);
+    rsp.bhafp_format = BLE_ATT_FIND_INFO_RSP_FORMAT_128BIT;
+    rc = ble_att_find_info_rsp_write(buf + off, sizeof buf - off, &rsp);
     TEST_ASSERT(rc == 0);
-    off += BLE_HS_ATT_FIND_INFO_RSP_MIN_SZ;
+    off += BLE_ATT_FIND_INFO_RSP_MIN_SZ;
 
     htole16(buf + off, 1);
     off += 2;
@@ -105,20 +105,20 @@ TEST_CASE(ble_hs_att_clt_test_rx_find_info)
     rc = ble_hs_test_util_l2cap_rx_payload_flat(conn, chan, buf, off);
     TEST_ASSERT(rc == 0);
 
-    handle_id = ble_hs_att_clt_find_entry_uuid128(conn, uuid128_1);
+    handle_id = ble_att_clt_find_entry_uuid128(conn, uuid128_1);
     TEST_ASSERT_FATAL(handle_id == 1);
 
     /*** One 16-bit UUID. */
     /* Ensure attribute mapping is not initially present. */
-    handle_id = ble_hs_att_clt_find_entry_uuid16(conn, 0x000f);
+    handle_id = ble_att_clt_find_entry_uuid16(conn, 0x000f);
     TEST_ASSERT_FATAL(handle_id == 0);
 
     /* Receive response with attribute mapping. */
     off = 0;
-    rsp.bhafp_format = BLE_HS_ATT_FIND_INFO_RSP_FORMAT_16BIT;
-    rc = ble_hs_att_find_info_rsp_write(buf + off, sizeof buf - off, &rsp);
+    rsp.bhafp_format = BLE_ATT_FIND_INFO_RSP_FORMAT_16BIT;
+    rc = ble_att_find_info_rsp_write(buf + off, sizeof buf - off, &rsp);
     TEST_ASSERT(rc == 0);
-    off += BLE_HS_ATT_FIND_INFO_RSP_MIN_SZ;
+    off += BLE_ATT_FIND_INFO_RSP_MIN_SZ;
 
     htole16(buf + off, 2);
     off += 2;
@@ -128,22 +128,22 @@ TEST_CASE(ble_hs_att_clt_test_rx_find_info)
     rc = ble_hs_test_util_l2cap_rx_payload_flat(conn, chan, buf, off);
     TEST_ASSERT(rc == 0);
 
-    handle_id = ble_hs_att_clt_find_entry_uuid16(conn, 0x000f);
+    handle_id = ble_att_clt_find_entry_uuid16(conn, 0x000f);
     TEST_ASSERT_FATAL(handle_id == 2);
 
     /*** Two 16-bit UUIDs. */
     /* Ensure attribute mappings are not initially present. */
-    handle_id = ble_hs_att_clt_find_entry_uuid16(conn, 0x0010);
+    handle_id = ble_att_clt_find_entry_uuid16(conn, 0x0010);
     TEST_ASSERT_FATAL(handle_id == 0);
-    handle_id = ble_hs_att_clt_find_entry_uuid16(conn, 0x0011);
+    handle_id = ble_att_clt_find_entry_uuid16(conn, 0x0011);
     TEST_ASSERT_FATAL(handle_id == 0);
 
     /* Receive response with attribute mappings. */
     off = 0;
-    rsp.bhafp_format = BLE_HS_ATT_FIND_INFO_RSP_FORMAT_16BIT;
-    rc = ble_hs_att_find_info_rsp_write(buf + off, sizeof buf - off, &rsp);
+    rsp.bhafp_format = BLE_ATT_FIND_INFO_RSP_FORMAT_16BIT;
+    rc = ble_att_find_info_rsp_write(buf + off, sizeof buf - off, &rsp);
     TEST_ASSERT(rc == 0);
-    off += BLE_HS_ATT_FIND_INFO_RSP_MIN_SZ;
+    off += BLE_ATT_FIND_INFO_RSP_MIN_SZ;
 
     htole16(buf + off, 3);
     off += 2;
@@ -158,22 +158,22 @@ TEST_CASE(ble_hs_att_clt_test_rx_find_info)
     rc = ble_hs_test_util_l2cap_rx_payload_flat(conn, chan, buf, off);
     TEST_ASSERT(rc == 0);
 
-    handle_id = ble_hs_att_clt_find_entry_uuid16(conn, 0x0010);
+    handle_id = ble_att_clt_find_entry_uuid16(conn, 0x0010);
     TEST_ASSERT_FATAL(handle_id == 3);
-    handle_id = ble_hs_att_clt_find_entry_uuid16(conn, 0x0011);
+    handle_id = ble_att_clt_find_entry_uuid16(conn, 0x0011);
     TEST_ASSERT_FATAL(handle_id == 4);
 }
 
-TEST_SUITE(ble_hs_att_clt_suite)
+TEST_SUITE(ble_att_clt_suite)
 {
-    ble_hs_att_clt_test_tx_find_info();
-    ble_hs_att_clt_test_rx_find_info();
+    ble_att_clt_test_tx_find_info();
+    ble_att_clt_test_rx_find_info();
 }
 
 int
-ble_hs_att_clt_test_all(void)
+ble_att_clt_test_all(void)
 {
-    ble_hs_att_clt_suite();
+    ble_att_clt_suite();
 
     return tu_any_failed;
 }


[3/3] incubator-mynewt-larva git commit: Rename ble_hs_att_* to ble_att_*

Posted by cc...@apache.org.
Rename ble_hs_att_* to ble_att_*

Identifiers are getting too long.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/commit/31f0c10b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/31f0c10b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/31f0c10b

Branch: refs/heads/master
Commit: 31f0c10b69827333e42d2c071d19ab6dcb592d68
Parents: 8598e84
Author: Christopher Collins <cc...@gmail.com>
Authored: Thu Dec 3 10:54:52 2015 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Thu Dec 3 10:54:52 2015 -0800

----------------------------------------------------------------------
 net/nimble/host/include/host/ble_gatt.h        |    4 +-
 net/nimble/host/include/host/ble_hs_test.h     |    4 +-
 net/nimble/host/src/ble_att.c                  |  118 ++
 net/nimble/host/src/ble_att.h                  |  166 +++
 net/nimble/host/src/ble_att_clt.c              |  511 ++++++++
 net/nimble/host/src/ble_att_cmd.c              |  482 ++++++++
 net/nimble/host/src/ble_att_cmd.h              |  249 ++++
 net/nimble/host/src/ble_att_svr.c              | 1226 ++++++++++++++++++
 net/nimble/host/src/ble_gatt.c                 |   14 +-
 net/nimble/host/src/ble_hs.c                   |    6 +-
 net/nimble/host/src/ble_hs_att.c               |  118 --
 net/nimble/host/src/ble_hs_att.h               |  171 ---
 net/nimble/host/src/ble_hs_att_clt.c           |  514 --------
 net/nimble/host/src/ble_hs_att_cmd.c           |  482 --------
 net/nimble/host/src/ble_hs_att_cmd.h           |  249 ----
 net/nimble/host/src/ble_hs_att_svr.c           | 1230 -------------------
 net/nimble/host/src/ble_hs_conn.c              |    6 +-
 net/nimble/host/src/ble_hs_conn.h              |    4 +-
 net/nimble/host/src/test/ble_host_hci_test.c   |    4 +-
 net/nimble/host/src/test/ble_hs_att_clt_test.c |   70 +-
 net/nimble/host/src/test/ble_hs_att_svr_test.c |  386 +++---
 net/nimble/host/src/test/ble_hs_conn_test.c    |   10 +-
 net/nimble/host/src/test/ble_hs_test.c         |    4 +-
 23 files changed, 3008 insertions(+), 3020 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/31f0c10b/net/nimble/host/include/host/ble_gatt.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_gatt.h b/net/nimble/host/include/host/ble_gatt.h
index 50ed37d..d1d6084 100644
--- a/net/nimble/host/include/host/ble_gatt.h
+++ b/net/nimble/host/include/host/ble_gatt.h
@@ -3,10 +3,10 @@
 
 #include <inttypes.h>
 struct ble_hs_conn;
-struct ble_hs_att_error_rsp;
+struct ble_att_error_rsp;
 
 void ble_gatt_rx_error(struct ble_hs_conn *conn,
-                       struct ble_hs_att_error_rsp *rsp);
+                       struct ble_att_error_rsp *rsp);
 void ble_gatt_wakeup(void);
 void ble_gatt_rx_mtu(struct ble_hs_conn *conn, uint16_t chan_mtu);
 int ble_gatt_mtu(uint16_t conn_handle);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/31f0c10b/net/nimble/host/include/host/ble_hs_test.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_hs_test.h b/net/nimble/host/include/host/ble_hs_test.h
index 874d92d..520c051 100644
--- a/net/nimble/host/include/host/ble_hs_test.h
+++ b/net/nimble/host/include/host/ble_hs_test.h
@@ -22,8 +22,8 @@ struct os_mbuf;
 void ble_hs_test_pkt_txed(struct os_mbuf *om);
 
 int l2cap_test_all(void);
-int ble_hs_att_svr_test_all(void);
-int ble_hs_att_clt_test_all(void);
+int ble_att_svr_test_all(void);
+int ble_att_clt_test_all(void);
 int ble_host_hci_test_all(void);
 int ble_hs_conn_test_all(void);
 int ble_gap_test_all(void);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/31f0c10b/net/nimble/host/src/ble_att.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att.c b/net/nimble/host/src/ble_att.c
new file mode 100644
index 0000000..3d2dc7a
--- /dev/null
+++ b/net/nimble/host/src/ble_att.c
@@ -0,0 +1,118 @@
+/**
+ * Copyright (c) 2015 Runtime Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stddef.h>
+#include <errno.h>
+#include "ble_l2cap.h"
+#include "ble_att_cmd.h"
+#include "ble_att.h"
+
+/** Dispatch table for incoming ATT requests.  Sorted by op code. */
+typedef int ble_att_rx_fn(struct ble_hs_conn *conn,
+                                 struct ble_l2cap_chan *chan,
+                                 struct os_mbuf *om);
+struct ble_att_rx_dispatch_entry {
+    uint8_t bde_op;
+    ble_att_rx_fn *bde_fn;
+};
+
+static struct ble_att_rx_dispatch_entry ble_att_rx_dispatch[] = {
+    { BLE_ATT_OP_MTU_REQ,              ble_att_svr_rx_mtu },
+    { BLE_ATT_OP_MTU_RSP,              ble_att_clt_rx_mtu },
+    { BLE_ATT_OP_FIND_INFO_REQ,        ble_att_svr_rx_find_info },
+    { BLE_ATT_OP_FIND_INFO_RSP,        ble_att_clt_rx_find_info },
+    { BLE_ATT_OP_FIND_TYPE_VALUE_REQ,  ble_att_svr_rx_find_type_value },
+    { BLE_ATT_OP_READ_TYPE_REQ,        ble_att_svr_rx_read_type },
+    { BLE_ATT_OP_READ_REQ,             ble_att_svr_rx_read },
+    { BLE_ATT_OP_WRITE_REQ,            ble_att_svr_rx_write },
+};
+
+#define BLE_ATT_RX_DISPATCH_SZ \
+    (sizeof ble_att_rx_dispatch / sizeof ble_att_rx_dispatch[0])
+
+static struct ble_att_rx_dispatch_entry *
+ble_att_rx_dispatch_entry_find(uint8_t op)
+{
+    struct ble_att_rx_dispatch_entry *entry;
+    int i;
+
+    for (i = 0; i < BLE_ATT_RX_DISPATCH_SZ; i++) {
+        entry = ble_att_rx_dispatch + i;
+        if (entry->bde_op == op) {
+            return entry;
+        }
+
+        if (entry->bde_op > op) {
+            break;
+        }
+    }
+
+    return NULL;
+}
+
+static int
+ble_att_rx(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan,
+           struct os_mbuf *om)
+{
+    struct ble_att_rx_dispatch_entry *entry;
+    uint8_t op;
+    int rc;
+
+    rc = os_mbuf_copydata(om, 0, 1, &op);
+    if (rc != 0) {
+        return EMSGSIZE;
+    }
+
+    entry = ble_att_rx_dispatch_entry_find(op);
+    if (entry == NULL) {
+        return EINVAL;
+    }
+
+    rc = entry->bde_fn(conn, chan, om);
+    if (rc != 0) {
+        return rc;
+    }
+
+    return 0;
+}
+
+void
+ble_att_set_peer_mtu(struct ble_l2cap_chan *chan, uint16_t peer_mtu)
+{
+    if (peer_mtu < BLE_ATT_MTU_DFLT) {
+        peer_mtu = BLE_ATT_MTU_DFLT;
+    }
+
+    chan->blc_peer_mtu = peer_mtu;
+}
+
+struct ble_l2cap_chan *
+ble_att_create_chan(void)
+{
+    struct ble_l2cap_chan *chan;
+
+    chan = ble_l2cap_chan_alloc();
+    if (chan == NULL) {
+        return NULL;
+    }
+
+    chan->blc_cid = BLE_L2CAP_CID_ATT;
+    chan->blc_my_mtu = BLE_ATT_MTU_DFLT;
+    chan->blc_default_mtu = BLE_ATT_MTU_DFLT;
+    chan->blc_rx_fn = ble_att_rx;
+
+    return chan;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/31f0c10b/net/nimble/host/src/ble_att.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att.h b/net/nimble/host/src/ble_att.h
new file mode 100644
index 0000000..c14fca0
--- /dev/null
+++ b/net/nimble/host/src/ble_att.h
@@ -0,0 +1,166 @@
+/**
+ * Copyright (c) 2015 Runtime Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef H_BLE_HS_ATT_
+#define H_BLE_HS_ATT_
+
+#include <inttypes.h>
+#include "os/queue.h"
+struct os_mbuf;
+struct ble_hs_conn;
+struct ble_l2cap_chan;
+struct ble_att_find_info_req;
+struct ble_att_error_rsp;
+struct ble_att_mtu_cmd;
+struct ble_att_read_req;
+struct ble_att_read_group_type_req;
+struct ble_att_read_group_type_rsp;
+
+#define BLE_ATT_MTU_DFLT         23  /* Also the minimum. */
+#define BLE_ATT_MTU_MAX          256 /* XXX: I'm making this up! */
+
+#define BLE_ATT_ERR_INVALID_HANDLE       0x01
+#define BLE_ATT_ERR_INVALID_PDU          0x04
+#define BLE_ATT_ERR_REQ_NOT_SUPPORTED    0x06
+#define BLE_ATT_ERR_ATTR_NOT_FOUND       0x0a
+#define BLE_ATT_ERR_UNLIKELY             0x0e
+#define BLE_ATT_ERR_INSUFFICIENT_RES     0x11
+
+union ble_att_svr_handle_arg {
+    struct {
+        void *attr_data;
+        int attr_len;
+    } aha_read;
+
+    struct {
+        struct os_mbuf *om;
+        int attr_len;
+    } aha_write;
+};
+
+struct ble_att_svr_entry;
+
+/**
+ * Called from ble_att_svr_walk().  Called on each entry in the 
+ * ble_att_svr_list.
+ *
+ * @param Contains the current ble_att being iterated through
+ * @param The user supplied argument to ble_att_svr_walk()
+ *
+ * @return 0 on continue, 1 on stop
+ */
+typedef int (*ble_att_svr_walk_func_t)(struct ble_att_svr_entry *entry,
+                                       void *arg);
+
+/**
+ * Handles a host attribute request.
+ *
+ * @param entry                 The host attribute being requested.
+ * @param op                    The operation being performed on the attribute.
+ * @param arg                   The request data associated with that host
+ *                                  attribute.
+ *
+ * @return                      0 on success;
+ *                              One of the BLE_ATT_ERR_[...] codes on
+ *                                  failure.
+ */
+typedef int ble_att_svr_handle_func(struct ble_att_svr_entry *entry,
+                                    uint8_t op,
+                                    union ble_att_svr_handle_arg *arg);
+
+#define HA_FLAG_PERM_READ            (1 << 0)
+#define HA_FLAG_PERM_WRITE           (1 << 1) 
+#define HA_FLAG_PERM_RW              (1 << 2)
+#define HA_FLAG_ENC_REQ              (1 << 3)
+#define HA_FLAG_AUTHENTICATION_REQ   (1 << 4)
+#define HA_FLAG_AUTHORIZATION_REQ    (1 << 5)
+
+struct ble_att_svr_entry {
+    STAILQ_ENTRY(ble_att_svr_entry) ha_next;
+
+    uint8_t ha_uuid[16];
+    uint8_t ha_flags;
+    uint8_t ha_pad1;
+    uint16_t ha_handle_id;
+    ble_att_svr_handle_func *ha_fn;
+};
+
+#define HA_OPCODE_METHOD_START (0)
+#define HA_OPCODE_METHOD_END (5)
+#define HA_OPCODE_COMMAND_FLAG (1 << 6) 
+#define HA_OPCODE_AUTH_SIG_FLAG (1 << 7) 
+
+struct ble_att_clt_entry {
+    SLIST_ENTRY(ble_att_clt_entry) bhac_next;
+    uint16_t bhac_handle_id;
+    uint8_t bhac_uuid[16];
+};
+
+SLIST_HEAD(ble_att_clt_entry_list, ble_att_clt_entry);
+
+/*** @gen */
+struct ble_l2cap_chan *ble_att_create_chan(void);
+void ble_att_set_peer_mtu(struct ble_l2cap_chan *chan, uint16_t peer_mtu);
+
+/*** @svr */
+int ble_att_svr_register(uint8_t *uuid, uint8_t flags, uint16_t *handle_id,
+                         ble_att_svr_handle_func *fn);
+
+
+int ble_att_svr_rx_mtu(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan,
+                       struct os_mbuf *om);
+int ble_att_svr_rx_find_info(struct ble_hs_conn *conn,
+                             struct ble_l2cap_chan *chan,
+                             struct os_mbuf *om);
+int ble_att_svr_rx_find_type_value(struct ble_hs_conn *conn,
+                                   struct ble_l2cap_chan *chan,
+                                   struct os_mbuf *om);
+int ble_att_svr_rx_read_type(struct ble_hs_conn *conn,
+                             struct ble_l2cap_chan *chan,
+                             struct os_mbuf *om);
+int ble_att_svr_rx_read(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan,
+                        struct os_mbuf *om);
+int ble_att_svr_rx_write(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan,
+                         struct os_mbuf *om);
+int ble_att_svr_init(void);
+
+/*** @clt */
+void ble_att_clt_entry_list_free(struct ble_att_clt_entry_list *list);
+int ble_att_clt_entry_insert(struct ble_hs_conn *conn, uint16_t handle_id,
+                             uint8_t *uuid);
+uint16_t ble_att_clt_find_entry_uuid128(struct ble_hs_conn *conn,
+                                        void *uuid128);
+uint16_t ble_att_clt_find_entry_uuid16(struct ble_hs_conn *conn,
+                                       uint16_t uuid16);
+int ble_att_clt_tx_mtu(struct ble_hs_conn *conn,
+                       struct ble_att_mtu_cmd *req);
+int ble_att_clt_rx_mtu(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan,
+                       struct os_mbuf *om);
+int ble_att_clt_tx_read(struct ble_hs_conn *conn,
+                        struct ble_att_read_req *req);
+int ble_att_clt_tx_find_info(struct ble_hs_conn *conn,
+                             struct ble_att_find_info_req *req);
+int ble_att_clt_rx_find_info(struct ble_hs_conn *conn,
+                             struct ble_l2cap_chan *chan, struct os_mbuf *om);
+int ble_att_clt_tx_read_group_type(struct ble_hs_conn *conn,
+                                   struct ble_att_read_group_type_req *req,
+                                   void *uuid128);
+int ble_att_clt_rx_read_group_type_rsp(struct ble_hs_conn *conn,
+                                       struct ble_l2cap_chan *chan,
+                                       struct os_mbuf *om);
+int ble_att_clt_init(void);
+
+#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/31f0c10b/net/nimble/host/src/ble_att_clt.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_clt.c b/net/nimble/host/src/ble_att_clt.c
new file mode 100644
index 0000000..6fe6a57
--- /dev/null
+++ b/net/nimble/host/src/ble_att_clt.c
@@ -0,0 +1,511 @@
+/**
+ * Copyright (c) 2015 Runtime Inc.
+ *
+ * Licensed 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 <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <assert.h>
+#include "os/os_mempool.h"
+#include "nimble/ble.h"
+#include "host/ble_gatt.h"
+#include "host/ble_hs.h"
+#include "ble_hs_uuid.h"
+#include "ble_hs_conn.h"
+#include "ble_att_cmd.h"
+#include "ble_att.h"
+
+#define BLE_ATT_CLT_NUM_ENTRIES  128
+static void *ble_att_clt_entry_mem;
+static struct os_mempool ble_att_clt_entry_pool;
+
+static struct ble_att_clt_entry *
+ble_att_clt_entry_alloc(void)
+{
+    struct ble_att_clt_entry *entry;
+
+    entry = os_memblock_get(&ble_att_clt_entry_pool);
+    if (entry != NULL) {
+        memset(entry, 0, sizeof *entry);
+    }
+
+    return entry;
+}
+
+static void
+ble_att_clt_entry_free(struct ble_att_clt_entry *entry)
+{
+    int rc;
+
+    rc = os_memblock_put(&ble_att_clt_entry_pool, entry);
+    assert(rc == 0);
+}
+
+void
+ble_att_clt_entry_list_free(struct ble_att_clt_entry_list *list)
+{
+    struct ble_att_clt_entry *entry;
+
+    while ((entry = SLIST_FIRST(list)) != NULL) {
+        SLIST_REMOVE_HEAD(list, bhac_next);
+        ble_att_clt_entry_free(entry);
+    }
+}
+
+int
+ble_att_clt_entry_insert(struct ble_hs_conn *conn, uint16_t handle_id,
+                         uint8_t *uuid)
+{
+    struct ble_att_clt_entry *entry;
+    struct ble_att_clt_entry *prev;
+    struct ble_att_clt_entry *cur;
+
+    /* XXX: Probably need to lock a semaphore here. */
+
+    entry = ble_att_clt_entry_alloc();
+    if (entry == NULL) {
+        return ENOMEM;
+    }
+
+    entry->bhac_handle_id = handle_id;
+    memcpy(entry->bhac_uuid, uuid, sizeof entry->bhac_uuid);
+
+    prev = NULL;
+    SLIST_FOREACH(cur, &conn->bhc_att_clt_list, bhac_next) {
+        if (cur->bhac_handle_id == handle_id) {
+            return EEXIST;
+        }
+        if (cur->bhac_handle_id > handle_id) {
+            break;
+        }
+
+        prev = cur;
+    }
+
+    if (prev == NULL) {
+        SLIST_INSERT_HEAD(&conn->bhc_att_clt_list, entry, bhac_next);
+    } else {
+        SLIST_INSERT_AFTER(prev, entry, bhac_next);
+    }
+
+    return 0;
+}
+
+uint16_t
+ble_att_clt_find_entry_uuid128(struct ble_hs_conn *conn, void *uuid128)
+{
+    struct ble_att_clt_entry *entry;
+    int rc;
+
+    SLIST_FOREACH(entry, &conn->bhc_att_clt_list, bhac_next) {
+        rc = memcmp(entry->bhac_uuid, uuid128, 16);
+        if (rc == 0) {
+            return entry->bhac_handle_id;
+        }
+    }
+
+    return 0;
+}
+
+static int
+ble_att_clt_prep_req(struct ble_hs_conn *conn, struct ble_l2cap_chan **chan,
+                     struct os_mbuf **txom, uint16_t initial_sz)
+{
+    void *buf;
+    int rc;
+
+    *chan = ble_hs_conn_chan_find(conn, BLE_L2CAP_CID_ATT);
+    assert(*chan != NULL);
+
+    *txom = os_mbuf_get_pkthdr(&ble_hs_mbuf_pool, 0);
+    if (*txom == NULL) {
+        rc = ENOMEM;
+        goto err;
+    }
+
+    buf = os_mbuf_extend(*txom, initial_sz);
+    if (buf == NULL) {
+        rc = ENOMEM;
+        goto err;
+    }
+
+    /* The caller expects the initial buffer to be at the start of the mbuf. */
+    assert(buf == (*txom)->om_data);
+
+    return 0;
+
+err:
+    os_mbuf_free_chain(*txom);
+    *txom = NULL;
+    return rc;
+}
+
+uint16_t
+ble_att_clt_find_entry_uuid16(struct ble_hs_conn *conn, uint16_t uuid16)
+{
+    uint8_t uuid128[16];
+    uint16_t handle_id;
+    int rc;
+
+    rc = ble_hs_uuid_from_16bit(uuid16, uuid128);
+    if (rc != 0) {
+        return 0;
+    }
+
+    handle_id = ble_att_clt_find_entry_uuid128(conn, uuid128);
+    return handle_id;
+}
+
+int
+ble_att_clt_tx_mtu(struct ble_hs_conn *conn, struct ble_att_mtu_cmd *req)
+{
+    struct ble_l2cap_chan *chan;
+    struct os_mbuf *txom;
+    int rc;
+
+    txom = NULL;
+
+    if (req->bhamc_mtu < BLE_ATT_MTU_DFLT) {
+        rc = EINVAL;
+        goto err;
+    }
+
+    rc = ble_att_clt_prep_req(conn, &chan, &txom, BLE_ATT_MTU_CMD_SZ);
+    if (rc != 0) {
+        goto err;
+    }
+
+    rc = ble_att_mtu_req_write(txom->om_data, txom->om_len, req);
+    if (rc != 0) {
+        goto err;
+    }
+
+    rc = ble_l2cap_tx(chan, txom);
+    txom = NULL;
+    if (rc != 0) {
+        goto err;
+    }
+
+    return 0;
+
+err:
+    os_mbuf_free_chain(txom);
+    return rc;
+}
+
+int
+ble_att_clt_rx_mtu(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan,
+                   struct os_mbuf *om)
+{
+    struct ble_att_mtu_cmd rsp;
+    int rc;
+
+    /* XXX: Pull up om */
+
+    rc = ble_att_mtu_cmd_parse(om->om_data, om->om_len, &rsp);
+    if (rc != 0) {
+        return rc;
+    }
+
+    ble_att_set_peer_mtu(chan, rsp.bhamc_mtu);
+
+    ble_gatt_rx_mtu(conn, ble_l2cap_chan_mtu(chan));
+
+    return 0;
+}
+
+int
+ble_att_clt_tx_find_info(struct ble_hs_conn *conn,
+                         struct ble_att_find_info_req *req)
+{
+    struct ble_l2cap_chan *chan;
+    struct os_mbuf *txom;
+    int rc;
+
+    txom = NULL;
+
+    if (req->bhafq_start_handle == 0 ||
+        req->bhafq_start_handle > req->bhafq_end_handle) {
+
+        rc = EINVAL;
+        goto err;
+    }
+
+    rc = ble_att_clt_prep_req(conn, &chan, &txom,
+                                 BLE_ATT_FIND_INFO_REQ_SZ);
+    if (rc != 0) {
+        goto err;
+    }
+
+    rc = ble_att_find_info_req_write(txom->om_data, txom->om_len, req);
+    if (rc != 0) {
+        goto err;
+    }
+
+    rc = ble_l2cap_tx(chan, txom);
+    txom = NULL;
+    if (rc != 0) {
+        goto err;
+    }
+
+    return 0;
+
+err:
+    os_mbuf_free_chain(txom);
+    return rc;
+}
+
+int
+ble_att_clt_rx_find_info(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan,
+                         struct os_mbuf *om)
+{
+    struct ble_att_find_info_rsp rsp;
+    uint16_t handle_id;
+    uint16_t uuid16;
+    uint8_t uuid128[16];
+    int off;
+    int rc;
+
+    /* XXX: Pull up om */
+
+    rc = ble_att_find_info_rsp_parse(om->om_data, om->om_len, &rsp);
+    if (rc != 0) {
+        return rc;
+    }
+
+    handle_id = 0;
+    off = BLE_ATT_FIND_INFO_RSP_MIN_SZ;
+    while (off < OS_MBUF_PKTHDR(om)->omp_len) {
+        rc = os_mbuf_copydata(om, off, 2, &handle_id);
+        if (rc != 0) {
+            rc = EINVAL;
+            goto done;
+        }
+        off += 2;
+        handle_id = le16toh(&handle_id);
+
+        switch (rsp.bhafp_format) {
+        case BLE_ATT_FIND_INFO_RSP_FORMAT_16BIT:
+            rc = os_mbuf_copydata(om, off, 2, &uuid16);
+            if (rc != 0) {
+                rc = EINVAL;
+                goto done;
+            }
+            off += 2;
+            uuid16 = le16toh(&uuid16);
+
+            rc = ble_hs_uuid_from_16bit(uuid16, uuid128);
+            if (rc != 0) {
+                rc = EINVAL;
+                goto done;
+            }
+            break;
+
+        case BLE_ATT_FIND_INFO_RSP_FORMAT_128BIT:
+            rc = os_mbuf_copydata(om, off, 16, &uuid128);
+            if (rc != 0) {
+                rc = EINVAL;
+                goto done;
+            }
+            off += 16;
+            break;
+
+        default:
+            rc = EINVAL;
+            goto done;
+        }
+
+        rc = ble_att_clt_entry_insert(conn, handle_id, uuid128);
+        if (rc != 0) {
+            return rc;
+        }
+    }
+
+    rc = 0;
+
+done:
+    ble_gatt_rx_find_info(conn, -rc, handle_id);
+    return rc;
+}
+
+int
+ble_att_clt_tx_read(struct ble_hs_conn *conn, struct ble_att_read_req *req)
+{
+    struct ble_l2cap_chan *chan;
+    struct os_mbuf *txom;
+    int rc;
+
+    txom = NULL;
+
+    if (req->bharq_handle == 0) {
+        rc = EINVAL;
+        goto err;
+    }
+
+    rc = ble_att_clt_prep_req(conn, &chan, &txom, BLE_ATT_READ_REQ_SZ);
+    if (rc != 0) {
+        goto err;
+    }
+
+    rc = ble_att_read_req_write(txom->om_data, txom->om_len, req);
+    if (rc != 0) {
+        goto err;
+    }
+
+    rc = ble_l2cap_tx(chan, txom);
+    txom = NULL;
+    if (rc != 0) {
+        goto err;
+    }
+
+    return 0;
+
+err:
+    os_mbuf_free_chain(txom);
+    return rc;
+}
+
+int
+ble_att_clt_tx_read_group_type(struct ble_hs_conn *conn,
+                               struct ble_att_read_group_type_req *req,
+                               void *uuid128)
+{
+    struct ble_l2cap_chan *chan;
+    struct os_mbuf *txom;
+    int rc;
+
+    txom = NULL;
+
+    if (req->bhagq_start_handle == 0 ||
+        req->bhagq_start_handle > req->bhagq_end_handle) {
+
+        rc = EINVAL;
+        goto err;
+    }
+
+    rc = ble_att_clt_prep_req(conn, &chan, &txom,
+                                 BLE_ATT_READ_GROUP_TYPE_REQ_BASE_SZ);
+    if (rc != 0) {
+        goto err;
+    }
+
+    rc = ble_att_read_group_type_req_write(txom->om_data, txom->om_len,
+                                              req);
+    if (rc != 0) {
+        goto err;
+    }
+
+    rc = ble_hs_uuid_append(txom, uuid128);
+    if (rc != 0) {
+        goto err;
+    }
+
+    rc = ble_l2cap_tx(chan, txom);
+    txom = NULL;
+    if (rc != 0) {
+        goto err;
+    }
+
+    return 0;
+
+err:
+    os_mbuf_free_chain(txom);
+    return rc;
+}
+
+struct ble_att_clt_adata {
+    uint16_t att_handle;
+    uint16_t end_group_handle;
+    void *value;
+};
+
+static int
+ble_att_clt_parse_attribute_data(struct os_mbuf *om, int data_len,
+                                 struct ble_att_clt_adata *adata)
+{
+    /* XXX: Pull up om */
+
+    adata->att_handle = le16toh(om->om_data + 0);
+    adata->end_group_handle = le16toh(om->om_data + 2);
+    adata->value = om->om_data + 6;
+
+    return 0;
+}
+
+int
+ble_att_clt_rx_read_group_type_rsp(struct ble_hs_conn *conn,
+                                   struct ble_l2cap_chan *chan,
+                                   struct os_mbuf *om)
+{
+    struct ble_att_read_group_type_rsp rsp;
+    struct ble_att_clt_adata adata;
+    int rc;
+
+    /* XXX: Pull up om */
+
+    rc = ble_att_read_group_type_rsp_parse(om->om_data, om->om_len, &rsp);
+    if (rc != 0) {
+        return rc;
+    }
+
+    /* XXX: Verify group handle is valid. */
+
+    while (OS_MBUF_PKTHDR(om)->omp_len > 0) {
+        rc = ble_att_clt_parse_attribute_data(om, rsp.bhagp_length, &adata);
+        if (rc != 0) {
+            break;
+        }
+
+        /* Save attribute mapping? */
+
+        /* XXX: Pass adata to GATT callback. */
+
+        os_mbuf_adj(om, rsp.bhagp_length);
+    }
+
+    return 0;
+}
+
+int
+ble_att_clt_init(void)
+{
+    int rc;
+
+    free(ble_att_clt_entry_mem);
+    ble_att_clt_entry_mem = malloc(
+        OS_MEMPOOL_BYTES(BLE_ATT_CLT_NUM_ENTRIES,
+                         sizeof (struct ble_att_clt_entry)));
+    if (ble_att_clt_entry_mem == NULL) {
+        rc = ENOMEM;
+        goto err;
+    }
+
+    rc = os_mempool_init(&ble_att_clt_entry_pool,
+                         BLE_ATT_CLT_NUM_ENTRIES,
+                         sizeof (struct ble_att_clt_entry),
+                         ble_att_clt_entry_mem,
+                         "ble_att_clt_entry_pool");
+    if (rc != 0) {
+        goto err;
+    }
+
+    return 0;
+
+err:
+    free(ble_att_clt_entry_mem);
+    ble_att_clt_entry_mem = NULL;
+
+    return rc;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/31f0c10b/net/nimble/host/src/ble_att_cmd.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_cmd.c b/net/nimble/host/src/ble_att_cmd.c
new file mode 100644
index 0000000..72306dd
--- /dev/null
+++ b/net/nimble/host/src/ble_att_cmd.c
@@ -0,0 +1,482 @@
+/**
+ * Copyright (c) 2015 Runtime Inc.
+ *
+ * Licensed 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 "os/os.h"
+#include "nimble/ble.h"
+#include "ble_hs_uuid.h"
+#include "ble_l2cap.h"
+#include "ble_att_cmd.h"
+
+int
+ble_att_error_rsp_parse(void *payload, int len,
+                           struct ble_att_error_rsp *rsp)
+{
+    uint8_t *u8ptr;
+
+    if (len < BLE_ATT_ERROR_RSP_SZ) {
+        return EMSGSIZE;
+    }
+
+    u8ptr = payload;
+
+    if (u8ptr[0] != BLE_ATT_OP_ERROR_RSP) {
+        return EINVAL;
+    }
+
+    rsp->bhaep_req_op = u8ptr[1];
+    rsp->bhaep_handle = le16toh(u8ptr + 2);
+    rsp->bhaep_error_code = u8ptr[4];
+
+    return 0;
+}
+
+int
+ble_att_error_rsp_write(void *payload, int len,
+                           struct ble_att_error_rsp *rsp)
+{
+    uint8_t *u8ptr;
+
+    if (len < BLE_ATT_ERROR_RSP_SZ) {
+        return EMSGSIZE;
+    }
+
+    u8ptr = payload;
+
+    u8ptr[0] = BLE_ATT_OP_ERROR_RSP;
+    u8ptr[1] = rsp->bhaep_req_op;
+    htole16(u8ptr + 2, rsp->bhaep_handle);
+    u8ptr[4] = rsp->bhaep_error_code;
+
+    return 0;
+}
+
+int
+ble_att_mtu_cmd_parse(void *payload, int len,
+                         struct ble_att_mtu_cmd *cmd)
+{
+    uint8_t *u8ptr;
+
+    if (len < BLE_ATT_MTU_CMD_SZ) {
+        return EMSGSIZE;
+    }
+
+    u8ptr = payload;
+
+    if (u8ptr[0] != BLE_ATT_OP_MTU_REQ &&
+        u8ptr[0] != BLE_ATT_OP_MTU_RSP) {
+
+        return EINVAL;
+    }
+
+    cmd->bhamc_mtu = le16toh(u8ptr + 1);
+
+    return 0;
+}
+
+int
+ble_att_mtu_req_write(void *payload, int len,
+                         struct ble_att_mtu_cmd *cmd)
+{
+    uint8_t *u8ptr;
+
+    if (len < BLE_ATT_MTU_CMD_SZ) {
+        return EMSGSIZE;
+    }
+
+    u8ptr = payload;
+
+    u8ptr[0] = BLE_ATT_OP_MTU_REQ;
+    htole16(u8ptr + 1, cmd->bhamc_mtu);
+
+    return 0;
+}
+
+int
+ble_att_mtu_rsp_write(void *payload, int len,
+                         struct ble_att_mtu_cmd *cmd)
+{
+    uint8_t *u8ptr;
+
+    if (len < BLE_ATT_MTU_CMD_SZ) {
+        return EMSGSIZE;
+    }
+
+    u8ptr = payload;
+
+    u8ptr[0] = BLE_ATT_OP_MTU_RSP;
+    htole16(u8ptr + 1, cmd->bhamc_mtu);
+
+    return 0;
+}
+
+int
+ble_att_find_info_req_parse(void *payload, int len,
+                               struct ble_att_find_info_req *req)
+{
+    uint8_t *u8ptr;
+
+    if (len < BLE_ATT_FIND_INFO_REQ_SZ) {
+        return EMSGSIZE;
+    }
+
+    u8ptr = payload;
+
+    if (u8ptr[0] != BLE_ATT_OP_FIND_INFO_REQ) {
+        return EINVAL;
+    }
+
+    req->bhafq_start_handle = le16toh(u8ptr + 1);
+    req->bhafq_end_handle = le16toh(u8ptr + 3);
+
+    return 0;
+}
+
+int
+ble_att_find_info_req_write(void *payload, int len,
+                               struct ble_att_find_info_req *req)
+{
+    uint8_t *u8ptr;
+
+    if (len < BLE_ATT_FIND_INFO_REQ_SZ) {
+        return EMSGSIZE;
+    }
+
+    u8ptr = payload;
+
+    u8ptr[0] = BLE_ATT_OP_FIND_INFO_REQ;
+    htole16(u8ptr + 1, req->bhafq_start_handle);
+    htole16(u8ptr + 3, req->bhafq_end_handle);
+
+    return 0;
+}
+
+int
+ble_att_find_info_rsp_parse(void *payload, int len,
+                               struct ble_att_find_info_rsp *rsp)
+{
+    uint8_t *u8ptr;
+
+    if (len < BLE_ATT_FIND_INFO_RSP_MIN_SZ) {
+        return EMSGSIZE;
+    }
+
+    u8ptr = payload;
+
+    if (u8ptr[0] != BLE_ATT_OP_FIND_INFO_RSP) {
+        return EINVAL;
+    }
+
+    rsp->bhafp_format = u8ptr[1];
+
+    return 0;
+}
+
+int
+ble_att_find_info_rsp_write(void *payload, int len,
+                               struct ble_att_find_info_rsp *rsp)
+{
+    uint8_t *u8ptr;
+
+    if (len < BLE_ATT_FIND_INFO_RSP_MIN_SZ) {
+        return EMSGSIZE;
+    }
+
+    u8ptr = payload;
+
+    u8ptr[0] = BLE_ATT_OP_FIND_INFO_RSP;
+    u8ptr[1] = rsp->bhafp_format;
+
+    return 0;
+}
+
+int
+ble_att_find_type_value_req_parse(
+    void *payload, int len, struct ble_att_find_type_value_req *req)
+{
+    uint8_t *u8ptr;
+
+    if (len < BLE_ATT_FIND_TYPE_VALUE_REQ_MIN_SZ) {
+        return EMSGSIZE;
+    }
+
+    u8ptr = payload;
+
+    if (u8ptr[0] != BLE_ATT_OP_FIND_TYPE_VALUE_REQ) {
+        return EINVAL;
+    }
+
+    req->bhavq_start_handle = le16toh(u8ptr + 1);
+    req->bhavq_end_handle = le16toh(u8ptr + 3);
+    req->bhavq_attr_type = le16toh(u8ptr + 5);
+
+    return 0;
+}
+
+int
+ble_att_find_type_value_req_write(
+    void *payload, int len, struct ble_att_find_type_value_req *req)
+{
+    uint8_t *u8ptr;
+
+    if (len < BLE_ATT_FIND_TYPE_VALUE_REQ_MIN_SZ) {
+        return EMSGSIZE;
+    }
+
+    u8ptr = payload;
+
+    u8ptr[0] = BLE_ATT_OP_FIND_TYPE_VALUE_REQ;
+    htole16(u8ptr + 1, req->bhavq_start_handle);
+    htole16(u8ptr + 3, req->bhavq_end_handle);
+    htole16(u8ptr + 5, req->bhavq_attr_type);
+
+    return 0;
+}
+
+int
+ble_att_read_type_req_parse(void *payload, int len,
+                               struct ble_att_read_type_req *req)
+{
+    uint8_t *u8ptr;
+
+    if (len < BLE_ATT_READ_TYPE_REQ_MIN_SZ) {
+        return EMSGSIZE;
+    }
+
+    u8ptr = payload;
+
+    if (u8ptr[0] != BLE_ATT_OP_READ_TYPE_REQ) {
+        return EINVAL;
+    }
+
+    req->bhatq_start_handle = le16toh(u8ptr + 1);
+    req->bhatq_end_handle = le16toh(u8ptr + 3);
+
+    return 0;
+}
+
+int
+ble_att_read_type_req_write(void *payload, int len,
+                               struct ble_att_read_type_req *req)
+{
+    uint8_t *u8ptr;
+
+    if (len < BLE_ATT_READ_TYPE_REQ_MIN_SZ) {
+        return EMSGSIZE;
+    }
+
+    u8ptr = payload;
+
+    u8ptr[0] = BLE_ATT_OP_READ_TYPE_REQ;
+    htole16(u8ptr + 1, req->bhatq_start_handle);
+    htole16(u8ptr + 3, req->bhatq_end_handle);
+
+    return 0;
+}
+
+int
+ble_att_read_type_rsp_parse(void *payload, int len,
+                               struct ble_att_read_type_rsp *rsp)
+{
+    uint8_t *u8ptr;
+
+    if (len < BLE_ATT_READ_TYPE_RSP_MIN_SZ) {
+        return EMSGSIZE;
+    }
+
+    u8ptr = payload;
+
+    rsp->bhatp_len = u8ptr[1];
+
+    return 0;
+}
+
+int
+ble_att_read_type_rsp_write(void *payload, int len,
+                               struct ble_att_read_type_rsp *rsp)
+{
+    uint8_t *u8ptr;
+
+    if (len < BLE_ATT_READ_TYPE_RSP_MIN_SZ) {
+        return EMSGSIZE;
+    }
+
+    u8ptr = payload;
+
+    u8ptr[0] = BLE_ATT_OP_READ_TYPE_RSP;
+    u8ptr[1] = rsp->bhatp_len;
+
+    return 0;
+}
+
+int
+ble_att_read_req_parse(void *payload, int len,
+                          struct ble_att_read_req *req)
+{
+    uint8_t *u8ptr;
+
+    if (len < BLE_ATT_READ_REQ_SZ) {
+        return EMSGSIZE;
+    }
+
+    u8ptr = payload;
+
+    if (u8ptr[0] != BLE_ATT_OP_READ_REQ) {
+        return EINVAL;
+    }
+
+    req->bharq_handle = le16toh(u8ptr + 1);
+
+    return 0;
+}
+
+int
+ble_att_read_req_write(void *payload, int len,
+                          struct ble_att_read_req *req)
+{
+    uint8_t *u8ptr;
+
+    if (len < BLE_ATT_READ_REQ_SZ) {
+        return EMSGSIZE;
+    }
+
+    u8ptr = payload;
+
+    u8ptr[0] = BLE_ATT_OP_READ_REQ;
+    htole16(u8ptr + 1, req->bharq_handle);
+
+    return 0;
+}
+
+int
+ble_att_read_group_type_req_parse(
+    void *payload, int len, struct ble_att_read_group_type_req *req)
+{
+    uint8_t *u8ptr;
+
+    if (len < BLE_ATT_READ_GROUP_TYPE_REQ_BASE_SZ) {
+        return EMSGSIZE;
+    }
+
+    u8ptr = payload;
+
+    if (u8ptr[0] != BLE_ATT_OP_READ_GROUP_TYPE_REQ) {
+        return EINVAL;
+    }
+
+    req->bhagq_start_handle = le16toh(u8ptr + 1);
+    req->bhagq_end_handle = le16toh(u8ptr + 3);
+
+    return 0;
+}
+
+int
+ble_att_read_group_type_req_write(
+    void *payload, int len, struct ble_att_read_group_type_req *req)
+{
+    uint8_t *u8ptr;
+
+    if (len < BLE_ATT_READ_GROUP_TYPE_REQ_BASE_SZ) {
+        return EMSGSIZE;
+    }
+
+    u8ptr = payload;
+
+    u8ptr[0] = BLE_ATT_OP_READ_GROUP_TYPE_REQ;
+    htole16(u8ptr + 1, req->bhagq_start_handle);
+    htole16(u8ptr + 3, req->bhagq_end_handle);
+
+    return 0;
+}
+
+int
+ble_att_read_group_type_rsp_parse(
+    void *payload, int len, struct ble_att_read_group_type_rsp *rsp)
+{
+    uint8_t *u8ptr;
+
+    if (len < BLE_ATT_READ_GROUP_TYPE_RSP_BASE_SZ) {
+        return EMSGSIZE;
+    }
+
+    u8ptr = payload;
+
+    if (u8ptr[0] != BLE_ATT_OP_READ_GROUP_TYPE_RSP) {
+        return EINVAL;
+    }
+
+    rsp->bhagp_length = u8ptr[1];
+
+    return 0;
+}
+
+int
+ble_att_read_group_type_rsp_write(
+    void *payload, int len, struct ble_att_read_group_type_rsp *rsp)
+{
+    uint8_t *u8ptr;
+
+    if (len < BLE_ATT_READ_GROUP_TYPE_RSP_BASE_SZ) {
+        return EMSGSIZE;
+    }
+
+    u8ptr = payload;
+
+    u8ptr[0] = BLE_ATT_OP_READ_GROUP_TYPE_RSP;
+    u8ptr[1] = rsp->bhagp_length;
+
+    return 0;
+}
+
+int
+ble_att_write_req_parse(void *payload, int len,
+                           struct ble_att_write_req *req)
+{
+    uint8_t *u8ptr;
+
+    if (len < BLE_ATT_WRITE_REQ_MIN_SZ) {
+        return EMSGSIZE;
+    }
+
+    u8ptr = payload;
+
+    if (u8ptr[0] != BLE_ATT_OP_WRITE_REQ) {
+        return EINVAL;
+    }
+
+    req->bhawq_handle = le16toh(u8ptr + 1);
+
+    return 0;
+}
+
+int
+ble_att_write_req_write(void *payload, int len,
+                           struct ble_att_write_req *req)
+{
+    uint8_t *u8ptr;
+
+    if (len < BLE_ATT_WRITE_REQ_MIN_SZ) {
+        return EMSGSIZE;
+    }
+
+    u8ptr = payload;
+
+    u8ptr[0] = BLE_ATT_OP_WRITE_REQ;
+    htole16(u8ptr + 1, req->bhawq_handle);
+
+    return 0;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/31f0c10b/net/nimble/host/src/ble_att_cmd.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_cmd.h b/net/nimble/host/src/ble_att_cmd.h
new file mode 100644
index 0000000..062a057
--- /dev/null
+++ b/net/nimble/host/src/ble_att_cmd.h
@@ -0,0 +1,249 @@
+/**
+ * Copyright (c) 2015 Runtime Inc.
+ *
+ * Licensed 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 <inttypes.h>
+struct ble_l2cap_chan;
+
+#define BLE_ATT_OP_ERROR_RSP             0x01
+#define BLE_ATT_OP_MTU_REQ               0x02
+#define BLE_ATT_OP_MTU_RSP               0x03
+#define BLE_ATT_OP_FIND_INFO_REQ         0x04
+#define BLE_ATT_OP_FIND_INFO_RSP         0x05
+#define BLE_ATT_OP_FIND_TYPE_VALUE_REQ   0x06
+#define BLE_ATT_OP_FIND_TYPE_VALUE_RSP   0x07
+#define BLE_ATT_OP_READ_TYPE_REQ         0x08
+#define BLE_ATT_OP_READ_TYPE_RSP         0x09
+#define BLE_ATT_OP_READ_REQ              0x0a
+#define BLE_ATT_OP_READ_RSP              0x0b
+#define BLE_ATT_OP_READ_GROUP_TYPE_REQ   0x10
+#define BLE_ATT_OP_READ_GROUP_TYPE_RSP   0x11
+#define BLE_ATT_OP_WRITE_REQ             0x12
+#define BLE_ATT_OP_WRITE_RSP             0x13
+
+/**
+ * | Parameter                          | Size (octets)     |
+ * +------------------------------------+-------------------+
+ * | Attribute Opcode                   | 1                 |
+ * | Request Opcode In Error            | 1                 |
+ * | Attribute Handle In Error          | 2                 |
+ * | Error Code                         | 1                 |
+ */
+#define BLE_ATT_ERROR_RSP_SZ             5
+struct ble_att_error_rsp {
+    uint8_t bhaep_req_op;
+    uint16_t bhaep_handle;
+    uint8_t bhaep_error_code;
+};
+
+/**
+ * | Parameter                          | Size (octets)     |
+ * +------------------------------------+-------------------+
+ * | Attribute Opcode                   | 1                 |
+ * | Server Rx MTU                      | 2                 |
+ */
+#define BLE_ATT_MTU_CMD_SZ               3
+struct ble_att_mtu_cmd {
+    uint16_t bhamc_mtu;
+};
+
+/**
+ * | Parameter                          | Size (octets)     |
+ * +------------------------------------+-------------------+
+ * | Attribute Opcode                   | 1                 |
+ * | Starting Handle                    | 2                 |
+ * | Ending Handle                      | 2                 |
+ */
+#define BLE_ATT_FIND_INFO_REQ_SZ         5
+struct ble_att_find_info_req {
+    uint16_t bhafq_start_handle;
+    uint16_t bhafq_end_handle;
+};
+
+/**
+ * | Parameter                          | Size (octets)     |
+ * +------------------------------------+-------------------+
+ * | Attribute Opcode                   | 1                 |
+ * | Format                             | 1                 |
+ * | Information Data                   | 4 to (ATT_MTU-2)  |
+ */
+#define BLE_ATT_FIND_INFO_RSP_MIN_SZ     2
+struct ble_att_find_info_rsp {
+    uint8_t bhafp_format;
+    /* Followed by information data. */
+};
+
+#define BLE_ATT_FIND_INFO_RSP_FORMAT_16BIT   1
+#define BLE_ATT_FIND_INFO_RSP_FORMAT_128BIT  2
+
+/**
+ * | Parameter                          | Size (octets)     |
+ * +------------------------------------+-------------------+
+ * | Attribute Opcode                   | 1                 |
+ * | Starting Handle                    | 2                 |
+ * | Ending Handle                      | 2                 |
+ * | Attribute Type                     | 2                 |
+ * | Attribute Value                    | 0 to (ATT_MTU-7)  |
+ */
+#define BLE_ATT_FIND_TYPE_VALUE_REQ_MIN_SZ   7
+struct ble_att_find_type_value_req {
+    uint16_t bhavq_start_handle;
+    uint16_t bhavq_end_handle;
+    uint16_t bhavq_attr_type;
+};
+
+/**
+ * | Parameter                          | Size (octets)     |
+ * +------------------------------------+-------------------+
+ * | Attribute Opcode                   | 1                 |
+ * | Information Data                   | 4 to (ATT_MTU-1)  |
+ */
+#define BLE_ATT_FIND_TYPE_VALUE_RSP_MIN_SZ   1
+
+/**
+ * | Parameter                          | Size (octets)     |
+ * +------------------------------------+-------------------+
+ * | Attribute Opcode                   | 1                 |
+ * | Starting Handle                    | 2                 |
+ * | Ending Handle                      | 2                 |
+ * | Attribute Type                     | 2 or 16           |
+ */
+#define BLE_ATT_READ_TYPE_REQ_MIN_SZ     7
+#define BLE_ATT_READ_TYPE_REQ_SZ_16      7
+#define BLE_ATT_READ_TYPE_REQ_SZ_128     21
+struct ble_att_read_type_req {
+    uint16_t bhatq_start_handle;
+    uint16_t bhatq_end_handle;
+};
+
+/**
+ * | Parameter                          | Size (octets)     |
+ * +------------------------------------+-------------------+
+ * | Attribute Opcode                   | 1                 |
+ * | Length                             | 1                 |
+ * | Attribute Data List                | 2 to (ATT_MTU-2)  |
+ */
+#define BLE_ATT_READ_TYPE_RSP_MIN_SZ     2
+struct ble_att_read_type_rsp {
+    uint8_t bhatp_len;
+};
+
+/**
+ * | Parameter                          | Size (octets)     |
+ * +------------------------------------+-------------------+
+ * | Attribute Opcode                   | 1                 |
+ * | Attribute Handle                   | 2                 |
+ */
+#define BLE_ATT_READ_REQ_SZ              3
+struct ble_att_read_req {
+    uint16_t bharq_handle;
+};
+
+/**
+ * | Parameter                          | Size (octets)     |
+ * +------------------------------------+-------------------+
+ * | Attribute Opcode                   | 1                 |
+ * | Attribute Value                    | 0 to (ATT_MTU-1)  |
+ */
+#define BLE_ATT_READ_RSP_MIN_SZ          1
+
+/**
+ * | Parameter                          | Size (octets)     |
+ * +------------------------------------+-------------------+
+ * | Attribute Opcode                   | 1                 |
+ * | Starting Handle                    | 2                 |
+ * | Ending Handle                      | 2                 |
+ * | Attribute Group Type               | 2 or 16           |
+ */
+#define BLE_ATT_READ_GROUP_TYPE_REQ_BASE_SZ  5
+#define BLE_ATT_READ_GROUP_TYPE_REQ_SZ_16    7
+#define BLE_ATT_READ_GROUP_TYPE_REQ_SZ_128   21
+struct ble_att_read_group_type_req {
+    uint16_t bhagq_start_handle;
+    uint16_t bhagq_end_handle;
+};
+
+/**
+ * | Parameter                          | Size (octets)     |
+ * +------------------------------------+-------------------+
+ * | Attribute Opcode                   | 1                 |
+ * | Length                             | 1                 |
+ * | Attribute Data List                | 2 to (ATT_MTU-2)  |
+ */
+#define BLE_ATT_READ_GROUP_TYPE_RSP_BASE_SZ  2
+struct ble_att_read_group_type_rsp {
+    uint8_t bhagp_length;
+};
+
+/**
+ * | Parameter                          | Size (octets)     |
+ * +------------------------------------+-------------------+
+ * | Attribute Opcode                   | 1                 |
+ * | Attribute Handle                   | 2                 |
+ * | Attribute Value                    | 0 to (ATT_MTU-3)  |
+ */
+#define BLE_ATT_WRITE_REQ_MIN_SZ         3
+struct ble_att_write_req {
+    uint16_t bhawq_handle;
+};
+
+#define BLE_ATT_WRITE_RSP_SZ             1
+
+int ble_att_error_rsp_parse(void *payload, int len,
+                               struct ble_att_error_rsp *rsp);
+int ble_att_error_rsp_write(void *payload, int len,
+                               struct ble_att_error_rsp *rsp);
+int ble_att_mtu_cmd_parse(void *payload, int len,
+                             struct ble_att_mtu_cmd *cmd);
+int ble_att_mtu_req_write(void *payload, int len,
+                             struct ble_att_mtu_cmd *cmd);
+int ble_att_mtu_rsp_write(void *payload, int len,
+                             struct ble_att_mtu_cmd *cmd);
+int ble_att_find_info_req_parse(void *payload, int len,
+                                   struct ble_att_find_info_req *req);
+int ble_att_find_info_req_write(void *payload, int len,
+                                   struct ble_att_find_info_req *req);
+int ble_att_find_info_rsp_parse(void *payload, int len,
+                                   struct ble_att_find_info_rsp *rsp);
+int ble_att_find_info_rsp_write(void *payload, int len,
+                                   struct ble_att_find_info_rsp *rsp);
+int ble_att_find_type_value_req_parse(
+    void *payload, int len, struct ble_att_find_type_value_req *req);
+int ble_att_find_type_value_req_write(
+    void *payload, int len, struct ble_att_find_type_value_req *req);
+int ble_att_read_req_parse(void *payload, int len,
+                              struct ble_att_read_req *req);
+int ble_att_read_req_write(void *payload, int len,
+                              struct ble_att_read_req *req);
+int ble_att_read_type_req_parse(void *payload, int len,
+                                   struct ble_att_read_type_req *req);
+int ble_att_read_type_req_write(void *payload, int len,
+                                   struct ble_att_read_type_req *req);
+int ble_att_read_type_rsp_parse(void *payload, int len,
+                                   struct ble_att_read_type_rsp *rsp);
+int ble_att_read_type_rsp_write(void *payload, int len,
+                                   struct ble_att_read_type_rsp *rsp);
+int ble_att_read_group_type_req_parse(
+    void *payload, int len, struct ble_att_read_group_type_req *req);
+int ble_att_read_group_type_req_write(
+    void *payload, int len, struct ble_att_read_group_type_req *req);
+int ble_att_read_group_type_rsp_parse(
+    void *payload, int len, struct ble_att_read_group_type_rsp *rsp);
+int ble_att_read_group_type_rsp_write(
+    void *payload, int len, struct ble_att_read_group_type_rsp *rsp);
+int ble_att_write_req_parse(void *payload, int len,
+                               struct ble_att_write_req *req);
+int ble_att_write_req_write(void *payload, int len,
+                               struct ble_att_write_req *req);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/31f0c10b/net/nimble/host/src/ble_att_svr.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_svr.c b/net/nimble/host/src/ble_att_svr.c
new file mode 100644
index 0000000..39c8cc2
--- /dev/null
+++ b/net/nimble/host/src/ble_att_svr.c
@@ -0,0 +1,1226 @@
+/**
+ * Copyright (c) 2015 Runtime Inc.
+ *
+ * Licensed 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 <errno.h>
+#include <assert.h>
+#include "os/os.h"
+#include "nimble/ble.h"
+#include "host/ble_hs.h"
+#include "ble_l2cap.h"
+#include "ble_hs_conn.h"
+#include "ble_hs_uuid.h"
+#include "ble_att_cmd.h"
+#include "ble_att.h"
+
+static STAILQ_HEAD(, ble_att_svr_entry) ble_att_svr_list;
+static uint16_t ble_att_svr_id;
+
+static struct os_mutex ble_att_svr_list_mutex;
+
+#define BLE_ATT_SVR_NUM_ENTRIES          32
+static void *ble_att_svr_entry_mem;
+static struct os_mempool ble_att_svr_entry_pool;
+
+/**
+ * Locks the host attribute list.
+ *
+ * @return 0 on success, non-zero error code on failure.
+ */
+static void
+ble_att_svr_list_lock(void)
+{
+    int rc;
+
+    rc = os_mutex_pend(&ble_att_svr_list_mutex, OS_WAIT_FOREVER);
+    assert(rc == 0 || rc == OS_NOT_STARTED);
+}
+
+/**
+ * Unlocks the host attribute list
+ *
+ * @return 0 on success, non-zero error code on failure.
+ */
+static void
+ble_att_svr_list_unlock(void)
+{
+    int rc;
+
+    rc = os_mutex_release(&ble_att_svr_list_mutex);
+    assert(rc == 0 || rc == OS_NOT_STARTED);
+}
+
+static struct ble_att_svr_entry *
+ble_att_svr_entry_alloc(void)
+{
+    struct ble_att_svr_entry *entry;
+
+    entry = os_memblock_get(&ble_att_svr_entry_pool);
+    if (entry != NULL) {
+        memset(entry, 0, sizeof *entry);
+    }
+
+    return entry;
+}
+
+#if 0
+static void
+ble_att_svr_entry_free(struct ble_att_svr_entry *entry)
+{
+    int rc;
+
+    rc = os_memblock_put(&ble_att_svr_entry_pool, entry);
+    assert(rc == 0);
+}
+#endif
+
+/**
+ * Allocate the next handle id and return it.
+ *
+ * @return A new 16-bit handle ID.
+ */
+static uint16_t
+ble_att_svr_next_id(void)
+{
+    /* Rollover is fatal. */
+    assert(ble_att_svr_id != UINT16_MAX);
+
+    return (++ble_att_svr_id);
+}
+
+/**
+ * Register a host attribute with the BLE stack.
+ *
+ * @param ha                    A filled out ble_att structure to register
+ * @param handle_id             A pointer to a 16-bit handle ID, which will be
+ *                                  the handle that is allocated.
+ * @param fn                    The callback function that gets executed when
+ *                                  the attribute is operated on.
+ *
+ * @return 0 on success, non-zero error code on failure.
+ */
+int
+ble_att_svr_register(uint8_t *uuid, uint8_t flags, uint16_t *handle_id,
+                     ble_att_svr_handle_func *fn)
+{
+    struct ble_att_svr_entry *entry;
+
+    entry = ble_att_svr_entry_alloc();
+    if (entry == NULL) {
+        return ENOMEM;
+    }
+
+    memcpy(&entry->ha_uuid, uuid, sizeof entry->ha_uuid);
+    entry->ha_flags = flags;
+    entry->ha_handle_id = ble_att_svr_next_id();
+    entry->ha_fn = fn;
+
+    ble_att_svr_list_lock();
+    STAILQ_INSERT_TAIL(&ble_att_svr_list, entry, ha_next);
+    ble_att_svr_list_unlock();
+
+    if (handle_id != NULL) {
+        *handle_id = entry->ha_handle_id;
+    }
+
+    return 0;
+}
+
+/**
+ * Walk the host attribute list, calling walk_func on each entry with argument.
+ * If walk_func wants to stop iteration, it returns 1.  To continue iteration
+ * it returns 0.
+ *
+ * @param walk_func The function to call for each element in the host attribute
+ *                  list.
+ * @param arg       The argument to provide to walk_func
+ * @param ha_ptr    On input: Indicates the starting point of the walk;
+ *                      null means start at the beginning of the list,
+ *                      non-null means start at the following entry.
+ *                  On output: Indicates the last ble_att element processed,
+ *                      or NULL if the entire list has been processed.
+ *
+ * @return 1 on stopped, 0 on fully processed and an error code otherwise.
+ */
+int
+ble_att_svr_walk(ble_att_svr_walk_func_t walk_func, void *arg,
+                 struct ble_att_svr_entry **ha_ptr)
+{
+    struct ble_att_svr_entry *ha;
+    int rc;
+
+    assert(ha_ptr != NULL);
+
+    ble_att_svr_list_lock();
+
+    if (*ha_ptr == NULL) {
+        ha = STAILQ_FIRST(&ble_att_svr_list);
+    } else {
+        ha = STAILQ_NEXT(*ha_ptr, ha_next);
+    }
+
+    while (ha != NULL) {
+        rc = walk_func(ha, arg);
+        if (rc == 1) {
+            *ha_ptr = ha;
+            goto done;
+        }
+
+        ha = STAILQ_NEXT(ha, ha_next);
+    }
+
+    rc = 0;
+
+done:
+    ble_att_svr_list_unlock();
+    return rc;
+}
+
+static int
+ble_att_svr_match_handle(struct ble_att_svr_entry *ha, void *arg)
+{
+    if (ha->ha_handle_id == *(uint16_t *) arg) {
+        return (1);
+    } else {
+        return (0);
+    }
+}
+
+
+/**
+ * Find a host attribute by handle id.
+ *
+ * @param handle_id             The handle_id to search for
+ * @param ha_ptr                A pointer to a pointer to put the matching host
+ *                                  attr into.
+ *
+ * @return                      0 on success; ENOENT on not found.
+ */
+int
+ble_att_svr_find_by_handle(uint16_t handle_id,
+                           struct ble_att_svr_entry **ha_ptr)
+{
+    int rc;
+
+    rc = ble_att_svr_walk(ble_att_svr_match_handle, &handle_id, ha_ptr);
+    if (rc == 1) {
+        /* Found a matching handle */
+        return 0;
+    } else {
+        /* Not found */
+        return ENOENT;
+    }
+}
+
+static int
+ble_att_svr_match_uuid(struct ble_att_svr_entry *ha, void *arg)
+{
+    uint8_t *uuid;
+
+    uuid = arg;
+
+    if (memcmp(ha->ha_uuid, uuid, sizeof ha->ha_uuid) == 0) {
+        return (1);
+    } else {
+        return (0);
+    }
+}
+
+/**
+ * Find a host attribute by UUID.
+ *
+ * @param uuid                  The ble_uuid_t to search for
+ * @param ha_ptr                A pointer to a pointer to put the matching host
+ *                                  attr into.
+ *
+ * @return                      0 on success; ENOENT on not found.
+ */
+int
+ble_att_svr_find_by_uuid(uint8_t *uuid,
+                         struct ble_att_svr_entry **ha_ptr)
+{
+    int rc;
+
+    rc = ble_att_svr_walk(ble_att_svr_match_uuid, uuid, ha_ptr);
+    if (rc == 1) {
+        /* Found a matching handle */
+        return 0;
+    } else {
+        /* No match */
+        return ENOENT;
+    }
+}
+
+static int
+ble_att_svr_tx_error_rsp(struct ble_l2cap_chan *chan, uint8_t req_op,
+                         uint16_t handle, uint8_t error_code)
+{
+    struct ble_att_error_rsp rsp;
+    struct os_mbuf *txom;
+    void *dst;
+    int rc;
+
+    txom = os_mbuf_get_pkthdr(&ble_hs_mbuf_pool, 0);
+    if (txom == NULL) {
+        rc = BLE_ATT_ERR_INSUFFICIENT_RES;
+        goto err;
+    }
+
+    dst = os_mbuf_extend(txom, BLE_ATT_ERROR_RSP_SZ);
+    if (dst == NULL) {
+        rc = BLE_ATT_ERR_INSUFFICIENT_RES;
+        goto err;
+    }
+
+    rsp.bhaep_req_op = req_op;
+    rsp.bhaep_handle = handle;
+    rsp.bhaep_error_code = error_code;
+
+    rc = ble_att_error_rsp_write(dst, BLE_ATT_ERROR_RSP_SZ, &rsp);
+    assert(rc == 0);
+
+    rc = ble_l2cap_tx(chan, txom);
+    txom = NULL;
+    if (rc != 0) {
+        rc = BLE_ATT_ERR_UNLIKELY;
+        goto err;
+    }
+
+    return 0;
+
+err:
+    os_mbuf_free_chain(txom);
+    return rc;
+}
+
+static int
+ble_att_svr_tx_mtu_rsp(struct ble_l2cap_chan *chan, uint8_t op, uint16_t mtu)
+{
+    struct ble_att_mtu_cmd cmd;
+    struct os_mbuf *txom;
+    void *dst;
+    int rc;
+
+    assert(op == BLE_ATT_OP_MTU_REQ || op == BLE_ATT_OP_MTU_RSP);
+    assert(mtu >= BLE_ATT_MTU_DFLT);
+
+    txom = os_mbuf_get_pkthdr(&ble_hs_mbuf_pool, 0);
+    if (txom == NULL) {
+        rc = BLE_ATT_ERR_INSUFFICIENT_RES;
+        goto err;
+    }
+
+    dst = os_mbuf_extend(txom, BLE_ATT_MTU_CMD_SZ);
+    if (dst == NULL) {
+        rc = BLE_ATT_ERR_INSUFFICIENT_RES;
+        goto err;
+    }
+
+    cmd.bhamc_mtu = mtu;
+
+    rc = ble_att_mtu_rsp_write(dst, BLE_ATT_MTU_CMD_SZ, &cmd);
+    assert(rc == 0);
+
+    rc = ble_l2cap_tx(chan, txom);
+    txom = NULL;
+    if (rc != 0) {
+        rc = BLE_ATT_ERR_UNLIKELY;
+        goto err;
+    }
+
+    chan->blc_flags |= BLE_L2CAP_CHAN_F_TXED_MTU;
+    return 0;
+
+err:
+    os_mbuf_free_chain(txom);
+    return rc;
+}
+
+int
+ble_att_svr_rx_mtu(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan,
+                   struct os_mbuf *om)
+{
+    struct ble_att_mtu_cmd cmd;
+    int rc;
+
+    /* XXX: Pull up om. */
+
+    rc = ble_att_mtu_cmd_parse(om->om_data, om->om_len, &cmd);
+    assert(rc == 0);
+
+    ble_att_set_peer_mtu(chan, cmd.bhamc_mtu);
+    rc = ble_att_svr_tx_mtu_rsp(chan, BLE_ATT_OP_MTU_RSP,
+                                   chan->blc_my_mtu);
+    if (rc != 0) {
+        return rc;
+    }
+
+    return 0;
+}
+
+/**
+ * Fills the supplied mbuf with the variable length Information Data field of a
+ * Find Information ATT response.
+ *
+ * @param req                   The Find Information request being responded
+ *                                  to.
+ * @param om                    The destination mbuf where the Information
+ *                                  Data field gets written.
+ * @param mtu                   The ATT L2CAP channel MTU.
+ * @param format                On success, the format field of the response
+ *                                  gets stored here.  One of:
+ *                                     o BLE_ATT_FIND_INFO_RSP_FORMAT_16BIT
+ *                                     o BLE_ATT_FIND_INFO_RSP_FORMAT_128BIT
+ *
+ * @return                      0 on success; an ATT error code on failure.
+ */
+static int
+ble_att_svr_fill_info(struct ble_att_find_info_req *req, struct os_mbuf *om,
+                      uint16_t mtu, uint8_t *format)
+{
+    struct ble_att_svr_entry *ha;
+    uint16_t handle_id;
+    uint16_t uuid16;
+    int num_entries;
+    int rsp_sz;
+    int rc;
+
+    *format = 0;
+    num_entries = 0;
+    rc = 0;
+
+    ble_att_svr_list_lock();
+
+    STAILQ_FOREACH(ha, &ble_att_svr_list, ha_next) {
+        if (ha->ha_handle_id > req->bhafq_end_handle) {
+            rc = 0;
+            goto done;
+        }
+        if (ha->ha_handle_id >= req->bhafq_start_handle) {
+            uuid16 = ble_hs_uuid_16bit(ha->ha_uuid);
+
+            if (*format == 0) {
+                if (uuid16 != 0) {
+                    *format = BLE_ATT_FIND_INFO_RSP_FORMAT_16BIT;
+                } else {
+                    *format = BLE_ATT_FIND_INFO_RSP_FORMAT_128BIT;
+                }
+            }
+
+            switch (*format) {
+            case BLE_ATT_FIND_INFO_RSP_FORMAT_16BIT:
+                if (uuid16 == 0) {
+                    rc = 0;
+                    goto done;
+                }
+
+                rsp_sz = OS_MBUF_PKTHDR(om)->omp_len + 4;
+                if (rsp_sz > mtu) {
+                    rc = 0;
+                    goto done;
+                }
+
+                htole16(&handle_id, ha->ha_handle_id);
+                rc = os_mbuf_append(om, &handle_id, 2);
+                if (rc != 0) {
+                    goto done;
+                }
+
+                htole16(&uuid16, uuid16);
+                rc = os_mbuf_append(om, &uuid16, 2);
+                if (rc != 0) {
+                    goto done;
+                }
+                break;
+
+            case BLE_ATT_FIND_INFO_RSP_FORMAT_128BIT:
+                if (uuid16 != 0) {
+                    rc = 0;
+                    goto done;
+                }
+
+                rsp_sz = OS_MBUF_PKTHDR(om)->omp_len + 18;
+                if (rsp_sz > mtu) {
+                    rc = 0;
+                    goto done;
+                }
+
+                htole16(&handle_id, ha->ha_handle_id);
+                rc = os_mbuf_append(om, &handle_id, 2);
+                if (rc != 0) {
+                    goto done;
+                }
+
+                rc = os_mbuf_append(om, &ha->ha_uuid,
+                                    16);
+                if (rc != 0) {
+                    goto done;
+                }
+                break;
+
+            default:
+                assert(0);
+                break;
+            }
+
+            num_entries++;
+        }
+    }
+
+done:
+    ble_att_svr_list_unlock();
+
+    if (rc == 0 && num_entries == 0) {
+        return ENOENT;
+    } else {
+        return rc;
+    }
+}
+
+int
+ble_att_svr_rx_find_info(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan,
+                         struct os_mbuf *rxom)
+{
+    struct ble_att_find_info_req req;
+    struct ble_att_find_info_rsp rsp;
+    struct os_mbuf *txom;
+    void *buf;
+    int rc;
+
+    txom = NULL;
+
+    /* XXX: Pull up rxom. */
+
+    rc = ble_att_find_info_req_parse(rxom->om_data, rxom->om_len, &req);
+    if (rc != 0) {
+        req.bhafq_start_handle = 0;
+        rc = BLE_ATT_ERR_INVALID_PDU;
+        goto err;
+    }
+
+    /* Tx error response if start handle is greater than end handle or is equal
+     * to 0 (Vol. 3, Part F, 3.4.3.1).
+     */
+    if (req.bhafq_start_handle > req.bhafq_end_handle ||
+        req.bhafq_start_handle == 0) {
+
+        rc = BLE_ATT_ERR_INVALID_HANDLE;
+        goto err;
+    }
+
+    txom = os_mbuf_get_pkthdr(&ble_hs_mbuf_pool, 0);
+    if (txom == NULL) {
+        rc = BLE_ATT_ERR_INSUFFICIENT_RES;
+        goto err;
+    }
+
+    /* Write the response base at the start of the buffer.  The format field is
+     * unknown at this point; it will be filled in later.
+     */
+    buf = os_mbuf_extend(txom, BLE_ATT_FIND_INFO_RSP_MIN_SZ);
+    if (buf == NULL) {
+        rc = BLE_ATT_ERR_INSUFFICIENT_RES;
+        goto err;
+    }
+
+    rc = ble_att_find_info_rsp_write(buf, BLE_ATT_FIND_INFO_RSP_MIN_SZ,
+                                        &rsp);
+    assert(rc == 0);
+
+    /* Write the variable length Information Data field, populating the format
+     * field as appropriate.
+     */
+    rc = ble_att_svr_fill_info(&req, txom, ble_l2cap_chan_mtu(chan),
+                                  txom->om_data + 1);
+    if (rc != 0) {
+        rc = BLE_ATT_ERR_ATTR_NOT_FOUND;
+        goto err;
+    }
+
+    rc = ble_l2cap_tx(chan, txom);
+    txom = NULL;
+    if (rc != 0) {
+        goto err;
+    }
+
+    return 0;
+
+err:
+    os_mbuf_free_chain(txom);
+    ble_att_svr_tx_error_rsp(chan, BLE_ATT_OP_FIND_INFO_REQ,
+                                req.bhafq_start_handle, rc);
+
+    return rc;
+}
+
+/**
+ * Processes a single non-matching attribute entry while filling a
+ * Find-By-Type-Value-Response.
+ *
+ * @param om                    The response mbuf.
+ * @param first                 Pointer to the first matching handle ID in the
+ *                                  current group of IDs.  0 if there is not a
+ *                                  current group.
+ * @param prev                  Pointer to the most recent matching handle ID
+ *                                  in the current group of IDs.  0 if there is
+ *                                  not a current group.
+ * @param mtu                   The ATT L2CAP channel MTU.
+ *
+ * @return                      0 if the response should be sent;
+ *                              EAGAIN if the entry was successfully processed
+ *                                  and subsequent entries can be inspected.
+ *                              Other nonzero on error.
+ */
+static int
+ble_att_svr_fill_type_value_no_match(struct os_mbuf *om, uint16_t *first,
+                                     uint16_t *prev, int mtu)
+{
+    uint16_t u16;
+    int rsp_sz;
+    int rc;
+
+    /* If there is no current group, then there is nothing to do. */
+    if (*first == 0) {
+        return EAGAIN;
+    }
+
+    rsp_sz = OS_MBUF_PKTHDR(om)->omp_len + 4;
+    if (rsp_sz > mtu) {
+        return 0;
+    }
+
+    u16 = *first;
+    htole16(&u16, u16);
+    rc = os_mbuf_append(om, &u16, 2);
+    if (rc != 0) {
+        return ENOMEM;
+    }
+
+    u16 = *prev;
+    htole16(&u16, u16);
+    rc = os_mbuf_append(om, &u16, 2);
+    if (rc != 0) {
+        return ENOMEM;
+    }
+
+    *first = 0;
+    *prev = 0;
+
+    return EAGAIN;
+}
+
+/**
+ * Processes a single matching attribute entry while filling a
+ * Find-By-Type-Value-Response.
+ *
+ * @param om                    The response mbuf.
+ * @param first                 Pointer to the first matching handle ID in the
+ *                                  current group of IDs.  0 if there is not a
+ *                                  current group.
+ * @param prev                  Pointer to the most recent matching handle ID
+ *                                  in the current group of IDs.  0 if there is
+ *                                  not a current group.
+ * @param handle_id             The matching handle ID to process.
+ * @param mtu                   The ATT L2CAP channel MTU.
+ *
+ * @return                      0 if the response should be sent;
+ *                              EAGAIN if the entry was successfully processed
+ *                                  and subsequent entries can be inspected.
+ *                              Other nonzero on error.
+ */
+static int
+ble_att_svr_fill_type_value_match(struct os_mbuf *om, uint16_t *first,
+                                  uint16_t *prev, uint16_t handle_id,
+                                  int mtu)
+{
+    int rc;
+
+    /* If this is the start of a group, record it as the first ID and keep
+     * searching.
+     */
+    if (*first == 0) {
+        *first = handle_id;
+        *prev = handle_id;
+        return EAGAIN;
+    }
+
+    /* If this is the continuation of a group, keep searching. */
+    if (handle_id == *prev + 1) {
+        *prev = handle_id;
+        return EAGAIN;
+    }
+
+    /* Otherwise, this handle is not a part of the previous group.  Write the
+     * previous group to the response, and remember this ID as the start of the
+     * next group.
+     */
+    rc = ble_att_svr_fill_type_value_no_match(om, first, prev, mtu);
+    *first = handle_id;
+    *prev = handle_id;
+    return rc;
+}
+
+/**
+ * Fills the supplied mbuf with the variable length Handles-Information-List
+ * field of a Find-By-Type-Value ATT response.
+ *
+ * @param req                   The Find-By-Type-Value-Request being responded
+ *                                  to.
+ * @param rxom                  The mbuf containing the received request.
+ * @param txom                  The destination mbuf where the
+ *                                  Handles-Information-List field gets
+ *                                  written.
+ * @param mtu                   The ATT L2CAP channel MTU.
+ *
+ * @return                      0 on success; an ATT error code on failure.
+ */
+static int
+ble_att_svr_fill_type_value(struct ble_att_find_type_value_req *req,
+                            struct os_mbuf *rxom, struct os_mbuf *txom,
+                            uint16_t mtu)
+{
+    union ble_att_svr_handle_arg arg;
+    struct ble_att_svr_entry *ha;
+    uint16_t uuid16;
+    uint16_t first;
+    uint16_t prev;
+    int any_entries;
+    int match;
+    int rc;
+
+    first = 0;
+    prev = 0;
+    rc = 0;
+
+    ble_att_svr_list_lock();
+
+    /* Iterate through the attribute list, keeping track of the current
+     * matching group.  For each attribute entry, determine if data needs to be
+     * written to the response.
+     */
+    STAILQ_FOREACH(ha, &ble_att_svr_list, ha_next) {
+        match = 0;
+
+        if (ha->ha_handle_id > req->bhavq_end_handle) {
+            break;
+        }
+
+        if (ha->ha_handle_id >= req->bhavq_start_handle) {
+            /* Compare the attribute type and value to the request fields to
+             * determine if this attribute matches.
+             */
+            uuid16 = ble_hs_uuid_16bit(ha->ha_uuid);
+            if (uuid16 == req->bhavq_attr_type) {
+                rc = ha->ha_fn(ha, BLE_ATT_OP_READ_REQ, &arg);
+                if (rc != 0) {
+                    rc = BLE_ATT_ERR_UNLIKELY;
+                    goto done;
+                }
+                rc = os_mbuf_memcmp(rxom,
+                                    BLE_ATT_FIND_TYPE_VALUE_REQ_MIN_SZ,
+                                    arg.aha_read.attr_data,
+                                    arg.aha_read.attr_len);
+                if (rc == 0) {
+                    match = 1;
+                }
+            }
+        }
+
+        if (match) {
+            rc = ble_att_svr_fill_type_value_match(txom, &first, &prev,
+                                                      ha->ha_handle_id, mtu);
+        } else {
+            rc = ble_att_svr_fill_type_value_no_match(txom, &first, &prev,
+                                                         mtu);
+        }
+
+        if (rc == 0) {
+            goto done;
+        }
+        if (rc != EAGAIN) {
+            rc = BLE_ATT_ERR_UNLIKELY;
+            goto done;
+        }
+    }
+
+    /* Process one last non-matching ID in case a group was in progress when
+     * the end of the attribute list was reached.
+     */
+    rc = ble_att_svr_fill_type_value_no_match(txom, &first, &prev, mtu);
+    if (rc == EAGAIN) {
+        rc = 0;
+    } else if (rc != 0) {
+        rc = BLE_ATT_ERR_UNLIKELY;
+    }
+
+done:
+    ble_att_svr_list_unlock();
+
+    any_entries = OS_MBUF_PKTHDR(txom)->omp_len >
+                  BLE_ATT_FIND_TYPE_VALUE_RSP_MIN_SZ;
+    if (rc == 0 && !any_entries) {
+        return BLE_ATT_ERR_ATTR_NOT_FOUND;
+    } else {
+        return rc;
+    }
+}
+
+int
+ble_att_svr_rx_find_type_value(struct ble_hs_conn *conn,
+                               struct ble_l2cap_chan *chan,
+                               struct os_mbuf *rxom)
+{
+    struct ble_att_find_type_value_req req;
+    struct os_mbuf *txom;
+    uint8_t *buf;
+    int rc;
+
+    txom = NULL;
+
+    /* XXX: Pull up rx_om. */
+
+    rc = ble_att_find_type_value_req_parse(rxom->om_data, rxom->om_len,
+                                              &req);
+    assert(rc == 0);
+
+    /* Tx error response if start handle is greater than end handle or is equal
+     * to 0 (Vol. 3, Part F, 3.4.3.3).
+     */
+    if (req.bhavq_start_handle > req.bhavq_end_handle ||
+        req.bhavq_start_handle == 0) {
+
+        rc = BLE_ATT_ERR_INVALID_HANDLE;
+        goto err;
+    }
+
+    txom = os_mbuf_get_pkthdr(&ble_hs_mbuf_pool, 0);
+    if (txom == NULL) {
+        rc = BLE_ATT_ERR_INSUFFICIENT_RES;
+        goto err;
+    }
+
+    /* Write the response base at the start of the buffer. */
+    buf = os_mbuf_extend(txom, BLE_ATT_FIND_TYPE_VALUE_RSP_MIN_SZ);
+    if (buf == NULL) {
+        rc = BLE_ATT_ERR_INSUFFICIENT_RES;
+        goto err;
+    }
+    buf[0] = BLE_ATT_OP_FIND_TYPE_VALUE_RSP;
+
+    /* Write the variable length Information Data field. */
+    rc = ble_att_svr_fill_type_value(&req, rxom, txom,
+                                        ble_l2cap_chan_mtu(chan));
+    if (rc != 0) {
+        goto err;
+    }
+
+    rc = ble_l2cap_tx(chan, txom);
+    txom = NULL;
+    if (rc != 0) {
+        rc = BLE_ATT_ERR_UNLIKELY;
+        goto err;
+    }
+
+    return 0;
+
+err:
+    os_mbuf_free_chain(txom);
+    ble_att_svr_tx_error_rsp(chan, BLE_ATT_OP_FIND_TYPE_VALUE_REQ,
+                            req.bhavq_start_handle, rc);
+    return rc;
+}
+
+static int
+ble_att_svr_tx_read_type_rsp(struct ble_hs_conn *conn,
+                             struct ble_l2cap_chan *chan,
+                             struct ble_att_read_type_req *req,
+                             uint8_t *uuid128)
+{
+    struct ble_att_read_type_rsp rsp;
+    union ble_att_svr_handle_arg arg;
+    struct ble_att_svr_entry *entry;
+    struct os_mbuf *txom;
+    uint8_t *dptr;
+    int txomlen;
+    int prev_attr_len;
+    int attr_len;
+    int rc;
+
+    txom = os_mbuf_get_pkthdr(&ble_hs_mbuf_pool, 0);
+    if (txom == NULL) {
+        rc = BLE_ATT_ERR_INSUFFICIENT_RES;
+        goto err;
+    }
+
+    /* Allocate space for the respose base, but don't fill in the fields.  They
+     * get filled in at the end, when we know the value of the length field.
+     */
+    dptr = os_mbuf_extend(txom,
+                          BLE_ATT_READ_TYPE_RSP_MIN_SZ);
+    if (dptr == NULL) {
+        rc = BLE_ATT_ERR_INSUFFICIENT_RES;
+        goto err;
+    }
+
+    /* Find all matching attributes, writing a record for each. */
+    prev_attr_len = 0;
+    entry = NULL;
+    while (1) {
+        rc = ble_att_svr_find_by_uuid(uuid128, &entry);
+        if (rc == ENOENT) {
+            break;
+        } else if (rc != 0) {
+            rc = BLE_ATT_ERR_UNLIKELY;
+            goto err;
+        }
+
+        if (entry->ha_handle_id > req->bhatq_end_handle) {
+            break;
+        }
+
+        if (entry->ha_handle_id >= req->bhatq_start_handle &&
+            entry->ha_handle_id <= req->bhatq_end_handle) {
+
+            rc = entry->ha_fn(entry, BLE_ATT_OP_READ_REQ, &arg);
+            if (rc != 0) {
+                rc = BLE_ATT_ERR_UNLIKELY;
+                goto err;
+            }
+
+            if (arg.aha_read.attr_len > ble_l2cap_chan_mtu(chan) - 4) {
+                attr_len = ble_l2cap_chan_mtu(chan) - 4;
+            } else {
+                attr_len = arg.aha_read.attr_len;
+            }
+
+            if (prev_attr_len == 0) {
+                prev_attr_len = attr_len;
+            } else if (prev_attr_len != attr_len) {
+                break;
+            }
+
+            txomlen = OS_MBUF_PKTHDR(txom)->omp_len + 2 + attr_len;
+            if (txomlen > ble_l2cap_chan_mtu(chan)) {
+                break;
+            }
+
+            dptr = os_mbuf_extend(txom, 2 + attr_len);
+            if (dptr == NULL) {
+                rc = BLE_ATT_ERR_INSUFFICIENT_RES;
+                goto err;
+            }
+
+            htole16(dptr + 0, entry->ha_handle_id);
+            memcpy(dptr + 2, arg.aha_read.attr_data, attr_len);
+        }
+    }
+
+    if (prev_attr_len == 0) {
+        /* No matching attributes. */
+        rc = BLE_ATT_ERR_ATTR_NOT_FOUND;
+        goto err;
+    }
+
+    /* Fill the response base. */
+    rsp.bhatp_len = prev_attr_len;
+    rc = ble_att_read_type_rsp_write(txom->om_data, txom->om_len, &rsp);
+    assert(rc == 0);
+
+    /* Transmit the response. */
+    rc = ble_l2cap_tx(chan, txom);
+    txom = NULL;
+    if (rc != 0) {
+        rc = BLE_ATT_ERR_UNLIKELY;
+        goto err;
+    }
+
+    return 0;
+
+err:
+    os_mbuf_free_chain(txom);
+    ble_att_svr_tx_error_rsp(chan, BLE_ATT_OP_READ_TYPE_REQ,
+                                req->bhatq_start_handle, rc);
+    return rc;
+}
+
+int
+ble_att_svr_rx_read_type(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan,
+                         struct os_mbuf *rx_om)
+{
+    struct ble_att_read_type_req req;
+    uint16_t uuid16;
+    uint8_t uuid128[16];
+    int rc;
+
+    /* XXX: Pull up mbuf. */
+
+    rc = ble_att_read_type_req_parse(rx_om->om_data, rx_om->om_len, &req);
+    if (rc != 0) {
+        goto done;
+    }
+
+    switch (rx_om->om_len) {
+    case BLE_ATT_READ_TYPE_REQ_SZ_16:
+        uuid16 = le16toh(rx_om->om_data + 5);
+        rc = ble_hs_uuid_from_16bit(uuid16, uuid128);
+        if (rc != 0) {
+            goto done;
+        }
+        break;
+
+    case BLE_ATT_READ_TYPE_REQ_SZ_128:
+        memcpy(uuid128, rx_om->om_data + 5, 16);
+        break;
+
+    default:
+        rc = EMSGSIZE;
+        goto done;
+    }
+
+    rc = ble_att_svr_tx_read_type_rsp(conn, chan, &req, uuid128);
+    if (rc != 0) {
+        goto done;
+    }
+
+    rc = 0;
+
+done:
+    os_mbuf_free_chain(rx_om);
+    return rc;
+}
+
+static int
+ble_att_svr_tx_read_rsp(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan,
+                        void *attr_data, int attr_len)
+{
+    struct os_mbuf *txom;
+    uint16_t data_len;
+    uint8_t op;
+    int rc;
+
+    txom = os_mbuf_get_pkthdr(&ble_hs_mbuf_pool, 0);
+    if (txom == NULL) {
+        rc = BLE_ATT_ERR_INSUFFICIENT_RES;
+        goto err;
+    }
+
+    op = BLE_ATT_OP_READ_RSP;
+    rc = os_mbuf_append(txom, &op, 1);
+    if (rc != 0) {
+        rc = BLE_ATT_ERR_INSUFFICIENT_RES;
+        goto err;
+    }
+
+    /* Vol. 3, part F, 3.2.9; don't send more than ATT_MTU-1 bytes of data. */
+    if (attr_len > ble_l2cap_chan_mtu(chan) - 1) {
+        data_len = ble_l2cap_chan_mtu(chan) - 1;
+    } else {
+        data_len = attr_len;
+    }
+
+    rc = os_mbuf_append(txom, attr_data, data_len);
+    if (rc != 0) {
+        rc = BLE_ATT_ERR_INSUFFICIENT_RES;
+        goto err;
+    }
+
+    rc = ble_l2cap_tx(chan, txom);
+    if (rc != 0) {
+        rc = BLE_ATT_ERR_UNLIKELY;
+        goto err;
+    }
+
+    return 0;
+
+err:
+    os_mbuf_free_chain(txom);
+    return rc;
+}
+
+int
+ble_att_svr_rx_read(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan,
+                    struct os_mbuf *om)
+{
+    union ble_att_svr_handle_arg arg;
+    struct ble_att_svr_entry *entry;
+    struct ble_att_read_req req;
+    uint8_t buf[BLE_ATT_READ_REQ_SZ];
+    int rc;
+
+    rc = os_mbuf_copydata(om, 0, sizeof buf, buf);
+    if (rc != 0) {
+        req.bharq_handle = 0;
+        rc = BLE_ATT_ERR_INVALID_PDU;
+        goto err;
+    }
+
+    rc = ble_att_read_req_parse(buf, sizeof buf, &req);
+    assert(rc == 0);
+
+    entry = NULL;
+    rc = ble_att_svr_find_by_handle(req.bharq_handle, &entry);
+    if (rc != 0) {
+        rc = BLE_ATT_ERR_INVALID_HANDLE;
+        goto err;
+    }
+
+    if (entry->ha_fn == NULL) {
+        rc = BLE_ATT_ERR_UNLIKELY;
+        goto err;
+    }
+
+    rc = entry->ha_fn(entry, BLE_ATT_OP_READ_REQ, &arg);
+    if (rc != 0) {
+        rc = BLE_ATT_ERR_UNLIKELY;
+        goto err;
+    }
+
+    rc = ble_att_svr_tx_read_rsp(conn, chan, arg.aha_read.attr_data,
+                                arg.aha_read.attr_len);
+    if (rc != 0) {
+        goto err;
+    }
+
+    return 0;
+
+err:
+    ble_att_svr_tx_error_rsp(chan, BLE_ATT_OP_READ_REQ,
+                            req.bharq_handle, rc);
+    return rc;
+}
+
+static int
+ble_att_svr_tx_write_rsp(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan)
+{
+    struct os_mbuf *txom;
+    uint8_t *dst;
+    int rc;
+
+    txom = os_mbuf_get_pkthdr(&ble_hs_mbuf_pool, 0);
+    if (txom == NULL) {
+        rc = BLE_ATT_ERR_INSUFFICIENT_RES;
+        goto err;
+    }
+
+    dst = os_mbuf_extend(txom, BLE_ATT_WRITE_RSP_SZ);
+    if (dst == NULL) {
+        rc = BLE_ATT_ERR_INSUFFICIENT_RES;
+        goto err;
+    }
+
+    *dst = BLE_ATT_OP_WRITE_RSP;
+    rc = ble_l2cap_tx(chan, txom);
+    txom = NULL;
+    if (rc != 0) {
+        rc = BLE_ATT_ERR_UNLIKELY;
+        goto err;
+    }
+
+    return 0;
+
+err:
+    os_mbuf_free_chain(txom);
+    return rc;
+}
+
+int
+ble_att_svr_rx_write(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan,
+                     struct os_mbuf *om)
+{
+    union ble_att_svr_handle_arg arg;
+    struct ble_att_svr_entry *entry;
+    struct ble_att_write_req req;
+    uint8_t buf[BLE_ATT_WRITE_REQ_MIN_SZ];
+    int rc;
+
+    rc = os_mbuf_copydata(om, 0, sizeof buf, buf);
+    if (rc != 0) {
+        return rc;
+    }
+
+    rc = ble_att_write_req_parse(buf, sizeof buf, &req);
+    assert(rc == 0);
+
+    entry = NULL;
+    rc = ble_att_svr_find_by_handle(req.bhawq_handle, &entry);
+    if (rc != 0) {
+        rc = BLE_ATT_ERR_INVALID_HANDLE;
+        goto send_err;
+    }
+
+    if (entry->ha_fn == NULL) {
+        rc = BLE_ATT_ERR_UNLIKELY;
+        goto send_err;
+    }
+
+    arg.aha_write.om = om;
+    arg.aha_write.attr_len = OS_MBUF_PKTHDR(om)->omp_len;
+    rc = entry->ha_fn(entry, BLE_ATT_OP_WRITE_REQ, &arg);
+    if (rc != 0) {
+        goto send_err;
+    }
+
+    rc = ble_att_svr_tx_write_rsp(conn, chan);
+    if (rc != 0) {
+        goto send_err;
+    }
+
+    return 0;
+
+send_err:
+    ble_att_svr_tx_error_rsp(chan, BLE_ATT_OP_WRITE_REQ,
+                                req.bhawq_handle, rc);
+    return rc;
+}
+
+int
+ble_att_svr_init(void)
+{
+    int rc;
+
+    STAILQ_INIT(&ble_att_svr_list);
+
+    rc = os_mutex_init(&ble_att_svr_list_mutex);
+    if (rc != 0) {
+        goto err;
+    }
+
+    free(ble_att_svr_entry_mem);
+    ble_att_svr_entry_mem = malloc(
+        OS_MEMPOOL_BYTES(BLE_ATT_SVR_NUM_ENTRIES,
+                         sizeof (struct ble_att_svr_entry)));
+    if (ble_att_svr_entry_mem == NULL) {
+        rc = ENOMEM;
+        goto err;
+    }
+
+    rc = os_mempool_init(&ble_att_svr_entry_pool,
+                         BLE_ATT_SVR_NUM_ENTRIES,
+                         sizeof (struct ble_att_svr_entry),
+                         ble_att_svr_entry_mem,
+                         "ble_att_svr_entry_pool");
+    if (rc != 0) {
+        goto err;
+    }
+
+    return 0;
+
+err:
+    free(ble_att_svr_entry_mem);
+    ble_att_svr_entry_mem = NULL;
+
+    return rc;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/31f0c10b/net/nimble/host/src/ble_gatt.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gatt.c b/net/nimble/host/src/ble_gatt.c
index c5c2764..6b52b96 100644
--- a/net/nimble/host/src/ble_gatt.c
+++ b/net/nimble/host/src/ble_gatt.c
@@ -23,8 +23,8 @@
 #include "host/ble_gatt.h"
 #include "host/ble_hs.h"
 #include "ble_hs_conn.h"
-#include "ble_hs_att_cmd.h"
-#include "ble_hs_att.h"
+#include "ble_att_cmd.h"
+#include "ble_att.h"
 
 struct ble_gatt_entry {
     STAILQ_ENTRY(ble_gatt_entry) next;
@@ -211,7 +211,7 @@ ble_gatt_new_entry(uint16_t conn_handle, struct ble_gatt_entry **entry)
 static int
 ble_gatt_kick_mtu(struct ble_gatt_entry *entry)
 {
-    struct ble_hs_att_mtu_cmd req;
+    struct ble_att_mtu_cmd req;
     struct ble_l2cap_chan *chan;
     struct ble_hs_conn *conn;
     int rc;
@@ -225,7 +225,7 @@ ble_gatt_kick_mtu(struct ble_gatt_entry *entry)
     assert(chan != NULL);
 
     req.bhamc_mtu = chan->blc_my_mtu;
-    rc = ble_hs_att_clt_tx_mtu(conn, &req);
+    rc = ble_att_clt_tx_mtu(conn, &req);
     if (rc != 0) {
         return rc;
     }
@@ -236,7 +236,7 @@ ble_gatt_kick_mtu(struct ble_gatt_entry *entry)
 static int
 ble_gatt_kick_find_info(struct ble_gatt_entry *entry)
 {
-    struct ble_hs_att_find_info_req req;
+    struct ble_att_find_info_req req;
     struct ble_hs_conn *conn;
     int rc;
 
@@ -247,7 +247,7 @@ ble_gatt_kick_find_info(struct ble_gatt_entry *entry)
 
     req.bhafq_start_handle = entry->find_info.next_handle;
     req.bhafq_end_handle = entry->find_info.end_handle;
-    rc = ble_hs_att_clt_tx_find_info(conn, &req);
+    rc = ble_att_clt_tx_find_info(conn, &req);
     if (rc != 0) {
         return rc;
     }
@@ -288,7 +288,7 @@ ble_gatt_wakeup(void)
 }
 
 void
-ble_gatt_rx_error(struct ble_hs_conn *conn, struct ble_hs_att_error_rsp *rsp)
+ble_gatt_rx_error(struct ble_hs_conn *conn, struct ble_att_error_rsp *rsp)
 {
     struct ble_gatt_entry *entry;
     struct ble_gatt_entry *prev;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/31f0c10b/net/nimble/host/src/ble_hs.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs.c b/net/nimble/host/src/ble_hs.c
index 916cc1a..519e3e7 100644
--- a/net/nimble/host/src/ble_hs.c
+++ b/net/nimble/host/src/ble_hs.c
@@ -21,7 +21,7 @@
 #include "host/host_hci.h"
 #include "host/ble_gatt.h"
 #include "host/ble_hs.h"
-#include "ble_hs_att.h"
+#include "ble_att.h"
 #include "ble_hs_conn.h"
 #include "ble_hs_ack.h"
 #include "ble_hs_hci_batch.h"
@@ -319,12 +319,12 @@ ble_hs_init(uint8_t prio)
         goto err;
     }
 
-    rc = ble_hs_att_svr_init();
+    rc = ble_att_svr_init();
     if (rc != 0) {
         goto err;
     }
 
-    rc = ble_hs_att_clt_init();
+    rc = ble_att_clt_init();
     if (rc != 0) {
         goto err;
     }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/31f0c10b/net/nimble/host/src/ble_hs_att.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_att.c b/net/nimble/host/src/ble_hs_att.c
deleted file mode 100644
index 7d20934..0000000
--- a/net/nimble/host/src/ble_hs_att.c
+++ /dev/null
@@ -1,118 +0,0 @@
-/**
- * Copyright (c) 2015 Runtime Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stddef.h>
-#include <errno.h>
-#include "ble_l2cap.h"
-#include "ble_hs_att_cmd.h"
-#include "ble_hs_att.h"
-
-/** Dispatch table for incoming ATT requests.  Sorted by op code. */
-typedef int ble_hs_att_rx_fn(struct ble_hs_conn *conn,
-                                 struct ble_l2cap_chan *chan,
-                                 struct os_mbuf *om);
-struct ble_hs_att_rx_dispatch_entry {
-    uint8_t bde_op;
-    ble_hs_att_rx_fn *bde_fn;
-};
-
-static struct ble_hs_att_rx_dispatch_entry ble_hs_att_rx_dispatch[] = {
-    { BLE_HS_ATT_OP_MTU_REQ,              ble_hs_att_svr_rx_mtu },
-    { BLE_HS_ATT_OP_MTU_RSP,              ble_hs_att_clt_rx_mtu },
-    { BLE_HS_ATT_OP_FIND_INFO_REQ,        ble_hs_att_svr_rx_find_info },
-    { BLE_HS_ATT_OP_FIND_INFO_RSP,        ble_hs_att_clt_rx_find_info },
-    { BLE_HS_ATT_OP_FIND_TYPE_VALUE_REQ,  ble_hs_att_svr_rx_find_type_value },
-    { BLE_HS_ATT_OP_READ_TYPE_REQ,        ble_hs_att_svr_rx_read_type },
-    { BLE_HS_ATT_OP_READ_REQ,             ble_hs_att_svr_rx_read },
-    { BLE_HS_ATT_OP_WRITE_REQ,            ble_hs_att_svr_rx_write },
-};
-
-#define BLE_HS_ATT_RX_DISPATCH_SZ \
-    (sizeof ble_hs_att_rx_dispatch / sizeof ble_hs_att_rx_dispatch[0])
-
-static struct ble_hs_att_rx_dispatch_entry *
-ble_hs_att_rx_dispatch_entry_find(uint8_t op)
-{
-    struct ble_hs_att_rx_dispatch_entry *entry;
-    int i;
-
-    for (i = 0; i < BLE_HS_ATT_RX_DISPATCH_SZ; i++) {
-        entry = ble_hs_att_rx_dispatch + i;
-        if (entry->bde_op == op) {
-            return entry;
-        }
-
-        if (entry->bde_op > op) {
-            break;
-        }
-    }
-
-    return NULL;
-}
-
-static int
-ble_hs_att_rx(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan,
-              struct os_mbuf *om)
-{
-    struct ble_hs_att_rx_dispatch_entry *entry;
-    uint8_t op;
-    int rc;
-
-    rc = os_mbuf_copydata(om, 0, 1, &op);
-    if (rc != 0) {
-        return EMSGSIZE;
-    }
-
-    entry = ble_hs_att_rx_dispatch_entry_find(op);
-    if (entry == NULL) {
-        return EINVAL;
-    }
-
-    rc = entry->bde_fn(conn, chan, om);
-    if (rc != 0) {
-        return rc;
-    }
-
-    return 0;
-}
-
-void
-ble_hs_att_set_peer_mtu(struct ble_l2cap_chan *chan, uint16_t peer_mtu)
-{
-    if (peer_mtu < BLE_HS_ATT_MTU_DFLT) {
-        peer_mtu = BLE_HS_ATT_MTU_DFLT;
-    }
-
-    chan->blc_peer_mtu = peer_mtu;
-}
-
-struct ble_l2cap_chan *
-ble_hs_att_create_chan(void)
-{
-    struct ble_l2cap_chan *chan;
-
-    chan = ble_l2cap_chan_alloc();
-    if (chan == NULL) {
-        return NULL;
-    }
-
-    chan->blc_cid = BLE_L2CAP_CID_ATT;
-    chan->blc_my_mtu = BLE_HS_ATT_MTU_DFLT;
-    chan->blc_default_mtu = BLE_HS_ATT_MTU_DFLT;
-    chan->blc_rx_fn = ble_hs_att_rx;
-
-    return chan;
-}