Skip to content

Commit 51d1a30

Browse files
Route unhandled cmd cmpl events to mbed. Cordio ignores command complete events for all commands that it doesn't have a specific handler for. This adds a catch-all handler that allows the user application to handle any command complete that isn't already handled by the stack. This involves adding a new type of event and routing the event through the stack to the device where it's forwarded to the existing event handling in mbed-os.
1 parent 0affb73 commit 51d1a30

File tree

6 files changed

+85
-0
lines changed

6 files changed

+85
-0
lines changed

features/FEATURE_BLE/targets/TARGET_CORDIO/mbed_lib.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@
6363
"help": "Where the CBC MAC calculatio is performed. Valid values are 0 (host) and 1 (controller through HCI).",
6464
"value": 1,
6565
"macro_name": "SEC_CCM_CFG"
66+
},
67+
"route_unhandled_command_complete_events": {
68+
"help": "If enabled the stack will forward to the user all HCI events not handled by the stack.",
69+
"value": 1
6670
}
6771
}
6872
}

features/FEATURE_BLE/targets/TARGET_CORDIO/stack/ble-host/include/dm_api.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,9 @@ enum
511511
DM_ERROR_IND, /*!< \brief General error */
512512
DM_HW_ERROR_IND, /*!< \brief Hardware error */
513513
DM_VENDOR_SPEC_IND /*!< \brief Vendor specific event */
514+
#if MBED_CONF_CORDIO_ROUTE_UNHANDLED_COMMAND_COMPLETE_EVENTS
515+
, DM_UNHANDLED_CMD_CMPL_EVT_IND, /*!< \brief Unhandled command complete events */
516+
#endif
514517
};
515518

516519
#define DM_CBACK_END DM_VENDOR_SPEC_IND /*!< \brief DM callback event ending value */
@@ -763,6 +766,9 @@ typedef union
763766
hciLeConnCteRspEnableCmdCmplEvt_t connCteRspStart; /*!< \brief handles \ref DM_CONN_CTE_RSP_START_IND */
764767
hciLeConnCteRspEnableCmdCmplEvt_t connCteRspStop; /*!< \brief handles \ref DM_CONN_CTE_RSP_STOP_IND */
765768
hciLeReadAntennaInfoCmdCmplEvt_t readAntennaInfo; /*!< \brief handles \ref DM_READ_ANTENNA_INFO_IND */
769+
#if MBED_CONF_CORDIO_ROUTE_UNHANDLED_COMMAND_COMPLETE_EVENTS
770+
hciUnhandledCmdCmplEvt_t unhandledCmdCmplEvt;
771+
#endif
766772
dmL2cCmdRejEvt_t l2cCmdRej; /*!< \brief handles \ref DM_L2C_CMD_REJ_IND */
767773
/* common header used by DM_ERROR_IND */
768774
hciHwErrorEvt_t hwError; /*!< \brief handles \ref DM_HW_ERROR_IND */

features/FEATURE_BLE/targets/TARGET_CORDIO/stack/ble-host/include/hci_api.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ extern "C" {
115115
#define HCI_CIS_EST_CBACK_EVT 68 /*!< \brief CIS established event */
116116
#define HCI_CIS_REQ_CBACK_EVT 69 /*!< \brief CIS request event */
117117
#define HCI_REQ_PEER_SCA_CBACK_EVT 70 /*!< \brief Request peer SCA complete */
118+
#if MBED_CONF_CORDIO_ROUTE_UNHANDLED_COMMAND_COMPLETE_EVENTS
119+
#define HCI_UNHANDLED_CMD_CMPL_CBACK_EVT 71 /*!< \brief Unhandled event */
120+
#endif
118121
/**@}*/
119122

120123
/**************************************************************************************************
@@ -679,6 +682,15 @@ typedef struct
679682
uint8_t cteMaxLen; /*!< \brief Max CTE Length. */
680683
} hciLeReadAntennaInfoCmdCmplEvt_t;
681684

685+
#if MBED_CONF_CORDIO_ROUTE_UNHANDLED_COMMAND_COMPLETE_EVENTS
686+
/*! \brief LE read antenna information command complete event */
687+
typedef struct
688+
{
689+
wsfMsgHdr_t hdr; /*!< \brief Event header containing the opcode in hdr.param. */
690+
uint8_t param[1]; /*!< \brief Unhandled event payload. */
691+
} hciUnhandledCmdCmplEvt_t;
692+
#endif // MBED_CONF_CORDIO_ROUTE_UNHANDLED_COMMAND_COMPLETE_EVENTS
693+
682694
/*! \brief Local version information */
683695
typedef struct
684696
{
@@ -754,6 +766,9 @@ typedef union
754766
hciLeConnCteReqEnableCmdCmplEvt_t leConnCteReqEnableCmdCmpl; /*!< \brief LE connection CTE request enable command complete. */
755767
hciLeConnCteRspEnableCmdCmplEvt_t leConnCteRspEnableCmdCmpl; /*!< \brief LE connection CTE response enable command complete. */
756768
hciLeReadAntennaInfoCmdCmplEvt_t leReadAntennaInfoCmdCmpl; /*!< \brief LE read antenna information command complete. */
769+
#if MBED_CONF_CORDIO_ROUTE_UNHANDLED_COMMAND_COMPLETE_EVENTS
770+
hciUnhandledCmdCmplEvt_t unhandledCmdCmpl; /*!< \brief Unhandled events. */
771+
#endif
757772
} hciEvt_t;
758773

759774
/*! \} */ /* STACK_HCI_EVT_API */

features/FEATURE_BLE/targets/TARGET_CORDIO/stack/ble-host/sources/hci/dual_chip/hci_evt.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2048,13 +2048,42 @@ void hciEvtProcessCmdCmpl(uint8_t *p, uint8_t len)
20482048
{
20492049
cbackEvt = hciCoreVsCmdCmplRcvd(opcode, p, len);
20502050
}
2051+
#if MBED_CONF_CORDIO_ROUTE_UNHANDLED_COMMAND_COMPLETE_EVENTS
2052+
else
2053+
{
2054+
cbackEvt = HCI_UNHANDLED_CMD_CMPL_CBACK_EVT;
2055+
}
2056+
#endif // MBED_CONF_CORDIO_ROUTE_UNHANDLED_COMMAND_COMPLETE_EVENTS
20512057
break;
20522058
}
20532059

20542060
/* if callback is executed for this event */
20552061
if (cbackEvt != 0)
20562062
{
20572063
/* allocate temp buffer */
2064+
#if MBED_CONF_CORDIO_ROUTE_UNHANDLED_COMMAND_COMPLETE_EVENTS
2065+
if (cbackEvt == HCI_UNHANDLED_CMD_CMPL_CBACK_EVT) {
2066+
const uint8_t structSize = sizeof(hciUnhandledCmdCmplEvt_t) - 1 /* removing the fake 1-byte array */;
2067+
const uint8_t remainingLen = len - 3 /* we already read opcode and numPkts */;
2068+
const uint8_t msgSize = structSize + remainingLen;
2069+
2070+
pMsg = WsfBufAlloc(msgSize);
2071+
if (pMsg != NULL) {
2072+
pMsg->hdr.param = opcode;
2073+
pMsg->hdr.event = HCI_UNHANDLED_CMD_CMPL_CBACK_EVT;
2074+
pMsg->hdr.status = HCI_SUCCESS;
2075+
/* copy the payload */
2076+
memcpy(pMsg->unhandledCmdCmpl.param, p, remainingLen);
2077+
2078+
/* execute callback */
2079+
(*cback)(pMsg);
2080+
2081+
/* free buffer */
2082+
WsfBufFree(pMsg);
2083+
}
2084+
}
2085+
else
2086+
#endif // MBED_CONF_CORDIO_ROUTE_UNHANDLED_COMMAND_COMPLETE_EVENTS
20582087
if ((pMsg = WsfBufAlloc(hciEvtCbackLen[cbackEvt])) != NULL)
20592088
{
20602089
/* initialize message header */

features/FEATURE_BLE/targets/TARGET_CORDIO/stack/ble-host/sources/stack/dm/dm_dev.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,23 @@ static void dmDevHciEvtHwError(hciEvt_t *pEvent)
128128
(*dmCb.cback)((dmEvt_t *) pEvent);
129129
}
130130

131+
#if MBED_CONF_CORDIO_ROUTE_UNHANDLED_COMMAND_COMPLETE_EVENTS
132+
/*************************************************************************************************/
133+
/*!
134+
* \brief Handle unhandled command complete events from HCI.
135+
*
136+
* \param pEvent Pointer to HCI callback event structure.
137+
*
138+
* \return None.
139+
*/
140+
/*************************************************************************************************/
141+
static void dmDevHciEvtUnhandledCmdCmpl(hciEvt_t *pEvent)
142+
{
143+
pEvent->hdr.event = DM_UNHANDLED_CMD_CMPL_EVT_IND;
144+
(*dmCb.cback)((dmEvt_t *) pEvent);
145+
}
146+
#endif // MBED_CONF_CORDIO_ROUTE_UNHANDLED_COMMAND_COMPLETE_EVENTS
147+
131148
/*************************************************************************************************/
132149
/*!
133150
* \brief DM dev HCI event handler.
@@ -153,6 +170,12 @@ void dmDevHciHandler(hciEvt_t *pEvent)
153170
dmDevHciEvtHwError(pEvent);
154171
break;
155172

173+
#if MBED_CONF_CORDIO_ROUTE_UNHANDLED_COMMAND_COMPLETE_EVENTS
174+
case HCI_UNHANDLED_CMD_CMPL_CBACK_EVT:
175+
dmDevHciEvtUnhandledCmdCmpl(pEvent);
176+
break;
177+
#endif // MBED_CONF_CORDIO_ROUTE_UNHANDLED_COMMAND_COMPLETE_EVENTS
178+
156179
default:
157180
/* ignore event */
158181
break;

features/FEATURE_BLE/targets/TARGET_CORDIO/stack/ble-host/sources/stack/dm/dm_main.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,14 @@ static const uint8_t dmHciToIdTbl[] =
107107
DM_ID_CONN_CTE, /* HCI_LE_CONN_CTE_REQ_ENABLE_CMD_CMPL_CBACK_EVT */
108108
DM_ID_CONN_CTE, /* HCI_LE_CONN_CTE_RSP_ENABLE_CMD_CMPL_CBACK_EVT */
109109
DM_ID_CONN_CTE /* HCI_LE_READ_ANTENNA_INFO_CMD_CMPL_CBACK_EVT */
110+
#if MBED_CONF_CORDIO_ROUTE_UNHANDLED_COMMAND_COMPLETE_EVENTS
111+
/* these 3 were inexplicably missing */
112+
, DM_ID_DEV /* HCI_CIS_EST_CBACK_EVT */
113+
, DM_ID_DEV /* HCI_CIS_REQ_CBACK_EVT */
114+
, DM_ID_DEV /* HCI_REQ_PEER_SCA_CBACK_EVT */
115+
116+
, DM_ID_DEV /* HCI_UNHANDLED_CMD_COMPL_CBACK_EVT */
117+
#endif
110118
};
111119

112120
/* DM callback event length table */

0 commit comments

Comments
 (0)