diff --git a/iop/kernel/include/secrman.h b/iop/kernel/include/secrman.h index de3ec4a9baf..25855c1941e 100644 --- a/iop/kernel/include/secrman.h +++ b/iop/kernel/include/secrman.h @@ -32,8 +32,8 @@ 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) #define secrman_IMPORTS_end END_IMPORT_TABLE diff --git a/iop/memorycard/dongleman/Makefile b/iop/memorycard/dongleman/Makefile new file mode 100644 index 00000000000..baf016d7dbe --- /dev/null +++ b/iop/memorycard/dongleman/Makefile @@ -0,0 +1,18 @@ +# _____ ___ ____ ___ ____ +# ____| | ____| | | |____| +# | ___| |____ ___| ____| | \ PS2DEV Open Source Project. +#----------------------------------------------------------------------- +# Copyright 2001-2004, ps2dev - http://www.ps2dev.org +# Licenced under Academic Free License version 2.0 +# Review ps2sdk README & LICENSE files for further details. + +IOP_PARENT_DIR = $(PS2SDKSRC)/iop/memorycard/mcman +IOP_SRC_DIR = $(IOP_PARENT_DIR)/src/ +IOP_INC_DIR = $(IOP_PARENT_DIR)/include/ + +IOP_BIN ?= dongleman.irx + +MCMAN_BUILDING_DONGLEMAN ?= 1 +MCMAN_BUILDING_XMCMAN ?= 1 + +include $(IOP_PARENT_DIR)/Makefile diff --git a/iop/memorycard/mcman/Makefile b/iop/memorycard/mcman/Makefile index f647354feb2..9339842270c 100644 --- a/iop/memorycard/mcman/Makefile +++ b/iop/memorycard/mcman/Makefile @@ -29,9 +29,17 @@ 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 endif +endif + ifneq (x$(MCMAN_BUILDING_XFROMMAN),x0) IOP_CFLAGS += -DBUILDING_XFROMMAN diff --git a/iop/memorycard/mcman/src/exports.tab b/iop/memorycard/mcman/src/exports.tab index a4b98ef3132..7c5358188a9 100644 --- a/iop/memorycard/mcman/src/exports.tab +++ b/iop/memorycard/mcman/src/exports.tab @@ -6,37 +6,37 @@ DECLARE_EXPORT_TABLE(mcman, 2, 3) #else DECLARE_EXPORT_TABLE(mcman, 1, 1) #endif - DECLARE_EXPORT(_start) - DECLARE_EXPORT(_dummy) - DECLARE_EXPORT(_dummy) - DECLARE_EXPORT(_dummy) - DECLARE_EXPORT(_start) - DECLARE_EXPORT(McDetectCard) - DECLARE_EXPORT(McOpen) - DECLARE_EXPORT(McClose) - DECLARE_EXPORT(McRead) - DECLARE_EXPORT(McWrite) - DECLARE_EXPORT(McSeek) - DECLARE_EXPORT(McFormat) - DECLARE_EXPORT(McGetDir) - DECLARE_EXPORT(McDelete) - DECLARE_EXPORT(McFlush) - DECLARE_EXPORT(McChDir) - DECLARE_EXPORT(McSetFileInfo) + DECLARE_EXPORT(_start) //1 + DECLARE_EXPORT(_dummy) //2 + DECLARE_EXPORT(_dummy) //3 + DECLARE_EXPORT(_dummy) //4 + DECLARE_EXPORT(_start) //5 + DECLARE_EXPORT(McDetectCard) //6 + DECLARE_EXPORT(McOpen) //7 + DECLARE_EXPORT(McClose) //8 + DECLARE_EXPORT(McRead) //9 + DECLARE_EXPORT(McWrite) //10 + DECLARE_EXPORT(McSeek) //11 + DECLARE_EXPORT(McFormat) //12 + DECLARE_EXPORT(McGetDir) //13 + DECLARE_EXPORT(McDelete) //14 + DECLARE_EXPORT(McFlush) //15 + DECLARE_EXPORT(McChDir) //16 + DECLARE_EXPORT(McSetFileInfo) //17 #if defined(BUILDING_XMCMAN) - DECLARE_EXPORT(McEraseBlock2) + DECLARE_EXPORT(McEraseBlock2) //18 #else - DECLARE_EXPORT(McEraseBlock) + DECLARE_EXPORT(McEraseBlock) //18 #endif - DECLARE_EXPORT(McReadPage) - DECLARE_EXPORT(McWritePage) - DECLARE_EXPORT(McDataChecksum) + DECLARE_EXPORT(McReadPage) //19 + DECLARE_EXPORT(McWritePage) //20 + DECLARE_EXPORT(McDataChecksum) //21 #if defined(BUILDING_XMCMAN) - DECLARE_EXPORT(McDetectCard2) - DECLARE_EXPORT(McGetFormat) - DECLARE_EXPORT(McGetEntSpace) - DECLARE_EXPORT(McReplaceBadBlock) - DECLARE_EXPORT(McCloseAll) + DECLARE_EXPORT(McDetectCard2) //22 + DECLARE_EXPORT(McGetFormat) //23 + DECLARE_EXPORT(McGetEntSpace) //24 + DECLARE_EXPORT(McReplaceBadBlock) //25 + DECLARE_EXPORT(McCloseAll) //26 #else DECLARE_EXPORT(_dummy) DECLARE_EXPORT(_dummy) @@ -44,34 +44,34 @@ DECLARE_EXPORT_TABLE(mcman, 1, 1) DECLARE_EXPORT(_dummy) DECLARE_EXPORT(_dummy) #endif - DECLARE_EXPORT(_dummy) - DECLARE_EXPORT(_dummy) - DECLARE_EXPORT(_dummy) - DECLARE_EXPORT(McReadPS1PDACard) - DECLARE_EXPORT(McWritePS1PDACard) - DECLARE_EXPORT(_dummy) - DECLARE_EXPORT(_dummy) - DECLARE_EXPORT(_dummy) - DECLARE_EXPORT(_dummy) - DECLARE_EXPORT(_dummy) - DECLARE_EXPORT(McUnformat) - DECLARE_EXPORT(McRetOnly) - DECLARE_EXPORT(McGetFreeClusters) - DECLARE_EXPORT(McGetMcType) - DECLARE_EXPORT(McSetPS1CardFlag) - DECLARE_EXPORT(_dummy) + DECLARE_EXPORT(_dummy) //27 + DECLARE_EXPORT(_dummy) //28 + DECLARE_EXPORT(_dummy) //29 + DECLARE_EXPORT(McReadPS1PDACard) //30 + DECLARE_EXPORT(McWritePS1PDACard) //31 + DECLARE_EXPORT(_dummy) //32 + DECLARE_EXPORT(_dummy) //33 + DECLARE_EXPORT(_dummy) //34 + DECLARE_EXPORT(_dummy) //35 + DECLARE_EXPORT(_dummy) //36 + DECLARE_EXPORT(McUnformat) //37 + DECLARE_EXPORT(McRetOnly) //38 + DECLARE_EXPORT(McGetFreeClusters) //39 + DECLARE_EXPORT(McGetMcType) //40 + DECLARE_EXPORT(McSetPS1CardFlag) //41 + DECLARE_EXPORT(_dummy) //42 #if defined(BUILDING_XMCMAN) - DECLARE_EXPORT(McGetModuleInfo) - DECLARE_EXPORT(McGetCardSpec) - DECLARE_EXPORT(McGetFATentry) - DECLARE_EXPORT(McCheckBlock) - DECLARE_EXPORT(McSetFATentry) - DECLARE_EXPORT(McReadDirEntry) - DECLARE_EXPORT(Mc1stCacheEntSetWrFlagOff) - DECLARE_EXPORT(McCreateDirentry) - DECLARE_EXPORT(McReadCluster) - DECLARE_EXPORT(McFlushCache) - DECLARE_EXPORT(McSetDirEntryState) + DECLARE_EXPORT(McGetModuleInfo) //43 + DECLARE_EXPORT(McGetCardSpec) //44 + DECLARE_EXPORT(McGetFATentry) //45 + DECLARE_EXPORT(McCheckBlock) //46 + DECLARE_EXPORT(McSetFATentry) //47 + DECLARE_EXPORT(McReadDirEntry) //48 + DECLARE_EXPORT(Mc1stCacheEntSetWrFlagOff) //49 + DECLARE_EXPORT(McCreateDirentry) //50 + DECLARE_EXPORT(McReadCluster) //51 + DECLARE_EXPORT(McFlushCache) //52 + DECLARE_EXPORT(McSetDirEntryState) //53 #else DECLARE_EXPORT(_dummy) DECLARE_EXPORT(_dummy) @@ -85,7 +85,7 @@ DECLARE_EXPORT_TABLE(mcman, 1, 1) DECLARE_EXPORT(_dummy) DECLARE_EXPORT(_dummy) #endif - DECLARE_EXPORT(_dummy) + DECLARE_EXPORT(_dummy) //54 END_EXPORT_TABLE void _dummy() {} diff --git a/iop/memorycard/mcman/src/imports.lst b/iop/memorycard/mcman/src/imports.lst index e04cac15041..bcdcdd6c6bb 100644 --- a/iop/memorycard/mcman/src/imports.lst +++ b/iop/memorycard/mcman/src/imports.lst @@ -104,6 +104,10 @@ secrman_IMPORTS_start I_SecrSetMcCommandHandler I_SecrSetMcDevIDHandler I_SecrAuthCard +#ifdef BUILDING_DONGLEMAN +DECLARE_IMPORT(20, SecrAuthDongle) +//I_SecrAuthDongle +#endif secrman_IMPORTS_end #endif diff --git a/iop/memorycard/mcman/src/main.c b/iop/memorycard/mcman/src/main.c index a1099383ecd..18a3487be5d 100644 --- a/iop/memorycard/mcman/src/main.c +++ b/iop/memorycard/mcman/src/main.c @@ -151,6 +151,7 @@ int MCMAN_ENTRYPOINT(int argc, char *argv[]) #ifdef SIO_DEBUG sio_init(38400, 0, 0, 0, 0); #endif + DPRINTF("_start...\n"); DPRINTF("registering exports...\n"); @@ -199,14 +200,14 @@ int MCMAN_ENTRYPOINT(int argc, char *argv[]) int McGetFormat(int port, int slot) // Export #22 XMCMAN only { DPRINTF("McGetFormat port%d slot%d\n", port, slot); - return mcman_devinfos[port][slot].cardform; + return GET_MCDEVINFO(port, slot).cardform; } //-------------------------------------------------------------- int McGetMcType(int port, int slot) // Export #39 { DPRINTF("McGetMcType port%d slot%d\n", port, slot); - return mcman_devinfos[port][slot].cardtype; + return GET_MCDEVINFO(port, slot).cardtype; } #ifdef _IOP @@ -229,7 +230,7 @@ void McSetPS1CardFlag(int flag) // Export #40 int McGetFreeClusters(int port, int slot) // Export #38 { register int r, mcfree; - register MCDevInfo *mcdi = &mcman_devinfos[port][slot]; + register MCDevInfo *mcdi = &GET_MCDEVINFO(port, slot); DPRINTF("McGetFreeClusters port%d slot%d\n", port, slot); @@ -417,11 +418,14 @@ int mcman_detectcard(int port, int slot) register MCDevInfo *mcdi; DPRINTF("mcman_detectcard port%d slot%d\n", port, slot); - mcdi = (MCDevInfo *)&mcman_devinfos[port][slot]; + mcdi = (MCDevInfo *)&GET_MCDEVINFO(port, slot); #if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN) if ((mcdi->cardtype == sceMcTypeNoCard) || (mcdi->cardtype == sceMcTypePS2)) { r = mcman_probePS2Card2(port, slot); +#ifdef BUILDING_DONGLEMAN + if (r < -9) r = mcman_probeSecurityDongle(port, slot); +#endif if (r < -9) { r = mcman_probePS1Card2(port, slot); if (!(r < -9)) { @@ -445,6 +449,9 @@ int mcman_detectcard(int port, int slot) if (r) { if ((r < -9) || (r >= 0)) { r = mcman_probePS2Card2(port, slot); +#ifdef BUILDING_DONGLEMAN + if (r < -9) r = mcman_probeSecurityDongle(port, slot); +#endif if (!(r < -9)) { mcdi->cardtype = sceMcTypePS2; return r; @@ -492,18 +499,21 @@ int McDetectCard2(int port, int slot) // Export #21 XMCMAN only register MCDevInfo *mcdi; DPRINTF("McDetectCard2 port%d slot%d\n", port, slot); + mcdi = (MCDevInfo *)&GET_MCDEVINFO(port, slot); - mcdi = (MCDevInfo *)&mcman_devinfos[port][slot]; #if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN) if ((mcdi->cardtype == sceMcTypeNoCard) || (mcdi->cardtype == sceMcTypePS2)) { r = mcman_probePS2Card(port, slot); +#ifdef BUILDING_DONGLEMAN + if (r < -9) r = mcman_probeSecurityDongle(port, slot); +#endif if (r < -9) { r = mcman_probePS1Card(port, slot); if (!(r < -9)) { if (mcman_probePDACard(port, slot)) { mcdi->cardtype = sceMcTypePS1; - return (!PS1CardFlag) ? sceMcResDeniedPS1Permit : r; + return (!PS1CardFlag) ? sceMcResDeniedPS1Permit : r; // dongleman return -19 instead of sceMcResDeniedPS1Permit } else { mcdi->cardtype = sceMcTypePDA; @@ -521,6 +531,9 @@ int McDetectCard2(int port, int slot) // Export #21 XMCMAN only if (r) { if ((r < -9) || (r >= 0)) { r = mcman_probePS2Card(port, slot); +#ifdef BUILDING_DONGLEMAN + if (r < -9) r = mcman_probeSecurityDongle(port, slot); +#endif if (!(r < -9)) { mcdi->cardtype = sceMcTypePS2; return r; @@ -573,7 +586,7 @@ int McOpen(int port, int slot, const char *filename, int flag) // Export #6 if (!PS1CardFlag) flag &= ~0x00002000; // disables FRCOM flag OR what is it - if (mcman_devinfos[port][slot].cardtype == sceMcTypePS2) + if (GET_MCDEVINFO(port, slot).cardtype == sceMcTypePS2) r = mcman_open2(port, slot, filename, flag); else r = mcman_open1(port, slot, filename, flag); @@ -818,7 +831,7 @@ int McGetEntSpace(int port, int slot, const char *dirname) // Export #23 XMCMAN if (r != sceMcResSucceed) return r; - if (mcman_devinfos[port][slot].cardtype == sceMcTypePS2) { + if (GET_MCDEVINFO(port, slot).cardtype == sceMcTypePS2) { r = mcman_getentspace(port, slot, dirname); } @@ -839,7 +852,7 @@ int McGetDir(int port, int slot, const char *dirname, int flags, int maxent, sce if (r != sceMcResSucceed) return r; - if (mcman_devinfos[port][slot].cardtype == sceMcTypePS2) + if (GET_MCDEVINFO(port, slot).cardtype == sceMcTypePS2) r = mcman_getdir2(port, slot, dirname, flags & 0xFFFF, maxent, info); else r = mcman_getdir1(port, slot, dirname, flags & 0xFFFF, maxent, info); @@ -897,7 +910,7 @@ int mcman_getstat(int port, int slot, const char *filename, MC_IO_STA_T *stat) if (r != sceMcResSucceed) return r; - if (mcman_devinfos[port][slot].cardtype == sceMcTypePS2) + if (GET_MCDEVINFO(port, slot).cardtype == sceMcTypePS2) r = mcman_getstat2(port, slot, filename, stat); else r = mcman_getstat1(port, slot, filename, stat); @@ -919,7 +932,7 @@ int McSetFileInfo(int port, int slot, const char *filename, sceMcTblGetDir *info if (r != sceMcResSucceed) return r; - if (mcman_devinfos[port][slot].cardtype == sceMcTypePS2) + if (GET_MCDEVINFO(port, slot).cardtype == sceMcTypePS2) r = mcman_setinfo2(port, slot, filename, info, flags); else r = mcman_setinfo1(port, slot, filename, info, flags); @@ -949,7 +962,7 @@ int McChDir(int port, int slot, const char *newdir, char *currentdir) // Export if (r != sceMcResSucceed) return r; - if (mcman_devinfos[port][slot].cardtype == sceMcTypePS2) + if (GET_MCDEVINFO(port, slot).cardtype == sceMcTypePS2) r = mcman_chdir(port, slot, newdir, currentdir); else { currentdir[0] = 0; @@ -973,7 +986,7 @@ int McDelete(int port, int slot, const char *filename, int flags) // Export #13 if (r != sceMcResSucceed) return r; - if (mcman_devinfos[port][slot].cardtype == sceMcTypePS2) + if (GET_MCDEVINFO(port, slot).cardtype == sceMcTypePS2) r = mcman_delete2(port, slot, filename, flags); else r = mcman_delete1(port, slot, filename, flags); @@ -999,7 +1012,7 @@ int McFormat(int port, int slot) // Export #11 mcman_clearcache(port, slot); - if (mcman_devinfos[port][slot].cardtype == sceMcTypePS2) + if (GET_MCDEVINFO(port, slot).cardtype == sceMcTypePS2) r = mcman_format2(port, slot); else r = mcman_format1(port, slot); @@ -1025,12 +1038,12 @@ int McUnformat(int port, int slot) // Export #36 mcman_clearcache(port, slot); - if (mcman_devinfos[port][slot].cardtype == sceMcTypePS2) + if (GET_MCDEVINFO(port, slot).cardtype == sceMcTypePS2) r = mcman_unformat2(port, slot); else r = mcman_unformat1(port, slot); - mcman_devinfos[port][slot].cardform = 0; + GET_MCDEVINFO(port, slot).cardform = 0; if (r < -9) { mcman_invhandles(port, slot); @@ -1116,7 +1129,7 @@ int McEraseBlock2(int port, int slot, int block, void **pagebuf, void *eccbuf) / int McReadPage(int port, int slot, int page, void *buf) // Export #18 { register int r, index, ecres, retries, count, erase_byte; - register MCDevInfo *mcdi = &mcman_devinfos[port][slot]; + register MCDevInfo *mcdi = &GET_MCDEVINFO(port, slot); u8 eccbuf[32]; u8 *pdata, *peccb; @@ -1199,6 +1212,9 @@ void McDataChecksum(void *buf, void *ecc) // Export #20 //-------------------------------------------------------------- int mcman_getcnum(int port, int slot) { +#ifdef BUILDING_DONGLEMAN + if (port == 0) return 0xf; +#endif return ((port & 1) << 3) + slot; } @@ -1252,14 +1268,14 @@ int mcman_correctdata(void *buf, void *ecc) //-------------------------------------------------------------- int mcman_sparesize(int port, int slot) { // Get ps2 mc spare size by dividing pagesize / 32 - return (mcman_devinfos[port][slot].pagesize + 0x1F) >> 5; + return (GET_MCDEVINFO(port, slot).pagesize + 0x1F) >> 5; } //-------------------------------------------------------------- int mcman_setdevspec(int port, int slot) { int cardsize; - register MCDevInfo *mcdi = &mcman_devinfos[port][slot]; + register MCDevInfo *mcdi = &GET_MCDEVINFO(port, slot); DPRINTF("mcman_setdevspec port%d, slot%d\n", port, slot); @@ -1284,7 +1300,7 @@ int mcman_setdevspec(int port, int slot) int mcman_setdevinfos(int port, int slot) { register int r, allocatable_clusters_per_card, iscluster_valid, current_allocatable_cluster, cluster_cnt; - register MCDevInfo *mcdi = &mcman_devinfos[port][slot]; + register MCDevInfo *mcdi = &GET_MCDEVINFO(port, slot); McFsEntry *pfse; DPRINTF("mcman_setdevinfos port%d slot%d\n", port, slot); @@ -1379,7 +1395,7 @@ int mcman_setdevinfos(int port, int slot) int mcman_reportBadBlocks(int port, int slot) { register int bad_blocks, erase_byte, err_limit; - register MCDevInfo *mcdi = &mcman_devinfos[port][slot]; + register MCDevInfo *mcdi = &GET_MCDEVINFO(port, slot); DPRINTF("mcman_reportBadBlocks port%d, slot%d\n", port, slot); @@ -1451,7 +1467,7 @@ int McCreateDirentry(int port, int slot, int parent_cluster, int num_entries, in { register int r; McCacheEntry *mce; - register MCDevInfo *mcdi = &mcman_devinfos[port][slot]; + register MCDevInfo *mcdi = &GET_MCDEVINFO(port, slot); McFsEntry *mfe, *mfe_next, *pfse; DPRINTF("McCreateDirentry port%d slot%d parent_cluster %x num_entries %d cluster %x\n", port, slot, parent_cluster, num_entries, cluster); @@ -1640,7 +1656,7 @@ int mcman_fatWseek(int fd) // modify FAT to hold new content for a file int mcman_findfree2(int port, int slot, int reserve) { register int r, rfree, ifc_index, indirect_offset, fat_index, block; - register MCDevInfo *mcdi = &mcman_devinfos[port][slot]; + register MCDevInfo *mcdi = &GET_MCDEVINFO(port, slot); McCacheEntry *mce1, *mce2; DPRINTF("mcman_findfree2 port%d slot%d reserve%d\n", port, slot, reserve); @@ -1738,7 +1754,7 @@ int mcman_getentspace(int port, int slot, const char *dirname) int mcman_cachedirentry(int port, int slot, const char *filename, McCacheDir *pcacheDir, McFsEntry **pfse, int unknown_flag) { register int r, fsindex, cluster, fmode; - register MCDevInfo *mcdi = &mcman_devinfos[port][slot]; + register MCDevInfo *mcdi = &GET_MCDEVINFO(port, slot); McFsEntry *fse; McCacheDir cacheDir; u8 *pfsentry, *pcache, *pfseend; @@ -2011,7 +2027,7 @@ int mcman_writecluster(int port, int slot, int cluster, int flag) { register int i, block; register u32 erase_value; - register MCDevInfo *mcdi = &mcman_devinfos[port][slot]; + register MCDevInfo *mcdi = &GET_MCDEVINFO(port, slot); block = cluster / mcdi->clusters_per_block; @@ -2133,7 +2149,7 @@ int mcman_writecluster(int port, int slot, int cluster, int flag) int McSetDirEntryState(int port, int slot, int cluster, int fsindex, int flags) { register int r, i, fat_index; - register MCDevInfo *mcdi = &mcman_devinfos[port][slot]; + register MCDevInfo *mcdi = &GET_MCDEVINFO(port, slot); McFsEntry *fse; int fat_entry; @@ -2205,7 +2221,7 @@ int McSetDirEntryState(int port, int slot, int cluster, int fsindex, int flags) int mcman_checkBackupBlocks(int port, int slot) { register int r1, r2, r, eccsize; - register MCDevInfo *mcdi = &mcman_devinfos[port][slot]; + register MCDevInfo *mcdi = &GET_MCDEVINFO(port, slot); McCacheEntry *mce; u32 *pagebuf = mcman_pagebuf.word; u32 value1, value2; @@ -2280,7 +2296,7 @@ int mcman_checkBackupBlocks(int port, int slot) int McCheckBlock(int port, int slot, int block) { register int r, i, j, page, ecc_count, pageword_cnt, flag, erase_value; - register MCDevInfo *mcdi = &mcman_devinfos[port][slot]; + register MCDevInfo *mcdi = &GET_MCDEVINFO(port, slot); u8 *p_page, *p_ecc; DPRINTF("McCheckBlock port%d slot%d block 0x%x\n", port, slot, block); @@ -2340,6 +2356,10 @@ int McCheckBlock(int port, int slot, int block) if (r != sceMcResSucceed) { r = mcman_probePS2Card2(port, slot); if (r != sceMcResSucceed) +#ifdef BUILDING_DONGLEMAN + if (r != sceMcResSucceed) r = mcman_probeSecurityDongle(port, slot); +#endif + if (r != sceMcResSucceed) return -45; flag = -1; goto lbl_8764; @@ -2349,6 +2369,9 @@ int McCheckBlock(int port, int slot, int block) r = McWritePage(port, slot, page + i, &mcman_pagebuf, mcman_eccdata); if (r != sceMcResSucceed) { r = mcman_probePS2Card2(port, slot); +#ifdef BUILDING_DONGLEMAN + if (r != sceMcResSucceed) r = mcman_probeSecurityDongle(port, slot); +#endif if (r != sceMcResSucceed) return -44; flag = -1; @@ -2385,6 +2408,9 @@ int McCheckBlock(int port, int slot, int block) r = mcman_eraseblock(port, slot, block, NULL, NULL); if (r != sceMcResSucceed) { r = mcman_probePS2Card2(port, slot); +#ifdef BUILDING_DONGLEMAN + if (r != sceMcResSucceed) r = mcman_probeSecurityDongle(port, slot); +#endif if (r != sceMcResSucceed) return -42; flag = -1; @@ -2395,6 +2421,9 @@ int McCheckBlock(int port, int slot, int block) r = McWritePage(port, slot, page + i, &mcman_pagebuf, mcman_eccdata); if (r != sceMcResSucceed) { r = mcman_probePS2Card2(port, slot); +#ifdef BUILDING_DONGLEMAN + if (r != sceMcResSucceed) r = mcman_probeSecurityDongle(port, slot); +#endif if (r != sceMcResSucceed) return -46; flag = -1; @@ -2442,6 +2471,9 @@ int McCheckBlock(int port, int slot, int block) r = McWritePage(port, slot, page + i, &mcman_pagebuf, mcman_eccdata); if (r != sceMcResSucceed) { r = mcman_probePS2Card2(port, slot); +#ifdef BUILDING_DONGLEMAN + if (r != sceMcResSucceed) r = mcman_probeSecurityDongle(port, slot); +#endif if (r != sceMcResSucceed) return -48; } @@ -2454,7 +2486,7 @@ int McCheckBlock(int port, int slot, int block) int mcman_setPS1devinfos(int port, int slot) { register int r, i; - MCDevInfo *mcdi = &mcman_devinfos[port][slot]; + MCDevInfo *mcdi = &GET_MCDEVINFO(port, slot); DPRINTF("mcman_setPS1devinfos port%d slot%d\n", port, slot); @@ -3102,7 +3134,7 @@ int mcman_cachePS1dirs(int port, int slot) int mcman_fillPS1backuparea(int port, int slot, int block) { register int r, i, curpage; - register MCDevInfo *mcdi = &mcman_devinfos[port][slot]; + register MCDevInfo *mcdi = &GET_MCDEVINFO(port, slot); memset(&mcman_PS1PDApagebuf, 0, 128); @@ -3650,7 +3682,7 @@ int mcman_flushcacheentry(McCacheEntry *mce) int McReadCluster(int port, int slot, int cluster, McCacheEntry **pmce) { register int i; - register MCDevInfo *mcdi = &mcman_devinfos[port][slot]; + register MCDevInfo *mcdi = &GET_MCDEVINFO(port, slot); McCacheEntry *mce; if (mcman_badblock > 0) { @@ -3711,7 +3743,7 @@ int McReadDirEntry(int port, int slot, int cluster, int fsindex, McFsEntry **pfs { register int r, i; static int maxent, index, clust; - register MCDevInfo *mcdi = &mcman_devinfos[port][slot]; + register MCDevInfo *mcdi = &GET_MCDEVINFO(port, slot); register McFatCache *fci = &mcman_fatcache[port][slot]; McCacheEntry *mce; @@ -3771,7 +3803,7 @@ int mcman_readdirentryPS1(int port, int slot, int cluster, McFsEntryPS1 **pfse) { register int r, offset, index, pages_per_fatclust; McCacheEntry *mce; - register MCDevInfo *mcdi = &mcman_devinfos[port][slot]; + register MCDevInfo *mcdi = &GET_MCDEVINFO(port, slot); if (cluster >= 15) return -73; @@ -3801,7 +3833,7 @@ int McSetFATentry(int port, int slot, int fat_index, int fat_entry) // Export #4 { register int r, ifc_index, indirect_index, indirect_offset, fat_offset; McCacheEntry *mce; - register MCDevInfo *mcdi = &mcman_devinfos[port][slot]; + register MCDevInfo *mcdi = &GET_MCDEVINFO(port, slot); //DPRINTF("McSetFATentry port%d slot%d fat_index %x fat_entry %x\n", port, slot, fat_index, fat_entry); @@ -3834,7 +3866,7 @@ int McGetFATentry(int port, int slot, int fat_index, int *fat_entry) // Export # { register int r, ifc_index, indirect_index, indirect_offset, fat_offset; McCacheEntry *mce; - register MCDevInfo *mcdi = &mcman_devinfos[port][slot]; + register MCDevInfo *mcdi = &GET_MCDEVINFO(port, slot); indirect_index = fat_index / mcdi->FATentries_per_cluster; fat_offset = fat_index % mcdi->FATentries_per_cluster; @@ -3862,7 +3894,7 @@ int McGetFATentry(int port, int slot, int fat_index, int *fat_entry) // Export # //-------------------------------------------------------------- int mcman_readclusterPS1(int port, int slot, int cluster, McCacheEntry **pmce) { - register MCDevInfo *mcdi = &mcman_devinfos[port][slot]; + register MCDevInfo *mcdi = &GET_MCDEVINFO(port, slot); McCacheEntry *mce; mce = mcman_getcacheentry(port, slot, cluster); @@ -3900,7 +3932,7 @@ int mcman_readclusterPS1(int port, int slot, int cluster, McCacheEntry **pmce) int mcman_replaceBackupBlock(int port, int slot, int block) { register int i; - register MCDevInfo *mcdi = &mcman_devinfos[port][slot]; + register MCDevInfo *mcdi = &GET_MCDEVINFO(port, slot); if (mcman_badblock > 0) return sceMcResFailReplace; @@ -3930,7 +3962,7 @@ int mcman_replaceBackupBlock(int port, int slot, int block) int mcman_fillbackupblock1(int port, int slot, int block, void **pagedata, void *eccdata) { register int r, i, sparesize, page_offset; - register MCDevInfo *mcdi = &mcman_devinfos[port][slot]; + register MCDevInfo *mcdi = &GET_MCDEVINFO(port, slot); register u8 *p_ecc; DPRINTF("mcman_fillbackupblock1 port%d slot%d block %x mcman_badblock %x\n", port, slot, block, mcman_badblock); @@ -4291,7 +4323,7 @@ int McReplaceBadBlock(void) int mcman_clearsuperblock(int port, int slot) { register int r, i; - register MCDevInfo *mcdi = &mcman_devinfos[port][slot]; + register MCDevInfo *mcdi = &GET_MCDEVINFO(port, slot); McCacheEntry *mce; // set superblock magic & version diff --git a/iop/memorycard/mcman/src/mcdev.c b/iop/memorycard/mcman/src/mcdev.c index 0e8c5214ed9..6424275128b 100644 --- a/iop/memorycard/mcman/src/mcdev.c +++ b/iop/memorycard/mcman/src/mcdev.c @@ -109,7 +109,11 @@ static MC_IO_DEV_T mcman_mcdev = { , 1, #if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN) - "Memory Card", + "Memory Card" +#ifdef BUILDING_DONGLEMAN +" (arcade)" +#endif +, #elif defined(BUILDING_VMCMAN) "Virtual Memory Card", #elif defined(BUILDING_XFROMMAN) diff --git a/iop/memorycard/mcman/src/mcman-internal.h b/iop/memorycard/mcman/src/mcman-internal.h index 4e929cdd42a..55f30b5c472 100644 --- a/iop/memorycard/mcman/src/mcman-internal.h +++ b/iop/memorycard/mcman/src/mcman-internal.h @@ -206,6 +206,14 @@ int mcman_cardchanged(int port, int slot); int mcman_resetauth(int port, int slot); int mcman_probePS2Card2(int port, int slot); int mcman_probePS2Card(int port, int slot); + +#ifdef BUILDING_DONGLEMAN +int mcman_probeSecurityDongle(int port, int slot); +#define GET_MCDEVINFO(port, slot) mcman_devinfos[port*2][slot] +#else +#define GET_MCDEVINFO(port, slot) mcman_devinfos[port][slot] +#endif + #if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN) int secrman_mc_command(int port, int slot, sio2_transfer_data_t *sio2data); #endif diff --git a/iop/memorycard/mcman/src/mcsio2.c b/iop/memorycard/mcman/src/mcsio2.c index b7c3c325cf4..7a7b2c0b647 100644 --- a/iop/memorycard/mcman/src/mcsio2.c +++ b/iop/memorycard/mcman/src/mcsio2.c @@ -437,7 +437,7 @@ int mcman_eraseblock(int port, int slot, int block, void **pagebuf, void *eccbuf u8 *p = mcman_sio2packet.out_dma.addr; #endif void *p_ecc; - register MCDevInfo *mcdi = &mcman_devinfos[port][slot]; + register MCDevInfo *mcdi = &GET_MCDEVINFO(port, slot); page = block * mcdi->blocksize; @@ -534,7 +534,7 @@ int McWritePage(int port, int slot, int page, void *pagebuf, void *eccbuf) // Ex #endif #if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN) - count = (mcman_devinfos[port][slot].pagesize + 127) >> 7; + count = (GET_MCDEVINFO(port, slot).pagesize + 127) >> 7; #endif retries = 0; @@ -553,7 +553,7 @@ int McWritePage(int port, int slot, int page, void *pagebuf, void *eccbuf) // Ex index++; } - if (mcman_devinfos[port][slot].cardflags & CF_USE_ECC) { + if (GET_MCDEVINFO(port, slot).cardflags & CF_USE_ECC) { // if memcard have ECC support sio2packet_add(port, slot, 0x0e, eccbuf); } @@ -574,7 +574,7 @@ int McWritePage(int port, int slot, int page, void *pagebuf, void *eccbuf) // Ex if (index < count) continue; - if (mcman_devinfos[port][slot].cardflags & CF_USE_ECC) { + if (GET_MCDEVINFO(port, slot).cardflags & CF_USE_ECC) { // if memcard have ECC support index++; if (p[5 + ((index + (index << 3)) << 4) + mcman_sparesize(port, slot)] != 0x5a) @@ -615,7 +615,7 @@ int mcman_readpage(int port, int slot, int page, void *buf, void *eccbuf) { #if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN) register int index, count, retries, r, i; - register MCDevInfo *mcdi = &mcman_devinfos[port][slot]; + register MCDevInfo *mcdi = &GET_MCDEVINFO(port, slot); u8 *pbuf = (u8 *)buf; u8 *pecc = (u8 *)eccbuf; u8 *p = mcman_sio2packet.out_dma.addr; @@ -954,7 +954,7 @@ int mcman_probePS1Card2(int port, int slot) { #if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN) register int retries; - register MCDevInfo *mcdi = &mcman_devinfos[port][slot]; + register MCDevInfo *mcdi = &GET_MCDEVINFO(port, slot); DPRINTF("mcman_probePS1Card2 port%d slot%d\n", port, slot); @@ -1013,7 +1013,7 @@ int mcman_probePS1Card(int port, int slot) { #if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN) register int i, r, retries; - register MCDevInfo *mcdi = &mcman_devinfos[port][slot]; + register MCDevInfo *mcdi = &GET_MCDEVINFO(port, slot); u32 *p; DPRINTF("mcman_probePS1Card port%d slot%d\n", port, slot); @@ -1124,7 +1124,7 @@ int McWritePS1PDACard(int port, int slot, int page, void *buf) // Export #30 { #if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN) register int i, retries; - register MCDevInfo *mcdi = &mcman_devinfos[port][slot]; + register MCDevInfo *mcdi = &GET_MCDEVINFO(port, slot); u8 *p; //DPRINTF("McWritePS1PDACard port%d slot%d page %x\n", port, slot, page); @@ -1194,7 +1194,7 @@ int McReadPS1PDACard(int port, int slot, int page, void *buf) // Export #29 { #if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN) register int i, retries; - register MCDevInfo *mcdi = &mcman_devinfos[port][slot]; + register MCDevInfo *mcdi = &GET_MCDEVINFO(port, slot); u8 *p; //DPRINTF("McReadPS1PDACard port%d slot%d page %x\n", port, slot, page); @@ -1262,4 +1262,65 @@ int McReadPS1PDACard(int port, int slot, int page, void *buf) // Export #29 return sceMcResSucceed; } - +#ifdef BUILDING_DONGLEMAN +int mcman_probeSecurityDongle(int port,int slot) +{ +#ifdef DEBUG + const char* FUNC = "probeSecurityDongle"; +#endif + DPRINTF("%s: port:%d, slot:%d\n", FUNC, port, slot); + int x; + int iVar3; + + iVar3 = sceMcResFailResetAuth; + if (mcman_resetauth(port, slot) != sceMcResSucceed) { + DPRINTF("%s: mcman_resetauth failed\n", FUNC); + return sceMcResFailResetAuth; + } + if (SecrAuthDongle(port + 2, slot, mcman_getcnum(port, slot))==0) { + DPRINTF("%s: SecrAuthDongle failed\n", FUNC); + return sceMcResFailAuth; + } + x = 0; + do { + sio2packet_add(port, slot, 0xffffffff, 0); + sio2packet_add(port, slot, 0x9,0); + sio2packet_add(port, slot, 0xfffffffe, 0); + mcsio2_transfer(port, slot, &mcman_sio2packet); + sio2_transfer(&mcman_sio2packet); + sio2_transfer_reset(); + if (((mcman_sio2packet.stat6c & 0xf000) == 0x1000) && (mcman_rdmabufs[4] != 0x66)) break; + x = x + 1; + } while (x < 5); + if (x == 5) { + DPRINTF("%s: failed cmd 0x9\n", FUNC); + return sceMcResFailDetect; + } + else { + mcman_clearcache(port,slot); + sio2packet_add(port,slot,0xffffffff,0); + sio2packet_add(port,slot,8,0); + sio2packet_add(port,slot,0xfffffffe,0); + iVar3 = 0; + do { + mcsio2_transfer(port, slot, &mcman_sio2packet); + if (((mcman_sio2packet.stat6c & 0xf000) == 0x1000) && (mcman_rdmabufs[4] == 'Z')) break; + iVar3++; + } while (iVar3 < 5); + if (iVar3 == 5) { + DPRINTF("%s: failed cmd 0x8\n", FUNC); + return sceMcResFailDetect2; + } + else { + x = mcman_setdevinfos(port,slot); + DPRINTF("%s: mcman_setdevinfos %d\n", FUNC, x); + iVar3 = -1; + if ((x != 0) && (iVar3 = x, x == -2)) { + mcman_devinfos[port * 2][slot].cardform = -2; + } + } + } + DPRINTF("%s: returning %d\n", FUNC, iVar3); + return iVar3; +} +#endif diff --git a/iop/memorycard/mcman/src/ps1mc_fio.c b/iop/memorycard/mcman/src/ps1mc_fio.c index b2d4616b1f1..2bb585feb04 100644 --- a/iop/memorycard/mcman/src/ps1mc_fio.c +++ b/iop/memorycard/mcman/src/ps1mc_fio.c @@ -18,7 +18,7 @@ static char mcman_PS1curdir[64]; int mcman_format1(int port, int slot) { register int r, i; - register MCDevInfo *mcdi = &mcman_devinfos[port][slot]; + register MCDevInfo *mcdi = &GET_MCDEVINFO(port, slot); DPRINTF("mcman_format1 port%d slot%d\n", port, slot); diff --git a/iop/memorycard/mcman/src/ps2mc_fio.c b/iop/memorycard/mcman/src/ps2mc_fio.c index 0fe6f9b8c77..7305c5e0c73 100644 --- a/iop/memorycard/mcman/src/ps2mc_fio.c +++ b/iop/memorycard/mcman/src/ps2mc_fio.c @@ -23,7 +23,7 @@ int mcman_format2(int port, int slot) register int r, i, size, ifc_index, indirect_offset, allocatable_clusters_per_card; register int ifc_length, fat_length, fat_entry, alloc_offset; register int j = 0, z = 0; - MCDevInfo *mcdi = &mcman_devinfos[port][slot]; + MCDevInfo *mcdi = &GET_MCDEVINFO(port, slot); McCacheEntry *mce; DPRINTF("mcman_format2 port%d, slot%d cardform %d\n", port, slot, mcdi->cardform); @@ -680,7 +680,7 @@ int mcman_open2(int port, int slot, const char *filename, int flags) mcman_wmemset((void *)fh, sizeof (MC_FHANDLE), 0); - mcdi = (MCDevInfo *)&mcman_devinfos[port][slot]; // s3 + mcdi = (MCDevInfo *)&GET_MCDEVINFO(port, slot); // s3 if ((flags & (sceMcFileCreateFile | sceMcFileCreateDir)) == 0) cacheDir.maxent = -1; //sp20 @@ -1026,7 +1026,7 @@ int mcman_open2(int port, int slot, const char *filename, int flags) int mcman_chdir(int port, int slot, const char *newdir, char *currentdir) { register int r, len, len2, cluster; - register MCDevInfo *mcdi = &mcman_devinfos[port][slot]; + register MCDevInfo *mcdi = &GET_MCDEVINFO(port, slot); McCacheDir cacheDir; McFsEntry *fse; @@ -1118,7 +1118,7 @@ int mcman_chdir(int port, int slot, const char *newdir, char *currentdir) int mcman_getdir2(int port, int slot, const char *dirname, int flags, int maxent, sceMcTblGetDir *info) { register int r, nument; - register MCDevInfo *mcdi = &mcman_devinfos[port][slot]; + register MCDevInfo *mcdi = &GET_MCDEVINFO(port, slot); McFsEntry *fse; char *p; @@ -1318,7 +1318,7 @@ int mcman_unformat2(int port, int slot) { register int r, i, j, z, l, pageword_cnt, page, blocks_on_card, erase_byte, err_cnt; register u32 erase_value; - register MCDevInfo *mcdi = &mcman_devinfos[port][slot]; + register MCDevInfo *mcdi = &GET_MCDEVINFO(port, slot); DPRINTF("mcman_unformat2 port%d slot%d\n", port, slot);