astyle
This commit is contained in:
parent
f184407cc5
commit
e4df2f3334
16 changed files with 121 additions and 120 deletions
|
|
@ -68,31 +68,31 @@ nfc_initiator_mifare_cmd(nfc_device *pnd, const mifare_cmd mc, const uint8_t ui8
|
|||
abtCmd[1] = ui8Block; // The block address (1K=0x00..0x39, 4K=0x00..0xff)
|
||||
|
||||
switch (mc) {
|
||||
// Read and store command have no parameter
|
||||
// Read and store command have no parameter
|
||||
case MC_READ:
|
||||
case MC_STORE:
|
||||
szParamLen = 0;
|
||||
break;
|
||||
|
||||
// Authenticate command
|
||||
// Authenticate command
|
||||
case MC_AUTH_A:
|
||||
case MC_AUTH_B:
|
||||
szParamLen = sizeof(struct mifare_param_auth);
|
||||
break;
|
||||
|
||||
// Data command
|
||||
// Data command
|
||||
case MC_WRITE:
|
||||
szParamLen = sizeof(struct mifare_param_data);
|
||||
break;
|
||||
|
||||
// Value command
|
||||
// Value command
|
||||
case MC_DECREMENT:
|
||||
case MC_INCREMENT:
|
||||
case MC_TRANSFER:
|
||||
szParamLen = sizeof(struct mifare_param_value);
|
||||
break;
|
||||
|
||||
// Please fix your code, you never should reach this statement
|
||||
// Please fix your code, you never should reach this statement
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -310,7 +310,7 @@ read_card(int read_unlocked)
|
|||
uint32_t uiReadBlocks = 0;
|
||||
|
||||
if (read_unlocked) {
|
||||
//If the user is attempting an unlocked read, but has a direct-write type magic card, they don't
|
||||
//If the user is attempting an unlocked read, but has a direct-write type magic card, they don't
|
||||
//need to use the R mode. We'll trigger a warning and let them proceed.
|
||||
if (magic2) {
|
||||
printf("Note: This card does not require an unlocked write (R) \n");
|
||||
|
|
@ -318,11 +318,11 @@ read_card(int read_unlocked)
|
|||
} else {
|
||||
//If User has requested an unlocked read, but we're unable to unlock the card, we'll error out.
|
||||
if (!unlock_card()) {
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
printf("Reading out %d blocks |", uiBlocks + 1);
|
||||
// Read the card from end to begin
|
||||
for (iBlock = uiBlocks; iBlock >= 0; iBlock--) {
|
||||
|
|
@ -390,7 +390,7 @@ write_card(int write_block_zero)
|
|||
uint32_t uiWriteBlocks = 0;
|
||||
|
||||
if (write_block_zero) {
|
||||
//If the user is attempting an unlocked write, but has a direct-write type magic card, they don't
|
||||
//If the user is attempting an unlocked write, but has a direct-write type magic card, they don't
|
||||
//need to use the W mode. We'll trigger a warning and let them proceed.
|
||||
if (magic2) {
|
||||
printf("Note: This card does not require an unlocked write (W) \n");
|
||||
|
|
@ -398,11 +398,11 @@ write_card(int write_block_zero)
|
|||
} else {
|
||||
//If User has requested an unlocked write, but we're unable to unlock the card, we'll error out.
|
||||
if (!unlock_card()) {
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
printf("Writing %d blocks |", uiBlocks + 1);
|
||||
// Write the card from begin to end;
|
||||
for (uiBlock = 0; uiBlock <= uiBlocks; uiBlock++) {
|
||||
|
|
|
|||
|
|
@ -182,11 +182,12 @@ unlock_card(void)
|
|||
return true;
|
||||
}
|
||||
|
||||
static bool check_magic() {
|
||||
bool bFailure = false;
|
||||
int uid_data;
|
||||
static bool check_magic()
|
||||
{
|
||||
bool bFailure = false;
|
||||
int uid_data;
|
||||
|
||||
for (uint32_t page = 0; page <= 1; page++) {
|
||||
for (uint32_t page = 0; page <= 1; page++) {
|
||||
// Show if the readout went well
|
||||
if (bFailure) {
|
||||
// When a failure occured we need to redo the anti-collision
|
||||
|
|
@ -206,27 +207,27 @@ static bool check_magic() {
|
|||
nfc_initiator_mifare_cmd(pnd, MC_WRITE, page, &mp);
|
||||
}
|
||||
|
||||
//Check that the ID is now set to 0x000000000000
|
||||
if (nfc_initiator_mifare_cmd(pnd, MC_READ, 0, &mp)) {
|
||||
//printf("%u", mp.mpd.abtData);
|
||||
bool result = true;
|
||||
for(int i = 0; i <= 7; i++) {
|
||||
if (mp.mpd.abtData[i] != 0x00) result = false;
|
||||
}
|
||||
|
||||
if (result) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//Check that the ID is now set to 0x000000000000
|
||||
if (nfc_initiator_mifare_cmd(pnd, MC_READ, 0, &mp)) {
|
||||
//printf("%u", mp.mpd.abtData);
|
||||
bool result = true;
|
||||
for (int i = 0; i <= 7; i++) {
|
||||
if (mp.mpd.abtData[i] != 0x00) result = false;
|
||||
}
|
||||
|
||||
//Initially check if we can unlock via the MF method
|
||||
if (unlock_card()) {
|
||||
if (result) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Initially check if we can unlock via the MF method
|
||||
if (unlock_card()) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static bool
|
||||
|
|
@ -351,7 +352,7 @@ static size_t str_to_uid(const char *str, uint8_t *uid)
|
|||
|
||||
memset(uid, 0x0, MAX_UID_LEN);
|
||||
i = 0;
|
||||
while ((*str != '\0') && ((i >> 1) < MAX_UID_LEN) ) {
|
||||
while ((*str != '\0') && ((i >> 1) < MAX_UID_LEN)) {
|
||||
char nibble[2] = { 0x00, '\n' }; /* for strtol */
|
||||
|
||||
nibble[0] = *str++;
|
||||
|
|
@ -391,8 +392,8 @@ main(int argc, const char *argv[])
|
|||
FILE *pfDump;
|
||||
|
||||
if (argc < 2) {
|
||||
print_usage(argv);
|
||||
exit(EXIT_FAILURE);
|
||||
print_usage(argv);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
DBG("\nChecking arguments and settings\n");
|
||||
|
|
@ -541,12 +542,12 @@ main(int argc, const char *argv[])
|
|||
write_card(bOTP, bLock, bUID);
|
||||
} else if (iAction == 3) {
|
||||
if (!check_magic()) {
|
||||
printf("Card is not magic\n");
|
||||
nfc_close(pnd);
|
||||
nfc_exit(context);
|
||||
exit(EXIT_FAILURE);
|
||||
printf("Card is not magic\n");
|
||||
nfc_close(pnd);
|
||||
nfc_exit(context);
|
||||
exit(EXIT_FAILURE);
|
||||
} else {
|
||||
printf("Card is magic\n");
|
||||
printf("Card is magic\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue