Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: Bluetooth: Tester: BTP MTU handling improvements #84301

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

sjanc
Copy link
Collaborator

@sjanc sjanc commented Jan 21, 2025

This is not allowed by C11 and may cause issues if GNU extensions are disabled.

@zephyrbot zephyrbot added area: Bluetooth area: Bluetooth Qualification Bluetooth Qualification -related issues and pull requests labels Jan 21, 2025
@zephyrbot zephyrbot requested review from jhedberg and Thalley January 21, 2025 12:13
struct btp_hdr hdr;
};
uint8_t data[BTP_MTU]; /* includes btp header */
uint8_t rsp[BTP_MTU - sizeof(struct btp_hdr)];
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider defining a BTP_RSP_MTU or something.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

RSP has same MTU, it is just that we don't have (need) header in response buffer (since data from command header is used)

uint8_t status;
uint16_t rsp_len = 0;
uint16_t len;

cmd = k_fifo_get(&cmds_queue, K_FOREVER);
hdr = (struct btp_hdr *)cmd->data;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we have an

Suggested change
hdr = (struct btp_hdr *)cmd->data;
hdr = (struct btp_hdr *)cmd->data;
__ASSERT_NO_MSG(hdr->len <= BTP_DATA_MAX_SIZE);

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

actually, I'm not sure if this should be assert as this means we assert on invalid command, I'll make this runtime check and simply return error (like we do for unknown command

@Thalley
Copy link
Collaborator

Thalley commented Jan 21, 2025

The commit message doesn't really make sense anymore since hdr is not longer in the middle of the struct

This may cause some compiler warnings due to flexible array being
used in btp_hdr. Simply avoid it and do explicit pointer type cast
where needed.

Signed-off-by: Szymon Janc <[email protected]>
@sjanc sjanc changed the title tests: Bluetooth: Tester: Avoid flexible array in middle of struct tests: Bluetooth: Tester: BTP MTU handling improvements Jan 24, 2025
Make sure MTU is validated to avoid reading pass command buffer.
Also make more explicit check in response length validation.

Signed-off-by: Szymon Janc <[email protected]>
Comment on lines +104 to +106
if (len > BTP_DATA_MAX_SIZE) {
status = BTP_STATUS_FAILED;
} else if (btp->index != hdr->index) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm, now I wonder if it's really need as we do have } else if ((btp->expect_len >= 0) && (btp->expect_len != len)) { which I guess would already catch it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Bluetooth Qualification Bluetooth Qualification -related issues and pull requests area: Bluetooth
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants