unshadow vars

This commit is contained in:
Philippe Teuwen 2020-05-03 21:43:03 +02:00
commit 723503b74e
5 changed files with 104 additions and 104 deletions

View file

@ -47,9 +47,9 @@ endif
DEFCFLAGS = -Wall -Werror -O3 DEFCFLAGS = -Wall -Werror -O3
# Some more warnings we want as errors: # Some more warnings we want as errors:
DEFCFLAGS += -Wredundant-decls -Wmissing-prototypes -Wchar-subscripts -Wundef -Wwrite-strings -Wunused -Wuninitialized -Wpointer-arith -Winline -Wformat -Wformat-security -Winit-self -Wmissing-include-dirs -Wnested-externs -Wmissing-declarations DEFCFLAGS += -Wredundant-decls -Wmissing-prototypes -Wchar-subscripts -Wshadow -Wundef -Wwrite-strings -Wunused -Wuninitialized -Wpointer-arith -Winline -Wformat -Wformat-security -Winit-self -Wmissing-include-dirs -Wnested-externs -Wmissing-declarations
# Some more warnings we need first to eliminate, so temporarely tolerated: # Some more warnings we need first to eliminate, so temporarely tolerated:
DEFCFLAGS += -Wbad-function-cast -Wno-error=bad-function-cast -Wshadow -Wno-error=shadow -Wcast-align -Wno-error=cast-align DEFCFLAGS += -Wbad-function-cast -Wno-error=bad-function-cast -Wcast-align -Wno-error=cast-align
# TODO?: # TODO?:
#DEFCFLAGS += -Wextra -Wswitch-enum -Wold-style-definition #DEFCFLAGS += -Wextra -Wswitch-enum -Wold-style-definition

View file

@ -642,7 +642,7 @@ static nxp_cardtype_t getCardType(uint8_t major, uint8_t minor) {
return DESFIRE_UNKNOWN; return DESFIRE_UNKNOWN;
} }
static int handler_desfire_auth(mfdes_authinput_t *payload, mfdes_auth_res_t *rpayload, bool defaultkey) { static int handler_desfire_auth(mfdes_authinput_t *payload, mfdes_auth_res_t *rpayload, bool def_key) {
// 3 different way to authenticate AUTH (CRC16) , AUTH_ISO (CRC32) , AUTH_AES (CRC32) // 3 different way to authenticate AUTH (CRC16) , AUTH_ISO (CRC32) , AUTH_AES (CRC32)
// 4 different crypto arg1 DES, 3DES, 3K3DES, AES // 4 different crypto arg1 DES, 3DES, 3K3DES, AES
// 3 different communication modes, PLAIN,MAC,CRYPTO // 3 different communication modes, PLAIN,MAC,CRYPTO
@ -679,7 +679,7 @@ static int handler_desfire_auth(mfdes_authinput_t *payload, mfdes_auth_res_t *rp
// Part 1 // Part 1
if (defaultkey) { if (def_key) {
if (payload->algo == MFDES_AUTH_DES) { if (payload->algo == MFDES_AUTH_DES) {
memcpy(keybytes, PICC_MASTER_KEY8, 8); memcpy(keybytes, PICC_MASTER_KEY8, 8);
} else if (payload->algo == MFDES_ALGO_AES || payload->algo == MFDES_ALGO_3DES) { } else if (payload->algo == MFDES_ALGO_AES || payload->algo == MFDES_ALGO_3DES) {

View file

@ -1739,24 +1739,24 @@ static void bitarray_to_list(uint8_t byte, uint32_t *bitarray, uint32_t *state_l
} }
static void add_cached_states(statelist_t *candidates, uint16_t part_sum_a0, uint16_t part_sum_a8, odd_even_t odd_even) { static void add_cached_states(statelist_t *cands, uint16_t part_sum_a0, uint16_t part_sum_a8, odd_even_t odd_even) {
candidates->states[odd_even] = sl_cache[part_sum_a0 / 2][part_sum_a8 / 2][odd_even].sl; cands->states[odd_even] = sl_cache[part_sum_a0 / 2][part_sum_a8 / 2][odd_even].sl;
candidates->len[odd_even] = sl_cache[part_sum_a0 / 2][part_sum_a8 / 2][odd_even].len; cands->len[odd_even] = sl_cache[part_sum_a0 / 2][part_sum_a8 / 2][odd_even].len;
return; return;
} }
static void add_matching_states(statelist_t *candidates, uint8_t part_sum_a0, uint8_t part_sum_a8, odd_even_t odd_even) { static void add_matching_states(statelist_t *cands, uint8_t part_sum_a0, uint8_t part_sum_a8, odd_even_t odd_even) {
const uint32_t worstcase_size = 1 << 20; const uint32_t worstcase_size = 1 << 20;
candidates->states[odd_even] = (uint32_t *)malloc(sizeof(uint32_t) * worstcase_size); cands->states[odd_even] = (uint32_t *)malloc(sizeof(uint32_t) * worstcase_size);
if (candidates->states[odd_even] == NULL) { if (cands->states[odd_even] == NULL) {
PrintAndLogEx(ERR, "Out of memory error in add_matching_states() - statelist.\n"); PrintAndLogEx(ERR, "Out of memory error in add_matching_states() - statelist.\n");
exit(4); exit(4);
} }
uint32_t *candidates_bitarray = (uint32_t *)malloc_bitarray(sizeof(uint32_t) * worstcase_size); uint32_t *cands_bitarray = (uint32_t *)malloc_bitarray(sizeof(uint32_t) * worstcase_size);
if (candidates_bitarray == NULL) { if (cands_bitarray == NULL) {
PrintAndLogEx(ERR, "Out of memory error in add_matching_states() - bitarray.\n"); PrintAndLogEx(ERR, "Out of memory error in add_matching_states() - bitarray.\n");
free(candidates->states[odd_even]); free(cands->states[odd_even]);
exit(4); exit(4);
} }
@ -1764,21 +1764,21 @@ static void add_matching_states(statelist_t *candidates, uint8_t part_sum_a0, ui
uint32_t *bitarray_a8 = part_sum_a8_bitarrays[odd_even][part_sum_a8 / 2]; uint32_t *bitarray_a8 = part_sum_a8_bitarrays[odd_even][part_sum_a8 / 2];
uint32_t *bitarray_bitflips = nonces[best_first_bytes[0]].states_bitarray[odd_even]; uint32_t *bitarray_bitflips = nonces[best_first_bytes[0]].states_bitarray[odd_even];
bitarray_AND4(candidates_bitarray, bitarray_a0, bitarray_a8, bitarray_bitflips); bitarray_AND4(cands_bitarray, bitarray_a0, bitarray_a8, bitarray_bitflips);
bitarray_to_list(best_first_bytes[0], candidates_bitarray, candidates->states[odd_even], &(candidates->len[odd_even]), odd_even); bitarray_to_list(best_first_bytes[0], cands_bitarray, cands->states[odd_even], &(cands->len[odd_even]), odd_even);
if (candidates->len[odd_even] == 0) { if (cands->len[odd_even] == 0) {
free(candidates->states[odd_even]); free(cands->states[odd_even]);
candidates->states[odd_even] = NULL; cands->states[odd_even] = NULL;
} else if (candidates->len[odd_even] + 1 < worstcase_size) { } else if (cands->len[odd_even] + 1 < worstcase_size) {
candidates->states[odd_even] = realloc(candidates->states[odd_even], sizeof(uint32_t) * (candidates->len[odd_even] + 1)); cands->states[odd_even] = realloc(cands->states[odd_even], sizeof(uint32_t) * (cands->len[odd_even] + 1));
} }
free_bitarray(candidates_bitarray); free_bitarray(cands_bitarray);
pthread_mutex_lock(&statelist_cache_mutex); pthread_mutex_lock(&statelist_cache_mutex);
sl_cache[part_sum_a0 / 2][part_sum_a8 / 2][odd_even].sl = candidates->states[odd_even]; sl_cache[part_sum_a0 / 2][part_sum_a8 / 2][odd_even].sl = cands->states[odd_even];
sl_cache[part_sum_a0 / 2][part_sum_a8 / 2][odd_even].len = candidates->len[odd_even]; sl_cache[part_sum_a0 / 2][part_sum_a8 / 2][odd_even].len = cands->len[odd_even];
sl_cache[part_sum_a0 / 2][part_sum_a8 / 2][odd_even].cache_status = COMPLETED; sl_cache[part_sum_a0 / 2][part_sum_a8 / 2][odd_even].cache_status = COMPLETED;
pthread_mutex_unlock(&statelist_cache_mutex); pthread_mutex_unlock(&statelist_cache_mutex);
return; return;

View file

@ -22,8 +22,8 @@
static int CmdHelp(const char *Cmd); static int CmdHelp(const char *Cmd);
// trace pointer // trace pointer
static uint8_t *trace; static uint8_t *g_trace;
long traceLen = 0; long g_traceLen = 0;
static int usage_trace_list(void) { static int usage_trace_list(void) {
PrintAndLogEx(NORMAL, "List protocol data in trace buffer."); PrintAndLogEx(NORMAL, "List protocol data in trace buffer.");
@ -491,26 +491,26 @@ static int CmdTraceLoad(const char *Cmd) {
return PM3_ESOFT; return PM3_ESOFT;
} }
if (trace) if (g_trace)
free(trace); free(g_trace);
trace = calloc(fsize, sizeof(uint8_t)); g_trace = calloc(fsize, sizeof(uint8_t));
if (!trace) { if (!g_trace) {
PrintAndLogEx(FAILED, "Cannot allocate memory for trace"); PrintAndLogEx(FAILED, "Cannot allocate memory for trace");
fclose(f); fclose(f);
return PM3_EMALLOC; return PM3_EMALLOC;
} }
size_t bytes_read = fread(trace, 1, fsize, f); size_t bytes_read = fread(g_trace, 1, fsize, f);
traceLen = bytes_read; g_traceLen = bytes_read;
fclose(f); fclose(f);
PrintAndLogEx(SUCCESS, "Recorded Activity (TraceLen = %lu bytes) loaded from file %s", traceLen, filename); PrintAndLogEx(SUCCESS, "Recorded Activity (TraceLen = %lu bytes) loaded from file %s", g_traceLen, filename);
return PM3_SUCCESS; return PM3_SUCCESS;
} }
static int CmdTraceSave(const char *Cmd) { static int CmdTraceSave(const char *Cmd) {
if (traceLen == 0) { if (g_traceLen == 0) {
PrintAndLogEx(WARNING, "trace is empty, nothing to save"); PrintAndLogEx(WARNING, "trace is empty, nothing to save");
return PM3_SUCCESS; return PM3_SUCCESS;
} }
@ -520,7 +520,7 @@ static int CmdTraceSave(const char *Cmd) {
if (strlen(Cmd) < 1 || cmdp == 'h') return usage_trace_save(); if (strlen(Cmd) < 1 || cmdp == 'h') return usage_trace_save();
param_getstr(Cmd, 0, filename, sizeof(filename)); param_getstr(Cmd, 0, filename, sizeof(filename));
saveFile(filename, ".bin", trace, traceLen); saveFile(filename, ".bin", g_trace, g_traceLen);
return PM3_SUCCESS; return PM3_SUCCESS;
} }
@ -628,10 +628,10 @@ int CmdTraceList(const char *Cmd) {
uint16_t tracepos = 0; uint16_t tracepos = 0;
// reserv some space. // reserve some space.
if (!trace) { if (!g_trace) {
trace = calloc(PM3_CMD_DATA_SIZE, sizeof(uint8_t)); g_trace = calloc(PM3_CMD_DATA_SIZE, sizeof(uint8_t));
if (trace == NULL) { if (g_trace == NULL) {
PrintAndLogEx(FAILED, "Cannot allocate memory for trace"); PrintAndLogEx(FAILED, "Cannot allocate memory for trace");
return PM3_EMALLOC; return PM3_EMALLOC;
} }
@ -640,38 +640,38 @@ int CmdTraceList(const char *Cmd) {
if (isOnline) { if (isOnline) {
// Query for the size of the trace, downloading PM3_CMD_DATA_SIZE // Query for the size of the trace, downloading PM3_CMD_DATA_SIZE
PacketResponseNG response; PacketResponseNG response;
if (!GetFromDevice(BIG_BUF, trace, PM3_CMD_DATA_SIZE, 0, NULL, 0, &response, 4000, true)) { if (!GetFromDevice(BIG_BUF, g_trace, PM3_CMD_DATA_SIZE, 0, NULL, 0, &response, 4000, true)) {
PrintAndLogEx(WARNING, "timeout while waiting for reply."); PrintAndLogEx(WARNING, "timeout while waiting for reply.");
return PM3_ETIMEOUT; return PM3_ETIMEOUT;
} }
traceLen = response.oldarg[2]; g_traceLen = response.oldarg[2];
if (traceLen > PM3_CMD_DATA_SIZE) { if (g_traceLen > PM3_CMD_DATA_SIZE) {
uint8_t *p = realloc(trace, traceLen); uint8_t *p = realloc(g_trace, g_traceLen);
if (p == NULL) { if (p == NULL) {
PrintAndLogEx(FAILED, "Cannot allocate memory for trace"); PrintAndLogEx(FAILED, "Cannot allocate memory for trace");
free(trace); free(g_trace);
return PM3_EMALLOC; return PM3_EMALLOC;
} }
trace = p; g_trace = p;
if (!GetFromDevice(BIG_BUF, trace, traceLen, 0, NULL, 0, NULL, 2500, false)) { if (!GetFromDevice(BIG_BUF, g_trace, g_traceLen, 0, NULL, 0, NULL, 2500, false)) {
PrintAndLogEx(WARNING, "command execution time out"); PrintAndLogEx(WARNING, "command execution time out");
free(trace); free(g_trace);
return PM3_ETIMEOUT; return PM3_ETIMEOUT;
} }
} }
} }
PrintAndLogEx(SUCCESS, "Recorded activity (trace len = " _YELLOW_("%lu") " bytes)", traceLen); PrintAndLogEx(SUCCESS, "Recorded activity (trace len = " _YELLOW_("%lu") " bytes)", g_traceLen);
/* /*
if (protocol == FELICA) { if (protocol == FELICA) {
printFelica(traceLen, trace); printFelica(g_traceLen, g_trace);
} */ } */
if (showHex) { if (showHex) {
while (tracepos < traceLen) { while (tracepos < g_traceLen) {
tracepos = printHexLine(tracepos, traceLen, trace, protocol); tracepos = printHexLine(tracepos, g_traceLen, g_trace, protocol);
} }
} else { } else {
PrintAndLogEx(INFO, _YELLOW_("Start") " = Start of Start Bit, " _YELLOW_("End") " = End of last modulation. " _YELLOW_("Src") " = Source of Transfer"); PrintAndLogEx(INFO, _YELLOW_("Start") " = Start of Start Bit, " _YELLOW_("End") " = End of last modulation. " _YELLOW_("Src") " = Source of Transfer");
@ -700,8 +700,8 @@ int CmdTraceList(const char *Cmd) {
PrintAndLogEx(NORMAL, "------------+------------+-----+-------------------------------------------------------------------------+-----+--------------------"); PrintAndLogEx(NORMAL, "------------+------------+-----+-------------------------------------------------------------------------+-----+--------------------");
ClearAuthData(); ClearAuthData();
while (tracepos < traceLen) { while (tracepos < g_traceLen) {
tracepos = printTraceLine(tracepos, traceLen, trace, protocol, showWaitCycles, markCRCBytes); tracepos = printTraceLine(tracepos, g_traceLen, g_trace, protocol, showWaitCycles, markCRCBytes);
if (kbd_enter_pressed()) if (kbd_enter_pressed())
break; break;

View file

@ -90,42 +90,42 @@ const char *mfGetAccessConditionsDesc(uint8_t blockn, uint8_t *data) {
return StaticNone; return StaticNone;
} }
/* /*
static int CalculateEncIVCommand(mf4Session_t *session, uint8_t *iv, bool verbose) { static int CalculateEncIVCommand(mf4Session_t *mf4session, uint8_t *iv, bool verbose) {
memcpy(&iv[0], &session->TI, 4); memcpy(&iv[0], &mf4session->TI, 4);
memcpy(&iv[4], &session->R_Ctr, 2); memcpy(&iv[4], &mf4session->R_Ctr, 2);
memcpy(&iv[6], &session->W_Ctr, 2); memcpy(&iv[6], &mf4session->W_Ctr, 2);
memcpy(&iv[8], &session->R_Ctr, 2); memcpy(&iv[8], &mf4session->R_Ctr, 2);
memcpy(&iv[10], &session->W_Ctr, 2); memcpy(&iv[10], &mf4session->W_Ctr, 2);
memcpy(&iv[12], &session->R_Ctr, 2); memcpy(&iv[12], &mf4session->R_Ctr, 2);
memcpy(&iv[14], &session->W_Ctr, 2); memcpy(&iv[14], &mf4session->W_Ctr, 2);
return 0; return 0;
} }
static int CalculateEncIVResponse(mf4Session *session, uint8_t *iv, bool verbose) { static int CalculateEncIVResponse(mf4Session *mf4session, uint8_t *iv, bool verbose) {
memcpy(&iv[0], &session->R_Ctr, 2); memcpy(&iv[0], &mf4session->R_Ctr, 2);
memcpy(&iv[2], &session->W_Ctr, 2); memcpy(&iv[2], &mf4session->W_Ctr, 2);
memcpy(&iv[4], &session->R_Ctr, 2); memcpy(&iv[4], &mf4session->R_Ctr, 2);
memcpy(&iv[6], &session->W_Ctr, 2); memcpy(&iv[6], &mf4session->W_Ctr, 2);
memcpy(&iv[8], &session->R_Ctr, 2); memcpy(&iv[8], &mf4session->R_Ctr, 2);
memcpy(&iv[10], &session->W_Ctr, 2); memcpy(&iv[10], &mf4session->W_Ctr, 2);
memcpy(&iv[12], &session->TI, 4); memcpy(&iv[12], &mf4session->TI, 4);
return 0; return 0;
} }
*/ */
int CalculateMAC(mf4Session_t *session, MACType_t mtype, uint8_t blockNum, uint8_t blockCount, uint8_t *data, int datalen, uint8_t *mac, bool verbose) { int CalculateMAC(mf4Session_t *mf4session, MACType_t mtype, uint8_t blockNum, uint8_t blockCount, uint8_t *data, int datalen, uint8_t *mac, bool verbose) {
if (!session || !session->Authenticated || !mac || !data || !datalen) if (!mf4session || !mf4session->Authenticated || !mac || !data || !datalen)
return 1; return 1;
memset(mac, 0x00, 8); memset(mac, 0x00, 8);
uint16_t ctr = session->R_Ctr; uint16_t ctr = mf4session->R_Ctr;
switch (mtype) { switch (mtype) {
case mtypWriteCmd: case mtypWriteCmd:
case mtypWriteResp: case mtypWriteResp:
ctr = session->W_Ctr; ctr = mf4session->W_Ctr;
break; break;
case mtypReadCmd: case mtypReadCmd:
case mtypReadResp: case mtypReadResp:
@ -134,7 +134,7 @@ int CalculateMAC(mf4Session_t *session, MACType_t mtype, uint8_t blockNum, uint8
uint8_t macdata[2049] = {data[0], (ctr & 0xFF), (ctr >> 8), 0}; uint8_t macdata[2049] = {data[0], (ctr & 0xFF), (ctr >> 8), 0};
int macdatalen = datalen; int macdatalen = datalen;
memcpy(&macdata[3], session->TI, 4); memcpy(&macdata[3], mf4session->TI, 4);
switch (mtype) { switch (mtype) {
case mtypReadCmd: case mtypReadCmd:
@ -160,10 +160,10 @@ int CalculateMAC(mf4Session_t *session, MACType_t mtype, uint8_t blockNum, uint8
if (verbose) if (verbose)
PrintAndLogEx(NORMAL, "MAC data[%d]: %s", macdatalen, sprint_hex(macdata, macdatalen)); PrintAndLogEx(NORMAL, "MAC data[%d]: %s", macdatalen, sprint_hex(macdata, macdatalen));
return aes_cmac8(NULL, session->Kmac, macdata, mac, macdatalen); return aes_cmac8(NULL, mf4session->Kmac, macdata, mac, macdatalen);
} }
int MifareAuth4(mf4Session_t *session, uint8_t *keyn, uint8_t *key, bool activateField, bool leaveSignalON, bool dropFieldIfError, bool verbose, bool silentMode) { int MifareAuth4(mf4Session_t *mf4session, uint8_t *keyn, uint8_t *key, bool activateField, bool leaveSignalON, bool dropFieldIfError, bool verbose, bool silentMode) {
uint8_t data[257] = {0}; uint8_t data[257] = {0};
int datalen = 0; int datalen = 0;
@ -173,8 +173,8 @@ int MifareAuth4(mf4Session_t *session, uint8_t *keyn, uint8_t *key, bool activat
if (silentMode) if (silentMode)
verbose = false; verbose = false;
if (session) if (mf4session)
session->Authenticated = false; mf4session->Authenticated = false;
uint8_t cmd1[] = {0x70, keyn[1], keyn[0], 0x00}; uint8_t cmd1[] = {0x70, keyn[1], keyn[0], 0x00};
int res = ExchangeRAW14a(cmd1, sizeof(cmd1), activateField, true, data, sizeof(data), &datalen, silentMode); int res = ExchangeRAW14a(cmd1, sizeof(cmd1), activateField, true, data, sizeof(data), &datalen, silentMode);
@ -284,19 +284,19 @@ int MifareAuth4(mf4Session_t *session, uint8_t *keyn, uint8_t *key, bool activat
if (verbose) if (verbose)
PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "");
if (session) { if (mf4session) {
session->Authenticated = true; mf4session->Authenticated = true;
session->R_Ctr = 0; mf4session->R_Ctr = 0;
session->W_Ctr = 0; mf4session->W_Ctr = 0;
session->KeyNum = keyn[1] + (keyn[0] << 8); mf4session->KeyNum = keyn[1] + (keyn[0] << 8);
memmove(session->RndA, RndA, 16); memmove(mf4session->RndA, RndA, 16);
memmove(session->RndB, RndB, 16); memmove(mf4session->RndB, RndB, 16);
memmove(session->Key, key, 16); memmove(mf4session->Key, key, 16);
memmove(session->TI, raw, 4); memmove(mf4session->TI, raw, 4);
memmove(session->PICCap2, &raw[20], 6); memmove(mf4session->PICCap2, &raw[20], 6);
memmove(session->PCDCap2, &raw[26], 6); memmove(mf4session->PCDCap2, &raw[26], 6);
memmove(session->Kenc, kenc, 16); memmove(mf4session->Kenc, kenc, 16);
memmove(session->Kmac, kmac, 16); memmove(mf4session->Kmac, kmac, 16);
} }
if (verbose) if (verbose)
@ -330,39 +330,39 @@ int MFPCommitPerso(bool activateField, bool leaveSignalON, uint8_t *dataout, int
return intExchangeRAW14aPlus(rcmd, sizeof(rcmd), activateField, leaveSignalON, dataout, maxdataoutlen, dataoutlen); return intExchangeRAW14aPlus(rcmd, sizeof(rcmd), activateField, leaveSignalON, dataout, maxdataoutlen, dataoutlen);
} }
int MFPReadBlock(mf4Session_t *session, bool plain, uint8_t blockNum, uint8_t blockCount, bool activateField, bool leaveSignalON, uint8_t *dataout, int maxdataoutlen, int *dataoutlen, uint8_t *mac) { int MFPReadBlock(mf4Session_t *mf4session, bool plain, uint8_t blockNum, uint8_t blockCount, bool activateField, bool leaveSignalON, uint8_t *dataout, int maxdataoutlen, int *dataoutlen, uint8_t *mac) {
uint8_t rcmd[4 + 8] = {(plain ? (0x37) : (0x33)), blockNum, 0x00, blockCount}; uint8_t rcmd[4 + 8] = {(plain ? (0x37) : (0x33)), blockNum, 0x00, blockCount};
if (!plain && session) if (!plain && mf4session)
CalculateMAC(session, mtypReadCmd, blockNum, blockCount, rcmd, 4, &rcmd[4], VerboseMode); CalculateMAC(mf4session, mtypReadCmd, blockNum, blockCount, rcmd, 4, &rcmd[4], VerboseMode);
int res = intExchangeRAW14aPlus(rcmd, plain ? 4 : sizeof(rcmd), activateField, leaveSignalON, dataout, maxdataoutlen, dataoutlen); int res = intExchangeRAW14aPlus(rcmd, plain ? 4 : sizeof(rcmd), activateField, leaveSignalON, dataout, maxdataoutlen, dataoutlen);
if (res) if (res)
return res; return res;
if (session) if (mf4session)
session->R_Ctr++; mf4session->R_Ctr++;
if (session && mac && *dataoutlen > 11) if (mf4session && mac && *dataoutlen > 11)
CalculateMAC(session, mtypReadResp, blockNum, blockCount, dataout, *dataoutlen - 8 - 2, mac, VerboseMode); CalculateMAC(mf4session, mtypReadResp, blockNum, blockCount, dataout, *dataoutlen - 8 - 2, mac, VerboseMode);
return 0; return 0;
} }
int MFPWriteBlock(mf4Session_t *session, uint8_t blockNum, uint8_t *data, bool activateField, bool leaveSignalON, uint8_t *dataout, int maxdataoutlen, int *dataoutlen, uint8_t *mac) { int MFPWriteBlock(mf4Session_t *mf4session, uint8_t blockNum, uint8_t *data, bool activateField, bool leaveSignalON, uint8_t *dataout, int maxdataoutlen, int *dataoutlen, uint8_t *mac) {
uint8_t rcmd[1 + 2 + 16 + 8] = {0xA3, blockNum, 0x00}; uint8_t rcmd[1 + 2 + 16 + 8] = {0xA3, blockNum, 0x00};
memmove(&rcmd[3], data, 16); memmove(&rcmd[3], data, 16);
if (session) if (mf4session)
CalculateMAC(session, mtypWriteCmd, blockNum, 1, rcmd, 19, &rcmd[19], VerboseMode); CalculateMAC(mf4session, mtypWriteCmd, blockNum, 1, rcmd, 19, &rcmd[19], VerboseMode);
int res = intExchangeRAW14aPlus(rcmd, sizeof(rcmd), activateField, leaveSignalON, dataout, maxdataoutlen, dataoutlen); int res = intExchangeRAW14aPlus(rcmd, sizeof(rcmd), activateField, leaveSignalON, dataout, maxdataoutlen, dataoutlen);
if (res) if (res)
return res; return res;
if (session) if (mf4session)
session->W_Ctr++; mf4session->W_Ctr++;
if (session && mac && *dataoutlen > 3) if (mf4session && mac && *dataoutlen > 3)
CalculateMAC(session, mtypWriteResp, blockNum, 1, dataout, *dataoutlen, mac, VerboseMode); CalculateMAC(mf4session, mtypWriteResp, blockNum, 1, dataout, *dataoutlen, mac, VerboseMode);
return 0; return 0;
} }