cybersecurity · beginner · ~15 min · safe pentest lab

BLE AD structure length

Read the AD length byte.

Challenge

Read the length byte of a BLE advertising-data structure — the first step in walking a Length-Type-Value record.

Task

Implement int ad_length(const unsigned char *ad) that returns the length byte at offset 0. This length covers the type plus the value bytes.

Input

  • ad: a byte buffer holding one BLE AD structure ([length][type][value...]). The grader passes a fixed buffer.

Output

Returns int: ad[0], the length of the type+value portion.

Example

ad = 0x02 0x01 0x06
ad_length(ad)   ->   2

Edge cases

  • The length byte does not include itself.

Input format

A byte buffer ad holding one BLE AD structure.

Output format

An int: the length byte ad[0].

Constraints

The length is byte 0 and covers type+value.

Starter code

int ad_length(const unsigned char *ad) {
    /* TODO */
    return 0;
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.