Merge upstream changes from GUI

Basically cleaning up and making sure functions succeed before returning the result.
This commit is contained in:
Joel16 2017-09-15 11:16:13 -05:00
parent 656331af53
commit 99fc2e4c58
29 changed files with 593 additions and 432 deletions

View File

@ -57,7 +57,6 @@ ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft
CFLAGS := -g -Wall -O2 -mword-relocations \
-fomit-frame-pointer -ffunction-sections \
-DVERSION_MAJOR=$(VERSION_MAJOR) -DVERSION_MINOR=$(VERSION_MINOR) \
$(ARCH)
CFLAGS += $(INCLUDE) -DARM11 -D_3DS
@ -69,8 +68,6 @@ LDFLAGS = -specs=3dsx.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
LIBS := -lctru -lm -lpng16 -lz
OS := $(shell uname)
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib

12
include/ac.h Normal file
View File

@ -0,0 +1,12 @@
#ifndef AC_H
#define AC_H
#include <3ds.h>
Result acGetServiceHandle(void);
Result acCloseServiceHandle(void);
Result ACU_GetConnectingSecurityMode(u32 * out);
Result ACU_GetConnectingSsid(u32 * out);
Result ACU_GetConnectingSsidLength(u32 * out);
#endif

View File

@ -5,8 +5,8 @@
FS_Archive fsArchive;
void openArchive(FS_ArchiveID id);
void closeArchive(void);
Result openArchive(FS_Archive * archive, FS_ArchiveID id);
Result closeArchive(FS_Archive archive);
Result makeDir(FS_Archive archive, const char * path);
bool fileExists(FS_Archive archive, const char * path);
bool dirExists(FS_Archive archive, const char * path);

10
include/hardware.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef HARDWARE_H
#define HARDWARE_H
#include <3ds.h>
char * getCardSlotStatus(void);
char * getBrightness(u32 screen);
bool detectSD(void);
#endif

View File

@ -2,11 +2,10 @@
#define KERNEL_H
#include <3ds.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char * getVersion(int version);
char * getCID(int type);
char * getSdmcCid(void);
char * getNandCid(void);
u32 getDeviceId(void);
#endif

View File

@ -4,9 +4,6 @@
#include <3ds.h>
u32 titleCount(FS_MediaType mediaType);
bool detectSD(void);
u64 getFreeStorage(FS_SystemMediaType mediaType);
u64 getTotalStorage(FS_SystemMediaType mediaType);
u64 getUsedStorage(FS_SystemMediaType mediaType);
char * getDeviceCert(void);
#endif

View File

@ -2,9 +2,6 @@
#define ACTU_H
#include <3ds.h>
#include <malloc.h>
#include <stdio.h>
#include <string.h>
struct Birthday
{
@ -50,9 +47,8 @@ typedef struct
u32 principalID; // Principal ID
} AccountDataBlock;
Result actInit(u32 sdkVer, u32 sharedMemSize);
Result actInit(void);
void actExit(void);
Result ACTU_Initialize(u32 sdkVer, void *addr, u32 memSize);
Result ACTU_GetAccountDataBlock(void * buffer, u32 size, u32 blkId);
#endif

View File

@ -3,6 +3,8 @@
#include <3ds.h>
Result amGetServiceHandle(void);
Result amCloseServiceHandle(void);
Result amNetGetDeviceCert(u8 const * buffer);
#endif

View File

@ -3,9 +3,8 @@
#include <3ds.h>
Result cfgsInit();
Result cfgsExit();
Result CFG_GetConfig(u32 size, u32 blkID, u8* outData);
Result cfgsSecureInfoGetSerialNo(char *serial);
Result cfgsInit(void);
Result cfgsExit(void);
Result CFGS_SecureInfoGetSerialNo(u8 * serial);
#endif

View File

@ -3,11 +3,13 @@
#include <3ds.h>
Result mcuInit();
Result mcuExit();
Result mcuGetBatteryLevel(u8* out);
Result mcuGetBatteryVoltage(u8* out);
Result GetMcuFwVerHigh(u8* out);
Result GetMcuFwVerLow(u8* out);
Result mcuInit(void);
Result mcuExit(void);
Result MCU_ReadRegister(u8 reg, u32 size, void * data);
Result MCU_GetBatteryVoltage(u8 * out);
Result MCU_GetBatteryLevel(u8 * out);
Result MCU_GetSoundVolume(u8 * out);
Result MCU_GetFwVerHigh(u8 * out);
Result MCU_GetFwVerLow(u8 * out);
#endif

10
include/storage.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef STORAGE_H
#define STORAGE_H
#include <3ds.h>
u64 getFreeStorage(FS_SystemMediaType mediaType);
u64 getTotalStorage(FS_SystemMediaType mediaType);
u64 getUsedStorage(FS_SystemMediaType mediaType);
#endif

View File

@ -10,12 +10,7 @@ const char * getLang(void);
char * getMacAddress(void);
char * getScreenType(void);
u64 getLocalFriendCodeSeed(void);
char * getSerialNum(void);
u32 getDeviceId(void);
u8 * getSerialNumber(void);
u64 getSoapId(void);
char * getDeviceCert(void);
char * getNNIDInfo(u32 size, u32 blkId);
char * getBrightness(u32 screen);
char * getCardSlotStatus(void);
#endif

View File

@ -2,16 +2,14 @@
#define UTILS_H
#include <3ds.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define ANY_KEY (KEY_TOUCH | KEY_A | KEY_B | KEY_X | KEY_Y | KEY_START | KEY_SELECT | \
KEY_UP | KEY_DOWN | KEY_LEFT | KEY_RIGHT | KEY_L | KEY_R | KEY_ZL | KEY_ZR | \
KEY_CSTICK_UP | KEY_CSTICK_DOWN | KEY_CSTICK_LEFT | KEY_CSTICK_RIGHT)
void getSizeString(char * string, uint64_t size);
void utf2ascii(char* dst, u16* src);
bool isN3DS(void);
void u16_to_u8(char * buf, const u16 * input, size_t bufsize);
char * base64Encode(u8 const * bytesToEnc, size_t bufLen);
#endif

View File

@ -65,4 +65,6 @@ typedef struct
u8 padding8[0x7EC];
} wifiSlotStructure;
char * getSecurityMode();
#endif

View File

@ -1,13 +1,13 @@
#include "fs.h"
void openArchive(FS_ArchiveID id)
Result openArchive(FS_Archive * archive, FS_ArchiveID id)
{
FSUSER_OpenArchive(&fsArchive, id, fsMakePath(PATH_EMPTY, ""));
return FSUSER_OpenArchive(archive, id, fsMakePath(PATH_EMPTY, ""));
}
void closeArchive(void)
Result closeArchive(FS_Archive archive)
{
FSUSER_CloseArchive(fsArchive);
return FSUSER_CloseArchive(archive);
}
Result makeDir(FS_Archive archive, const char * path)
@ -25,14 +25,10 @@ bool fileExists(FS_Archive archive, const char * path)
Handle handle;
Result ret = FSUSER_OpenFile(&handle, archive, fsMakePath(PATH_ASCII, path), FS_OPEN_READ, 0);
if(ret != 0)
if (R_FAILED(FSUSER_OpenFile(&handle, archive, fsMakePath(PATH_ASCII, path), FS_OPEN_READ, 0)))
return false;
ret = FSFILE_Close(handle);
if(ret != 0)
if (R_FAILED(FSFILE_Close(handle)))
return false;
return true;
@ -45,14 +41,10 @@ bool dirExists(FS_Archive archive, const char * path)
Handle handle;
Result ret = FSUSER_OpenDirectory(&handle, archive, fsMakePath(PATH_ASCII, path));
if(ret != 0)
if (R_FAILED(FSUSER_OpenDirectory(&handle, archive, fsMakePath(PATH_ASCII, path))))
return false;
ret = FSDIR_Close(handle);
if(ret != 0)
if (R_FAILED(FSDIR_Close(handle)))
return false;
return true;

58
source/hardware.c Normal file
View File

@ -0,0 +1,58 @@
#include <stdio.h>
#include "hardware.h"
char * getCardSlotStatus(void)
{
bool isInserted = false;
FS_CardType cardType = 0;
static char card[20];
if (R_SUCCEEDED(FSUSER_CardSlotIsInserted(&isInserted)))
{
if (isInserted)
{
FSUSER_GetCardType(&cardType);
snprintf(card, 20, "inserted %s", cardType? "(TWL)" : "(CTR)");
return card;
}
}
snprintf(card, 20, "not inserted");
return card;
}
bool detectSD(void)
{
bool isSD = false;
if (R_SUCCEEDED(FSUSER_IsSdmcDetected(&isSD)))
return isSD;
return false;
}
char * getBrightness(u32 screen)
{
u32 brightness = 0;
if(R_SUCCEEDED(gspLcdInit()))
{
if (R_SUCCEEDED(GSPLCD_GetBrightness(screen, &brightness)))
gspLcdExit();
}
if (brightness == 0x10)
return "1 (20%)";
else if (brightness == 0x1C)
return "2 (40%)";
else if (brightness == 0x30)
return "3 (60%)";
else if (brightness == 0x52)
return "4 (80%)";
else if (brightness == 0x8E)
return "5 (100%)";
else
return "n3DS only";
}

View File

@ -1,3 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "kernel.h"
#include "system.h"
@ -43,21 +47,44 @@ char * getVersion(int version)
return str_sysver;
}
char * getCID(int type)
char * getSdmcCid(void)
{
u8 buf[16];
static char cid[33];
if (type == 0) //SDMC
FSUSER_GetSdmcCid(buf, 0x10);
else if (type == 1) //NAND
FSUSER_GetNandCid(buf, 0x10);
if (R_SUCCEEDED(FSUSER_GetSdmcCid(buf, 0x10)))
{
snprintf(cid, 33, "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
buf[0], buf[1], buf[2], buf[3], buf[4], buf[5],
buf[6], buf[7], buf[8], buf[9], buf[10], buf[11],
buf[12], buf[13], buf[14], buf[15]);
}
return cid;
}
char * getNandCid(void)
{
u8 buf[16];
static char cid[33];
if (R_SUCCEEDED(FSUSER_GetNandCid(buf, 0x10)))
{
snprintf(cid, 33, "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
buf[0], buf[1], buf[2], buf[3], buf[4], buf[5],
buf[6], buf[7], buf[8], buf[9], buf[10], buf[11],
buf[12], buf[13], buf[14], buf[15]);
}
return cid;
}
u32 getDeviceId(void) // Same as PS_GetDeviceId
{
u32 id = 0;
if (R_SUCCEEDED(AM_GetDeviceId(&id)))
return id;
return 0;
}

View File

@ -1,13 +1,18 @@
#include <3ds.h>
#include <malloc.h>
#include "ac.h"
#include "actu.h"
#include "cfgs.h"
#include "fs.h"
#include "hardware.h"
#include "kernel.h"
#include "mcu.h"
#include "misc.h"
#include "power.h"
#include "screenshot.h"
#include "storage.h"
#include "system.h"
#include "utils.h"
#include "wifi.h"
@ -19,9 +24,6 @@ void initServices()
gfxInitDefault();
cfguInit();
cfgsInit();
fsInit();
sdmcInit();
openArchive(ARCHIVE_SDMC);
ptmuInit();
mcuInit();
amInit();
@ -29,24 +31,37 @@ void initServices()
psInit();
aptInit();
hidInit();
actInit(SDK(11, 2, 0, 200), 0x20000);
acGetServiceHandle();
actInit();
socInit((u32*)memalign(0x1000, 0x10000), 0x10000);
fsInit();
sdmcInit();
openArchive(&fsArchive, ARCHIVE_SDMC);
if (isN3DS())
osSetSpeedupEnable(true);
}
void termServices()
{
if (isN3DS())
osSetSpeedupEnable(false);
closeArchive(fsArchive);
sdmcExit();
fsExit();
socExit();
actExit();
hidExit();
aptExit();
psExit();
acExit();
acCloseServiceHandle();
amExit();
mcuExit();
ptmuExit();
closeArchive();
sdmcExit();
fsExit();
cfgsExit();
cfguExit();
gfxExit();
@ -66,8 +81,7 @@ int main(int argc, char *argv[])
unsigned int principalID = 0;
u8 batteryPercent = 0, batteryVolt = 0, volume = 0, mcuFwMajor = 0, mcuFwMinor = 0;
bool isConnected = false;
char sdFreeSize[16], sdTotalSize[16], ctrFreeSize[16], ctrTotalSize[16], name[0x16];
Result ret = 0;
char sdFreeSize[16], sdTotalSize[16], ctrFreeSize[16], ctrTotalSize[16], country[0x3], name[0x16], nnid[0x11], timeZone[0x41];
wifiSlotStructure slotData;
AccountDataBlock accountDataBlock;
MiiData miiData;
@ -94,9 +108,10 @@ int main(int argc, char *argv[])
if (principalID != 0)
{
printf("\x1b[35;1m*\x1b[0m NNID: \x1b[35;1m%s\x1b[0m\n", getNNIDInfo(0x11, 0x8));
if (R_SUCCEEDED(ACTU_GetAccountDataBlock(nnid, 0x11, 0x8)))
printf("\x1b[35;1m*\x1b[0m NNID: \x1b[35;1m%s\x1b[0m\n", nnid);
utf2ascii(name, accountDataBlock.miiName);
u16_to_u8(name, accountDataBlock.miiName, 0x16);
printf("\x1b[35;1m*\x1b[0m Mii name: \x1b[35;1m%s\x1b[0m (\x1b[35;1m%u\x1b[0m)\n", name, (unsigned int)miiData.miiID);
printf("\x1b[35;1m*\x1b[0m Principal ID: \x1b[35;1m%u\x1b[0m\n", principalID);
@ -105,17 +120,18 @@ int main(int argc, char *argv[])
printf("\x1b[35;1m*\x1b[0m Transferable ID: \x1b[35;1m%llu\x1b[0m\n", accountDataBlock.transferableID);
printf("\x1b[35;1m*\x1b[0m Country: \x1b[35;1m%s\x1b[0m\n", getNNIDInfo(0x3, 0xB));
if (R_SUCCEEDED(ACTU_GetAccountDataBlock(country, 0x3, 0xB)))
printf("\x1b[35;1m*\x1b[0m Country: \x1b[35;1m%s\x1b[0m\n", country);
printf("\x1b[35;1m*\x1b[0m Time Zone: \x1b[35;1m%s\x1b[0m\n\n", getNNIDInfo(0x41, 0x1E));
if (R_SUCCEEDED(ACTU_GetAccountDataBlock(timeZone, 0x41, 0x1E)))
printf("\x1b[35;1m*\x1b[0m Time Zone: \x1b[35;1m%s\x1b[0m\n\n", timeZone);
}
//=====================================================================//
//------------------------------WIFI Info------------------------------//
//=====================================================================//
ret = CFG_GetConfigInfoBlk8(CFG_WIFI_SLOT_SIZE, CFG_WIFI_BLKID + 0, (u8*)&slotData);
if ((!ret) && (slotData.set))
if ((R_SUCCEEDED(CFG_GetConfigInfoBlk8(CFG_WIFI_SLOT_SIZE, CFG_WIFI_BLKID + 0, (u8*)&slotData))) && (slotData.set))
{
if (slotData.network.use)
{
@ -131,8 +147,7 @@ int main(int argc, char *argv[])
printf("\x1b[32;1m*\x1b[0m WiFi 1 mac address: \x1b[32;1m%02X:%02X:%02X:%02X:%02X:%02X\x1b[0m\n\n", slotData.mac_addr[0], slotData.mac_addr[1], slotData.mac_addr[2], slotData.mac_addr[3], slotData.mac_addr[4], slotData.mac_addr[5]);
}
ret = CFG_GetConfigInfoBlk8(CFG_WIFI_SLOT_SIZE, CFG_WIFI_BLKID + 1, (u8*)&slotData);
if ((!ret) && (slotData.set))
if ((R_SUCCEEDED(CFG_GetConfigInfoBlk8(CFG_WIFI_SLOT_SIZE, CFG_WIFI_BLKID + 1, (u8*)&slotData))) && (slotData.set))
{
if (slotData.network.use)
{
@ -148,8 +163,7 @@ int main(int argc, char *argv[])
printf("\x1b[32;1m*\x1b[0m WiFi 2 mac address: \x1b[32;1m%02X:%02X:%02X:%02X:%02X:%02X\x1b[0m\n\n", slotData.mac_addr[0], slotData.mac_addr[1], slotData.mac_addr[2], slotData.mac_addr[3], slotData.mac_addr[4], slotData.mac_addr[5]);
}
ret = CFG_GetConfigInfoBlk8(CFG_WIFI_SLOT_SIZE, CFG_WIFI_BLKID + 2, (u8*)&slotData);
if ((!ret) && (slotData.set))
if ((R_SUCCEEDED(CFG_GetConfigInfoBlk8(CFG_WIFI_SLOT_SIZE, CFG_WIFI_BLKID + 2, (u8*)&slotData))) && (slotData.set))
{
if (slotData.network.use)
{
@ -170,7 +184,7 @@ int main(int argc, char *argv[])
consoleInit(GFX_TOP, NULL);
printf("\x1b[1;1H"); //Move the cursor to the top left corner of the screen
printf("\x1b[32;1m3DSident 0.7.6\x1b[0m\n\n");
printf("\x1b[32;1m3DSident 0.7.7\x1b[0m\n\n");
//=====================================================================//
//------------------------------Firm Info------------------------------//
@ -194,13 +208,13 @@ int main(int argc, char *argv[])
printf("\x1b[31;1m*\x1b[0m ECS Device ID: \x1b[31;1m%llu \n", getSoapId());
printf("\x1b[31;1m*\x1b[0m Local friend code seed: \x1b[31;1m%010llX\x1b[0m \n", getLocalFriendCodeSeed());
printf("\x1b[31;1m*\x1b[0m MAC Address: \x1b[31;1m%s\x1b[0m \n", getMacAddress());
printf("\x1b[31;1m*\x1b[0m Serial number: \x1b[31;1m%s\x1b[0m \n", getSerialNum());
printf("\x1b[31;1m*\x1b[0m Serial number: \x1b[31;1m%s\x1b[0m \n", getSerialNumber());
printf("\x1b[31;1m*\x1b[0m SDMC CID: \x1b[31;1m%s\x1b[0m \n", getCID(0));
printf("\x1b[31;1m*\x1b[0m SDMC CID: \x1b[31;1m%s\x1b[0m \n", getSdmcCid());
printf("\x1b[31;1m*\x1b[0m NAND CID: \x1b[31;1m%s\x1b[0m \n", getCID(1));
printf("\x1b[31;1m*\x1b[0m NAND CID: \x1b[31;1m%s\x1b[0m \n", getNandCid());
ret = APT_GetAppletInfo(APPID_HOMEMENU, &homemenuID, NULL, NULL, NULL, NULL);
if (R_SUCCEEDED(APT_GetAppletInfo(APPID_HOMEMENU, &homemenuID, NULL, NULL, NULL, NULL)))
printf("\x1b[31;1m*\x1b[0m Homemenu ID: \x1b[31;1m%016llX\x1b[0m \n\n", homemenuID);
while (aptMainLoop())
@ -210,20 +224,19 @@ int main(int argc, char *argv[])
//=====================================================================//
printf("\x1b[19;0H");
mcuGetBatteryLevel(&batteryPercent);
if (R_SUCCEEDED(MCU_GetBatteryLevel(&batteryPercent)))
printf("\x1b[34;1m*\x1b[0m Battery percentage: \x1b[34;1m%3d%%\x1b[0m (\x1b[34;1m%s\x1b[0m) \n", batteryPercent, batteryStatus());
printf("\x1b[20;0H");
mcuGetBatteryVoltage(&batteryVolt);
if (R_SUCCEEDED(MCU_GetBatteryVoltage(&batteryVolt)))
printf("\x1b[34;1m*\x1b[0m Battery voltage: \x1b[34;1m%d\x1b[0m (\x1b[34;1m%.1f V\x1b[0m) \n", batteryVolt, 5.0 * ((double)batteryVolt / 256.0));//,(Estimated: %0.1lf V) estimatedVolt);
printf("\x1b[21;0H");
PTMU_GetAdapterState(&isConnected);
if (R_SUCCEEDED(PTMU_GetAdapterState(&isConnected)))
printf("\x1b[34;1m*\x1b[0m Adapter state: \x1b[34;1m%s\x1b[0m\n", isConnected? "connected " : "disconnected");
printf("\x1b[22;0H");
GetMcuFwVerHigh(&mcuFwMajor);
GetMcuFwVerLow(&mcuFwMinor);
if ((R_SUCCEEDED(MCU_GetFwVerHigh(&mcuFwMajor))) && (R_SUCCEEDED(MCU_GetFwVerLow(&mcuFwMinor))))
printf("\x1b[34;1m*\x1b[0m MCU firmware: \x1b[34;1m%u.%u\x1b[0m\n\n", (mcuFwMajor - 16), mcuFwMinor);
//=====================================================================//
@ -248,9 +261,11 @@ int main(int argc, char *argv[])
printf("\x1b[36;1m*\x1b[0m WiFi signal strength: \x1b[36;1m%d\x1b[0m (\x1b[36;1m%.0lf%%\x1b[0m) \n", osGetWifiStrength(), wifiPercent);
printf("\x1b[28;0H");
HIDUSER_GetSoundVolume(&volume);
if (R_SUCCEEDED(HIDUSER_GetSoundVolume(&volume)))
{
volPercent = (volume * 1.5873015873);
printf("\x1b[36;1m*\x1b[0m Volume slider state: \x1b[36;1m%d\x1b[0m (\x1b[36;1m%.0lf%%\x1b[0m) \n", volume, volPercent);
}
printf("\x1b[29;0H");
_3dSliderPercent = (osGet3DSliderState() * 100.0);

View File

@ -1,44 +1,23 @@
#include "am.h"
#include "misc.h"
#include "utils.h"
u32 titleCount(FS_MediaType mediaType)
{
u32 count = 0;
AM_GetTitleCount(mediaType, &count);
if (R_SUCCEEDED(AM_GetTitleCount(mediaType, &count)))
return count;
return 0;
}
bool detectSD(void)
char * getDeviceCert(void)
{
bool isSD;
FSUSER_IsSdmcDetected(&isSD);
return isSD;
}
u64 getFreeStorage(FS_SystemMediaType mediaType)
{
FS_ArchiveResource resource = {0};
FSUSER_GetArchiveResource(&resource, mediaType);
return (((u64) resource.freeClusters * (u64) resource.clusterSize));
}
u64 getTotalStorage(FS_SystemMediaType mediaType)
{
FS_ArchiveResource resource = {0};
FSUSER_GetArchiveResource(&resource, mediaType);
return (((u64) resource.totalClusters * (u64) resource.clusterSize));
}
u64 getUsedStorage(FS_SystemMediaType mediaType)
{
FS_ArchiveResource resource = {0};
FSUSER_GetArchiveResource(&resource, mediaType);
return ((((u64) resource.totalClusters * (u64) resource.clusterSize)) - (((u64) resource.freeClusters * (u64) resource.clusterSize)));
u8 const cert[0x180];
if (R_SUCCEEDED(amNetGetDeviceCert(cert)))
return base64Encode(cert, 0x180);
return NULL;
}

View File

@ -3,11 +3,15 @@
const char * batteryStatus(void)
{
u8 batteryStateBool;
PTMU_GetBatteryChargeState(&batteryStateBool);
u8 batteryStatus;
if (!batteryStateBool)
return "not charging";
else
if (R_SUCCEEDED(PTMU_GetBatteryChargeState(&batteryStatus)))
{
if (batteryStatus)
return "charging";
return "not charging";
}
return NULL;
}

58
source/services/ac.c Normal file
View File

@ -0,0 +1,58 @@
#include "ac.h"
static Handle acHandle;
Result acGetServiceHandle(void)
{
return srvGetServiceHandle(&acHandle, "ac:u");
}
Result acCloseServiceHandle(void)
{
return svcCloseHandle(acHandle);
}
Result ACU_GetConnectingSecurityMode(u32 * out)
{
Result ret = 0;
u32 * cmdbuf = getThreadCommandBuffer();
cmdbuf[0] = IPC_MakeHeader(0x33, 0, 0); // 0x00330000
if (R_FAILED(ret = svcSendSyncRequest(acHandle)))
return ret;
*out = cmdbuf[2];
return cmdbuf[1];
}
Result ACU_GetConnectingSsid(u32 * out)
{
Result ret = 0;
u32 * cmdbuf = getThreadCommandBuffer();
cmdbuf[0] = IPC_MakeHeader(0x34, 0, 0); // 0x00340000
if (R_FAILED(ret = svcSendSyncRequest(acHandle)))
return ret;
*out = cmdbuf[2];
return cmdbuf[1];
}
Result ACU_GetConnectingSsidLength(u32 * out)
{
Result ret = 0;
u32 * cmdbuf = getThreadCommandBuffer();
cmdbuf[0] = IPC_MakeHeader(0x35, 0, 0); // 0x00350000
if (R_FAILED(ret = svcSendSyncRequest(acHandle)))
return ret;
*out = cmdbuf[2];
return cmdbuf[1];
}

View File

@ -1,44 +1,27 @@
#include <malloc.h>
#include <stdio.h>
#include <string.h>
#include "actu.h"
static Handle actHandle;
static int actRefCount;
static u32 *act_shareMemAddr;
static u32 act_shareMemSize;
static Handle act_shareMemHandle;
Result actInit(u32 sdkVer, u32 sharedMemSize)
Result actInit(void)
{
Result ret = 0;
if (AtomicPostIncrement(&actRefCount))
return 0;
ret = srvGetServiceHandle(&actHandle, "act:u");
if (R_FAILED(ret))
ret = srvGetServiceHandle(&actHandle, "act:a");
if (R_SUCCEEDED(ret))
{
act_shareMemSize = sharedMemSize;
act_shareMemHandle = 0;
if(act_shareMemSize)
{
act_shareMemAddr = (u32*)memalign(0x1000, act_shareMemSize);
if(act_shareMemAddr != NULL)
{
memset((void*)act_shareMemAddr, 0, act_shareMemSize);
ret = svcCreateMemoryBlock(&act_shareMemHandle, (u32)act_shareMemAddr, act_shareMemSize, 0, MEMPERM_READ | MEMPERM_WRITE);
if (R_FAILED(ret))
actExit();
}
}
AtomicDecrement(&actRefCount);
ret = ACTU_Initialize(sdkVer, &act_shareMemHandle, act_shareMemSize);
if (R_FAILED(ret))
actExit();
}
return ret;
}
@ -48,35 +31,6 @@ void actExit(void)
return;
svcCloseHandle(actHandle);
if(act_shareMemHandle)
{
svcUnmapMemoryBlock(act_shareMemHandle, (u32)act_shareMemAddr);
free(act_shareMemAddr);
act_shareMemAddr = NULL;
svcCloseHandle(act_shareMemHandle);
act_shareMemHandle = 0;
act_shareMemSize = 0;
}
}
Result ACTU_Initialize(u32 sdkVer, void * addr, u32 memSize)
{
Result ret = 0;
u32 *cmdbuf = getThreadCommandBuffer();
cmdbuf[0] = IPC_MakeHeader(0x1, 2, 4); // 0x00010084
cmdbuf[1] = sdkVer;
cmdbuf[2] = memSize;
cmdbuf[3] = 0x20;
cmdbuf[4] = IPC_Desc_CurProcessHandle();
cmdbuf[5] = 0;
cmdbuf[6] = (u32)addr;
if(R_FAILED(ret = svcSendSyncRequest(actHandle)))
return ret;
return (Result)cmdbuf[1];
}
Result ACTU_GetAccountDataBlock(void * buffer, u32 size, u32 blkId)

View File

@ -2,6 +2,16 @@
static Handle amHandle;
Result amGetServiceHandle(void)
{
return srvGetServiceHandle(&amHandle, "am:net");
}
Result amCloseServiceHandle(void)
{
return svcCloseHandle(amHandle);
}
Result amNetGetDeviceCert(u8 const * buffer)
{
Result ret = 0;

View File

@ -1,46 +1,29 @@
#include "cfgs.h"
static Handle cfgHandle;
static Handle cfgsHandle;
Result cfgsInit() //Already initialized with CFGUinit();
Result cfgsInit(void) // Already initialized with CFGUinit(), but we need to use this handle.
{
return srvGetServiceHandle(&cfgHandle, "cfg:s");
return srvGetServiceHandle(&cfgsHandle, "cfg:s");
}
Result cfgsExit()
Result cfgsExit(void)
{
return svcCloseHandle(cfgHandle);
return svcCloseHandle(cfgsHandle);
}
Result CFG_GetConfig(u32 size, u32 blkID, u8 * outData)
Result CFGS_SecureInfoGetSerialNo(u8 * serial)
{
Result ret = 0;
u32 * cmdbuf = getThreadCommandBuffer();
cmdbuf[0] = IPC_MakeHeader(0x1, 2, 2); // 0x10082
cmdbuf[1] = size;
cmdbuf[2] = blkID;
cmdbuf[3] = IPC_Desc_Buffer(size,IPC_BUFFER_W);
cmdbuf[4] = (u32)outData;
if (R_FAILED(ret = svcSendSyncRequest(cfgHandle)))
return ret;
return (Result)cmdbuf[1];
}
Result cfgsSecureInfoGetSerialNo(char * serial)
{
Result ret = 0;
u32 *cmdbuf = getThreadCommandBuffer();
cmdbuf[0] = IPC_MakeHeader(0x408, 1, 2); // 0x10082
cmdbuf[0] = IPC_MakeHeader(0x408, 1, 2); // 0x04080042
cmdbuf[1] = 0xF;
cmdbuf[2] = 12 | (0xF << 4);
cmdbuf[3] = (u32)serial;
if (R_FAILED(ret = svcSendSyncRequest(cfgHandle)))
if (R_FAILED(ret = svcSendSyncRequest(cfgsHandle)))
return ret;
return (Result)cmdbuf[1];
return cmdbuf[1];
}

View File

@ -1,73 +1,116 @@
#include "mcu.h"
static Handle mcuhwcHandle;
static Handle mcuHandle;
static int mcuRefCount;
Result mcuInit()
Result mcuInit(void)
{
return srvGetServiceHandle(&mcuhwcHandle, "mcu::HWC");
Result ret = 0;
if (AtomicPostIncrement(&mcuRefCount))
return 0;
ret = srvGetServiceHandle(&mcuHandle, "mcu::HWC");
if (R_FAILED(ret))
AtomicDecrement(&mcuRefCount);
return ret;
}
Result mcuExit()
Result mcuExit(void)
{
return svcCloseHandle(mcuhwcHandle);
return svcCloseHandle(mcuHandle);
}
Result mcuGetBatteryLevel(u8* out)
Result MCU_ReadRegister(u8 reg, u32 size, void * data)
{
u32* ipc = getThreadCommandBuffer();
ipc[0] = 0x50000;
Result ret = 0;
u32 * cmdbuf = getThreadCommandBuffer();
Result ret = svcSendSyncRequest(mcuhwcHandle);
cmdbuf[0] = IPC_MakeHeader(0x01, 2, 2); // 0x00010082
cmdbuf[1] = reg;
cmdbuf[2] = size;
cmdbuf[3] = size << 4 | 0xC;
cmdbuf[4] = (u32)data;
if(ret < 0)
if (R_FAILED(ret = svcSendSyncRequest(mcuHandle)))
return ret;
*out = ipc[2];
return ipc[1];
return cmdbuf[1];
}
Result mcuGetBatteryVoltage(u8* out)
Result MCU_GetBatteryVoltage(u8 * out)
{
u32* ipc = getThreadCommandBuffer();
ipc[0] = 0x40000;
Result ret = 0;
u32 * cmdbuf = getThreadCommandBuffer();
Result ret = svcSendSyncRequest(mcuhwcHandle);
cmdbuf[0] = IPC_MakeHeader(0x04, 0, 0); // 0x00040000
if(ret < 0)
if (R_FAILED(ret = svcSendSyncRequest(mcuHandle)))
return ret;
*out = ipc[2];
*out = cmdbuf[2];
return ipc[1];
return cmdbuf[1];
}
Result GetMcuFwVerHigh(u8* out)
Result MCU_GetBatteryLevel(u8 * out)
{
u32* ipc = getThreadCommandBuffer();
ipc[0] = 0x100000;
Result ret = 0;
u32 * cmdbuf = getThreadCommandBuffer();
Result ret = svcSendSyncRequest(mcuhwcHandle);
cmdbuf[0] = IPC_MakeHeader(0x05, 0, 0); // 0x00050000
if(ret < 0)
if (R_FAILED(ret = svcSendSyncRequest(mcuHandle)))
return ret;
*out = ipc[2];
*out = cmdbuf[2];
return ipc[1];
return cmdbuf[1];
}
Result GetMcuFwVerLow(u8* out)
Result MCU_GetSoundVolume(u8 * out) // Same as HIDUSER_GetSoundVolume
{
u32* ipc = getThreadCommandBuffer();
ipc[0] = 0x110000;
Result ret = 0;
u32 * cmdbuf = getThreadCommandBuffer();
Result ret = svcSendSyncRequest(mcuhwcHandle);
cmdbuf[0] = IPC_MakeHeader(0x0B, 0, 0); // 0x000B0000
if(ret < 0)
if (R_FAILED(ret = svcSendSyncRequest(mcuHandle)))
return ret;
*out = ipc[2];
*out = cmdbuf[2];
return ipc[1];
return cmdbuf[1];
}
Result MCU_GetFwVerHigh(u8 * out)
{
Result ret = 0;
u32 * cmdbuf = getThreadCommandBuffer();
cmdbuf[0] = IPC_MakeHeader(0x10, 0, 0); // 0x00100000
if (R_FAILED(ret = svcSendSyncRequest(mcuHandle)))
return ret;
*out = cmdbuf[2];
return cmdbuf[1];
}
Result MCU_GetFwVerLow(u8 * out)
{
Result ret = 0;
u32 * cmdbuf = getThreadCommandBuffer();
cmdbuf[0] = IPC_MakeHeader(0x11, 0, 0); // 0x00110000
if (R_FAILED(ret = svcSendSyncRequest(mcuHandle)))
return ret;
*out = cmdbuf[2];
return cmdbuf[1];
}

31
source/storage.c Normal file
View File

@ -0,0 +1,31 @@
#include "storage.h"
u64 getFreeStorage(FS_SystemMediaType mediaType)
{
FS_ArchiveResource resource = {0};
if (R_SUCCEEDED(FSUSER_GetArchiveResource(&resource, mediaType)))
return (((u64) resource.freeClusters * (u64) resource.clusterSize));
return 0;
}
u64 getTotalStorage(FS_SystemMediaType mediaType)
{
FS_ArchiveResource resource = {0};
if (R_SUCCEEDED(FSUSER_GetArchiveResource(&resource, mediaType)))
return (((u64) resource.totalClusters * (u64) resource.clusterSize));
return 0;
}
u64 getUsedStorage(FS_SystemMediaType mediaType)
{
FS_ArchiveResource resource = {0};
if (R_SUCCEEDED(FSUSER_GetArchiveResource(&resource, mediaType)))
return ((((u64) resource.totalClusters * (u64) resource.clusterSize)) - (((u64) resource.freeClusters * (u64) resource.clusterSize)));
return 0;
}

View File

@ -1,5 +1,6 @@
#include "actu.h"
#include "am.h"
#include <stdio.h>
#include <string.h>
#include "cfgs.h"
#include "system.h"
#include "utils.h"
@ -18,11 +19,13 @@ const char * getModel(void)
};
u8 model = 0;
CFGU_GetSystemModel(&model);
if (R_SUCCEEDED(CFGU_GetSystemModel(&model)))
{
if (model < 6)
return models[model];
else
}
return models[6];
}
@ -41,22 +44,21 @@ const char * getRegion(void)
};
u8 region = 0;
CFGU_SecureInfoGetRegion(&region);
if (R_SUCCEEDED(CFGU_SecureInfoGetRegion(&region)))
{
if (region < 7)
return regions[region];
else
}
return regions[7];
}
const char getFirmRegion(void)
{
u8 canadaOrUsa = 0;
CFGU_GetRegionCanadaUSA(&canadaOrUsa);
if (strncmp(getRegion(), "JPN", 3) == 0)
return 'J';
else if (canadaOrUsa == 1)
else if (strncmp(getRegion(), "USA", 3) == 0)
return 'U';
else if ((strncmp(getRegion(), "EUR", 3) == 0) || (strncmp(getRegion(), "AUS", 3) == 0))
return 'E';
@ -66,8 +68,21 @@ const char getFirmRegion(void)
return 'K';
else if (strncmp(getRegion(), "TWN", 3) == 0)
return 'T';
else
return 'X';
return 0;
}
bool IsCoppacsSupported()
{
u8 IsCoppacs = 0;
if (R_SUCCEEDED(CFGU_GetRegionCanadaUSA(&IsCoppacs)))
{
if (IsCoppacs)
return true;
}
return false;
}
const char * getLang(void)
@ -85,16 +100,19 @@ const char * getLang(void)
"Dutch",
"Portugese",
"Russian",
"Traditional Chinese"
"Traditional Chinese",
"Unknown"
};
u8 language;
CFGU_GetSystemLanguage(&language);
if (language < 11)
if (R_SUCCEEDED(CFGU_GetSystemLanguage(&language)))
{
if (language < 12)
return languages[language];
else
return languages[11];
}
return languages[12];
}
char * getMacAddress(void)
@ -102,7 +120,6 @@ char * getMacAddress(void)
u8 * macByte = (u8 *)0x1FF81060;
static char macAddress[18];
//sprintf automatically zero-terminates the string
snprintf(macAddress, 18, "%02X:%02X:%02X:%02X:%02X:%02X", *macByte, *(macByte + 1), *(macByte + 2), *(macByte + 3), *(macByte + 4), *(macByte + 5));
return macAddress;
@ -110,21 +127,18 @@ char * getMacAddress(void)
char * getScreenType(void)
{
bool isNew3DS = 0;
APT_CheckNew3DS(&isNew3DS);
static char uScreenType[20];
static char dScreenType[20];
static char screenType[32];
if (isNew3DS)
if (isN3DS())
{
u8 screens = 0;
if(R_SUCCEEDED(gspLcdInit()))
{
GSPLCD_GetVendors(&screens);
if (R_SUCCEEDED(GSPLCD_GetVendors(&screens)))
gspLcdExit();
}
@ -166,94 +180,28 @@ u64 getLocalFriendCodeSeed(void)
{
u64 seed = 0;
PS_GetLocalFriendCodeSeed(&seed);
if (R_SUCCEEDED(PS_GetLocalFriendCodeSeed(&seed)))
return seed;
return 0;
}
char * getSerialNum(void)
u8 * getSerialNumber(void)
{
static char str[32];
char serial[0x10];
static u8 serial[0xF];
cfgsSecureInfoGetSerialNo(serial);
strcpy(str, serial);
if (R_SUCCEEDED(CFGS_SecureInfoGetSerialNo(serial)))
return serial;
return str;
}
u32 getDeviceId(void) // Same as PS_GetDeviceId
{
u32 tmp = 0;
AM_GetDeviceId(&tmp);
return tmp;
return NULL;
}
u64 getSoapId(void)
{
u32 tmp = 0;
AM_GetDeviceId(&tmp);
return (tmp | (((u64) 4) << 32));
}
char * getDeviceCert(void)
{
u8 const cert[0x180];
amNetGetDeviceCert(cert);
return base64Encode(cert, 0x180);
}
char * getNNIDInfo(u32 size, u32 blkId)
{
char info[size];
static char str[100];
ACTU_GetAccountDataBlock(info, size, blkId);
snprintf(str, size, "%s", info);
return str;
}
char * getBrightness(u32 screen)
{
u32 brightness = 0;
if(R_SUCCEEDED(gspLcdInit()))
{
GSPLCD_GetBrightness(screen, &brightness);
gspLcdExit();
}
if (brightness == 0x10)
return "1 (20%)";
else if (brightness == 0x1C)
return "2 (40%)";
else if (brightness == 0x30)
return "3 (60%)";
else if (brightness == 0x52)
return "4 (80%)";
else if (brightness == 0x8E)
return "5 (100%)";
else
return "n3DS only";
}
char * getCardSlotStatus(void)
{
bool isInserted = false;
FS_CardType cardType = 0;
static char card[20];
FSUSER_CardSlotIsInserted(&isInserted);
if (isInserted)
{
FSUSER_GetCardType(&cardType);
snprintf(card, 20, "inserted %s", cardType? "(TWL)" : "(CTR)");
return card;
}
snprintf(card, 20, "not inserted");
return card;
u32 id = 0;
if (R_SUCCEEDED(AM_GetDeviceId(&id)))
return (id | (((u64) 4) << 32));
return 0;
}

View File

@ -1,3 +1,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "utils.h"
void getSizeString(char *string, uint64_t size) //Thanks TheOfficialFloW
@ -14,13 +18,24 @@ void getSizeString(char *string, uint64_t size) //Thanks TheOfficialFloW
sprintf(string, "%.*f %s", (i == 0) ? 0 : 2, double_size, units[i]);
}
void utf2ascii(char* dst, u16* src)
bool isN3DS(void)
{
if(!src || !dst)
return;
bool isNew3DS = false;
while(*src)*(dst++)=(*(src++))&0xFF;
*dst=0x00;
if (R_SUCCEEDED(APT_CheckNew3DS(&isNew3DS)))
return isNew3DS;
return false;
}
void u16_to_u8(char * buf, const u16 * input, size_t bufsize)
{
ssize_t units = utf16_to_utf8((u8 *)buf, input, bufsize);
if (units < 0)
units = 0;
buf[units] = 0;
}
// Crashes doesn't work. Leavign it here for anyone who's interested.

25
source/wifi.c Normal file
View File

@ -0,0 +1,25 @@
#include "ac.h"
#include "wifi.h"
char * getSecurityMode()
{
u32 securityMode = 0;
if (R_FAILED(ACU_GetConnectingSecurityMode(&securityMode)))
securityMode = 8;
static char * securityString[] =
{
"Open authentication",
"WEP 40-bit",
"WEP 104-bit",
"WEP 128-bit",
"WPA TKIP",
"WPA2 TKIP",
"WPA AES",
"WPA2 AES",
"Unknown"
};
return securityString[securityMode];
}