Repository: incubator-mynewt-core Updated Branches: refs/heads/develop 2551b3c0b -> 3f0d5f502
MYNEWT-566; nmgr_uart - fix warning when using -Werror=strict-aliasing 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/3f0d5f50 Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/3f0d5f50 Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/3f0d5f50 Branch: refs/heads/develop Commit: 3f0d5f502b24df319656e994731d00bff0de21b7 Parents: 2551b3c Author: Marko Kiiskila <[email protected]> Authored: Fri Jan 27 11:10:30 2017 -0800 Committer: Marko Kiiskila <[email protected]> Committed: Fri Jan 27 11:10:30 2017 -0800 ---------------------------------------------------------------------- .../newtmgr/transport/nmgr_uart/src/nmgr_uart.c | 42 ++++++++++++++------ 1 file changed, 29 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3f0d5f50/mgmt/newtmgr/transport/nmgr_uart/src/nmgr_uart.c ---------------------------------------------------------------------- diff --git a/mgmt/newtmgr/transport/nmgr_uart/src/nmgr_uart.c b/mgmt/newtmgr/transport/nmgr_uart/src/nmgr_uart.c index 6a6b3d9..4465079 100644 --- a/mgmt/newtmgr/transport/nmgr_uart/src/nmgr_uart.c +++ b/mgmt/newtmgr/transport/nmgr_uart/src/nmgr_uart.c @@ -75,8 +75,7 @@ nmgr_uart_out(struct nmgr_transport *nt, struct os_mbuf *m) struct nmgr_uart_state *nus = (struct nmgr_uart_state *)nt; struct os_mbuf_pkthdr *mpkt; struct os_mbuf *n; - char tmp_buf[12]; - uint16_t crc; + uint16_t tmp_buf[6]; char *dst; int off; int boff; @@ -89,32 +88,49 @@ nmgr_uart_out(struct nmgr_transport *nt, struct os_mbuf *m) assert(OS_MBUF_IS_PKTHDR(m)); mpkt = OS_MBUF_PKTHDR(m); + /* + * Compute CRC-16 and append it to end. + */ off = 0; - crc = CRC16_INITIAL_CRC; + tmp_buf[0] = CRC16_INITIAL_CRC; for (n = m; n; n = SLIST_NEXT(n, om_next)) { - crc = crc16_ccitt(crc, n->om_data, n->om_len); + tmp_buf[0] = crc16_ccitt(tmp_buf[0], n->om_data, n->om_len); } - crc = htons(crc); - dst = os_mbuf_extend(m, sizeof(crc)); + tmp_buf[0] = htons(tmp_buf[0]); + dst = os_mbuf_extend(m, sizeof(uint16_t)); if (!dst) { goto err; } - memcpy(dst, &crc, sizeof(crc)); + memcpy(dst, tmp_buf, sizeof(uint16_t)); + /* + * Create another mbuf chain with base64 encoded data. + */ n = os_msys_get(SHELL_NLIP_MAX_FRAME, 0); if (!n || OS_MBUF_TRAILINGSPACE(n) < 32) { goto err; } while (off < mpkt->omp_len) { + /* + * First fragment has a different header, and length of the full frame + * (need to base64 encode that). + */ + if (off == 0) { + tmp_buf[0] = htons(SHELL_NLIP_PKT); + } else { + tmp_buf[0] = htons(SHELL_NLIP_DATA); + } + rc = os_mbuf_append(n, tmp_buf, sizeof(uint16_t)); + if (rc) { + goto err; + } tx_sz = 2; - dst = os_mbuf_extend(n, 2); + if (off == 0) { - *(uint16_t *)dst = htons(SHELL_NLIP_PKT); - *(uint16_t *)tmp_buf = htons(mpkt->omp_len); - boff = 2; + tmp_buf[0] = htons(mpkt->omp_len); + boff = sizeof(uint16_t); } else { - *(uint16_t *)dst = htons(SHELL_NLIP_DATA); boff = 0; } @@ -128,7 +144,7 @@ nmgr_uart_out(struct nmgr_transport *nt, struct os_mbuf *m) if (tx_sz + BASE64_ENCODE_SIZE(slen + boff) >= 124) { break; } - rc = os_mbuf_copydata(m, off, slen, tmp_buf + boff); + rc = os_mbuf_copydata(m, off, slen, (uint8_t *)tmp_buf + boff); assert(rc == 0); off += slen;
