This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

pc-ble-driver: sd_ble_gattc_read() why length is (ATT-1) instead (ATT-3) ?

Hi 
I use nrf-ble-driver ver.4.1.1 with PCA10031 dongle (nRF51844 chip on board) and "connectivity_4.1.1_1m_with_s130_2.0.1.hex" firmware for that dongle. in this case ATT_MTU = 23.

In description of function sd_ble_gattc_read() says: 
"If the Characteristic or Descriptor to be read is longer than ATT_MTU-1, this function must be called multiple times with appropriate offset to read the complete value."

Its all ok and work fine, but I have a stupid question: why ATT_MTU-1  but not ATT_MTU-3 ?

In peripheral I have characteristic 23 bytes len and really after call 2 times an sd_ble_gattc_read(),  I receive first 22 bytes and second 1 bytes in 2 packets. in other words I receive all data, but I assumed that first packet should be 20 bytes len (ATT_MTU-3) and second packet = 3 bytes len.

Continuing this one more question: when I enable notification for this characteristic, on BLE_GATTC_EVT_HVX event I receive only 20 bytes and can't get more, but if to follow the logic of ATT_MTU description, I have to receive 22 bytes.

Tell me please, where could I get confused?

Thanks.

  • I will answer myself, maybe someone will help:

    In core spec. Vol.3 Part F, 3.4.4.6 "Read BLob Responce" in Table 3.2 we see format of response packet and really attribute value = att_mtu-1 because service data (opcode) have len = 1.

    And about notification: In core spec. Vol.3 Part F, 3.4.7.1 "Handle Value Notification" in Table 3.34 we see that service data have 3 bytes len (opcode - 1byte  and handle - 2 bytes). And If the attribute value is longer than (ATT_MTU-3) octets, then only the first (ATT_MTU-3) octets of this attributes value can be sent in a notification.

  • I added these comments to my code to illustrate, might be useful:

    // |<-------------------------------------------- Slave -> Master Data Packet -------------------------------------->|
    // |                                                                                                                 |
    // +-----------------------------------------------------------------------------------------------------------------+
    // |                                            BLE Data Packet Min/Max/eg(186)                                      |
    // +-----------------------------------------------------------------------------------------------------------------+
    // |                                     1MHz: 10/265/217 octets, 2MHz: 11/266/218 octets                            |
    // +----------+--------+--------------------------------------------------------------------------------------+------+
    // |          | Access |                                                                                      |      |
    // | Preamble | Address|         Protocol Data Unit PDU                                                       | CRCC |
    // +----------+--------+--------------------------------------------------------------------------------------+------+
    // |   1 (2)  |    4   |                                                   2-257                              |  3   |
    // |          |        +-----------+------------------------------------------------------------------+-------+      |
    // |          |        | LL Header |  Payload                                                         |  MIC  |      |
    // |          |        +-----------+------------------------------------------------------------------+ (opt) |      |
    // |          |        |   2       |                                       0-251                      |   4   |      |
    // |          |        |           +--------+---------------------------------------------------------+       |      |
    // |          |        |           | L2CAP  |                                                         |       |      |
    // |          |        |           | Header |  ATT Data                                               |       |      |
    // |          |        |           +--------+---------------------------------------------------------+       |      |
    // |          |        |           |   4    |                              0-247                      |       |      |
    // |          |        |           |        +-----+-------+-------------------------------------------+       |      |
    // |          |        |           |        | ATT | ATT   |                                           |       |      |
    // |          |        |           |        | Op  | Attrib|  ATT Payload                              |       |      |
    // |          |        |           |        +-----+-------+-------------------------------------------+       |      |
    // |  1 (2)   |   4    |  2        |   4    |  1  |  2    |                0-244                      |  (4)  |  3   |
    // +----------+--------+-----------+--------+-----+-------+-------------------------------------------+-------+------+
    //                                                        /                                           \
    //                                                      /                                               \
    //                                                    /                                                   \
    //                                                  /                                                       \
    //                                                /                                                           \
    //                                              /                                                               \
    //                                            |<---------------------- eg Payload 186 bytes --------------------->|
    //
    //
    // Preamble is 1 byte for LE 1MHz (BLE 4.2) and 2 bytes for 2MHz (BLE 5.0). If the first bit of the ADDRESS is 0 the preamble
    // will be 0xAA otherwise 0x55.
    // The MIC field is optional used when we are using an encrypted connection

Related