Skip to content

Commit

Permalink
Sync for event, Gen1 BT devices may have two or more events per comma…
Browse files Browse the repository at this point in the history
…nd, we should read all of them before sending another command.
  • Loading branch information
zxystd committed Aug 29, 2021
1 parent fd6110f commit 06f9d25
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
21 changes: 21 additions & 0 deletions IntelBluetoothFirmware/BtIntel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,27 @@ intelSendHCISync(HciCommandHdr *cmd, void *event, uint32_t eventBufSize, uint32_
return true;
}

bool BtIntel::
intelSendHCISyncEvent(HciCommandHdr *cmd, void *event, uint32_t eventBufSize, uint32_t *size, uint8_t syncEvent, int timeout)
{
IOReturn ret;
if ((ret = m_pUSBDeviceController->sendHCIRequest(cmd, timeout)) != kIOReturnSuccess) {
XYLog("%s sendHCIRequest failed: %s %d\n", __FUNCTION__, m_pUSBDeviceController->stringFromReturn(ret), ret);
return false;
}
do {
ret = m_pUSBDeviceController->interruptPipeRead(event, eventBufSize, size, timeout);
if (ret != kIOReturnSuccess) {
XYLog("%s interruptPipeRead failed: %s %d\n", __FUNCTION__, m_pUSBDeviceController->stringFromReturn(ret), ret);
break;
}
if (*(uint8_t *)event == syncEvent) {
return true;
}
} while (true);
return false;
}

bool BtIntel::
intelBulkHCISync(HciCommandHdr *cmd, void *event, uint32_t eventBufSize, uint32_t *size, int timeout)
{
Expand Down
2 changes: 2 additions & 0 deletions IntelBluetoothFirmware/BtIntel.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ class BtIntel : public OSObject {

bool intelSendHCISync(HciCommandHdr *cmd, void *event, uint32_t eventBufSize, uint32_t *size, int timeout);

bool intelSendHCISyncEvent(HciCommandHdr *cmd, void *event, uint32_t eventBufSize, uint32_t *size, uint8_t syncEvent, int timeout);

bool intelBulkHCISync(HciCommandHdr *cmd, void *event, uint32_t eventBufSize, uint32_t *size, int timeout);

protected:
Expand Down
2 changes: 1 addition & 1 deletion IntelBluetoothFirmware/IntelBluetoothOpsGen1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ patching(OSData *fwData, const uint8_t **fw_ptr, bool *disablePatch)
hciCmd->len = cmd->len;
memcpy(hciCmd->data, cmdParam, hciCmd->len);

if (!intelSendHCISync(hciCmd, resp, sizeof(respBuf), &actRespLen, HCI_INIT_TIMEOUT)) {
if (!intelSendHCISyncEvent(hciCmd, resp, sizeof(respBuf), &actRespLen, evt->evt, HCI_INIT_TIMEOUT)) {
XYLog("sending Intel patch command (0x%4.4x) failed\n", hciCmd->opcode);
return false;
}
Expand Down

0 comments on commit 06f9d25

Please sign in to comment.