You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by st...@apache.org on 2015/12/04 01:13:18 UTC
incubator-mynewt-larva git commit: change get_pkthdr() to get the
full length of the packet including header. Only free mbuf to pool,
if pool ptr is not null.
Repository: incubator-mynewt-larva
Updated Branches:
refs/heads/master 568f0c682 -> 3b84fcd48
change get_pkthdr() to get the full length of the packet including header. Only free mbuf to pool, if pool ptr is not null.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/commit/3b84fcd4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/3b84fcd4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/3b84fcd4
Branch: refs/heads/master
Commit: 3b84fcd48c162f974dfe0cfa559f97e96fabc405
Parents: 568f0c6
Author: Sterling Hughes <st...@apache.org>
Authored: Thu Dec 3 16:13:01 2015 -0800
Committer: Sterling Hughes <st...@apache.org>
Committed: Thu Dec 3 16:13:13 2015 -0800
----------------------------------------------------------------------
libs/os/src/os_mbuf.c | 10 +++++----
libs/shell/src/shell.c | 41 ++++++++++++++++++++++++++++++------
libs/util/include/util/base64.h | 2 +-
3 files changed, 42 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/3b84fcd4/libs/os/src/os_mbuf.c
----------------------------------------------------------------------
diff --git a/libs/os/src/os_mbuf.c b/libs/os/src/os_mbuf.c
index 8700e31..fc57fc8 100644
--- a/libs/os/src/os_mbuf.c
+++ b/libs/os/src/os_mbuf.c
@@ -186,7 +186,7 @@ os_msys_get_pkthdr(uint16_t dsize, uint16_t pkthdr_len)
struct os_mbuf *m;
struct os_mbuf_pool *pool;
- pool = _os_msys_find_pool(dsize);
+ pool = _os_msys_find_pool(dsize + pkthdr_len);
if (!pool) {
goto err;
}
@@ -285,9 +285,11 @@ os_mbuf_free(struct os_mbuf *om)
{
int rc;
- rc = os_memblock_put(om->om_omp->omp_pool, om);
- if (rc != 0) {
- goto err;
+ if (om->om_omp != NULL) {
+ rc = os_memblock_put(om->om_omp->omp_pool, om);
+ if (rc != 0) {
+ goto err;
+ }
}
return (0);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/3b84fcd4/libs/shell/src/shell.c
----------------------------------------------------------------------
diff --git a/libs/shell/src/shell.c b/libs/shell/src/shell.c
index 187ca7d..20c8251 100644
--- a/libs/shell/src/shell.c
+++ b/libs/shell/src/shell.c
@@ -224,10 +224,16 @@ err:
static int
shell_nlip_mtx(struct os_mbuf *m)
{
- uint8_t buf[12];
+#define SHELL_NLIP_MTX_BUF_SIZE (12)
+ uint8_t readbuf[SHELL_NLIP_MTX_BUF_SIZE];
+ char encodebuf[BASE64_ENCODE_SIZE(SHELL_NLIP_MTX_BUF_SIZE)];
+ uint8_t esc_seq[2];
+ uint8_t pkt_seq[2];
uint16_t totlen;
uint16_t dlen;
uint16_t off;
+ int elen;
+ uint16_t nwritten;
int rc;
/* Convert the mbuf into a packet.
@@ -243,18 +249,41 @@ shell_nlip_mtx(struct os_mbuf *m)
* buffer has been sent.
*/
totlen = OS_MBUF_PKTHDR(m)->omp_len;
+ nwritten = 0;
+ off = 0;
+
+ pkt_seq[0] = SHELL_NLIP_PKT_START1;
+ pkt_seq[1] = SHELL_NLIP_PKT_START2;
+
+ esc_seq[0] = SHELL_NLIP_DATA_START1;
+ esc_seq[1] = SHELL_NLIP_DATA_START2;
+
+ /* Start a packet */
+ console_write((char *) pkt_seq, sizeof(pkt_seq));
while (totlen > 0) {
- dlen = min(sizeof(buf), totlen);
+ dlen = min(SHELL_NLIP_MTX_BUF_SIZE, totlen);
- rc = os_mbuf_copydata(m, off, dlen, buf);
+ if (nwritten != 0 &&
+ ((nwritten + BASE64_ENCODE_SIZE(dlen)) % 122) == 0) {
+ console_write((char *) esc_seq, sizeof(esc_seq));
+ console_write("\n", sizeof("\n")-1);
+ }
+
+ rc = os_mbuf_copydata(m, off, dlen, readbuf);
if (rc != 0) {
goto err;
}
off += dlen;
- console_write((char *) buf, dlen);
+ elen = base64_encode(readbuf, dlen, encodebuf,
+ totlen - dlen > 0 ? 0 : 1);
+
+ console_write(encodebuf, elen);
+
+ nwritten += elen;
totlen -= dlen;
+
}
return (0);
@@ -329,10 +358,10 @@ shell_read_console(void)
}
g_nlip_expected_len = 0;
- rc = shell_nlip_process(shell_line, rc);
+ rc = shell_nlip_process(&shell_line[2], rc-2);
} else if (shell_line[0] == SHELL_NLIP_DATA_START1 &&
shell_line[1] == SHELL_NLIP_DATA_START2) {
- rc = shell_nlip_process(shell_line, rc);
+ rc = shell_nlip_process(&shell_line[2], rc-2);
} else {
rc = shell_process_command(shell_line, rc);
if (rc != 0) {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/3b84fcd4/libs/util/include/util/base64.h
----------------------------------------------------------------------
diff --git a/libs/util/include/util/base64.h b/libs/util/include/util/base64.h
index d6baca5..8d978c5 100644
--- a/libs/util/include/util/base64.h
+++ b/libs/util/include/util/base64.h
@@ -19,6 +19,6 @@
int base64_encode(const void *, int, char *, uint8_t);
int base64_decode(const char *, void *buf);
-#define BASE64_ENCODE_SIZE(size) (((__size) * (4 / 3)) + 4)
+#define BASE64_ENCODE_SIZE(__size) (((__size) * (4 / 3)) + 4)
#endif /* __UTIL_BASE64_H__ */