Fix compilation warnings. Fix Issue 52.

This commit is contained in:
Romuald Conty 2010-01-12 12:36:43 +00:00
parent e2336b8b90
commit f0acc73541
5 changed files with 39 additions and 41 deletions

View file

@ -118,7 +118,7 @@ int main(int argc,char* argv[])
print_usage(argv); print_usage(argv);
return 0; return 0;
} else if (0 == strcmp(argv[arg], "-q")) { } else if (0 == strcmp(argv[arg], "-q")) {
INFO("Quiet mode."); INFO("%s", "Quiet mode.");
quiet_output = true; quiet_output = true;
} else { } else {
ERR("%s is not supported option.", argv[arg]); ERR("%s is not supported option.", argv[arg]);

View file

@ -1,4 +1,4 @@
/** /*-
* Public platform independent Near Field Communication (NFC) library * Public platform independent Near Field Communication (NFC) library
* *
* Copyright (C) 2009, Roel Verdult * Copyright (C) 2009, Roel Verdult
@ -15,10 +15,11 @@
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/> * along with this program. If not, see <http://www.gnu.org/licenses/>
* */
*
* @file nfc-mftool.c /**
* @brief * @file nfc-mfclassic.c
* @brief MIFARE Classic manipulation example
*/ */
#include <stdio.h> #include <stdio.h>
@ -311,8 +312,8 @@ void mifare_classic_extract_payload(const char* abDump, char* pbPayload)
typedef enum { typedef enum {
ACTION_READ, ACTION_READ,
ACTION_WRITE, ACTION_WRITE,
ACTION_EXPLAIN, ACTION_EXTRACT,
ACTION_EXTRACT ACTION_USAGE
} action_t; } action_t;
void print_usage(const char* pcProgramName) void print_usage(const char* pcProgramName)
@ -333,17 +334,15 @@ void print_usage(const char* pcProgramName)
int main(int argc, const char* argv[]) int main(int argc, const char* argv[])
{ {
bool b4K; bool b4K;
action_t atAction; action_t atAction = ACTION_USAGE;
byte_t* pbtUID; byte_t* pbtUID;
FILE* pfKeys = NULL; FILE* pfKeys = NULL;
FILE* pfDump = NULL; FILE* pfDump = NULL;
// printf("Checking arguments and settings\n");
if(argc < 2) if(argc < 2)
{ {
print_usage(argv[0]); print_usage(argv[0]);
return 1; exit(EXIT_FAILURE);
} }
const char* command = argv[1]; const char* command = argv[1];
@ -357,21 +356,22 @@ int main(int argc, const char* argv[])
atAction = ACTION_WRITE; atAction = ACTION_WRITE;
bUseKeyA = (tolower(*(argv[2])) == 'a'); bUseKeyA = (tolower(*(argv[2])) == 'a');
bUseKeyFile = (argc > 4); bUseKeyFile = (argc > 4);
} else if(strcmp(command, "e") == 0)
{
atAction = ACTION_EXPLAIN;
} else if(strcmp(command, "x") == 0) } else if(strcmp(command, "x") == 0)
{ {
atAction = ACTION_EXTRACT; atAction = ACTION_EXTRACT;
} }
switch(atAction) { switch(atAction) {
case ACTION_USAGE:
print_usage(argv[0]);
exit(EXIT_FAILURE);
break;
case ACTION_READ: case ACTION_READ:
case ACTION_WRITE: case ACTION_WRITE:
if (argc < 4) if (argc < 4)
{ {
print_usage(argv[0]); print_usage(argv[0]);
return 1; exit(EXIT_FAILURE);
} }
if (bUseKeyFile) if (bUseKeyFile)
@ -380,13 +380,13 @@ int main(int argc, const char* argv[])
if (pfKeys == NULL) if (pfKeys == NULL)
{ {
printf("Could not open keys file: %s\n",argv[4]); printf("Could not open keys file: %s\n",argv[4]);
return 1; exit(EXIT_FAILURE);
} }
if (fread(&mtKeys,1,sizeof(mtKeys),pfKeys) != sizeof(mtKeys)) if (fread(&mtKeys,1,sizeof(mtKeys),pfKeys) != sizeof(mtKeys))
{ {
printf("Could not read keys file: %s\n",argv[4]); printf("Could not read keys file: %s\n",argv[4]);
fclose(pfKeys); fclose(pfKeys);
return 1; exit(EXIT_FAILURE);
} }
fclose(pfKeys); fclose(pfKeys);
} }
@ -399,14 +399,14 @@ int main(int argc, const char* argv[])
if (pfDump == NULL) if (pfDump == NULL)
{ {
printf("Could not open dump file: %s\n",argv[3]); printf("Could not open dump file: %s\n",argv[3]);
return 1; exit(EXIT_FAILURE);
} }
if (fread(&mtDump,1,sizeof(mtDump),pfDump) != sizeof(mtDump)) if (fread(&mtDump,1,sizeof(mtDump),pfDump) != sizeof(mtDump))
{ {
printf("Could not read dump file: %s\n",argv[3]); printf("Could not read dump file: %s\n",argv[3]);
fclose(pfDump); fclose(pfDump);
return 1; exit(EXIT_FAILURE);
} }
fclose(pfDump); fclose(pfDump);
} }
@ -417,7 +417,7 @@ int main(int argc, const char* argv[])
if (pnd == NULL) if (pnd == NULL)
{ {
printf("Error connecting NFC reader\n"); printf("Error connecting NFC reader\n");
return 1; exit(EXIT_FAILURE);
} }
nfc_initiator_init(pnd); nfc_initiator_init(pnd);
@ -440,7 +440,7 @@ int main(int argc, const char* argv[])
{ {
printf("Error: no tag was found\n"); printf("Error: no tag was found\n");
nfc_disconnect(pnd); nfc_disconnect(pnd);
return 1; exit(EXIT_FAILURE);
} }
// Test if we are dealing with a MIFARE compatible tag // Test if we are dealing with a MIFARE compatible tag
@ -448,7 +448,7 @@ int main(int argc, const char* argv[])
{ {
printf("Error: tag is not a MIFARE Classic card\n"); printf("Error: tag is not a MIFARE Classic card\n");
nfc_disconnect(pnd); nfc_disconnect(pnd);
return 1; exit(EXIT_FAILURE);
} }
if (bUseKeyFile) if (bUseKeyFile)
@ -481,7 +481,7 @@ int main(int argc, const char* argv[])
if (fwrite(&mtDump,1,sizeof(mtDump),pfDump) != sizeof(mtDump)) if (fwrite(&mtDump,1,sizeof(mtDump),pfDump) != sizeof(mtDump))
{ {
printf("\nCould not write to file: %s\n",argv[3]); printf("\nCould not write to file: %s\n",argv[3]);
return 1; exit(EXIT_FAILURE);
} }
printf("Done.\n"); printf("Done.\n");
fclose(pfDump); fclose(pfDump);
@ -508,14 +508,14 @@ int main(int argc, const char* argv[])
if (pfDump == NULL) if (pfDump == NULL)
{ {
printf("Could not open dump file: %s\n",pcDump); printf("Could not open dump file: %s\n",pcDump);
return 1; exit(EXIT_FAILURE);
} }
if (fread(abDump,1,sizeof(abDump),pfDump) != sizeof(abDump)) if (fread(abDump,1,sizeof(abDump),pfDump) != sizeof(abDump))
{ {
printf("Could not read dump file: %s\n",pcDump); printf("Could not read dump file: %s\n",pcDump);
fclose(pfDump); fclose(pfDump);
return 1; exit(EXIT_FAILURE);
} }
fclose(pfDump); fclose(pfDump);
@ -526,13 +526,13 @@ int main(int argc, const char* argv[])
if (fwrite(abPayload,1,sizeof(abPayload),pfPayload) != sizeof(abPayload)) if (fwrite(abPayload,1,sizeof(abPayload),pfPayload) != sizeof(abPayload))
{ {
printf("Could not write to file: %s\n",pcPayload); printf("Could not write to file: %s\n",pcPayload);
return 1; exit(EXIT_FAILURE);
} }
fclose(pfPayload); fclose(pfPayload);
printf("Done, all bytes have been extracted!\n"); printf("Done, all bytes have been extracted!\n");
} }
}; };
return 0; exit(EXIT_SUCCESS);
} }

View file

@ -160,15 +160,15 @@ void print_hex_bits(const byte_t* pbtData, const size_t szBits)
printf("%02x ",pbtData[szPos]); printf("%02x ",pbtData[szPos]);
} }
uint8_t uRemainder = szBits % 8;
// Print the rest bits // Print the rest bits
if (szBits%8 != 0) if (uRemainder != 0)
{ {
if (szBits%8 < 5) if (uRemainder < 5)
printf("%01x (%i bits)",pbtData[szBytes], szBits%8); printf("%01x (%d bits)",pbtData[szBytes], uRemainder);
else else
printf("%02x (%i bits)",pbtData[szBytes], szBits%8); printf("%02x (%d bits)",pbtData[szBytes], uRemainder);
} }
printf("\n"); printf("\n");
} }
@ -188,15 +188,15 @@ void print_hex_par(const byte_t* pbtData, const size_t szBits, const byte_t* pbt
} }
} }
uint8_t uRemainder = szBits % 8;
// Print the rest bits, these cannot have parity bit // Print the rest bits, these cannot have parity bit
if (szBits%8 != 0) if (uRemainder != 0)
{ {
if (szBits%8 < 5) if (uRemainder < 5)
printf("%01x (%i bits)",pbtData[szBytes], szBits%8); printf("%01x (%d bits)",pbtData[szBytes], uRemainder);
else else
printf("%02x (%i bits)",pbtData[szBytes], szBits%8); printf("%02x (%d bits)",pbtData[szBytes], uRemainder);
} }
printf("\n"); printf("\n");
} }

View file

@ -133,7 +133,6 @@ acr122_list_devices(nfc_device_desc_t pnddDevices[], size_t szDevices, size_t *p
size_t szPos = 0; size_t szPos = 0;
char acDeviceNames[256+64*DRIVERS_MAX_DEVICES]; char acDeviceNames[256+64*DRIVERS_MAX_DEVICES];
size_t szDeviceNamesLen = sizeof(acDeviceNames); size_t szDeviceNamesLen = sizeof(acDeviceNames);
acr122_spec_t as;
uint32_t uiBusIndex = 0; uint32_t uiBusIndex = 0;
SCARDCONTEXT *pscc; SCARDCONTEXT *pscc;
@ -178,7 +177,6 @@ acr122_list_devices(nfc_device_desc_t pnddDevices[], size_t szDevices, size_t *p
{ {
DBG("PCSC device [%s] is not NFC capable or not supported by libnfc.", acDeviceNames + szPos); DBG("PCSC device [%s] is not NFC capable or not supported by libnfc.", acDeviceNames + szPos);
} }
SCardDisconnect(as.hCard,SCARD_LEAVE_CARD);
// Find next device name position // Find next device name position
while (acDeviceNames[szPos++] != '\0'); while (acDeviceNames[szPos++] != '\0');

View file

@ -169,7 +169,7 @@ nfc_device_t* pn532_uart_connect(const nfc_device_desc_t* pndd)
// We have a connection // We have a connection
pnd = malloc(sizeof(nfc_device_t)); pnd = malloc(sizeof(nfc_device_t));
strncpy(pnd->acName, pndd->acDevice, DEVICE_NAME_LENGTH - 1); strncpy(pnd->acName, pndd->acDevice, DEVICE_NAME_LENGTH - 1);
pnd->acName[DEVICE_NAME_LENGTH] = '\0'; pnd->acName[DEVICE_NAME_LENGTH - 1] = '\0';
pnd->nc = NC_PN532; pnd->nc = NC_PN532;
pnd->nds = (nfc_device_spec_t)sp; pnd->nds = (nfc_device_spec_t)sp;