diff --git a/applications/main/lfrfid/helpers/rfid_writer.c b/applications/main/lfrfid/helpers/rfid_writer.c deleted file mode 100644 index 7cc6326c4..000000000 --- a/applications/main/lfrfid/helpers/rfid_writer.c +++ /dev/null @@ -1,96 +0,0 @@ -#include "rfid_writer.h" -#include - -void writer_start() { - furi_hal_rfid_tim_read(125000, 0.5); - furi_hal_rfid_pins_read(); - furi_hal_rfid_tim_read_start(); - - // do not ground the antenna - furi_hal_rfid_pin_pull_release(); -} - -void writer_stop() { - furi_hal_rfid_tim_read_stop(); - furi_hal_rfid_tim_reset(); - furi_hal_rfid_pins_reset(); -} - -void write_gap(uint32_t gap_time) { - furi_hal_rfid_tim_read_stop(); - furi_delay_us(gap_time * 8); - furi_hal_rfid_tim_read_start(); -} - -void write_bit(T55xxTiming* t55xxtiming, bool value) { - if(value) { - furi_delay_us(t55xxtiming->data_1 * 8); - } else { - furi_delay_us(t55xxtiming->data_0 * 8); - } - write_gap(t55xxtiming->write_gap); -} - -void write_block( - T55xxTiming* t55xxtiming, - uint8_t page, - uint8_t block, - bool lock_bit, - uint32_t data, - bool password_enable, - uint32_t password) { - furi_delay_us(t55xxtiming->wait_time * 8); - - //client: https://github.com/Proxmark/proxmark3/blob/6116334485ca77343eda51c557cdc81032afcf38/client/cmdlft55xx.c#L944 - //hardware: https://github.com/Proxmark/proxmark3/blob/555fa197730c061bbf0ab01334e99bc47fb3dc06/armsrc/lfops.c#L1465 - //hardware: https://github.com/Proxmark/proxmark3/blob/555fa197730c061bbf0ab01334e99bc47fb3dc06/armsrc/lfops.c#L1396 - - // start gap - write_gap(t55xxtiming->start_gap); - - // opcode - switch(page) { - case 0: - write_bit(t55xxtiming, 1); - write_bit(t55xxtiming, 0); - break; - case 1: - write_bit(t55xxtiming, 1); - write_bit(t55xxtiming, 1); - break; - default: - furi_check(false); - break; - } - - // password - if(password_enable) { - for(uint8_t i = 0; i < 32; i++) { - write_bit(t55xxtiming, (password >> (31 - i)) & 1); - } - } - - // lock bit - write_bit(t55xxtiming, lock_bit); - - // data - for(uint8_t i = 0; i < 32; i++) { - write_bit(t55xxtiming, (data >> (31 - i)) & 1); - } - - // block address - write_bit(t55xxtiming, (block >> 2) & 1); - write_bit(t55xxtiming, (block >> 1) & 1); - write_bit(t55xxtiming, (block >> 0) & 1); - - furi_delay_us(t55xxtiming->program * 8); - - furi_delay_us(t55xxtiming->wait_time * 8); - write_reset(t55xxtiming); -} - -void write_reset(T55xxTiming* t55xxtiming) { - write_gap(t55xxtiming->start_gap); - write_bit(t55xxtiming, 1); - write_bit(t55xxtiming, 0); -} \ No newline at end of file diff --git a/applications/main/lfrfid/helpers/rfid_writer.h b/applications/main/lfrfid/helpers/rfid_writer.h deleted file mode 100644 index 2b97bd321..000000000 --- a/applications/main/lfrfid/helpers/rfid_writer.h +++ /dev/null @@ -1,26 +0,0 @@ -#include -#include - -typedef struct { - uint16_t wait_time; - uint8_t start_gap; - uint8_t write_gap; - uint8_t data_0; - uint8_t data_1; - uint16_t program; -} T55xxTiming; - -void writer_start(); -void writer_stop(); -void write_gap(uint32_t gap_time); -void write_bit(T55xxTiming* t55xxtiming, bool value); -void write_block( - T55xxTiming* t55xxtiming, - uint8_t page, - uint8_t block, - bool lock_bit, - uint32_t data, - bool password_enable, - uint32_t password); - -void write_reset(T55xxTiming* t55xxtiming); \ No newline at end of file diff --git a/applications/main/lfrfid/scenes/lfrfid_scene_clear_t5577.c b/applications/main/lfrfid/scenes/lfrfid_scene_clear_t5577.c index 3b9b41909..08636e036 100644 --- a/applications/main/lfrfid/scenes/lfrfid_scene_clear_t5577.c +++ b/applications/main/lfrfid/scenes/lfrfid_scene_clear_t5577.c @@ -1,17 +1,7 @@ #include "../lfrfid_i.h" -#include "../helpers/rfid_writer.h" - -static void writer_initialize(T55xxTiming* t55xxtiming) { - t55xxtiming->wait_time = 400; - t55xxtiming->start_gap = 30; - t55xxtiming->write_gap = 18; - t55xxtiming->data_0 = 24; - t55xxtiming->data_1 = 56; - t55xxtiming->program = 700; -} +#define TAG "Clear T5577" static void lfrfid_clear_t5577_password_and_config_to_EM(LfRfid* app) { - T55xxTiming* t55xxtiming = malloc(sizeof(T55xxTiming)); Popup* popup = app->popup; char curr_buf[32] = {}; //TODO: use .txt file in resources for passwords. @@ -35,30 +25,27 @@ static void lfrfid_clear_t5577_password_and_config_to_EM(LfRfid* app) { 0x07d7bb0b, 0x9636ef8f, 0xb5f44686, 0x9E3779B9, 0xC6EF3720, 0x7854794A, 0xF1EA5EED, 0x69314718, 0x57721566, 0x93C467E3, 0x27182818, 0x50415353}; const uint8_t default_passwords_len = sizeof(default_passwords) / sizeof(uint32_t); - const uint32_t em_config_block_data = - 0b00000000000101001000000001000000; //no pwd&aor config block - - writer_initialize(t55xxtiming); popup_set_header(popup, "Removing\npassword", 90, 36, AlignCenter, AlignCenter); popup_set_icon(popup, 0, 3, &I_RFIDDolphinSend_97x61); popup_set_text(popup, curr_buf, 90, 56, AlignCenter, AlignCenter); notification_message(app->notifications, &sequence_blink_start_magenta); + LFRFIDT5577 data = { + .block[0] = 0b00000000000101001000000001000000, + .blocks_to_write = 1, + }; + for(uint8_t i = 0; i < default_passwords_len; i++) { - FURI_CRITICAL_ENTER(); snprintf(curr_buf, sizeof(curr_buf), "Pass %d of %d", i, default_passwords_len); view_dispatcher_switch_to_view(app->view_dispatcher, LfRfidViewPopup); - writer_start(); - write_block(t55xxtiming, 0, 0, false, em_config_block_data, true, default_passwords[i]); - write_reset(t55xxtiming); - writer_stop(); - FURI_CRITICAL_EXIT(); + + t5577_write_with_pass(&data, default_passwords[i]); furi_delay_ms(8); } + notification_message(app->notifications, &sequence_blink_stop); popup_reset(app->popup); - free(t55xxtiming); } void lfrfid_scene_clear_t5577_on_enter(void* context) { diff --git a/firmware/targets/f7/api_symbols.csv b/firmware/targets/f7/api_symbols.csv index ae38d0c84..bc9ce6650 100644 --- a/firmware/targets/f7/api_symbols.csv +++ b/firmware/targets/f7/api_symbols.csv @@ -1,5 +1,5 @@ entry,status,name,type,params -Version,+,27.0,, +Version,+,27.1,, Header,+,applications/services/bt/bt_service/bt.h,, Header,+,applications/services/cli/cli.h,, Header,+,applications/services/cli/cli_vcp.h,, @@ -3367,6 +3367,7 @@ Function,+,submenu_set_header,void,"Submenu*, const char*" Function,+,submenu_set_selected_item,void,"Submenu*, uint32_t" Function,-,system,int,const char* Function,+,t5577_write,void,LFRFIDT5577* +Function,-,t5577_write_with_pass,void,"LFRFIDT5577*, uint32_t" Function,-,tan,double,double Function,-,tanf,float,float Function,-,tanh,double,double diff --git a/lib/lfrfid/tools/t5577.c b/lib/lfrfid/tools/t5577.c index 3444afea3..686c1aa6a 100644 --- a/lib/lfrfid/tools/t5577.c +++ b/lib/lfrfid/tools/t5577.c @@ -54,7 +54,12 @@ static void t5577_write_reset() { t5577_write_bit(0); } -static void t5577_write_block(uint8_t block, bool lock_bit, uint32_t data) { +static void t5577_write_block_pass( + uint8_t block, + bool lock_bit, + uint32_t data, + bool with_pass, + uint32_t password) { furi_delay_us(T5577_TIMING_WAIT_TIME * 8); // start gap @@ -63,6 +68,13 @@ static void t5577_write_block(uint8_t block, bool lock_bit, uint32_t data) { // opcode for page 0 t5577_write_opcode(T5577_OPCODE_PAGE_0); + // password + if(with_pass) { + for(uint8_t i = 0; i < 32; i++) { + t5577_write_bit((password >> (31 - i)) & 1); + } + } + // lock bit t5577_write_bit(lock_bit); @@ -82,11 +94,26 @@ static void t5577_write_block(uint8_t block, bool lock_bit, uint32_t data) { t5577_write_reset(); } +static void t5577_write_block_simple(uint8_t block, bool lock_bit, uint32_t data) { + t5577_write_block_pass(block, lock_bit, data, false, 0); +} + void t5577_write(LFRFIDT5577* data) { t5577_start(); FURI_CRITICAL_ENTER(); for(size_t i = 0; i < data->blocks_to_write; i++) { - t5577_write_block(i, false, data->block[i]); + t5577_write_block_simple(i, false, data->block[i]); + } + t5577_write_reset(); + FURI_CRITICAL_EXIT(); + t5577_stop(); +} + +void t5577_write_with_pass(LFRFIDT5577* data, uint32_t password) { + t5577_start(); + FURI_CRITICAL_ENTER(); + for(size_t i = 0; i < data->blocks_to_write; i++) { + t5577_write_block_pass(0, false, data->block[i], true, password); } t5577_write_reset(); FURI_CRITICAL_EXIT(); diff --git a/lib/lfrfid/tools/t5577.h b/lib/lfrfid/tools/t5577.h index 6d53b5dc7..c77984476 100644 --- a/lib/lfrfid/tools/t5577.h +++ b/lib/lfrfid/tools/t5577.h @@ -51,6 +51,8 @@ typedef struct { */ void t5577_write(LFRFIDT5577* data); +void t5577_write_with_pass(LFRFIDT5577* data, uint32_t password); + #ifdef __cplusplus } #endif \ No newline at end of file