s32 STM_ShutdownToIdle() { int res; _viReg[1] = 0; if(__stm_initialized==0) { #ifdef DEBUG_STM printf("STM notinited\n"); #endif return STM_ENOTINIT; } switch(SYS_GetHollywoodRevision()) { case 0: case 1: case 2: __stm_immbufin[0] = 0xFCA08280; default: __stm_immbufin[0] = 0xFCE082C0; } res= IOS_Ioctl(__stm_imm_fd,IOCTL_STM_IDLE,__stm_immbufin,0x20,__stm_immbufout,0x20); if(res<0) { #ifdef DEBUG_STM printf("STM IDLE failed: %d\n",res); #endif } return res; }
/* Register a USB class driver */ int UhsClassDrvReg(int uhs_handle, UhsInterfaceFilter *filter, void *context, int (*cb)(void *ctx, UhsInterfaceProfile *profile)) { /* Symbol loading */ unsigned int coreinit_handle; OSDynLoad_Acquire("coreinit.rpl", &coreinit_handle); void* (*memcpy)(void *dest, void *src, uint32_t length); int (*IOS_Ioctl)(int fd, int request, void *inbuf, int inlen, void *outbuf, int outlen); OSDynLoad_FindExport(coreinit_handle, false, "memcpy", &memcpy); OSDynLoad_FindExport(coreinit_handle, false, "IOS_Ioctl", &IOS_Ioctl); /* Allocate and fill in the request buffer */ uint32_t reqbuf[6]; reqbuf[0] = (uint32_t)context; reqbuf[1] = (uint32_t)cb; memcpy(&reqbuf[2], filter, sizeof(UhsInterfaceFilter)); /* Perform the ioctl() request */ int ret = -1; IOS_Ioctl(uhs_handle, 0x01, reqbuf, 0x18, &ret, 4); /* Set up the callback to be executed */ wait_uhs_event(uhs_handle); return ret; }
MCPError MCP_GetTitleId(IOSHandle handle, be_val<uint64_t> *titleId) { auto result = MCPError::OK; auto output = internal::mcpAllocateMessage(sizeof(MCPResponseGetTitleId)); if (!output) { return MCPError::AllocError; } auto iosError = IOS_Ioctl(handle, MCPCommand::GetTitleId, nullptr, 0, output, sizeof(MCPResponseGetTitleId)); result = internal::mcpDecodeIosErrorToMcpError(iosError); if (result >= 0) { auto response = reinterpret_cast<MCPResponseGetTitleId *>(output); *titleId = response->titleId; } internal::mcpFreeMessage(output); return result; }
s32 Nand_Enable(nandDevice *dev) { s32 fd, ret; /* Open /dev/fs */ fd = IOS_Open("/dev/fs", 0); if (fd < 0) return fd; memset(inbuf, 0, sizeof(inbuf)); /* Set input buffer */ if (IOS_GetRevision() >= 20) { // New method, fully enable full emulation inbuf[0] = dev->mode | 0x100; } else { // Old method inbuf[0] = dev->mode; } /* Enable NAND emulator */ ret = IOS_Ioctl(fd, 100, inbuf, sizeof(inbuf), NULL, 0); /* Close /dev/fs */ IOS_Close(fd); return ret; }
IOSError mcpSearchTitleList(IOSHandle handle, MCPTitleListType *searchTitle, MCPTitleListSearchFlags searchFlags, MCPTitleListType *titleList, uint32_t titleListLength) { auto message = mcpAllocateMessage(sizeof(MCPRequestSearchTitleList)); if (!message) { return static_cast<IOSError>(MCPError::AllocError); } auto request = reinterpret_cast<MCPRequestSearchTitleList *>(message); request->searchTitle = *searchTitle; request->searchFlags = searchFlags; auto iosError = IOS_Ioctl(handle, MCPCommand::SearchTitleList, request, sizeof(MCPRequestSearchTitleList), titleList, titleListLength * sizeof(MCPTitleListType)); mcpFreeMessage(message); return iosError; }
s32 CheckDisk(void *id) { const char di_fs[] ATTRIBUTE_ALIGN(32) = "/dev/di"; s32 di_fd = -1; u32 inbuf[8] ATTRIBUTE_ALIGN(32); u32 outbuf[8] ATTRIBUTE_ALIGN(32); /* Open "/dev/di" */ di_fd = IOS_Open(di_fs, 0); if (di_fd < 0) return di_fd; // error /* Reset drive */ memset(inbuf, 0, sizeof(inbuf)); inbuf[0] = IOCTL_DI_RESET << 24; inbuf[1] = 1; s32 ret = IOS_Ioctl(di_fd, IOCTL_DI_RESET, inbuf, sizeof(inbuf), outbuf, sizeof(outbuf)); if (ret < 0) { IOS_Close(di_fd); return ret; } /* Read disc ID */ memset(inbuf, 0, sizeof(inbuf)); inbuf[0] = IOCTL_DI_READID << 24; ret = IOS_Ioctl(di_fd, IOCTL_DI_READID, inbuf, sizeof(inbuf), outbuf, sizeof(outbuf)); if (ret < 0) return ret; if (ret == 1 && id) memcpy(id, outbuf, sizeof(dvddiskid)); /* Stop motor */ memset(inbuf, 0, sizeof(inbuf)); inbuf[0] = IOCTL_DI_STOPMOTOR << 24; IOS_Ioctl(di_fd, IOCTL_DI_STOPMOTOR, inbuf, sizeof(inbuf), outbuf, sizeof(outbuf)); IOS_Close(di_fd); if (ret != 1) { grlib_menu (0, "Sorry, no disc is detected in your WII", " OK "); } return ret; }
/* Determine which USB device interfaces are plugged in and available */ int UhsQueryInterfaces(int uhs_handle, UhsInterfaceFilter *filter, UhsInterfaceProfile *profiles, int max_profiles) { /* Symbol loading */ unsigned int coreinit_handle; OSDynLoad_Acquire("coreinit.rpl", &coreinit_handle); int (*IOS_Ioctl)(int fd, int request, void *inbuf, int inlen, void *outbuf, int outlen); OSDynLoad_FindExport(coreinit_handle, false, "IOS_Ioctl", &IOS_Ioctl); /* Perform the ioctl() request */ return IOS_Ioctl(uhs_handle, 0x11, filter, 0x10, profiles, max_profiles * 0x16c); }
s32 DVDEjectDisc( void ) { s32 fd = IOS_Open("/dev/di", 0 ); if( fd < 0 ) return fd; s32 r = IOS_Ioctl( fd, DVD_EJECT_DISC, NULL, 0, NULL, 0 ); IOS_Close( fd ); return r; }
s32 DVDLowPrepareCoverRegister( u32 *Cover ) { s32 fd = IOS_Open("/dev/di", 0 ); if( fd < 0 ) return fd; s32 r = IOS_Ioctl( fd, 0x7A, NULL, 0, Cover, sizeof(u32) ); IOS_Close( fd ); return r; }
s32 DVDGetGameCount( u32 *Count ) { s32 fd = IOS_Open("/dev/di", 0 ); if( fd < 0 ) return fd; s32 r = IOS_Ioctl( fd, DVD_GET_GAMECOUNT, NULL, 0, Count, sizeof(u32) ); IOS_Close( fd ); return r; }
s32 DVDConnected( void ) { s32 fd = IOS_Open("/dev/di", 0 ); if( fd < 0 ) return fd; s32 r = IOS_Ioctl( fd, DVD_CONNECTED, NULL, 0, NULL, 0); IOS_Close( fd ); return r; }
s32 DVDInsertDisc( void ) { s32 fd = IOS_Open("/dev/di", 0 ); if( fd < 0 ) return fd; s32 r = IOS_Ioctl( fd, DVD_INSERT_DISC, NULL, 0, NULL, 0 ); IOS_Close( fd ); return r; }
s32 WDVD_ReadDiskId(void *id) { memset(inbuf, 0, sizeof(inbuf)); /* Read disc ID */ inbuf[0] = IOCTL_DI_READID << 24; s32 ret = IOS_Ioctl(di_fd, IOCTL_DI_READID, inbuf, sizeof(inbuf), outbuf, sizeof(outbuf)); if(ret < 0) return ret; memcpy(id, outbuf, sizeof(dvddiskid)); return (ret == 1) ? 0 : -ret; }
s32 WDVD_Reset(void) { memset(inbuf, 0, sizeof(inbuf)); /* Reset drive */ inbuf[0] = IOCTL_DI_RESET << 24; inbuf[1] = 1; s32 ret = IOS_Ioctl(di_fd, IOCTL_DI_RESET, inbuf, sizeof(inbuf), outbuf, sizeof(outbuf)); if(ret < 0) return ret; return (ret == 1) ? 0 : -ret; }
s32 WDVD_Seek(u32 offset) { memset(inbuf, 0, sizeof(inbuf)); /* Drive seek */ inbuf[0] = IOCTL_DI_SEEK << 24; inbuf[1] = offset; s32 ret = IOS_Ioctl(di_fd, IOCTL_DI_SEEK, inbuf, sizeof(inbuf), outbuf, sizeof(outbuf)); if(ret < 0) return ret; return (ret == 1) ? 0 : -ret; }
s32 WDVD_Read(void *buf, u32 len, u32 offset) { memset(inbuf, 0, sizeof(inbuf)); /* Disc read */ inbuf[0] = IOCTL_DI_READ << 24; inbuf[1] = len; inbuf[2] = offset; s32 ret = IOS_Ioctl(di_fd, IOCTL_DI_READ, inbuf, sizeof(inbuf), buf, len); if(ret < 0) return ret; return (ret == 1) ? 0 : -ret; }
s32 __STM_ReleaseEventHook() { s32 ret; if(__stm_initialized==0) return STM_ENOTINIT; if(__stm_ehregistered==0) return STM_ENOHANDLER; __stm_ehclear = 1; ret = IOS_Ioctl(__stm_imm_fd,IOCTL_STM_RELEASE_EH,__stm_immbufin,0x20,__stm_immbufout,0x20); if(ret>=0) __stm_ehregistered = 0; return ret; }
MCPError MCP_TitleCount(IOSHandle handle) { auto result = IOS_Ioctl(handle, MCPCommand::TitleCount, nullptr, 0, nullptr, 0); if (result < 0) { return internal::mcpDecodeIosErrorToMcpError(result); } return static_cast<MCPError>(result); }
int DIP::Close_Partition() { Lock(); Command[0] = Ioctl::DI_ClosePartition << 24; int Ret = IOS_Ioctl(Device_Handle, Ioctl::DI_ClosePartition, Command, 0x20, Output, 0x20); Unlock(); if (Ret == 2) throw "Ioctl error (DI_ClosePartition)"; return ((Ret == 1)? 0 : -Ret); }
int DIP::Reset() { Command[0] = Ioctl::DI_Reset << 24; Command[1] = 1; Lock(); int Ret = IOS_Ioctl(Device_Handle, Ioctl::DI_Reset, Command, 0x20, Output, 0x20); Unlock(); if (Ret == 2) throw "Ioctl error (DI_Reset)"; return ((Ret == 1) ? 0 : -Ret); }
int DIP::Wait_CoverClose() { memset(Command, 0, 0x20); Command[0] = Ioctl::DI_WaitCoverClose << 24; Lock(); int Ret = IOS_Ioctl(Device_Handle, Ioctl::DI_WaitCoverClose, Command, 0x20, Output, 0x20); Unlock(); if (Ret == 2) throw "Ioctl error (DI_WaitCoverClose)"; return ((Ret == 1) ? 0 : -Ret); }
s32 WDVD_Read(void *buf, u32 len, u64 offset) { s32 ret; memset(inbuf, 0, sizeof(inbuf)); inbuf[0] = IOCTL_DI_READ << 24; inbuf[1] = len; inbuf[2] = (u32)(offset >> 2); ret = IOS_Ioctl(di_fd, IOCTL_DI_READ, inbuf, sizeof(inbuf), buf, len); if (ret < 0) return ret; return (ret == 1) ? 0 : -ret; }
int DIP::Stop_Motor() { Command[0] = Ioctl::DI_StopMotor << 24; Command[1] = 0; // Set this to 1 to eject the disc Command[2] = 0; // This will temporarily kill the drive if set!!! Lock(); int Ret = IOS_Ioctl(Device_Handle, Ioctl::DI_StopMotor, Command, 0x20, Output, 0x20); Unlock(); if (Ret == 2) throw "Ioctl error (DI_StopMotor)"; return ((Ret == 1) ? 0 : -Ret); }
int DIP::Get_OffsetBase(unsigned int* Base) { memset(Command, 0, 0x20); Command[0] = Ioctl::DI_GetOffsetBase << 24; Lock(); int Ret = IOS_Ioctl(Device_Handle, Ioctl::DI_GetOffsetBase, Command, 0x20, Output, 0x20); Unlock(); if (Ret == 2) throw "Ioctl error (DI_GetOffsetBase)"; if (Ret == 1) *Base = *((unsigned int*)Output); return ((Ret == 1) ? 0 : -Ret); }
int DIP::Enable_DVD() { memset(Command, 0, 0x20); Command[0] = Ioctl::DI_EnableDVD << 24; Command[1] = 1; Lock(); int Ret = IOS_Ioctl(Device_Handle, Ioctl::DI_EnableDVD, Command, 0x20, Output, 0x20); Unlock(); if (Ret == 2) throw "Ioctl error (DI_EnableDVD)"; return ((Ret == 1) ? 0 : -Ret); }
int DIP::Verify_Cover(bool *Inserted) { memset(Command, 0, 0x20); Command[0] = Ioctl::DI_VerifyCover << 24; Lock(); int Ret = IOS_Ioctl(Device_Handle, Ioctl::DI_VerifyCover, Command, 0x20, Output, 0x20); Unlock(); if (Ret == 2) throw "Ioctl error (DI_VerifyCover)"; if (Ret == 1) *Inserted = !((bool)*Output); return ((Ret == 1) ? 0 : -Ret); }
s32 WDVD_ClosePartition(void) { s32 ret; // partitionOpen = false; memset(inbuf, 0, sizeof(inbuf)); inbuf[0] = IOCTL_DI_CLOSEPART << 24; ret = IOS_Ioctl(di_fd, IOCTL_DI_CLOSEPART, inbuf, sizeof(inbuf), NULL, 0); if (ret < 0) return ret; return (ret == 1) ? 0 : -ret; }
/**************************************************************************** * Get network IP ***************************************************************************/ bool ShutdownWC24() { bool onlinefix = IsNetworkInit(); if (onlinefix) { s32 kd_fd, ret; STACK_ALIGN(u8, kd_buf, 0x20, 32); kd_fd = IOS_Open("/dev/net/kd/request", 0); if (kd_fd >= 0) { ret = IOS_Ioctl(kd_fd, 7, NULL, 0, kd_buf, 0x20); if (ret >= 0) onlinefix = false; // fixed no IOS reload needed IOS_Close(kd_fd); } } return onlinefix; }
int DIP::Read_DiscID(dvddiskid* Disc_ID) { if (!Disc_ID) throw "Null Disc_ID pointer"; Command[0] = Ioctl::DI_ReadID << 24; Lock(); int Ret = IOS_Ioctl(Device_Handle, Ioctl::DI_ReadID, Command, 0x20, Output, 0x20); Unlock(); if (Ret == 2) throw "Ioctl error (DI_ReadID)"; memcpy(Disc_ID, Output, 0x20); return ((Ret == 1) ? 0 : -Ret); }
int DIP::Inquiry(void* Drive_ID) { if (!Drive_ID) throw "Null DriveID pointer"; Command[0] = Ioctl::DI_Inquiry << 24; Lock(); int Ret = IOS_Ioctl(Device_Handle, Ioctl::DI_Inquiry, Command, 0x20, Output, 0x20); Unlock(); if (Ret == 2) throw "Ioctl error (DI_Inquiry)"; memcpy(Drive_ID, Output, 8); return ((Ret == 1) ? 0 : -Ret); }