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.

CC2640R2F: CMDSTA_ILLEGAL_PTR on incoming connection while GAPRole_EstablishLink(). Multi-role stops advertising.

Part Number: CC2640R2F

SDK: 5.10 (and all previous versions)

Project: Multi-Role 

Part: CC2640R2F (also seen on CC26X2R) 

Launchpad CC2640R2


After days of digging, the following conditions will reproduce a HCI_COMMAND_STATUS_EVENT_CODE with value 0x81 CMDSTA_ILLEGAL_PTR with 100% fail rate:
  1. There need to be only one connection handle available, i.e. linkDB_NumActive() == MAX_NUM_BLE_CONNS-1
  2. There needs to be a new connection establishment attempt with GAPRole_EstablishLink()
  3. There needs to be a client (phone) connecting to the multi-role at the same time, while GAPRole_EstablishLink() on multi-role.
  4. There is a conflict to get the last available connection handle, this will lead to HCI_COMMAND_STATUS_EVENT_CODE with value 0x81 CMDSTA_ILLEGAL_PTR. At that moment a reboot is necessary. If multi-role is not rebooted, advertising will quietly stop forever until reboot. 
How to reproduce on unmodified multi-role:
  • Set MAX_NUM_BLE_CONNS=1
  • (alternatively can also connect more peripherals to use up all but one connection handles)
  • Find multi-role on a client (phone) but do not connect yet.
  • multi-role do: Scan and choose a peripheral device to connect to
  • switch off the peripheral device or stop advertising, this step is not necessary but helps to reproduce more easily 
  • multi-role do: Connect to a device
  • Immediately after pressing the multi-role button to connect to a device, connect to the advertising multi-role with the client (phone).
  • The client connection will fail, multi-role triggers CMDSTA_ILLEGAL_PTR and stops advertising until reboot.
How to avoid CMDSTA_ILLEGAL_PTR 
  • if "linkDB_NumActive() == MAX_NUM_BLE_CONNS-1", don't initiate GAPRole_EstablishLink(). However there is a race condition in which an external connection could still occur between this test and initiating GapInit_cancelConnect(). 
  • if "linkDB_NumActive() == MAX_NUM_BLE_CONNS-1", stop advertising before each call to GAPRole_EstablishLink() and until success or cancelled with GAPRole_TerminateConnection(GAP_CONNHANDLE_INIT) or GapInit_cancelConnect(), depending on the SDK version.

Hopefully this information will help anyone else cut their headache. 

  • Hey Jerome,

    Thank you for the thorough investigation, as well as your suggested workaround. I will investigate this and follow up with the team internally to incorporate any improvements in the stack.

    Do you happen to have a sniffer capture of the issue that you can share?

  • multirole_CMDSTA_ILLEGAL_PTR.zip
    Here attached a capture,

    For the purpose of the capture, those were my steps. On unmodified multi-role:

    • Set MAX_NUM_BLE_CONNS=2
    • Find multi-role on a client (phone) but do not connect yet.
    • multi-role do: Scan and choose a peripheral device to connect to
    • multi-role do: Connect to the peripheral
    • make sure peripheral is not advertising anymore 
    • multi-role do: Without scanning, try to connect to the same peripheral again, this is expected to fail as multi-role is already connected to that peripheral and peripheral has stopped advertising. 
    • 2 seconds after pressing the multi-role button to connect to the device, connect to the advertising multi-role with the client (phone).
    • The client connection will fail, multi-role triggers CMDSTA_ILLEGAL_PTR and ASSERT SPIN LOCK. 

    Note that default multi-role will assert and spinlock. However I should point out that the issue described as "Multi-role stops advertising" occurs only when we remove the spinlock and try to continue operations without rebooting, as rebooting negatively affects our UX we are trying to avoid it. 

  • Thank you for the logs, this is very helpful for us.

    I'll mark this thread as closed now and forward this to the team internally. If I have any questions or if there is another workaround I can provide, I will comment on this post with a follow up.