Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add DONGLEMAN module #537

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions iop/kernel/include/secrman.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ extern void SecrSetMcCommandHandler(McCommandHandler_t handler);
extern void SecrSetMcDevIDHandler(McDevIDHandler_t handler);

extern int SecrAuthCard(int port, int slot, int cnum);
extern int SecrAuthDongle(int port, int slot, int cnum);
extern void SecrResetAuthCard(int port, int slot, int cnum);

#define secrman_IMPORTS_start DECLARE_IMPORT_TABLE(secrman, 1, 3)
Expand All @@ -57,6 +58,9 @@ extern void SecrResetAuthCard(int port, int slot, int cnum);
#define I_SecrDownloadGetKc DECLARE_IMPORT(18, SecrDownloadGetKc)
#define I_SecrDownloadGetICVPS2 DECLARE_IMPORT(19, SecrDownloadGetICVPS2)

/* FOLLOWING EXPORTS ARE ONLY AVAILABLE IN ARCADE SECRMAN */
#define I_SecrAuthDongle DECLARE_IMPORT(20, SecrAuthDongle)

#ifdef __cplusplus
}
#endif
Expand Down
11 changes: 11 additions & 0 deletions iop/memorycard/mcman/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,19 @@ MCMAN_BUILDING_XFROMMAN ?= 0
# Read from a file on the filesystem insead of the memory card?
MCMAN_BUILDING_VMCMAN ?= 0

# support for COH-H10020
MCMAN_BUILDING_DONGLEMAN ?= 0

ifneq (x$(MCMAN_BUILDING_XMCMAN),x0)
IOP_CFLAGS += -DBUILDING_XMCMAN

ifneq (x$(MCMAN_BUILDING_DONGLEMAN),x0)#because DONGLEMAN is based on XMCMAN
IOP_CFLAGS += -DBUILDING_DONGLEMAN

ifneq (x$(DONGLEMAN_USE_SEMAPHORE),x0)#use semaphores to avoid issues with rom0:DAEMON
IOP_CFLAGS += -DDONGLEMAN_USE_SEMAPHORE
endif
endif
endif

ifneq (x$(MCMAN_BUILDING_XFROMMAN),x0)
Expand Down
4 changes: 4 additions & 0 deletions iop/memorycard/mcman/src/exports.tab
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ DECLARE_EXPORT_TABLE(mcman, 1, 1)
DECLARE_EXPORT(_dummy)
DECLARE_EXPORT(_dummy)
#endif
#if defined(BUILDING_DONGLEMAN)
DECLARE_EXPORT(mcman_export_26)
#else
DECLARE_EXPORT(_dummy)
#endif
DECLARE_EXPORT(_dummy)
DECLARE_EXPORT(_dummy)
DECLARE_EXPORT(McReadPS1PDACard)
Expand Down
6 changes: 6 additions & 0 deletions iop/memorycard/mcman/src/imports.lst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ sior_IMPORTS_end
#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
#ifndef BUILDING_XFROMMAN
#ifdef BUILDING_XMCMAN
#ifdef BUILDING_DONGLEMAN
I_sio2_mtap_get_slot_max2
#endif
#ifndef SIO2MAN_V2
xsio2man_IMPORTS_start
#else
Expand Down Expand Up @@ -105,6 +108,9 @@ I_SecrSetMcCommandHandler
I_SecrSetMcDevIDHandler
I_SecrAuthCard
secrman_IMPORTS_end
#ifdef BUILDING_DONGLEMAN
I_SecrAuthDongle
#endif
#endif

cdvdman_IMPORTS_start
Expand Down
37 changes: 31 additions & 6 deletions iop/memorycard/mcman/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@
// CRC32: EC5F33F9
// Note: currently is based on the last XMCMAN from BOOTROM:
// 0x02,0x0a (looks like mistake, cause last XMCMAN is 0x02,0x09)
IRX_ID(MODNAME, 2, 11);

#define MAJOR 2
#if !defined(BUILDING_DONGLEMAN) //dongleman version is 0x204
#define MINOR 11
#else
#define MINOR 4
#endif

IRX_ID(MODNAME, MAJOR, MINOR);

char SUPERBLOCK_MAGIC[] = "Sony PS2 Memory Card Format ";
char SUPERBLOCK_VERSION[] = "1.2.0.0";
Expand Down Expand Up @@ -400,6 +408,14 @@ int McCloseAll(void) // Export #25 XMCMAN only
return rv;
}

//--------------------------------------------------------------
#if defined(BUILDING_DONGLEMAN)
void mcman_export_26(u32 port) { //El_isra: i'm not sure if this appears on other MCMAN's, but I found this implementation on DONGLEMAN from BR3
sio2_mtap_get_slot_max2((port & 1) | 2); //export 59 of XSIO2MAN?
return;
}
#endif

//--------------------------------------------------------------
int McDetectCard(int port, int slot) // Export #5
{
Expand All @@ -415,7 +431,6 @@ int mcman_detectcard(int port, int slot)
{
register int r;
register MCDevInfo *mcdi;

DPRINTF("mcman_detectcard port%d slot%d\n", port, slot);
mcdi = (MCDevInfo *)&mcman_devinfos[port][slot];

Expand Down Expand Up @@ -462,10 +477,12 @@ int mcman_detectcard(int port, int slot)
}
}
else {
if (PS1CardFlag)
if (PS1CardFlag) {
return sceMcResSucceed;
if (mcdi->cardtype == sceMcTypePS1)
}
if (mcdi->cardtype == sceMcTypePS1) {
return sceMcResDeniedPS1Permit;
}
return sceMcResSucceed;
}
}
Expand All @@ -481,7 +498,6 @@ int mcman_detectcard(int port, int slot)
mcdi->cardform = 0;
mcman_invhandles(port, slot);
mcman_clearcache(port, slot);

return r;
}

Expand Down Expand Up @@ -1109,7 +1125,11 @@ int McEraseBlock(int port, int block, void **pagebuf, void *eccbuf) // Export #1
//--------------------------------------------------------------
int McEraseBlock2(int port, int slot, int block, void **pagebuf, void *eccbuf) // Export #17 in XMCMAN
{
return mcman_eraseblock(port, slot, block, (void **)pagebuf, eccbuf);
int x;
DONGLEMAN_WAIT_SEMA();
x = mcman_eraseblock(port, slot, block, (void **)pagebuf, eccbuf);
DONGLEMAN_SIGN_SEMA();
return x;
}

//--------------------------------------------------------------
Expand Down Expand Up @@ -1199,7 +1219,12 @@ void McDataChecksum(void *buf, void *ecc) // Export #20
//--------------------------------------------------------------
int mcman_getcnum(int port, int slot)
{
#if defined(BUILDING_DONGLEMAN)
DPRINTF("%s: port %d slot %d original ret would be 0x%x\n", __FUNCTION__, port, slot, (((port & 1) << 3) + slot))
return 0xf;
#else
return ((port & 1) << 3) + slot;
#endif
}

//--------------------------------------------------------------
Expand Down
14 changes: 13 additions & 1 deletion iop/memorycard/mcman/src/mcman-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,14 @@
#endif
#endif

#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN) && !defined(BUILDING_DONGLEMAN)
#define MODNAME "mcman_cex"
#elif defined(BUILDING_VMCMAN)
#define MODNAME "vmcman"
#elif defined(BUILDING_XFROMMAN)
#define MODNAME "xfromman"
#elif defined(BUILDING_DONGLEMAN)
#define MODNAME "dongleman"
#endif
#define MODVER 0x20b

Expand Down Expand Up @@ -360,4 +362,14 @@ extern u8 mcman_eccdata[512]; // size for 32 ecc
// Defined in mcsio2.c
extern u8 mcman_sio2outbufs_PS1PDA[0x90];

#if defined(BUILDING_DONGLEMAN) && defined(DONGLEMAN_USE_SEMAPHORE)
/// probably they added this to avoid `rom0:DAEMON` from accessing the card at the same time than something else
extern int sema_hakama;
#define DONGLEMAN_WAIT_SEMA() WaitSema(sema_hakama)
#define DONGLEMAN_SIGN_SEMA() SignalSema(sema_hakama)
#else
#define DONGLEMAN_WAIT_SEMA()
#define DONGLEMAN_SIGN_SEMA()
#endif

#endif // __MCMAN_INTERNAL_H__
Loading
Loading