Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/block.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Comment thread
fderepas marked this conversation as resolved.
POUCH_STATIC_ASSERT((CONFIG_POUCH_BLOCK_SIZE & (CONFIG_POUCH_BLOCK_SIZE - 1)) == 0,
"CONFIG_POUCH_BLOCK_SIZE must be a power of two");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually explicitly want to avoid this, as the rounding down is deliberate on the device side. As the block size always has to be a power of two, rounding down works well here as well, as long as we account for it when calculating the capacity of the block.

I made a counter proposal for this problem in #336, which changes the uplink module to use the appropriate block API for calculating the capacity of the buffer.


int block_decode_hdr(struct pouch_bufview *v,
uint16_t *block_size,
uint8_t *stream_id,
Expand Down
7 changes: 4 additions & 3 deletions src/gateway/uplink.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "uplink.h"
#include "../buf.h"
#include "../block.h"

POUCH_LOG_REGISTER(gw_uplink, CONFIG_POUCH_GATEWAY_LOG_LEVEL);

Expand Down Expand Up @@ -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,
Expand Down
Loading