make style

This commit is contained in:
Philippe Teuwen 2019-04-06 19:09:01 +02:00
parent 05b4b27823
commit 41f36ca20b
13 changed files with 89 additions and 89 deletions

View file

@ -1140,24 +1140,24 @@ void SimulateIso14443aTag(int tagType, int flags, uint8_t *data) {
AddCrc14A(emdata, len); AddCrc14A(emdata, len);
EmSendCmd(emdata, len + 2); EmSendCmd(emdata, len + 2);
p_response = NULL; p_response = NULL;
} else if ((receivedCmd[0] == MIFARE_ULC_WRITE || receivedCmd[0] == MIFARE_ULC_COMP_WRITE) && (tagType == 2 || tagType == 7)) { // Received a WRITE } else if ((receivedCmd[0] == MIFARE_ULC_WRITE || receivedCmd[0] == MIFARE_ULC_COMP_WRITE) && (tagType == 2 || tagType == 7)) { // Received a WRITE
// cmd + block + 4/16 bytes data + 2 bytes crc // cmd + block + 4/16 bytes data + 2 bytes crc
if (len == 8 || len == 20) { if (len == 8 || len == 20) {
bool isCrcCorrect = CheckCrc14A(receivedCmd, len); bool isCrcCorrect = CheckCrc14A(receivedCmd, len);
if (isCrcCorrect) { if (isCrcCorrect) {
int block = receivedCmd[1] + 12; // first 12 blocks of emu are [getversion answer - check tearing - pack - 0x00 - signature] int block = receivedCmd[1] + 12; // first 12 blocks of emu are [getversion answer - check tearing - pack - 0x00 - signature]
emlSetMem_xt(&receivedCmd[2], block, 1, 4); emlSetMem_xt(&receivedCmd[2], block, 1, 4);
// send ACK // send ACK
EmSend4bit(CARD_ACK); EmSend4bit(CARD_ACK);
} else { } else {
// send NACK 0x1 == crc/parity error // send NACK 0x1 == crc/parity error
EmSend4bit(CARD_NACK_PA); EmSend4bit(CARD_NACK_PA);
} }
} else { } else {
// send NACK 0x0 == invalid argument // send NACK 0x0 == invalid argument
EmSend4bit(CARD_NACK_IV); EmSend4bit(CARD_NACK_IV);
} }
p_response = NULL; p_response = NULL;
} else if (receivedCmd[0] == MIFARE_ULEV1_READSIG && tagType == 7) { // Received a READ SIGNATURE -- } else if (receivedCmd[0] == MIFARE_ULEV1_READSIG && tagType == 7) { // Received a READ SIGNATURE --
// first 12 blocks of emu are [getversion answer - check tearing - pack - 0x00 - signature] // first 12 blocks of emu are [getversion answer - check tearing - pack - 0x00 - signature]
uint16_t start = 4 * 4; uint16_t start = 4 * 4;

View file

@ -106,7 +106,7 @@ typedef struct {
#ifndef CheckCrc14A #ifndef CheckCrc14A
# define CheckCrc14A(data, len) check_crc(CRC_14443_A, (data), (len)) # define CheckCrc14A(data, len) check_crc(CRC_14443_A, (data), (len))
#endif #endif
void GetParity(const uint8_t *pbtCmd, uint16_t len, uint8_t *par); void GetParity(const uint8_t *pbtCmd, uint16_t len, uint8_t *par);

View file

@ -540,7 +540,7 @@ size_t CreateAPDU(uint8_t *datain, size_t len, uint8_t *dataout) {
uint8_t cmd[cmdlen]; uint8_t cmd[cmdlen];
memset(cmd, 0, cmdlen); memset(cmd, 0, cmdlen);
cmd[0] = 0x0A; // 0x0A = send cid, 0x02 = no cid. cmd[0] = 0x0A; // 0x0A = send cid, 0x02 = no cid.
cmd[0] |= pcb_blocknum; // OR the block number into the PCB cmd[0] |= pcb_blocknum; // OR the block number into the PCB
cmd[1] = 0x00; // CID: 0x00 //TODO: allow multiple selected cards cmd[1] = 0x00; // CID: 0x00 //TODO: allow multiple selected cards

View file

@ -41,4 +41,4 @@ extern void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t arg2, u
// 18 * 8 data bits, 18 * 1 parity bits, 5 start bits, 5 stop bits, 5 correction bits -> need 177 bytes buffer // 18 * 8 data bits, 18 * 1 parity bits, 5 start bits, 5 stop bits, 5 correction bits -> need 177 bytes buffer
#define ALLOCATED_TAG_MODULATION_BUFFER_SIZE 512 // number of bytes required for precompiled response #define ALLOCATED_TAG_MODULATION_BUFFER_SIZE 512 // number of bytes required for precompiled response
#endif #endif

View file

@ -848,7 +848,7 @@ int CmdHF15Restore(const char *Cmd) {
} }
PrintAndLogEx(INFO, "Restoring data blocks."); PrintAndLogEx(INFO, "Restoring data blocks.");
while (1) { while (1) {
tried = 0; tried = 0;
hex[0] = 0x00; hex[0] = 0x00;

View file

@ -1060,7 +1060,7 @@ int CmdHF14AMfRestore(const char *Cmd) {
} }
} }
fclose(fdump); fclose(fdump);
PrintAndLogEx(INFO, "Finish restore"); PrintAndLogEx(INFO, "Finish restore");
return 0; return 0;
} }

View file

@ -2221,7 +2221,7 @@ int CmdHF14AMfURestore(const char *Cmd) {
DropField(); DropField();
free(dump); free(dump);
PrintAndLogEx(INFO, "Finish restore"); PrintAndLogEx(INFO, "Finish restore");
return 0; return 0;
} }
// //

View file

@ -547,7 +547,7 @@ int CmdT55xxDetect(const char *Cmd) {
} }
if (!tryDetectModulation()) if (!tryDetectModulation())
PrintAndLogEx(WARNING, "Could not detect modulation automatically. Try setting it manually with " _YELLOW_("\'lf t55xx config\'") ); PrintAndLogEx(WARNING, "Could not detect modulation automatically. Try setting it manually with " _YELLOW_("\'lf t55xx config\'"));
return 0; return 0;
} }
@ -767,7 +767,7 @@ bool GetT55xxBlockData(uint32_t *blockdata) {
return false; return false;
uint8_t idx = config.offset; uint8_t idx = config.offset;
if (idx + 32 > DemodBufferLen) { if (idx + 32 > DemodBufferLen) {
PrintAndLogEx(WARNING, "The configured offset %d is too big. Possible offset: %d)", idx, DemodBufferLen - 32); PrintAndLogEx(WARNING, "The configured offset %d is too big. Possible offset: %d)", idx, DemodBufferLen - 32);
return false; return false;
@ -1472,7 +1472,7 @@ int CmdT55xxInfo(const char *Cmd) {
if (((!gotdata) && (!config.Q5)) || (gotdata && (!dataasq5))) if (((!gotdata) && (!config.Q5)) || (gotdata && (!dataasq5)))
printT5x7KnownBlock0(block0); printT5x7KnownBlock0(block0);
PrintAndLogEx(NORMAL, "-------------------------------------------------------------"); PrintAndLogEx(NORMAL, "-------------------------------------------------------------");
return 0; return 0;

View file

@ -702,46 +702,46 @@ static int l_keygen_algoD(lua_State *L) {
} }
/* /*
Read T55Xx block. Read T55Xx block.
param1 uint8_t block param1 uint8_t block
param2 bool page1 param2 bool page1
param3 bool override param3 bool override
param4 uint32_t password param4 uint32_t password
*/ */
static int l_T55xx_readblock(lua_State *L) { static int l_T55xx_readblock(lua_State *L) {
//Check number of arguments //Check number of arguments
int n = lua_gettop(L); int n = lua_gettop(L);
if ( n != 4 ) { if (n != 4) {
return returnToLuaWithError(L, "Wrong number of arguments, got %d bytes, expected 4", n); return returnToLuaWithError(L, "Wrong number of arguments, got %d bytes, expected 4", n);
} }
uint32_t block, usepage1, override, password; uint32_t block, usepage1, override, password;
bool usepwd; bool usepwd;
size_t size; size_t size;
const char *p_blockno = luaL_checklstring(L, 1, &size); const char *p_blockno = luaL_checklstring(L, 1, &size);
if (size < 1 || size > 2) return returnToLuaWithError(L, "Wrong size of blockNo, got %d, expected 1 or 2", (int) size); if (size < 1 || size > 2) return returnToLuaWithError(L, "Wrong size of blockNo, got %d, expected 1 or 2", (int) size);
sscanf(p_blockno, "%x", &block); sscanf(p_blockno, "%x", &block);
const char *p_usepage1 = luaL_checklstring(L, 2, &size); const char *p_usepage1 = luaL_checklstring(L, 2, &size);
if (size != 1) return returnToLuaWithError(L, "Wrong size of usePage1, got %d, expected 1", (int) size); if (size != 1) return returnToLuaWithError(L, "Wrong size of usePage1, got %d, expected 1", (int) size);
sscanf(p_usepage1, "%x", &usepage1); sscanf(p_usepage1, "%x", &usepage1);
const char *p_override = luaL_checklstring(L, 3, &size); const char *p_override = luaL_checklstring(L, 3, &size);
if (size != 1) return returnToLuaWithError(L, "Wrong size of override, got %d, expected 1", (int) size); if (size != 1) return returnToLuaWithError(L, "Wrong size of override, got %d, expected 1", (int) size);
sscanf(p_override, "%x", &override); sscanf(p_override, "%x", &override);
const char *p_pwd = luaL_checklstring(L, 4, &size); const char *p_pwd = luaL_checklstring(L, 4, &size);
if ( size == 0 ) { if (size == 0) {
usepwd = false; usepwd = false;
} else { } else {
if (size != 8) return returnToLuaWithError(L, "Wrong size of pwd, got %d , expected 8", (int) size); if (size != 8) return returnToLuaWithError(L, "Wrong size of pwd, got %d , expected 8", (int) size);
sscanf(p_pwd, "%08x", &password); sscanf(p_pwd, "%08x", &password);
usepwd = true; usepwd = true;
} }
//Password mode //Password mode
if (usepwd) { if (usepwd) {
// try reading the config block and verify that PWD bit is set before doing this! // try reading the config block and verify that PWD bit is set before doing this!
@ -767,16 +767,16 @@ static int l_T55xx_readblock(lua_State *L) {
if (!AquireData(usepage1, block, usepwd, password)) { if (!AquireData(usepage1, block, usepwd, password)) {
return returnToLuaWithError(L, "Failed to aquire data from card"); return returnToLuaWithError(L, "Failed to aquire data from card");
} }
if (!DecodeT55xxBlock()) { if (!DecodeT55xxBlock()) {
return returnToLuaWithError(L, "Failed to decode signal"); return returnToLuaWithError(L, "Failed to decode signal");
} }
uint32_t blockData = 0; uint32_t blockData = 0;
if (GetT55xxBlockData(&blockData) == false) { if (GetT55xxBlockData(&blockData) == false) {
return returnToLuaWithError(L, "Failed to get actual data"); return returnToLuaWithError(L, "Failed to get actual data");
} }
lua_pushunsigned(L, blockData); lua_pushunsigned(L, blockData);
return 1; return 1;
} }
@ -787,7 +787,7 @@ static int l_T55xx_detect(lua_State *L) {
bool useGB = false, usepwd = false, isok; bool useGB = false, usepwd = false, isok;
uint32_t gb, password = 0; uint32_t gb, password = 0;
size_t size; size_t size;
//Check number of arguments //Check number of arguments
int n = lua_gettop(L); int n = lua_gettop(L);
@ -796,15 +796,15 @@ static int l_T55xx_detect(lua_State *L) {
const char *p_gb = luaL_checklstring(L, 2, &size); const char *p_gb = luaL_checklstring(L, 2, &size);
if (size != 1) return returnToLuaWithError(L, "Wrong size of useGB, got %d , expected 1", (int) size); if (size != 1) return returnToLuaWithError(L, "Wrong size of useGB, got %d , expected 1", (int) size);
sscanf(p_gb, "%u", &gb); sscanf(p_gb, "%u", &gb);
useGB = ( gb ) ? true : false; useGB = (gb) ? true : false;
printf("p_gb size %zu | %c \n", size, useGB ? 'Y':'N'); printf("p_gb size %zu | %c \n", size, useGB ? 'Y' : 'N');
} }
case 1: { case 1: {
const char *p_pwd = luaL_checklstring(L, 1, &size); const char *p_pwd = luaL_checklstring(L, 1, &size);
if ( size == 0 ) { if (size == 0) {
usepwd = false; usepwd = false;
} else { } else {
if (size != 8) return returnToLuaWithError(L, "Wrong size of pwd, got %d , expected 8", (int) size); if (size != 8) return returnToLuaWithError(L, "Wrong size of pwd, got %d , expected 8", (int) size);
sscanf(p_pwd, "%08x", &password); sscanf(p_pwd, "%08x", &password);
usepwd = true; usepwd = true;
@ -814,24 +814,24 @@ static int l_T55xx_detect(lua_State *L) {
default : default :
break; break;
} }
if (!useGB) { if (!useGB) {
isok = AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, usepwd, password); isok = AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, usepwd, password);
if ( isok == false ) { if (isok == false) {
// signal error by returning Nil, errorstring // signal error by returning Nil, errorstring
lua_pushnil(L); lua_pushnil(L);
lua_pushstring(L, "Failed to aquire LF signal data"); lua_pushstring(L, "Failed to aquire LF signal data");
return 2; return 2;
} }
} }
isok = tryDetectModulation(); isok = tryDetectModulation();
if ( isok == false ) { if (isok == false) {
// signal error by returning Nil, errorstring // signal error by returning Nil, errorstring
lua_pushnil(L); lua_pushnil(L);
lua_pushstring(L, "Could not detect modulation automatically. Try setting it manually with \'lf t55xx config\'"); lua_pushstring(L, "Could not detect modulation automatically. Try setting it manually with \'lf t55xx config\'");
return 2; return 2;
} }
lua_pushinteger(L, isok); lua_pushinteger(L, isok);

View file

@ -44,7 +44,7 @@ local DEBUG = false -- the debug flag
local total_tests = 0 local total_tests = 0
local total_pass = 0 local total_pass = 0
local data_blocks_cmds = { local data_blocks_cmds = {
[1] = '00000000', [1] = '00000000',
[2] = 'ffffffff', [2] = 'ffffffff',
[3] = '80000000', [3] = '80000000',
@ -96,10 +96,10 @@ end
local function GetConfigs( modulation ) local function GetConfigs( modulation )
local t = {} local t = {}
t['PSK1'] = { t['PSK1'] = {
[1] = '00001040', [1] = '00001040',
[2] = '00041040', [2] = '00041040',
[3] = '00081040', [3] = '00081040',
[4] = '000c1040', [4] = '000c1040',
[5] = '00101040', [5] = '00101040',
@ -118,7 +118,7 @@ local function GetConfigs( modulation )
[7] = '00182040', [7] = '00182040',
[8] = '001c2040', [8] = '001c2040',
} }
t['PSK3'] = { t['PSK3'] = {
[1] = '00003040', [1] = '00003040',
[2] = '00043040', [2] = '00043040',
@ -141,7 +141,7 @@ local function GetConfigs( modulation )
[8] = '00184040', [8] = '00184040',
[9] = '001c4040', [9] = '001c4040',
} }
t['FSK2'] = { t['FSK2'] = {
[1] = '00005040', [1] = '00005040',
[2] = '00045040', [2] = '00045040',
@ -152,7 +152,7 @@ local function GetConfigs( modulation )
[7] = '00185040', [7] = '00185040',
[8] = '001c5040', [8] = '001c5040',
} }
t['FSK1A'] = { t['FSK1A'] = {
[1] = '00006040', [1] = '00006040',
[2] = '00046040', [2] = '00046040',
@ -163,7 +163,7 @@ local function GetConfigs( modulation )
[7] = '00186040', [7] = '00186040',
[8] = '001c6040', [8] = '001c6040',
} }
t['FSK2A'] = { t['FSK2A'] = {
[1] = '00007040', [1] = '00007040',
[2] = '00047040', [2] = '00047040',
@ -174,10 +174,10 @@ local function GetConfigs( modulation )
[7] = '00187040', [7] = '00187040',
[8] = '001c7040', [8] = '001c7040',
} }
t['ASK'] = { t['ASK'] = {
[1] = '00008040', [1] = '00008040',
[2] = '00048040', [2] = '00048040',
[3] = '00088040', [3] = '00088040',
[4] = '000c8040', [4] = '000c8040',
[5] = '00108040', [5] = '00108040',
@ -185,7 +185,7 @@ local function GetConfigs( modulation )
[7] = '00188040', [7] = '00188040',
[8] = '001c8040', [8] = '001c8040',
} }
t['BI'] = { t['BI'] = {
[1] = '00010040', [1] = '00010040',
[2] = '00050040', [2] = '00050040',
@ -196,7 +196,7 @@ local function GetConfigs( modulation )
[7] = '00190040', [7] = '00190040',
[8] = '001d0040', [8] = '001d0040',
} }
return t[modulation:upper()] return t[modulation:upper()]
end end
--- ---
@ -205,10 +205,10 @@ local function WipeCard()
print('Wiping card') print('Wiping card')
core.console('lf t55xx wipe') core.console('lf t55xx wipe')
print('Detecting card') print('Detecting card')
local res, msg = core.t55xx_detect() local res, msg = core.t55xx_detect()
if not res then if not res then
oops("Can't detect modulation. Test failed.") oops("Can't detect modulation. Test failed.")
core.console("rem [ERR:DETECT:WIPED] Failed to detect after wipe") core.console("rem [ERR:DETECT:WIPED] Failed to detect after wipe")
return false return false
@ -235,20 +235,20 @@ local function CheckReadBlock(block)
end end
local function test(modulation) local function test(modulation)
local process_block0_cmds = {} local process_block0_cmds = {}
local y local y
local block = "00" local block = "00"
local s = ('Start test of %s'):format(modulation) local s = ('Start test of %s'):format(modulation)
print(s) print(s)
process_block0_cmds = GetConfigs(modulation) process_block0_cmds = GetConfigs(modulation)
if process_block0_cmds == nil then return oops('Cant find modulation '..modulation) end if process_block0_cmds == nil then return oops('Cant find modulation '..modulation) end
for _ = 1, #process_block0_cmds do for _ = 1, #process_block0_cmds do
local p_config_cmd = process_block0_cmds[_] local p_config_cmd = process_block0_cmds[_]
local errors = 0 local errors = 0
core.clearCommandBuffer() core.clearCommandBuffer()
@ -261,9 +261,9 @@ local function test(modulation)
if err then return oops(err) end if err then return oops(err) end
local response = core.WaitForResponseTimeout(cmds.CMD_ACK,TIMEOUT) local response = core.WaitForResponseTimeout(cmds.CMD_ACK,TIMEOUT)
-- Detect -- Detect
local res, msg = core.t55xx_detect() local res, msg = core.t55xx_detect()
if not res then if not res then
print("can't detect modulation, skip to next config") print("can't detect modulation, skip to next config")
core.console(format("rem [ERR:DETECT:%s] Failed to detect modulation", p_config_cmd)) core.console(format("rem [ERR:DETECT:%s] Failed to detect modulation", p_config_cmd))
core.console(format('rem [SUMMARY:%s] FAIL detection', p_config_cmd)) core.console(format('rem [SUMMARY:%s] FAIL detection', p_config_cmd))
@ -304,11 +304,11 @@ local function main(args)
core.clearCommandBuffer() core.clearCommandBuffer()
local res local res
-- Adjust this table to set which configurations should be tested -- Adjust this table to set which configurations should be tested
-- local test_modes = { 'PSK1', 'PSK2', 'PSK3', 'FSK1', 'FSK2', 'FSK1A', 'FSK2A', 'ASK', 'BI' } -- local test_modes = { 'PSK1', 'PSK2', 'PSK3', 'FSK1', 'FSK2', 'FSK1A', 'FSK2A', 'ASK', 'BI' }
local test_modes = { 'ASK', 'PSK1' } local test_modes = { 'ASK', 'PSK1' }
for _ = 1, #test_modes do for _ = 1, #test_modes do
res = WipeCard() res = WipeCard()
if res then if res then
@ -322,6 +322,6 @@ local function main(args)
exitMsg('Tests finished') exitMsg('Tests finished')
core.console( format('rem [SUMMARY] Success rate: %d/%d tests passed%s', total_pass, total_tests, total_pass < total_tests and ", help me improving that number!" or " \\o/")) core.console( format('rem [SUMMARY] Success rate: %d/%d tests passed%s', total_pass, total_tests, total_pass < total_tests and ", help me improving that number!" or " \\o/"))
end end
main(args) main(args)

View file

@ -200,8 +200,8 @@ int FillBuffer(uint8_t *data, size_t maxDataLength, size_t *dataLength, ...);
bool CheckStringIsHEXValue(const char *value); bool CheckStringIsHEXValue(const char *value);
void hex_to_buffer(const uint8_t *buf, const uint8_t *hex_data, const size_t hex_len, void hex_to_buffer(const uint8_t *buf, const uint8_t *hex_data, const size_t hex_len,
const size_t hex_max_len, const size_t min_str_len, const size_t spaces_between, const size_t hex_max_len, const size_t min_str_len, const size_t spaces_between,
bool uppercase); bool uppercase);
void print_hex(const uint8_t *data, const size_t len); void print_hex(const uint8_t *data, const size_t len);
void print_hex_break(const uint8_t *data, const size_t len, const uint8_t breaks); void print_hex_break(const uint8_t *data, const size_t len, const uint8_t breaks);

View file

@ -65,13 +65,13 @@ uint32_t CRC8Legic(uint8_t *buff, size_t size);
/* Static initialization of a crc structure */ /* Static initialization of a crc structure */
#define CRC_INITIALIZER(_order, _polynom, _initial_value, _final_xor) { \ #define CRC_INITIALIZER(_order, _polynom, _initial_value, _final_xor) { \
.state = ((_initial_value) & ((1L<<(_order))-1)), \ .state = ((_initial_value) & ((1L<<(_order))-1)), \
.order = (_order), \ .order = (_order), \
.polynom = (_polynom), \ .polynom = (_polynom), \
.initial_value = (_initial_value), \ .initial_value = (_initial_value), \
.final_xor = (_final_xor), \ .final_xor = (_final_xor), \
.mask = ((1L<<(_order))-1) \ .mask = ((1L<<(_order))-1) \
.refin = false, \ .refin = false, \
.refout = false \ .refout = false \
} }
#endif /* __CRC_H */ #endif /* __CRC_H */

View file

@ -1620,7 +1620,7 @@ int nrzRawDemod(uint8_t *dest, size_t *size, int *clk, int *invert, int *startId
if (g_debugMode == 2) prnt("DEBUG nrzRawDemod: just noise detected - quitting"); if (g_debugMode == 2) prnt("DEBUG nrzRawDemod: just noise detected - quitting");
return -1; return -1;
} }
size_t clkStartIdx = 0; size_t clkStartIdx = 0;
*clk = DetectNRZClock(dest, *size, *clk, &clkStartIdx); *clk = DetectNRZClock(dest, *size, *clk, &clkStartIdx);
if (*clk == 0) return -2; if (*clk == 0) return -2;
@ -1911,13 +1911,13 @@ int pskRawDemod_ext(uint8_t *dest, size_t *size, int *clock, int *invert, int *s
if (waveLenCnt > fc) { if (waveLenCnt > fc) {
//this wave is a phase shift //this wave is a phase shift
/* /*
prnt("DEBUG: phase shift at: %d, len: %d, nextClk: %d, i: %d, fc: %d" prnt("DEBUG: phase shift at: %d, len: %d, nextClk: %d, i: %d, fc: %d"
, waveStart , waveStart
, waveLenCnt , waveLenCnt
, lastClkBit + *clock - tol , lastClkBit + *clock - tol
, i + 1 , i + 1
, fc); , fc);
*/ */
if (i + 1 >= lastClkBit + *clock - tol) { //should be a clock bit if (i + 1 >= lastClkBit + *clock - tol) { //should be a clock bit
curPhase ^= 1; curPhase ^= 1;
dest[numBits++] = curPhase; dest[numBits++] = curPhase;