Skip to content

Commit

Permalink
Ignore the PS4 packet CRC if it's not being set correctly
Browse files Browse the repository at this point in the history
This fixes handling the 8BitDo SN30 Pro with the 2.00 firmware in PS4 mode

Fixes libsdl-org#7270
  • Loading branch information
slouken committed Mar 14, 2023
1 parent f1d9c36 commit 3951cae
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/joystick/hidapi/SDL_hidapi_ps4.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ typedef struct
Uint8 led_blue;
Uint64 sensor_ticks;
Uint16 last_tick;
Uint16 valid_crc_packets; /* wrapping counter */
PS4StatePacket_t last_state;
} SDL_DriverPS4_Context;

Expand Down Expand Up @@ -1026,7 +1027,18 @@ static SDL_bool HIDAPI_DriverPS4_IsPacketValid(SDL_DriverPS4_Context *ctx, Uint8
case k_EPS4ReportIdBluetoothState8:
case k_EPS4ReportIdBluetoothState9:
/* Bluetooth state packets have two additional bytes at the beginning, the first notes if HID data is present */
if (size >= 78 && (data[1] & 0x80) && VerifyCRC(data, 78)) {
if (size >= 78 && (data[1] & 0x80)) {
if (VerifyCRC(data, 78)) {
++ctx->valid_crc_packets;
} else {
if (ctx->valid_crc_packets > 0) {
--ctx->valid_crc_packets;
}
if (ctx->valid_crc_packets >= 3) {
/* We're generally getting valid CRC, but failed one */
return SDL_FALSE;
}
}
return SDL_TRUE;
}
break;
Expand Down

0 comments on commit 3951cae

Please sign in to comment.