This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Bonding information issue when only one side the bonding is delete

Hi,

sometimes not always, the function peer_id_is_allocated return false and this causes an ASSERT of device, because a NRF_ERROR_INVALID_PARAM is returned by pdb_write_buf_get. And Peer_Manager return an assert.

Someone can help to me, why this happens?

Thanks, Anna

Parents
  • i don't have advertising start with the DELETE_SUCCEDED.

    this is my case:

      case  (PM_EVT_PEERS_DELETE_SUCCEEDED):
            break;
    

    Complete below:

        static void PR_MGR_EventHandler(pm_evt_t const * p_evt)
    {
       ret_code_t err_code;
       switch(p_evt->evt_id)
       {
          case PM_EVT_BONDED_PEER_CONNECTED:
          {
             APP_LOG("Connected to previously bonded device\r\n");                      
             err_code=TIMER_Start(TIMER_REQUEST,SECURITY_REQUEST_DELAY,NULL);
             APP_ERROR_CHECK(err_code);
             
             err_code = pm_peer_rank_highest(p_evt->peer_id);
             if (err_code != NRF_ERROR_BUSY)
             {
                     APP_ERROR_CHECK(err_code);
             }
          }
          break;//PM_EVT_BONDED_PEER_CONNECTED
    
          case PM_EVT_CONN_SEC_START:
             break;//PM_EVT_CONN_SEC_START
    
          case PM_EVT_CONN_SEC_SUCCEEDED:
             {
                pm_conn_sec_status_t conn_sec_status;
                err_code = pm_conn_sec_status_get(p_evt->conn_handle, &conn_sec_status);
                APP_ERROR_CHECK(err_code);
                err_code = pm_peer_rank_highest(p_evt->peer_id);
                APP_ERROR_CHECK(err_code);
              }
             
             break;//PM_EVT_CONN_SEC_SUCCEEDED
    
          case PM_EVT_CONN_SEC_FAILED:
             {
             /** In some cases, when securing fails, it can be restarted directly. Sometimes it can
              *  be restarted, but only after changing some Security Parameters. Sometimes, it cannot
              *  be restarted until the link is disconnected and reconnected. Sometimes it is
              *  impossible, to secure the link, or the peer device does not support it. How to
              *  handle this error is highly application dependent. */
              
             switch (p_evt->params.conn_sec_failed.error)
             {
                case PM_CONN_SEC_ERROR_DISCONNECT :
                NRF_LOG_PRINTF_DEBUG("error: PM_CONN_SEC_ERROR_DISCONNECT ");
                break;//PM_CONN_SEC_ERROR_DISCONNECT
    
                case PM_CONN_SEC_ERROR_SMP_TIMEOUT:
                NRF_LOG_PRINTF_DEBUG("error: PM_CONN_SEC_ERROR_SMP_TIMEOUT");
                break;//PM_CONN_SEC_ERROR_SMP_TIMEOUT
                
                case PM_CONN_SEC_ERROR_PIN_OR_KEY_MISSING:
                   // Rebond if one party has lost its keys.
                   err_code = pm_conn_secure(p_evt->conn_handle, true);
                   if (err_code != NRF_ERROR_INVALID_STATE)
                   {
                   APP_ERROR_CHECK(err_code);
                   }
                   break;
               
                default:
                NRF_LOG_PRINTF_DEBUG("unknown error");
                break;
             }
                err_code = CNT_MGR_Disconnect();
                APP_ERROR_CHECK(err_code);
                lPeerMsg.msg = QUEUE_PEER_FAILED;
                QUEUE_Put(lPeerMsg );  
                CNT_MGR_SetConnStatus(BLE_CONN_HANDLE_INVALID);
             }
             break;//PM_EVT_CONN_SEC_FAILED
    
          case PM_EVT_CONN_SEC_CONFIG_REQ:
             {
             // Allow pairing request from an already bonded peer.
                pm_conn_sec_config_t conn_sec_config = {.allow_repairing = true};
                pm_conn_sec_config_reply(p_evt->conn_handle, &conn_sec_config);
             }
             break;//PM_EVT_CONN_SEC_CONFIG_REQ
    
             case PM_EVT_STORAGE_FULL:
             {
             // Run garbage collection on the flash.
             err_code = fds_gc();
             if (err_code == FDS_ERR_BUSY || err_code == FDS_ERR_NO_SPACE_IN_QUEUES)
             {
                 // Retry.
             }
             else
             {
                 APP_ERROR_CHECK(err_code);
             }
             }
             break;//PM_EVT_STORAGE_FULL
    
          case PM_EVT_ERROR_UNEXPECTED:
             // Assert.
             APP_ERROR_CHECK(p_evt->params.error_unexpected.error);
             break;//PM_EVT_ERROR_UNEXPECTED
    
    
          case PM_EVT_PEER_DATA_UPDATE_FAILED:
             // Assert.
             APP_ERROR_CHECK_BOOL(false);
             break;//PM_EVT_PEER_DATA_UPDATE_FAILED
    
    
          case PM_EVT_PEER_DELETE_FAILED:
             // Assert.
             APP_ERROR_CHECK(p_evt->params.peer_delete_failed.error);
             break;//PM_EVT_PEER_DELETE_FAILED
    
          case  (PM_EVT_PEERS_DELETE_SUCCEEDED):
                break;
         
          case PM_EVT_PEERS_DELETE_FAILED:
             // Assert.
             APP_ERROR_CHECK(p_evt->params.peers_delete_failed_evt.error);
             break;//PM_EVT_PEERS_DELETE_FAILED
    
    
      /*    case PM_EVT_LOCAL_DB_CACHE_APPLY_FAILED:
             // The local database has likely changed, send service changed indications.
             pm_local_database_has_changed();
             break;//PM_EVT_LOCAL_DB_CACHE_APPLY_FAILED*/
    
          default:
             // No implementation needed.
             break;
       }
    }
    
Reply
  • i don't have advertising start with the DELETE_SUCCEDED.

    this is my case:

      case  (PM_EVT_PEERS_DELETE_SUCCEEDED):
            break;
    

    Complete below:

        static void PR_MGR_EventHandler(pm_evt_t const * p_evt)
    {
       ret_code_t err_code;
       switch(p_evt->evt_id)
       {
          case PM_EVT_BONDED_PEER_CONNECTED:
          {
             APP_LOG("Connected to previously bonded device\r\n");                      
             err_code=TIMER_Start(TIMER_REQUEST,SECURITY_REQUEST_DELAY,NULL);
             APP_ERROR_CHECK(err_code);
             
             err_code = pm_peer_rank_highest(p_evt->peer_id);
             if (err_code != NRF_ERROR_BUSY)
             {
                     APP_ERROR_CHECK(err_code);
             }
          }
          break;//PM_EVT_BONDED_PEER_CONNECTED
    
          case PM_EVT_CONN_SEC_START:
             break;//PM_EVT_CONN_SEC_START
    
          case PM_EVT_CONN_SEC_SUCCEEDED:
             {
                pm_conn_sec_status_t conn_sec_status;
                err_code = pm_conn_sec_status_get(p_evt->conn_handle, &conn_sec_status);
                APP_ERROR_CHECK(err_code);
                err_code = pm_peer_rank_highest(p_evt->peer_id);
                APP_ERROR_CHECK(err_code);
              }
             
             break;//PM_EVT_CONN_SEC_SUCCEEDED
    
          case PM_EVT_CONN_SEC_FAILED:
             {
             /** In some cases, when securing fails, it can be restarted directly. Sometimes it can
              *  be restarted, but only after changing some Security Parameters. Sometimes, it cannot
              *  be restarted until the link is disconnected and reconnected. Sometimes it is
              *  impossible, to secure the link, or the peer device does not support it. How to
              *  handle this error is highly application dependent. */
              
             switch (p_evt->params.conn_sec_failed.error)
             {
                case PM_CONN_SEC_ERROR_DISCONNECT :
                NRF_LOG_PRINTF_DEBUG("error: PM_CONN_SEC_ERROR_DISCONNECT ");
                break;//PM_CONN_SEC_ERROR_DISCONNECT
    
                case PM_CONN_SEC_ERROR_SMP_TIMEOUT:
                NRF_LOG_PRINTF_DEBUG("error: PM_CONN_SEC_ERROR_SMP_TIMEOUT");
                break;//PM_CONN_SEC_ERROR_SMP_TIMEOUT
                
                case PM_CONN_SEC_ERROR_PIN_OR_KEY_MISSING:
                   // Rebond if one party has lost its keys.
                   err_code = pm_conn_secure(p_evt->conn_handle, true);
                   if (err_code != NRF_ERROR_INVALID_STATE)
                   {
                   APP_ERROR_CHECK(err_code);
                   }
                   break;
               
                default:
                NRF_LOG_PRINTF_DEBUG("unknown error");
                break;
             }
                err_code = CNT_MGR_Disconnect();
                APP_ERROR_CHECK(err_code);
                lPeerMsg.msg = QUEUE_PEER_FAILED;
                QUEUE_Put(lPeerMsg );  
                CNT_MGR_SetConnStatus(BLE_CONN_HANDLE_INVALID);
             }
             break;//PM_EVT_CONN_SEC_FAILED
    
          case PM_EVT_CONN_SEC_CONFIG_REQ:
             {
             // Allow pairing request from an already bonded peer.
                pm_conn_sec_config_t conn_sec_config = {.allow_repairing = true};
                pm_conn_sec_config_reply(p_evt->conn_handle, &conn_sec_config);
             }
             break;//PM_EVT_CONN_SEC_CONFIG_REQ
    
             case PM_EVT_STORAGE_FULL:
             {
             // Run garbage collection on the flash.
             err_code = fds_gc();
             if (err_code == FDS_ERR_BUSY || err_code == FDS_ERR_NO_SPACE_IN_QUEUES)
             {
                 // Retry.
             }
             else
             {
                 APP_ERROR_CHECK(err_code);
             }
             }
             break;//PM_EVT_STORAGE_FULL
    
          case PM_EVT_ERROR_UNEXPECTED:
             // Assert.
             APP_ERROR_CHECK(p_evt->params.error_unexpected.error);
             break;//PM_EVT_ERROR_UNEXPECTED
    
    
          case PM_EVT_PEER_DATA_UPDATE_FAILED:
             // Assert.
             APP_ERROR_CHECK_BOOL(false);
             break;//PM_EVT_PEER_DATA_UPDATE_FAILED
    
    
          case PM_EVT_PEER_DELETE_FAILED:
             // Assert.
             APP_ERROR_CHECK(p_evt->params.peer_delete_failed.error);
             break;//PM_EVT_PEER_DELETE_FAILED
    
          case  (PM_EVT_PEERS_DELETE_SUCCEEDED):
                break;
         
          case PM_EVT_PEERS_DELETE_FAILED:
             // Assert.
             APP_ERROR_CHECK(p_evt->params.peers_delete_failed_evt.error);
             break;//PM_EVT_PEERS_DELETE_FAILED
    
    
      /*    case PM_EVT_LOCAL_DB_CACHE_APPLY_FAILED:
             // The local database has likely changed, send service changed indications.
             pm_local_database_has_changed();
             break;//PM_EVT_LOCAL_DB_CACHE_APPLY_FAILED*/
    
          default:
             // No implementation needed.
             break;
       }
    }
    
Children
No Data
Related