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.

CC2540 - GAP Terminate Link does not work

Other Parts Discussed in Thread: CC2540

Hi All,

I am having an issue with the HCI command to Terminate a link (FE0A)

The command gets correctly sent in my opinion (I receive back the Command Status Message with Status Success), but then I don't receive back the Link Termination event and the connection does not get terminated (same for either central or peripheral mode). 

This happens if I use the single connection handle, or if I send FFFF to terminate all connections (I have 1 active connection at any single point in time).

Curiously, if I use the Immediate Disconnection (FC13) with the connection handle, the termination is successful and I receive almost immediately the Link Termination event (0606).

I am posting here for two things:

first, why don't I get the even back with the termination? It seems pretty basic to me, but I don't get anything on the UART after I received the command status. I check if they come inverted for some reason, but it does not seem to be the case.

Is it coming differently from the link termination in case of external disconnection? I really don't know what to think anymore.

secondly, I won't be very concerned, but there is a case when I am trying to connect to another device and if the connection fails, I will try to connect to another one. What happens if I don't send the FFFE (connection request termination) to the CC2540 and proceed in connecting another device? If this is not a problem, I will keep using the Immediate Disconnection.

Thanks,

Fabrizio

  • Hi,

    I believe your device(MCU+CC2540) is a Master device that is connected to multiple peripheral devices. And you initiate and link terminate with one of the peripheral devices. 

    Are you saying that you didn't receive a GAP link terminate event back saying, connection termination is successful? You should get back an event with reason 0x16( Host requested termination). 

    Can you check if the peripheral disconnects what happens? Are you getting a GAP link terminate event back with reason Supervisor Timeout or Remote User requested termination?

    Regarding your second question, If you don't receive a GAP Link establish event, you can again request for a GAP Link establish(with either the same device or new device). This command might return with an error if earlier link establish is under progress and you may try to establish connection after some time(give a 5 seconds delay before next try). If  not then , there is no issue and you will receive a connection successful event shortly.

    But if you receive a Link established event successfully, then please send the link terminate if you have reached the maximum number of connections possible scenario and wait for the event before sending next command.

    Regards,

    Arun

  • Hi Arun,

    Thank you for the fast reply. I did a lot more tests and let me clarify what I see (which does not look very good). I have the 1.4 ble stack on the CC2540, connected through UART to a MSP430. On the central device, we have no low power modes activated ever. On the peripheral device(same architecture and design) we go low power and we change connection parameters sometimes. The peripheral connects even to our mobile app, and the terminate link still does not work.

    On the central device, the process is to scan for 20 seconds to create a list of nearby devices. Then we go 1 by 1 to connect to them and download the data in the flash. The first connection usually goes through with no problem, then the central calls the terminate links, which waits for 3 seconds for a disconnection event (the one that never comes). Then the device tries to connect to the second one, but since it is still connected to the previous one (and we support in our code just one connection) everything gets complicated. Believing I am still connected, the device moves on and re-sends the same messages to the same device. Then tries to disconnect again..and again (depending by the number of devices previously found, and always failing) until the first one disconnects. The first one disconnects since the device reset the BLE after not receiving messages for 30 seconds, so I get a TIMEOUT disconnection event. 

    Sometime I get the disconnection event with reason 3E, which is not even in the documentation.

    Peripheral:

    On the perpheral the situation is different. We call the terminate link when there is an user intervention and the device is connected. We get the Status Event back with 0x00, then we keep listening for the Link Termination Event that never comes. Using a sniffer I verieifed that the connection is never dropping after we send the message, so the fact that I don't get the link termination event, is right. For some reason the connection does not drop with that command. If I use the Disconnect Immediate, it always does.

    Now I am going to try to use the disconnect immediate from the central device. 

  • Hello Fabrizio,
    The return code 3E is:
    HCI_ERROR_CODE_CONN_FAILED_TO_ESTABLISH

    Do you think it is possible that your are trying to initiate a connection right before you send GAP_TerminateLinkRequest?
  • Hi, may I know did you found any solution to immediately terminate the link? I am facing the same issue, I found a workaround - by initiate the link-termination from the peripherals (but the host doesn't know it's already disconnected)