mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-16 04:24:45 -07:00
Add magspoof
This commit is contained in:
480
applications/external/magspoof/helpers/mag_helpers.c
vendored
Normal file
480
applications/external/magspoof/helpers/mag_helpers.c
vendored
Normal file
@@ -0,0 +1,480 @@
|
||||
#include "mag_helpers.h"
|
||||
|
||||
#define TAG "MagHelpers"
|
||||
|
||||
// Haviv Board - pins gpio_ext_pa7 & gpio_ext_pa6 was swapped.
|
||||
#define GPIO_PIN_A &gpio_ext_pa7
|
||||
#define GPIO_PIN_B &gpio_ext_pa6
|
||||
#define GPIO_PIN_ENABLE &gpio_ext_pa4
|
||||
#define RFID_PIN_OUT &gpio_rfid_carrier_out
|
||||
|
||||
#define ZERO_PREFIX 25 // n zeros prefix
|
||||
#define ZERO_BETWEEN 53 // n zeros between tracks
|
||||
#define ZERO_SUFFIX 25 // n zeros suffix
|
||||
|
||||
// bits per char on a given track
|
||||
const uint8_t bitlen[] = {7, 5, 5};
|
||||
// char offset by track
|
||||
const int sublen[] = {32, 48, 48};
|
||||
|
||||
uint8_t last_value = 2;
|
||||
|
||||
void play_halfbit(bool value, MagSetting* setting) {
|
||||
switch(setting->tx) {
|
||||
case MagTxStateRFID:
|
||||
furi_hal_gpio_write(RFID_PIN_OUT, value);
|
||||
/*furi_hal_gpio_write(RFID_PIN_OUT, !value);
|
||||
furi_hal_gpio_write(RFID_PIN_OUT, value);
|
||||
furi_hal_gpio_write(RFID_PIN_OUT, !value);
|
||||
furi_hal_gpio_write(RFID_PIN_OUT, value);*/
|
||||
break;
|
||||
case MagTxStateGPIO:
|
||||
furi_hal_gpio_write(GPIO_PIN_A, value);
|
||||
furi_hal_gpio_write(GPIO_PIN_B, !value);
|
||||
break;
|
||||
case MagTxStatePiezo:
|
||||
furi_hal_gpio_write(&gpio_speaker, value);
|
||||
/*furi_hal_gpio_write(&gpio_speaker, !value);
|
||||
furi_hal_gpio_write(&gpio_speaker, value);
|
||||
furi_hal_gpio_write(&gpio_speaker, !value);
|
||||
furi_hal_gpio_write(&gpio_speaker, value);*/
|
||||
|
||||
break;
|
||||
case MagTxStateLF_P:
|
||||
furi_hal_gpio_write(RFID_PIN_OUT, value);
|
||||
furi_hal_gpio_write(&gpio_speaker, value);
|
||||
|
||||
/* // Weaker but cleaner signal
|
||||
if(value) {
|
||||
furi_hal_gpio_write(RFID_PIN_OUT, value);
|
||||
furi_hal_gpio_write(&gpio_speaker, value);
|
||||
furi_delay_us(10);
|
||||
furi_hal_gpio_write(RFID_PIN_OUT, !value);
|
||||
furi_hal_gpio_write(&gpio_speaker, !value);
|
||||
} else {
|
||||
furi_delay_us(10);
|
||||
}*/
|
||||
|
||||
/*furi_hal_gpio_write(RFID_PIN_OUT, value);
|
||||
furi_hal_gpio_write(&gpio_speaker, value);
|
||||
furi_hal_gpio_write(RFID_PIN_OUT, !value);
|
||||
furi_hal_gpio_write(&gpio_speaker, !value);
|
||||
furi_hal_gpio_write(RFID_PIN_OUT, value);
|
||||
furi_hal_gpio_write(&gpio_speaker, value);*/
|
||||
break;
|
||||
case MagTxStateNFC:
|
||||
// turn on for duration of half-bit? or "blip" the field on / off?
|
||||
// getting nothing from the mag reader either way
|
||||
//(value) ? furi_hal_nfc_ll_txrx_on() : furi_hal_nfc_ll_txrx_off();
|
||||
|
||||
if(last_value == 2 || value != (bool)last_value) {
|
||||
furi_hal_nfc_ll_txrx_on();
|
||||
//furi_delay_us(64);
|
||||
furi_hal_nfc_ll_txrx_off();
|
||||
}
|
||||
break;
|
||||
case MagTxCC1101_434:
|
||||
case MagTxCC1101_868:
|
||||
if(last_value == 2 || value != (bool)last_value) {
|
||||
furi_hal_gpio_write(&gpio_cc1101_g0, true);
|
||||
furi_delay_us(64);
|
||||
furi_hal_gpio_write(&gpio_cc1101_g0, false);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
last_value = value;
|
||||
}
|
||||
|
||||
void play_track(uint8_t* bits_manchester, uint16_t n_bits, MagSetting* setting, bool reverse) {
|
||||
for(uint16_t i = 0; i < n_bits; i++) {
|
||||
uint16_t j = (reverse) ? (n_bits - i - 1) : i;
|
||||
uint8_t byte = j / 8;
|
||||
uint8_t bitmask = 1 << (7 - (j % 8));
|
||||
/* Bits are stored in their arrays like on a card (LSB first). This is not how usually bits are stored in a
|
||||
* byte, with the MSB first. the var bitmask creates the pattern to iterate through each bit, LSB first, like so
|
||||
* 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01, 0x80... masking bits one by one from the current byte
|
||||
*
|
||||
* I've chosen this LSB approach since bits and bytes are hard enough to visualize with the 5/8 and 7/8 encoding
|
||||
* MSR uses. It's a biiit more complicated to process, but visualizing it with printf or a debugger is
|
||||
* infinitely easier
|
||||
*
|
||||
* Encoding the following pairs of 5 bits as 5/8: A1234 B1234 C1234 D1234
|
||||
* using this LSB format looks like: A1234B12 34C1234D 12340000
|
||||
* using the MSB format, looks like: 21B4321A D4321C43 00004321
|
||||
* this means reading each byte backwards when printing/debugging, and the jumping 16 bits ahead, reading 8 more
|
||||
* bits backward, jumping 16 more bits ahead.
|
||||
*
|
||||
* I find this much more convenient for debugging, with the tiny incovenience of reading the bits in reverse
|
||||
* order. Thus, the reason for the bitmask above
|
||||
*/
|
||||
|
||||
bool bit = !!(bits_manchester[byte] & bitmask);
|
||||
|
||||
// TODO: reimplement timing delays. Replace fixed furi_hal_cortex_delay_us to wait instead to a specific value
|
||||
// for DWT->CYCCNT. Note timer is aliased to 64us as per
|
||||
// #define FURI_HAL_CORTEX_INSTRUCTIONS_PER_MICROSECOND (SystemCoreClock / 1000000) | furi_hal_cortex.c
|
||||
|
||||
play_halfbit(bit, setting);
|
||||
furi_delay_us(setting->us_clock);
|
||||
// if (i % 2 == 1) furi_delay_us(setting->us_interpacket);
|
||||
}
|
||||
}
|
||||
|
||||
void tx_init_rfid() {
|
||||
// initialize RFID system for TX
|
||||
|
||||
// OTG needed for RFID? Or just legacy from GPIO?
|
||||
// furi_hal_power_enable_otg();
|
||||
furi_hal_ibutton_pin_configure();
|
||||
|
||||
// furi_hal_ibutton_start_drive();
|
||||
furi_hal_ibutton_pin_write(false);
|
||||
|
||||
// Initializing at GpioSpeedLow seems sufficient for our needs; no improvements seen by increasing speed setting
|
||||
|
||||
// this doesn't seem to make a difference, leaving it in
|
||||
furi_hal_gpio_init(&gpio_rfid_data_in, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
|
||||
furi_hal_gpio_write(&gpio_rfid_data_in, false);
|
||||
|
||||
// false->ground RFID antenna; true->don't ground
|
||||
// skotopes (RFID dev) say normally you'd want RFID_PULL in high for signal forming, while modulating RFID_OUT
|
||||
// dunaevai135 had it low in their old code. Leaving low, as it doesn't seem to make a difference on my janky antenna
|
||||
furi_hal_gpio_init(&gpio_nfc_irq_rfid_pull, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
|
||||
furi_hal_gpio_write(&gpio_nfc_irq_rfid_pull, false);
|
||||
|
||||
furi_hal_gpio_init(RFID_PIN_OUT, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
|
||||
|
||||
furi_delay_ms(300);
|
||||
}
|
||||
|
||||
void tx_deinit_rfid() {
|
||||
// reset RFID system
|
||||
furi_hal_gpio_write(RFID_PIN_OUT, 0);
|
||||
|
||||
furi_hal_rfid_pins_reset();
|
||||
furi_hal_power_disable_otg();
|
||||
}
|
||||
|
||||
void tx_init_rf(int hz) {
|
||||
// presets and frequency will need some experimenting
|
||||
furi_hal_subghz_reset();
|
||||
// furi_hal_subghz_load_preset(FuriHalSubGhzPresetOok650Async);
|
||||
// furi_hal_subghz_load_preset(FuriHalSubGhzPresetGFSK9_99KbAsync);
|
||||
// furi_hal_subghz_load_preset(FuriHalSubGhzPresetMSK99_97KbAsync);
|
||||
// furi_hal_subghz_load_preset(FuriHalSubGhzPreset2FSKDev238Async);
|
||||
// furi_hal_subghz_load_preset(FuriHalSubGhzPreset2FSKDev476Async);
|
||||
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
|
||||
furi_hal_subghz_set_frequency_and_path(hz);
|
||||
furi_hal_subghz_tx();
|
||||
furi_hal_gpio_write(&gpio_cc1101_g0, false);
|
||||
}
|
||||
|
||||
void tx_init_piezo() {
|
||||
// TODO: some special mutex acquire procedure? c.f. furi_hal_speaker.c
|
||||
furi_hal_gpio_init(&gpio_speaker, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
|
||||
}
|
||||
|
||||
void tx_deinit_piezo() {
|
||||
// TODO: some special mutex release procedure?
|
||||
furi_hal_gpio_init(&gpio_speaker, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
|
||||
}
|
||||
|
||||
bool tx_init(MagSetting* setting) {
|
||||
// Initialize configured TX method
|
||||
switch(setting->tx) {
|
||||
case MagTxStateRFID:
|
||||
tx_init_rfid();
|
||||
break;
|
||||
case MagTxStateGPIO:
|
||||
furi_hal_power_enable_otg();
|
||||
// gpio_item_configure_all_pins(GpioModeOutputPushPull);
|
||||
furi_hal_gpio_init(GPIO_PIN_A, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
|
||||
furi_hal_gpio_init(GPIO_PIN_B, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
|
||||
furi_hal_gpio_init(GPIO_PIN_ENABLE, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
|
||||
|
||||
furi_hal_gpio_write(GPIO_PIN_ENABLE, 1);
|
||||
|
||||
// had some issues with ~300; bumped higher temporarily
|
||||
furi_delay_ms(500);
|
||||
break;
|
||||
case MagTxStatePiezo:
|
||||
tx_init_piezo();
|
||||
break;
|
||||
case MagTxStateLF_P:
|
||||
tx_init_piezo();
|
||||
tx_init_rfid();
|
||||
break;
|
||||
case MagTxStateNFC:
|
||||
furi_hal_nfc_exit_sleep();
|
||||
break;
|
||||
case MagTxCC1101_434:
|
||||
tx_init_rf(434000000);
|
||||
break;
|
||||
case MagTxCC1101_868:
|
||||
tx_init_rf(868000000);
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool tx_deinit(MagSetting* setting) {
|
||||
// Reset configured TX method
|
||||
switch(setting->tx) {
|
||||
case MagTxStateRFID:
|
||||
tx_deinit_rfid();
|
||||
break;
|
||||
case MagTxStateGPIO:
|
||||
furi_hal_gpio_write(GPIO_PIN_A, 0);
|
||||
furi_hal_gpio_write(GPIO_PIN_B, 0);
|
||||
furi_hal_gpio_write(GPIO_PIN_ENABLE, 0);
|
||||
|
||||
// set back to analog output mode?
|
||||
//gpio_item_configure_all_pins(GpioModeAnalog);
|
||||
furi_hal_power_disable_otg();
|
||||
break;
|
||||
case MagTxStatePiezo:
|
||||
tx_deinit_piezo();
|
||||
break;
|
||||
case MagTxStateLF_P:
|
||||
tx_deinit_piezo();
|
||||
tx_deinit_rfid();
|
||||
break;
|
||||
case MagTxStateNFC:
|
||||
furi_hal_nfc_ll_txrx_off();
|
||||
furi_hal_nfc_start_sleep();
|
||||
break;
|
||||
case MagTxCC1101_434:
|
||||
case MagTxCC1101_868:
|
||||
furi_hal_gpio_write(&gpio_cc1101_g0, false);
|
||||
furi_hal_subghz_reset();
|
||||
furi_hal_subghz_idle();
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void mag_spoof(Mag* mag) {
|
||||
MagSetting* setting = mag->setting;
|
||||
|
||||
// TODO: cleanup this section. Possibly move precompute + tx_init to emulate_on_enter?
|
||||
FuriString* ft1 = mag->mag_dev->dev_data.track[0].str;
|
||||
FuriString* ft2 = mag->mag_dev->dev_data.track[1].str;
|
||||
FuriString* ft3 = mag->mag_dev->dev_data.track[2].str;
|
||||
|
||||
char *data1, *data2, *data3;
|
||||
data1 = malloc(furi_string_size(ft1) + 1);
|
||||
data2 = malloc(furi_string_size(ft2) + 1);
|
||||
data3 = malloc(furi_string_size(ft3) + 1);
|
||||
strncpy(data1, furi_string_get_cstr(ft1), furi_string_size(ft1));
|
||||
strncpy(data2, furi_string_get_cstr(ft2), furi_string_size(ft2));
|
||||
strncpy(data3, furi_string_get_cstr(ft3), furi_string_size(ft3));
|
||||
|
||||
if(furi_log_get_level() >= FuriLogLevelDebug) {
|
||||
debug_mag_string(data1, bitlen[0], sublen[0]);
|
||||
debug_mag_string(data2, bitlen[1], sublen[1]);
|
||||
debug_mag_string(data3, bitlen[2], sublen[2]);
|
||||
}
|
||||
|
||||
uint8_t bits_t1_raw[64] = {0x00}; // 68 chars max track 1 + 1 char crc * 7 approx =~ 483 bits
|
||||
uint8_t bits_t1_manchester[128] = {0x00}; // twice the above
|
||||
uint16_t bits_t1_count = mag_encode(
|
||||
data1, (uint8_t*)bits_t1_manchester, (uint8_t*)bits_t1_raw, bitlen[0], sublen[0]);
|
||||
uint8_t bits_t2_raw[64] = {0x00}; // 68 chars max track 1 + 1 char crc * 7 approx =~ 483 bits
|
||||
uint8_t bits_t2_manchester[128] = {0x00}; // twice the above
|
||||
uint16_t bits_t2_count = mag_encode(
|
||||
data2, (uint8_t*)bits_t2_manchester, (uint8_t*)bits_t2_raw, bitlen[1], sublen[1]);
|
||||
uint8_t bits_t3_raw[64] = {0x00};
|
||||
uint8_t bits_t3_manchester[128] = {0x00};
|
||||
uint16_t bits_t3_count = mag_encode(
|
||||
data3, (uint8_t*)bits_t3_manchester, (uint8_t*)bits_t3_raw, bitlen[2], sublen[2]);
|
||||
|
||||
if(furi_log_get_level() >= FuriLogLevelDebug) {
|
||||
printf(
|
||||
"Manchester bitcount: T1: %d, T2: %d, T3: %d\r\n",
|
||||
bits_t1_count,
|
||||
bits_t2_count,
|
||||
bits_t3_count);
|
||||
printf("T1 raw: ");
|
||||
for(int i = 0; i < bits_t1_count / 16; i++) printf("%02x ", bits_t1_raw[i]);
|
||||
printf("\r\nT1 manchester: ");
|
||||
for(int i = 0; i < bits_t1_count / 8; i++) printf("%02x ", bits_t1_manchester[i]);
|
||||
printf("\r\nT2 raw: ");
|
||||
for(int i = 0; i < bits_t2_count / 16; i++) printf("%02x ", bits_t2_raw[i]);
|
||||
printf("\r\nT2 manchester: ");
|
||||
for(int i = 0; i < bits_t2_count / 8; i++) printf("%02x ", bits_t2_manchester[i]);
|
||||
printf("\r\nT3 raw: ");
|
||||
for(int i = 0; i < bits_t3_count / 16; i++) printf("%02x ", bits_t3_raw[i]);
|
||||
printf("\r\nT3 manchester: ");
|
||||
for(int i = 0; i < bits_t3_count / 8; i++) printf("%02x ", bits_t3_manchester[i]);
|
||||
printf("\r\nBitwise emulation done\r\n\r\n");
|
||||
}
|
||||
|
||||
last_value = 2;
|
||||
bool bit = false;
|
||||
|
||||
if(!tx_init(setting)) return;
|
||||
|
||||
FURI_CRITICAL_ENTER();
|
||||
for(uint16_t i = 0; i < (ZERO_PREFIX * 2); i++) {
|
||||
// is this right?
|
||||
if(!!(i % 2)) bit ^= 1;
|
||||
play_halfbit(bit, setting);
|
||||
furi_delay_us(setting->us_clock);
|
||||
}
|
||||
|
||||
if((setting->track == MagTrackStateOneAndTwo) || (setting->track == MagTrackStateOne))
|
||||
play_track((uint8_t*)bits_t1_manchester, bits_t1_count, setting, false);
|
||||
|
||||
if((setting->track == MagTrackStateOneAndTwo))
|
||||
for(uint16_t i = 0; i < (ZERO_BETWEEN * 2); i++) {
|
||||
if(!!(i % 2)) bit ^= 1;
|
||||
play_halfbit(bit, setting);
|
||||
furi_delay_us(setting->us_clock);
|
||||
}
|
||||
|
||||
if((setting->track == MagTrackStateOneAndTwo) || (setting->track == MagTrackStateTwo))
|
||||
play_track(
|
||||
(uint8_t*)bits_t2_manchester,
|
||||
bits_t2_count,
|
||||
setting,
|
||||
(setting->reverse == MagReverseStateOn));
|
||||
|
||||
if((setting->track == MagTrackStateThree))
|
||||
play_track((uint8_t*)bits_t3_manchester, bits_t3_count, setting, false);
|
||||
|
||||
for(uint16_t i = 0; i < (ZERO_SUFFIX * 2); i++) {
|
||||
if(!!(i % 2)) bit ^= 1;
|
||||
play_halfbit(bit, setting);
|
||||
furi_delay_us(setting->us_clock);
|
||||
}
|
||||
FURI_CRITICAL_EXIT();
|
||||
|
||||
free(data1);
|
||||
free(data2);
|
||||
free(data3);
|
||||
tx_deinit(setting);
|
||||
}
|
||||
|
||||
uint16_t add_bit(bool value, uint8_t* out, uint16_t count) {
|
||||
uint8_t bit = count % 8;
|
||||
uint8_t byte = count / 8;
|
||||
if(value) {
|
||||
out[byte] |= 0x01;
|
||||
}
|
||||
if(bit < 7) out[byte] <<= 1;
|
||||
return count + 1;
|
||||
}
|
||||
|
||||
uint16_t add_bit_manchester(bool value, uint8_t* out, uint16_t count) {
|
||||
static bool toggle = 0;
|
||||
toggle ^= 0x01;
|
||||
count = add_bit(toggle, out, count);
|
||||
if(value) toggle ^= 0x01;
|
||||
count = add_bit(toggle, out, count);
|
||||
return count;
|
||||
}
|
||||
|
||||
uint16_t mag_encode(
|
||||
char* data,
|
||||
uint8_t* out_manchester,
|
||||
uint8_t* out_raw,
|
||||
uint8_t track_bits,
|
||||
uint8_t track_ascii_offset) {
|
||||
/*
|
||||
* track_bits - the number of raw (data) bits on the track. on ISO cards, that's 7 for track 1, or 5 for 2/3 - this is samy's bitlen
|
||||
* - this count includes the parity bit
|
||||
* track_ascii_offset - how much the ascii values are offset. track 1 makes space (ascii 32) become data 0x00,
|
||||
* - tracks 2/3 make ascii "0" become data 0x00 - this is samy's sublen
|
||||
*
|
||||
*/
|
||||
|
||||
uint16_t raw_bits_count = 0;
|
||||
uint16_t output_count = 0;
|
||||
int tmp, crc, lrc = 0;
|
||||
|
||||
/* // why are we adding zeros to the encoded string if we're also doing it while playing?
|
||||
for(int i = 0; i < ZERO_PREFIX; i++) {
|
||||
output_count = add_bit_manchester(0, out_manchester, output_count);
|
||||
raw_bits_count = add_bit(0, out_raw, raw_bits_count);
|
||||
}*/
|
||||
|
||||
for(int i = 0; *(data + i) != 0; i++) {
|
||||
crc = 1;
|
||||
tmp = *(data + i) - track_ascii_offset;
|
||||
|
||||
for(int j = 0; j < track_bits - 1; j++) {
|
||||
crc ^= tmp & 1;
|
||||
lrc ^= (tmp & 1) << j;
|
||||
raw_bits_count = add_bit(tmp & 0x01, out_raw, raw_bits_count);
|
||||
output_count = add_bit_manchester(tmp & 0x01, out_manchester, output_count);
|
||||
tmp >>= 1;
|
||||
}
|
||||
raw_bits_count = add_bit(crc, out_raw, raw_bits_count);
|
||||
output_count = add_bit_manchester(crc, out_manchester, output_count);
|
||||
}
|
||||
|
||||
// LRC byte
|
||||
tmp = lrc;
|
||||
crc = 1;
|
||||
for(int j = 0; j < track_bits - 1; j++) {
|
||||
crc ^= tmp & 0x01;
|
||||
raw_bits_count = add_bit(tmp & 0x01, out_raw, raw_bits_count);
|
||||
output_count = add_bit_manchester(tmp & 0x01, out_manchester, output_count);
|
||||
tmp >>= 1;
|
||||
}
|
||||
raw_bits_count = add_bit(crc, out_raw, raw_bits_count);
|
||||
output_count = add_bit_manchester(crc, out_manchester, output_count);
|
||||
|
||||
return output_count;
|
||||
}
|
||||
|
||||
void debug_mag_string(char* data, uint8_t track_bits, uint8_t track_ascii_offset) {
|
||||
uint8_t bits_raw[64] = {0}; // 68 chars max track 1 + 1 char crc * 7 approx =~ 483 bits
|
||||
uint8_t bits_manchester[128] = {0}; // twice the above
|
||||
int numbits = 0;
|
||||
|
||||
printf("Encoding [%s] with %d bits\r\n", data, track_bits);
|
||||
numbits = mag_encode(
|
||||
data, (uint8_t*)bits_manchester, (uint8_t*)bits_raw, track_bits, track_ascii_offset);
|
||||
printf("Got %d bits\r\n", numbits);
|
||||
printf("Raw byte stream: ");
|
||||
for(int i = 0; i < numbits / 8 / 2; i++) {
|
||||
printf("%02x", bits_raw[i]);
|
||||
if(i % 4 == 3) printf(" ");
|
||||
}
|
||||
|
||||
printf("\r\n");
|
||||
|
||||
printf("Bits ");
|
||||
int space_counter = 0;
|
||||
for(int i = 0; i < numbits / 2; i++) {
|
||||
/*if(i < ZERO_PREFIX) {
|
||||
printf("X");
|
||||
continue;
|
||||
} else if(i == ZERO_PREFIX) {
|
||||
printf(" ");
|
||||
space_counter = 0;
|
||||
}*/
|
||||
printf("%01x", (bits_raw[i / 8] & (1 << (7 - (i % 8)))) != 0);
|
||||
if((space_counter) % track_bits == track_bits - 1) printf(" ");
|
||||
space_counter++;
|
||||
}
|
||||
|
||||
printf("\r\n");
|
||||
|
||||
printf("Manchester encoded, byte stream: ");
|
||||
for(int i = 0; i < numbits / 8; i++) {
|
||||
printf("%02x", bits_manchester[i]);
|
||||
if(i % 4 == 3) printf(" ");
|
||||
}
|
||||
printf("\r\n\r\n");
|
||||
}
|
||||
25
applications/external/magspoof/helpers/mag_helpers.h
vendored
Normal file
25
applications/external/magspoof/helpers/mag_helpers.h
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
#include "../mag_i.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
void play_halfbit(bool value, MagSetting* setting);
|
||||
void play_track(uint8_t* bits_manchester, uint16_t n_bits, MagSetting* setting, bool reverse);
|
||||
|
||||
void tx_init_rf(int hz);
|
||||
void tx_init_rfid();
|
||||
void tx_init_piezo();
|
||||
bool tx_init(MagSetting* setting);
|
||||
void tx_deinit_piezo();
|
||||
void tx_deinit_rfid();
|
||||
bool tx_deinit(MagSetting* setting);
|
||||
|
||||
uint16_t add_bit(bool value, uint8_t* out, uint16_t count);
|
||||
uint16_t add_bit_manchester(bool value, uint8_t* out, uint16_t count);
|
||||
uint16_t mag_encode(
|
||||
char* data,
|
||||
uint8_t* out_manchester,
|
||||
uint8_t* out_raw,
|
||||
uint8_t track_bits,
|
||||
uint8_t track_ascii_offset);
|
||||
void debug_mag_string(char* data, uint8_t track_bits, uint8_t track_ascii_offset);
|
||||
void mag_spoof(Mag* mag);
|
||||
583
applications/external/magspoof/helpers/mag_text_input.c
vendored
Normal file
583
applications/external/magspoof/helpers/mag_text_input.c
vendored
Normal file
@@ -0,0 +1,583 @@
|
||||
#include "mag_text_input.h"
|
||||
#include <gui/elements.h>
|
||||
#include <assets_icons.h>
|
||||
#include <furi.h>
|
||||
|
||||
struct Mag_TextInput {
|
||||
View* view;
|
||||
FuriTimer* timer;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
const char text;
|
||||
const uint8_t x;
|
||||
const uint8_t y;
|
||||
} Mag_TextInputKey;
|
||||
|
||||
typedef struct {
|
||||
const char* header;
|
||||
char* text_buffer;
|
||||
size_t text_buffer_size;
|
||||
bool clear_default_text;
|
||||
|
||||
Mag_TextInputCallback callback;
|
||||
void* callback_context;
|
||||
|
||||
uint8_t selected_row;
|
||||
uint8_t selected_column;
|
||||
|
||||
// Mag_TextInputValidatorCallback validator_callback;
|
||||
// void* validator_callback_context;
|
||||
// FuriString* validator_text;
|
||||
// bool validator_message_visible;
|
||||
} Mag_TextInputModel;
|
||||
|
||||
static const uint8_t keyboard_origin_x = 1;
|
||||
static const uint8_t keyboard_origin_y = 29;
|
||||
static const uint8_t keyboard_row_count = 3;
|
||||
|
||||
#define ENTER_KEY '\r'
|
||||
#define BACKSPACE_KEY '\b'
|
||||
|
||||
static const Mag_TextInputKey keyboard_keys_row_1[] = {
|
||||
{'q', 1, 8},
|
||||
{'w', 9, 8},
|
||||
{'e', 17, 8},
|
||||
{'r', 25, 8},
|
||||
{'t', 33, 8},
|
||||
{'y', 41, 8},
|
||||
{'u', 49, 8},
|
||||
{'i', 57, 8},
|
||||
{'o', 65, 8},
|
||||
{'p', 73, 8},
|
||||
{'0', 81, 8},
|
||||
{'1', 89, 8},
|
||||
{'2', 97, 8},
|
||||
{'3', 105, 8},
|
||||
{'%', 113, 8},
|
||||
{'^', 120, 8},
|
||||
};
|
||||
|
||||
static const Mag_TextInputKey keyboard_keys_row_2[] = {
|
||||
{'a', 1, 20},
|
||||
{'s', 9, 20},
|
||||
{'d', 18, 20},
|
||||
{'f', 25, 20},
|
||||
{'g', 33, 20},
|
||||
{'h', 41, 20},
|
||||
{'j', 49, 20},
|
||||
{'k', 57, 20},
|
||||
{'l', 65, 20},
|
||||
{BACKSPACE_KEY, 72, 12},
|
||||
{'4', 89, 20},
|
||||
{'5', 97, 20},
|
||||
{'6', 105, 20},
|
||||
{'/', 113, 20},
|
||||
{'?', 120, 20},
|
||||
|
||||
};
|
||||
|
||||
static const Mag_TextInputKey keyboard_keys_row_3[] = {
|
||||
{'z', 1, 32},
|
||||
{'x', 9, 32},
|
||||
{'c', 18, 32},
|
||||
{'v', 25, 32},
|
||||
{'b', 33, 32},
|
||||
{'n', 41, 32},
|
||||
{'m', 49, 32},
|
||||
{'_', 57, 32},
|
||||
{ENTER_KEY, 64, 23},
|
||||
{'7', 89, 32},
|
||||
{'8', 97, 32},
|
||||
{'9', 105, 32},
|
||||
{';', 113, 32},
|
||||
{'=', 120, 32},
|
||||
};
|
||||
|
||||
static uint8_t get_row_size(uint8_t row_index) {
|
||||
uint8_t row_size = 0;
|
||||
|
||||
switch(row_index + 1) {
|
||||
case 1:
|
||||
row_size = sizeof(keyboard_keys_row_1) / sizeof(Mag_TextInputKey);
|
||||
break;
|
||||
case 2:
|
||||
row_size = sizeof(keyboard_keys_row_2) / sizeof(Mag_TextInputKey);
|
||||
break;
|
||||
case 3:
|
||||
row_size = sizeof(keyboard_keys_row_3) / sizeof(Mag_TextInputKey);
|
||||
break;
|
||||
}
|
||||
|
||||
return row_size;
|
||||
}
|
||||
|
||||
static const Mag_TextInputKey* get_row(uint8_t row_index) {
|
||||
const Mag_TextInputKey* row = NULL;
|
||||
|
||||
switch(row_index + 1) {
|
||||
case 1:
|
||||
row = keyboard_keys_row_1;
|
||||
break;
|
||||
case 2:
|
||||
row = keyboard_keys_row_2;
|
||||
break;
|
||||
case 3:
|
||||
row = keyboard_keys_row_3;
|
||||
break;
|
||||
}
|
||||
|
||||
return row;
|
||||
}
|
||||
|
||||
static char get_selected_char(Mag_TextInputModel* model) {
|
||||
return get_row(model->selected_row)[model->selected_column].text;
|
||||
}
|
||||
|
||||
static bool char_is_lowercase(char letter) {
|
||||
return (letter >= 0x61 && letter <= 0x7A);
|
||||
}
|
||||
|
||||
static char char_to_uppercase(const char letter) {
|
||||
if(letter == '_') {
|
||||
return 0x20;
|
||||
} else if(isalpha(letter)) {
|
||||
return (letter - 0x20);
|
||||
} else {
|
||||
return letter;
|
||||
}
|
||||
}
|
||||
|
||||
static void mag_text_input_backspace_cb(Mag_TextInputModel* model) {
|
||||
uint8_t text_length = model->clear_default_text ? 1 : strlen(model->text_buffer);
|
||||
if(text_length > 0) {
|
||||
model->text_buffer[text_length - 1] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void mag_text_input_view_draw_callback(Canvas* canvas, void* _model) {
|
||||
Mag_TextInputModel* model = _model;
|
||||
// uint8_t text_length = model->text_buffer ? strlen(model->text_buffer) : 0;
|
||||
uint8_t needed_string_width = canvas_width(canvas) - 8;
|
||||
uint8_t start_pos = 4;
|
||||
|
||||
const char* text = model->text_buffer;
|
||||
|
||||
canvas_clear(canvas);
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
|
||||
canvas_draw_str(canvas, 2, 8, model->header);
|
||||
elements_slightly_rounded_frame(canvas, 1, 12, 126, 15);
|
||||
|
||||
if(canvas_string_width(canvas, text) > needed_string_width) {
|
||||
canvas_draw_str(canvas, start_pos, 22, "...");
|
||||
start_pos += 6;
|
||||
needed_string_width -= 8;
|
||||
}
|
||||
|
||||
while(text != 0 && canvas_string_width(canvas, text) > needed_string_width) {
|
||||
text++;
|
||||
}
|
||||
|
||||
if(model->clear_default_text) {
|
||||
elements_slightly_rounded_box(
|
||||
canvas, start_pos - 1, 14, canvas_string_width(canvas, text) + 2, 10);
|
||||
canvas_set_color(canvas, ColorWhite);
|
||||
} else {
|
||||
canvas_draw_str(canvas, start_pos + canvas_string_width(canvas, text) + 1, 22, "|");
|
||||
canvas_draw_str(canvas, start_pos + canvas_string_width(canvas, text) + 2, 22, "|");
|
||||
}
|
||||
canvas_draw_str(canvas, start_pos, 22, text);
|
||||
|
||||
canvas_set_font(canvas, FontKeyboard);
|
||||
|
||||
for(uint8_t row = 0; row <= keyboard_row_count; row++) {
|
||||
const uint8_t column_count = get_row_size(row);
|
||||
const Mag_TextInputKey* keys = get_row(row);
|
||||
|
||||
for(size_t column = 0; column < column_count; column++) {
|
||||
if(keys[column].text == ENTER_KEY) {
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
if(model->selected_row == row && model->selected_column == column) {
|
||||
canvas_draw_icon(
|
||||
canvas,
|
||||
keyboard_origin_x + keys[column].x,
|
||||
keyboard_origin_y + keys[column].y,
|
||||
&I_KeySaveSelected_24x11);
|
||||
} else {
|
||||
canvas_draw_icon(
|
||||
canvas,
|
||||
keyboard_origin_x + keys[column].x,
|
||||
keyboard_origin_y + keys[column].y,
|
||||
&I_KeySave_24x11);
|
||||
}
|
||||
} else if(keys[column].text == BACKSPACE_KEY) {
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
if(model->selected_row == row && model->selected_column == column) {
|
||||
canvas_draw_icon(
|
||||
canvas,
|
||||
keyboard_origin_x + keys[column].x,
|
||||
keyboard_origin_y + keys[column].y,
|
||||
&I_KeyBackspaceSelected_16x9);
|
||||
} else {
|
||||
canvas_draw_icon(
|
||||
canvas,
|
||||
keyboard_origin_x + keys[column].x,
|
||||
keyboard_origin_y + keys[column].y,
|
||||
&I_KeyBackspace_16x9);
|
||||
}
|
||||
} else {
|
||||
if(model->selected_row == row && model->selected_column == column) {
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
canvas_draw_box(
|
||||
canvas,
|
||||
keyboard_origin_x + keys[column].x - 1,
|
||||
keyboard_origin_y + keys[column].y - 8,
|
||||
7,
|
||||
10);
|
||||
canvas_set_color(canvas, ColorWhite);
|
||||
} else {
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
}
|
||||
|
||||
if(model->clear_default_text || (char_is_lowercase(keys[column].text))) {
|
||||
canvas_draw_glyph(
|
||||
canvas,
|
||||
keyboard_origin_x + keys[column].x,
|
||||
keyboard_origin_y + keys[column].y,
|
||||
char_to_uppercase(keys[column].text));
|
||||
//keys[column].text);
|
||||
} else {
|
||||
canvas_draw_glyph(
|
||||
canvas,
|
||||
keyboard_origin_x + keys[column].x,
|
||||
keyboard_origin_y + keys[column].y,
|
||||
keys[column].text);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/*if(model->validator_message_visible) {
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
canvas_set_color(canvas, ColorWhite);
|
||||
canvas_draw_box(canvas, 8, 10, 110, 48);
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
canvas_draw_icon(canvas, 10, 14, &I_WarningDolphin_45x42);
|
||||
canvas_draw_rframe(canvas, 8, 8, 112, 50, 3);
|
||||
canvas_draw_rframe(canvas, 9, 9, 110, 48, 2);
|
||||
elements_multiline_text(canvas, 62, 20, furi_string_get_cstr(model->validator_text));
|
||||
canvas_set_font(canvas, FontKeyboard);
|
||||
}*/
|
||||
}
|
||||
|
||||
static void mag_text_input_handle_up(Mag_TextInput* mag_text_input, Mag_TextInputModel* model) {
|
||||
UNUSED(mag_text_input);
|
||||
if(model->selected_row > 0) {
|
||||
model->selected_row--;
|
||||
if(model->selected_column > get_row_size(model->selected_row) - 6) {
|
||||
model->selected_column = model->selected_column + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void mag_text_input_handle_down(Mag_TextInput* mag_text_input, Mag_TextInputModel* model) {
|
||||
UNUSED(mag_text_input);
|
||||
if(model->selected_row < keyboard_row_count - 1) {
|
||||
model->selected_row++;
|
||||
if(model->selected_column > get_row_size(model->selected_row) - 4) {
|
||||
model->selected_column = model->selected_column - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void mag_text_input_handle_left(Mag_TextInput* mag_text_input, Mag_TextInputModel* model) {
|
||||
UNUSED(mag_text_input);
|
||||
if(model->selected_column > 0) {
|
||||
model->selected_column--;
|
||||
} else {
|
||||
model->selected_column = get_row_size(model->selected_row) - 1;
|
||||
}
|
||||
}
|
||||
|
||||
static void mag_text_input_handle_right(Mag_TextInput* mag_text_input, Mag_TextInputModel* model) {
|
||||
UNUSED(mag_text_input);
|
||||
if(model->selected_column < get_row_size(model->selected_row) - 1) {
|
||||
model->selected_column++;
|
||||
} else {
|
||||
model->selected_column = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
mag_text_input_handle_ok(Mag_TextInput* mag_text_input, Mag_TextInputModel* model, bool shift) {
|
||||
UNUSED(mag_text_input);
|
||||
|
||||
char selected = get_selected_char(model);
|
||||
uint8_t text_length = strlen(model->text_buffer);
|
||||
|
||||
if(shift) {
|
||||
selected = char_to_uppercase(selected);
|
||||
}
|
||||
|
||||
if(selected == ENTER_KEY) {
|
||||
/*if(model->validator_callback &&
|
||||
(!model->validator_callback(
|
||||
model->text_buffer, model->validator_text, model->validator_callback_context))) {
|
||||
model->validator_message_visible = true;
|
||||
furi_timer_start(mag_text_input->timer, furi_kernel_get_tick_frequency() * 4);
|
||||
} else*/
|
||||
if(model->callback != 0 && text_length > 0) {
|
||||
model->callback(model->callback_context);
|
||||
}
|
||||
} else if(selected == BACKSPACE_KEY) {
|
||||
mag_text_input_backspace_cb(model);
|
||||
} else {
|
||||
if(model->clear_default_text) {
|
||||
text_length = 0;
|
||||
}
|
||||
if(text_length < (model->text_buffer_size - 1)) {
|
||||
if(char_is_lowercase(selected)) {
|
||||
selected = char_to_uppercase(selected);
|
||||
}
|
||||
model->text_buffer[text_length] = selected;
|
||||
model->text_buffer[text_length + 1] = 0;
|
||||
}
|
||||
}
|
||||
model->clear_default_text = false;
|
||||
}
|
||||
|
||||
static bool mag_text_input_view_input_callback(InputEvent* event, void* context) {
|
||||
Mag_TextInput* mag_text_input = context;
|
||||
furi_assert(mag_text_input);
|
||||
|
||||
bool consumed = false;
|
||||
|
||||
// Acquire model
|
||||
Mag_TextInputModel* model = view_get_model(mag_text_input->view);
|
||||
|
||||
/* if((!(event->type == InputTypePress) && !(event->type == InputTypeRelease)) &&
|
||||
model->validator_message_visible) {
|
||||
model->validator_message_visible = false;
|
||||
consumed = true;
|
||||
} else*/
|
||||
if(event->type == InputTypeShort) {
|
||||
consumed = true;
|
||||
switch(event->key) {
|
||||
case InputKeyUp:
|
||||
mag_text_input_handle_up(mag_text_input, model);
|
||||
break;
|
||||
case InputKeyDown:
|
||||
mag_text_input_handle_down(mag_text_input, model);
|
||||
break;
|
||||
case InputKeyLeft:
|
||||
mag_text_input_handle_left(mag_text_input, model);
|
||||
break;
|
||||
case InputKeyRight:
|
||||
mag_text_input_handle_right(mag_text_input, model);
|
||||
break;
|
||||
case InputKeyOk:
|
||||
mag_text_input_handle_ok(mag_text_input, model, false);
|
||||
break;
|
||||
default:
|
||||
consumed = false;
|
||||
break;
|
||||
}
|
||||
} else if(event->type == InputTypeLong) {
|
||||
consumed = true;
|
||||
switch(event->key) {
|
||||
case InputKeyUp:
|
||||
mag_text_input_handle_up(mag_text_input, model);
|
||||
break;
|
||||
case InputKeyDown:
|
||||
mag_text_input_handle_down(mag_text_input, model);
|
||||
break;
|
||||
case InputKeyLeft:
|
||||
mag_text_input_handle_left(mag_text_input, model);
|
||||
break;
|
||||
case InputKeyRight:
|
||||
mag_text_input_handle_right(mag_text_input, model);
|
||||
break;
|
||||
case InputKeyOk:
|
||||
mag_text_input_handle_ok(mag_text_input, model, true);
|
||||
break;
|
||||
case InputKeyBack:
|
||||
mag_text_input_backspace_cb(model);
|
||||
break;
|
||||
default:
|
||||
consumed = false;
|
||||
break;
|
||||
}
|
||||
} else if(event->type == InputTypeRepeat) {
|
||||
consumed = true;
|
||||
switch(event->key) {
|
||||
case InputKeyUp:
|
||||
mag_text_input_handle_up(mag_text_input, model);
|
||||
break;
|
||||
case InputKeyDown:
|
||||
mag_text_input_handle_down(mag_text_input, model);
|
||||
break;
|
||||
case InputKeyLeft:
|
||||
mag_text_input_handle_left(mag_text_input, model);
|
||||
break;
|
||||
case InputKeyRight:
|
||||
mag_text_input_handle_right(mag_text_input, model);
|
||||
break;
|
||||
case InputKeyBack:
|
||||
mag_text_input_backspace_cb(model);
|
||||
break;
|
||||
default:
|
||||
consumed = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Commit model
|
||||
view_commit_model(mag_text_input->view, consumed);
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void mag_text_input_timer_callback(void* context) {
|
||||
furi_assert(context);
|
||||
Mag_TextInput* mag_text_input = context;
|
||||
UNUSED(mag_text_input);
|
||||
|
||||
/*with_view_model(
|
||||
mag_text_input->view,
|
||||
Mag_TextInputModel * model,
|
||||
{ model->validator_message_visible = false; },
|
||||
true);*/
|
||||
}
|
||||
|
||||
Mag_TextInput* mag_text_input_alloc() {
|
||||
Mag_TextInput* mag_text_input = malloc(sizeof(Mag_TextInput));
|
||||
mag_text_input->view = view_alloc();
|
||||
view_set_context(mag_text_input->view, mag_text_input);
|
||||
view_allocate_model(mag_text_input->view, ViewModelTypeLocking, sizeof(Mag_TextInputModel));
|
||||
view_set_draw_callback(mag_text_input->view, mag_text_input_view_draw_callback);
|
||||
view_set_input_callback(mag_text_input->view, mag_text_input_view_input_callback);
|
||||
|
||||
mag_text_input->timer =
|
||||
furi_timer_alloc(mag_text_input_timer_callback, FuriTimerTypeOnce, mag_text_input);
|
||||
|
||||
/*with_view_model(
|
||||
mag_text_input->view,
|
||||
Mag_TextInputModel * model,
|
||||
{ model->validator_text = furi_string_alloc(); },
|
||||
false);*/
|
||||
|
||||
mag_text_input_reset(mag_text_input);
|
||||
|
||||
return mag_text_input;
|
||||
}
|
||||
|
||||
void mag_text_input_free(Mag_TextInput* mag_text_input) {
|
||||
furi_assert(mag_text_input);
|
||||
/*with_view_model(
|
||||
mag_text_input->view,
|
||||
Mag_TextInputModel * model,
|
||||
{ furi_string_free(model->validator_text); },
|
||||
false);*/
|
||||
|
||||
// Send stop command
|
||||
furi_timer_stop(mag_text_input->timer);
|
||||
// Release allocated memory
|
||||
furi_timer_free(mag_text_input->timer);
|
||||
|
||||
view_free(mag_text_input->view);
|
||||
|
||||
free(mag_text_input);
|
||||
}
|
||||
|
||||
void mag_text_input_reset(Mag_TextInput* mag_text_input) {
|
||||
furi_assert(mag_text_input);
|
||||
with_view_model(
|
||||
mag_text_input->view,
|
||||
Mag_TextInputModel * model,
|
||||
{
|
||||
model->text_buffer_size = 0;
|
||||
model->header = "";
|
||||
model->selected_row = 0;
|
||||
model->selected_column = 0;
|
||||
model->clear_default_text = false;
|
||||
model->text_buffer = NULL;
|
||||
model->text_buffer_size = 0;
|
||||
model->callback = NULL;
|
||||
model->callback_context = NULL;
|
||||
/*model->validator_callback = NULL;
|
||||
model->validator_callback_context = NULL;
|
||||
furi_string_reset(model->validator_text);
|
||||
model->validator_message_visible = false;*/
|
||||
},
|
||||
true);
|
||||
}
|
||||
|
||||
View* mag_text_input_get_view(Mag_TextInput* mag_text_input) {
|
||||
furi_assert(mag_text_input);
|
||||
return mag_text_input->view;
|
||||
}
|
||||
|
||||
void mag_text_input_set_result_callback(
|
||||
Mag_TextInput* mag_text_input,
|
||||
Mag_TextInputCallback callback,
|
||||
void* callback_context,
|
||||
char* text_buffer,
|
||||
size_t text_buffer_size,
|
||||
bool clear_default_text) {
|
||||
with_view_model(
|
||||
mag_text_input->view,
|
||||
Mag_TextInputModel * model,
|
||||
{
|
||||
model->callback = callback;
|
||||
model->callback_context = callback_context;
|
||||
model->text_buffer = text_buffer;
|
||||
model->text_buffer_size = text_buffer_size;
|
||||
model->clear_default_text = clear_default_text;
|
||||
if(text_buffer && text_buffer[0] != '\0') {
|
||||
// Set focus on Save
|
||||
model->selected_row = 2;
|
||||
model->selected_column = 8;
|
||||
}
|
||||
},
|
||||
true);
|
||||
}
|
||||
|
||||
/* void mag_text_input_set_validator(
|
||||
Mag_TextInput* mag_text_input,
|
||||
Mag_TextInputValidatorCallback callback,
|
||||
void* callback_context) {
|
||||
with_view_model(
|
||||
mag_text_input->view,
|
||||
Mag_TextInputModel * model,
|
||||
{
|
||||
model->validator_callback = callback;
|
||||
model->validator_callback_context = callback_context;
|
||||
},
|
||||
true);
|
||||
}
|
||||
|
||||
Mag_TextInputValidatorCallback
|
||||
mag_text_input_get_validator_callback(Mag_TextInput* mag_text_input) {
|
||||
Mag_TextInputValidatorCallback validator_callback = NULL;
|
||||
with_view_model(
|
||||
mag_text_input->view,
|
||||
Mag_TextInputModel * model,
|
||||
{ validator_callback = model->validator_callback; },
|
||||
false);
|
||||
return validator_callback;
|
||||
}
|
||||
|
||||
void* mag_text_input_get_validator_callback_context(Mag_TextInput* mag_text_input) {
|
||||
void* validator_callback_context = NULL;
|
||||
with_view_model(
|
||||
mag_text_input->view,
|
||||
Mag_TextInputModel * model,
|
||||
{ validator_callback_context = model->validator_callback_context; },
|
||||
false);
|
||||
return validator_callback_context;
|
||||
}*/
|
||||
|
||||
void mag_text_input_set_header_text(Mag_TextInput* mag_text_input, const char* text) {
|
||||
with_view_model(
|
||||
mag_text_input->view, Mag_TextInputModel * model, { model->header = text; }, true);
|
||||
}
|
||||
82
applications/external/magspoof/helpers/mag_text_input.h
vendored
Normal file
82
applications/external/magspoof/helpers/mag_text_input.h
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
#pragma once
|
||||
|
||||
#include <gui/view.h>
|
||||
// #include "mag_validators.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** Text input anonymous structure */
|
||||
typedef struct Mag_TextInput Mag_TextInput;
|
||||
typedef void (*Mag_TextInputCallback)(void* context);
|
||||
// typedef bool (*Mag_TextInputValidatorCallback)(const char* text, FuriString* error, void* context);
|
||||
|
||||
/** Allocate and initialize text input
|
||||
*
|
||||
* This text input is used to enter string
|
||||
*
|
||||
* @return Mag_TextInput instance
|
||||
*/
|
||||
Mag_TextInput* mag_text_input_alloc();
|
||||
|
||||
/** Deinitialize and free text input
|
||||
*
|
||||
* @param mag_text_input Mag_TextInput instance
|
||||
*/
|
||||
void mag_text_input_free(Mag_TextInput* mag_text_input);
|
||||
|
||||
/** Clean text input view Note: this function does not free memory
|
||||
*
|
||||
* @param mag_text_input Text input instance
|
||||
*/
|
||||
void mag_text_input_reset(Mag_TextInput* mag_text_input);
|
||||
|
||||
/** Get text input view
|
||||
*
|
||||
* @param mag_text_input Mag_TextInput instance
|
||||
*
|
||||
* @return View instance that can be used for embedding
|
||||
*/
|
||||
View* mag_text_input_get_view(Mag_TextInput* mag_text_input);
|
||||
|
||||
/** Set text input result callback
|
||||
*
|
||||
* @param mag_text_input Mag_TextInput instance
|
||||
* @param callback callback fn
|
||||
* @param callback_context callback context
|
||||
* @param text_buffer pointer to YOUR text buffer, that we going
|
||||
* to modify
|
||||
* @param text_buffer_size YOUR text buffer size in bytes. Max string
|
||||
* length will be text_buffer_size-1.
|
||||
* @param clear_default_text clear text from text_buffer on first OK
|
||||
* event
|
||||
*/
|
||||
void mag_text_input_set_result_callback(
|
||||
Mag_TextInput* mag_text_input,
|
||||
Mag_TextInputCallback callback,
|
||||
void* callback_context,
|
||||
char* text_buffer,
|
||||
size_t text_buffer_size,
|
||||
bool clear_default_text);
|
||||
|
||||
/* void mag_text_input_set_validator(
|
||||
Mag_TextInput* mag_text_input,
|
||||
Mag_TextInputValidatorCallback callback,
|
||||
void* callback_context);
|
||||
|
||||
Mag_TextInputValidatorCallback
|
||||
mag_text_input_get_validator_callback(Mag_TextInput* mag_text_input);
|
||||
|
||||
void* mag_text_input_get_validator_callback_context(Mag_TextInput* mag_text_input); */
|
||||
|
||||
/** Set text input header text
|
||||
*
|
||||
* @param mag_text_input Mag_TextInput instance
|
||||
* @param text text to be shown
|
||||
*/
|
||||
void mag_text_input_set_header_text(Mag_TextInput* mag_text_input, const char* text);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
44
applications/external/magspoof/helpers/mag_types.h
vendored
Normal file
44
applications/external/magspoof/helpers/mag_types.h
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
|
||||
#define MAG_VERSION_APP "0.05"
|
||||
#define MAG_DEVELOPER "Zachary Weiss"
|
||||
#define MAG_GITHUB "github.com/zacharyweiss/magspoof_flipper"
|
||||
|
||||
typedef enum {
|
||||
MagViewSubmenu,
|
||||
MagViewDialogEx,
|
||||
MagViewPopup,
|
||||
MagViewLoading,
|
||||
MagViewWidget,
|
||||
MagViewVariableItemList,
|
||||
MagViewTextInput,
|
||||
MagViewMagTextInput,
|
||||
} MagView;
|
||||
|
||||
typedef enum {
|
||||
MagReverseStateOff,
|
||||
MagReverseStateOn,
|
||||
} MagReverseState;
|
||||
|
||||
typedef enum {
|
||||
MagTrackStateOneAndTwo,
|
||||
MagTrackStateOne,
|
||||
MagTrackStateTwo,
|
||||
MagTrackStateThree,
|
||||
} MagTrackState;
|
||||
|
||||
typedef enum {
|
||||
MagTxStateRFID,
|
||||
MagTxStateGPIO,
|
||||
MagTxStatePiezo,
|
||||
MagTxStateLF_P, // combo of RFID and Piezo
|
||||
MagTxStateNFC,
|
||||
MagTxCC1101_434,
|
||||
MagTxCC1101_868,
|
||||
} MagTxState;
|
||||
|
||||
typedef enum {
|
||||
UART_TerminalEventRefreshConsoleOutput = 0,
|
||||
UART_TerminalEventStartConsole,
|
||||
UART_TerminalEventStartKeyboard,
|
||||
} UART_TerminalCustomEvent;
|
||||
Reference in New Issue
Block a user