Author Topic: Figuring out error detection scheme for custom protocol  (Read 1661 times)

0 Members and 1 Guest are viewing this topic.

Offline m.elsayedTopic starter

  • Contributor
  • Posts: 18
  • Country: eg
Figuring out error detection scheme for custom protocol
« on: October 14, 2025, 01:18:53 am »
Background:
I have a cheap game controller that uses some kind of custom communication protocol, the closest I have found similar to it is MicroWire or half-duplex SPI
There are two controllers, one is the primary which connects to a computer over USB, and poll the secondary using what I think a custom protocol.

Of course the two chips are black blobs, so there is no way to get any information about how do they work.

1. There are two wires, clock and data
2. clock and data are idle high
3. primary controller generate the clock (25kHz)
4. when the clock ticks, second controller will take control of the bus and send 8 bytes, sampled on the falling edge
5. then the primary controller takes control and send 2 bytes (mostly to control the rumble motor and perhaps acknowledgment)
6. primary controller will tick twice, so a total of 90 clock cycles
7. idle for 10-13 microsecond, then repeat.

I have successfully mapped all the buttons to individual bits like this:

Code: [Select]
struct ControllerData {
  uint8_t x;
  uint8_t y;
  uint8_t rx;
  uint8_t ry;
  uint8_t Key1 : 1;
  uint8_t Key2 : 1;
  uint8_t Key3 : 1;
  uint8_t Key4 : 1;
  uint8_t L1 : 1;
  uint8_t R1 : 1;
  uint8_t L2 : 1;
  uint8_t R2 : 1;
 
 
  uint8_t Start : 1;
  uint8_t Select : 1;
  uint8_t LThumb : 1;
  uint8_t RThumb : 1;
  uint8_t Up : 1;
  uint8_t Down : 1;
 
  uint8_t Left : 1;
  uint8_t Right : 1;
 
  uint8_t _pad0 : 4;
  uint8_t curr_mode : 1; // LED on/off
  uint8_t _pad1 : 8; // error detection?
  uint8_t _pad2 : 3; // // error detection?
};

Can anyone recognize what kind of error detection is this?

my only problem is figuring out what kind of error detection/CRC it uses.
my guess is that the last 8-11 bits are used for that.

I have tried to focus on cases where all the bits are 0 except for a single bit and observe the change, and what I have noticed is that the last 11 bits will change drastically.

mainly these cases:
Code: [Select]
00 00 00 00 00 00 5A 6B
00 00 00 00 00 00 6A CB
00 00 00 00 00 01 4A 1F
00 00 00 00 00 10 2A 0B
00 00 00 00 00 20 8A 0B
00 00 00 00 00 40 CA 0A
00 00 00 00 00 80 4A 08
00 00 00 00 01 00 4A 73
00 00 00 00 02 00 4A FB
00 00 00 00 04 00 2A AB
00 00 00 00 08 00 EA 0B
00 00 00 00 10 00 0A 0A

this is all the patterns that I have gathered, it includes almost all possible combinations (single button, multiple buttons, analog sticks, ...etc)

Code: [Select]
00 00 00 00 00 00 5A 6B
00 00 00 00 00 00 6A CB
00 00 00 00 00 01 4A 1F
00 00 00 00 00 10 2A 0B
00 00 00 00 00 20 8A 0B
00 00 00 00 00 40 CA 0A
00 00 00 00 00 80 4A 08
00 00 00 00 01 00 4A 73
00 00 00 00 02 00 4A FB
00 00 00 00 04 00 2A AB
00 00 00 00 08 00 EA 0B
00 00 00 00 10 00 0A 0A
00 00 7C 00 00 00 8A 70
00 00 CC 00 00 00 AA 0B
00 00 EC 00 00 00 8A E9
00 00 FC 50 00 00 2A 21
00 00 FC 7C 00 00 2A EC
00 0C FC 00 00 00 2A 12
00 10 FC 00 00 00 8A 9E
00 84 00 48 00 00 8A 3F
00 FC 00 48 00 00 EA 7E
34 84 7C 80 00 64 5A FD
70 84 7C 80 00 00 8A C8
74 00 00 00 00 00 4A F3
74 00 00 68 00 00 AA 21
74 00 00 80 00 00 6A 0F
74 00 7C 80 00 00 8A B4
74 84 00 00 00 00 6A 1A
74 84 00 04 00 00 AA DB
74 84 00 10 00 00 CA DD
74 84 00 50 00 00 EA 03
74 84 00 80 00 00 4A E6
74 84 00 FC 00 00 CA 32
74 84 60 80 00 03 4A BC
74 84 68 80 00 02 CA A0
74 84 7C 00 04 00 CA C1
74 84 7C 80 00 00 9A FD
74 84 7C 80 00 00 AA 5D
74 84 7C 80 00 01 8A 89
74 84 7C 80 00 04 8A CD
74 84 7C 80 00 08 8A 3D
74 84 7C 80 00 10 EA 9D
74 84 7C 80 00 14 CA 0D
74 84 7C 80 00 20 4A 9D
74 84 7C 80 00 30 0A 5D
74 84 7C 80 00 40 0A 9C
74 84 7C 80 00 50 4A 5C
74 84 7C 80 00 60 EA 5C
74 84 7C 80 00 80 8A 9E
74 84 7C 80 00 90 CA 5E
74 84 7C 80 00 98 DA 9E
74 84 7C 80 00 C0 2A 5F
74 84 7C 80 00 F0 8A 5F
74 84 7C 80 01 00 8A E5
74 84 7C 80 01 00 BA 45
74 84 7C 80 01 08 AA 85
74 84 7C 80 02 00 8A 6D
74 84 7C 80 02 08 AA 0D
74 84 7C 80 02 40 2A AC
74 84 7C 80 02 50 6A 6C
74 84 7C 80 02 70 8A AC
74 84 7C 80 03 00 AA D5
74 84 7C 80 03 08 BA 15
74 84 7C 80 04 00 EA 3D
74 84 7C 80 04 08 CA 5D
74 84 7C 80 05 00 CA 85
74 84 7C 80 06 00 CA 0D
74 84 7C 80 06 A0 0A 0E
74 84 7C 80 07 00 EA B5
74 84 7C 80 08 00 2A 9D
74 84 7C 80 08 08 0A FD
74 84 7C 80 09 00 0A 25
74 84 7C 80 09 90 6A 26
74 84 7C 80 0A 00 0A AD
74 84 7C 80 0C 08 7A 3D
74 84 7C 80 0C 90 0A FE
74 84 7C 80 0F 00 6A 75
74 84 7C 80 10 00 CA 9C
74 84 7C FC 00 00 2A 89
74 84 C8 FC 00 00 6A 36
74 84 FC 00 00 00 AA E9
74 84 FC 80 00 00 8A 15
74 84 FC FC 00 00 0A C1
74 FC 7C FC 00 00 4A C8
7C 84 7C 80 00 0C 8A C7
80 FC 7C 80 08 00 4A 87
C8 00 00 FC 00 00 6A 7B
CC 84 00 80 00 00 EA D3
FC 00 00 00 00 00 4A FA
FC 00 00 78 00 00 0A EF
FC 00 00 7C 00 00 CA 2E
FC 00 00 80 00 00 6A 06
FC 00 7C FC 00 00 0A 69
FC 00 84 00 00 00 0A 76
FC 00 FC 00 00 00 8A 09
FC 00 FC 8C 00 00 8A F7
FC 84 00 80 00 00 4A EF
FC 84 7C 80 00 00 AA 54
FC 84 7C 80 00 01 8A 80
FC 84 FC FC 00 00 0A C8
FC FC 00 48 00 00 CA 4F
FC FC 00 FC 00 00 AA 7A
FC FC 7C 80 00 00 CA 15
 

Offline darkspr1te

  • Frequent Contributor
  • **
  • Posts: 550
  • Country: zm
 

Offline m.elsayedTopic starter

  • Contributor
  • Posts: 18
  • Country: eg
Re: Figuring out error detection scheme for custom protocol
« Reply #2 on: October 14, 2025, 07:36:12 pm »
There are two possibles I can think of. it's either sony DS2 protocol or nintendo protcol,
see these sites

https://circuitcellar.com/research-design-hub/projects/interfacing-with-video-game-controllers/
https://learn.adafruit.com/super-nintendo-usb-controller/how-it-works
https://gamefaqs.gamespot.com/snes/916396-super-nintendo/faqs/5395


darkspr1te

Thank you so much for your reply, unfortunately it's neither of these protocols.
It's not as complex as PS2(half-duplex) and slightly more complex(2-way communication) than Nintendo NES protocol.

To be honest I have given up on finding out which protocol it is, and I only need to figure out the error detection scheme.
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 6939
  • Country: es
Re: Figuring out error detection scheme for custom protocol
« Reply #3 on: October 14, 2025, 07:54:18 pm »
The first 4 bytes look like 8-bit signed integers for the joysticks:
Code: [Select]
[74 84 7C FC] 00 00 2A 89
The last byte doesn't seem to be a checksum, it repeats for different data.
It might be other flags for the buttons, indicating timing, previous states...

I sorted the list by "checksum":
Code: [Select]
74 84 00 50 00 00 EA 03
FC 00 00 80 00 00 6A 06
00 00 00 00 00 80 4A 08
FC 00 FC 00 00 00 8A 09
00 00 00 00 00 40 CA 0A
00 00 00 00 10 00 0A 0A
00 00 00 00 00 10 2A 0B
00 00 00 00 00 20 8A 0B
00 00 00 00 08 00 EA 0B
00 00 CC 00 00 00 AA 0B
74 84 7C 80 00 14 CA 0D
74 84 7C 80 02 08 AA 0D
74 84 7C 80 06 00 CA 0D
74 84 7C 80 06 A0 0A 0E
74 00 00 80 00 00 6A 0F
00 0C FC 00 00 00 2A 12
74 84 7C 80 03 08 BA 15
74 84 FC 80 00 00 8A 15
74 84 00 00 00 00 6A 1A
00 00 00 00 00 01 4A 1F
00 00 FC 50 00 00 2A 21
74 00 00 68 00 00 AA 21
74 84 7C 80 09 00 0A 25
74 84 7C 80 09 90 6A 26
FC 00 00 7C 00 00 CA 2E
74 84 00 FC 00 00 CA 32
74 84 C8 FC 00 00 6A 36
74 84 7C 80 00 08 8A 3D
74 84 7C 80 04 00 EA 3D
74 84 7C 80 0C 08 7A 3D
00 84 00 48 00 00 8A 3F
74 84 7C 80 01 00 BA 45
74 84 7C 80 00 50 4A 5C
74 84 7C 80 00 60 EA 5C
74 84 7C 80 00 00 AA 5D
74 84 7C 80 00 30 0A 5D
74 84 7C 80 04 08 CA 5D
74 84 7C 80 00 90 CA 5E
74 84 7C 80 00 C0 2A 5F
74 84 7C 80 00 F0 8A 5F
FC 00 7C FC 00 00 0A 69
00 00 00 00 00 00 5A 6B
74 84 7C 80 02 50 6A 6C
74 84 7C 80 02 00 8A 6D
00 00 7C 00 00 00 8A 70
00 00 00 00 01 00 4A 73
74 84 7C 80 0F 00 6A 75
FC 00 84 00 00 00 0A 76
C8 00 00 FC 00 00 6A 7B
00 FC 00 48 00 00 EA 7E
74 84 7C 80 01 08 AA 85
74 84 7C 80 05 00 CA 85
80 FC 7C 80 08 00 4A 87
74 84 7C 80 00 01 8A 89
74 84 7C FC 00 00 2A 89
74 84 7C 80 00 40 0A 9C
74 84 7C 80 10 00 CA 9C
74 84 7C 80 00 10 EA 9D
74 84 7C 80 00 20 4A 9D
74 84 7C 80 08 00 2A 9D
00 10 FC 00 00 00 8A 9E
74 84 7C 80 00 80 8A 9E
74 84 7C 80 00 98 DA 9E
74 84 68 80 00 02 CA A0
00 00 00 00 04 00 2A AB
74 84 7C 80 02 40 2A AC
74 84 7C 80 02 70 8A AC
74 84 7C 80 0A 00 0A AD
74 00 7C 80 00 00 8A B4
74 84 7C 80 07 00 EA B5
74 84 60 80 00 03 4A BC
74 84 7C 00 04 00 CA C1
74 84 FC FC 00 00 0A C1
7C 84 7C 80 00 0C 8A C7
70 84 7C 80 00 00 8A C8
74 FC 7C FC 00 00 4A C8
00 00 00 00 00 00 6A CB
74 84 7C 80 00 04 8A CD
CC 84 00 80 00 00 EA D3
74 84 7C 80 03 00 AA D5
74 84 00 04 00 00 AA DB
74 84 00 10 00 00 CA DD
74 84 7C 80 01 00 8A E5
74 84 00 80 00 00 4A E6
00 00 EC 00 00 00 8A E9
74 84 FC 00 00 00 AA E9
00 00 FC 7C 00 00 2A EC
FC 00 00 78 00 00 0A EF
74 00 00 00 00 00 4A F3
FC 00 FC 8C 00 00 8A F7
FC 00 00 00 00 00 4A FA
00 00 00 00 02 00 4A FB
34 84 7C 80 00 64 5A FD
74 84 7C 80 00 00 8A FD
74 84 7C 80 08 08 0A FD
74 84 7C 80 0C 90 0A FE
« Last Edit: October 14, 2025, 08:04:48 pm by DavidAlfa »
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 

Offline cunningfellow

  • Regular Contributor
  • *
  • Posts: 187
  • Country: au
Re: Figuring out error detection scheme for custom protocol
« Reply #4 on: October 14, 2025, 08:09:47 pm »

mainly these cases:
Code: [Select]
00 00 00 00 00 00 5A 6B
00 00 00 00 00 00 6A CB


is that above bit correct?  If so then the checksum bytes have different output for the same input.  Maybe they also have a count of packets in them.

If it is a cheap chinese product then it could well be something dumb like vertical parity
 

Offline m.elsayedTopic starter

  • Contributor
  • Posts: 18
  • Country: eg
Re: Figuring out error detection scheme for custom protocol
« Reply #5 on: October 14, 2025, 09:04:24 pm »
The first 4 bytes look like 8-bit signed integers for the joysticks:
Code: [Select]
[74 84 7C FC] 00 00 2A 89
The last byte doesn't seem to be a checksum, it repeats for different data.
It might be other flags for the buttons, indicating timing, previous states...

I sorted the list by "checksum":
Code: [Select]
74 84 00 50 00 00 EA 03
FC 00 00 80 00 00 6A 06
00 00 00 00 00 80 4A 08
FC 00 FC 00 00 00 8A 09
00 00 00 00 00 40 CA 0A
00 00 00 00 10 00 0A 0A
00 00 00 00 00 10 2A 0B
00 00 00 00 00 20 8A 0B
00 00 00 00 08 00 EA 0B
00 00 CC 00 00 00 AA 0B
74 84 7C 80 00 14 CA 0D
74 84 7C 80 02 08 AA 0D
74 84 7C 80 06 00 CA 0D
74 84 7C 80 06 A0 0A 0E
74 00 00 80 00 00 6A 0F
00 0C FC 00 00 00 2A 12
74 84 7C 80 03 08 BA 15
74 84 FC 80 00 00 8A 15
74 84 00 00 00 00 6A 1A
00 00 00 00 00 01 4A 1F
00 00 FC 50 00 00 2A 21
74 00 00 68 00 00 AA 21
74 84 7C 80 09 00 0A 25
74 84 7C 80 09 90 6A 26
FC 00 00 7C 00 00 CA 2E
74 84 00 FC 00 00 CA 32
74 84 C8 FC 00 00 6A 36
74 84 7C 80 00 08 8A 3D
74 84 7C 80 04 00 EA 3D
74 84 7C 80 0C 08 7A 3D
00 84 00 48 00 00 8A 3F
74 84 7C 80 01 00 BA 45
74 84 7C 80 00 50 4A 5C
74 84 7C 80 00 60 EA 5C
74 84 7C 80 00 00 AA 5D
74 84 7C 80 00 30 0A 5D
74 84 7C 80 04 08 CA 5D
74 84 7C 80 00 90 CA 5E
74 84 7C 80 00 C0 2A 5F
74 84 7C 80 00 F0 8A 5F
FC 00 7C FC 00 00 0A 69
00 00 00 00 00 00 5A 6B
74 84 7C 80 02 50 6A 6C
74 84 7C 80 02 00 8A 6D
00 00 7C 00 00 00 8A 70
00 00 00 00 01 00 4A 73
74 84 7C 80 0F 00 6A 75
FC 00 84 00 00 00 0A 76
C8 00 00 FC 00 00 6A 7B
00 FC 00 48 00 00 EA 7E
74 84 7C 80 01 08 AA 85
74 84 7C 80 05 00 CA 85
80 FC 7C 80 08 00 4A 87
74 84 7C 80 00 01 8A 89
74 84 7C FC 00 00 2A 89
74 84 7C 80 00 40 0A 9C
74 84 7C 80 10 00 CA 9C
74 84 7C 80 00 10 EA 9D
74 84 7C 80 00 20 4A 9D
74 84 7C 80 08 00 2A 9D
00 10 FC 00 00 00 8A 9E
74 84 7C 80 00 80 8A 9E
74 84 7C 80 00 98 DA 9E
74 84 68 80 00 02 CA A0
00 00 00 00 04 00 2A AB
74 84 7C 80 02 40 2A AC
74 84 7C 80 02 70 8A AC
74 84 7C 80 0A 00 0A AD
74 00 7C 80 00 00 8A B4
74 84 7C 80 07 00 EA B5
74 84 60 80 00 03 4A BC
74 84 7C 00 04 00 CA C1
74 84 FC FC 00 00 0A C1
7C 84 7C 80 00 0C 8A C7
70 84 7C 80 00 00 8A C8
74 FC 7C FC 00 00 4A C8
00 00 00 00 00 00 6A CB
74 84 7C 80 00 04 8A CD
CC 84 00 80 00 00 EA D3
74 84 7C 80 03 00 AA D5
74 84 00 04 00 00 AA DB
74 84 00 10 00 00 CA DD
74 84 7C 80 01 00 8A E5
74 84 00 80 00 00 4A E6
00 00 EC 00 00 00 8A E9
74 84 FC 00 00 00 AA E9
00 00 FC 7C 00 00 2A EC
FC 00 00 78 00 00 0A EF
74 00 00 00 00 00 4A F3
FC 00 FC 8C 00 00 8A F7
FC 00 00 00 00 00 4A FA
00 00 00 00 02 00 4A FB
34 84 7C 80 00 64 5A FD
74 84 7C 80 00 00 8A FD
74 84 7C 80 08 08 0A FD
74 84 7C 80 0C 90 0A FE

I though about that as well, that maybe this is some kind of a map to indicate which group of buttons are pressed, but the last 11 bits still do not make any sense.
changing a single bit will usually change 3 bits on average --I think--

so my best guess so far is that this is probably some kind of CRC
 

Offline m.elsayedTopic starter

  • Contributor
  • Posts: 18
  • Country: eg
Re: Figuring out error detection scheme for custom protocol
« Reply #6 on: October 14, 2025, 09:11:38 pm »

mainly these cases:
Code: [Select]
00 00 00 00 00 00 5A 6B
00 00 00 00 00 00 6A CB


is that above bit correct?  If so then the checksum bytes have different output for the same input.  Maybe they also have a count of packets in them.

If it is a cheap chinese product then it could well be something dumb like vertical parity

Thanks, I will read more about vertical parity

Yes, this is correct, this is the LED(mode button)
This is the mapping for the last 2 bytes:

  uint8_t _pad0 : 4; // no idea!
  uint8_t curr_mode : 1; // LED on/off
  uint8_t _pad1 : 8; // error detection?
  uint8_t _pad2 : 3; // // error detection?
 

Offline __greg__

  • Newbie
  • Posts: 8
  • Country: pl
Re: Figuring out error detection scheme for custom protocol
« Reply #7 on: October 15, 2025, 08:55:25 am »
reveng finds:
Quote
reveng -w 8 -s 748400500000EA03 FC00008000006A06 0000000000804A08 0000000000005A6B
width=8  poly=0xcb  init=0xda  refin=true  refout=true  xorout=0x00  check=0x36  residue=0x00  name=(none)
 
The following users thanked this post: pardo-bsso, 5U4GB

Offline m.elsayedTopic starter

  • Contributor
  • Posts: 18
  • Country: eg
Re: Figuring out error detection scheme for custom protocol
« Reply #8 on: October 15, 2025, 09:20:53 am »
reveng finds:
Quote
reveng -w 8 -s 748400500000EA03 FC00008000006A06 0000000000804A08 0000000000005A6B
width=8  poly=0xcb  init=0xda  refin=true  refout=true  xorout=0x00  check=0x36  residue=0x00  name=(none)

Thank you so much, this is it!
I have tested with all the patterns I have and they all match

Of course there is a tool for this, but I haven't thought about that at all.
So thank you for letting me know that such tool exist.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

- - -
-->