Logitech Unifying

Parsing Logitech Unifying messages

When processing Logitech Unifying messages sent to a compatible interface, the whad_unifying_get_message_type() function returns the corresponding message type (whad_unifying_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 Logitech Unifying packet sniffing. The supported commands must also be indicated in the interface’s capabilities as described in Discovery of interface characteristics.

void process_unifying_message(Message *p_message)
{
    Message response;

    switch (whad_unifying_get_message_type(p_message))
    {
        case WHAD_UNIFYING_SNIFF_MODE:
        {
            /* Configure our interface in sniffing mode ... (custom code) */
            /* ... */

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

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

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

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

Logitech Unifying API reference

Defines

UNIFYING_PACKET_MAX_SIZE
UNIFYING_ADDR_MAX_SIZE

Enums

enum whad_unifying_msgtype_t

Message types.

This enum defines aliases for NanoPb commands bitmask in order to hide the NanoPb implementation.

This structure needs to be updated if a command is added or removed in WHAD protocol.

Values:

enumerator WHAD_UNIFYING_UNKNOWN
enumerator WHAD_UNIFYING_SET_NODE_ADDR
enumerator WHAD_UNIFYING_SNIFF_MODE
enumerator WHAD_UNIFYING_JAM_MODE
enumerator WHAD_UNIFYING_SEND
enumerator WHAD_UNIFYING_SEND_RAW
enumerator WHAD_UNIFYING_DONGLE_MODE
enumerator WHAD_UNIFYING_KEYBOARD_MODE
enumerator WHAD_UNIFYING_MOUSE_MODE
enumerator WHAD_UNIFYING_START
enumerator WHAD_UNIFYING_STOP
enumerator WHAD_UNIFYING_SNIFF_PAIRING
enumerator WHAD_UNIFYING_JAMMED
enumerator WHAD_UNIFYING_RAW_PDU_RECEIVED
enumerator WHAD_UNIFYING_PDU_RECEIVED

Functions

whad_unifying_msgtype_t whad_unifying_get_message_type(Message *p_message)
whad_result_t whad_unifying_set_node_address(Message *p_message, whad_unifying_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_unifying_addr_t structure containing the address

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message or address pointer.

whad_result_t whad_unifying_set_node_address_parse(Message *p_message, whad_unifying_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_esb_address_t structure

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message or address pointer.

whad_result_t whad_unifying_sniff(Message *p_message, whad_unifying_address_t *p_addr, uint32_t channel, bool show_ack)

Create a SniffCmd message.

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

  • p_addr[in] Pointer to a buffer containing the address bytes

  • channel[in] ESB channel to listen on

  • show_ack[in] If set to true, acknowledgements will be reported.

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message or address pointer.

whad_result_t whad_unifying_sniff_parse(Message *p_message, whad_unifying_sniff_params_t *p_params)

Parse a SniffCmd message.

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

  • p_params[inout] Pointer to a whad_esb_sniff_params_t structure

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message or address pointer.

whad_result_t whad_unifying_jam(Message *p_message, uint32_t channel)

Create a JamCmd message.

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

  • channel[in] ESB channel to listen on

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message pointer

whad_result_t whad_unifying_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 the ESB channel

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message or channel pointer.

whad_result_t whad_unifying_send(Message *p_message, uint32_t channel, int retr_count, uint8_t *p_packet, uint8_t packet_len)

Create a JamCmd message.

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

  • channel[in] Unifying channel to listen on

  • retr_count[in] Number of retransmissions

  • p_packet[in] Pointer to the packet bytes to send

  • packet_len[in] Packet length in bytes

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message or packet pointer.

whad_result_t whad_unifying_send_parse(Message *p_message, whad_unifying_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_unifying_send_params_t structure

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message or packet pointer.

whad_result_t whad_unifying_send_raw(Message *p_message, uint32_t channel, int retr_count, uint8_t *p_packet, uint8_t packet_len)

Create a SendRawCmd message.

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

  • channel[in] ESB channel to listen on

  • retr_count[in] Number of retransmissions

  • p_packet[in] Pointer to the packet bytes to send

  • packet_len[in] Packet length in bytes

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message or packet pointer.

whad_result_t whad_unifying_send_raw_parse(Message *p_message, whad_unifying_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_unifying_send_params_t structure

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message or packet pointer.

whad_result_t whad_unifying_dongle_mode(Message *p_message, uint32_t channel)

Create a LogitechDongleModeCmd message.

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

  • channel[in] Unifying channel to listen on

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message or packet pointer.

whad_result_t whad_unifying_dongle_mode_parse(Message *p_message, uint32_t *p_channel)

parse a LogitechDongleModeCmd message

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

  • p_channel[inout] Pointer to the unifying channel

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message or channel pointer.

whad_result_t whad_unifying_keyboard_mode(Message *p_message, uint32_t channel)

Create a LogitechKeyboardModeCmd message.

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

  • channel[in] Unifying channel to listen on

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message or packet pointer.

whad_result_t whad_unifying_keyboard_mode_parse(Message *p_message, uint32_t *p_channel)

Parse a LogitechKeyboardModeCmd message.

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

  • p_channel[inout] Pointer to the ESB channel

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message or channel pointer.

whad_result_t whad_unifying_mouse_mode(Message *p_message, uint32_t channel)

Create a LogitechKeyboardModeCmd message for mouse.

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

  • channel[in] Unifying channel to listen on

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message or packet pointer.

whad_result_t whad_unifying_mouse_mode_parse(Message *p_message, uint32_t *p_channel)

Parse a LogitechKeyboardModeCmd message (mouse)

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

  • p_channel[inout] Pointer to the Unifying channel

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message or channel pointer.

whad_result_t whad_unifying_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_unifying_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_unifying_sniff_pairing(Message *p_message)

Create a SniffPairingCmd 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_unifying_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_unifying_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_unifying_raw_pdu_received(Message *p_message, whad_unifying_recvd_packet_t *p_pdu)

Create a RawPduReceived message.

Parameters:
  • p_message[inout] Pointer to a NanoPb Message structure

  • p_pdu[in] Pointer to a whad_esb_recvd_packet_t structure

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message or packet pointer.

whad_result_t whad_unifying_raw_pdu_received_parse(Message *p_message, whad_unifying_recvd_packet_t *p_pdu)

Parse a RawPduReceived message.

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

  • p_pdu[inout] Pointer to a whad_esb_recvd_packet_t structure

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message or packet pointer.

whad_result_t whad_unifying_pdu_received(Message *p_message, whad_unifying_recvd_packet_t *p_pdu)

Create a PduReceived message.

Parameters:
  • p_message[inout] Pointer to a NanoPb Message structure

  • p_pdu[in] Pointer to a whad_unifying_recvd_packet_t structure

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message or packet pointer.

whad_result_t whad_unifying_pdu_received_parse(Message *p_message, whad_unifying_recvd_packet_t *p_pdu)

Parse a PduReceived message.

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

  • p_pdu[inout] Pointer to a whad_unifying_recvd_packet_t structure

Return values:
  • WHAD_SUCCESS – Success.

  • WHAD_ERROR – Invalid message or packet pointer.