├── timestamps.png ├── WiiUFtpServer.png ├── _sdCard └── wiiu │ └── apps │ └── WiiUFtpServer │ ├── icon.png │ └── meta.xml ├── src ├── fat │ ├── libfatversion.h │ ├── lock.c │ ├── filetime.h │ ├── mem_allocate.h │ ├── bit_ops.h │ ├── lock.h │ ├── fatdir.h │ ├── file_allocation_table.h │ ├── common.h │ ├── filetime.c │ ├── fatfile.h │ ├── disc.h │ ├── partition.h │ ├── disc.c │ ├── fat.h │ ├── cache.h │ ├── directory.h │ ├── libfat.c │ └── cache.c ├── common │ ├── os_defs.h │ ├── types.h │ ├── fs_defs.h │ └── common.h ├── link.ld ├── controllers.h ├── iosuhax │ ├── iosuhax_devoptab.h │ ├── iosuhax_iosapi.h │ ├── iosuhax_cfw.h │ ├── iosuhax_disc_interface.h │ ├── iosuhax.h │ ├── iosuhax_cfw.c │ └── iosuhax_disc_interface.c ├── ftp.h ├── vrt.h ├── virtualpath.h ├── dynamic_libs │ ├── padscore_functions.c │ ├── socket_functions.c │ ├── fs_functions.h │ ├── socket_functions.h │ ├── padscore_functions.h │ ├── fs_functions.c │ ├── vpad_functions.h │ └── vpad_functions.c ├── system │ ├── memory.h │ └── memory.c ├── net.h └── controllers.c ├── LICENSE.txt ├── README.md └── Makefile /timestamps.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Laf111/WiiUFtpServer/HEAD/timestamps.png -------------------------------------------------------------------------------- /WiiUFtpServer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Laf111/WiiUFtpServer/HEAD/WiiUFtpServer.png -------------------------------------------------------------------------------- /_sdCard/wiiu/apps/WiiUFtpServer/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Laf111/WiiUFtpServer/HEAD/_sdCard/wiiu/apps/WiiUFtpServer/icon.png -------------------------------------------------------------------------------- /src/fat/libfatversion.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIBFATVERSION_H__ 2 | #define __LIBFATVERSION_H__ 3 | 4 | #define _LIBFAT_MAJOR_ 1 5 | #define _LIBFAT_MINOR_ 2 6 | #define _LIBFAT_PATCH_ 0 7 | 8 | #define _LIBFAT_STRING "libFAT Release 1.2.0" 9 | 10 | #endif // __LIBFATVERSION_H__ 11 | -------------------------------------------------------------------------------- /src/fat/lock.c: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | 3 | #if !defined(USE_LWP_LOCK) && (defined(__wiiu__) && defined(__WUT__)) 4 | 5 | #ifndef mutex_t 6 | typedef int mutex_t; 7 | #endif 8 | 9 | void __attribute__ ((weak)) _FAT_lock_init(mutex_t *mutex) 10 | { 11 | return; 12 | } 13 | 14 | void __attribute__ ((weak)) _FAT_lock_deinit(mutex_t *mutex) 15 | { 16 | return; 17 | } 18 | 19 | void __attribute__ ((weak)) _FAT_lock(mutex_t *mutex) 20 | { 21 | return; 22 | } 23 | 24 | void __attribute__ ((weak)) _FAT_unlock(mutex_t *mutex) 25 | { 26 | return; 27 | } 28 | 29 | #endif // USE_LWP_LOCK 30 | -------------------------------------------------------------------------------- /_sdCard/wiiu/apps/WiiUFtpServer/meta.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | WiiUFtpServer 4 | Laf111 5 | 9.3.0 6 | 20220329204046 7 | A robust and optimized FTP server for the Wii-U! 8 | 16 | 17 | -------------------------------------------------------------------------------- /src/common/os_defs.h: -------------------------------------------------------------------------------- 1 | #ifndef __OS_DEFS_H_ 2 | #define __OS_DEFS_H_ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | typedef struct _OsSpecifics { 9 | unsigned int addr_OSDynLoad_Acquire; 10 | unsigned int addr_OSDynLoad_FindExport; 11 | unsigned int addr_OSTitle_main_entry; 12 | 13 | unsigned int addr_KernSyscallTbl1; 14 | unsigned int addr_KernSyscallTbl2; 15 | unsigned int addr_KernSyscallTbl3; 16 | unsigned int addr_KernSyscallTbl4; 17 | unsigned int addr_KernSyscallTbl5; 18 | } OsSpecifics; 19 | 20 | typedef struct _s_mem_area { 21 | unsigned int address; 22 | unsigned int size; 23 | struct _s_mem_area* next; 24 | } s_mem_area; 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | 30 | #endif // __OS_DEFS_H_ 31 | -------------------------------------------------------------------------------- /src/link.ld: -------------------------------------------------------------------------------- 1 | OUTPUT(WiiUFtpServer.elf); 2 | 3 | /* Tell linker where our application entry is so the garbage collect can work correct */ 4 | ENTRY(__entry_menu); 5 | 6 | SECTIONS { 7 | . = 0x00802000; 8 | .text : { 9 | *(.text*); 10 | } 11 | .rodata : { 12 | *(.rodata*); 13 | } 14 | .data : { 15 | *(.data*); 16 | 17 | __sdata_start = .; 18 | *(.sdata*); 19 | __sdata_end = .; 20 | 21 | __sdata2_start = .; 22 | *(.sdata2*); 23 | __sdata2_end = .; 24 | } 25 | .bss : { 26 | __bss_start = .; 27 | *(.bss*); 28 | *(.sbss*); 29 | *(COMMON); 30 | __bss_end = .; 31 | } 32 | __CODE_END = .; 33 | 34 | /DISCARD/ : { 35 | *(*); 36 | } 37 | } 38 | 39 | /******************************************************** FS ********************************************************/ 40 | /* coreinit.rpl difference in addresses 0xFE3C00 */ 41 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (C) 2008 Joseph Jordan 2 | 3 | This software is provided 'as-is', without any express or implied warranty. 4 | In no event will the authors be held liable for any damages arising from 5 | the use of this software. 6 | 7 | Permission is granted to anyone to use this software for any purpose, 8 | including commercial applications, and to alter it and redistribute it 9 | freely, subject to the following restrictions: 10 | 11 | 1.The origin of this software must not be misrepresented; you must not 12 | claim that you wrote the original software. If you use this software in a 13 | product, an acknowledgment in the product documentation would be 14 | appreciated but is not required. 15 | 16 | 2.Altered source versions must be plainly marked as such, and must not be 17 | misrepresented as being the original software. 18 | 19 | 3.This notice may not be removed or altered from any source distribution. -------------------------------------------------------------------------------- /src/controllers.h: -------------------------------------------------------------------------------- 1 | #ifndef CONTROLLERS_H 2 | #define CONTROLLERS_H 3 | 4 | #include "dynamic_libs/padscore_functions.h" 5 | #include "dynamic_libs/vpad_functions.h" 6 | 7 | enum buttons { 8 | PAD_BUTTON_A, 9 | PAD_BUTTON_B, 10 | PAD_BUTTON_X, 11 | PAD_BUTTON_Y, 12 | PAD_BUTTON_UP, 13 | PAD_BUTTON_DOWN, 14 | PAD_BUTTON_LEFT, 15 | PAD_BUTTON_RIGHT, 16 | PAD_BUTTON_L, 17 | PAD_BUTTON_R, 18 | PAD_BUTTON_ZL, 19 | PAD_BUTTON_ZR, 20 | PAD_BUTTON_PLUS, 21 | PAD_BUTTON_MINUS, 22 | PAD_BUTTON_Z, 23 | PAD_BUTTON_C, 24 | PAD_BUTTON_STICK_L, 25 | PAD_BUTTON_STICK_R, 26 | PAD_BUTTON_HOME, 27 | PAD_BUTTON_SYNC, 28 | PAD_BUTTON_TV, 29 | PAD_BUTTON_1, 30 | PAD_BUTTON_2, 31 | PAD_BUTTON_ANY 32 | }; 33 | 34 | enum buttonStates { 35 | PRESS, 36 | HOLD, 37 | RELEASE 38 | }; 39 | 40 | void updateButtons(); 41 | int checkButton(int button, int state); 42 | 43 | 44 | #endif //CONTROLLERS_H 45 | -------------------------------------------------------------------------------- /src/iosuhax/iosuhax_devoptab.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2015 3 | * by Dimok 4 | * 5 | * This software is provided 'as-is', without any express or implied 6 | * warranty. In no event will the authors be held liable for any 7 | * damages arising from the use of this software. 8 | * 9 | * Permission is granted to anyone to use this software for any 10 | * purpose, including commercial applications, and to alter it and 11 | * redistribute it freely, subject to the following restrictions: 12 | * 13 | * 1. The origin of this software must not be misrepresented; you 14 | * must not claim that you wrote the original software. If you use 15 | * this software in a product, an acknowledgment in the product 16 | * documentation would be appreciated but is not required. 17 | * 18 | * 2. Altered source versions must be plainly marked as such, and 19 | * must not be misrepresented as being the original software. 20 | * 21 | * 3. This notice may not be removed or altered from any source 22 | * distribution. 23 | ***************************************************************************/ 24 | #ifndef __IOSUHAX_DEVOPTAB_H_ 25 | #define __IOSUHAX_DEVOPTAB_H_ 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | //! virtual name example: sd or odd (for sd:/ or odd:/ access) 32 | //! fsaFd: fd received by IOSUHAX_FSA_Open(); 33 | //! dev_path: (optional) if a device should be mounted to the mount_path. If NULL no IOSUHAX_FSA_Mount is not executed. 34 | //! mount_path: path to map to virtual device name 35 | int mount_fs(const char *virt_name, int fsaFd, const char *dev_path, const char *mount_path); 36 | int unmount_fs(const char *virt_name); 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif 41 | 42 | #endif // __IOSUHAX_DEVOPTAB_H_ 43 | -------------------------------------------------------------------------------- /src/fat/filetime.h: -------------------------------------------------------------------------------- 1 | /* 2 | filetime.h 3 | Conversion of file time and date values to various other types 4 | 5 | Copyright (c) 2006 Michael "Chishm" Chisholm 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation and/or 14 | other materials provided with the distribution. 15 | 3. The name of the author may not be used to endorse or promote products derived 16 | from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 20 | AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 26 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef _FILETIME_H 30 | #define _FILETIME_H 31 | 32 | #include "common.h" 33 | #include 34 | 35 | uint16_t _FAT_filetime_getTimeFromRTC (void); 36 | uint16_t _FAT_filetime_getDateFromRTC (void); 37 | 38 | time_t _FAT_filetime_to_time_t (uint16_t t, uint16_t d); 39 | 40 | 41 | #endif // _FILETIME_H 42 | -------------------------------------------------------------------------------- /src/ftp.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | ftpii -- an FTP server for the Wii 4 | 5 | Copyright (C) 2008 Joseph Jordan 6 | 7 | This software is provided 'as-is', without any express or implied warranty. 8 | In no event will the authors be held liable for any damages arising from 9 | the use of this software. 10 | 11 | Permission is granted to anyone to use this software for any purpose, 12 | including commercial applications, and to alter it and redistribute it 13 | freely, subject to the following restrictions: 14 | 15 | 1.The origin of this software must not be misrepresented; you must not 16 | claim that you wrote the original software. If you use this software in a 17 | product, an acknowledgment in the product documentation would be 18 | appreciated but is not required. 19 | 20 | 2.Altered source versions must be plainly marked as such, and must not be 21 | misrepresented as being the original software. 22 | 23 | 3.This notice may not be removed or altered from any source distribution. 24 | 25 | */ 26 | #ifndef _FTP_H_ 27 | #define _FTP_H_ 28 | 29 | #include 30 | #include 31 | #define FTP_PORT 21 32 | 33 | // Connection time out in seconds 34 | #define FTP_CONNECTION_TIMEOUT 85 35 | 36 | #define FTP_MSG_BUFFER_SIZE 1024 37 | 38 | // Number max of simultaneous connections from the client : 39 | // 1 for communication with the client + NB_SIMULTANEOUS_TRANSFERS 40 | #define FTP_NB_SIMULTANEOUS_TRANSFERS (1+NB_SIMULTANEOUS_TRANSFERS) 41 | 42 | #define FTP_STACK_SIZE (20*1024) 43 | 44 | #define FTP_TRANSFER_STACK_SIZE (18*1024) 45 | 46 | #ifdef __cplusplus 47 | extern "C"{ 48 | #endif 49 | 50 | char* virtualToVolPath(char *vPath); 51 | 52 | int32_t create_server(uint16_t port); 53 | bool process_ftp_events(); 54 | void cleanup_ftp(); 55 | 56 | void setOsTime(struct tm *tmTime); 57 | 58 | 59 | #ifdef __cplusplus 60 | } 61 | #endif 62 | 63 | #endif /* _FTP_H_ */ 64 | -------------------------------------------------------------------------------- /src/common/types.h: -------------------------------------------------------------------------------- 1 | #ifndef __GCTYPES_H__ 2 | #define __GCTYPES_H__ 3 | 4 | /*! \file gctypes.h 5 | \brief Data type definitions 6 | */ 7 | 8 | #include 9 | #include 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif /* __cplusplus */ 14 | 15 | 16 | /*+----------------------------------------------------------------------------------------------+*/ 17 | // alias type typedefs 18 | #define FIXED int32_t ///< Alias type for sfp32 19 | /*+----------------------------------------------------------------------------------------------+*/ 20 | #ifndef NULL 21 | #define NULL 0 ///< Pointer to 0 22 | #endif 23 | /*+----------------------------------------------------------------------------------------------+*/ 24 | #ifndef LITTLE_ENDIAN 25 | #define LITTLE_ENDIAN 3412 26 | #endif /* LITTLE_ENDIAN */ 27 | /*+----------------------------------------------------------------------------------------------+*/ 28 | #ifndef BIG_ENDIAN 29 | #define BIG_ENDIAN 1234 30 | #endif /* BIGE_ENDIAN */ 31 | /*+----------------------------------------------------------------------------------------------+*/ 32 | #ifndef BYTE_ORDER 33 | #define BYTE_ORDER BIG_ENDIAN 34 | #endif /* BYTE_ORDER */ 35 | /*+----------------------------------------------------------------------------------------------+*/ 36 | 37 | 38 | //! argv structure 39 | /*! \struct __argv 40 | structure used to set up argc/argv 41 | */ 42 | struct __argv { 43 | int argvMagic; //!< argv magic number, set to 0x5f617267 ('_arg') if valid 44 | char *commandLine; //!< base address of command line, set of null terminated strings 45 | int length;//!< total length of command line 46 | int argc; 47 | char **argv; 48 | char **endARGV; 49 | }; 50 | 51 | //! Default location for the system argv structure. 52 | extern struct __argv *__system_argv; 53 | 54 | // argv struct magic number 55 | #define ARGV_MAGIC 0x5f617267 56 | 57 | #ifdef __cplusplus 58 | } 59 | #endif /* __cplusplus */ 60 | 61 | #endif /* TYPES_H */ 62 | 63 | -------------------------------------------------------------------------------- /src/iosuhax/iosuhax_iosapi.h: -------------------------------------------------------------------------------- 1 | #ifndef _IOSUHAX_IOS_API_H_ 2 | #define _IOSUHAX_IOS_API_H_ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #define IOCTL_MEM_WRITE 0x00 9 | #define IOCTL_MEM_READ 0x01 10 | #define IOCTL_SVC 0x02 11 | #define IOCTL_MEMCPY 0x04 12 | #define IOCTL_REPEATED_WRITE 0x05 13 | #define IOCTL_KERN_READ32 0x06 14 | #define IOCTL_KERN_WRITE32 0x07 15 | 16 | #define IOCTL_FSA_OPEN 0x40 17 | #define IOCTL_FSA_CLOSE 0x41 18 | #define IOCTL_FSA_MOUNT 0x42 19 | #define IOCTL_FSA_UNMOUNT 0x43 20 | #define IOCTL_FSA_GETDEVICEINFO 0x44 21 | #define IOCTL_FSA_OPENDIR 0x45 22 | #define IOCTL_FSA_READDIR 0x46 23 | #define IOCTL_FSA_CLOSEDIR 0x47 24 | #define IOCTL_FSA_MAKEDIR 0x48 25 | #define IOCTL_FSA_OPENFILE 0x49 26 | #define IOCTL_FSA_READFILE 0x4A 27 | #define IOCTL_FSA_WRITEFILE 0x4B 28 | #define IOCTL_FSA_STATFILE 0x4C 29 | #define IOCTL_FSA_CLOSEFILE 0x4D 30 | #define IOCTL_FSA_SETFILEPOS 0x4E 31 | #define IOCTL_FSA_GETSTAT 0x4F 32 | #define IOCTL_FSA_REMOVE 0x50 33 | #define IOCTL_FSA_REWINDDIR 0x51 34 | #define IOCTL_FSA_CHDIR 0x52 35 | #define IOCTL_FSA_RENAME 0x53 36 | #define IOCTL_FSA_RAW_OPEN 0x54 37 | #define IOCTL_FSA_RAW_READ 0x55 38 | #define IOCTL_FSA_RAW_WRITE 0x56 39 | #define IOCTL_FSA_RAW_CLOSE 0x57 40 | #define IOCTL_FSA_CHANGEMODE 0x58 41 | //HaxchiFW exclusive 42 | #define IOCTL_FSA_FLUSHVOLUME 0x59 43 | //HaxchiFW exclusive 44 | #define IOCTL_CHECK_IF_IOSUHAX 0x5B 45 | #define IOSUHAX_MAGIC_WORD 0x4E696365 46 | 47 | //MochaLite exclusive/ioctl100 48 | #define IPC_CUSTOM_LOG_STRING 0xFF 49 | #define IPC_CUSTOM_META_XML_SWAP_REQUIRED 0xFE 50 | #define IPC_CUSTOM_MEN_RPX_HOOK_COMPLETED 0xFD 51 | #define IPC_CUSTOM_LOAD_CUSTOM_RPX 0xFC 52 | #define IPC_CUSTOM_META_XML_READ 0xFB 53 | 54 | #ifdef __cplusplus 55 | } 56 | #endif 57 | 58 | #endif //_IOSUHAX_IOS_API_H_ 59 | -------------------------------------------------------------------------------- /src/vrt.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2008 Joseph Jordan 4 | This work is derived from Daniel Ehlers' srg_vrt branch. 5 | 6 | This software is provided 'as-is', without any express or implied warranty. 7 | In no event will the authors be held liable for any damages arising from 8 | the use of this software. 9 | 10 | Permission is granted to anyone to use this software for any purpose, 11 | including commercial applications, and to alter it and redistribute it 12 | freely, subject to the following restrictions: 13 | 14 | 1.The origin of this software must not be misrepresented; you must not 15 | claim that you wrote the original software. If you use this software in a 16 | product, an acknowledgment in the product documentation would be 17 | appreciated but is not required. 18 | 19 | 2.Altered source versions must be plainly marked as such, and must not be 20 | misrepresented as being the original software. 21 | 22 | 3.This notice may not be removed or altered from any source distribution. 23 | 24 | */ 25 | /**************************************************************************** 26 | * WiiUFtpServer 27 | * 2021-12-05:Laf111:V7-0 28 | ***************************************************************************/ 29 | 30 | #ifndef _VRT_H_ 31 | #define _VRT_H_ 32 | 33 | #ifdef __cplusplus 34 | extern "C"{ 35 | #endif 36 | 37 | #include 38 | #include 39 | 40 | typedef struct 41 | { 42 | DIR *dir; 43 | char *path; 44 | uint8_t virt_root; 45 | } DIR_P; 46 | 47 | char *to_real_path(char *virtual_cwd, char *virtual_path); 48 | 49 | FILE *vrt_fopen(char *cwd, char *path, char *mode); 50 | int vrt_stat(char *cwd, char *path, struct stat *st); 51 | int vrt_checkdir(char *cwd, char *path); 52 | int vrt_chdir(char *cwd, char *path); 53 | int vrt_unlink(char *cwd, char *path); 54 | int vrt_mkdir(char *cwd, char *path, mode_t mode); 55 | int vrt_rename(char *cwd, char *from_path, char *to_path); 56 | DIR_P *vrt_opendir(char *cwd, char *path); 57 | struct dirent *vrt_readdir(DIR_P *iter); 58 | int vrt_closedir(DIR_P *iter); 59 | 60 | #ifdef __cplusplus 61 | } 62 | #endif 63 | 64 | #endif /* _VRT_H_ */ 65 | -------------------------------------------------------------------------------- /src/fat/mem_allocate.h: -------------------------------------------------------------------------------- 1 | /* 2 | mem_allocate.h 3 | Memory allocation and destruction calls 4 | Replace these calls with custom allocators if 5 | malloc is unavailable 6 | 7 | Copyright (c) 2006 Michael "Chishm" Chisholm 8 | 9 | Redistribution and use in source and binary forms, with or without modification, 10 | are permitted provided that the following conditions are met: 11 | 12 | 1. Redistributions of source code must retain the above copyright notice, 13 | this list of conditions and the following disclaimer. 14 | 2. Redistributions in binary form must reproduce the above copyright notice, 15 | this list of conditions and the following disclaimer in the documentation and/or 16 | other materials provided with the distribution. 17 | 3. The name of the author may not be used to endorse or promote products derived 18 | from this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 21 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 22 | AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 28 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef _MEM_ALLOCATE_H 32 | #define _MEM_ALLOCATE_H 33 | 34 | #include 35 | 36 | static inline void* _FAT_mem_allocate (size_t size) { 37 | return malloc (size); 38 | } 39 | 40 | static inline void* _FAT_mem_align (size_t size) { 41 | #if defined(__wii__) 42 | return memalign (32, size); 43 | #elif defined(__wiiu__) 44 | return memalign (0x40, size); 45 | #else 46 | return malloc (size); 47 | #endif 48 | } 49 | 50 | static inline void _FAT_mem_free (void* mem) { 51 | free (mem); 52 | } 53 | 54 | #endif // _MEM_ALLOCATE_H 55 | -------------------------------------------------------------------------------- /src/virtualpath.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2010 3 | * by Dimok 4 | * 5 | * Original VIRTUAL_PART Struct 6 | * Copyright (C) 2008 7 | * Joseph Jordan 8 | * 9 | * This software is provided 'as-is', without any express or implied 10 | * warranty. In no event will the authors be held liable for any 11 | * damages arising from the use of this software. 12 | * 13 | * Permission is granted to anyone to use this software for any 14 | * purpose, including commercial applications, and to alter it and 15 | * redistribute it freely, subject to the following restrictions: 16 | * 17 | * 1. The origin of this software must not be misrepresented; you 18 | * must not claim that you wrote the original software. If you use 19 | * this software in a product, an acknowledgment in the product 20 | * documentation would be appreciated but is not required. 21 | * 22 | * 2. Altered source versions must be plainly marked as such, and 23 | * must not be misrepresented as being the original software. 24 | * 25 | * 3. This notice may not be removed or altered from any source 26 | * distribution. 27 | * 28 | * for WiiXplorer 2010 29 | ***************************************************************************/ 30 | 31 | /**************************************************************************** 32 | * WiiUFtpServer 33 | * 2021-12-05:Laf111:V7-0 34 | ***************************************************************************/ 35 | 36 | #ifndef _VIRTUALPATH_H_ 37 | #define _VIRTUALPATH_H_ 38 | 39 | #ifdef __cplusplus 40 | extern "C"{ 41 | #endif 42 | 43 | #include 44 | #include 45 | 46 | #include "iosuhax/iosuhax.h" 47 | #include "iosuhax/iosuhax_devoptab.h" 48 | typedef struct { 49 | char *name; 50 | char *alias; 51 | char *prefix; 52 | bool inserted; 53 | } VIRTUAL_PARTITION; 54 | 55 | extern VIRTUAL_PARTITION * VIRTUAL_PARTITIONS; 56 | extern uint8_t MAX_VIRTUAL_PARTITIONS; 57 | 58 | int MountVirtualDevices(bool mountMlc); 59 | void UnmountVirtualPaths(); 60 | void UnmountVirtualDevices(); 61 | 62 | void VirtualMountDevice(const char * path); 63 | 64 | void ResetVirtualPaths(); 65 | 66 | #ifdef __cplusplus 67 | } 68 | #endif 69 | 70 | #endif /* _VIRTUALPART_H_ */ 71 | -------------------------------------------------------------------------------- /src/iosuhax/iosuhax_cfw.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2020 3 | * by Ash Logan 4 | * 5 | * This software is provided 'as-is', without any express or implied 6 | * warranty. In no event will the authors be held liable for any 7 | * damages arising from the use of this software. 8 | * 9 | * Permission is granted to anyone to use this software for any 10 | * purpose, including commercial applications, and to alter it and 11 | * redistribute it freely, subject to the following restrictions: 12 | * 13 | * 1. The origin of this software must not be misrepresented; you 14 | * must not claim that you wrote the original software. If you use 15 | * this software in a product, an acknowledgment in the product 16 | * documentation would be appreciated but is not required. 17 | * 18 | * 2. Altered source versions must be plainly marked as such, and 19 | * must not be misrepresented as being the original software. 20 | * 21 | * 3. This notice may not be removed or altered from any source 22 | * distribution. 23 | ***************************************************************************/ 24 | #ifndef _LIB_IOSUHAX_CFW_H_ 25 | #define _LIB_IOSUHAX_CFW_H_ 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | typedef enum IOSUHAX_CFW_Family { 32 | IOSUHAX_CFW_NO_CFW = 0, 33 | IOSUHAX_CFW_MOCHA, 34 | IOSUHAX_CFW_HAXCHIFW, 35 | } IOSUHAX_CFW_Family; 36 | 37 | typedef enum IOSUHAX_CFW_Variant { 38 | IOSUHAX_CFW_VARIANT_STOCK = 0, 39 | IOSUHAX_CFW_VARIANT_MOCHALITE, 40 | IOSUHAX_CFW_VARIANT_MOCHA_RPX, 41 | } IOSUHAX_CFW_Variant; 42 | 43 | typedef enum IOSUHAX_CFW_RPXStyle { 44 | IOSUHAX_CFW_RPX_STYLE_NONE = 0, 45 | IOSUHAX_CFW_RPX_STYLE_IPC, 46 | IOSUHAX_CFW_RPX_STYLE_RAW_PATH, 47 | } IOSUHAX_CFW_RPXStyle; 48 | 49 | //! Whether iosuhax, and therefore the FSA, SVC and memory APIs are available 50 | int IOSUHAX_CFW_Available(); 51 | 52 | //! Whether IOS-MCP APIs are available - this is variable on HaxchiFW. 53 | int IOSUHAX_CFW_MCPAvailable(); 54 | 55 | //! Get the CFW family (no cfw, mocha, haxchi) of the current environment. 56 | IOSUHAX_CFW_Family IOSUHAX_CFW_GetFamily(); 57 | //! Get the running CFW's variant. 58 | IOSUHAX_CFW_Variant IOSUHAX_CFW_GetVariant(); 59 | //! Get the IOSU-side RPX loading style, if any. 60 | IOSUHAX_CFW_RPXStyle IOSUHAX_CFW_GetRPXStyle(); 61 | 62 | #ifdef __cplusplus 63 | } 64 | #endif 65 | 66 | #endif //_LIB_IOSUHAX_CFW_H_ 67 | -------------------------------------------------------------------------------- /src/common/fs_defs.h: -------------------------------------------------------------------------------- 1 | #ifndef FS_DEFS_H 2 | #define FS_DEFS_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include "common/common.h" 9 | 10 | /* FS defines and types */ 11 | #define FS_MAX_LOCALPATH_SIZE 511 12 | #define FS_MAX_MOUNTPATH_SIZE 128 13 | #define FS_MAX_FULLPATH_SIZE (FS_MAX_LOCALPATH_SIZE + FS_MAX_MOUNTPATH_SIZE) 14 | #define FS_MAX_ARGPATH_SIZE FS_MAX_FULLPATH_SIZE 15 | 16 | #define FS_STATUS_OK 0 17 | #define FS_STATUS_EOF -2 18 | #define FS_STATUS_FATAL_ERROR -0x400 19 | #define FS_RET_UNSUPPORTED_CMD 0x0400 20 | #define FS_RET_NO_ERROR 0x0000 21 | #define FS_RET_ALL_ERROR (uint32_t)(-1) 22 | 23 | #define FS_IO_BUFFER_ALIGN 64 24 | 25 | #define FS_STAT_FLAG_IS_DIRECTORY 0x80000000 26 | 27 | /* max length of file/dir name */ 28 | #define FS_MAX_ENTNAME_SIZE 256 29 | 30 | #define FS_SOURCETYPE_EXTERNAL 0 31 | #define FS_SOURCETYPE_HFIO 1 32 | 33 | #define FS_MOUNT_SOURCE_SIZE 0x300 34 | #define FS_CLIENT_SIZE 0x1700 35 | #define FS_CMD_BLOCK_SIZE 0xA80 36 | 37 | typedef struct FSClient_ { 38 | uint8_t buffer[FS_CLIENT_SIZE]; 39 | } FSClient; 40 | 41 | typedef struct FSCmdBlock_ { 42 | uint8_t buffer[FS_CMD_BLOCK_SIZE]; 43 | } FSCmdBlock; 44 | 45 | typedef struct { 46 | uint32_t flag; 47 | uint32_t permission; 48 | uint32_t owner_id; 49 | uint32_t group_id; 50 | uint32_t size; 51 | uint32_t alloc_size; 52 | uint64_t quota_size; 53 | uint32_t ent_id; 54 | uint64_t ctime; 55 | uint64_t mtime; 56 | uint8_t attributes[48]; 57 | } __attribute__((packed)) FSStat; 58 | 59 | typedef struct { 60 | FSStat stat; 61 | char name[FS_MAX_ENTNAME_SIZE]; 62 | } FSDirEntry; 63 | 64 | typedef void (*FSAsyncCallback)(FSClient * pClient, FSCmdBlock * pCmd, int32_t result, void *context); 65 | typedef struct { 66 | FSAsyncCallback userCallback; 67 | void *userContext; 68 | OSMessageQueue *ioMsgQueue; 69 | } FSAsyncParams; 70 | 71 | typedef struct { 72 | void* data; // pointer to a FSAsyncResult; 73 | uint32_t unkwn1; 74 | uint32_t unkwn2; 75 | uint32_t unkwn3; // always 0x08 76 | } __attribute__((packed)) FSMessage; 77 | 78 | typedef struct FSAsyncResult_ { 79 | FSAsyncParams userParams; 80 | FSMessage ioMsg; 81 | 82 | FSClient * client; 83 | FSCmdBlock * block; 84 | uint32_t result; 85 | } FSAsyncResult; 86 | 87 | #ifdef __cplusplus 88 | } 89 | #endif 90 | 91 | #endif /* FS_DEFS_H */ 92 | 93 | -------------------------------------------------------------------------------- /src/fat/bit_ops.h: -------------------------------------------------------------------------------- 1 | /* 2 | bit_ops.h 3 | Functions for dealing with conversion of data between types 4 | 5 | Copyright (c) 2006 Michael "Chishm" Chisholm 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation and/or 14 | other materials provided with the distribution. 15 | 3. The name of the author may not be used to endorse or promote products derived 16 | from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 20 | AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 26 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef _BIT_OPS_H 30 | #define _BIT_OPS_H 31 | 32 | #include 33 | 34 | /*----------------------------------------------------------------- 35 | Functions to deal with little endian values stored in uint8_t arrays 36 | -----------------------------------------------------------------*/ 37 | static inline uint16_t uint8_t_array_to_uint16_t (const uint8_t* item, int offset) { 38 | return ( item[offset] | (item[offset + 1] << 8)); 39 | } 40 | 41 | static inline uint32_t uint8_t_array_to_uint32_t (const uint8_t* item, int offset) { 42 | return ( item[offset] | (item[offset + 1] << 8) | (item[offset + 2] << 16) | (item[offset + 3] << 24)); 43 | } 44 | 45 | static inline void uint16_t_to_uint8_tarray (uint8_t* item, int offset, uint16_t value) { 46 | item[offset] = (uint8_t) value; 47 | item[offset + 1] = (uint8_t)(value >> 8); 48 | } 49 | 50 | static inline void uint32_t_to_uint8_tarray (uint8_t* item, int offset, uint32_t value) { 51 | item[offset] = (uint8_t) value; 52 | item[offset + 1] = (uint8_t)(value >> 8); 53 | item[offset + 2] = (uint8_t)(value >> 16); 54 | item[offset + 3] = (uint8_t)(value >> 24); 55 | } 56 | 57 | #endif // _BIT_OPS_H 58 | -------------------------------------------------------------------------------- /src/dynamic_libs/padscore_functions.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2015 3 | * by Dimok 4 | * 5 | * This software is provided 'as-is', without any express or implied 6 | * warranty. In no event will the authors be held liable for any 7 | * damages arising from the use of this software. 8 | * 9 | * Permission is granted to anyone to use this software for any 10 | * purpose, including commercial applications, and to alter it and 11 | * redistribute it freely, subject to the following restrictions: 12 | * 13 | * 1. The origin of this software must not be misrepresented; you 14 | * must not claim that you wrote the original software. If you use 15 | * this software in a product, an acknowledgment in the product 16 | * documentation would be appreciated but is not required. 17 | * 18 | * 2. Altered source versions must be plainly marked as such, and 19 | * must not be misrepresented as being the original software. 20 | * 21 | * 3. This notice may not be removed or altered from any source 22 | * distribution. 23 | ***************************************************************************/ 24 | #include "os_functions.h" 25 | #include "padscore_functions.h" 26 | 27 | uint32_t padscore_handle __attribute__((section(".data"))) = 0; 28 | 29 | EXPORT_DECL(void, KPADInit, void); 30 | EXPORT_DECL(void, WPADInit, void); 31 | EXPORT_DECL(int32_t, WPADProbe, int32_t chan, uint32_t * pad_type); 32 | EXPORT_DECL(int32_t, WPADSetDataFormat, int32_t chan, int32_t format); 33 | EXPORT_DECL(void, WPADEnableURCC, int32_t enable); 34 | EXPORT_DECL(void, WPADRead, int32_t chan, void * data); 35 | EXPORT_DECL(int32_t, KPADRead, int32_t chan, KPADData * data, uint32_t size); 36 | EXPORT_DECL(int32_t, KPADReadEx, int32_t chan, KPADData * data, uint32_t size, int32_t *error); 37 | EXPORT_DECL(void,WPADSetAutoSleepTime,uint8_t minute); 38 | EXPORT_DECL(void,WPADDisconnect,int32_t chan); 39 | 40 | void InitAcquirePadScore(void) { 41 | if(coreinit_handle == 0) { 42 | InitAcquireOS(); 43 | }; 44 | OSDynLoad_Acquire("padscore.rpl", &padscore_handle); 45 | } 46 | 47 | void InitPadScoreFunctionPointers(void) { 48 | uint32_t *funcPointer = 0; 49 | InitAcquirePadScore(); 50 | 51 | OS_FIND_EXPORT(padscore_handle, WPADInit); 52 | OS_FIND_EXPORT(padscore_handle, KPADInit); 53 | OS_FIND_EXPORT(padscore_handle, WPADProbe); 54 | OS_FIND_EXPORT(padscore_handle, WPADSetDataFormat); 55 | OS_FIND_EXPORT(padscore_handle, WPADEnableURCC); 56 | OS_FIND_EXPORT(padscore_handle, WPADRead); 57 | OS_FIND_EXPORT(padscore_handle, KPADRead); 58 | OS_FIND_EXPORT(padscore_handle, KPADReadEx); 59 | OS_FIND_EXPORT(padscore_handle, WPADSetAutoSleepTime); 60 | OS_FIND_EXPORT(padscore_handle, WPADDisconnect); 61 | 62 | KPADInit(); 63 | WPADEnableURCC(1); 64 | } -------------------------------------------------------------------------------- /src/iosuhax/iosuhax_disc_interface.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2016 3 | * by Dimok 4 | * 5 | * This software is provided 'as-is', without any express or implied 6 | * warranty. In no event will the authors be held liable for any 7 | * damages arising from the use of this software. 8 | * 9 | * Permission is granted to anyone to use this software for any 10 | * purpose, including commercial applications, and to alter it and 11 | * redistribute it freely, subject to the following restrictions: 12 | * 13 | * 1. The origin of this software must not be misrepresented; you 14 | * must not claim that you wrote the original software. If you use 15 | * this software in a product, an acknowledgment in the product 16 | * documentation would be appreciated but is not required. 17 | * 18 | * 2. Altered source versions must be plainly marked as such, and 19 | * must not be misrepresented as being the original software. 20 | * 21 | * 3. This notice may not be removed or altered from any source 22 | * distribution. 23 | ***************************************************************************/ 24 | #ifndef _IOSUHAX_DISC_INTERFACE_H_ 25 | #define _IOSUHAX_DISC_INTERFACE_H_ 26 | 27 | #include 28 | #include 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | #define DEVICE_TYPE_WII_U_SD (('W'<<24)|('U'<<16)|('S'<<8)|'D') 35 | #define DEVICE_TYPE_WII_U_USB (('W'<<24)|('U'<<16)|('S'<<8)|'B') 36 | #define FEATURE_WII_U_SD 0x00001000 37 | #define FEATURE_WII_U_USB 0x00002000 38 | 39 | #ifndef OGC_DISC_IO_INCLUDE 40 | typedef uint32_t sec_t; 41 | 42 | #define FEATURE_MEDIUM_CANREAD 0x00000001 43 | #define FEATURE_MEDIUM_CANWRITE 0x00000002 44 | 45 | typedef bool (* FN_MEDIUM_STARTUP)(void) ; 46 | typedef bool (* FN_MEDIUM_ISINSERTED)(void) ; 47 | typedef bool (* FN_MEDIUM_READSECTORS)(uint32_t sector, uint32_t numSectors, void* buffer) ; 48 | typedef bool (* FN_MEDIUM_WRITESECTORS)(uint32_t sector, uint32_t numSectors, const void* buffer) ; 49 | typedef bool (* FN_MEDIUM_CLEARSTATUS)(void) ; 50 | typedef bool (* FN_MEDIUM_SHUTDOWN)(void) ; 51 | 52 | struct DISC_INTERFACE_STRUCT { 53 | unsigned long ioType ; 54 | unsigned long features ; 55 | FN_MEDIUM_STARTUP startup ; 56 | FN_MEDIUM_ISINSERTED isInserted ; 57 | FN_MEDIUM_READSECTORS readSectors ; 58 | FN_MEDIUM_WRITESECTORS writeSectors ; 59 | FN_MEDIUM_CLEARSTATUS clearStatus ; 60 | FN_MEDIUM_SHUTDOWN shutdown ; 61 | } ; 62 | 63 | typedef struct DISC_INTERFACE_STRUCT DISC_INTERFACE ; 64 | #endif 65 | 66 | extern const DISC_INTERFACE IOSUHAX_sdio_disc_interface; 67 | extern const DISC_INTERFACE IOSUHAX_usb_disc_interface; 68 | 69 | #ifdef __cplusplus 70 | } 71 | #endif 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /src/fat/lock.h: -------------------------------------------------------------------------------- 1 | /* 2 | lock.h 3 | 4 | Copyright (c) 2008 Sven Peter 5 | 6 | Redistribution and use in source and binary forms, with or without modification, 7 | are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, 10 | this list of conditions and the following disclaimer. 11 | 2. Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation and/or 13 | other materials provided with the distribution. 14 | 3. The name of the author may not be used to endorse or promote products derived 15 | from this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 18 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 19 | AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 20 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 25 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | */ 28 | 29 | #ifndef _LOCK_H 30 | #define _LOCK_H 31 | 32 | #include "common.h" 33 | 34 | #if defined(__wiiu__) && !defined(__WUT__) 35 | 36 | extern void (* OSInitMutex)(void* mutex); 37 | extern void (* OSLockMutex)(void* mutex); 38 | extern void (* OSUnlockMutex)(void* mutex); 39 | 40 | static inline void _FAT_lock_init(mutex_t *mutex) 41 | { 42 | OSInitMutex(mutex); 43 | } 44 | 45 | static inline void _FAT_lock_deinit(mutex_t *mutex) 46 | { 47 | (void)mutex; 48 | return; 49 | } 50 | 51 | static inline void _FAT_lock(mutex_t *mutex) 52 | { 53 | OSLockMutex(mutex); 54 | } 55 | 56 | static inline void _FAT_unlock(mutex_t *mutex) 57 | { 58 | OSUnlockMutex(mutex); 59 | } 60 | 61 | #elif defined(USE_LWP_LOCK) 62 | 63 | static inline void _FAT_lock_init(mutex_t *mutex) 64 | { 65 | LWP_MutexInit(mutex, false); 66 | } 67 | 68 | static inline void _FAT_lock_deinit(mutex_t *mutex) 69 | { 70 | LWP_MutexDestroy(*mutex); 71 | } 72 | 73 | static inline void _FAT_lock(mutex_t *mutex) 74 | { 75 | LWP_MutexLock(*mutex); 76 | } 77 | 78 | static inline void _FAT_unlock(mutex_t *mutex) 79 | { 80 | LWP_MutexUnlock(*mutex); 81 | } 82 | #else 83 | 84 | // We still need a blank lock type 85 | #ifndef mutex_t 86 | typedef int mutex_t; 87 | #endif 88 | 89 | void _FAT_lock_init(mutex_t *mutex); 90 | void _FAT_lock_deinit(mutex_t *mutex); 91 | void _FAT_lock(mutex_t *mutex); 92 | void _FAT_unlock(mutex_t *mutex); 93 | 94 | #endif // USE_LWP_LOCK 95 | 96 | 97 | #endif // _LOCK_H 98 | 99 | -------------------------------------------------------------------------------- /src/fat/fatdir.h: -------------------------------------------------------------------------------- 1 | /* 2 | fatdir.h 3 | 4 | Functions used by the newlib disc stubs to interface with 5 | this library 6 | 7 | Copyright (c) 2006 Michael "Chishm" Chisholm 8 | 9 | Redistribution and use in source and binary forms, with or without modification, 10 | are permitted provided that the following conditions are met: 11 | 12 | 1. Redistributions of source code must retain the above copyright notice, 13 | this list of conditions and the following disclaimer. 14 | 2. Redistributions in binary form must reproduce the above copyright notice, 15 | this list of conditions and the following disclaimer in the documentation and/or 16 | other materials provided with the distribution. 17 | 3. The name of the author may not be used to endorse or promote products derived 18 | from this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 21 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 22 | AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 28 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | 32 | #ifndef _FATDIR_H 33 | #define _FATDIR_H 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include "common.h" 40 | #include "directory.h" 41 | 42 | typedef struct { 43 | PARTITION* partition; 44 | DIR_ENTRY currentEntry; 45 | uint32_t startCluster; 46 | bool inUse; 47 | bool validEntry; 48 | } DIR_STATE_STRUCT; 49 | 50 | extern int _FAT_stat_r (struct _reent *r, const char *path, struct stat *st); 51 | 52 | extern int _FAT_link_r (struct _reent *r, const char *existing, const char *newLink); 53 | 54 | extern int _FAT_unlink_r (struct _reent *r, const char *name); 55 | 56 | extern int _FAT_chdir_r (struct _reent *r, const char *name); 57 | 58 | extern int _FAT_rename_r (struct _reent *r, const char *oldName, const char *newName); 59 | 60 | extern int _FAT_mkdir_r (struct _reent *r, const char *path, int mode); 61 | 62 | extern int _FAT_rmdir_r (struct _reent *r, const char *path); 63 | 64 | extern int _FAT_statvfs_r (struct _reent *r, const char *path, struct statvfs *buf); 65 | 66 | /* 67 | Directory iterator functions 68 | */ 69 | extern DIR_ITER* _FAT_diropen_r(struct _reent *r, DIR_ITER *dirState, const char *path); 70 | extern int _FAT_dirreset_r (struct _reent *r, DIR_ITER *dirState); 71 | extern int _FAT_dirnext_r (struct _reent *r, DIR_ITER *dirState, char *filename, struct stat *filestat); 72 | extern int _FAT_dirclose_r (struct _reent *r, DIR_ITER *dirState); 73 | 74 | 75 | #endif // _FATDIR_H 76 | -------------------------------------------------------------------------------- /src/fat/file_allocation_table.h: -------------------------------------------------------------------------------- 1 | /* 2 | file_allocation_table.h 3 | Reading, writing and manipulation of the FAT structure on 4 | a FAT partition 5 | 6 | Copyright (c) 2006 Michael "Chishm" Chisholm 7 | 8 | Redistribution and use in source and binary forms, with or without modification, 9 | are permitted provided that the following conditions are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright notice, 12 | this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the documentation and/or 15 | other materials provided with the distribution. 16 | 3. The name of the author may not be used to endorse or promote products derived 17 | from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 20 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 21 | AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 27 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef _FAT_H 31 | #define _FAT_H 32 | 33 | #include "common.h" 34 | #include "partition.h" 35 | 36 | #define CLUSTER_EOF_16 0xFFFF 37 | #define CLUSTER_EOF 0x0FFFFFFF 38 | #define CLUSTER_FREE 0x00000000 39 | #define CLUSTER_ROOT 0x00000000 40 | #define CLUSTER_FIRST 0x00000002 41 | #define CLUSTER_ERROR 0xFFFFFFFF 42 | 43 | #define CLUSTERS_PER_FAT12 4085 44 | #define CLUSTERS_PER_FAT16 65525 45 | 46 | 47 | uint32_t _FAT_fat_nextCluster(PARTITION* partition, uint32_t cluster); 48 | 49 | uint32_t _FAT_fat_linkFreeCluster(PARTITION* partition, uint32_t cluster); 50 | uint32_t _FAT_fat_linkFreeClusterCleared (PARTITION* partition, uint32_t cluster); 51 | 52 | bool _FAT_fat_clearLinks (PARTITION* partition, uint32_t cluster); 53 | 54 | uint32_t _FAT_fat_trimChain (PARTITION* partition, uint32_t startCluster, unsigned int chainLength); 55 | 56 | uint32_t _FAT_fat_lastCluster (PARTITION* partition, uint32_t cluster); 57 | 58 | unsigned int _FAT_fat_freeClusterCount (PARTITION* partition); 59 | 60 | static inline sec_t _FAT_fat_clusterToSector (PARTITION* partition, uint32_t cluster) { 61 | return (cluster >= CLUSTER_FIRST) ? 62 | ((cluster - CLUSTER_FIRST) * (sec_t)partition->sectorsPerCluster) + partition->dataStart : 63 | partition->rootDirStart; 64 | } 65 | 66 | static inline bool _FAT_fat_isValidCluster (PARTITION* partition, uint32_t cluster) { 67 | return (cluster >= CLUSTER_FIRST) && (cluster <= partition->fat.lastCluster /* This will catch CLUSTER_ERROR */); 68 | } 69 | 70 | #endif // _FAT_H 71 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WiiUFtpServer : a robust and optimized FTP server for the WiiU 2 | 3 | **EDIT : devs are interrupted. This version is for users running a CFW = MOCHA, HAXCHI or CBHC 4 | The code is not compatible with the latest devkitpro version ! 5 | Use the last release stable version (V12-1)** 6 | 7 | This branch use dynamic libs instead of WUT (creates a ELF file compatible only with "old" CFW such as Haxchi, Mocha or CBHC) 8 | Note that you can launch ELF files with Tiramisu (throught the Mii-maker). 9 | 10 |

11 | 12 |

13 | 14 | Based on ftpiiu but with the following issues fixed : 15 | - **connections failures and crashs** 16 | - extend supported clients list 17 | - file's dates (timestamps) 18 | - **file injection (add rights on files uploaded)** 19 | - remove the one slot limitation on upload and unlock up to **8 simultaneous transfers (download/upload)** 20 | - **much more faster than the original** 21 | 22 | 23 | https://user-images.githubusercontent.com/47532310/153688829-2e39085a-c96e-43cc-9c7a-caf48838b12e.mp4 24 | 25 | Few games such as WWHD check the save files'rights and refuse to import them if permissions rights are not set. 26 | 27 | WiiuFtpServer comes also with some **extra features** : 28 | 29 | - **support Wiiu PRO and Wiimote controllers** 30 | - **you can choose to disable or enable the power saving feature** 31 | - **enable / disable VERBOSE mode on server side** 32 | - **mount NAND paths only if you ask for it** 33 | 34 | **NOTES :** 35 | 36 | - No user/password requiered and **only one client is allowed** 37 | 38 | - The server does not implement the [MTDM](https://support.solarwinds.com/SuccessCenter/s/article/Enable-the-MDTM-command-to-preserve-the-original-time-stamp-of-uploaded-files?language=en_US) function (and so does not preserves files timestamps) but now displays the correct dates : 39 | 40 |

41 | 42 |

43 | 44 | - Recommended FTP client settings : 45 | - 90 sec for timeout which ensure to not timeout on transfer 46 | - 99 or unlimited retry number 47 | - 0 sec between retries 48 | - Auto : ASCII/bin 49 | - auto : IPV4 / V6 50 | - allow retry in active mode (full **active mode is not working**) 51 | 52 | - Under windows, enable long filenames support with setting to 1 the value of *HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem\LongPathsEnabled* because some files created by the Wii-U have a name with more than 128 characters (up to 170) and so the limit of 255 characters for the entire path can easily be reached. 53 | 54 | - I opened a ticket for FileZilla client that failed to transfer such files (https://trac.filezilla-project.org/ticket/12675#ticket) 55 | 56 | # 57 | # BUILD : 58 | 59 | (Binairies are available in the [Releases](https://github.com/Laf111/WiiUFtpServer/releases/latest) section) 60 | 61 | 62 | To build from scratch : 63 | 64 | - install [devkitPro](https://github.com/devkitPro/installer/releases/latest) (in DEVKITPRO_PATH) 65 | 66 | 67 | Launch "msys2\msys2_shell.bat" 68 | 69 | - export DEVKITPRO=$DEVKITPRO_PATH 70 | - cd to WiiUFtpServer folder 71 | - ./build.sh 72 | 73 | 74 | It creates a HBL App under \_sdCard\wiiu\apps\WiiUFtpServer. 75 | 76 | Then just copy the \_sdCard folder content to your SD card. 77 | 78 | # 79 | # KNOWN ISSUES : 80 | 81 | When dumping games for CEMU, just ignore those errors (CEMU does not use them). 82 | - libFat is used because of very poor performance on SDCard transfers using only libIOSUHAX 83 | -------------------------------------------------------------------------------- /src/system/memory.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2015 Dimok 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | ****************************************************************************/ 17 | #ifndef __MEMORY_H_ 18 | #define __MEMORY_H_ 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | #include 25 | 26 | #define FlushBlock(addr) asm volatile("dcbf %0, %1\n" \ 27 | "icbi %0, %1\n" \ 28 | "sync\n" \ 29 | "eieio\n" \ 30 | "isync\n" \ 31 | : \ 32 | :"r"(0), "r"(((addr) & ~31)) \ 33 | :"memory", "ctr", "lr", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12" \ 34 | ); 35 | 36 | #define LIMIT(x, min, max) \ 37 | ({ \ 38 | typeof( x ) _x = x; \ 39 | typeof( min ) _min = min; \ 40 | typeof( max ) _max = max; \ 41 | ( ( ( _x ) < ( _min ) ) ? ( _min ) : ( ( _x ) > ( _max ) ) ? ( _max) : ( _x ) ); \ 42 | }) 43 | 44 | #define DegToRad(a) ( (a) * 0.01745329252f ) 45 | #define RadToDeg(a) ( (a) * 57.29577951f ) 46 | 47 | #define ALIGN4(x) (((x) + 3) & ~3) 48 | #define ALIGN32(x) (((x) + 31) & ~31) 49 | 50 | // those work only in powers of 2 51 | #define ROUNDDOWN(val, align) ((val) & ~(align-1)) 52 | #define ROUNDUP(val, align) ROUNDDOWN(((val) + (align-1)), align) 53 | 54 | #define le16(i) ((((u16) ((i) & 0xFF)) << 8) | ((u16) (((i) & 0xFF00) >> 8))) 55 | #define le32(i) ((((u32)le16((i) & 0xFFFF)) << 16) | ((u32)le16(((i) & 0xFFFF0000) >> 16))) 56 | #define le64(i) ((((u64)le32((i) & 0xFFFFFFFFLL)) << 32) | ((u64)le32(((i) & 0xFFFFFFFF00000000LL) >> 32))) 57 | 58 | void memoryInitialize(void); 59 | void memoryRelease(void); 60 | 61 | void * MEM2_alloc(unsigned int size, unsigned int align); 62 | void MEM2_free(void *ptr); 63 | 64 | void * MEM1_alloc(unsigned int size, unsigned int align); 65 | void MEM1_free(void *ptr); 66 | 67 | void * MEMBucket_alloc(unsigned int size, unsigned int align); 68 | void MEMBucket_free(void *ptr); 69 | 70 | #ifdef __cplusplus 71 | } 72 | #endif 73 | 74 | #endif // __MEMORY_H_ 75 | -------------------------------------------------------------------------------- /src/fat/common.h: -------------------------------------------------------------------------------- 1 | /* 2 | common.h 3 | Common definitions and included files for the FATlib 4 | 5 | Copyright (c) 2006 Michael "Chishm" Chisholm 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation and/or 14 | other materials provided with the distribution. 15 | 3. The name of the author may not be used to endorse or promote products derived 16 | from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 20 | AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 26 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef _COMMON_H 30 | #define _COMMON_H 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | // When compiling for NDS, make sure NDS is defined 37 | #ifndef NDS 38 | #if defined ARM9 || defined ARM7 39 | #define NDS 40 | #endif 41 | #endif 42 | 43 | // Platform specific includes 44 | #if defined (__wiiu__) 45 | #include 46 | typedef uint8_t uint8_t; 47 | typedef uint16_t uint16_t; 48 | typedef int32_t int32_t; 49 | typedef uint32_t uint32_t; 50 | 51 | // The mutex needs 44 bytes. See 52 | // https://github.com/decaf-emu/wut/blob/fe9e0b208cbc0b970e9a6035290cf698fe984242/include/coreinit/mutex.h#L63 53 | #if !defined (__WUT__) 54 | typedef struct mutex_t { 55 | unsigned char byte[44]; 56 | } mutex_t; 57 | #endif 58 | 59 | #elif defined(__gamecube__) || defined (__wii__) 60 | #include 61 | #include 62 | #include 63 | #elif defined(NDS) 64 | #include 65 | #include 66 | #include 67 | #elif defined(GBA) 68 | #include 69 | #include 70 | #elif defined(GP2X) 71 | #include 72 | #include 73 | #endif 74 | 75 | // Platform specific options 76 | #if defined (__wiiu__) 77 | #define DEFAULT_CACHE_PAGES 512 78 | #define DEFAULT_SECTORS_PAGE 128 79 | // #define USE_RTC_TIME 80 | #elif defined (__wii__) 81 | #define DEFAULT_CACHE_PAGES 4 82 | #define DEFAULT_SECTORS_PAGE 64 83 | #define USE_LWP_LOCK 84 | #define USE_RTC_TIME 85 | #elif defined (__gamecube__) 86 | #define DEFAULT_CACHE_PAGES 4 87 | #define DEFAULT_SECTORS_PAGE 64 88 | #define USE_LWP_LOCK 89 | #define USE_RTC_TIME 90 | #elif defined (NDS) 91 | #define DEFAULT_CACHE_PAGES 16 92 | #define DEFAULT_SECTORS_PAGE 8 93 | #define USE_RTC_TIME 94 | #elif defined (GBA) 95 | #define DEFAULT_CACHE_PAGES 2 96 | #define DEFAULT_SECTORS_PAGE 8 97 | #define LIMIT_SECTORS 128 98 | #elif defined (GP2X) 99 | #define DEFAULT_CACHE_PAGES 16 100 | #define DEFAULT_SECTORS_PAGE 8 101 | #endif 102 | 103 | #endif // _COMMON_H 104 | -------------------------------------------------------------------------------- /src/fat/filetime.c: -------------------------------------------------------------------------------- 1 | /* 2 | filetime.c 3 | Conversion of file time and date values to various other types 4 | 5 | Copyright (c) 2006 Michael "Chishm" Chisholm 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation and/or 14 | other materials provided with the distribution. 15 | 3. The name of the author may not be used to endorse or promote products derived 16 | from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 20 | AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 26 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | 30 | #include 31 | #include "filetime.h" 32 | #include "common.h" 33 | 34 | #define MAX_HOUR 23 35 | #define MAX_MINUTE 59 36 | #define MAX_SECOND 59 37 | 38 | #define MAX_MONTH 11 39 | #define MIN_MONTH 0 40 | #define MAX_DAY 31 41 | #define MIN_DAY 1 42 | 43 | uint16_t _FAT_filetime_getTimeFromRTC (void) { 44 | #ifdef USE_RTC_TIME 45 | struct tm timeParts; 46 | time_t epochTime; 47 | 48 | if (time(&epochTime) == (time_t)-1) { 49 | return 0; 50 | } 51 | localtime_r(&epochTime, &timeParts); 52 | 53 | // Check that the values are all in range. 54 | // If they are not, return 0 (no timestamp) 55 | if ((timeParts.tm_hour < 0) || (timeParts.tm_hour > MAX_HOUR)) return 0; 56 | if ((timeParts.tm_min < 0) || (timeParts.tm_min > MAX_MINUTE)) return 0; 57 | if ((timeParts.tm_sec < 0) || (timeParts.tm_sec > MAX_SECOND)) return 0; 58 | 59 | return ( 60 | ((timeParts.tm_hour & 0x1F) << 11) | 61 | ((timeParts.tm_min & 0x3F) << 5) | 62 | ((timeParts.tm_sec >> 1) & 0x1F) 63 | ); 64 | #else 65 | return 0; 66 | #endif 67 | } 68 | 69 | 70 | uint16_t _FAT_filetime_getDateFromRTC (void) { 71 | #ifdef USE_RTC_TIME 72 | struct tm timeParts; 73 | time_t epochTime; 74 | 75 | if (time(&epochTime) == (time_t)-1) { 76 | return 0; 77 | } 78 | localtime_r(&epochTime, &timeParts); 79 | 80 | if ((timeParts.tm_mon < MIN_MONTH) || (timeParts.tm_mon > MAX_MONTH)) return 0; 81 | if ((timeParts.tm_mday < MIN_DAY) || (timeParts.tm_mday > MAX_DAY)) return 0; 82 | 83 | return ( 84 | (((timeParts.tm_year - 80) & 0x7F) <<9) | // Adjust for MS-FAT base year (1980 vs 1900 for tm_year) 85 | (((timeParts.tm_mon + 1) & 0xF) << 5) | 86 | (timeParts.tm_mday & 0x1F) 87 | ); 88 | #else 89 | return 0; 90 | #endif 91 | } 92 | 93 | time_t _FAT_filetime_to_time_t (uint16_t t, uint16_t d) { 94 | struct tm timeParts; 95 | 96 | timeParts.tm_hour = t >> 11; 97 | timeParts.tm_min = (t >> 5) & 0x3F; 98 | timeParts.tm_sec = (t & 0x1F) << 1; 99 | 100 | timeParts.tm_mday = d & 0x1F; 101 | timeParts.tm_mon = ((d >> 5) & 0x0F) - 1; 102 | timeParts.tm_year = (d >> 9) + 80; 103 | 104 | timeParts.tm_isdst = 0; 105 | 106 | return mktime(&timeParts); 107 | } 108 | -------------------------------------------------------------------------------- /src/fat/fatfile.h: -------------------------------------------------------------------------------- 1 | /* 2 | fatfile.h 3 | 4 | Functions used by the newlib disc stubs to interface with 5 | this library 6 | 7 | Copyright (c) 2006 Michael "Chishm" Chisholm 8 | 9 | Redistribution and use in source and binary forms, with or without modification, 10 | are permitted provided that the following conditions are met: 11 | 12 | 1. Redistributions of source code must retain the above copyright notice, 13 | this list of conditions and the following disclaimer. 14 | 2. Redistributions in binary form must reproduce the above copyright notice, 15 | this list of conditions and the following disclaimer in the documentation and/or 16 | other materials provided with the distribution. 17 | 3. The name of the author may not be used to endorse or promote products derived 18 | from this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 21 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 22 | AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 28 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | 32 | #ifndef _FATFILE_H 33 | #define _FATFILE_H 34 | 35 | #include 36 | #include 37 | 38 | #include "common.h" 39 | #include "partition.h" 40 | #include "directory.h" 41 | 42 | #define FILE_MAX_SIZE ((uint32_t)0xFFFFFFFF) // 4GiB - 1B 43 | 44 | typedef struct { 45 | uint32_t cluster; 46 | sec_t sector; 47 | int32_t byte; 48 | } FILE_POSITION; 49 | 50 | struct _FILE_STRUCT; 51 | 52 | struct _FILE_STRUCT { 53 | uint32_t filesize; 54 | uint32_t startCluster; 55 | uint32_t currentPosition; 56 | FILE_POSITION rwPosition; 57 | FILE_POSITION appendPosition; 58 | DIR_ENTRY_POSITION dirEntryStart; // Points to the start of the LFN entries of a file, or the alias for no LFN 59 | DIR_ENTRY_POSITION dirEntryEnd; // Always points to the file's alias entry 60 | PARTITION* partition; 61 | struct _FILE_STRUCT* prevOpenFile; // The previous entry in a double-linked list of open files 62 | struct _FILE_STRUCT* nextOpenFile; // The next entry in a double-linked list of open files 63 | bool read; 64 | bool write; 65 | bool append; 66 | bool inUse; 67 | bool modified; 68 | }; 69 | 70 | typedef struct _FILE_STRUCT FILE_STRUCT; 71 | 72 | int _FAT_open_r (struct _reent *r, void *fileStruct, const char *path, int flags, int mode); 73 | 74 | int _FAT_close_r (struct _reent *r, void *fd); 75 | 76 | ssize_t _FAT_write_r (struct _reent *r,void *fd, const char *ptr, size_t len); 77 | 78 | ssize_t _FAT_read_r (struct _reent *r, void *fd, char *ptr, size_t len); 79 | 80 | off_t _FAT_seek_r (struct _reent *r, void *fd, off_t pos, int dir); 81 | 82 | int _FAT_fstat_r (struct _reent *r, void *fd, struct stat *st); 83 | 84 | int _FAT_stat_r (struct _reent *r, const char *path, struct stat *st); 85 | 86 | int _FAT_link_r (struct _reent *r, const char *existing, const char *newLink); 87 | 88 | int _FAT_chdir_r (struct _reent *r, const char *name); 89 | 90 | int _FAT_rename_r (struct _reent *r, const char *oldName, const char *newName); 91 | 92 | int _FAT_ftruncate_r (struct _reent *r, void *fd, off_t len); 93 | 94 | int _FAT_fsync_r (struct _reent *r, void *fd); 95 | 96 | /* 97 | Synchronizes the file data to disc. 98 | Does no locking of its own -- lock the partition before calling. 99 | Returns 0 on success, an error code on failure. 100 | */ 101 | extern int _FAT_syncToDisc (FILE_STRUCT* file); 102 | 103 | #endif // _FATFILE_H 104 | -------------------------------------------------------------------------------- /src/fat/disc.h: -------------------------------------------------------------------------------- 1 | /* 2 | disc.h 3 | Interface to the low level disc functions. Used by the higher level 4 | file system code. 5 | 6 | Copyright (c) 2006 Michael "Chishm" Chisholm 7 | 8 | Redistribution and use in source and binary forms, with or without modification, 9 | are permitted provided that the following conditions are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright notice, 12 | this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the documentation and/or 15 | other materials provided with the distribution. 16 | 3. The name of the author may not be used to endorse or promote products derived 17 | from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 20 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 21 | AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 27 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | #ifndef _DISC_H 30 | #define _DISC_H 31 | 32 | #include "common.h" 33 | 34 | /* 35 | A list of all default devices to try at startup, 36 | terminated by a {NULL,NULL} entry. 37 | */ 38 | typedef struct { 39 | const char* name; 40 | const DISC_INTERFACE* (*getInterface)(void); 41 | } INTERFACE_ID; 42 | extern const INTERFACE_ID _FAT_disc_interfaces[]; 43 | 44 | /* 45 | Check if a disc is inserted 46 | Return true if a disc is inserted and ready, false otherwise 47 | */ 48 | static inline bool _FAT_disc_isInserted (const DISC_INTERFACE* disc) { 49 | return disc->isInserted(); 50 | } 51 | 52 | /* 53 | Read numSectors sectors from a disc, starting at sector. 54 | numSectors is between 1 and LIMIT_SECTORS if LIMIT_SECTORS is defined, 55 | else it is at least 1 56 | sector is 0 or greater 57 | buffer is a pointer to the memory to fill 58 | */ 59 | static inline bool _FAT_disc_readSectors (const DISC_INTERFACE* disc, sec_t sector, sec_t numSectors, void* buffer) { 60 | return disc->readSectors (sector, numSectors, buffer); 61 | } 62 | 63 | /* 64 | Write numSectors sectors to a disc, starting at sector. 65 | numSectors is between 1 and LIMIT_SECTORS if LIMIT_SECTORS is defined, 66 | else it is at least 1 67 | sector is 0 or greater 68 | buffer is a pointer to the memory to read from 69 | */ 70 | static inline bool _FAT_disc_writeSectors (const DISC_INTERFACE* disc, sec_t sector, sec_t numSectors, const void* buffer) { 71 | return disc->writeSectors (sector, numSectors, buffer); 72 | } 73 | 74 | /* 75 | Reset the card back to a ready state 76 | */ 77 | static inline bool _FAT_disc_clearStatus (const DISC_INTERFACE* disc) { 78 | return disc->clearStatus(); 79 | } 80 | 81 | /* 82 | Initialise the disc to a state ready for data reading or writing 83 | */ 84 | static inline bool _FAT_disc_startup (const DISC_INTERFACE* disc) { 85 | return disc->startup(); 86 | } 87 | 88 | /* 89 | Put the disc in a state ready for power down. 90 | Complete any pending writes and disable the disc if necessary 91 | */ 92 | static inline bool _FAT_disc_shutdown (const DISC_INTERFACE* disc) { 93 | return disc->shutdown(); 94 | } 95 | 96 | /* 97 | Return a 32 bit value unique to each type of interface 98 | */ 99 | static inline uint32_t _FAT_disc_hostType (const DISC_INTERFACE* disc) { 100 | return disc->ioType; 101 | } 102 | 103 | /* 104 | Return a 32 bit value that specifies the capabilities of the disc 105 | */ 106 | static inline uint32_t _FAT_disc_features (const DISC_INTERFACE* disc) { 107 | return disc->features; 108 | } 109 | 110 | #endif // _DISC_H 111 | -------------------------------------------------------------------------------- /src/fat/partition.h: -------------------------------------------------------------------------------- 1 | /* 2 | partition.h 3 | Functions for mounting and dismounting partitions 4 | on various block devices. 5 | 6 | Copyright (c) 2006 Michael "Chishm" Chisholm 7 | 8 | Redistribution and use in source and binary forms, with or without modification, 9 | are permitted provided that the following conditions are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright notice, 12 | this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the documentation and/or 15 | other materials provided with the distribution. 16 | 3. The name of the author may not be used to endorse or promote products derived 17 | from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 20 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 21 | AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 27 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef _PARTITION_H 31 | #define _PARTITION_H 32 | 33 | #include "common.h" 34 | #include "cache.h" 35 | #include "lock.h" 36 | 37 | #define MIN_SECTOR_SIZE 512 38 | #define MAX_SECTOR_SIZE 4096 39 | 40 | // Filesystem type 41 | typedef enum {FS_UNKNOWN, FS_FAT12, FS_FAT16, FS_FAT32} FS_TYPE; 42 | 43 | typedef struct { 44 | sec_t fatStart; 45 | uint32_t sectorsPerFat; 46 | uint32_t lastCluster; 47 | uint32_t firstFree; 48 | uint32_t numberFreeCluster; 49 | uint32_t numberLastAllocCluster; 50 | } FAT; 51 | 52 | typedef struct { 53 | const DISC_INTERFACE* disc; 54 | CACHE* cache; 55 | // Info about the partition 56 | FS_TYPE filesysType; 57 | uint64_t totalSize; 58 | sec_t rootDirStart; 59 | uint32_t rootDirCluster; 60 | uint32_t numberOfSectors; 61 | sec_t dataStart; 62 | uint32_t bytesPerSector; 63 | uint32_t sectorsPerCluster; 64 | uint32_t bytesPerCluster; 65 | uint32_t fsInfoSector; 66 | FAT fat; 67 | // Values that may change after construction 68 | uint32_t cwdCluster; // Current working directory cluster 69 | int openFileCount; 70 | struct _FILE_STRUCT* firstOpenFile; // The start of a linked list of files 71 | mutex_t lock; // A lock for partition operations 72 | bool readOnly; // If this is set, then do not try writing to the disc 73 | char label[12]; // Volume label 74 | } PARTITION; 75 | 76 | /* 77 | Mount the supplied device and return a pointer to the struct necessary to use it 78 | */ 79 | PARTITION* _FAT_partition_constructor (const DISC_INTERFACE* disc, uint32_t cacheSize, uint32_t SectorsPerPage, sec_t startSector); 80 | 81 | /* 82 | Dismount the device and free all structures used. 83 | Will also attempt to synchronise all open files to disc. 84 | */ 85 | void _FAT_partition_destructor (PARTITION* partition); 86 | 87 | /* 88 | Return the partition specified in a path, as taken from the devoptab. 89 | */ 90 | PARTITION* _FAT_partition_getPartitionFromPath (const char* path); 91 | 92 | /* 93 | Create the fs info sector. 94 | */ 95 | void _FAT_partition_createFSinfo(PARTITION * partition); 96 | 97 | /* 98 | Read the fs info sector data. 99 | */ 100 | void _FAT_partition_readFSinfo(PARTITION * partition); 101 | 102 | /* 103 | Write the fs info sector data. 104 | */ 105 | void _FAT_partition_writeFSinfo(PARTITION * partition); 106 | 107 | #endif // _PARTITION_H 108 | -------------------------------------------------------------------------------- /src/iosuhax/iosuhax.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2016 3 | * by Dimok 4 | * 5 | * This software is provided 'as-is', without any express or implied 6 | * warranty. In no event will the authors be held liable for any 7 | * damages arising from the use of this software. 8 | * 9 | * Permission is granted to anyone to use this software for any 10 | * purpose, including commercial applications, and to alter it and 11 | * redistribute it freely, subject to the following restrictions: 12 | * 13 | * 1. The origin of this software must not be misrepresented; you 14 | * must not claim that you wrote the original software. If you use 15 | * this software in a product, an acknowledgment in the product 16 | * documentation would be appreciated but is not required. 17 | * 18 | * 2. Altered source versions must be plainly marked as such, and 19 | * must not be misrepresented as being the original software. 20 | * 21 | * 3. This notice may not be removed or altered from any source 22 | * distribution. 23 | ***************************************************************************/ 24 | #ifndef _LIB_IOSUHAX_H_ 25 | #define _LIB_IOSUHAX_H_ 26 | 27 | #include 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | /* Legacy case: dynamic_libs */ 34 | #include 35 | #include 36 | 37 | /* Hide behind IOSUHAX types. One day these may be changed to mirror the wut 38 | types more closely. */ 39 | typedef FSStat IOSUHAX_FSA_Stat; 40 | #define IOSUHAX_FSA_STAT_IS_DYNAMICLIBS 41 | 42 | typedef FSDirEntry IOSUHAX_FSA_DirectoryEntry; 43 | #define IOSUHAX_FSA_DIRECTORYENTRY_IS_DYNAMICLIBS 44 | 45 | #define FSA_MOUNTFLAGS_BINDMOUNT (1 << 0) 46 | #define FSA_MOUNTFLAGS_GLOBAL (1 << 1) 47 | 48 | int IOSUHAX_Open(const char *dev); // if dev == NULL the default path /dev/iosuhax will be used 49 | int IOSUHAX_Close(void); 50 | 51 | int IOSUHAX_memwrite(uint32_t address, const uint8_t * buffer, uint32_t size); // IOSU external input 52 | int IOSUHAX_memread(uint32_t address, uint8_t * out_buffer, uint32_t size); // IOSU external output 53 | int IOSUHAX_memcpy(uint32_t dst, uint32_t src, uint32_t size); // IOSU internal memcpy only 54 | 55 | int IOSUHAX_SVC(uint32_t svc_id, uint32_t * args, uint32_t arg_cnt); 56 | 57 | int IOSUHAX_FSA_Open(); 58 | int IOSUHAX_FSA_Close(int fsaFd); 59 | 60 | int IOSUHAX_FSA_Mount(int fsaFd, const char* device_path, const char* volume_path, uint32_t flags, const char* arg_string, int arg_string_len); 61 | int IOSUHAX_FSA_Unmount(int fsaFd, const char* path, uint32_t flags); 62 | int IOSUHAX_FSA_FlushVolume(int fsaFd, const char* volume_path); 63 | 64 | int IOSUHAX_FSA_GetDeviceInfo(int fsaFd, const char* device_path, int type, uint32_t* out_data); 65 | 66 | int IOSUHAX_FSA_MakeDir(int fsaFd, const char* path, uint32_t flags); 67 | int IOSUHAX_FSA_OpenDir(int fsaFd, const char* path, int* outHandle); 68 | int IOSUHAX_FSA_ReadDir(int fsaFd, int handle, IOSUHAX_FSA_DirectoryEntry* out_data); 69 | int IOSUHAX_FSA_RewindDir(int fsaFd, int dirHandle); 70 | int IOSUHAX_FSA_CloseDir(int fsaFd, int handle); 71 | int IOSUHAX_FSA_ChangeDir(int fsaFd, const char *path); 72 | 73 | int IOSUHAX_FSA_OpenFile(int fsaFd, const char* path, const char* mode, int* outHandle); 74 | int IOSUHAX_FSA_ReadFile(int fsaFd, void* data, uint32_t size, uint32_t cnt, int fileHandle, uint32_t flags); 75 | int IOSUHAX_FSA_WriteFile(int fsaFd, const void* data, uint32_t size, uint32_t cnt, int fileHandle, uint32_t flags); 76 | int IOSUHAX_FSA_StatFile(int fsaFd, int fileHandle, IOSUHAX_FSA_Stat* out_data); 77 | int IOSUHAX_FSA_CloseFile(int fsaFd, int fileHandle); 78 | int IOSUHAX_FSA_SetFilePos(int fsaFd, int fileHandle, uint32_t position); 79 | int IOSUHAX_FSA_GetStat(int fsaFd, const char *path, IOSUHAX_FSA_Stat* out_data); 80 | int IOSUHAX_FSA_Remove(int fsaFd, const char *path); 81 | int IOSUHAX_FSA_ChangeMode(int fsaFd, const char* path, int mode); 82 | 83 | int IOSUHAX_FSA_RawOpen(int fsaFd, const char* device_path, int* outHandle); 84 | int IOSUHAX_FSA_RawRead(int fsaFd, void* data, uint32_t block_size, uint32_t block_cnt, uint64_t sector_offset, int device_handle); 85 | int IOSUHAX_FSA_RawWrite(int fsaFd, const void* data, uint32_t block_size, uint32_t block_cnt, uint64_t sector_offset, int device_handle); 86 | int IOSUHAX_FSA_RawClose(int fsaFd, int device_handle); 87 | 88 | #ifdef __cplusplus 89 | } 90 | #endif 91 | 92 | #endif 93 | -------------------------------------------------------------------------------- /src/fat/disc.c: -------------------------------------------------------------------------------- 1 | /* 2 | disc.c 3 | Interface to the low level disc functions. Used by the higher level 4 | file system code. 5 | 6 | Copyright (c) 2008 Michael "Chishm" Chisholm 7 | 8 | Redistribution and use in source and binary forms, with or without modification, 9 | are permitted provided that the following conditions are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright notice, 12 | this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the documentation and/or 15 | other materials provided with the distribution. 16 | 3. The name of the author may not be used to endorse or promote products derived 17 | from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 20 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 21 | AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 27 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #include "disc.h" 31 | 32 | /* 33 | The list of interfaces consists of a series of name/interface pairs. 34 | The interface is returned via a simple function. This allows for 35 | platforms where the interface has to be "assembled" before it can 36 | be used, like DLDI on the NDS. For cases where a simple struct 37 | is available, wrapper functions are used. 38 | The list is terminated by a NULL/NULL entry. 39 | */ 40 | 41 | /* ====================== Wii U ====================== */ 42 | #if defined (__wiiu__) 43 | #include 44 | 45 | static const DISC_INTERFACE* get_io_wiiu_sd (void) { 46 | return &IOSUHAX_sdio_disc_interface; 47 | } 48 | 49 | static const DISC_INTERFACE* get_io_wiiu_usb (void) { 50 | return &IOSUHAX_usb_disc_interface; 51 | } 52 | 53 | const INTERFACE_ID _FAT_disc_interfaces[] = { 54 | {"sd", get_io_wiiu_sd}, 55 | {"usb", get_io_wiiu_usb}, 56 | {NULL, NULL} 57 | }; 58 | 59 | /* ====================== Wii ====================== */ 60 | #elif defined (__wii__) 61 | #include 62 | #include 63 | #include 64 | 65 | static const DISC_INTERFACE* get_io_wiisd (void) { 66 | return &__io_wiisd; 67 | } 68 | static const DISC_INTERFACE* get_io_usbstorage (void) { 69 | return &__io_usbstorage; 70 | } 71 | 72 | static const DISC_INTERFACE* get_io_gcsda (void) { 73 | return &__io_gcsda; 74 | } 75 | 76 | static const DISC_INTERFACE* get_io_gcsdb (void) { 77 | return &__io_gcsdb; 78 | } 79 | 80 | const INTERFACE_ID _FAT_disc_interfaces[] = { 81 | {"sd", get_io_wiisd}, 82 | {"usb", get_io_usbstorage}, 83 | {"carda", get_io_gcsda}, 84 | {"cardb", get_io_gcsdb}, 85 | {NULL, NULL} 86 | }; 87 | 88 | /* ==================== Gamecube ==================== */ 89 | #elif defined (__gamecube__) 90 | #include 91 | 92 | static const DISC_INTERFACE* get_io_gcsd2 (void) { 93 | return &__io_gcsd2; 94 | } 95 | 96 | static const DISC_INTERFACE* get_io_gcsdb (void) { 97 | return &__io_gcsdb; 98 | } 99 | 100 | static const DISC_INTERFACE* get_io_gcsda (void) { 101 | return &__io_gcsda; 102 | } 103 | 104 | const INTERFACE_ID _FAT_disc_interfaces[] = { 105 | {"sd", get_io_gcsd2}, 106 | {"carda", get_io_gcsda}, 107 | {"cardb", get_io_gcsdb}, 108 | {NULL, NULL} 109 | }; 110 | 111 | /* ====================== NDS ====================== */ 112 | #elif defined (NDS) 113 | #include 114 | #include 115 | #include 116 | 117 | const INTERFACE_ID _FAT_disc_interfaces[] = { 118 | {"sd", get_io_dsisd}, 119 | {"fat", dldiGetInternal}, 120 | {NULL, NULL} 121 | }; 122 | 123 | /* ====================== GBA ====================== */ 124 | #elif defined (GBA) 125 | #include 126 | 127 | const INTERFACE_ID _FAT_disc_interfaces[] = { 128 | {"fat", discGetInterface}, 129 | {NULL, NULL} 130 | }; 131 | 132 | /* ====================== GP2X ====================== */ 133 | #elif defined (GP2X) 134 | #include 135 | 136 | const INTERFACE_ID _FAT_disc_interfaces[] = { 137 | {"sd", get_io_gp2xsd}, 138 | {NULL, NULL} 139 | 140 | }; 141 | 142 | #endif 143 | 144 | -------------------------------------------------------------------------------- /src/net.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2008 Joseph Jordan 4 | 5 | This software is provided 'as-is', without any express or implied warranty. 6 | In no event will the authors be held liable for any damages arising from 7 | the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1.The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software in a 15 | product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 18 | 2.Altered source versions must be plainly marked as such, and must not be 19 | misrepresented as being the original software. 20 | 21 | 3.This notice may not be removed or altered from any source distribution. 22 | 23 | */ 24 | #ifndef _NET_H_ 25 | #define _NET_H_ 26 | 27 | #include 28 | 29 | #include 30 | 31 | #include "dynamic_libs/socket_functions.h" 32 | #include "ftp.h" 33 | 34 | #ifdef __cplusplus 35 | extern "C"{ 36 | #endif 37 | 38 | #define UNUSED __attribute__((unused)) 39 | 40 | #ifndef MIN 41 | #define MIN(x, y) ((x) < (y) ? (x) : (y)) 42 | #endif 43 | #ifndef MAX 44 | #define MAX(x, y) ((x) > (y) ? (x) : (y)) 45 | #endif 46 | 47 | #define NET_RETRY_TIME_STEP_MILLISECS 3900 48 | #define SO_RUSRBUF 0x10000 // enable userspace socket buffer 49 | #define SO_NOSLOWSTART 0x4000 // suppress slowstart 50 | #define TCP_NOACKDELAY 0x2002 // suppress delayed ACKs 51 | #define TCP_MAXSEG 0x2003 // set maximum segment size 52 | #define TCP_NODELAY 0x2004 // suppress TCP delay 53 | #define UNSCALED_BUFFER_SIZE (8*1024) 54 | 55 | #define SOCKET_BUFFER_SIZE (16*UNSCALED_BUFFER_SIZE) 56 | 57 | // socket memory buffer size = (2*sndBuffSize+2*rcvBuffSize) 58 | #define SOMEMOPT_BUFFER_SIZE (4*SOCKET_BUFFER_SIZE) 59 | 60 | // preallocated transfer buffer per connections 61 | // (using a small transfer buffer for UL reduce the number of simultaneuous transfers) 62 | // (using a large buffer for DL has the same effect) 63 | #define TRANSFER_BUFFER_SIZE (4*SOCKET_BUFFER_SIZE*16) 64 | 65 | typedef int32_t (*data_connection_callback)(int32_t data_socket, void *arg); 66 | struct connection_struct { 67 | int32_t socket; 68 | char representation_type; 69 | int32_t passive_socket; 70 | int32_t data_socket; 71 | char cwd[MAXPATHLEN]; 72 | char pending_rename[MAXPATHLEN]; 73 | off_t restart_marker; 74 | struct sockaddr_in address; 75 | bool authenticated; 76 | char buf[FTP_MSG_BUFFER_SIZE]; 77 | int32_t offset; 78 | bool data_connection_connected; 79 | data_connection_callback data_callback; 80 | void *data_connection_callback_arg; 81 | void (*data_connection_cleanup)(void *arg); 82 | uint32_t index; 83 | // file to transfer 84 | FILE *f; 85 | // for file transferring 86 | char fileName[MAXPATHLEN]; 87 | // volume path to the file 88 | char *volPath; 89 | // thread for transfering 90 | OSThread *transferThread; 91 | // preallocated transfer thread stack 92 | uint32_t transferThreadStack[FTP_TRANSFER_STACK_SIZE]; 93 | // buffer for transferring files 94 | char *transferBuffer; 95 | // for data transfer tracking 96 | int32_t dataTransferOffset; 97 | // last speed computed in MB/s 98 | float speed; 99 | // return code of send/recv functions 100 | int32_t bytesTransferred; 101 | uint64_t data_connection_timer; 102 | }; 103 | 104 | 105 | typedef struct connection_struct connection_t; 106 | 107 | void initialise_network(); 108 | void finalize_network(); 109 | int32_t network_socket(uint32_t domain,uint32_t type,uint32_t protocol); 110 | 111 | int32_t network_bind(int32_t s,struct sockaddr *name,int32_t namelen); 112 | 113 | int32_t network_listen(int32_t s,uint32_t backlog); 114 | 115 | int32_t network_accept(int32_t s,struct sockaddr *addr,int32_t *addrlen); 116 | 117 | int32_t network_connect(int32_t s,struct sockaddr *,int32_t); 118 | 119 | int32_t network_read(int32_t s,char *mem,int32_t len); 120 | 121 | int32_t network_close(int32_t s); 122 | 123 | uint32_t network_gethostip(); 124 | 125 | int32_t set_blocking(int32_t s, bool blocking); 126 | 127 | int32_t network_close_blocking(int32_t s); 128 | 129 | int32_t send_exact(int32_t s, char *buf, int32_t length); 130 | 131 | int32_t send_from_file(int32_t data_socket, connection_t* connection); 132 | 133 | int32_t recv_to_file(int32_t data_socket, connection_t* connection); 134 | 135 | 136 | #ifdef __cplusplus 137 | } 138 | #endif 139 | 140 | #endif /* _NET_H_ */ 141 | -------------------------------------------------------------------------------- /src/fat/fat.h: -------------------------------------------------------------------------------- 1 | /* 2 | fat.h 3 | Simple functionality for startup, mounting and unmounting of FAT-based devices. 4 | 5 | Copyright (c) 2006 - 2012 6 | Michael "Chishm" Chisholm 7 | Dave "WinterMute" Murphy 8 | 9 | Redistribution and use in source and binary forms, with or without modification, 10 | are permitted provided that the following conditions are met: 11 | 12 | 1. Redistributions of source code must retain the above copyright notice, 13 | this list of conditions and the following disclaimer. 14 | 2. Redistributions in binary form must reproduce the above copyright notice, 15 | this list of conditions and the following disclaimer in the documentation and/or 16 | other materials provided with the distribution. 17 | 3. The name of the author may not be used to endorse or promote products derived 18 | from this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 21 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 22 | AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 28 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | 32 | #ifndef _LIBFAT_H 33 | #define _LIBFAT_H 34 | 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | #include "libfatversion.h" 40 | 41 | // When compiling for NDS, make sure NDS is defined 42 | #ifndef NDS 43 | #if defined ARM9 || defined ARM7 44 | #define NDS 45 | #endif 46 | #endif 47 | 48 | #include 49 | 50 | #if defined (__wiiu__) 51 | # include 52 | #elif defined(__gamecube__) || defined (__wii__) 53 | # include 54 | #else 55 | # ifdef NDS 56 | # include 57 | # else 58 | # include 59 | # endif 60 | #endif 61 | 62 | 63 | /* 64 | Initialise any inserted block-devices. 65 | Add the fat device driver to the devoptab, making it available for standard file functions. 66 | cacheSize: The number of pages to allocate for each inserted block-device 67 | setAsDefaultDevice: if true, make this the default device driver for file operations 68 | cacheSectorsPage: The cache sectors per page value 69 | */ 70 | extern bool fatInitEx (uint32_t cacheSize, bool setAsDefaultDevice, uint32_t cacheSectorsPage); 71 | 72 | /* 73 | Calls fatInit cacheSectorsPage optimised for the host system. 74 | */ 75 | extern bool fatInit (uint32_t cacheSize, bool setAsDefaultDevice); 76 | 77 | /* 78 | Calls fatInit with setAsDefaultDevice = true and cacheSize optimised for the host system. 79 | */ 80 | extern bool fatInitDefault (void); 81 | 82 | /* 83 | Mount the device pointed to by interface, and set up a devoptab entry for it as "name:". 84 | You can then access the filesystem using "name:/". 85 | This will mount the active partition or the first valid partition on the disc, 86 | and will use a cache size optimized for the host system. 87 | */ 88 | extern bool fatMountSimple (const char* name, const DISC_INTERFACE* interface); 89 | 90 | /* 91 | Mount the device pointed to by interface, and set up a devoptab entry for it as "name:". 92 | You can then access the filesystem using "name:/". 93 | If startSector = 0, it will mount the active partition of the first valid partition on 94 | the disc. Otherwise it will try to mount the partition starting at startSector. 95 | cacheSize specifies the number of pages to allocate for the cache. 96 | This will not startup the disc, so you need to call interface->startup(); first. 97 | */ 98 | extern bool fatMount (const char* name, const DISC_INTERFACE* interface, sec_t startSector, uint32_t cacheSize, uint32_t SectorsPerPage); 99 | 100 | /* 101 | Unmount the partition specified by name. 102 | If there are open files, it will attempt to synchronise them to disc. 103 | */ 104 | extern void fatUnmount (const char* name); 105 | 106 | /* 107 | Get Volume Label 108 | */ 109 | extern void fatGetVolumeLabel (const char* name, char *label); 110 | 111 | // File attributes 112 | #define ATTR_ARCHIVE 0x20 // Archive 113 | #define ATTR_DIRECTORY 0x10 // Directory 114 | #define ATTR_VOLUME 0x08 // Volume 115 | #define ATTR_SYSTEM 0x04 // System 116 | #define ATTR_HIDDEN 0x02 // Hidden 117 | #define ATTR_READONLY 0x01 // Read only 118 | 119 | /* 120 | Methods to modify DOS File Attributes 121 | */ 122 | int FAT_getAttr(const char *file); 123 | int FAT_setAttr(const char *file, uint8_t attr ); 124 | 125 | #define LIBFAT_FEOS_MULTICWD 126 | 127 | #ifdef __cplusplus 128 | } 129 | #endif 130 | 131 | #endif // _LIBFAT_H 132 | -------------------------------------------------------------------------------- /src/fat/cache.h: -------------------------------------------------------------------------------- 1 | /* 2 | cache.h 3 | The cache is not visible to the user. It should be flushed 4 | when any file is closed or changes are made to the filesystem. 5 | 6 | This cache implements a least-used-page replacement policy. This will 7 | distribute sectors evenly over the pages, so if less than the maximum 8 | pages are used at once, they should all eventually remain in the cache. 9 | This also has the benefit of throwing out old sectors, so as not to keep 10 | too many stale pages around. 11 | 12 | Copyright (c) 2006 Michael "Chishm" Chisholm 13 | 14 | Redistribution and use in source and binary forms, with or without modification, 15 | are permitted provided that the following conditions are met: 16 | 17 | 1. Redistributions of source code must retain the above copyright notice, 18 | this list of conditions and the following disclaimer. 19 | 2. Redistributions in binary form must reproduce the above copyright notice, 20 | this list of conditions and the following disclaimer in the documentation and/or 21 | other materials provided with the distribution. 22 | 3. The name of the author may not be used to endorse or promote products derived 23 | from this software without specific prior written permission. 24 | 25 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 26 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 27 | AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 28 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 33 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #ifndef _CACHE_H 37 | #define _CACHE_H 38 | 39 | #include "common.h" 40 | #include "disc.h" 41 | 42 | typedef struct { 43 | sec_t sector; 44 | unsigned int count; 45 | unsigned int last_access; 46 | bool dirty; 47 | uint8_t* cache; 48 | } CACHE_ENTRY; 49 | 50 | typedef struct { 51 | const DISC_INTERFACE* disc; 52 | sec_t endOfPartition; 53 | unsigned int numberOfPages; 54 | unsigned int sectorsPerPage; 55 | unsigned int bytesPerSector; 56 | CACHE_ENTRY* cacheEntries; 57 | } CACHE; 58 | 59 | /* 60 | Read data from a sector in the cache 61 | If the sector is not in the cache, it will be swapped in 62 | offset is the position to start reading from 63 | size is the amount of data to read 64 | Precondition: offset + size <= BYTES_PER_READ 65 | */ 66 | bool _FAT_cache_readPartialSector (CACHE* cache, void* buffer, sec_t sector, unsigned int offset, size_t size); 67 | 68 | bool _FAT_cache_readLittleEndianValue (CACHE* cache, uint32_t *value, sec_t sector, unsigned int offset, int num_bytes); 69 | 70 | /* 71 | Write data to a sector in the cache 72 | If the sector is not in the cache, it will be swapped in. 73 | When the sector is swapped out, the data will be written to the disc 74 | offset is the position to start writing to 75 | size is the amount of data to write 76 | Precondition: offset + size <= BYTES_PER_READ 77 | */ 78 | bool _FAT_cache_writePartialSector (CACHE* cache, const void* buffer, sec_t sector, unsigned int offset, size_t size); 79 | 80 | bool _FAT_cache_writeLittleEndianValue (CACHE* cache, const uint32_t value, sec_t sector, unsigned int offset, int num_bytes); 81 | 82 | /* 83 | Write data to a sector in the cache, zeroing the sector first 84 | If the sector is not in the cache, it will be swapped in. 85 | When the sector is swapped out, the data will be written to the disc 86 | offset is the position to start writing to 87 | size is the amount of data to write 88 | Precondition: offset + size <= BYTES_PER_READ 89 | */ 90 | bool _FAT_cache_eraseWritePartialSector (CACHE* cache, const void* buffer, sec_t sector, unsigned int offset, size_t size); 91 | 92 | /* 93 | Read several sectors from the cache 94 | */ 95 | bool _FAT_cache_readSectors (CACHE* cache, sec_t sector, sec_t numSectors, void* buffer); 96 | 97 | /* 98 | Read a full sector from the cache 99 | */ 100 | static inline bool _FAT_cache_readSector (CACHE* cache, void* buffer, sec_t sector) { 101 | return _FAT_cache_readPartialSector (cache, buffer, sector, 0, cache->bytesPerSector); 102 | } 103 | 104 | /* 105 | Write a full sector to the cache 106 | */ 107 | static inline bool _FAT_cache_writeSector (CACHE* cache, const void* buffer, sec_t sector) { 108 | return _FAT_cache_writePartialSector (cache, buffer, sector, 0, cache->bytesPerSector); 109 | } 110 | 111 | bool _FAT_cache_writeSectors (CACHE* cache, sec_t sector, sec_t numSectors, const void* buffer); 112 | 113 | /* 114 | Write any dirty sectors back to disc and clear out the contents of the cache 115 | */ 116 | bool _FAT_cache_flush (CACHE* cache); 117 | 118 | /* 119 | Clear out the contents of the cache without writing any dirty sectors first 120 | */ 121 | void _FAT_cache_invalidate (CACHE* cache); 122 | 123 | CACHE* _FAT_cache_constructor (unsigned int numberOfPages, unsigned int sectorsPerPage, const DISC_INTERFACE* discInterface, sec_t endOfPartition, unsigned int bytesPerSector); 124 | 125 | void _FAT_cache_destructor (CACHE* cache); 126 | 127 | #endif // _CACHE_H 128 | 129 | -------------------------------------------------------------------------------- /src/dynamic_libs/socket_functions.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2015 3 | * by Dimok 4 | * 5 | * This software is provided 'as-is', without any express or implied 6 | * warranty. In no event will the authors be held liable for any 7 | * damages arising from the use of this software. 8 | * 9 | * Permission is granted to anyone to use this software for any 10 | * purpose, including commercial applications, and to alter it and 11 | * redistribute it freely, subject to the following restrictions: 12 | * 13 | * 1. The origin of this software must not be misrepresented; you 14 | * must not claim that you wrote the original software. If you use 15 | * this software in a product, an acknowledgment in the product 16 | * documentation would be appreciated but is not required. 17 | * 18 | * 2. Altered source versions must be plainly marked as such, and 19 | * must not be misrepresented as being the original software. 20 | * 21 | * 3. This notice may not be removed or altered from any source 22 | * distribution. 23 | ***************************************************************************/ 24 | #include 25 | #include 26 | 27 | #include "os_functions.h" 28 | #include "socket_functions.h" 29 | 30 | #define SOCKLIB_BUFSIZE MAX_NET_BUFFER_SIZE*4 // For send & receive + double buffering 31 | 32 | #define NET_STACK_SIZE 0x2000 33 | 34 | extern void display(const char *format, ...); 35 | 36 | uint32_t hostIpAddress = 0; 37 | 38 | uint32_t nsysnet_handle __attribute__((section(".data"))) = 0; 39 | 40 | EXPORT_DECL(int32_t, socket_lib_init, void); 41 | EXPORT_DECL(int32_t, socket_lib_finish, void); 42 | EXPORT_DECL(int32_t, socket, int32_t domain, int32_t type, int32_t protocol); 43 | EXPORT_DECL(int32_t, socketclose, int32_t s); 44 | EXPORT_DECL(int32_t, shutdown, int32_t s, int32_t how); 45 | EXPORT_DECL(int32_t, connect, int32_t s, void *addr, int32_t addrlen); 46 | EXPORT_DECL(int32_t, bind, int32_t s,struct sockaddr *name,int32_t namelen); 47 | EXPORT_DECL(int32_t, listen, int32_t s,uint32_t backlog); 48 | EXPORT_DECL(int32_t, accept, int32_t s,struct sockaddr *addr,int32_t *addrlen); 49 | EXPORT_DECL(int32_t, send, int32_t s, const void *buffer, int32_t size, int32_t flags); 50 | EXPORT_DECL(int32_t, recv, int32_t s, void *buffer, int32_t size, int32_t flags); 51 | EXPORT_DECL(int32_t, recvfrom,int32_t sockfd, void *buf, int32_t len, int32_t flags,struct sockaddr *src_addr, int32_t *addrlen); 52 | EXPORT_DECL(int32_t, sendto, int32_t s, const void *buffer, int32_t size, int32_t flags, const struct sockaddr *dest, int32_t dest_len); 53 | EXPORT_DECL(int32_t, setsockopt, int32_t s, int32_t level, int32_t optname, void *optval, int32_t optlen); 54 | EXPORT_DECL(int32_t, getsockopt, int32_t s, int32_t level, int32_t optname, void *optval, int32_t optlen); 55 | EXPORT_DECL(int32_t, somemopt, int type, void *buf, size_t bufsize, int unk); 56 | 57 | EXPORT_DECL(char *, inet_ntoa, struct in_addr in); 58 | EXPORT_DECL(int32_t, inet_aton, const char *cp, struct in_addr *inp); 59 | EXPORT_DECL(const char *, inet_ntop, int32_t af, const void *src, char *dst, int32_t size); 60 | EXPORT_DECL(int32_t, inet_pton, int32_t af, const char *src, void *dst); 61 | EXPORT_DECL(int32_t, socketlasterr, void); 62 | 63 | 64 | void InitAcquireSocket(void) { 65 | if(coreinit_handle == 0) { 66 | InitAcquireOS(); 67 | }; 68 | OSDynLoad_Acquire("nsysnet.rpl", &nsysnet_handle); 69 | } 70 | 71 | void InitSocketFunctionPointers(void) { 72 | 73 | uint32_t *funcPointer = 0; 74 | 75 | InitAcquireSocket(); 76 | 77 | uint32_t nn_ac_handle; 78 | int32_t(*ACInitialize)(); 79 | int32_t(*ACGetStartupId) (uint32_t *id); 80 | int32_t(*ACConnectWithConfigId) (uint32_t id); 81 | int32_t(*ACGetAssignedAddress) (uint32_t * ip); 82 | OSDynLoad_Acquire("nn_ac.rpl", &nn_ac_handle); 83 | OSDynLoad_FindExport(nn_ac_handle, 0, "ACInitialize", &ACInitialize); 84 | OSDynLoad_FindExport(nn_ac_handle, 0, "ACGetStartupId", &ACGetStartupId); 85 | OSDynLoad_FindExport(nn_ac_handle, 0, "ACConnectWithConfigId",&ACConnectWithConfigId); 86 | OSDynLoad_FindExport(nn_ac_handle, 0, "ACGetAssignedAddress",&ACGetAssignedAddress); 87 | 88 | OS_FIND_EXPORT(nsysnet_handle, socket_lib_init); 89 | OS_FIND_EXPORT(nsysnet_handle, socket_lib_finish); 90 | OS_FIND_EXPORT(nsysnet_handle, socketlasterr); 91 | OS_FIND_EXPORT(nsysnet_handle, socket); 92 | OS_FIND_EXPORT(nsysnet_handle, socketclose); 93 | OS_FIND_EXPORT(nsysnet_handle, shutdown); 94 | OS_FIND_EXPORT(nsysnet_handle, connect); 95 | OS_FIND_EXPORT(nsysnet_handle, bind); 96 | OS_FIND_EXPORT(nsysnet_handle, listen); 97 | OS_FIND_EXPORT(nsysnet_handle, accept); 98 | OS_FIND_EXPORT(nsysnet_handle, send); 99 | OS_FIND_EXPORT(nsysnet_handle, recv); 100 | OS_FIND_EXPORT(nsysnet_handle, recvfrom); 101 | OS_FIND_EXPORT(nsysnet_handle, sendto); 102 | OS_FIND_EXPORT(nsysnet_handle, setsockopt); 103 | OS_FIND_EXPORT(nsysnet_handle, getsockopt); 104 | OS_FIND_EXPORT(nsysnet_handle, somemopt); 105 | OS_FIND_EXPORT(nsysnet_handle, inet_ntoa); 106 | OS_FIND_EXPORT(nsysnet_handle, inet_aton); 107 | OS_FIND_EXPORT(nsysnet_handle, inet_ntop); 108 | OS_FIND_EXPORT(nsysnet_handle, inet_pton); 109 | 110 | uint32_t nn_startupid; 111 | ACInitialize(); 112 | ACGetStartupId(&nn_startupid); 113 | ACConnectWithConfigId(nn_startupid); 114 | ACGetAssignedAddress(&hostIpAddress); 115 | 116 | socket_lib_init(); 117 | } 118 | 119 | void FreeSocketFunctionPointers(void) { 120 | 121 | socket_lib_finish(); 122 | } -------------------------------------------------------------------------------- /src/common/common.h: -------------------------------------------------------------------------------- 1 | #ifndef COMMON_H 2 | #define COMMON_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include "types.h" 9 | #include "os_defs.h" 10 | 11 | #define CAFE_OS_SD_PATH "/vol/external01" 12 | #define SD_PATH "storage_sdcard:" 13 | #define WIIU_PATH "/wiiu" 14 | 15 | #ifndef MEM_BASE 16 | #define MEM_BASE (0x00800000) 17 | #endif 18 | 19 | #define ELF_DATA_ADDR (*(volatile unsigned int*)(MEM_BASE + 0x1300 + 0x00)) 20 | #define ELF_DATA_SIZE (*(volatile unsigned int*)(MEM_BASE + 0x1300 + 0x04)) 21 | #define MAIN_ENTRY_ADDR (*(volatile unsigned int*)(MEM_BASE + 0x1400 + 0x00)) 22 | #define OS_FIRMWARE (*(volatile unsigned int*)(MEM_BASE + 0x1400 + 0x04)) 23 | 24 | #define OS_SPECIFICS ((OsSpecifics*)(MEM_BASE + 0x1500)) 25 | 26 | #ifndef EXIT_SUCCESS 27 | #define EXIT_SUCCESS 0 28 | #endif 29 | #define EXIT_HBL_EXIT 0xFFFFFFFE 30 | #define EXIT_RELAUNCH_ON_LOAD 0xFFFFFFFD 31 | 32 | 33 | #define OS_MESSAGE_NOBLOCK 0 34 | #define OS_MESSAGE_BLOCK 1 35 | 36 | #define OS_EXCEPTION_DSI 2 37 | #define OS_EXCEPTION_ISI 3 38 | #define OS_EXCEPTION_PROGRAM 6 39 | #define OS_EXCEPTION_MODE_THREAD 1 40 | #define OS_EXCEPTION_MODE_GLOBAL_ALL_CORES 4 41 | 42 | #define OS_THREAD_ATTR_AFFINITY_NONE 0x0007u // affinity to run on every core 43 | #define OS_THREAD_ATTR_AFFINITY_CORE0 0x0001u // run only on core0 44 | #define OS_THREAD_ATTR_AFFINITY_CORE1 0x0002u // run only on core1 45 | #define OS_THREAD_ATTR_AFFINITY_CORE2 0x0004u // run only on core2 46 | #define OS_THREAD_ATTR_DETACH 0x0008u // detached 47 | #define OS_THREAD_ATTR_PINNED_AFFINITY 0x0010u // pinned (affinitized) to a single core 48 | #define OS_THREAD_ATTR_CHECK_STACK_USE 0x0040u // check for stack usage 49 | #define OS_THREAD_ATTR_NAME_SENT 0x0080u // debugger has seen the name 50 | #define OS_THREAD_ATTR_LAST (OS_THREAD_ATTR_DETACH | OS_THREAD_ATTR_PINNED_AFFINITY | OS_THREAD_ATTR_AFFINITY_NONE) 51 | 52 | typedef struct OSThread_ OSThread; 53 | 54 | typedef struct OSThreadLink_ { 55 | OSThread *next; 56 | OSThread *prev; 57 | } OSThreadLink; 58 | 59 | typedef struct OSThreadQueue_ { 60 | OSThread *head; 61 | OSThread *tail; 62 | void *parentStruct; 63 | uint32_t reserved; 64 | } OSThreadQueue; 65 | 66 | typedef struct OSMessage_ { 67 | uint32_t message; 68 | uint32_t data0; 69 | uint32_t data1; 70 | uint32_t data2; 71 | } OSMessage; 72 | 73 | typedef struct OSMessageQueue_ { 74 | uint32_t tag; 75 | char *name; 76 | uint32_t reserved; 77 | 78 | OSThreadQueue sendQueue; 79 | OSThreadQueue recvQueue; 80 | OSMessage *messages; 81 | int msgCount; 82 | int firstIndex; 83 | int usedCount; 84 | } OSMessageQueue; 85 | 86 | typedef struct OSContext_ { 87 | char tag[8]; 88 | 89 | uint32_t gpr[32]; 90 | 91 | uint32_t cr; 92 | uint32_t lr; 93 | uint32_t ctr; 94 | uint32_t xer; 95 | 96 | uint32_t srr0; 97 | uint32_t srr1; 98 | 99 | uint32_t ex0; 100 | uint32_t ex1; 101 | 102 | uint32_t exception_type; 103 | uint32_t reserved; 104 | 105 | double fpscr; 106 | double fpr[32]; 107 | 108 | uint16_t spinLockCount; 109 | uint16_t state; 110 | 111 | uint32_t gqr[8]; 112 | uint32_t pir; 113 | double psf[32]; 114 | 115 | uint64_t coretime[3]; 116 | uint64_t starttime; 117 | 118 | uint32_t error; 119 | uint32_t attributes; 120 | 121 | uint32_t pmc1; 122 | uint32_t pmc2; 123 | uint32_t pmc3; 124 | uint32_t pmc4; 125 | uint32_t mmcr0; 126 | uint32_t mmcr1; 127 | } OSContext; 128 | 129 | typedef enum OSExceptionType { 130 | OS_EXCEPTION_TYPE_SYSTEM_RESET = 0, 131 | OS_EXCEPTION_TYPE_MACHINE_CHECK = 1, 132 | OS_EXCEPTION_TYPE_DSI = 2, 133 | OS_EXCEPTION_TYPE_ISI = 3, 134 | OS_EXCEPTION_TYPE_EXTERNAL_INTERRUPT = 4, 135 | OS_EXCEPTION_TYPE_ALIGNMENT = 5, 136 | OS_EXCEPTION_TYPE_PROGRAM = 6, 137 | OS_EXCEPTION_TYPE_FLOATING_POINT = 7, 138 | OS_EXCEPTION_TYPE_DECREMENTER = 8, 139 | OS_EXCEPTION_TYPE_SYSTEM_CALL = 9, 140 | OS_EXCEPTION_TYPE_TRACE = 10, 141 | OS_EXCEPTION_TYPE_PERFORMANCE_MONITOR = 11, 142 | OS_EXCEPTION_TYPE_BREAKPOINT = 12, 143 | OS_EXCEPTION_TYPE_SYSTEM_INTERRUPT = 13, 144 | OS_EXCEPTION_TYPE_ICI = 14, 145 | } OSExceptionType; 146 | 147 | typedef int (*ThreadFunc)(int argc, void *argv); 148 | 149 | struct OSThread_ { 150 | OSContext context; 151 | 152 | uint32_t txtTag; 153 | uint8_t state; 154 | uint8_t attr; 155 | 156 | short threadId; 157 | int suspend; 158 | int priority; 159 | 160 | char _[0x394 - 0x330 - sizeof(OSThreadLink)]; 161 | OSThreadLink linkActive; 162 | 163 | void *stackBase; 164 | void *stackEnd; 165 | 166 | ThreadFunc entryPoint; 167 | 168 | char _3A0[0x6A0 - 0x3A0]; 169 | }; 170 | 171 | typedef struct _OSCalendarTime { 172 | int sec; 173 | int min; 174 | int hour; 175 | int mday; 176 | int mon; 177 | int year; 178 | int wday; 179 | int yday; 180 | int msec; 181 | int usec; 182 | } OSCalendarTime; 183 | 184 | 185 | typedef struct MCPTitleListType { 186 | uint64_t titleId; 187 | uint8_t unknwn[4]; 188 | int8_t path[56]; 189 | uint32_t appType; 190 | uint8_t unknwn1[0x54 - 0x48]; 191 | uint8_t device; 192 | uint8_t unknwn2; 193 | int8_t indexedDevice[10]; 194 | uint8_t unk0x60; 195 | } MCPTitleListType; 196 | 197 | #ifdef __cplusplus 198 | } 199 | #endif 200 | 201 | #endif /* COMMON_H */ 202 | 203 | -------------------------------------------------------------------------------- /src/iosuhax/iosuhax_cfw.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2020 3 | * by Ash Logan 4 | * 5 | * This software is provided 'as-is', without any express or implied 6 | * warranty. In no event will the authors be held liable for any 7 | * damages arising from the use of this software. 8 | * 9 | * Permission is granted to anyone to use this software for any 10 | * purpose, including commercial applications, and to alter it and 11 | * redistribute it freely, subject to the following restrictions: 12 | * 13 | * 1. The origin of this software must not be misrepresented; you 14 | * must not claim that you wrote the original software. If you use 15 | * this software in a product, an acknowledgment in the product 16 | * documentation would be appreciated but is not required. 17 | * 18 | * 2. Altered source versions must be plainly marked as such, and 19 | * must not be misrepresented as being the original software. 20 | * 21 | * 3. This notice may not be removed or altered from any source 22 | * distribution. 23 | ***************************************************************************/ 24 | 25 | #include 26 | 27 | #include "iosuhax.h" 28 | #include "iosuhax_iosapi.h" 29 | #include "iosuhax_cfw.h" 30 | 31 | static int cfw_identified = 0; 32 | static IOSUHAX_CFW_Family cfw_family = IOSUHAX_CFW_NO_CFW; 33 | static IOSUHAX_CFW_Variant cfw_variant = IOSUHAX_CFW_VARIANT_STOCK; 34 | static IOSUHAX_CFW_RPXStyle cfw_rpxstyle = IOSUHAX_CFW_RPX_STYLE_NONE; 35 | static int mcp_available = 1; 36 | static int iosuhax_available = 0; 37 | 38 | static void IOSUHAX_CFW_Identify() { 39 | int mcpFd = IOS_Open("/dev/mcp", 0); 40 | if (mcpFd < 0) return; 41 | 42 | int iosuhaxFd = IOS_Open("/dev/iosuhax", 0); 43 | if (iosuhaxFd >= 0) { 44 | /* Mocha-style CFW */ 45 | cfw_family = IOSUHAX_CFW_MOCHA; 46 | iosuhax_available = 1; 47 | IOS_Close(iosuhaxFd); 48 | 49 | int ioctl100_ret = 0; 50 | 51 | /* Detect ioctl100/modern RPX loading 52 | Important: the size of dummy must be more than 0x280-1 to make Mocha RPX 53 | fail on it. */ 54 | const int dummy_size = 0x300; 55 | void* dummy = memalign(0x20, 0x300); 56 | *(uint32_t*)dummy = 0; //this must *not* be a valid IPC_CUSTOM command 57 | IOS_Ioctl(mcpFd, 100, dummy, dummy_size, &ioctl100_ret, sizeof(ioctl100_ret)); 58 | free(dummy); 59 | 60 | if (ioctl100_ret == 1) { 61 | /* "Mocha RPX" */ 62 | cfw_variant = IOSUHAX_CFW_VARIANT_MOCHA_RPX; 63 | cfw_rpxstyle = IOSUHAX_CFW_RPX_STYLE_RAW_PATH; 64 | } else if (ioctl100_ret == 2) { 65 | /* MochaLite */ 66 | cfw_variant = IOSUHAX_CFW_VARIANT_MOCHALITE; 67 | cfw_rpxstyle = IOSUHAX_CFW_RPX_STYLE_IPC; 68 | } else { 69 | /* Mocha */ 70 | cfw_rpxstyle = IOSUHAX_CFW_RPX_STYLE_NONE; 71 | } 72 | cfw_identified = 1; 73 | IOS_Close(mcpFd); 74 | return; 75 | } 76 | 77 | /* Try to detect Haxchi FW - MCP hook open */ 78 | uint32_t* haxchi_magic = memalign(0x20, 0x100); 79 | IOS_Ioctl(mcpFd, 0x5B, NULL, 0, haxchi_magic, sizeof(*haxchi_magic)); 80 | if (*haxchi_magic == IOSUHAX_MAGIC_WORD) { 81 | cfw_family = IOSUHAX_CFW_HAXCHIFW; 82 | mcp_available = 0; 83 | 84 | cfw_identified = 1; 85 | IOS_Close(mcpFd); 86 | free(haxchi_magic); 87 | return; 88 | } 89 | free(haxchi_magic); 90 | 91 | /* Try to detect Haxchi FW - no MCP hook */ 92 | struct { 93 | int major; 94 | int minor; 95 | int patch; 96 | char region[4]; 97 | } *mcp_version = memalign(0x20, 0x100); 98 | IOS_Ioctl(mcpFd, 0x89, NULL, 0, mcp_version, sizeof(*mcp_version)); 99 | if (mcp_version->major == 99 && 100 | mcp_version->minor == 99 && 101 | mcp_version->patch == 99) { 102 | cfw_family = IOSUHAX_CFW_HAXCHIFW; 103 | iosuhax_available = 1; 104 | 105 | cfw_identified = 1; 106 | IOS_Close(mcpFd); 107 | free(mcp_version); 108 | return; 109 | } 110 | free(mcp_version); 111 | 112 | /* Alright, we got nothing */ 113 | cfw_identified = 1; 114 | IOS_Close(mcpFd); 115 | return; 116 | } 117 | 118 | static void IOSUHAX_CFW_CheckMCP() { 119 | if (!cfw_identified) { 120 | IOSUHAX_CFW_Identify(); 121 | } else { 122 | /* State might have changed since last call */ 123 | if (cfw_family == IOSUHAX_CFW_HAXCHIFW) { 124 | int mcpFd = IOS_Open("/dev/mcp", 0); 125 | if (mcpFd < 0) { 126 | mcp_available = 0; 127 | return; 128 | } 129 | 130 | uint32_t haxchi_magic = 0; 131 | IOS_Ioctl(mcpFd, IOCTL_CHECK_IF_IOSUHAX, NULL, 0, &haxchi_magic, sizeof(haxchi_magic)); 132 | if (haxchi_magic == IOSUHAX_MAGIC_WORD) { 133 | mcp_available = 0; 134 | iosuhax_available = 1; 135 | } else { 136 | mcp_available = 1; 137 | iosuhax_available = 0; 138 | } 139 | IOS_Close(mcpFd); 140 | } 141 | } 142 | } 143 | 144 | IOSUHAX_CFW_Family IOSUHAX_CFW_GetFamily() { 145 | if (!cfw_identified) { 146 | IOSUHAX_CFW_Identify(); 147 | } 148 | 149 | return cfw_family; 150 | } 151 | 152 | IOSUHAX_CFW_Variant IOSUHAX_CFW_GetVariant() { 153 | if (!cfw_identified) { 154 | IOSUHAX_CFW_Identify(); 155 | } 156 | 157 | return cfw_variant; 158 | } 159 | 160 | IOSUHAX_CFW_RPXStyle IOSUHAX_CFW_GetRPXStyle() { 161 | if (!cfw_identified) { 162 | IOSUHAX_CFW_Identify(); 163 | } 164 | 165 | return cfw_rpxstyle; 166 | } 167 | 168 | int IOSUHAX_CFW_MCPAvailable() { 169 | IOSUHAX_CFW_CheckMCP(); 170 | 171 | return mcp_available; 172 | } 173 | 174 | int IOSUHAX_CFW_Available() { 175 | IOSUHAX_CFW_CheckMCP(); 176 | 177 | return iosuhax_available; 178 | } 179 | -------------------------------------------------------------------------------- /src/dynamic_libs/fs_functions.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2015 3 | * by Dimok 4 | * 5 | * This software is provided 'as-is', without any express or implied 6 | * warranty. In no event will the authors be held liable for any 7 | * damages arising from the use of this software. 8 | * 9 | * Permission is granted to anyone to use this software for any 10 | * purpose, including commercial applications, and to alter it and 11 | * redistribute it freely, subject to the following restrictions: 12 | * 13 | * 1. The origin of this software must not be misrepresented; you 14 | * must not claim that you wrote the original software. If you use 15 | * this software in a product, an acknowledgment in the product 16 | * documentation would be appreciated but is not required. 17 | * 18 | * 2. Altered source versions must be plainly marked as such, and 19 | * must not be misrepresented as being the original software. 20 | * 21 | * 3. This notice may not be removed or altered from any source 22 | * distribution. 23 | ***************************************************************************/ 24 | #ifndef __FS_FUNCTIONS_H_ 25 | #define __FS_FUNCTIONS_H_ 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | #include "common/fs_defs.h" 32 | 33 | void InitFSFunctionPointers(void); 34 | 35 | extern int32_t (* FSInit)(void); 36 | extern int32_t (* FSShutdown)(void); 37 | extern int32_t (* FSAddClient)(void *pClient, int32_t errHandling); 38 | extern int32_t (* FSAddClientEx)(void *pClient, int32_t unk_zero_param, int32_t errHandling); 39 | extern int32_t (* FSDelClient)(void *pClient); 40 | extern void (* FSInitCmdBlock)(void *pCmd); 41 | extern void *(* FSGetCurrentCmdBlock)(void *pClient); 42 | extern int32_t (* FSGetMountSource)(void *pClient, void *pCmd, int32_t type, void *source, int32_t errHandling); 43 | 44 | extern int32_t (* FSMount)(void *pClient, void *pCmd, void *source, char *target, uint32_t bytes, int32_t errHandling); 45 | extern int32_t (* FSUnmount)(void *pClient, void *pCmd, const char *target, int32_t errHandling); 46 | extern int32_t (* FSRename)(void *pClient, void *pCmd, const char *oldPath, const char *newPath, int32_t error); 47 | extern int32_t (* FSRenameAsync)(void *pClient, void *pCmd, const char *oldPath, const char *newPath, int32_t error, void *asyncParams); 48 | extern int32_t (* FSRemove)(void *pClient, void *pCmd, const char *path, int32_t error); 49 | extern int32_t (* FSRemoveAsync)(void *pClient, void *pCmd, const char *path, int32_t error, void *asyncParams); 50 | 51 | extern int32_t (* FSGetStat)(void *pClient, void *pCmd, const char *path, FSStat *stats, int32_t errHandling); 52 | extern int32_t (* FSGetStatAsync)(void *pClient, void *pCmd, const char *path, void *stats, int32_t error, void *asyncParams); 53 | extern int32_t (* FSRename)(void *pClient, void *pCmd, const char *oldPath, const char *newPath, int32_t error); 54 | extern int32_t (* FSRenameAsync)(void *pClient, void *pCmd, const char *oldPath, const char *newPath, int32_t error, void *asyncParams); 55 | extern int32_t (* FSRemove)(void *pClient, void *pCmd, const char *path, int32_t error); 56 | extern int32_t (* FSRemoveAsync)(void *pClient, void *pCmd, const char *path, int32_t error, void *asyncParams); 57 | extern int32_t (* FSFlushQuota)(void *pClient, void *pCmd, const char* path, int32_t error); 58 | extern int32_t (* FSFlushQuotaAsync)(void *pClient, void *pCmd, const char *path, int32_t error, void *asyncParams); 59 | extern int32_t (* FSGetFreeSpaceSize)(void *pClient, void *pCmd, const char *path, uint64_t *returnedFreeSize, int32_t error); 60 | extern int32_t (* FSGetFreeSpaceSizeAsync)(void *pClient, void *pCmd, const char *path, uint64_t *returnedFreeSize, int32_t error, void *asyncParams); 61 | extern int32_t (* FSRollbackQuota)(void *pClient, void *pCmd, const char *path, int32_t error); 62 | extern int32_t (* FSRollbackQuotaAsync)(void *pClient, void *pCmd, const char *path, int32_t error, void *asyncParams); 63 | 64 | extern int32_t (* FSOpenDir)(void *pClient, void *pCmd, const char *path, int32_t *dh, int32_t errHandling); 65 | extern int32_t (* FSOpenDirAsync)(void *pClient, void* pCmd, const char *path, int32_t *handle, int32_t error, void *asyncParams); 66 | extern int32_t (* FSReadDir)(void *pClient, void *pCmd, int32_t dh, FSDirEntry *dir_entry, int32_t errHandling); 67 | extern int32_t (* FSRewindDir)(void *pClient, void *pCmd, int32_t dh, int32_t errHandling); 68 | extern int32_t (* FSCloseDir)(void *pClient, void *pCmd, int32_t dh, int32_t errHandling); 69 | extern int32_t (* FSChangeDir)(void *pClient, void *pCmd, const char *path, int32_t errHandling); 70 | extern int32_t (* FSChangeDirAsync)(void *pClient, void *pCmd, const char *path, int32_t error, void *asyncParams); 71 | extern int32_t (* FSMakeDir)(void *pClient, void *pCmd, const char *path, int32_t errHandling); 72 | extern int32_t (* FSMakeDirAsync)(void *pClient, void *pCmd, const char *path, int32_t error, void *asyncParams); 73 | 74 | extern int32_t (* FSOpenFile)(void *pClient, void *pCmd, const char *path, const char *mode, int32_t *fd, int32_t errHandling); 75 | extern int32_t (* FSOpenFileAsync)(void *pClient, void *pCmd, const char *path, const char *mode, int32_t *handle, int32_t error, const void *asyncParams); 76 | extern int32_t (* FSReadFile)(void *pClient, void *pCmd, void *buffer, int32_t size, int32_t count, int32_t fd, int32_t flag, int32_t errHandling); 77 | extern int32_t (* FSCloseFile)(void *pClient, void *pCmd, int32_t fd, int32_t errHandling); 78 | 79 | extern int32_t (* FSFlushFile)(void *pClient, void *pCmd, int32_t fd, int32_t error); 80 | extern int32_t (* FSTruncateFile)(void *pClient, void *pCmd, int32_t fd, int32_t error); 81 | extern int32_t (* FSGetStatFile)(void *pClient, void *pCmd, int32_t fd, void *buffer, int32_t error); 82 | extern int32_t (* FSSetPosFile)(void *pClient, void *pCmd, int32_t fd, uint32_t pos, int32_t error); 83 | extern int32_t (* FSWriteFile)(void *pClient, void *pCmd, const void *source, int32_t block_size, int32_t block_count, int32_t fd, int32_t flag, int32_t error); 84 | 85 | extern int32_t (* FSBindMount)(void *pClient, void *pCmd, char *source, char *target, int32_t error); 86 | extern int32_t (* FSBindUnmount)(void *pClient, void *pCmd, char *target, int32_t error); 87 | 88 | extern int32_t (* FSMakeQuota)( void *pClient, void *pCmd, const char *path,uint32_t mode, uint64_t size, int32_t errHandling); 89 | extern int32_t (* FSMakeQuotaAsync)(void *pClient, void *pCmd, const char *path,uint32_t mode, uint64_t size, int32_t errHandling,const void *asyncParams); 90 | 91 | extern int32_t (* FSGetCwd)(void * client,void * block,char * buffer,uint32_t bufferSize,uint32_t flags); 92 | 93 | 94 | #ifdef __cplusplus 95 | } 96 | #endif 97 | 98 | #endif // __FS_FUNCTIONS_H_ 99 | -------------------------------------------------------------------------------- /src/fat/directory.h: -------------------------------------------------------------------------------- 1 | /* 2 | directory.h 3 | Reading, writing and manipulation of the directory structure on 4 | a FAT partition 5 | 6 | Copyright (c) 2006 Michael "Chishm" Chisholm 7 | 8 | Redistribution and use in source and binary forms, with or without modification, 9 | are permitted provided that the following conditions are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright notice, 12 | this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the documentation and/or 15 | other materials provided with the distribution. 16 | 3. The name of the author may not be used to endorse or promote products derived 17 | from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 20 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 21 | AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 27 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef _DIRECTORY_H 31 | #define _DIRECTORY_H 32 | 33 | #include 34 | #include 35 | 36 | #include "common.h" 37 | #include "partition.h" 38 | 39 | #define DIR_ENTRY_DATA_SIZE 0x20 40 | #define MAX_LFN_LENGTH 256 41 | #define MAX_ALIAS_LENGTH 13 42 | #define LFN_ENTRY_LENGTH 13 43 | #define ALIAS_ENTRY_LENGTH 11 44 | #define MAX_ALIAS_EXT_LENGTH 3 45 | #define MAX_ALIAS_PRI_LENGTH 8 46 | #define MAX_NUMERIC_TAIL 999999 47 | #define FAT16_ROOT_DIR_CLUSTER 0 48 | 49 | #define DIR_SEPARATOR '/' 50 | 51 | // File attributes 52 | #define ATTRIB_ARCH 0x20 // Archive 53 | #define ATTRIB_DIR 0x10 // Directory 54 | #define ATTRIB_LFN 0x0F // Long file name 55 | #define ATTRIB_VOL 0x08 // Volume 56 | #define ATTRIB_SYS 0x04 // System 57 | #define ATTRIB_HID 0x02 // Hidden 58 | #define ATTRIB_RO 0x01 // Read only 59 | 60 | #define CASE_LOWER_EXT 0x10 // WinNT lowercase extension 61 | #define CASE_LOWER_BASE 0x08 // WinNT lowercase basename 62 | 63 | typedef enum {FT_DIRECTORY, FT_FILE} FILE_TYPE; 64 | 65 | typedef struct { 66 | uint32_t cluster; 67 | sec_t sector; 68 | int32_t offset; 69 | } DIR_ENTRY_POSITION; 70 | 71 | typedef struct { 72 | uint8_t entryData[DIR_ENTRY_DATA_SIZE]; 73 | DIR_ENTRY_POSITION dataStart; // Points to the start of the LFN entries of a file, or the alias for no LFN 74 | DIR_ENTRY_POSITION dataEnd; // Always points to the file/directory's alias entry 75 | char filename[NAME_MAX]; 76 | } DIR_ENTRY; 77 | 78 | // Directory entry offsets 79 | enum DIR_ENTRY_offset { 80 | DIR_ENTRY_name = 0x00, 81 | DIR_ENTRY_extension = 0x08, 82 | DIR_ENTRY_attributes = 0x0B, 83 | DIR_ENTRY_caseInfo = 0x0C, 84 | DIR_ENTRY_cTime_ms = 0x0D, 85 | DIR_ENTRY_cTime = 0x0E, 86 | DIR_ENTRY_cDate = 0x10, 87 | DIR_ENTRY_aDate = 0x12, 88 | DIR_ENTRY_clusterHigh = 0x14, 89 | DIR_ENTRY_mTime = 0x16, 90 | DIR_ENTRY_mDate = 0x18, 91 | DIR_ENTRY_cluster = 0x1A, 92 | DIR_ENTRY_fileSize = 0x1C 93 | }; 94 | 95 | /* 96 | Returns true if the file specified by entry is a directory 97 | */ 98 | static inline bool _FAT_directory_isDirectory (DIR_ENTRY* entry) { 99 | return ((entry->entryData[DIR_ENTRY_attributes] & ATTRIB_DIR) != 0); 100 | } 101 | 102 | static inline bool _FAT_directory_isWritable (DIR_ENTRY* entry) { 103 | return ((entry->entryData[DIR_ENTRY_attributes] & ATTRIB_RO) == 0); 104 | } 105 | 106 | static inline bool _FAT_directory_isDot (DIR_ENTRY* entry) { 107 | return ((entry->filename[0] == '.') && ((entry->filename[1] == '\0') || 108 | ((entry->filename[1] == '.') && entry->filename[2] == '\0'))); 109 | } 110 | 111 | /* 112 | Reads the first directory entry from the directory starting at dirCluster 113 | Places result in entry 114 | entry will be destroyed even if no directory entry is found 115 | Returns true on success, false on failure 116 | */ 117 | bool _FAT_directory_getFirstEntry (PARTITION* partition, DIR_ENTRY* entry, uint32_t dirCluster); 118 | 119 | /* 120 | Reads the next directory entry after the one already pointed to by entry 121 | Places result in entry 122 | entry will be destroyed even if no directory entry is found 123 | Returns true on success, false on failure 124 | */ 125 | bool _FAT_directory_getNextEntry (PARTITION* partition, DIR_ENTRY* entry); 126 | 127 | /* 128 | Gets the directory entry corrsponding to the supplied path 129 | entry will be destroyed even if no directory entry is found 130 | pathEnd specifies the end of the path string, for cutting strings short if needed 131 | specify NULL to use the full length of path 132 | pathEnd is only a suggestion, and the path string will be searched up until the next PATH_SEPARATOR 133 | after pathEND. 134 | Returns true on success, false on failure 135 | */ 136 | bool _FAT_directory_entryFromPath (PARTITION* partition, DIR_ENTRY* entry, const char* path, const char* pathEnd); 137 | 138 | /* 139 | Changes the current directory to the one specified by path 140 | Returns true on success, false on failure 141 | */ 142 | bool _FAT_directory_chdir (PARTITION* partition, const char* path); 143 | 144 | /* 145 | Removes the directory entry specified by entry 146 | Assumes that entry is valid 147 | Returns true on success, false on failure 148 | */ 149 | bool _FAT_directory_removeEntry (PARTITION* partition, DIR_ENTRY* entry); 150 | 151 | /* 152 | Add a directory entry to the directory specified by dirCluster 153 | The fileData, dataStart and dataEnd elements of the DIR_ENTRY struct are 154 | updated with the new directory entry position and alias. 155 | Returns true on success, false on failure 156 | */ 157 | bool _FAT_directory_addEntry (PARTITION* partition, DIR_ENTRY* entry, uint32_t dirCluster); 158 | 159 | /* 160 | Get the start cluster of a file from it's entry data 161 | */ 162 | uint32_t _FAT_directory_entryGetCluster (PARTITION* partition, const uint8_t* entryData); 163 | 164 | /* 165 | Fill in the file name and entry data of DIR_ENTRY* entry. 166 | Assumes that the entry's dataStart and dataEnd are correct 167 | Returns true on success, false on failure 168 | */ 169 | bool _FAT_directory_entryFromPosition (PARTITION* partition, DIR_ENTRY* entry); 170 | 171 | /* 172 | Fill in a stat struct based on a file entry 173 | */ 174 | void _FAT_directory_entryStat (PARTITION* partition, DIR_ENTRY* entry, struct stat *st); 175 | 176 | /* 177 | Get volume label 178 | */ 179 | bool _FAT_directory_getVolumeLabel (PARTITION* partition, char *label); 180 | 181 | #endif // _DIRECTORY_H 182 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | ifeq ($(strip $(DEVKITPRO)),) 2 | $(error "Please set DEVKITPRO in your environment. export DEVKITPRO=/devkitpro") 3 | endif 4 | 5 | ifeq ($(strip $(WiiUFtpServerVersion)),) 6 | export WiiUFtpServerVersion=0.0.0 7 | $(info WiiUFtpServerVersion set to $(WiiUFtpServerVersion), use build.sh instead) 8 | endif 9 | 10 | export DEVKITPPC := $(DEVKITPRO)/devkitPPC 11 | export PATH := $(DEVKITPRO)/tools/bin:$(DEVKITPPC)/bin:$(PORTLIBS)/bin:$(PATH) 12 | export PORTLIBS := $(DEVKITPRO)/portlibs/ppc 13 | 14 | PREFIX := powerpc-eabi- 15 | 16 | export AS := $(PREFIX)as 17 | export CC := $(PREFIX)gcc 18 | export CXX := $(PREFIX)g++ 19 | export AR := $(PREFIX)ar 20 | export OBJCOPY := $(PREFIX)objcopy 21 | 22 | #--------------------------------------------------------------------------------- 23 | # TARGET is the name of the output 24 | # BUILD is the directory where object files & intermediate files will be placed 25 | # SOURCES is a list of directories containing source code 26 | # INCLUDES is a list of directories containing extra header files 27 | #--------------------------------------------------------------------------------- 28 | TARGET := WiiUFtpServer 29 | BUILD := build 30 | BUILD_DBG := $(TARGET)_dbg 31 | SOURCES := src \ 32 | src/common \ 33 | src/system \ 34 | src/fat \ 35 | src/dynamic_libs \ 36 | src/iosuhax 37 | DATA := 38 | 39 | INCLUDES := src \ 40 | src/common \ 41 | src/system \ 42 | src/fat \ 43 | src/dynamic_libs \ 44 | src/iosuhax 45 | 46 | 47 | #--------------------------------------------------------------------------------- 48 | # options for code generation 49 | #--------------------------------------------------------------------------------- 50 | 51 | CFLAGS := -mrvl -mcpu=750 -meabi -mhard-float -ffast-math \ 52 | -O3 -Wall -Wextra -Wno-unused-parameter -Wno-strict-aliasing $(INCLUDE) 53 | 54 | CFLAGS += -D_GNU_SOURCE -DVERSION_STRING="\"WiiU Ftp Server v$(WiiUFtpServerVersion)\"" 55 | 56 | CFLAGS += $(INCLUDE) -D__WIIU__ -D__wiiu__ 57 | 58 | # enable WiiUFtpServer log file 59 | # /sd/wiiu/apps/WiiuFtpServer/WiiuFtpServer.log and .old (previous session) 60 | #CFLAGS += -DLOG2FILE 61 | 62 | 63 | ASFLAGS := -mregnames 64 | LDFLAGS := -nostartfiles -Wl,-Map,$(notdir $@).map,-wrap,malloc,-wrap,free,-wrap,memalign,-wrap,calloc,-wrap,realloc,-wrap,malloc_usable_size,-wrap,_malloc_r,-wrap,_free_r,-wrap,_realloc_r,-wrap,_calloc_r,-wrap,_memalign_r,-wrap,_malloc_usable_size_r,-wrap,valloc,-wrap,_valloc_r,-wrap,_pvalloc_r,--gc-sections 65 | 66 | #--------------------------------------------------------------------------------- 67 | MAKEFLAGS += --no-print-directory 68 | #--------------------------------------------------------------------------------- 69 | # any extra libraries we wish to link with the project 70 | #--------------------------------------------------------------------------------- 71 | LIBS := 72 | 73 | #--------------------------------------------------------------------------------- 74 | # list of directories containing libraries, this must be the top level containing 75 | # include and lib 76 | #--------------------------------------------------------------------------------- 77 | LIBDIRS := $(CURDIR) \ 78 | $(DEVKITPPC)/lib \ 79 | $(DEVKITPPC)/lib/gcc/powerpc-eabi/bin 80 | 81 | 82 | #--------------------------------------------------------------------------------- 83 | # no real need to edit anything past this point unless you need to add additional 84 | # rules for different file extensions 85 | #--------------------------------------------------------------------------------- 86 | ifneq ($(BUILD),$(notdir $(CURDIR))) 87 | #--------------------------------------------------------------------------------- 88 | export PROJECTDIR := $(CURDIR) 89 | export OUTPUT := $(CURDIR)/$(TARGETDIR)/$(TARGET) 90 | export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ 91 | $(foreach dir,$(DATA),$(CURDIR)/$(dir)) 92 | export DEPSDIR := $(CURDIR)/$(BUILD) 93 | 94 | #--------------------------------------------------------------------------------- 95 | # automatically build a list of object files for our project 96 | #--------------------------------------------------------------------------------- 97 | CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) 98 | CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) 99 | 100 | #--------------------------------------------------------------------------------- 101 | # use CXX for linking C++ projects, CC for standard C 102 | #--------------------------------------------------------------------------------- 103 | ifeq ($(strip $(CPPFILES)),) 104 | export LD := $(CC) 105 | else 106 | export LD := $(CXX) 107 | endif 108 | 109 | export OFILES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \ 110 | $(sFILES:.s=.o) $(SFILES:.S=.o) \ 111 | $(PNGFILES:.png=.png.o) $(addsuffix .o,$(BINFILES)) 112 | 113 | #--------------------------------------------------------------------------------- 114 | # build a list of include paths 115 | #--------------------------------------------------------------------------------- 116 | export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ 117 | $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ 118 | -I$(CURDIR)/$(BUILD) \ 119 | -I$(PORTLIBS)/include 120 | 121 | #--------------------------------------------------------------------------------- 122 | # build a list of library paths 123 | #--------------------------------------------------------------------------------- 124 | export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \ 125 | -L$(PORTLIBS)/lib 126 | 127 | export OUTPUT := $(CURDIR)/$(TARGET) 128 | .PHONY: $(BUILD) clean install 129 | 130 | #--------------------------------------------------------------------------------- 131 | $(BUILD): 132 | @[ -d $@ ] || mkdir -p $@ 133 | @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile 134 | 135 | #--------------------------------------------------------------------------------- 136 | clean: 137 | @echo clean ... 138 | @rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).bin $(BUILD_DBG).elf 139 | 140 | #--------------------------------------------------------------------------------- 141 | else 142 | 143 | DEPENDS := $(OFILES:.o=.d) 144 | 145 | #--------------------------------------------------------------------------------- 146 | # main targets 147 | #--------------------------------------------------------------------------------- 148 | $(OUTPUT).elf: $(OFILES) 149 | 150 | #--------------------------------------------------------------------------------- 151 | %.elf: link.ld $(OFILES) 152 | @echo "linking ... $(TARGET).elf" 153 | @$(LD) -n -T $^ $(LDFLAGS) -o ../$(BUILD_DBG).elf $(LIBPATHS) $(LIBS) 154 | @$(OBJCOPY) -S -R .comment -R .gnu.attributes ../$(BUILD_DBG).elf $@ 155 | 156 | #--------------------------------------------------------------------------------- 157 | %.o: %.c 158 | @echo $(notdir $<) 159 | @$(CC) -MMD -MP -MF $(DEPSDIR)/$*.d $(CFLAGS) -c $< -o $@ $(ERROR_FILTER) 160 | 161 | 162 | -include $(DEPENDS) 163 | 164 | #--------------------------------------------------------------------------------- 165 | endif 166 | #--------------------------------------------------------------------------------- 167 | -------------------------------------------------------------------------------- /src/iosuhax/iosuhax_disc_interface.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2016 3 | * by Dimok 4 | * 5 | * This software is provided 'as-is', without any express or implied 6 | * warranty. In no event will the authors be held liable for any 7 | * damages arising from the use of this software. 8 | * 9 | * Permission is granted to anyone to use this software for any 10 | * purpose, including commercial applications, and to alter it and 11 | * redistribute it freely, subject to the following restrictions: 12 | * 13 | * 1. The origin of this software must not be misrepresented; you 14 | * must not claim that you wrote the original software. If you use 15 | * this software in a product, an acknowledgment in the product 16 | * documentation would be appreciated but is not required. 17 | * 18 | * 2. Altered source versions must be plainly marked as such, and 19 | * must not be misrepresented as being the original software. 20 | * 21 | * 3. This notice may not be removed or altered from any source 22 | * distribution. 23 | ***************************************************************************/ 24 | #include 25 | #include 26 | #include "iosuhax.h" 27 | #include "iosuhax_disc_interface.h" 28 | 29 | #define FSA_REF_SD 0x01 30 | #define FSA_REF_USB 0x02 31 | 32 | static int initialized = 0; 33 | 34 | static int fsaFdSd = 0; 35 | static int fsaFdUsb = 0; 36 | static int sdioFd = 0; 37 | static int usbFd = 0; 38 | 39 | static void IOSUHAX_disc_io_initialize(void) 40 | { 41 | if(initialized == 0) 42 | { 43 | initialized = 1; 44 | fsaFdSd = -1; 45 | fsaFdUsb = -1; 46 | sdioFd = -1; 47 | usbFd = -1; 48 | } 49 | } 50 | 51 | static bool IOSUHAX_disc_io_fsa_open(int fsaFd) 52 | { 53 | IOSUHAX_disc_io_initialize(); 54 | 55 | if(IOSUHAX_Open(NULL) < 0) 56 | return false; 57 | 58 | if(fsaFd == FSA_REF_SD) 59 | { 60 | if(fsaFdSd < 0) 61 | { 62 | fsaFdSd = IOSUHAX_FSA_Open(); 63 | } 64 | 65 | if(fsaFdSd >= 0) 66 | return true; 67 | } 68 | else if(fsaFd == FSA_REF_USB) 69 | { 70 | if(fsaFdUsb < 0) 71 | { 72 | fsaFdUsb = IOSUHAX_FSA_Open(); 73 | } 74 | 75 | if(fsaFdUsb >= 0) 76 | return true; 77 | } 78 | 79 | return false; 80 | } 81 | 82 | static void IOSUHAX_disc_io_fsa_close(int fsaFd) 83 | { 84 | if(fsaFd == FSA_REF_SD) 85 | { 86 | if(fsaFdSd >= 0) 87 | { 88 | IOSUHAX_FSA_Close(fsaFdSd); 89 | fsaFdSd = -1; 90 | } 91 | } 92 | else if(fsaFd == FSA_REF_USB) 93 | { 94 | if(fsaFdUsb >= 0) 95 | { 96 | IOSUHAX_FSA_Close(fsaFdUsb); 97 | fsaFdUsb = -1; 98 | } 99 | } 100 | } 101 | 102 | static bool IOSUHAX_sdio_startup(void) 103 | { 104 | if(!IOSUHAX_disc_io_fsa_open(FSA_REF_SD)) 105 | return false; 106 | 107 | if(sdioFd < 0) 108 | { 109 | int res = IOSUHAX_FSA_RawOpen(fsaFdSd, "/dev/sdcard01", &sdioFd); 110 | if(res < 0) 111 | { 112 | IOSUHAX_disc_io_fsa_close(FSA_REF_SD); 113 | sdioFd = -1; 114 | } 115 | } 116 | 117 | return (sdioFd >= 0); 118 | } 119 | 120 | static bool IOSUHAX_sdio_isInserted(void) 121 | { 122 | //! TODO: check for SD card inserted with IOSUHAX_FSA_GetDeviceInfo() 123 | return initialized && (fsaFdSd >= 0) && (sdioFd >= 0); 124 | } 125 | 126 | static bool IOSUHAX_sdio_clearStatus(void) 127 | { 128 | return true; 129 | } 130 | 131 | static bool IOSUHAX_sdio_shutdown(void) 132 | { 133 | if(!IOSUHAX_sdio_isInserted()) 134 | return false; 135 | 136 | IOSUHAX_FSA_RawClose(fsaFdSd, sdioFd); 137 | IOSUHAX_disc_io_fsa_close(FSA_REF_SD); 138 | sdioFd = -1; 139 | return true; 140 | } 141 | 142 | static bool IOSUHAX_sdio_readSectors(uint32_t sector, uint32_t numSectors, void* buffer) 143 | { 144 | if(!IOSUHAX_sdio_isInserted()) 145 | return false; 146 | 147 | int res = IOSUHAX_FSA_RawRead(fsaFdSd, buffer, 512, numSectors, sector, sdioFd); 148 | if(res < 0) 149 | { 150 | return false; 151 | } 152 | 153 | return true; 154 | } 155 | 156 | static bool IOSUHAX_sdio_writeSectors(uint32_t sector, uint32_t numSectors, const void* buffer) 157 | { 158 | if(!IOSUHAX_sdio_isInserted()) 159 | return false; 160 | 161 | int res = IOSUHAX_FSA_RawWrite(fsaFdSd, buffer, 512, numSectors, sector, sdioFd); 162 | if(res < 0) 163 | { 164 | return false; 165 | } 166 | 167 | return true; 168 | } 169 | 170 | const DISC_INTERFACE IOSUHAX_sdio_disc_interface = 171 | { 172 | DEVICE_TYPE_WII_U_SD, 173 | FEATURE_MEDIUM_CANREAD | FEATURE_MEDIUM_CANWRITE | FEATURE_WII_U_SD, 174 | IOSUHAX_sdio_startup, 175 | IOSUHAX_sdio_isInserted, 176 | IOSUHAX_sdio_readSectors, 177 | IOSUHAX_sdio_writeSectors, 178 | IOSUHAX_sdio_clearStatus, 179 | IOSUHAX_sdio_shutdown 180 | }; 181 | 182 | static bool IOSUHAX_usb_startup(void) 183 | { 184 | if(!IOSUHAX_disc_io_fsa_open(FSA_REF_USB)) 185 | return false; 186 | 187 | if(usbFd < 0) 188 | { 189 | int res = IOSUHAX_FSA_RawOpen(fsaFdUsb, "/dev/usb01", &usbFd); 190 | if(res < 0) 191 | { 192 | res = IOSUHAX_FSA_RawOpen(fsaFdUsb, "/dev/usb02", &usbFd); 193 | if(res < 0) 194 | { 195 | IOSUHAX_disc_io_fsa_close(FSA_REF_USB); 196 | usbFd = -1; 197 | } 198 | } 199 | } 200 | return (usbFd >= 0); 201 | } 202 | 203 | static bool IOSUHAX_usb_isInserted(void) 204 | { 205 | return initialized && (fsaFdUsb >= 0) && (usbFd >= 0); 206 | } 207 | 208 | static bool IOSUHAX_usb_clearStatus(void) 209 | { 210 | return true; 211 | } 212 | 213 | static bool IOSUHAX_usb_shutdown(void) 214 | { 215 | if(!IOSUHAX_usb_isInserted()) 216 | return false; 217 | 218 | IOSUHAX_FSA_RawClose(fsaFdUsb, usbFd); 219 | IOSUHAX_disc_io_fsa_close(FSA_REF_USB); 220 | usbFd = -1; 221 | return true; 222 | } 223 | 224 | static bool IOSUHAX_usb_readSectors(uint32_t sector, uint32_t numSectors, void* buffer) 225 | { 226 | if(!IOSUHAX_usb_isInserted()) 227 | return false; 228 | 229 | int res = IOSUHAX_FSA_RawRead(fsaFdUsb, buffer, 512, numSectors, sector, usbFd); 230 | if(res < 0) 231 | { 232 | return false; 233 | } 234 | 235 | return true; 236 | } 237 | 238 | static bool IOSUHAX_usb_writeSectors(uint32_t sector, uint32_t numSectors, const void* buffer) 239 | { 240 | if(!IOSUHAX_usb_isInserted()) 241 | return false; 242 | 243 | int res = IOSUHAX_FSA_RawWrite(fsaFdUsb, buffer, 512, numSectors, sector, usbFd); 244 | if(res < 0) 245 | { 246 | return false; 247 | } 248 | 249 | return true; 250 | } 251 | 252 | const DISC_INTERFACE IOSUHAX_usb_disc_interface = 253 | { 254 | DEVICE_TYPE_WII_U_USB, 255 | FEATURE_MEDIUM_CANREAD | FEATURE_MEDIUM_CANWRITE | FEATURE_WII_U_USB, 256 | IOSUHAX_usb_startup, 257 | IOSUHAX_usb_isInserted, 258 | IOSUHAX_usb_readSectors, 259 | IOSUHAX_usb_writeSectors, 260 | IOSUHAX_usb_clearStatus, 261 | IOSUHAX_usb_shutdown 262 | }; 263 | -------------------------------------------------------------------------------- /src/system/memory.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2015 Dimok 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | ****************************************************************************/ 17 | #include 18 | #include 19 | #include "dynamic_libs/os_functions.h" 20 | #include "common/common.h" 21 | #include "memory.h" 22 | 23 | #define MEMORY_ARENA_1 0 24 | #define MEMORY_ARENA_2 1 25 | #define MEMORY_ARENA_3 2 26 | #define MEMORY_ARENA_4 3 27 | #define MEMORY_ARENA_5 4 28 | #define MEMORY_ARENA_6 5 29 | #define MEMORY_ARENA_7 6 30 | #define MEMORY_ARENA_8 7 31 | #define MEMORY_ARENA_FG_BUCKET 8 32 | 33 | //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 34 | //! Memory functions 35 | //! This is the only place where those are needed so lets keep them more or less private 36 | //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 37 | extern unsigned int * pMEMAllocFromDefaultHeapEx; 38 | extern unsigned int * pMEMAllocFromDefaultHeap; 39 | extern unsigned int * pMEMFreeToDefaultHeap; 40 | 41 | extern int (* MEMGetBaseHeapHandle)(int mem_arena); 42 | extern unsigned int (* MEMGetAllocatableSizeForFrmHeapEx)(int heap, int align); 43 | extern void *(* MEMAllocFromFrmHeapEx)(int heap, unsigned int size, int align); 44 | extern void (* MEMFreeToFrmHeap)(int heap, int mode); 45 | extern void *(* MEMAllocFromExpHeapEx)(int heap, unsigned int size, int align); 46 | extern int (* MEMCreateExpHeapEx)(void* address, unsigned int size, unsigned short flags); 47 | extern void *(* MEMDestroyExpHeap)(int heap); 48 | extern void (* MEMFreeToExpHeap)(int heap, void* ptr); 49 | 50 | static int mem1_heap = -1; 51 | static int bucket_heap = -1; 52 | 53 | void memoryInitialize(void) 54 | { 55 | int mem1_heap_handle = MEMGetBaseHeapHandle(MEMORY_ARENA_1); 56 | unsigned int mem1_allocatable_size = MEMGetAllocatableSizeForFrmHeapEx(mem1_heap_handle, 4); 57 | void *mem1_memory = MEMAllocFromFrmHeapEx(mem1_heap_handle, mem1_allocatable_size, 4); 58 | if(mem1_memory) 59 | mem1_heap = MEMCreateExpHeapEx(mem1_memory, mem1_allocatable_size, 0); 60 | 61 | int bucket_heap_handle = MEMGetBaseHeapHandle(MEMORY_ARENA_FG_BUCKET); 62 | unsigned int bucket_allocatable_size = MEMGetAllocatableSizeForFrmHeapEx(bucket_heap_handle, 4); 63 | void *bucket_memory = MEMAllocFromFrmHeapEx(bucket_heap_handle, bucket_allocatable_size, 4); 64 | if(bucket_memory) 65 | bucket_heap = MEMCreateExpHeapEx(bucket_memory, bucket_allocatable_size, 0); 66 | } 67 | 68 | void memoryRelease(void) 69 | { 70 | MEMDestroyExpHeap(mem1_heap); 71 | MEMFreeToFrmHeap(MEMGetBaseHeapHandle(MEMORY_ARENA_1), 3); 72 | mem1_heap = -1; 73 | 74 | MEMDestroyExpHeap(bucket_heap); 75 | MEMFreeToFrmHeap(MEMGetBaseHeapHandle(MEMORY_ARENA_FG_BUCKET), 3); 76 | bucket_heap = -1; 77 | } 78 | 79 | //!------------------------------------------------------------------------------------------- 80 | //! wraps 81 | //!------------------------------------------------------------------------------------------- 82 | void *__wrap_malloc(size_t size) 83 | { 84 | // pointer to a function resolve 85 | return ((void * (*)(size_t))(*pMEMAllocFromDefaultHeap))(size); 86 | } 87 | 88 | void *__wrap_memalign(size_t align, size_t size) 89 | { 90 | if (align < 4) 91 | align = 4; 92 | 93 | // pointer to a function resolve 94 | return ((void * (*)(size_t, size_t))(*pMEMAllocFromDefaultHeapEx))(size, align); 95 | } 96 | 97 | void __wrap_free(void *p) 98 | { 99 | // pointer to a function resolve 100 | if(p != 0) 101 | ((void (*)(void *))(*pMEMFreeToDefaultHeap))(p); 102 | } 103 | 104 | void *__wrap_calloc(size_t n, size_t size) 105 | { 106 | void *p = __wrap_malloc(n * size); 107 | if (p != 0) { 108 | memset(p, 0, n * size); 109 | } 110 | return p; 111 | } 112 | 113 | size_t __wrap_malloc_usable_size(void *p) 114 | { 115 | //! TODO: this is totally wrong and needs to be addressed 116 | return 0x7FFFFFFF; 117 | } 118 | 119 | void *__wrap_realloc(void *p, size_t size) 120 | { 121 | void *new_ptr = __wrap_malloc(size); 122 | if (new_ptr != 0) 123 | { 124 | memcpy(new_ptr, p, __wrap_malloc_usable_size(p) < size ? __wrap_malloc_usable_size(p) : size); 125 | __wrap_free(p); 126 | } 127 | return new_ptr; 128 | } 129 | 130 | //!------------------------------------------------------------------------------------------- 131 | //! reent versions 132 | //!------------------------------------------------------------------------------------------- 133 | void *__wrap__malloc_r(struct _reent *r, size_t size) 134 | { 135 | return __wrap_malloc(size); 136 | } 137 | 138 | void *__wrap__calloc_r(struct _reent *r, size_t n, size_t size) 139 | { 140 | return __wrap_calloc(n, size); 141 | } 142 | 143 | void *__wrap__memalign_r(struct _reent *r, size_t align, size_t size) 144 | { 145 | return __wrap_memalign(align, size); 146 | } 147 | 148 | void __wrap__free_r(struct _reent *r, void *p) 149 | { 150 | __wrap_free(p); 151 | } 152 | 153 | size_t __wrap__malloc_usable_size_r(struct _reent *r, void *p) 154 | { 155 | return __wrap_malloc_usable_size(p); 156 | } 157 | 158 | void *__wrap__realloc_r(struct _reent *r, void *p, size_t size) 159 | { 160 | return __wrap_realloc(p, size); 161 | } 162 | 163 | //!------------------------------------------------------------------------------------------- 164 | //! some wrappers 165 | //!------------------------------------------------------------------------------------------- 166 | void * MEM2_alloc(unsigned int size, unsigned int align) 167 | { 168 | return __wrap_memalign(align, size); 169 | } 170 | 171 | void MEM2_free(void *ptr) 172 | { 173 | __wrap_free(ptr); 174 | } 175 | 176 | void * MEM1_alloc(unsigned int size, unsigned int align) 177 | { 178 | if (align < 4) 179 | align = 4; 180 | return MEMAllocFromExpHeapEx(mem1_heap, size, align); 181 | } 182 | 183 | void MEM1_free(void *ptr) 184 | { 185 | MEMFreeToExpHeap(mem1_heap, ptr); 186 | } 187 | 188 | void * MEMBucket_alloc(unsigned int size, unsigned int align) 189 | { 190 | if (align < 4) 191 | align = 4; 192 | return MEMAllocFromExpHeapEx(bucket_heap, size, align); 193 | } 194 | 195 | void MEMBucket_free(void *ptr) 196 | { 197 | MEMFreeToExpHeap(bucket_heap, ptr); 198 | } 199 | -------------------------------------------------------------------------------- /src/dynamic_libs/socket_functions.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2015 3 | * by Dimok 4 | * 5 | * This software is provided 'as-is', without any express or implied 6 | * warranty. In no event will the authors be held liable for any 7 | * damages arising from the use of this software. 8 | * 9 | * Permission is granted to anyone to use this software for any 10 | * purpose, including commercial applications, and to alter it and 11 | * redistribute it freely, subject to the following restrictions: 12 | * 13 | * 1. The origin of this software must not be misrepresented; you 14 | * must not claim that you wrote the original software. If you use 15 | * this software in a product, an acknowledgment in the product 16 | * documentation would be appreciated but is not required. 17 | * 18 | * 2. Altered source versions must be plainly marked as such, and 19 | * must not be misrepresented as being the original software. 20 | * 21 | * 3. This notice may not be removed or altered from any source 22 | * distribution. 23 | ***************************************************************************/ 24 | #ifndef __SOCKET_FUNCTIONS_H_ 25 | #define __SOCKET_FUNCTIONS_H_ 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | #include 32 | 33 | #include "common/types.h" 34 | 35 | // number max of concurrents transfer slots 36 | #define NB_SIMULTANEOUS_TRANSFERS 8 37 | 38 | 39 | #define INADDR_ANY 0 40 | 41 | #define AF_INET 2 42 | 43 | #define IPPROTO_IP 0 44 | #define IPPROTO_TCP 6 45 | #define IPPROTO_UDP 17 46 | 47 | #define TCP_NODELAY 0x2004 48 | 49 | #define SOL_SOCKET -1 50 | #define SOCK_STREAM 1 51 | #define SOCK_DGRAM 2 52 | 53 | /* 54 | * Option flags per-socket. 55 | */ 56 | #define SO_DEBUG 0x0001 /* turn on debugging info recording */ 57 | #define SO_ACCEPTCONN 0x0002 /* socket has had listen() */ 58 | #define SO_REUSEADDR 0x0004 59 | #define SO_KEEPALIVE 0x0008 /* keep connections alive */ 60 | #define SO_DONTROUTE 0x0010 /* just use interface addresses */ 61 | #define SO_BROADCAST 0x0020 // broadcast 62 | #define SO_USELOOPBACK 0x0040 /* bypass hardware when possible */ 63 | 64 | #define SO_LINGER 0x0080 // linger (no effect?) 65 | #define SO_OOBINLINE 0x0100 // out-of-band data inline (no effect?) 66 | #define SO_TCPSACK 0x0200 // set tcp selective acknowledgment 67 | #define SO_WINSCALE 0x0400 // set tcp window scaling 68 | 69 | #define TCP_NOACKDELAY 0x2002 /* suppress delayed ACKs */ 70 | #define TCP_MAXSEG 0x2003 /* set maximum segment size */ 71 | 72 | #define SO_USERBUF 0x10000 // enable userspace buffer 73 | /* 74 | * Additional options, not kept in so_options. 75 | */ 76 | #define SO_SNDBUF 0x1001 // send buffer size 77 | #define SO_RCVBUF 0x1002 // receive buffer size 78 | #define SO_SNDLOWAT 0x1003 // send low-water mark (no effect?) 79 | #define SO_RCVLOWAT 0x1004 // receive low-water mark 80 | #define SO_SNDTIMEO 0x1005 /* send timeout */ 81 | #define SO_RCVTIMEO 0x1006 /* receive timeout */ 82 | 83 | #define SO_TYPE 0x1008 // get socket type 84 | 85 | #define SO_NBIO 0x1014 // set socket to NON-blocking mode 86 | #define SO_BIO 0x1015 // set socket to blocking mode 87 | #define SO_NONBLOCK 0x1016 88 | #define SO_MYADDR 0x1013 89 | 90 | // From https://wiiubrew.org/wiki/Nsysnet.rpl 91 | // SO functions return codes 92 | #define SO_SUCCESS 0 // The operation were successful 93 | #define SO_ETIMEDOUT 2 // The connection timed out 94 | #define SO_ECONNREFUSED 7 // The connection were refused 95 | #define SO_ERROR 41 // The operation hit a generic error and were not successful 96 | #define SO_ELIBNOTREADY 43 // The library is not ready, did you forget to initialize it? 97 | 98 | #define ENODATA 1 99 | #define ENOENT 2 100 | #define EISCONN 3 101 | #define EWOULDBLOCK 6 102 | #define EALREADY 10 103 | #define EAGAIN EWOULDBLOCK 104 | #define EINVAL 11 105 | #define ENOMEM 18 106 | #define ENODEV 19 107 | #define EINPROGRESS 22 108 | #define EBUSY 16 /* Device or resource busy */ 109 | #define ENOMEM 18 110 | #define ENODEV 19 111 | #define EINPROGRESS 22 112 | #define ENFILE 23 /* Too many open files in system */ 113 | #define EMFILE 24 /* File descriptor value too large */ 114 | #define MSG_DONTWAIT 32 115 | #define ETIME 62 /* Stream ioctl timeout */ 116 | #define ECONNREFUSED 111 /* Connection refused */ 117 | #define ECONNABORTED 113 /* Software caused connection abort */ 118 | #define ETIMEDOUT 116 /* Connection timed out */ 119 | #define EHOSTUNREACH 118 /* Host is unreachable */ 120 | #define MSG_DONTWAIT 32 121 | 122 | #define htonl(x) x 123 | #define htons(x) x 124 | #define ntohl(x) x 125 | #define ntohs(x) x 126 | 127 | #define geterrno() (socketlasterr()) 128 | 129 | struct in_addr { 130 | unsigned int s_addr; 131 | }; 132 | struct sockaddr_in { 133 | short sin_family; 134 | unsigned short sin_port; 135 | struct in_addr sin_addr; 136 | char sin_zero[8]; 137 | }; 138 | 139 | struct sockaddr 140 | { 141 | unsigned short sa_family; 142 | char sa_data[14]; 143 | }; 144 | 145 | void InitSocketFunctionPointers(void); 146 | void FreeSocketFunctionPointers(void); 147 | void InitAcquireSocket(void); 148 | 149 | extern int32_t (*socket_lib_init)(void); 150 | extern int32_t (*socket_lib_finish)(void); 151 | extern int32_t (*socket)(int32_t domain, int32_t type, int32_t protocol); 152 | extern int32_t (*socketclose)(int32_t s); 153 | extern int32_t (*shutdown)(int32_t s, int32_t how); 154 | extern int32_t (*connect)(int32_t s, void *addr, int32_t addrlen); 155 | extern int32_t (*bind)(int32_t s,struct sockaddr *name,int32_t namelen); 156 | extern int32_t (*listen)(int32_t s,uint32_t backlog); 157 | extern int32_t (*accept)(int32_t s,struct sockaddr *addr,int32_t *addrlen); 158 | extern int32_t (*send)(int32_t s, const void *buffer, int32_t size, int32_t flags); 159 | extern int32_t (*recv)(int32_t s, void *buffer, int32_t size, int32_t flags); 160 | extern int32_t (*recvfrom)(int32_t sockfd, void *buf, int32_t len, int32_t flags,struct sockaddr *src_addr, int32_t *addrlen); 161 | extern int32_t (*socketlasterr)(void); 162 | 163 | extern int32_t (*sendto)(int32_t s, const void *buffer, int32_t size, int32_t flags, const struct sockaddr *dest, int32_t dest_len); 164 | extern int32_t (*setsockopt)(int32_t s, int32_t level, int32_t optname, void *optval, int32_t optlen); 165 | extern int32_t (*getsockopt)(int32_t s, int32_t level, int32_t optname, void *optval, int32_t optlen); 166 | extern int32_t (*somemopt) (int type, void *buf, size_t bufsize, int unk); 167 | 168 | extern char * (*inet_ntoa)(struct in_addr in); 169 | extern int32_t (*inet_aton)(const char *cp, struct in_addr *inp); 170 | extern const char * (*inet_ntop)(int32_t af, const void *src, char *dst, int32_t size); 171 | extern int32_t (*inet_pton)(int32_t af, const char *src, void *dst); 172 | 173 | #ifdef __cplusplus 174 | } 175 | #endif 176 | 177 | #endif // __SOCKET_FUNCTIONS_H_ 178 | -------------------------------------------------------------------------------- /src/dynamic_libs/padscore_functions.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2015 3 | * by Dimok 4 | * 5 | * This software is provided 'as-is', without any express or implied 6 | * warranty. In no event will the authors be held liable for any 7 | * damages arising from the use of this software. 8 | * 9 | * Permission is granted to anyone to use this software for any 10 | * purpose, including commercial applications, and to alter it and 11 | * redistribute it freely, subject to the following restrictions: 12 | * 13 | * 1. The origin of this software must not be misrepresented; you 14 | * must not claim that you wrote the original software. If you use 15 | * this software in a product, an acknowledgment in the product 16 | * documentation would be appreciated but is not required. 17 | * 18 | * 2. Altered source versions must be plainly marked as such, and 19 | * must not be misrepresented as being the original software. 20 | * 21 | * 3. This notice may not be removed or altered from any source 22 | * distribution. 23 | ***************************************************************************/ 24 | #ifndef __PAD_SCORE_FUNCTIONS_H_ 25 | #define __PAD_SCORE_FUNCTIONS_H_ 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | #include "vpad_functions.h" 32 | 33 | extern uint32_t padscore_handle; 34 | 35 | #define WPAD_EXT_CORE 0 36 | #define WPAD_EXT_NUNCHUK 1 37 | #define WPAD_EXT_CLASSIC 2 38 | #define WPAD_EXT_MPLUS 5 39 | #define WPAD_EXT_MPLUS_NUNCHUK 6 40 | #define WPAD_EXT_MPLUS_CLASSIC 7 41 | #define WPAD_EXT_PRO_CONTROLLER 31 42 | 43 | #define WPAD_FMT_PRO_CONTROLLER 22 44 | 45 | #define WPAD_BUTTON_LEFT 0x0001 46 | #define WPAD_BUTTON_RIGHT 0x0002 47 | #define WPAD_BUTTON_DOWN 0x0004 48 | #define WPAD_BUTTON_UP 0x0008 49 | #define WPAD_BUTTON_PLUS 0x0010 50 | #define WPAD_BUTTON_2 0x0100 51 | #define WPAD_BUTTON_1 0x0200 52 | #define WPAD_BUTTON_B 0x0400 53 | #define WPAD_BUTTON_A 0x0800 54 | #define WPAD_BUTTON_MINUS 0x1000 55 | #define WPAD_BUTTON_Z 0x2000 56 | #define WPAD_BUTTON_C 0x4000 57 | #define WPAD_BUTTON_HOME 0x8000 58 | 59 | #define WPAD_CLASSIC_BUTTON_UP 0x0001 60 | #define WPAD_CLASSIC_BUTTON_LEFT 0x0002 61 | #define WPAD_CLASSIC_BUTTON_ZR 0x0004 62 | #define WPAD_CLASSIC_BUTTON_X 0x0008 63 | #define WPAD_CLASSIC_BUTTON_A 0x0010 64 | #define WPAD_CLASSIC_BUTTON_Y 0x0020 65 | #define WPAD_CLASSIC_BUTTON_B 0x0040 66 | #define WPAD_CLASSIC_BUTTON_ZL 0x0080 67 | #define WPAD_CLASSIC_BUTTON_R 0x0200 68 | #define WPAD_CLASSIC_BUTTON_PLUS 0x0400 69 | #define WPAD_CLASSIC_BUTTON_HOME 0x0800 70 | #define WPAD_CLASSIC_BUTTON_MINUS 0x1000 71 | #define WPAD_CLASSIC_BUTTON_L 0x2000 72 | #define WPAD_CLASSIC_BUTTON_DOWN 0x4000 73 | #define WPAD_CLASSIC_BUTTON_RIGHT 0x8000 74 | 75 | #define WPAD_PRO_BUTTON_UP 0x00000001 76 | #define WPAD_PRO_BUTTON_LEFT 0x00000002 77 | #define WPAD_PRO_TRIGGER_ZR 0x00000004 78 | #define WPAD_PRO_BUTTON_X 0x00000008 79 | #define WPAD_PRO_BUTTON_A 0x00000010 80 | #define WPAD_PRO_BUTTON_Y 0x00000020 81 | #define WPAD_PRO_BUTTON_B 0x00000040 82 | #define WPAD_PRO_TRIGGER_ZL 0x00000080 83 | #define WPAD_PRO_RESERVED 0x00000100 84 | #define WPAD_PRO_TRIGGER_R 0x00000200 85 | #define WPAD_PRO_BUTTON_PLUS 0x00000400 86 | #define WPAD_PRO_BUTTON_HOME 0x00000800 87 | #define WPAD_PRO_BUTTON_MINUS 0x00001000 88 | #define WPAD_PRO_TRIGGER_L 0x00002000 89 | #define WPAD_PRO_BUTTON_DOWN 0x00004000 90 | #define WPAD_PRO_BUTTON_RIGHT 0x00008000 91 | #define WPAD_PRO_BUTTON_STICK_R 0x00010000 92 | #define WPAD_PRO_BUTTON_STICK_L 0x00020000 93 | 94 | #define WPAD_PRO_STICK_L_EMULATION_UP 0x00200000 95 | #define WPAD_PRO_STICK_L_EMULATION_DOWN 0x00100000 96 | #define WPAD_PRO_STICK_L_EMULATION_LEFT 0x00040000 97 | #define WPAD_PRO_STICK_L_EMULATION_RIGHT 0x00080000 98 | 99 | #define WPAD_PRO_STICK_R_EMULATION_UP 0x02000000 100 | #define WPAD_PRO_STICK_R_EMULATION_DOWN 0x01000000 101 | #define WPAD_PRO_STICK_R_EMULATION_LEFT 0x00400000 102 | #define WPAD_PRO_STICK_R_EMULATION_RIGHT 0x00800000 103 | 104 | typedef struct _KPADData { 105 | uint32_t btns_h; 106 | uint32_t btns_d; 107 | uint32_t btns_r; 108 | float acc_x; 109 | float acc_y; 110 | float acc_z; 111 | float acc_value; 112 | float acc_speed; 113 | float pos_x; 114 | float pos_y; 115 | float vec_x; 116 | float vec_y; 117 | float speed; 118 | float angle_x; 119 | float angle_y; 120 | float angle_vec_x; 121 | float angle_vec_y; 122 | float angle_speed; 123 | float dist; 124 | float dist_vec; 125 | float dist_speed; 126 | float acc_vertical_x; 127 | float acc_vertical_y; 128 | uint8_t device_type; 129 | int8_t wpad_error; 130 | int8_t pos_valid; 131 | uint8_t format; 132 | 133 | union { 134 | struct { 135 | float stick_x; 136 | float stick_y; 137 | } nunchuck; 138 | 139 | struct { 140 | uint32_t btns_h; 141 | uint32_t btns_d; 142 | uint32_t btns_r; 143 | float lstick_x; 144 | float lstick_y; 145 | float rstick_x; 146 | float rstick_y; 147 | float ltrigger; 148 | float rtrigger; 149 | } classic; 150 | 151 | struct { 152 | uint32_t btns_h; 153 | uint32_t btns_d; 154 | uint32_t btns_r; 155 | float lstick_x; 156 | float lstick_y; 157 | float rstick_x; 158 | float rstick_y; 159 | int32_t charging; 160 | int32_t wired; 161 | } pro; 162 | 163 | uint32_t unused_6[20]; 164 | }; 165 | uint32_t unused_7[16]; 166 | } KPADData; 167 | 168 | typedef struct WPADReadData_ { 169 | uint8_t unknown[40]; 170 | uint8_t dev; 171 | uint8_t err; 172 | uint8_t unknown1[2]; 173 | uint32_t buttons; 174 | int16_t l_stick_x; 175 | int16_t l_stick_y; 176 | int16_t r_stick_x; 177 | int16_t r_stick_y; 178 | uint8_t unknown2[8]; 179 | uint8_t fmt; 180 | } WPADReadData; 181 | 182 | typedef WPADReadData KPADUnifiedWpadData; 183 | 184 | void InitPadScoreFunctionPointers(void); 185 | void InitAcquirePadScore(void); 186 | 187 | typedef void (* wpad_sampling_callback_t)(int32_t chan); 188 | typedef void (* wpad_extension_callback_t)(int32_t chan, int32_t status); 189 | typedef void (* wpad_connect_callback_t)(int32_t chan, int32_t status); 190 | 191 | extern void (* KPADInit)(void); 192 | extern void (* WPADInit)(void); 193 | extern int32_t (* WPADProbe)(int32_t chan, uint32_t * pad_type); 194 | extern int32_t (* WPADSetDataFormat)(int32_t chan, int32_t format); 195 | extern void (* WPADEnableURCC)(int32_t enable); 196 | extern void (* WPADRead)(int32_t chan, void * data); 197 | extern int32_t (* KPADRead)(int32_t chan, KPADData * data, uint32_t size); 198 | extern int32_t (* KPADReadEx)(int32_t chan, KPADData * data, uint32_t size, int32_t *error); 199 | extern void (*WPADSetAutoSleepTime)(uint8_t time); 200 | extern void (*WPADDisconnect)( int32_t chan ); 201 | 202 | #ifdef __cplusplus 203 | } 204 | #endif 205 | 206 | #endif // __PAD_SCORE_FUNCTIONS_H_ -------------------------------------------------------------------------------- /src/fat/libfat.c: -------------------------------------------------------------------------------- 1 | /* 2 | libfat.c 3 | Simple functionality for startup, mounting and unmounting of FAT-based devices. 4 | 5 | Copyright (c) 2006 Michael "Chishm" Chisholm 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation and/or 14 | other materials provided with the distribution. 15 | 3. The name of the author may not be used to endorse or promote products derived 16 | from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 20 | AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 26 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #include "common.h" 37 | #include "partition.h" 38 | #include "fatfile.h" 39 | #include "fatdir.h" 40 | #include "lock.h" 41 | #include "mem_allocate.h" 42 | #include "disc.h" 43 | 44 | static const devoptab_t dotab_fat = { 45 | "fat", 46 | sizeof (FILE_STRUCT), 47 | _FAT_open_r, 48 | _FAT_close_r, 49 | _FAT_write_r, 50 | _FAT_read_r, 51 | _FAT_seek_r, 52 | _FAT_fstat_r, 53 | _FAT_stat_r, 54 | _FAT_link_r, 55 | _FAT_unlink_r, 56 | _FAT_chdir_r, 57 | _FAT_rename_r, 58 | _FAT_mkdir_r, 59 | sizeof (DIR_STATE_STRUCT), 60 | _FAT_diropen_r, 61 | _FAT_dirreset_r, 62 | _FAT_dirnext_r, 63 | _FAT_dirclose_r, 64 | _FAT_statvfs_r, 65 | _FAT_ftruncate_r, 66 | _FAT_fsync_r, 67 | NULL, /* Device data */ 68 | NULL, // chmod_r 69 | NULL, // fchmod_r 70 | _FAT_rmdir_r, 71 | _FAT_stat_r, 72 | NULL, // _FAT_utimes_r 73 | }; 74 | 75 | bool fatMount (const char* name, const DISC_INTERFACE* interface, sec_t startSector, uint32_t cacheSize, uint32_t SectorsPerPage) { 76 | PARTITION* partition; 77 | devoptab_t* devops; 78 | char* nameCopy; 79 | 80 | if(!name || strlen(name) > 8 || !interface) 81 | return false; 82 | 83 | if(!interface->startup()) 84 | return false; 85 | 86 | if(!interface->isInserted()) 87 | return false; 88 | 89 | char devname[10]; 90 | strcpy(devname, name); 91 | strcat(devname, ":"); 92 | if(FindDevice(devname) >= 0) 93 | return true; 94 | 95 | devops = _FAT_mem_allocate (sizeof(devoptab_t) + strlen(name) + 1); 96 | if (!devops) { 97 | return false; 98 | } 99 | // Use the space allocated at the end of the devoptab struct for storing the name 100 | nameCopy = (char*)(devops+1); 101 | 102 | // Initialize the file system 103 | partition = _FAT_partition_constructor (interface, cacheSize, SectorsPerPage, startSector); 104 | if (!partition) { 105 | _FAT_mem_free (devops); 106 | return false; 107 | } 108 | 109 | // Add an entry for this device to the devoptab table 110 | memcpy (devops, &dotab_fat, sizeof(dotab_fat)); 111 | strcpy (nameCopy, name); 112 | devops->name = nameCopy; 113 | devops->deviceData = partition; 114 | 115 | AddDevice (devops); 116 | 117 | return true; 118 | } 119 | 120 | bool fatMountSimple (const char* name, const DISC_INTERFACE* interface) { 121 | return fatMount (name, interface, 0, DEFAULT_CACHE_PAGES, DEFAULT_SECTORS_PAGE); 122 | } 123 | 124 | void fatUnmount (const char* name) { 125 | devoptab_t *devops; 126 | PARTITION* partition; 127 | 128 | if(!name) 129 | return; 130 | 131 | devops = (devoptab_t*)GetDeviceOpTab (name); 132 | if (!devops) { 133 | return; 134 | } 135 | 136 | // Perform a quick check to make sure we're dealing with a libfat controlled device 137 | if (devops->open_r != dotab_fat.open_r) { 138 | return; 139 | } 140 | 141 | if (RemoveDevice (name) == -1) { 142 | return; 143 | } 144 | 145 | partition = (PARTITION*)devops->deviceData; 146 | _FAT_partition_destructor (partition); 147 | _FAT_mem_free (devops); 148 | } 149 | 150 | 151 | bool fatInitEx (uint32_t cacheSize, bool setAsDefaultDevice, uint32_t cacheSectorsPage) { 152 | int i; 153 | int defaultDevice = -1; 154 | const DISC_INTERFACE *disc; 155 | 156 | for (i = 0; 157 | _FAT_disc_interfaces[i].name != NULL && _FAT_disc_interfaces[i].getInterface != NULL; 158 | i++) 159 | { 160 | disc = _FAT_disc_interfaces[i].getInterface(); 161 | if (!disc) { 162 | continue; 163 | } 164 | if (fatMount (_FAT_disc_interfaces[i].name, disc, 0, cacheSize, cacheSectorsPage)) { 165 | // The first device to successfully mount is set as the default 166 | if (defaultDevice < 0) { 167 | defaultDevice = i; 168 | } 169 | } 170 | } 171 | 172 | if (defaultDevice < 0) { 173 | // None of our devices mounted 174 | return false; 175 | } 176 | 177 | if (setAsDefaultDevice) { 178 | char filePath[PATH_MAX]; 179 | strcpy (filePath, _FAT_disc_interfaces[defaultDevice].name); 180 | strcat (filePath, ":/"); 181 | #ifdef ARGV_MAGIC 182 | if ( __system_argv->argvMagic == ARGV_MAGIC && __system_argv->argc >= 1 && strrchr( __system_argv->argv[0], '/' )!=NULL ) { 183 | // Check the app's path against each of our mounted devices, to see 184 | // if we can support it. If so, change to that path. 185 | for (i = 0; 186 | _FAT_disc_interfaces[i].name != NULL && _FAT_disc_interfaces[i].getInterface != NULL; 187 | i++) 188 | { 189 | if ( !strncasecmp( __system_argv->argv[0], _FAT_disc_interfaces[i].name, 190 | strlen(_FAT_disc_interfaces[i].name))) 191 | { 192 | char *lastSlash; 193 | strcpy(filePath, __system_argv->argv[0]); 194 | lastSlash = strrchr( filePath, '/' ); 195 | 196 | if ( NULL != lastSlash) { 197 | if ( *(lastSlash - 1) == ':') lastSlash++; 198 | *lastSlash = 0; 199 | } 200 | } 201 | } 202 | } 203 | #endif 204 | chdir (filePath); 205 | } 206 | 207 | return true; 208 | } 209 | 210 | bool fatInit (uint32_t cacheSize, bool setAsDefaultDevice) { 211 | return fatInitEx(cacheSize, setAsDefaultDevice, DEFAULT_SECTORS_PAGE); 212 | } 213 | 214 | bool fatInitDefault (void) { 215 | return fatInit (DEFAULT_CACHE_PAGES, true); 216 | } 217 | 218 | void fatGetVolumeLabel (const char* name, char *label) { 219 | devoptab_t *devops; 220 | PARTITION* partition; 221 | char *buf; 222 | int namelen,i; 223 | 224 | if(!name || !label) 225 | return; 226 | 227 | namelen = strlen(name); 228 | buf=(char*)_FAT_mem_allocate(sizeof(char)*namelen+2); 229 | strcpy(buf,name); 230 | 231 | if (name[namelen-1] == '/') { 232 | buf[namelen-1]='\0'; 233 | namelen--; 234 | } 235 | 236 | if (name[namelen-1] != ':') { 237 | buf[namelen]=':'; 238 | buf[namelen+1]='\0'; 239 | } 240 | 241 | devops = (devoptab_t*)GetDeviceOpTab(buf); 242 | 243 | for(i=0;buf[i]!='\0' && buf[i]!=':';i++); 244 | if (!devops || strncasecmp(buf,devops->name,i)) { 245 | _FAT_mem_free(buf); 246 | return; 247 | } 248 | 249 | _FAT_mem_free(buf); 250 | 251 | // Perform a quick check to make sure we're dealing with a libfat controlled device 252 | if (devops->open_r != dotab_fat.open_r) { 253 | return; 254 | } 255 | 256 | partition = (PARTITION*)devops->deviceData; 257 | 258 | if(!_FAT_directory_getVolumeLabel(partition, label)) { 259 | strncpy(label,partition->label,11); 260 | label[11]='\0'; 261 | } 262 | if(!strncmp(label, "NO NAME", 7)) label[0]='\0'; 263 | } 264 | -------------------------------------------------------------------------------- /src/dynamic_libs/fs_functions.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2015 3 | * by Dimok 4 | * 5 | * This software is provided 'as-is', without any express or implied 6 | * warranty. In no event will the authors be held liable for any 7 | * damages arising from the use of this software. 8 | * 9 | * Permission is granted to anyone to use this software for any 10 | * purpose, including commercial applications, and to alter it and 11 | * redistribute it freely, subject to the following restrictions: 12 | * 13 | * 1. The origin of this software must not be misrepresented; you 14 | * must not claim that you wrote the original software. If you use 15 | * this software in a product, an acknowledgment in the product 16 | * documentation would be appreciated but is not required. 17 | * 18 | * 2. Altered source versions must be plainly marked as such, and 19 | * must not be misrepresented as being the original software. 20 | * 21 | * 3. This notice may not be removed or altered from any source 22 | * distribution. 23 | ***************************************************************************/ 24 | #include "fs_functions.h" 25 | #include "os_functions.h" 26 | 27 | EXPORT_DECL(int32_t, FSInit, void); 28 | EXPORT_DECL(int32_t, FSShutdown, void); 29 | EXPORT_DECL(int32_t, FSAddClient, void *pClient, int32_t errHandling); 30 | EXPORT_DECL(int32_t, FSAddClientEx, void *pClient, int32_t unk_zero_param, int32_t errHandling); 31 | EXPORT_DECL(int32_t, FSDelClient, void *pClient); 32 | EXPORT_DECL(void, FSInitCmdBlock, void *pCmd); 33 | EXPORT_DECL(void *, FSGetCurrentCmdBlock, void *pClient); 34 | EXPORT_DECL(int32_t, FSGetMountSource, void *pClient, void *pCmd, int32_t type, void *source, int32_t errHandling); 35 | 36 | EXPORT_DECL(int32_t, FSMount, void *pClient, void *pCmd, void *source, char *target, uint32_t bytes, int32_t errHandling); 37 | EXPORT_DECL(int32_t, FSUnmount, void *pClient, void *pCmd, const char *target, int32_t errHandling); 38 | 39 | EXPORT_DECL(int32_t, FSGetStat, void *pClient, void *pCmd, const char *path, FSStat *stats, int32_t errHandling); 40 | EXPORT_DECL(int32_t, FSGetStatAsync, void *pClient, void *pCmd, const char *path, void *stats, int32_t error, void *asyncParams); 41 | EXPORT_DECL(int32_t, FSRename, void *pClient, void *pCmd, const char *oldPath, const char *newPath, int32_t error); 42 | EXPORT_DECL(int32_t, FSRenameAsync, void *pClient, void *pCmd, const char *oldPath, const char *newPath, int32_t error, void *asyncParams); 43 | EXPORT_DECL(int32_t, FSRemove, void *pClient, void *pCmd, const char *path, int32_t error); 44 | EXPORT_DECL(int32_t, FSRemoveAsync, void *pClient, void *pCmd, const char *path, int32_t error, void *asyncParams); 45 | EXPORT_DECL(int32_t, FSFlushQuota, void *pClient, void *pCmd, const char* path, int32_t error); 46 | EXPORT_DECL(int32_t, FSFlushQuotaAsync, void *pClient, void *pCmd, const char *path, int32_t error, void *asyncParams); 47 | EXPORT_DECL(int32_t, FSGetFreeSpaceSize, void *pClient, void *pCmd, const char *path, uint64_t *returnedFreeSize, int32_t error); 48 | EXPORT_DECL(int32_t, FSGetFreeSpaceSizeAsync, void *pClient, void *pCmd, const char *path, uint64_t *returnedFreeSize, int32_t error, void *asyncParams); 49 | EXPORT_DECL(int32_t, FSRollbackQuota, void *pClient, void *pCmd, const char *path, int32_t error); 50 | EXPORT_DECL(int32_t, FSRollbackQuotaAsync, void *pClient, void *pCmd, const char *path, int32_t error, void *asyncParams); 51 | 52 | EXPORT_DECL(int32_t, FSOpenDir, void *pClient, void *pCmd, const char *path, int32_t *dh, int32_t errHandling); 53 | EXPORT_DECL(int32_t, FSOpenDirAsync, void *pClient, void* pCmd, const char *path, int32_t *handle, int32_t error, void *asyncParams); 54 | EXPORT_DECL(int32_t, FSReadDir, void *pClient, void *pCmd, int32_t dh, FSDirEntry *dir_entry, int32_t errHandling); 55 | EXPORT_DECL(int32_t, FSRewindDir, void *pClient, void *pCmd, int32_t dh, int32_t errHandling); 56 | EXPORT_DECL(int32_t, FSCloseDir, void *pClient, void *pCmd, int32_t dh, int32_t errHandling); 57 | EXPORT_DECL(int32_t, FSChangeDir, void *pClient, void *pCmd, const char *path, int32_t errHandling); 58 | EXPORT_DECL(int32_t, FSChangeDirAsync, void *pClient, void *pCmd, const char *path, int32_t error, void *asyncParams); 59 | EXPORT_DECL(int32_t, FSMakeDir, void *pClient, void *pCmd, const char *path, int32_t errHandling); 60 | EXPORT_DECL(int32_t, FSMakeDirAsync, void *pClient, void *pCmd, const char *path, int32_t error, void *asyncParams); 61 | 62 | EXPORT_DECL(int32_t, FSOpenFile, void *pClient, void *pCmd, const char *path, const char *mode, int32_t *fd, int32_t errHandling); 63 | EXPORT_DECL(int32_t, FSOpenFileAsync, void *pClient, void *pCmd, const char *path, const char *mode, int32_t *handle, int32_t error, const void *asyncParams); 64 | EXPORT_DECL(int32_t, FSReadFile, void *pClient, void *pCmd, void *buffer, int32_t size, int32_t count, int32_t fd, int32_t flag, int32_t errHandling); 65 | EXPORT_DECL(int32_t, FSCloseFile, void *pClient, void *pCmd, int32_t fd, int32_t errHandling); 66 | 67 | EXPORT_DECL(int32_t, FSFlushFile, void *pClient, void *pCmd, int32_t fd, int32_t error); 68 | EXPORT_DECL(int32_t, FSTruncateFile, void *pClient, void *pCmd, int32_t fd, int32_t error); 69 | EXPORT_DECL(int32_t, FSGetStatFile, void *pClient, void *pCmd, int32_t fd, void *buffer, int32_t error); 70 | EXPORT_DECL(int32_t, FSSetPosFile, void *pClient, void *pCmd, int32_t fd, uint32_t pos, int32_t error); 71 | EXPORT_DECL(int32_t, FSWriteFile, void *pClient, void *pCmd, const void *source, int32_t block_size, int32_t block_count, int32_t fd, int32_t flag, int32_t error); 72 | 73 | EXPORT_DECL(int32_t, FSBindMount, void *pClient, void *pCmd, char *source, char *target, int32_t error); 74 | EXPORT_DECL(int32_t, FSBindUnmount, void *pClient, void *pCmd, char *target, int32_t error); 75 | 76 | EXPORT_DECL(int32_t, FSMakeQuota, void *pClient, void *pCmd, const char *path,uint32_t mode, uint64_t size, int32_t errHandling); 77 | EXPORT_DECL(int32_t, FSMakeQuotaAsync ,void *pClient, void *pCmd, const char *path,uint32_t mode, uint64_t size, int32_t errHandling,const void *asyncParams); 78 | 79 | EXPORT_DECL(int32_t, FSGetCwd,void * client,void * block,char * buffer,uint32_t bufferSize,uint32_t flags); 80 | 81 | void InitFSFunctionPointers(void) { 82 | if(coreinit_handle == 0) { 83 | InitAcquireOS(); 84 | }; 85 | uint32_t *funcPointer = 0; 86 | 87 | OS_FIND_EXPORT(coreinit_handle, FSInit); 88 | OS_FIND_EXPORT(coreinit_handle, FSShutdown); 89 | OS_FIND_EXPORT(coreinit_handle, FSAddClient); 90 | OS_FIND_EXPORT(coreinit_handle, FSAddClientEx); 91 | OS_FIND_EXPORT(coreinit_handle, FSDelClient); 92 | OS_FIND_EXPORT(coreinit_handle, FSInitCmdBlock); 93 | OS_FIND_EXPORT(coreinit_handle, FSGetCurrentCmdBlock); 94 | OS_FIND_EXPORT(coreinit_handle, FSGetMountSource); 95 | 96 | OS_FIND_EXPORT(coreinit_handle, FSMount); 97 | OS_FIND_EXPORT(coreinit_handle, FSUnmount); 98 | 99 | OS_FIND_EXPORT(coreinit_handle, FSGetStat); 100 | OS_FIND_EXPORT(coreinit_handle, FSGetStatAsync); 101 | OS_FIND_EXPORT(coreinit_handle, FSRename); 102 | OS_FIND_EXPORT(coreinit_handle, FSRenameAsync); 103 | OS_FIND_EXPORT(coreinit_handle, FSRemove); 104 | OS_FIND_EXPORT(coreinit_handle, FSRemoveAsync); 105 | OS_FIND_EXPORT(coreinit_handle, FSFlushQuota); 106 | OS_FIND_EXPORT(coreinit_handle, FSFlushQuotaAsync); 107 | OS_FIND_EXPORT(coreinit_handle, FSGetFreeSpaceSize); 108 | OS_FIND_EXPORT(coreinit_handle, FSGetFreeSpaceSizeAsync); 109 | OS_FIND_EXPORT(coreinit_handle, FSRollbackQuota); 110 | OS_FIND_EXPORT(coreinit_handle, FSRollbackQuotaAsync); 111 | 112 | OS_FIND_EXPORT(coreinit_handle, FSOpenDir); 113 | OS_FIND_EXPORT(coreinit_handle, FSOpenDirAsync); 114 | OS_FIND_EXPORT(coreinit_handle, FSReadDir); 115 | OS_FIND_EXPORT(coreinit_handle, FSRewindDir); 116 | OS_FIND_EXPORT(coreinit_handle, FSCloseDir); 117 | OS_FIND_EXPORT(coreinit_handle, FSChangeDir); 118 | OS_FIND_EXPORT(coreinit_handle, FSChangeDirAsync); 119 | OS_FIND_EXPORT(coreinit_handle, FSMakeDir); 120 | OS_FIND_EXPORT(coreinit_handle, FSMakeDirAsync); 121 | 122 | 123 | OS_FIND_EXPORT(coreinit_handle, FSOpenFile); 124 | OS_FIND_EXPORT(coreinit_handle, FSOpenFileAsync); 125 | OS_FIND_EXPORT(coreinit_handle, FSReadFile); 126 | OS_FIND_EXPORT(coreinit_handle, FSCloseFile); 127 | 128 | OS_FIND_EXPORT(coreinit_handle, FSFlushFile); 129 | OS_FIND_EXPORT(coreinit_handle, FSTruncateFile); 130 | OS_FIND_EXPORT(coreinit_handle, FSGetStatFile); 131 | OS_FIND_EXPORT(coreinit_handle, FSSetPosFile); 132 | OS_FIND_EXPORT(coreinit_handle, FSWriteFile); 133 | 134 | OS_FIND_EXPORT(coreinit_handle, FSBindMount); 135 | OS_FIND_EXPORT(coreinit_handle, FSBindUnmount); 136 | 137 | OS_FIND_EXPORT(coreinit_handle, FSMakeQuota); 138 | OS_FIND_EXPORT(coreinit_handle, FSMakeQuotaAsync); 139 | 140 | OS_FIND_EXPORT(coreinit_handle, FSGetCwd); 141 | } 142 | -------------------------------------------------------------------------------- /src/dynamic_libs/vpad_functions.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2015 3 | * by Dimok 4 | * 5 | * This software is provided 'as-is', without any express or implied 6 | * warranty. In no event will the authors be held liable for any 7 | * damages arising from the use of this software. 8 | * 9 | * Permission is granted to anyone to use this software for any 10 | * purpose, including commercial applications, and to alter it and 11 | * redistribute it freely, subject to the following restrictions: 12 | * 13 | * 1. The origin of this software must not be misrepresented; you 14 | * must not claim that you wrote the original software. If you use 15 | * this software in a product, an acknowledgment in the product 16 | * documentation would be appreciated but is not required. 17 | * 18 | * 2. Altered source versions must be plainly marked as such, and 19 | * must not be misrepresented as being the original software. 20 | * 21 | * 3. This notice may not be removed or altered from any source 22 | * distribution. 23 | ***************************************************************************/ 24 | #ifndef __VPAD_FUNCTIONS_H_ 25 | #define __VPAD_FUNCTIONS_H_ 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | #include 32 | 33 | extern uint32_t vpad_handle; 34 | extern uint32_t vpadbase_handle; 35 | 36 | #define VPAD_BUTTON_A 0x8000 37 | #define VPAD_BUTTON_B 0x4000 38 | #define VPAD_BUTTON_X 0x2000 39 | #define VPAD_BUTTON_Y 0x1000 40 | #define VPAD_BUTTON_LEFT 0x0800 41 | #define VPAD_BUTTON_RIGHT 0x0400 42 | #define VPAD_BUTTON_UP 0x0200 43 | #define VPAD_BUTTON_DOWN 0x0100 44 | #define VPAD_BUTTON_ZL 0x0080 45 | #define VPAD_BUTTON_ZR 0x0040 46 | #define VPAD_BUTTON_L 0x0020 47 | #define VPAD_BUTTON_R 0x0010 48 | #define VPAD_BUTTON_PLUS 0x0008 49 | #define VPAD_BUTTON_MINUS 0x0004 50 | #define VPAD_BUTTON_HOME 0x0002 51 | #define VPAD_BUTTON_SYNC 0x0001 52 | #define VPAD_BUTTON_STICK_R 0x00020000 53 | #define VPAD_BUTTON_STICK_L 0x00040000 54 | #define VPAD_BUTTON_TV 0x00010000 55 | 56 | #define VPAD_STICK_R_EMULATION_LEFT 0x04000000 57 | #define VPAD_STICK_R_EMULATION_RIGHT 0x02000000 58 | #define VPAD_STICK_R_EMULATION_UP 0x01000000 59 | #define VPAD_STICK_R_EMULATION_DOWN 0x00800000 60 | 61 | #define VPAD_STICK_L_EMULATION_LEFT 0x40000000 62 | #define VPAD_STICK_L_EMULATION_RIGHT 0x20000000 63 | #define VPAD_STICK_L_EMULATION_UP 0x10000000 64 | #define VPAD_STICK_L_EMULATION_DOWN 0x08000000 65 | 66 | //! Own definitions 67 | #define VPAD_BUTTON_TOUCH 0x00080000 68 | #define VPAD_MASK_EMULATED_STICKS 0x7F800000 69 | #define VPAD_MASK_BUTTONS ~VPAD_MASK_EMULATED_STICKS 70 | 71 | typedef enum VPADTPResolution { 72 | VPAD_TP_1920x1080, 73 | VPAD_TP_1280x720, 74 | VPAD_TP_854x480 75 | } VPADTPResolution; 76 | 77 | typedef enum VPADGyroZeroDriftMode { 78 | VPAD_GYRO_ZERODRIFT_LOOSE, 79 | VPAD_GYRO_ZERODRIFT_STANDARD, 80 | VPAD_GYRO_ZERODRIFT_TIGHT 81 | } VPADGyroZeroDriftMode; 82 | 83 | typedef struct { 84 | float x,y; 85 | } Vec2D; 86 | 87 | typedef struct { 88 | float x,y,z; 89 | } Vec3D; 90 | 91 | typedef struct { 92 | Vec3D X,Y,Z; 93 | } VPADDir; 94 | 95 | typedef struct { 96 | uint16_t x, y; /* Touch coordinates */ 97 | uint16_t touched; /* 1 = Touched, 0 = Not touched */ 98 | uint16_t invalid; /* 0 = All valid, 1 = X invalid, 2 = Y invalid, 3 = Both invalid? */ 99 | } VPADTPData; 100 | 101 | typedef struct { 102 | int16_t offsetX; 103 | int16_t offsetY; 104 | float scaleX; 105 | float scaleY; 106 | } VPADTPCalibrationParam; 107 | 108 | typedef struct { 109 | uint32_t btns_h; /* Held buttons */ 110 | uint32_t btns_d; /* Buttons that are pressed at that instant */ 111 | uint32_t btns_r; /* Released buttons */ 112 | Vec2D lstick, rstick; /* Each contains 4-byte X and Y components */ 113 | Vec3D acc; /* Status of DRC accelerometer */ 114 | float acc_magnitude; /* Accelerometer magnitude */ 115 | float acc_variation; /* Accelerometer variation */ 116 | Vec2D acc_vertical; /* Vertical */ 117 | Vec3D gyro; /* Gyro data */ 118 | Vec3D angle; /* Angle data */ 119 | int8_t error; /* Error */ 120 | VPADTPData tpdata; /* Normal touchscreen data */ 121 | VPADTPData tpdata1; /* Modified touchscreen data 1 */ 122 | VPADTPData tpdata2; /* Modified touchscreen data 2 */ 123 | VPADDir dir; /* Orientation in three-dimensional space */ 124 | int32_t headphone; /* Set to TRUE if headphones are plugged in, FALSE otherwise */ 125 | Vec3D mag; /* Magnetometer data */ 126 | uint8_t volume; /* 0 to 255 */ 127 | uint8_t battery; /* 0 to 6 */ 128 | uint8_t mic; /* Microphone status */ 129 | uint8_t unk_volume; /* One less than volume */ 130 | uint8_t paddings[7]; 131 | } VPADData; 132 | 133 | void InitVPadFunctionPointers(void); 134 | void InitAcquireVPad(void); 135 | 136 | extern void (* VPADInit)(void); 137 | extern void (* VPADShutdown)(void); 138 | extern int32_t (* VPADRead)(int32_t chan, VPADData *buffer, uint32_t buffer_size, int32_t *error); 139 | extern void (* VPADSetAccParam)(int32_t chan, float play_radius, float sensitivity); 140 | extern void (* VPADGetAccParam)(int32_t chan, float *play_radius, float *sensitivity); 141 | extern void (* VPADSetBtnRepeat)(int32_t chan, float delay_sec, float pulse_sec); 142 | extern void (* VPADEnableStickCrossClamp)(int32_t chan); 143 | extern void (* VPADDisableStickCrossClamp)(int32_t chan); 144 | extern void (* VPADSetLStickClampThreshold)(int32_t chan, int32_t max, int32_t min); 145 | extern void (* VPADSetRStickClampThreshold)(int32_t chan, int32_t max, int32_t min); 146 | extern void (* VPADGetLStickClampThreshold)(int32_t chan, int32_t* max, int32_t* min); 147 | extern void (* VPADGetRStickClampThreshold)(int32_t chan, int32_t* max, int32_t* min); 148 | extern void (* VPADSetStickOrigin)(int32_t chan); 149 | extern void (* VPADDisableLStickZeroClamp)(int32_t chan); 150 | extern void (* VPADDisableRStickZeroClamp)(int32_t chan); 151 | extern void (* VPADEnableLStickZeroClamp)(int32_t chan); 152 | extern void (* VPADEnableRStickZeroClamp)(int32_t chan); 153 | extern void (* VPADSetCrossStickEmulationParamsL)(int32_t chan, float rot_deg, float xy_deg, float radius); 154 | extern void (* VPADSetCrossStickEmulationParamsR)(int32_t chan, float rot_deg, float xy_deg, float radius); 155 | extern void (* VPADGetCrossStickEmulationParamsL)(int32_t chan, float* rot_deg, float* xy_deg, float* radius); 156 | extern void (* VPADGetCrossStickEmulationParamsR)(int32_t chan, float* rot_deg, float* xy_deg, float* radius); 157 | extern void (* VPADSetGyroAngle)(int32_t chan, float ax, float ay, float az); 158 | extern void (* VPADSetGyroDirection)(int32_t chan, VPADDir *dir); 159 | extern void (* VPADSetGyroDirectionMag)(int32_t chan, float mag); 160 | extern void (* VPADSetGyroMagnification)(int32_t chan, float pitch, float yaw, float roll); 161 | extern void (* VPADEnableGyroZeroPlay)(int32_t chan); 162 | extern void (* VPADEnableGyroDirRevise)(int32_t chan); 163 | extern void (* VPADEnableGyroAccRevise)(int32_t chan); 164 | extern void (* VPADDisableGyroZeroPlay)(int32_t chan); 165 | extern void (* VPADDisableGyroDirRevise)(int32_t chan); 166 | extern void (* VPADDisableGyroAccRevise)(int32_t chan); 167 | extern float (* VPADIsEnableGyroZeroPlay)(int32_t chan); 168 | extern float (* VPADIsEnableGyroZeroDrift)(int32_t chan); 169 | extern float (* VPADIsEnableGyroDirRevise)(int32_t chan); 170 | extern float (* VPADIsEnableGyroAccRevise)(int32_t chan); 171 | extern void (* VPADSetGyroZeroPlayParam)(int32_t chan, float radius); 172 | extern void (* VPADSetGyroDirReviseParam)(int32_t chan, float revis_pw); 173 | extern void (* VPADSetGyroAccReviseParam)(int32_t chan, float revise_pw, float revise_range); 174 | extern void (* VPADSetGyroDirReviseBase)(int32_t chan, VPADDir *base); 175 | extern void (* VPADGetGyroZeroPlayParam)(int32_t chan, float *radius); 176 | extern void (* VPADGetGyroDirReviseParam)(int32_t chan, float *revise_pw); 177 | extern void (* VPADGetGyroAccReviseParam)(int32_t chan, float *revise_pw, float *revise_range); 178 | extern void (* VPADInitGyroZeroPlayParam)(int32_t chan); 179 | extern void (* VPADInitGyroDirReviseParam)(int32_t chan); 180 | extern void (* VPADInitGyroAccReviseParam)(int32_t chan); 181 | extern void (* VPADInitGyroZeroDriftMode)(int32_t chan); 182 | extern void (* VPADSetGyroZeroDriftMode)(int32_t chan, VPADGyroZeroDriftMode mode); 183 | extern void (* VPADGetGyroZeroDriftMode)(int32_t chan, VPADGyroZeroDriftMode *mode); 184 | extern int16_t (* VPADCalcTPCalibrationParam)(VPADTPCalibrationParam* param, uint16_t rawX1, uint16_t rawY1, uint16_t x1, uint16_t y1, uint16_t rawX2, uint16_t rawY2, uint16_t x2, uint16_t y2); 185 | extern void (* VPADSetTPCalibrationParam)(int32_t chan, const VPADTPCalibrationParam param); 186 | extern void (* VPADGetTPCalibrationParam)(int32_t chan, VPADTPCalibrationParam* param); 187 | extern void (* VPADGetTPCalibratedPoint)(int32_t chan, VPADTPData *disp, const VPADTPData *raw); 188 | extern void (* VPADGetTPCalibratedPointEx)(int32_t chan, VPADTPResolution tpReso, VPADTPData *disp, const VPADTPData *raw); 189 | extern int32_t (* VPADControlMotor)(int32_t chan, uint8_t* pattern, uint8_t length); 190 | extern void (* VPADStopMotor)(int32_t chan); 191 | extern int32_t (* VPADSetLcdMode)(int32_t chan, int32_t lcdmode); 192 | extern int32_t (* VPADGetLcdMode)(int32_t chan, int32_t *lcdmode); 193 | extern int32_t (* VPADBASEGetMotorOnRemainingCount)(int32_t lcdmode); 194 | extern int32_t (* VPADBASESetMotorOnRemainingCount)(int32_t lcdmode, int32_t counter); 195 | extern void (* VPADBASESetSensorBarSetting)(int32_t chan, int8_t setting); 196 | extern void (* VPADBASEGetSensorBarSetting)(int32_t chan, int8_t *setting); 197 | extern int32_t (*VPADSetSensorBar)(int32_t chan, bool on); 198 | 199 | typedef void(*samplingCallback)(int32_t chan); 200 | extern samplingCallback ( *VPADSetSamplingCallback)(int32_t chan, samplingCallback callback); 201 | 202 | 203 | #ifdef __cplusplus 204 | } 205 | #endif 206 | 207 | #endif // __VPAD_FUNCTIONS_H_ 208 | -------------------------------------------------------------------------------- /src/dynamic_libs/vpad_functions.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | * Copyright (C) 2015 3 | * by Dimok 4 | * 5 | * This software is provided 'as-is', without any express or implied 6 | * warranty. In no event will the authors be held liable for any 7 | * damages arising from the use of this software. 8 | * 9 | * Permission is granted to anyone to use this software for any 10 | * purpose, including commercial applications, and to alter it and 11 | * redistribute it freely, subject to the following restrictions: 12 | * 13 | * 1. The origin of this software must not be misrepresented; you 14 | * must not claim that you wrote the original software. If you use 15 | * this software in a product, an acknowledgment in the product 16 | * documentation would be appreciated but is not required. 17 | * 18 | * 2. Altered source versions must be plainly marked as such, and 19 | * must not be misrepresented as being the original software. 20 | * 21 | * 3. This notice may not be removed or altered from any source 22 | * distribution. 23 | ***************************************************************************/ 24 | #include "os_functions.h" 25 | #include "vpad_functions.h" 26 | 27 | uint32_t vpad_handle __attribute__((section(".data"))) = 0; 28 | uint32_t vpadbase_handle __attribute__((section(".data"))) = 0; 29 | 30 | EXPORT_DECL(void, VPADInit, void); 31 | EXPORT_DECL(void, VPADShutdown, void); 32 | EXPORT_DECL(int32_t, VPADRead, int32_t chan, VPADData *buffer, uint32_t buffer_size, int32_t *error); 33 | EXPORT_DECL(void, VPADSetAccParam, int32_t chan, float play_radius, float sensitivity); 34 | EXPORT_DECL(void, VPADGetAccParam, int32_t chan, float *play_radius, float *sensitivity); 35 | EXPORT_DECL(void, VPADSetBtnRepeat, int32_t chan, float delay_sec, float pulse_sec); 36 | EXPORT_DECL(void, VPADEnableStickCrossClamp, int32_t chan); 37 | EXPORT_DECL(void, VPADDisableStickCrossClamp, int32_t chan); 38 | EXPORT_DECL(void, VPADSetLStickClampThreshold, int32_t chan, int32_t max, int32_t min); 39 | EXPORT_DECL(void, VPADSetRStickClampThreshold, int32_t chan, int32_t max, int32_t min); 40 | EXPORT_DECL(void, VPADGetLStickClampThreshold, int32_t chan, int32_t* max, int32_t* min); 41 | EXPORT_DECL(void, VPADGetRStickClampThreshold, int32_t chan, int32_t* max, int32_t* min); 42 | EXPORT_DECL(void, VPADSetStickOrigin, int32_t chan); 43 | EXPORT_DECL(void, VPADDisableLStickZeroClamp, int32_t chan); 44 | EXPORT_DECL(void, VPADDisableRStickZeroClamp, int32_t chan); 45 | EXPORT_DECL(void, VPADEnableLStickZeroClamp, int32_t chan); 46 | EXPORT_DECL(void, VPADEnableRStickZeroClamp, int32_t chan); 47 | EXPORT_DECL(void, VPADSetCrossStickEmulationParamsL, int32_t chan, float rot_deg, float xy_deg, float radius); 48 | EXPORT_DECL(void, VPADSetCrossStickEmulationParamsR, int32_t chan, float rot_deg, float xy_deg, float radius); 49 | EXPORT_DECL(void, VPADGetCrossStickEmulationParamsL, int32_t chan, float* rot_deg, float* xy_deg, float* radius); 50 | EXPORT_DECL(void, VPADGetCrossStickEmulationParamsR, int32_t chan, float* rot_deg, float* xy_deg, float* radius); 51 | EXPORT_DECL(void, VPADSetGyroAngle, int32_t chan, float ax, float ay, float az); 52 | EXPORT_DECL(void, VPADSetGyroDirection, int32_t chan, VPADDir *dir); 53 | EXPORT_DECL(void, VPADSetGyroDirectionMag, int32_t chan, float mag); 54 | EXPORT_DECL(void, VPADSetGyroMagnification, int32_t chan, float pitch, float yaw, float roll); 55 | EXPORT_DECL(void, VPADEnableGyroZeroPlay, int32_t chan); 56 | EXPORT_DECL(void, VPADEnableGyroDirRevise, int32_t chan); 57 | EXPORT_DECL(void, VPADEnableGyroAccRevise, int32_t chan); 58 | EXPORT_DECL(void, VPADDisableGyroZeroPlay, int32_t chan); 59 | EXPORT_DECL(void, VPADDisableGyroDirRevise, int32_t chan); 60 | EXPORT_DECL(void, VPADDisableGyroAccRevise, int32_t chan); 61 | EXPORT_DECL(float, VPADIsEnableGyroZeroPlay, int32_t chan); 62 | EXPORT_DECL(float, VPADIsEnableGyroZeroDrift, int32_t chan); 63 | EXPORT_DECL(float, VPADIsEnableGyroDirRevise, int32_t chan); 64 | EXPORT_DECL(float, VPADIsEnableGyroAccRevise, int32_t chan); 65 | EXPORT_DECL(void, VPADSetGyroZeroPlayParam, int32_t chan, float radius); 66 | EXPORT_DECL(void, VPADSetGyroDirReviseParam, int32_t chan, float revis_pw); 67 | EXPORT_DECL(void, VPADSetGyroAccReviseParam, int32_t chan, float revise_pw, float revise_range); 68 | EXPORT_DECL(void, VPADSetGyroDirReviseBase, int32_t chan, VPADDir *base); 69 | EXPORT_DECL(void, VPADGetGyroZeroPlayParam, int32_t chan, float *radius); 70 | EXPORT_DECL(void, VPADGetGyroDirReviseParam, int32_t chan, float *revise_pw); 71 | EXPORT_DECL(void, VPADGetGyroAccReviseParam, int32_t chan, float *revise_pw, float *revise_range); 72 | EXPORT_DECL(void, VPADInitGyroZeroPlayParam, int32_t chan); 73 | EXPORT_DECL(void, VPADInitGyroDirReviseParam, int32_t chan); 74 | EXPORT_DECL(void, VPADInitGyroAccReviseParam, int32_t chan); 75 | EXPORT_DECL(void, VPADInitGyroZeroDriftMode, int32_t chan); 76 | EXPORT_DECL(void, VPADSetGyroZeroDriftMode, int32_t chan, VPADGyroZeroDriftMode mode); 77 | EXPORT_DECL(void, VPADGetGyroZeroDriftMode, int32_t chan, VPADGyroZeroDriftMode *mode); 78 | EXPORT_DECL(int16_t, VPADCalcTPCalibrationParam, VPADTPCalibrationParam* param, uint16_t rawX1, uint16_t rawY1, uint16_t x1, uint16_t y1, uint16_t rawX2, uint16_t rawY2, uint16_t x2, uint16_t y2); 79 | EXPORT_DECL(void, VPADSetTPCalibrationParam, int32_t chan, const VPADTPCalibrationParam param); 80 | EXPORT_DECL(void, VPADGetTPCalibrationParam, int32_t chan, VPADTPCalibrationParam* param); 81 | EXPORT_DECL(void, VPADGetTPCalibratedPoint, int32_t chan, VPADTPData *disp, const VPADTPData *raw); 82 | EXPORT_DECL(void, VPADGetTPCalibratedPointEx, int32_t chan, VPADTPResolution tpReso, VPADTPData *disp, const VPADTPData *raw); 83 | EXPORT_DECL(int32_t, VPADControlMotor, int32_t chan, uint8_t* pattern, uint8_t length); 84 | EXPORT_DECL(void, VPADStopMotor, int32_t chan); 85 | EXPORT_DECL(int32_t, VPADSetLcdMode, int32_t chan, int32_t lcdmode); 86 | EXPORT_DECL(int32_t, VPADGetLcdMode, int32_t chan, int32_t *lcdmode); 87 | EXPORT_DECL(int32_t, VPADBASEGetMotorOnRemainingCount, int32_t lcdmode); 88 | EXPORT_DECL(int32_t, VPADBASESetMotorOnRemainingCount, int32_t lcdmode, int32_t counter); 89 | EXPORT_DECL(void, VPADBASESetSensorBarSetting, int32_t chan, int8_t setting); 90 | EXPORT_DECL(void, VPADBASEGetSensorBarSetting, int32_t chan, int8_t *setting); 91 | EXPORT_DECL(int32_t, VPADSetSensorBar, int32_t chan, bool on); 92 | EXPORT_DECL(samplingCallback, VPADSetSamplingCallback, int32_t chan, samplingCallback callbackn); 93 | 94 | void InitAcquireVPad(void) { 95 | if(coreinit_handle == 0) { 96 | InitAcquireOS(); 97 | }; 98 | OSDynLoad_Acquire("vpad.rpl", &vpad_handle); 99 | OSDynLoad_Acquire("vpadbase.rpl", &vpadbase_handle); 100 | } 101 | 102 | void InitVPadFunctionPointers(void) { 103 | uint32_t *funcPointer = 0; 104 | 105 | InitAcquireVPad(); 106 | 107 | OS_FIND_EXPORT(vpad_handle, VPADInit); 108 | OS_FIND_EXPORT(vpad_handle, VPADShutdown); 109 | OS_FIND_EXPORT(vpad_handle, VPADRead); 110 | OS_FIND_EXPORT(vpad_handle, VPADSetAccParam); 111 | OS_FIND_EXPORT(vpad_handle, VPADGetAccParam); 112 | OS_FIND_EXPORT(vpad_handle, VPADSetBtnRepeat); 113 | OS_FIND_EXPORT(vpad_handle, VPADEnableStickCrossClamp); 114 | OS_FIND_EXPORT(vpad_handle, VPADDisableStickCrossClamp); 115 | OS_FIND_EXPORT(vpad_handle, VPADSetLStickClampThreshold); 116 | OS_FIND_EXPORT(vpad_handle, VPADSetRStickClampThreshold); 117 | OS_FIND_EXPORT(vpad_handle, VPADGetLStickClampThreshold); 118 | OS_FIND_EXPORT(vpad_handle, VPADGetRStickClampThreshold); 119 | OS_FIND_EXPORT(vpad_handle, VPADSetStickOrigin); 120 | OS_FIND_EXPORT(vpad_handle, VPADDisableLStickZeroClamp); 121 | OS_FIND_EXPORT(vpad_handle, VPADDisableRStickZeroClamp); 122 | OS_FIND_EXPORT(vpad_handle, VPADEnableLStickZeroClamp); 123 | OS_FIND_EXPORT(vpad_handle, VPADEnableRStickZeroClamp); 124 | OS_FIND_EXPORT(vpad_handle, VPADSetCrossStickEmulationParamsL); 125 | OS_FIND_EXPORT(vpad_handle, VPADSetCrossStickEmulationParamsR); 126 | OS_FIND_EXPORT(vpad_handle, VPADGetCrossStickEmulationParamsL); 127 | OS_FIND_EXPORT(vpad_handle, VPADGetCrossStickEmulationParamsR); 128 | OS_FIND_EXPORT(vpad_handle, VPADSetGyroAngle); 129 | OS_FIND_EXPORT(vpad_handle, VPADSetGyroDirection); 130 | OS_FIND_EXPORT(vpad_handle, VPADSetGyroDirectionMag); 131 | OS_FIND_EXPORT(vpad_handle, VPADSetGyroMagnification); 132 | OS_FIND_EXPORT(vpad_handle, VPADEnableGyroZeroPlay); 133 | OS_FIND_EXPORT(vpad_handle, VPADEnableGyroDirRevise); 134 | OS_FIND_EXPORT(vpad_handle, VPADEnableGyroAccRevise); 135 | OS_FIND_EXPORT(vpad_handle, VPADDisableGyroZeroPlay); 136 | OS_FIND_EXPORT(vpad_handle, VPADDisableGyroDirRevise); 137 | OS_FIND_EXPORT(vpad_handle, VPADDisableGyroAccRevise); 138 | OS_FIND_EXPORT(vpad_handle, VPADIsEnableGyroZeroPlay); 139 | OS_FIND_EXPORT(vpad_handle, VPADIsEnableGyroZeroDrift); 140 | OS_FIND_EXPORT(vpad_handle, VPADIsEnableGyroDirRevise); 141 | OS_FIND_EXPORT(vpad_handle, VPADIsEnableGyroAccRevise); 142 | OS_FIND_EXPORT(vpad_handle, VPADSetGyroZeroPlayParam); 143 | OS_FIND_EXPORT(vpad_handle, VPADSetGyroDirReviseParam); 144 | OS_FIND_EXPORT(vpad_handle, VPADSetGyroAccReviseParam); 145 | OS_FIND_EXPORT(vpad_handle, VPADSetGyroDirReviseBase); 146 | OS_FIND_EXPORT(vpad_handle, VPADGetGyroZeroPlayParam); 147 | OS_FIND_EXPORT(vpad_handle, VPADGetGyroDirReviseParam); 148 | OS_FIND_EXPORT(vpad_handle, VPADGetGyroAccReviseParam); 149 | OS_FIND_EXPORT(vpad_handle, VPADInitGyroZeroPlayParam); 150 | OS_FIND_EXPORT(vpad_handle, VPADInitGyroDirReviseParam); 151 | OS_FIND_EXPORT(vpad_handle, VPADInitGyroAccReviseParam); 152 | OS_FIND_EXPORT(vpad_handle, VPADInitGyroZeroDriftMode); 153 | OS_FIND_EXPORT(vpad_handle, VPADSetGyroZeroDriftMode); 154 | OS_FIND_EXPORT(vpad_handle, VPADGetGyroZeroDriftMode); 155 | OS_FIND_EXPORT(vpad_handle, VPADCalcTPCalibrationParam); 156 | OS_FIND_EXPORT(vpad_handle, VPADSetTPCalibrationParam); 157 | OS_FIND_EXPORT(vpad_handle, VPADGetTPCalibrationParam); 158 | OS_FIND_EXPORT(vpad_handle, VPADGetTPCalibratedPoint); 159 | OS_FIND_EXPORT(vpad_handle, VPADGetTPCalibratedPointEx); 160 | OS_FIND_EXPORT(vpad_handle, VPADControlMotor); 161 | OS_FIND_EXPORT(vpad_handle, VPADStopMotor); 162 | OS_FIND_EXPORT(vpad_handle, VPADSetLcdMode); 163 | OS_FIND_EXPORT(vpad_handle, VPADGetLcdMode); 164 | OS_FIND_EXPORT(vpad_handle, VPADSetSensorBar); 165 | OS_FIND_EXPORT(vpad_handle, VPADSetSamplingCallback); 166 | OS_FIND_EXPORT(vpadbase_handle, VPADBASEGetMotorOnRemainingCount); 167 | OS_FIND_EXPORT(vpadbase_handle, VPADBASESetMotorOnRemainingCount); 168 | OS_FIND_EXPORT(vpadbase_handle, VPADBASESetSensorBarSetting); 169 | OS_FIND_EXPORT(vpadbase_handle, VPADBASEGetSensorBarSetting); 170 | } 171 | -------------------------------------------------------------------------------- /src/fat/cache.c: -------------------------------------------------------------------------------- 1 | /* 2 | cache.c 3 | The cache is not visible to the user. It should be flushed 4 | when any file is closed or changes are made to the filesystem. 5 | 6 | This cache implements a least-used-page replacement policy. This will 7 | distribute sectors evenly over the pages, so if less than the maximum 8 | pages are used at once, they should all eventually remain in the cache. 9 | This also has the benefit of throwing out old sectors, so as not to keep 10 | too many stale pages around. 11 | 12 | Copyright (c) 2006 Michael "Chishm" Chisholm 13 | 14 | Redistribution and use in source and binary forms, with or without modification, 15 | are permitted provided that the following conditions are met: 16 | 17 | 1. Redistributions of source code must retain the above copyright notice, 18 | this list of conditions and the following disclaimer. 19 | 2. Redistributions in binary form must reproduce the above copyright notice, 20 | this list of conditions and the following disclaimer in the documentation and/or 21 | other materials provided with the distribution. 22 | 3. The name of the author may not be used to endorse or promote products derived 23 | from this software without specific prior written permission. 24 | 25 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 26 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 27 | AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 28 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 33 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #include 37 | #include 38 | 39 | #include "common.h" 40 | #include "cache.h" 41 | #include "disc.h" 42 | 43 | #include "mem_allocate.h" 44 | #include "bit_ops.h" 45 | #include "file_allocation_table.h" 46 | 47 | #define CACHE_FREE UINT_MAX 48 | 49 | CACHE* _FAT_cache_constructor (unsigned int numberOfPages, unsigned int sectorsPerPage, const DISC_INTERFACE* discInterface, sec_t endOfPartition, unsigned int bytesPerSector) { 50 | CACHE* cache; 51 | unsigned int i; 52 | CACHE_ENTRY* cacheEntries; 53 | 54 | if (numberOfPages < 2) { 55 | numberOfPages = 2; 56 | } 57 | 58 | if (sectorsPerPage < 8) { 59 | sectorsPerPage = 8; 60 | } 61 | 62 | cache = (CACHE*) _FAT_mem_allocate (sizeof(CACHE)); 63 | if (cache == NULL) { 64 | return NULL; 65 | } 66 | 67 | cache->disc = discInterface; 68 | cache->endOfPartition = endOfPartition; 69 | cache->numberOfPages = numberOfPages; 70 | cache->sectorsPerPage = sectorsPerPage; 71 | cache->bytesPerSector = bytesPerSector; 72 | 73 | 74 | cacheEntries = (CACHE_ENTRY*) _FAT_mem_allocate ( sizeof(CACHE_ENTRY) * numberOfPages); 75 | if (cacheEntries == NULL) { 76 | _FAT_mem_free (cache); 77 | return NULL; 78 | } 79 | 80 | for (i = 0; i < numberOfPages; i++) { 81 | cacheEntries[i].sector = CACHE_FREE; 82 | cacheEntries[i].count = 0; 83 | cacheEntries[i].last_access = 0; 84 | cacheEntries[i].dirty = false; 85 | cacheEntries[i].cache = (uint8_t*) _FAT_mem_align ( sectorsPerPage * bytesPerSector ); 86 | } 87 | 88 | cache->cacheEntries = cacheEntries; 89 | 90 | return cache; 91 | } 92 | 93 | void _FAT_cache_destructor (CACHE* cache) { 94 | unsigned int i; 95 | // Clear out cache before destroying it 96 | _FAT_cache_flush(cache); 97 | 98 | // Free memory in reverse allocation order 99 | for (i = 0; i < cache->numberOfPages; i++) { 100 | _FAT_mem_free (cache->cacheEntries[i].cache); 101 | } 102 | _FAT_mem_free (cache->cacheEntries); 103 | _FAT_mem_free (cache); 104 | } 105 | 106 | 107 | static uint32_t accessCounter = 0; 108 | 109 | static uint32_t accessTime(){ 110 | accessCounter++; 111 | return accessCounter; 112 | } 113 | 114 | 115 | static CACHE_ENTRY* _FAT_cache_getPage(CACHE *cache,sec_t sector) 116 | { 117 | unsigned int i; 118 | CACHE_ENTRY* cacheEntries = cache->cacheEntries; 119 | unsigned int numberOfPages = cache->numberOfPages; 120 | unsigned int sectorsPerPage = cache->sectorsPerPage; 121 | 122 | bool foundFree = false; 123 | unsigned int oldUsed = 0; 124 | unsigned int oldAccess = UINT_MAX; 125 | 126 | for(i=0;i=cacheEntries[i].sector && sector<(cacheEntries[i].sector + cacheEntries[i].count)) { 128 | cacheEntries[i].last_access = accessTime(); 129 | return &(cacheEntries[i]); 130 | } 131 | 132 | if(foundFree==false && (cacheEntries[i].sector==CACHE_FREE || cacheEntries[i].last_accessdisc,cacheEntries[oldUsed].sector,cacheEntries[oldUsed].count,cacheEntries[oldUsed].cache)) return NULL; 141 | cacheEntries[oldUsed].dirty = false; 142 | } 143 | 144 | sector = (sector/sectorsPerPage)*sectorsPerPage; // align base sector to page size 145 | sec_t next_page = sector + sectorsPerPage; 146 | if(next_page > cache->endOfPartition) next_page = cache->endOfPartition; 147 | 148 | if(!_FAT_disc_readSectors(cache->disc,sector,next_page-sector,cacheEntries[oldUsed].cache)) return NULL; 149 | 150 | cacheEntries[oldUsed].sector = sector; 151 | cacheEntries[oldUsed].count = next_page-sector; 152 | cacheEntries[oldUsed].last_access = accessTime(); 153 | 154 | return &(cacheEntries[oldUsed]); 155 | } 156 | 157 | bool _FAT_cache_readSectors(CACHE *cache,sec_t sector,sec_t numSectors,void *buffer) 158 | { 159 | sec_t sec; 160 | sec_t secs_to_read; 161 | CACHE_ENTRY *entry; 162 | uint8_t *dest = (uint8_t *)buffer; 163 | 164 | while(numSectors>0) { 165 | entry = _FAT_cache_getPage(cache,sector); 166 | if(entry==NULL) return false; 167 | 168 | sec = sector - entry->sector; 169 | secs_to_read = entry->count - sec; 170 | if(secs_to_read>numSectors) secs_to_read = numSectors; 171 | 172 | memcpy(dest,entry->cache + (sec*cache->bytesPerSector),(secs_to_read*cache->bytesPerSector)); 173 | 174 | dest += (secs_to_read*cache->bytesPerSector); 175 | sector += secs_to_read; 176 | numSectors -= secs_to_read; 177 | } 178 | 179 | return true; 180 | } 181 | 182 | /* 183 | Reads some data from a cache page, determined by the sector number 184 | */ 185 | bool _FAT_cache_readPartialSector (CACHE* cache, void* buffer, sec_t sector, unsigned int offset, size_t size) 186 | { 187 | sec_t sec; 188 | CACHE_ENTRY *entry; 189 | 190 | if (offset + size > cache->bytesPerSector) return false; 191 | 192 | entry = _FAT_cache_getPage(cache,sector); 193 | if(entry==NULL) return false; 194 | 195 | sec = sector - entry->sector; 196 | memcpy(buffer,entry->cache + ((sec*cache->bytesPerSector) + offset),size); 197 | 198 | return true; 199 | } 200 | 201 | bool _FAT_cache_readLittleEndianValue (CACHE* cache, uint32_t *value, sec_t sector, unsigned int offset, int num_bytes) { 202 | uint8_t buf[4]; 203 | if (!_FAT_cache_readPartialSector(cache, buf, sector, offset, num_bytes)) return false; 204 | 205 | switch(num_bytes) { 206 | case 1: *value = buf[0]; break; 207 | case 2: *value = uint8_t_array_to_uint16_t(buf,0); break; 208 | case 4: *value = uint8_t_array_to_uint32_t(buf,0); break; 209 | default: return false; 210 | } 211 | return true; 212 | } 213 | 214 | /* 215 | Writes some data to a cache page, making sure it is loaded into memory first. 216 | */ 217 | bool _FAT_cache_writePartialSector (CACHE* cache, const void* buffer, sec_t sector, unsigned int offset, size_t size) 218 | { 219 | sec_t sec; 220 | CACHE_ENTRY *entry; 221 | 222 | if (offset + size > cache->bytesPerSector) return false; 223 | 224 | entry = _FAT_cache_getPage(cache,sector); 225 | if(entry==NULL) return false; 226 | 227 | sec = sector - entry->sector; 228 | memcpy(entry->cache + ((sec*cache->bytesPerSector) + offset),buffer,size); 229 | 230 | entry->dirty = true; 231 | return true; 232 | } 233 | 234 | bool _FAT_cache_writeLittleEndianValue (CACHE* cache, const uint32_t value, sec_t sector, unsigned int offset, int size) { 235 | uint8_t buf[4] = {0, 0, 0, 0}; 236 | 237 | switch(size) { 238 | case 1: buf[0] = value; break; 239 | case 2: uint16_t_to_uint8_tarray(buf, 0, value); break; 240 | case 4: uint32_t_to_uint8_tarray(buf, 0, value); break; 241 | default: return false; 242 | } 243 | 244 | return _FAT_cache_writePartialSector(cache, buf, sector, offset, size); 245 | } 246 | 247 | /* 248 | Writes some data to a cache page, zeroing out the page first 249 | */ 250 | bool _FAT_cache_eraseWritePartialSector (CACHE* cache, const void* buffer, sec_t sector, unsigned int offset, size_t size) 251 | { 252 | sec_t sec; 253 | CACHE_ENTRY *entry; 254 | 255 | if (offset + size > cache->bytesPerSector) return false; 256 | 257 | entry = _FAT_cache_getPage(cache,sector); 258 | if(entry==NULL) return false; 259 | 260 | sec = sector - entry->sector; 261 | memset(entry->cache + (sec*cache->bytesPerSector),0,cache->bytesPerSector); 262 | memcpy(entry->cache + ((sec*cache->bytesPerSector) + offset),buffer,size); 263 | 264 | entry->dirty = true; 265 | return true; 266 | } 267 | 268 | 269 | bool _FAT_cache_writeSectors (CACHE* cache, sec_t sector, sec_t numSectors, const void* buffer) 270 | { 271 | sec_t sec; 272 | sec_t secs_to_write; 273 | CACHE_ENTRY* entry; 274 | const uint8_t *src = (const uint8_t *)buffer; 275 | 276 | while(numSectors>0) 277 | { 278 | entry = _FAT_cache_getPage(cache,sector); 279 | if(entry==NULL) return false; 280 | 281 | sec = sector - entry->sector; 282 | secs_to_write = entry->count - sec; 283 | if(secs_to_write>numSectors) secs_to_write = numSectors; 284 | 285 | memcpy(entry->cache + (sec*cache->bytesPerSector),src,(secs_to_write*cache->bytesPerSector)); 286 | 287 | src += (secs_to_write*cache->bytesPerSector); 288 | sector += secs_to_write; 289 | numSectors -= secs_to_write; 290 | 291 | entry->dirty = true; 292 | } 293 | return true; 294 | } 295 | 296 | /* 297 | Flushes all dirty pages to disc, clearing the dirty flag. 298 | */ 299 | bool _FAT_cache_flush (CACHE* cache) { 300 | unsigned int i; 301 | 302 | for (i = 0; i < cache->numberOfPages; i++) { 303 | if (cache->cacheEntries[i].dirty) { 304 | if (!_FAT_disc_writeSectors (cache->disc, cache->cacheEntries[i].sector, cache->cacheEntries[i].count, cache->cacheEntries[i].cache)) { 305 | return false; 306 | } 307 | } 308 | cache->cacheEntries[i].dirty = false; 309 | } 310 | 311 | return true; 312 | } 313 | 314 | void _FAT_cache_invalidate (CACHE* cache) { 315 | unsigned int i; 316 | _FAT_cache_flush(cache); 317 | for (i = 0; i < cache->numberOfPages; i++) { 318 | cache->cacheEntries[i].sector = CACHE_FREE; 319 | cache->cacheEntries[i].last_access = 0; 320 | cache->cacheEntries[i].count = 0; 321 | cache->cacheEntries[i].dirty = false; 322 | } 323 | } 324 | -------------------------------------------------------------------------------- /src/controllers.c: -------------------------------------------------------------------------------- 1 | //Based on code from lib_easy, current stickPos() is straight borrowed from there 2 | 3 | #include "controllers.h" 4 | 5 | int vpadError = -1; 6 | static VPADData vpad; 7 | 8 | static int32_t padErrors[4]; 9 | static uint32_t padTypes[4]; 10 | static KPADData pads[4]; 11 | 12 | 13 | static uint32_t buttons_hold[5]; //Held buttons 14 | static uint32_t buttons_pressed[5]; //Pressed buttons 15 | static uint32_t buttons_released[5]; //Released buttons 16 | 17 | static void pingControllers() { 18 | for (int i = 0; i < 4; i++) { 19 | padErrors[i] = WPADProbe(i, &padTypes[i]); 20 | } 21 | } 22 | 23 | static bool isWiimote(KPADData *padData){ 24 | return padData->device_type == 0 || padData->device_type == 1 || padData->device_type == 5 || padData->device_type == 6; 25 | } 26 | 27 | static bool isClassicController(KPADData *padData){ 28 | return padData->device_type == 2 || padData->device_type == 7; 29 | } 30 | 31 | static bool isProController(KPADData *padData){ 32 | return padData->device_type == 31; 33 | } 34 | 35 | void updateButtons() { 36 | VPADRead(0, &vpad, 1, &vpadError); 37 | buttons_pressed[0] = vpad.btns_d; 38 | buttons_hold[0] = vpad.btns_h; 39 | buttons_released[0] = vpad.btns_r; 40 | 41 | pingControllers(); 42 | for (int i = 0; i < 4; i++) { 43 | if (padErrors[i] == 0) { 44 | KPADRead(i, &pads[i], 1); 45 | if (isWiimote(&pads[i])) { 46 | buttons_pressed[i + 1] = pads[i].btns_d; 47 | buttons_hold[i + 1] = pads[i].btns_h; 48 | buttons_released[i + 1] = pads[i].btns_r; 49 | } 50 | else if (isClassicController(&pads[i])) { 51 | buttons_pressed[i + 1] = pads[i].classic.btns_d; 52 | buttons_hold[i + 1] = pads[i].classic.btns_h; 53 | buttons_released[i + 1] = pads[i].classic.btns_r; 54 | } 55 | else if (isProController(&pads[i])) { 56 | buttons_pressed[i + 1] = pads[i].pro.btns_d; 57 | buttons_hold[i + 1] = pads[i].pro.btns_h; 58 | buttons_released[i + 1] = pads[i].pro.btns_r; 59 | } 60 | } 61 | } 62 | } 63 | 64 | int checkButton(int button, int state) { 65 | uint32_t *stateArray; 66 | 67 | switch(state) { 68 | case PRESS: 69 | stateArray = (uint32_t *) &buttons_pressed; 70 | break; 71 | 72 | case HOLD: 73 | stateArray = (uint32_t *) &buttons_hold; 74 | break; 75 | 76 | case RELEASE: 77 | stateArray = (uint32_t *) &buttons_released; 78 | break; 79 | 80 | default: 81 | return 0; 82 | } 83 | 84 | //Check for any button at all 85 | if (button == PAD_BUTTON_ANY) { 86 | for (int i = 0; i < 5; i++) { 87 | if (stateArray[i] > 0) return 1; 88 | } 89 | } 90 | 91 | //VPad buttons 92 | switch (button) { 93 | case PAD_BUTTON_A: 94 | if (stateArray[0] & VPAD_BUTTON_A) return 1; 95 | break; 96 | 97 | case PAD_BUTTON_B: 98 | if (stateArray[0] & VPAD_BUTTON_B) return 1; 99 | break; 100 | 101 | case PAD_BUTTON_X: 102 | if (stateArray[0] & VPAD_BUTTON_X) return 1; 103 | break; 104 | 105 | case PAD_BUTTON_Y: 106 | if (stateArray[0] & VPAD_BUTTON_Y) return 1; 107 | break; 108 | 109 | case PAD_BUTTON_UP: 110 | if (stateArray[0] & VPAD_BUTTON_UP) return 1; 111 | break; 112 | 113 | case PAD_BUTTON_DOWN: 114 | if (stateArray[0] & VPAD_BUTTON_DOWN) return 1; 115 | break; 116 | 117 | case PAD_BUTTON_LEFT: 118 | if (stateArray[0] & VPAD_BUTTON_LEFT) return 1; 119 | break; 120 | 121 | case PAD_BUTTON_RIGHT: 122 | if (stateArray[0] & VPAD_BUTTON_RIGHT) return 1; 123 | break; 124 | 125 | case PAD_BUTTON_L: 126 | if (stateArray[0] & VPAD_BUTTON_L) return 1; 127 | break; 128 | 129 | case PAD_BUTTON_R: 130 | if (stateArray[0] & VPAD_BUTTON_R) return 1; 131 | break; 132 | 133 | case PAD_BUTTON_ZL: 134 | if (stateArray[0] & VPAD_BUTTON_ZL) return 1; 135 | break; 136 | 137 | case PAD_BUTTON_ZR: 138 | if (stateArray[0] & VPAD_BUTTON_ZR) return 1; 139 | break; 140 | 141 | case PAD_BUTTON_PLUS: 142 | if (stateArray[0] & VPAD_BUTTON_PLUS) return 1; 143 | break; 144 | 145 | case PAD_BUTTON_MINUS: 146 | if (stateArray[0] & VPAD_BUTTON_MINUS) return 1; 147 | break; 148 | 149 | case PAD_BUTTON_HOME: 150 | if (stateArray[0] & VPAD_BUTTON_HOME) return 1; 151 | break; 152 | 153 | case PAD_BUTTON_SYNC: 154 | if (stateArray[0] & VPAD_BUTTON_SYNC) return 1; 155 | break; 156 | 157 | case PAD_BUTTON_STICK_L: 158 | if (stateArray[0] & VPAD_BUTTON_L) return 1; 159 | break; 160 | 161 | case PAD_BUTTON_STICK_R: 162 | if (stateArray[0] & VPAD_BUTTON_STICK_R) return 1; 163 | break; 164 | 165 | case PAD_BUTTON_TV: 166 | if (stateArray[0] & VPAD_BUTTON_TV) return 1; 167 | break; 168 | 169 | default: 170 | break; 171 | } 172 | 173 | //Buttons handled by the padscore library 174 | for (int i = 0; i < 4; i++) { 175 | if (padErrors[i] == 0) { 176 | if (isWiimote(&pads[i])) { 177 | switch (button) { 178 | case PAD_BUTTON_UP: 179 | if (stateArray[i + 1] & WPAD_BUTTON_UP) return 1; 180 | break; 181 | 182 | case PAD_BUTTON_DOWN: 183 | if (stateArray[i + 1] & WPAD_BUTTON_DOWN) return 1; 184 | break; 185 | 186 | case PAD_BUTTON_LEFT: 187 | if (stateArray[i + 1] & WPAD_BUTTON_LEFT) return 1; 188 | break; 189 | 190 | case PAD_BUTTON_RIGHT: 191 | if (stateArray[i + 1] & WPAD_BUTTON_RIGHT) return 1; 192 | break; 193 | 194 | case PAD_BUTTON_A: 195 | if (stateArray[i + 1] & WPAD_BUTTON_A) return 1; 196 | break; 197 | 198 | case PAD_BUTTON_B: 199 | if (stateArray[i + 1] & WPAD_BUTTON_B) return 1; 200 | break; 201 | 202 | case PAD_BUTTON_L: 203 | if (stateArray[i + 1] & WPAD_BUTTON_1) return 1; 204 | break; 205 | 206 | case PAD_BUTTON_R: 207 | if (stateArray[i + 1] & WPAD_BUTTON_2) return 1; 208 | break; 209 | 210 | case PAD_BUTTON_1: 211 | if (stateArray[i + 1] & WPAD_BUTTON_1) return 1; 212 | break; 213 | 214 | case PAD_BUTTON_2: 215 | if (stateArray[i + 1] & WPAD_BUTTON_2) return 1; 216 | break; 217 | 218 | case PAD_BUTTON_Z: 219 | if (stateArray[i + 1] & WPAD_BUTTON_Z) return 1; 220 | break; 221 | 222 | case PAD_BUTTON_C: 223 | if (stateArray[i + 1] & WPAD_BUTTON_C) return 1; 224 | break; 225 | 226 | case PAD_BUTTON_PLUS: 227 | if (stateArray[i + 1] & WPAD_BUTTON_PLUS) return 1; 228 | break; 229 | 230 | case PAD_BUTTON_MINUS: 231 | if (stateArray[i + 1] & WPAD_BUTTON_MINUS) return 1; 232 | break; 233 | 234 | case PAD_BUTTON_HOME: 235 | if (stateArray[i + 1] & WPAD_BUTTON_HOME) return 1; 236 | break; 237 | } 238 | } 239 | //Turns out the Pro Controller and Classic Controller have almost the exact same mapping 240 | //Except for the Pro Controller having clicky sticks 241 | else if (isClassicController(&pads[i]) || isProController(&pads[i])) { 242 | switch (button) { 243 | case PAD_BUTTON_UP: 244 | if (stateArray[i + 1] & WPAD_CLASSIC_BUTTON_UP) return 1; 245 | break; 246 | 247 | case PAD_BUTTON_DOWN: 248 | if (stateArray[i + 1] & WPAD_CLASSIC_BUTTON_DOWN) return 1; 249 | break; 250 | 251 | case PAD_BUTTON_LEFT: 252 | if (stateArray[i + 1] & WPAD_CLASSIC_BUTTON_LEFT) return 1; 253 | break; 254 | 255 | case PAD_BUTTON_RIGHT: 256 | if (stateArray[i + 1] & WPAD_CLASSIC_BUTTON_RIGHT) return 1; 257 | break; 258 | 259 | case PAD_BUTTON_A: 260 | if (stateArray[i + 1] & WPAD_CLASSIC_BUTTON_A) return 1; 261 | break; 262 | 263 | case PAD_BUTTON_B: 264 | if (stateArray[i + 1] & WPAD_CLASSIC_BUTTON_B) return 1; 265 | break; 266 | 267 | case PAD_BUTTON_X: 268 | if (stateArray[i + 1] & WPAD_CLASSIC_BUTTON_X) return 1; 269 | break; 270 | 271 | case PAD_BUTTON_Y: 272 | if (stateArray[i + 1] & WPAD_CLASSIC_BUTTON_Y) return 1; 273 | break; 274 | 275 | case PAD_BUTTON_L: 276 | if (stateArray[i + 1] & WPAD_CLASSIC_BUTTON_L) return 1; 277 | break; 278 | 279 | case PAD_BUTTON_R: 280 | if (stateArray[i + 1] & WPAD_CLASSIC_BUTTON_R) return 1; 281 | break; 282 | 283 | case PAD_BUTTON_ZL: 284 | if (stateArray[i + 1] & WPAD_CLASSIC_BUTTON_ZL) return 1; 285 | break; 286 | 287 | case PAD_BUTTON_ZR: 288 | if (stateArray[i + 1] & WPAD_CLASSIC_BUTTON_ZR) return 1; 289 | break; 290 | 291 | case PAD_BUTTON_PLUS: 292 | if (stateArray[i + 1] & WPAD_CLASSIC_BUTTON_PLUS) return 1; 293 | break; 294 | 295 | case PAD_BUTTON_MINUS: 296 | if (stateArray[i + 1] & WPAD_CLASSIC_BUTTON_MINUS) return 1; 297 | break; 298 | 299 | case PAD_BUTTON_HOME: 300 | if (stateArray[i + 1] & WPAD_CLASSIC_BUTTON_HOME) return 1; 301 | break; 302 | } 303 | //Here, we handle the aforementioned clicky sticks 304 | if (isProController(&pads[i])) { 305 | switch (button) { 306 | case PAD_BUTTON_STICK_L: 307 | if (stateArray[i + 1] & WPAD_PRO_BUTTON_STICK_L) return 1; 308 | break; 309 | 310 | case PAD_BUTTON_STICK_R: 311 | if (stateArray[i + 1] & WPAD_PRO_BUTTON_STICK_R) return 1; 312 | break; 313 | } 314 | } 315 | } 316 | } 317 | } 318 | 319 | return 0; 320 | } 321 | --------------------------------------------------------------------------------