Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 90 additions & 9 deletions ios_mcp/source/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
static void option_SetColdbootTitle(void);
static void option_DumpSyslogs(void);
static void option_DumpOtpAndSeeprom(void);
static void option_DumpDRCcode(void);
static void option_StartWupserver(void);
static void option_LoadNetConf(void);
static void option_pairDRC(void);
Expand Down Expand Up @@ -62,6 +63,7 @@ static const Menu mainMenuOptions[] = {
{"Set Coldboot Title", {.callback = option_SetColdbootTitle}},
{"Dump Syslogs", {.callback = option_DumpSyslogs}},
{"Dump OTP + SEEPROM", {.callback = option_DumpOtpAndSeeprom}},
{"Dump gamepad PIN", {.callback = option_DumpDRCcode}},
{"Start wupserver", {.callback = option_StartWupserver}},
{"Load Network Configuration", {.callback = option_LoadNetConf}},
{"Pair Gamepad", {.callback = option_pairDRC}},
Expand All @@ -72,6 +74,13 @@ static const Menu mainMenuOptions[] = {
{"Shutdown", {.callback = option_Shutdown}},
};

static const char symbol_names[][8] = {
"spade",
"heart",
"diamond",
"clubs",
};

static void drawTopBar(const char* title)
{
// draw top bar
Expand Down Expand Up @@ -456,6 +465,85 @@ static void option_DumpOtpAndSeeprom(void)
IOS_HeapFree(CROSS_PROCESS_HEAP_ID, dataBuffer);
}

static void option_DumpDRCcode(void)
{
gfx_clear(COLOR_BACKGROUND);
drawTopBar("Dumping gamepad PIN...");
setNotificationLED(NOTIF_LED_RED_BLINKING, 0);

uint32_t index = 16 + 8 + 2 + 8;

int res = CCRCDCSetup();
if (res < 0) {
gfx_set_font_color(COLOR_ERROR);
gfx_printf(16, index, 0, "CCRCDCSetup() failed: %x", res);
setNotificationLED(NOTIF_LED_PURPLE, 0);

waitButtonInput();
return;
}

gfx_print(16, index, 0, "Get pincode...");
index += CHAR_SIZE_DRC_Y + 4;

uint8_t pincode[4];
res = CCRSysGetPincode(pincode);
if (res < 0) {
gfx_set_font_color(COLOR_ERROR);
gfx_printf(16, index, 0, "Failed to get pincode: %x", res);
setNotificationLED(NOTIF_LED_PURPLE, 0);

waitButtonInput();
return;
}

gfx_print(16, index, 0, "Creating gamepadPIN.txt...");
index += CHAR_SIZE_DRC_Y + 4;

void* dataBuffer = IOS_HeapAllocAligned(CROSS_PROCESS_HEAP_ID, 0x400, 0x40);
if (!dataBuffer) {
gfx_set_font_color(COLOR_ERROR);
gfx_print(16, index, 0, "Out of memory!");
setNotificationLED(NOTIF_LED_PURPLE, 0);
waitButtonInput();
return;
}

int drcHandle;
res = FSA_OpenFile(fsaHandle, "/vol/storage_recovsd/gamepadPIN.txt", "w", &drcHandle);
if (res < 0) {
gfx_set_font_color(COLOR_ERROR);
gfx_printf(16, index, 0, "Failed to create gamepadPIN.txt: %x", res);
setNotificationLED(NOTIF_LED_PURPLE, 0);
waitButtonInput();

IOS_HeapFree(CROSS_PROCESS_HEAP_ID, dataBuffer);
return;
}

snprintf(dataBuffer, 0x400, "%s %s %s %s\n", symbol_names[pincode[0]], symbol_names[pincode[1]], symbol_names[pincode[2]], symbol_names[pincode[3]]);
res = FSA_WriteFile(fsaHandle, dataBuffer, strnlen(dataBuffer, 0x400), 1, drcHandle, 0);
if (res != 1) {
gfx_set_font_color(COLOR_ERROR);
gfx_printf(16, index, 0, "Failed to write gamepadPIN.txt: %x", res);
setNotificationLED(NOTIF_LED_PURPLE, 0);
waitButtonInput();

FSA_CloseFile(fsaHandle, drcHandle);
IOS_HeapFree(CROSS_PROCESS_HEAP_ID, dataBuffer);
return;
}

gfx_set_font_color(COLOR_SUCCESS);

gfx_print(16, index, 0, "Done!");
setNotificationLED(NOTIF_LED_PURPLE, 0);
waitButtonInput();

FSA_CloseFile(fsaHandle, drcHandle);
IOS_HeapFree(CROSS_PROCESS_HEAP_ID, dataBuffer);
}

static void option_StartWupserver(void)
{
gfx_clear(COLOR_BACKGROUND);
Expand Down Expand Up @@ -746,13 +834,6 @@ static void option_pairDRC(void)
return;
}

static const char symbol_names[][8] = {
"spade",
"heart",
"diamond",
"clubs",
};

gfx_set_font_color(COLOR_SUCCESS);
gfx_printf(16, index, 0, "Pincode: %x%x%x%x (%s %s %s %s)",
pincode[0], pincode[1], pincode[2], pincode[3],
Expand Down Expand Up @@ -1445,7 +1526,7 @@ int menuThread(void* arg)
printf("menuThread running\n");

// set LED to purple-orange blinking
setNotificationLED(NOTIF_LED_RED | NOTIF_LED_RED_BLINKING | NOTIF_LED_BLUE | NOTIF_LED_BLUE_BLINKING | NOTIF_LED_ORANGE);
setNotificationLED(NOTIF_LED_RED | NOTIF_LED_RED_BLINKING | NOTIF_LED_BLUE | NOTIF_LED_BLUE_BLINKING | NOTIF_LED_ORANGE, 0);

// stop ppcHeartbeatThread and reset PPC
IOS_CancelThread(ppcHeartBeatThreadId, 0);
Expand Down Expand Up @@ -1490,7 +1571,7 @@ int menuThread(void* arg)
}

// set LED to purple
setNotificationLED(NOTIF_LED_RED | NOTIF_LED_BLUE);
setNotificationLED(NOTIF_LED_PURPLE, 0);

int selected = 0;
while (1) {
Expand Down
44 changes: 42 additions & 2 deletions ios_mcp/source/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@
#include "imports.h"
#include "fsa.h"

#include <stdbool.h>
#include <unistd.h>

#define COPY_BUFFER_SIZE 1024

#define HW_RSTB 0x0d800194

static NOTIF_LED oldLedState = NOTIF_LED_PURPLE;
static int ledTid = -1;
static volatile bool ledCanceled;
static uint8_t ledThreadStack[0x400] __attribute__((aligned(0x20)));

uint32_t kernRead32(uint32_t address)
{
return IOS_Syscall0x81(0, address, 0);
Expand Down Expand Up @@ -96,9 +104,41 @@ int readDCConfig(DisplayController_Config* config)
return bspRead("DISPLAY", 0, "DC_CONFIG", 0x14, config);
}

int setNotificationLED(uint8_t mask)
static int ledThread(void *arg)
{
for(uint32_t i = 0; i < (uint32_t)arg; ++i)
{
usleep(1);
if(ledCanceled)
return 0;
}

bspWrite("SMC", 0, "NotificationLED", 1, &oldLedState);
return 0;
}

void setNotificationLED(NOTIF_LED state, uint32_t duration)
{
return bspWrite("SMC", 0, "NotificationLED", 1, &mask);
if(state == oldLedState)
return;

if(ledTid != -1)
{
ledCanceled = true;
IOS_JoinThread(ledTid, NULL);
ledTid = -1;
}

bspWrite("SMC", 0, "NotificationLED", 1, &state);

if(duration != 0)
{
ledCanceled = false;
ledTid = IOS_CreateThread(ledThread, (void *)duration, ledThreadStack + sizeof(ledThreadStack), sizeof(ledThreadStack), IOS_GetThreadPriority(0), 0);
IOS_StartThread(ledTid);
}
else
oldLedState = state;
}

int setDrivePower(int power)
Expand Down
8 changes: 5 additions & 3 deletions ios_mcp/source/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,17 @@ typedef struct DisplayController_Config {
void* framebuffer;
} DisplayController_Config;

enum {
typedef enum {
NOTIF_LED_OFF = 0,
NOTIF_LED_ORANGE_BLINKING = 1 << 0,
NOTIF_LED_ORANGE = 1 << 1,
NOTIF_LED_RED_BLINKING = 1 << 2,
NOTIF_LED_RED = 1 << 3,
NOTIF_LED_BLUE_BLINKING = 1 << 4,
NOTIF_LED_BLUE = 1 << 5,
};
NOTIF_LED_PURPLE = NOTIF_LED_RED | NOTIF_LED_BLUE,
NOTIF_LED_PURPLE_BLINKING = NOTIF_LED_RED_BLINKING | NOTIF_LED_BLUE_BLINKING,
} NOTIF_LED;

uint32_t kernRead32(uint32_t address);

Expand All @@ -65,6 +67,6 @@ int initDisplay(uint32_t configuration);

int readDCConfig(DisplayController_Config* config);

int setNotificationLED(uint8_t mask);
void setNotificationLED(NOTIF_LED state, uint32_t duration);

int setDrivePower(int power);