You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by an...@apache.org on 2017/04/10 11:46:53 UTC

[01/50] incubator-mynewt-core git commit: nimble/att: Add generic helpers for sending commands

Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/master e23872dc6 -> 95935c62c


nimble/att: Add generic helpers for sending commands

Those will be used to construct ATT command directly in os_mbuf.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/71a8a47c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/71a8a47c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/71a8a47c

Branch: refs/heads/master
Commit: 71a8a47cb6acaad0d7899adbfbc09d23e4e7a9d5
Parents: a94e4de
Author: Szymon Janc <sz...@codecoup.pl>
Authored: Fri Mar 24 12:51:52 2017 +0100
Committer: Szymon Janc <sz...@codecoup.pl>
Committed: Mon Apr 10 10:23:07 2017 +0200

----------------------------------------------------------------------
 net/nimble/host/src/ble_att_cmd.c      | 55 +++++++++++++++++++++++++++++
 net/nimble/host/src/ble_att_cmd_priv.h | 12 +++++++
 2 files changed, 67 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/71a8a47c/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
index b99f896..7997ff1 100644
--- a/net/nimble/host/src/ble_att_cmd.c
+++ b/net/nimble/host/src/ble_att_cmd.c
@@ -26,6 +26,61 @@
 #include "host/ble_uuid.h"
 #include "ble_hs_priv.h"
 
+void *
+ble_att_cmd_prepare(uint8_t opcode, size_t len, struct os_mbuf *txom)
+{
+    struct ble_att_hdr *hdr;
+
+    if (os_mbuf_extend(txom, sizeof(*hdr) + len) == NULL) {
+        os_mbuf_free_chain(txom);
+        return NULL;
+    }
+
+    hdr = (struct ble_att_hdr *)(txom)->om_data;
+
+    hdr->opcode = opcode;
+
+    return hdr->data;
+}
+
+void *
+ble_att_cmd_get(uint8_t opcode, size_t len, struct os_mbuf **txom)
+{
+    *txom = ble_hs_mbuf_l2cap_pkt();
+    if (*txom == NULL) {
+        return NULL;
+    }
+
+    return ble_att_cmd_prepare(opcode, len, *txom);
+}
+
+int
+ble_att_tx(uint16_t conn_handle, struct os_mbuf *txom)
+{
+    struct ble_l2cap_chan *chan;
+    struct ble_hs_conn *conn;
+    int rc;
+
+    BLE_HS_DBG_ASSERT_EVAL(txom->om_len >= 1);
+    ble_att_inc_tx_stat(txom->om_data[0]);
+
+    ble_hs_lock();
+
+    ble_hs_misc_conn_chan_find_reqd(conn_handle, BLE_L2CAP_CID_ATT, &conn,
+                                    &chan);
+    if (chan == NULL) {
+        os_mbuf_free_chain(txom);
+        rc = BLE_HS_ENOTCONN;
+    } else {
+        ble_att_truncate_to_mtu(chan, txom);
+        rc = ble_l2cap_tx(conn, chan, txom);
+    }
+
+    ble_hs_unlock();
+
+    return rc;
+}
+
 static const void *
 ble_att_init_parse(uint8_t op, const void *payload,
                    int min_len, int actual_len)

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/71a8a47c/net/nimble/host/src/ble_att_cmd_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_cmd_priv.h b/net/nimble/host/src/ble_att_cmd_priv.h
index ec96c22..17516e8 100644
--- a/net/nimble/host/src/ble_att_cmd_priv.h
+++ b/net/nimble/host/src/ble_att_cmd_priv.h
@@ -21,10 +21,18 @@
 #define H_BLE_ATT_CMD_
 
 #include <inttypes.h>
+#include <stddef.h>
+#include "os/os_mbuf.h"
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
+struct ble_att_hdr {
+    uint8_t opcode;
+    uint8_t data[0];
+} __attribute__((packed));
+
 /**
  * | Parameter                          | Size (octets)     |
  * +------------------------------------+-------------------+
@@ -412,6 +420,10 @@ void ble_att_indicate_rsp_parse(const void *payload, int len);
 void ble_att_indicate_rsp_write(void *payload, int len);
 void ble_att_indicate_req_log(const struct ble_att_indicate_req *cmd);
 
+void *ble_att_cmd_prepare(uint8_t opcode, size_t len, struct os_mbuf *txom);
+void *ble_att_cmd_get(uint8_t opcode, size_t len, struct os_mbuf **txom);
+int ble_att_tx(uint16_t conn_handle, struct os_mbuf *txom);
+
 #ifdef __cplusplus
 }
 #endif


[48/50] incubator-mynewt-core git commit: nimble/l2cap: Use endian.h API for protocol data

Posted by an...@apache.org.
nimble/l2cap: Use endian.h API for protocol data

Don't use TOFROMLE16 API for protocol data. This API hide direction of
convertion making code hard to follow.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/7e1ac05a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/7e1ac05a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/7e1ac05a

Branch: refs/heads/master
Commit: 7e1ac05a06168984fa0bf772fdb72caedd086327
Parents: fd6c58a
Author: Szymon Janc <sz...@codecoup.pl>
Authored: Fri Mar 24 15:50:09 2017 +0100
Committer: Szymon Janc <sz...@codecoup.pl>
Committed: Mon Apr 10 11:31:33 2017 +0200

----------------------------------------------------------------------
 net/nimble/host/src/ble_l2cap_sig_cmd.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7e1ac05a/net/nimble/host/src/ble_l2cap_sig_cmd.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sig_cmd.c b/net/nimble/host/src/ble_l2cap_sig_cmd.c
index ae8b102..1fe5683 100644
--- a/net/nimble/host/src/ble_l2cap_sig_cmd.c
+++ b/net/nimble/host/src/ble_l2cap_sig_cmd.c
@@ -36,21 +36,17 @@ ble_l2cap_sig_tx(uint16_t conn_handle, struct os_mbuf *txom)
     return rc;
 }
 
-static void
-ble_l2cap_sig_hdr_swap(struct ble_l2cap_sig_hdr *dst,
-                       struct ble_l2cap_sig_hdr *src)
-{
-    dst->op = src->op;
-    dst->identifier = src->identifier;
-    dst->length = TOFROMLE16(src->length);
-}
-
 void
 ble_l2cap_sig_hdr_parse(void *payload, uint16_t len,
                         struct ble_l2cap_sig_hdr *dst)
 {
+    struct ble_l2cap_sig_hdr *src = payload;
+
     BLE_HS_DBG_ASSERT(len >= BLE_L2CAP_SIG_HDR_SZ);
-    ble_l2cap_sig_hdr_swap(dst, payload);
+
+    dst->op = src->op;
+    dst->identifier = src->identifier;
+    dst->length = le16toh(src->length);
 }
 
 int


[25/50] incubator-mynewt-core git commit: nimble/att: Use packed struct for receiving Read By Type Response

Posted by an...@apache.org.
nimble/att: Use packed struct for receiving Read By Type Response

Use packed structure to map it to received mbuf instead of using
dedicated parsing function. Modern compilers generate effective code
in such case anyway.


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

Branch: refs/heads/master
Commit: c3cca4259a16b116b3a17a44896195483fdc38fa
Parents: e15ad92
Author: Szymon Janc <sz...@codecoup.pl>
Authored: Fri Mar 24 15:50:03 2017 +0100
Committer: Szymon Janc <sz...@codecoup.pl>
Committed: Mon Apr 10 11:31:32 2017 +0200

----------------------------------------------------------------------
 net/nimble/host/src/ble_att_clt.c | 55 ++++++++++++++++++----------------
 1 file changed, 29 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c3cca425/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
index f3a084c..b445f2d 100644
--- a/net/nimble/host/src/ble_att_clt.c
+++ b/net/nimble/host/src/ble_att_clt.c
@@ -419,24 +419,6 @@ ble_att_clt_tx_read_type(uint16_t conn_handle, uint16_t start_handle,
     return ble_att_tx(conn_handle, txom);
 }
 
-static int
-ble_att_clt_parse_read_type_adata(struct os_mbuf **om, int data_len,
-                                  struct ble_att_read_type_adata *adata)
-{
-    int rc;
-
-    rc = ble_hs_mbuf_pullup_base(om, data_len);
-    if (rc != 0) {
-        return rc;
-    }
-
-    adata->att_handle = get_le16((*om)->om_data + 0);
-    adata->value_len = data_len - BLE_ATT_READ_TYPE_ADATA_BASE_SZ;
-    adata->value = (*om)->om_data + BLE_ATT_READ_TYPE_ADATA_BASE_SZ;
-
-    return 0;
-}
-
 int
 ble_att_clt_rx_read_type(uint16_t conn_handle, struct os_mbuf **rxom)
 {
@@ -445,30 +427,51 @@ ble_att_clt_rx_read_type(uint16_t conn_handle, struct os_mbuf **rxom)
 #endif
 
     struct ble_att_read_type_adata adata;
-    struct ble_att_read_type_rsp rsp;
+    struct ble_att_attr_data_list *data;
+    struct ble_att_read_type_rsp *rsp;
+    uint8_t data_len;
     int rc;
 
-    rc = ble_hs_mbuf_pullup_base(rxom, BLE_ATT_READ_TYPE_RSP_BASE_SZ);
+    /* TODO move this to common part
+     * Strip L2CAP ATT header from the front of the mbuf.
+     */
+    os_mbuf_adj(*rxom, 1);
+
+    rc = ble_hs_mbuf_pullup_base(rxom, sizeof(*rsp));
     if (rc != 0) {
         goto done;
     }
 
-    ble_att_read_type_rsp_parse((*rxom)->om_data, (*rxom)->om_len, &rsp);
+    rsp = (struct ble_att_read_type_rsp *)(*rxom)->om_data;
+
     BLE_ATT_LOG_CMD(0, "read type rsp", conn_handle, ble_att_read_type_rsp_log,
-                    &rsp);
+                    rsp);
+
+    data_len = rsp->batp_length;
 
     /* Strip the response base from the front of the mbuf. */
-    os_mbuf_adj(*rxom, BLE_ATT_READ_TYPE_RSP_BASE_SZ);
+    os_mbuf_adj(*rxom, sizeof(*rsp));
+
+    if (data_len < sizeof(*data)) {
+        rc = BLE_HS_EBADDATA;
+        goto done;
+    }
 
     /* Parse the Attribute Data List field, passing each entry to the GATT. */
     while (OS_MBUF_PKTLEN(*rxom) > 0) {
-        rc = ble_att_clt_parse_read_type_adata(rxom, rsp.batp_length, &adata);
+        rc = ble_hs_mbuf_pullup_base(rxom, data_len);
         if (rc != 0) {
-            goto done;
+            break;
         }
 
+        data = (struct ble_att_attr_data_list *)(*rxom)->om_data;
+
+        adata.att_handle = le16toh(data->handle);
+        adata.value_len = data_len - sizeof(*data);
+        adata.value = data->value;
+
         ble_gattc_rx_read_type_adata(conn_handle, &adata);
-        os_mbuf_adj(*rxom, rsp.batp_length);
+        os_mbuf_adj(*rxom, data_len);
     }
 
 done:


[13/50] incubator-mynewt-core git commit: nimble/att: Use new helpers for sending Read By Group Type Request

Posted by an...@apache.org.
nimble/att: Use new helpers for sending Read By Group Type Request

This constructs response directly on mbuf reducing number of memcopies.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/1c08e62b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/1c08e62b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/1c08e62b

Branch: refs/heads/master
Commit: 1c08e62b42bed9fe0ba83d564548b388c55ebc45
Parents: 3f4cac3
Author: Szymon Janc <sz...@codecoup.pl>
Authored: Fri Mar 24 15:31:52 2017 +0100
Committer: Szymon Janc <sz...@codecoup.pl>
Committed: Mon Apr 10 11:31:31 2017 +0200

----------------------------------------------------------------------
 net/nimble/host/src/ble_att_clt.c      | 40 +++++++++--------------------
 net/nimble/host/src/ble_att_cmd_priv.h |  1 +
 net/nimble/host/src/ble_att_priv.h     |  6 ++---
 net/nimble/host/src/ble_gattc.c        |  7 +++--
 4 files changed, 19 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1c08e62b/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
index 96a04e2..c35ad89 100644
--- a/net/nimble/host/src/ble_att_clt.c
+++ b/net/nimble/host/src/ble_att_clt.c
@@ -707,50 +707,34 @@ ble_att_clt_rx_read_mult(uint16_t conn_handle, struct os_mbuf **rxom)
 
 int
 ble_att_clt_tx_read_group_type(uint16_t conn_handle,
-                               const struct ble_att_read_group_type_req *req,
+                               uint16_t start_handle, uint16_t end_handle,
                                const ble_uuid_t *uuid)
 {
 #if !NIMBLE_BLE_ATT_CLT_READ_GROUP_TYPE
     return BLE_HS_ENOTSUP;
 #endif
 
+    struct ble_att_read_group_type_req *req;
     struct os_mbuf *txom;
-    int rc;
-
-    txom = NULL;
-
-    if (req->bagq_start_handle == 0 ||
-        req->bagq_start_handle > req->bagq_end_handle) {
-
-        rc = BLE_HS_EINVAL;
-        goto err;
-    }
 
-    rc = ble_att_clt_init_req(BLE_ATT_READ_GROUP_TYPE_REQ_BASE_SZ, &txom);
-    if (rc != 0) {
-        goto err;
+    if (start_handle == 0 || start_handle > end_handle) {
+        return BLE_HS_EINVAL;
     }
-    ble_att_read_group_type_req_write(txom->om_data, txom->om_len, req);
 
-    rc = ble_uuid_to_mbuf(uuid, txom);
-    if (rc != 0) {
-        goto err;
+    req = ble_att_cmd_get(BLE_ATT_OP_READ_GROUP_TYPE_REQ,
+                          sizeof(*req) + ble_uuid_length(uuid), &txom);
+    if (req == NULL) {
+        return BLE_HS_ENOMEM;
     }
 
-    rc = ble_att_clt_tx_req(conn_handle, txom);
-    txom = NULL;
-    if (rc != 0) {
-        goto err;
-    }
+    req->bagq_start_handle = htole16(start_handle);
+    req->bagq_end_handle = htole16(end_handle);
+    ble_uuid_flat(uuid, req->uuid);
 
     BLE_ATT_LOG_CMD(1, "read group type req", conn_handle,
                     ble_att_read_group_type_req_log, req);
 
-    return 0;
-
-err:
-    os_mbuf_free_chain(txom);
-    return rc;
+    return ble_att_tx(conn_handle, txom);
 }
 
 static int

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1c08e62b/net/nimble/host/src/ble_att_cmd_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_cmd_priv.h b/net/nimble/host/src/ble_att_cmd_priv.h
index be7fda3..d1c7d33 100644
--- a/net/nimble/host/src/ble_att_cmd_priv.h
+++ b/net/nimble/host/src/ble_att_cmd_priv.h
@@ -222,6 +222,7 @@ struct ble_att_read_mult_req {
 struct ble_att_read_group_type_req {
     uint16_t bagq_start_handle;
     uint16_t bagq_end_handle;
+    uint8_t uuid[0];
 } __attribute__((packed));
 
 /**

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1c08e62b/net/nimble/host/src/ble_att_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_priv.h b/net/nimble/host/src/ble_att_priv.h
index 19f84a4..08185bc 100644
--- a/net/nimble/host/src/ble_att_priv.h
+++ b/net/nimble/host/src/ble_att_priv.h
@@ -263,9 +263,9 @@ int ble_att_clt_rx_read_mult(uint16_t conn_handle, struct os_mbuf **rxom);
 int ble_att_clt_tx_read_type(uint16_t conn_handle, uint16_t start_handle,
                              uint16_t end_handle, const ble_uuid_t *uuid);
 int ble_att_clt_rx_read_type(uint16_t conn_handle, struct os_mbuf **rxom);
-int ble_att_clt_tx_read_group_type(
-    uint16_t conn_handle, const struct ble_att_read_group_type_req *req,
-    const ble_uuid_t *uuid128);
+int ble_att_clt_tx_read_group_type(uint16_t conn_handle,
+                                   uint16_t start_handle, uint16_t end_handle,
+                                   const ble_uuid_t *uuid128);
 int ble_att_clt_rx_read_group_type(uint16_t conn_handle,
                                    struct os_mbuf **rxom);
 int ble_att_clt_tx_find_info(uint16_t conn_handle,

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1c08e62b/net/nimble/host/src/ble_gattc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gattc.c b/net/nimble/host/src/ble_gattc.c
index 2e04e54..84491dc 100644
--- a/net/nimble/host/src/ble_gattc.c
+++ b/net/nimble/host/src/ble_gattc.c
@@ -1385,15 +1385,14 @@ ble_gattc_disc_all_svcs_tmo(struct ble_gattc_proc *proc)
 static int
 ble_gattc_disc_all_svcs_tx(struct ble_gattc_proc *proc)
 {
-    struct ble_att_read_group_type_req req;
     ble_uuid16_t uuid = BLE_UUID16_INIT(BLE_ATT_UUID_PRIMARY_SERVICE);
     int rc;
 
     ble_gattc_dbg_assert_proc_not_inserted(proc);
 
-    req.bagq_start_handle = proc->disc_all_svcs.prev_handle + 1;
-    req.bagq_end_handle = 0xffff;
-    rc = ble_att_clt_tx_read_group_type(proc->conn_handle, &req, &uuid.u);
+    rc = ble_att_clt_tx_read_group_type(proc->conn_handle,
+                                        proc->disc_all_svcs.prev_handle + 1,
+                                        0xffff, &uuid.u);
     if (rc != 0) {
         return rc;
     }


[02/50] incubator-mynewt-core git commit: nimble/att: Use new helpers for sending error response

Posted by an...@apache.org.
nimble/att: Use new helpers for sending error response

This constructs response directly on mbuf reducing number of memcopies.


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

Branch: refs/heads/master
Commit: b50707b6a67dd8b4d6b168904b0a4d6b8a79bcf7
Parents: 71a8a47
Author: Szymon Janc <sz...@codecoup.pl>
Authored: Fri Mar 24 12:52:57 2017 +0100
Committer: Szymon Janc <sz...@codecoup.pl>
Committed: Mon Apr 10 11:31:16 2017 +0200

----------------------------------------------------------------------
 net/nimble/host/src/ble_att_svr.c | 71 +++++++++++++---------------------
 1 file changed, 27 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b50707b6/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
index 5ca2c87..ac6fa55 100644
--- a/net/nimble/host/src/ble_att_svr.c
+++ b/net/nimble/host/src/ble_att_svr.c
@@ -568,43 +568,26 @@ ble_att_svr_write_handle(uint16_t conn_handle, uint16_t attr_handle,
 }
 
 static int
-ble_att_svr_tx_error_rsp(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan,
-                         struct os_mbuf *txom, uint8_t req_op,
-                         uint16_t handle, uint8_t error_code)
+ble_att_svr_tx_error_rsp(uint16_t conn_handle, struct os_mbuf *txom,
+                         uint8_t req_op, uint16_t handle, uint8_t error_code)
 {
-    struct ble_att_error_rsp rsp;
-    void *dst;
-    int rc;
+    struct ble_att_error_rsp *rsp;
 
     BLE_HS_DBG_ASSERT(error_code != 0);
     BLE_HS_DBG_ASSERT(OS_MBUF_PKTLEN(txom) == 0);
 
-    dst = os_mbuf_extend(txom, BLE_ATT_ERROR_RSP_SZ);
-    if (dst == NULL) {
-        rc = BLE_HS_ENOMEM;
-        goto err;
-    }
-
-    rsp.baep_req_op = req_op;
-    rsp.baep_handle = handle;
-    rsp.baep_error_code = error_code;
-
-    ble_att_error_rsp_write(dst, BLE_ATT_ERROR_RSP_SZ, &rsp);
-
-    rc = ble_l2cap_tx(conn, chan, txom);
-    txom = NULL;
-    if (rc != 0) {
-        goto err;
+    rsp = ble_att_cmd_prepare(BLE_ATT_OP_ERROR_RSP, sizeof(*rsp), txom);
+    if (rsp == NULL) {
+        return BLE_HS_ENOMEM;
     }
 
-    BLE_ATT_LOG_CMD(1, "error rsp", conn->bhc_handle,
-                    ble_att_error_rsp_log, &rsp);
+    rsp->baep_req_op = req_op;
+    rsp->baep_handle = htole16(handle);
+    rsp->baep_error_code = error_code;
 
-    return 0;
+    BLE_ATT_LOG_CMD(1, "error rsp", conn_handle, ble_att_error_rsp_log, rsp);
 
-err:
-    os_mbuf_free_chain(txom);
-    return rc;
+    return ble_att_tx(conn_handle, txom);
 }
 
 /**
@@ -664,26 +647,26 @@ ble_att_svr_tx_rsp(uint16_t conn_handle, int hs_status, struct os_mbuf *om,
                 if (hs_status != 0) {
                     err_status = BLE_ATT_ERR_UNLIKELY;
                 }
-            }
+           }
+        }
 
-            if (hs_status != 0) {
-                STATS_INC(ble_att_stats, error_rsp_tx);
+        ble_hs_unlock();
 
-                /* Reuse om for error response. */
-                if (om == NULL) {
-                    om = ble_hs_mbuf_l2cap_pkt();
-                } else {
-                    os_mbuf_adj(om, OS_MBUF_PKTLEN(om));
-                }
-                if (om != NULL) {
-                    ble_att_svr_tx_error_rsp(conn, chan, om, att_op,
-                                             err_handle, err_status);
-                    om = NULL;
-                }
+        if (hs_status != 0) {
+            STATS_INC(ble_att_stats, error_rsp_tx);
+
+            /* Reuse om for error response. */
+            if (om == NULL) {
+                om = ble_hs_mbuf_l2cap_pkt();
+            } else {
+                os_mbuf_adj(om, OS_MBUF_PKTLEN(om));
+            }
+            if (om != NULL) {
+                ble_att_svr_tx_error_rsp(conn_handle, om, att_op,
+                                         err_handle, err_status);
+                om = NULL;
             }
         }
-
-        ble_hs_unlock();
     }
 
     /* Free mbuf if it was not consumed (i.e., if the send failed). */


[09/50] incubator-mynewt-core git commit: nimble/att: Use new helpers for sending read command

Posted by an...@apache.org.
nimble/att: Use new helpers for sending read command

This constructs response directly on mbuf reducing number of memcopies.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/58743be0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/58743be0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/58743be0

Branch: refs/heads/master
Commit: 58743be0c8f1991e4dc98b4c33d3b0420bdb3743
Parents: 55b8a5c
Author: Szymon Janc <sz...@codecoup.pl>
Authored: Fri Mar 24 15:27:57 2017 +0100
Committer: Szymon Janc <sz...@codecoup.pl>
Committed: Mon Apr 10 11:31:31 2017 +0200

----------------------------------------------------------------------
 net/nimble/host/src/ble_att_clt.c           | 16 +++++++++-------
 net/nimble/host/src/ble_att_priv.h          |  3 +--
 net/nimble/host/src/ble_gattc.c             | 13 ++++---------
 net/nimble/host/test/src/ble_att_clt_test.c |  7 ++-----
 4 files changed, 16 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/58743be0/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
index 7ea7980..fc5a432 100644
--- a/net/nimble/host/src/ble_att_clt.c
+++ b/net/nimble/host/src/ble_att_clt.c
@@ -557,26 +557,28 @@ done:
  *****************************************************************************/
 
 int
-ble_att_clt_tx_read(uint16_t conn_handle, const struct ble_att_read_req *req)
+ble_att_clt_tx_read(uint16_t conn_handle, uint16_t handle)
 {
 #if !NIMBLE_BLE_ATT_CLT_READ
     return BLE_HS_ENOTSUP;
 #endif
 
+    struct ble_att_read_req *req;
     struct os_mbuf *txom;
     int rc;
 
-    if (req->barq_handle == 0) {
+    if (handle == 0) {
         return BLE_HS_EINVAL;
     }
 
-    rc = ble_att_clt_init_req(BLE_ATT_READ_REQ_SZ, &txom);
-    if (rc != 0) {
-        return rc;
+    req = ble_att_cmd_get(BLE_ATT_OP_READ_REQ, sizeof(*req), &txom);
+    if (req == NULL) {
+        return BLE_HS_ENOMEM;
     }
-    ble_att_read_req_write(txom->om_data, txom->om_len, req);
 
-    rc = ble_att_clt_tx_req(conn_handle, txom);
+    req->barq_handle = htole16(handle);
+
+    rc = ble_att_tx(conn_handle, txom);
     if (rc != 0) {
         return rc;
     }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/58743be0/net/nimble/host/src/ble_att_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_priv.h b/net/nimble/host/src/ble_att_priv.h
index 4e37bb7..85da2de 100644
--- a/net/nimble/host/src/ble_att_priv.h
+++ b/net/nimble/host/src/ble_att_priv.h
@@ -252,8 +252,7 @@ struct ble_att_read_group_type_adata {
 int ble_att_clt_rx_error(uint16_t conn_handle, struct os_mbuf **rxom);
 int ble_att_clt_tx_mtu(uint16_t conn_handle, uint16_t mtu);
 int ble_att_clt_rx_mtu(uint16_t conn_handle, struct os_mbuf **rxom);
-int ble_att_clt_tx_read(uint16_t conn_handle,
-                        const struct ble_att_read_req *req);
+int ble_att_clt_tx_read(uint16_t conn_handle, uint16_t handle);
 int ble_att_clt_rx_read(uint16_t conn_handle, struct os_mbuf **rxom);
 int ble_att_clt_tx_read_blob(uint16_t conn_handle,
                              const struct ble_att_read_blob_req *req);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/58743be0/net/nimble/host/src/ble_gattc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gattc.c b/net/nimble/host/src/ble_gattc.c
index d50368f..ba84727 100644
--- a/net/nimble/host/src/ble_gattc.c
+++ b/net/nimble/host/src/ble_gattc.c
@@ -1850,7 +1850,6 @@ static int
 ble_gattc_find_inc_svcs_tx(struct ble_gattc_proc *proc)
 {
     struct ble_att_read_type_req read_type_req;
-    struct ble_att_read_req read_req;
     ble_uuid16_t uuid = BLE_UUID16_INIT(BLE_ATT_UUID_INCLUDE);
     int rc;
 
@@ -1869,8 +1868,8 @@ ble_gattc_find_inc_svcs_tx(struct ble_gattc_proc *proc)
         }
     } else {
         /* Read the UUID of the previously found service. */
-        read_req.barq_handle = proc->find_inc_svcs.cur_start;
-        rc = ble_att_clt_tx_read(proc->conn_handle, &read_req);
+        rc = ble_att_clt_tx_read(proc->conn_handle,
+                                 proc->find_inc_svcs.cur_start);
         if (rc != 0) {
             return rc;
         }
@@ -2950,11 +2949,9 @@ ble_gattc_read_rx_read_rsp(struct ble_gattc_proc *proc, int status,
 static int
 ble_gattc_read_tx(struct ble_gattc_proc *proc)
 {
-    struct ble_att_read_req req;
     int rc;
 
-    req.barq_handle = proc->read.handle;
-    rc = ble_att_clt_tx_read(proc->conn_handle, &req);
+    rc = ble_att_clt_tx_read(proc->conn_handle, proc->read.handle);
     if (rc != 0) {
         return rc;
     }
@@ -3256,14 +3253,12 @@ static int
 ble_gattc_read_long_tx(struct ble_gattc_proc *proc)
 {
     struct ble_att_read_blob_req blob_req;
-    struct ble_att_read_req read_req;
     int rc;
 
     ble_gattc_dbg_assert_proc_not_inserted(proc);
 
     if (proc->read_long.offset == 0) {
-        read_req.barq_handle = proc->read_long.handle;
-        rc = ble_att_clt_tx_read(proc->conn_handle, &read_req);
+        rc = ble_att_clt_tx_read(proc->conn_handle, proc->read_long.handle);
         if (rc != 0) {
             return rc;
         }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/58743be0/net/nimble/host/test/src/ble_att_clt_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/test/src/ble_att_clt_test.c b/net/nimble/host/test/src/ble_att_clt_test.c
index c452128..3d12ee8 100644
--- a/net/nimble/host/test/src/ble_att_clt_test.c
+++ b/net/nimble/host/test/src/ble_att_clt_test.c
@@ -297,20 +297,17 @@ TEST_CASE(ble_att_clt_test_tx_write)
 
 TEST_CASE(ble_att_clt_test_tx_read)
 {
-    struct ble_att_read_req req;
     uint16_t conn_handle;
     int rc;
 
     conn_handle = ble_att_clt_test_misc_init();
 
     /*** Success. */
-    req.barq_handle = 1;
-    rc = ble_att_clt_tx_read(conn_handle, &req);
+    rc = ble_att_clt_tx_read(conn_handle, 1);
     TEST_ASSERT(rc == 0);
 
     /*** Error: handle of 0. */
-    req.barq_handle = 0;
-    rc = ble_att_clt_tx_read(conn_handle, &req);
+    rc = ble_att_clt_tx_read(conn_handle, 0);
     TEST_ASSERT(rc == BLE_HS_EINVAL);
 }
 


[44/50] incubator-mynewt-core git commit: nimble/l2cap: Remove some dead code

Posted by an...@apache.org.
nimble/l2cap: Remove some dead code

Those functions are not used anymore.


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

Branch: refs/heads/master
Commit: fd6c58a82396a6b59772b9781ecfe25d4b39b2b9
Parents: 7674f26
Author: Szymon Janc <sz...@codecoup.pl>
Authored: Fri Mar 24 15:50:08 2017 +0100
Committer: Szymon Janc <sz...@codecoup.pl>
Committed: Mon Apr 10 11:31:33 2017 +0200

----------------------------------------------------------------------
 net/nimble/host/src/ble_l2cap_sig_cmd.c  | 8 --------
 net/nimble/host/src/ble_l2cap_sig_priv.h | 4 ----
 2 files changed, 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/fd6c58a8/net/nimble/host/src/ble_l2cap_sig_cmd.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sig_cmd.c b/net/nimble/host/src/ble_l2cap_sig_cmd.c
index 4381be5..ae8b102 100644
--- a/net/nimble/host/src/ble_l2cap_sig_cmd.c
+++ b/net/nimble/host/src/ble_l2cap_sig_cmd.c
@@ -53,14 +53,6 @@ ble_l2cap_sig_hdr_parse(void *payload, uint16_t len,
     ble_l2cap_sig_hdr_swap(dst, payload);
 }
 
-void
-ble_l2cap_sig_hdr_write(void *payload, uint16_t len,
-                        struct ble_l2cap_sig_hdr *src)
-{
-    BLE_HS_DBG_ASSERT(len >= BLE_L2CAP_SIG_HDR_SZ);
-    ble_l2cap_sig_hdr_swap(payload, src);
-}
-
 int
 ble_l2cap_sig_reject_tx(uint16_t conn_handle, uint8_t id, uint16_t reason,
                         void *data, int data_len)

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/fd6c58a8/net/nimble/host/src/ble_l2cap_sig_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sig_priv.h b/net/nimble/host/src/ble_l2cap_sig_priv.h
index 49d096c..3a23b92 100644
--- a/net/nimble/host/src/ble_l2cap_sig_priv.h
+++ b/net/nimble/host/src/ble_l2cap_sig_priv.h
@@ -89,12 +89,8 @@ struct ble_l2cap_sig_le_credits {
     uint16_t credits;
 } __attribute__((packed));
 
-int ble_l2cap_sig_init_cmd(uint8_t op, uint8_t id, uint8_t payload_len,
-                           struct os_mbuf **out_om, void **out_payload_buf);
 void ble_l2cap_sig_hdr_parse(void *payload, uint16_t len,
                              struct ble_l2cap_sig_hdr *hdr);
-void ble_l2cap_sig_hdr_write(void *payload, uint16_t len,
-                             struct ble_l2cap_sig_hdr *hdr);
 int ble_l2cap_sig_reject_tx(uint16_t conn_handle,
                             uint8_t id, uint16_t reason,
                             void *data, int data_len);


[12/50] incubator-mynewt-core git commit: nimble/att: Use new helpers for sending Find Information Request

Posted by an...@apache.org.
nimble/att: Use new helpers for sending Find Information Request

This constructs response directly on mbuf reducing number of memcopies.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/5e82b3f7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/5e82b3f7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/5e82b3f7

Branch: refs/heads/master
Commit: 5e82b3f7c0daf08547b51ec47907891e4cbb1b38
Parents: 1c08e62
Author: Szymon Janc <sz...@codecoup.pl>
Authored: Fri Mar 24 15:32:18 2017 +0100
Committer: Szymon Janc <sz...@codecoup.pl>
Committed: Mon Apr 10 11:31:31 2017 +0200

----------------------------------------------------------------------
 net/nimble/host/src/ble_att_clt.c           | 25 ++++++++++--------------
 net/nimble/host/src/ble_att_priv.h          |  4 ++--
 net/nimble/host/src/ble_gattc.c             |  8 +++-----
 net/nimble/host/test/src/ble_att_clt_test.c | 17 ++++------------
 4 files changed, 19 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5e82b3f7/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
index c35ad89..f72b209 100644
--- a/net/nimble/host/src/ble_att_clt.c
+++ b/net/nimble/host/src/ble_att_clt.c
@@ -209,37 +209,32 @@ ble_att_clt_rx_mtu(uint16_t conn_handle, struct os_mbuf **rxom)
  *****************************************************************************/
 
 int
-ble_att_clt_tx_find_info(uint16_t conn_handle,
-                         const struct ble_att_find_info_req *req)
+ble_att_clt_tx_find_info(uint16_t conn_handle, uint16_t start_handle,
+                         uint16_t end_handle)
 {
 #if !NIMBLE_BLE_ATT_CLT_FIND_INFO
     return BLE_HS_ENOTSUP;
 #endif
 
+    struct ble_att_find_info_req *req;
     struct os_mbuf *txom;
-    int rc;
-
-    if (req->bafq_start_handle == 0 ||
-        req->bafq_start_handle > req->bafq_end_handle) {
 
+    if (start_handle == 0 || start_handle > end_handle) {
         return BLE_HS_EINVAL;
     }
 
-    rc = ble_att_clt_init_req(BLE_ATT_FIND_INFO_REQ_SZ, &txom);
-    if (rc != 0) {
-        return rc;
+    req = ble_att_cmd_get(BLE_ATT_OP_FIND_INFO_REQ, sizeof(*req), &txom);
+    if (req == NULL) {
+        return BLE_HS_ENOMEM;
     }
-    ble_att_find_info_req_write(txom->om_data, txom->om_len, req);
 
-    rc = ble_att_clt_tx_req(conn_handle, txom);
-    if (rc != 0) {
-        return rc;
-    }
+    req->bafq_start_handle = htole16(start_handle);
+    req->bafq_end_handle = htole16(end_handle);
 
     BLE_ATT_LOG_CMD(1, "find info req", conn_handle,
                     ble_att_find_info_req_log, req);
 
-    return 0;
+    return ble_att_tx(conn_handle, txom);
 }
 
 static int

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5e82b3f7/net/nimble/host/src/ble_att_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_priv.h b/net/nimble/host/src/ble_att_priv.h
index 08185bc..86a7b76 100644
--- a/net/nimble/host/src/ble_att_priv.h
+++ b/net/nimble/host/src/ble_att_priv.h
@@ -268,8 +268,8 @@ int ble_att_clt_tx_read_group_type(uint16_t conn_handle,
                                    const ble_uuid_t *uuid128);
 int ble_att_clt_rx_read_group_type(uint16_t conn_handle,
                                    struct os_mbuf **rxom);
-int ble_att_clt_tx_find_info(uint16_t conn_handle,
-                             const struct ble_att_find_info_req *req);
+int ble_att_clt_tx_find_info(uint16_t conn_handle, uint16_t start_handle,
+                             uint16_t end_handle);
 int ble_att_clt_rx_find_info(uint16_t conn_handle, struct os_mbuf **rxom);
 int ble_att_clt_tx_find_type_value(
     uint16_t conn_handle, const struct ble_att_find_type_value_req *req,

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5e82b3f7/net/nimble/host/src/ble_gattc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gattc.c b/net/nimble/host/src/ble_gattc.c
index 84491dc..99d2e83 100644
--- a/net/nimble/host/src/ble_gattc.c
+++ b/net/nimble/host/src/ble_gattc.c
@@ -2679,15 +2679,13 @@ ble_gattc_disc_all_dscs_tmo(struct ble_gattc_proc *proc)
 static int
 ble_gattc_disc_all_dscs_tx(struct ble_gattc_proc *proc)
 {
-    struct ble_att_find_info_req req;
     int rc;
 
     ble_gattc_dbg_assert_proc_not_inserted(proc);
 
-    req.bafq_start_handle = proc->disc_all_dscs.prev_handle + 1;
-    req.bafq_end_handle = proc->disc_all_dscs.end_handle;
-
-    rc = ble_att_clt_tx_find_info(proc->conn_handle, &req);
+    rc = ble_att_clt_tx_find_info(proc->conn_handle,
+                                  proc->disc_all_dscs.prev_handle + 1,
+                                  proc->disc_all_dscs.end_handle);
     if (rc != 0) {
         return rc;
     }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5e82b3f7/net/nimble/host/test/src/ble_att_clt_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/test/src/ble_att_clt_test.c b/net/nimble/host/test/src/ble_att_clt_test.c
index afd7c41..dec4695 100644
--- a/net/nimble/host/test/src/ble_att_clt_test.c
+++ b/net/nimble/host/test/src/ble_att_clt_test.c
@@ -77,34 +77,25 @@ ble_att_clt_test_tx_write_req_or_cmd(uint16_t conn_handle,
 
 TEST_CASE(ble_att_clt_test_tx_find_info)
 {
-    struct ble_att_find_info_req req;
     uint16_t conn_handle;
     int rc;
 
     conn_handle = ble_att_clt_test_misc_init();
 
     /*** Success. */
-    req.bafq_start_handle = 1;
-    req.bafq_end_handle = 0xffff;
-    rc = ble_att_clt_tx_find_info(conn_handle, &req);
+    rc = ble_att_clt_tx_find_info(conn_handle, 1, 0xffff);
     TEST_ASSERT(rc == 0);
 
     /*** Error: start handle of 0. */
-    req.bafq_start_handle = 0;
-    req.bafq_end_handle = 0xffff;
-    rc = ble_att_clt_tx_find_info(conn_handle, &req);
+    rc = ble_att_clt_tx_find_info(conn_handle, 0, 0xffff);
     TEST_ASSERT(rc == BLE_HS_EINVAL);
 
     /*** Error: start handle greater than end handle. */
-    req.bafq_start_handle = 500;
-    req.bafq_end_handle = 499;
-    rc = ble_att_clt_tx_find_info(conn_handle, &req);
+    rc = ble_att_clt_tx_find_info(conn_handle, 500, 499);
     TEST_ASSERT(rc == BLE_HS_EINVAL);
 
     /*** Success; start and end handles equal. */
-    req.bafq_start_handle = 500;
-    req.bafq_end_handle = 500;
-    rc = ble_att_clt_tx_find_info(conn_handle, &req);
+    rc = ble_att_clt_tx_find_info(conn_handle, 500, 500);
     TEST_ASSERT(rc == 0);
 }
 


[45/50] incubator-mynewt-core git commit: nimble/att: Use packed struct for receiving Write Command

Posted by an...@apache.org.
nimble/att: Use packed struct for receiving Write Command

Use packed structure to map it to received mbuf instead of using
dedicated parsing function. Modern compilers generate effective code
in such case anyway.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/3876f10f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/3876f10f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/3876f10f

Branch: refs/heads/master
Commit: 3876f10f11473407fb8326cacd15956105fc10b4
Parents: 255debf
Author: Szymon Janc <sz...@codecoup.pl>
Authored: Fri Mar 24 15:50:07 2017 +0100
Committer: Szymon Janc <sz...@codecoup.pl>
Committed: Mon Apr 10 11:31:33 2017 +0200

----------------------------------------------------------------------
 net/nimble/host/src/ble_att_svr.c | 27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3876f10f/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
index 23599a8..8c9a6cb 100644
--- a/net/nimble/host/src/ble_att_svr.c
+++ b/net/nimble/host/src/ble_att_svr.c
@@ -2109,30 +2109,31 @@ ble_att_svr_rx_write_no_rsp(uint16_t conn_handle, struct os_mbuf **rxom)
     return BLE_HS_ENOTSUP;
 #endif
 
-    struct ble_att_write_req req;
+    struct ble_att_write_req *req;
     uint8_t att_err;
+    uint16_t handle;
     int rc;
 
-    rc = ble_att_svr_pullup_req_base(rxom, BLE_ATT_WRITE_REQ_BASE_SZ,
-                                     &att_err);
+    /* TODO move this to common part
+     * Strip L2CAP ATT header from the front of the mbuf.
+     */
+    os_mbuf_adj(*rxom, 1);
+
+    rc = ble_att_svr_pullup_req_base(rxom, sizeof(*req), &att_err);
     if (rc != 0) {
         return rc;
     }
 
-    ble_att_write_cmd_parse((*rxom)->om_data, (*rxom)->om_len, &req);
+    req = (struct ble_att_write_req *)(*rxom)->om_data;
     BLE_ATT_LOG_CMD(0, "write cmd", conn_handle,
-                    ble_att_write_req_log, &req);
+                    ble_att_write_req_log, req);
 
-    /* Strip the request base from the front of the mbuf. */
-    os_mbuf_adj(*rxom, BLE_ATT_WRITE_REQ_BASE_SZ);
+    handle = le16toh(req->bawq_handle);
 
-    rc = ble_att_svr_write_handle(conn_handle, req.bawq_handle, 0, rxom,
-                                  &att_err);
-    if (rc != 0) {
-        return rc;
-    }
+    /* Strip the request base from the front of the mbuf. */
+    os_mbuf_adj(*rxom, sizeof(*req));
 
-    return 0;
+    return ble_att_svr_write_handle(conn_handle, handle, 0, rxom, &att_err);
 }
 
 /**


[47/50] incubator-mynewt-core git commit: nimble/att: Use packed struct for receiving Notification

Posted by an...@apache.org.
nimble/att: Use packed struct for receiving Notification

Use packed structure to map it to received mbuf instead of using
dedicated parsing function. Modern compilers generate effective code
in such case anyway.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/7ea6ad88
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/7ea6ad88
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/7ea6ad88

Branch: refs/heads/master
Commit: 7ea6ad8838ffd9b99989eddd5c4317938ce4ae69
Parents: f495fa7
Author: Szymon Janc <sz...@codecoup.pl>
Authored: Fri Mar 24 15:50:06 2017 +0100
Committer: Szymon Janc <sz...@codecoup.pl>
Committed: Mon Apr 10 11:31:33 2017 +0200

----------------------------------------------------------------------
 net/nimble/host/src/ble_att_svr.c | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7ea6ad88/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
index 11877cb..b6da4df 100644
--- a/net/nimble/host/src/ble_att_svr.c
+++ b/net/nimble/host/src/ble_att_svr.c
@@ -2590,30 +2590,35 @@ ble_att_svr_rx_notify(uint16_t conn_handle, struct os_mbuf **rxom)
     return BLE_HS_ENOTSUP;
 #endif
 
-    struct ble_att_notify_req req;
+    struct ble_att_notify_req *req;
+    uint16_t handle;
     int rc;
 
-    if (OS_MBUF_PKTLEN(*rxom) < BLE_ATT_NOTIFY_REQ_BASE_SZ) {
-        return BLE_HS_EBADDATA;
-    }
+    /* TODO move this to common part
+     * Strip L2CAP ATT header from the front of the mbuf.
+     */
+    os_mbuf_adj(*rxom, 1);
 
-    rc = ble_att_svr_pullup_req_base(rxom, BLE_ATT_NOTIFY_REQ_BASE_SZ, NULL);
+    rc = ble_att_svr_pullup_req_base(rxom, sizeof(*req), NULL);
     if (rc != 0) {
         return BLE_HS_ENOMEM;
     }
 
-    ble_att_notify_req_parse((*rxom)->om_data, (*rxom)->om_len, &req);
+    req = (struct ble_att_notify_req *)(*rxom)->om_data;
+
     BLE_ATT_LOG_CMD(0, "notify req", conn_handle,
-                    ble_att_notify_req_log, &req);
+                    ble_att_notify_req_log, req);
 
-    if (req.banq_handle == 0) {
+    handle = le16toh(req->banq_handle);
+
+    if (handle == 0) {
         return BLE_HS_EBADDATA;
     }
 
     /* Strip the request base from the front of the mbuf. */
-    os_mbuf_adj(*rxom, BLE_ATT_NOTIFY_REQ_BASE_SZ);
+    os_mbuf_adj(*rxom, sizeof(*req));
 
-    ble_gap_notify_rx_event(conn_handle, req.banq_handle, *rxom, 0);
+    ble_gap_notify_rx_event(conn_handle, handle, *rxom, 0);
     *rxom = NULL;
 
     return 0;


[33/50] incubator-mynewt-core git commit: nimble/att: Use packed struct for receiving Read Multiple Response

Posted by an...@apache.org.
nimble/att: Use packed struct for receiving Read Multiple Response

Use packed structure to map it to received mbuf instead of using
dedicated parsing function. Modern compilers generate effective code
in such case anyway.


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

Branch: refs/heads/master
Commit: a36089c42de642b1678ccede93d7606a6c6796e9
Parents: d7da6aa
Author: Szymon Janc <sz...@codecoup.pl>
Authored: Fri Mar 24 15:50:05 2017 +0100
Committer: Szymon Janc <sz...@codecoup.pl>
Committed: Mon Apr 10 11:31:32 2017 +0200

----------------------------------------------------------------------
 net/nimble/host/src/ble_att_clt.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a36089c4/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
index 612d3c5..a8220f4 100644
--- a/net/nimble/host/src/ble_att_clt.c
+++ b/net/nimble/host/src/ble_att_clt.c
@@ -637,10 +637,10 @@ ble_att_clt_rx_read_mult(uint16_t conn_handle, struct os_mbuf **rxom)
 
     BLE_ATT_LOG_EMPTY_CMD(0, "read mult rsp", conn_handle);
 
-    /* Reponse consists of a one-byte opcode (already verified) and a variable
-     * length Attribute Value field.  Strip the opcode from the response.
+    /* TODO move this to common part
+     * Strip L2CAP ATT header from the front of the mbuf.
      */
-    os_mbuf_adj(*rxom, BLE_ATT_READ_MULT_RSP_BASE_SZ);
+    os_mbuf_adj(*rxom, 1);
 
     /* Pass the Attribute Value field to GATT. */
     ble_gattc_rx_read_mult_rsp(conn_handle, 0, rxom);


[08/50] incubator-mynewt-core git commit: nimble/att: Use new helpers for sending Read Blob Request

Posted by an...@apache.org.
nimble/att: Use new helpers for sending Read Blob Request

This constructs response directly on mbuf reducing number of memcopies.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/090f62b7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/090f62b7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/090f62b7

Branch: refs/heads/master
Commit: 090f62b725b2713cb4dd9013ff7f4f3fa413a2cc
Parents: 58743be
Author: Szymon Janc <sz...@codecoup.pl>
Authored: Fri Mar 24 15:28:38 2017 +0100
Committer: Szymon Janc <sz...@codecoup.pl>
Committed: Mon Apr 10 11:31:31 2017 +0200

----------------------------------------------------------------------
 net/nimble/host/src/ble_att_clt.c           | 18 ++++++++++--------
 net/nimble/host/src/ble_att_priv.h          |  4 ++--
 net/nimble/host/src/ble_gattc.c             |  7 +++----
 net/nimble/host/test/src/ble_att_clt_test.c |  9 ++-------
 4 files changed, 17 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/090f62b7/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
index fc5a432..e85beac 100644
--- a/net/nimble/host/src/ble_att_clt.c
+++ b/net/nimble/host/src/ble_att_clt.c
@@ -612,27 +612,29 @@ ble_att_clt_rx_read(uint16_t conn_handle, struct os_mbuf **rxom)
  *****************************************************************************/
 
 int
-ble_att_clt_tx_read_blob(uint16_t conn_handle,
-                         const struct ble_att_read_blob_req *req)
+ble_att_clt_tx_read_blob(uint16_t conn_handle, uint16_t handle, uint16_t offset)
 {
 #if !NIMBLE_BLE_ATT_CLT_READ_BLOB
     return BLE_HS_ENOTSUP;
 #endif
 
+    struct ble_att_read_blob_req *req;
     struct os_mbuf *txom;
     int rc;
 
-    if (req->babq_handle == 0) {
+    if (handle == 0) {
         return BLE_HS_EINVAL;
     }
 
-    rc = ble_att_clt_init_req(BLE_ATT_READ_BLOB_REQ_SZ, &txom);
-    if (rc != 0) {
-        return rc;
+    req = ble_att_cmd_get(BLE_ATT_OP_READ_BLOB_REQ, sizeof(*req), &txom);
+    if (req == NULL) {
+        return BLE_HS_ENOMEM;
     }
-    ble_att_read_blob_req_write(txom->om_data, txom->om_len, req);
 
-    rc = ble_att_clt_tx_req(conn_handle, txom);
+    req->babq_handle = htole16(handle);
+    req->babq_offset = htole16(offset);
+
+    rc = ble_att_tx(conn_handle, txom);
     if (rc != 0) {
         return rc;
     }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/090f62b7/net/nimble/host/src/ble_att_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_priv.h b/net/nimble/host/src/ble_att_priv.h
index 85da2de..62bebf9 100644
--- a/net/nimble/host/src/ble_att_priv.h
+++ b/net/nimble/host/src/ble_att_priv.h
@@ -254,8 +254,8 @@ int ble_att_clt_tx_mtu(uint16_t conn_handle, uint16_t mtu);
 int ble_att_clt_rx_mtu(uint16_t conn_handle, struct os_mbuf **rxom);
 int ble_att_clt_tx_read(uint16_t conn_handle, uint16_t handle);
 int ble_att_clt_rx_read(uint16_t conn_handle, struct os_mbuf **rxom);
-int ble_att_clt_tx_read_blob(uint16_t conn_handle,
-                             const struct ble_att_read_blob_req *req);
+int ble_att_clt_tx_read_blob(uint16_t conn_handle, uint16_t handle,
+                             uint16_t offset);
 int ble_att_clt_rx_read_blob(uint16_t conn_handle, struct os_mbuf **rxom);
 int ble_att_clt_tx_read_mult(uint16_t conn_handle,
                              const uint16_t *handles, int num_handles);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/090f62b7/net/nimble/host/src/ble_gattc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gattc.c b/net/nimble/host/src/ble_gattc.c
index ba84727..85866b5 100644
--- a/net/nimble/host/src/ble_gattc.c
+++ b/net/nimble/host/src/ble_gattc.c
@@ -3252,7 +3252,6 @@ ble_gattc_read_long_tmo(struct ble_gattc_proc *proc)
 static int
 ble_gattc_read_long_tx(struct ble_gattc_proc *proc)
 {
-    struct ble_att_read_blob_req blob_req;
     int rc;
 
     ble_gattc_dbg_assert_proc_not_inserted(proc);
@@ -3263,9 +3262,9 @@ ble_gattc_read_long_tx(struct ble_gattc_proc *proc)
             return rc;
         }
     } else {
-        blob_req.babq_handle = proc->read_long.handle;
-        blob_req.babq_offset = proc->read_long.offset;
-        rc = ble_att_clt_tx_read_blob(proc->conn_handle, &blob_req);
+        rc = ble_att_clt_tx_read_blob(proc->conn_handle,
+                                      proc->read_long.handle,
+                                      proc->read_long.offset);
         if (rc != 0) {
             return rc;
         }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/090f62b7/net/nimble/host/test/src/ble_att_clt_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/test/src/ble_att_clt_test.c b/net/nimble/host/test/src/ble_att_clt_test.c
index 3d12ee8..afd7c41 100644
--- a/net/nimble/host/test/src/ble_att_clt_test.c
+++ b/net/nimble/host/test/src/ble_att_clt_test.c
@@ -339,22 +339,17 @@ TEST_CASE(ble_att_clt_test_rx_read)
 
 TEST_CASE(ble_att_clt_test_tx_read_blob)
 {
-    struct ble_att_read_blob_req req;
     uint16_t conn_handle;
     int rc;
 
     conn_handle = ble_att_clt_test_misc_init();
 
     /*** Success. */
-    req.babq_handle = 1;
-    req.babq_offset = 0;
-    rc = ble_att_clt_tx_read_blob(conn_handle, &req);
+    rc = ble_att_clt_tx_read_blob(conn_handle, 1, 0);
     TEST_ASSERT(rc == 0);
 
     /*** Error: handle of 0. */
-    req.babq_handle = 0;
-    req.babq_offset = 0;
-    rc = ble_att_clt_tx_read_blob(conn_handle, &req);
+    rc = ble_att_clt_tx_read_blob(conn_handle, 0, 0);
     TEST_ASSERT(rc == BLE_HS_EINVAL);
 }
 


[32/50] incubator-mynewt-core git commit: nimble/att: Use packed struct for receiving Read By Group Type Request

Posted by an...@apache.org.
nimble/att: Use packed struct for receiving Read By Group Type Request

Use packed structure to map it to received mbuf instead of using
dedicated parsing function. Modern compilers generate effective code
in such case anyway.


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

Branch: refs/heads/master
Commit: de742e26ccadf17c129d149f4c7c25c6670429e3
Parents: a36089c
Author: Szymon Janc <sz...@codecoup.pl>
Authored: Fri Mar 24 15:50:05 2017 +0100
Committer: Szymon Janc <sz...@codecoup.pl>
Committed: Mon Apr 10 11:31:32 2017 +0200

----------------------------------------------------------------------
 net/nimble/host/src/ble_att_svr.c | 74 +++++++++++++++++-----------------
 1 file changed, 38 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/de742e26/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
index f3e4bec..0990e8d 100644
--- a/net/nimble/host/src/ble_att_svr.c
+++ b/net/nimble/host/src/ble_att_svr.c
@@ -1760,29 +1760,28 @@ ble_att_svr_read_group_type_entry_write(struct os_mbuf *om, uint16_t mtu,
  */
 static int
 ble_att_svr_build_read_group_type_rsp(uint16_t conn_handle,
-                                      struct ble_att_read_group_type_req *req,
+                                      uint16_t start_handle,
+                                      uint16_t end_handle,
                                       const ble_uuid_t *group_uuid,
                                       struct os_mbuf **rxom,
                                       struct os_mbuf **out_txom,
                                       uint8_t *att_err,
                                       uint16_t *err_handle)
 {
-    struct ble_att_read_group_type_rsp rsp;
+    struct ble_att_read_group_type_rsp *rsp;
     struct ble_att_svr_entry *entry;
     struct os_mbuf *txom;
     uint16_t start_group_handle;
     uint16_t end_group_handle;
     uint16_t mtu;
     ble_uuid_any_t service_uuid;
-    void *rsp_buf;
     int rc;
 
     /* Silence warnings. */
-    rsp_buf = NULL;
     end_group_handle = 0;
 
     *att_err = 0;
-    *err_handle = req->bagq_start_handle;
+    *err_handle = start_handle;
 
     mtu = ble_att_mtu(conn_handle);
 
@@ -1792,20 +1791,21 @@ ble_att_svr_build_read_group_type_rsp(uint16_t conn_handle,
     os_mbuf_adj(txom, OS_MBUF_PKTLEN(txom));
 
     /* Reserve space for the response base. */
-    rsp_buf = os_mbuf_extend(txom, BLE_ATT_READ_GROUP_TYPE_RSP_BASE_SZ);
-    if (rsp_buf == NULL) {
+    rsp = ble_att_cmd_prepare(BLE_ATT_OP_READ_GROUP_TYPE_RSP, sizeof(*rsp),
+                              txom);
+    if (rsp == NULL) {
         *att_err = BLE_ATT_ERR_INSUFFICIENT_RES;
         rc = BLE_HS_ENOMEM;
         goto done;
     }
 
     start_group_handle = 0;
-    rsp.bagp_length = 0;
+    rsp->bagp_length = 0;
     STAILQ_FOREACH(entry, &ble_att_svr_list, ha_next) {
-        if (entry->ha_handle_id < req->bagq_start_handle) {
+        if (entry->ha_handle_id < start_handle) {
             continue;
         }
-        if (entry->ha_handle_id > req->bagq_end_handle) {
+        if (entry->ha_handle_id > end_handle) {
             /* The full input range has been searched. */
             rc = 0;
             goto done;
@@ -1851,12 +1851,12 @@ ble_att_svr_build_read_group_type_rsp(uint16_t conn_handle,
                  * group has a different length UUID, then cut the response
                  * short.
                  */
-                switch (rsp.bagp_length) {
+                switch (rsp->bagp_length) {
                 case 0:
                     if (service_uuid.u.type == BLE_UUID_TYPE_16) {
-                        rsp.bagp_length = BLE_ATT_READ_GROUP_TYPE_ADATA_SZ_16;
+                        rsp->bagp_length = BLE_ATT_READ_GROUP_TYPE_ADATA_SZ_16;
                     } else {
-                        rsp.bagp_length = BLE_ATT_READ_GROUP_TYPE_ADATA_SZ_128;
+                        rsp->bagp_length = BLE_ATT_READ_GROUP_TYPE_ADATA_SZ_128;
                     }
                     break;
 
@@ -1918,11 +1918,8 @@ done:
     }
 
     if (rc == 0 || rc == BLE_HS_EMSGSIZE) {
-        ble_att_read_group_type_rsp_write(rsp_buf,
-                                          BLE_ATT_READ_GROUP_TYPE_RSP_BASE_SZ,
-                                          &rsp);
         BLE_ATT_LOG_CMD(1, "read group type rsp", conn_handle,
-                        ble_att_read_group_type_rsp_log, &rsp);
+                        ble_att_read_group_type_rsp_log, rsp);
         rc = 0;
     }
 
@@ -1937,24 +1934,29 @@ ble_att_svr_rx_read_group_type(uint16_t conn_handle, struct os_mbuf **rxom)
     return BLE_HS_ENOTSUP;
 #endif
 
-    struct ble_att_read_group_type_req req;
+    struct ble_att_read_group_type_req *req;
     struct os_mbuf *txom;
     ble_uuid_any_t uuid;
-    uint16_t err_handle;
+    uint16_t err_handle, start_handle, end_handle;
     uint16_t pktlen;
     uint8_t att_err;
     int om_uuid_len;
     int rc;
 
+    /* TODO move this to common part
+     * Strip L2CAP ATT header from the front of the mbuf.
+     */
+    os_mbuf_adj(*rxom, 1);
+
     /* Initialize some values in case of early error. */
     txom = NULL;
 
     pktlen = OS_MBUF_PKTLEN(*rxom);
-    if (pktlen != BLE_ATT_READ_GROUP_TYPE_REQ_SZ_16 &&
-        pktlen != BLE_ATT_READ_GROUP_TYPE_REQ_SZ_128) {
-
-        /* Malformed request; discard. */
-        return BLE_HS_EBADDATA;
+    if (pktlen != sizeof(*req) + 2 && pktlen != sizeof(*req) + 16) {
+        /* Malformed packet */
+        err_handle = 0;
+        rc = BLE_HS_EBADDATA;
+        goto done;
     }
 
     rc = ble_att_svr_pullup_req_base(rxom, pktlen, &att_err);
@@ -1963,39 +1965,39 @@ ble_att_svr_rx_read_group_type(uint16_t conn_handle, struct os_mbuf **rxom)
         goto done;
     }
 
-    ble_att_read_group_type_req_parse((*rxom)->om_data, (*rxom)->om_len, &req);
+    req = (struct ble_att_read_group_type_req *)(*rxom)->om_data;
     BLE_ATT_LOG_CMD(0, "read group type req", conn_handle,
-                    ble_att_read_group_type_req_log, &req);
+                    ble_att_read_group_type_req_log, req);
 
-    if (req.bagq_start_handle > req.bagq_end_handle ||
-        req.bagq_start_handle == 0) {
+    start_handle = le16toh(req->bagq_start_handle);
+    end_handle = le16toh(req->bagq_end_handle);
 
+    if (start_handle > end_handle || start_handle == 0) {
         att_err = BLE_ATT_ERR_INVALID_HANDLE;
-        err_handle = req.bagq_start_handle;
+        err_handle = start_handle;
         rc = BLE_HS_EBADDATA;
         goto done;
     }
 
-    om_uuid_len = OS_MBUF_PKTHDR(*rxom)->omp_len -
-                  BLE_ATT_READ_GROUP_TYPE_REQ_BASE_SZ;
-    rc = ble_uuid_init_from_mbuf(&uuid, *rxom,
-                                 BLE_ATT_READ_GROUP_TYPE_REQ_BASE_SZ,
+    om_uuid_len = OS_MBUF_PKTHDR(*rxom)->omp_len - sizeof(*req);
+    rc = ble_uuid_init_from_mbuf(&uuid, *rxom, sizeof(*req),
                                  om_uuid_len);
     if (rc != 0) {
         att_err = BLE_ATT_ERR_INVALID_PDU;
-        err_handle = req.bagq_start_handle;
+        err_handle = start_handle;
         rc = BLE_HS_EBADDATA;
         goto done;
     }
 
     if (!ble_att_svr_is_valid_read_group_type(&uuid.u)) {
         att_err = BLE_ATT_ERR_UNSUPPORTED_GROUP;
-        err_handle = req.bagq_start_handle;
+        err_handle = start_handle;
         rc = BLE_HS_ENOTSUP;
         goto done;
     }
 
-    rc = ble_att_svr_build_read_group_type_rsp(conn_handle, &req, &uuid.u,
+    rc = ble_att_svr_build_read_group_type_rsp(conn_handle, start_handle,
+                                               end_handle, &uuid.u,
                                                rxom, &txom, &att_err,
                                                &err_handle);
     if (rc != 0) {


[07/50] incubator-mynewt-core git commit: nimble/att: Use new helpers for sending Read By Type Request

Posted by an...@apache.org.
nimble/att: Use new helpers for sending Read By Type Request

This constructs response directly on mbuf reducing number of memcopies.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/3f4cac38
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/3f4cac38
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/3f4cac38

Branch: refs/heads/master
Commit: 3f4cac389abd597446cfdd5edbbf535b9142e294
Parents: ab23765
Author: Szymon Janc <sz...@codecoup.pl>
Authored: Fri Mar 24 15:29:40 2017 +0100
Committer: Szymon Janc <sz...@codecoup.pl>
Committed: Mon Apr 10 11:31:31 2017 +0200

----------------------------------------------------------------------
 net/nimble/host/src/ble_att_clt.c      | 43 +++++++++--------------------
 net/nimble/host/src/ble_att_cmd_priv.h |  1 +
 net/nimble/host/src/ble_att_priv.h     |  5 ++--
 net/nimble/host/src/ble_gattc.c        | 41 ++++++++-------------------
 4 files changed, 28 insertions(+), 62 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3f4cac38/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
index 95db5bb..96a04e2 100644
--- a/net/nimble/host/src/ble_att_clt.c
+++ b/net/nimble/host/src/ble_att_clt.c
@@ -445,52 +445,35 @@ ble_att_clt_rx_find_type_value(uint16_t conn_handle, struct os_mbuf **rxom)
  *****************************************************************************/
 
 int
-ble_att_clt_tx_read_type(uint16_t conn_handle,
-                         const struct ble_att_read_type_req *req,
-                         const ble_uuid_t *uuid)
+ble_att_clt_tx_read_type(uint16_t conn_handle, uint16_t start_handle,
+                         uint16_t end_handle, const ble_uuid_t *uuid)
 {
 #if !NIMBLE_BLE_ATT_CLT_READ_TYPE
     return BLE_HS_ENOTSUP;
 #endif
 
+    struct ble_att_read_type_req *req;
     struct os_mbuf *txom;
-    int rc;
-
-    txom = NULL;
-
-    if (req->batq_start_handle == 0 ||
-        req->batq_start_handle > req->batq_end_handle) {
 
-        rc = BLE_HS_EINVAL;
-        goto err;
+    if (start_handle == 0 || start_handle > end_handle) {
+        return BLE_HS_EINVAL;
     }
 
-    rc = ble_att_clt_init_req(BLE_ATT_READ_TYPE_REQ_BASE_SZ, &txom);
-    if (rc != 0) {
-        goto err;
+    req = ble_att_cmd_get(BLE_ATT_OP_READ_TYPE_REQ,
+                          sizeof(*req) + ble_uuid_length(uuid), &txom);
+    if (req == NULL) {
+        return BLE_HS_ENOMEM;
     }
 
-    ble_att_read_type_req_write(txom->om_data, txom->om_len, req);
-    rc = ble_uuid_to_mbuf(uuid, txom);
-    if (rc != 0) {
-        rc = BLE_HS_ENOMEM;
-        goto err;
-    }
+    req->batq_start_handle = htole16(start_handle);
+    req->batq_end_handle = htole16(end_handle);
 
-    rc = ble_att_clt_tx_req(conn_handle, txom);
-    txom = NULL;
-    if (rc != 0) {
-        goto err;
-    }
+    ble_uuid_flat(uuid, req->uuid);
 
     BLE_ATT_LOG_CMD(1, "read type req", conn_handle,
                     ble_att_read_type_req_log, req);
 
-    return 0;
-
-err:
-    os_mbuf_free_chain(txom);
-    return rc;
+    return ble_att_tx(conn_handle, txom);
 }
 
 static int

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3f4cac38/net/nimble/host/src/ble_att_cmd_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_cmd_priv.h b/net/nimble/host/src/ble_att_cmd_priv.h
index c07455a..be7fda3 100644
--- a/net/nimble/host/src/ble_att_cmd_priv.h
+++ b/net/nimble/host/src/ble_att_cmd_priv.h
@@ -130,6 +130,7 @@ struct ble_att_find_type_value_req {
 struct ble_att_read_type_req {
     uint16_t batq_start_handle;
     uint16_t batq_end_handle;
+    uint8_t uuid[0];
 } __attribute__((packed));
 
 /**

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3f4cac38/net/nimble/host/src/ble_att_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_priv.h b/net/nimble/host/src/ble_att_priv.h
index 62bebf9..19f84a4 100644
--- a/net/nimble/host/src/ble_att_priv.h
+++ b/net/nimble/host/src/ble_att_priv.h
@@ -260,9 +260,8 @@ int ble_att_clt_rx_read_blob(uint16_t conn_handle, struct os_mbuf **rxom);
 int ble_att_clt_tx_read_mult(uint16_t conn_handle,
                              const uint16_t *handles, int num_handles);
 int ble_att_clt_rx_read_mult(uint16_t conn_handle, struct os_mbuf **rxom);
-int ble_att_clt_tx_read_type(uint16_t conn_handle,
-                             const struct ble_att_read_type_req *req,
-                             const ble_uuid_t *uuid);
+int ble_att_clt_tx_read_type(uint16_t conn_handle, uint16_t start_handle,
+                             uint16_t end_handle, const ble_uuid_t *uuid);
 int ble_att_clt_rx_read_type(uint16_t conn_handle, struct os_mbuf **rxom);
 int ble_att_clt_tx_read_group_type(
     uint16_t conn_handle, const struct ble_att_read_group_type_req *req,

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3f4cac38/net/nimble/host/src/ble_gattc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gattc.c b/net/nimble/host/src/ble_gattc.c
index 85866b5..2e04e54 100644
--- a/net/nimble/host/src/ble_gattc.c
+++ b/net/nimble/host/src/ble_gattc.c
@@ -1849,7 +1849,6 @@ ble_gattc_find_inc_svcs_tmo(struct ble_gattc_proc *proc)
 static int
 ble_gattc_find_inc_svcs_tx(struct ble_gattc_proc *proc)
 {
-    struct ble_att_read_type_req read_type_req;
     ble_uuid16_t uuid = BLE_UUID16_INIT(BLE_ATT_UUID_INCLUDE);
     int rc;
 
@@ -1857,12 +1856,9 @@ ble_gattc_find_inc_svcs_tx(struct ble_gattc_proc *proc)
 
     if (proc->find_inc_svcs.cur_start == 0) {
         /* Find the next included service. */
-        read_type_req.batq_start_handle =
-            proc->find_inc_svcs.prev_handle + 1;
-        read_type_req.batq_end_handle = proc->find_inc_svcs.end_handle;
-
         rc = ble_att_clt_tx_read_type(proc->conn_handle,
-                                      &read_type_req, &uuid.u);
+                                      proc->find_inc_svcs.prev_handle + 1,
+                                      proc->find_inc_svcs.end_handle, &uuid.u);
         if (rc != 0) {
             return rc;
         }
@@ -2182,16 +2178,14 @@ ble_gattc_disc_all_chrs_tmo(struct ble_gattc_proc *proc)
 static int
 ble_gattc_disc_all_chrs_tx(struct ble_gattc_proc *proc)
 {
-    struct ble_att_read_type_req req;
     ble_uuid16_t uuid = BLE_UUID16_INIT(BLE_ATT_UUID_CHARACTERISTIC);
     int rc;
 
     ble_gattc_dbg_assert_proc_not_inserted(proc);
 
-    req.batq_start_handle = proc->disc_all_chrs.prev_handle + 1;
-    req.batq_end_handle = proc->disc_all_chrs.end_handle;
-
-    rc = ble_att_clt_tx_read_type(proc->conn_handle, &req, &uuid.u);
+    rc = ble_att_clt_tx_read_type(proc->conn_handle,
+                                  proc->disc_all_chrs.prev_handle + 1,
+                                  proc->disc_all_chrs.end_handle, &uuid.u);
     if (rc != 0) {
         return rc;
     }
@@ -2428,16 +2422,14 @@ ble_gattc_disc_chr_uuid_tmo(struct ble_gattc_proc *proc)
 static int
 ble_gattc_disc_chr_uuid_tx(struct ble_gattc_proc *proc)
 {
-    struct ble_att_read_type_req req;
     ble_uuid16_t uuid = BLE_UUID16_INIT(BLE_ATT_UUID_CHARACTERISTIC);
     int rc;
 
     ble_gattc_dbg_assert_proc_not_inserted(proc);
 
-    req.batq_start_handle = proc->disc_chr_uuid.prev_handle + 1;
-    req.batq_end_handle = proc->disc_chr_uuid.end_handle;
-
-    rc = ble_att_clt_tx_read_type(proc->conn_handle, &req, &uuid.u);
+    rc = ble_att_clt_tx_read_type(proc->conn_handle,
+                                  proc->disc_chr_uuid.prev_handle + 1,
+                                  proc->disc_chr_uuid.end_handle, &uuid.u);
     if (rc != 0) {
         return rc;
     }
@@ -3127,19 +3119,10 @@ ble_gattc_read_uuid_rx_complete(struct ble_gattc_proc *proc, int status)
 static int
 ble_gattc_read_uuid_tx(struct ble_gattc_proc *proc)
 {
-    struct ble_att_read_type_req req;
-    int rc;
-
-    req.batq_start_handle = proc->read_uuid.start_handle;
-    req.batq_end_handle = proc->read_uuid.end_handle;
-
-    rc = ble_att_clt_tx_read_type(proc->conn_handle, &req,
-                                  &proc->read_uuid.chr_uuid.u);
-    if (rc != 0) {
-        return rc;
-    }
-
-    return 0;
+    return ble_att_clt_tx_read_type(proc->conn_handle,
+                                    proc->read_uuid.start_handle,
+                                    proc->read_uuid.end_handle,
+                                    &proc->read_uuid.chr_uuid.u);
 }
 
 /**


[20/50] incubator-mynewt-core git commit: nimble/att: Use packed struct for receiving MTU Exchange

Posted by an...@apache.org.
nimble/att: Use packed struct for receiving MTU Exchange

Use packed structure to map it to received mbuf instead of using
dedicated parsing function. Modern compilers generate effective code
in such case anyway.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/1a6ebaa3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/1a6ebaa3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/1a6ebaa3

Branch: refs/heads/master
Commit: 1a6ebaa3128a2b854d5c35a65d4a7a50308e75ca
Parents: fe97914
Author: Szymon Janc <sz...@codecoup.pl>
Authored: Fri Mar 24 15:47:53 2017 +0100
Committer: Szymon Janc <sz...@codecoup.pl>
Committed: Mon Apr 10 11:31:32 2017 +0200

----------------------------------------------------------------------
 net/nimble/host/src/ble_att_svr.c | 30 ++++++++++++++++++------------
 1 file changed, 18 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1a6ebaa3/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
index 3aea795..cf6160c 100644
--- a/net/nimble/host/src/ble_att_svr.c
+++ b/net/nimble/host/src/ble_att_svr.c
@@ -679,11 +679,10 @@ static int
 ble_att_svr_build_mtu_rsp(uint16_t conn_handle, struct os_mbuf **rxom,
                           struct os_mbuf **out_txom, uint8_t *att_err)
 {
-    struct ble_att_mtu_cmd cmd;
+    struct ble_att_mtu_cmd *cmd;
     struct ble_l2cap_chan *chan;
     struct os_mbuf *txom;
     uint16_t mtu;
-    void *dst;
     int rc;
 
     *att_err = 0; /* Silence unnecessary warning. */
@@ -705,17 +704,16 @@ ble_att_svr_build_mtu_rsp(uint16_t conn_handle, struct os_mbuf **rxom,
     *rxom = NULL;
     os_mbuf_adj(txom, OS_MBUF_PKTLEN(txom));
 
-    dst = os_mbuf_extend(txom, BLE_ATT_MTU_CMD_SZ);
-    if (dst == NULL) {
+    cmd = ble_att_cmd_prepare(BLE_ATT_OP_MTU_RSP, sizeof(*cmd), txom);
+    if (cmd == NULL) {
         *att_err = BLE_ATT_ERR_INSUFFICIENT_RES;
         rc = BLE_HS_ENOMEM;
         goto done;
     }
 
-    cmd.bamc_mtu = mtu;
+    cmd->bamc_mtu = htole16(mtu);
 
-    ble_att_mtu_rsp_write(dst, BLE_ATT_MTU_CMD_SZ, &cmd);
-    BLE_ATT_LOG_CMD(1, "mtu rsp", conn_handle, ble_att_mtu_cmd_log, &cmd);
+    BLE_ATT_LOG_CMD(1, "mtu rsp", conn_handle, ble_att_mtu_cmd_log, cmd);
 
     rc = 0;
 
@@ -727,7 +725,7 @@ done:
 int
 ble_att_svr_rx_mtu(uint16_t conn_handle, struct os_mbuf **rxom)
 {
-    struct ble_att_mtu_cmd cmd;
+    struct ble_att_mtu_cmd *cmd;
     struct ble_l2cap_chan *chan;
     struct ble_hs_conn *conn;
     struct os_mbuf *txom;
@@ -735,15 +733,23 @@ ble_att_svr_rx_mtu(uint16_t conn_handle, struct os_mbuf **rxom)
     uint8_t att_err;
     int rc;
 
+    /* TODO move this to common part
+     * Strip L2CAP ATT header from the front of the mbuf.
+     */
+    os_mbuf_adj(*rxom, 1);
+
     txom = NULL;
+    mtu = 0;
 
-    rc = ble_att_svr_pullup_req_base(rxom, BLE_ATT_MTU_CMD_SZ, &att_err);
+    rc = ble_att_svr_pullup_req_base(rxom, sizeof(*cmd), &att_err);
     if (rc != 0) {
         goto done;
     }
 
-    ble_att_mtu_req_parse((*rxom)->om_data, (*rxom)->om_len, &cmd);
-    BLE_ATT_LOG_CMD(0, "mtu req", conn_handle, ble_att_mtu_cmd_log, &cmd);
+    cmd = (struct ble_att_mtu_cmd *)(*rxom)->om_data;
+    BLE_ATT_LOG_CMD(0, "mtu req", conn_handle, ble_att_mtu_cmd_log, cmd);
+
+    mtu = le16toh(cmd->bamc_mtu);
 
     rc = ble_att_svr_build_mtu_rsp(conn_handle, rxom, &txom, &att_err);
     if (rc != 0) {
@@ -760,7 +766,7 @@ done:
 
         rc = ble_att_conn_chan_find(conn_handle, &conn, &chan);
         if (rc == 0) {
-            ble_att_set_peer_mtu(chan, cmd.bamc_mtu);
+            ble_att_set_peer_mtu(chan, mtu);
             chan->flags |= BLE_L2CAP_CHAN_F_TXED_MTU;
             mtu = ble_att_chan_mtu(chan);
         }


[17/50] incubator-mynewt-core git commit: nimble/att: Use new helpers for sending Prepare Write Request

Posted by an...@apache.org.
nimble/att: Use new helpers for sending Prepare Write Request

This constructs response directly on mbuf reducing number of memcopies.


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

Branch: refs/heads/master
Commit: d290cd7eb79540f1d9f14623861894e0dbd8ee9e
Parents: a9549fd
Author: Szymon Janc <sz...@codecoup.pl>
Authored: Fri Mar 24 15:34:39 2017 +0100
Committer: Szymon Janc <sz...@codecoup.pl>
Committed: Mon Apr 10 11:31:31 2017 +0200

----------------------------------------------------------------------
 net/nimble/host/src/ble_att_clt.c           | 29 ++++++++++--------------
 net/nimble/host/src/ble_att_cmd_priv.h      |  1 +
 net/nimble/host/src/ble_att_priv.h          |  5 ++--
 net/nimble/host/src/ble_gattc.c             | 15 ++++--------
 net/nimble/host/test/src/ble_att_clt_test.c |  9 ++------
 5 files changed, 22 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d290cd7e/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
index 114abea..141e6e7 100644
--- a/net/nimble/host/src/ble_att_clt.c
+++ b/net/nimble/host/src/ble_att_clt.c
@@ -872,52 +872,47 @@ ble_att_clt_rx_write(uint16_t conn_handle, struct os_mbuf **rxom)
  *****************************************************************************/
 
 int
-ble_att_clt_tx_prep_write(uint16_t conn_handle,
-                          const struct ble_att_prep_write_cmd *req,
-                          struct os_mbuf *txom)
+ble_att_clt_tx_prep_write(uint16_t conn_handle, uint16_t handle,
+                          uint16_t offset, struct os_mbuf *txom)
 {
 #if !NIMBLE_BLE_ATT_CLT_PREP_WRITE
     return BLE_HS_ENOTSUP;
 #endif
 
+    struct ble_att_prep_write_cmd *req;
+    struct os_mbuf *txom2;
     int rc;
 
-    if (req->bapc_handle == 0) {
+    if (handle == 0) {
         rc = BLE_HS_EINVAL;
         goto err;
     }
 
-    if (req->bapc_offset + OS_MBUF_PKTLEN(txom) > BLE_ATT_ATTR_MAX_LEN) {
+    if (offset + OS_MBUF_PKTLEN(txom) > BLE_ATT_ATTR_MAX_LEN) {
         rc = BLE_HS_EINVAL;
         goto err;
     }
 
     if (OS_MBUF_PKTLEN(txom) >
         ble_att_mtu(conn_handle) - BLE_ATT_PREP_WRITE_CMD_BASE_SZ) {
-
         rc = BLE_HS_EINVAL;
         goto err;
     }
 
-    txom = os_mbuf_prepend_pullup(txom, BLE_ATT_PREP_WRITE_CMD_BASE_SZ);
-    if (txom == NULL) {
+    req = ble_att_cmd_get(BLE_ATT_OP_PREP_WRITE_REQ, sizeof(*req), &txom2);
+    if (req == NULL) {
         rc = BLE_HS_ENOMEM;
         goto err;
     }
 
-    ble_att_prep_write_req_write(txom->om_data, BLE_ATT_PREP_WRITE_CMD_BASE_SZ,
-                                 req);
-
-    rc = ble_att_clt_tx_req(conn_handle, txom);
-    txom = NULL;
-    if (rc != 0) {
-        goto err;
-    }
+    req->bapc_handle = htole16(handle);
+    req->bapc_offset = htole16(offset);
+    os_mbuf_concat(txom2, txom);
 
     BLE_ATT_LOG_CMD(1, "prep write req", conn_handle,
                     ble_att_prep_write_cmd_log, req);
 
-    return 0;
+    return ble_att_tx(conn_handle, txom2);
 
 err:
     os_mbuf_free_chain(txom);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d290cd7e/net/nimble/host/src/ble_att_cmd_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_cmd_priv.h b/net/nimble/host/src/ble_att_cmd_priv.h
index 491dc99..3e03cca 100644
--- a/net/nimble/host/src/ble_att_cmd_priv.h
+++ b/net/nimble/host/src/ble_att_cmd_priv.h
@@ -269,6 +269,7 @@ struct ble_att_write_req {
 struct ble_att_prep_write_cmd {
     uint16_t bapc_handle;
     uint16_t bapc_offset;
+    uint16_t bapc_value[0];
 } __attribute__((packed));
 
 /**

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d290cd7e/net/nimble/host/src/ble_att_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_priv.h b/net/nimble/host/src/ble_att_priv.h
index b7def41..dd14be7 100644
--- a/net/nimble/host/src/ble_att_priv.h
+++ b/net/nimble/host/src/ble_att_priv.h
@@ -280,9 +280,8 @@ int ble_att_clt_tx_write_req(uint16_t conn_handle, uint16_t handle,
                              struct os_mbuf *txom);
 int ble_att_clt_tx_write_cmd(uint16_t conn_handle, uint16_t handle,
                              struct os_mbuf *txom);
-int ble_att_clt_tx_prep_write(uint16_t conn_handle,
-                              const struct ble_att_prep_write_cmd *req,
-                              struct os_mbuf *txom);
+int ble_att_clt_tx_prep_write(uint16_t conn_handle, uint16_t handle,
+                              uint16_t offset, struct os_mbuf *txom);
 int ble_att_clt_rx_prep_write(uint16_t conn_handle, struct os_mbuf **rxom);
 int ble_att_clt_tx_exec_write(uint16_t conn_handle,
                               const struct ble_att_exec_write_req *req);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d290cd7e/net/nimble/host/src/ble_gattc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gattc.c b/net/nimble/host/src/ble_gattc.c
index 7e57433..fede8d1 100644
--- a/net/nimble/host/src/ble_gattc.c
+++ b/net/nimble/host/src/ble_gattc.c
@@ -3816,7 +3816,6 @@ ble_gattc_write_long_tmo(struct ble_gattc_proc *proc)
 static int
 ble_gattc_write_long_tx(struct ble_gattc_proc *proc)
 {
-    struct ble_att_prep_write_cmd prep_req;
     struct ble_att_exec_write_req exec_req;
     struct os_mbuf *om;
     int write_len;
@@ -3859,10 +3858,9 @@ ble_gattc_write_long_tx(struct ble_gattc_proc *proc)
         goto done;
     }
 
-    prep_req.bapc_handle = proc->write_long.attr.handle;
-    prep_req.bapc_offset = proc->write_long.attr.offset;
-
-    rc = ble_att_clt_tx_prep_write(proc->conn_handle, &prep_req, om);
+    rc = ble_att_clt_tx_prep_write(proc->conn_handle,
+                                   proc->write_long.attr.handle,
+                                   proc->write_long.attr.offset, om);
     om = NULL;
     if (rc != 0) {
         goto done;
@@ -4130,7 +4128,6 @@ ble_gattc_write_reliable_tmo(struct ble_gattc_proc *proc)
 static int
 ble_gattc_write_reliable_tx(struct ble_gattc_proc *proc)
 {
-    struct ble_att_prep_write_cmd prep_req;
     struct ble_att_exec_write_req exec_req;
     struct ble_gatt_attr *attr;
     struct os_mbuf *om;
@@ -4175,10 +4172,8 @@ ble_gattc_write_reliable_tx(struct ble_gattc_proc *proc)
         goto done;
     }
 
-    prep_req.bapc_handle = attr->handle;
-    prep_req.bapc_offset = attr->offset;
-
-    rc = ble_att_clt_tx_prep_write(proc->conn_handle, &prep_req, om);
+    rc = ble_att_clt_tx_prep_write(proc->conn_handle, attr->handle,
+                                   attr->offset, om);
     om = NULL;
     if (rc != 0) {
         goto done;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d290cd7e/net/nimble/host/test/src/ble_att_clt_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/test/src/ble_att_clt_test.c b/net/nimble/host/test/src/ble_att_clt_test.c
index 97a1a44..e3ba5ce 100644
--- a/net/nimble/host/test/src/ble_att_clt_test.c
+++ b/net/nimble/host/test/src/ble_att_clt_test.c
@@ -199,10 +199,8 @@ ble_att_clt_test_misc_prep_good(uint16_t handle, uint16_t offset,
 
     conn_handle = ble_att_clt_test_misc_init();
 
-    req.bapc_handle = handle;
-    req.bapc_offset = offset;
     om = ble_hs_test_util_om_from_flat(attr_data, attr_data_len);
-    rc = ble_att_clt_tx_prep_write(conn_handle, &req, om);
+    rc = ble_att_clt_tx_prep_write(conn_handle, handle, offset, om);
     TEST_ASSERT(rc == 0);
 
     ble_hs_test_util_tx_all();
@@ -247,7 +245,6 @@ ble_att_clt_test_misc_prep_bad(uint16_t handle, uint16_t offset,
                                uint8_t *attr_data, uint16_t attr_data_len,
                                int status)
 {
-    struct ble_att_prep_write_cmd req;
     struct os_mbuf *om;
     uint16_t conn_handle;
     int rc;
@@ -256,9 +253,7 @@ ble_att_clt_test_misc_prep_bad(uint16_t handle, uint16_t offset,
 
     om = ble_hs_test_util_om_from_flat(attr_data, attr_data_len);
 
-    req.bapc_handle = handle;
-    req.bapc_offset = offset;
-    rc = ble_att_clt_tx_prep_write(conn_handle, &req, om);
+    rc = ble_att_clt_tx_prep_write(conn_handle, handle, offset, om);
     TEST_ASSERT(rc == status);
 }
 


[34/50] incubator-mynewt-core git commit: nimble/att: Use packed struct for receiving MTU exchange

Posted by an...@apache.org.
nimble/att: Use packed struct for receiving MTU exchange

Use packed structure to map it to received mbuf instead of using
dedicated parsing function. Modern compilers generate effective code
in such case anyway.


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

Branch: refs/heads/master
Commit: a31e34bb4dd830603115bc31d27551a9e578786b
Parents: 8e60273
Author: Szymon Janc <sz...@codecoup.pl>
Authored: Fri Mar 24 15:46:20 2017 +0100
Committer: Szymon Janc <sz...@codecoup.pl>
Committed: Mon Apr 10 11:31:32 2017 +0200

----------------------------------------------------------------------
 net/nimble/host/src/ble_att_clt.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a31e34bb/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
index c63ec52..1d45ef0 100644
--- a/net/nimble/host/src/ble_att_clt.c
+++ b/net/nimble/host/src/ble_att_clt.c
@@ -118,23 +118,29 @@ ble_att_clt_tx_mtu(uint16_t conn_handle, uint16_t mtu)
 int
 ble_att_clt_rx_mtu(uint16_t conn_handle, struct os_mbuf **rxom)
 {
-    struct ble_att_mtu_cmd cmd;
+    struct ble_att_mtu_cmd *cmd;
     struct ble_l2cap_chan *chan;
     uint16_t mtu;
     int rc;
 
+    /* TODO move this to common part
+     * Strip L2CAP ATT header from the front of the mbuf.
+     */
+    os_mbuf_adj(*rxom, 1);
+
     mtu = 0;
 
-    rc = ble_hs_mbuf_pullup_base(rxom, BLE_ATT_MTU_CMD_SZ);
+    rc = ble_hs_mbuf_pullup_base(rxom, sizeof(*cmd));
     if (rc == 0) {
-        ble_att_mtu_rsp_parse((*rxom)->om_data, (*rxom)->om_len, &cmd);
-        BLE_ATT_LOG_CMD(0, "mtu rsp", conn_handle, ble_att_mtu_cmd_log, &cmd);
+        cmd = (struct ble_att_mtu_cmd *)(*rxom)->om_data;
+
+        BLE_ATT_LOG_CMD(0, "mtu rsp", conn_handle, ble_att_mtu_cmd_log, cmd);
 
         ble_hs_lock();
 
         rc = ble_att_conn_chan_find(conn_handle, NULL, &chan);
         if (rc == 0) {
-            ble_att_set_peer_mtu(chan, cmd.bamc_mtu);
+            ble_att_set_peer_mtu(chan, le16toh(cmd->bamc_mtu));
             mtu = ble_att_chan_mtu(chan);
         }
 


[37/50] incubator-mynewt-core git commit: nimble/att: Strip common ATT header before passing buf to handlers

Posted by an...@apache.org.
nimble/att: Strip common ATT header before passing buf to handlers

This reduce code size and move common part in single place.


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

Branch: refs/heads/master
Commit: d458bb8c3b6ea61ed6b05b1465bc876dc070b3bb
Parents: 3876f10
Author: Szymon Janc <sz...@codecoup.pl>
Authored: Fri Mar 24 15:50:08 2017 +0100
Committer: Szymon Janc <sz...@codecoup.pl>
Committed: Mon Apr 10 11:31:33 2017 +0200

----------------------------------------------------------------------
 net/nimble/host/src/ble_att.c     |  3 ++
 net/nimble/host/src/ble_att_clt.c | 55 --------------------------
 net/nimble/host/src/ble_att_svr.c | 70 ----------------------------------
 3 files changed, 3 insertions(+), 125 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d458bb8c/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
index 1756fc8..034c71d 100644
--- a/net/nimble/host/src/ble_att.c
+++ b/net/nimble/host/src/ble_att.c
@@ -490,6 +490,9 @@ ble_att_rx(struct ble_l2cap_chan *chan)
 
     ble_att_inc_rx_stat(op);
 
+    /* Strip L2CAP ATT header from the front of the mbuf. */
+    os_mbuf_adj(*om, 1);
+
     rc = entry->bde_fn(conn_handle, om);
     if (rc != 0) {
         return rc;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d458bb8c/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
index 4a04e70..9ff9b53 100644
--- a/net/nimble/host/src/ble_att_clt.c
+++ b/net/nimble/host/src/ble_att_clt.c
@@ -36,11 +36,6 @@ ble_att_clt_rx_error(uint16_t conn_handle, struct os_mbuf **rxom)
     struct ble_att_error_rsp *rsp;
     int rc;
 
-    /* TODO move this to common part
-     * Strip L2CAP ATT header from the front of the mbuf.
-     */
-    os_mbuf_adj(*rxom, 1);
-
     rc = ble_hs_mbuf_pullup_base(rxom, sizeof(*rsp));
     if (rc != 0) {
         return rc;
@@ -123,11 +118,6 @@ ble_att_clt_rx_mtu(uint16_t conn_handle, struct os_mbuf **rxom)
     uint16_t mtu;
     int rc;
 
-    /* TODO move this to common part
-     * Strip L2CAP ATT header from the front of the mbuf.
-     */
-    os_mbuf_adj(*rxom, 1);
-
     mtu = 0;
 
     rc = ble_hs_mbuf_pullup_base(rxom, sizeof(*cmd));
@@ -250,11 +240,6 @@ ble_att_clt_rx_find_info(uint16_t conn_handle, struct os_mbuf **om)
     struct ble_att_find_info_rsp *rsp;
     int rc;
 
-    /* TODO move this to common part
-     * Strip L2CAP ATT header from the front of the mbuf.
-     */
-    os_mbuf_adj(*om, 1);
-
     rc = ble_hs_mbuf_pullup_base(om, sizeof(*rsp));
     if (rc != 0) {
         goto done;
@@ -361,11 +346,6 @@ ble_att_clt_rx_find_type_value(uint16_t conn_handle, struct os_mbuf **rxom)
 
     BLE_ATT_LOG_EMPTY_CMD(0, "find type value rsp", conn_handle);
 
-    /* TODO move this to common part
-     * Strip L2CAP ATT header from the front of the mbuf.
-     */
-    os_mbuf_adj(*rxom, 1);
-
     /* Parse the Handles-Information-List field, passing each entry to GATT. */
     rc = 0;
     while (OS_MBUF_PKTLEN(*rxom) > 0) {
@@ -432,11 +412,6 @@ ble_att_clt_rx_read_type(uint16_t conn_handle, struct os_mbuf **rxom)
     uint8_t data_len;
     int rc;
 
-    /* TODO move this to common part
-     * Strip L2CAP ATT header from the front of the mbuf.
-     */
-    os_mbuf_adj(*rxom, 1);
-
     rc = ble_hs_mbuf_pullup_base(rxom, sizeof(*rsp));
     if (rc != 0) {
         goto done;
@@ -526,11 +501,6 @@ ble_att_clt_rx_read(uint16_t conn_handle, struct os_mbuf **rxom)
 
     BLE_ATT_LOG_EMPTY_CMD(0, "read rsp", conn_handle);
 
-    /* Reponse consists of a one-byte opcode (already verified) and a variable
-     * length Attribute Value field.  Strip the opcode from the response.
-     */
-    os_mbuf_adj(*rxom, BLE_ATT_READ_RSP_BASE_SZ);
-
     /* Pass the Attribute Value field to GATT. */
     ble_gattc_rx_read_rsp(conn_handle, 0, rxom);
     return 0;
@@ -583,11 +553,6 @@ ble_att_clt_rx_read_blob(uint16_t conn_handle, struct os_mbuf **rxom)
 
     BLE_ATT_LOG_EMPTY_CMD(0, "read blob rsp", conn_handle);
 
-    /* TODO move this to common part
-     * Strip L2CAP ATT header from the front of the mbuf.
-     */
-    os_mbuf_adj(*rxom, 1);
-
     /* Pass the Attribute Value field to GATT. */
     ble_gattc_rx_read_blob_rsp(conn_handle, 0, rxom);
     return 0;
@@ -637,11 +602,6 @@ ble_att_clt_rx_read_mult(uint16_t conn_handle, struct os_mbuf **rxom)
 
     BLE_ATT_LOG_EMPTY_CMD(0, "read mult rsp", conn_handle);
 
-    /* TODO move this to common part
-     * Strip L2CAP ATT header from the front of the mbuf.
-     */
-    os_mbuf_adj(*rxom, 1);
-
     /* Pass the Attribute Value field to GATT. */
     ble_gattc_rx_read_mult_rsp(conn_handle, 0, rxom);
     return 0;
@@ -719,11 +679,6 @@ ble_att_clt_rx_read_group_type(uint16_t conn_handle, struct os_mbuf **rxom)
     uint8_t len;
     int rc;
 
-    /* TODO move this to common part
-     * Strip L2CAP ATT header from the front of the mbuf.
-     */
-    os_mbuf_adj(*rxom, 1);
-
     rc = ble_hs_mbuf_pullup_base(rxom, sizeof(*rsp));
     if (rc != 0) {
         goto done;
@@ -901,11 +856,6 @@ ble_att_clt_rx_prep_write(uint16_t conn_handle, struct os_mbuf **rxom)
     uint16_t handle, offset;
     int rc;
 
-    /* TODO move this to common part
-     * Strip L2CAP ATT header from the front of the mbuf.
-     */
-    os_mbuf_adj(*rxom, 1);
-
     /* Initialize some values in case of early error. */
     handle = 0;
     offset = 0;
@@ -971,11 +921,6 @@ ble_att_clt_rx_exec_write(uint16_t conn_handle, struct os_mbuf **rxom)
     return BLE_HS_ENOTSUP;
 #endif
 
-    /* TODO move this to common part
-     * Strip L2CAP ATT header from the front of the mbuf.
-     */
-    os_mbuf_adj(*rxom, 1);
-
     BLE_ATT_LOG_EMPTY_CMD(0, "exec write rsp", conn_handle);
 
     ble_gattc_rx_exec_write_rsp(conn_handle, 0);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d458bb8c/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
index 8c9a6cb..234aac6 100644
--- a/net/nimble/host/src/ble_att_svr.c
+++ b/net/nimble/host/src/ble_att_svr.c
@@ -733,11 +733,6 @@ ble_att_svr_rx_mtu(uint16_t conn_handle, struct os_mbuf **rxom)
     uint8_t att_err;
     int rc;
 
-    /* TODO move this to common part
-     * Strip L2CAP ATT header from the front of the mbuf.
-     */
-    os_mbuf_adj(*rxom, 1);
-
     txom = NULL;
     mtu = 0;
 
@@ -924,11 +919,6 @@ ble_att_svr_rx_find_info(uint16_t conn_handle, struct os_mbuf **rxom)
     uint8_t att_err;
     int rc;
 
-    /* TODO move this to common part
-     * Strip L2CAP ATT header from the front of the mbuf.
-     */
-    os_mbuf_adj(*rxom, 1);
-
     /* Initialize some values in case of early error. */
     txom = NULL;
     att_err = 0;
@@ -1243,11 +1233,6 @@ ble_att_svr_rx_find_type_value(uint16_t conn_handle, struct os_mbuf **rxom)
     uint8_t att_err;
     int rc;
 
-    /* TODO move this to common part
-    * Strip L2CAP ATT header from the front of the mbuf.
-    */
-    os_mbuf_adj(*rxom, 1);
-
     /* Initialize some values in case of early error. */
     txom = NULL;
     att_err = 0;
@@ -1424,11 +1409,6 @@ ble_att_svr_rx_read_type(uint16_t conn_handle, struct os_mbuf **rxom)
     uint8_t att_err;
     int rc;
 
-    /* TODO move this to common part
-     * Strip L2CAP ATT header from the front of the mbuf.
-     */
-    os_mbuf_adj(*rxom, 1);
-
     /* Initialize some values in case of early error. */
     txom = NULL;
 
@@ -1498,11 +1478,6 @@ ble_att_svr_rx_read(uint16_t conn_handle, struct os_mbuf **rxom)
     uint8_t att_err;
     int rc;
 
-    /* TODO move this to common part
-     * Strip L2CAP ATT header from the front of the mbuf.
-     */
-    os_mbuf_adj(*rxom, 1);
-
     /* Initialize some values in case of early error. */
     txom = NULL;
     att_err = 0;
@@ -1553,11 +1528,6 @@ ble_att_svr_rx_read_blob(uint16_t conn_handle, struct os_mbuf **rxom)
     uint8_t att_err;
     int rc;
 
-    /* TODO move this to common part
-     * Strip L2CAP ATT header from the front of the mbuf.
-     */
-    os_mbuf_adj(*rxom, 1);
-
     /* Initialize some values in case of early error. */
     txom = NULL;
     att_err = 0;
@@ -1676,11 +1646,6 @@ ble_att_svr_rx_read_mult(uint16_t conn_handle, struct os_mbuf **rxom)
     uint8_t att_err;
     int rc;
 
-    /* TODO move this to common part
-     * Strip L2CAP ATT header from the front of the mbuf.
-     */
-    os_mbuf_adj(*rxom, 1);
-
     BLE_ATT_LOG_EMPTY_CMD(0, "read mult req", conn_handle);
 
     /* Initialize some values in case of early error. */
@@ -1943,11 +1908,6 @@ ble_att_svr_rx_read_group_type(uint16_t conn_handle, struct os_mbuf **rxom)
     int om_uuid_len;
     int rc;
 
-    /* TODO move this to common part
-     * Strip L2CAP ATT header from the front of the mbuf.
-     */
-    os_mbuf_adj(*rxom, 1);
-
     /* Initialize some values in case of early error. */
     txom = NULL;
 
@@ -2054,11 +2014,6 @@ ble_att_svr_rx_write(uint16_t conn_handle, struct os_mbuf **rxom)
     uint8_t att_err;
     int rc;
 
-    /* TODO move this to common part
-     * Strip L2CAP ATT header from the front of the mbuf.
-     */
-    os_mbuf_adj(*rxom, 1);
-
     /* Initialize some values in case of early error. */
     txom = NULL;
     att_err = 0;
@@ -2114,11 +2069,6 @@ ble_att_svr_rx_write_no_rsp(uint16_t conn_handle, struct os_mbuf **rxom)
     uint16_t handle;
     int rc;
 
-    /* TODO move this to common part
-     * Strip L2CAP ATT header from the front of the mbuf.
-     */
-    os_mbuf_adj(*rxom, 1);
-
     rc = ble_att_svr_pullup_req_base(rxom, sizeof(*req), &att_err);
     if (rc != 0) {
         return rc;
@@ -2424,11 +2374,6 @@ ble_att_svr_rx_prep_write(uint16_t conn_handle, struct os_mbuf **rxom)
     uint8_t att_err;
     int rc;
 
-    /* TODO move this to common part
-     * Strip L2CAP ATT header from the front of the mbuf.
-     */
-    os_mbuf_adj(*rxom, 1);
-
     /* Initialize some values in case of early error. */
     txom = NULL;
     att_err = 0;
@@ -2519,11 +2464,6 @@ ble_att_svr_rx_exec_write(uint16_t conn_handle, struct os_mbuf **rxom)
     uint8_t flags;
     int rc;
 
-    /* TODO move this to common part
-     * Strip L2CAP ATT header from the front of the mbuf.
-     */
-    os_mbuf_adj(*rxom, 1);
-
     /* Initialize some values in case of early error. */
     txom = NULL;
     err_handle = 0;
@@ -2595,11 +2535,6 @@ ble_att_svr_rx_notify(uint16_t conn_handle, struct os_mbuf **rxom)
     uint16_t handle;
     int rc;
 
-    /* TODO move this to common part
-     * Strip L2CAP ATT header from the front of the mbuf.
-     */
-    os_mbuf_adj(*rxom, 1);
-
     rc = ble_att_svr_pullup_req_base(rxom, sizeof(*req), NULL);
     if (rc != 0) {
         return BLE_HS_ENOMEM;
@@ -2670,11 +2605,6 @@ ble_att_svr_rx_indicate(uint16_t conn_handle, struct os_mbuf **rxom)
     uint8_t att_err;
     int rc;
 
-    /* TODO move this to common part
-     * Strip L2CAP ATT header from the front of the mbuf.
-     */
-    os_mbuf_adj(*rxom, 1);
-
     /* Initialize some values in case of early error. */
     txom = NULL;
     att_err = 0;


[42/50] incubator-mynewt-core git commit: nimble/att: Use packed struct for receiving Execute Write Request

Posted by an...@apache.org.
nimble/att: Use packed struct for receiving Execute Write Request

Use packed structure to map it to received mbuf instead of using
dedicated parsing function. Modern compilers generate effective code
in such case anyway.


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

Branch: refs/heads/master
Commit: ca16b6bc33e35418d2e0aa80cd57d5b918d6e1c8
Parents: 2b2c14e
Author: Szymon Janc <sz...@codecoup.pl>
Authored: Fri Mar 24 15:50:06 2017 +0100
Committer: Szymon Janc <sz...@codecoup.pl>
Committed: Mon Apr 10 11:31:33 2017 +0200

----------------------------------------------------------------------
 net/nimble/host/src/ble_att_svr.c | 64 ++++++++++++----------------------
 1 file changed, 22 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ca16b6bc/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
index 93d6cef..11877cb 100644
--- a/net/nimble/host/src/ble_att_svr.c
+++ b/net/nimble/host/src/ble_att_svr.c
@@ -2502,38 +2502,6 @@ done:
     return rc;
 }
 
-/**
- * @return                      0 on success; nonzero on failure.
- */
-static int
-ble_att_svr_build_exec_write_rsp(struct os_mbuf **rxom,
-                                 struct os_mbuf **out_txom, uint8_t *att_err)
-{
-    struct os_mbuf *txom;
-    uint8_t *dst;
-    int rc;
-
-    /* Just reuse the request buffer for the response. */
-    txom = *rxom;
-    *rxom = NULL;
-    os_mbuf_adj(txom, OS_MBUF_PKTLEN(txom));
-
-    dst = os_mbuf_extend(txom, BLE_ATT_EXEC_WRITE_RSP_SZ);
-    if (dst == NULL) {
-        *att_err = BLE_ATT_ERR_INSUFFICIENT_RES;
-        rc = BLE_HS_ENOMEM;
-        goto done;
-    }
-
-    ble_att_exec_write_rsp_write(dst, BLE_ATT_EXEC_WRITE_RSP_SZ);
-
-    rc = 0;
-
-done:
-    *out_txom = txom;
-    return rc;
-}
-
 int
 ble_att_svr_rx_exec_write(uint16_t conn_handle, struct os_mbuf **rxom)
 {
@@ -2542,30 +2510,42 @@ ble_att_svr_rx_exec_write(uint16_t conn_handle, struct os_mbuf **rxom)
 #endif
 
     struct ble_att_prep_entry_list prep_list;
-    struct ble_att_exec_write_req req;
+    struct ble_att_exec_write_req *req;
     struct ble_hs_conn *conn;
     struct os_mbuf *txom;
     uint16_t err_handle;
     uint8_t att_err;
+    uint8_t flags;
     int rc;
 
+    /* TODO move this to common part
+     * Strip L2CAP ATT header from the front of the mbuf.
+     */
+    os_mbuf_adj(*rxom, 1);
+
     /* Initialize some values in case of early error. */
     txom = NULL;
+    err_handle = 0;
 
-    rc = ble_att_svr_pullup_req_base(rxom, BLE_ATT_EXEC_WRITE_REQ_SZ,
-                                     &att_err);
+    rc = ble_att_svr_pullup_req_base(rxom, sizeof(*req), &att_err);
     if (rc != 0) {
-        err_handle = 0;
         goto done;
     }
 
-    ble_att_exec_write_req_parse((*rxom)->om_data, (*rxom)->om_len, &req);
+    req = (struct ble_att_exec_write_req *)(*rxom)->om_data;
     BLE_ATT_LOG_CMD(0, "exec write req", conn_handle,
-                    ble_att_exec_write_req_log, &req);
+                    ble_att_exec_write_req_log, req);
 
-    rc = ble_att_svr_build_exec_write_rsp(rxom, &txom, &att_err);
-    if (rc != 0) {
-        err_handle = 0;
+    flags = req->baeq_flags;
+
+    /* Just reuse the request buffer for the response. */
+    txom = *rxom;
+    *rxom = NULL;
+    os_mbuf_adj(txom, OS_MBUF_PKTLEN(txom));
+
+    if (ble_att_cmd_prepare(BLE_ATT_OP_EXEC_WRITE_RSP, 0, txom) == NULL) {
+        att_err = BLE_ATT_ERR_INSUFFICIENT_RES;
+        rc = BLE_HS_ENOMEM;
         goto done;
     }
 
@@ -2585,7 +2565,7 @@ done:
         SLIST_INIT(&conn->bhc_att_svr.basc_prep_list);
         ble_hs_unlock();
 
-        if (req.baeq_flags) {
+        if (flags) {
             /* Perform attribute writes. */
             att_err = ble_att_svr_prep_write(conn_handle, &prep_list,
                                              &err_handle);


[49/50] incubator-mynewt-core git commit: nimble/att: Use packed struct for receiving Indication

Posted by an...@apache.org.
nimble/att: Use packed struct for receiving Indication

Use packed structure to map it to received mbuf instead of using
dedicated parsing function. Modern compilers generate effective code
in such case anyway.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/255debf8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/255debf8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/255debf8

Branch: refs/heads/master
Commit: 255debf84dfea8ff0beb2f7e4729ee09c0226c90
Parents: 7ea6ad8
Author: Szymon Janc <sz...@codecoup.pl>
Authored: Fri Mar 24 15:50:07 2017 +0100
Committer: Szymon Janc <sz...@codecoup.pl>
Committed: Mon Apr 10 11:31:33 2017 +0200

----------------------------------------------------------------------
 net/nimble/host/src/ble_att_svr.c | 39 ++++++++++++++++------------------
 1 file changed, 18 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/255debf8/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
index b6da4df..23599a8 100644
--- a/net/nimble/host/src/ble_att_svr.c
+++ b/net/nimble/host/src/ble_att_svr.c
@@ -2632,7 +2632,6 @@ ble_att_svr_build_indicate_rsp(struct os_mbuf **rxom,
                                struct os_mbuf **out_txom, uint8_t *out_att_err)
 {
     struct os_mbuf *txom;
-    uint8_t *dst;
     int rc;
 
     /* Allocate a new buffer for the response.  An indicate response never
@@ -2644,15 +2643,12 @@ ble_att_svr_build_indicate_rsp(struct os_mbuf **rxom,
         goto done;
     }
 
-    dst = os_mbuf_extend(txom, BLE_ATT_INDICATE_RSP_SZ);
-    if (dst == NULL) {
+    if (ble_att_cmd_prepare(BLE_ATT_OP_INDICATE_RSP, 0, txom) == NULL) {
         rc = BLE_HS_ENOMEM;
         *out_att_err = BLE_ATT_ERR_INSUFFICIENT_RES;
         goto done;
     }
 
-    ble_att_indicate_rsp_write(dst, BLE_ATT_INDICATE_RSP_SZ);
-
     rc = 0;
 
 done:
@@ -2667,33 +2663,34 @@ ble_att_svr_rx_indicate(uint16_t conn_handle, struct os_mbuf **rxom)
     return BLE_HS_ENOTSUP;
 #endif
 
-    struct ble_att_indicate_req req;
+    struct ble_att_indicate_req *req;
     struct os_mbuf *txom;
-    uint16_t err_handle;
+    uint16_t handle;
     uint8_t att_err;
     int rc;
 
+    /* TODO move this to common part
+     * Strip L2CAP ATT header from the front of the mbuf.
+     */
+    os_mbuf_adj(*rxom, 1);
+
     /* Initialize some values in case of early error. */
     txom = NULL;
     att_err = 0;
-    err_handle = 0;
-
-    if (OS_MBUF_PKTLEN(*rxom) < BLE_ATT_INDICATE_REQ_BASE_SZ) {
-        rc = BLE_HS_EBADDATA;
-        goto done;
-    }
+    handle = 0;
 
-    rc = ble_att_svr_pullup_req_base(rxom, BLE_ATT_INDICATE_REQ_BASE_SZ, NULL);
+    rc = ble_att_svr_pullup_req_base(rxom, sizeof(*req), NULL);
     if (rc != 0) {
         goto done;
     }
 
-    ble_att_indicate_req_parse((*rxom)->om_data, (*rxom)->om_len, &req);
+    req = (struct ble_att_indicate_req *)(*rxom)->om_data;
     BLE_ATT_LOG_CMD(0, "indicate req", conn_handle,
-                    ble_att_indicate_req_log, &req);
-    err_handle = req.baiq_handle;
+                    ble_att_indicate_req_log, req);
 
-    if (req.baiq_handle == 0) {
+    handle = le16toh(req->baiq_handle);
+
+    if (handle == 0) {
         rc = BLE_HS_EBADDATA;
         goto done;
     }
@@ -2707,9 +2704,9 @@ ble_att_svr_rx_indicate(uint16_t conn_handle, struct os_mbuf **rxom)
     }
 
     /* Strip the request base from the front of the mbuf. */
-    os_mbuf_adj(*rxom, BLE_ATT_INDICATE_REQ_BASE_SZ);
+    os_mbuf_adj(*rxom, sizeof(*req));
 
-    ble_gap_notify_rx_event(conn_handle, req.baiq_handle, *rxom, 1);
+    ble_gap_notify_rx_event(conn_handle, handle, *rxom, 1);
     *rxom = NULL;
 
     BLE_ATT_LOG_EMPTY_CMD(1, "indicate rsp", conn_handle);
@@ -2718,7 +2715,7 @@ ble_att_svr_rx_indicate(uint16_t conn_handle, struct os_mbuf **rxom)
 
 done:
     rc = ble_att_svr_tx_rsp(conn_handle, rc, txom, BLE_ATT_OP_INDICATE_REQ,
-                            att_err, err_handle);
+                            att_err, handle);
     return rc;
 }
 


[50/50] incubator-mynewt-core git commit: This closes #215.

Posted by an...@apache.org.
This closes #215.

Merge branch 'att' of https://github.com/sjanc/incubator-mynewt-core into master


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/95935c62
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/95935c62
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/95935c62

Branch: refs/heads/master
Commit: 95935c62cd936d6d0b056cf728bc32409f6a821a
Parents: e23872d dccf07d
Author: Andrzej Kaczmarek <an...@codecoup.pl>
Authored: Mon Apr 10 13:43:38 2017 +0200
Committer: Andrzej Kaczmarek <an...@codecoup.pl>
Committed: Mon Apr 10 13:43:38 2017 +0200

----------------------------------------------------------------------
 apps/bletest/src/bletest_hci.c              |   3 +-
 net/nimble/host/src/ble_att.c               |   3 +
 net/nimble/host/src/ble_att_clt.c           | 650 ++++++++---------------
 net/nimble/host/src/ble_att_cmd.c           | 310 ++++++-----
 net/nimble/host/src/ble_att_cmd_priv.h      |  52 +-
 net/nimble/host/src/ble_att_priv.h          |  51 +-
 net/nimble/host/src/ble_att_svr.c           | 601 +++++++++------------
 net/nimble/host/src/ble_gatt_priv.h         |   4 +-
 net/nimble/host/src/ble_gattc.c             | 184 +++----
 net/nimble/host/src/ble_hs_endian_priv.h    |  65 ---
 net/nimble/host/src/ble_hs_priv.h           |   1 -
 net/nimble/host/src/ble_l2cap_sig_cmd.c     |  22 +-
 net/nimble/host/src/ble_l2cap_sig_priv.h    |   4 -
 net/nimble/host/src/ble_sm.c                |   6 +-
 net/nimble/host/test/src/ble_att_clt_test.c |  67 +--
 15 files changed, 814 insertions(+), 1209 deletions(-)
----------------------------------------------------------------------



[05/50] incubator-mynewt-core git commit: nimble/att: Don't pass Writes Response as packed structure

Posted by an...@apache.org.
nimble/att: Don't pass Writes Response as packed structure

Use packed structure only for mapping it onto received mbuf. Data is
passed to upper layers in native form. This allows compiler to generate
more effective code with regards to unaligned access.


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

Branch: refs/heads/master
Commit: a63f7d30ca2f0128973b258d6592d49775f2fbd5
Parents: 4e0f1b9
Author: Szymon Janc <sz...@codecoup.pl>
Authored: Fri Mar 24 15:39:11 2017 +0100
Committer: Szymon Janc <sz...@codecoup.pl>
Committed: Mon Apr 10 11:31:31 2017 +0200

----------------------------------------------------------------------
 net/nimble/host/src/ble_att_clt.c   |  3 ++-
 net/nimble/host/src/ble_gatt_priv.h |  2 +-
 net/nimble/host/src/ble_gattc.c     | 25 +++++++++++++------------
 3 files changed, 16 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a63f7d30/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
index d34c096..cbd41c9 100644
--- a/net/nimble/host/src/ble_att_clt.c
+++ b/net/nimble/host/src/ble_att_clt.c
@@ -884,7 +884,8 @@ ble_att_clt_rx_prep_write(uint16_t conn_handle, struct os_mbuf **rxom)
 
 done:
     /* Notify GATT client that the full response has been parsed. */
-    ble_gattc_rx_prep_write_rsp(conn_handle, rc, &rsp, rxom);
+    ble_gattc_rx_prep_write_rsp(conn_handle, rc, rsp.bapc_handle,
+                                rsp.bapc_offset, rxom);
     return rc;
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a63f7d30/net/nimble/host/src/ble_gatt_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gatt_priv.h b/net/nimble/host/src/ble_gatt_priv.h
index ea06b33..2ed8170 100644
--- a/net/nimble/host/src/ble_gatt_priv.h
+++ b/net/nimble/host/src/ble_gatt_priv.h
@@ -126,7 +126,7 @@ void ble_gattc_rx_find_type_value_hinfo(
 void ble_gattc_rx_find_type_value_complete(uint16_t conn_handle, int status);
 void ble_gattc_rx_write_rsp(uint16_t conn_handle);
 void ble_gattc_rx_prep_write_rsp(uint16_t conn_handle, int status,
-                                 struct ble_att_prep_write_cmd *rsp,
+                                 uint16_t handle, uint16_t offset,
                                  struct os_mbuf **rxom);
 void ble_gattc_rx_exec_write_rsp(uint16_t conn_handle, int status);
 void ble_gattc_rx_indicate_rsp(uint16_t conn_handle);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a63f7d30/net/nimble/host/src/ble_gattc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gattc.c b/net/nimble/host/src/ble_gattc.c
index ca5d541..66344d8 100644
--- a/net/nimble/host/src/ble_gattc.c
+++ b/net/nimble/host/src/ble_gattc.c
@@ -335,7 +335,7 @@ typedef int ble_gattc_rx_adata_fn(struct ble_gattc_proc *proc,
                                   struct ble_att_read_type_adata *adata);
 
 typedef int ble_gattc_rx_prep_fn(struct ble_gattc_proc *proc, int status,
-                                 struct ble_att_prep_write_cmd *rsp,
+                                 uint16_t handle, uint16_t offset,
                                  struct os_mbuf **om);
 
 typedef int ble_gattc_rx_attr_fn(struct ble_gattc_proc *proc, int status,
@@ -3917,7 +3917,8 @@ ble_gattc_write_long_err(struct ble_gattc_proc *proc, int status,
  */
 static int
 ble_gattc_write_long_rx_prep(struct ble_gattc_proc *proc,
-                             int status, struct ble_att_prep_write_cmd *rsp,
+                             int status,
+                             uint16_t handle, uint16_t offset,
                              struct os_mbuf **rxom)
 {
     struct os_mbuf *om;
@@ -3943,15 +3944,15 @@ ble_gattc_write_long_rx_prep(struct ble_gattc_proc *proc,
         rc = BLE_HS_EBADDATA;
         goto err;
     }
-    if (rsp->bapc_handle != proc->write_long.attr.handle) {
+    if (handle != proc->write_long.attr.handle) {
         rc = BLE_HS_EBADDATA;
         goto err;
     }
-    if (rsp->bapc_offset != proc->write_long.attr.offset) {
+    if (offset != proc->write_long.attr.offset) {
         rc = BLE_HS_EBADDATA;
         goto err;
     }
-    if (rsp->bapc_offset + OS_MBUF_PKTLEN(om) >
+    if (offset + OS_MBUF_PKTLEN(om) >
         OS_MBUF_PKTLEN(proc->write_long.attr.om)) {
 
         rc = BLE_HS_EBADDATA;
@@ -3962,7 +3963,7 @@ ble_gattc_write_long_rx_prep(struct ble_gattc_proc *proc,
         goto err;
     }
     if (os_mbuf_cmpm(om, 0,
-                     proc->write_long.attr.om, rsp->bapc_offset,
+                     proc->write_long.attr.om, offset,
                      proc->write_long.length) != 0) {
 
         rc = BLE_HS_EBADDATA;
@@ -4225,7 +4226,7 @@ ble_gattc_write_reliable_err(struct ble_gattc_proc *proc, int status,
 static int
 ble_gattc_write_reliable_rx_prep(struct ble_gattc_proc *proc,
                                  int status,
-                                 struct ble_att_prep_write_cmd *rsp,
+                                 uint16_t handle, uint16_t offset,
                                  struct os_mbuf **rxom)
 {
     struct ble_gatt_attr *attr;
@@ -4252,15 +4253,15 @@ ble_gattc_write_reliable_rx_prep(struct ble_gattc_proc *proc,
     attr = proc->write_reliable.attrs + proc->write_reliable.cur_attr;
 
     /* Verify the response. */
-    if (rsp->bapc_handle != attr->handle) {
+    if (handle != attr->handle) {
         rc = BLE_HS_EBADDATA;
         goto err;
     }
-    if (rsp->bapc_offset != attr->offset) {
+    if (offset != attr->offset) {
         rc = BLE_HS_EBADDATA;
         goto err;
     }
-    if (os_mbuf_cmpm(attr->om, rsp->bapc_offset, om, 0,
+    if (os_mbuf_cmpm(attr->om, offset, om, 0,
                      proc->write_reliable.length) != 0) {
 
         rc = BLE_HS_EBADDATA;
@@ -4958,7 +4959,7 @@ ble_gattc_rx_write_rsp(uint16_t conn_handle)
  */
 void
 ble_gattc_rx_prep_write_rsp(uint16_t conn_handle, int status,
-                            struct ble_att_prep_write_cmd *rsp,
+                            uint16_t handle, uint16_t offset,
                             struct os_mbuf **om)
 {
 #if !NIMBLE_BLE_ATT_CLT_PREP_WRITE
@@ -4973,7 +4974,7 @@ ble_gattc_rx_prep_write_rsp(uint16_t conn_handle, int status,
                                          ble_gattc_rx_prep_entries,
                                          &rx_entry);
     if (proc != NULL) {
-        rc = rx_entry->cb(proc, status, rsp, om);
+        rc = rx_entry->cb(proc, status, handle, offset, om);
         ble_gattc_process_status(proc, rc);
     }
 }


[22/50] incubator-mynewt-core git commit: nimble/att: Use packed struct for receiving Find Information Request

Posted by an...@apache.org.
nimble/att: Use packed struct for receiving Find Information Request

Use packed structure to map it to received mbuf instead of using
dedicated parsing function. Modern compilers generate effective code
in such case anyway.


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

Branch: refs/heads/master
Commit: fefbc8198c5ef807c19c732939ee63aa91a7c869
Parents: 1a6ebaa
Author: Szymon Janc <sz...@codecoup.pl>
Authored: Fri Mar 24 15:48:26 2017 +0100
Committer: Szymon Janc <sz...@codecoup.pl>
Committed: Mon Apr 10 11:31:32 2017 +0200

----------------------------------------------------------------------
 net/nimble/host/src/ble_att_svr.c | 55 ++++++++++++++++++----------------
 1 file changed, 30 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/fefbc819/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
index cf6160c..52d54b6 100644
--- a/net/nimble/host/src/ble_att_svr.c
+++ b/net/nimble/host/src/ble_att_svr.c
@@ -797,8 +797,8 @@ done:
  * @return                      0 on success; nonzero 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)
+ble_att_svr_fill_info(uint16_t start_handle, uint16_t end_handle,
+                      struct os_mbuf *om, uint16_t mtu, uint8_t *format)
 {
     struct ble_att_svr_entry *ha;
     uint8_t *buf;
@@ -811,11 +811,11 @@ ble_att_svr_fill_info(struct ble_att_find_info_req *req, struct os_mbuf *om,
     rc = 0;
 
     STAILQ_FOREACH(ha, &ble_att_svr_list, ha_next) {
-        if (ha->ha_handle_id > req->bafq_end_handle) {
+        if (ha->ha_handle_id > end_handle) {
             rc = 0;
             goto done;
         }
-        if (ha->ha_handle_id >= req->bafq_start_handle) {
+        if (ha->ha_handle_id >= start_handle) {
             if (ha->ha_uuid->type == BLE_UUID_TYPE_16) {
                 if (*format == 0) {
                     *format = BLE_ATT_FIND_INFO_RSP_FORMAT_16BIT;
@@ -864,15 +864,14 @@ done:
 
 static int
 ble_att_svr_build_find_info_rsp(uint16_t conn_handle,
-                                struct ble_att_find_info_req *req,
+                                uint16_t start_handle, uint16_t end_handle,
                                 struct os_mbuf **rxom,
                                 struct os_mbuf **out_txom,
                                 uint8_t *att_err)
 {
-    struct ble_att_find_info_rsp rsp;
+    struct ble_att_find_info_rsp *rsp;
     struct os_mbuf *txom;
     uint16_t mtu;
-    void *buf;
     int rc;
 
     /* Just reuse the request buffer for the response. */
@@ -883,20 +882,19 @@ ble_att_svr_build_find_info_rsp(uint16_t conn_handle,
     /* 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_BASE_SZ);
-    if (buf == NULL) {
+    rsp = ble_att_cmd_prepare(BLE_ATT_OP_FIND_INFO_RSP, sizeof(*rsp), txom);
+    if (rsp == NULL) {
         *att_err = BLE_ATT_ERR_INSUFFICIENT_RES;
         rc = BLE_HS_ENOMEM;
         goto done;
     }
 
-    ble_att_find_info_rsp_write(buf, BLE_ATT_FIND_INFO_RSP_BASE_SZ, &rsp);
-
     /* Write the variable length Information Data field, populating the format
      * field as appropriate.
      */
     mtu = ble_att_mtu(conn_handle);
-    rc = ble_att_svr_fill_info(req, txom, mtu, txom->om_data + 1);
+    rc = ble_att_svr_fill_info(start_handle, end_handle, txom, mtu,
+                               &rsp->bafp_format);
     if (rc != 0) {
         *att_err = BLE_ATT_ERR_ATTR_NOT_FOUND;
         rc = BLE_HS_ENOENT;
@@ -904,7 +902,7 @@ ble_att_svr_build_find_info_rsp(uint16_t conn_handle,
     }
 
     BLE_ATT_LOG_CMD(1, "find info rsp", conn_handle, ble_att_find_info_rsp_log,
-                    &rsp);
+                    rsp);
 
     rc = 0;
 
@@ -920,43 +918,50 @@ ble_att_svr_rx_find_info(uint16_t conn_handle, struct os_mbuf **rxom)
     return BLE_HS_ENOTSUP;
 #endif
 
-    struct ble_att_find_info_req req;
+    struct ble_att_find_info_req *req;
     struct os_mbuf *txom;
-    uint16_t err_handle;
+    uint16_t err_handle, start_handle, end_handle;
     uint8_t att_err;
     int rc;
 
+    /* TODO move this to common part
+     * Strip L2CAP ATT header from the front of the mbuf.
+     */
+    os_mbuf_adj(*rxom, 1);
+
     /* Initialize some values in case of early error. */
     txom = NULL;
     att_err = 0;
     err_handle = 0;
 
-    rc = ble_att_svr_pullup_req_base(rxom, BLE_ATT_FIND_INFO_REQ_SZ, &att_err);
+    rc = ble_att_svr_pullup_req_base(rxom, sizeof(*req), &att_err);
     if (rc != 0) {
         err_handle = 0;
         goto done;
     }
 
-    ble_att_find_info_req_parse((*rxom)->om_data, (*rxom)->om_len, &req);
+    req = (struct ble_att_find_info_req *)(*rxom)->om_data;
+    start_handle = le16toh(req->bafq_start_handle);
+    end_handle = le16toh(req->bafq_end_handle);
+
     BLE_ATT_LOG_CMD(0, "find info req", conn_handle, ble_att_find_info_req_log,
-                    &req);
+                    req);
 
     /* 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.bafq_start_handle > req.bafq_end_handle ||
-        req.bafq_start_handle == 0) {
-
+    if (start_handle > end_handle || start_handle == 0) {
         att_err = BLE_ATT_ERR_INVALID_HANDLE;
-        err_handle = req.bafq_start_handle;
+        err_handle = start_handle;
         rc = BLE_HS_EBADDATA;
         goto done;
     }
 
-    rc = ble_att_svr_build_find_info_rsp(conn_handle, &req, rxom, &txom,
-                                         &att_err);
+    rc = ble_att_svr_build_find_info_rsp(conn_handle,
+                                        start_handle, end_handle,
+                                        rxom, &txom, &att_err);
     if (rc != 0) {
-        err_handle = req.bafq_start_handle;
+        err_handle = start_handle;
         goto done;
     }
 


[23/50] incubator-mynewt-core git commit: nimble/att: Fix no responding with error for invalid data

Posted by an...@apache.org.
nimble/att: Fix no responding with error for invalid data

We should always responde to avoid stalling ATT channel.


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

Branch: refs/heads/master
Commit: f6800fc7e083c392fb50c05637714dfe7cff29a2
Parents: 1e81657
Author: Szymon Janc <sz...@codecoup.pl>
Authored: Fri Mar 24 15:50:02 2017 +0100
Committer: Szymon Janc <sz...@codecoup.pl>
Committed: Mon Apr 10 11:31:32 2017 +0200

----------------------------------------------------------------------
 net/nimble/host/src/ble_att_svr.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f6800fc7/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
index 022a0fb..8a6acc3 100644
--- a/net/nimble/host/src/ble_att_svr.c
+++ b/net/nimble/host/src/ble_att_svr.c
@@ -1431,7 +1431,8 @@ ble_att_svr_rx_read_type(uint16_t conn_handle, struct os_mbuf **rxom)
         pktlen != BLE_ATT_READ_TYPE_REQ_SZ_128) {
 
         /* Malformed packet; discard. */
-        return BLE_HS_EBADDATA;
+        rc = BLE_HS_EBADDATA;
+        goto done;
     }
 
     rc = ble_att_svr_pullup_req_base(rxom, pktlen, &att_err);


[21/50] incubator-mynewt-core git commit: nimble/att: Use packed struct for receiving Find Information Response

Posted by an...@apache.org.
nimble/att: Use packed struct for receiving Find Information Response

Use packed structure to map it to received mbuf instead of using
dedicated parsing function. Modern compilers generate effective code
in such case anyway.


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

Branch: refs/heads/master
Commit: fe97914df0e8a0c497a3f737754d8873e8399959
Parents: a31e34b
Author: Szymon Janc <sz...@codecoup.pl>
Authored: Fri Mar 24 15:47:10 2017 +0100
Committer: Szymon Janc <sz...@codecoup.pl>
Committed: Mon Apr 10 11:31:32 2017 +0200

----------------------------------------------------------------------
 net/nimble/host/src/ble_att_clt.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/fe97914d/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
index 1d45ef0..4644b35 100644
--- a/net/nimble/host/src/ble_att_clt.c
+++ b/net/nimble/host/src/ble_att_clt.c
@@ -247,23 +247,29 @@ ble_att_clt_rx_find_info(uint16_t conn_handle, struct os_mbuf **om)
 #endif
 
     struct ble_att_find_info_idata idata;
-    struct ble_att_find_info_rsp rsp;
+    struct ble_att_find_info_rsp *rsp;
     int rc;
 
-    rc = ble_hs_mbuf_pullup_base(om, BLE_ATT_FIND_INFO_RSP_BASE_SZ);
+    /* TODO move this to common part
+     * Strip L2CAP ATT header from the front of the mbuf.
+     */
+    os_mbuf_adj(*om, 1);
+
+    rc = ble_hs_mbuf_pullup_base(om, sizeof(*rsp));
     if (rc != 0) {
         goto done;
     }
 
-    ble_att_find_info_rsp_parse((*om)->om_data, (*om)->om_len, &rsp);
+    rsp = (struct ble_att_find_info_rsp *)(*om)->om_data;
+
     BLE_ATT_LOG_CMD(0, "find info rsp", conn_handle, ble_att_find_info_rsp_log,
-                    &rsp);
+                    rsp);
 
     /* Strip the response base from the front of the mbuf. */
-    os_mbuf_adj((*om), BLE_ATT_FIND_INFO_RSP_BASE_SZ);
+    os_mbuf_adj((*om), sizeof(*rsp));
 
     while (OS_MBUF_PKTLEN(*om) > 0) {
-        rc = ble_att_clt_parse_find_info_entry(om, rsp.bafp_format, &idata);
+        rc = ble_att_clt_parse_find_info_entry(om, rsp->bafp_format, &idata);
         if (rc != 0) {
             goto done;
         }


[29/50] incubator-mynewt-core git commit: nimble/att: Use packed struct for receiving Read Multiple Request

Posted by an...@apache.org.
nimble/att: Use packed struct for receiving Read Multiple Request

Use packed structure to map it to received mbuf instead of using
dedicated parsing function. Modern compilers generate effective code
in such case anyway.


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

Branch: refs/heads/master
Commit: d7da6aa8ceff9e18ffda5cc7eee2f407a19b6110
Parents: ac38eb7
Author: Szymon Janc <sz...@codecoup.pl>
Authored: Fri Mar 24 15:50:05 2017 +0100
Committer: Szymon Janc <sz...@codecoup.pl>
Committed: Mon Apr 10 11:31:32 2017 +0200

----------------------------------------------------------------------
 net/nimble/host/src/ble_att_svr.c | 33 ++++++++-------------------------
 1 file changed, 8 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d7da6aa8/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
index 65f3501..f3e4bec 100644
--- a/net/nimble/host/src/ble_att_svr.c
+++ b/net/nimble/host/src/ble_att_svr.c
@@ -1612,7 +1612,6 @@ ble_att_svr_build_read_mult_rsp(uint16_t conn_handle,
     struct os_mbuf *txom;
     uint16_t handle;
     uint16_t mtu;
-    uint8_t *dptr;
     int rc;
 
     mtu = ble_att_mtu(conn_handle);
@@ -1623,14 +1622,12 @@ ble_att_svr_build_read_mult_rsp(uint16_t conn_handle,
         goto done;
     }
 
-    dptr = os_mbuf_extend(txom, BLE_ATT_READ_MULT_RSP_BASE_SZ);
-    if (dptr == NULL) {
+    if (ble_att_cmd_prepare(BLE_ATT_OP_READ_MULT_RSP, 0, txom) == NULL) {
         *att_err = BLE_ATT_ERR_INSUFFICIENT_RES;
         *err_handle = 0;
         rc = BLE_HS_ENOMEM;
         goto done;
     }
-    ble_att_read_mult_rsp_write(dptr, BLE_ATT_READ_MULT_RSP_BASE_SZ);
 
     /* Iterate through requested handles, reading the corresponding attribute
      * for each.  Stop when there are no more handles to process, or the
@@ -1679,6 +1676,11 @@ ble_att_svr_rx_read_mult(uint16_t conn_handle, struct os_mbuf **rxom)
     uint8_t att_err;
     int rc;
 
+    /* TODO move this to common part
+     * Strip L2CAP ATT header from the front of the mbuf.
+     */
+    os_mbuf_adj(*rxom, 1);
+
     BLE_ATT_LOG_EMPTY_CMD(0, "read mult req", conn_handle);
 
     /* Initialize some values in case of early error. */
@@ -1686,30 +1688,11 @@ ble_att_svr_rx_read_mult(uint16_t conn_handle, struct os_mbuf **rxom)
     err_handle = 0;
     att_err = 0;
 
-    rc = ble_att_svr_pullup_req_base(rxom, BLE_ATT_READ_MULT_REQ_BASE_SZ,
-                                     &att_err);
-    if (rc != 0) {
-        err_handle = 0;
-        goto done;
-    }
-
-    ble_att_read_mult_req_parse((*rxom)->om_data, (*rxom)->om_len);
-
-    /* Strip opcode from request. */
-    os_mbuf_adj(*rxom, BLE_ATT_READ_MULT_REQ_BASE_SZ);
-
     rc = ble_att_svr_build_read_mult_rsp(conn_handle, rxom, &txom, &att_err,
                                          &err_handle);
-    if (rc != 0) {
-        goto done;
-    }
 
-    rc = 0;
-
-done:
-    rc = ble_att_svr_tx_rsp(conn_handle, rc, txom, BLE_ATT_OP_READ_MULT_REQ,
-                            att_err, err_handle);
-    return rc;
+    return ble_att_svr_tx_rsp(conn_handle, rc, txom, BLE_ATT_OP_READ_MULT_REQ,
+                              att_err, err_handle);
 }
 
 static int


[11/50] incubator-mynewt-core git commit: nimble/att: Use new helpers for sending Find By Type Value Request

Posted by an...@apache.org.
nimble/att: Use new helpers for sending Find By Type Value Request

This constructs response directly on mbuf reducing number of memcopies.
read


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/191acab7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/191acab7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/191acab7

Branch: refs/heads/master
Commit: 191acab73c9c77c157a806d8871b653f3c64cbc9
Parents: 5e82b3f
Author: Szymon Janc <sz...@codecoup.pl>
Authored: Fri Mar 24 15:33:07 2017 +0100
Committer: Szymon Janc <sz...@codecoup.pl>
Committed: Mon Apr 10 11:31:31 2017 +0200

----------------------------------------------------------------------
 net/nimble/host/src/ble_att_clt.c      | 48 +++++++++++------------------
 net/nimble/host/src/ble_att_cmd_priv.h |  1 +
 net/nimble/host/src/ble_att_priv.h     |  6 ++--
 net/nimble/host/src/ble_gattc.c        | 10 +++---
 4 files changed, 26 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/191acab7/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
index f72b209..0464821 100644
--- a/net/nimble/host/src/ble_att_clt.c
+++ b/net/nimble/host/src/ble_att_clt.c
@@ -333,53 +333,41 @@ done:
  * $find by type value                                                       *
  *****************************************************************************/
 
+/*
+ * TODO consider this to accept UUID instead of value, it is used only for this
+ * anyway
+ */
 int
-ble_att_clt_tx_find_type_value(uint16_t conn_handle,
-                               const struct ble_att_find_type_value_req *req,
+ble_att_clt_tx_find_type_value(uint16_t conn_handle, uint16_t start_handle,
+                               uint16_t end_handle, uint16_t attribute_type,
                                const void *attribute_value, int value_len)
 {
 #if !NIMBLE_BLE_ATT_CLT_FIND_TYPE
     return BLE_HS_ENOTSUP;
 #endif
 
+    struct ble_att_find_type_value_req *req;
     struct os_mbuf *txom;
-    int rc;
-
-    txom = NULL;
-
-    if (req->bavq_start_handle == 0 ||
-        req->bavq_start_handle > req->bavq_end_handle) {
-
-        rc = BLE_HS_EINVAL;
-        goto err;
-    }
 
-    rc = ble_att_clt_init_req(BLE_ATT_FIND_TYPE_VALUE_REQ_BASE_SZ, &txom);
-    if (rc != 0) {
-        goto err;
+    if (start_handle == 0 || start_handle > end_handle) {
+        return BLE_HS_EINVAL;
     }
 
-    ble_att_find_type_value_req_write(txom->om_data, txom->om_len, req);
-    rc = os_mbuf_append(txom, attribute_value, value_len);
-    if (rc != 0) {
-        rc = BLE_HS_ENOMEM;
-        goto err;
+    req = ble_att_cmd_get(BLE_ATT_OP_FIND_INFO_REQ, sizeof(*req) + value_len,
+                          &txom);
+    if (req == NULL) {
+        return BLE_HS_ENOMEM;
     }
 
-    rc = ble_att_clt_tx_req(conn_handle, txom);
-    txom = NULL;
-    if (rc != 0) {
-        goto err;
-    }
+    req->bavq_start_handle = htole16(start_handle);
+    req->bavq_end_handle = htole16(end_handle);
+    req->bavq_attr_type = htole16(attribute_type);
+    memcpy(req->bavq_value, attribute_value, value_len);
 
     BLE_ATT_LOG_CMD(1, "find type value req", conn_handle,
                     ble_att_find_type_value_req_log, req);
 
-    return 0;
-
-err:
-    os_mbuf_free_chain(txom);
-    return rc;
+    return ble_att_tx(conn_handle, txom);
 }
 
 static int

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/191acab7/net/nimble/host/src/ble_att_cmd_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_cmd_priv.h b/net/nimble/host/src/ble_att_cmd_priv.h
index d1c7d33..80fe713 100644
--- a/net/nimble/host/src/ble_att_cmd_priv.h
+++ b/net/nimble/host/src/ble_att_cmd_priv.h
@@ -105,6 +105,7 @@ struct ble_att_find_type_value_req {
     uint16_t bavq_start_handle;
     uint16_t bavq_end_handle;
     uint16_t bavq_attr_type;
+    uint16_t bavq_value[0];
 } __attribute__((packed));
 
 /**

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/191acab7/net/nimble/host/src/ble_att_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_priv.h b/net/nimble/host/src/ble_att_priv.h
index 86a7b76..a51f7cc 100644
--- a/net/nimble/host/src/ble_att_priv.h
+++ b/net/nimble/host/src/ble_att_priv.h
@@ -271,9 +271,9 @@ int ble_att_clt_rx_read_group_type(uint16_t conn_handle,
 int ble_att_clt_tx_find_info(uint16_t conn_handle, uint16_t start_handle,
                              uint16_t end_handle);
 int ble_att_clt_rx_find_info(uint16_t conn_handle, struct os_mbuf **rxom);
-int ble_att_clt_tx_find_type_value(
-    uint16_t conn_handle, const struct ble_att_find_type_value_req *req,
-    const void *attribute_value, int value_len);
+int ble_att_clt_tx_find_type_value(uint16_t conn_handle, uint16_t start_handle,
+                                   uint16_t end_handle, uint16_t attribute_type,
+                                   const void *attribute_value, int value_len);
 int ble_att_clt_rx_find_type_value(uint16_t conn_handle,
                                    struct os_mbuf **rxom);
 int ble_att_clt_tx_write_req(uint16_t conn_handle,

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/191acab7/net/nimble/host/src/ble_gattc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gattc.c b/net/nimble/host/src/ble_gattc.c
index 99d2e83..6aa8bb1 100644
--- a/net/nimble/host/src/ble_gattc.c
+++ b/net/nimble/host/src/ble_gattc.c
@@ -1619,18 +1619,16 @@ ble_gattc_disc_svc_uuid_tmo(struct ble_gattc_proc *proc)
 static int
 ble_gattc_disc_svc_uuid_tx(struct ble_gattc_proc *proc)
 {
-    struct ble_att_find_type_value_req req;
     uint8_t val[16];
     int rc;
 
     ble_gattc_dbg_assert_proc_not_inserted(proc);
 
-    req.bavq_start_handle = proc->disc_svc_uuid.prev_handle + 1;
-    req.bavq_end_handle = 0xffff;
-    req.bavq_attr_type = BLE_ATT_UUID_PRIMARY_SERVICE;
-
     ble_uuid_flat(&proc->disc_svc_uuid.service_uuid.u, val);
-    rc = ble_att_clt_tx_find_type_value(proc->conn_handle, &req, val,
+    rc = ble_att_clt_tx_find_type_value(proc->conn_handle,
+                                        proc->disc_svc_uuid.prev_handle + 1,
+                                        0xffff, BLE_ATT_UUID_PRIMARY_SERVICE,
+                                        val,
                                         ble_uuid_length(&proc->disc_svc_uuid.service_uuid.u));
     if (rc != 0) {
         return rc;


[43/50] incubator-mynewt-core git commit: nimble: Remove ble_hs_endian_priv.h API

Posted by an...@apache.org.
nimble: Remove ble_hs_endian_priv.h API

This API is no longer used and so/endian.h should be used instead.


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

Branch: refs/heads/master
Commit: dccf07dc4cb7fae81c6942b135f6a67cfa03a631
Parents: 82674a0
Author: Szymon Janc <sz...@codecoup.pl>
Authored: Fri Mar 24 15:50:10 2017 +0100
Committer: Szymon Janc <sz...@codecoup.pl>
Committed: Mon Apr 10 11:31:33 2017 +0200

----------------------------------------------------------------------
 net/nimble/host/src/ble_hs_endian_priv.h | 65 ---------------------------
 net/nimble/host/src/ble_hs_priv.h        |  1 -
 2 files changed, 66 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/dccf07dc/net/nimble/host/src/ble_hs_endian_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_endian_priv.h b/net/nimble/host/src/ble_hs_endian_priv.h
deleted file mode 100644
index 79a702f..0000000
--- a/net/nimble/host/src/ble_hs_endian_priv.h
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- * 
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-#ifndef H_BLE_HS_ENDIAN_
-#define H_BLE_HS_ENDIAN_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
-
-#define TOFROMLE16(x)   ((uint16_t) (x))
-#define TOFROMLE32(x)   ((uint32_t) (x))
-#define TOFROMLE64(x)   ((uint64_t) (x))
-
-#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
-
-#define TOFROMLE16(x)   ((uint16_t)                                 \
-                         ((((x) & 0xff00) >> 8) |                   \
-                          (((x) & 0x00ff) << 8)))
-
-#define TOFROMLE32(x)  ((uint32_t)                                  \
-                         ((((x) & 0xff000000) >> 24) |              \
-                          (((x) & 0x00ff0000) >>  8) |              \
-                          (((x) & 0x0000ff00) <<  8) |              \
-                          (((x) & 0x000000ff) << 24)))
-
-#define TOFROMLE64(x)  ((uint64_t)                                  \
-                         ((((x) & 0xff00000000000000ull) >> 56) |   \
-                          (((x) & 0x00ff000000000000ull) >> 40) |   \
-                          (((x) & 0x0000ff0000000000ull) >> 24) |   \
-                          (((x) & 0x000000ff00000000ull) >>  8) |   \
-                          (((x) & 0x00000000ff000000ull) <<  8) |   \
-                          (((x) & 0x0000000000ff0000ull) << 24) |   \
-                          (((x) & 0x000000000000ff00ull) << 40) |   \
-                          (((x) & 0x00000000000000ffull) << 56)))
-
-#else
-
-#error Unsupported endianness.
-
-#endif
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/dccf07dc/net/nimble/host/src/ble_hs_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_priv.h b/net/nimble/host/src/ble_hs_priv.h
index 4bdb22c..baac103 100644
--- a/net/nimble/host/src/ble_hs_priv.h
+++ b/net/nimble/host/src/ble_hs_priv.h
@@ -32,7 +32,6 @@
 #include "ble_hs_atomic_priv.h"
 #include "ble_hs_conn_priv.h"
 #include "ble_hs_atomic_priv.h"
-#include "ble_hs_endian_priv.h"
 #include "ble_hs_mbuf_priv.h"
 #include "ble_hs_startup_priv.h"
 #include "ble_l2cap_priv.h"


[28/50] incubator-mynewt-core git commit: nimble/att: Use packed struct for receiving Read Blob Request

Posted by an...@apache.org.
nimble/att: Use packed struct for receiving Read Blob Request

Use packed structure to map it to received mbuf instead of using
dedicated parsing function. Modern compilers generate effective code
in such case anyway.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/9c897e5c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/9c897e5c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/9c897e5c

Branch: refs/heads/master
Commit: 9c897e5cc99bfe7adc2857e729bafec41fdccdac
Parents: 3b25076
Author: Szymon Janc <sz...@codecoup.pl>
Authored: Fri Mar 24 15:50:04 2017 +0100
Committer: Szymon Janc <sz...@codecoup.pl>
Committed: Mon Apr 10 11:31:32 2017 +0200

----------------------------------------------------------------------
 net/nimble/host/src/ble_att_svr.c | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9c897e5c/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
index f5d39ce..65f3501 100644
--- a/net/nimble/host/src/ble_att_svr.c
+++ b/net/nimble/host/src/ble_att_svr.c
@@ -1547,43 +1547,46 @@ ble_att_svr_rx_read_blob(uint16_t conn_handle, struct os_mbuf **rxom)
     return BLE_HS_ENOTSUP;
 #endif
 
-    struct ble_att_read_blob_req req;
+    struct ble_att_read_blob_req *req;
     struct os_mbuf *txom;
-    uint16_t err_handle;
-    uint8_t *dptr;
+    uint16_t err_handle, offset;
     uint8_t att_err;
     int rc;
 
+    /* TODO move this to common part
+     * Strip L2CAP ATT header from the front of the mbuf.
+     */
+    os_mbuf_adj(*rxom, 1);
+
     /* Initialize some values in case of early error. */
     txom = NULL;
     att_err = 0;
     err_handle = 0;
 
-    rc = ble_att_svr_pullup_req_base(rxom, BLE_ATT_READ_BLOB_REQ_SZ, &att_err);
+    rc = ble_att_svr_pullup_req_base(rxom, sizeof(*req), &att_err);
     if (rc != 0) {
         goto done;
     }
 
-    ble_att_read_blob_req_parse((*rxom)->om_data, (*rxom)->om_len, &req);
+    req = (struct ble_att_read_blob_req *)(*rxom)->om_data;
     BLE_ATT_LOG_CMD(0, "read blob req", conn_handle, ble_att_read_blob_req_log,
-                    &req);
+                    req);
 
-    err_handle = req.babq_handle;
+    err_handle = le16toh(req->babq_handle);
+    offset = le16toh(req->babq_offset);
 
     /* Just reuse the request buffer for the response. */
     txom = *rxom;
     *rxom = NULL;
     os_mbuf_adj(txom, OS_MBUF_PKTLEN(txom));
 
-    dptr = os_mbuf_extend(txom, 1);
-    if (dptr == NULL) {
+    if (ble_att_cmd_prepare(BLE_ATT_OP_READ_BLOB_RSP, 0, txom) == NULL) {
         att_err = BLE_ATT_ERR_INSUFFICIENT_RES;
         rc = BLE_HS_ENOMEM;
         goto done;
     }
-    *dptr = BLE_ATT_OP_READ_BLOB_RSP;
 
-    rc = ble_att_svr_read_handle(conn_handle, req.babq_handle, req.babq_offset,
+    rc = ble_att_svr_read_handle(conn_handle, err_handle, offset,
                                  txom, &att_err);
     if (rc != 0) {
         goto done;


[06/50] incubator-mynewt-core git commit: nimble/att: Use new helpers for sending Write Request and Command

Posted by an...@apache.org.
nimble/att: Use new helpers for sending Write Request and Command

This constructs response directly on mbuf reducing number of memcopies.


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

Branch: refs/heads/master
Commit: a9549fdbc17383c00851dde7bd555cf628d3876b
Parents: 191acab
Author: Szymon Janc <sz...@codecoup.pl>
Authored: Fri Mar 24 15:34:01 2017 +0100
Committer: Szymon Janc <sz...@codecoup.pl>
Committed: Mon Apr 10 11:31:31 2017 +0200

----------------------------------------------------------------------
 net/nimble/host/src/ble_att_clt.c           | 65 +++++++++---------------
 net/nimble/host/src/ble_att_cmd.c           | 10 +++-
 net/nimble/host/src/ble_att_cmd_priv.h      | 17 ++++++-
 net/nimble/host/src/ble_att_priv.h          |  6 +--
 net/nimble/host/src/ble_att_svr.c           |  4 +-
 net/nimble/host/src/ble_gattc.c             |  8 +--
 net/nimble/host/test/src/ble_att_clt_test.c | 14 ++---
 7 files changed, 59 insertions(+), 65 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a9549fdb/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
index 0464821..114abea 100644
--- a/net/nimble/host/src/ble_att_clt.c
+++ b/net/nimble/host/src/ble_att_clt.c
@@ -789,62 +789,41 @@ done:
  * $write                                                                    *
  *****************************************************************************/
 
-static int
-ble_att_clt_tx_write_req_or_cmd(uint16_t conn_handle,
-                                const struct ble_att_write_req *req,
-                                struct os_mbuf *txom, int is_req)
-{
-    int rc;
-
-    txom = os_mbuf_prepend_pullup(txom, BLE_ATT_WRITE_REQ_BASE_SZ);
-    if (txom == NULL) {
-        return BLE_HS_ENOMEM;
-    }
-
-    if (is_req) {
-        ble_att_write_req_write(txom->om_data, BLE_ATT_WRITE_REQ_BASE_SZ, req);
-    } else {
-        ble_att_write_cmd_write(txom->om_data, BLE_ATT_WRITE_REQ_BASE_SZ, req);
-    }
-
-    rc = ble_att_clt_tx_req(conn_handle, txom);
-    if (rc != 0) {
-        return rc;
-    }
-
-    return 0;
-}
-
 int
-ble_att_clt_tx_write_req(uint16_t conn_handle,
-                         const struct ble_att_write_req *req,
+ble_att_clt_tx_write_req(uint16_t conn_handle, uint16_t handle,
                          struct os_mbuf *txom)
 {
 #if !NIMBLE_BLE_ATT_CLT_WRITE
     return BLE_HS_ENOTSUP;
 #endif
 
-    int rc;
+    struct ble_att_write_req *req;
+    struct os_mbuf *txom2;
 
-    rc = ble_att_clt_tx_write_req_or_cmd(conn_handle, req, txom, 1);
-    if (rc != 0) {
-        return rc;
+    req = ble_att_cmd_get(BLE_ATT_OP_WRITE_REQ, sizeof(*req), &txom2);
+    if (req == NULL) {
+        os_mbuf_free_chain(txom);
+        return BLE_HS_ENOMEM;
     }
 
-    BLE_ATT_LOG_CMD(1, "write req", conn_handle, ble_att_write_cmd_log, req);
+    req->bawq_handle = htole16(handle);
+    os_mbuf_concat(txom2, txom);
 
-    return 0;
+    BLE_ATT_LOG_CMD(1, "write req", conn_handle, ble_att_write_req_log, req);
+
+    return ble_att_tx(conn_handle, txom2);
 }
 
 int
-ble_att_clt_tx_write_cmd(uint16_t conn_handle,
-                         const struct ble_att_write_req *req,
+ble_att_clt_tx_write_cmd(uint16_t conn_handle, uint16_t handle,
                          struct os_mbuf *txom)
 {
 #if !NIMBLE_BLE_ATT_CLT_WRITE_NO_RSP
     return BLE_HS_ENOTSUP;
 #endif
 
+    struct ble_att_write_cmd *cmd;
+    struct os_mbuf *txom2;
     uint8_t b;
     int rc;
     int i;
@@ -860,14 +839,18 @@ ble_att_clt_tx_write_cmd(uint16_t conn_handle,
     }
     
 
-    rc = ble_att_clt_tx_write_req_or_cmd(conn_handle, req, txom, 0);
-    if (rc != 0) {
-        return rc;
+    cmd = ble_att_cmd_get(BLE_ATT_OP_WRITE_CMD, sizeof(*cmd), &txom2);
+    if (cmd == NULL) {
+        os_mbuf_free_chain(txom);
+        return BLE_HS_ENOMEM;
     }
 
-    BLE_ATT_LOG_CMD(1, "write cmd", conn_handle, ble_att_write_cmd_log, req);
+    cmd->handle = htole16(handle);
+    os_mbuf_concat(txom2, txom);
 
-    return 0;
+    BLE_ATT_LOG_CMD(1, "write cmd", conn_handle, ble_att_write_cmd_log, cmd);
+
+    return ble_att_tx(conn_handle, txom2);
 }
 
 int

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a9549fdb/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
index 7997ff1..9fb81d1 100644
--- a/net/nimble/host/src/ble_att_cmd.c
+++ b/net/nimble/host/src/ble_att_cmd.c
@@ -610,9 +610,15 @@ ble_att_write_cmd_write(void *payload, int len,
 }
 
 void
-ble_att_write_cmd_log(const struct ble_att_write_req *cmd)
+ble_att_write_cmd_log(const struct ble_att_write_cmd *cmd)
 {
-    BLE_HS_LOG(DEBUG, "handle=0x%04x", cmd->bawq_handle);
+    BLE_HS_LOG(DEBUG, "handle=0x%04x", cmd->handle);
+}
+
+void
+ble_att_write_req_log(const struct ble_att_write_req *req)
+{
+    BLE_HS_LOG(DEBUG, "handle=0x%04x", req->bawq_handle);
 }
 
 static void

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a9549fdb/net/nimble/host/src/ble_att_cmd_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_cmd_priv.h b/net/nimble/host/src/ble_att_cmd_priv.h
index 80fe713..491dc99 100644
--- a/net/nimble/host/src/ble_att_cmd_priv.h
+++ b/net/nimble/host/src/ble_att_cmd_priv.h
@@ -252,6 +252,7 @@ struct ble_att_read_group_type_rsp {
 #define BLE_ATT_WRITE_REQ_BASE_SZ       3
 struct ble_att_write_req {
     uint16_t bawq_handle;
+    uint8_t value[0];
 } __attribute__((packed));
 
 #define BLE_ATT_WRITE_RSP_SZ            1
@@ -322,6 +323,19 @@ struct ble_att_indicate_req {
  */
 #define BLE_ATT_INDICATE_RSP_SZ         1
 
+/**
+ * | Parameter                          | Size (octets)     |
+ * +------------------------------------+-------------------+
+ * | Attribute Opcode                   | 1                 |
+ * | Attribute Handle                   | 2                 |
+ * | Attribute Value                    | 0 to (ATT_MTU-3)  |
+ */
+#define BLE_ATT_WRITE_CMD_BASE_SZ       3
+struct ble_att_write_cmd {
+    uint16_t handle;
+    uint8_t value[0];
+} __attribute__((packed));
+
 void ble_att_error_rsp_parse(const void *payload, int len,
                              struct ble_att_error_rsp *rsp);
 void ble_att_error_rsp_write(void *payload, int len,
@@ -396,7 +410,8 @@ void ble_att_write_cmd_parse(const void *payload, int len,
                              struct ble_att_write_req *req);
 void ble_att_write_cmd_write(void *payload, int len,
                              const struct ble_att_write_req *req);
-void ble_att_write_cmd_log(const struct ble_att_write_req *cmd);
+void ble_att_write_cmd_log(const struct ble_att_write_cmd *cmd);
+void ble_att_write_req_log(const struct ble_att_write_req *req);
 void ble_att_prep_write_req_parse(const void *payload, int len,
                                   struct ble_att_prep_write_cmd *cmd);
 void ble_att_prep_write_req_write(void *payload, int len,

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a9549fdb/net/nimble/host/src/ble_att_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_priv.h b/net/nimble/host/src/ble_att_priv.h
index a51f7cc..b7def41 100644
--- a/net/nimble/host/src/ble_att_priv.h
+++ b/net/nimble/host/src/ble_att_priv.h
@@ -276,11 +276,9 @@ int ble_att_clt_tx_find_type_value(uint16_t conn_handle, uint16_t start_handle,
                                    const void *attribute_value, int value_len);
 int ble_att_clt_rx_find_type_value(uint16_t conn_handle,
                                    struct os_mbuf **rxom);
-int ble_att_clt_tx_write_req(uint16_t conn_handle,
-                             const struct ble_att_write_req *req,
+int ble_att_clt_tx_write_req(uint16_t conn_handle, uint16_t handle,
                              struct os_mbuf *txom);
-int ble_att_clt_tx_write_cmd(uint16_t conn_handle,
-                             const struct ble_att_write_req *req,
+int ble_att_clt_tx_write_cmd(uint16_t conn_handle, uint16_t handle,
                              struct os_mbuf *txom);
 int ble_att_clt_tx_prep_write(uint16_t conn_handle,
                               const struct ble_att_prep_write_cmd *req,

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a9549fdb/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
index ac6fa55..3aea795 100644
--- a/net/nimble/host/src/ble_att_svr.c
+++ b/net/nimble/host/src/ble_att_svr.c
@@ -2055,7 +2055,7 @@ ble_att_svr_rx_write(uint16_t conn_handle, struct os_mbuf **rxom)
 
     ble_att_write_req_parse((*rxom)->om_data, (*rxom)->om_len, &req);
     BLE_ATT_LOG_CMD(0, "write req", conn_handle,
-                    ble_att_write_cmd_log, &req);
+                    ble_att_write_req_log, &req);
 
     err_handle = req.bawq_handle;
 
@@ -2105,7 +2105,7 @@ ble_att_svr_rx_write_no_rsp(uint16_t conn_handle, struct os_mbuf **rxom)
 
     ble_att_write_cmd_parse((*rxom)->om_data, (*rxom)->om_len, &req);
     BLE_ATT_LOG_CMD(0, "write cmd", conn_handle,
-                    ble_att_write_cmd_log, &req);
+                    ble_att_write_req_log, &req);
 
     /* Strip the request base from the front of the mbuf. */
     os_mbuf_adj(*rxom, BLE_ATT_WRITE_REQ_BASE_SZ);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a9549fdb/net/nimble/host/src/ble_gattc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gattc.c b/net/nimble/host/src/ble_gattc.c
index 6aa8bb1..7e57433 100644
--- a/net/nimble/host/src/ble_gattc.c
+++ b/net/nimble/host/src/ble_gattc.c
@@ -3560,15 +3560,13 @@ ble_gattc_write_no_rsp(uint16_t conn_handle, uint16_t attr_handle,
     return BLE_HS_ENOTSUP;
 #endif
 
-    struct ble_att_write_req req;
     int rc;
 
     STATS_INC(ble_gattc_stats, write_no_rsp);
 
     ble_gattc_log_write(attr_handle, OS_MBUF_PKTLEN(txom), 0);
 
-    req.bawq_handle = attr_handle;
-    rc = ble_att_clt_tx_write_cmd(conn_handle, &req, txom);
+    rc = ble_att_clt_tx_write_cmd(conn_handle, attr_handle, txom);
     if (rc != 0) {
         STATS_INC(ble_gattc_stats, write);
     }
@@ -3692,7 +3690,6 @@ ble_gattc_write(uint16_t conn_handle, uint16_t attr_handle,
     return BLE_HS_ENOTSUP;
 #endif
 
-    struct ble_att_write_req req;
     struct ble_gattc_proc *proc;
     int rc;
 
@@ -3712,8 +3709,7 @@ ble_gattc_write(uint16_t conn_handle, uint16_t attr_handle,
 
     ble_gattc_log_write(attr_handle, OS_MBUF_PKTLEN(txom), 1);
 
-    req.bawq_handle = attr_handle;
-    rc = ble_att_clt_tx_write_req(conn_handle, &req, txom);
+    rc = ble_att_clt_tx_write_req(conn_handle, attr_handle, txom);
     txom = NULL;
     if (rc != 0) {
         goto done;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a9549fdb/net/nimble/host/test/src/ble_att_clt_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/test/src/ble_att_clt_test.c b/net/nimble/host/test/src/ble_att_clt_test.c
index dec4695..97a1a44 100644
--- a/net/nimble/host/test/src/ble_att_clt_test.c
+++ b/net/nimble/host/test/src/ble_att_clt_test.c
@@ -59,8 +59,7 @@ ble_att_clt_test_misc_verify_tx_write(uint16_t handle_id, void *value,
 }
 
 static void
-ble_att_clt_test_tx_write_req_or_cmd(uint16_t conn_handle,
-                                     struct ble_att_write_req *req,
+ble_att_clt_test_tx_write_req_or_cmd(uint16_t conn_handle, uint16_t handle,
                                      void *value, int value_len, int is_req)
 {
     struct os_mbuf *om;
@@ -68,9 +67,9 @@ ble_att_clt_test_tx_write_req_or_cmd(uint16_t conn_handle,
 
     om = ble_hs_test_util_om_from_flat(value, value_len);
     if (is_req) {
-        rc = ble_att_clt_tx_write_req(conn_handle, req, om);
+        rc = ble_att_clt_tx_write_req(conn_handle, handle, om);
     } else {
-        rc = ble_att_clt_tx_write_cmd(conn_handle, req, om);
+        rc = ble_att_clt_tx_write_cmd(conn_handle, handle, om);
     }
     TEST_ASSERT(rc == 0);
 }
@@ -167,7 +166,6 @@ TEST_CASE(ble_att_clt_test_rx_find_info)
 static void
 ble_att_clt_test_case_tx_write_req_or_cmd(int is_req)
 {
-    struct ble_att_write_req req;
     uint16_t conn_handle;
     uint8_t value300[500] = { 0 };
     uint8_t value5[5] = { 6, 7, 54, 34, 8 };
@@ -175,16 +173,14 @@ ble_att_clt_test_case_tx_write_req_or_cmd(int is_req)
     conn_handle = ble_att_clt_test_misc_init();
 
     /*** 5-byte write. */
-    req.bawq_handle = 0x1234;
-    ble_att_clt_test_tx_write_req_or_cmd(conn_handle, &req, value5,
+    ble_att_clt_test_tx_write_req_or_cmd(conn_handle, 0x1234, value5,
                                          sizeof value5, is_req);
     ble_hs_test_util_tx_all();
     ble_att_clt_test_misc_verify_tx_write(0x1234, value5, sizeof value5,
                                           is_req);
 
     /*** Overlong write; verify command truncated to ATT MTU. */
-    req.bawq_handle = 0xab83;
-    ble_att_clt_test_tx_write_req_or_cmd(conn_handle, &req, value300,
+    ble_att_clt_test_tx_write_req_or_cmd(conn_handle, 0xab83, value300,
                                          sizeof value300, is_req);
     ble_hs_test_util_tx_all();
     ble_att_clt_test_misc_verify_tx_write(0xab83, value300,


[14/50] incubator-mynewt-core git commit: nimble/att: Don't pass Error Responce as packed structure

Posted by an...@apache.org.
nimble/att: Don't pass Error Responce as packed structure

Use packed structure only for mapping it onto received mbuf. Data is
passed to upper layers in native form. This allows compiler to generate
more effective code with regards to unaligned access.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/4e0f1b91
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/4e0f1b91
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/4e0f1b91

Branch: refs/heads/master
Commit: 4e0f1b9183a44d896d1a58be6d4bf42ab9fbb620
Parents: 8dbabc6
Author: Szymon Janc <sz...@codecoup.pl>
Authored: Fri Mar 24 15:35:59 2017 +0100
Committer: Szymon Janc <sz...@codecoup.pl>
Committed: Mon Apr 10 11:31:31 2017 +0200

----------------------------------------------------------------------
 net/nimble/host/src/ble_att_clt.c   | 2 +-
 net/nimble/host/src/ble_gatt_priv.h | 2 +-
 net/nimble/host/src/ble_gattc.c     | 5 ++---
 3 files changed, 4 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4e0f1b91/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
index 76d61eb..d34c096 100644
--- a/net/nimble/host/src/ble_att_clt.c
+++ b/net/nimble/host/src/ble_att_clt.c
@@ -44,7 +44,7 @@ ble_att_clt_rx_error(uint16_t conn_handle, struct os_mbuf **rxom)
     ble_att_error_rsp_parse((*rxom)->om_data, (*rxom)->om_len, &rsp);
     BLE_ATT_LOG_CMD(0, "error rsp", conn_handle, ble_att_error_rsp_log, &rsp);
 
-    ble_gattc_rx_err(conn_handle, &rsp);
+    ble_gattc_rx_err(conn_handle, rsp.baep_handle, rsp.baep_error_code);
 
     return 0;
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4e0f1b91/net/nimble/host/src/ble_gatt_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gatt_priv.h b/net/nimble/host/src/ble_gatt_priv.h
index 2325120..ea06b33 100644
--- a/net/nimble/host/src/ble_gatt_priv.h
+++ b/net/nimble/host/src/ble_gatt_priv.h
@@ -107,7 +107,7 @@ struct ble_gatts_conn {
 int ble_gattc_locked_by_cur_task(void);
 void ble_gatts_indicate_fail_notconn(uint16_t conn_handle);
 
-void ble_gattc_rx_err(uint16_t conn_handle, struct ble_att_error_rsp *rsp);
+void ble_gattc_rx_err(uint16_t conn_handle, uint16_t handle, uint16_t status);
 void ble_gattc_rx_mtu(uint16_t conn_handle, int status, uint16_t chan_mtu);
 void ble_gattc_rx_read_type_adata(uint16_t conn_handle,
                                   struct ble_att_read_type_adata *adata);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4e0f1b91/net/nimble/host/src/ble_gattc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gattc.c b/net/nimble/host/src/ble_gattc.c
index 6594182..ca5d541 100644
--- a/net/nimble/host/src/ble_gattc.c
+++ b/net/nimble/host/src/ble_gattc.c
@@ -4647,7 +4647,7 @@ done:
  * procedure.
  */
 void
-ble_gattc_rx_err(uint16_t conn_handle, struct ble_att_error_rsp *rsp)
+ble_gattc_rx_err(uint16_t conn_handle, uint16_t handle, uint16_t status)
 {
     struct ble_gattc_proc *proc;
     ble_gattc_err_fn *err_cb;
@@ -4656,8 +4656,7 @@ ble_gattc_rx_err(uint16_t conn_handle, struct ble_att_error_rsp *rsp)
     if (proc != NULL) {
         err_cb = ble_gattc_err_dispatch_get(proc->op);
         if (err_cb != NULL) {
-            err_cb(proc, BLE_HS_ERR_ATT_BASE + rsp->baep_error_code,
-                   rsp->baep_handle);
+            err_cb(proc, BLE_HS_ERR_ATT_BASE + status, handle);
         }
         ble_gattc_proc_free(proc);
     }


[03/50] incubator-mynewt-core git commit: nimble/att: Use new helpers for sending MTU exchange

Posted by an...@apache.org.
nimble/att: Use new helpers for sending MTU exchange

This constructs response directly on mbuf reducing number of memcopies.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/55b8a5c2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/55b8a5c2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/55b8a5c2

Branch: refs/heads/master
Commit: 55b8a5c20766f93996cd04d8ba06f8b77787932d
Parents: b50707b
Author: Szymon Janc <sz...@codecoup.pl>
Authored: Fri Mar 24 15:27:26 2017 +0100
Committer: Szymon Janc <sz...@codecoup.pl>
Committed: Mon Apr 10 11:31:30 2017 +0200

----------------------------------------------------------------------
 net/nimble/host/src/ble_att_clt.c           | 16 +++++++++-------
 net/nimble/host/src/ble_att_priv.h          |  3 +--
 net/nimble/host/src/ble_gattc.c             | 15 +++++----------
 net/nimble/host/test/src/ble_att_clt_test.c |  4 +---
 4 files changed, 16 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/55b8a5c2/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
index 8c92893..7ea7980 100644
--- a/net/nimble/host/src/ble_att_clt.c
+++ b/net/nimble/host/src/ble_att_clt.c
@@ -116,14 +116,15 @@ ble_att_clt_rx_error(uint16_t conn_handle, struct os_mbuf **rxom)
  *****************************************************************************/
 
 int
-ble_att_clt_tx_mtu(uint16_t conn_handle, const struct ble_att_mtu_cmd *req)
+ble_att_clt_tx_mtu(uint16_t conn_handle, uint16_t mtu)
 {
+    struct ble_att_mtu_cmd *req;
     struct ble_l2cap_chan *chan;
     struct ble_hs_conn *conn;
     struct os_mbuf *txom;
     int rc;
 
-    if (req->bamc_mtu < BLE_ATT_MTU_DFLT) {
+    if (mtu < BLE_ATT_MTU_DFLT) {
         return BLE_HS_EINVAL;
     }
 
@@ -143,13 +144,14 @@ ble_att_clt_tx_mtu(uint16_t conn_handle, const struct ble_att_mtu_cmd *req)
         return rc;
     }
 
-    rc = ble_att_clt_init_req(BLE_ATT_MTU_CMD_SZ, &txom);
-    if (rc != 0) {
-        return rc;
+    req = ble_att_cmd_get(BLE_ATT_OP_MTU_REQ, sizeof(*req), &txom);
+    if (req == NULL) {
+        return BLE_HS_ENOMEM;
     }
-    ble_att_mtu_req_write(txom->om_data, txom->om_len, req);
 
-    rc = ble_att_clt_tx_req(conn_handle, txom);
+    req->bamc_mtu = htole16(mtu);
+
+    rc = ble_att_tx(conn_handle, txom);
     if (rc != 0) {
         return rc;
     }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/55b8a5c2/net/nimble/host/src/ble_att_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_priv.h b/net/nimble/host/src/ble_att_priv.h
index 918ca9b..4e37bb7 100644
--- a/net/nimble/host/src/ble_att_priv.h
+++ b/net/nimble/host/src/ble_att_priv.h
@@ -250,8 +250,7 @@ struct ble_att_read_group_type_adata {
 };
 
 int ble_att_clt_rx_error(uint16_t conn_handle, struct os_mbuf **rxom);
-int ble_att_clt_tx_mtu(uint16_t conn_handle,
-                       const struct ble_att_mtu_cmd *req);
+int ble_att_clt_tx_mtu(uint16_t conn_handle, uint16_t mtu);
 int ble_att_clt_rx_mtu(uint16_t conn_handle, struct os_mbuf **rxom);
 int ble_att_clt_tx_read(uint16_t conn_handle,
                         const struct ble_att_read_req *req);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/55b8a5c2/net/nimble/host/src/ble_gattc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gattc.c b/net/nimble/host/src/ble_gattc.c
index 917e21a..d50368f 100644
--- a/net/nimble/host/src/ble_gattc.c
+++ b/net/nimble/host/src/ble_gattc.c
@@ -1267,28 +1267,23 @@ ble_gattc_mtu_err(struct ble_gattc_proc *proc, int status, uint16_t att_handle)
 static int
 ble_gattc_mtu_tx(struct ble_gattc_proc *proc)
 {
-    struct ble_att_mtu_cmd req;
     struct ble_l2cap_chan *chan;
     struct ble_hs_conn *conn;
+    uint16_t mtu;
     int rc;
 
     ble_hs_lock();
     rc = ble_att_conn_chan_find(proc->conn_handle, &conn, &chan);
     if (rc == 0) {
-        req.bamc_mtu = chan->my_mtu;
+        mtu = chan->my_mtu;
     }
     ble_hs_unlock();
 
-    if (rc != 0) {
-        return rc;
-    }
-
-    rc = ble_att_clt_tx_mtu(proc->conn_handle, &req);
-    if (rc != 0) {
-        return rc;
+    if (rc == 0) {
+        rc = ble_att_clt_tx_mtu(proc->conn_handle, mtu);
     }
 
-    return 0;
+    return rc;
 }
 
 /**

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/55b8a5c2/net/nimble/host/test/src/ble_att_clt_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/test/src/ble_att_clt_test.c b/net/nimble/host/test/src/ble_att_clt_test.c
index 3728557..c452128 100644
--- a/net/nimble/host/test/src/ble_att_clt_test.c
+++ b/net/nimble/host/test/src/ble_att_clt_test.c
@@ -278,11 +278,9 @@ ble_att_clt_test_misc_prep_bad(uint16_t handle, uint16_t offset,
 static void
 ble_att_clt_test_misc_tx_mtu(uint16_t conn_handle, uint16_t mtu, int status)
 {
-    struct ble_att_mtu_cmd req;
     int rc;
 
-    req.bamc_mtu = mtu;
-    rc = ble_att_clt_tx_mtu(conn_handle, &req);
+    rc = ble_att_clt_tx_mtu(conn_handle, mtu);
     TEST_ASSERT(rc == status);
 
     if (rc == 0) {


[46/50] incubator-mynewt-core git commit: nimble/att: Use packed struct for receiving Write Request and Command

Posted by an...@apache.org.
nimble/att: Use packed struct for receiving Write Request and Command

Use packed structure to map it to received mbuf instead of using
dedicated parsing function. Modern compilers generate effective code
in such case anyway.


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

Branch: refs/heads/master
Commit: be6aace608a3acf890c2eb704c6d1bcefe8ef34b
Parents: 37cec14
Author: Szymon Janc <sz...@codecoup.pl>
Authored: Fri Mar 24 15:50:05 2017 +0100
Committer: Szymon Janc <sz...@codecoup.pl>
Committed: Mon Apr 10 11:31:33 2017 +0200

----------------------------------------------------------------------
 net/nimble/host/src/ble_att_svr.c | 35 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/be6aace6/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
index 0990e8d..41567b6 100644
--- a/net/nimble/host/src/ble_att_svr.c
+++ b/net/nimble/host/src/ble_att_svr.c
@@ -2018,7 +2018,6 @@ ble_att_svr_build_write_rsp(struct os_mbuf **rxom, struct os_mbuf **out_txom,
                             uint8_t *att_err)
 {
     struct os_mbuf *txom;
-    uint8_t *dst;
     int rc;
 
     /* Allocate a new buffer for the response.  A write response never reuses
@@ -2029,15 +2028,12 @@ ble_att_svr_build_write_rsp(struct os_mbuf **rxom, struct os_mbuf **out_txom,
         goto done;
     }
 
-    dst = os_mbuf_extend(txom, BLE_ATT_WRITE_RSP_SZ);
-    if (dst == NULL) {
+    if (ble_att_cmd_prepare(BLE_ATT_OP_WRITE_RSP, 0, txom) == NULL) {
         *att_err = BLE_ATT_ERR_INSUFFICIENT_RES;
         rc = BLE_HS_ENOMEM;
         goto done;
     }
 
-    *dst = BLE_ATT_OP_WRITE_RSP;
-
     rc = 0;
 
 done:
@@ -2052,29 +2048,33 @@ ble_att_svr_rx_write(uint16_t conn_handle, struct os_mbuf **rxom)
     return BLE_HS_ENOTSUP;
 #endif
 
-    struct ble_att_write_req req;
+    struct ble_att_write_req *req;
     struct os_mbuf *txom;
-    uint16_t err_handle;
+    uint16_t handle;
     uint8_t att_err;
     int rc;
 
+    /* TODO move this to common part
+     * Strip L2CAP ATT header from the front of the mbuf.
+     */
+    os_mbuf_adj(*rxom, 1);
+
     /* Initialize some values in case of early error. */
     txom = NULL;
     att_err = 0;
-    err_handle = 0;
+    handle = 0;
 
-    rc = ble_att_svr_pullup_req_base(rxom, BLE_ATT_WRITE_REQ_BASE_SZ,
-                                     &att_err);
+    rc = ble_att_svr_pullup_req_base(rxom, sizeof(*req), &att_err);
     if (rc != 0) {
-        err_handle = 0;
         goto done;
     }
 
-    ble_att_write_req_parse((*rxom)->om_data, (*rxom)->om_len, &req);
+    req = (struct ble_att_write_req *)(*rxom)->om_data;
+
     BLE_ATT_LOG_CMD(0, "write req", conn_handle,
-                    ble_att_write_req_log, &req);
+                    ble_att_write_req_log, req);
 
-    err_handle = req.bawq_handle;
+    handle = le16toh(req->bawq_handle);
 
     /* Allocate the write response.  This must be done prior to processing the
      * request.  See the note at the top of this file for details.
@@ -2085,10 +2085,9 @@ ble_att_svr_rx_write(uint16_t conn_handle, struct os_mbuf **rxom)
     }
 
     /* Strip the request base from the front of the mbuf. */
-    os_mbuf_adj(*rxom, BLE_ATT_WRITE_REQ_BASE_SZ);
+    os_mbuf_adj(*rxom, sizeof(*req));
 
-    rc = ble_att_svr_write_handle(conn_handle, req.bawq_handle, 0, rxom,
-                                  &att_err);
+    rc = ble_att_svr_write_handle(conn_handle, handle, 0, rxom, &att_err);
     if (rc != 0) {
         goto done;
     }
@@ -2099,7 +2098,7 @@ ble_att_svr_rx_write(uint16_t conn_handle, struct os_mbuf **rxom)
 
 done:
     rc = ble_att_svr_tx_rsp(conn_handle, rc, txom, BLE_ATT_OP_WRITE_REQ,
-                            att_err, err_handle);
+                            att_err, handle);
     return rc;
 }
 


[36/50] incubator-mynewt-core git commit: nimble/att: Use packed struct for receiving Prepare Write Request

Posted by an...@apache.org.
nimble/att: Use packed struct for receiving Prepare Write Request

Use packed structure to map it to received mbuf instead of using
dedicated parsing function. Modern compilers generate effective code
in such case anyway.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/3a3571ec
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/3a3571ec
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/3a3571ec

Branch: refs/heads/master
Commit: 3a3571ecdf46be5957a2004d5ee210f413f08d39
Parents: be6aace
Author: Szymon Janc <sz...@codecoup.pl>
Authored: Fri Mar 24 15:50:06 2017 +0100
Committer: Szymon Janc <sz...@codecoup.pl>
Committed: Mon Apr 10 11:31:33 2017 +0200

----------------------------------------------------------------------
 net/nimble/host/src/ble_att_svr.c | 41 +++++++++++++++++++++-------------
 1 file changed, 25 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3a3571ec/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
index 41567b6..93d6cef 100644
--- a/net/nimble/host/src/ble_att_svr.c
+++ b/net/nimble/host/src/ble_att_svr.c
@@ -2354,7 +2354,7 @@ ble_att_svr_prep_write(uint16_t conn_handle,
 
 static int
 ble_att_svr_insert_prep_entry(uint16_t conn_handle,
-                              const struct ble_att_prep_write_cmd *req,
+                              uint16_t handle, uint16_t offset,
                               const struct os_mbuf *rxom,
                               uint8_t *out_att_err)
 {
@@ -2369,15 +2369,15 @@ ble_att_svr_insert_prep_entry(uint16_t conn_handle,
     if (prep_entry == NULL) {
         return BLE_HS_ENOMEM;
     }
-    prep_entry->bape_handle = req->bapc_handle;
-    prep_entry->bape_offset = req->bapc_offset;
+    prep_entry->bape_handle = handle;
+    prep_entry->bape_offset = offset;
 
     /* Append attribute value from request onto prep mbuf. */
     rc = os_mbuf_appendfrom(
         prep_entry->bape_value,
         rxom,
-        BLE_ATT_PREP_WRITE_CMD_BASE_SZ,
-        OS_MBUF_PKTLEN(rxom) - BLE_ATT_PREP_WRITE_CMD_BASE_SZ);
+        sizeof(struct ble_att_prep_write_cmd),
+        OS_MBUF_PKTLEN(rxom) - sizeof(struct ble_att_prep_write_cmd));
     if (rc != 0) {
         /* Failed to allocate an mbuf to hold the additional data. */
         ble_att_svr_prep_free(prep_entry);
@@ -2391,8 +2391,7 @@ ble_att_svr_insert_prep_entry(uint16_t conn_handle,
     }
 
     prep_prev = ble_att_svr_prep_find_prev(&conn->bhc_att_svr,
-                                           req->bapc_handle,
-                                           req->bapc_offset);
+                                           handle, offset);
     if (prep_prev == NULL) {
         SLIST_INSERT_HEAD(&conn->bhc_att_svr.basc_prep_list, prep_entry,
                           bape_next);
@@ -2417,31 +2416,37 @@ ble_att_svr_rx_prep_write(uint16_t conn_handle, struct os_mbuf **rxom)
     return BLE_HS_ENOTSUP;
 #endif
 
-    struct ble_att_prep_write_cmd req;
+    struct ble_att_prep_write_cmd *req;
     struct ble_att_svr_entry *attr_entry;
     struct os_mbuf *txom;
     uint16_t err_handle;
     uint8_t att_err;
     int rc;
 
+    /* TODO move this to common part
+     * Strip L2CAP ATT header from the front of the mbuf.
+     */
+    os_mbuf_adj(*rxom, 1);
+
     /* Initialize some values in case of early error. */
     txom = NULL;
     att_err = 0;
     err_handle = 0;
 
-    rc = ble_att_svr_pullup_req_base(rxom, BLE_ATT_PREP_WRITE_CMD_BASE_SZ,
-                                     &att_err);
+    rc = ble_att_svr_pullup_req_base(rxom, sizeof(*req), &att_err);
     if (rc != 0) {
         err_handle = 0;
         goto done;
     }
 
-    ble_att_prep_write_req_parse((*rxom)->om_data, (*rxom)->om_len, &req);
+    req = (struct ble_att_prep_write_cmd *)(*rxom)->om_data;
+
     BLE_ATT_LOG_CMD(0, "prep write req", conn_handle,
-                    ble_att_prep_write_cmd_log, &req);
-    err_handle = req.bapc_handle;
+                    ble_att_prep_write_cmd_log, req);
+
+    err_handle = le16toh(req->bapc_handle);
 
-    attr_entry = ble_att_svr_find_by_handle(req.bapc_handle);
+    attr_entry = ble_att_svr_find_by_handle(le16toh(req->bapc_handle));
 
     /* A prepare write request gets rejected for the following reasons:
      * 1. Insufficient authorization.
@@ -2466,7 +2471,9 @@ ble_att_svr_rx_prep_write(uint16_t conn_handle, struct os_mbuf **rxom)
     }
 
     ble_hs_lock();
-    rc = ble_att_svr_insert_prep_entry(conn_handle, &req, *rxom, &att_err);
+    rc = ble_att_svr_insert_prep_entry(conn_handle, le16toh(req->bapc_handle),
+                                       le16toh(req->bapc_offset), *rxom,
+                                       &att_err);
     ble_hs_unlock();
 
     /* Reuse rxom for response.  On success, the response is identical to
@@ -2480,10 +2487,12 @@ ble_att_svr_rx_prep_write(uint16_t conn_handle, struct os_mbuf **rxom)
         goto done;
     }
 
+    /* adjust for ATT header */
+    os_mbuf_prepend(txom, 1);
     txom->om_data[0] = BLE_ATT_OP_PREP_WRITE_RSP;
 
     BLE_ATT_LOG_CMD(1, "prep write rsp", conn_handle,
-                    ble_att_prep_write_cmd_log, &req);
+                    ble_att_prep_write_cmd_log, req);
 
     rc = 0;
 


[26/50] incubator-mynewt-core git commit: nimble/att: Use packed struct for receiving Read By Type Request

Posted by an...@apache.org.
nimble/att: Use packed struct for receiving Read By Type Request

Use packed structure to map it to received mbuf instead of using
dedicated parsing function. Modern compilers generate effective code
in such case anyway.


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

Branch: refs/heads/master
Commit: e15ad929887f470e3bd39535666bb66a077fd4ac
Parents: f6800fc
Author: Szymon Janc <sz...@codecoup.pl>
Authored: Fri Mar 24 15:50:03 2017 +0100
Committer: Szymon Janc <sz...@codecoup.pl>
Committed: Mon Apr 10 11:31:32 2017 +0200

----------------------------------------------------------------------
 net/nimble/host/src/ble_att_cmd_priv.h |  7 +++
 net/nimble/host/src/ble_att_svr.c      | 66 ++++++++++++++++-------------
 2 files changed, 44 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e15ad929/net/nimble/host/src/ble_att_cmd_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_cmd_priv.h b/net/nimble/host/src/ble_att_cmd_priv.h
index 4a7e491..c0bef79 100644
--- a/net/nimble/host/src/ble_att_cmd_priv.h
+++ b/net/nimble/host/src/ble_att_cmd_priv.h
@@ -151,8 +151,15 @@ struct ble_att_read_type_req {
  * | Attribute Data List                | 2 to (ATT_MTU-2)  |
  */
 #define BLE_ATT_READ_TYPE_RSP_BASE_SZ       2
+
+struct ble_att_attr_data_list {
+    uint16_t handle;
+    uint8_t value[0];
+} __attribute__((packed));
+
 struct ble_att_read_type_rsp {
     uint8_t batp_length;
+    struct ble_att_attr_data_list batp_list[0];
 } __attribute__((packed));
 
 #define BLE_ATT_READ_TYPE_ADATA_BASE_SZ     2

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e15ad929/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
index 8a6acc3..fffb9dd 100644
--- a/net/nimble/host/src/ble_att_svr.c
+++ b/net/nimble/host/src/ble_att_svr.c
@@ -1293,20 +1293,20 @@ done:
 
 static int
 ble_att_svr_build_read_type_rsp(uint16_t conn_handle,
-                                struct ble_att_read_type_req *req,
+                                uint16_t start_handle, uint16_t end_handle,
                                 const ble_uuid_t *uuid,
                                 struct os_mbuf **rxom,
                                 struct os_mbuf **out_txom,
                                 uint8_t *att_err,
                                 uint16_t *err_handle)
 {
-    struct ble_att_read_type_rsp rsp;
+    struct ble_att_attr_data_list *data;
+    struct ble_att_read_type_rsp *rsp;
     struct ble_att_svr_entry *entry;
     struct os_mbuf *txom;
     uint16_t attr_len;
     uint16_t mtu;
     uint8_t buf[19];
-    uint8_t *dptr;
     int entry_written;
     int txomlen;
     int prev_attr_len;
@@ -1314,7 +1314,7 @@ ble_att_svr_build_read_type_rsp(uint16_t conn_handle,
 
     *att_err = 0;    /* Silence unnecessary warning. */
 
-    *err_handle = req->batq_start_handle;
+    *err_handle = start_handle;
     entry_written = 0;
     prev_attr_len = 0;
 
@@ -1326,8 +1326,9 @@ ble_att_svr_build_read_type_rsp(uint16_t conn_handle,
     /* 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_BASE_SZ);
-    if (dptr == NULL) {
+
+    rsp = ble_att_cmd_prepare(BLE_ATT_OP_READ_TYPE_RSP, sizeof(*rsp), txom);
+    if (rsp == NULL) {
         *att_err = BLE_ATT_ERR_INSUFFICIENT_RES;
         *err_handle = 0;
         rc = BLE_HS_ENOMEM;
@@ -1339,13 +1340,13 @@ ble_att_svr_build_read_type_rsp(uint16_t conn_handle,
     /* Find all matching attributes, writing a record for each. */
     entry = NULL;
     while (1) {
-        entry = ble_att_svr_find_by_uuid(entry, uuid, req->batq_end_handle);
+        entry = ble_att_svr_find_by_uuid(entry, uuid, end_handle);
         if (entry == NULL) {
             rc = BLE_HS_ENOENT;
             break;
         }
 
-        if (entry->ha_handle_id >= req->batq_start_handle) {
+        if (entry->ha_handle_id >= start_handle) {
             rc = ble_att_svr_read_flat(conn_handle, entry, 0, sizeof buf, buf,
                                        &attr_len, att_err);
             if (rc != 0) {
@@ -1368,16 +1369,16 @@ ble_att_svr_build_read_type_rsp(uint16_t conn_handle,
                 break;
             }
 
-            dptr = os_mbuf_extend(txom, 2 + attr_len);
-            if (dptr == NULL) {
+            data = os_mbuf_extend(txom, 2 + attr_len);
+            if (data == NULL) {
                 *att_err = BLE_ATT_ERR_INSUFFICIENT_RES;
                 *err_handle = entry->ha_handle_id;
                 rc = BLE_HS_ENOMEM;
                 goto done;
             }
 
-            put_le16(dptr + 0, entry->ha_handle_id);
-            memcpy(dptr + 2, buf, attr_len);
+            data->handle = htole16(entry->ha_handle_id);
+            memcpy(data->value, buf, attr_len);
             entry_written = 1;
         }
     }
@@ -1397,10 +1398,9 @@ done:
         *att_err = 0;
 
         /* Fill the response base. */
-        rsp.batp_length = BLE_ATT_READ_TYPE_ADATA_BASE_SZ + prev_attr_len;
-        ble_att_read_type_rsp_write(txom->om_data, txom->om_len, &rsp);
+        rsp->batp_length = htole16(sizeof(*data) + prev_attr_len);
         BLE_ATT_LOG_CMD(1, "read type rsp", conn_handle,
-                        ble_att_read_type_rsp_log, &rsp);
+                        ble_att_read_type_rsp_log, rsp);
     }
 
     *out_txom = txom;
@@ -1415,7 +1415,8 @@ ble_att_svr_rx_read_type(uint16_t conn_handle, struct os_mbuf **rxom)
     return BLE_HS_ENOTSUP;
 #endif
 
-    struct ble_att_read_type_req req;
+    struct ble_att_read_type_req *req;
+    uint16_t start_handle, end_handle;
     struct os_mbuf *txom;
     uint16_t err_handle;
     uint16_t pktlen;
@@ -1423,14 +1424,18 @@ ble_att_svr_rx_read_type(uint16_t conn_handle, struct os_mbuf **rxom)
     uint8_t att_err;
     int rc;
 
+    /* TODO move this to common part
+     * Strip L2CAP ATT header from the front of the mbuf.
+     */
+    os_mbuf_adj(*rxom, 1);
+
     /* Initialize some values in case of early error. */
     txom = NULL;
 
     pktlen = OS_MBUF_PKTLEN(*rxom);
-    if (pktlen != BLE_ATT_READ_TYPE_REQ_SZ_16 &&
-        pktlen != BLE_ATT_READ_TYPE_REQ_SZ_128) {
-
-        /* Malformed packet; discard. */
+    if (pktlen != sizeof(*req) + 2 && pktlen != sizeof(*req) + 16) {
+        /* Malformed packet */
+        err_handle = 0;
         rc = BLE_HS_EBADDATA;
         goto done;
     }
@@ -1441,21 +1446,23 @@ ble_att_svr_rx_read_type(uint16_t conn_handle, struct os_mbuf **rxom)
         goto done;
     }
 
-    ble_att_read_type_req_parse((*rxom)->om_data, (*rxom)->om_len, &req);
-    BLE_ATT_LOG_CMD(0, "read type req", conn_handle, ble_att_read_type_req_log,
-                    &req);
+    req = (struct ble_att_read_type_req *)(*rxom)->om_data;
 
+    BLE_ATT_LOG_CMD(0, "read type req", conn_handle, ble_att_read_type_req_log,
+                    req);
 
-    if (req.batq_start_handle > req.batq_end_handle ||
-        req.batq_start_handle == 0) {
+    start_handle = le16toh(req->batq_start_handle);
+    end_handle = le16toh(req->batq_end_handle);
 
+    if (start_handle > end_handle || start_handle == 0) {
         att_err = BLE_ATT_ERR_INVALID_HANDLE;
-        err_handle = req.batq_start_handle;
+        err_handle = start_handle;
         rc = BLE_HS_EBADDATA;
         goto done;
     }
 
-    rc = ble_uuid_init_from_mbuf(&uuid, *rxom, 5, (*rxom)->om_len - 5);
+    rc = ble_uuid_init_from_mbuf(&uuid, *rxom, sizeof(*req),
+                                 pktlen - sizeof(*req));
     if (rc != 0) {
         att_err = BLE_ATT_ERR_INVALID_PDU;
         err_handle = 0;
@@ -1463,8 +1470,9 @@ ble_att_svr_rx_read_type(uint16_t conn_handle, struct os_mbuf **rxom)
         goto done;
     }
 
-    rc = ble_att_svr_build_read_type_rsp(conn_handle, &req, &uuid.u,
-                                         rxom, &txom, &att_err, &err_handle);
+    rc = ble_att_svr_build_read_type_rsp(conn_handle, start_handle, end_handle,
+                                         &uuid.u, rxom, &txom, &att_err,
+                                         &err_handle);
     if (rc != 0) {
         goto done;
     }


[30/50] incubator-mynewt-core git commit: nimble/att: Use packed struct for receiving Read Blob Response

Posted by an...@apache.org.
nimble/att: Use packed struct for receiving Read Blob Response

Use packed structure to map it to received mbuf instead of using
dedicated parsing function. Modern compilers generate effective code
in such case anyway.


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

Branch: refs/heads/master
Commit: ac38eb72d6525c1b21b95ec8af5e0c3976d2746a
Parents: 9c897e5
Author: Szymon Janc <sz...@codecoup.pl>
Authored: Fri Mar 24 15:50:04 2017 +0100
Committer: Szymon Janc <sz...@codecoup.pl>
Committed: Mon Apr 10 11:31:32 2017 +0200

----------------------------------------------------------------------
 net/nimble/host/src/ble_att_clt.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ac38eb72/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
index b445f2d..612d3c5 100644
--- a/net/nimble/host/src/ble_att_clt.c
+++ b/net/nimble/host/src/ble_att_clt.c
@@ -583,10 +583,10 @@ ble_att_clt_rx_read_blob(uint16_t conn_handle, struct os_mbuf **rxom)
 
     BLE_ATT_LOG_EMPTY_CMD(0, "read blob rsp", conn_handle);
 
-    /* Reponse consists of a one-byte opcode (already verified) and a variable
-     * length Attribute Value field.  Strip the opcode from the response.
+    /* TODO move this to common part
+     * Strip L2CAP ATT header from the front of the mbuf.
      */
-    os_mbuf_adj(*rxom, BLE_ATT_READ_BLOB_RSP_BASE_SZ);
+    os_mbuf_adj(*rxom, 1);
 
     /* Pass the Attribute Value field to GATT. */
     ble_gattc_rx_read_blob_rsp(conn_handle, 0, rxom);


[41/50] incubator-mynewt-core git commit: nimble/sm: Use endian.h API for protocol data

Posted by an...@apache.org.
nimble/sm: Use endian.h API for protocol data

Don't use TOFROMLE16 API for protocol data. This API hide direction of
convertion making code hard to follow.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/7674f263
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/7674f263
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/7674f263

Branch: refs/heads/master
Commit: 7674f26323d8dfce61fcfd6e2175894a7eb89f10
Parents: 32db778
Author: Szymon Janc <sz...@codecoup.pl>
Authored: Fri Mar 24 15:50:08 2017 +0100
Committer: Szymon Janc <sz...@codecoup.pl>
Committed: Mon Apr 10 11:31:33 2017 +0200

----------------------------------------------------------------------
 net/nimble/host/src/ble_sm.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7674f263/net/nimble/host/src/ble_sm.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm.c b/net/nimble/host/src/ble_sm.c
index b58e7ae..9c925fd 100644
--- a/net/nimble/host/src/ble_sm.c
+++ b/net/nimble/host/src/ble_sm.c
@@ -1103,8 +1103,7 @@ ble_sm_ltk_req_reply_tx(uint16_t conn_handle, uint8_t *ltk)
         return BLE_HS_ECONTROLLER;
     }
 
-    ack_conn_handle = TOFROMLE16(ack_conn_handle);
-    if (ack_conn_handle != conn_handle) {
+    if (le16toh(ack_conn_handle) != conn_handle) {
         return BLE_HS_ECONTROLLER;
     }
 
@@ -1129,8 +1128,7 @@ ble_sm_ltk_req_neg_reply_tx(uint16_t conn_handle)
         return BLE_HS_ECONTROLLER;
     }
 
-    ack_conn_handle = TOFROMLE16(ack_conn_handle);
-    if (ack_conn_handle != conn_handle) {
+    if (le16toh(ack_conn_handle) != conn_handle) {
         return BLE_HS_ECONTROLLER;
     }
 


[16/50] incubator-mynewt-core git commit: nimble/att: Use new helpers for sending Execute Write Request

Posted by an...@apache.org.
nimble/att: Use new helpers for sending Execute Write Request

This constructs response directly on mbuf reducing number of memcopies.


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

Branch: refs/heads/master
Commit: d74cc3eeb8a729346de2208fdf9f57593d1627a3
Parents: d290cd7
Author: Szymon Janc <sz...@codecoup.pl>
Authored: Fri Mar 24 15:34:55 2017 +0100
Committer: Szymon Janc <sz...@codecoup.pl>
Committed: Mon Apr 10 11:31:31 2017 +0200

----------------------------------------------------------------------
 net/nimble/host/src/ble_att_clt.c           | 47 ++++--------------------
 net/nimble/host/src/ble_att_priv.h          |  3 +-
 net/nimble/host/src/ble_gattc.c             | 22 ++++-------
 net/nimble/host/test/src/ble_att_clt_test.c |  7 +---
 4 files changed, 19 insertions(+), 60 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d74cc3ee/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
index 141e6e7..52c83c0 100644
--- a/net/nimble/host/src/ble_att_clt.c
+++ b/net/nimble/host/src/ble_att_clt.c
@@ -27,38 +27,6 @@
 #include "ble_hs_priv.h"
 
 static int
-ble_att_clt_init_req(uint16_t initial_sz, struct os_mbuf **out_txom)
-{
-    struct os_mbuf *om;
-    void *buf;
-    int rc;
-
-    *out_txom = NULL;
-
-    om = ble_hs_mbuf_l2cap_pkt();
-    if (om == NULL) {
-        rc = BLE_HS_ENOMEM;
-        goto err;
-    }
-
-    buf = os_mbuf_extend(om, initial_sz);
-    if (buf == NULL) {
-        rc = BLE_HS_ENOMEM;
-        goto err;
-    }
-
-    /* The caller expects the initial buffer to be at the start of the mbuf. */
-    BLE_HS_DBG_ASSERT(buf == om->om_data);
-
-    *out_txom = om;
-    return 0;
-
-err:
-    os_mbuf_free_chain(om);
-    return rc;
-}
-
-static int
 ble_att_clt_tx_req(uint16_t conn_handle, struct os_mbuf *txom)
 {
     struct ble_l2cap_chan *chan;
@@ -955,23 +923,24 @@ done:
  *****************************************************************************/
 
 int
-ble_att_clt_tx_exec_write(uint16_t conn_handle,
-                          const struct ble_att_exec_write_req *req)
+ble_att_clt_tx_exec_write(uint16_t conn_handle, uint8_t flags)
 {
 #if !NIMBLE_BLE_ATT_CLT_EXEC_WRITE
     return BLE_HS_ENOTSUP;
 #endif
 
+    struct ble_att_exec_write_req *req;
     struct os_mbuf *txom;
     int rc;
 
-    rc = ble_att_clt_init_req(BLE_ATT_EXEC_WRITE_REQ_SZ, &txom);
-    if (rc != 0) {
-        return rc;
+    req = ble_att_cmd_get(BLE_ATT_OP_EXEC_WRITE_REQ, sizeof(*req), &txom);
+    if (req == NULL) {
+        return BLE_HS_ENOMEM;
     }
-    ble_att_exec_write_req_write(txom->om_data, txom->om_len, req);
 
-    rc = ble_att_clt_tx_req(conn_handle, txom);
+    req->baeq_flags = flags;
+
+    rc = ble_att_tx(conn_handle, txom);
     if (rc != 0) {
         return rc;
     }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d74cc3ee/net/nimble/host/src/ble_att_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_priv.h b/net/nimble/host/src/ble_att_priv.h
index dd14be7..fbc81d9 100644
--- a/net/nimble/host/src/ble_att_priv.h
+++ b/net/nimble/host/src/ble_att_priv.h
@@ -283,8 +283,7 @@ int ble_att_clt_tx_write_cmd(uint16_t conn_handle, uint16_t handle,
 int ble_att_clt_tx_prep_write(uint16_t conn_handle, uint16_t handle,
                               uint16_t offset, struct os_mbuf *txom);
 int ble_att_clt_rx_prep_write(uint16_t conn_handle, struct os_mbuf **rxom);
-int ble_att_clt_tx_exec_write(uint16_t conn_handle,
-                              const struct ble_att_exec_write_req *req);
+int ble_att_clt_tx_exec_write(uint16_t conn_handle, uint8_t flags);
 int ble_att_clt_rx_exec_write(uint16_t conn_handle, struct os_mbuf **rxom);
 int ble_att_clt_rx_write(uint16_t conn_handle, struct os_mbuf **rxom);
 int ble_att_clt_tx_notify(uint16_t conn_handle,

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d74cc3ee/net/nimble/host/src/ble_gattc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gattc.c b/net/nimble/host/src/ble_gattc.c
index fede8d1..59fbea8 100644
--- a/net/nimble/host/src/ble_gattc.c
+++ b/net/nimble/host/src/ble_gattc.c
@@ -3816,7 +3816,6 @@ ble_gattc_write_long_tmo(struct ble_gattc_proc *proc)
 static int
 ble_gattc_write_long_tx(struct ble_gattc_proc *proc)
 {
-    struct ble_att_exec_write_req exec_req;
     struct os_mbuf *om;
     int write_len;
     int max_sz;
@@ -3838,8 +3837,8 @@ ble_gattc_write_long_tx(struct ble_gattc_proc *proc)
                         proc->write_long.attr.offset);
 
     if (write_len <= 0) {
-        exec_req.baeq_flags = BLE_ATT_EXEC_WRITE_F_EXECUTE;
-        rc = ble_att_clt_tx_exec_write(proc->conn_handle, &exec_req);
+        rc = ble_att_clt_tx_exec_write(proc->conn_handle,
+                                       BLE_ATT_EXEC_WRITE_F_EXECUTE);
         goto done;
     }
 
@@ -3895,8 +3894,6 @@ static void
 ble_gattc_write_long_err(struct ble_gattc_proc *proc, int status,
                          uint16_t att_handle)
 {
-    struct ble_att_exec_write_req exec_req;
-
     ble_gattc_dbg_assert_proc_not_inserted(proc);
 
     /* If we have successfully queued any data, and the failure occurred before
@@ -3906,8 +3903,8 @@ ble_gattc_write_long_err(struct ble_gattc_proc *proc, int status,
         proc->write_long.attr.offset <
             OS_MBUF_PKTLEN(proc->write_long.attr.om)) {
 
-        exec_req.baeq_flags = BLE_ATT_EXEC_WRITE_F_CANCEL;
-        ble_att_clt_tx_exec_write(proc->conn_handle, &exec_req);
+        ble_att_clt_tx_exec_write(proc->conn_handle,
+                                  BLE_ATT_EXEC_WRITE_F_CANCEL);
     }
 
     /* Report failure. */
@@ -4128,7 +4125,6 @@ ble_gattc_write_reliable_tmo(struct ble_gattc_proc *proc)
 static int
 ble_gattc_write_reliable_tx(struct ble_gattc_proc *proc)
 {
-    struct ble_att_exec_write_req exec_req;
     struct ble_gatt_attr *attr;
     struct os_mbuf *om;
     uint16_t max_sz;
@@ -4142,8 +4138,8 @@ ble_gattc_write_reliable_tx(struct ble_gattc_proc *proc)
     attr_idx = proc->write_reliable.cur_attr;
 
     if (attr_idx >= proc->write_reliable.num_attrs) {
-        exec_req.baeq_flags = BLE_ATT_EXEC_WRITE_F_EXECUTE;
-        rc = ble_att_clt_tx_exec_write(proc->conn_handle, &exec_req);
+        rc = ble_att_clt_tx_exec_write(proc->conn_handle,
+                                       BLE_ATT_EXEC_WRITE_F_EXECUTE);
         goto done;
     }
 
@@ -4208,8 +4204,6 @@ static void
 ble_gattc_write_reliable_err(struct ble_gattc_proc *proc, int status,
                              uint16_t att_handle)
 {
-    struct ble_att_exec_write_req exec_req;
-
     ble_gattc_dbg_assert_proc_not_inserted(proc);
     ble_gattc_write_reliable_cb(proc, status, att_handle);
 
@@ -4219,8 +4213,8 @@ ble_gattc_write_reliable_err(struct ble_gattc_proc *proc, int status,
     if (proc->write_reliable.cur_attr >= 0 &&
         proc->write_reliable.cur_attr < proc->write_reliable.num_attrs) {
 
-        exec_req.baeq_flags = BLE_ATT_EXEC_WRITE_F_CANCEL;
-        ble_att_clt_tx_exec_write(proc->conn_handle, &exec_req);
+        ble_att_clt_tx_exec_write(proc->conn_handle,
+                                  BLE_ATT_EXEC_WRITE_F_CANCEL);
     }
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d74cc3ee/net/nimble/host/test/src/ble_att_clt_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/test/src/ble_att_clt_test.c b/net/nimble/host/test/src/ble_att_clt_test.c
index e3ba5ce..4bd1947 100644
--- a/net/nimble/host/test/src/ble_att_clt_test.c
+++ b/net/nimble/host/test/src/ble_att_clt_test.c
@@ -227,8 +227,7 @@ ble_att_clt_test_misc_exec_good(uint8_t flags)
 
     conn_handle = ble_att_clt_test_misc_init();
 
-    req.baeq_flags = flags;
-    rc = ble_att_clt_tx_exec_write(conn_handle, &req);
+    rc = ble_att_clt_tx_exec_write(conn_handle, flags);
     TEST_ASSERT(rc == 0);
 
     ble_hs_test_util_tx_all();
@@ -481,7 +480,6 @@ TEST_CASE(ble_att_clt_test_rx_prep_write)
 
 TEST_CASE(ble_att_clt_test_tx_exec_write)
 {
-    struct ble_att_exec_write_req req;
     uint16_t conn_handle;
     int rc;
 
@@ -492,8 +490,7 @@ TEST_CASE(ble_att_clt_test_tx_exec_write)
     ble_att_clt_test_misc_exec_good(BLE_ATT_EXEC_WRITE_F_EXECUTE);
 
     /*** Success: nonzero == execute. */
-    req.baeq_flags = 0x02;
-    rc = ble_att_clt_tx_exec_write(conn_handle, &req);
+    rc = ble_att_clt_tx_exec_write(conn_handle, 0x02);
     TEST_ASSERT(rc == 0);
 }
 


[27/50] incubator-mynewt-core git commit: nimble/att: Use packed struct for receiving Read Request

Posted by an...@apache.org.
nimble/att: Use packed struct for receiving Read Request

Use packed structure to map it to received mbuf instead of using
dedicated parsing function. Modern compilers generate effective code
in such case anyway.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/3b250764
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/3b250764
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/3b250764

Branch: refs/heads/master
Commit: 3b2507644e34a87016fce639416ea47302169ae2
Parents: c3cca42
Author: Szymon Janc <sz...@codecoup.pl>
Authored: Fri Mar 24 15:50:04 2017 +0100
Committer: Szymon Janc <sz...@codecoup.pl>
Committed: Mon Apr 10 11:31:32 2017 +0200

----------------------------------------------------------------------
 net/nimble/host/src/ble_att_svr.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3b250764/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
index fffb9dd..f5d39ce 100644
--- a/net/nimble/host/src/ble_att_svr.c
+++ b/net/nimble/host/src/ble_att_svr.c
@@ -1492,43 +1492,44 @@ ble_att_svr_rx_read(uint16_t conn_handle, struct os_mbuf **rxom)
     return BLE_HS_ENOTSUP;
 #endif
 
-    struct ble_att_read_req req;
+    struct ble_att_read_req *req;
     struct os_mbuf *txom;
     uint16_t err_handle;
     uint8_t att_err;
-    uint8_t *dptr;
     int rc;
 
+    /* TODO move this to common part
+     * Strip L2CAP ATT header from the front of the mbuf.
+     */
+    os_mbuf_adj(*rxom, 1);
+
     /* Initialize some values in case of early error. */
     txom = NULL;
     att_err = 0;
     err_handle = 0;
 
-    rc = ble_att_svr_pullup_req_base(rxom, BLE_ATT_READ_REQ_SZ, &att_err);
+    rc = ble_att_svr_pullup_req_base(rxom, sizeof(*req), &att_err);
     if (rc != 0) {
         goto done;
     }
 
-    ble_att_read_req_parse((*rxom)->om_data, (*rxom)->om_len, &req);
-    BLE_ATT_LOG_CMD(0, "read req", conn_handle, ble_att_read_req_log, &req);
+    req = (struct ble_att_read_req *)(*rxom)->om_data;
+    BLE_ATT_LOG_CMD(0, "read req", conn_handle, ble_att_read_req_log, req);
 
-    err_handle = req.barq_handle;
+    err_handle = le16toh(req->barq_handle);
 
     /* Just reuse the request buffer for the response. */
     txom = *rxom;
     *rxom = NULL;
     os_mbuf_adj(txom, OS_MBUF_PKTLEN(txom));
 
-    dptr = os_mbuf_extend(txom, 1);
-    if (dptr == NULL) {
+    if (ble_att_cmd_prepare(BLE_ATT_OP_READ_RSP, 0, txom) == NULL) {
         att_err = BLE_ATT_ERR_INSUFFICIENT_RES;
         rc = BLE_HS_ENOMEM;
         goto done;
     }
-    *dptr = BLE_ATT_OP_READ_RSP;
 
-    rc = ble_att_svr_read_handle(conn_handle, req.barq_handle, 0, txom,
-                                 &att_err);
+    rc = ble_att_svr_read_handle(conn_handle, err_handle, 0, txom, &att_err);
     if (rc != 0) {
         goto done;
     }


[40/50] incubator-mynewt-core git commit: bletest: Use endian.h API for protocol data

Posted by an...@apache.org.
bletest: Use endian.h API for protocol data

Don't use TOFROMLE16 API for protocol data. This API hide direction of
convertion making code hard to follow.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/82674a00
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/82674a00
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/82674a00

Branch: refs/heads/master
Commit: 82674a00eb15a91f3755131cc2ea88788730b370
Parents: 7e1ac05
Author: Szymon Janc <sz...@codecoup.pl>
Authored: Fri Mar 24 15:50:10 2017 +0100
Committer: Szymon Janc <sz...@codecoup.pl>
Committed: Mon Apr 10 11:31:33 2017 +0200

----------------------------------------------------------------------
 apps/bletest/src/bletest_hci.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/82674a00/apps/bletest/src/bletest_hci.c
----------------------------------------------------------------------
diff --git a/apps/bletest/src/bletest_hci.c b/apps/bletest/src/bletest_hci.c
index 86d2293..3cac170 100755
--- a/apps/bletest/src/bletest_hci.c
+++ b/apps/bletest/src/bletest_hci.c
@@ -115,8 +115,7 @@ bletest_send_ltk_req_reply(uint16_t handle)
         return -1;
     }
 
-    ack_conn_handle = TOFROMLE16(ack_conn_handle);
-    if (ack_conn_handle != handle) {
+    if (le16toh(ack_conn_handle) != conn_handle) {
         return -1;
     }
     return 0;


[15/50] incubator-mynewt-core git commit: nimble/att: Use new helpers for sending Indication

Posted by an...@apache.org.
nimble/att: Use new helpers for sending Indication

This constructs response directly on mbuf reducing number of memcopies.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/8dbabc6e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/8dbabc6e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/8dbabc6e

Branch: refs/heads/master
Commit: 8dbabc6e1ee9dbc9f0fa116815a7ec5ad9f3f391
Parents: 504e0e1
Author: Szymon Janc <sz...@codecoup.pl>
Authored: Fri Mar 24 15:35:42 2017 +0100
Committer: Szymon Janc <sz...@codecoup.pl>
Committed: Mon Apr 10 11:31:31 2017 +0200

----------------------------------------------------------------------
 net/nimble/host/src/ble_att_clt.c  | 53 ++++++---------------------------
 net/nimble/host/src/ble_att_priv.h |  3 +-
 net/nimble/host/src/ble_gattc.c    |  4 +--
 3 files changed, 11 insertions(+), 49 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8dbabc6e/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
index d8d5d1c..76d61eb 100644
--- a/net/nimble/host/src/ble_att_clt.c
+++ b/net/nimble/host/src/ble_att_clt.c
@@ -26,36 +26,6 @@
 #include "host/ble_uuid.h"
 #include "ble_hs_priv.h"
 
-static int
-ble_att_clt_tx_req(uint16_t conn_handle, struct os_mbuf *txom)
-{
-    struct ble_l2cap_chan *chan;
-    struct ble_hs_conn *conn;
-    int rc;
-
-    BLE_HS_DBG_ASSERT_EVAL(txom->om_len >= 1);
-    ble_att_inc_tx_stat(txom->om_data[0]);
-
-    ble_hs_lock();
-
-    rc = ble_att_conn_chan_find(conn_handle, &conn, &chan);
-    if (rc != 0) {
-        rc = BLE_HS_ENOTCONN;
-    } else {
-        ble_att_truncate_to_mtu(chan, txom);
-        rc = ble_l2cap_tx(conn, chan, txom);
-        txom = NULL;
-    }
-
-    ble_hs_unlock();
-
-    if (rc != 0) {
-        os_mbuf_free_chain(txom);
-    }
-
-    return rc;
-}
-
 /*****************************************************************************
  * $error response                                                           *
  *****************************************************************************/
@@ -1015,40 +985,35 @@ err:
  *****************************************************************************/
 
 int
-ble_att_clt_tx_indicate(uint16_t conn_handle,
-                        const struct ble_att_indicate_req *req,
+ble_att_clt_tx_indicate(uint16_t conn_handle, uint16_t handle,
                         struct os_mbuf *txom)
 {
 #if !NIMBLE_BLE_ATT_CLT_INDICATE
     return BLE_HS_ENOTSUP;
 #endif
 
+    struct ble_att_indicate_req *req;
+    struct os_mbuf *txom2;
     int rc;
 
-    if (req->baiq_handle == 0) {
+    if (handle == 0) {
         rc = BLE_HS_EINVAL;
         goto err;
     }
 
-    txom = os_mbuf_prepend_pullup(txom, BLE_ATT_INDICATE_REQ_BASE_SZ);
-    if (txom == NULL) {
+    req = ble_att_cmd_get(BLE_ATT_OP_INDICATE_REQ, sizeof(*req), &txom2);
+    if (req == NULL) {
         rc = BLE_HS_ENOMEM;
         goto err;
     }
 
-    ble_att_indicate_req_write(txom->om_data, BLE_ATT_INDICATE_REQ_BASE_SZ,
-                               req);
-
-    rc = ble_att_clt_tx_req(conn_handle, txom);
-    txom = NULL;
-    if (rc != 0) {
-        goto err;
-    }
+    req->baiq_handle = htole16(handle);
+    os_mbuf_concat(txom2, txom);
 
     BLE_ATT_LOG_CMD(1, "indicate req", conn_handle, ble_att_indicate_req_log,
                     req);
 
-    return 0;
+    return ble_att_tx(conn_handle, txom2);
 
 err:
     os_mbuf_free_chain(txom);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8dbabc6e/net/nimble/host/src/ble_att_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_priv.h b/net/nimble/host/src/ble_att_priv.h
index 8457767..8e72fba 100644
--- a/net/nimble/host/src/ble_att_priv.h
+++ b/net/nimble/host/src/ble_att_priv.h
@@ -288,8 +288,7 @@ int ble_att_clt_rx_exec_write(uint16_t conn_handle, struct os_mbuf **rxom);
 int ble_att_clt_rx_write(uint16_t conn_handle, struct os_mbuf **rxom);
 int ble_att_clt_tx_notify(uint16_t conn_handle, uint16_t handle,
                           struct os_mbuf *txom);
-int ble_att_clt_tx_indicate(uint16_t conn_handle,
-                            const struct ble_att_indicate_req *req,
+int ble_att_clt_tx_indicate(uint16_t conn_handle, uint16_t handle,
                             struct os_mbuf *txom);
 int ble_att_clt_rx_indicate(uint16_t conn_handle, struct os_mbuf **rxom);
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8dbabc6e/net/nimble/host/src/ble_gattc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gattc.c b/net/nimble/host/src/ble_gattc.c
index 85111af..6594182 100644
--- a/net/nimble/host/src/ble_gattc.c
+++ b/net/nimble/host/src/ble_gattc.c
@@ -4574,7 +4574,6 @@ ble_gattc_indicate(uint16_t conn_handle, uint16_t chr_val_handle)
     return BLE_HS_ENOTSUP;
 #endif
 
-    struct ble_att_indicate_req req;
     struct ble_gattc_proc *proc;
     struct ble_hs_conn *conn;
     struct os_mbuf *om;
@@ -4611,8 +4610,7 @@ ble_gattc_indicate(uint16_t conn_handle, uint16_t chr_val_handle)
         goto done;
     }
 
-    req.baiq_handle = chr_val_handle;
-    rc = ble_att_clt_tx_indicate(conn_handle, &req, om);
+    rc = ble_att_clt_tx_indicate(conn_handle, chr_val_handle, om);
     om = NULL;
     if (rc != 0) {
         goto done;


[10/50] incubator-mynewt-core git commit: nimble/att: Use new helpers for sending Read Multiple Request

Posted by an...@apache.org.
nimble/att: Use new helpers for sending Read Multiple Request

This constructs response directly on mbuf reducing number of memcopies.


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

Branch: refs/heads/master
Commit: ab23765903ebeab9303d639fb5b52924ce5bb923
Parents: 090f62b
Author: Szymon Janc <sz...@codecoup.pl>
Authored: Fri Mar 24 15:29:05 2017 +0100
Committer: Szymon Janc <sz...@codecoup.pl>
Committed: Mon Apr 10 11:31:31 2017 +0200

----------------------------------------------------------------------
 net/nimble/host/src/ble_att_clt.c      | 61 ++++++-----------------------
 net/nimble/host/src/ble_att_cmd_priv.h |  3 ++
 2 files changed, 16 insertions(+), 48 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ab237659/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
index e85beac..95db5bb 100644
--- a/net/nimble/host/src/ble_att_clt.c
+++ b/net/nimble/host/src/ble_att_clt.c
@@ -667,71 +667,36 @@ ble_att_clt_rx_read_blob(uint16_t conn_handle, struct os_mbuf **rxom)
 /*****************************************************************************
  * $read multiple                                                            *
  *****************************************************************************/
-
-static int
-ble_att_clt_build_read_mult_req(const uint16_t *att_handles,
-                                int num_att_handles,
-                                struct os_mbuf **out_txom)
-{
-    struct os_mbuf *txom;
-    void *buf;
-    int rc;
-    int i;
-
-    *out_txom = NULL;
-
-    rc = ble_att_clt_init_req(BLE_ATT_READ_MULT_REQ_BASE_SZ, &txom);
-    if (rc != 0) {
-        goto err;
-    }
-    ble_att_read_mult_req_write(txom->om_data, txom->om_len);
-
-    for (i = 0; i < num_att_handles; i++) {
-        buf = os_mbuf_extend(txom, 2);
-        if (buf == NULL) {
-            rc = BLE_HS_ENOMEM;
-            goto err;
-        }
-
-        put_le16(buf, att_handles[i]);
-    }
-
-    *out_txom = txom;
-    return 0;
-
-err:
-    os_mbuf_free_chain(txom);
-    return rc;
-}
-
 int
-ble_att_clt_tx_read_mult(uint16_t conn_handle, const uint16_t *att_handles,
-                         int num_att_handles)
+ble_att_clt_tx_read_mult(uint16_t conn_handle, const uint16_t *handles,
+                         int num_handles)
 {
 #if !NIMBLE_BLE_ATT_CLT_READ_MULT
     return BLE_HS_ENOTSUP;
 #endif
 
+    struct ble_att_read_mult_req *req;
     struct os_mbuf *txom;
-    int rc;
+    int i;
 
     BLE_ATT_LOG_EMPTY_CMD(1, "reqd mult req", conn_handle);
 
-    if (num_att_handles < 1) {
+    if (num_handles < 1) {
         return BLE_HS_EINVAL;
     }
 
-    rc = ble_att_clt_build_read_mult_req(att_handles, num_att_handles, &txom);
-    if (rc != 0) {
-        return rc;
+    req = ble_att_cmd_get(BLE_ATT_OP_READ_MULT_REQ,
+                          sizeof(req->handles[0]) * num_handles,
+                          &txom);
+    if (req == NULL) {
+        return BLE_HS_ENOMEM;
     }
 
-    rc = ble_att_clt_tx_req(conn_handle, txom);
-    if (rc != 0) {
-        return rc;
+    for(i = 0; i < num_handles; i++) {
+        req->handles[i] = htole16(handles[i]);
     }
 
-    return 0;
+    return ble_att_tx(conn_handle, txom);
 }
 
 int

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ab237659/net/nimble/host/src/ble_att_cmd_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_cmd_priv.h b/net/nimble/host/src/ble_att_cmd_priv.h
index 17516e8..c07455a 100644
--- a/net/nimble/host/src/ble_att_cmd_priv.h
+++ b/net/nimble/host/src/ble_att_cmd_priv.h
@@ -195,6 +195,9 @@ struct ble_att_read_blob_req {
  * | Set Of Handles                     | 4 to (ATT_MTU-1)  |
  */
 #define BLE_ATT_READ_MULT_REQ_BASE_SZ   1
+struct ble_att_read_mult_req {
+        uint16_t handles[0];
+} __attribute__((packed));
 
 /**
  * | Parameter                          | Size (octets)     |


[31/50] incubator-mynewt-core git commit: nimble/att: Use packed struct for receiving Read By Group Type Request

Posted by an...@apache.org.
nimble/att: Use packed struct for receiving Read By Group Type Request

Use packed structure to map it to received mbuf instead of using
dedicated parsing function. Modern compilers generate effective code
in such case anyway.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/37cec14c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/37cec14c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/37cec14c

Branch: refs/heads/master
Commit: 37cec14c0d828dbb71febbb6ffaa2ad5ad1b6819
Parents: de742e2
Author: Szymon Janc <sz...@codecoup.pl>
Authored: Fri Mar 24 15:50:05 2017 +0100
Committer: Szymon Janc <sz...@codecoup.pl>
Committed: Mon Apr 10 11:31:32 2017 +0200

----------------------------------------------------------------------
 net/nimble/host/src/ble_att_clt.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/37cec14c/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
index a8220f4..6e91079 100644
--- a/net/nimble/host/src/ble_att_clt.c
+++ b/net/nimble/host/src/ble_att_clt.c
@@ -715,31 +715,39 @@ ble_att_clt_rx_read_group_type(uint16_t conn_handle, struct os_mbuf **rxom)
 #endif
 
     struct ble_att_read_group_type_adata adata;
-    struct ble_att_read_group_type_rsp rsp;
+    struct ble_att_read_group_type_rsp *rsp;
+    uint8_t len;
     int rc;
 
-    rc = ble_hs_mbuf_pullup_base(rxom, BLE_ATT_READ_GROUP_TYPE_RSP_BASE_SZ);
+    /* TODO move this to common part
+     * Strip L2CAP ATT header from the front of the mbuf.
+     */
+    os_mbuf_adj(*rxom, 1);
+
+    rc = ble_hs_mbuf_pullup_base(rxom, sizeof(*rsp));
     if (rc != 0) {
         goto done;
     }
 
-    ble_att_read_group_type_rsp_parse((*rxom)->om_data, (*rxom)->om_len, &rsp);
+    rsp = (struct ble_att_read_group_type_rsp *)(*rxom)->om_data;
+
     BLE_ATT_LOG_CMD(0, "read group type rsp", conn_handle,
-                    ble_att_read_group_type_rsp_log, &rsp);
+                    ble_att_read_group_type_rsp_log, rsp);
+
+    len = rsp->bagp_length;
 
     /* Strip the base from the front of the response. */
-    os_mbuf_adj(*rxom, BLE_ATT_READ_GROUP_TYPE_RSP_BASE_SZ);
+    os_mbuf_adj(*rxom, sizeof(*rsp));
 
     /* Parse the Attribute Data List field, passing each entry to GATT. */
     while (OS_MBUF_PKTLEN(*rxom) > 0) {
-        rc = ble_att_clt_parse_read_group_type_adata(rxom, rsp.bagp_length,
-                                                     &adata);
+        rc = ble_att_clt_parse_read_group_type_adata(rxom, len, &adata);
         if (rc != 0) {
             goto done;
         }
 
         ble_gattc_rx_read_group_type_adata(conn_handle, &adata);
-        os_mbuf_adj(*rxom, rsp.bagp_length);
+        os_mbuf_adj(*rxom, len);
     }
 
 done:


[24/50] incubator-mynewt-core git commit: nimble/att: Use packed struct for receiving Find By Type Response

Posted by an...@apache.org.
nimble/att: Use packed struct for receiving Find By Type Response

Use packed structure to map it to received mbuf instead of using
dedicated parsing function. Modern compilers generate effective code
in such case anyway.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/1e816573
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/1e816573
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/1e816573

Branch: refs/heads/master
Commit: 1e81657393641c3cccbc4fda600104bc7777f28e
Parents: f0949b9
Author: Szymon Janc <sz...@codecoup.pl>
Authored: Fri Mar 24 15:49:19 2017 +0100
Committer: Szymon Janc <sz...@codecoup.pl>
Committed: Mon Apr 10 11:31:32 2017 +0200

----------------------------------------------------------------------
 net/nimble/host/src/ble_att_clt.c      | 19 +++++++++++--------
 net/nimble/host/src/ble_att_cmd_priv.h |  9 +++++++++
 2 files changed, 20 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1e816573/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
index 4644b35..f3a084c 100644
--- a/net/nimble/host/src/ble_att_clt.c
+++ b/net/nimble/host/src/ble_att_clt.c
@@ -331,15 +331,20 @@ static int
 ble_att_clt_parse_find_type_value_hinfo(
     struct os_mbuf **om, struct ble_att_find_type_value_hinfo *dst)
 {
+    struct ble_att_handle_group *group;
     int rc;
 
-    rc = os_mbuf_copydata(*om, 0, BLE_ATT_FIND_TYPE_VALUE_HINFO_BASE_SZ, dst);
+    rc = ble_hs_mbuf_pullup_base(om, sizeof(*group));
     if (rc != 0) {
         return BLE_HS_EBADDATA;
     }
 
-    dst->attr_handle = TOFROMLE16(dst->attr_handle);
-    dst->group_end_handle = TOFROMLE16(dst->group_end_handle);
+    group = (struct ble_att_handle_group *)(*om)->om_data;
+
+    dst->attr_handle = le16toh(group->attr_handle);
+    dst->group_end_handle = le16toh(group->group_end_handle);
+
+    os_mbuf_adj((*om), sizeof(*group));
 
     return 0;
 }
@@ -356,11 +361,10 @@ ble_att_clt_rx_find_type_value(uint16_t conn_handle, struct os_mbuf **rxom)
 
     BLE_ATT_LOG_EMPTY_CMD(0, "find type value rsp", conn_handle);
 
-    /* Reponse consists of a one-byte opcode (already verified) and a variable
-     * length Handles-Information-List field.  Strip the opcode from the
-     * response.
+    /* TODO move this to common part
+     * Strip L2CAP ATT header from the front of the mbuf.
      */
-    os_mbuf_adj(*rxom, BLE_ATT_FIND_TYPE_VALUE_RSP_BASE_SZ);
+    os_mbuf_adj(*rxom, 1);
 
     /* Parse the Handles-Information-List field, passing each entry to GATT. */
     rc = 0;
@@ -371,7 +375,6 @@ ble_att_clt_rx_find_type_value(uint16_t conn_handle, struct os_mbuf **rxom)
         }
 
         ble_gattc_rx_find_type_value_hinfo(conn_handle, &hinfo);
-        os_mbuf_adj(*rxom, BLE_ATT_FIND_TYPE_VALUE_HINFO_BASE_SZ);
     }
 
     /* Notify GATT client that the full response has been parsed. */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1e816573/net/nimble/host/src/ble_att_cmd_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_cmd_priv.h b/net/nimble/host/src/ble_att_cmd_priv.h
index 3e03cca..4a7e491 100644
--- a/net/nimble/host/src/ble_att_cmd_priv.h
+++ b/net/nimble/host/src/ble_att_cmd_priv.h
@@ -117,6 +117,15 @@ struct ble_att_find_type_value_req {
 #define BLE_ATT_FIND_TYPE_VALUE_RSP_BASE_SZ     1
 #define BLE_ATT_FIND_TYPE_VALUE_HINFO_BASE_SZ   4
 
+struct ble_att_handle_group {
+        uint16_t attr_handle;
+        uint16_t group_end_handle;
+} __attribute__((packed));
+
+struct ble_att_find_type_value_rsp {
+    struct ble_att_handle_group list[0];
+} __attribute__((packed));
+
 /**
  * | Parameter                          | Size (octets)     |
  * +------------------------------------+-------------------+


[35/50] incubator-mynewt-core git commit: nimble/att: Use packed struct for receiving Execute Write Response

Posted by an...@apache.org.
nimble/att: Use packed struct for receiving Execute Write Response

Use packed structure to map it to received mbuf instead of using
dedicated parsing function. Modern compilers generate effective code
in such case anyway.


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

Branch: refs/heads/master
Commit: f495fa70a9a4870f306b8248c79371a0c2bade83
Parents: ca16b6b
Author: Szymon Janc <sz...@codecoup.pl>
Authored: Fri Mar 24 15:50:06 2017 +0100
Committer: Szymon Janc <sz...@codecoup.pl>
Committed: Mon Apr 10 11:31:33 2017 +0200

----------------------------------------------------------------------
 net/nimble/host/src/ble_att_clt.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f495fa70/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
index 2666eb2..4a04e70 100644
--- a/net/nimble/host/src/ble_att_clt.c
+++ b/net/nimble/host/src/ble_att_clt.c
@@ -971,17 +971,15 @@ ble_att_clt_rx_exec_write(uint16_t conn_handle, struct os_mbuf **rxom)
     return BLE_HS_ENOTSUP;
 #endif
 
-    int rc;
+    /* TODO move this to common part
+     * Strip L2CAP ATT header from the front of the mbuf.
+     */
+    os_mbuf_adj(*rxom, 1);
 
     BLE_ATT_LOG_EMPTY_CMD(0, "exec write rsp", conn_handle);
 
-    rc = ble_hs_mbuf_pullup_base(rxom, BLE_ATT_EXEC_WRITE_RSP_SZ);
-    if (rc == 0) {
-        ble_att_exec_write_rsp_parse((*rxom)->om_data, (*rxom)->om_len);
-    }
-
-    ble_gattc_rx_exec_write_rsp(conn_handle, rc);
-    return rc;
+    ble_gattc_rx_exec_write_rsp(conn_handle, 0);
+    return 0;
 }
 
 /*****************************************************************************


[18/50] incubator-mynewt-core git commit: nimble/att: Use new helpers for sending Notification

Posted by an...@apache.org.
nimble/att: Use new helpers for sending Notification

This constructs response directly on mbuf reducing number of memcopies.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/504e0e13
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/504e0e13
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/504e0e13

Branch: refs/heads/master
Commit: 504e0e132f3462275c7aef8fd1a4cc6b3b819e16
Parents: d74cc3e
Author: Szymon Janc <sz...@codecoup.pl>
Authored: Fri Mar 24 15:35:09 2017 +0100
Committer: Szymon Janc <sz...@codecoup.pl>
Committed: Mon Apr 10 11:31:31 2017 +0200

----------------------------------------------------------------------
 net/nimble/host/src/ble_att_clt.c  | 21 +++++++++------------
 net/nimble/host/src/ble_att_priv.h |  3 +--
 net/nimble/host/src/ble_gattc.c    |  4 +---
 3 files changed, 11 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/504e0e13/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
index 52c83c0..d8d5d1c 100644
--- a/net/nimble/host/src/ble_att_clt.c
+++ b/net/nimble/host/src/ble_att_clt.c
@@ -976,37 +976,34 @@ ble_att_clt_rx_exec_write(uint16_t conn_handle, struct os_mbuf **rxom)
  *****************************************************************************/
 
 int
-ble_att_clt_tx_notify(uint16_t conn_handle,
-                      const struct ble_att_notify_req *req,
+ble_att_clt_tx_notify(uint16_t conn_handle, uint16_t handle,
                       struct os_mbuf *txom)
 {
 #if !NIMBLE_BLE_ATT_CLT_NOTIFY
     return BLE_HS_ENOTSUP;
 #endif
 
+    struct ble_att_notify_req *req;
+    struct os_mbuf *txom2;
     int rc;
 
-    if (req->banq_handle == 0) {
+    if (handle == 0) {
         rc = BLE_HS_EINVAL;
         goto err;
     }
 
-    txom = os_mbuf_prepend_pullup(txom, BLE_ATT_NOTIFY_REQ_BASE_SZ);
-    if (txom == NULL) {
+    req = ble_att_cmd_get(BLE_ATT_OP_NOTIFY_REQ, sizeof(*req), &txom2);
+    if (req == NULL) {
         rc = BLE_HS_ENOMEM;
         goto err;
     }
-    ble_att_notify_req_write(txom->om_data, BLE_ATT_NOTIFY_REQ_BASE_SZ, req);
 
-    rc = ble_att_clt_tx_req(conn_handle, txom);
-    txom = NULL;
-    if (rc != 0) {
-        goto err;
-    }
+    req->banq_handle = htole16(handle);
+    os_mbuf_concat(txom2, txom);
 
     BLE_ATT_LOG_CMD(1, "notify req", conn_handle, ble_att_notify_req_log, req);
 
-    return 0;
+    return ble_att_tx(conn_handle, txom2);
 
 err:
     os_mbuf_free_chain(txom);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/504e0e13/net/nimble/host/src/ble_att_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_priv.h b/net/nimble/host/src/ble_att_priv.h
index fbc81d9..8457767 100644
--- a/net/nimble/host/src/ble_att_priv.h
+++ b/net/nimble/host/src/ble_att_priv.h
@@ -286,8 +286,7 @@ int ble_att_clt_rx_prep_write(uint16_t conn_handle, struct os_mbuf **rxom);
 int ble_att_clt_tx_exec_write(uint16_t conn_handle, uint8_t flags);
 int ble_att_clt_rx_exec_write(uint16_t conn_handle, struct os_mbuf **rxom);
 int ble_att_clt_rx_write(uint16_t conn_handle, struct os_mbuf **rxom);
-int ble_att_clt_tx_notify(uint16_t conn_handle,
-                          const struct ble_att_notify_req *req,
+int ble_att_clt_tx_notify(uint16_t conn_handle, uint16_t handle,
                           struct os_mbuf *txom);
 int ble_att_clt_tx_indicate(uint16_t conn_handle,
                             const struct ble_att_indicate_req *req,

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/504e0e13/net/nimble/host/src/ble_gattc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gattc.c b/net/nimble/host/src/ble_gattc.c
index 59fbea8..85111af 100644
--- a/net/nimble/host/src/ble_gattc.c
+++ b/net/nimble/host/src/ble_gattc.c
@@ -4405,7 +4405,6 @@ ble_gattc_notify_custom(uint16_t conn_handle, uint16_t chr_val_handle,
     return BLE_HS_ENOTSUP;
 #endif
 
-    struct ble_att_notify_req req;
     int rc;
 
     STATS_INC(ble_gattc_stats, notify);
@@ -4430,8 +4429,7 @@ ble_gattc_notify_custom(uint16_t conn_handle, uint16_t chr_val_handle,
         }
     }
 
-    req.banq_handle = chr_val_handle;
-    rc = ble_att_clt_tx_notify(conn_handle, &req, txom);
+    rc = ble_att_clt_tx_notify(conn_handle, chr_val_handle, txom);
     txom = NULL;
     if (rc != 0) {
         goto err;


[39/50] incubator-mynewt-core git commit: nimble/att: Use endian.h API for protocol data

Posted by an...@apache.org.
nimble/att: Use endian.h API for protocol data

Don't use TOFROMLE16 API for protocol data. This API hide direction of
convertion making code hard to follow.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/32db7782
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/32db7782
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/32db7782

Branch: refs/heads/master
Commit: 32db7782acd49b787d76d9afb05ea6092844f90b
Parents: d458bb8
Author: Szymon Janc <sz...@codecoup.pl>
Authored: Fri Mar 24 15:50:08 2017 +0100
Committer: Szymon Janc <sz...@codecoup.pl>
Committed: Mon Apr 10 11:31:33 2017 +0200

----------------------------------------------------------------------
 net/nimble/host/src/ble_att_cmd.c | 251 ++++++++++++---------------------
 1 file changed, 92 insertions(+), 159 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/32db7782/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
index 9fb81d1..246c7ac 100644
--- a/net/nimble/host/src/ble_att_cmd.c
+++ b/net/nimble/host/src/ble_att_cmd.c
@@ -108,15 +108,6 @@ ble_att_init_write(uint8_t op, void *payload, int min_len, int actual_len)
     return u8ptr + 1;
 }
 
-static void
-ble_att_error_rsp_swap(struct ble_att_error_rsp *dst,
-                       const struct ble_att_error_rsp *src)
-{
-    dst->baep_req_op = src->baep_req_op;
-    dst->baep_handle = TOFROMLE16(src->baep_handle);
-    dst->baep_error_code = src->baep_error_code;
-}
-
 void
 ble_att_error_rsp_parse(const void *payload, int len,
                         struct ble_att_error_rsp *dst)
@@ -125,7 +116,10 @@ ble_att_error_rsp_parse(const void *payload, int len,
 
     src = ble_att_init_parse(BLE_ATT_OP_ERROR_RSP, payload,
                              BLE_ATT_ERROR_RSP_SZ, len);
-    ble_att_error_rsp_swap(dst, src);
+
+    dst->baep_req_op = src->baep_req_op;
+    dst->baep_handle = le16toh(src->baep_handle);
+    dst->baep_error_code = src->baep_error_code;
 }
 
 void
@@ -136,7 +130,10 @@ ble_att_error_rsp_write(void *payload, int len,
 
     dst = ble_att_init_write(BLE_ATT_OP_ERROR_RSP, payload,
                              BLE_ATT_ERROR_RSP_SZ, len);
-    ble_att_error_rsp_swap(dst, src);
+
+    dst->baep_req_op = src->baep_req_op;
+    dst->baep_handle = htole16(src->baep_handle);
+    dst->baep_error_code = src->baep_error_code;
 }
 
 void
@@ -146,13 +143,6 @@ ble_att_error_rsp_log(const struct ble_att_error_rsp *cmd)
                cmd->baep_req_op, cmd->baep_handle, cmd->baep_error_code);
 }
 
-static void
-ble_att_mtu_cmd_swap(struct ble_att_mtu_cmd *dst,
-                     const struct ble_att_mtu_cmd *src)
-{
-    dst->bamc_mtu = TOFROMLE16(src->bamc_mtu);
-}
-
 void
 ble_att_mtu_req_parse(const void *payload, int len,
                       struct ble_att_mtu_cmd *dst)
@@ -161,7 +151,8 @@ ble_att_mtu_req_parse(const void *payload, int len,
 
     src = ble_att_init_parse(BLE_ATT_OP_MTU_REQ, payload, BLE_ATT_MTU_CMD_SZ,
                              len);
-    ble_att_mtu_cmd_swap(dst, src);
+
+    dst->bamc_mtu = le16toh(src->bamc_mtu);
 }
 
 void
@@ -172,7 +163,8 @@ ble_att_mtu_rsp_parse(const void *payload, int len,
 
     src = ble_att_init_parse(BLE_ATT_OP_MTU_RSP, payload, BLE_ATT_MTU_CMD_SZ,
                              len);
-    ble_att_mtu_cmd_swap(dst, src);
+
+    dst->bamc_mtu = le16toh(src->bamc_mtu);
 }
 
 void
@@ -183,7 +175,8 @@ ble_att_mtu_req_write(void *payload, int len,
 
     dst = ble_att_init_write(BLE_ATT_OP_MTU_REQ, payload,
                              BLE_ATT_MTU_CMD_SZ, len);
-    ble_att_mtu_cmd_swap(dst, src);
+
+    dst->bamc_mtu = htole16(src->bamc_mtu);
 }
 
 void
@@ -194,7 +187,7 @@ ble_att_mtu_rsp_write(void *payload, int len,
 
     dst = ble_att_init_write(BLE_ATT_OP_MTU_RSP, payload,
                              BLE_ATT_MTU_CMD_SZ, len);
-    ble_att_mtu_cmd_swap(dst, src);
+    dst->bamc_mtu = htole16(src->bamc_mtu);
 }
 
 void
@@ -203,14 +196,6 @@ ble_att_mtu_cmd_log(const struct ble_att_mtu_cmd *cmd)
     BLE_HS_LOG(DEBUG, "mtu=%d", cmd->bamc_mtu);
 }
 
-static void
-ble_att_find_info_req_swap(struct ble_att_find_info_req *dst,
-                           const struct ble_att_find_info_req *src)
-{
-    dst->bafq_start_handle = TOFROMLE16(src->bafq_start_handle);
-    dst->bafq_end_handle = TOFROMLE16(src->bafq_end_handle);
-}
-
 void
 ble_att_find_info_req_parse(const void *payload, int len,
                             struct ble_att_find_info_req *dst)
@@ -219,7 +204,9 @@ ble_att_find_info_req_parse(const void *payload, int len,
 
     src = ble_att_init_parse(BLE_ATT_OP_FIND_INFO_REQ, payload,
                              BLE_ATT_FIND_INFO_REQ_SZ, len);
-    ble_att_find_info_req_swap(dst, src);
+
+    dst->bafq_start_handle = le16toh(src->bafq_start_handle);
+    dst->bafq_end_handle = le16toh(src->bafq_end_handle);
 }
 
 void
@@ -230,7 +217,9 @@ ble_att_find_info_req_write(void *payload, int len,
 
     dst = ble_att_init_write(BLE_ATT_OP_FIND_INFO_REQ, payload,
                              BLE_ATT_FIND_INFO_REQ_SZ, len);
-    ble_att_find_info_req_swap(dst, src);
+
+    dst->bafq_start_handle = htole16(src->bafq_start_handle);
+    dst->bafq_end_handle = htole16(src->bafq_end_handle);
 }
 
 void
@@ -240,13 +229,6 @@ ble_att_find_info_req_log(const struct ble_att_find_info_req *cmd)
                cmd->bafq_start_handle, cmd->bafq_end_handle);
 }
 
-static void
-ble_att_find_info_rsp_swap(struct ble_att_find_info_rsp *dst,
-                           const struct ble_att_find_info_rsp *src)
-{
-    dst->bafp_format = src->bafp_format;
-}
-
 void
 ble_att_find_info_rsp_parse(const void *payload, int len,
                             struct ble_att_find_info_rsp *dst)
@@ -255,7 +237,8 @@ ble_att_find_info_rsp_parse(const void *payload, int len,
 
     src = ble_att_init_parse(BLE_ATT_OP_FIND_INFO_RSP, payload,
                              BLE_ATT_FIND_INFO_RSP_BASE_SZ, len);
-    ble_att_find_info_rsp_swap(dst, src);
+
+    dst->bafp_format = src->bafp_format;
 }
 
 void
@@ -266,7 +249,8 @@ ble_att_find_info_rsp_write(void *payload, int len,
 
     dst = ble_att_init_write(BLE_ATT_OP_FIND_INFO_RSP, payload,
                              BLE_ATT_FIND_INFO_RSP_BASE_SZ, len);
-    ble_att_find_info_rsp_swap(dst, src);
+
+    dst->bafp_format = src->bafp_format;
 }
 
 void
@@ -275,15 +259,6 @@ ble_att_find_info_rsp_log(const struct ble_att_find_info_rsp *cmd)
     BLE_HS_LOG(DEBUG, "format=%d", cmd->bafp_format);
 }
 
-static void
-ble_att_find_type_value_req_swap(struct ble_att_find_type_value_req *dst,
-                                 const struct ble_att_find_type_value_req *src)
-{
-    dst->bavq_start_handle = TOFROMLE16(src->bavq_start_handle);
-    dst->bavq_end_handle = TOFROMLE16(src->bavq_end_handle);
-    dst->bavq_attr_type = TOFROMLE16(src->bavq_attr_type);
-}
-
 void
 ble_att_find_type_value_req_parse(const void *payload, int len,
                                   struct ble_att_find_type_value_req *dst)
@@ -292,7 +267,10 @@ ble_att_find_type_value_req_parse(const void *payload, int len,
 
     src = ble_att_init_parse(BLE_ATT_OP_FIND_TYPE_VALUE_REQ, payload,
                              BLE_ATT_FIND_TYPE_VALUE_REQ_BASE_SZ, len);
-    ble_att_find_type_value_req_swap(dst, src);
+
+    dst->bavq_start_handle = le16toh(src->bavq_start_handle);
+    dst->bavq_end_handle = le16toh(src->bavq_end_handle);
+    dst->bavq_attr_type = le16toh(src->bavq_attr_type);
 }
 
 void
@@ -303,7 +281,10 @@ ble_att_find_type_value_req_write(
 
     dst = ble_att_init_write(BLE_ATT_OP_FIND_TYPE_VALUE_REQ, payload,
                              BLE_ATT_FIND_TYPE_VALUE_REQ_BASE_SZ, len);
-    ble_att_find_type_value_req_swap(dst, src);
+
+    dst->bavq_start_handle = htole16(src->bavq_start_handle);
+    dst->bavq_end_handle = htole16(src->bavq_end_handle);
+    dst->bavq_attr_type = htole16(src->bavq_attr_type);
 }
 
 void
@@ -314,14 +295,6 @@ ble_att_find_type_value_req_log(const struct ble_att_find_type_value_req *cmd)
                cmd->bavq_attr_type);
 }
 
-static void
-ble_att_read_type_req_swap(struct ble_att_read_type_req *dst,
-                           const struct ble_att_read_type_req *src)
-{
-    dst->batq_start_handle = TOFROMLE16(src->batq_start_handle);
-    dst->batq_end_handle = TOFROMLE16(src->batq_end_handle);
-}
-
 void
 ble_att_read_type_req_parse(const void *payload, int len,
                             struct ble_att_read_type_req *dst)
@@ -330,7 +303,9 @@ ble_att_read_type_req_parse(const void *payload, int len,
 
     src = ble_att_init_parse(BLE_ATT_OP_READ_TYPE_REQ, payload,
                              BLE_ATT_READ_TYPE_REQ_BASE_SZ, len);
-    ble_att_read_type_req_swap(dst, src);
+
+    dst->batq_start_handle = le16toh(src->batq_start_handle);
+    dst->batq_end_handle = le16toh(src->batq_end_handle);
 }
 
 void
@@ -341,7 +316,9 @@ ble_att_read_type_req_write(void *payload, int len,
 
     dst = ble_att_init_write(BLE_ATT_OP_READ_TYPE_REQ, payload,
                              BLE_ATT_READ_TYPE_REQ_BASE_SZ, len);
-    ble_att_read_type_req_swap(dst, src);
+
+    dst->batq_start_handle = htole16(src->batq_start_handle);
+    dst->batq_end_handle = htole16(src->batq_end_handle);
 }
 
 void
@@ -351,13 +328,6 @@ ble_att_read_type_req_log(const struct ble_att_read_type_req *cmd)
                cmd->batq_start_handle, cmd->batq_end_handle);
 }
 
-static void
-ble_att_read_type_rsp_swap(struct ble_att_read_type_rsp *dst,
-                           const struct ble_att_read_type_rsp *src)
-{
-    dst->batp_length = src->batp_length;
-}
-
 void
 ble_att_read_type_rsp_parse(const void *payload, int len,
                             struct ble_att_read_type_rsp *dst)
@@ -366,7 +336,8 @@ ble_att_read_type_rsp_parse(const void *payload, int len,
 
     src = ble_att_init_parse(BLE_ATT_OP_READ_TYPE_RSP, payload,
                              BLE_ATT_READ_TYPE_RSP_BASE_SZ, len);
-    ble_att_read_type_rsp_swap(dst, src);
+
+    dst->batp_length = src->batp_length;
 }
 
 void
@@ -377,7 +348,8 @@ ble_att_read_type_rsp_write(void *payload, int len,
 
     dst = ble_att_init_write(BLE_ATT_OP_READ_TYPE_RSP, payload,
                              BLE_ATT_READ_TYPE_RSP_BASE_SZ, len);
-    ble_att_read_type_rsp_swap(dst, src);
+
+    dst->batp_length = src->batp_length;
 }
 
 void
@@ -386,13 +358,6 @@ ble_att_read_type_rsp_log(const struct ble_att_read_type_rsp *cmd)
     BLE_HS_LOG(DEBUG, "length=%d", cmd->batp_length);
 }
 
-static void
-ble_att_read_req_swap(struct ble_att_read_req *dst,
-                      const struct ble_att_read_req *src)
-{
-    dst->barq_handle = TOFROMLE16(src->barq_handle);
-}
-
 void
 ble_att_read_req_parse(const void *payload, int len,
                        struct ble_att_read_req *dst)
@@ -401,7 +366,8 @@ ble_att_read_req_parse(const void *payload, int len,
 
     src = ble_att_init_parse(BLE_ATT_OP_READ_REQ, payload,
                              BLE_ATT_READ_REQ_SZ, len);
-    ble_att_read_req_swap(dst, src);
+
+    dst->barq_handle = le16toh(src->barq_handle);
 }
 
 void
@@ -412,7 +378,8 @@ ble_att_read_req_write(void *payload, int len,
 
     dst = ble_att_init_write(BLE_ATT_OP_READ_REQ, payload,
                              BLE_ATT_READ_REQ_SZ, len);
-    ble_att_read_req_swap(dst, src);
+
+    dst->barq_handle = htole16(src->barq_handle);
 }
 
 void
@@ -421,14 +388,6 @@ ble_att_read_req_log(const struct ble_att_read_req *cmd)
     BLE_HS_LOG(DEBUG, "handle=0x%04x", cmd->barq_handle);
 }
 
-static void
-ble_att_read_blob_req_swap(struct ble_att_read_blob_req *dst,
-                           const struct ble_att_read_blob_req *src)
-{
-    dst->babq_handle = TOFROMLE16(src->babq_handle);
-    dst->babq_offset = TOFROMLE16(src->babq_offset);
-}
-
 void
 ble_att_read_blob_req_parse(const void *payload, int len,
                             struct ble_att_read_blob_req *dst)
@@ -437,7 +396,9 @@ ble_att_read_blob_req_parse(const void *payload, int len,
 
     src = ble_att_init_parse(BLE_ATT_OP_READ_BLOB_REQ, payload,
                              BLE_ATT_READ_BLOB_REQ_SZ, len);
-    ble_att_read_blob_req_swap(dst, src);
+
+    dst->babq_handle = le16toh(src->babq_handle);
+    dst->babq_offset = le16toh(src->babq_offset);
 }
 
 void
@@ -448,7 +409,9 @@ ble_att_read_blob_req_write(void *payload, int len,
 
     dst = ble_att_init_write(BLE_ATT_OP_READ_BLOB_REQ, payload,
                              BLE_ATT_READ_BLOB_REQ_SZ, len);
-    ble_att_read_blob_req_swap(dst, src);
+
+    dst->babq_handle = htole16(src->babq_handle);
+    dst->babq_offset = htole16(src->babq_offset);
 }
 
 void
@@ -486,14 +449,6 @@ ble_att_read_mult_rsp_write(void *payload, int len)
                        BLE_ATT_READ_MULT_RSP_BASE_SZ, len);
 }
 
-static void
-ble_att_read_group_type_req_swap(struct ble_att_read_group_type_req *dst,
-                                 const struct ble_att_read_group_type_req *src)
-{
-    dst->bagq_start_handle = TOFROMLE16(src->bagq_start_handle);
-    dst->bagq_end_handle = TOFROMLE16(src->bagq_end_handle);
-}
-
 void
 ble_att_read_group_type_req_parse(const void *payload, int len,
                                   struct ble_att_read_group_type_req *dst)
@@ -502,7 +457,9 @@ ble_att_read_group_type_req_parse(const void *payload, int len,
 
     src = ble_att_init_parse(BLE_ATT_OP_READ_GROUP_TYPE_REQ, payload,
                              BLE_ATT_READ_GROUP_TYPE_REQ_BASE_SZ, len);
-    ble_att_read_group_type_req_swap(dst, src);
+
+    dst->bagq_start_handle = le16toh(src->bagq_start_handle);
+    dst->bagq_end_handle = le16toh(src->bagq_end_handle);
 }
 
 void
@@ -513,7 +470,9 @@ ble_att_read_group_type_req_write(
 
     dst = ble_att_init_write(BLE_ATT_OP_READ_GROUP_TYPE_REQ, payload,
                              BLE_ATT_READ_GROUP_TYPE_REQ_BASE_SZ, len);
-    ble_att_read_group_type_req_swap(dst, src);
+
+    dst->bagq_start_handle = htole16(src->bagq_start_handle);
+    dst->bagq_end_handle = htole16(src->bagq_end_handle);
 }
 
 void
@@ -523,13 +482,6 @@ ble_att_read_group_type_req_log(const struct ble_att_read_group_type_req *cmd)
                cmd->bagq_start_handle, cmd->bagq_end_handle);
 }
 
-static void
-ble_att_read_group_type_rsp_swap(struct ble_att_read_group_type_rsp *dst,
-                                 const struct ble_att_read_group_type_rsp *src)
-{
-    dst->bagp_length = src->bagp_length;
-}
-
 void
 ble_att_read_group_type_rsp_parse(const void *payload, int len,
                                   struct ble_att_read_group_type_rsp *dst)
@@ -538,7 +490,8 @@ ble_att_read_group_type_rsp_parse(const void *payload, int len,
 
     src = ble_att_init_parse(BLE_ATT_OP_READ_GROUP_TYPE_RSP, payload,
                              BLE_ATT_READ_GROUP_TYPE_RSP_BASE_SZ, len);
-    ble_att_read_group_type_rsp_swap(dst, src);
+
+    dst->bagp_length = src->bagp_length;
 }
 
 void
@@ -549,7 +502,8 @@ ble_att_read_group_type_rsp_write(
 
     dst = ble_att_init_write(BLE_ATT_OP_READ_GROUP_TYPE_RSP, payload,
                              BLE_ATT_READ_GROUP_TYPE_RSP_BASE_SZ, len);
-    ble_att_read_group_type_rsp_swap(dst, src);
+
+    dst->bagp_length = src->bagp_length;
 }
 
 void
@@ -558,13 +512,6 @@ ble_att_read_group_type_rsp_log(const struct ble_att_read_group_type_rsp *cmd)
     BLE_HS_LOG(DEBUG, "length=%d", cmd->bagp_length);
 }
 
-static void
-ble_att_write_req_swap(struct ble_att_write_req *dst,
-                       const struct ble_att_write_req *src)
-{
-    dst->bawq_handle = TOFROMLE16(src->bawq_handle);
-}
-
 void
 ble_att_write_req_parse(const void *payload, int len,
                         struct ble_att_write_req *dst)
@@ -573,7 +520,8 @@ ble_att_write_req_parse(const void *payload, int len,
 
     src = ble_att_init_parse(BLE_ATT_OP_WRITE_REQ, payload,
                              BLE_ATT_WRITE_REQ_BASE_SZ, len);
-    ble_att_write_req_swap(dst, src);
+
+    dst->bawq_handle = le16toh(src->bawq_handle);
 }
 
 void
@@ -584,7 +532,7 @@ ble_att_write_cmd_parse(const void *payload, int len,
 
     src = ble_att_init_parse(BLE_ATT_OP_WRITE_CMD, payload,
                              BLE_ATT_WRITE_REQ_BASE_SZ, len);
-    ble_att_write_req_swap(dst, src);
+    dst->bawq_handle = le16toh(src->bawq_handle);
 }
 
 void
@@ -595,7 +543,7 @@ ble_att_write_req_write(void *payload, int len,
 
     dst = ble_att_init_write(BLE_ATT_OP_WRITE_REQ, payload,
                              BLE_ATT_WRITE_REQ_BASE_SZ, len);
-    ble_att_write_req_swap(dst, src);
+    dst->bawq_handle = htole16(src->bawq_handle);
 }
 
 void
@@ -606,7 +554,7 @@ ble_att_write_cmd_write(void *payload, int len,
 
     dst = ble_att_init_write(BLE_ATT_OP_WRITE_CMD, payload,
                              BLE_ATT_WRITE_REQ_BASE_SZ, len);
-    ble_att_write_req_swap(dst, src);
+    dst->bawq_handle = htole16(src->bawq_handle);
 }
 
 void
@@ -621,14 +569,6 @@ ble_att_write_req_log(const struct ble_att_write_req *req)
     BLE_HS_LOG(DEBUG, "handle=0x%04x", req->bawq_handle);
 }
 
-static void
-ble_att_prep_write_cmd_swap(struct ble_att_prep_write_cmd *dst,
-                            const struct ble_att_prep_write_cmd *src)
-{
-    dst->bapc_handle = TOFROMLE16(src->bapc_handle);
-    dst->bapc_offset = TOFROMLE16(src->bapc_offset);
-}
-
 void
 ble_att_prep_write_req_parse(const void *payload, int len,
                              struct ble_att_prep_write_cmd *dst)
@@ -637,7 +577,9 @@ ble_att_prep_write_req_parse(const void *payload, int len,
 
     src = ble_att_init_parse(BLE_ATT_OP_PREP_WRITE_REQ, payload,
                              BLE_ATT_PREP_WRITE_CMD_BASE_SZ, len);
-    ble_att_prep_write_cmd_swap(dst, src);
+
+    dst->bapc_handle = le16toh(src->bapc_handle);
+    dst->bapc_offset = le16toh(src->bapc_offset);
 }
 
 void
@@ -648,7 +590,9 @@ ble_att_prep_write_req_write(void *payload, int len,
 
     dst = ble_att_init_write(BLE_ATT_OP_PREP_WRITE_REQ, payload,
                              BLE_ATT_PREP_WRITE_CMD_BASE_SZ, len);
-    ble_att_prep_write_cmd_swap(dst, src);
+
+    dst->bapc_handle = htole16(src->bapc_handle);
+    dst->bapc_offset = htole16(src->bapc_offset);
 }
 
 void
@@ -659,7 +603,9 @@ ble_att_prep_write_rsp_parse(const void *payload, int len,
 
     src = ble_att_init_parse(BLE_ATT_OP_PREP_WRITE_RSP, payload,
                              BLE_ATT_PREP_WRITE_CMD_BASE_SZ, len);
-    ble_att_prep_write_cmd_swap(dst, src);
+
+    dst->bapc_handle = le16toh(src->bapc_handle);
+    dst->bapc_offset = le16toh(src->bapc_offset);
 }
 
 void
@@ -670,7 +616,9 @@ ble_att_prep_write_rsp_write(void *payload, int len,
 
     dst = ble_att_init_write(BLE_ATT_OP_PREP_WRITE_RSP, payload,
                              BLE_ATT_PREP_WRITE_CMD_BASE_SZ, len);
-    ble_att_prep_write_cmd_swap(dst, src);
+
+    dst->bapc_handle = htole16(src->bapc_handle);
+    dst->bapc_offset = htole16(src->bapc_offset);
 }
 
 void
@@ -680,13 +628,6 @@ ble_att_prep_write_cmd_log(const struct ble_att_prep_write_cmd *cmd)
                cmd->bapc_offset);
 }
 
-static void
-ble_att_exec_write_req_swap(struct ble_att_exec_write_req *dst,
-                            const struct ble_att_exec_write_req *src)
-{
-    dst->baeq_flags = src->baeq_flags;
-}
-
 void
 ble_att_exec_write_req_parse(const void *payload, int len,
                              struct ble_att_exec_write_req *dst)
@@ -695,7 +636,8 @@ ble_att_exec_write_req_parse(const void *payload, int len,
 
     src = ble_att_init_parse(BLE_ATT_OP_EXEC_WRITE_REQ, payload,
                              BLE_ATT_EXEC_WRITE_REQ_SZ, len);
-    ble_att_exec_write_req_swap(dst, src);
+
+    dst->baeq_flags = src->baeq_flags;
 }
 
 void
@@ -706,7 +648,8 @@ ble_att_exec_write_req_write(void *payload, int len,
 
     dst = ble_att_init_write(BLE_ATT_OP_EXEC_WRITE_REQ, payload,
                              BLE_ATT_EXEC_WRITE_REQ_SZ, len);
-    ble_att_exec_write_req_swap(dst, src);
+
+    dst->baeq_flags = src->baeq_flags;
 }
 
 void
@@ -729,13 +672,6 @@ ble_att_exec_write_rsp_write(void *payload, int len)
                        BLE_ATT_EXEC_WRITE_RSP_SZ, len);
 }
 
-static void
-ble_att_notify_req_swap(struct ble_att_notify_req *dst,
-                        const struct ble_att_notify_req *src)
-{
-    dst->banq_handle = TOFROMLE16(src->banq_handle);
-}
-
 void
 ble_att_notify_req_parse(const void *payload, int len,
                          struct ble_att_notify_req *dst)
@@ -744,7 +680,8 @@ ble_att_notify_req_parse(const void *payload, int len,
 
     src = ble_att_init_parse(BLE_ATT_OP_NOTIFY_REQ, payload,
                              BLE_ATT_NOTIFY_REQ_BASE_SZ, len);
-    ble_att_notify_req_swap(dst, src);
+
+    dst->banq_handle = le16toh(src->banq_handle);
 }
 
 void
@@ -755,7 +692,8 @@ ble_att_notify_req_write(void *payload, int len,
 
     dst = ble_att_init_write(BLE_ATT_OP_NOTIFY_REQ, payload,
                              BLE_ATT_NOTIFY_REQ_BASE_SZ, len);
-    ble_att_notify_req_swap(dst, src);
+
+    dst->banq_handle = htole16(src->banq_handle);
 }
 
 void
@@ -764,13 +702,6 @@ ble_att_notify_req_log(const struct ble_att_notify_req *cmd)
     BLE_HS_LOG(DEBUG, "handle=0x%04x", cmd->banq_handle);
 }
 
-static void
-ble_att_indicate_req_swap(struct ble_att_indicate_req *dst,
-                          const struct ble_att_indicate_req *src)
-{
-    dst->baiq_handle = TOFROMLE16(src->baiq_handle);
-}
-
 void
 ble_att_indicate_req_parse(const void *payload, int len,
                            struct ble_att_indicate_req *dst)
@@ -779,7 +710,8 @@ ble_att_indicate_req_parse(const void *payload, int len,
 
     src = ble_att_init_parse(BLE_ATT_OP_INDICATE_REQ, payload,
                              BLE_ATT_INDICATE_REQ_BASE_SZ, len);
-    ble_att_indicate_req_swap(dst, src);
+
+    dst->baiq_handle = le16toh(src->baiq_handle);
 }
 
 void
@@ -790,7 +722,8 @@ ble_att_indicate_req_write(void *payload, int len,
 
     dst = ble_att_init_write(BLE_ATT_OP_INDICATE_REQ, payload,
                              BLE_ATT_INDICATE_REQ_BASE_SZ, len);
-    ble_att_indicate_req_swap(dst, src);
+
+    dst->baiq_handle = htole16(src->baiq_handle);
 }
 
 void


[04/50] incubator-mynewt-core git commit: nimble/att: Use packed struct for receiving Error Response

Posted by an...@apache.org.
nimble/att: Use packed struct for receiving Error Response

Use packed structure to map it to received mbuf instead of using
dedicated parsing function. Modern compilers generate effective code
in such case anyway.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/8e602737
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/8e602737
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/8e602737

Branch: refs/heads/master
Commit: 8e602737948270f5d40369d354f485a41ef94caa
Parents: a63f7d3
Author: Szymon Janc <sz...@codecoup.pl>
Authored: Fri Mar 24 15:40:05 2017 +0100
Committer: Szymon Janc <sz...@codecoup.pl>
Committed: Mon Apr 10 11:31:31 2017 +0200

----------------------------------------------------------------------
 net/nimble/host/src/ble_att_clt.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8e602737/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
index cbd41c9..c63ec52 100644
--- a/net/nimble/host/src/ble_att_clt.c
+++ b/net/nimble/host/src/ble_att_clt.c
@@ -33,18 +33,25 @@
 int
 ble_att_clt_rx_error(uint16_t conn_handle, struct os_mbuf **rxom)
 {
-    struct ble_att_error_rsp rsp;
+    struct ble_att_error_rsp *rsp;
     int rc;
 
-    rc = ble_hs_mbuf_pullup_base(rxom, BLE_ATT_ERROR_RSP_SZ);
+    /* TODO move this to common part
+     * Strip L2CAP ATT header from the front of the mbuf.
+     */
+    os_mbuf_adj(*rxom, 1);
+
+    rc = ble_hs_mbuf_pullup_base(rxom, sizeof(*rsp));
     if (rc != 0) {
         return rc;
     }
 
-    ble_att_error_rsp_parse((*rxom)->om_data, (*rxom)->om_len, &rsp);
-    BLE_ATT_LOG_CMD(0, "error rsp", conn_handle, ble_att_error_rsp_log, &rsp);
+    rsp = (struct ble_att_error_rsp *)(*rxom)->om_data;
+
+    BLE_ATT_LOG_CMD(0, "error rsp", conn_handle, ble_att_error_rsp_log, rsp);
 
-    ble_gattc_rx_err(conn_handle, rsp.baep_handle, rsp.baep_error_code);
+    ble_gattc_rx_err(conn_handle, le16toh(rsp->baep_handle),
+                     le16toh(rsp->baep_error_code));
 
     return 0;
 }


[19/50] incubator-mynewt-core git commit: nimble/att: Use packed struct for receiving Find By Type Request

Posted by an...@apache.org.
nimble/att: Use packed struct for receiving Find By Type Request

Use packed structure to map it to received mbuf instead of using
dedicated parsing function. Modern compilers generate effective code
in such case anyway.


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

Branch: refs/heads/master
Commit: f0949b9f61a1ffd0be7083874c37d96c79c6fe1c
Parents: fefbc81
Author: Szymon Janc <sz...@codecoup.pl>
Authored: Fri Mar 24 15:49:10 2017 +0100
Committer: Szymon Janc <sz...@codecoup.pl>
Committed: Mon Apr 10 11:31:32 2017 +0200

----------------------------------------------------------------------
 net/nimble/host/src/ble_att_svr.c | 58 +++++++++++++++++++---------------
 1 file changed, 33 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f0949b9f/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
index 52d54b6..022a0fb 100644
--- a/net/nimble/host/src/ble_att_svr.c
+++ b/net/nimble/host/src/ble_att_svr.c
@@ -1085,7 +1085,8 @@ ble_att_svr_is_valid_group_end(const ble_uuid_t *uuid_group,
  */
 static int
 ble_att_svr_fill_type_value(uint16_t conn_handle,
-                            struct ble_att_find_type_value_req *req,
+                            uint16_t start_handle, uint16_t end_handle,
+                            ble_uuid16_t attr_type,
                             struct os_mbuf *rxom, struct os_mbuf *txom,
                             uint16_t mtu, uint8_t *out_att_err)
 {
@@ -1094,13 +1095,11 @@ ble_att_svr_fill_type_value(uint16_t conn_handle,
     uint16_t attr_len;
     uint16_t first;
     uint16_t prev;
-    ble_uuid16_t attr_type;
     int any_entries;
     int rc;
 
     first = 0;
     prev = 0;
-    attr_type = (ble_uuid16_t) BLE_UUID16_INIT(req->bavq_attr_type);
     rc = 0;
 
     /* Iterate through the attribute list, keeping track of the current
@@ -1108,12 +1107,12 @@ ble_att_svr_fill_type_value(uint16_t conn_handle,
      * written to the response.
      */
     STAILQ_FOREACH(ha, &ble_att_svr_list, ha_next) {
-        if (ha->ha_handle_id < req->bavq_start_handle) {
+        if (ha->ha_handle_id < start_handle) {
             continue;
         }
 
         /* Continue to look for end of group in case group is in progress. */
-        if (!first && ha->ha_handle_id > req->bavq_end_handle) {
+        if (!first && ha->ha_handle_id > end_handle) {
             break;
         }
 
@@ -1135,7 +1134,7 @@ ble_att_svr_fill_type_value(uint16_t conn_handle,
 
             /* Break in case we were just looking for end of group past the end
              * handle ID. */
-            if (ha->ha_handle_id > req->bavq_end_handle) {
+            if (ha->ha_handle_id > end_handle) {
                 break;
             }
         }
@@ -1149,7 +1148,8 @@ ble_att_svr_fill_type_value(uint16_t conn_handle,
             if (rc != 0) {
                 goto done;
             }
-            rc = os_mbuf_cmpf(rxom, BLE_ATT_FIND_TYPE_VALUE_REQ_BASE_SZ,
+            /* value is at the end of req */
+            rc = os_mbuf_cmpf(rxom, sizeof(struct ble_att_find_type_value_req),
                               buf, attr_len);
             if (rc == 0) {
                 first = ha->ha_handle_id;
@@ -1184,7 +1184,9 @@ done:
 
 static int
 ble_att_svr_build_find_type_value_rsp(uint16_t conn_handle,
-                                      struct ble_att_find_type_value_req *req,
+                                      uint16_t start_handle,
+                                      uint16_t end_handle,
+                                      ble_uuid16_t attr_type,
                                       struct os_mbuf **rxom,
                                       struct os_mbuf **out_txom,
                                       uint8_t *out_att_err)
@@ -1199,19 +1201,19 @@ ble_att_svr_build_find_type_value_rsp(uint16_t conn_handle,
         goto done;
     }
 
-    /* Write the response base at the start of the buffer. */
-    buf = os_mbuf_extend(txom, BLE_ATT_FIND_TYPE_VALUE_RSP_BASE_SZ);
+    /* info list is filled later on */
+    buf = ble_att_cmd_prepare(BLE_ATT_OP_FIND_TYPE_VALUE_RSP, 0, txom);
     if (buf == NULL) {
         *out_att_err = BLE_ATT_ERR_INSUFFICIENT_RES;
         rc = BLE_HS_ENOMEM;
         goto done;
     }
-    buf[0] = BLE_ATT_OP_FIND_TYPE_VALUE_RSP;
 
     /* Write the variable length Information Data field. */
     mtu = ble_att_mtu(conn_handle);
 
-    rc = ble_att_svr_fill_type_value(conn_handle, req, *rxom, txom, mtu,
+    rc = ble_att_svr_fill_type_value(conn_handle, start_handle, end_handle,
+                                     attr_type, *rxom, txom, mtu,
                                      out_att_err);
     if (rc != 0) {
         goto done;
@@ -1233,44 +1235,50 @@ ble_att_svr_rx_find_type_value(uint16_t conn_handle, struct os_mbuf **rxom)
     return BLE_HS_ENOTSUP;
 #endif
 
-    struct ble_att_find_type_value_req req;
+    struct ble_att_find_type_value_req *req;
+    uint16_t start_handle, end_handle;
+    ble_uuid16_t attr_type;
     struct os_mbuf *txom;
     uint16_t err_handle;
     uint8_t att_err;
     int rc;
 
+    /* TODO move this to common part
+    * Strip L2CAP ATT header from the front of the mbuf.
+    */
+    os_mbuf_adj(*rxom, 1);
+
     /* Initialize some values in case of early error. */
     txom = NULL;
     att_err = 0;
     err_handle = 0;
 
-    rc = ble_att_svr_pullup_req_base(rxom, BLE_ATT_FIND_TYPE_VALUE_REQ_BASE_SZ,
-                                     &att_err);
+    rc = ble_att_svr_pullup_req_base(rxom, sizeof(*req), &att_err);
     if (rc != 0) {
-        err_handle = 0;
         goto done;
     }
 
-    ble_att_find_type_value_req_parse((*rxom)->om_data, (*rxom)->om_len, &req);
+    req = (struct ble_att_find_type_value_req *)(*rxom)->om_data;
+    start_handle = le16toh(req->bavq_start_handle);
+    end_handle = le16toh(req->bavq_end_handle);
+    attr_type = (ble_uuid16_t) BLE_UUID16_INIT(le16toh(req->bavq_attr_type));
     BLE_ATT_LOG_CMD(0, "find type value req", conn_handle,
-                    ble_att_find_type_value_req_log, &req);
+                    ble_att_find_type_value_req_log, req);
 
     /* 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.bavq_start_handle > req.bavq_end_handle ||
-        req.bavq_start_handle == 0) {
-
+    if (start_handle > end_handle || start_handle == 0) {
         att_err = BLE_ATT_ERR_INVALID_HANDLE;
-        err_handle = req.bavq_start_handle;
+        err_handle = start_handle;
         rc = BLE_HS_EBADDATA;
         goto done;
     }
-
-    rc = ble_att_svr_build_find_type_value_rsp(conn_handle, &req, rxom,
+    rc = ble_att_svr_build_find_type_value_rsp(conn_handle, start_handle,
+                                               end_handle, attr_type, rxom,
                                                &txom, &att_err);
     if (rc != 0) {
-        err_handle = req.bavq_start_handle;
+        err_handle = start_handle;
         goto done;
     }
 


[38/50] incubator-mynewt-core git commit: nimble/att: Use packed struct for receiving Prepare Write Response

Posted by an...@apache.org.
nimble/att: Use packed struct for receiving Prepare Write Response

Use packed structure to map it to received mbuf instead of using
dedicated parsing function. Modern compilers generate effective code
in such case anyway.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/2b2c14e7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/2b2c14e7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/2b2c14e7

Branch: refs/heads/master
Commit: 2b2c14e71f9308014c2c13f58681c1c4f2a9586c
Parents: 3a3571e
Author: Szymon Janc <sz...@codecoup.pl>
Authored: Fri Mar 24 15:50:06 2017 +0100
Committer: Szymon Janc <sz...@codecoup.pl>
Committed: Mon Apr 10 11:31:33 2017 +0200

----------------------------------------------------------------------
 net/nimble/host/src/ble_att_clt.c | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2b2c14e7/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
index 6e91079..2666eb2 100644
--- a/net/nimble/host/src/ble_att_clt.c
+++ b/net/nimble/host/src/ble_att_clt.c
@@ -897,28 +897,37 @@ ble_att_clt_rx_prep_write(uint16_t conn_handle, struct os_mbuf **rxom)
     return BLE_HS_ENOTSUP;
 #endif
 
-    struct ble_att_prep_write_cmd rsp;
+    struct ble_att_prep_write_cmd *rsp;
+    uint16_t handle, offset;
     int rc;
 
+    /* TODO move this to common part
+     * Strip L2CAP ATT header from the front of the mbuf.
+     */
+    os_mbuf_adj(*rxom, 1);
+
     /* Initialize some values in case of early error. */
-    memset(&rsp, 0, sizeof rsp);
+    handle = 0;
+    offset = 0;
 
-    rc = ble_hs_mbuf_pullup_base(rxom, BLE_ATT_PREP_WRITE_CMD_BASE_SZ);
+    rc = ble_hs_mbuf_pullup_base(rxom, sizeof(*rsp));
     if (rc != 0) {
         goto done;
     }
 
-    ble_att_prep_write_rsp_parse((*rxom)->om_data, (*rxom)->om_len, &rsp);
+    rsp = (struct ble_att_prep_write_cmd *)(*rxom)->om_data;
     BLE_ATT_LOG_CMD(0, "prep write rsp", conn_handle,
-                    ble_att_prep_write_cmd_log, &rsp);
+                    ble_att_prep_write_cmd_log, rsp);
+
+    handle = le16toh(rsp->bapc_handle);
+    offset = le16toh(rsp->bapc_offset);
 
     /* Strip the base from the front of the response. */
-    os_mbuf_adj(*rxom, BLE_ATT_PREP_WRITE_CMD_BASE_SZ);
+    os_mbuf_adj(*rxom, sizeof(*rsp));
 
 done:
     /* Notify GATT client that the full response has been parsed. */
-    ble_gattc_rx_prep_write_rsp(conn_handle, rc, rsp.bapc_handle,
-                                rsp.bapc_offset, rxom);
+    ble_gattc_rx_prep_write_rsp(conn_handle, rc, handle, offset, rxom);
     return rc;
 }