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

Compile-time (or run-time) validation for Advertisting data length #178

Closed
plaes opened this issue Nov 25, 2024 · 3 comments
Closed

Compile-time (or run-time) validation for Advertisting data length #178

plaes opened this issue Nov 25, 2024 · 3 comments

Comments

@plaes
Copy link
Contributor

plaes commented Nov 25, 2024

It's currently quite easy to create a compilable and runnable example code, but which doesn't show up in the nrf connect:

    let mut adv_data = [0; 31];
    AdStructure::encode_slice(
        &[
            AdStructure::Flags(LE_GENERAL_DISCOVERABLE | BR_EDR_NOT_SUPPORTED),
            AdStructure::ServiceUuids16(&[Uuid::Uuid16([0x0f, 0x18])]),
            AdStructure::CompleteLocalName(b"12345678901234567890123"), // Causes silent advertising failure
            // AdStructure::CompleteLocalName(b"1234567890123456789012"), // WORKS
        ],
        &mut adv_data[..],
    )?;
// ...
@plaes plaes changed the title Compile-time validation for Advertisting data Compile-time (or run-time) validation for Advertisting data length Nov 25, 2024
@jamessizeland
Copy link
Collaborator

This will be because of the packet size limit of 22 bytes for name. I've put a check in my latest PR, but I agree it could be a built in assertion.

    let name = if name.len() > 22 { 
         let truncated_name = &name[..22]; 
         info!("Name truncated to {}", truncated_name); 
         truncated_name 
     } else { 
         name 
     };

@plaes
Copy link
Contributor Author

plaes commented Nov 25, 2024

There's something else as well, because device does not appear when scanning with NRF connect on Android,

@lulf
Copy link
Member

lulf commented Nov 29, 2024

It will not advertise, because the advertise_task() will fail on insufficient space. Rather than truncating, I think it's better to panic on this error, I've raised a PR for this #187

@lulf lulf closed this as completed Nov 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants