This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2640: No LTK requested and saved in SNV.

Part Number: CC2640

Hello TI,

I'm upgrading cc2640 to BLE 4.2 stack and have an issue with pairing the device. When it starts pairing the peripheral's SMP response  has no LTK request, and when the authentication successfully finished pDevSecInfo is 0, as result the device LTK is not saved in SNV. The connection is established and secured, I can read/write from/to the device.

If I disconnect and try to connect again the central (Mac and iOS) drops the connection with 'Peer removed pairing information' reason.

Here is some PacketLogger trace:

Sep 16 20:06:45.204 SMP Send 0x0042 60:77:71:4E:BD:87 SMP Pairing Request Command
SMP Pairing Request Command
IO Capability: 0x04 - Keyboard Display
OOB Data: 0x00 - Oob Authentication Data Not Present
Auth Req: 0x0D - Bonding Enabled - MITM Enabled - SC Enabled - Keypress Disabled - CT2 Disabled
Max Enc Key Size: 0x10 (16)
Initiator Key Distribution: 0x03 - LTK IRK Requested    - the central asked for both LTK and IRK from the peripheral
Responder Key Distribution: 0x03 - LTK IRK Requested
Sep 16 20:06:45.204 L2CAP Send 0x0042 60:77:71:4E:BD:87 Channel ID: 0x0006 Length: 0x0007 (07) [ 01 04 00 0D 10 03 03 ]
Sep 16 20:06:45.218 HCI Event 0x0042 60:77:71:4E:BD:87 Number Of Completed Packets - Handle: 0x0042 - Packets: 0x0001
Sep 16 20:06:45.218 Kernel Debug 0x0000 **** [IOBluetoothHostController][DecrementOutstandingACLPackets] - decremented - Classic-LE L|M|H - Delta: 0|0|0-1|0|0 - Device: 0|0|0-1|0|0 - ACL Pkt: In Q: 0|0|0-0|0|0 - Outstanding: 0|0|0-0|0|0 ****
Sep 16 20:06:45.233 SMP Receive 0x0042 60:77:71:4E:BD:87 SMP Pairing Response Command
SMP Pairing Response Command
IO Capability: 0x03 - No Input No Output
OOB Data: 0x00 - Oob Authentication Data Not Present
Auth Req: 0x09 - Bonding Enabled - MITM Disabled - SC Enabled - Keypress Disabled - CT2 Disabled
Max Enc Key Size: 0x10 (16)
Initiator Key Distribution: 0x02 - IRK Requested    - the peripheral asked only for IRK
Responder Key Distribution: 0x02 - IRK Requested

The flags for authentication request are set as following:

static uint8_t gapBond_KeyDistList =

(

  GAPBOND_KEYDIST_SENCKEY     // sEncKey enabled, to send the encryption key

   | GAPBOND_KEYDIST_SIDKEY   // sIdKey enabled, to send the IRK, and BD_ADDR

   | GAPBOND_KEYDIST_SSIGN    // sSign enabled, to send the CSRK

   | GAPBOND_KEYDIST_MENCKEY  // mEncKey enabled, to get the master's encryption key

   | GAPBOND_KEYDIST_MIDKEY   // mIdKey enabled, to get the master's IRK and BD_ADDR

   | GAPBOND_KEYDIST_MSIGN    // mSign enabled, to get the master's CSRK

);

I tried to change the flags, but it makes no difference, the value in the SMP response is always 0x02 as it's highlighted in the log above.

I can provide more code and traces if needed, please help to pinpoint the problem, thanks!

  • Sergei,

    Thanks for the inquiry. You mentioned BLE 4.2 stack - does it mean the SDK version 4.20 or the BLE version 4.2? I suspect the former but just wanted to confirm.

    At any rate, I wonder if secure connections are disabled, which could cause the pDevSecInfo to be zero. The example "Secure Connections" of the GAP Bond Manager reference below shows this configuration.

    http://software-dl.ti.com/lprf/sdg-latest/html/ble-stack-3.x/gapbondmngr.html#gapbondmgr-examples-for-different-pairing-modes

    The pairing process that goes successfully AND stores the data in the NV memory would flag the state  GAPBOND_PAIRING_STATE_BOND_SAVED in the function SimplePeripheral_processPairState() of the <simple_peripheral.c> file. A breakpoint or watchpoint there could help verify if the bond is indeed successful (although you seem to already have another reporting mechanism).

    I will try to find additional details that may be influencing the ability to have long term bonding enabled and report back.

    Hope this helps,

    Rafael

  • Hi Rafael,

    Thanks for your reply.

    That's correct, the BLE version is 4.2, the SDK version is TI-BLE-Stack-2.2.2.0.

    The security flag is set and we can see it in the device SMP response: Bonding Enabled - MITM Disabled - SC Enabled - Keypress Disabled - CT2 Disabled.
    I actually tried both: GAPBOND_SECURE_CONNECTION_ALLOW and GAPBOND_SECURE_CONNECTION_ONLY, none of them helps.

    I traced 4.1 (SDK TI-BLE-Stack-2.1.0.3) and the SMP response from the device has key distribution list value 0x3:
    'Initiator Key Distribution: 0x03 - LTK IRK Requested'. It looks to me that this field in the message is set somewhere in a lower protocol layer before sending it.
    And it ignores the parameters I provide for the message. I've tried different combinations but the value is always 0x02.

    I will keep trying different configurations and debugging, and will let you know if I find something.

    Thanks,
    Sergei.

  • Hi Rafael,

    I debugged it a bit more and see that in SM_StartPairing it skips smGeneratePairingReqRsp due to some zero value in the authentication parameters, provided to the function. It's hard for me to say from the disassembly what caused it. It gets some GAP parameters earlier in the function, those values can cause the issue.

    It would be very helpful If you can take a look at the code and tell me what GAP parameters it's using, and I will double check their values.

    Thanks,
    Sergei. 

  • Sergei,

    Please apologize for the delay. I was sidetracked and will address the first thing on Monday.

    Regards,

    Rafael

  • Hi Rafael,

    I think the place I described in my previous post is not the actual one, where it builds the pairing request/response.
    In that place it just checks the key length with MIN and MAX values and exists. It continues processing the pairing request event later.
    At some point it calls smSetPairingReqRsp where it uses parameters pre-allocated in the heap (in my case the address is 0x20001978) to fill up the response also allocated in the heap at 0x20002af8. The keyDistList value there is 0x02 which means it asks only for IRK.

    I think we should understand how it builds the parameters and what causes the value not to include LTK into the list.

    Thanks,
    Sergei.

  • Sergei,

    The Security manager usually interfaces through the GAP Bond Manager, therefore I am debugging a level up from you to try to find a combination of factors accessible by the user to reproduce the problem. The flags on my system match yours (MITM disabled, Bonding, etc.) and at the point of authentication I have the following flags:

    At the moment am trying to reproduce the failing pairing "retention" bonding here in my setup to no avail so far - it always saves the bonding to the SNV memory. That is, as long as I keep the GAPBOND_BONDING_ENABLED set. I can see this when I get to the point of adding the bonding to the SNV, where the function gapBondMgrAddBond() shows a valid LTK.

    I don't have an apple device (where PacketLogger is being hosted right?) and I am pairing with an Android device and connecting using the application LightBlue. i don't think this should matter (well, hopefully not).

    I hope this helps take you a bit further on the debug process.

    Regards,

    Rafael

  • Hi Rafael,

    Thanks for your response.

    You are right, I think I have gone a bit further because at the point you are showing at the first screen shot everything looks good:
    when it calls GAP_Authenticate(&params, pPairReq); the key distribution flags set properly to 0707: LTK, IRK, Sign.
    But when the stack builds the actual response message in smSetPairingReqRsp it somehow ignores this list and sets only IRK flag to be sent to the central. Thus the central send send only IRK key back to the peripheral and when it comes to gapBondMgrAddBond the pAuthEvt->pSecurityInfo pointer is NULL.

    Can you please put a breakpoint at smSetPairingReqRsp and try to see where it takes the flags from and why it doesn't set LTK flag in the response message?

    I also use LightBlue or BlueSee with Mac or iOS for testing and I think the problem is on the peripheral side, something is misconfigured there.

    Thank you,

    Sergei.

  • Hi,

    For others following this thread, this is being worked offline. I will post any relevant updates.

    Regards,

    Rafael

  • any news upon this?

  • This was expected behavior as:

    "2.4.3.2 LE Secure Connections key distribution" only allows IRK and CSRK key distribution.
    MITM must be enabled for LE SC.

    I hope it helps,

    Sergei.