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.

How do you implement HCI_Read_Stored_Link_Key and HCI_Write_Stored_Link_Key with SPPLE project

Expert 1570 points
Other Parts Discussed in Thread: CC2564, MSP430F5219

We are using the SPPLE example project on an MSP430F5219 device with CC2564 attached and want to save and restore pairing keys to avoid having to pair each time the device is power-cycled or reset.  I don't see any examples of how to use these functions (HCI_Write_Stored_Link_Key and HCI_Read_Stored_Link_Key), except for some documentation in the BluetopiaCoreAPI.PDF file in the documentation folder.  None of the example projects appear to use these functions and I couldn't find much on them on the forum either. 


Where/how would these be called in a project like the SPPLE_lite demo?

Thanks,

Angelo

HCI_Write_Stored_Link_Key

  • Hi,

    We recommend you do not use those APIs as  they offload the link key management to the radio and we recommend that the application should control the link key management as it may happen that the application and radio are not in sync and that may affect user experience. It is better for the radio to ask the application whenever link keys are needed. 

    Application can save the link keys/BDaddr pair information to flash and read it on initialization so that the pairing survives power cycles.

    There is some sample code that has worked for others in storing/retrieving the link keys from flash in this post. http://e2e.ti.com/support/wireless_connectivity/f/660/t/267220.aspx

    Thanks,

    Stonestreet One.

  • Thanks, I was looking at that thread also and I already had some code added to read and write the keys to Flash but they weren't working so I was looking for an alternative.  What none of the examples really show is where the key should be saved.  I was calling a function to write them to Flash after these lines in the GAP_Event_Callback function in SSPLE.c:

                      /* Check to see if we found a location to store the   */
                      /* Link Key information into.                         */
                      if(Index != (-1))
                      {
                         LinkKeyInfo[Index].BD_ADDR = GAP_Event_Data->Event_Data.GAP_Authentication_Event_Data->Remote_Device;
                         LinkKeyInfo[Index].LinkKey = GAP_Event_Data->Event_Data.GAP_Authentication_Event_Data->Authentication_Event_Data.Link_Key_Info.Link_Key;
    

    But that was causing it to stop working, i.e. it wouldn't establish the connection.  The processor continued to run and I could see timer interrupts were still running, etc. but it didn't complete the pairing.

  • I had the same problem when attempting to write the link key to flash in the callback from the bluetopia stack - i received overrun errors on the MSP to CC256x uart.

    To get around this I added the flash write function to the scheduler with a 2-5sec delay, that way the routine is run in the foreground but after all the pairing commands have been sent back and forth between the 2 processors.

  • Barak,

    Could you share where you placed your WriteBluetoothLinkKey(sizeof(LinkKeyInfo[Index]), (Byte_t *)&LinkKeyInfo[Index]);

    and ReadBluetoothLinkKey(sizeof(link_key), (Byte_t *)&link_key);

    ?

    Thanks!
  • At the end of the case for atLinkKeyCreation:
    I do a
    BTPS_AddFunctionToScheduler(ScheduleWriteBluetoothLinkKey, NULL, 1000);
    where
    void ScheduleWriteBluetoothLinkKey(void *UserParameter)
    {
    BTPS_DeleteFunctionFromScheduler(ScheduleWriteBluetoothLinkKey, NULL);
    WriteBluetoothLinkKey(sizeof(link_key), (Byte_t *)&link_key);
    }
    The ReadBluetoothLinkKey I placed after I successfully open the stack.
  • Thanks Barak,

    I was able to place the call after the

    /* Check to see if we found a location to store the */
    /* Link Key information into. */
    if(Index != (-1))
    {
    LinkKeyInfo[Index].BD_ADDR = GAP_Event_Data->Event_Data.GAP_Authentication_Event_Data->Remote_Device;
    LinkKeyInfo[Index].LinkKey = GAP_Event_Data->Event_Data.GAP_Authentication_Event_Data->Authentication_Event_Data.Link_Key_Info.Link_Key;
    Display("atLinkKeyCreating succesful");
    WriteBluetoothLinkKey(sizeof(LinkKeyInfo),(Byte_t*).... ));

    I added the prototype of WriteBluetoothLinkKey() and ReadBluetoothLinkKey() to the main.h and then was able to succesfully place the call.

    Thanks for your help!