cybersecurity · intermediate · ~15 min · safe pentest lab

802.11 frame type

Extract a bitfield from a control byte.

Challenge

Extract the 2-bit frame TYPE from an 802.11 Frame Control byte.

Task

Implement int frame_type(unsigned char fc0) that returns the type field: bits 2-3 of fc0, i.e. (fc0 >> 2) & 0x3.

Input

  • fc0: the first byte of the Frame Control field. The grader passes fixed bytes.

Output

Returns int: the 2-bit type (0=management, 1=control, 2=data, 3=reserved).

Example

frame_type(0x00)   ->   0   (management)
frame_type(0x04)   ->   1   (control)
frame_type(0x08)   ->   2   (data)

Edge cases

  • Subtype and protocol-version bits are masked out by & 0x3.

Rules

  • One shift and one mask.

Input format

The Frame Control first byte fc0.

Output format

An int: the 2-bit frame type (fc0 >> 2) & 0x3.

Constraints

Shift right 2, mask 0x3.

Starter code

int frame_type(unsigned char fc0) {
    /* TODO */
    return 0;
}

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