Hi TI devs,
We're having a recurring problem with bonding on a CC2541, and I was hoping someone might have some insight - I am stumped.
About 50% of the time, everything works as expected - an iOS client can connect and bond with our CC2541 and exchange data. If we turn the CC2541 off and on again, the iOS device can reconnect with the same bond keys.
The other 50%? The iOS device can connect and bond and send some data, but if it disconnects and attmempts to reconnect the bond is gone from the CC2541! Of course iOS is now confused because it is attempting to connect to a device with an encrypted channel, but the CC2541 has lost its half of the bond.
Once this happens, it seems like the bond never sticks on that CC2541 anymore until I re-flash the firmware back to stock. It's the same code, but suddenly bonds start working reliably again...until they don't. I also connect from a Python client, and have experience the same issue, so I don't think it has anything to do with iOS in particular.
Here's where we initialize the bond manager:
static void initialize_gap_bond_manager(void) { // Parameter Values uint8 pairMode = GAPBOND_PAIRING_MODE_WAIT_FOR_REQ; uint8 bonding = TRUE; uint8 mitm = FALSE; uint8 ioCap = GAPBOND_IO_CAP_NO_INPUT_NO_OUTPUT; // If we are already bonded with a device, disable pairing with further // devices uint8 bondCount = 0; GAPBondMgr_GetParameter(GAPBOND_BOND_COUNT, &bondCount); if (bondCount != 0) { pairMode = GAPBOND_PAIRING_MODE_NO_PAIRING; } // Set parameters GAPBondMgr_SetParameter(GAPBOND_PAIRING_MODE, sizeof(uint8), &pairMode); GAPBondMgr_SetParameter(GAPBOND_MITM_PROTECTION, sizeof(uint8), &mitm); GAPBondMgr_SetParameter(GAPBOND_IO_CAPABILITIES, sizeof(uint8), &ioCap); GAPBondMgr_SetParameter(GAPBOND_BONDING_ENABLED, sizeof(uint8), &bonding); }
and here's our pair state callback:
static void _PairStateCB(uint16 connHandle, uint8 state, uint8 status) { if (state == GAPBOND_PAIRING_STATE_COMPLETE && status == SUCCESS) { log_message(LOG_INFO, LOG_TAG, "%s", "New device connected via pairing, setting up a bond"); linkDBItem_t *pItem; if ((pItem = linkDB_Find(connHandle)) != NULL) { if ((pItem->stateFlags & LINK_BOUND) == LINK_BOUND) { if(_connectionStateChangedCallback != NULL) { _connection_state = BLE_CONN_STATE_BONDED; _connectionStateChangedCallback(_connection_state); } } } } else if (state == GAPBOND_PAIRING_STATE_BONDED && status == SUCCESS) { log_message(LOG_INFO, LOG_TAG, "%s", "Previously bonded device connected"); if(_connectionStateChangedCallback != NULL) { _connection_state = BLE_CONN_STATE_BONDED; _connectionStateChangedCallback(_connection_state); } } }
I can post more sections of code, but honestly I'm not sure what would have an effect on the ability to store the bond - that's all inside the TI stack as far as I can tell.
Any advice would be most appreciated! Thanks.