[OpenWrt-Devel] [PATCH] [libubox][v3] b64: add base64 support
The base code has been taken from zstream project which was written by Steven Barth. Signed-off-by: Luka Perkov l...@openwrt.org CC: Steven Barth ste...@midlink.org --- = changes in v2: Use new API: size_t b64decode(void **out, const char *in, size_t len); size_t b64encode(char **out, const void *in, size_t len); = changes in v3: Use new API: static inline int b64_decode_size(const void *in, size_t len); static inline int b64_encode_size(size_t len); size_t b64decode(void *out, const void *in, size_t len); size_t b64encode(void *out, const void *in, size_t len); In this set a few corner cases of invalid writes in b64decode were fixed. Furthermore, b64decode() works fine when in == out. CMakeLists.txt | 2 +- b64.c | 112 + b64.h | 60 +++ 3 files changed, 173 insertions(+), 1 deletion(-) create mode 100644 b64.c create mode 100644 b64.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 58381da..77f4842 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,7 @@ IF(JSONC_FOUND) INCLUDE_DIRECTORIES(${JSONC_INCLUDE_DIRS}) ENDIF() -SET(SOURCES avl.c avl-cmp.c blob.c blobmsg.c uloop.c usock.c ustream.c ustream-fd.c vlist.c utils.c safe_list.c runqueue.c md5.c kvlist.c ulog.c) +SET(SOURCES avl.c avl-cmp.c blob.c blobmsg.c uloop.c usock.c ustream.c ustream-fd.c vlist.c utils.c safe_list.c runqueue.c md5.c kvlist.c ulog.c b64.c) ADD_LIBRARY(ubox SHARED ${SOURCES}) ADD_LIBRARY(ubox-static STATIC ${SOURCES}) diff --git a/b64.c b/b64.c new file mode 100644 index 000..007fb91 --- /dev/null +++ b/b64.c @@ -0,0 +1,112 @@ +/* + * Copyright (C) 2011 Steven Barth ste...@midlink.org + * Copyright (C) 2015 Luka Perkov l...@openwrt.org + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED AS IS AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include stdint.h +#include stdlib.h + +#include b64.h + +static const uint8_t b64decode_tbl[] = { + 0x3e, 0xff, 0xff, 0xff, 0x3f, 0x34, 0x35, 0x36, + 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0xff, + 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0x01, + 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, + 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, + 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1a, 0x1b, + 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, + 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, + 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33 +}; + +size_t b64decode(void *out, const void *in, size_t len) +{ + uint8_t *o = (uint8_t *) out; + const uint8_t *data = (const uint8_t *) in; + size_t lenout, i, j; + + lenout = b64_decode_size(in, len); + if (!lenout) + return 0; + + uint32_t cv = 0; + for (i = 0; i (len - 4); i += 4) { + cv = 0; + for (j = 0; j 4; j++) { + uint8_t c = data[i + j] - 43; + if (c 79 || (c = b64decode_tbl[c]) == 0xff) + return 0; + + cv |= c; + if (j != 3) + cv = 6; + } + + o[2] = (uint8_t)(cv 0xff); + o[1] = (uint8_t)((cv 8) 0xff); + o[0] = (uint8_t)((cv 16) 0xff); + o += 3; + } + + if (data[len - 1] != '=') + o[2] = (uint8_t)(cv 0xff); + + if (data[len - 1] != '=') + o[1] = (uint8_t)((cv 8) 0xff); + + o[0] = (uint8_t)((cv 16) 0xff); + + return lenout; +} + +static const uint8_t b64encode_tbl[] = + ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/; + +size_t b64encode(void *out, const void *in, size_t len) +{ + uint8_t *o = (uint8_t *) out; + const uint8_t *data = (const uint8_t *) in; + size_t lenout, pad, i; + + lenout = b64_encode_size(len); + if (!lenout) + return 0; + + for (i = 0; i len; i += 3) { + uint32_t cv = (data[i] 16) | (data[i + 1] 8) | data[i + 2]; + o[3] = b64encode_tbl[cv 0x3f]; + o[2] = b64encode_tbl[(cv 6) 0x3f]; + o[1] = b64encode_tbl[(cv 12) 0x3f]; + o[0]
[OpenWrt-Devel] [PATCH] wpan: remove duplicate DEPENDS
Signed-off-by: Varka Bhadram var...@cdac.in --- package/kernel/linux/modules/wpan.mk |1 - 1 file changed, 1 deletion(-) diff --git a/package/kernel/linux/modules/wpan.mk b/package/kernel/linux/modules/wpan.mk index 8b25377..0b1f33a 100644 --- a/package/kernel/linux/modules/wpan.mk +++ b/package/kernel/linux/modules/wpan.mk @@ -110,7 +110,6 @@ define KernelPackage/ieee802154_6lowpan TITLE:= 6LoWPAN support over IEEE-802.15.4 DEPENDS:=@LINUX_4_0 KCONFIG:=CONFIG_IEEE802154_6LOWPAN - DEPENDS:=@LINUX_4_0 FILES:=$(LINUX_DIR)/net/ieee802154/6lowpan/ieee802154_6lowpan.ko AUTOLOAD:=$(call AutoLoad,91,ieee802154_6lowpan) endef -- 1.7.9.5 ___ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
Re: [OpenWrt-Devel] [PATCH] [libubox][v2] b64: add base64 support
On 2015-04-12 03:31, Luka Perkov wrote: The base code has been taken from zstream project which was written by Steven Barth. Signed-off-by: Luka Perkov l...@openwrt.org CC: Steven Barth ste...@midlink.org Your v2 patch did not properly consider my comments on v1. I'll repeat them with some added clarifications. I think output *buffers* (not just pointers to output buffer pointers) should be passed in by the caller, and the functions should return size_t. Your functions should not do any memory allocation at all! You could then add an inline function that returns the maximum output buffer size for encode/decode. Example: size_t b64decode(void *out, const void *in, size_t len); size_t b64encode(void *out, const void *in, size_t len); static inline int b64_decode_size(size_t in); static inline int b64_encode_size(size_t in); b64decode() should also be able to handle in == out, i.e. working within the same buffer. - Felix ___ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
[OpenWrt-Devel] [PATCH] b53: override CPU port state on BCM5301X with CPU port other than 8
Newer revisions (5+) of BCM53011 and probably all revs of BCM53012 require overriding CPU port to work. So far we were handling it only for CPU port 8, but some devices may use e.g. port 5. In such case we need to use recently defined GMII_PORT registers. It was tested for regressions on BCM53011 revs 2 3. It was also confirmed to fix switch on some internal Broadcom board. Signed-off-by: Rafał Miłecki zaj...@gmail.com --- .../linux/generic/files/drivers/net/phy/b53/b53_common.c | 15 +++ 1 file changed, 15 insertions(+) diff --git a/target/linux/generic/files/drivers/net/phy/b53/b53_common.c b/target/linux/generic/files/drivers/net/phy/b53/b53_common.c index d2bb51a..87c4d5b 100644 --- a/target/linux/generic/files/drivers/net/phy/b53/b53_common.c +++ b/target/linux/generic/files/drivers/net/phy/b53/b53_common.c @@ -534,6 +534,21 @@ static int b53_switch_reset(struct b53_device *dev) b53_write8(dev, B53_CTRL_PAGE, B53_PORT_OVERRIDE_CTRL, mii_port_override | PORT_OVERRIDE_EN | PORT_OVERRIDE_LINK); + } else if (is5301x(dev)) { + if (dev-sw_dev.cpu_port == 8) { + /* TODO: Ports 5 7 require some extra handling */ + } else { + u8 po_reg = B53_GMII_PORT_OVERRIDE_CTRL(dev-sw_dev.cpu_port); + u8 gmii_po; + + b53_read8(dev, B53_CTRL_PAGE, po_reg, gmii_po); + gmii_po |= GMII_PO_LINK | + GMII_PO_RX_FLOW | + GMII_PO_TX_FLOW | + GMII_PO_EN | + GMII_PO_SPEED_2000M; + b53_write8(dev, B53_CTRL_PAGE, po_reg, gmii_po); + } } b53_enable_mib(dev); -- 1.8.4.5 ___ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
[OpenWrt-Devel] [PATCH V2] b53: override CPU port state on BCM5301X with CPU port other than 8
Newer revisions (5+) of BCM53011 and probably all revs of BCM53012 require overriding CPU port to work. So far we were handling it only for CPU port 8, but some devices may use e.g. port 5. In such case we need to use recently defined GMII_PORT registers. It was tested for regressions on BCM53011 revs 2 3. It was also confirmed to fix switch on some internal Broadcom board. Signed-off-by: Rafał Miłecki zaj...@gmail.com --- V2: Use new code branch to make (unused) port 8 branch reachable. --- .../generic/files/drivers/net/phy/b53/b53_common.c | 17 + 1 file changed, 17 insertions(+) diff --git a/target/linux/generic/files/drivers/net/phy/b53/b53_common.c b/target/linux/generic/files/drivers/net/phy/b53/b53_common.c index d2bb51a..2079f80 100644 --- a/target/linux/generic/files/drivers/net/phy/b53/b53_common.c +++ b/target/linux/generic/files/drivers/net/phy/b53/b53_common.c @@ -536,6 +536,23 @@ static int b53_switch_reset(struct b53_device *dev) PORT_OVERRIDE_LINK); } + if (is5301x(dev)) { + if (dev-sw_dev.cpu_port == 8) { + /* TODO: Ports 5 7 require some extra handling */ + } else { + u8 po_reg = B53_GMII_PORT_OVERRIDE_CTRL(dev-sw_dev.cpu_port); + u8 gmii_po; + + b53_read8(dev, B53_CTRL_PAGE, po_reg, gmii_po); + gmii_po |= GMII_PO_LINK | + GMII_PO_RX_FLOW | + GMII_PO_TX_FLOW | + GMII_PO_EN | + GMII_PO_SPEED_2000M; + b53_write8(dev, B53_CTRL_PAGE, po_reg, gmii_po); + } + } + b53_enable_mib(dev); return b53_flush_arl(dev); -- 1.8.4.5 ___ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
Re: [OpenWrt-Devel] [PATCH] b53: override CPU port state on BCM5301X with CPU port other than 8
On Sun, Apr 12, 2015 at 6:03 PM, Rafał Miłecki zaj...@gmail.com wrote: Newer revisions (5+) of BCM53011 and probably all revs of BCM53012 require overriding CPU port to work. So far we were handling it only for CPU port 8, but some devices may use e.g. port 5. In such case we need to use recently defined GMII_PORT registers. It was tested for regressions on BCM53011 revs 2 3. It was also confirmed to fix switch on some internal Broadcom board. Signed-off-by: Rafał Miłecki zaj...@gmail.com --- .../linux/generic/files/drivers/net/phy/b53/b53_common.c | 15 +++ 1 file changed, 15 insertions(+) diff --git a/target/linux/generic/files/drivers/net/phy/b53/b53_common.c b/target/linux/generic/files/drivers/net/phy/b53/b53_common.c index d2bb51a..87c4d5b 100644 --- a/target/linux/generic/files/drivers/net/phy/b53/b53_common.c +++ b/target/linux/generic/files/drivers/net/phy/b53/b53_common.c @@ -534,6 +534,21 @@ static int b53_switch_reset(struct b53_device *dev) b53_write8(dev, B53_CTRL_PAGE, B53_PORT_OVERRIDE_CTRL, mii_port_override | PORT_OVERRIDE_EN | PORT_OVERRIDE_LINK); + } else if (is5301x(dev)) { + if (dev-sw_dev.cpu_port == 8) { + /* TODO: Ports 5 7 require some extra handling */ This branch can never be reached because the previous has else if ((is531x5(dev) || is5301x(dev)) dev-sw_dev.cpu_port == B53_CPU_PORT) { /* B53_CPU_PORT is 8 */ + } else { + u8 po_reg = B53_GMII_PORT_OVERRIDE_CTRL(dev-sw_dev.cpu_port); + u8 gmii_po; + + b53_read8(dev, B53_CTRL_PAGE, po_reg, gmii_po); + gmii_po |= GMII_PO_LINK | + GMII_PO_RX_FLOW | + GMII_PO_TX_FLOW | + GMII_PO_EN | + GMII_PO_SPEED_2000M; + b53_write8(dev, B53_CTRL_PAGE, po_reg, gmii_po); + } } b53_enable_mib(dev); Jonas ___ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
Re: [OpenWrt-Devel] [PATCH] b53: override CPU port state on BCM5301X with CPU port other than 8
On 12 April 2015 at 18:16, Jonas Gorski j...@openwrt.org wrote: On Sun, Apr 12, 2015 at 6:03 PM, Rafał Miłecki zaj...@gmail.com wrote: Newer revisions (5+) of BCM53011 and probably all revs of BCM53012 require overriding CPU port to work. So far we were handling it only for CPU port 8, but some devices may use e.g. port 5. In such case we need to use recently defined GMII_PORT registers. It was tested for regressions on BCM53011 revs 2 3. It was also confirmed to fix switch on some internal Broadcom board. Signed-off-by: Rafał Miłecki zaj...@gmail.com --- .../linux/generic/files/drivers/net/phy/b53/b53_common.c | 15 +++ 1 file changed, 15 insertions(+) diff --git a/target/linux/generic/files/drivers/net/phy/b53/b53_common.c b/target/linux/generic/files/drivers/net/phy/b53/b53_common.c index d2bb51a..87c4d5b 100644 --- a/target/linux/generic/files/drivers/net/phy/b53/b53_common.c +++ b/target/linux/generic/files/drivers/net/phy/b53/b53_common.c @@ -534,6 +534,21 @@ static int b53_switch_reset(struct b53_device *dev) b53_write8(dev, B53_CTRL_PAGE, B53_PORT_OVERRIDE_CTRL, mii_port_override | PORT_OVERRIDE_EN | PORT_OVERRIDE_LINK); + } else if (is5301x(dev)) { + if (dev-sw_dev.cpu_port == 8) { + /* TODO: Ports 5 7 require some extra handling */ This branch can never be reached because the previous has else if ((is531x5(dev) || is5301x(dev)) dev-sw_dev.cpu_port == B53_CPU_PORT) { /* B53_CPU_PORT is 8 */ Yes, as discussed with you earlier, I didn't move the code from previous branch yet, since there weren't any differences. Once we implement differences in port 8 handling on BCM5301X all the code should be moved to the new branch and condition should be changed. -- Rafał ___ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel