+\r
+/** Sends a Bluetooth HCI control command to the attached Bluetooth device.\r
+ *\r
+ * \param[in] HCICommandHeader HCI command header to send to the attached device\r
+ * \param[in] Parameters Pointer to the source of the control parameters (if any)\r
+ * \param[in] ParameterLength Length of the parameters to send in bytes\r
+ *\r
+ * \return A value from the USB_Host_SendControlErrorCodes_t enum.\r
+ */\r
+static uint8_t Bluetooth_SendHCICommand(const BT_HCICommand_Header_t* const HCICommandHeader, const void* Parameters, const uint16_t ParameterLength)\r
+{\r
+ /* Need to reserve the amount of bytes given in the header for the complete payload */\r
+ uint8_t CommandBuffer[sizeof(BT_HCICommand_Header_t) + HCICommandHeader->ParameterLength];\r
+\r
+ USB_ControlRequest = (USB_Request_Header_t)\r
+ {\r
+ .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_DEVICE),\r
+ .bRequest = 0,\r
+ .wValue = 0,\r
+ .wIndex = 0,\r
+ .wLength = sizeof(CommandBuffer)\r
+ };\r
+\r
+ /* Copy over the HCI command header to the allocated buffer */\r
+ memcpy(CommandBuffer, HCICommandHeader, sizeof(BT_HCICommand_Header_t));\r
+ \r
+ /* Zero out the parameter section of the response so that all padding bytes are known to be zero */\r
+ memset(&CommandBuffer[sizeof(BT_HCICommand_Header_t)], 0x00, HCICommandHeader->ParameterLength);\r
+\r
+ /* Copy over the command parameters (if any) to the command buffer - note, the number of actual source parameter bytes\r
+ may differ to those in the header; any difference in length is filled with 0x00 padding bytes */\r
+ memcpy(&CommandBuffer[sizeof(BT_HCICommand_Header_t)], Parameters, ParameterLength);\r
+ \r
+ Pipe_SelectPipe(PIPE_CONTROLPIPE);\r
+ return USB_Host_SendControlRequest(CommandBuffer);\r
+}\r