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:
- There need to be only one connection handle available, i.e. linkDB_NumActive() == MAX_NUM_BLE_CONNS-1
- There needs to be a new connection establishment attempt with GAPRole_EstablishLink()
- There needs to be a client (phone) connecting to the multi-role at the same time, while GAPRole_EstablishLink() on multi-role.
- 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.
- 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.
- 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.