Bluetooth Low Energy

Parsing BLE messages

When processing Bluetooth Low Energy messages sent to a compatible interface, the whad_ble_get_message_type() function returns the corresponding message type (whad_ble_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 BLE device scanning. The supported commands must also be indicated in the interface’s capabilities as described in Discovery of interface characteristics.

void process_ble_message(Message *p_message)
{
    Message response;

    switch (whad_ble_get_message_type(p_message))
    {
        case WHAD_BLE_SCAN_MODE:
        {
            /* Configure our interface in scan mode ... (custom code) */
            /* ... */

            /* Return a success message. */
            whad_generic_cmd_result(&response, WHAD_RESULT_SUCCESS);
        }
        break;

        case WHAD_BLE_START:
        {
            /* Start current mode. */
            /* ... */

            /* Return a success message. */
            whad_generic_cmd_result(&response, WHAD_RESULT_SUCCESS);
        }
        break;

        case WHAD_BLE_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);
}

Bluetooth Low Energy API reference

Defines

BLE_PREPSEQ_PACKET_MAX_SIZE
BLE_PREPSEQ_TRIGGER_MAX_SIZE
BLE_RSSI_NONE

Functions

whad_ble_msgtype_t whad_ble_get_message_type(Message *p_message)
whad_result_t whad_ble_raw_pdu(Message *p_message, uint32_t channel, int32_t rssi, uint32_t conn_handle, uint32_t access_address, uint8_t *p_pdu, int length, uint32_t crc, bool crc_validity, uint32_t timestamp, uint32_t relative_timestamp, whad_ble_direction_t direction, bool processed, bool decrypted, bool use_timestamp)

Initialize a message reporting a BLE raw PDU.

Parameters:
  • p_message[inout] Pointer to the message structure to initialize

  • channel[in] Channel on which this PDU has been received

  • rssi[in] Received Signal Strength Indicator

  • conn_handle[in] Connection handle

  • access_address[in] Access Address of the connection

  • p_pdu[in] Pointer to a byte array containing the PDU

  • length[in] Length of the data PDU, in bytes

  • crc[in] PDU CRC value

  • crc_validity[in] Set to true if CRC matches the expected value, false otherwise

  • timestamp[in] PDU timestamp (in micro-seconds)

  • relative_timestamp[in] PDU relative timestamp (number of micro-seconds in the last connection event)

  • direction[in] Direction of the PDU (master -> slave / slave -> master)

  • processed[in] Set to true if PDU has been processed by the device, false otherwise

  • decrypted[in] Set to true if PDU has been decrypted, false otherwise

  • use_timestamp[in] If set to true, message will include timestamp and relative timestamp

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message pointer or PDU pointer.

whad_result_t whad_ble_pdu(Message *p_message, uint8_t *p_pdu, int length, whad_ble_direction_t direction, int conn_handle, bool processed, bool decrypted)

Initialize a message reporting a BLE link-layer data PDU.

Parameters:
  • p_message[inout] Pointer to the message structure to initialize

  • p_pdu[in] Pointer to a byte array containing the PDU

  • length[in] Length of the data PDU, in bytes

  • direction[in] Direction of the PDU (master -> slave / slave -> master)

  • conn_handle[in] Connection handle of the connection this PDU has been captured from

  • processed[in] Set to true if PDU has been processed by the device, false otherwise

  • decrypted[in] Set to true if PDU has been decrypted, false otherwise

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message pointer or PDU pointer.

whad_result_t whad_ble_pdu_parse(Message *p_message, whad_ble_pdu_t *p_parameters)

Parse a message reporting a BLE link-layer data PDU.

Parameters:
  • p_message[in] Pointer to the message structure to initialize

  • p_parameters[inout] Pointer to a whad_ble_pdu_t structure

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message pointer or PDU pointer.

whad_result_t whad_ble_notify_connected(Message *p_message, whad_ble_addrtype_t adv_addr_type, uint8_t *p_adv_addr, whad_ble_addrtype_t init_addr_type, uint8_t *p_init_addr, uint32_t conn_handle)

Initialize a message reporting a BLE connection.

Parameters:
  • p_message[inout] Pointer to the message structure to initialize

  • adv_addr_type[in] Advertiser address type (public/random)

  • p_adv_addr[in] Pointer to the advertiser BD address (6 bytes)

  • init_addr_type[in] Initiator address type (public/random)

  • p_init_addr[in] Pointer to the initiator BD address (6 bytes)

  • conn_handle[in] Connection handle of the connection this PDU has been captured from

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message pointer.

whad_result_t whad_ble_notify_disconnected(Message *p_message, uint32_t conn_handle, uint32_t reason)

Initialize a message reporting a BLE disconnection.

Parameters:
  • p_message[inout] Pointer to the message structure to initialize

  • conn_handle[in] Connection handle of the connection this PDU has been captured from

  • reason[in] Disconnection reason (as defined in the BLE specification)

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message pointer.

whad_result_t whad_ble_notify_disconnected_parse(Message *p_message, whad_ble_disconnected_params_t *p_parameters)

Parse a message reporting a BLE disconnection.

Parameters:
  • p_message[in] Pointer to the message structure to initialize

  • p_parameters[inout] Pointer to a structure that will contain the disconnection parameters

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message pointer.

whad_result_t whad_ble_set_bdaddress(Message *p_message, whad_ble_addrtype_t addr_type, uint8_t *p_bdaddr)

Initialize a message setting the BD address of the adapter.

Parameters:
  • p_message[inout] Pointer to the message structure to initialize

  • addr_type[in] BD address type

  • p_bdaddr[in] Pointer to a buffer containing the target BD address (6-byte array)

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message pointer.

whad_result_t whad_ble_set_bdaddress_parse(Message *p_message, whad_ble_addrtype_t *p_addr_type, uint8_t *p_bdaddr)

Parse a message setting the BD address of the adapter.

Parameters:
  • p_message[in] Pointer to the message structure to parse

  • p_addr_type[out] Pointer to output BD address type

  • p_bdaddr[out] Pointer to a buffer where the target BD address will be copied (6-byte array)

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message pointer.

whad_result_t whad_ble_sniff_adv(Message *p_message, bool use_ext_adv, uint32_t channel, uint8_t *p_bdaddr)

Initialize a message enabling sniffing mode for advertisements.

Parameters:
  • p_message[inout] Pointer to the message structure to initialize

  • use_ext_adv[in] If set to true, sniffer will sniff extended advertisements

  • channel[in] The advertising channel on which the sniffing must be performed

  • p_bdaddr[in] The target BD address, as a pointer to a 6-byte array

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message pointer.

whad_result_t whad_ble_sniff_adv_parse(Message *p_message, whad_ble_sniff_adv_params_t *p_parameters)

Parse a message enabling sniffing mode for advertisements.

Parameters:
  • p_message[in] Pointer to the message structure to parse

  • p_parameters[inout] Pointer to a whad_ble_sniff_adv_params_t structure

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message pointer.

whad_result_t whad_ble_jam_adv(Message *p_message)

Initialize a message enabling advertisement jamming mode.

Parameters:

p_message[inout] Pointer to the message structure to initialize

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message pointer.

whad_result_t whad_ble_jam_adv_channel(Message *p_message, uint32_t channel)

Initialize a message enabling jamming on a specific advertising channel.

Parameters:
  • p_message[inout] Pointer to the message structure to initialize

  • channel[in] The advertising channel on which the jamming must be performed

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message pointer.

whad_result_t whad_ble_jam_adv_channel_parse(Message *p_message, uint32_t *p_channel)

Parse a message enabling jamming on a specific advertising channel.

Parameters:
  • p_message[in] Pointer to the message structure to parse

  • p_channel[inout] Pointer to the extracted advertising channel

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message pointer.

whad_result_t whad_ble_sniff_conn_req(Message *p_message, bool show_empty_packets, bool show_adv, uint32_t channel, uint8_t *p_bdaddr)

Initialize a message enabling connection request sniffing mode.

Parameters:
  • p_message[inout] Pointer to the message structure to initialize

  • show_empty_packets[in] If set to true, empty packets will also be reported

  • show_adv[in] If set to true, advertisements received during the device lookup phase will be reported

  • channel[in] If specified, will listen only on this channel

  • p_bdaddr[in] Target BD address

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message pointer.

whad_result_t whad_ble_sniff_conn_req_parse(Message *p_message, whad_ble_sniff_connreq_params_t *p_parameters)

Parse a connection sniffing request message.

Parameters:
  • p_message – Pointer to a Message structure.

  • p_parameters – Pointer to a whad_ble_sniff_connreq_params_t structure

Returns:

whad_result_t

whad_result_t whad_ble_sniff_access_address(Message *p_message, uint8_t *p_channelmap)

Initialize a message enabling access address sniffing.

Parameters:
  • p_message[inout] Pointer to the message structure to initialize

  • p_channelmap[in] Channel map to use for sniffing as a 5-byte array (40 bits)

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message pointer.

whad_result_t whad_ble_sniff_access_address_parse(Message *p_message, uint8_t *p_channelmap)

Parse an access address sniffing message.

Parameters:
  • p_message[in] Pointer to the message to parse

  • p_channelmap[out] Pointer to a 5-byte array that will contain the extracted channel map

Returns:

whad_result_t

whad_result_t whad_ble_sniff_active_conn(Message *p_message, uint32_t access_address, uint32_t crc_init, uint32_t hop_interval, uint32_t hop_increment, uint8_t *p_channelmap, uint8_t *p_channels)

Initialize a message enabling active connection sniffing.

Parameters:
  • p_message[inout] Pointer to the message structure to initialize

  • access_address[in] Access address of the active connection to sniff

  • crc_init[in] CRC initial value (seed)

  • hop_interval[in] Hopping interval

  • hop_increment[in] Hopping increment

  • p_channelmap[in] Provided channel map to use for synchronization

  • p_channels[in] A set of channels to use to dynamically reconstruct the channel map. This parameter is used when parallelized channel map recovery is enabled.

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message pointer.

whad_result_t whad_ble_sniff_active_conn_parse(Message *p_message, whad_ble_sniff_conn_params_t *p_parameters)

Parse an active connection sniffing message.

Parameters:
  • p_message[in] Pointer to the message to parse

  • p_parameters[out] Pointer to a whad_ble_sniff_conn_params_t structure that will contain the extracted parameters.

Returns:

whad_result_t

whad_result_t whad_ble_jam_active_conn(Message *p_message, uint32_t access_address)

Initialize an active connection jamming message.

Parameters:
  • p_message[inout] Pointer to the message structure to initialize

  • access_address[in] Access address of the active connection to sniff

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message pointer.

whad_result_t whad_ble_jam_active_conn_parse(Message *p_message, uint32_t *p_access_address)

Parse an active connection jamming message.

Parameters:
  • p_message[in] Pointer to the message structure to parse

  • p_access_address[inout] Pointer to the extracted access address

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message pointer.

whad_result_t whad_ble_scan_mode(Message *p_message, bool active_scan)

Initialize a message enabling scanning mode.

Parameters:
  • p_message[inout] Pointer to the message structure to initialize

  • active_scan[in] If set to true, the adapter will send SCAN_REQ PDU to get additional data

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message pointer.

whad_result_t whad_ble_scan_mode_parse(Message *p_message, bool *p_active_scan)

Parse a scan mode message.

Parameters:
  • p_message[in] Pointer to the message to parse.

  • p_active_scan[out] Pointer to a boolean value, if true an active scan has to be performed.

Returns:

whad_result_t

whad_result_t whad_ble_adv_mode(Message *p_message, uint8_t *p_adv_data, int adv_data_length, uint8_t *p_scanrsp_data, int scanrsp_data_length)

Initialize a message enabling advertising mode (and only advertising)

Advertising data and scan response data buffers cannot exceed 31-byte each.

Parameters:
  • p_message[inout] Pointer to the message structure to initialize

  • p_adv_data[in] Pointer to a byte array containing the advertising data

  • adv_data_length[in] Length of advertising data

  • p_scanrsp_data[in] Pointer to a byte array containing the scan response data

  • scanrsp_data_length[in] Length of scan response data

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message pointer.

whad_result_t whad_ble_adv_mode_parse(Message *p_message, whad_ble_adv_mode_params_t *p_parameters)
whad_result_t whad_ble_set_adv_data(Message *p_message, uint8_t *p_adv_data, int adv_data_length, uint8_t *p_scanrsp_data, int scanrsp_data_length)

TODO Not yet supported, need some fix in whad-protocol.

whad_result_t whad_ble_set_adv_data_parse(Message *p_message, uint8_t *p_adv_data, int *p_adv_data_length, uint8_t *p_scanrsp_data, int *p_scanrsp_data_length)
whad_result_t whad_ble_central_mode(Message *p_message)

Initialize a message enabling central mode.

Parameters:

p_message[inout] Pointer to the message structure to initialize

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message pointer.

whad_result_t whad_ble_connect_to(Message *p_message, uint8_t *p_bdaddr, whad_ble_addrtype_t addr_type, uint32_t access_address, uint8_t *p_channelmap, uint32_t hop_interval, uint32_t hop_increment, uint32_t crc_init)

Initialize a message to initiate a connection to a specific device identified by its BD address.

Parameters:
  • p_message[inout] Pointer to the message structure to initialize

  • p_bdaddr[in] Pointer to the BD address of the device to connect to, as a 6-byte array

  • addr_type[in] Device address type

  • access_address[in] Specify the connection access address, if supported by the adapter

  • p_channelmap[in] Channel map to use for the connectionm if supported by the adapter

  • hop_interval[in] Hop interval to use for the connection, if supported by the adapter

  • hop_increment[in] Hop increment to use for the connection, if supported by the adapter

  • crc_init[in] CRC initial value (seed) to use for the connection, if supported by the adapter

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message pointer.

whad_result_t whad_ble_connect_to_parse(Message *p_message, whad_ble_connect_params_t *p_parameters)

Parse a message to initiate a connection to a specific device identified by its BD address.

Parameters:
  • p_message[in] Pointer to the message structure to initialize

  • p_parameters[inout] Pointer to a whad_ble_connect_params_t structure that will receive the extracted information

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message pointer or parameters pointer.

whad_result_t whad_ble_send_raw_pdu(Message *p_message, whad_ble_direction_t direction, uint32_t conn_handle, uint32_t access_address, uint8_t *p_pdu, int length, uint32_t crc, bool encrypt)

Initialize a message to send a raw PDU to a target device in an established connection.

Parameters:
  • p_message[inout] Pointer to the message structure to initialize

  • direction[in] Specify the target device (initiator or advertiser)

  • conn_handle[in] Connection handle

  • access_address[in] Specify the access address to use when sending the PDU

  • p_pdu[in] Pointer to a byte array containing the PDU to send

  • length[in] PDU length in bytes

  • crc[in] PDU CRC value

  • encrypt[in] If set to true, PDU will be encrypted with the current cryptographic material associated with the target connection

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message pointer.

whad_result_t whad_ble_send_raw_pdu_parse(Message *p_message, whad_ble_pdu_params_t *p_parameters)

parse a message to send a raw PDU to a target device in an established connection

Parameters:
  • p_message[inout] Pointer to the message structure to initialize

  • p_parameters[inout] Pointer to a whad_ble_pdu_params_t structure that will receive the extracted information

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message pointer.

whad_result_t whad_ble_send_pdu(Message *p_message, whad_ble_direction_t direction, uint32_t conn_handle, uint8_t *p_pdu, int length, bool encrypt)

Initialize a message to send a PDU to a target device in an established connection.

Parameters:
  • p_message[inout] Pointer to the message structure to initialize

  • direction[in] Specify the target device (initiator or advertiser)

  • conn_handle[in] Connection handle

  • p_pdu[in] Pointer to a byte array containing the PDU to send

  • length[in] PDU length in bytes

  • encrypt[in] If set to true, PDU will be encrypted with the current cryptographic material associated with the target connection

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message pointer.

whad_result_t whad_ble_send_pdu_parse(Message *p_message, whad_ble_pdu_params_t *p_parameters)

Parse a message to send a raw PDU to a target device in an established connection.

Parameters:
  • p_message[inout] Pointer to the message structure to initialize

  • p_parameters[inout] Pointer to a whad_ble_pdu_params_t structure that will receive the extracted information

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message pointer.

whad_result_t whad_ble_disconnect(Message *p_message, uint32_t conn_handle)

Initialize a message to disconnect from a device.

Parameters:
  • p_message[inout] Pointer to the message structure to initialize

  • conn_handle[in] Connection handle

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message pointer.

whad_result_t whad_ble_disconnect_parse(Message *p_message, uint32_t *p_conn_handle)

Parse a message to disconnect from a device.

Parameters:
  • p_message[in] Pointer to the message structure to initialize

  • p_conn_handle[inout] Pointer to the retrieved connection handle

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message pointer or connection handle pointer.

whad_result_t whad_ble_peripheral_mode(Message *p_message, uint8_t *p_adv_data, int adv_data_length, uint8_t *p_scanrsp_data, int scanrsp_data_length)

Initialize a message to enable Peripheral mode.

Parameters:
  • p_message[inout] Pointer to the message structure to initialize

  • p_adv_data[in] Pointer to the advertising data to use when advertising this peripheral

  • adv_data_length[in] Length of advertising data in bytes (max length: 31)

  • p_scanrsp_data[in] Pointer to the scan response data to use when advertising this peripheral

  • scanrsp_data_length[in] Length of scan response data in bytes (max length: 31)

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message pointer.

whad_result_t whad_ble_peripheral_mode_parse(Message *p_message, whad_ble_adv_mode_params_t *p_parameters)
whad_result_t whad_ble_start(Message *p_message)

Initialize a message to start the current mode.

Parameters:

p_message[inout] Pointer to the message structure to initialize

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message pointer.

whad_result_t whad_ble_stop(Message *p_message)

Initialize a message to stop the current mode.

Parameters:

p_message[inout] Pointer to the message structure to initialize

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message pointer.

whad_result_t whad_ble_hijack_master(Message *p_message, uint32_t access_address)

Initialize a message to hijack the master (initiator) of an existing connection.

Parameters:
  • p_message[inout] Pointer to the message structure to initialize

  • access_address[in] Access address of the target connection

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message pointer.

whad_result_t whad_ble_hijack_master_parse(Message *p_message, uint32_t *p_access_address)

Parse a message to hijack the master (initiator) of an existing connection.

Parameters:
  • p_message[in] Pointer to the message structure to parse

  • p_access_address[inout] pointer to the extracted access address

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message pointer.

whad_result_t whad_ble_hijack_slave(Message *p_message, uint32_t access_address)

Initialize a message to hijack the slave (advertiser) of an existing connection.

Parameters:
  • p_message[inout] Pointer to the message structure to initialize

  • access_address[in] Access address of the target connection

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message pointer.

whad_result_t whad_ble_hijack_slave_parse(Message *p_message, uint32_t *p_access_address)

Parse a message to hijack the slave (advertiser) of an existing connection.

Parameters:
  • p_message[in] Pointer to the message structure to parse

  • p_access_address[inout] pointer to the extracted access address

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message pointer.

whad_result_t whad_ble_hijack_both(Message *p_message, uint32_t access_address)

Initialize a message to hijack both the master (initiator) and the slave (advertiser) of an existing connection.

Parameters:
  • p_message[inout] Pointer to the message structure to initialize

  • access_address[in] Access address of the target connection

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message pointer.

whad_result_t whad_ble_hijack_both_parse(Message *p_message, uint32_t *p_access_address)

Parse a message to hijack both the master (initiator) and the slave (advertiser) of an existing connection.

Parameters:
  • p_message[in] Pointer to the message structure to parse

  • p_access_address[inout] pointer to the extracted access address

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message pointer.

whad_result_t whad_ble_set_encryption(Message *p_message, uint32_t conn_handle, bool enabled, uint8_t *p_ll_key, uint8_t *p_ll_iv, uint8_t *p_key, uint8_t *p_rand, uint8_t *p_ediv)

Initialize a message to enable encryption.

The p_ll_key and p_ll_iv parameters will be used by WHAD adapters supporting BLE encryption while p_key, p_rand and p_ediv will be used by adapters that cannot control the link-layer. All these fields must be set.

Parameters:
  • p_message[inout] Pointer to the message structure to initialize

  • conn_handle[in] Connection handle

  • enabled[in] If set to true, encryption is immediately enabled. If set to false, cryptographic material is provided but encryption must be started later

  • p_ll_key[in] Pointer to a 16-byte array containing the encryption key (LTK)

  • p_ll_iv[in] Pointer to a 8-byte array containing the encryption IV

  • p_key[in] Pointer to a 16-byte array containing the encryption key

  • p_rand[in] Pointer to a 8-byte array containing the randomizer

  • p_ediv[in] Pointer to a 2-byte array containing the diversifier

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message pointer.

whad_result_t whad_ble_set_encryption_parse(Message *p_message, whad_ble_encryption_params_t *p_parameters)

Parse a BLE set encryption message and extract encryption parameters.

Parameters:
  • p_message[in] Pointer to a Message structure

  • p_parameters[out] Pointer to a whad_ble_encryption_params_t structure

Returns:

whad_result_t

whad_result_t whad_ble_reactive_jam(Message *p_message, uint32_t channel, uint8_t *p_pattern, int pattern_length, uint32_t position)

Initialize a message to enable reactive jamming mode.

In reactive jamming, we are waiting for a PDU matching a specific pattern and start jamming right after having receiving this pattern. This can be done only on a single channel that needs to be specified.

Parameters:
  • p_message[inout] Pointer to the message structure to initialize

  • channel[in] Channel to listen on

  • p_pattern[in] Pointer to a byte array specifying a matching pattern

  • pattern_length[in] Length of the matching pattern in bytes

  • position[in] Specify the expected offset in a PDU of the matching pattern

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message pointer.

whad_result_t whad_ble_reactive_jam_parse(Message *p_message, whad_ble_reactive_jam_params_t *p_parameters)
whad_result_t _whad_ble_sequence_copy_packets(Message *p_message, whad_prepared_packet_t *p_packets, int pkt_count)

Copy a sequence of prepared packets into a BLE prepared sequence message.

Parameters:
  • p_message[inout] Pointer to the target message structure

  • p_packets[in] Pointer to an array of prepared packets

  • pkt_count[in] Number of packets to copy

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message pointer.

whad_result_t whad_ble_prepare_sequence_get_trigger_type(Message *p_message, whad_ble_trigger_t *p_trigger_type)
whad_result_t whad_ble_prepare_sequence_on_recv(Message *p_message, uint8_t *p_pattern, uint8_t *p_mask, int length, int offset, uint32_t id, whad_ble_direction_t direction, whad_prepared_packet_t *p_packets, int pkt_count)

Initialize a message to send a sequence of PDU when a matching PDU is received.

Parameters:
  • p_message[inout] Pointer to the message structure to initialize

  • p_pattern[in] Pointer to a byte array containing the matching pattern

  • p_mask[in] Pointer to a byte array specifying the matching mask to apply to the pattern

  • length[in] Pattern and mask length

  • offset[in] Offset at which the matching pattern must be applied

  • id[in] Prepared sequence identifier

  • direction[in] PDU sequence direction

  • p_packets[in] Pointer to an array of prepared packets

  • pkt_count[in] Number of packets in the prepared packets sequence

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid pointer or packet size exceed the allowed size.

whad_result_t whad_ble_prepare_sequence_manual(Message *p_message, uint32_t id, whad_ble_direction_t direction, whad_prepared_packet_t *p_packets, int pkt_count)

Initialize a message to send a sequence of PDU all at once on a manual trigger.

Parameters:
  • p_message[inout] Pointer to the message structure to initialize

  • id[in] Prepared sequence identifier

  • direction[in] PDU sequence direction

  • p_packets[in] Pointer to an array of prepared packets

  • pkt_count[in] Number of packets in the prepared packets sequence

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid pointer or packet size exceed the allowed size.

whad_result_t whad_ble_prepare_sequence_manual_parse(Message *p_message, whad_ble_prepseq_params_t *p_parameters)

Parse a message to send a sequence of PDU all at once on a manual trigger.

Parameters:
  • p_message[in] Pointer to the message to parse

  • p_parameters[inout] Pointer to a whad_ble_prepseq_params_t

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid pointer or packet size exceed the allowed size.

whad_result_t whad_ble_prepare_sequence_conn_evt(Message *p_message, uint32_t connection_event, uint32_t id, whad_ble_direction_t direction, whad_prepared_packet_t *p_packets, int pkt_count)

Initialize a message to send a sequence of PDU all at once on a specific connection event.

Parameters:
  • p_message[inout] Pointer to the message structure to initialize

  • connection_event[in] Connection event value at which the PDUs must be sent

  • id[in] Prepared sequence identifier

  • direction[in] PDU sequence direction

  • p_packets[in] Pointer to an array of prepared packets

  • pkt_count[in] Number of packets in the prepared packets sequence

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid pointer or packet size exceed the allowed size.

whad_result_t whad_ble_prepare_sequence_conn_evt_parse(Message *p_message, whad_ble_prepseq_params_t *p_parameters)

Parse a message to send a sequence of PDU all at once on a connection event trigger.

Parameters:
  • p_message[in] Pointer to the message to parse

  • p_parameters[inout] Pointer to a whad_ble_prepseq_params_t

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid pointer or packet size exceed the allowed size.

whad_result_t whad_ble_prepare_sequence_trigger(Message *p_message, uint32_t id)

Initialize a message to manually trigger the sending of a prepared sequence of PDUs.

Parameters:
  • p_message[inout] Pointer to the message structure to initialize

  • id[in] Prepared sequence identifier

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid pointer or packet size exceed the allowed size.

whad_result_t whad_ble_prepare_sequence_trigger_parse(Message *p_message, uint32_t *p_id)

Parse a message to manually trigger the sending of a prepared sequence of PDUs.

Parameters:
  • p_message[in] Pointer to the message structure to initialize

  • p_id[inout] Pointer to the trigger id

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid pointer or packet size exceed the allowed size.

whad_result_t whad_ble_prepare_sequence_delete(Message *p_message, uint32_t id)

Initialize a message to delete a previously registered prepared sequence.

Parameters:
  • p_message[inout] Pointer to the message structure to initialize

  • id[in] Prepared sequence identifier

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid pointer or packet size exceed the allowed size.

whad_result_t whad_ble_triggered(Message *p_message, uint32_t id)

Initialize a message to notify that a prepared sequence has been triggered.

Parameters:
  • p_message[inout] Pointer to the message structure to initialize

  • id[in] Prepared sequence identifier

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid pointer or packet size exceed the allowed size.

whad_result_t whad_ble_triggered_parse(Message *p_message, uint32_t *p_id)

Parse a message to notify that a prepared sequence has been triggered.

Parameters:
  • p_message[in] Pointer to the message structure to initialize

  • p_id[inout] Pointer to the sequence id

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid pointer or packet size exceed the allowed size.

whad_result_t whad_ble_access_address_discovered(Message *p_message, uint32_t access_address, uint32_t timestamp, int32_t rssi, bool inc_ts, bool inc_rssi)

Initialize a message to notify that an access address has been discovered.

Parameters:
  • p_message[inout] Pointer to the message structure to initialize

  • access_address[in] Discovered access address

  • timestamp[in] Timestamp at which the address was discovered

  • rssi[in] Received Signal Strength Indicator

  • inc_ts[in] If set to true, the message will include a timestamp.

  • inc_rssi[in] If set to true, the message will include the RSSI.

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid pointer or packet size exceed the allowed size.

whad_result_t whad_ble_access_address_discovered_parse(Message *p_message, whad_ble_aa_disc_params_t *p_parameters)

Parse a message to notify that an access address has been discovered.

Parameters:
  • p_message[in] Pointer to the message structure to initialize

  • p_parameters[in] Pointer to a whad_ble_aa_disc_params_t structure

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid pointer or packet size exceed the allowed size.

whad_result_t whad_ble_adv_pdu(Message *p_message, whad_ble_advtype_t adv_type, int32_t rssi, uint8_t *p_bdaddr, whad_ble_addrtype_t addr_type, uint8_t *p_adv_data, int adv_data_length)

Initialize a message to notify an advertising PDU.

Parameters:
  • p_message[inout] Pointer to the message structure to initialize

  • adv_type[in] Advertisement type

  • rssi[in] Received Signal Strength Indicator

  • p_bdaddr[in] Pointer to a byte buffer containing the BD address (6 bytes)

  • addr_type[in] Specifies the advertiser’s BD address type (public/random)

  • p_adv_data[in] Pointer to a byte buffer containing the advertising data

  • adv_data_length[in] Length of advertising data in bytes

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid pointer or packet size exceed the allowed size.

whad_result_t whad_ble_adv_pdu_parse(Message *p_message, whad_ble_adv_pdu_t *p_parameters)

Parse a message notifying an advertising PDU.

Parameters:
  • p_message[in] Pointer to the message to parse

  • p_parameters[inout] Pointer to a whad_ble_prepseq_params_t

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid pointer or packet size exceed the allowed size.

whad_result_t whad_ble_synchronized(Message *p_message, uint32_t access_address, uint32_t crc_init, uint32_t hop_interval, uint32_t hop_increment, uint8_t *p_channelmap)

Initialize a message to notify that the adapter has synchronized with an active connection.

Parameters:
  • p_message[inout] Pointer to the message structure to initialize

  • access_address[in] Access address

  • crc_init[in] CRC initial value (seed)

  • hop_interval[in] Connection recovered hop interval

  • hop_increment[in] Connection recovered hop increment

  • p_channelmap[in] Connection channel map

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid pointer or packet size exceed the allowed size.

whad_result_t whad_ble_synchronized_parse(Message *p_message, whad_ble_synchro_params_t *p_parameters)

Parse a message to notify that the adapter has synchronized with an active connection.

Parameters:
  • p_message[in] Pointer to the message structure to initialize

  • p_parameters[inout] Pointer to a whad_ble_synchro_params_t structure

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid pointer or packet size exceed the allowed size.

whad_result_t whad_ble_desynchronized(Message *p_message, uint32_t access_address)

Initialize a message to notify that the adapter has been desynchronized from an active connection.

Parameters:
  • p_message[inout] Pointer to the message structure to initialize

  • access_address[in] Access address

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid pointer or packet size exceed the allowed size.

whad_result_t whad_ble_desynchronized_parse(Message *p_message, uint32_t *p_access_address)

Parse a message to notify that the adapter has been desynchronized from an active connection.

Parameters:
  • p_message[in] Pointer to the message structure to initialize

  • p_access_address[inout] Pointer to the access address of the desynchronized connection

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid pointer or packet size exceed the allowed size.

whad_result_t whad_ble_hijacked(Message *p_message, uint32_t access_address, bool success)

Initialize a message to notify that the adapter has successfully (or not) hijacked a connection.

Parameters:
  • p_message[inout] Pointer to the message structure to initialize

  • access_address[in] Access address

  • success[in] Set to true to notify a successful hijacking, false otherwise.

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid pointer or packet size exceed the allowed size.

whad_result_t whad_ble_hijacked_parse(Message *p_message, whad_ble_hijacked_params_t *p_parameters)

Parse a message to notify that the adapter has successfully (or not) hijacked a connection.

Parameters:
  • p_message[in] Pointer to the message structure to initialize

  • p_parameters[inout] Pointer to the message parameters

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid pointer or packet size exceed the allowed size.

whad_result_t whad_ble_injected(Message *p_message, uint32_t access_address, uint32_t attempts, bool success)

Initialize a message to notify that the adapter has successfully (or not) hijacked a connection.

Parameters:
  • p_message[inout] Pointer to the message structure to initialize

  • access_address[in] Access address

  • attempts[in] Number of attempts

  • success[in] Set to true to notify a successful hijacking, false otherwise.

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid pointer or packet size exceed the allowed size.

whad_result_t whad_ble_injected_parse(Message *p_message, whad_ble_injected_params_t *p_parameters)

Parse a message to notify that the adapter has successfully (or not) hijacked a connection.

Parameters:
  • p_message[in] Pointer to the message structure to initialize

  • p_parameters[inout] Pointer to a structure containing the parameters

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid pointer or packet size exceed the allowed size.