Skip to content

Commit

Permalink
upd uhf rfid
Browse files Browse the repository at this point in the history
  • Loading branch information
xMasterX committed Mar 20, 2024
1 parent f242900 commit 9461329
Show file tree
Hide file tree
Showing 13 changed files with 341 additions and 245 deletions.
6 changes: 3 additions & 3 deletions non_catalog_apps/uhf_rfid/application.fam
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
App(
appid="uhf_rfid",
name="[(Q)M100] UHF RFID",
name="[YRM100] UHF RFID",
apptype=FlipperAppType.EXTERNAL,
targets=["f7"],
entry_point="uhf_app_main",
requires=[
"storage",
"gui",
],
stack_size=8 * 1024,
stack_size=10 * 1024,
order=30,
fap_icon="icons/uhf_10px.png",
fap_category="RFID",
fap_category="GPIO",
fap_icon_assets="icons",
fap_icon_assets_symbol="uhf_rfid",
)
10 changes: 5 additions & 5 deletions non_catalog_apps/uhf_rfid/scenes/uhf_scene_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
#include "../uhf_module.h"

void uhf_settings_set_module_baudrate(VariableItem* item) {
M100Module* uhf_module = variable_item_get_context(item);
M100Module* module = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);
if(index >= BAUD_RATES_COUNT) {
return;
}
uint32_t baudrate = BAUD_RATES[index];
m100_set_baudrate(uhf_module, baudrate);
m100_set_baudrate(module, baudrate);
char text_buf[10];
snprintf(text_buf, sizeof(text_buf), "%lu", uhf_module->baudrate);
snprintf(text_buf, sizeof(text_buf), "%lu", module->uart->baudrate);
variable_item_set_current_value_text(item, text_buf);
}

Expand Down Expand Up @@ -40,7 +40,7 @@ void uhf_settings_set_module_working_region(VariableItem* item) {

uint8_t uhf_settings_get_module_baudrate_index(M100Module* module) {
for(uint8_t i = 0; i < BAUD_RATES_COUNT; i++) {
if(BAUD_RATES[i] == module->baudrate) {
if(BAUD_RATES[i] == module->uart->baudrate) {
return i;
}
}
Expand Down Expand Up @@ -73,7 +73,7 @@ void uhf_scene_settings_on_enter(void* ctx) {

uint8_t value_index = uhf_settings_get_module_baudrate_index(uhf_module);
char text_buf[10];
snprintf(text_buf, sizeof(text_buf), "%lu", uhf_module->baudrate);
snprintf(text_buf, sizeof(text_buf), "%lu", uhf_module->uart->baudrate);
item = variable_item_list_add(
variable_item_list,
"Baudrate:",
Expand Down
11 changes: 3 additions & 8 deletions non_catalog_apps/uhf_rfid/uhf_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,25 +201,20 @@ int32_t uhf_app_main(void* ctx) {
expansion_disable(expansion);

UHFApp* uhf_app = uhf_alloc();

// enable 5v pin
uint8_t attempts = 0;
uint8_t attempts = 0;
bool otg_was_enabled = furi_hal_power_is_otg_enabled();
while(!furi_hal_power_is_otg_enabled() && attempts++ < 5) {
furi_hal_power_enable_otg();
furi_delay_ms(10);
}
furi_delay_ms(200);
// init pin a2
// furi_hal_gpio_init_simple(&gpio_ext_pa7, GpioModeOutputPushPull);
// enter app
scene_manager_next_scene(uhf_app->scene_manager, UHFSceneModuleInfo);
view_dispatcher_run(uhf_app->view_dispatcher);

// disable 5v pin
if(furi_hal_power_is_otg_enabled() && !otg_was_enabled) {
if(furi_hal_power_is_otg_enabled() && !otg_was_enabled) {
furi_hal_power_disable_otg();
}
// furi_hal_gpio_disable_int_callback()
// exit app
uhf_free(uhf_app);

Expand Down
20 changes: 12 additions & 8 deletions non_catalog_apps/uhf_rfid/uhf_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <stdlib.h>
#include <string.h>

Buffer* buffer_alloc(size_t initial_capacity) {
Buffer* uhf_buffer_alloc(size_t initial_capacity) {
Buffer* buf = (Buffer*)malloc(sizeof(Buffer));
buf->data = (uint8_t*)malloc(sizeof(uint8_t) * initial_capacity);
if(!buf->data) {
Expand All @@ -14,7 +14,7 @@ Buffer* buffer_alloc(size_t initial_capacity) {
return buf;
}

bool buffer_append_single(Buffer* buf, uint8_t data) {
bool uhf_buffer_append_single(Buffer* buf, uint8_t data) {
if(buf->closed) return false;
if(buf->size + 1 > buf->capacity) {
size_t new_capacity = buf->capacity * 2;
Expand All @@ -27,7 +27,7 @@ bool buffer_append_single(Buffer* buf, uint8_t data) {
return true;
}

bool buffer_append(Buffer* buf, uint8_t* data, size_t data_size) {
bool uhf_buffer_append(Buffer* buf, uint8_t* data, size_t data_size) {
if(buf->closed) return false;
if(buf->size + data_size > buf->capacity) {
size_t new_capacity = buf->capacity * 2;
Expand All @@ -43,27 +43,31 @@ bool buffer_append(Buffer* buf, uint8_t* data, size_t data_size) {
return true;
}

uint8_t* buffer_get_data(Buffer* buf) {
uint8_t* uhf_buffer_get_data(Buffer* buf) {
return buf->data;
}

size_t buffer_get_size(Buffer* buf) {
size_t uhf_buffer_get_size(Buffer* buf) {
return buf->size;
}

void buffer_close(Buffer* buf) {
bool uhf_is_buffer_closed(Buffer* buf) {
return buf->closed;
}

void uhf_buffer_close(Buffer* buf) {
buf->closed = true;
}

void buffer_reset(Buffer* buf) {
void uhf_buffer_reset(Buffer* buf) {
for(size_t i = 0; i < MAX_BUFFER_SIZE; i++) {
buf->data[i] = 0;
}
buf->size = 0;
buf->closed = false;
}

void buffer_free(Buffer* buf) {
void uhf_buffer_free(Buffer* buf) {
free(buf->data);
free(buf);
}
18 changes: 10 additions & 8 deletions non_catalog_apps/uhf_rfid/uhf_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ typedef struct Buffer {
bool closed;
} Buffer;

Buffer* buffer_alloc(size_t inital_capacity);
bool buffer_append_single(Buffer* buf, uint8_t value);
bool buffer_append(Buffer* buf, uint8_t* data, size_t size);
uint8_t* buffer_get_data(Buffer* buf);
size_t buffer_get_size(Buffer* buf);
void buffer_close(Buffer* buf);
void buffer_reset(Buffer* buf);
void buffer_free(Buffer* buf);
Buffer* uhf_buffer_alloc(size_t inital_capacity);
bool uhf_buffer_append_single(Buffer* buf, uint8_t value);
bool uhf_buffer_append(Buffer* buf, uint8_t* data, size_t size);

uint8_t* uhf_buffer_get_data(Buffer* buf);
size_t uhf_buffer_get_size(Buffer* buf);
bool uhf_is_buffer_closed(Buffer* buf);
void uhf_buffer_close(Buffer* buf);
void uhf_buffer_reset(Buffer* buf);
void uhf_buffer_free(Buffer* buf);
103 changes: 1 addition & 102 deletions non_catalog_apps/uhf_rfid/uhf_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

static const char* uhf_file_header = "Flipper UHF RFID device";
static const uint32_t uhf_file_version = 1;
// static const uint8_t bank_data_start = 20;
// static const uint8_t bank_data_length = 16;

UHFDevice* uhf_device_alloc() {
UHFDevice* uhf_device = malloc(sizeof(UHFDevice));
Expand Down Expand Up @@ -178,15 +176,6 @@ static bool uhf_device_load_data(UHFDevice* dev, FuriString* path, bool show_dia
return parsed;
}

// void picopass_device_clear(UHFDevice* dev) {
// furi_assert(dev);

// picopass_device_data_clear(&dev->dev_data);
// memset(&dev->dev_data, 0, sizeof(dev->dev_data));
// dev->format = PicopassDeviceSaveFormatHF;
// furi_string_reset(dev->load_path);
// }

void uhf_device_free(UHFDevice* uhf_dev) {
furi_assert(uhf_dev);
furi_record_close(RECORD_STORAGE);
Expand Down Expand Up @@ -224,16 +213,6 @@ bool uhf_file_select(UHFDevice* dev) {
return res;
}

// void uhf_device_data_clear(UHFDevice* dev_data) {
// for(size_t i = 0; i < PICOPASS_MAX_APP_LIMIT; i++) {
// memset(dev_data->AA1[i].data, 0, sizeof(dev_data->AA1[i].data));
// }
// dev_data->pacs.legacy = false;
// dev_data->pacs.se_enabled = false;
// dev_data->pacs.elite_kdf = false;
// dev_data->pacs.pin_length = 0;
// }

bool uhf_device_delete(UHFDevice* dev, bool use_load_path) {
furi_assert(dev);

Expand Down Expand Up @@ -265,84 +244,4 @@ void uhf_device_set_loading_callback(UHFDevice* dev, UHFLoadingCallback callback

dev->loading_cb = callback;
dev->loading_cb_ctx = context;
}

// ReturnCode picopass_device_decrypt(uint8_t* enc_data, uint8_t* dec_data) {
// uint8_t key[32] = {0};
// memcpy(key, picopass_iclass_decryptionkey, sizeof(picopass_iclass_decryptionkey));
// mbedtls_des3_context ctx;
// mbedtls_des3_init(&ctx);
// mbedtls_des3_set2key_dec(&ctx, key);
// mbedtls_des3_crypt_ecb(&ctx, enc_data, dec_data);
// mbedtls_des3_free(&ctx);
// return ERR_NONE;
// }

// ReturnCode picopass_device_parse_credential(PicopassBlock* AA1, PicopassPacs* pacs) {
// ReturnCode err;

// pacs->biometrics = AA1[6].data[4];
// pacs->pin_length = AA1[6].data[6] & 0x0F;
// pacs->encryption = AA1[6].data[7];

// if(pacs->encryption == PicopassDeviceEncryption3DES) {
// FURI_LOG_D(TAG, "3DES Encrypted");
// err = picopass_device_decrypt(AA1[7].data, pacs->credential);
// if(err != ERR_NONE) {
// FURI_LOG_E(TAG, "decrypt error %d", err);
// return err;
// }

// err = picopass_device_decrypt(AA1[8].data, pacs->pin0);
// if(err != ERR_NONE) {
// FURI_LOG_E(TAG, "decrypt error %d", err);
// return err;
// }

// err = picopass_device_decrypt(AA1[9].data, pacs->pin1);
// if(err != ERR_NONE) {
// FURI_LOG_E(TAG, "decrypt error %d", err);
// return err;
// }
// } else if(pacs->encryption == PicopassDeviceEncryptionNone) {
// FURI_LOG_D(TAG, "No Encryption");
// memcpy(pacs->credential, AA1[7].data, PICOPASS_BLOCK_LEN);
// memcpy(pacs->pin0, AA1[8].data, PICOPASS_BLOCK_LEN);
// memcpy(pacs->pin1, AA1[9].data, PICOPASS_BLOCK_LEN);
// } else if(pacs->encryption == PicopassDeviceEncryptionDES) {
// FURI_LOG_D(TAG, "DES Encrypted");
// } else {
// FURI_LOG_D(TAG, "Unknown encryption");
// }

// pacs->sio = (AA1[10].data[0] == 0x30); // rough check

// return ERR_NONE;
// }

// ReturnCode picopass_device_parse_wiegand(uint8_t* data, PicopassWiegandRecord* record) {
// uint32_t* halves = (uint32_t*)data;
// if(halves[0] == 0) {
// uint8_t leading0s = __builtin_clz(REVERSE_BYTES_U32(halves[1]));
// record->bitLength = 31 - leading0s;
// } else {
// uint8_t leading0s = __builtin_clz(REVERSE_BYTES_U32(halves[0]));
// record->bitLength = 63 - leading0s;
// }
// FURI_LOG_D(TAG, "bitLength: %d", record->bitLength);

// if(record->bitLength == 26) {
// uint8_t* v4 = data + 4;
// uint32_t bot = v4[3] | (v4[2] << 8) | (v4[1] << 16) | (v4[0] << 24);

// record->CardNumber = (bot >> 1) & 0xFFFF;
// record->FacilityCode = (bot >> 17) & 0xFF;
// FURI_LOG_D(TAG, "FC: %u CN: %u", record->FacilityCode, record->CardNumber);
// record->valid = true;
// } else {
// record->CardNumber = 0;
// record->FacilityCode = 0;
// record->valid = false;
// }
// return ERR_NONE;
// }
}
Loading

0 comments on commit 9461329

Please sign in to comment.