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.

CC2541: BLE Pairing mode does not disconnect if wrong passkey typed.

Part Number: CC2541

Hi,

I am Darpan Noel D'Soza, I have been working on the BLE chip CC2541 for quite sometime and need to enable the pairing procedure in it.

I am using the Light Blue App on an Apple touch device for testing it for various BLE features. While I setup the pairing procedure using the (swru271g) development document, it all works fine but the connection approval. While I click on the advertise a pop up window asking for the passkey appears, but if noticed the app gets connected in the background. Even if I cancel the passkey window without entering any passkey the app shows a connected status.

I need to know how to resolve this issue as soon as possible.

Regards,

Noel D'Souza

  • Hi Darpan,

    Could you provide a sniffer log? This sound like it could be the app not displaying the correct status, in that case you will be ale to see the CC2541 advertising while the Light Blue App claims they are connected.
  • Hi,

    I did not mention the whole scenario earlier. When my device at first advertises and I click to connect to the peripheral via the Apple touch device, a window requesting for the passkey appears and if noticed it connect to the peripheral in the background. In order to confirm the connection, I switch the "Listen for Notifications" ON and when the condition meets I get a notification. This happens until I deliberately disconnect from the peripheral device.

    I have sniffed the connection and produced the log below. The procedure in which I have logged is as follows:

    1. My peripheral device advertises.

    2. I click on the advertisement to connect.

    3. A window appears asking for the passkey, and it connects on the background.

    4. I type in the correct passkey and click on the "OK" button.

    5. I open my service and enable the Notification alert.

    6. I click a button on the peripheral end to send the notification and it appears on the client device.

    7. I disconnect from the peripheral device and the peripheral device starts advertising again.


    This is the entire procedure followed and logged in the following PSD file.

    BLE Jewel packet sniffer.psd

    Regards,

    Noel D'Souza.

  • Hi Noel,

    I can't see a disconnect in the sniffer log you sent. The devices connect (at P.nbr. 64) with an authentication. Then at P.nbr. 513 they pair and the link is encrypted.
  • Hi,

    Is the disconnection log important in finding out the problem that I am facing with the pairing mode?

    Yes, I have checked the log for the time at which they connect and at the time they pair and the link is encrypted, but despite the pair request and the encryption procedure the Application connects to the device at the time of connection irrespective of the pairing and encryption procedure.

    Should I look at something in particular where I may find the problem?

    Regards,

    Noel D'Souza.

  • Hi Noel,

    The connection itself should not wait for an authentication, so your device is not misbehaving as far as I can see. If you don't want your devices to connect at all with foreign devices you should implement a white list. (Think about it: If your devices aren't connected - there is no way for them to exchange the passkey.)

    The link is not authenticated (or encrypted) before the correct passkey is exchanged. You can use this to restrict reading and writing to attributes by giving them GATT permits like GATT_PERMIT_AUTHEN_READ.         

    #define GATT_PERMIT_READ                 0x01   //!< Attribute is Readable
    #define GATT_PERMIT_WRITE                0x02   //!< Attribute is Writable
    #define GATT_PERMIT_AUTHEN_READ          0x04   //!< Read requires Authentication
    #define GATT_PERMIT_AUTHEN_WRITE         0x08   //!< Write requires Authentication
    #define GATT_PERMIT_AUTHOR_READ          0x10   //!< Read requires Authorization
    #define GATT_PERMIT_AUTHOR_WRITE         0x20   //!< Write requires Authorization
    #define GATT_PERMIT_ENCRYPT_READ         0x40   //!< Read requires Encryption
    #define GATT_PERMIT_ENCRYPT_WRITE        0x80   //!< Write requires Encryption

  • Hi,

    Thanks for the help from this reply, I have managed to hide my BLE custom services by using the Authentication Read / Write feature in case of wrong PIN entered, but after the wrong PIN is entered it still remains connected to the device.

    I would like it if the device could disconnect from the client if in case the PIN entered is wrong. How can I implement this feature into my sever device.

    Regards,

    Noel.

  • Hi Noel,

    You can edit the GAPBondMgr_PasscodeRsp() function in gapbondmgr.c to terminate the connection in case of wrong passcode:

    /*********************************************************************
     * @brief   Respond to a passcode request.
     *
     * Public function defined in gapbondmgr.h.
     */
    bStatus_t GAPBondMgr_PasscodeRsp( uint16 connectionHandle, uint8 status, uint32 passcode )
    {
      bStatus_t ret = SUCCESS;
    
      if ( status == SUCCESS )
      {
        // Truncate the passcode
        passcode = passcode % (GAP_PASSCODE_MAX + 1);
    
        ret = GAP_PasscodeUpdate( passcode, connectionHandle );
        if ( ret != SUCCESS )
        {
          VOID GAP_TerminateAuth( connectionHandle, SMP_PAIRING_FAILED_PASSKEY_ENTRY_FAILED );
          GAPRole_TerminateConnection();
        }
      }
      else
      {
        VOID GAP_TerminateAuth( connectionHandle, status );
      }
    
      return ret;
    }