mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-21 22:03:42 -07:00
unshadow vars
This commit is contained in:
parent
4d4984657e
commit
723503b74e
5 changed files with 104 additions and 104 deletions
|
@ -47,9 +47,9 @@ endif
|
|||
|
||||
DEFCFLAGS = -Wall -Werror -O3
|
||||
# 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:
|
||||
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?:
|
||||
#DEFCFLAGS += -Wextra -Wswitch-enum -Wold-style-definition
|
||||
|
||||
|
|
|
@ -642,7 +642,7 @@ static nxp_cardtype_t getCardType(uint8_t major, uint8_t minor) {
|
|||
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)
|
||||
// 4 different crypto arg1 DES, 3DES, 3K3DES, AES
|
||||
// 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
|
||||
if (defaultkey) {
|
||||
if (def_key) {
|
||||
if (payload->algo == MFDES_AUTH_DES) {
|
||||
memcpy(keybytes, PICC_MASTER_KEY8, 8);
|
||||
} else if (payload->algo == MFDES_ALGO_AES || payload->algo == MFDES_ALGO_3DES) {
|
||||
|
|
|
@ -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) {
|
||||
candidates->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;
|
||||
static void add_cached_states(statelist_t *cands, uint16_t part_sum_a0, uint16_t part_sum_a8, odd_even_t odd_even) {
|
||||
cands->states[odd_even] = sl_cache[part_sum_a0 / 2][part_sum_a8 / 2][odd_even].sl;
|
||||
cands->len[odd_even] = sl_cache[part_sum_a0 / 2][part_sum_a8 / 2][odd_even].len;
|
||||
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;
|
||||
candidates->states[odd_even] = (uint32_t *)malloc(sizeof(uint32_t) * worstcase_size);
|
||||
if (candidates->states[odd_even] == NULL) {
|
||||
cands->states[odd_even] = (uint32_t *)malloc(sizeof(uint32_t) * worstcase_size);
|
||||
if (cands->states[odd_even] == NULL) {
|
||||
PrintAndLogEx(ERR, "Out of memory error in add_matching_states() - statelist.\n");
|
||||
exit(4);
|
||||
}
|
||||
uint32_t *candidates_bitarray = (uint32_t *)malloc_bitarray(sizeof(uint32_t) * worstcase_size);
|
||||
if (candidates_bitarray == NULL) {
|
||||
uint32_t *cands_bitarray = (uint32_t *)malloc_bitarray(sizeof(uint32_t) * worstcase_size);
|
||||
if (cands_bitarray == NULL) {
|
||||
PrintAndLogEx(ERR, "Out of memory error in add_matching_states() - bitarray.\n");
|
||||
free(candidates->states[odd_even]);
|
||||
free(cands->states[odd_even]);
|
||||
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_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) {
|
||||
free(candidates->states[odd_even]);
|
||||
candidates->states[odd_even] = NULL;
|
||||
} else if (candidates->len[odd_even] + 1 < worstcase_size) {
|
||||
candidates->states[odd_even] = realloc(candidates->states[odd_even], sizeof(uint32_t) * (candidates->len[odd_even] + 1));
|
||||
if (cands->len[odd_even] == 0) {
|
||||
free(cands->states[odd_even]);
|
||||
cands->states[odd_even] = NULL;
|
||||
} else if (cands->len[odd_even] + 1 < worstcase_size) {
|
||||
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);
|
||||
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].len = candidates->len[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 = cands->len[odd_even];
|
||||
sl_cache[part_sum_a0 / 2][part_sum_a8 / 2][odd_even].cache_status = COMPLETED;
|
||||
pthread_mutex_unlock(&statelist_cache_mutex);
|
||||
return;
|
||||
|
|
|
@ -22,8 +22,8 @@
|
|||
static int CmdHelp(const char *Cmd);
|
||||
|
||||
// trace pointer
|
||||
static uint8_t *trace;
|
||||
long traceLen = 0;
|
||||
static uint8_t *g_trace;
|
||||
long g_traceLen = 0;
|
||||
|
||||
static int usage_trace_list(void) {
|
||||
PrintAndLogEx(NORMAL, "List protocol data in trace buffer.");
|
||||
|
@ -491,26 +491,26 @@ static int CmdTraceLoad(const char *Cmd) {
|
|||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
if (trace)
|
||||
free(trace);
|
||||
if (g_trace)
|
||||
free(g_trace);
|
||||
|
||||
trace = calloc(fsize, sizeof(uint8_t));
|
||||
if (!trace) {
|
||||
g_trace = calloc(fsize, sizeof(uint8_t));
|
||||
if (!g_trace) {
|
||||
PrintAndLogEx(FAILED, "Cannot allocate memory for trace");
|
||||
fclose(f);
|
||||
return PM3_EMALLOC;
|
||||
}
|
||||
|
||||
size_t bytes_read = fread(trace, 1, fsize, f);
|
||||
traceLen = bytes_read;
|
||||
size_t bytes_read = fread(g_trace, 1, fsize, f);
|
||||
g_traceLen = bytes_read;
|
||||
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;
|
||||
}
|
||||
|
||||
static int CmdTraceSave(const char *Cmd) {
|
||||
|
||||
if (traceLen == 0) {
|
||||
if (g_traceLen == 0) {
|
||||
PrintAndLogEx(WARNING, "trace is empty, nothing to save");
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
@ -520,7 +520,7 @@ static int CmdTraceSave(const char *Cmd) {
|
|||
if (strlen(Cmd) < 1 || cmdp == 'h') return usage_trace_save();
|
||||
|
||||
param_getstr(Cmd, 0, filename, sizeof(filename));
|
||||
saveFile(filename, ".bin", trace, traceLen);
|
||||
saveFile(filename, ".bin", g_trace, g_traceLen);
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -628,10 +628,10 @@ int CmdTraceList(const char *Cmd) {
|
|||
|
||||
uint16_t tracepos = 0;
|
||||
|
||||
// reserv some space.
|
||||
if (!trace) {
|
||||
trace = calloc(PM3_CMD_DATA_SIZE, sizeof(uint8_t));
|
||||
if (trace == NULL) {
|
||||
// reserve some space.
|
||||
if (!g_trace) {
|
||||
g_trace = calloc(PM3_CMD_DATA_SIZE, sizeof(uint8_t));
|
||||
if (g_trace == NULL) {
|
||||
PrintAndLogEx(FAILED, "Cannot allocate memory for trace");
|
||||
return PM3_EMALLOC;
|
||||
}
|
||||
|
@ -640,38 +640,38 @@ int CmdTraceList(const char *Cmd) {
|
|||
if (isOnline) {
|
||||
// Query for the size of the trace, downloading PM3_CMD_DATA_SIZE
|
||||
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.");
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
|
||||
traceLen = response.oldarg[2];
|
||||
if (traceLen > PM3_CMD_DATA_SIZE) {
|
||||
uint8_t *p = realloc(trace, traceLen);
|
||||
g_traceLen = response.oldarg[2];
|
||||
if (g_traceLen > PM3_CMD_DATA_SIZE) {
|
||||
uint8_t *p = realloc(g_trace, g_traceLen);
|
||||
if (p == NULL) {
|
||||
PrintAndLogEx(FAILED, "Cannot allocate memory for trace");
|
||||
free(trace);
|
||||
free(g_trace);
|
||||
return PM3_EMALLOC;
|
||||
}
|
||||
trace = p;
|
||||
if (!GetFromDevice(BIG_BUF, trace, traceLen, 0, NULL, 0, NULL, 2500, false)) {
|
||||
g_trace = p;
|
||||
if (!GetFromDevice(BIG_BUF, g_trace, g_traceLen, 0, NULL, 0, NULL, 2500, false)) {
|
||||
PrintAndLogEx(WARNING, "command execution time out");
|
||||
free(trace);
|
||||
free(g_trace);
|
||||
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) {
|
||||
printFelica(traceLen, trace);
|
||||
printFelica(g_traceLen, g_trace);
|
||||
} */
|
||||
|
||||
if (showHex) {
|
||||
while (tracepos < traceLen) {
|
||||
tracepos = printHexLine(tracepos, traceLen, trace, protocol);
|
||||
while (tracepos < g_traceLen) {
|
||||
tracepos = printHexLine(tracepos, g_traceLen, g_trace, protocol);
|
||||
}
|
||||
} else {
|
||||
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, "------------+------------+-----+-------------------------------------------------------------------------+-----+--------------------");
|
||||
|
||||
ClearAuthData();
|
||||
while (tracepos < traceLen) {
|
||||
tracepos = printTraceLine(tracepos, traceLen, trace, protocol, showWaitCycles, markCRCBytes);
|
||||
while (tracepos < g_traceLen) {
|
||||
tracepos = printTraceLine(tracepos, g_traceLen, g_trace, protocol, showWaitCycles, markCRCBytes);
|
||||
|
||||
if (kbd_enter_pressed())
|
||||
break;
|
||||
|
|
|
@ -90,42 +90,42 @@ const char *mfGetAccessConditionsDesc(uint8_t blockn, uint8_t *data) {
|
|||
return StaticNone;
|
||||
}
|
||||
/*
|
||||
static int CalculateEncIVCommand(mf4Session_t *session, uint8_t *iv, bool verbose) {
|
||||
memcpy(&iv[0], &session->TI, 4);
|
||||
memcpy(&iv[4], &session->R_Ctr, 2);
|
||||
memcpy(&iv[6], &session->W_Ctr, 2);
|
||||
memcpy(&iv[8], &session->R_Ctr, 2);
|
||||
memcpy(&iv[10], &session->W_Ctr, 2);
|
||||
memcpy(&iv[12], &session->R_Ctr, 2);
|
||||
memcpy(&iv[14], &session->W_Ctr, 2);
|
||||
static int CalculateEncIVCommand(mf4Session_t *mf4session, uint8_t *iv, bool verbose) {
|
||||
memcpy(&iv[0], &mf4session->TI, 4);
|
||||
memcpy(&iv[4], &mf4session->R_Ctr, 2);
|
||||
memcpy(&iv[6], &mf4session->W_Ctr, 2);
|
||||
memcpy(&iv[8], &mf4session->R_Ctr, 2);
|
||||
memcpy(&iv[10], &mf4session->W_Ctr, 2);
|
||||
memcpy(&iv[12], &mf4session->R_Ctr, 2);
|
||||
memcpy(&iv[14], &mf4session->W_Ctr, 2);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int CalculateEncIVResponse(mf4Session *session, uint8_t *iv, bool verbose) {
|
||||
memcpy(&iv[0], &session->R_Ctr, 2);
|
||||
memcpy(&iv[2], &session->W_Ctr, 2);
|
||||
memcpy(&iv[4], &session->R_Ctr, 2);
|
||||
memcpy(&iv[6], &session->W_Ctr, 2);
|
||||
memcpy(&iv[8], &session->R_Ctr, 2);
|
||||
memcpy(&iv[10], &session->W_Ctr, 2);
|
||||
memcpy(&iv[12], &session->TI, 4);
|
||||
static int CalculateEncIVResponse(mf4Session *mf4session, uint8_t *iv, bool verbose) {
|
||||
memcpy(&iv[0], &mf4session->R_Ctr, 2);
|
||||
memcpy(&iv[2], &mf4session->W_Ctr, 2);
|
||||
memcpy(&iv[4], &mf4session->R_Ctr, 2);
|
||||
memcpy(&iv[6], &mf4session->W_Ctr, 2);
|
||||
memcpy(&iv[8], &mf4session->R_Ctr, 2);
|
||||
memcpy(&iv[10], &mf4session->W_Ctr, 2);
|
||||
memcpy(&iv[12], &mf4session->TI, 4);
|
||||
|
||||
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) {
|
||||
if (!session || !session->Authenticated || !mac || !data || !datalen)
|
||||
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 (!mf4session || !mf4session->Authenticated || !mac || !data || !datalen)
|
||||
return 1;
|
||||
|
||||
memset(mac, 0x00, 8);
|
||||
|
||||
uint16_t ctr = session->R_Ctr;
|
||||
uint16_t ctr = mf4session->R_Ctr;
|
||||
switch (mtype) {
|
||||
case mtypWriteCmd:
|
||||
case mtypWriteResp:
|
||||
ctr = session->W_Ctr;
|
||||
ctr = mf4session->W_Ctr;
|
||||
break;
|
||||
case mtypReadCmd:
|
||||
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};
|
||||
int macdatalen = datalen;
|
||||
memcpy(&macdata[3], session->TI, 4);
|
||||
memcpy(&macdata[3], mf4session->TI, 4);
|
||||
|
||||
switch (mtype) {
|
||||
case mtypReadCmd:
|
||||
|
@ -160,10 +160,10 @@ int CalculateMAC(mf4Session_t *session, MACType_t mtype, uint8_t blockNum, uint8
|
|||
if (verbose)
|
||||
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};
|
||||
int datalen = 0;
|
||||
|
||||
|
@ -173,8 +173,8 @@ int MifareAuth4(mf4Session_t *session, uint8_t *keyn, uint8_t *key, bool activat
|
|||
if (silentMode)
|
||||
verbose = false;
|
||||
|
||||
if (session)
|
||||
session->Authenticated = false;
|
||||
if (mf4session)
|
||||
mf4session->Authenticated = false;
|
||||
|
||||
uint8_t cmd1[] = {0x70, keyn[1], keyn[0], 0x00};
|
||||
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)
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
|
||||
if (session) {
|
||||
session->Authenticated = true;
|
||||
session->R_Ctr = 0;
|
||||
session->W_Ctr = 0;
|
||||
session->KeyNum = keyn[1] + (keyn[0] << 8);
|
||||
memmove(session->RndA, RndA, 16);
|
||||
memmove(session->RndB, RndB, 16);
|
||||
memmove(session->Key, key, 16);
|
||||
memmove(session->TI, raw, 4);
|
||||
memmove(session->PICCap2, &raw[20], 6);
|
||||
memmove(session->PCDCap2, &raw[26], 6);
|
||||
memmove(session->Kenc, kenc, 16);
|
||||
memmove(session->Kmac, kmac, 16);
|
||||
if (mf4session) {
|
||||
mf4session->Authenticated = true;
|
||||
mf4session->R_Ctr = 0;
|
||||
mf4session->W_Ctr = 0;
|
||||
mf4session->KeyNum = keyn[1] + (keyn[0] << 8);
|
||||
memmove(mf4session->RndA, RndA, 16);
|
||||
memmove(mf4session->RndB, RndB, 16);
|
||||
memmove(mf4session->Key, key, 16);
|
||||
memmove(mf4session->TI, raw, 4);
|
||||
memmove(mf4session->PICCap2, &raw[20], 6);
|
||||
memmove(mf4session->PCDCap2, &raw[26], 6);
|
||||
memmove(mf4session->Kenc, kenc, 16);
|
||||
memmove(mf4session->Kmac, kmac, 16);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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};
|
||||
if (!plain && session)
|
||||
CalculateMAC(session, mtypReadCmd, blockNum, blockCount, rcmd, 4, &rcmd[4], VerboseMode);
|
||||
if (!plain && mf4session)
|
||||
CalculateMAC(mf4session, mtypReadCmd, blockNum, blockCount, rcmd, 4, &rcmd[4], VerboseMode);
|
||||
|
||||
int res = intExchangeRAW14aPlus(rcmd, plain ? 4 : sizeof(rcmd), activateField, leaveSignalON, dataout, maxdataoutlen, dataoutlen);
|
||||
if (res)
|
||||
return res;
|
||||
|
||||
if (session)
|
||||
session->R_Ctr++;
|
||||
if (mf4session)
|
||||
mf4session->R_Ctr++;
|
||||
|
||||
if (session && mac && *dataoutlen > 11)
|
||||
CalculateMAC(session, mtypReadResp, blockNum, blockCount, dataout, *dataoutlen - 8 - 2, mac, VerboseMode);
|
||||
if (mf4session && mac && *dataoutlen > 11)
|
||||
CalculateMAC(mf4session, mtypReadResp, blockNum, blockCount, dataout, *dataoutlen - 8 - 2, mac, VerboseMode);
|
||||
|
||||
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};
|
||||
memmove(&rcmd[3], data, 16);
|
||||
if (session)
|
||||
CalculateMAC(session, mtypWriteCmd, blockNum, 1, rcmd, 19, &rcmd[19], VerboseMode);
|
||||
if (mf4session)
|
||||
CalculateMAC(mf4session, mtypWriteCmd, blockNum, 1, rcmd, 19, &rcmd[19], VerboseMode);
|
||||
|
||||
int res = intExchangeRAW14aPlus(rcmd, sizeof(rcmd), activateField, leaveSignalON, dataout, maxdataoutlen, dataoutlen);
|
||||
if (res)
|
||||
return res;
|
||||
|
||||
if (session)
|
||||
session->W_Ctr++;
|
||||
if (mf4session)
|
||||
mf4session->W_Ctr++;
|
||||
|
||||
if (session && mac && *dataoutlen > 3)
|
||||
CalculateMAC(session, mtypWriteResp, blockNum, 1, dataout, *dataoutlen, mac, VerboseMode);
|
||||
if (mf4session && mac && *dataoutlen > 3)
|
||||
CalculateMAC(mf4session, mtypWriteResp, blockNum, 1, dataout, *dataoutlen, mac, VerboseMode);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue