Skip to content

Commit

Permalink
Xbox 360 Pass-through Authentication (#1138)
Browse files Browse the repository at this point in the history
* [ImgBot] Optimize images

*Total -- 6,536.44kb -> 6,081.92kb (6.95%)

/configs/OpenCore0/assets/Open_Core0_LED_order.png -- 81.87kb -> 34.77kb (57.53%)
/configs/OpenCore0/assets/Open_Core0_pin_mapping.png -- 79.46kb -> 34.15kb (57.02%)
/configs/OpenCore0/assets/Open_Core0_layout.png -- 80.33kb -> 34.76kb (56.73%)
/configs/OpenCore0/assets/Open_Core0_2.jpg -- 3,134.92kb -> 2,976.17kb (5.06%)
/configs/OpenCore0/assets/Open_Core0.jpg -- 3,159.87kb -> 3,002.07kb (4.99%)

Signed-off-by: ImgBotApp <ImgBotHelp@gmail.com>

* Very WIP xbox 360 auth, don't use this for any reason

* Packet size has to be 64

* Fixed a bug with descriptor strings that was causing the xbox 360 security auth to fail

* X360 Auth Working! Need to go over a lot of this code because I sync cores now, a lot of xinput changes, etc.

* Re-enabling printf to figure out what is going wrong with release

DO NOT USE THIS VERSION

* Let's revert some core dependence if that's the issue on release

* Add sync back in and move add-ons to after driver init

* Removing stdio init seems to fix haute42

* Lots of code cleaning. Core0 will always setup() before Core1() so we can remove core1 wait. Added nop to while loop just to add some CPU spice

* Updating TinyUSB to 0.17.0 release from Sept. 2024

* Getting x360 back up to working, fixing some small bugs

* One merge fix for feature data + tud auth data

* Formatting, getting ready for merge

* Last of the formatting!

---------

Signed-off-by: ImgBotApp <ImgBotHelp@gmail.com>
Co-authored-by: ImgBotApp <ImgBotHelp@gmail.com>
  • Loading branch information
arntsonl and ImgBotApp authored Sep 24, 2024
1 parent fd18b3c commit 6a7dc59
Show file tree
Hide file tree
Showing 18 changed files with 815 additions and 199 deletions.
6 changes: 3 additions & 3 deletions headers/drivers/shared/driverhelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

static uint16_t * getStringDescriptor(const char * value, uint8_t index)
{
static uint16_t descriptorStringBuffer[32]; // Max 64 bytes, 31 unicode characters
static uint16_t descriptorStringBuffer[128]; // Max 256 bytes, 127 unicode characters
size_t charCount;
if ( index == 0 ) // language always has a character count of 1
charCount = 1;
else {
charCount = strlen(value);
if (charCount > 31)
charCount = 31;
if (charCount > 127)
charCount = 127;
}
// Fill descriptionStringBuffer[1] .. [32]
for (uint8_t i = 0; i < charCount; i++)
Expand Down
58 changes: 51 additions & 7 deletions headers/drivers/xinput/XInputAuth.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,68 @@
typedef enum {
auth_idle_state = 0,
send_auth_console_to_dongle = 1,
send_auth_dongle_to_console = 2,
wait_auth_console_to_dongle = 3,
wait_auth_dongle_to_console = 4,
send_auth_dongle_to_console = 2
} XInputAuthState;

typedef struct {
XInputAuthState xboneState;
class XInputAuthBuffer {
public:
XInputAuthBuffer() {
data = nullptr;
length = 0;
}
~XInputAuthBuffer(){
if ( data != nullptr ) {
delete [] data;
}
}

void setBuffer(uint8_t * inData, uint16_t inLen) {
data = new uint8_t[inLen];
length = inLen;
memcpy(data, inData, inLen);
}

void reset() {
if ( data != nullptr ) {
delete [] data;
}
data = nullptr;
length = 0;
}

// Console-to-Host e.g. Xbox 360 to MagicBoots
bool authCompleted;
uint8_t * data;
uint16_t length;
};

#define X360_AUTHLEN_CONSOLE_INIT 34
#define X360_AUTHLEN_DONGLE_SERIAL 29
#define X360_AUTHLEN_DONGLE_INIT 46
#define X360_AUTHLEN_CHALLENGE 22

// We need to keep track of:
// Xbox 360 Console Auth Init 34 bytes
// Dongle Serial 29 bytes
// Console-Dongle Back and Forth 46 bytes & 22 bytes
typedef struct {
XInputAuthState xinputState;
uint8_t consoleInitialAuth[X360_AUTHLEN_CONSOLE_INIT]; // Console Init (Keep when Dongle Reboots)
uint8_t dongleSerial[X360_AUTHLEN_DONGLE_SERIAL]; // Dongle Serial
uint8_t passthruBuffer[X360_AUTHLEN_DONGLE_INIT]; // Back-and-Forth Buffer (46 or 22 bytes)
uint8_t passthruBufferLen; // Length of Passthru (do we need this?)
uint8_t passthruBufferID; // ID of vendor request
bool authCompleted = false;
bool hasInitAuth = false;
bool dongle_ready = false;
} XInputAuthData;

class XInputAuth : public GPAuthDriver {
public:
virtual void initialize();
virtual bool available();
void process();
XInputAuthData * getAuthData() { return &xinputAuthData; }
private:
XInputAuthData xinputAuthData;
};

#endif
32 changes: 29 additions & 3 deletions headers/drivers/xinput/XInputAuthUSBListener.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,48 @@
#define _XINPUTAUTHUSBLISTENER_H_

#include "usblistener.h"
#include "XInputAuth.h"
#include "usbhostmanager.h"

#include "drivers/shared/xinput_host.h"
#include "drivers/xinput/XInputDescriptors.h"

typedef enum {
DONGLE_AUTH_IDLE = 0,
DONGLE_AUTH_WAIT_STATE
} DONGLE_AUTH_STATE;

class XInputAuthUSBListener : public USBListener {
public:
virtual void setup();
virtual void mount(uint8_t dev_addr, uint8_t instance, uint8_t const* desc_report, uint16_t desc_len){}
virtual void xmount(uint8_t dev_addr, uint8_t instance, uint8_t controllerType, uint8_t subtype);
virtual void unmount(uint8_t dev_addr);
virtual void report_received(uint8_t dev_addr, uint8_t instance, uint8_t const* report, uint16_t len);
virtual void report_sent(uint8_t dev_addr, uint8_t instance, uint8_t const* report, uint16_t len){}
virtual void report_received(uint8_t dev_addr, uint8_t instance, uint8_t const* report, uint16_t len) {}
virtual void report_sent(uint8_t dev_addr, uint8_t instance, uint8_t const* report, uint16_t len) {}
virtual void set_report_complete(uint8_t dev_addr, uint8_t instance, uint8_t report_id, uint8_t report_type, uint16_t len){}
virtual void get_report_complete(uint8_t dev_addr, uint8_t instance, uint8_t report_id, uint8_t report_type, uint16_t len){}
void process();
void setAuthData(XInputAuthData *);
private:
bool xinputh_vendor_report(tusb_dir_t dir, uint8_t request, uint16_t value, uint16_t length, uint8_t * recvBuf, uintptr_t user_data);
// Helper functions for Xbox 360 Authentication
bool auth_dongle_get_serial();
bool auth_dongle_init_challenge();
bool auth_dongle_challenge_verify();
bool auth_dongle_data_reply(uint8_t replyLen);
bool auth_dongle_wait_get_state();
bool auth_dongle_keepalive();
void auth_dongle_wait(uint8_t waitID);
uint8_t xinput_dev_addr;
uint8_t xinput_instance;
bool mounted;
bool sending;
XInputAuthData * xinputAuthData;
uint32_t wait_time;
uint8_t wait_count;
uint8_t waitBuffer[64]; // wait buffer
uint8_t waitBufferID;
DONGLE_AUTH_STATE dongleAuthState;
};

#endif // _XINPUTAUTHUSBLISTENER_H_
Loading

0 comments on commit 6a7dc59

Please sign in to comment.