cybersecurity · beginner · ~15 min · safe pentest lab

BLE AD type

Read the AD type byte.

Challenge

Read the type byte of a BLE advertising-data structure — it tells you how to interpret the value that follows.

Task

Implement int ad_type(const unsigned char *ad) that returns the type byte at offset 1.

Input

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

Output

Returns int: ad[1], the AD type (e.g. 0x01 = flags, 0x09 = complete local name).

Example

ad = 0x02 0x01 0x06          ->   ad_type(ad) -> 1   (flags)
ad = 0x05 0x09 'a' 'b' 'c'   ->   ad_type(ad) -> 9   (complete local name)

Edge cases

  • The type is always at offset 1, right after the length byte.

Input format

A byte buffer ad holding one BLE AD structure.

Output format

An int: the type byte ad[1].

Constraints

The type is byte 1.

Starter code

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

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