cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 4 MCU

Anonymous
Not applicable

I implemented the authentication process on BLE device that will pair with an Android 7.1.1 phone and other BLE-enabled devices (eg. laptop, ipad, etc). Below is the configuration info:

          Security mode/level: Mode 1 authenticated pairing with encryption

          I/O capabilities: Display

          Bonding requirement: Bonding/enabled

Here's how I handled the pairing process and what events are generated:

     1. send authentication request using API CyBle_GapAuthReq() when the CYBLE_EVT_GAP_DEVICE_CONNECTED is generated, which means that peer device (master) initiated pairing.

     2. display passkey in UART terminal when CYBLE_EVT_GAP_PASSKEY_DISPLAY_REQUEST is received by the stack.

     3. key-in the passkey in the peer device

     4. CYBLE_EVT_GAP_AUTH_COMPLETE is generated indicating authentication is successful

     5.  call API CyBle_StoreBondingData() to prevent going through the pairing process again

However, when I issue a CyBle_GapDisconnect() on the currently connected device, say the Android phone, to allow other master devices to pair with the BLE, I observed that the BLE is removed from the list of "paired devices" of the phone. This prevents the BLE from reconnecting to the Android phone. However, this issue does not occur with the laptop and ipad that I paired with the BLE.

Does anyone know why this happens?

0 Likes
Reply
11 Replies
Moderator
Moderator

Looks like this issue is with Bluetooth v5.0. Can you tell me more about your phone and the Bluetooth version. Also, try checking on phones with Bluetooth v4.2 or so. Let me know your observations.

Regards,

Dheeraj

0 Likes
Reply
Anonymous
Not applicable

Hi ddka​. I am not working with Bluetooth v5.0. The Cypress ble chip I was using has Bluetooth v4.2 and the phone I mentioned is Android v7.1.1, which I believe has Bluetooth v4.0 or something but surely works with BLE.

0 Likes
Reply
Moderator
Moderator

We tried to reproduce your issue on different phones. And we observed that most phones with bluetooth v5 aren't able to store the bonding information. Other phones with bluetooth v4.2 and below, most of them worked perfectly. So this looks like some Android bug. You could use a small delay as mentioned below as a workaround:

f((cyBle_pendingFlashWrite != 0u) && ((UART_SpiUartGetTxBufferSize() + UART_GET_TX_FIFO_SR_VALID) == 0u))

{

  // Store Bonding informtation to flash

  apiResult = CyBle_StoreBondingData(0u);

  if ( apiResult == CYBLE_ERROR_OK)

  {

      CyDelay(500); //Add some delay

      printf("Bonding data stored\r\n");

  }

  else

  {

      printf ("Bonding data storing pending\r\n");

  }

}

Let me know if this worked for you.

Regards,

Dheeraj

0 Likes
Reply
Anonymous
Not applicable

Hi ddka .Thanks. I added the delay as you suggested, but unfortunately, the same thing happens with the Android phone (OS v7.1.1).

Here's more information on what's in the code and what happens during testing:

1. BLE successfully paired with 2 devices (laptop and Android phone) after entering the correct passkey.

2. The BLE is configured as a GAP Peripheral with HID as application, and it needs to be able to swap connection between master devices.

3. A code snippet on BLE issuing a disconnect:

          uint8 bdHandle_toConnect; //ie. laptop_bdHandle=4, phone_bdHandle=3

          

        case CYBLE_EVT_GATT_CONNECT_IND:

            if (bdHandle_toConnect!=cyBle_connHandle.bdHandle) {

                CyBle_GapDisconnect();

                CyBle_ProcessEvents();

            }

            break;

4. Say BLE is currently connected with the Android phone and I wanted to connect to the laptop, BLE automatically connects to no specific device, then BLE issues GapDisconnect if it's the wrong device. This continuously happens in a cycle until it connects to the correct device.

At the first instance that BLE disconnects with the Android phone, I observed that it removes the BLE from its list of paired devices. At that point, BLE will successully connect to the laptop. However, the BLE can no longer connect back to the Android phone.

5. Turning OFF then ON the bluetooth of the Android phone returns the BLE to its list of paired devices. Then, BLE will be able to connect back to it, but the HID functionality of the BLE no longer happens.

BLE_config_passkey.png

0 Likes
Reply
Moderator
Moderator

Is it possible for you to log the events and then share it so that I can understand the sequence of events leading to the issue?

Regards,

Dheeraj

0 Likes
Reply
Anonymous
Not applicable

Here are the logs, ddka​. The values after the events are eventParam values in HEX, and I've also added some comments.

0 Likes
Reply
Moderator
Moderator

It may be because the central device isn't able to resolve the client. Can you try adding some lines of code for adding devices to a resolving list. I have attached a project below which shows how you can write the code. You can find more information about how resolving a device works in page 15 under Link Layer Privacy (Link: http://www.cypress.com/file/224826/download

Kindly add these lines of code and let me know if there is any progress.

Regards,

Dheeraj

0 Likes
Reply
Anonymous
Not applicable

Hi ddka​. I added the lines of code from the project above, and tested with the same laptop PC and Android mobile phone as before. The result is still the same.

I stand corrected. The Cypress BLE chip I'm using is CYBLE-022001-00 which is core version 4.1. Based on AN99209: PSoC® 4 BLE and PRoC™ BLE: Bluetooth LE 4.2 Features, BLE 4.1 is not Link Layer Privacy-enabled unlike 4.2. Is this the reason why it's having issues with the Android phone that has Random Address? Or, the issue is with Android OS 7.1.1?

Thanks.

0 Likes
Reply
Moderator
Moderator

What is the bluetooth version on your phone? Can you check if your application is working on v4.1, v4.2 and v5.0 bluetooth standard phones if you have them. I'm trying to check from my side.

Regards,

Dheeraj

0 Likes
Reply
Anonymous
Not applicable

The bluetooth version of my phone is v4.1. The application has been working on it except after the addition of the passkey-for-pairing feature. I'll see/try if I can look for other phones with other Bluetooth versions.

0 Likes
Reply
Moderator
Moderator

Can you try the below configurations ?

1) Set the GAP Appearance to "Unknown" under the GAP Settings tab of the BLE Component

2) Under the security settings, use "Unauthenticated pairing with encryption"

3) Also check if your application works with other IO Capabilities

Basically I want you to just create a simple application with minimal security settings and check if the bonding information is retained then.

Let me know if it works with the above settings. Is it possible for you to share your project?

Regards,

Dheeraj

0 Likes
Reply