DescriptionQ601
Q601FWBroadcomASIC interview problem
Locate the payload in an Ethernet frame
TechniquesFirmware & ValidationFirmware / Validationlocate the payload in an ethernet frame
DifficultyEasy
TopicFirmware & Validation
LanguageC
Requirements4 checkpoints
01
Problem
Firmware receives a complete Ethernet frame without FCS. It supports either an untagged header or one 802.1Q tag with TPID 0x8100. Write a bounded C parser that returns EtherType and payload offset.
Starting declarationC
int eth_payload(const uint8_t *f, size_t n,
uint16_t *type, size_t *offset);Example input and output
Use this case to check your interpretationInput
An untagged frame of at least 14 bytes has f[12]=8'h08 and f[13]=8'h00.Output
Return 0 with type=16'h0800 and offset=14.Explanation
The big-endian field is not the VLAN TPID 16'h8100, so it is the EtherType and the payload begins after the base Ethernet header.
02
Requirements (4)
- Require f, type, and offset and require n>=14; return -1 and preserve outputs otherwise.
- Read the big-endian field at bytes 12 and 13. If it is not 0x8100, return it as type and set offset=14.
- If it is 0x8100, require n>=18, read big-endian inner EtherType at bytes 16 and 17, and set offset=18.
- On success write both outputs and return 0; support exactly zero or one VLAN tag.
