IEEE 802.15.4
Parsing Dot15d4 messages
When processing Dot15d4 messages sent to a compatible interface,
the whad_dot15d4_get_message_type() function returns the corresponding
message type (whad_dot15d4_msgtype_t). This message type is then used
to process and parse the incoming message.
The following example code shows a message processing function defined for a compatible interface that only supports Dot15d4 packet sniffing. The supported commands must also be indicated in the interface’s capabilities as described in Discovery of interface characteristics.
void process_dot15d4_message(Message *p_message)
{
Message response;
switch (whad_dot15d4_get_message_type(p_message))
{
case WHAD_DOT15D4_SNIFF:
{
/* Configure our interface in sniff mode ... (custom code) */
/* ... */
/* Return a success message. */
whad_generic_cmd_result(&response, WHAD_RESULT_SUCCESS);
}
break;
case WHAD_DOT15D4_START:
{
/* Start current mode. */
/* ... */
/* Return a success message. */
whad_generic_cmd_result(&response, WHAD_RESULT_SUCCESS);
}
break;
case WHAD_DOT15D4_STOP:
{
/* Stop current mode. */
/* ... */
/* Return a success message. */
whad_generic_cmd_result(&response, WHAD_RESULT_SUCCESS);
}
break;
default:
{
/* Return an error message. */
whad_generic_cmd_result(&response, WHAD_RESULT_ERROR);
}
break;
}
/* Send the response to the host. */
whad_send_message(&response);
}
Dot15d4 API reference
Defines
-
DOT15D4_PACKET_MAX_SIZE
Enums
-
enum whad_dot15d4_msgtype_t
Values:
-
enumerator WHAD_DOT15D4_UNKNOWN
-
enumerator WHAD_DOT15D4_SET_NODE_ADDRESS
-
enumerator WHAD_DOT15D4_SNIFF
-
enumerator WHAD_DOT15D4_JAM
-
enumerator WHAD_DOT15D4_NRG_DETECTION
-
enumerator WHAD_DOT15D4_SEND
-
enumerator WHAD_DOT15D4_SEND_RAW
-
enumerator WHAD_DOT15D4_END_DEVICE_MODE
-
enumerator WHAD_DOT15D4_ROUTER_MODE
-
enumerator WHAD_DOT15D4_COORD_MODE
-
enumerator WHAD_DOT15D4_START
-
enumerator WHAD_DOT15D4_STOP
-
enumerator WHAD_DOT15D4_MITM_MODE
-
enumerator WHAD_DOT15D4_JAMMED
-
enumerator WHAD_DOT15D4_NRG_DETECTION_SAMPLE
-
enumerator WHAD_DOT15D4_RAW_PDU_RECEIVED
-
enumerator WHAD_DOT15D4_PDU_RECEIVED
-
enumerator WHAD_DOT15D4_UNKNOWN
Functions
-
whad_dot15d4_msgtype_t whad_dot15d4_get_message_type(Message *p_message)
-
whad_result_t whad_dot15d4_set_node_address(Message *p_message, whad_dot15d4_address_t *p_addr)
Create a SetNodeAddrCmd message.
- Parameters:
p_message – [in] Pointer to a NanoPb Message structure
p_addr – [in] Pointer to a whad_dot15d4_address_t structure containing the address
- Return values:
WHAD_SUCCESS – Success.
WHAD_ERROR – Invalid message or address pointer.
-
whad_result_t whad_dot15d4_set_node_address_parse(Message *p_message, whad_dot15d4_address_t *p_addr)
Parse a SetNodeAddrCmd message.
- Parameters:
p_message – [in] Pointer to a NanoPb Message structure
p_addr – [inout] Pointer to a whad_dot15d4_address_t structure
- Return values:
WHAD_SUCCESS – Success.
WHAD_ERROR – Invalid message or address pointer.
-
whad_result_t whad_dot15d4_sniff(Message *p_message, uint32_t channel)
Create a SniffCmd message.
- Parameters:
p_message – [in] Pointer to a NanoPb Message structure
channel – [in] Channel to sniff
- Return values:
WHAD_SUCCESS – Success.
WHAD_ERROR – Invalid message or address pointer.
-
whad_result_t whad_dot15d4_sniff_parse(Message *p_message, uint32_t *p_channel)
Parse a SniffCmd message.
- Parameters:
p_message – [in] Pointer to a NanoPb Message structure
p_channel – [inout] Pointer to an integer that will contain the extracted channel value
- Return values:
WHAD_SUCCESS – Success.
WHAD_ERROR – Invalid message or address pointer.
-
whad_result_t whad_dot15d4_jam(Message *p_message, uint32_t channel)
Create a JamCmd message.
- Parameters:
p_message – [in] Pointer to a NanoPb Message structure
channel – [in] Channel to sniff
- Return values:
WHAD_SUCCESS – Success.
WHAD_ERROR – Invalid message or address pointer.
-
whad_result_t whad_dot15d4_jam_parse(Message *p_message, uint32_t *p_channel)
Parse a JamCmd message.
- Parameters:
p_message – [in] Pointer to a NanoPb Message structure
p_channel – [inout] Pointer to an integer that will contain the extracted channel value
- Return values:
WHAD_SUCCESS – Success.
WHAD_ERROR – Invalid message or address pointer.
-
whad_result_t whad_dot15d4_energy_detect(Message *p_message, uint32_t channel)
Create a EnergyDetectionCmd message.
- Parameters:
p_message – [in] Pointer to a NanoPb Message structure
channel – [in] Channel to sniff
- Return values:
WHAD_SUCCESS – Success.
WHAD_ERROR – Invalid message or address pointer.
-
whad_result_t whad_dot15d4_energy_detect_parse(Message *p_message, uint32_t *p_channel)
Parse a EnergyDetectionCmd message.
- Parameters:
p_message – [in] Pointer to a NanoPb Message structure
p_channel – [inout] Pointer to an integer that will contain the extracted channel value
- Return values:
WHAD_SUCCESS – Success.
WHAD_ERROR – Invalid message or address pointer.
-
whad_result_t whad_dot15d4_send(Message *p_message, uint32_t channel, uint8_t *p_packet, int length)
Create a SendCmd message.
- Parameters:
p_message – [in] Pointer to a NanoPb Message structure
channel – [in] Channel on which the packet will be sent
p_packet – [in] Pointer to a Zigbee packet
length – [in] Packet length in bytes
- Return values:
WHAD_SUCCESS – Success.
WHAD_ERROR – Invalid message or address pointer.
-
whad_result_t whad_dot15d4_send_parse(Message *p_message, whad_dot15d4_send_params_t *p_params)
Parse a SendCmd message.
- Parameters:
p_message – [in] Pointer to a NanoPb Message structure
p_params – [inout] Pointer to a
whad_dot15d4_send_params_tstructure
- Return values:
WHAD_SUCCESS – Success.
WHAD_ERROR – Invalid message or address pointer.
-
whad_result_t whad_dot15d4_send_raw(Message *p_message, uint32_t channel, uint8_t *p_packet, int length, uint32_t fcs)
Create a SendRawCmd message.
- Parameters:
p_message – [in] Pointer to a NanoPb Message structure
channel – [in] Channel on which the packet will be sent
p_packet – [in] Pointer to a Zigbee packet
length – [in] Packet length in bytes
fcs – [in] Frame Control Sequence
- Return values:
WHAD_SUCCESS – Success.
WHAD_ERROR – Invalid message or address pointer.
-
whad_result_t whad_dot15d4_send_raw_parse(Message *p_message, whad_dot15d4_send_params_t *p_params)
Parse a SendRawCmd message.
- Parameters:
p_message – [in] Pointer to a NanoPb Message structure
p_params – [inout] Pointer to a
whad_dot15d4_send_params_tstructure
- Return values:
WHAD_SUCCESS – Success.
WHAD_ERROR – Invalid message or address pointer.
-
whad_result_t whad_dot15d4_end_device_mode(Message *p_message, uint32_t channel)
Create a EndDeviceCmd message.
- Parameters:
p_message – [in] Pointer to a NanoPb Message structure
channel – [in] Channel to use by the device
- Return values:
WHAD_SUCCESS – Success.
WHAD_ERROR – Invalid message or address pointer.
-
whad_result_t whad_dot15d4_end_device_mode_parse(Message *p_message, uint32_t *p_channel)
Parse a EndDeviceCmd message.
- Parameters:
p_message – [in] Pointer to a NanoPb Message structure
p_channel – [inout] Pointer to an integer that will contain the extracted channel value
- Return values:
WHAD_SUCCESS – Success.
WHAD_ERROR – Invalid message or address pointer.
-
whad_result_t whad_dot15d4_router_mode(Message *p_message, uint32_t channel)
Create a RouterCmd message.
- Parameters:
p_message – [in] Pointer to a NanoPb Message structure
channel – [in] Channel to use by the device
- Return values:
WHAD_SUCCESS – Success.
WHAD_ERROR – Invalid message or address pointer.
-
whad_result_t whad_dot15d4_router_mode_parse(Message *p_message, uint32_t *p_channel)
Parse a RouterCmd message.
- Parameters:
p_message – [in] Pointer to a NanoPb Message structure
p_channel – [inout] Pointer to an integer that will contain the extracted channel value
- Return values:
WHAD_SUCCESS – Success.
WHAD_ERROR – Invalid message or address pointer.
-
whad_result_t whad_dot15d4_coord_mode(Message *p_message, uint32_t channel)
Create a CoordinatorCmd message.
- Parameters:
p_message – [in] Pointer to a NanoPb Message structure
channel – [in] Channel to use by the device
- Return values:
WHAD_SUCCESS – Success.
WHAD_ERROR – Invalid message or address pointer.
-
whad_result_t whad_dot15d4_coord_mode_parse(Message *p_message, uint32_t *p_channel)
Parse a CoordinatorMsg message.
- Parameters:
p_message – [in] Pointer to a NanoPb Message structure
p_channel – [inout] Pointer to an integer that will contain the extracted channel value
- Return values:
WHAD_SUCCESS – Success.
WHAD_ERROR – Invalid message or address pointer.
-
whad_result_t whad_dot15d4_mitm_mode(Message *p_message, whad_dot15d4_mitm_role_t role)
Create a ManInTheMiddleCmd message.
- Parameters:
p_message – [in] Pointer to a NanoPb Message structure
role – [in] Mitm role to use
- Return values:
WHAD_SUCCESS – Success.
WHAD_ERROR – Invalid message or address pointer.
-
whad_result_t whad_dot15d4_mitm_mode_parse(Message *p_message, whad_dot15d4_mitm_role_t *p_role)
Parse a ManInTheMiddleCmd message.
- Parameters:
p_message – [in] Pointer to a NanoPb Message structure
p_role – [inout] Pointer to an integer that will contain the extracted MitM role
- Return values:
WHAD_SUCCESS – Success.
WHAD_ERROR – Invalid message or address pointer.
-
whad_result_t whad_dot15d4_start(Message *p_message)
Create a StartCmd message.
- Parameters:
p_message – [in] Pointer to a NanoPb Message structure
- Return values:
WHAD_SUCCESS – Success.
WHAD_ERROR – Invalid message or packet pointer.
-
whad_result_t whad_dot15d4_stop(Message *p_message)
Create a StopCmd message.
- Parameters:
p_message – [in] Pointer to a NanoPb Message structure
- Return values:
WHAD_SUCCESS – Success.
WHAD_ERROR – Invalid message or packet pointer.
-
whad_result_t whad_dot15d4_jammed(Message *p_message, uint32_t timestamp)
Create a Jammed message.
- Parameters:
p_message – [in] Pointer to a NanoPb Message structure
timestamp – [in] Timestamp at which the jamming has been detected
- Return values:
WHAD_SUCCESS – Success.
WHAD_ERROR – Invalid message or packet pointer.
-
whad_result_t whad_dot15d4_jammed_parse(Message *p_message, uint32_t *p_timestamp)
Parse a Jammed message.
- Parameters:
p_message – [in] Pointer to a NanoPb Message structure
p_timestamp – [inout] Pointer to the timestamp
- Return values:
WHAD_SUCCESS – Success.
WHAD_ERROR – Invalid message or channel pointer.
-
whad_result_t whad_dot15d4_energy_detect_sample(Message *p_message, uint32_t timestamp, uint32_t sample)
Create a EnergyDetectionSample message.
- Parameters:
p_message – [in] Pointer to a NanoPb Message structure
timestamp – [in] Sample timestamp
sample – [in] Sample value
- Return values:
WHAD_SUCCESS – Success.
WHAD_ERROR – Invalid message or packet pointer.
-
whad_result_t whad_dot15d4_energy_detect_sample_parse(Message *p_message, whad_dot15d4_ed_sample_t *p_sample)
Parse a EnergyDetectionSample message.
- Parameters:
p_message – [in] Pointer to a NanoPb Message structure
p_sample – [inout] Pointer to a
whad_dot15d4_ed_sample_tstructure
- Return values:
WHAD_SUCCESS – Success.
WHAD_ERROR – Invalid message or channel pointer.
-
whad_result_t whad_dot15d4_raw_pdu_received(Message *p_message, whad_dot15d4_recvd_packet_t *p_packet)
Create a RawPduReceived message.
- Parameters:
p_message – [inout] Pointer to a NanoPb Message structure
p_packet – [in] Pointer to a
whad_dot15d4_recvd_packet_tstructure
- Return values:
WHAD_SUCCESS – Success.
WHAD_ERROR – Invalid message or packet pointer.
-
whad_result_t whad_dot15d4_raw_pdu_received_parse(Message *p_message, whad_dot15d4_recvd_packet_t *p_packet)
Parse a RawPduReceived message.
- Parameters:
p_message – [in] Pointer to a NanoPb Message structure
p_packet – [inout] Pointer to a
whad_dot15d4_recvd_packet_tstructure
- Return values:
WHAD_SUCCESS – Success.
WHAD_ERROR – Invalid message or packet pointer.
-
whad_result_t whad_dot15d4_pdu_received(Message *p_message, whad_dot15d4_recvd_packet_t *p_packet)
Create a PduReceived message.
- Parameters:
p_message – [inout] Pointer to a NanoPb Message structure
p_packet – [in] Pointer to a
whad_dot15d4_recvd_packet_tstructure
- Return values:
WHAD_SUCCESS – Success.
WHAD_ERROR – Invalid message or packet pointer.
-
whad_result_t whad_dot15d4_pdu_received_parse(Message *p_message, whad_dot15d4_recvd_packet_t *p_packet)
Parse a PduReceived message.
- Parameters:
p_message – [in] Pointer to a NanoPb Message structure
p_packet – [inout] Pointer to a
whad_dot15d4_recvd_packet_tstructure
- Return values:
WHAD_SUCCESS – Success.
WHAD_ERROR – Invalid message or packet pointer.