Skip to content

Commit

Permalink
Hub Support! (OpenStickCommunity#1070)
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 <[email protected]>

* Initial hub support test

* Getting closer to magic-x support

* Another attempt, add a conditional so we don't try to double-mount the ps4 dongle

---------

Signed-off-by: ImgBotApp <[email protected]>
Co-authored-by: ImgBotApp <[email protected]>
  • Loading branch information
arntsonl and ImgBotApp authored Jun 19, 2024
1 parent 93974ac commit f1ea2f2
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 4 deletions.
3 changes: 3 additions & 0 deletions headers/addons/keyboard_host_listener.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ class KeyboardHostListener : public USBListener {
KeyboardButtonMapping _keyboard_host_mapButtonR3;
KeyboardButtonMapping _keyboard_host_mapButtonA1;
KeyboardButtonMapping _keyboard_host_mapButtonA2;

uint8_t _keyboard_dev_addr;
uint8_t _keyboard_instance;
};

#endif // _KeyboardHost_H_
1 change: 1 addition & 0 deletions headers/drivers/ps4/PS4AuthUSBListener.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class PS4AuthUSBListener : public USBListener {
bool awaiting_cb;
bool ps4_auth_host_ready;
uint8_t * ps4_auth_buffer;
bool ps_mounted;
};

#endif // _PS4AUTHUSBLISTENER_H_
22 changes: 19 additions & 3 deletions src/addons/keyboard_host_listener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ void KeyboardHostListener::setup() {
_keyboard_host_mapButtonA2.setKey(keyboardMapping.keyButtonA2);

_keyboard_host_enabled = false;
_keyboard_dev_addr = 0;
_keyboard_instance = 0;
}

void KeyboardHostListener::process() {
Expand All @@ -62,15 +64,29 @@ void KeyboardHostListener::process() {
}

void KeyboardHostListener::mount(uint8_t dev_addr, uint8_t instance, uint8_t const* desc_report, uint16_t desc_len) {
_keyboard_host_enabled = true;
// Interface protocol (hid_interface_protocol_enum_t)
uint8_t const itf_protocol = tuh_hid_interface_protocol(dev_addr, instance);

// tuh_hid_report_received_cb() will be invoked when report is available
if (itf_protocol != HID_ITF_PROTOCOL_KEYBOARD)
return;

_keyboard_dev_addr = dev_addr;
_keyboard_instance = instance;
_keyboard_host_enabled = true;
}

void KeyboardHostListener::unmount(uint8_t dev_addr) {
_keyboard_host_enabled = false;
if ( _keyboard_dev_addr == dev_addr ) {
_keyboard_host_enabled = false;
_keyboard_dev_addr = 0;
_keyboard_instance = 0;
}
}

void KeyboardHostListener::report_received(uint8_t dev_addr, uint8_t instance, uint8_t const* report, uint16_t len){
if ( _keyboard_host_enabled == false )
if ( _keyboard_host_enabled == false ||
_keyboard_dev_addr != dev_addr || _keyboard_instance != instance )
return; // do nothing if we haven't mounted

// Interface protocol (hid_interface_protocol_enum_t)
Expand Down
34 changes: 34 additions & 0 deletions src/drivers/ps4/PS4AuthUSBListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ void PS4AuthUSBListener::setup() {
passthrough_state = PS4State::no_nonce;
ps4_auth_host_ready = false;
ps4_auth_buffer = nullptr;
ps_dev_addr = 0xFF;
ps_instance = 0xFF;
ps_mounted = false;
}

void PS4AuthUSBListener::process(PS4State pState, uint8_t pNonceId, uint8_t * pNonceBuffer) {
Expand Down Expand Up @@ -92,8 +95,27 @@ bool PS4AuthUSBListener::host_set_report(uint8_t report_id, void* report, uint16
}

void PS4AuthUSBListener::mount(uint8_t dev_addr, uint8_t instance, uint8_t const* desc_report, uint16_t desc_len) {
// Prevent Magic-X double mount
if ( ps_mounted == true )
return;

// Only a PS4 interface has vendor IDs F0, F1, F2, and F3
tuh_hid_report_info_t report_info[4];
uint8_t report_count = tuh_hid_parse_report_descriptor(report_info, 4, desc_report, desc_len);
bool ps4Dongle = false;
for(uint8_t i = 0; i < report_count; i++) {
if ( report_info[i].usage_page == 0xFFF0 &&
(report_info[i].report_id == 0xF3) ) {
ps4Dongle = true;
break;
}
}
if (ps4Dongle == false )
return;

ps_dev_addr = dev_addr;
ps_instance = instance;
ps_mounted = true;

// Reset as soon as its connected
memset(report_buffer, 0, sizeof(report_buffer));
Expand All @@ -102,14 +124,23 @@ void PS4AuthUSBListener::mount(uint8_t dev_addr, uint8_t instance, uint8_t const
}

void PS4AuthUSBListener::unmount(uint8_t dev_addr) {
if ( ps_mounted == false || dev_addr != ps_dev_addr )
return;

nonce_page = 0; // no nonce yet
send_nonce_part = 0; // which part of the nonce are we getting from send?
awaiting_cb = false; // did we receive the sign state yet
passthrough_state = PS4State::no_nonce;
ps4_auth_host_ready = false;
ps_dev_addr = 0xFF;
ps_instance = 0xFF;
ps_mounted = false;
}

void PS4AuthUSBListener::set_report_complete(uint8_t dev_addr, uint8_t instance, uint8_t report_id, uint8_t report_type, uint16_t len) {
if ( ps_mounted == false || dev_addr != ps_dev_addr || instance != ps_instance )
return;

switch(report_id) {
case PS4AuthReport::PS4_SET_AUTH_PAYLOAD:
if (nonce_page == 5) {
Expand All @@ -124,6 +155,9 @@ void PS4AuthUSBListener::set_report_complete(uint8_t dev_addr, uint8_t instance,
}

void PS4AuthUSBListener::get_report_complete(uint8_t dev_addr, uint8_t instance, uint8_t report_id, uint8_t report_type, uint16_t len) {
if ( ps_mounted == false || dev_addr != ps_dev_addr || instance != ps_instance )
return;

switch(report_id) {
case PS4AuthReport::PS4_DEFINITION:
break;
Expand Down
4 changes: 3 additions & 1 deletion src/drivers/xbone/XBOneAuthUSBListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ static uint32_t lastReportQueue = 0;

void XBOneAuthUSBListener::setup() {
xboxOneAuthData = nullptr;
xbone_dev_addr = 0;
xbone_instance = 0;
}

void XBOneAuthUSBListener::setAuthData(XboxOneAuthData * authData ) {
Expand Down Expand Up @@ -88,7 +90,7 @@ void XBOneAuthUSBListener::unmount(uint8_t dev_addr) {
}

void XBOneAuthUSBListener::report_received(uint8_t dev_addr, uint8_t instance, uint8_t const* report, uint16_t len) {
if ( mounted == false || xboxOneAuthData == nullptr || dev_addr != xbone_dev_addr) {
if ( mounted == false || xboxOneAuthData == nullptr || dev_addr != xbone_dev_addr || instance != xbone_instance ) {
return;
}

Expand Down

0 comments on commit f1ea2f2

Please sign in to comment.