Cleanup, add possibility to clear the inserted PIN by pressing SELECT
This commit is contained in:
parent
3572b835b5
commit
37e467ba60
@ -44,4 +44,4 @@
|
|||||||
#define SINGLE_PAYLOAD_BUTTONS (DPAD_BUTTONS | BUTTON_B | BUTTON_X | BUTTON_Y)
|
#define SINGLE_PAYLOAD_BUTTONS (DPAD_BUTTONS | BUTTON_B | BUTTON_X | BUTTON_Y)
|
||||||
#define L_PAYLOAD_BUTTONS (BUTTON_R1 | BUTTON_A | BUTTON_START | BUTTON_SELECT)
|
#define L_PAYLOAD_BUTTONS (BUTTON_R1 | BUTTON_A | BUTTON_START | BUTTON_SELECT)
|
||||||
#define MENU_BUTTONS (DPAD_BUTTONS | BUTTON_A | BUTTON_START)
|
#define MENU_BUTTONS (DPAD_BUTTONS | BUTTON_A | BUTTON_START)
|
||||||
#define PIN_BUTTONS (BUTTON_A | BUTTON_B | BUTTON_X | BUTTON_Y | DPAD_BUTTONS | BUTTON_START)
|
#define PIN_BUTTONS (BUTTON_A | BUTTON_B | BUTTON_X | BUTTON_Y | DPAD_BUTTONS | BUTTON_START | BUTTON_SELECT)
|
@ -397,6 +397,5 @@ void configMenu(bool isSdMode, bool oldPinStatus, u32 oldPinMode)
|
|||||||
else if(oldPinStatus) fileDelete(PIN_FILE);
|
else if(oldPinStatus) fileDelete(PIN_FILE);
|
||||||
|
|
||||||
while(HID_PAD & PIN_BUTTONS);
|
while(HID_PAD & PIN_BUTTONS);
|
||||||
startChrono();
|
wait(false, 2ULL);
|
||||||
while(chrono(false) < 2);
|
|
||||||
}
|
}
|
@ -55,9 +55,7 @@ bool loadSplash(void)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
swapFramebuffers(true);
|
swapFramebuffers(true);
|
||||||
|
wait(false, 3ULL);
|
||||||
startChrono();
|
|
||||||
while(chrono(false) < 3);
|
|
||||||
|
|
||||||
ret = true;
|
ret = true;
|
||||||
}
|
}
|
||||||
|
@ -190,7 +190,7 @@ void loadPayload(u32 pressed, const char *payloadPath)
|
|||||||
void payloadMenu(void)
|
void payloadMenu(void)
|
||||||
{
|
{
|
||||||
DIR dir;
|
DIR dir;
|
||||||
char path[_MAX_LFN + 10] = "payloads";
|
char path[62] = "payloads";
|
||||||
|
|
||||||
if(f_opendir(&dir, path) == FR_OK)
|
if(f_opendir(&dir, path) == FR_OK)
|
||||||
{
|
{
|
||||||
@ -272,8 +272,7 @@ void payloadMenu(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
while(HID_PAD & MENU_BUTTONS);
|
while(HID_PAD & MENU_BUTTONS);
|
||||||
startChrono();
|
wait(false, 2ULL);
|
||||||
while(chrono(false) < 2);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
12
source/i2c.c
12
source/i2c.c
@ -25,7 +25,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "i2c.h"
|
#include "i2c.h"
|
||||||
#include "utils.h"
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
@ -155,16 +154,7 @@ bool i2cWriteRegister(u8 dev_id, u8 reg, u8 data)
|
|||||||
*i2cGetCntReg(bus_id) = 0xC1;
|
*i2cGetCntReg(bus_id) = 0xC1;
|
||||||
i2cStop(bus_id, 0);
|
i2cStop(bus_id, 0);
|
||||||
|
|
||||||
if(i2cGetResult(bus_id))
|
if(i2cGetResult(bus_id)) return true;
|
||||||
{
|
|
||||||
if(dev_id == I2C_DEV_MCU)
|
|
||||||
{
|
|
||||||
startChrono();
|
|
||||||
while(chrono(true) < 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
*i2cGetCntReg(bus_id) = 0xC5;
|
*i2cGetCntReg(bus_id) = 0xC5;
|
||||||
i2cWaitBusy(bus_id);
|
i2cWaitBusy(bus_id);
|
||||||
|
@ -148,8 +148,7 @@ void main(void)
|
|||||||
if(pinExists && !shouldLoadConfigMenu)
|
if(pinExists && !shouldLoadConfigMenu)
|
||||||
{
|
{
|
||||||
while(HID_PAD & PIN_BUTTONS);
|
while(HID_PAD & PIN_BUTTONS);
|
||||||
startChrono();
|
wait(false, 2ULL);
|
||||||
while(chrono(false) < 2);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
93
source/pin.c
93
source/pin.c
@ -50,19 +50,29 @@ void newPin(bool allowSkipping, u32 pinMode)
|
|||||||
|
|
||||||
u8 length = 4 + 2 * (pinMode - 1);
|
u8 length = 4 + 2 * (pinMode - 1);
|
||||||
|
|
||||||
const char *title = allowSkipping ? "Press START to skip or enter a new PIN" : "Enter a new PIN to proceed";
|
drawString("Enter a new PIN using ABXY and the DPad", true, 10, 10, COLOR_TITLE);
|
||||||
drawString(title, true, 10, 10, COLOR_TITLE);
|
drawString(allowSkipping ? "Press START to skip, SELECT to reset" : "Press SELECT to reset", true, 10, 10 + SPACING_Y, COLOR_TITLE);
|
||||||
drawString("PIN ( digits): ", true, 10, 10 + 2 * SPACING_Y, COLOR_WHITE);
|
|
||||||
drawCharacter('0' + length, true, 10 + 5 * SPACING_X, 10 + 2 * SPACING_Y, COLOR_WHITE);
|
drawString("PIN ( digits): ", true, 10, 10 + 3 * SPACING_Y, COLOR_WHITE);
|
||||||
|
drawCharacter('0' + length, true, 10 + 5 * SPACING_X, 10 + 3 * SPACING_Y, COLOR_WHITE);
|
||||||
|
|
||||||
//Pad to AES block length with zeroes
|
//Pad to AES block length with zeroes
|
||||||
__attribute__((aligned(4))) u8 enteredPassword[AES_BLOCK_SIZE] = {0};
|
__attribute__((aligned(4))) u8 enteredPassword[AES_BLOCK_SIZE] = {0};
|
||||||
|
|
||||||
|
bool reset = false;
|
||||||
u8 cnt = 0;
|
u8 cnt = 0;
|
||||||
u32 charDrawPos = 16 * SPACING_X;
|
|
||||||
|
|
||||||
while(cnt < length)
|
while(cnt < length)
|
||||||
{
|
{
|
||||||
|
if(reset)
|
||||||
|
{
|
||||||
|
for(u32 i = 0; i < cnt; i++)
|
||||||
|
drawCharacter((char)enteredPassword[i], true, 10 + (16 + 2 * i) * SPACING_X, 10 + 3 * SPACING_Y, COLOR_BLACK);
|
||||||
|
|
||||||
|
cnt = 0;
|
||||||
|
reset = false;
|
||||||
|
}
|
||||||
|
|
||||||
u32 pressed;
|
u32 pressed;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
@ -74,14 +84,17 @@ void newPin(bool allowSkipping, u32 pinMode)
|
|||||||
if(!allowSkipping) pressed &= ~BUTTON_START;
|
if(!allowSkipping) pressed &= ~BUTTON_START;
|
||||||
|
|
||||||
if(pressed & BUTTON_START) return;
|
if(pressed & BUTTON_START) return;
|
||||||
if(!pressed) continue;
|
|
||||||
|
|
||||||
char key = pinKeyToLetter(pressed);
|
if(pressed & BUTTON_SELECT) reset = true;
|
||||||
enteredPassword[cnt++] = (u8)key; //Add character to password
|
else if(pressed != 0)
|
||||||
|
{
|
||||||
|
enteredPassword[cnt] = (u8)pinKeyToLetter(pressed); //Add character to password
|
||||||
|
|
||||||
//Visualize character on screen
|
//Visualize character on screen
|
||||||
drawCharacter(key, true, 10 + charDrawPos, 10 + 2 * SPACING_Y, COLOR_WHITE);
|
drawCharacter(enteredPassword[cnt], true, 10 + (16 + 2 * cnt) * SPACING_X, 10 + 3 * SPACING_Y, COLOR_WHITE);
|
||||||
charDrawPos += 2 * SPACING_X;
|
|
||||||
|
cnt++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PinData pin;
|
PinData pin;
|
||||||
@ -125,12 +138,11 @@ bool verifyPin(u32 pinMode)
|
|||||||
|
|
||||||
initScreens();
|
initScreens();
|
||||||
|
|
||||||
//Pad to AES block length with zeroes
|
drawString("Enter the PIN using ABXY and the DPad to proceed", true, 10, 10, COLOR_TITLE);
|
||||||
__attribute__((aligned(4))) u8 enteredPassword[AES_BLOCK_SIZE] = {0};
|
drawString("Press START to shutdown, SELECT to clear", true, 10, 10 + SPACING_Y, COLOR_TITLE);
|
||||||
|
|
||||||
bool unlock = false;
|
drawString("PIN ( digits): ", true, 10, 10 + 3 * SPACING_Y, COLOR_WHITE);
|
||||||
u8 cnt = 0;
|
drawCharacter('0' + lengthBlock[0], true, 10 + 5 * SPACING_X, 10 + 3 * SPACING_Y, COLOR_WHITE);
|
||||||
u32 charDrawPos = 16 * SPACING_X;
|
|
||||||
|
|
||||||
const char *messageFile = "pinmessage.txt";
|
const char *messageFile = "pinmessage.txt";
|
||||||
|
|
||||||
@ -147,11 +159,23 @@ bool verifyPin(u32 pinMode)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Pad to AES block length with zeroes
|
||||||
|
__attribute__((aligned(4))) u8 enteredPassword[AES_BLOCK_SIZE] = {0};
|
||||||
|
|
||||||
|
bool unlock = false,
|
||||||
|
reset = false;
|
||||||
|
u8 cnt = 0;
|
||||||
|
|
||||||
while(!unlock)
|
while(!unlock)
|
||||||
{
|
{
|
||||||
drawString("Press START to shutdown or enter PIN to proceed", true, 10, 10, COLOR_TITLE);
|
if(reset)
|
||||||
drawString("PIN ( digits): ", true, 10, 10 + 2 * SPACING_Y, COLOR_WHITE);
|
{
|
||||||
drawCharacter('0' + lengthBlock[0], true, 10 + 5 * SPACING_X, 10 + 2 * SPACING_Y, COLOR_WHITE);
|
for(u32 i = 0; i < cnt; i++)
|
||||||
|
drawCharacter((char)enteredPassword[i], true, 10 + (16 + 2 * i) * SPACING_X, 10 + 3 * SPACING_Y, COLOR_BLACK);
|
||||||
|
|
||||||
|
cnt = 0;
|
||||||
|
reset = false;
|
||||||
|
}
|
||||||
|
|
||||||
u32 pressed;
|
u32 pressed;
|
||||||
do
|
do
|
||||||
@ -164,28 +188,25 @@ bool verifyPin(u32 pinMode)
|
|||||||
|
|
||||||
pressed &= PIN_BUTTONS;
|
pressed &= PIN_BUTTONS;
|
||||||
|
|
||||||
if(!pressed) continue;
|
if(pressed & BUTTON_SELECT) reset = true;
|
||||||
|
else if(pressed != 0)
|
||||||
char key = pinKeyToLetter(pressed);
|
|
||||||
enteredPassword[cnt++] = (u8)key; //Add character to password
|
|
||||||
|
|
||||||
//Visualize character on screen
|
|
||||||
drawCharacter(key, true, 10 + charDrawPos, 10 + 2 * SPACING_Y, COLOR_WHITE);
|
|
||||||
charDrawPos += 2 * SPACING_X;
|
|
||||||
|
|
||||||
if(cnt >= lengthBlock[0])
|
|
||||||
{
|
{
|
||||||
computePinHash(tmp, enteredPassword);
|
enteredPassword[cnt] = (u8)pinKeyToLetter(pressed); //Add character to password
|
||||||
unlock = memcmp(pin.hash, tmp, sizeof(tmp)) == 0;
|
|
||||||
|
|
||||||
if(!unlock)
|
//Visualize character on screen
|
||||||
|
drawCharacter((char)enteredPassword[cnt], true, 10 + (16 + 2 * cnt) * SPACING_X, 10 + 3 * SPACING_Y, COLOR_WHITE);
|
||||||
|
|
||||||
|
if(++cnt >= lengthBlock[0])
|
||||||
{
|
{
|
||||||
charDrawPos = 16 * SPACING_X;
|
computePinHash(tmp, enteredPassword);
|
||||||
cnt = 0;
|
unlock = memcmp(pin.hash, tmp, sizeof(tmp)) == 0;
|
||||||
|
|
||||||
clearScreens(true, false, false);
|
if(!unlock)
|
||||||
|
{
|
||||||
|
reset = true;
|
||||||
|
|
||||||
drawString("Wrong PIN, try again", true, 10, 10 + 4 * SPACING_Y, COLOR_RED);
|
drawString("Wrong PIN, try again", true, 10, 10 + 5 * SPACING_Y, COLOR_RED);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,7 @@
|
|||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
#include "cache.h"
|
#include "cache.h"
|
||||||
#include "i2c.h"
|
#include "i2c.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
vu32 *arm11Entry = (vu32 *)BRAHMA_ARM11_ENTRY;
|
vu32 *arm11Entry = (vu32 *)BRAHMA_ARM11_ENTRY;
|
||||||
static const u32 brightness[4] = {0x5F, 0x4C, 0x39, 0x26};
|
static const u32 brightness[4] = {0x5F, 0x4C, 0x39, 0x26};
|
||||||
@ -295,6 +296,7 @@ void initScreens(void)
|
|||||||
|
|
||||||
//Turn on backlight
|
//Turn on backlight
|
||||||
i2cWriteRegister(I2C_DEV_MCU, 0x22, 0x2A);
|
i2cWriteRegister(I2C_DEV_MCU, 0x22, 0x2A);
|
||||||
|
wait(true, 3ULL);
|
||||||
}
|
}
|
||||||
else updateBrightness(MULTICONFIG(BRIGHTNESS));
|
else updateBrightness(MULTICONFIG(BRIGHTNESS));
|
||||||
|
|
||||||
|
@ -31,16 +31,38 @@
|
|||||||
#include "draw.h"
|
#include "draw.h"
|
||||||
#include "cache.h"
|
#include "cache.h"
|
||||||
|
|
||||||
|
static void startChrono(void)
|
||||||
|
{
|
||||||
|
REG_TIMER_CNT(0) = 0; //67MHz
|
||||||
|
for(u32 i = 1; i < 4; i++) REG_TIMER_CNT(i) = 4; //Count-up
|
||||||
|
|
||||||
|
for(u32 i = 0; i < 4; i++) REG_TIMER_VAL(i) = 0;
|
||||||
|
|
||||||
|
REG_TIMER_CNT(0) = 0x80; //67MHz; enabled
|
||||||
|
for(u32 i = 1; i < 4; i++) REG_TIMER_CNT(i) = 0x84; //Count-up; enabled
|
||||||
|
}
|
||||||
|
|
||||||
|
static u64 chrono(bool isMilliseconds)
|
||||||
|
{
|
||||||
|
u64 res;
|
||||||
|
for(u32 i = 0; i < 4; i++) res |= REG_TIMER_VAL(i) << (16 * i);
|
||||||
|
|
||||||
|
if(isMilliseconds) res /= (TICKS_PER_SEC / 1000);
|
||||||
|
else res /= TICKS_PER_SEC;
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
u32 waitInput(bool isMenu)
|
u32 waitInput(bool isMenu)
|
||||||
{
|
{
|
||||||
static u64 dPadDelay = 0;
|
static u64 dPadDelay = 0ULL;
|
||||||
bool pressedKey = false;
|
bool pressedKey = false;
|
||||||
u32 key,
|
u32 key,
|
||||||
oldKey = HID_PAD;
|
oldKey = HID_PAD;
|
||||||
|
|
||||||
if(isMenu)
|
if(isMenu)
|
||||||
{
|
{
|
||||||
dPadDelay = dPadDelay > 0 ? 87 : 143;
|
dPadDelay = dPadDelay > 0ULL ? 87ULL : 143ULL;
|
||||||
startChrono();
|
startChrono();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,26 +99,10 @@ void mcuPowerOff(void)
|
|||||||
while(true);
|
while(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void startChrono(void)
|
void wait(bool isMilliseconds, u64 amount)
|
||||||
{
|
{
|
||||||
REG_TIMER_CNT(0) = 0; //67MHz
|
startChrono();
|
||||||
for(u32 i = 1; i < 4; i++) REG_TIMER_CNT(i) = 4; //Count-up
|
while(chrono(isMilliseconds) < amount);
|
||||||
|
|
||||||
for(u32 i = 0; i < 4; i++) REG_TIMER_VAL(i) = 0;
|
|
||||||
|
|
||||||
REG_TIMER_CNT(0) = 0x80; //67MHz; enabled
|
|
||||||
for(u32 i = 1; i < 4; i++) REG_TIMER_CNT(i) = 0x84; //Count-up; enabled
|
|
||||||
}
|
|
||||||
|
|
||||||
u64 chrono(bool isMilliseconds)
|
|
||||||
{
|
|
||||||
u64 res;
|
|
||||||
for(u32 i = 0; i < 4; i++) res |= REG_TIMER_VAL(i) << (16 * i);
|
|
||||||
|
|
||||||
if(isMilliseconds) res /= (TICKS_PER_SEC / 1000);
|
|
||||||
else res /= TICKS_PER_SEC;
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void error(const char *message)
|
void error(const char *message)
|
||||||
|
@ -34,6 +34,5 @@
|
|||||||
|
|
||||||
u32 waitInput(bool isMenu);
|
u32 waitInput(bool isMenu);
|
||||||
void mcuPowerOff(void);
|
void mcuPowerOff(void);
|
||||||
void startChrono(void);
|
void wait(bool isMilliseconds, u64 amount);
|
||||||
u64 chrono(bool isMilliseconds);
|
|
||||||
void error(const char *message);
|
void error(const char *message);
|
Reference in New Issue
Block a user