Skip to content

Commit

Permalink
upd seader
Browse files Browse the repository at this point in the history
  • Loading branch information
xMasterX committed Dec 19, 2023
1 parent 2da78ea commit ab51889
Show file tree
Hide file tree
Showing 7 changed files with 227 additions and 191 deletions.
3 changes: 1 addition & 2 deletions non_catalog_apps/seader/ccid.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ void seader_ccid_check_for_sam(SeaderUartBridge* seader_uart) {
hasSAM = false; // If someone is calling this, reset sam state
powered[0] = false;
powered[1] = false;
retries = 3;
seader_ccid_GetSlotStatus(seader_uart, 0);
}

Expand Down Expand Up @@ -154,7 +155,6 @@ size_t seader_ccid_process(Seader* seader, uint8_t* cmd, size_t cmd_len) {
if(hasSAM && sam_slot == 0) {
break;
}
retries = 0;
sequence[0] = 0;
seader_ccid_IccPowerOn(seader_uart, 0);
break;
Expand All @@ -178,7 +178,6 @@ size_t seader_ccid_process(Seader* seader, uint8_t* cmd, size_t cmd_len) {
if(hasSAM && sam_slot == 1) {
break;
}
retries = 0;
sequence[1] = 0;
seader_ccid_IccPowerOn(seader_uart, 1);
break;
Expand Down
3 changes: 2 additions & 1 deletion non_catalog_apps/seader/readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Seader

[Flipper Zero](https://flipperzero.one/) application (aka "fap"). Versioning TBD.

A [Flipper Zero](https://flipperzero.one/) application (aka "fap") to interface with a SAM from the Flipper Zero over UART. Latest release on the [App Catalog](https://lab.flipper.net/apps/seader).

## Bugs

Expand Down
34 changes: 29 additions & 5 deletions non_catalog_apps/seader/sam_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ uint8_t read4Block6[] = {RFAL_PICOPASS_CMD_READ4, 0x06, 0x45, 0x56};
uint8_t read4Block9[] = {RFAL_PICOPASS_CMD_READ4, 0x09, 0xB2, 0xAE};
uint8_t read4Block10[] = {RFAL_PICOPASS_CMD_READ4, 0x0A, 0x29, 0x9C};
uint8_t read4Block13[] = {RFAL_PICOPASS_CMD_READ4, 0x0D, 0x96, 0xE8};
//uint8_t read4Block14[] = {RFAL_PICOPASS_CMD_READ4, 0x0E, 0x0d, 0xda};

uint8_t updateBlock2[] = {RFAL_PICOPASS_CMD_UPDATE, 0x02};

void* calloc(size_t count, size_t size) {
Expand Down Expand Up @@ -54,9 +56,11 @@ void seader_picopass_state_machine(Seader* seader, uint8_t* buffer, size_t len)
bit_buffer_append_bytes(tx_buffer, buffer, len);
BitBuffer* rx_buffer = bit_buffer_alloc(SEADER_POLLER_MAX_BUFFER_SIZE);

uint8_t config[PICOPASS_BLOCK_LEN] = {0x12, 0xff, 0xff, 0xff, 0x7f, 0x1f, 0xff, 0x3c};
uint8_t sr_aia[PICOPASS_BLOCK_LEN] = {0xFF, 0xff, 0xff, 0xff, 0xFF, 0xFf, 0xff, 0xFF};
uint8_t epurse[PICOPASS_BLOCK_LEN] = {0xff, 0xff, 0xff, 0xff, 0xe3, 0xff, 0xff, 0xff};
uint8_t pacs_sr_cfg[PICOPASS_BLOCK_LEN] = {0xA3, 0x03, 0x03, 0x03, 0x00, 0x03, 0xe0, 0x14};
uint8_t zeroes[PICOPASS_BLOCK_LEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

uint8_t tmac[4] = {};
uint8_t cc_p[12] = {};
Expand All @@ -70,6 +74,12 @@ void seader_picopass_state_machine(Seader* seader, uint8_t* buffer, size_t len)
bit_buffer_append_bytes(rx_buffer, sr_aia, sizeof(sr_aia));
} else if(buffer[1] == PACS_CFG_INDEX) {
bit_buffer_append_bytes(rx_buffer, pacs_sr_cfg, sizeof(pacs_sr_cfg));
} else { // What i've seen is 0c 12
offset = buffer[1] - SEADER_ICLASS_SR_SIO_BASE_BLOCK;
bit_buffer_append_bytes(
rx_buffer,
seader->credential->sio + (PICOPASS_BLOCK_LEN * offset),
PICOPASS_BLOCK_LEN);
}
iso13239_crc_append(Iso13239CrcTypePicopass, rx_buffer);
break;
Expand All @@ -90,11 +100,25 @@ void seader_picopass_state_machine(Seader* seader, uint8_t* buffer, size_t len)
bit_buffer_append_bytes(rx_buffer, tmac, sizeof(tmac));
break;
case RFAL_PICOPASS_CMD_READ4:
offset = buffer[1] - SEADER_ICLASS_SR_SIO_BASE_BLOCK;
bit_buffer_append_bytes(
rx_buffer,
seader->credential->sio + (PICOPASS_BLOCK_LEN * offset),
PICOPASS_BLOCK_LEN * 4);
if(buffer[1] < SEADER_ICLASS_SR_SIO_BASE_BLOCK) {
if(buffer[1] == PACS_CFG_INDEX) {
bit_buffer_append_bytes(rx_buffer, pacs_sr_cfg, sizeof(pacs_sr_cfg));
bit_buffer_append_bytes(rx_buffer, zeroes, sizeof(zeroes));
bit_buffer_append_bytes(rx_buffer, zeroes, sizeof(zeroes));
bit_buffer_append_bytes(rx_buffer, zeroes, sizeof(zeroes));
}
} else {
offset = buffer[1] - SEADER_ICLASS_SR_SIO_BASE_BLOCK;
bit_buffer_append_bytes(
rx_buffer,
seader->credential->sio + (PICOPASS_BLOCK_LEN * offset),
PICOPASS_BLOCK_LEN * 4);
}
iso13239_crc_append(Iso13239CrcTypePicopass, rx_buffer);
break;
case RFAL_PICOPASS_CMD_PAGESEL:
// this should be considered an attempt, but realisticly not working
bit_buffer_append_bytes(rx_buffer, config, sizeof(config));
iso13239_crc_append(Iso13239CrcTypePicopass, rx_buffer);
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ bool seader_scene_read_card_success_on_event(void* context, SceneManagerEvent ev
consumed = true;
}
} else if(event.type == SceneManagerEventTypeBack) {
scene_manager_search_and_switch_to_previous_scene(seader->scene_manager, SeaderSceneStart);
scene_manager_search_and_switch_to_previous_scene(
seader->scene_manager, SeaderSceneSamPresent);
consumed = true;
}
return consumed;
Expand Down
6 changes: 5 additions & 1 deletion non_catalog_apps/seader/scenes/seader_scene_save_name.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <gui/modules/validators.h>
#include <toolbox/path.h>

#define TAG "SeaderSceneSaveName"

void seader_scene_save_name_text_input_callback(void* context) {
Seader* seader = context;

Expand Down Expand Up @@ -52,7 +54,9 @@ bool seader_scene_save_name_on_event(void* context, SceneManagerEvent event) {

if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SeaderCustomEventTextInputDone) {
if(strcmp(seader->credential->name, "") != 0) {
if(seader->credential->save_format == SeaderCredentialSaveFormatAgnostic &&
strcmp(seader->credential->name, "") != 0) {
FURI_LOG_D(TAG, "Delete existing named credential [%s]", seader->credential->name);
seader_credential_delete(seader->credential, true);
}
strlcpy(seader->credential->name, seader->text_store, strlen(seader->text_store) + 1);
Expand Down
Loading

0 comments on commit ab51889

Please sign in to comment.