Where can we find the long term key(LTK) value if we are implementing passcode in simple peripheral code that is used for passcode purpose ?
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.
M SPIM,
Sorry for getting back to you a bit later. First, I'd be curious as to why you want to do this, just for my education. Can you provide some insight there?
Second, you can find information on how the LTK is calculated in the Bluetooth LE Specification: https://www.bluetooth.com/specifications/bluetooth-core-specification
For BLE4.2, you can find more information on the BLE Security Manager Spec in Vol3, Part H.
Third, reading the LTK is a bit more complicated as the keys are stored in Secure Non-Volatile memory (SNV). The SNV is not easy to decode, but if you have the ID, you can use the osal_snv_read() to read the LTK. But this is generally abstracted by the GAPBondMgr.
In the gapbondmgr.c, you will find the following macro:
#define localLTKNvID(bondIdx)
This takes the bondIdx as an argument and returns the NVID. From there you can use osal_snv_read(), then get the IDX from GAPBondMgr_ResolveAddr.
For the arguments for the GAPBondMgr_ResolveAddr(), you can use linkDB_GetInfo() to retrieve what you need to pass into the Resolve Addr API.
As a best practice, it may also be good to reference the GAPBondMgr and LE Secure Connections Documentation to see how the pairing callbacks work.
Simple Peripheral is actually passcode pairing.
You can observe why it is by examining the simple_peripheral.c file, particularly the following section:
// Setup the GAP Bond Manager. For more information see the section in the // User's Guide: // software-dl.ti.com/.../ { // Don't send a pairing request after connecting; the peer device must // initiate pairing uint8_t pairMode = GAPBOND_PAIRING_MODE_WAIT_FOR_REQ; // Use authenticated pairing: require passcode. uint8_t mitm = TRUE; // This device only has display capabilities. Therefore, it will display the // passcode during pairing. However, since the default passcode is being // used, there is no need to display anything. uint8_t ioCap = GAPBOND_IO_CAP_DISPLAY_ONLY; // Request bonding (storing long-term keys for re-encryption upon subsequent // connections without repairing) uint8_t bonding = TRUE; GAPBondMgr_SetParameter(GAPBOND_PAIRING_MODE, sizeof(uint8_t), &pairMode); GAPBondMgr_SetParameter(GAPBOND_MITM_PROTECTION, sizeof(uint8_t), &mitm); GAPBondMgr_SetParameter(GAPBOND_IO_CAPABILITIES, sizeof(uint8_t), &ioCap); GAPBondMgr_SetParameter(GAPBOND_BONDING_ENABLED, sizeof(uint8_t), &bonding); }
You can reference the following portion of the software users guide for more information and see what just works vs pairing vs other secure connection methods. http://software-dl.ti.com/lprf/simplelink_cc2640r2_latest/docs/blestack/ble_user_guide/html/ble-stack-3.x/gapbondmngr.html?highlight=just%20works#gapbondmgr-examples-for-different-pairing-modes