question

newuser-927dea69-9bef-487c-afd5-946123762499 avatar image

Alexa gadget BLE GetDevcieInformation packet decoding

Hi I would like to understand the protocol buffer encoding of GetDeviceInformation and GetDeviceFeature transactions.


I see that response to GetDeviceInformation is as follows:-

01 00 00 00 24 24 08 14

4a 20 -> Length delimated wire type with field Field number 9 (is it for response)

1a 1e -> What these bytes are?

0a 07 61 61 62 62 63 63 64

12 0a 47 61 64 67 65 74 4e 61 6d 65

1a 01 00

22 04 77 78 79 7a

Also I would like to know how to decode the GetDeviceFeature response bytes,

03 00 00 00 09 09 08 1c  4a 05 e2 01 02 08 13 


Regards,

Hemanth


alexa gadgets toolkitalexa gadgetsbluetooth setup
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

samer@amazon avatar image
samer@amazon answered

Thanks for your question.

The response bytes in the sample output are the raw packets sent over BLE. It looks like this:

Creating response: Command_GET_DEVICE_INFORMATION
New Tx Transaction [1] :: Stream [0]
Tx Progress [36/36] :: Stream [0] :: Transaction [1]
>>>>> Response from Gadget -> Echo:
Packet [1/1] contains: 01 00 00 00 24 24 08 14  4a 20 1a 1e 0a 07 61 61 
                       62 62 63 63 64 12 0a 47  61 64 67 65 74 4e 61 6d 
                       65 1a 01 00 22 04 77 78  79 7a 

where the first 6 bytes 01 00 00 00 24 24 are the header containing

  • 01: StreamId: 0: control stream and transactionId: 1.
  • 00: sequence number: 0, type: initial transaction (type 0), Ack: false and Extended length: false
  • 00: reserved
  • 00 24: total transaction length 36 bytes (big endian).
  • 24: payload length: 36 bytes.

When total transaction length = payload length, it indicates that this is the transaction consists on only one packet (this packet).


The following 36 bytes are a protobuf3 encoded message. Ideally, the byte sequence that follows the header should be passed to a protobuf decoder library, like nanopb. For the purpose of demonstration only, here is the breakdown of the payload according to the protobuf encoding rules:

  • 08: Wire type 0 (varint), field number 1 (command)
  • 14: Value: GET_DEVICE_INFORMATION
  • 4a: Wire type 2 (embedded message), field number 9 (response)
  • 20: response length = 32 bytes.
  • 1a: Wire type 2 (embedded message), field number 3 (device_information)
  • 1e: device_information length = 30 bytes.
  • 0a: Wire type 2 (string), field number 1 (serial_number)
  • 07: serial_number length = 7 bytes
  • 61 61 62 62 63 63 64 = example serial number value “aabbccd”
  • 12: Wire type 2 (string), field number 2 (name)
  • 0a: name length = 10 bytes
  • 47 61 64 67 65 74 4e 61 6d 65 = example name value “GadgetName”
  • 1a: Wire type 2 (repeated field), field number 3 (supported_transports)
  • 01: supported_transports length = 1 byte.
  • 00: Supported transport value: BLUETOOTH_LOW_ENERGY.
  • 22: Wire type 2 (string), field number 4 (device_type)
  • 04: device_type length: 4 bytes.
  • 77 78 79 7a: = example device_type value “wxyz”


Regarding the GetDeviceFeature response:

Creating response: Command_GET_DEVICE_FEATURES
New Tx Transaction [3] :: Stream [0]
Tx Progress [9/9] :: Stream [0] :: Transaction [3]
>>>>> Response from Gadget -> Echo:
Packet [1/1] contains: 03 00 00 00 09 09 08 1c  4a 05 e2 01 02 08 13 

the first 6 bytes 03 00 00 00 09 09 decode similarly as a packet header as follows:

  • 03: StreamId: 0: control stream and transactionId: 3.
  • 00: sequence number: 0, type: initial transaction (type 0), Ack: false and Extended length: false
  • 00: reserved
  • 00 09: total transaction length 9 bytes (big endian).
  • 09: payload length: 9 bytes.

The following 9 bytes are a protobuf message:

  • 08: Wire type 0 (varint), field number 1 (command)
  • 1c: Value: GET_DEVICE_FEATURES
  • 4a: Wire type 2 (embedded message), field number 9 (response)
  • 05: response length = 5 bytes.
  • e2 01: Wire type 2 (embedded message), field number 28 (device_features)
  • 02: device_features length = 2 bytes.
  • 08: Wire type 0 (varint), field number 1 (features)
  • 13: features values. Supports Alexa Gadgets Toolkit and OTA.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.