You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by vi...@apache.org on 2016/11/21 21:22:30 UTC

incubator-mynewt-core git commit: MYNEWT-489 Changes to newtmgr fragmentation code

Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/develop cee601816 -> 543fb9703


MYNEWT-489 Changes to newtmgr fragmentation code

- Removing RSP_COMPLETE flag
- Removing newtmgr headers from subsequent chunks


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

Branch: refs/heads/develop
Commit: 543fb970386dbc12df153117cf8b92c6073708fd
Parents: cee6018
Author: Vipul Rahane <vi...@apache.org>
Authored: Mon Nov 21 13:14:39 2016 -0800
Committer: Vipul Rahane <vi...@apache.org>
Committed: Mon Nov 21 13:14:39 2016 -0800

----------------------------------------------------------------------
 mgmt/newtmgr/include/newtmgr/newtmgr.h |  2 --
 mgmt/newtmgr/src/newtmgr.c             | 49 ++++++++++-------------------
 2 files changed, 17 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/543fb970/mgmt/newtmgr/include/newtmgr/newtmgr.h
----------------------------------------------------------------------
diff --git a/mgmt/newtmgr/include/newtmgr/newtmgr.h b/mgmt/newtmgr/include/newtmgr/newtmgr.h
index 98e7374..3c3081a 100644
--- a/mgmt/newtmgr/include/newtmgr/newtmgr.h
+++ b/mgmt/newtmgr/include/newtmgr/newtmgr.h
@@ -33,8 +33,6 @@ extern "C" {
 #define NMGR_OP_WRITE           (2)
 #define NMGR_OP_WRITE_RSP       (3)
 
-#define NMGR_F_CBOR_RSP_COMPLETE (0x01)
-
 struct nmgr_hdr {
     uint8_t  nh_op;             /* NMGR_OP_XXX */
     uint8_t  nh_flags;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/543fb970/mgmt/newtmgr/src/newtmgr.c
----------------------------------------------------------------------
diff --git a/mgmt/newtmgr/src/newtmgr.c b/mgmt/newtmgr/src/newtmgr.c
index 242b188..465751a 100644
--- a/mgmt/newtmgr/src/newtmgr.c
+++ b/mgmt/newtmgr/src/newtmgr.c
@@ -106,14 +106,13 @@ nmgr_send_err_rsp(struct nmgr_transport *nt, struct os_mbuf *m,
         cbor_encode_bytes_written(&nmgr_task_cbuf.n_b.encoder);
 
     hdr->nh_len = htons(hdr->nh_len);
-    hdr->nh_flags = NMGR_F_CBOR_RSP_COMPLETE;
+    hdr->nh_flags = 0;
     nt->nt_output(nt, nmgr_task_cbuf.n_out_m);
 }
 
 static int
-nmgr_send_rspfrag(struct nmgr_transport *nt, struct nmgr_hdr *rsp_hdr,
-                  struct os_mbuf *rsp, struct os_mbuf *req, uint16_t len,
-                  uint16_t *offset)
+nmgr_send_rspfrag(struct nmgr_transport *nt, struct os_mbuf *rsp,
+                  struct os_mbuf *req, uint16_t len)
 {
     struct os_mbuf *rspfrag;
     int rc;
@@ -130,22 +129,7 @@ nmgr_send_rspfrag(struct nmgr_transport *nt, struct nmgr_hdr *rsp_hdr,
     memcpy(OS_MBUF_USRHDR(rspfrag), OS_MBUF_USRHDR(req),
            OS_MBUF_USRHDR_LEN(req));
 
-    if (os_mbuf_append(rspfrag, rsp_hdr, sizeof(struct nmgr_hdr))) {
-        rc = MGMT_ERR_ENOMEM;
-        goto err;
-    }
-
-    if (os_mbuf_appendfrom(rspfrag, rsp, *offset, len)) {
-        rc = MGMT_ERR_ENOMEM;
-        goto err;
-    }
-
-    *offset += len;
-
-    len = htons(len);
-
-    if (os_mbuf_copyinto(rspfrag, offsetof(struct nmgr_hdr, nh_len), &len,
-                         sizeof(len))) {
+    if (os_mbuf_appendfrom(rspfrag, rsp, 0, len)) {
         rc = MGMT_ERR_ENOMEM;
         goto err;
     }
@@ -164,32 +148,31 @@ static int
 nmgr_rsp_fragment(struct nmgr_transport *nt, struct nmgr_hdr *rsp_hdr,
                   struct os_mbuf *rsp, struct os_mbuf *req)
 {
-    uint16_t offset;
-    uint16_t len;
     uint16_t mtu;
+    uint16_t rsplen;
+    uint16_t len ;
     int rc;
 
-    offset = sizeof(struct nmgr_hdr);
-    len = rsp_hdr->nh_len;
+    len = 0;
 
-    mtu = nt->nt_get_mtu(req) - sizeof(struct nmgr_hdr);
+    mtu = nt->nt_get_mtu(req);
 
     do {
-        if (len <= mtu) {
-            rsp_hdr->nh_flags |= NMGR_F_CBOR_RSP_COMPLETE;
+        len = OS_MBUF_PKTLEN(rsp);
+        if (len >= mtu) {
+            rsplen = mtu;
         } else {
-            len = mtu;
+            rsplen = len;
         }
 
-        rc = nmgr_send_rspfrag(nt, rsp_hdr, rsp, req, len, &offset);
+        rc = nmgr_send_rspfrag(nt, rsp, req, rsplen);
         if (rc) {
             goto err;
         }
 
-        len = rsp_hdr->nh_len - offset + sizeof(struct nmgr_hdr);
+        os_mbuf_adj(rsp, rsplen);
 
-    } while (!((rsp_hdr->nh_flags & NMGR_F_CBOR_RSP_COMPLETE) ==
-                NMGR_F_CBOR_RSP_COMPLETE));
+    } while (OS_MBUF_PKTLEN(rsp));
 
     return MGMT_ERR_EOK;
 err:
@@ -277,6 +260,8 @@ nmgr_handle_req(struct nmgr_transport *nt, struct os_mbuf *req)
         rsp_hdr->nh_len +=
             cbor_encode_bytes_written(&nmgr_task_cbuf.n_b.encoder);
         off += sizeof(hdr) + OS_ALIGN(hdr.nh_len, 4);
+
+        rsp_hdr->nh_len = htons(rsp_hdr->nh_len);
         rc = nmgr_rsp_fragment(nt, rsp_hdr, rsp, req);
         if (rc) {
             goto err;