Hi to all,
i am developing a device based on CC2540 soc and i want use from cc2540 as central and i have a problem with bonding. the overall procedure is in below manner:
1- user from host computer send connection request to a specific ble device
2- cc2540 remove all bonded devices with GAPBOND_ERASE_ALLBONDS parameter, and then also my app write something on flash after setting the GAPBOND_ERASE_ALLBONDS parameter
3- then cc2540 try to establish BLE link with calling GAPCentralRole_EstablishLink function
4- then other side of ble connection Noticed the connection request and turn the spec led on
5- then peers exchange the required keys that is required for bonding(i see this procedure in the sniffer)
6- and then my app in cc2540 recieve GAPBOND_PAIRING_STATE_COMPLETE event and turn an led for that indicate that link stablished
7- and the connection keep continue and devices can reconnect to eachother with saved keys
Note: and if user from host computer send disconnection request we again remove all bonded devices with GAPBOND_ERASE_ALLBONDS parameter, and then also my app write something on flash after setting the GAPBOND_ERASE_ALLBONDS parameter.
in normal state step 1-7 work prefect and all thing work good. but after sometime(it is random, sometime 2 week and sometime one day) that user send connect and disconnect request to cc2540, a problem happen. the problem is in this manner that step 1-5 work fine but my app in cc2540 did not receive GAPBOND_PAIRING_STATE_COMPLETE event and also dose not send any packet through BLE. and also after 20 sec the peripheral device get timeout and then start to advertising and then cc2540 and peripheral auto-connect to each other. and if onetime this problem happen, it happen every time in next connections until i re flash the cc2540 and then it work normal until next time this problem happen.
this problem is very strange for me and i do not have any idea to solve this problem. in below i put some code that pay help to solve this problem:
this is code where in step-2 i execute to remove all bonds.
void remove_all_bonded_devices( void )
{
uint8 * bonding_addresses;
uint8 idx;
uint8 cnt=0;
GAPBondMgr_GetParameter(GAPBOND_BOND_COUNT,&cnt);
bonding_addresses = (uint8 *)osal_mem_alloc(cnt * B_ADDR_LEN);
GAPBondMgr_GetParameter(GAPBOND_BONDED_LIST,bonding_addresses);
GAPBondMgr_SetParameter(GAPBOND_ERASE_ALLBONDS,0,NULL); // TODO-DELETE ALL BONDING
for(uint8 i=0;i<cnt;i++)
{
idx = get_idx_by_addr(bonding_addresses + B_ADDR_LEN * i);
name_list_remove(bonding_addresses + B_ADDR_LEN * i);
if(is_connected(bonding_addresses + B_ADDR_LEN * i))
{
GAPCentralRole_TerminateLink(bridge_devices[idx].connHandle);
}
}
osal_mem_free(bonding_addresses);
/*osal_set_event(task_id, NL_UPDATE_EVT);***********/
osal_stop_timerEx(task_id, NL_UPDATE_EVT);
osal_start_timerEx(task_id, NL_UPDATE_EVT,30000);
}
and when i receive NL_UPDATE_EV i execute below code:
void name_list_update( void )
{
osal_snv_write(NAME_LIST_SNV_ID, sizeof(bonded_fob_t)*GAP_BONDINGS_MAX, bonded_fob_list);
}
now there is anyone can give me a advise to solve this problem??
