diff --git a/src/block.h b/src/block.h index f5526d6a..dea57ff7 100644 --- a/src/block.h +++ b/src/block.h @@ -23,6 +23,14 @@ /** Maximum ciphertext size without the length of the size field */ #define MAX_BLOCK_SIZE_FIELD_VALUE (MAX_CIPHERTEXT_BLOCK_SIZE - sizeof(uint16_t)) +/* + * CONFIG_POUCH_BLOCK_SIZE feeds LOG2() above, which rounds DOWN to a power of two. + * A non-power-of-two value silently yields a smaller block everywhere it is used. Reject it at build + * time so the configured size is the size actually used. + */ +POUCH_STATIC_ASSERT((CONFIG_POUCH_BLOCK_SIZE & (CONFIG_POUCH_BLOCK_SIZE - 1)) == 0, + "CONFIG_POUCH_BLOCK_SIZE must be a power of two"); + int block_decode_hdr(struct pouch_bufview *v, uint16_t *block_size, uint8_t *stream_id, diff --git a/src/gateway/uplink.c b/src/gateway/uplink.c index bc7177c3..06085882 100644 --- a/src/gateway/uplink.c +++ b/src/gateway/uplink.c @@ -16,6 +16,7 @@ #include "uplink.h" #include "../buf.h" +#include "../block.h" POUCH_LOG_REGISTER(gw_uplink, CONFIG_POUCH_GATEWAY_LOG_LEVEL); @@ -191,11 +192,11 @@ static void send_uplink_via_cloud(struct pouch_gateway_uplink *uplink) } /* - * Max bytes per gateway block. Each pouch_buf slot holds at least - * CONFIG_POUCH_BLOCK_SIZE bytes; we conservatively use that as the + * Max payload bytes per gateway block. Each pouch_buf slot holds at least + * MAX_BLOCK_PAYLOAD_SIZE bytes; we conservatively use that as the * per-block capacity. */ -#define GW_BLOCK_MAX_BYTES CONFIG_POUCH_BLOCK_SIZE +#define GW_BLOCK_MAX_BYTES MAX_BLOCK_PAYLOAD_SIZE int pouch_gateway_uplink_write(struct pouch_gateway_uplink *uplink, const uint8_t *payload,