[go: nahoru, domu]

Skip to content

Commit

Permalink
Major code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
GaryOderNichts committed Jan 1, 2023
1 parent 8c8b420 commit ac02b4f
Show file tree
Hide file tree
Showing 27 changed files with 782 additions and 607 deletions.
3 changes: 3 additions & 0 deletions pair_menu/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
#include <whb/log.h>
#include <whb/log_console.h>

// Info about the reports can be found here:
// - <https://github.com/torvalds/linux/blob/master/drivers/hid/hid-sony.c>

#define DS3_VID 0x054c
#define DS3_PID 0x0268

Expand Down
48 changes: 31 additions & 17 deletions source/ios_kernel/source/pad.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,22 +80,36 @@ void run_ios_pad_patches(void)
*(volatile uint32_t *) 0x11f0274c = ARM_BL(0x11f0274c, btrm_receive_message_hook);

#ifdef MORE_LOGS
// Set bta_sys_cfg.trace_level to BT_TRACE_LEVEL_DEBUG
*(volatile uint8_t *) 0x11fca8d4 = 5;

// Set appl_trace_level to BT_TRACE_LEVEL_DEBUG
*(volatile uint8_t *) 0x120fd085 = 5;

// Set btm_cb.trace_level to BT_TRACE_LEVEL_DEBUG
*(volatile uint8_t *) 0x12150f88 = 5;

// Set hh_cb.trace_level to BT_TRACE_LEVEL_DEBUG
*(volatile uint8_t *) 0x12151475 = 5;

// Set l2cb.l2cap_trace_level to BT_TRACE_LEVEL_DEBUG
*(volatile uint8_t *) 0x12151478 = 5;

// Set sdp_cb.trace_level to BT_TRACE_LEVEL_DEBUG
*(volatile uint8_t *) 0x12155454 = 5;
/******************************************************************************
**
** Trace Levels
**
** The following values may be used for different levels:
** BT_TRACE_LEVEL_NONE 0 * No trace messages to be generated
** BT_TRACE_LEVEL_ERROR 1 * Error condition trace messages
** BT_TRACE_LEVEL_WARNING 2 * Warning condition trace messages
** BT_TRACE_LEVEL_API 3 * API traces
** BT_TRACE_LEVEL_EVENT 4 * Debug messages for events
** BT_TRACE_LEVEL_DEBUG 5 * Debug messages (general)
******************************************************************************/
#define TRACE_LEVEL 5

// bta_sys_cfg.trace_level
*(volatile uint8_t *) 0x11fca8d4 = TRACE_LEVEL;

// appl_trace_level
*(volatile uint8_t *) 0x120fd085 = TRACE_LEVEL;

// btm_cb.trace_level
*(volatile uint8_t *) 0x12150f88 = TRACE_LEVEL;

// hh_cb.trace_level
*(volatile uint8_t *) 0x12151475 = TRACE_LEVEL;

// l2cb.l2cap_trace_level
*(volatile uint8_t *) 0x12151478 = TRACE_LEVEL;

// sdp_cb.trace_level
*(volatile uint8_t *) 0x12155454 = TRACE_LEVEL;
#endif
}
5 changes: 4 additions & 1 deletion source/ios_pad/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ endif
ASFLAGS := $(MACHDEP)

LDFLAGS := -nostartfiles -nodefaultlibs -mbig-endian \
-Wl,-L $(TOPDIR) -Wl,-Map,$(notdir $*.map),-T $(TOPDIR)/link.ld
-Wl,-L $(TOPDIR) \
-Wl,-Map,$(notdir $*.map) \
-Wl,-T $(TOPDIR)/link.ld \
-Wl,--no-warn-rwx-segments

LIBS := -lgcc

Expand Down
2 changes: 2 additions & 0 deletions source/ios_pad/imports.ld
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ PROVIDE(memcpy = 0x11f833ec);
PROVIDE(memset = 0x11f83488);
PROVIDE(memcmp = 0x11f83304);
PROVIDE(strncmp = 0x11f83edc);
PROVIDE(strnlen = 0x11f83f60);
PROVIDE(strncpy = 0x11f83e80);
PROVIDE(vsnprintf = 0x11f83e04);

Expand Down Expand Up @@ -55,6 +56,7 @@ PROVIDE(smdIopReceive = 0x11f7e154);
PROVIDE(btm_remove_acl = 0x11f09b58);
PROVIDE(deleteDevice = 0x11f04ec8);
PROVIDE(registerNewDevice = 0x11f41370);
PROVIDE(bdaddr_to_string = 0x11f40150);

PROVIDE(bta_hh_sm_execute = 0x11f07a88);
PROVIDE(bta_hh_start_sdp = 0x11f06d5c);
Expand Down
9 changes: 7 additions & 2 deletions source/ios_pad/link.ld
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ OUTPUT_ARCH(arm)
INCLUDE "imports.ld"

SECTIONS {
. = 0x11F86000;
. = 0x11f86000;

.text : {
_text_start = .;
*(.text*);
*(.rodata*);
*(.data*);
}
_text_end = .;

/* the kernel will copy the crypto tables here */
.crypto : {
Expand All @@ -20,14 +19,20 @@ SECTIONS {
PROVIDE(__sboxes = .);
. += 0x900;
}
_text_end = .;

. = 0x12159000;

.bss : {
_bss_start = .;
*(.bss*);
}
_bss_end = .;

/DISCARD/ : {
*(*);
}
}

ASSERT(_text_end < 0x11fc0000, "ios_pad text is too big");
ASSERT(_bss_end < 0x12300000, "ios_pad bss is too big");
8 changes: 8 additions & 0 deletions source/ios_pad/source/bt_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,19 @@ typedef struct
tBTA_DM_INQ_COND filter_cond; /* Filter condition data. */
} tBTA_DM_INQ;

/* minor device class field for Peripheral Major Class */
#define BTM_COD_MINOR_GAMEPAD 0x08

/***************************
** major device class field
****************************/
#define BTM_COD_MAJOR_PERIPHERAL 0x05

/* the COD masks */
#define BTM_COD_FORMAT_TYPE_MASK 0x03
#define BTM_COD_MINOR_CLASS_MASK 0xFC
#define BTM_COD_MAJOR_CLASS_MASK 0x1F

/* Search callback events */
#define BTA_DM_INQ_RES_EVT 0 /* Inquiry result for a peer device. */
#define BTA_DM_INQ_CMPL_EVT 1 /* Inquiry complete. */
Expand Down
9 changes: 7 additions & 2 deletions source/ios_pad/source/bta/bta_hh.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ void bta_hh_event(uint8_t event, void *p_data)
tBTA_HH_CONN* conn_data = (tBTA_HH_CONN*) p_data;
DEBUG("open event for handle %u\n", conn_data->handle);

// initialize the controller
if (conn_data->handle != BTA_HH_INVALID_HANDLE) {
if (initController(conn_data->bda, conn_data->handle) != 0) {
// close connection
// close connection on failure
BTA_HhClose(conn_data->handle);
return;
}
Expand All @@ -44,8 +45,9 @@ void bta_hh_event(uint8_t event, void *p_data)
tBTA_HH_CBDATA* cb_data = (tBTA_HH_CBDATA*) p_data;
DEBUG("close event handle %u status %x\n", cb_data->handle, cb_data->status);

// deinit the controller if it was initialized
if (cb_data->handle != BTA_HH_INVALID_HANDLE) {
Controller_t* controller = &controllers[cb_data->handle];
Controller* controller = &controllers[cb_data->handle];
if (!controller->isInitialized) {
break;
}
Expand All @@ -58,6 +60,7 @@ void bta_hh_event(uint8_t event, void *p_data)
}
break;
}
// TODO can this be removed?
case BTA_HH_VC_UNPLUG_EVT: {
tBTA_HH_CBDATA* cb_data = (tBTA_HH_CBDATA*) p_data;
DEBUG("vc unplug %u\n", cb_data->handle);
Expand All @@ -80,6 +83,7 @@ void bta_hh_api_disable(void)
{
DEBUG("bta_hh_api_disable\n");

// deinitialize all controllers
for (int i = 0; i < BTA_HH_MAX_KNOWN; i++) {
if (controllers[i].isInitialized) {
if (controllers[i].deinit) {
Expand All @@ -89,6 +93,7 @@ void bta_hh_api_disable(void)
}
}

// stop report thread
deinitReportThread();

real_bta_hh_api_disable();
Expand Down
24 changes: 9 additions & 15 deletions source/ios_pad/source/bta/bta_hh_sdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ void name_read_cback(tBTM_REMOTE_DEV_NAME* name)
if (retry++ < 4) {
// retry until we succeed
BTM_ReadRemoteDeviceName(bta_hh_cb->p_cur->addr, name_read_cback);
}
else {
} else {
retry = 0;
utl_freebuf((void **)&bta_hh_cb->p_disc_db);
uint8_t status = 7;
Expand All @@ -45,18 +44,16 @@ void name_read_cback(tBTM_REMOTE_DEV_NAME* name)

retry = 0;

StoredInfo_t* info = store_get_device_info(bta_hh_cb->p_cur->addr);
StoredInfo* info = store_get_device_info(bta_hh_cb->p_cur->addr);
if (!info) {
info = store_allocate_device_info(bta_hh_cb->p_cur->addr);
}

if (isOfficialName((const char*) name->remote_bd_name)) {
info->magic = MAGIC_OFFICIAL;
}
else if (isSwitchControllerName((const char*) name->remote_bd_name)) {
} else if (isSwitchControllerName((const char*) name->remote_bd_name)) {
info->magic = MAGIC_SWITCH;
}
else {
} else {
info->magic = MAGIC_BLOOPAIR;
}

Expand All @@ -80,8 +77,7 @@ void bta_hh_di_sdp_callback(uint16_t result)
if (retry++ < 4) {
// retry until we succeed
SDP_DiDiscover(bta_hh_cb->p_cur->addr, bta_hh_cb->p_disc_db, sdp_db_size, bta_hh_di_sdp_callback);
}
else {
} else {
retry = 0;
utl_freebuf((void **)&bta_hh_cb->p_disc_db);
/* send SDP_CMPL_EVT into state machine */
Expand All @@ -105,15 +101,14 @@ void name_read_cback_open(tBTM_REMOTE_DEV_NAME* name)
DEBUG("open: got name %s status %d\n", name->remote_bd_name, name->status);

if (name->status == 0) {
StoredInfo_t* info = store_get_device_info(bta_hh_cb->p_cur->addr);
StoredInfo* info = store_get_device_info(bta_hh_cb->p_cur->addr);
if (!info) {
info = store_allocate_device_info(bta_hh_cb->p_cur->addr);
}

if (isOfficialName((const char*) name->remote_bd_name)) {
info->magic = MAGIC_OFFICIAL;
}
else {
} else {
info->magic = MAGIC_BLOOPAIR;
}
}
Expand All @@ -132,14 +127,13 @@ void bta_hh_open_act(tBTA_HH_DEV_CB *p_cb, void *p_data)

/* SDP has been done */
if (p_cb->app_id != 0) {
StoredInfo_t* info = store_get_device_info(p_cb->addr);
StoredInfo* info = store_get_device_info(p_cb->addr);

// controllers paired without bloopair running have an unknown entry in the store
if (info && info->magic == MAGIC_UNKNOWN) {
bta_hh_cb->p_cur = p_cb;
BTM_ReadRemoteDeviceName(p_cb->addr, name_read_cback_open);
}
else {
} else {
bta_hh_sm_execute(p_cb, BTA_HH_OPEN_CMPL_EVT, p_data);
}
}
Expand Down
8 changes: 5 additions & 3 deletions source/ios_pad/source/bta/bta_search.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,14 @@ void BTA_DmSearch_hook(tBTA_DM_INQ *p_dm_inq, uint32_t services, void *p_cback)

p_dm_inq->duration = 10;

// only search for peripherals (could probably filter this even further to only search for gamepads)
// only search for gamepad peripherals
p_dm_inq->filter_type = BTM_FILTER_COND_DEVICE_CLASS;
p_dm_inq->filter_cond.dev_class_cond.dev_class_mask[0] = 0;
p_dm_inq->filter_cond.dev_class_cond.dev_class_mask[1] = 0x1f;
p_dm_inq->filter_cond.dev_class_cond.dev_class_mask[2] = 0;
p_dm_inq->filter_cond.dev_class_cond.dev_class_mask[1] = BTM_COD_MAJOR_CLASS_MASK;
p_dm_inq->filter_cond.dev_class_cond.dev_class_mask[2] = BTM_COD_MINOR_CLASS_MASK;
p_dm_inq->filter_cond.dev_class_cond.dev_class[0] = 0;
p_dm_inq->filter_cond.dev_class_cond.dev_class[1] = BTM_COD_MAJOR_PERIPHERAL;
p_dm_inq->filter_cond.dev_class_cond.dev_class[2] = BTM_COD_MINOR_GAMEPAD;

real_BTA_DmSearch(p_dm_inq, services, p_cback);
}
Loading

0 comments on commit ac02b4f

Please sign in to comment.