Skip to content

Commit

Permalink
Indent whole code using make indent. (Fixes issue 84).
Browse files Browse the repository at this point in the history
  • Loading branch information
neomilium committed Sep 7, 2010
1 parent f93b493 commit 18cc86a
Show file tree
Hide file tree
Showing 42 changed files with 2,609 additions and 2,475 deletions.
56 changes: 29 additions & 27 deletions examples/doc/quick_start_example1.c
Original file line number Diff line number Diff line change
@@ -1,59 +1,61 @@
#ifdef HAVE_CONFIG_H
#include "config.h"
# include "config.h"
#endif // HAVE_CONFIG_H

#include <stdlib.h>
#include <nfc/nfc.h>
#include <nfc/nfc-messages.h>

int main(int argc, const char* argv[])
int
main (int argc, const char *argv[])
{
nfc_device_t* pnd;
nfc_device_t *pnd;
nfc_target_info_t nti;

// Display libnfc version
const char* acLibnfcVersion = nfc_version();
printf("%s use libnfc %s\n", argv[0], acLibnfcVersion);
const char *acLibnfcVersion = nfc_version ();
printf ("%s use libnfc %s\n", argv[0], acLibnfcVersion);

// Connect using the first available NFC device
pnd = nfc_connect(NULL);
pnd = nfc_connect (NULL);

if (pnd == NULL) {
ERR("%s", "Unable to connect to NFC device.");
return EXIT_FAILURE;
ERR ("%s", "Unable to connect to NFC device.");
return EXIT_FAILURE;
}

// Set connected NFC device to initiator mode
nfc_initiator_init(pnd);
nfc_initiator_init (pnd);

// Drop the field for a while
nfc_configure(pnd,NDO_ACTIVATE_FIELD,false);
nfc_configure (pnd, NDO_ACTIVATE_FIELD, false);

// Let the reader only try once to find a tag
nfc_configure(pnd,NDO_INFINITE_SELECT,false);
nfc_configure (pnd, NDO_INFINITE_SELECT, false);

// Configure the CRC and Parity settings
nfc_configure(pnd,NDO_HANDLE_CRC,true);
nfc_configure(pnd,NDO_HANDLE_PARITY,true);
nfc_configure (pnd, NDO_HANDLE_CRC, true);
nfc_configure (pnd, NDO_HANDLE_PARITY, true);

// Enable field so more power consuming cards can power themselves up
nfc_configure(pnd,NDO_ACTIVATE_FIELD,true);
nfc_configure (pnd, NDO_ACTIVATE_FIELD, true);

printf("Connected to NFC reader: %s\n",pnd->acName);
printf ("Connected to NFC reader: %s\n", pnd->acName);

// Poll for a ISO14443A (MIFARE) tag
if (nfc_initiator_select_passive_target(pnd,NM_ISO14443A_106,NULL,0,&nti)) {
printf("The following (NFC) ISO14443A tag was found:\n");
printf(" ATQA (SENS_RES): "); print_hex(nti.nai.abtAtqa,2);
printf(" UID (NFCID%c): ",(nti.nai.abtUid[0]==0x08?'3':'1')); print_hex(nti.nai.abtUid,nti.nai.szUidLen);
printf(" SAK (SEL_RES): "); print_hex(&nti.nai.btSak,1);
if (nti.nai.szAtsLen) {
printf(" ATS (ATR): ");
print_hex(nti.nai.abtAts,nti.nai.szAtsLen);
}
if (nfc_initiator_select_passive_target (pnd, NM_ISO14443A_106, NULL, 0, &nti)) {
printf ("The following (NFC) ISO14443A tag was found:\n");
printf (" ATQA (SENS_RES): ");
print_hex (nti.nai.abtAtqa, 2);
printf (" UID (NFCID%c): ", (nti.nai.abtUid[0] == 0x08 ? '3' : '1'));
print_hex (nti.nai.abtUid, nti.nai.szUidLen);
printf (" SAK (SEL_RES): ");
print_hex (&nti.nai.btSak, 1);
if (nti.nai.szAtsLen) {
printf (" ATS (ATR): ");
print_hex (nti.nai.abtAts, nti.nai.szAtsLen);
}
}

// Disconnect from NFC device
nfc_disconnect(pnd);
nfc_disconnect (pnd);
return EXIT_SUCCESS;
}
62 changes: 31 additions & 31 deletions examples/mifare.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,70 +17,70 @@
* After a successful authentication it will be possible to execute other commands (e.g. Read/Write).
* The MIFARE Classic Specification (http://www.nxp.com/acrobat/other/identification/M001053_MF1ICS50_rev5_3.pdf) explains more about this process.
*/
bool nfc_initiator_mifare_cmd(nfc_device_t* pnd, const mifare_cmd mc, const uint8_t ui8Block, mifare_param* pmp)
bool
nfc_initiator_mifare_cmd (nfc_device_t * pnd, const mifare_cmd mc, const uint8_t ui8Block, mifare_param * pmp)
{
byte_t abtRx[265];
size_t szRxLen;
size_t szParamLen;
byte_t abtCmd[265];
byte_t abtRx[265];
size_t szRxLen;
size_t szParamLen;
byte_t abtCmd[265];

// Make sure we are dealing with a active device
if (!pnd->bActive) return false;
if (!pnd->bActive)
return false;

abtCmd[0] = mc; // The MIFARE Classic command
abtCmd[1] = ui8Block; // The block address (1K=0x00..0x39, 4K=0x00..0xff)
abtCmd[0] = mc; // The MIFARE Classic command
abtCmd[1] = ui8Block; // The block address (1K=0x00..0x39, 4K=0x00..0xff)

switch (mc)
{
switch (mc) {
// Read and store command have no parameter
case MC_READ:
case MC_STORE:
szParamLen = 0;
case MC_READ:
case MC_STORE:
szParamLen = 0;
break;

// Authenticate command
case MC_AUTH_A:
case MC_AUTH_B:
szParamLen = sizeof(mifare_param_auth);
case MC_AUTH_A:
case MC_AUTH_B:
szParamLen = sizeof (mifare_param_auth);
break;

// Data command
case MC_WRITE:
szParamLen = sizeof(mifare_param_data);
case MC_WRITE:
szParamLen = sizeof (mifare_param_data);
break;

// Value command
case MC_DECREMENT:
case MC_INCREMENT:
case MC_TRANSFER:
szParamLen = sizeof(mifare_param_value);
case MC_DECREMENT:
case MC_INCREMENT:
case MC_TRANSFER:
szParamLen = sizeof (mifare_param_value);
break;

// Please fix your code, you never should reach this statement
default:
return false;
default:
return false;
break;
}

// When available, copy the parameter bytes
if (szParamLen) memcpy(abtCmd+2,(byte_t*)pmp,szParamLen);
if (szParamLen)
memcpy (abtCmd + 2, (byte_t *) pmp, szParamLen);

// Fire the mifare command
if (!nfc_initiator_transceive_bytes(pnd,abtCmd,2+szParamLen,abtRx,&szRxLen)) {
if (!nfc_initiator_transceive_bytes (pnd, abtCmd, 2 + szParamLen, abtRx, &szRxLen)) {
if (pnd->iLastError != 0x14)
nfc_perror (pnd, "nfc_initiator_transceive_bytes");
nfc_perror (pnd, "nfc_initiator_transceive_bytes");
return false;
}

// When we have executed a read command, copy the received bytes into the param
if (mc == MC_READ) {
if(szRxLen == 16) {
memcpy(pmp->mpd.abtData,abtRx,16);
if (szRxLen == 16) {
memcpy (pmp->mpd.abtData, abtRx, 16);
} else {
return false;
}
}

// Command succesfully executed
return true;
}
72 changes: 36 additions & 36 deletions examples/mifare.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,36 @@
*/

#ifndef _LIBNFC_MIFARE_H_
#define _LIBNFC_MIFARE_H_
# define _LIBNFC_MIFARE_H_

#include <nfc/nfc-types.h>
# include <nfc/nfc-types.h>

// Compiler directive, set struct alignment to 1 byte_t for compatibility
#pragma pack(1)
# pragma pack(1)

typedef enum {
MC_AUTH_A = 0x60,
MC_AUTH_B = 0x61,
MC_READ = 0x30,
MC_WRITE = 0xA0,
MC_TRANSFER = 0xB0,
MC_DECREMENT = 0xC0,
MC_INCREMENT = 0xC1,
MC_STORE = 0xC2
MC_AUTH_A = 0x60,
MC_AUTH_B = 0x61,
MC_READ = 0x30,
MC_WRITE = 0xA0,
MC_TRANSFER = 0xB0,
MC_DECREMENT = 0xC0,
MC_INCREMENT = 0xC1,
MC_STORE = 0xC2
} mifare_cmd;

// MIFARE command params
typedef struct {
byte_t abtKey[6];
byte_t abtUid[4];
byte_t abtKey[6];
byte_t abtUid[4];
} mifare_param_auth;

typedef struct {
byte_t abtData[16];
byte_t abtData[16];
} mifare_param_data;

typedef struct {
byte_t abtValue[4];
byte_t abtValue[4];
} mifare_param_value;

typedef union {
Expand All @@ -61,30 +61,30 @@ typedef union {
} mifare_param;

// Reset struct alignment to default
#pragma pack()
# pragma pack()

bool nfc_initiator_mifare_cmd(nfc_device_t* pnd, const mifare_cmd mc, const uint8_t ui8Block, mifare_param* pmp);
bool nfc_initiator_mifare_cmd (nfc_device_t * pnd, const mifare_cmd mc, const uint8_t ui8Block, mifare_param * pmp);

// Compiler directive, set struct alignment to 1 byte_t for compatibility
#pragma pack(1)
# pragma pack(1)

// MIFARE Classic
typedef struct {
byte_t abtUID[4];
byte_t btBCC;
byte_t btUnknown;
byte_t abtATQA[2];
byte_t abtUnknown[8];
byte_t abtUID[4];
byte_t btBCC;
byte_t btUnknown;
byte_t abtATQA[2];
byte_t abtUnknown[8];
} mifare_classic_block_manufacturer;

typedef struct {
byte_t abtData[16];
byte_t abtData[16];
} mifare_classic_block_data;

typedef struct {
byte_t abtKeyA[6];
byte_t abtAccessBits[4];
byte_t abtKeyB[6];
byte_t abtKeyA[6];
byte_t abtAccessBits[4];
byte_t abtKeyB[6];
} mifare_classic_block_trailer;

typedef union {
Expand All @@ -99,17 +99,17 @@ typedef struct {

// MIFARE Ultralight
typedef struct {
byte_t sn0[3];
byte_t btBCC0;
byte_t sn1[4];
byte_t btBCC1;
byte_t internal;
byte_t lock[2];
byte_t otp[4];
byte_t sn0[3];
byte_t btBCC0;
byte_t sn1[4];
byte_t btBCC1;
byte_t internal;
byte_t lock[2];
byte_t otp[4];
} mifareul_block_manufacturer;

typedef struct {
byte_t abtData[16];
byte_t abtData[16];
} mifareul_block_data;

typedef union {
Expand All @@ -122,6 +122,6 @@ typedef struct {
} mifareul_tag;

// Reset struct alignment to default
#pragma pack()
# pragma pack()

#endif // _LIBNFC_MIFARE_H_
Loading

0 comments on commit 18cc86a

Please sign in to comment.