Skip to content

Conversation

SeppoTakalo
Copy link
Contributor

Instead of relying non-standard compiler behavior, define encode and decode functions for all CMUX command structures.

Drop:

struct modem_cmux_command *modem_cmux_command_wrap(const uint8_t *data);
static int modem_cmux_wrap_command(struct modem_cmux_command **command, const uint8_t *data,
				   uint16_t data_len);

And replace with:

static struct modem_cmux_command_type modem_cmux_command_type_decode(const uint8_t byte);
static uint8_t modem_cmux_command_type_encode(const struct modem_cmux_command_type type);
static struct modem_cmux_command_length modem_cmux_command_length_decode(const uint8_t byte);
static uint8_t modem_cmux_command_length_encode(const struct modem_cmux_command_length length);
static struct modem_cmux_command modem_cmux_command_decode(const uint8_t *data, size_t len);
static int modem_cmux_command_encode(uint8_t *buf, size_t len,
				     const struct modem_cmux_command *command);

as previous _wrap_ functions were relying on:

struct modem_cmux_command_type {
	uint8_t ea: 1;
	uint8_t cr: 1;
	uint8_t value: 6;
};

to be placed correctly. But as discussed on PR #97569 here this is non-standard behavior.
Works on GCC on Arm and seem to be working on GCC on X86_64 native_sim, but we should not rely on that.

@SeppoTakalo
Copy link
Contributor Author

Fixed the compilation issues.
That was a real bug... not GCC failure.

Looks like we need to have static buffer instead of flexible array member, because we end up decoding the whole command and its included data.

Instead of relying non-standard compiler behavior, define
encode and decode functions for all CMUX command structures.

Final command is encoded into a shared buffer, because it is
always copied directly to TX ringbuffer.

Signed-off-by: Seppo Takalo <[email protected]>
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants