Skip to content

Instantly share code, notes, and snippets.

@Tolsi
Forked from btchip/balenos_ble.asc
Created February 19, 2020 09:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Tolsi/5130ed7a0aacf7f9930f6b1cffadfb9f to your computer and use it in GitHub Desktop.
Save Tolsi/5130ed7a0aacf7f9930f6b1cffadfb9f to your computer and use it in GitHub Desktop.

Ledger Nano X : Bluetooth Low Energy Communication

1.0

  • Public release

About

This specification describes the default BLE transport used for Ledger Nano X applications

BLE Transport protocol

The Ledger Nano X acts as a GATT server.

The link shall preferably be established using a LE Secure Connection supporting Numeric Comparison. LE legacy pairing is optionally available with a warning displayed to the user.

Ledger Nano X GATT service

The service UUID is 13D63400-2C97-0004-0000-4C6564676572 and it implements the following characteristics :

Name

Property

Length

UUID

Request

Write

20 to 153 bytes

13D63400-2C97-0004-0002-4C6564676572

Response

Notify

20 to 153 bytes

13D63400-2C97-0004-0001-4C6564676572

The value of the negociated MTU can be queried from the higher level transport protocol to optimize the size of fragments sent to the Ledger Nano X as described below.

High level communication overview

A communication between a host and the Ledger Nano X is performed as follows :

  • The Ledger Nano X is turned on

  • The Ledger Nano X advertises its service

  • The Client scans for the Ledger Nano X service

  • The Client performs characteristic discovery on the Ledger Nano X

  • If not already paired, the Client and the Ledger Nano X shall perform BLE pairing and create a LTK. A confirmation will be prompted on the Ledger Nano X

  • The Client registers for notifications on the Response characteristic

  • The Client formats and writes a request into the Request characteristic. As a first request, the Client queries the negociated MTU or uses the minimum BLE payload length if not available

  • The Ledger Nano X processes the request and responds by sending notifications over the Response characteristic. The Ledger Nano X can indicate that the connection should be closed and reopened later if significant processing time is expected.

  • The connection is closed by the Client or the connection times out and is closed by the Ledger Nano X

    Note : in order for the bonding information to be writtent in NVM, the client shall disconnect from the Nano X. If the disconnection is initiated from the Nano X bonding information won't be writtent in NVM.

Transport protcool

General transport description

Requests and responses are encapsulated using a flexible protocol allowing to fragment large payloads.

The initial packet in a sequence is formatted as follows :

Description

Length

Command tag

1

Packet sequence index (big endian), set to 0

2

Data length (big endian)

2

Payload

var

The following packets in a sequence are formatted as follows :

Description

Length

Command tag

1

Packet sequence index (big endian)

2

Payload

var

The Command tag describes the message content. A response is sent with a Command tag matching the request or set to 0x0E to report a protocol error.

The Packet sequence index describes the current sequence for fragmented payloads. The first fragment index is 0x00 and increased in following packets.

APDU command tag

The APDU command tag 0x05 is used to transfer application specific data.

You can refer to the following documents to obtain additional details about the APDU format :

GET MTU command tag

The GET MTU command tag 0x08 is used to query the negociated MTU and optimize the size of fragments

The command packet shall be formatted as follows

Description

Length

Command tag 0x08

1

Packet sequence index (big endian), set to 0

2

Data length (big endian), set to 0

2

The command response is formatted as follows

Description

Length

Command tag 0x08

1

Packet sequence index (big endian), set to 0

2

Data length (big endian), set to 1

2

Negociated MTU size

1

GET VERSION command tag

The GET VERSION command tag 0x00 is used to query the current version of the protocol being used

The command packet shall be formatted as follows

Description

Length

Command tag 0x00

1

Packet sequence index (big endian), set to 0

2

Data length (big endian), set to 0

2

The command response is formatted as follows

Description

Length

Command tag 0x00

1

Packet sequence index (big endian), set to 0

2

Data length (big endian), set to 4

2

Protocol version (big endian), currently 0

4

INIT command tag

The INIT command tag 0x01 is used to reset the high level BLE state machine in case the host lost information about its current state

The command packet shall be formatted as follows

Description

Length

Command tag 0x01

1

Packet sequence index (big endian), set to 0

2

Data length (big endian), set to 0

2

The command response is formatted as follows

Description

Length

Command tag 0x01

1

Packet sequence index (big endian), set to 0

2

Data length (big endian), set to 0

2

ECHO command tag

The ECHO command tag 0x02 is used to test the speed of the link by echoing back the payload being sent

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment