Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Which CRC32 algorithm for PS5 Controller BT package? [Help wanted] #28

Open
nonobody15 opened this issue Mar 18, 2023 · 2 comments
Open

Comments

@nonobody15
Copy link

Hi,
i am trying to use the PS5 controller via bluetooth with a microcontroller (ESP32) and the Arduino framework. This library offers the possibility to receive and process the input from the controller without problems. The previous version (for the PS4 controller) also offers the functionality to send an output and for example control the RGB LED of the controller. Unfortunately, this function is not adapted in the library for the PS5 controller, so it does not work. Therefore I try to implement this function based on this repository. I have already posted my current status here.
My question:
Which algorithm must be used to calculate the CRC32 checksum? I have of course looked at the algorithm in DS_CRC32.cpp. However, when I run it on my ESP32 (32bit), it gives a result that I can't find in this online calculator that I use as a reference. Therefore, my question is how I can check whether the ESP32 calculates the checksum correctly.
I would be very happy if someone can help me further. If there are any uncertainties regarding my question, please bring them to my attention.

@p-groarke
Copy link

p-groarke commented Sep 30, 2023

For future reference, using zlib (c package), you don't need anything fancy. Information online is misleading.

If your report doesn't start with the report type seed, you'll need to crc it first.

  • input report : 0xA1
  • output report : 0xA2
  • feature report : 0xA3

Then you simply use zlib crc32 to encode the report (excluding the last 4 bytes which will hold your crc value). You can double check you have it right by reading a feature report, CRCing it, and comparing with the expected crc (last 4 bytes of recieved report).

Example (assuming feature report, which doesn't start with report type) :

const uint8_t seed = 0xA3; // feature report
uint32_t crc = crc32(0, &seed, 1); // report buffer doesn't start with type, preheat manually
crc = crc32(crc, your_buffer, your_buffer_size - 4); // compute plain boring crc

// now compare with last 4 bytes of report, it should match

Note, according to zlib doc, you might want to start with a crc32(0L, Z_NULL, 0) value. Not sure it matters, not there yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants