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.

CC2564: How to differentiate disconnection reason?

Part Number: CC2564

Hi,

I am currently working on a sort of a headset which use a Bluetooth connection between a phone and my device.
The device is based on the CC2564MODA chip controlled by a STM32L4 micro controller.
I successfully integrated the Bluetopia stack on my ST chip and managed to control the CC2564 with HCI commands and I2S audio samples.

I chose to include the Bluetooth HFP profile using the example given in the stack. It also works fine for my use case.

My issue is:

My device must automatically connect the phone in case of a disconnection due to distance or transmission errors.
But it must NOT try to reconnect the phone if the user decided to stop the connection to my device on the phone-side.
I currently use the event etHFRE_Close_Port_Indication to detect a disconnection and start a re-connection procedure but this event does not let me see if the connection was stop on purpose by the user.

Is there a way to differentiate the disconnection reason?

I looked through the TI forum but I did not find any information about the subject.

Thanks in advance,

Alain.

 

  • Alain , can you share HCI tester and firmware logs ?

    Thanks
    Saurabh
  • Hi Saurabh,

    My device does not include UART output so I cannot access firmware logs anymore.
    I can only share the BT logs from the TX_DBG pin. Is this relevant?

    Regards,

    Alain.

  • Hi Alain,

    Yes, please share the BT firmware logs from the TX_DBG pin.

    BT Logger User's Guide : 

    BR,

    Vihang

  • Hi Vihang,

    I divided the logs into 3 files, each one representing a different scenario:

    1. The first one shows a connection to the remote device (an android phone) which was previously paired with my device. There is no issue at this time.
    2. The second file shows, after an established connection, a disconnection from the user. For that, I go into the Android Bluetooth Menu and click on my device name.
    3. The last one shows, after an established connection, a disconnection from distance. For that I take my phone and go far away for my device until the Bluetooth Menu indicates no connection between them.

    I would like to differentiate the scenario 2 and 3 on the device side; so in case 3 I launch a re-connection procedure and in case 2 I do nothing.

    Thank you for your help,

    Alain

    Attached files:

    logs.zip

  • Hi Vihang,

    A little update on this matter:
    From another of my post on this forum, Saurabh said that my logs were incomplete. So I logged, with right parameters this time, a disconnection from user on the remote side (see attached files) and studied the logs.

    As I can see, there is a HCI_Disconnect command send from the host to the device with Reason 0x13 (Remote User Terminated Connection). It is this information that I would like to get on my microcontroller. Because my code do not send intentionally the HCI_Disconnect command, I suspect that is the library SS1BTHFR that is doing it.

    I registered and added the HCI_Event_Callback in the idea of retrieving a etDisconnection_Complete_Event. Unfortunately, it never come.
    Below a snippet of the HCI_Event_Callback:

    static void BTPSAPI HCI_Event_Callback(unsigned int BluetoothStackID, HCI_Event_Data_t *HCI_Event_Data, unsigned long CallbackParameter)
    {
      HCI_Disconnection_Complete_Event_Data_t *HCI_Disconnection_Complete_Event_Data;
    
      /* First, check to see if the required parameters appear to be       */
      /* semi-valid.                                                       */
      if((BluetoothStackID) && (HCI_Event_Data))
      {
        /* The parameters appear to be semi-valid, now check to see what  */
        /* type the incoming event is.                                    */
        switch(HCI_Event_Data->Event_Data_Type)
        {
          case etDisconnection_Complete_Event:
    
          HCI_Disconnection_Complete_Event_Data = HCI_Event_Data->Event_Data.HCI_Disconnection_Complete_Event_Data; 
          if(HCI_Disconnection_Complete_Event_Data->Reason == HCI_ERROR_CODE_OTHER_END_TERMINATED_CONNECTION_USER_ENDED)
          {
            while(1);
          }
          break;
        }
      }
    }

    So my question is still the same, is there a way to get the information remote user terminated connection on host side.

    Best regards,

    Alain.

    Attached files:

    2335.logs.zip

  • Alain,

    I see some unusual behavior in these logs. While it does look like the host stack is sending HCI_Disconnect command to the CC256xB, the chip is being reset before it can send the Disconnection_Complete_Event for this HCI_Disconnect.
    - #2453 Host sends HCI_Disconnect command with reason 0x13.
    - #2454 Controller sends the HCI_Command_Status_Event for this command.
    - #2455 The host sends HCI_VS_Sleep_Mode_Configurations command to the controller. This would never be sent out by the stack or the profile itself unless specifically programmed in the application. <- Please check if you application is doing this.
    - # 2468 Before the CC256x controller can disconnect the connection and send the corresponding HCI_Disconnection_Complete_Event to the host, the controller is reset by toggling the nSHUTD pin. <- Please check your application for this misbehavior as well.

    In general, the HCI_Disconnection_Complete_Event will contain one of the two reason codes in a "link loss" scenario due to the remote device being out of range.
    HCI_ERROR_CODE_CONNECTION_TIMEOUT 0x08 , OR
    HCI_ERROR_CODE_LMP_RESPONSE_TIMEOUT 0x22.

    Similarly, the reason code would be 0x13 (like your implementation above) when the remote user manually disconnects.

    So, I think you are on the right path regarding the HCI_Event_Callback. By checking for the correct reason codes in the etDisconnection_Complete_Event case, you can successfully distinguish between a disconnection due to link loss and a disconnection due to user termination.

    Best regards,
    Vihang
  • Hi Vihang,

    I checked the unusual behavior you pointed out to me.
    In fact I was monitoring the disconnection too early in the process (something like HFP close port indication) which triggered a shutdown of the BT module in my code.
    Now I wait for the HCI disconnection event before closing anything and it works as expected !

    Thank you very much for your help.

    Best regards,

    Alain.