Added ledcontrol to lf functions

This commit is contained in:
Łukasz Jurczyk
2021-11-18 15:00:54 +01:00
parent d4b5bfbeaa
commit 218a4ba2ec
26 changed files with 432 additions and 426 deletions
+1
View File
@@ -34,6 +34,7 @@ This project uses the changelog in accordance with [keepchangelog](http://keepac
- Changed `hf mfdes` - detect LRP mode and info updates (@merlokk)
- Fixed `hf mfdes` - increase response buffer length (@merlokk)
- Fixed `SimulateTagLowFrequencyEx` ignoring the `ledcontrol` argument (@zabszk)
- Added ledcontrol argument to LF operations (@zabszk)
## [crimson.4.14434][2021-09-18]
- Fixed `hf mf staticnested` - flashmem / non loop now works (@horrordash)
+2 -2
View File
@@ -260,7 +260,7 @@ static int ExecuteMode(int mode, int slot) {
//default first mode is simulate
case LF_RWSB_MODE_READ:
Dbprintf("[=] >> Read mode started <<");
lf_em410x_watch(1, &high[slot], &low[slot]);
lf_em410x_watch(1, &high[slot], &low[slot], true);
LED_Update(mode, slot);
Dbprintf("[=] >> Tag found. Saving. <<");
FlashLEDs(100, 5);
@@ -276,7 +276,7 @@ static int ExecuteMode(int mode, int slot) {
return LF_RWSB_UNKNOWN_RESULT;
case LF_RWSB_MODE_WRITE:
Dbprintf("[!!] >> Write mode started <<");
copy_em410x_to_t55xx(LF_RWSB_T55XX_TYPE, LF_CLOCK, (uint32_t)(low[slot] >> 32), (uint32_t)(low[slot] & 0xffffffff));
copy_em410x_to_t55xx(LF_RWSB_T55XX_TYPE, LF_CLOCK, (uint32_t)(low[slot] >> 32), (uint32_t)(low[slot] & 0xffffffff), true);
return LF_RWSB_UNKNOWN_RESULT;
case LF_RWSB_MODE_BRUTE:
Dbprintf("[=] >> Bruteforce mode started <<");
+2 -2
View File
@@ -172,7 +172,7 @@ void RunMod(void) {
state = 3;
} else if (button_pressed == BUTTON_SINGLE_CLICK) {
// Click - exit to select mode
lf_em410x_watch(1, &high[selected], &low[selected]);
lf_em410x_watch(1, &high[selected], &low[selected], true);
flash_leds(100, 5);
#ifdef WITH_FLASH
SaveIDtoFlash(selected, low[selected]);
@@ -208,7 +208,7 @@ void RunMod(void) {
state = 0;
} else if (button_pressed == BUTTON_SINGLE_CLICK) {
// Click - write ID to tag
copy_em410x_to_t55xx(0, LF_CLOCK, (uint32_t)(low[selected] >> 32), (uint32_t)(low[selected] & 0xffffffff));
copy_em410x_to_t55xx(0, LF_CLOCK, (uint32_t)(low[selected] >> 32), (uint32_t)(low[selected] & 0xffffffff), true);
led_slot(selected);
state = 0; // Switch to select mode
}
+2 -2
View File
@@ -75,7 +75,7 @@ void RunMod(void) {
// record
DbpString("[=] starting recording");
lf_hid_watch(1, &high[selected], &low[selected]);
lf_hid_watch(1, &high[selected], &low[selected], true);
Dbprintf("[=] recorded %x %x %08x", selected, high[selected], low[selected]);
LEDsoff();
@@ -95,7 +95,7 @@ void RunMod(void) {
WAIT_BUTTON_RELEASED();
CopyHIDtoT55x7(0, high[selected], low[selected], 0, false, false);
CopyHIDtoT55x7(0, high[selected], low[selected], 0, false, false, true);
Dbprintf("[=] cloned %x %x %08x", selected, high[selected], low[selected]);
LEDsoff();
+4 -4
View File
@@ -354,21 +354,21 @@ void RunMod(void) {
// since we steal 12800 from bigbuffer, no need to sample it.
size_t size = MIN(28000, BigBuf_max_traceLen());
DoAcquisition_config(false, size);
DoAcquisition_config(false, size, true);
res = IceHIDDemod();
if (res == PM3_SUCCESS) {
LED_A_OFF();
continue;
}
DoAcquisition_config(false, size);
DoAcquisition_config(false, size, true);
res = IceAWIDdemod();
if (res == PM3_SUCCESS) {
LED_A_OFF();
continue;
}
DoAcquisition_config(false, size);
DoAcquisition_config(false, size, true);
res = IceIOdemod();
if (res == PM3_SUCCESS) {
LED_A_OFF();
@@ -376,7 +376,7 @@ void RunMod(void) {
}
size = MIN(20000, BigBuf_max_traceLen());
DoAcquisition_config(false, size);
DoAcquisition_config(false, size, true);
res = IceEM410xdemod();
if (res == PM3_SUCCESS) {
LED_A_OFF();
+1 -1
View File
@@ -323,7 +323,7 @@ void RunMod(void) {
size_t size = MIN(16385, BigBuf_max_traceLen());
DoAcquisition_config(false, size);
DoAcquisition_config(false, size, true);
res = demodNexWatch();
if (res == PM3_SUCCESS) {
LED_A_OFF();
+1 -1
View File
@@ -57,7 +57,7 @@ void RunMod(void) {
DbpString("[=] starting recording");
// findone, high, low
lf_hid_watch(1, &high, &low);
lf_hid_watch(1, &high, &low, true);
Dbprintf("[=] recorded | %x%08x", high, low);
+2 -2
View File
@@ -77,7 +77,7 @@ void RunMod(void) {
// findone, high, low, no ledcontrol (A)
uint32_t hi = 0, lo = 0;
lf_hid_watch(1, &hi, &lo);
lf_hid_watch(1, &hi, &lo, true);
high[selected] = hi;
low[selected] = lo;
@@ -121,7 +121,7 @@ void RunMod(void) {
Dbprintf("[=] cloning %x | %x%08x", selected, high[selected], low[selected]);
// high2, high, low, no longFMT
CopyHIDtoT55x7(0, high[selected], low[selected], 0, false, false);
CopyHIDtoT55x7(0, high[selected], low[selected], 0, false, false, true);
DbpString("[=] cloned done");
+1 -1
View File
@@ -219,7 +219,7 @@ void RunMod(void) {
SpinDelay(200);
}
em4x50_handle_commands(&command, tag);
em4x50_handle_commands(&command, tag, true);
// check if new password was found
if (g_Password != reflect32(tag[EM4X50_DEVICE_PASSWORD])) {
+50 -49
View File
@@ -812,7 +812,7 @@ static void PacketReceived(PacketCommandNG *packet) {
bool verbose : 1;
} PACKED;
struct p *payload = (struct p *)packet->data.asBytes;
uint32_t bits = SampleLF(payload->verbose, payload->samples);
uint32_t bits = SampleLF(payload->verbose, payload->samples, true);
reply_ng(CMD_LF_ACQ_RAW_ADC, PM3_SUCCESS, (uint8_t *)&bits, sizeof(bits));
break;
}
@@ -831,7 +831,7 @@ static void PacketReceived(PacketCommandNG *packet) {
uint16_t period_extra[LF_CMDREAD_MAX_EXTRA_SYMBOLS];
memcpy(symbol_extra, payload->symbol_extra, sizeof(symbol_extra));
memcpy(period_extra, payload->period_extra, sizeof(period_extra));
ModThenAcquireRawAdcSamples125k(payload->delay, payload->period_0, payload->period_1, symbol_extra, period_extra, packet->data.asBytes + sizeof(struct p), payload->verbose, payload->samples);
ModThenAcquireRawAdcSamples125k(payload->delay, payload->period_0, payload->period_1, symbol_extra, period_extra, packet->data.asBytes + sizeof(struct p), payload->verbose, payload->samples, true);
break;
}
case CMD_LF_SNIFF_RAW_ADC: {
@@ -840,13 +840,13 @@ static void PacketReceived(PacketCommandNG *packet) {
bool verbose : 1;
} PACKED;
struct p *payload = (struct p *)packet->data.asBytes;
uint32_t bits = SniffLF(payload->verbose, payload->samples);
uint32_t bits = SniffLF(payload->verbose, payload->samples, true);
reply_ng(CMD_LF_SNIFF_RAW_ADC, PM3_SUCCESS, (uint8_t *)&bits, sizeof(bits));
break;
}
case CMD_LF_HID_WATCH: {
uint32_t high, low;
int res = lf_hid_watch(0, &high, &low);
int res = lf_hid_watch(0, &high, &low, true);
reply_ng(CMD_LF_HID_WATCH, res, NULL, 0);
break;
}
@@ -877,19 +877,19 @@ static void PacketReceived(PacketCommandNG *packet) {
}
case CMD_LF_HID_CLONE: {
lf_hidsim_t *payload = (lf_hidsim_t *)packet->data.asBytes;
CopyHIDtoT55x7(payload->hi2, payload->hi, payload->lo, payload->longFMT, payload->Q5, payload->EM);
CopyHIDtoT55x7(payload->hi2, payload->hi, payload->lo, payload->longFMT, payload->Q5, payload->EM, true);
break;
}
case CMD_LF_IO_WATCH: {
uint32_t high, low;
int res = lf_io_watch(0, &high, &low);
int res = lf_io_watch(0, &high, &low, true);
reply_ng(CMD_LF_IO_WATCH, res, NULL, 0);
break;
}
case CMD_LF_EM410X_WATCH: {
uint32_t high;
uint64_t low;
int res = lf_em410x_watch(0, &high, &low);
int res = lf_em410x_watch(0, &high, &low, true);
reply_ng(CMD_LF_EM410X_WATCH, res, NULL, 0);
break;
}
@@ -901,12 +901,12 @@ static void PacketReceived(PacketCommandNG *packet) {
uint32_t low;
} PACKED;
struct p *payload = (struct p *)packet->data.asBytes;
int res = copy_em410x_to_t55xx(payload->card, payload->clock, payload->high, payload->low);
int res = copy_em410x_to_t55xx(payload->card, payload->clock, payload->high, payload->low, true);
reply_ng(CMD_LF_EM410X_WRITE, res, NULL, 0);
break;
}
case CMD_LF_TI_READ: {
ReadTItag();
ReadTItag(true);
break;
}
case CMD_LF_TI_WRITE: {
@@ -916,7 +916,7 @@ static void PacketReceived(PacketCommandNG *packet) {
uint16_t crc;
} PACKED;
struct p *payload = (struct p *)packet->data.asBytes;
WriteTItag(payload->high, payload->low, packet->crc);
WriteTItag(payload->high, payload->low, packet->crc, true);
break;
}
case CMD_LF_SIMULATE: {
@@ -945,16 +945,16 @@ static void PacketReceived(PacketCommandNG *packet) {
uint8_t downlink_mode;
} PACKED;
struct p *payload = (struct p *) packet->data.asBytes;
T55xxReadBlock(payload->page, payload->pwdmode, false, payload->blockno, payload->password, payload->downlink_mode);
T55xxReadBlock(payload->page, payload->pwdmode, false, payload->blockno, payload->password, payload->downlink_mode, true);
break;
}
case CMD_LF_T55XX_WRITEBL: {
// uses NG format
T55xxWriteBlock(packet->data.asBytes);
T55xxWriteBlock(packet->data.asBytes, true);
break;
}
case CMD_LF_T55XX_DANGERRAW: {
T55xxDangerousRawTest(packet->data.asBytes);
T55xxDangerousRawTest(packet->data.asBytes, true);
break;
}
case CMD_LF_T55XX_WAKEUP: {
@@ -963,19 +963,19 @@ static void PacketReceived(PacketCommandNG *packet) {
uint8_t flags;
} PACKED;
struct p *payload = (struct p *) packet->data.asBytes;
T55xxWakeUp(payload->password, payload->flags);
T55xxWakeUp(payload->password, payload->flags, true);
break;
}
case CMD_LF_T55XX_RESET_READ: {
T55xxResetRead(packet->data.asBytes[0] & 0xff);
T55xxResetRead(packet->data.asBytes[0] & 0xff, true);
break;
}
case CMD_LF_T55XX_CHK_PWDS: {
T55xx_ChkPwds(packet->data.asBytes[0] & 0xff);
T55xx_ChkPwds(packet->data.asBytes[0] & 0xff, true);
break;
}
case CMD_LF_PCF7931_READ: {
ReadPCF7931();
ReadPCF7931(true);
break;
}
case CMD_LF_PCF7931_WRITE: {
@@ -985,7 +985,8 @@ static void PacketReceived(PacketCommandNG *packet) {
packet->data.asBytes[7] - 128, packet->data.asBytes[8] - 128,
packet->oldarg[0],
packet->oldarg[1],
packet->oldarg[2]
packet->oldarg[2],
true
);
break;
}
@@ -994,7 +995,7 @@ static void PacketReceived(PacketCommandNG *packet) {
uint32_t password;
} PACKED;
struct p *payload = (struct p *) packet->data.asBytes;
EM4xLogin(payload->password);
EM4xLogin(payload->password, true);
break;
}
case CMD_LF_EM4X_BF: {
@@ -1003,7 +1004,7 @@ static void PacketReceived(PacketCommandNG *packet) {
uint32_t n;
} PACKED;
struct p *payload = (struct p *) packet->data.asBytes;
EM4xBruteforce(payload->start_pwd, payload->n);
EM4xBruteforce(payload->start_pwd, payload->n, true);
break;
}
case CMD_LF_EM4X_READWORD: {
@@ -1013,7 +1014,7 @@ static void PacketReceived(PacketCommandNG *packet) {
uint8_t usepwd;
} PACKED;
struct p *payload = (struct p *) packet->data.asBytes;
EM4xReadWord(payload->address, payload->password, payload->usepwd);
EM4xReadWord(payload->address, payload->password, payload->usepwd, true);
break;
}
case CMD_LF_EM4X_WRITEWORD: {
@@ -1024,7 +1025,7 @@ static void PacketReceived(PacketCommandNG *packet) {
uint8_t usepwd;
} PACKED;
struct p *payload = (struct p *) packet->data.asBytes;
EM4xWriteWord(payload->address, payload->data, payload->password, payload->usepwd);
EM4xWriteWord(payload->address, payload->data, payload->password, payload->usepwd, true);
break;
}
case CMD_LF_EM4X_PROTECTWORD: {
@@ -1034,12 +1035,12 @@ static void PacketReceived(PacketCommandNG *packet) {
uint8_t usepwd;
} PACKED;
struct p *payload = (struct p *) packet->data.asBytes;
EM4xProtectWord(payload->data, payload->password, payload->usepwd);
EM4xProtectWord(payload->data, payload->password, payload->usepwd, true);
break;
}
case CMD_LF_AWID_WATCH: {
uint32_t high, low;
int res = lf_awid_watch(0, &high, &low);
int res = lf_awid_watch(0, &high, &low, true);
reply_ng(CMD_LF_AWID_WATCH, res, NULL, 0);
break;
}
@@ -1050,7 +1051,7 @@ static void PacketReceived(PacketCommandNG *packet) {
uint8_t blocks[8];
} PACKED;
struct p *payload = (struct p *)packet->data.asBytes;
CopyVikingtoT55xx(payload->blocks, payload->Q5, payload->EM);
CopyVikingtoT55xx(payload->blocks, payload->Q5, payload->EM, true);
break;
}
case CMD_LF_COTAG_READ: {
@@ -1058,43 +1059,43 @@ static void PacketReceived(PacketCommandNG *packet) {
uint8_t mode;
} PACKED;
struct p *payload = (struct p *)packet->data.asBytes;
Cotag(payload->mode);
Cotag(payload->mode, true);
break;
}
#endif
#ifdef WITH_HITAG
case CMD_LF_HITAG_SNIFF: { // Eavesdrop Hitag tag, args = type
SniffHitag2();
SniffHitag2(true);
// SniffHitag2(packet->oldarg[0]);
reply_ng(CMD_LF_HITAG_SNIFF, PM3_SUCCESS, NULL, 0);
break;
}
case CMD_LF_HITAG_SIMULATE: { // Simulate Hitag tag, args = memory content
SimulateHitag2();
SimulateHitag2(true);
break;
}
case CMD_LF_HITAG_READER: { // Reader for Hitag tags, args = type and function
ReaderHitag((hitag_function)packet->oldarg[0], (hitag_data *)packet->data.asBytes);
ReaderHitag((hitag_function)packet->oldarg[0], (hitag_data *)packet->data.asBytes, true);
break;
}
case CMD_LF_HITAGS_SIMULATE: { // Simulate Hitag s tag, args = memory content
SimulateHitagSTag((bool)packet->oldarg[0], packet->data.asBytes);
SimulateHitagSTag((bool)packet->oldarg[0], packet->data.asBytes, true);
break;
}
case CMD_LF_HITAGS_TEST_TRACES: { // Tests every challenge within the given file
check_challenges((bool)packet->oldarg[0], packet->data.asBytes);
check_challenges((bool)packet->oldarg[0], packet->data.asBytes, true);
break;
}
case CMD_LF_HITAGS_READ: { //Reader for only Hitag S tags, args = key or challenge
ReadHitagS((hitag_function)packet->oldarg[0], (hitag_data *)packet->data.asBytes);
ReadHitagS((hitag_function)packet->oldarg[0], (hitag_data *)packet->data.asBytes, true);
break;
}
case CMD_LF_HITAGS_WRITE: { //writer for Hitag tags args=data to write,page and key or challenge
if ((hitag_function)packet->oldarg[0] < 10) {
WritePageHitagS((hitag_function)packet->oldarg[0], (hitag_data *)packet->data.asBytes, packet->oldarg[2]);
WritePageHitagS((hitag_function)packet->oldarg[0], (hitag_data *)packet->data.asBytes, packet->oldarg[2], true);
} else {
WriterHitag((hitag_function)packet->oldarg[0], (hitag_data *)packet->data.asBytes, packet->oldarg[2]);
WriterHitag((hitag_function)packet->oldarg[0], (hitag_data *)packet->data.asBytes, packet->oldarg[2], true);
}
break;
}
@@ -1108,27 +1109,27 @@ static void PacketReceived(PacketCommandNG *packet) {
#ifdef WITH_EM4x50
case CMD_LF_EM4X50_INFO: {
em4x50_info((em4x50_data_t *)packet->data.asBytes);
em4x50_info((em4x50_data_t *)packet->data.asBytes, true);
break;
}
case CMD_LF_EM4X50_WRITE: {
em4x50_write((em4x50_data_t *)packet->data.asBytes);
em4x50_write((em4x50_data_t *)packet->data.asBytes, true);
break;
}
case CMD_LF_EM4X50_WRITEPWD: {
em4x50_writepwd((em4x50_data_t *)packet->data.asBytes);
em4x50_writepwd((em4x50_data_t *)packet->data.asBytes, true);
break;
}
case CMD_LF_EM4X50_READ: {
em4x50_read((em4x50_data_t *)packet->data.asBytes);
em4x50_read((em4x50_data_t *)packet->data.asBytes, true);
break;
}
case CMD_LF_EM4X50_BRUTE: {
em4x50_brute((em4x50_data_t *)packet->data.asBytes);
em4x50_brute((em4x50_data_t *)packet->data.asBytes, true);
break;
}
case CMD_LF_EM4X50_LOGIN: {
em4x50_login((uint32_t *)packet->data.asBytes);
em4x50_login((uint32_t *)packet->data.asBytes, true);
break;
}
case CMD_LF_EM4X50_SIM: {
@@ -1138,11 +1139,11 @@ static void PacketReceived(PacketCommandNG *packet) {
// destroy the Emulator Memory.
//-----------------------------------------------------------------------------
FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
em4x50_sim((uint32_t *)packet->data.asBytes);
em4x50_sim((uint32_t *)packet->data.asBytes, true);
break;
}
case CMD_LF_EM4X50_READER: {
em4x50_reader();
em4x50_reader(true);
break;
}
case CMD_LF_EM4X50_ESET: {
@@ -1162,34 +1163,34 @@ static void PacketReceived(PacketCommandNG *packet) {
// destroy the Emulator Memory.
//-----------------------------------------------------------------------------
FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
em4x50_chk((uint8_t *)packet->data.asBytes);
em4x50_chk((uint8_t *)packet->data.asBytes, true);
break;
}
#endif
#ifdef WITH_EM4x70
case CMD_LF_EM4X70_INFO: {
em4x70_info((em4x70_data_t *)packet->data.asBytes);
em4x70_info((em4x70_data_t *)packet->data.asBytes, true);
break;
}
case CMD_LF_EM4X70_WRITE: {
em4x70_write((em4x70_data_t *)packet->data.asBytes);
em4x70_write((em4x70_data_t *)packet->data.asBytes, true);
break;
}
case CMD_LF_EM4X70_UNLOCK: {
em4x70_unlock((em4x70_data_t *)packet->data.asBytes);
em4x70_unlock((em4x70_data_t *)packet->data.asBytes, true);
break;
}
case CMD_LF_EM4X70_AUTH: {
em4x70_auth((em4x70_data_t *)packet->data.asBytes);
em4x70_auth((em4x70_data_t *)packet->data.asBytes, true);
break;
}
case CMD_LF_EM4X70_WRITEPIN: {
em4x70_write_pin((em4x70_data_t *)packet->data.asBytes);
em4x70_write_pin((em4x70_data_t *)packet->data.asBytes, true);
break;
}
case CMD_LF_EM4X70_WRITEKEY: {
em4x70_write_key((em4x70_data_t *)packet->data.asBytes);
em4x70_write_key((em4x70_data_t *)packet->data.asBytes, true);
break;
}
#endif
+83 -83
View File
@@ -676,42 +676,42 @@ static bool brute(uint32_t start, uint32_t stop, uint32_t *pwd) {
}
// login into EM4x50
void em4x50_login(uint32_t *password) {
void em4x50_login(uint32_t *password, bool ledcontrol) {
em4x50_setup_read();
int status = PM3_EFAILED;
LED_C_ON();
if (ledcontrol) LED_C_ON();
if (get_signalproperties() && find_em4x50_tag()) {
LED_C_OFF();
LED_D_ON();
if (ledcontrol) LED_C_OFF();
if (ledcontrol) LED_D_ON();
status = login(*password);
}
LEDsoff();
lf_finalize();
if (ledcontrol) LEDsoff();
lf_finalize(ledcontrol);
reply_ng(CMD_LF_EM4X50_LOGIN, status, NULL, 0);
}
// envoke password search
void em4x50_brute(em4x50_data_t *etd) {
void em4x50_brute(em4x50_data_t *etd, bool ledcontrol) {
em4x50_setup_read();
bool bsuccess = false;
uint32_t pwd = 0x0;
LED_C_ON();
if (ledcontrol) LED_C_ON();
if (get_signalproperties() && find_em4x50_tag()) {
LED_C_OFF();
LED_D_ON();
if (ledcontrol) LED_C_OFF();
if (ledcontrol) LED_D_ON();
bsuccess = brute(etd->password1, etd->password2, &pwd);
}
LEDsoff();
lf_finalize();
if (ledcontrol) LEDsoff();
lf_finalize(ledcontrol);
reply_ng(CMD_LF_EM4X50_BRUTE, bsuccess ? PM3_SUCCESS : PM3_EFAILED, (uint8_t *)(&pwd), sizeof(pwd));
}
// check passwords from dictionary content in flash memory
void em4x50_chk(uint8_t *filename) {
void em4x50_chk(uint8_t *filename, bool ledcontrol) {
int status = PM3_EFAILED;
uint32_t pwd = 0x0;
@@ -733,11 +733,11 @@ void em4x50_chk(uint8_t *filename) {
em4x50_setup_read();
// set g_High and g_Low
LED_C_ON();
if (ledcontrol) LED_C_ON();
if (get_signalproperties() && find_em4x50_tag()) {
LED_C_OFF();
LED_D_ON();
if (ledcontrol) LED_C_OFF();
if (ledcontrol) LED_D_ON();
// try to login with current password
for (int i = 0; i < pwd_count; i++) {
@@ -765,8 +765,8 @@ void em4x50_chk(uint8_t *filename) {
#endif
LEDsoff();
lf_finalize();
if (ledcontrol) LEDsoff();
lf_finalize(ledcontrol);
reply_ng(CMD_LF_EM4X50_CHK, status, (uint8_t *)&pwd, sizeof(pwd));
}
@@ -849,18 +849,18 @@ static int selective_read(uint32_t addresses, uint32_t *words) {
}
// reads by using "selective read mode" -> bidirectional communication
void em4x50_read(em4x50_data_t *etd) {
void em4x50_read(em4x50_data_t *etd, bool ledcontrol) {
int status = PM3_EFAILED;
uint32_t words[EM4X50_NO_WORDS] = {0x0};
em4x50_setup_read();
// set g_High and g_Low
LED_C_ON();
if (ledcontrol) LED_C_ON();
if (get_signalproperties() && find_em4x50_tag()) {
LED_C_OFF();
LED_D_ON();
if (ledcontrol) LED_C_OFF();
if (ledcontrol) LED_D_ON();
bool blogin = true;
@@ -873,23 +873,23 @@ void em4x50_read(em4x50_data_t *etd) {
status = selective_read(etd->addresses, words);
}
LEDsoff();
if (ledcontrol) LEDsoff();
LOW(GPIO_SSC_DOUT);
lf_finalize();
lf_finalize(ledcontrol);
reply_ng(CMD_LF_EM4X50_READ, status, (uint8_t *)words, EM4X50_TAG_MAX_NO_BYTES);
}
// collects as much information as possible via selective read mode
void em4x50_info(em4x50_data_t *etd) {
void em4x50_info(em4x50_data_t *etd, bool ledcontrol) {
int status = PM3_EFAILED;
uint32_t words[EM4X50_NO_WORDS] = {0x0};
em4x50_setup_read();
LED_C_ON();
if (ledcontrol) LED_C_ON();
if (get_signalproperties() && find_em4x50_tag()) {
LED_C_OFF();
LED_D_ON();
if (ledcontrol) LED_C_OFF();
if (ledcontrol) LED_D_ON();
bool blogin = true;
// login with given password
@@ -902,29 +902,29 @@ void em4x50_info(em4x50_data_t *etd) {
}
}
LEDsoff();
lf_finalize();
if (ledcontrol) LEDsoff();
lf_finalize(ledcontrol);
reply_ng(CMD_LF_EM4X50_INFO, status, (uint8_t *)words, EM4X50_TAG_MAX_NO_BYTES);
}
// reads data that tag transmits "voluntarily" -> standard read mode
void em4x50_reader(void) {
void em4x50_reader(bool ledcontrol) {
int now = 0;
uint32_t words[EM4X50_NO_WORDS] = {0x0};
em4x50_setup_read();
LED_C_ON();
if (ledcontrol) LED_C_ON();
if (get_signalproperties() && find_em4x50_tag()) {
LED_C_OFF();
LED_D_ON();
if (ledcontrol) LED_C_OFF();
if (ledcontrol) LED_D_ON();
standard_read(&now, words);
}
LEDsoff();
if (ledcontrol) LEDsoff();
LOW(GPIO_SSC_DOUT);
lf_finalize();
lf_finalize(ledcontrol);
reply_ng(CMD_LF_EM4X50_READER, now, (uint8_t *)words, 4 * now);
}
@@ -1023,17 +1023,17 @@ static int write_password(uint32_t password, uint32_t new_password) {
// write operation process for EM4x50 tag,
// single word is written to given address, verified by selective read operation
// wrong password -> return with PM3_EFAILED
void em4x50_write(em4x50_data_t *etd) {
void em4x50_write(em4x50_data_t *etd, bool ledcontrol) {
int status = PM3_EFAILED;
uint32_t words[EM4X50_NO_WORDS] = {0x0};
em4x50_setup_read();
LED_C_ON();
if (ledcontrol) LED_C_ON();
if (get_signalproperties() && find_em4x50_tag()) {
LED_C_OFF();
LED_D_ON();
if (ledcontrol) LED_C_OFF();
if (ledcontrol) LED_D_ON();
// if password is given try to login first
status = PM3_SUCCESS;
@@ -1045,7 +1045,7 @@ void em4x50_write(em4x50_data_t *etd) {
// write word to given address
status = write(etd->word, etd->addresses);
if (status == PM3_ETEAROFF) {
lf_finalize();
lf_finalize(ledcontrol);
return;
}
@@ -1075,36 +1075,36 @@ void em4x50_write(em4x50_data_t *etd) {
}
}
LEDsoff();
lf_finalize();
if (ledcontrol) LEDsoff();
lf_finalize(ledcontrol);
reply_ng(CMD_LF_EM4X50_WRITE, status, (uint8_t *)words, EM4X50_TAG_MAX_NO_BYTES);
}
// simple change of password
void em4x50_writepwd(em4x50_data_t *etd) {
void em4x50_writepwd(em4x50_data_t *etd, bool ledcontrol) {
int status = PM3_EFAILED;
em4x50_setup_read();
LED_C_ON();
if (ledcontrol) LED_C_ON();
if (get_signalproperties() && find_em4x50_tag()) {
LED_C_OFF();
LED_D_ON();
if (ledcontrol) LED_C_OFF();
if (ledcontrol) LED_D_ON();
// login and change password
if (login(etd->password1) == PM3_SUCCESS) {
status = write_password(etd->password1, etd->password2);
if (status == PM3_ETEAROFF) {
lf_finalize();
lf_finalize(ledcontrol);
return;
}
}
}
LEDsoff();
lf_finalize();
if (ledcontrol) LEDsoff();
lf_finalize(ledcontrol);
reply_ng(CMD_LF_EM4X50_WRITEPWD, status, NULL, 0);
}
@@ -1324,7 +1324,7 @@ static bool em4x50_sim_read_word(uint32_t *word) {
}
// check if reader requests receive mode (rm) by sending two zeros
static int check_rm_request(uint32_t *tag) {
static int check_rm_request(uint32_t *tag, bool ledcontrol) {
// look for first zero
int bit = em4x50_sim_read_bit();
@@ -1334,7 +1334,7 @@ static int check_rm_request(uint32_t *tag) {
bit = em4x50_sim_read_bit();
if (bit == 0) {
LED_C_ON();
if (ledcontrol) LED_C_ON();
// if command before was EM4X50_COMMAND_WRITE_PASSWORD
// switch to separate process
@@ -1353,7 +1353,7 @@ static int check_rm_request(uint32_t *tag) {
}
// send single listen window in simulation mode
static int em4x50_sim_send_listen_window(uint32_t *tag) {
static int em4x50_sim_send_listen_window(uint32_t *tag, bool ledcontrol) {
SHORT_COIL();
wait_cycles(EM4X50_T_TAG_HALF_PERIOD);
@@ -1365,7 +1365,7 @@ static int em4x50_sim_send_listen_window(uint32_t *tag) {
wait_cycles(2 * EM4X50_T_TAG_FULL_PERIOD);
OPEN_COIL();
int command = check_rm_request(tag);
int command = check_rm_request(tag, ledcontrol);
if (command != PM3_SUCCESS) {
return command;
}
@@ -1426,7 +1426,7 @@ static void em4x50_sim_send_nak(void) {
}
// standard read mode process (simulation mode)
static int em4x50_sim_handle_standard_read_command(uint32_t *tag) {
static int em4x50_sim_handle_standard_read_command(uint32_t *tag, bool ledcontrol) {
// extract control data
int fwr = reflect32(tag[EM4X50_CONTROL]) & 0xFF; // first word read
@@ -1441,7 +1441,7 @@ static int em4x50_sim_handle_standard_read_command(uint32_t *tag) {
WDT_HIT();
int res = em4x50_sim_send_listen_window(tag);
int res = em4x50_sim_send_listen_window(tag, ledcontrol);
if (res != PM3_SUCCESS) {
return res;
@@ -1449,7 +1449,7 @@ static int em4x50_sim_handle_standard_read_command(uint32_t *tag) {
for (int i = fwr; i <= lwr; i++) {
res = em4x50_sim_send_listen_window(tag);
res = em4x50_sim_send_listen_window(tag, ledcontrol);
if (res != PM3_SUCCESS) {
return res;
}
@@ -1466,7 +1466,7 @@ static int em4x50_sim_handle_standard_read_command(uint32_t *tag) {
}
// selective read mode process (simulation mode)
static int em4x50_sim_handle_selective_read_command(uint32_t *tag) {
static int em4x50_sim_handle_selective_read_command(uint32_t *tag, bool ledcontrol) {
// read password
uint32_t address = 0;
@@ -1496,14 +1496,14 @@ static int em4x50_sim_handle_selective_read_command(uint32_t *tag) {
WDT_HIT();
int command = em4x50_sim_send_listen_window(tag);
int command = em4x50_sim_send_listen_window(tag, ledcontrol);
if (command != PM3_SUCCESS) {
return command;
}
for (int i = fwr; i <= lwr; i++) {
command = em4x50_sim_send_listen_window(tag);
command = em4x50_sim_send_listen_window(tag, ledcontrol);
if (command != PM3_SUCCESS) {
return command;
}
@@ -1521,7 +1521,7 @@ static int em4x50_sim_handle_selective_read_command(uint32_t *tag) {
}
// login process (simulation mode)
static int em4x50_sim_handle_login_command(uint32_t *tag) {
static int em4x50_sim_handle_login_command(uint32_t *tag, bool ledcontrol) {
// read password
uint32_t password = 0;
@@ -1533,11 +1533,11 @@ static int em4x50_sim_handle_login_command(uint32_t *tag) {
if (pwd && (password == reflect32(tag[EM4X50_DEVICE_PASSWORD]))) {
em4x50_sim_send_ack();
g_Login = true;
LED_D_ON();
if (ledcontrol) LED_D_ON();
} else {
em4x50_sim_send_nak();
g_Login = false;
LED_D_OFF();
if (ledcontrol) LED_D_OFF();
// save transmitted password (to be used in standalone mode)
g_Password = password;
@@ -1547,7 +1547,7 @@ static int em4x50_sim_handle_login_command(uint32_t *tag) {
}
// reset process (simulation mode)
static int em4x50_sim_handle_reset_command(uint32_t *tag) {
static int em4x50_sim_handle_reset_command(uint32_t *tag, bool ledcontrol) {
// processing pause time (corresponds to a "1" bit)
em4x50_sim_send_bit(1);
@@ -1555,7 +1555,7 @@ static int em4x50_sim_handle_reset_command(uint32_t *tag) {
// send ACK
em4x50_sim_send_ack();
g_Login = false;
LED_D_OFF();
if (ledcontrol) LED_D_OFF();
// wait for initialization (tinit)
wait_cycles(EM4X50_T_TAG_TINIT);
@@ -1565,7 +1565,7 @@ static int em4x50_sim_handle_reset_command(uint32_t *tag) {
}
// write process (simulation mode)
static int em4x50_sim_handle_write_command(uint32_t *tag) {
static int em4x50_sim_handle_write_command(uint32_t *tag, bool ledcontrol) {
// read address
uint8_t address = 0;
@@ -1653,12 +1653,12 @@ static int em4x50_sim_handle_write_command(uint32_t *tag) {
// if "read after write" (raw) bit is set, send written data once
if (raw) {
int command = em4x50_sim_send_listen_window(tag);
int command = em4x50_sim_send_listen_window(tag, ledcontrol);
if (command != PM3_SUCCESS) {
return command;
}
command = em4x50_sim_send_listen_window(tag);
command = em4x50_sim_send_listen_window(tag, ledcontrol);
if (command != PM3_SUCCESS) {
return command;
}
@@ -1671,7 +1671,7 @@ static int em4x50_sim_handle_write_command(uint32_t *tag) {
}
// write password process (simulation mode)
static int em4x50_sim_handle_writepwd_command(uint32_t *tag) {
static int em4x50_sim_handle_writepwd_command(uint32_t *tag, bool ledcontrol) {
bool pwd = false;
@@ -1698,7 +1698,7 @@ static int em4x50_sim_handle_writepwd_command(uint32_t *tag) {
return EM4X50_COMMAND_STANDARD_READ;
}
int command = em4x50_sim_send_listen_window(tag);
int command = em4x50_sim_send_listen_window(tag, ledcontrol);
g_WritePasswordProcess = false;
if (command != EM4X50_COMMAND_WRITE_PASSWORD) {
return command;
@@ -1732,33 +1732,33 @@ static int em4x50_sim_handle_writepwd_command(uint32_t *tag) {
return EM4X50_COMMAND_STANDARD_READ;
}
void em4x50_handle_commands(int *command, uint32_t *tag) {
void em4x50_handle_commands(int *command, uint32_t *tag, bool ledcontrol) {
switch (*command) {
case EM4X50_COMMAND_LOGIN:
*command = em4x50_sim_handle_login_command(tag);
*command = em4x50_sim_handle_login_command(tag, ledcontrol);
break;
case EM4X50_COMMAND_RESET:
*command = em4x50_sim_handle_reset_command(tag);
*command = em4x50_sim_handle_reset_command(tag, ledcontrol);
break;
case EM4X50_COMMAND_WRITE:
*command = em4x50_sim_handle_write_command(tag);
*command = em4x50_sim_handle_write_command(tag, ledcontrol);
break;
case EM4X50_COMMAND_WRITE_PASSWORD:
*command = em4x50_sim_handle_writepwd_command(tag);
*command = em4x50_sim_handle_writepwd_command(tag, ledcontrol);
break;
case EM4X50_COMMAND_SELECTIVE_READ:
*command = em4x50_sim_handle_selective_read_command(tag);
*command = em4x50_sim_handle_selective_read_command(tag, ledcontrol);
break;
case EM4X50_COMMAND_STANDARD_READ:
LED_C_OFF();
*command = em4x50_sim_handle_standard_read_command(tag);
if (ledcontrol) LED_C_OFF();
*command = em4x50_sim_handle_standard_read_command(tag, ledcontrol);
break;
// bit errors during reading may lead to unknown commands
@@ -1772,7 +1772,7 @@ void em4x50_handle_commands(int *command, uint32_t *tag) {
// simulate uploaded data in emulator memory
// LED C -> reader command has been detected
// LED D -> operations that require authentication are possible
void em4x50_sim(uint32_t *password) {
void em4x50_sim(uint32_t *password, bool ledcontrol) {
int command = PM3_ENODATA;
@@ -1791,7 +1791,7 @@ void em4x50_sim(uint32_t *password) {
if (tag[EM4X50_DEVICE_SERIAL] != tag[EM4X50_DEVICE_ID]) {
// init
LEDsoff();
if (ledcontrol) LEDsoff();
em4x50_setup_sim();
g_Login = false;
g_WritePasswordProcess = false;
@@ -1801,7 +1801,7 @@ void em4x50_sim(uint32_t *password) {
for (;;) {
em4x50_handle_commands(&command, tag);
em4x50_handle_commands(&command, tag, ledcontrol);
// stop if key (pm3 button or enter key) has been pressed
if (command == PM3_EOPABORTED) {
@@ -1813,12 +1813,12 @@ void em4x50_sim(uint32_t *password) {
if (command == PM3_ETIMEOUT) {
command = EM4X50_COMMAND_STANDARD_READ;
g_Login = false;
LED_D_OFF();
if (ledcontrol) LED_D_OFF();
}
}
}
BigBuf_free();
lf_finalize();
lf_finalize(ledcontrol);
reply_ng(CMD_LF_EM4X50_SIM, command, NULL, 0);
}
+10 -10
View File
@@ -17,16 +17,16 @@ void em4x50_setup_read(void);
int standard_read(int *now, uint32_t *words);
void em4x50_setup_sim(void);
void em4x50_handle_commands(int *command, uint32_t *tag);
void em4x50_handle_commands(int *command, uint32_t *tag, bool ledcontrol);
void em4x50_info(em4x50_data_t *etd);
void em4x50_write(em4x50_data_t *etd);
void em4x50_writepwd(em4x50_data_t *etd);
void em4x50_read(em4x50_data_t *etd);
void em4x50_brute(em4x50_data_t *etd);
void em4x50_login(uint32_t *password);
void em4x50_sim(uint32_t *password);
void em4x50_reader(void);
void em4x50_chk(uint8_t *filename);
void em4x50_info(em4x50_data_t *etd, bool ledcontrol);
void em4x50_write(em4x50_data_t *etd, bool ledcontrol);
void em4x50_writepwd(em4x50_data_t *etd, bool ledcontrol);
void em4x50_read(em4x50_data_t *etd, bool ledcontrol);
void em4x50_brute(em4x50_data_t *etd, bool ledcontrol);
void em4x50_login(uint32_t *password, bool ledcontrol);
void em4x50_sim(uint32_t *password, bool ledcontrol);
void em4x50_reader(bool ledcontrol);
void em4x50_chk(uint8_t *filename, bool ledcontrol);
#endif /* EM4X50_H */
+12 -12
View File
@@ -624,7 +624,7 @@ static int em4x70_receive(uint8_t *bits, size_t length) {
return bit_pos;
}
void em4x70_info(em4x70_data_t *etd) {
void em4x70_info(em4x70_data_t *etd, bool ledcontrol) {
uint8_t status = 0;
@@ -641,11 +641,11 @@ void em4x70_info(em4x70_data_t *etd) {
}
StopTicks();
lf_finalize();
lf_finalize(ledcontrol);
reply_ng(CMD_LF_EM4X70_INFO, status, tag.data, sizeof(tag.data));
}
void em4x70_write(em4x70_data_t *etd) {
void em4x70_write(em4x70_data_t *etd, bool ledcontrol) {
uint8_t status = 0;
@@ -671,11 +671,11 @@ void em4x70_write(em4x70_data_t *etd) {
}
StopTicks();
lf_finalize();
lf_finalize(ledcontrol);
reply_ng(CMD_LF_EM4X70_WRITE, status, tag.data, sizeof(tag.data));
}
void em4x70_unlock(em4x70_data_t *etd) {
void em4x70_unlock(em4x70_data_t *etd, bool ledcontrol) {
uint8_t status = 0;
@@ -704,11 +704,11 @@ void em4x70_unlock(em4x70_data_t *etd) {
}
StopTicks();
lf_finalize();
lf_finalize(ledcontrol);
reply_ng(CMD_LF_EM4X70_UNLOCK, status, tag.data, sizeof(tag.data));
}
void em4x70_auth(em4x70_data_t *etd) {
void em4x70_auth(em4x70_data_t *etd, bool ledcontrol) {
uint8_t status = 0;
uint8_t response[3] = {0};
@@ -726,11 +726,11 @@ void em4x70_auth(em4x70_data_t *etd) {
}
StopTicks();
lf_finalize();
lf_finalize(ledcontrol);
reply_ng(CMD_LF_EM4X70_AUTH, status, response, sizeof(response));
}
void em4x70_write_pin(em4x70_data_t *etd) {
void em4x70_write_pin(em4x70_data_t *etd, bool ledcontrol) {
uint8_t status = 0;
@@ -766,11 +766,11 @@ void em4x70_write_pin(em4x70_data_t *etd) {
}
StopTicks();
lf_finalize();
lf_finalize(ledcontrol);
reply_ng(CMD_LF_EM4X70_WRITEPIN, status, tag.data, sizeof(tag.data));
}
void em4x70_write_key(em4x70_data_t *etd) {
void em4x70_write_key(em4x70_data_t *etd, bool ledcontrol) {
uint8_t status = 0;
@@ -804,6 +804,6 @@ void em4x70_write_key(em4x70_data_t *etd) {
}
StopTicks();
lf_finalize();
lf_finalize(ledcontrol);
reply_ng(CMD_LF_EM4X70_WRITEKEY, status, tag.data, sizeof(tag.data));
}
+6 -6
View File
@@ -22,11 +22,11 @@ typedef enum {
FALLING_EDGE
} edge_detection_t;
void em4x70_info(em4x70_data_t *etd);
void em4x70_write(em4x70_data_t *etd);
void em4x70_unlock(em4x70_data_t *etd);
void em4x70_auth(em4x70_data_t *etd);
void em4x70_write_pin(em4x70_data_t *etd);
void em4x70_write_key(em4x70_data_t *etd);
void em4x70_info(em4x70_data_t *etd, bool ledcontrol);
void em4x70_write(em4x70_data_t *etd, bool ledcontrol);
void em4x70_unlock(em4x70_data_t *etd, bool ledcontrol);
void em4x70_auth(em4x70_data_t *etd, bool ledcontrol);
void em4x70_write_pin(em4x70_data_t *etd, bool ledcontrol);
void em4x70_write_key(em4x70_data_t *etd, bool ledcontrol);
#endif /* EM4x70_H */
+44 -42
View File
@@ -153,8 +153,8 @@ static void hitag2_init(void) {
/*
// sim
static void hitag_send_bit(int bit) {
LED_A_ON();
static void hitag_send_bit(int bit, bool ledcontrol) {
if (ledcontrol) LED_A_ON();
// Reset clock for the next bit
AT91C_BASE_TC0->TC_CCR = AT91C_TC_SWTRG;
@@ -174,7 +174,7 @@ static void hitag_send_bit(int bit) {
LOW(GPIO_SSC_DOUT);
while (AT91C_BASE_TC0->TC_CV < HITAG_T0 * HITAG_T_TAG_FULL_PERIOD);
}
LED_A_OFF();
if (ledcontrol) LED_A_OFF();
}
// sim
@@ -324,9 +324,9 @@ static void hitag2_handle_reader_command(uint8_t *rx, const size_t rxlen, uint8_
// reader/writer
// returns how long it took
static uint32_t hitag_reader_send_bit(int bit) {
static uint32_t hitag_reader_send_bit(int bit, bool ledcontrol) {
uint32_t wait = 0;
LED_A_ON();
if (ledcontrol) LED_A_ON();
// Binary pulse length modulation (BPLM) is used to encode the data stream
// This means that a transmission of a one takes longer than that of a zero
@@ -350,17 +350,17 @@ static uint32_t hitag_reader_send_bit(int bit) {
wait += HITAG_T_1 - HITAG_T_LOW;
}
LED_A_OFF();
if (ledcontrol) LED_A_OFF();
return wait;
}
// reader / writer commands
static uint32_t hitag_reader_send_frame(const uint8_t *frame, size_t frame_len) {
static uint32_t hitag_reader_send_frame(const uint8_t *frame, size_t frame_len, bool ledcontrol) {
uint32_t wait = 0;
// Send the content of the frame
for (size_t i = 0; i < frame_len; i++) {
wait += hitag_reader_send_bit((frame[i / 8] >> (7 - (i % 8))) & 1);
wait += hitag_reader_send_bit((frame[i / 8] >> (7 - (i % 8))) & 1, ledcontrol);
}
// Enable modulation, which means, drop the field
@@ -994,9 +994,9 @@ void EloadHitag(uint8_t *data, uint16_t len) {
// T1 26-32 fc (total time ONE)
// Tstop 36 > fc (high field stop limit)
// Tlow 4-10 fc (reader field low time)
void SniffHitag2(void) {
void SniffHitag2(bool ledcontrol) {
DbpString("Starting Hitag2 sniffing");
LED_D_ON();
if (ledcontrol) LED_D_ON();
FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
@@ -1006,7 +1006,7 @@ void SniffHitag2(void) {
set_tracing(true);
/*
lf_init(false, false);
lf_init(false, false, ledcontrol);
// no logging of the raw signal
g_logging = lf_get_reader_modulation();
@@ -1111,10 +1111,10 @@ void SniffHitag2(void) {
// LogTrace(rx, nbytes(rdr), 0, 0, NULL, true);
// total_count += nbytes(rdr);
}
LED_A_INV();
if (ledcontrol) LED_A_INV();
}
lf_finalize();
lf_finalize(ledcontrol);
Dbprintf("Collected %u bytes", total_count);
@@ -1183,7 +1183,7 @@ void SniffHitag2(void) {
// Shorter periods will only happen with reader frames
if (reader_frame == false && rising_edge && ra < HITAG_T_TAG_CAPTURE_ONE_HALF) {
// Switch from tag to reader capture
LED_C_OFF();
if (ledcontrol) LED_C_OFF();
reader_frame = true;
rxlen = 0;
}
@@ -1199,7 +1199,7 @@ void SniffHitag2(void) {
overflow = 0;
if (reader_frame) {
LED_B_ON();
if (ledcontrol) LED_B_ON();
// Capture reader frame
if (ra >= HITAG_T_STOP) {
// if (rxlen != 0) {
@@ -1218,7 +1218,7 @@ void SniffHitag2(void) {
}
} else {
LED_C_ON();
if (ledcontrol) LED_C_ON();
// Capture tag frame (manchester decoding using only falling edges)
if (ra >= HITAG_T_EOF) {
// if (rxlen != 0) {
@@ -1285,8 +1285,10 @@ void SniffHitag2(void) {
tag_sof = 4;
overflow = 0;
LED_B_OFF();
LED_C_OFF();
if (ledcontrol) {
LED_B_OFF();
LED_C_OFF();
}
} else {
// Save the timer overflow, will be 0 when frame was received
overflow += (AT91C_BASE_TC1->TC_CV / HITAG_T0);
@@ -1301,7 +1303,7 @@ void SniffHitag2(void) {
AT91C_BASE_TCB->TCB_BCR = 1;
}
LEDsoff();
if (ledcontrol) LEDsoff();
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS;
AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKDIS;
@@ -1314,7 +1316,7 @@ void SniffHitag2(void) {
}
// Hitag2 simulation
void SimulateHitag2(void) {
void SimulateHitag2(bool ledcontrol) {
BigBuf_free();
BigBuf_Clear_ext(false);
@@ -1322,7 +1324,7 @@ void SimulateHitag2(void) {
set_tracing(true);
// empties bigbuff etc
lf_init(false, true);
lf_init(false, true, ledcontrol);
int response = 0;
uint8_t rx[HITAG_FRAME_LEN] = {0};
@@ -1367,10 +1369,10 @@ void SimulateHitag2(void) {
// use malloc
initSampleBufferEx(&signal_size, true);
LED_D_ON();
if (ledcontrol) LED_D_ON();
// lf_reset_counter();
LED_A_OFF();
if (ledcontrol) LED_A_OFF();
WDT_HIT();
/*
@@ -1409,7 +1411,7 @@ void SimulateHitag2(void) {
break;
}
LED_A_ON();
if (ledcontrol) LED_A_ON();
// Are we dealing with the first incoming edge
if (waiting_for_first_edge) {
@@ -1448,12 +1450,12 @@ void SimulateHitag2(void) {
}
}
LED_D_OFF();
if (ledcontrol) LED_D_OFF();
// If there is no response, just repeat the loop
if (!detected_modulation) continue;
LED_A_OFF();
if (ledcontrol) LED_A_OFF();
// Make sure we always have an even number of samples. This fixes the problem
// of ending the manchester decoding with a zero. See the example below where
@@ -1466,7 +1468,7 @@ void SimulateHitag2(void) {
nrz_samples[nrzs++] = reader_modulation;
}
LED_B_ON();
if (ledcontrol) LED_B_ON();
// decode bitstream
manrawdecode((uint8_t *)nrz_samples, &nrzs, true, 0);
@@ -1509,7 +1511,7 @@ void SimulateHitag2(void) {
if (txlen) {
// Transmit the tag frame
//hitag_send_frame(tx, txlen);
lf_manchester_send_bytes(tx, txlen);
lf_manchester_send_bytes(tx, txlen, ledcontrol);
// Store the frame in the trace
LogTrace(tx, nbytes(txlen), 0, 0, NULL, false);
@@ -1519,11 +1521,11 @@ void SimulateHitag2(void) {
memset(rx, 0x00, sizeof(rx));
response = 0;
LED_B_OFF();
if (ledcontrol) LED_B_OFF();
}
}
lf_finalize();
lf_finalize(ledcontrol);
// release allocated memory from BigBuff.
BigBuf_free();
@@ -1533,7 +1535,7 @@ void SimulateHitag2(void) {
// reply_ng(CMD_LF_HITAG_SIMULATE, (checked == -1) ? PM3_EOPABORTED : PM3_SUCCESS, (uint8_t *)tag.sectors, tag_size);
}
void ReaderHitag(hitag_function htf, hitag_data *htd) {
void ReaderHitag(hitag_function htf, hitag_data *htd, bool ledcontrol) {
uint32_t command_start = 0, command_duration = 0;
uint32_t response_start = 0, response_duration = 0;
@@ -1644,7 +1646,7 @@ void ReaderHitag(hitag_function htf, hitag_data *htd) {
}
}
LED_D_ON();
if (ledcontrol) LED_D_ON();
// hitag2 state machine?
hitag2_init();
@@ -1677,7 +1679,7 @@ void ReaderHitag(hitag_function htf, hitag_data *htd) {
}
// init as reader
lf_init(true, false);
lf_init(true, false, ledcontrol);
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
uint8_t tag_modulation;
@@ -1762,7 +1764,7 @@ void ReaderHitag(hitag_function htf, hitag_data *htd) {
command_start += t_wait_2;
}
// Transmit the reader frame
command_duration = hitag_reader_send_frame(tx, txlen);
command_duration = hitag_reader_send_frame(tx, txlen, ledcontrol);
response_start = command_start + command_duration;
// Let the antenna and ADC values settle
@@ -1863,7 +1865,7 @@ void ReaderHitag(hitag_function htf, hitag_data *htd) {
nrz_samples[nrzs++] = tag_modulation;
}
LED_B_ON();
if (ledcontrol) LED_B_ON();
// decode bitstream
manrawdecode((uint8_t *)nrz_samples, &nrzs, true, 0);
@@ -1913,7 +1915,7 @@ void ReaderHitag(hitag_function htf, hitag_data *htd) {
}
out:
lf_finalize();
lf_finalize(ledcontrol);
// release allocated memory from BigBuff.
BigBuf_free();
@@ -1924,7 +1926,7 @@ out:
reply_mix(CMD_ACK, bSuccessful, 0, 0, 0, 0);
}
void WriterHitag(hitag_function htf, hitag_data *htd, int page) {
void WriterHitag(hitag_function htf, hitag_data *htd, int page, bool ledcontrol) {
uint32_t command_start = 0;
uint32_t command_duration = 0;
@@ -1986,12 +1988,12 @@ void WriterHitag(hitag_function htf, hitag_data *htd, int page) {
break;
}
LED_D_ON();
if (ledcontrol) LED_D_ON();
hitag2_init();
// init as reader
lf_init(true, false);
lf_init(true, false, ledcontrol);
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
// Tag specific configuration settings (sof, timings, etc.)
@@ -2081,7 +2083,7 @@ void WriterHitag(hitag_function htf, hitag_data *htd, int page) {
}
// Transmit the reader frame
command_duration = hitag_reader_send_frame(tx, txlen);
command_duration = hitag_reader_send_frame(tx, txlen, ledcontrol);
response_start = command_start + command_duration;
@@ -2186,7 +2188,7 @@ void WriterHitag(hitag_function htf, hitag_data *htd, int page) {
nrz_samples[nrzs++] = tag_modulation;
}
LED_B_ON();
if (ledcontrol) LED_B_ON();
// decode bitstream
manrawdecode((uint8_t *)nrz_samples, &nrzs, true, 0);
@@ -2230,7 +2232,7 @@ void WriterHitag(hitag_function htf, hitag_data *htd, int page) {
out:
lf_finalize();
lf_finalize(ledcontrol);
// release allocated memory from BigBuff.
BigBuf_free();
+4 -4
View File
@@ -15,9 +15,9 @@
#include "common.h"
#include "hitag.h"
void SniffHitag2(void);
void SimulateHitag2(void);
void ReaderHitag(hitag_function htf, hitag_data *htd);
void WriterHitag(hitag_function htf, hitag_data *htd, int page);
void SniffHitag2(bool ledcontrol);
void SimulateHitag2(bool ledcontrol);
void ReaderHitag(hitag_function htf, hitag_data *htd, bool ledcontrol);
void WriterHitag(hitag_function htf, hitag_data *htd, int page, bool ledcontrol);
void EloadHitag(uint8_t *data, uint16_t len);
#endif
+37 -37
View File
@@ -119,8 +119,8 @@ static void calc_crc(unsigned char *crc, unsigned char data, unsigned char Bitco
} while (--Bitcount);
}
static void hitag_send_bit(int bit) {
LED_A_ON();
static void hitag_send_bit(int bit, bool ledcontrol) {
if (ledcontrol) LED_A_ON();
// Reset clock for the next bit
AT91C_BASE_TC0->TC_CCR = AT91C_TC_SWTRG;
@@ -149,7 +149,7 @@ static void hitag_send_bit(int bit) {
while (AT91C_BASE_TC0->TC_CV < T0 * 64) {};
}
LED_A_OFF();
if (ledcontrol) LED_A_OFF();
break;
case AC4K:
if (bit == 0) {
@@ -174,7 +174,7 @@ static void hitag_send_bit(int bit) {
LOW(GPIO_SSC_DOUT);
while (AT91C_BASE_TC0->TC_CV < T0 * 32) {};
}
LED_A_OFF();
if (ledcontrol) LED_A_OFF();
break;
case MC4K:
if (bit == 0) {
@@ -194,7 +194,7 @@ static void hitag_send_bit(int bit) {
while (AT91C_BASE_TC0->TC_CV < T0 * 32) {};
}
LED_A_OFF();
if (ledcontrol) LED_A_OFF();
break;
case MC8K:
if (bit == 0) {
@@ -214,14 +214,14 @@ static void hitag_send_bit(int bit) {
while (AT91C_BASE_TC0->TC_CV < T0 * 16) {};
}
LED_A_OFF();
if (ledcontrol) LED_A_OFF();
break;
default:
break;
}
}
static void hitag_send_frame(const uint8_t *frame, size_t frame_len) {
static void hitag_send_frame(const uint8_t *frame, size_t frame_len, bool ledcontrol) {
if (g_dbglevel >= DBG_EXTENDED)
Dbprintf("hitag_send_frame: (%i) %02X %02X %02X %02X", frame_len, frame[0], frame[1], frame[2], frame[3]);
// The beginning of the frame is hidden in some high level; pause until our bits will have an effect
@@ -240,20 +240,20 @@ static void hitag_send_frame(const uint8_t *frame, size_t frame_len) {
// SOF - send start of frame
for (size_t i = 0; i < sof_bits; i++) {
hitag_send_bit(1);
hitag_send_bit(1, ledcontrol);
}
// Send the content of the frame
for (size_t i = 0; i < frame_len; i++) {
hitag_send_bit((frame[i / 8] >> (7 - (i % 8))) & 1);
hitag_send_bit((frame[i / 8] >> (7 - (i % 8))) & 1, ledcontrol);
}
LOW(GPIO_SSC_DOUT);
}
static void hitag_reader_send_bit(int bit) {
static void hitag_reader_send_bit(int bit, bool ledcontrol) {
LED_A_ON();
if (ledcontrol) LED_A_ON();
// Reset clock for the next bit
AT91C_BASE_TC0->TC_CCR = AT91C_TC_SWTRG;
@@ -290,16 +290,16 @@ static void hitag_reader_send_bit(int bit) {
}
#endif
LED_A_OFF();
if (ledcontrol) LED_A_OFF();
}
static void hitag_reader_send_frame(const uint8_t *frame, size_t frame_len) {
static void hitag_reader_send_frame(const uint8_t *frame, size_t frame_len, bool ledcontrol) {
// Send the content of the frame
for (size_t i = 0; i < frame_len; i++) {
// if (frame[0] == 0xf8) {
//Dbprintf("BIT: %d",(frame[i / 8] >> (7 - (i % 8))) & 1);
// }
hitag_reader_send_bit((frame[i / 8] >> (7 - (i % 8))) & 1);
hitag_reader_send_bit((frame[i / 8] >> (7 - (i % 8))) & 1, ledcontrol);
}
// send EOF
AT91C_BASE_TC0->TC_CCR = AT91C_TC_SWTRG;
@@ -852,7 +852,7 @@ static int hitagS_handle_tag_auth(hitag_function htf, uint64_t key, uint64_t NrA
/*
* Emulates a Hitag S Tag with the given data from the .hts file
*/
void SimulateHitagSTag(bool tag_mem_supplied, uint8_t *data) {
void SimulateHitagSTag(bool tag_mem_supplied, uint8_t *data, bool ledcontrol) {
StopTicks();
@@ -877,7 +877,7 @@ void SimulateHitagSTag(bool tag_mem_supplied, uint8_t *data) {
clear_trace();
DbpString("Starting HitagS simulation");
LED_D_ON();
if (ledcontrol) LED_D_ON();
tag.pstate = HT_READY;
tag.tstate = HT_NO_OP;
@@ -1010,7 +1010,7 @@ void SimulateHitagSTag(bool tag_mem_supplied, uint8_t *data) {
// Reset timer every frame, we have to capture the last edge for timing
AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG;
LED_B_ON();
if (ledcontrol) LED_B_ON();
// Capture reader frame
if (ra >= HITAG_T_STOP) {
@@ -1054,7 +1054,7 @@ void SimulateHitagSTag(bool tag_mem_supplied, uint8_t *data) {
// Send and store the tag answer (if there is any)
if (txlen > 0) {
// Transmit the tag frame
hitag_send_frame(tx, txlen);
hitag_send_frame(tx, txlen, ledcontrol);
LogTrace(tx, nbytes(txlen), 0, 0, NULL, false);
}
@@ -1065,7 +1065,7 @@ void SimulateHitagSTag(bool tag_mem_supplied, uint8_t *data) {
memset(rx, 0x00, sizeof(rx));
response = 0;
LED_B_OFF();
if (ledcontrol) LED_B_OFF();
}
// Reset the frame length
rxlen = 0;
@@ -1077,14 +1077,14 @@ void SimulateHitagSTag(bool tag_mem_supplied, uint8_t *data) {
}
set_tracing(false);
lf_finalize();
lf_finalize(ledcontrol);
// release allocated memory from BigBuff.
BigBuf_free();
DbpString("Sim Stopped");
}
static void hitagS_receive_frame(uint8_t *rx, size_t *rxlen, int *response) {
static void hitagS_receive_frame(uint8_t *rx, size_t *rxlen, int *response, bool ledcontrol) {
// Reset values for receiving frames
memset(rx, 0x00, HITAG_FRAME_LEN * sizeof(uint8_t));
@@ -1105,7 +1105,7 @@ static void hitagS_receive_frame(uint8_t *rx, size_t *rxlen, int *response) {
// Reset timer every frame, we have to capture the last edge for timing
AT91C_BASE_TC0->TC_CCR = AT91C_TC_SWTRG;
LED_B_ON();
if (ledcontrol) LED_B_ON();
// Capture tag frame (manchester decoding using only falling edges)
if (ra >= HITAG_T_EOF) {
@@ -1164,7 +1164,7 @@ static void hitagS_receive_frame(uint8_t *rx, size_t *rxlen, int *response) {
* If the key was given the password will be decrypted.
* Reads every page of a hitag S transpoder.
*/
void ReadHitagS(hitag_function htf, hitag_data *htd) {
void ReadHitagS(hitag_function htf, hitag_data *htd, bool ledcontrol) {
StopTicks();
@@ -1227,7 +1227,7 @@ void ReadHitagS(hitag_function htf, hitag_data *htd) {
bQuiet = false;
LED_D_ON();
if (ledcontrol) LED_D_ON();
// Set fpga in edge detect with reader field, we can modulate as reader now
FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_EDGE_DETECT | FPGA_LF_EDGE_DETECT_READER_FIELD);
@@ -1399,7 +1399,7 @@ void ReadHitagS(hitag_function htf, hitag_data *htd) {
while (AT91C_BASE_TC0->TC_CV < T0 * (t_wait + (HITAG_T_TAG_HALF_PERIOD * lastbit))) {};
// Transmit the reader frame
hitag_reader_send_frame(tx, txlen);
hitag_reader_send_frame(tx, txlen, ledcontrol);
// Enable and reset external trigger in timer for capturing future frames
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG;
@@ -1410,12 +1410,12 @@ void ReadHitagS(hitag_function htf, hitag_data *htd) {
LogTrace(tx, nbytes(txlen), HITAG_T_WAIT_2, HITAG_T_WAIT_2, NULL, true);
}
hitagS_receive_frame(rx, &rxlen, &response);
hitagS_receive_frame(rx, &rxlen, &response, ledcontrol);
}
end = false;
set_tracing(false);
lf_finalize();
lf_finalize(ledcontrol);
reply_mix(CMD_ACK, bSuccessful, 0, 0, 0, 0);
}
@@ -1423,7 +1423,7 @@ void ReadHitagS(hitag_function htf, hitag_data *htd) {
* Authenticates to the Tag with the given Key or Challenge.
* Writes the given 32Bit data into page_
*/
void WritePageHitagS(hitag_function htf, hitag_data *htd, int page) {
void WritePageHitagS(hitag_function htf, hitag_data *htd, int page, bool ledcontrol) {
StopTicks();
@@ -1484,7 +1484,7 @@ void WritePageHitagS(hitag_function htf, hitag_data *htd, int page) {
tag.pstate = HT_READY;
tag.tstate = HT_NO_OP;
LED_D_ON();
if (ledcontrol) LED_D_ON();
// Configure output and enable pin that is connected to the FPGA (for modulating)
AT91C_BASE_PIOA->PIO_OER = GPIO_SSC_DOUT;
@@ -1614,7 +1614,7 @@ void WritePageHitagS(hitag_function htf, hitag_data *htd, int page) {
while (AT91C_BASE_TC0->TC_CV < T0 * (t_wait + (HITAG_T_TAG_HALF_PERIOD * lastbit))) {};
// Transmit the reader frame
hitag_reader_send_frame(tx, txlen);
hitag_reader_send_frame(tx, txlen, ledcontrol);
// Enable and reset external trigger in timer for capturing future frames
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG;
@@ -1625,13 +1625,13 @@ void WritePageHitagS(hitag_function htf, hitag_data *htd, int page) {
LogTrace(tx, nbytes(txlen), HITAG_T_WAIT_2, HITAG_T_WAIT_2, NULL, true);
}
hitagS_receive_frame(rx, &rxlen, &response);
hitagS_receive_frame(rx, &rxlen, &response, ledcontrol);
}
end = false;
set_tracing(false);
lf_finalize();
lf_finalize(ledcontrol);
reply_mix(CMD_ACK, bSuccessful, 0, 0, 0, 0);
}
@@ -1643,7 +1643,7 @@ void WritePageHitagS(hitag_function htf, hitag_data *htd, int page) {
* is not received correctly due to Antenna problems. This function
* detects these challenges.
*/
void check_challenges(bool file_given, uint8_t *data) {
void check_challenges(bool file_given, uint8_t *data, bool ledcontrol) {
int i, j, z, k;
// int frame_count = 0;
int response = 0;
@@ -1671,7 +1671,7 @@ void check_challenges(bool file_given, uint8_t *data) {
bQuiet = false;
LED_D_ON();
if (ledcontrol) LED_D_ON();
// Configure output and enable pin that is connected to the FPGA (for modulating)
AT91C_BASE_PIOA->PIO_OER = GPIO_SSC_DOUT;
@@ -1853,7 +1853,7 @@ void check_challenges(bool file_given, uint8_t *data) {
while (AT91C_BASE_TC0->TC_CV < T0 * (t_wait + (HITAG_T_TAG_HALF_PERIOD * lastbit))) {};
// Transmit the reader frame
hitag_reader_send_frame(tx, txlen);
hitag_reader_send_frame(tx, txlen, ledcontrol);
// Enable and reset external trigger in timer for capturing future frames
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG;
@@ -1864,10 +1864,10 @@ void check_challenges(bool file_given, uint8_t *data) {
LogTrace(tx, nbytes(txlen), HITAG_T_WAIT_2, HITAG_T_WAIT_2, NULL, true);
}
hitagS_receive_frame(rx, &rxlen, &response);
hitagS_receive_frame(rx, &rxlen, &response, ledcontrol);
}
set_tracing(false);
lf_finalize();
lf_finalize(ledcontrol);
reply_mix(CMD_ACK, bSuccessful, 0, 0, 0, 0);
}
+4 -4
View File
@@ -16,9 +16,9 @@
#include "hitag.h"
void SimulateHitagSTag(bool tag_mem_supplied, uint8_t *data);
void ReadHitagS(hitag_function htf, hitag_data *htd);
void WritePageHitagS(hitag_function htf, hitag_data *htd, int page);
void check_challenges(bool file_given, uint8_t *data);
void SimulateHitagSTag(bool tag_mem_supplied, uint8_t *data, bool ledcontrol);
void ReadHitagS(hitag_function htf, hitag_data *htd, bool ledcontrol);
void WritePageHitagS(hitag_function htf, hitag_data *htd, int page, bool ledcontrol);
void check_challenges(bool file_given, uint8_t *data, bool ledcontrol);
#endif
+7 -7
View File
@@ -186,7 +186,7 @@ void lf_wait_periods(size_t periods) {
lf_count_edge_periods_ex(periods, true, false);
}
void lf_init(bool reader, bool simulate) {
void lf_init(bool reader, bool simulate, bool ledcontrol) {
StopTicks();
@@ -240,7 +240,7 @@ void lf_init(bool reader, bool simulate) {
AT91C_BASE_TC1->TC_CMR = AT91C_TC_CLKS_TIMER_DIV4_CLOCK;
// Clear all leds
LEDsoff();
if (ledcontrol) LEDsoff();
// Reset and enable timers
AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG;
@@ -258,7 +258,7 @@ void lf_init(bool reader, bool simulate) {
lf_sample_mean();
}
void lf_finalize(void) {
void lf_finalize(bool ledcontrol) {
// Disable timers
AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKDIS;
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS;
@@ -269,7 +269,7 @@ void lf_finalize(void) {
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
LEDsoff();
if (ledcontrol) LEDsoff();
StartTicks();
}
@@ -329,9 +329,9 @@ static void lf_manchester_send_bit(uint8_t bit) {
}
// simulation
bool lf_manchester_send_bytes(const uint8_t *frame, size_t frame_len) {
bool lf_manchester_send_bytes(const uint8_t *frame, size_t frame_len, bool ledcontrol) {
LED_B_ON();
if (ledcontrol) LED_B_ON();
lf_manchester_send_bit(1);
lf_manchester_send_bit(1);
@@ -344,6 +344,6 @@ bool lf_manchester_send_bytes(const uint8_t *frame, size_t frame_len) {
lf_manchester_send_bit((frame[i / 8] >> (7 - (i % 8))) & 1);
}
LED_B_OFF();
if (ledcontrol) LED_B_OFF();
return true;
}
+3 -3
View File
@@ -29,11 +29,11 @@ bool lf_get_reader_modulation(void);
void lf_wait_periods(size_t periods);
//void lf_init(bool reader);
void lf_init(bool reader, bool simulate);
void lf_finalize(void);
void lf_init(bool reader, bool simulate, bool ledcontrol);
void lf_finalize(bool ledcontrol);
size_t lf_detect_field_drop(size_t max);
bool lf_manchester_send_bytes(const uint8_t *frame, size_t frame_len);
bool lf_manchester_send_bytes(const uint8_t *frame, size_t frame_len, bool ledcontrol);
void lf_modulation(bool modulation);
#endif // __LFADC_H__

Some files were not shown because too many files have changed in this diff Show More