Reduce variables scopes
This commit is contained in:
parent
2033519b0c
commit
04ef5ca902
4 changed files with 8 additions and 9 deletions
|
@ -371,7 +371,6 @@ int
|
||||||
pn53x_wrap_frame(const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar,
|
pn53x_wrap_frame(const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar,
|
||||||
uint8_t *pbtFrame)
|
uint8_t *pbtFrame)
|
||||||
{
|
{
|
||||||
uint8_t btFrame;
|
|
||||||
uint8_t btData;
|
uint8_t btData;
|
||||||
uint32_t uiBitPos;
|
uint32_t uiBitPos;
|
||||||
uint32_t uiDataPos = 0;
|
uint32_t uiDataPos = 0;
|
||||||
|
@ -398,7 +397,7 @@ pn53x_wrap_frame(const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbt
|
||||||
// air-bytes = mirror(buffer-byte) + mirror(buffer-byte) + mirror(buffer-byte) + ..
|
// air-bytes = mirror(buffer-byte) + mirror(buffer-byte) + mirror(buffer-byte) + ..
|
||||||
while (true) {
|
while (true) {
|
||||||
// Reset the temporary frame byte;
|
// Reset the temporary frame byte;
|
||||||
btFrame = 0;
|
uint8_t btFrame = 0;
|
||||||
|
|
||||||
for (uiBitPos = 0; uiBitPos < 8; uiBitPos++) {
|
for (uiBitPos = 0; uiBitPos < 8; uiBitPos++) {
|
||||||
// Copy as much data that fits in the frame byte
|
// Copy as much data that fits in the frame byte
|
||||||
|
@ -1466,9 +1465,8 @@ static void __pn53x_init_timer(struct nfc_device *pnd, const uint32_t max_cycles
|
||||||
|
|
||||||
static uint32_t __pn53x_get_timer(struct nfc_device *pnd, const uint8_t last_cmd_byte)
|
static uint32_t __pn53x_get_timer(struct nfc_device *pnd, const uint8_t last_cmd_byte)
|
||||||
{
|
{
|
||||||
uint8_t parity;
|
|
||||||
uint8_t counter_hi, counter_lo;
|
uint8_t counter_hi, counter_lo;
|
||||||
uint16_t counter, u16cycles;
|
uint16_t counter;
|
||||||
uint32_t u32cycles;
|
uint32_t u32cycles;
|
||||||
size_t off = 0;
|
size_t off = 0;
|
||||||
if (CHIP_DATA(pnd)->type == PN533) {
|
if (CHIP_DATA(pnd)->type == PN533) {
|
||||||
|
@ -1496,6 +1494,8 @@ static uint32_t __pn53x_get_timer(struct nfc_device *pnd, const uint8_t last_cmd
|
||||||
// counter saturated
|
// counter saturated
|
||||||
u32cycles = 0xFFFFFFFF;
|
u32cycles = 0xFFFFFFFF;
|
||||||
} else {
|
} else {
|
||||||
|
uint8_t parity;
|
||||||
|
uint16_t u16cycles;
|
||||||
u16cycles = 0xFFFF - counter;
|
u16cycles = 0xFFFF - counter;
|
||||||
u32cycles = u16cycles;
|
u32cycles = u16cycles;
|
||||||
u32cycles *= (CHIP_DATA(pnd)->timer_prescaler * 2 + 1);
|
u32cycles *= (CHIP_DATA(pnd)->timer_prescaler * 2 + 1);
|
||||||
|
|
|
@ -400,15 +400,14 @@ acr122_pcsc_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szData, int
|
||||||
{
|
{
|
||||||
// FIXME: timeout is not handled
|
// FIXME: timeout is not handled
|
||||||
(void) timeout;
|
(void) timeout;
|
||||||
|
|
||||||
int len;
|
int len;
|
||||||
uint8_t abtRxCmd[5] = { 0xFF, 0xC0, 0x00, 0x00 };
|
|
||||||
|
|
||||||
if (DRIVER_DATA(pnd)->ioCard.dwProtocol == SCARD_PROTOCOL_T0) {
|
if (DRIVER_DATA(pnd)->ioCard.dwProtocol == SCARD_PROTOCOL_T0) {
|
||||||
/*
|
/*
|
||||||
* Retrieve the PN532 response.
|
* Retrieve the PN532 response.
|
||||||
*/
|
*/
|
||||||
DWORD dwRxLen = sizeof(DRIVER_DATA(pnd)->abtRx);
|
DWORD dwRxLen = sizeof(DRIVER_DATA(pnd)->abtRx);
|
||||||
|
uint8_t abtRxCmd[5] = { 0xFF, 0xC0, 0x00, 0x00 };
|
||||||
abtRxCmd[4] = DRIVER_DATA(pnd)->abtRx[1];
|
abtRxCmd[4] = DRIVER_DATA(pnd)->abtRx[1];
|
||||||
if (SCardTransmit(DRIVER_DATA(pnd)->hCard, &(DRIVER_DATA(pnd)->ioCard), abtRxCmd, sizeof(abtRxCmd), NULL, DRIVER_DATA(pnd)->abtRx, &dwRxLen) != SCARD_S_SUCCESS) {
|
if (SCardTransmit(DRIVER_DATA(pnd)->hCard, &(DRIVER_DATA(pnd)->ioCard), abtRxCmd, sizeof(abtRxCmd), NULL, DRIVER_DATA(pnd)->abtRx, &dwRxLen) != SCARD_S_SUCCESS) {
|
||||||
pnd->last_error = NFC_EIO;
|
pnd->last_error = NFC_EIO;
|
||||||
|
|
|
@ -47,10 +47,10 @@
|
||||||
void
|
void
|
||||||
iso14443a_crc(uint8_t *pbtData, size_t szLen, uint8_t *pbtCrc)
|
iso14443a_crc(uint8_t *pbtData, size_t szLen, uint8_t *pbtCrc)
|
||||||
{
|
{
|
||||||
uint8_t bt;
|
|
||||||
uint32_t wCrc = 0x6363;
|
uint32_t wCrc = 0x6363;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
uint8_t bt;
|
||||||
bt = *pbtData++;
|
bt = *pbtData++;
|
||||||
bt = (bt ^ (uint8_t)(wCrc & 0x00FF));
|
bt = (bt ^ (uint8_t)(wCrc & 0x00FF));
|
||||||
bt = (bt ^ (bt << 4));
|
bt = (bt ^ (bt << 4));
|
||||||
|
@ -78,10 +78,10 @@ iso14443a_crc_append(uint8_t *pbtData, size_t szLen)
|
||||||
void
|
void
|
||||||
iso14443b_crc(uint8_t *pbtData, size_t szLen, uint8_t *pbtCrc)
|
iso14443b_crc(uint8_t *pbtData, size_t szLen, uint8_t *pbtCrc)
|
||||||
{
|
{
|
||||||
uint8_t bt;
|
|
||||||
uint32_t wCrc = 0xFFFF;
|
uint32_t wCrc = 0xFFFF;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
uint8_t bt;
|
||||||
bt = *pbtData++;
|
bt = *pbtData++;
|
||||||
bt = (bt ^ (uint8_t)(wCrc & 0x00FF));
|
bt = (bt ^ (uint8_t)(wCrc & 0x00FF));
|
||||||
bt = (bt ^ (bt << 4));
|
bt = (bt ^ (bt << 4));
|
||||||
|
|
|
@ -184,7 +184,6 @@ static bool
|
||||||
authenticate(uint32_t uiBlock)
|
authenticate(uint32_t uiBlock)
|
||||||
{
|
{
|
||||||
mifare_cmd mc;
|
mifare_cmd mc;
|
||||||
uint32_t uiTrailerBlock;
|
|
||||||
|
|
||||||
// Set the authentication information (uid)
|
// Set the authentication information (uid)
|
||||||
memcpy(mp.mpa.abtAuthUid, nt.nti.nai.abtUid + nt.nti.nai.szUidLen - 4, 4);
|
memcpy(mp.mpa.abtAuthUid, nt.nti.nai.abtUid + nt.nti.nai.szUidLen - 4, 4);
|
||||||
|
@ -196,6 +195,7 @@ authenticate(uint32_t uiBlock)
|
||||||
if (bUseKeyFile) {
|
if (bUseKeyFile) {
|
||||||
|
|
||||||
// Locate the trailer (with the keys) used for this sector
|
// Locate the trailer (with the keys) used for this sector
|
||||||
|
uint32_t uiTrailerBlock;
|
||||||
uiTrailerBlock = get_trailer_block(uiBlock);
|
uiTrailerBlock = get_trailer_block(uiBlock);
|
||||||
|
|
||||||
// Extract the right key from dump file
|
// Extract the right key from dump file
|
||||||
|
|
Loading…
Reference in a new issue