5 Replies Latest reply on Nov 8, 2017 7:30 AM by e.pratt_1639216

    BLE 4.1, 1 button input, random resolvable adress, and "FIFO" managment of bonded devices

    denis.touillon_1826166

      Hello,

       

      I came here again and need some help after multiples workarounds..

       

      The goal is to command a device ( a motorized door) with smartphones.

      The smartphone have to be bonded with the door to allow easy use of the phone application.

       

      There is only 1 button on the door, and the Ble module in use is in 4.1. Today's most device use resolvable random adress so can't use whitlistening to discard not allowed device to connect.

       

      To work around the 1 button problem without the whitelist (i use just work and have to allow connection with 1 button), i do things like that :

       

      /**********************************************************

              *                       GATT Events

              ***********************************************************/

       

       

              case CYBLE_EVT_GATT_CONNECT_IND:

      /* This event is received when device is connected over GATT level */

                  #ifdef PRINT_MESSAGE_LOG

      UART_UartPutString("\n\r\tConnected_Ind \n\r");

                     #endif

             

                    connectionHandle = *(CYBLE_CONN_HANDLE_T  *)eventParam;

       

      break;

       

       

       

       

      case CYBLE_EVT_GAP_DEVICE_CONNECTED:

      /* This event is received when device is connected over GAP layer */

       

       

      /* This flag is used in application to check connection status */

      deviceConnected = TRUE;

            

        CyBle_GapGetBondedDevicesList(&bondedDeviceList);         

            

                 

                  if (pairingAuth == TRUE) // button have been pressed (TRUE during 3 sec)

                  {

                      cyBle_authInfo.authErr = CYBLE_GAP_AUTH_ERROR_NONE;

       

                  }

                  else if ((bondedDeviceList.count >= 1) && (connectionHandle.bdHandle == 4))

                  {

                 

                      cyBle_authInfo.authErr = CYBLE_GAP_AUTH_ERROR_NONE;

                  }

                  else if ((bondedDeviceList.count >= 2) && (connectionHandle.bdHandle == 3))

                  {

                 

                      cyBle_authInfo.authErr = CYBLE_GAP_AUTH_ERROR_NONE;

       

                  }

                   else if ((bondedDeviceList.count >= 3) && (connectionHandle.bdHandle == 2))

                  {

                 

                      cyBle_authInfo.authErr = CYBLE_GAP_AUTH_ERROR_NONE;

       

                  }

                    else if ((bondedDeviceList.count >= 4) && (connectionHandle.bdHandle == 1))

                  {        

                      cyBle_authInfo.authErr = CYBLE_GAP_AUTH_ERROR_NONE;

                  }

                  else

                  {

                  cyBle_authInfo.authErr = CYBLE_GAP_AUTH_ERROR_PAIRING_NOT_SUPPORTED;

                  CyBle_GapDisconnect(connectionHandle.bdHandle);

                  }

       

      break;

       

       

       

              case CYBLE_EVT_GAP_DEVICE_DISCONNECTED:

      /* This event is received when device is disconnected */

        

                    CyBle_GapGetBondedDevicesList(&bondedDeviceList);

             

                      /* bonded device remove "FIFO handle" */

                      if (bondedDeviceList.count == 4 )

                      {

       

                          CyBle_GapRemoveOldestDeviceFromBondedList();

       

                      //be sure to store it in flash

                      if((cyBle_pendingFlashWrite != 0u) &&

                          ((UART_SpiUartGetTxBufferSize() + UART_GET_TX_FIFO_SR_VALID) == 0u))

                           {                           

                                if(CYBLE_ERROR_OK== CyBle_StoreBondingData(1u))                                     

                          }

                 

       

                      }

             

      break;

       

       

      It seems Ok to allow/discard the connection to a smartphone, with the input button  :

      If non bonded, and if bonded just by checking the bdHandle and the Bonded device count.

       

       

      But my problem is that i want to automaticaly delete the oldest bonded device when the the bonded list is full to allow this new device to be bonded.

       

      The problem is that  it is not working, indeed     CyBle_GapRemoveOldestDeviceFromBondedList();  does not update the bd.handle.

       

      I would like that the bdHandle == 3 is now 4, 2 now 3, 1 now 2

      bondedDeviceList.count  is updated correctly so i just would like to "slide" the bdHandles number..

       

       

       

      How can i go throught that, it seems not possible

      We can't ask the users to delete all their smartphones if they want to add a new one.

       

       

       

      Thanks for your help