Updated fonts
[hackover2013-badge-firmware.git] / drivers / sensors / pn532 / pn532_mifare.c
1 /**************************************************************************/
2 /*!
3 @file pn532_mifare.c
4 */
5 /**************************************************************************/
6 #include <string.h>
7
8 #include "pn532.h"
9 #include "pn532_mifare.h"
10
11 bool pn532MifareCmd(const pn532_mifare_cmd_t mc, const uint8_t ui8Block, pn532_mifare_param_t * pmp)
12 {
13 byte_t abtRx[265];
14 size_t szRx = sizeof(abtRx);
15 size_t szParamLen;
16 byte_t abtCmd[265];
17 bool bEasyFraming;
18
19 abtCmd[0] = mc; // The MIFARE Classic command
20 abtCmd[1] = ui8Block; // The block address (1K=0x00..0x39, 4K=0x00..0xff)
21
22 switch (mc) {
23 // Read and store command have no parameter
24 case PN532_MIFARE_CMD_READ:
25 case PN532_MIFARE_CMD_STORE:
26 szParamLen = 0;
27 break;
28
29 // Authenticate command
30 case PN532_MIFARE_CMD_AUTH_A:
31 case PN532_MIFARE_CMD_AUTH_B:
32 szParamLen = sizeof (pn532_mifare_param_auth_t);
33 break;
34
35 // Data command
36 case PN532_MIFARE_CMD_WRITE:
37 szParamLen = sizeof (pn532_mifare_param_data_t);
38 break;
39
40 // Value command
41 case PN532_MIFARE_CMD_DECREMENT:
42 case PN532_MIFARE_CMD_INCREMENT:
43 case PN532_MIFARE_CMD_TRANSFER:
44 szParamLen = sizeof (pn532_mifare_param_value_t);
45 break;
46
47 // Please fix your code, you never should reach this statement
48 default:
49 return false;
50 break;
51 }
52
53 // When available, copy the parameter bytes
54 if (szParamLen)
55 memcpy (abtCmd + 2, (byte_t *) pmp, szParamLen);
56
57 // bEasyFraming = pnd->bEasyFraming;
58 // if (!nfc_configure (pnd, NDO_EASY_FRAMING, true)) {
59 // nfc_perror (pnd, "nfc_configure");
60 // return false;
61 // }
62 //
63 // // Fire the mifare command
64 // if (!nfc_initiator_transceive_bytes (pnd, abtCmd, 2 + szParamLen, abtRx, &szRx)) {
65 // if (pnd->iLastError == EINVRXFRAM) {
66 // // "Invalid received frame" AKA EINVRXFRAM, usual means we are
67 // // authenticated on a sector but the requested MIFARE cmd (read, write)
68 // // is not permitted by current acces bytes;
69 // // So there is nothing to do here.
70 // } else {
71 // nfc_perror (pnd, "nfc_initiator_transceive_bytes");
72 // }
73 // nfc_configure (pnd, NDO_EASY_FRAMING, bEasyFraming);
74 // return false;
75 // }
76 // if (!nfc_configure (pnd, NDO_EASY_FRAMING, bEasyFraming)) {
77 // nfc_perror (pnd, "nfc_configure");
78 // return false;
79 // }
80 //
81 // // When we have executed a read command, copy the received bytes into the param
82 // if (mc == MC_READ) {
83 // if (szRx == 16) {
84 // memcpy (pmp->mpd.abtData, abtRx, 16);
85 // } else {
86 // return false;
87 // }
88 // }
89
90 // Command succesfully executed
91 return true;
92 }
This page took 0.081803 seconds and 5 git commands to generate.