Search code examples
cbluetoothdriverubuntu-14.04wiimote

C code to extract pairing code from wiimote, strange result


I was helping someone over at Ask Ubuntu with , what should of been a simple issue of connecting a Wiimote to Ubuntu, however we ran in to a bug in the driver.

The driver would request a bluetooth pairing code for the device, the user did not have one.

The user found a post on wiibrew explaining how to extract the code with a bit of C code.

They gave

char pin[6];
pin[0] = 0x6D;
pin[1] = 0x7E;
pin[2] = 0x3B;
pin[3] = 0x35;
pin[4] = 0x1E;
pin[5] = 0x00; 

So. the user made what they thought was a valid C file

#include <stdio.h> 

int main(void) 

{
 char pin[6]; 
 pin[0] = 0x41; 
 pin[1] = 0x7D; 
 pin[2] = 0x5D;  
 pin[3] = 0x8A;
 pin[4] = 0xD2;
 pin[5] = 0x40; 

 printf("the password is:\n"); printf("%s \n", pin ); 

}

The code compiles fine, no errors, however it should produce a 6 number passcode but just displays what looks like nonsense characters,

 A}]��@

As I am not a programmer, I don't understand what is wrong with this output, why did it give this result and how can we get the actual pairing code using this ?


Solution

  • It is printing fine 0x8A and 0xD2 are not valid ASCII characters. Ascii uses Hex values 0x00-0x7F.

    See here