remove some cppcheck warnings

This commit is contained in:
Philippe Teuwen
2019-06-12 06:41:23 -07:00
parent dd9005719a
commit 1ebfa897c8
24 changed files with 145 additions and 146 deletions

View File

@@ -387,19 +387,19 @@ void RunMod() {
LED_B_ON(); // green
// assuming arg0==0, use hardcoded uid 0xdeadbeaf
uint16_t flags;
uint16_t simflags;
switch (p_card.uidlen) {
case 10:
flags = FLAG_10B_UID_IN_DATA;
simflags = FLAG_10B_UID_IN_DATA;
break;
case 7:
flags = FLAG_7B_UID_IN_DATA;
simflags = FLAG_7B_UID_IN_DATA;
break;
default:
flags = FLAG_4B_UID_IN_DATA;
simflags = FLAG_4B_UID_IN_DATA;
break;
}
Mifare1ksim(flags | FLAG_MF_1K, 0, uid);
Mifare1ksim(simflags | FLAG_MF_1K, 0, uid);
LED_B_OFF();
/*

View File

@@ -89,6 +89,8 @@ void cmac(const desfirekey_t key, uint8_t *ivect, const uint8_t *data, size_t le
}
size_t key_block_size(const desfirekey_t key) {
if (key == NULL)
return 0;
size_t block_size = 8;
switch (key->type) {
case T_DES:

View File

@@ -685,7 +685,7 @@ void SniffHitag(void) {
StopTicks();
int frame_count;
// int frame_count;
int response;
int overflow;
bool rising_edge;
@@ -743,7 +743,7 @@ void SniffHitag(void) {
// Reset the received frame, frame count and timing info
memset(rx, 0x00, sizeof(rx));
frame_count = 0;
// frame_count = 0;
response = 0;
overflow = 0;
reader_frame = false;
@@ -850,7 +850,7 @@ void SniffHitag(void) {
// Check if frame was captured
if (rxlen > 0) {
frame_count++;
// frame_count++;
LogTrace(rx, nbytes(rxlen), response, 0, NULL, reader_frame);
// Check if we recognize a valid authentication attempt
@@ -901,7 +901,8 @@ void SimulateHitagTag(bool tag_mem_supplied, uint8_t *data) {
StopTicks();
int frame_count = 0, response = 0, overflow = 0;
// int frame_count = 0;
int response = 0, overflow = 0;
uint8_t rx[HITAG_FRAME_LEN];
size_t rxlen = 0;
uint8_t tx[HITAG_FRAME_LEN];
@@ -915,7 +916,7 @@ void SimulateHitagTag(bool tag_mem_supplied, uint8_t *data) {
auth_table_len = 0;
auth_table_pos = 0;
uint8_t *auth_table = BigBuf_malloc(AUTH_TABLE_LENGTH);
auth_table = BigBuf_malloc(AUTH_TABLE_LENGTH);
memset(auth_table, 0x00, AUTH_TABLE_LENGTH);
// Reset the received frame, frame count and timing info
@@ -1018,7 +1019,7 @@ void SimulateHitagTag(bool tag_mem_supplied, uint8_t *data) {
// Check if frame was captured
if (rxlen > 4) {
frame_count++;
// frame_count++;
LogTrace(rx, nbytes(rxlen), response, response, NULL, true);
// Disable timer 1 with external trigger to avoid triggers during our own modulation
@@ -1074,7 +1075,7 @@ void ReaderHitag(hitag_function htf, hitag_data *htd) {
StopTicks();
int frame_count = 0;
// int frame_count = 0;
int response = 0;
uint8_t rx[HITAG_FRAME_LEN];
size_t rxlen = 0;
@@ -1209,7 +1210,7 @@ void ReaderHitag(hitag_function htf, hitag_data *htd) {
// Check if frame was captured and store it
if (rxlen > 0) {
frame_count++;
// frame_count++;
LogTrace(rx, nbytes(rxlen), response, response, NULL, false);
}
@@ -1265,7 +1266,7 @@ void ReaderHitag(hitag_function htf, hitag_data *htd) {
// Add transmitted frame to total count
if (txlen > 0) {
frame_count++;
// frame_count++;
LogTrace(tx, nbytes(txlen), HITAG_T_WAIT_2, HITAG_T_WAIT_2, NULL, true);
}
@@ -1359,7 +1360,8 @@ void WriterHitag(hitag_function htf, hitag_data *htd, int page) {
StopTicks();
int frame_count = 0, response = 0;
// int frame_count = 0;
int response = 0;
uint8_t rx[HITAG_FRAME_LEN];
size_t rxlen = 0;
uint8_t txbuf[HITAG_FRAME_LEN];
@@ -1468,7 +1470,7 @@ void WriterHitag(hitag_function htf, hitag_data *htd, int page) {
// Check if frame was captured and store it
if (rxlen > 0) {
frame_count++;
// frame_count++;
LogTrace(rx, nbytes(rxlen), response, response, NULL, false);
}
@@ -1505,7 +1507,7 @@ void WriterHitag(hitag_function htf, hitag_data *htd, int page) {
// Add transmitted frame to total count
if (txlen > 0) {
frame_count++;
// frame_count++;
LogTrace(tx, nbytes(txlen), HITAG_T_WAIT_2, HITAG_T_WAIT_2, NULL, true);
}

View File

@@ -35,9 +35,9 @@ static int temp2 = 0;
static int sof_bits; // number of start-of-frame bits
static uint8_t pwdh0, pwdl0, pwdl1; // password bytes
static uint32_t rnd = 0x74124485; // randomnumber
static int test = 0;
size_t blocknr;
bool end = false;
//#define SENDBIT_TEST
#define ht2bs_4a(a,b,c,d) (~(((a|b)&c)^(a|d)^b))
#define ht2bs_4b(a,b,c,d) (~(((d|c)&(a^b))^(d|a|b)))
@@ -220,33 +220,33 @@ static void hitag_reader_send_bit(int bit) {
HIGH(GPIO_SSC_DOUT);
if (test == 1) {
// Wait for 4-10 times the carrier period
while (AT91C_BASE_TC0->TC_CV < T0 * 6) {};
#ifdef SENDBIT_TEST
// Wait for 4-10 times the carrier period
while (AT91C_BASE_TC0->TC_CV < T0 * 6) {};
LOW(GPIO_SSC_DOUT);
LOW(GPIO_SSC_DOUT);
if (bit == 0) {
// Zero bit: |_-|
while (AT91C_BASE_TC0->TC_CV < T0 * 11) {};
} else {
// One bit: |_--|
while (AT91C_BASE_TC0->TC_CV < T0 * 14) {};
}
if (bit == 0) {
// Zero bit: |_-|
while (AT91C_BASE_TC0->TC_CV < T0 * 11) {};
} else {
// Wait for 4-10 times the carrier period
while (AT91C_BASE_TC0->TC_CV < T0 * 6) {};
LOW(GPIO_SSC_DOUT);
if (bit == 0) {
// Zero bit: |_-|
while (AT91C_BASE_TC0->TC_CV < T0 * 22) {};
} else {
// One bit: |_--|
while (AT91C_BASE_TC0->TC_CV < T0 * 28) {};
}
// One bit: |_--|
while (AT91C_BASE_TC0->TC_CV < T0 * 14) {};
}
#else
// Wait for 4-10 times the carrier period
while (AT91C_BASE_TC0->TC_CV < T0 * 6) {};
LOW(GPIO_SSC_DOUT);
if (bit == 0) {
// Zero bit: |_-|
while (AT91C_BASE_TC0->TC_CV < T0 * 22) {};
} else {
// One bit: |_--|
while (AT91C_BASE_TC0->TC_CV < T0 * 28) {};
}
#endif
LED_A_OFF();
}
@@ -275,11 +275,10 @@ static void hitag_reader_send_frame(const uint8_t *frame, size_t frame_len) {
*/
static int check_select(uint8_t *rx, uint32_t uid) {
unsigned char resp[48];
int i;
uint32_t ans = 0x0;
for (i = 0; i < 48; i++)
for (int i = 0; i < 48; i++)
resp[i] = (rx[i / 8] >> (7 - (i % 8))) & 0x1;
for (i = 0; i < 32; i++)
for (int i = 0; i < 32; i++)
ans += resp[5 + i] << (31 - i);
temp_uid = ans;
@@ -733,18 +732,19 @@ static int hitagS_handle_tag_auth(hitag_function htf, uint64_t key, uint64_t NrA
for (int i = 0; i < 5; i++) {
response_bit[i] = 0;
}
int i = 5;
for (; i < 37; i++) {
response_bit[i] = uid[i - 5];
}
{
int i = 5;
for (; i < 37; i++) {
response_bit[i] = uid[i - 5];
}
for (int j = 0; j < 8; j++) {
response_bit[i] = 0;
if ((crc & ((mask << 7) >> j)) != 0)
response_bit[i] = 1;
i++;
for (int j = 0; j < 8; j++) {
response_bit[i] = 0;
if ((crc & ((mask << 7) >> j)) != 0)
response_bit[i] = 1;
i++;
}
}
k = 0;
for (int i = 0; i < 6; i++) {
tx[i] = (response_bit[k] << 7)
@@ -892,7 +892,8 @@ void SimulateHitagSTag(bool tag_mem_supplied, uint8_t *data) {
StopTicks();
int frame_count = 0, response = 0, overflow = 0;
// int frame_count = 0;
int response = 0, overflow = 0;
int i, j;
uint8_t rx[HITAG_FRAME_LEN];
size_t rxlen = 0;
@@ -1058,7 +1059,7 @@ void SimulateHitagSTag(bool tag_mem_supplied, uint8_t *data) {
// Check if frame was captured
if (rxlen > 0) {
frame_count++;
// frame_count++;
LogTrace(rx, nbytes(rxlen), response, 0, NULL, true);
// Disable timer 1 with external trigger to avoid triggers during our own modulation
@@ -1121,7 +1122,8 @@ void ReadHitagS(hitag_function htf, hitag_data *htd) {
StopTicks();
int i, j, z, k;
int frame_count = 0, response = 0;
// int frame_count = 0;
int response = 0;
int response_bit[200];
uint8_t rx[HITAG_FRAME_LEN];
size_t rxlen = 0;
@@ -1228,7 +1230,7 @@ void ReadHitagS(hitag_function htf, hitag_data *htd) {
// Check if frame was captured and store it
if (rxlen > 0) {
frame_count++;
// frame_count++;
LogTrace(rx, nbytes(rxlen), response, 0, NULL, false);
}
@@ -1355,7 +1357,7 @@ void ReadHitagS(hitag_function htf, hitag_data *htd) {
// Add transmitted frame to total count
if (txlen > 0) {
frame_count++;
// frame_count++;
LogTrace(tx, nbytes(txlen), HITAG_T_WAIT_2, 0, NULL, true);
}
@@ -1449,7 +1451,8 @@ void WritePageHitagS(hitag_function htf, hitag_data *htd, int page) {
StopTicks();
int frame_count = 0, response = 0;
// int frame_count = 0;
int response = 0;
uint8_t rx[HITAG_FRAME_LEN];
size_t rxlen = 0;
uint8_t txbuf[HITAG_FRAME_LEN];
@@ -1556,7 +1559,7 @@ void WritePageHitagS(hitag_function htf, hitag_data *htd, int page) {
// Check if frame was captured and store it
if (rxlen > 0) {
frame_count++;
// frame_count++;
LogTrace(rx, nbytes(rxlen), response, 0, NULL, false);
}
@@ -1643,7 +1646,7 @@ void WritePageHitagS(hitag_function htf, hitag_data *htd, int page) {
// Add transmitted frame to total count
if (txlen > 0) {
frame_count++;
// frame_count++;
LogTrace(tx, nbytes(txlen), HITAG_T_WAIT_2, 0, NULL, true);
}
@@ -1741,7 +1744,8 @@ void WritePageHitagS(hitag_function htf, hitag_data *htd, int page) {
*/
void check_challenges(bool file_given, uint8_t *data) {
int i, j, z, k;
int frame_count = 0, response = 0;
// int frame_count = 0;
int response = 0;
uint8_t uid_byte[4];
uint8_t rx[HITAG_FRAME_LEN];
uint8_t unlocker[60][8];
@@ -1824,7 +1828,7 @@ void check_challenges(bool file_given, uint8_t *data) {
// Check if frame was captured and store it
if (rxlen > 0) {
frame_count++;
// frame_count++;
LogTrace(rx, nbytes(rxlen), response, 0, NULL, false);
}
@@ -1951,7 +1955,7 @@ void check_challenges(bool file_given, uint8_t *data) {
// Add transmitted frame to total count
if (txlen > 0) {
frame_count++;
// frame_count++;
LogTrace(tx, nbytes(txlen), HITAG_T_WAIT_2, 0, NULL, true);
}

View File

@@ -153,7 +153,6 @@ static void uart_init(uint8_t *data) {
static void uart_bit(uint8_t bit) {
static uint8_t buf = 0xff;
static uint8_t n_buf;
static uint8_t msg_byte;
static int nmsg_byte;
buf <<= 1;
buf |= bit ? 1 : 0;
@@ -166,6 +165,7 @@ static void uart_bit(uint8_t bit) {
nmsg_byte = 0;
}
} else {
static uint8_t msg_byte;
n_buf++;
if (n_buf == 8) {
msg_byte >>= 2;

View File

@@ -1400,8 +1400,7 @@ void SimulateIso14443aTag(uint8_t tagType, uint8_t flags, uint8_t *data) {
EmSendCmd(cmd, sizeof(cmd));
} else {
EmSend4bit(CARD_NACK_NA);
uint32_t pwd = bytes_to_num(receivedCmd + 1, 4);
if (DBGLEVEL >= DBG_DEBUG) Dbprintf("Auth attempt: %08x", pwd);
if (DBGLEVEL >= DBG_DEBUG) Dbprintf("Auth attempt: %08x", bytes_to_num(receivedCmd + 1, 4));
}
p_response = NULL;
} else if (receivedCmd[0] == MIFARE_ULEV1_VCSL && len == 23 && tagType == 7) {
@@ -2126,13 +2125,8 @@ static int GetATQA(uint8_t *resp, uint8_t *resp_par) {
// requests ATS unless no_rats is true
int iso14443a_select_card(uint8_t *uid_ptr, iso14a_card_select_t *p_card, uint32_t *cuid_ptr, bool anticollision, uint8_t num_cascades, bool no_rats) {
uint8_t sel_all[] = { ISO14443A_CMD_ANTICOLL_OR_SELECT, 0x20 };
uint8_t sel_uid[] = { ISO14443A_CMD_ANTICOLL_OR_SELECT, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
uint8_t rats[] = { ISO14443A_CMD_RATS, 0x80, 0x00, 0x00 }; // FSD=256, FSDI=8, CID=0
uint8_t resp[MAX_FRAME_SIZE] = {0}; // theoretically. A usual RATS will be much smaller
uint8_t resp_par[MAX_PARITY_SIZE] = {0};
uint8_t uid_resp[4] = {0};
size_t uid_resp_len = 0;
uint8_t sak = 0x04; // cascade uid
int cascade_level = 0;
@@ -2166,6 +2160,9 @@ int iso14443a_select_card(uint8_t *uid_ptr, iso14a_card_select_t *p_card, uint32
// While the UID is not complete, the 3nd bit (from the right) is set in the SAK.
for (; sak & 0x04; cascade_level++) {
// SELECT_* (L1: 0x93, L2: 0x95, L3: 0x97)
uint8_t sel_all[] = { ISO14443A_CMD_ANTICOLL_OR_SELECT, 0x20 };
uint8_t sel_uid[] = { ISO14443A_CMD_ANTICOLL_OR_SELECT, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
uint8_t uid_resp[4] = {0};
sel_uid[0] = sel_all[0] = 0x93 + cascade_level * 2;
if (anticollision) {
@@ -2213,7 +2210,7 @@ int iso14443a_select_card(uint8_t *uid_ptr, iso14a_card_select_t *p_card, uint32
memcpy(uid_resp, uid_ptr + cascade_level * 3, 4);
}
}
uid_resp_len = 4;
size_t uid_resp_len = 4;
// calculate crypto UID. Always use last 4 Bytes.
if (cuid_ptr)
@@ -2259,7 +2256,7 @@ int iso14443a_select_card(uint8_t *uid_ptr, iso14a_card_select_t *p_card, uint32
// RATS, Request for answer to select
if (!no_rats) {
uint8_t rats[] = { ISO14443A_CMD_RATS, 0x80, 0x00, 0x00 }; // FSD=256, FSDI=8, CID=0
AddCrc14A(rats, 2);
ReaderTransmit(rats, sizeof(rats), NULL);
int len = ReaderReceive(resp, resp_par);
@@ -2281,8 +2278,6 @@ int iso14443a_select_card(uint8_t *uid_ptr, iso14a_card_select_t *p_card, uint32
}
int iso14443a_fast_select_card(uint8_t *uid_ptr, uint8_t num_cascades) {
uint8_t sel_all[] = { ISO14443A_CMD_ANTICOLL_OR_SELECT, 0x20 };
uint8_t sel_uid[] = { ISO14443A_CMD_ANTICOLL_OR_SELECT, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
uint8_t resp[5] = {0}; // theoretically. A usual RATS will be much smaller
uint8_t resp_par[1] = {0};
uint8_t uid_resp[4] = {0};
@@ -2298,6 +2293,8 @@ int iso14443a_fast_select_card(uint8_t *uid_ptr, uint8_t num_cascades) {
// which case we need to make a cascade 2 request and select - this is a long UID
// While the UID is not complete, the 3nd bit (from the right) is set in the SAK.
for (; sak & 0x04; cascade_level++) {
uint8_t sel_all[] = { ISO14443A_CMD_ANTICOLL_OR_SELECT, 0x20 };
uint8_t sel_uid[] = { ISO14443A_CMD_ANTICOLL_OR_SELECT, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
// SELECT_* (L1: 0x93, L2: 0x95, L3: 0x97)
sel_uid[0] = sel_all[0] = 0x93 + cascade_level * 2;

View File

@@ -1956,10 +1956,10 @@ void MifareCIdent() {
if (!ReaderReceive(rec, recpar) || (rec[0] != 0x0a)) {
goto TEST2;
};
isGen = GEN_1B;
ReaderTransmit(wupC2, sizeof(wupC2), NULL);
if (!ReaderReceive(rec, recpar) || (rec[0] != 0x0a)) {
isGen = GEN_1B;
goto OUT;
};
isGen = GEN_1A;

View File

@@ -605,12 +605,12 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain) {
// Incoming SELECT CLx for any cascade level
if (receivedCmd_len == 9 && receivedCmd[1] == 0x70) {
if (memcmp(&receivedCmd[2], responses[uid_index].response, 4) == 0) {
bool finished = (uid_len == 4 && uid_index == UIDBCC1) ||
bool cl_finished = (uid_len == 4 && uid_index == UIDBCC1) ||
(uid_len == 7 && uid_index == UIDBCC2) ||
(uid_len == 10 && uid_index == UIDBCC3);
EmSendPrecompiledCmd(&responses[finished ? SAK : SAKuid]);
EmSendPrecompiledCmd(&responses[cl_finished ? SAK : SAKuid]);
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("SELECT CLx %02x%02x%02x%02x received", receivedCmd[2], receivedCmd[3], receivedCmd[4], receivedCmd[5]);
if (finished) {
if (cl_finished) {
LED_B_ON();
cardSTATE = MFEMUL_WORK;
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_SELECT] cardSTATE = MFEMUL_WORK");