You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2016/09/30 20:55:40 UTC
[2/3] incubator-mynewt-core git commit: Newtmgr Fragmentation
Newtmgr Fragmentation
- Cleaning up, seperating fragmentation function
- Also fixing a compilation error caused by console/stub
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/d11ae70b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/d11ae70b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/d11ae70b
Branch: refs/heads/develop
Commit: d11ae70b4f53184e327a406002e5802b6bec7a39
Parents: f206987
Author: Vipul Rahane <vi...@runtime.io>
Authored: Fri Sep 30 12:37:02 2016 -0700
Committer: Vipul Rahane <vi...@runtime.io>
Committed: Fri Sep 30 13:52:55 2016 -0700
----------------------------------------------------------------------
libs/newtmgr/include/newtmgr/newtmgr.h | 7 +-
libs/newtmgr/src/newtmgr.c | 160 ++++++++++++++--------
libs/newtmgr/transport/ble/pkg.yml | 2 +-
libs/newtmgr/transport/ble/src/newtmgr_ble.c | 22 +--
sys/console/stub/include/console/prompt.h | 1 -
5 files changed, 123 insertions(+), 69 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d11ae70b/libs/newtmgr/include/newtmgr/newtmgr.h
----------------------------------------------------------------------
diff --git a/libs/newtmgr/include/newtmgr/newtmgr.h b/libs/newtmgr/include/newtmgr/newtmgr.h
index a2bc5f1..43450ae 100644
--- a/libs/newtmgr/include/newtmgr/newtmgr.h
+++ b/libs/newtmgr/include/newtmgr/newtmgr.h
@@ -109,16 +109,19 @@ struct nmgr_group {
struct nmgr_transport;
typedef int (*nmgr_transport_out_func_t)(struct nmgr_transport *nt,
struct os_mbuf *m);
+typedef uint16_t (*nmgr_transport_get_mtu_func_t)(struct os_mbuf *m);
struct nmgr_transport {
struct os_mqueue nt_imq;
- nmgr_transport_out_func_t nt_output;
+ nmgr_transport_out_func_t nt_output;
+ nmgr_transport_get_mtu_func_t nt_get_mtu;
};
int nmgr_task_init(void);
int nmgr_transport_init(struct nmgr_transport *nt,
- nmgr_transport_out_func_t output_func);
+ nmgr_transport_out_func_t output_func,
+ nmgr_transport_get_mtu_func_t get_mtu_func);
int nmgr_rx_req(struct nmgr_transport *nt, struct os_mbuf *req);
int nmgr_rsp_extend(struct nmgr_hdr *, struct os_mbuf *, void *data, uint16_t);
int nmgr_group_register(struct nmgr_group *group);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d11ae70b/libs/newtmgr/src/newtmgr.c
----------------------------------------------------------------------
diff --git a/libs/newtmgr/src/newtmgr.c b/libs/newtmgr/src/newtmgr.c
index 4f9957f..d3883e1 100644
--- a/libs/newtmgr/src/newtmgr.c
+++ b/libs/newtmgr/src/newtmgr.c
@@ -28,7 +28,6 @@
#include "shell/shell.h"
#include "newtmgr/newtmgr.h"
#include "nmgr_os/nmgr_os.h"
-#include "nmgrble/newtmgr_ble.h"
os_stack_t newtmgr_stack[OS_STACK_ALIGN(MYNEWT_VAL(NEWTMGR_STACK_SIZE))];
@@ -312,19 +311,106 @@ nmgr_jbuf_setoerr(struct nmgr_jbuf *njb, int errcode)
}
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) {
+
+ struct os_mbuf *rspfrag;
+ int rc;
+
+ rspfrag = NULL;
+
+ rspfrag = os_msys_get_pkthdr(len, OS_MBUF_USRHDR_LEN(req));
+ if (!rspfrag) {
+ rc = OS_EINVAL;
+ goto err;
+ }
+
+ /* Copy the request packet header into the response. */
+ 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 = OS_EINVAL;
+ goto err;
+ }
+
+ if (os_mbuf_appendfrom(rspfrag, rsp, *offset, len)) {
+ rc = OS_EINVAL;
+ goto err;
+ }
+
+ *offset += len;
+
+ len = htons(len);
+
+ if (os_mbuf_copyinto(rspfrag, offsetof(struct nmgr_hdr, nh_len), &len, sizeof(len))) {
+ rc = OS_EINVAL;
+ goto err;
+ }
+
+ nt->nt_output(nt, rspfrag);
+
+ return OS_OK;
+err:
+ if (rspfrag) {
+ os_mbuf_free_chain(rspfrag);
+ }
+ return rc;
+}
+
+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;
+ int rc;
+
+ if (!rsp_hdr) {
+ rc = OS_EINVAL;
+ goto err;
+ }
+
+ offset = sizeof(struct nmgr_hdr);
+ len = rsp_hdr->nh_len;
+ rsp_hdr->nh_group = htons(rsp_hdr->nh_group);
+
+ mtu = nt->nt_get_mtu(req) - sizeof(struct nmgr_hdr);
+
+ do {
+ if (len <= mtu) {
+ rsp_hdr->nh_flags |= NMGR_F_JSON_RSP_COMPLETE;
+ } else {
+ len = mtu;
+ }
+
+ rc = nmgr_send_rspfrag(nt, rsp_hdr, rsp, req, len, &offset);
+ if (rc) {
+ goto err;
+ }
+
+ len = rsp_hdr->nh_len - offset + sizeof(struct nmgr_hdr);
+
+ } while (!((rsp_hdr->nh_flags & NMGR_F_JSON_RSP_COMPLETE) ==
+ NMGR_F_JSON_RSP_COMPLETE));
+
+ return OS_OK;
+err:
+ return rc;
+}
+
+static int
nmgr_handle_req(struct nmgr_transport *nt, struct os_mbuf *req)
{
struct os_mbuf *rsp;
struct nmgr_handler *handler;
struct nmgr_hdr *rsp_hdr;
struct nmgr_hdr hdr;
- struct os_mbuf *rspfrag;
- uint32_t off;
- uint32_t offtmp;
+ int off;
uint16_t len;
int rc;
- rspfrag = NULL;
rsp_hdr = NULL;
rsp = os_msys_get_pkthdr(512, OS_MBUF_USRHDR_LEN(req));
@@ -365,7 +451,7 @@ nmgr_handle_req(struct nmgr_transport *nt, struct os_mbuf *req)
goto err;
}
rsp_hdr->nh_len = 0;
- rsp_hdr->nh_flags = hdr.nh_flags;
+ rsp_hdr->nh_flags = 0;
rsp_hdr->nh_op = (hdr.nh_op == NMGR_OP_READ) ? NMGR_OP_READ_RSP :
NMGR_OP_WRITE_RSP;
rsp_hdr->nh_group = hdr.nh_group;
@@ -406,60 +492,16 @@ nmgr_handle_req(struct nmgr_transport *nt, struct os_mbuf *req)
}
off += sizeof(hdr) + OS_ALIGN(hdr.nh_len, 4);
-
- if (!rsp_hdr) {
- goto err;
- }
-
- offtmp = 8;
- len = rsp_hdr->nh_len;
- rsp_hdr->nh_group = htons(rsp_hdr->nh_group);
-
- do {
-
- nmgr_ble_update_rsp_len(req, &len, &rsp_hdr->nh_flags);
-
- rspfrag = os_msys_get_pkthdr(len, OS_MBUF_USRHDR_LEN(req));
- if (!rspfrag) {
- rc = OS_EINVAL;
- goto err;
- }
- /* Copy the request packet header into the response. */
- 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 = OS_EINVAL;
- goto err;
- }
-
- if (os_mbuf_appendfrom(rspfrag, rsp, offtmp, len)) {
- rc = OS_EINVAL;
- goto err;
- }
-
- offtmp += len;
-
- len = htons(len);
-
- if (os_mbuf_copyinto(rspfrag, offsetof(struct nmgr_hdr, nh_len), &len, sizeof(len))) {
- rc = OS_EINVAL;
+ rc = nmgr_rsp_fragment(nt, rsp_hdr, rsp, req);
+ if (rc) {
goto err;
}
-
- nt->nt_output(nt, rspfrag);
- len = rsp_hdr->nh_len - offtmp + sizeof(struct nmgr_hdr);
-
- } while (!((hdr.nh_flags & NMGR_F_JSON_RSP_COMPLETE) ==
- NMGR_F_JSON_RSP_COMPLETE));
}
os_mbuf_free_chain(rsp);
- return (0);
+ return OS_OK;
err:
os_mbuf_free_chain(rsp);
- if (rspfrag) {
- os_mbuf_free_chain(rspfrag);
- }
return (rc);
}
@@ -506,11 +548,13 @@ nmgr_task(void *arg)
int
nmgr_transport_init(struct nmgr_transport *nt,
- nmgr_transport_out_func_t output_func)
+ nmgr_transport_out_func_t output_func,
+ nmgr_transport_get_mtu_func_t get_mtu_func)
{
int rc;
nt->nt_output = output_func;
+ nt->nt_get_mtu = get_mtu_func;
rc = os_mqueue_init(&nt->nt_imq, nt);
if (rc != 0) {
@@ -546,6 +590,11 @@ nmgr_rx_req(struct nmgr_transport *nt, struct os_mbuf *req)
return rc;
}
+static uint16_t
+nmgr_shell_get_mtu(struct os_mbuf *m) {
+ return NMGR_MAX_MTU;
+}
+
static int
nmgr_shell_out(struct nmgr_transport *nt, struct os_mbuf *m)
{
@@ -587,7 +636,8 @@ nmgr_task_init(void)
os_eventq_init(&g_nmgr_evq);
- rc = nmgr_transport_init(&g_nmgr_shell_transport, nmgr_shell_out);
+ rc = nmgr_transport_init(&g_nmgr_shell_transport, nmgr_shell_out,
+ nmgr_shell_get_mtu);
if (rc != 0) {
goto err;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d11ae70b/libs/newtmgr/transport/ble/pkg.yml
----------------------------------------------------------------------
diff --git a/libs/newtmgr/transport/ble/pkg.yml b/libs/newtmgr/transport/ble/pkg.yml
index e3a9117..7950fa7 100644
--- a/libs/newtmgr/transport/ble/pkg.yml
+++ b/libs/newtmgr/transport/ble/pkg.yml
@@ -27,7 +27,7 @@ pkg.keywords:
pkg.deps:
- kernel/os
- - net/nimble
+ - net/nimble/host
pkg.init_function: newtmgr_ble_pkg_init
pkg.init_stage: 5
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d11ae70b/libs/newtmgr/transport/ble/src/newtmgr_ble.c
----------------------------------------------------------------------
diff --git a/libs/newtmgr/transport/ble/src/newtmgr_ble.c b/libs/newtmgr/transport/ble/src/newtmgr_ble.c
index 1164ba3..817673d 100644
--- a/libs/newtmgr/transport/ble/src/newtmgr_ble.c
+++ b/libs/newtmgr/transport/ble/src/newtmgr_ble.c
@@ -24,6 +24,7 @@
#include "host/ble_hs.h"
#include "newtmgr/newtmgr.h"
#include "os/endian.h"
+#include "console/console.h"
/* nmgr ble mqueue */
struct os_mqueue ble_nmgr_mq;
@@ -143,21 +144,22 @@ gatt_svr_chr_access_newtmgr(uint16_t conn_handle, uint16_t attr_handle,
}
}
-void
-nmgr_ble_update_rsp_len(struct os_mbuf *req, uint16_t *len, uint8_t *flags) {
+uint16_t
+nmgr_ble_get_mtu(struct os_mbuf *req) {
- uint16_t ble_data_len;
uint16_t conn_handle;
+ uint16_t mtu;
memcpy(&conn_handle, OS_MBUF_USRHDR(req), sizeof (conn_handle));
+ mtu = ble_att_mtu(conn_handle);
+ if (!mtu) {
+ assert(0);
+ }
- ble_data_len = ble_att_mtu(conn_handle) - 3 - sizeof(struct nmgr_hdr);
+ /* 3 is the number of bytes for ATT notification base */
+ mtu = mtu - 3;
- if (*len <= ble_data_len) {
- *flags |= NMGR_F_JSON_RSP_COMPLETE;
- } else {
- *len = ble_data_len;
- }
+ return (mtu);
}
/**
@@ -243,7 +245,7 @@ nmgr_ble_gatt_svr_init(void)
os_mqueue_init(&ble_nmgr_mq, &ble_nmgr_mq);
- rc = nmgr_transport_init(&ble_nt, &nmgr_ble_out);
+ rc = nmgr_transport_init(&ble_nt, nmgr_ble_out, nmgr_ble_get_mtu);
err:
return rc;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d11ae70b/sys/console/stub/include/console/prompt.h
----------------------------------------------------------------------
diff --git a/sys/console/stub/include/console/prompt.h b/sys/console/stub/include/console/prompt.h
index a1d72c9..6f3c3c2 100644
--- a/sys/console/stub/include/console/prompt.h
+++ b/sys/console/stub/include/console/prompt.h
@@ -19,7 +19,6 @@
#ifndef __CONSOLE_PROMPT_H__
#define __CONSOLE_PROMPT_H__
-nclude/console/prompt.h
#include <stdarg.h>