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.

Updating password for bonding

I'm using the following code to ask for the user for a password (set by default to 000000) + a GATT_PERMIT_AUTHEN_READ attribute.

All is working fine but :

- what is the best process to allow the user to change this default password for the first time he is using the device ?

- Do I need to use a profile characteristic to manage this password ?

Tx for your help !

{
uint32 passkey = 0; // passkey "000000"
uint8 pairMode = GAPBOND_PAIRING_MODE_WAIT_FOR_REQ;
uint8 mitm = TRUE;
uint8 ioCap = GAPBOND_IO_CAP_DISPLAY_ONLY;
uint8 bonding = TRUE;
GAPBondMgr_SetParameter( GAPBOND_DEFAULT_PASSCODE, sizeof ( uint32 ), &passkey );
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 );
}

  • It is safer to have a profile characteristic with value permissions set to GATT_PERMIT_AUTHEN_WRITE. That way, whenever a value is written to this characteristic, you give a callback to your application, where you change the password.

    uint32 newValue;
    
      switch( paramID )
      {
        case SIMPLEPROFILE_CHAR2:
          SimpleProfile_GetParameter( SIMPLEPROFILE_CHAR2, &newValue );
          GAPBondMgr_SetParameter( GAPBOND_DEFAULT_PASSCODE, sizeof ( uint32 ), &newValue );
    
          #if (defined HAL_LCD) && (HAL_LCD == TRUE)
            HalLcdWriteStringValue( "Char 3:", (uint16)(newValue), 10,  HAL_LCD_LINE_3 );
          #endif // (defined HAL_LCD) && (HAL_LCD == TRUE)
    
          break;
    
        default:
          // should not reach here!
          break;
      }

    I am using SIMPLEPROFILE_CHAR2 for storing passkey.