Codebase list libfreefare / 26865bb
Remove extra whitespaces/tabs before EOL. find . -name '*.[ch]' | xargs perl -pi -e 's/\t+$//; s/ +$//' Thanks to Ludovic. Romuald Conty 11 years ago
66 changed file(s) with 490 addition(s) and 490 deletion(s). Raw diff Collapse all Expand all
00 /*-
11 * Public platform independent Near Field Communication (NFC) library
2 *
2 *
33 * Copyright (C) 2011, Romuald Conty
4 *
4 *
55 * This program is free software: you can redistribute it and/or modify it
66 * under the terms of the GNU Lesser General Public License as published by the
77 * Free Software Foundation, either version 3 of the License, or (at your
88 * option) any later version.
9 *
9 *
1010 * This program is distributed in the hope that it will be useful, but WITHOUT
1111 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1212 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
00 /*-
11 * Public platform independent Near Field Communication (NFC) library
2 *
2 *
33 * Copyright (C) 2011, Romuald Conty
4 *
4 *
55 * This program is free software: you can redistribute it and/or modify it
66 * under the terms of the GNU Lesser General Public License as published by the
77 * Free Software Foundation, either version 3 of the License, or (at your
88 * option) any later version.
9 *
9 *
1010 * This program is distributed in the hope that it will be useful, but WITHOUT
1111 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1212 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
00 /*-
11 * Public platform independent Near Field Communication (NFC) library
2 *
2 *
33 * Copyright (C) 2010, Romuald Conty
44 * Copyright (C) 2011, Glenn Ergeerts
5 *
5 *
66 * This program is free software: you can redistribute it and/or modify it
77 * under the terms of the GNU Lesser General Public License as published by the
88 * Free Software Foundation, either version 3 of the License, or (at your
99 * option) any later version.
10 *
10 *
1111 * This program is distributed in the hope that it will be useful, but WITHOUT
1212 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1313 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
1717 * along with this program. If not, see <http://www.gnu.org/licenses/>
1818 */
1919
20 /**
20 /**
2121 * @file windows.h
2222 * @brief Provide some windows related hacks due to lack of POSIX compat
2323 */
0 /**
0 /**
11 * @file quick_start_example1.c
22 * @brief Quick start example that presents how to use libnfc
33 */
1717 {
1818 nfc_device *pnd;
1919 nfc_target nt;
20
20
2121 nfc_init (NULL);
2222
2323 // Display libnfc version
3434 // Set opened NFC device to initiator mode
3535 if (nfc_initiator_init (pnd) < 0) {
3636 nfc_perror (pnd, "nfc_initiator_init");
37 exit (EXIT_FAILURE);
37 exit (EXIT_FAILURE);
3838 }
3939
4040 printf ("NFC reader: %s opened\n", nfc_device_get_name (pnd));
00 /*-
11 * Public platform independent Near Field Communication (NFC) library examples
2 *
2 *
33 * Copyright (C) 2009, Roel Verdult
4 *
4 *
55 * Redistribution and use in source and binary forms, with or without
66 * modification, are permitted provided that the following conditions are met:
77 * 1) Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
8 * this list of conditions and the following disclaimer.
99 * 2 )Redistributions in binary form must reproduce the above copyright
1010 * notice, this list of conditions and the following disclaimer in the
1111 * documentation and/or other materials provided with the distribution.
2121 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2222 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2323 * POSSIBILITY OF SUCH DAMAGE.
24 *
24 *
2525 * Note that this license only applies on the examples, NFC library itself is under LGPL
2626 *
2727 */
2828
29 /**
29 /**
3030 * @file nfc-anticol.c
3131 * @brief Generates one ISO14443-A anti-collision process "by-hand"
3232 */
149149 }
150150
151151 nfc_init (NULL);
152
152
153153 // Try to open the NFC reader
154154 pnd = nfc_open (NULL, NULL);
155155
161161 // Initialise NFC device as "initiator"
162162 if (nfc_initiator_init (pnd) < 0) {
163163 nfc_perror (pnd, "nfc_initiator_init");
164 exit (EXIT_FAILURE);
164 exit (EXIT_FAILURE);
165165 }
166166
167167 // Configure the CRC
00 /*-
11 * Public platform independent Near Field Communication (NFC) library examples
2 *
2 *
33 * Copyright (C) 2009, Roel Verdult
44 * Copyright (C) 2010, Romuald Conty
5 *
5 *
66 * Redistribution and use in source and binary forms, with or without
77 * modification, are permitted provided that the following conditions are met:
88 * 1) Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
9 * this list of conditions and the following disclaimer.
1010 * 2 )Redistributions in binary form must reproduce the above copyright
1111 * notice, this list of conditions and the following disclaimer in the
1212 * documentation and/or other materials provided with the distribution.
2222 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2323 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2424 * POSSIBILITY OF SUCH DAMAGE.
25 *
25 *
2626 * Note that this license only applies on the examples, NFC library itself is under LGPL
2727 *
2828 */
6969 printf ("Usage: %s\n", argv[0]);
7070 return EXIT_FAILURE;
7171 }
72
72
7373 nfc_init (NULL);
7474
7575 pnd = nfc_open (NULL, NULL);
00 /*-
11 * Public platform independent Near Field Communication (NFC) library examples
2 *
2 *
33 * Copyright (C) 2009, Roel Verdult
44 * Copyright (C) 2010, Romuald Conty
5 *
5 *
66 * Redistribution and use in source and binary forms, with or without
77 * modification, are permitted provided that the following conditions are met:
88 * 1) Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
9 * this list of conditions and the following disclaimer.
1010 * 2 )Redistributions in binary form must reproduce the above copyright
1111 * notice, this list of conditions and the following disclaimer in the
1212 * documentation and/or other materials provided with the distribution.
2222 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2323 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2424 * POSSIBILITY OF SUCH DAMAGE.
25 *
25 *
2626 * Note that this license only applies on the examples, NFC library itself is under LGPL
2727 *
2828 */
00 /*-
11 * Public platform independent Near Field Communication (NFC) library examples
2 *
2 *
33 * Copyright (C) 2011, Romuald Conty
4 *
4 *
55 * Redistribution and use in source and binary forms, with or without
66 * modification, are permitted provided that the following conditions are met:
77 * 1) Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
8 * this list of conditions and the following disclaimer.
99 * 2 )Redistributions in binary form must reproduce the above copyright
1010 * notice, this list of conditions and the following disclaimer in the
1111 * documentation and/or other materials provided with the distribution.
2121 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2222 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2323 * POSSIBILITY OF SUCH DAMAGE.
24 *
24 *
2525 * Note that this license only applies on the examples, NFC library itself is under LGPL
2626 *
2727 */
3030 * @file nfc-emulate-forum-tag2.c
3131 * @brief Emulates a NFC Forum Tag Type 2 with a NDEF message
3232 * This example allow to emulate an NFC Forum Tag Type 2 that contains a read-only NDEF message.
33 *
33 *
3434 * It have been developed using PN533 USB hardware as target and Google Nexus S phone as initiator.
3535 *
3636 * This is know to NOT work with Nokia 6212 Classic and could not work with
5050 * NFC Forum Type 2 Tag Operation
5151 * Technical Specification
5252 * NFCForum-TS-Type-2-Tag_1.0 - 2007-07-09
53 *
54 * ISO/IEC 14443-3
53 *
54 * ISO/IEC 14443-3
5555 * First edition - 2001-02-01
5656 * Identification cards — Contactless integrated circuit(s) cards — Proximity cards
5757 * Part 3: Initialization and anticollision
8585
8686 static uint8_t __nfcforum_tag2_memory_area[] = {
8787 0x00, 0x00, 0x00, 0x00, // Block 0
88 0x00, 0x00, 0x00, 0x00,
88 0x00, 0x00, 0x00, 0x00,
8989 0x00, 0x00, 0xFF, 0xFF, // Block 2 (Static lock bytes: CC area and data area are read-only locked)
9090 0xE1, 0x10, 0x06, 0x0F, // Block 3 (CC - NFC-Forum Tag Type 2 version 1.0, Data area (from block 4 to the end) is 48 bytes, Read-only mode)
9191
181181 };
182182
183183 signal (SIGINT, stop_emulation);
184 nfc_init (NULL);
184 nfc_init (NULL);
185185 pnd = nfc_open (NULL, NULL);
186186
187187 if (pnd == NULL) {
00 /*-
11 * Public platform independent Near Field Communication (NFC) library examples
2 *
2 *
33 * Copyright (C) 2010, Romuald Conty
4 *
4 *
55 * Redistribution and use in source and binary forms, with or without
66 * modification, are permitted provided that the following conditions are met:
77 * 1) Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
8 * this list of conditions and the following disclaimer.
99 * 2 )Redistributions in binary form must reproduce the above copyright
1010 * notice, this list of conditions and the following disclaimer in the
1111 * documentation and/or other materials provided with the distribution.
2121 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2222 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2323 * POSSIBILITY OF SUCH DAMAGE.
24 *
24 *
2525 * Note that this license only applies on the examples, NFC library itself is under LGPL
2626 *
2727 */
6565 (void) sig;
6666 printf ("\nQuitting...\n");
6767 if (pnd != NULL) {
68 nfc_close(pnd);
68 nfc_close(pnd);
6969 }
7070 nfc_exit (NULL);
7171 exit (EXIT_FAILURE);
7272 }
7373
74 static bool
74 static bool
7575 target_io( nfc_target *pnt, const uint8_t *pbtInput, const size_t szInput, uint8_t *pbtOutput, size_t *pszOutput )
7676 {
7777 bool loop = true;
181181 #endif
182182
183183 nfc_init (NULL);
184
184
185185 // Try to open the NFC reader
186186 pnd = nfc_open (NULL, NULL);
187187
00 /*-
11 * Public platform independent Near Field Communication (NFC) library examples
2 *
2 *
33 * Copyright (C) 2009, Roel Verdult
44 * Copyright (C) 2010, Romuald Conty
5 *
5 *
66 * Redistribution and use in source and binary forms, with or without
77 * modification, are permitted provided that the following conditions are met:
88 * 1) Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
9 * this list of conditions and the following disclaimer.
1010 * 2 )Redistributions in binary form must reproduce the above copyright
1111 * notice, this list of conditions and the following disclaimer in the
1212 * documentation and/or other materials provided with the distribution.
2222 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2323 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2424 * POSSIBILITY OF SUCH DAMAGE.
25 *
25 *
2626 * Note that this license only applies on the examples, NFC library itself is under LGPL
2727 *
2828 */
3030 /**
3131 * @file nfc-emulate-uid.c
3232 * @brief Emulates a tag which which have a "really" custom UID
33 *
33 *
3434 * NFC devices are able to emulate passive tags but manufacturers restrict the
3535 * customization of UID. With PN53x, UID is only 4-byte long and the first
3636 * byte of emulated UID is hard-wired to 0x08 which is the standard way to say
126126 #endif
127127
128128 nfc_init (NULL);
129
129
130130 // Try to open the NFC device
131131 pnd = nfc_open (NULL, NULL);
132132
00 /*-
11 * Public platform independent Near Field Communication (NFC) library examples
2 *
2 *
33 * Copyright (C) 2009, Roel Verdult
44 * Copyright (C) 2011, Adam Laurie
5 *
5 *
66 * Redistribution and use in source and binary forms, with or without
77 * modification, are permitted provided that the following conditions are met:
88 * 1) Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
9 * this list of conditions and the following disclaimer.
1010 * 2 )Redistributions in binary form must reproduce the above copyright
1111 * notice, this list of conditions and the following disclaimer in the
1212 * documentation and/or other materials provided with the distribution.
2222 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2323 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2424 * POSSIBILITY OF SUCH DAMAGE.
25 *
25 *
2626 * Note that this license only applies on the examples, NFC library itself is under LGPL
2727 *
2828 */
2929
30 /**
30 /**
3131 * @file nfc-mfsetuid.c
3232 * @brief Set UID of special Mifare cards
3333 */
177177 }
178178
179179 nfc_init (NULL);
180
180
181181 // Try to open the NFC reader
182182 pnd = nfc_open (NULL, NULL);
183183
189189 // Initialise NFC device as "initiator"
190190 if (nfc_initiator_init (pnd) < 0) {
191191 nfc_perror (pnd, "nfc_initiator_init");
192 exit (EXIT_FAILURE);
192 exit (EXIT_FAILURE);
193193 }
194194
195195 // Configure the CRC
00 /*-
11 * Public platform independent Near Field Communication (NFC) library examples
2 *
2 *
33 * Copyright (C) 2010, Romuald Conty
44 * Copyright (C) 2011, Romain Tartiere, Romuald Conty
5 *
5 *
66 * Redistribution and use in source and binary forms, with or without
77 * modification, are permitted provided that the following conditions are met:
88 * 1) Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
9 * this list of conditions and the following disclaimer.
1010 * 2 )Redistributions in binary form must reproduce the above copyright
1111 * notice, this list of conditions and the following disclaimer in the
1212 * documentation and/or other materials provided with the distribution.
2222 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2323 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2424 * POSSIBILITY OF SUCH DAMAGE.
25 *
25 *
2626 * Note that this license only applies on the examples, NFC library itself is under LGPL
2727 *
2828 */
101101
102102 nfc_target nt;
103103 int res = 0;
104
104
105105 nfc_init (NULL);
106106
107107 pnd = nfc_open (NULL, NULL);
113113
114114 if (nfc_initiator_init (pnd) < 0) {
115115 nfc_perror (pnd, "nfc_initiator_init");
116 exit (EXIT_FAILURE);
116 exit (EXIT_FAILURE);
117117 }
118118
119119 printf ("NFC reader: %s opened\n", nfc_device_get_name (pnd));
00 /*-
11 * Public platform independent Near Field Communication (NFC) library examples
2 *
2 *
33 * Copyright (C) 2009, Roel Verdult
44 * Copyright (C) 2010, Romuald Conty
5 *
5 *
66 * Redistribution and use in source and binary forms, with or without
77 * modification, are permitted provided that the following conditions are met:
88 * 1) Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
9 * this list of conditions and the following disclaimer.
1010 * 2 )Redistributions in binary form must reproduce the above copyright
1111 * notice, this list of conditions and the following disclaimer in the
1212 * documentation and/or other materials provided with the distribution.
2222 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2323 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2424 * POSSIBILITY OF SUCH DAMAGE.
25 *
25 *
2626 * Note that this license only applies on the examples, NFC library itself is under LGPL
2727 *
2828 */
115115 ERR ("%zd device found but two opened devices are needed to relay NFC.", szFound);
116116 return EXIT_FAILURE;
117117 }
118
118
119119 nfc_init (NULL);
120
120
121121 // Try to open the NFC emulator device
122122 pndTag = nfc_open (NULL, connstrings[0]);
123123 if (pndTag == NULL) {
167167
168168 printf ("NFC reader device: %s opened", nfc_device_get_name (pndReader));
169169 printf ("%s", "Configuring NFC reader settings...");
170
170
171171 if (nfc_initiator_init (pndReader) < 0) {
172172 nfc_perror (pndReader, "nfc_initiator_init");
173 exit (EXIT_FAILURE);
173 exit (EXIT_FAILURE);
174174 }
175175 if ((nfc_device_set_property_bool (pndReader, NP_HANDLE_CRC, false) < 0) ||
176176 (nfc_device_set_property_bool (pndReader, NP_HANDLE_PARITY, false) < 0) ||
219219 }
220220 }
221221
222 nfc_close (pndTag);
222 nfc_close (pndTag);
223223 nfc_close (pndReader);
224224 nfc_exit (NULL);
225225 exit (EXIT_SUCCESS);
00 /*-
11 * Public platform independent Near Field Communication (NFC) library examples
2 *
2 *
33 * Copyright (C) 2010, Romuald Conty
4 *
4 *
55 * Redistribution and use in source and binary forms, with or without
66 * modification, are permitted provided that the following conditions are met:
77 * 1) Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
8 * this list of conditions and the following disclaimer.
99 * 2 )Redistributions in binary form must reproduce the above copyright
1010 * notice, this list of conditions and the following disclaimer in the
1111 * documentation and/or other materials provided with the distribution.
2121 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2222 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2323 * POSSIBILITY OF SUCH DAMAGE.
24 *
24 *
2525 * Note that this license only applies on the examples, NFC library itself is under LGPL
2626 *
2727 */
2828
29 /**
29 /**
3030 * @file pn53x-diagnose.c
3131 * @brief Small application to diagnose PN53x using dedicated commands
3232 */
6666 if (argc > 1) {
6767 errx (1, "usage: %s", argv[0]);
6868 }
69
69
7070 nfc_init (NULL);
71
71
7272 // Display libnfc version
7373 acLibnfcVersion = nfc_version ();
7474 printf ("%s uses libnfc %s\n", argv[0], acLibnfcVersion);
00 /*-
11 * Public platform independent Near Field Communication (NFC) library examples
2 *
2 *
33 * Copyright (C) 2010, Emanuele Bertoldi
4 *
4 *
55 * Redistribution and use in source and binary forms, with or without
66 * modification, are permitted provided that the following conditions are met:
77 * 1) Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
8 * this list of conditions and the following disclaimer.
99 * 2 )Redistributions in binary form must reproduce the above copyright
1010 * notice, this list of conditions and the following disclaimer in the
1111 * documentation and/or other materials provided with the distribution.
2121 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2222 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2323 * POSSIBILITY OF SUCH DAMAGE.
24 *
24 *
2525 * Note that this license only applies on the examples, NFC library itself is under LGPL
2626 *
2727 */
7373 {
7474 (void) argc;
7575 (void) argv;
76
76
7777 int ret = EXIT_FAILURE;
7878
7979 nfc_init (NULL);
80
80
8181 // Display libnfc version
8282 const char *acLibnfcVersion = nfc_version ();
8383 printf ("%s uses libnfc %s\n", argv[0], acLibnfcVersion);
00 /*-
11 * Public platform independent Near Field Communication (NFC) library examples
2 *
2 *
33 * Copyright (C) 2010, Romuald Conty
4 *
4 *
55 * Redistribution and use in source and binary forms, with or without
66 * modification, are permitted provided that the following conditions are met:
77 * 1) Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
8 * this list of conditions and the following disclaimer.
99 * 2 )Redistributions in binary form must reproduce the above copyright
1010 * notice, this list of conditions and the following disclaimer in the
1111 * documentation and/or other materials provided with the distribution.
2121 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2222 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2323 * POSSIBILITY OF SUCH DAMAGE.
24 *
24 *
2525 * Note that this license only applies on the examples, NFC library itself is under LGPL
2626 *
2727 */
8383 }
8484
8585 nfc_init (NULL);
86
86
8787 // Try to open the NFC reader
8888 pnd = nfc_open(NULL, NULL);
8989
9595 printf ("NFC reader: %s opened\n", nfc_device_get_name (pnd));
9696 if (nfc_initiator_init (pnd) < 0) {
9797 nfc_perror (pnd, "nfc_initiator_init");
98 exit (EXIT_FAILURE);
98 exit (EXIT_FAILURE);
9999 }
100100
101101 char *cmd;
00 /*-
11 * Public platform independent Near Field Communication (NFC) library
2 *
2 *
33 * Copyright (C) 2011, Romuald Conty, Romain Tartière
4 *
4 *
55 * This program is free software: you can redistribute it and/or modify it
66 * under the terms of the GNU Lesser General Public License as published by the
77 * Free Software Foundation, either version 3 of the License, or (at your
88 * option) any later version.
9 *
9 *
1010 * This program is distributed in the hope that it will be useful, but WITHOUT
1111 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1212 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
1616 * along with this program. If not, see <http://www.gnu.org/licenses/>
1717 */
1818
19 /**
19 /**
2020 * @file nfc-emulation.h
2121 * @brief Provide a small API to ease emulation in libnfc
2222 */
00 /**
11 * Public platform independent Near Field Communication (NFC) library
2 *
2 *
33 * Copyright (C) 2009, Roel Verdult
44 * Copyright (C) 2010, Romain Tartière, Romuald Conty
55 * Copyright (C) 2011, Romain Tartière, Romuald Conty
6 *
6 *
77 * This program is free software: you can redistribute it and/or modify it
88 * under the terms of the GNU Lesser General Public License as published by the
99 * Free Software Foundation, either version 3 of the License, or (at your
1010 * option) any later version.
11 *
11 *
1212 * This program is distributed in the hope that it will be useful, but WITHOUT
1313 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1414 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
1818 * along with this program. If not, see <http://www.gnu.org/licenses/>
1919 */
2020
21 /**
21 /**
2222 * @file nfc-types.h
2323 * @brief Define NFC types
2424 */
4747 * Properties
4848 */
4949 typedef enum {
50 /**
50 /**
5151 * Default command processing timeout
5252 * Property value's (duration) unit is ms and 0 means no timeout (infinite).
5353 * Default value is set by driver layer
5454 */
5555 NP_TIMEOUT_COMMAND,
56 /**
56 /**
5757 * Timeout between ATR_REQ and ATR_RES
5858 * When the device is in initiator mode, a target is considered as mute if no
5959 * valid ATR_RES is received within this timeout value.
00 /*-
11 * Public platform independent Near Field Communication (NFC) library
2 *
2 *
33 * Copyright (C) 2009, Roel Verdult
44 * Copyright (C) 2010, Romuald Conty
5 *
5 *
66 * This program is free software: you can redistribute it and/or modify it
77 * under the terms of the GNU Lesser General Public License as published by the
88 * Free Software Foundation, either version 3 of the License, or (at your
99 * option) any later version.
10 *
10 *
1111 * This program is distributed in the hope that it will be useful, but WITHOUT
1212 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1313 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
136136 #define NFC_EIO -1
137137 /** @ingroup error
138138 * @hideinitializer
139 * Invalid argument(s)
139 * Invalid argument(s)
140140 */
141141 #define NFC_EINVARG -2
142142 /** @ingroup error
143143 * @hideinitializer
144 * Operation not supported by device
144 * Operation not supported by device
145145 */
146146 #define NFC_EDEVNOTSUPP -3
147147 /** @ingroup error
148148 * @hideinitializer
149 * No such device
149 * No such device
150150 */
151151 #define NFC_ENOTSUCHDEV -4
152152 /** @ingroup error
153153 * @hideinitializer
154 * Buffer overflow
154 * Buffer overflow
155155 */
156156 #define NFC_EOVFLOW -5
157157 /** @ingroup error
158158 * @hideinitializer
159 * Operation timed out
159 * Operation timed out
160160 */
161161 #define NFC_ETIMEOUT -6
162162 /** @ingroup error
163163 * @hideinitializer
164 * Operation aborted (by user)
164 * Operation aborted (by user)
165165 */
166166 #define NFC_EOPABORTED -7
167167 /** @ingroup error
168168 * @hideinitializer
169 * Not (yet) implemented
169 * Not (yet) implemented
170170 */
171171 #define NFC_ENOTIMPL -8
172172 /** @ingroup error
173173 * @hideinitializer
174 * Target released
174 * Target released
175175 */
176 #define NFC_ETGRELEASED -10
176 #define NFC_ETGRELEASED -10
177177 /** @ingroup error
178178 * @hideinitializer
179 * Error while RF transmission
179 * Error while RF transmission
180180 */
181181 #define NFC_ERFTRANS -20
182182 /** @ingroup error
186186 #define NFC_ESOFT -80
187187 /** @ingroup error
188188 * @hideinitializer
189 * Device's internal chip error
189 * Device's internal chip error
190190 */
191191 #define NFC_ECHIP -90
192192
00 /*-
11 * Public platform independent Near Field Communication (NFC) library
2 *
2 *
33 * Copyright (C) 2009, 2010, Roel Verdult, Romuald Conty
4 *
4 *
55 * This program is free software: you can redistribute it and/or modify it
66 * under the terms of the GNU Lesser General Public License as published by the
77 * Free Software Foundation, either version 3 of the License, or (at your
88 * option) any later version.
9 *
9 *
1010 * This program is distributed in the hope that it will be useful, but WITHOUT
1111 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1212 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
00 /*-
11 * Public platform independent Near Field Communication (NFC) library
2 *
2 *
33 * Copyright (C) 2009, Roel Verdult, Romuald Conty
44 * Copyright (C) 2010, Roel Verdult, Romuald Conty
55 * Copyright (C) 2011, Romuald Conty, Romain Tartière
6 *
6 *
77 * This program is free software: you can redistribute it and/or modify it
88 * under the terms of the GNU Lesser General Public License as published by the
99 * Free Software Foundation, either version 3 of the License, or (at your
1010 * option) any later version.
11 *
11 *
1212 * This program is distributed in the hope that it will be useful, but WITHOUT
1313 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1414 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
00 /*-
11 * Public platform independent Near Field Communication (NFC) library
2 *
2 *
33 * Copyright (C) 2009, 2010, Roel Verdult, Romuald Conty
44 * Copyright (C) 2010, Roel Verdult, Romuald Conty
55 * Copyright (C) 2011, Romuald Conty, Romain Tartière
6 *
6 *
77 * This program is free software: you can redistribute it and/or modify it
88 * under the terms of the GNU Lesser General Public License as published by the
99 * Free Software Foundation, either version 3 of the License, or (at your
1010 * option) any later version.
11 *
11 *
1212 * This program is distributed in the hope that it will be useful, but WITHOUT
1313 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1414 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
137137 uart_set_speed (serial_port sp, const uint32_t uiPortSpeed)
138138 {
139139 log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "Serial port speed requested to be set to %d bauds.", uiPortSpeed);
140
140
141141 // Portability note: on some systems, B9600 != 9600 so we have to do
142142 // uint32_t <=> speed_t associations by hand.
143143 speed_t stPortSpeed = B9600;
351351 char **res2 = realloc (res, (szRes+1) * sizeof (char *));
352352 if (!res2)
353353 goto oom;
354
354
355355 res = res2;
356356 if (!(res[szRes-1] = malloc (6 + strlen (pdDirEnt->d_name))))
357357 goto oom;
358358
359359 sprintf (res[szRes-1], "/dev/%s", pdDirEnt->d_name);
360
360
361361 szRes++;
362362 res[szRes-1] = NULL;
363363 }
00 /*-
11 * Public platform independent Near Field Communication (NFC) library
2 *
2 *
33 * Copyright (C) 2009, 2010, Roel Verdult, Romuald Conty
4 *
4 *
55 * This program is free software: you can redistribute it and/or modify it
66 * under the terms of the GNU Lesser General Public License as published by the
77 * Free Software Foundation, either version 3 of the License, or (at your
88 * option) any later version.
9 *
9 *
1010 * This program is distributed in the hope that it will be useful, but WITHOUT
1111 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1212 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
166166 do {
167167 log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "ReadFile");
168168 res = ReadFile (((struct serial_port_windows *) sp)->hPort, pbtRx + dwTotalBytesReceived,
169 dwBytesToGet,
169 dwBytesToGet,
170170 &dwBytesReceived, NULL);
171171
172172 dwTotalBytesReceived += dwBytesReceived;
178178 } else if (dwBytesReceived == 0) {
179179 return NFC_ETIMEOUT;
180180 }
181
181
182182 if (((DWORD)szRx) > dwTotalBytesReceived) {
183183 dwBytesToGet -= dwBytesReceived;
184184 }
00 /*-
11 * Public platform independent Near Field Communication (NFC) library
2 *
2 *
33 * Copyright (C) 2011, Romuald Conty, Romain Tartière
4 *
4 *
55 * This program is free software: you can redistribute it and/or modify it
66 * under the terms of the GNU Lesser General Public License as published by the
77 * Free Software Foundation, either version 3 of the License, or (at your
88 * option) any later version.
9 *
9 *
1010 * This program is distributed in the hope that it will be useful, but WITHOUT
1111 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1212 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
7373 #define TgGetTargetStatus 0x8A
7474
7575 /** @note PN53x's normal frame:
76 *
76 *
7777 * .-- Start
7878 * | .-- Packet length
7979 * | | .-- Length checksum
8080 * | | | .-- Direction (D4 Host to PN, D5 PN to Host)
8181 * | | | | .-- Code
8282 * | | | | | .-- Packet checksum
83 * | | | | | | .-- Postamble
83 * | | | | | | .-- Postamble
8484 * V | | | | | |
8585 * ----- V V V V V V
8686 * 00 FF 02 FE D4 02 2A 00
8787 */
8888
8989 /** @note PN53x's extended frame:
90 *
90 *
9191 * .-- Start
9292 * | .-- Fixed to FF to enable extended frame
9393 * | | .-- Packet length
9595 * | | | | .-- Direction (D4 Host to PN, D5 PN to Host)
9696 * | | | | | .-- Code
9797 * | | | | | | .-- Packet checksum
98 * | | | | | | | .-- Postamble
98 * | | | | | | | .-- Postamble
9999 * V V V | | | | |
100100 * ----- ----- ----- V V V V V
101101 * 00 FF FF FF 00 02 FE D4 02 2A 00
102102 */
103103
104 /**
104 /**
105105 * Start bytes, packet length, length checksum, direction, packet checksum and postamble are overhead
106106 */
107107 // The TFI is considered part of the overhead
155155 PNCMD( SAMConfiguration, PN531|PN532 ),
156156 PNCMD( PowerDown, PN531|PN532 ),
157157 PNCMD( AlparCommandForTDA, PN533|RCS360 ), // Has another usage on RC-S360...
158
158
159159 // RF communication
160160 PNCMD( RFConfiguration, PN531|PN532|PN533|RCS360 ),
161161 PNCMD( RFRegulationTest, PN531|PN532|PN533 ),
00 /*-
11 * Public platform independent Near Field Communication (NFC) library
2 *
2 *
33 * Copyright (C) 2009, Roel Verdult, Romuald Conty
44 * Copyright (C) 2010, Roel Verdult, Romuald Conty, Romain Tartière
55 * Copyright (C) 2011, Romuald Conty, Romain Tartière
6 *
6 *
77 * This program is free software: you can redistribute it and/or modify it
88 * under the terms of the GNU Lesser General Public License as published by the
99 * Free Software Foundation, either version 3 of the License, or (at your
1010 * option) any later version.
11 *
11 *
1212 * This program is distributed in the hope that it will be useful, but WITHOUT
1313 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1414 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
7979 nbSupportedModulation++;
8080 CHIP_DATA(pnd)->supported_modulation_as_initiator[nbSupportedModulation] = NMT_FELICA;
8181 nbSupportedModulation++;
82 }
82 }
8383 if (pnd->btSupportByte & SUPPORT_ISO14443B) {
8484 CHIP_DATA(pnd)->supported_modulation_as_initiator[nbSupportedModulation] = NMT_ISO14443B;
8585 nbSupportedModulation++;
86 }
86 }
8787 if(CHIP_DATA(pnd)->type != PN531) {
8888 CHIP_DATA(pnd)->supported_modulation_as_initiator[nbSupportedModulation] = NMT_JEWEL;
8989 nbSupportedModulation++;
9292 nbSupportedModulation++;
9393 CHIP_DATA(pnd)->supported_modulation_as_initiator[nbSupportedModulation] = 0;
9494 }
95
95
9696 if (!CHIP_DATA(pnd)->supported_modulation_as_target) {
9797 CHIP_DATA(pnd)->supported_modulation_as_target = (nfc_modulation_type*) pn53x_supported_modulation_as_target;
9898 }
99
99
100100 // CRC handling should be enabled by default as declared in nfc_device_new
101101 // which is the case by default for pn53x, so nothing to do here
102102 // Parity handling should be enabled by default as declared in nfc_device_new
487487 case NMT_ISO14443BI:
488488 // Skip V & T Addresses
489489 pbtRawData++;
490 if (*pbtRawData != 0x07) { // 0x07 = REPGEN
490 if (*pbtRawData != 0x07) { // 0x07 = REPGEN
491491 return NFC_ECHIP;
492492 }
493493 pbtRawData++;
756756 return res;
757757 }
758758
759 int
759 int
760760 pn53x_set_property_int (struct nfc_device *pnd, const nfc_property property, const int value)
761761 {
762762 switch (property) {
845845 // TODO Made some research around this point:
846846 // timings could be tweak better than this, and maybe we can tweak timings
847847 // to "gain" a sort-of hardware polling (ie. like PN532 does)
848 if (pn53x_RFConfiguration__MaxRetries (pnd,
848 if (pn53x_RFConfiguration__MaxRetries (pnd,
849849 (bEnable) ? 0xff : 0x00, // MxRtyATR, default: active = 0xff, passive = 0x02
850850 (bEnable) ? 0xff : 0x01, // MxRtyPSL, default: 0x01
851851 (bEnable) ? 0xff : 0x02 // MxRtyPassiveActivation, default: 0xff (0x00 leads to problems with PN531)
983983 szRx = (size_t) res;
984984 if ((sizeof(abtExpectedRx) == szRx) && (0 == memcmp (abtRx, abtExpectedRx, sizeof(abtExpectedRx))))
985985 return NFC_SUCCESS;
986
986
987987 return NFC_EIO;
988988 }
989989
10501050 const uint8_t abtReqt[]= { 0x10 };
10511051 // Getting product code / fab code & store it in output buffer after the serial nr we'll obtain later
10521052 if ((res = pn53x_initiator_transceive_bytes (pnd, abtReqt, sizeof(abtReqt), abtTargetsData+2, sizeof(abtTargetsData)-2, timeout)) < 0) {
1053 return res;
1053 return res;
10541054 }
10551055 szTargetsData = (size_t)res;
10561056 }
11221122 nfc_target *pnt)
11231123 {
11241124 int res = 0;
1125
1125
11261126 if (CHIP_DATA(pnd)->type == PN532) {
11271127 size_t szTargetTypes = 0;
11281128 pn53x_target_type apttTargetTypes[32];
11661166 size_t szInitiatorData;
11671167 prepare_initiator_data (pnmModulations[n], &pbtInitiatorData, &szInitiatorData);
11681168 const int timeout_ms = uiPeriod * 150;
1169
1169
11701170 if ((res = pn53x_initiator_select_passive_target_ext (pnd, pnmModulations[n], pbtInitiatorData, szInitiatorData, pnt, timeout_ms)) < 0) {
11711171 if (pnd->last_error != NFC_ETIMEOUT) {
11721172 return pnd->last_error;
16301630 return pn53x_InDeselect (pnd, 0); // 0 mean deselect all selected targets
16311631 }
16321632
1633 int
1633 int
16341634 pn53x_initiator_target_is_present (struct nfc_device *pnd, const nfc_target nt)
16351635 {
16361636 // TODO Check if nt is equal to current target
17851785 // Set System Code
17861786 abtFeliCaParams[16] = 0x0f;
17871787 abtFeliCaParams[17] = 0xab;
1788
1788
17891789 pbtFeliCaParams = abtFeliCaParams;
17901790 break;
17911791 case NMT_ISO14443B:
18831883 uint8_t abtRx[PN53x_EXTENDED_FRAME__DATA_MAX_LEN];
18841884 size_t szRx = sizeof (abtRx);
18851885 int res = 0;
1886
1886
18871887 // Try to gather a received frame from the reader
18881888 if ((res = pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), abtRx, szRx, -1)) < 0)
18891889 return res;
20472047 return pnd->last_error;
20482048 }
20492049 }
2050 // NO BREAK
2050 // NO BREAK
20512051 case NMT_JEWEL:
20522052 case NMT_ISO14443B:
20532053 case NMT_ISO14443BI:
20632063
20642064 // Copy the data into the command frame
20652065 memcpy (abtCmd + 1, pbtTx, szTx);
2066
2066
20672067 // Try to send the bits to the reader
20682068 if ((res = pn53x_transceive (pnd, abtCmd, szTx + 1, NULL, 0, timeout)) < 0)
20692069 return res;
25642564 return res;
25652565 szRx = (size_t) res;
25662566
2567 // Note: the first byte is skip:
2567 // Note: the first byte is skip:
25682568 // its the "mode" byte which contains baudrate, DEP and Framing type (Mifare, active or FeliCa) datas.
25692569 if(pbtModeByte) {
25702570 *pbtModeByte = abtRx[0];
25722572
25732573 // Save the received byte count
25742574 szRx -= 1;
2575
2575
25762576 if ((szRx - 1) > szRxLen)
25772577 return NFC_EOVFLOW;
25782578 // Copy the received bytes
28302830 return PTT_UNDEFINED;
28312831 }
28322832
2833 int
2833 int
28342834 pn53x_get_supported_modulation(nfc_device *pnd, const nfc_mode mode, const nfc_modulation_type * *const supported_mt)
28352835 {
28362836 switch (mode) {
28402840 case N_INITIATOR:
28412841 *supported_mt = CHIP_DATA(pnd)->supported_modulation_as_initiator;
28422842 break;
2843 default:
2843 default:
28442844 return NFC_EINVARG;
28452845 }
28462846 return NFC_SUCCESS;
28482848
28492849 int
28502850 pn53x_get_supported_baud_rate (nfc_device *pnd, const nfc_modulation_type nmt, const nfc_baud_rate * *const supported_br)
2851 {
2851 {
28522852 switch (nmt) {
2853 case NMT_FELICA:
2853 case NMT_FELICA:
28542854 *supported_br = (nfc_baud_rate*)pn53x_felica_supported_baud_rates;
28552855 break;
2856 case NMT_ISO14443A:
2856 case NMT_ISO14443A:
28572857 *supported_br = (nfc_baud_rate*)pn53x_iso14443a_supported_baud_rates;
28582858 break;
28592859 case NMT_ISO14443B:
28712871 case NMT_JEWEL:
28722872 *supported_br = (nfc_baud_rate*)pn53x_jewel_supported_baud_rates;
28732873 break;
2874 case NMT_DEP:
2874 case NMT_DEP:
28752875 *supported_br = (nfc_baud_rate*)pn53x_dep_supported_baud_rates;
28762876 break;
28772877 default:
29052905 if ((res = nfc_device_get_supported_modulation(pnd, N_INITIATOR, &nmt)) < 0) {
29062906 return res;
29072907 }
2908
2908
29092909 for (int i=0; nmt[i]; i++) {
29102910 if ((res = snprintf (buf, buflen, "%s%s (", (i==0)?"":", ", str_nfc_modulation_type (nmt[i]))) < 0) {
29112911 return NFC_ESOFT;
29192919 if ((res = nfc_device_get_supported_baud_rate (pnd, nmt[i], &nbr)) < 0) {
29202920 return res;
29212921 }
2922
2922
29232923 for (int j=0; nbr[j]; j++) {
29242924 if ((res = snprintf (buf, buflen, "%s%s", (j==0)?"":", ", str_nfc_baud_rate (nbr[j]))) < 0) {
29252925 return NFC_ESOFT;
29592959 if ((res = nfc_device_get_supported_modulation(pnd, N_TARGET, &nmt)) < 0) {
29602960 return res;
29612961 }
2962
2962
29632963 for (int i=0; nmt[i]; i++) {
29642964 if ((res = snprintf (buf, buflen, "%s%s (", (i==0)?"":", ", str_nfc_modulation_type (nmt[i]))) < 0) {
29652965 return NFC_ESOFT;
29732973 if ((res = nfc_device_get_supported_baud_rate (pnd, nmt[i], &nbr)) < 0) {
29742974 return res;
29752975 }
2976
2976
29772977 for (int j=0; nbr[j]; j++) {
29782978 if ((res = snprintf (buf, buflen, "%s%s", (j==0)?"":", ", str_nfc_baud_rate (nbr[j]))) < 0) {
29792979 return NFC_ESOFT;
30423042
30433043 // Set default communication timeout (52 ms)
30443044 CHIP_DATA (pnd)->timeout_communication = 52;
3045
3045
30463046 CHIP_DATA (pnd)->supported_modulation_as_initiator = NULL;
3047
3048 CHIP_DATA (pnd)->supported_modulation_as_target = NULL;
3047
3048 CHIP_DATA (pnd)->supported_modulation_as_target = NULL;
30493049 }
30503050
30513051 void
00 /*-
11 * Public platform independent Near Field Communication (NFC) library
2 *
2 *
33 * Copyright (C) 2009, Roel Verdult, Romuald Conty
44 * Copyright (C) 2010, Roel Verdult, Romuald Conty, Romain Tartière
55 * Copyright (C) 2011, Romuald Conty, Romain Tartière
6 *
6 *
77 * This program is free software: you can redistribute it and/or modify it
88 * under the terms of the GNU Lesser General Public License as published by the
99 * Free Software Foundation, either version 3 of the License, or (at your
1010 * option) any later version.
11 *
11 *
1212 * This program is distributed in the hope that it will be useful, but WITHOUT
1313 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1414 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
1818 * along with this program. If not, see <http://www.gnu.org/licenses/>
1919 */
2020
21 /**
21 /**
2222 * @file pn53x.h
2323 * @brief PN531, PN532 and PN533 common functions
2424 */
188188 int timeout_atr;
189189 /** Communication timeout */
190190 int timeout_communication;
191 /** Supported modulation type */
192 nfc_modulation_type *supported_modulation_as_initiator;
191 /** Supported modulation type */
192 nfc_modulation_type *supported_modulation_as_initiator;
193193 nfc_modulation_type *supported_modulation_as_target;
194194 };
195195
209209 /** JIS X 6319-4 (Sony Felica) http://en.wikipedia.org/wiki/FeliCa */
210210 PM_FELICA_424 = 0x02,
211211 /** ISO14443-B http://en.wikipedia.org/wiki/ISO/IEC_14443 (Not supported by PN531) */
212 PM_ISO14443B_106 = 0x03,
212 PM_ISO14443B_106 = 0x03,
213213 /** Jewel Topaz (Innovision Research & Development) (Not supported by PN531) */
214214 PM_JEWEL_106 = 0x04,
215215 /** ISO14443-B http://en.wikipedia.org/wiki/ISO/IEC_14443 (Not supported by PN531 nor PN532) */
321321 nfc_target *pnt);
322322 int pn53x_initiator_select_dep_target (struct nfc_device *pnd,
323323 const nfc_dep_mode ndm, const nfc_baud_rate nbr,
324 const nfc_dep_info *pndiInitiator,
324 const nfc_dep_info *pndiInitiator,
325325 nfc_target *pnt,
326326 const int timeout);
327327 int pn53x_initiator_transceive_bits (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits,
00 /*-
11 * Public platform independent Near Field Communication (NFC) library
2 *
2 *
33 * Copyright (C) 2009, Roel Verdult
44 * Copyright (C) 2011, Romain Tartiere, Romuald Conty
55 * Copyright (C) 2012, Romuald Conty
6 *
6 *
77 * This program is free software: you can redistribute it and/or modify it
88 * under the terms of the GNU Lesser General Public License as published by the
99 * Free Software Foundation, either version 3 of the License, or (at your
1010 * option) any later version.
11 *
11 *
1212 * This program is distributed in the hope that it will be useful, but WITHOUT
1313 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1414 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
281281 pn53x_data_new (pnd, &acr122_pcsc_io);
282282
283283 SCARDCONTEXT *pscc;
284
284
285285 log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "Attempt to open %s", ndd.pcsc_device_name);
286286 // Test if context succeeded
287287 if (!(pscc = acr122_pcsc_get_scardcontext ()))
00 /**
11 * Public platform independent Near Field Communication (NFC) library
2 *
2 *
33 * Copyright (C) 2009, Roel Verdult
44 * Copyright (C) 2011, Romain Tartiere, Romuald Conty
55 * Copyright (C) 2012, Romuald Conty
6 *
6 *
77 * This program is free software: you can redistribute it and/or modify it
88 * under the terms of the GNU Lesser General Public License as published by the
99 * Free Software Foundation, either version 3 of the License, or (at your
1010 * option) any later version.
11 *
11 *
1212 * This program is distributed in the hope that it will be useful, but WITHOUT
1313 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1414 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
1616 *
1717 * You should have received a copy of the GNU Lesser General Public License
1818 * along with this program. If not, see <http://www.gnu.org/licenses/>
19 *
20 *
19 *
20 *
2121 * @file acr122_pcsc.h
2222 * @brief Driver for ACR122 devices (behind PC/SC daemon)
2323 */
00 /*-
11 * Public platform independent Near Field Communication (NFC) library
2 *
2 *
33 * Copyright (C) 2009, Roel Verdult
44 * Copyright (C) 2010, Romain Tartière, Romuald Conty
55 * Copyright (C) 2011, Romain Tartière, Romuald Conty
6 *
6 *
77 * This program is free software: you can redistribute it and/or modify it
88 * under the terms of the GNU Lesser General Public License as published by the
99 * Free Software Foundation, either version 3 of the License, or (at your
1010 * option) any later version.
11 *
11 *
1212 * This program is distributed in the hope that it will be useful, but WITHOUT
1313 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1414 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
3232 * Revision 1.1
3333 * April 22rd, 2005
3434 * http://www.usb.org/developers/devclass_docs/DWG_Smart-Card_CCID_Rev110.pdf
35 *
35 *
3636 * ACR122U NFC Reader
3737 * Application Programming Interface
3838 * Revision 1.2
683683
684684 /*
685685 // See ACR122 manual: "Bi-Color LED and Buzzer Control" section
686 uint8_t acr122u_get_led_state_frame[] = {
686 uint8_t acr122u_get_led_state_frame[] = {
687687 0x6b, // CCID
688688 0x09, // lenght of frame
689689 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // padding
00 /**
11 * Public platform independent Near Field Communication (NFC) library
2 *
2 *
33 * Copyright (C) 2009, Roel Verdult
44 * Copyright (C) 2011, Romain Tartière
5 *
5 *
66 * This program is free software: you can redistribute it and/or modify it
77 * under the terms of the GNU Lesser General Public License as published by the
88 * Free Software Foundation, either version 3 of the License, or (at your
99 * option) any later version.
10 *
10 *
1111 * This program is distributed in the hope that it will be useful, but WITHOUT
1212 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1313 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
1515 *
1616 * You should have received a copy of the GNU Lesser General Public License
1717 * along with this program. If not, see <http://www.gnu.org/licenses/>
18 *
19 *
18 *
19 *
2020 * @file acr122_usb.h
2121 * @brief Driver for ACR122 devices using direct USB connection (without PCSC)
2222 */
478478 return false;
479479 #else /* SERIAL_AUTOPROBE_ENABLED */
480480 *pszDeviceFound = 0;
481
481
482482 serial_port sp;
483483 char **acPorts = uart_list_ports ();
484484 const char *acPort;
487487 while ((acPort = acPorts[iDevice++])) {
488488 sp = uart_open (acPort);
489489 log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "Trying to find ACR122S device on serial port: %s at %d bauds.", acPort, ACR122S_DEFAULT_SPEED);
490
490
491491 if ((sp != INVALID_SERIAL_PORT) && (sp != CLAIMED_SERIAL_PORT)) {
492492 // We need to flush input to be sure first reply does not comes from older byte transceive
493493 uart_flush_input (sp);
511511 pn53x_data_new(pnd, &acr122s_io);
512512 CHIP_DATA(pnd)->type = PN532;
513513 CHIP_DATA(pnd)->power_mode = NORMAL;
514
514
515515 char version[32];
516516 int ret = acr122s_get_firmware_version(pnd, version, sizeof(version));
517517 if (ret == 0 && strncmp("ACR122S", version, 7) != 0) {
524524
525525 if (ret != 0)
526526 continue;
527
527
528528 // ACR122S reader is found
529529 memcpy (connstrings[*pszDeviceFound], connstring, sizeof(nfc_connstring));
530530 (*pszDeviceFound)++;
531
531
532532 // Test if we reach the maximum "wanted" devices
533533 if (*pszDeviceFound >= connstrings_len)
534534 break;
550550 nfc_device *pnd;
551551 struct acr122s_descriptor ndd;
552552 int connstring_decode_level = acr122s_connstring_decode (connstring, &ndd);
553
553
554554 if (connstring_decode_level < 2) {
555555 return NULL;
556556 }
00 /*-
11 * Public platform independent Near Field Communication (NFC) library
2 *
2 *
33 * Copyright (C) 2009, Roel Verdult
44 * Copyright (C) 2010, Romuald Conty
55 * Copyright (C) 2011, Romain Tartière, Romuald Conty
6 *
6 *
77 * This program is free software: you can redistribute it and/or modify it
88 * under the terms of the GNU Lesser General Public License as published by the
99 * Free Software Foundation, either version 3 of the License, or (at your
1010 * option) any later version.
11 *
11 *
1212 * This program is distributed in the hope that it will be useful, but WITHOUT
1313 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1414 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
2121 /**
2222 * @file arygon.c
2323 * @brief ARYGON readers driver
24 *
24 *
2525 * This driver can handle ARYGON readers that use UART as bus.
2626 * UART connection can be direct (host<->arygon_uc) or could be provided by internal USB to serial interface (e.g. host<->ftdi_chip<->arygon_uc)
2727 */
4949 #include "uart.h"
5050
5151 /** @def DEV_ARYGON_PROTOCOL_ARYGON_ASCII
52 * @brief High level language in ASCII format. (Common µC commands and Mifare® commands)
52 * @brief High level language in ASCII format. (Common µC commands and Mifare® commands)
5353 */
5454 #define DEV_ARYGON_PROTOCOL_ARYGON_ASCII '0'
5555 /** @def DEV_ARYGON_MODE_HL_ASCII
56 * @brief High level language in Binary format With AddressingByte for party line. (Common µC commands and Mifare® commands)
56 * @brief High level language in Binary format With AddressingByte for party line. (Common µC commands and Mifare® commands)
5757 */
5858 #define DEV_ARYGON_PROTOCOL_ARYGON_BINARY_WAB '1'
5959 /** @def DEV_ARYGON_PROTOCOL_TAMA
540540 return NFC_SUCCESS;
541541 }
542542
543 static int
543 static int
544544 arygon_abort_command (nfc_device *pnd)
545545 {
546546 if (pnd) {
00 /**
11 * Public platform independent Near Field Communication (NFC) library
2 *
2 *
33 * Copyright (C) 2009, Roel Verdult
44 * Copyright (C) 2010, Romuald Conty
55 * Copyright (C) 2011, Romuald Conty, Romain Tartière
6 *
6 *
77 * This program is free software: you can redistribute it and/or modify it
88 * under the terms of the GNU Lesser General Public License as published by the
99 * Free Software Foundation, either version 3 of the License, or (at your
1010 * option) any later version.
11 *
11 *
1212 * This program is distributed in the hope that it will be useful, but WITHOUT
1313 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1414 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
1616 *
1717 * You should have received a copy of the GNU Lesser General Public License
1818 * along with this program. If not, see <http://www.gnu.org/licenses/>
19 *
20 *
19 *
20 *
2121 * @file arygon.h
2222 * @brief Driver for PN53x-equipped ARYGON device connected using UART
2323 */
00 /*-
11 * Public platform independent Near Field Communication (NFC) library
2 *
2 *
33 * Copyright (C) 2010, Roel Verdult, Romuald Conty
44 * Copyright (C) 2011, Romuald Conty, Romain Tartière
5 *
5 *
66 * This program is free software: you can redistribute it and/or modify it
77 * under the terms of the GNU Lesser General Public License as published by the
88 * Free Software Foundation, either version 3 of the License, or (at your
99 * option) any later version.
10 *
10 *
1111 * This program is distributed in the hope that it will be useful, but WITHOUT
1212 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1313 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
6060 volatile bool abort_flag;
6161 #endif
6262 };
63
63
6464 #define DRIVER_DATA(pnd) ((struct pn532_uart_data*)(pnd->driver_data))
6565
6666 bool
00 /**
11 * Public platform independent Near Field Communication (NFC) library
2 *
2 *
33 * Copyright (C) 2010, Roel Verdult, Romuald Conty
44 * Copyright (C) 2011, Romuald Conty, Romain Tartière
5 *
5 *
66 * This program is free software: you can redistribute it and/or modify it
77 * under the terms of the GNU Lesser General Public License as published by the
88 * Free Software Foundation, either version 3 of the License, or (at your
99 * option) any later version.
10 *
10 *
1111 * This program is distributed in the hope that it will be useful, but WITHOUT
1212 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1313 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
1515 *
1616 * You should have received a copy of the GNU Lesser General Public License
1717 * along with this program. If not, see <http://www.gnu.org/licenses/>
18 *
19 *
18 *
19 *
2020 * @file pn532_uart.h
2121 * @brief Driver for PN532 connected in UART (HSU)
2222 */
00 /*-
11 * Public platform independent Near Field Communication (NFC) library
2 *
2 *
33 * Copyright (C) 2009, Roel Verdult
44 * Copyright (C) 2010, Romain Tartière, Romuald Conty
55 * Copyright (C) 2011, Romain Tartière, Romuald Conty
6 *
6 *
77 * This program is free software: you can redistribute it and/or modify it
88 * under the terms of the GNU Lesser General Public License as published by the
99 * Free Software Foundation, either version 3 of the License, or (at your
1010 * option) any later version.
11 *
11 *
1212 * This program is distributed in the hope that it will be useful, but WITHOUT
1313 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1414 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
685685
686686 /*
687687 On ASK LoGO hardware:
688 LEDs port bits definition:
688 LEDs port bits definition:
689689 * LED 1: bit 2 (P32)
690690 * LED 2: bit 1 (P31)
691691 * LED 3: bit 0 or 3 (depending of hardware revision) (P30 or P33)
692692 * LED 4: bit 5 (P35)
693 Notes:
694 * Set logical 0 to switch LED on; logical 1 to switch LED off.
693 Notes:
694 * Set logical 0 to switch LED on; logical 1 to switch LED off.
695695 * Bit 4 should be maintained at 1 to keep RF field on.
696696
697697 Progressive field activation:
698698 The ASK LoGO hardware can progressively power-up the antenna.
699699 To use this feature we have to switch on the field by switching on
700 the field on PN533 (RFConfiguration) then set P34 to '1', and cut-off the
700 the field on PN533 (RFConfiguration) then set P34 to '1', and cut-off the
701701 field by switching off the field on PN533 then set P34 to '0'.
702702 */
703703
00 /**
11 * Public platform independent Near Field Communication (NFC) library
2 *
2 *
33 * Copyright (C) 2009, Roel Verdult
44 * Copyright (C) 2011, Romain Tartière
5 *
5 *
66 * This program is free software: you can redistribute it and/or modify it
77 * under the terms of the GNU Lesser General Public License as published by the
88 * Free Software Foundation, either version 3 of the License, or (at your
99 * option) any later version.
10 *
10 *
1111 * This program is distributed in the hope that it will be useful, but WITHOUT
1212 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1313 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
1515 *
1616 * You should have received a copy of the GNU Lesser General Public License
1717 * along with this program. If not, see <http://www.gnu.org/licenses/>
18 *
19 *
18 *
19 *
2020 * @file pn53x_usb.h
2121 * @brief Drive for PN53x USB devices
2222 */
00 /*-
11 * Public platform independent Near Field Communication (NFC) library
2 *
2 *
33 * Copyright (C) 2009, Roel Verdult
44 * Copyright (C) 2011, Romuald Conty, Romain Tartière
5 *
5 *
66 * This program is free software: you can redistribute it and/or modify it
77 * under the terms of the GNU Lesser General Public License as published by the
88 * Free Software Foundation, either version 3 of the License, or (at your
99 * option) any later version.
10 *
10 *
1111 * This program is distributed in the hope that it will be useful, but WITHOUT
1212 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1313 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
00 /*-
11 * Public platform independent Near Field Communication (NFC) library
2 *
2 *
33 * Copyright (C) 2009, Roel Verdult
4 *
4 *
55 * This program is free software: you can redistribute it and/or modify it
66 * under the terms of the GNU Lesser General Public License as published by the
77 * Free Software Foundation, either version 3 of the License, or (at your
88 * option) any later version.
9 *
9 *
1010 * This program is distributed in the hope that it will be useful, but WITHOUT
1111 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1212 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
9494 * @brief Add cascade tags (0x88) in UID
9595 * @see ISO/IEC 14443-3 (6.4.4 UID contents and cascade levels)
9696 */
97 void
97 void
9898 iso14443_cascade_uid (const uint8_t abtUID[], const size_t szUID, uint8_t *pbtCascadedUID, size_t *pszCascadedUID)
9999 {
100 switch (szUID) {
101 case 7:
102 pbtCascadedUID[0] = 0x88;
103 memcpy (pbtCascadedUID + 1, abtUID, 7);
104 *pszCascadedUID = 8;
105 break;
106
107 case 10:
108 pbtCascadedUID[0] = 0x88;
109 memcpy (pbtCascadedUID + 1, abtUID, 3);
110 pbtCascadedUID[4] = 0x88;
111 memcpy (pbtCascadedUID + 5, abtUID + 3, 7);
112 *pszCascadedUID = 12;
113 break;
114
115 case 4:
116 default:
117 memcpy (pbtCascadedUID, abtUID, szUID);
118 *pszCascadedUID = szUID;
119 break;
120 }
100 switch (szUID) {
101 case 7:
102 pbtCascadedUID[0] = 0x88;
103 memcpy (pbtCascadedUID + 1, abtUID, 7);
104 *pszCascadedUID = 8;
105 break;
106
107 case 10:
108 pbtCascadedUID[0] = 0x88;
109 memcpy (pbtCascadedUID + 1, abtUID, 3);
110 pbtCascadedUID[4] = 0x88;
111 memcpy (pbtCascadedUID + 5, abtUID + 3, 7);
112 *pszCascadedUID = 12;
113 break;
114
115 case 4:
116 default:
117 memcpy (pbtCascadedUID, abtUID, szUID);
118 *pszCascadedUID = szUID;
119 break;
120 }
121121 }
00 /*-
11 * Public platform independent Near Field Communication (NFC) library
2 *
2 *
33 * Copyright (C) 2011, Romuald Conty, Romain Tartière
4 *
4 *
55 * This program is free software: you can redistribute it and/or modify it
66 * under the terms of the GNU Lesser General Public License as published by the
77 * Free Software Foundation, either version 3 of the License, or (at your
88 * option) any later version.
9 *
9 *
1010 * This program is distributed in the hope that it will be useful, but WITHOUT
1111 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1212 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
4040 __attribute__((format(printf, 3, 4)))
4141 # endif
4242 ;
43
44
43
44
4545 #define NFC_PRIORITY_FATAL "fatal"
4646 #define NFC_PRIORITY_ALERT "alert"
4747 #define NFC_PRIORITY_CRIT "critical"
5858 #define log_msg(category, priority, message) do {} while (0)
5959 #define log_set_appender(category, appender) do {} while (0)
6060 #define log_put(category, priority, format, ...) do {} while (0)
61
61
6262 #define NFC_PRIORITY_FATAL 8
6363 #define NFC_PRIORITY_ALERT 7
6464 #define NFC_PRIORITY_CRIT 6
00 /*-
11 * Public platform independent Near Field Communication (NFC) library
2 *
2 *
33 * Copyright (C) 2009, Roel Verdult
4 *
4 *
55 * This program is free software: you can redistribute it and/or modify it
66 * under the terms of the GNU Lesser General Public License as published by the
77 * Free Software Foundation, either version 3 of the License, or (at your
88 * option) any later version.
9 *
9 *
1010 * This program is distributed in the hope that it will be useful, but WITHOUT
1111 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1212 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
00 /**
11 * Public platform independent Near Field Communication (NFC) library
2 *
2 *
33 * Copyright (C) 2009, Roel Verdult
4 *
4 *
55 * This program is free software: you can redistribute it and/or modify it
66 * under the terms of the GNU Lesser General Public License as published by the
77 * Free Software Foundation, either version 3 of the License, or (at your
88 * option) any later version.
9 *
9 *
1010 * This program is distributed in the hope that it will be useful, but WITHOUT
1111 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1212 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
1414 *
1515 * You should have received a copy of the GNU Lesser General Public License
1616 * along with this program. If not, see <http://www.gnu.org/licenses/>
17 *
18 *
17 *
18 *
1919 * @file mirror-subr.h
2020 * @brief Mirror bytes
2121 */
00 /*-
11 * Public platform independent Near Field Communication (NFC) library
2 *
2 *
33 * Copyright (C) 2011, Romain Tartière, Romuald Conty
4 *
4 *
55 * This program is free software: you can redistribute it and/or modify it
66 * under the terms of the GNU Lesser General Public License as published by the
77 * Free Software Foundation, either version 3 of the License, or (at your
88 * option) any later version.
9 *
9 *
1010 * This program is distributed in the hope that it will be useful, but WITHOUT
1111 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1212 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
00 /*-
11 * Public platform independent Near Field Communication (NFC) library
2 *
2 *
33 * Copyright (C) 2011, Romuald Conty, Romain Tartière
4 *
4 *
55 * This program is free software: you can redistribute it and/or modify it
66 * under the terms of the GNU Lesser General Public License as published by the
77 * Free Software Foundation, either version 3 of the License, or (at your
88 * option) any later version.
9 *
9 *
1010 * This program is distributed in the hope that it will be useful, but WITHOUT
1111 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1212 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
00 /*-
11 * Public platform independent Near Field Communication (NFC) library
2 *
2 *
33 * Copyright (C) 2011, Romuald Conty
4 *
4 *
55 * This program is free software: you can redistribute it and/or modify it
66 * under the terms of the GNU Lesser General Public License as published by the
77 * Free Software Foundation, either version 3 of the License, or (at your
88 * option) any later version.
9 *
9 *
1010 * This program is distributed in the hope that it will be useful, but WITHOUT
1111 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1212 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
2424 #include <nfc/nfc.h>
2525 #include "nfc-internal.h"
2626
27 void
27 void
2828 prepare_initiator_data (const nfc_modulation nm, uint8_t **ppbtInitiatorData, size_t * pszInitiatorData)
2929 {
3030 switch (nm.nmt) {
00 /*-
11 * Public platform independent Near Field Communication (NFC) library
2 *
2 *
33 * Copyright (C) 2011, Romain Tartière, Romuald Conty
4 *
4 *
55 * This program is free software: you can redistribute it and/or modify it
66 * under the terms of the GNU Lesser General Public License as published by the
77 * Free Software Foundation, either version 3 of the License, or (at your
88 * option) any later version.
9 *
9 *
1010 * This program is distributed in the hope that it will be useful, but WITHOUT
1111 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1212 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
5353
5454 /*
5555 * Buffer management macros.
56 *
56 *
5757 * The following macros ease setting-up and using buffers:
5858 * BUFFER_INIT (data, 5); // data -> [ xx, xx, xx, xx, xx ]
5959 * BUFFER_SIZE (data); // size -> 0
00 /*-
11 * Public platform independent Near Field Communication (NFC) library
2 *
2 *
33 * Copyright (C) 2009, Roel Verdult, Romuald Conty
44 * Copyright (C) 2010, Roel Verdult, Romuald Conty, Romain Tartière
55 * Copyright (C) 2011, Romuald Conty, Romain Tartière
6 *
6 *
77 * This program is free software: you can redistribute it and/or modify it
88 * under the terms of the GNU Lesser General Public License as published by the
99 * Free Software Foundation, either version 3 of the License, or (at your
1010 * option) any later version.
11 *
11 *
1212 * This program is distributed in the hope that it will be useful, but WITHOUT
1313 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1414 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
1818 * along with this program. If not, see <http://www.gnu.org/licenses/>
1919 */
2020
21 /**
21 /**
2222 * @file nfc.c
2323 * @brief NFC library implementation
2424 */
2929 * must not call any libnfc functions after deinitialization.
3030 */
3131 /**
32 * @defgroup dev NFC Device/Hardware manipulation
32 * @defgroup dev NFC Device/Hardware manipulation
3333 * The functionality documented below is designed to help with the following
3434 * operations:
3535 * - Enumerating the NFC devices currently attached to the system
3636 * - Opening and closing the chosen device
37 */
37 */
3838 /**
3939 * @defgroup initiator NFC initiator
4040 * This page details how to act as "reader".
41 */
41 */
4242 /**
4343 * @defgroup target NFC target
4444 * This page details how to act as tag (i.e. MIFARE Classic) or NFC target device.
45 */
45 */
4646 /**
4747 * @defgroup error Error reporting
4848 * Most libnfc functions return 0 on success or one of error codes defined on failure.
49 */
49 */
5050 /**
5151 * @defgroup data Special data accessors
5252 * The functionnality documented below allow to access to special data as device name or device connstring.
53 */
53 */
5454 /**
5555 * @defgroup properties Properties accessors
5656 * The functionnality documented below allow to configure parameters and registers.
57 */
57 */
5858 /**
5959 * @defgroup misc Miscellaneous
60 *
61 */
60 *
61 */
6262
6363 /* vim:set ts=2 sw=2 et: */
6464
127127
128128 /** @ingroup dev
129129 * @brief Get the defaut NFC device
130 * @param connstring \a nfc_connstring pointer where the default connection string will be stored
130 * @param connstring \a nfc_connstring pointer where the default connection string will be stored
131131 * @return \e true on success
132132 *
133133 * This function fill \e connstring with the LIBNFC_DEFAULT_DEVICE environment variable content
135135 * \e connstring with the corresponding \a nfc_connstring value.
136136 *
137137 * This function returns true when LIBNFC_DEFAULT_DEVICE is set or an available device is found.
138 *
138 *
139139 * @note The \e connstring content can be invalid if LIBNFC_DEFAULT_DEVICE is
140140 * set with incorrect value.
141141 */
142 bool
142 bool
143143 nfc_get_default_device (nfc_connstring *connstring)
144144 {
145145 char *env_default_connstring = getenv ("LIBNFC_DEFAULT_DEVICE");
165165 * @return Returns pointer to a \a nfc_device struct if successfull; otherwise returns \c NULL value.
166166 *
167167 * If \e connstring is \c NULL, the \a nfc_get_default_device() function is used.
168 *
168 *
169169 * If \e connstring is set, this function will try to claim the right device using information provided by \e connstring.
170170 *
171171 * When it has successfully claimed a NFC device, memory is allocated to save the device information.
172172 * It will return a pointer to a \a nfc_device struct.
173173 * This pointer should be supplied by every next functions of libnfc that should perform an action with this device.
174174 *
175 * @note Depending on the desired operation mode, the device needs to be configured by using nfc_initiator_init() or nfc_target_init(),
175 * @note Depending on the desired operation mode, the device needs to be configured by using nfc_initiator_init() or nfc_target_init(),
176176 * optionally followed by manual tuning of the parameters if the default parameters are not suiting your goals.
177177 */
178178 nfc_device *
190190 } else {
191191 strncpy (ncs, connstring, sizeof (nfc_connstring));
192192 }
193
193
194194 // Search through the device list for an available device
195195 const struct nfc_driver *ndr;
196196 const struct nfc_driver **pndr = nfc_drivers;
197197 while ((ndr = *pndr)) {
198 // Specific device is requested: using device description
198 // Specific device is requested: using device description
199199 if (0 != strncmp (ndr->name, ncs, strlen(ndr->name))) {
200200 pndr++;
201201 continue;
208208 log_fini ();
209209 return pnd;
210210 }
211
211
212212 log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "\"%s\" (%s) has been claimed.", pnd->name, pnd->connstring);
213213 log_fini ();
214214 return pnd;
232232 if (pnd) {
233233 // Go in idle mode
234234 nfc_idle (pnd);
235 // Close, clean up and release the device
235 // Close, clean up and release the device
236236 pnd->driver->close (pnd);
237237
238238 }
244244 * @param context The context to operate on, or NULL for the default context.
245245 * @param connstrings array of \a nfc_connstring.
246246 * @param szDevices size of the \a connstrings array.
247 *
247 *
248248 */
249249 size_t
250250 nfc_list_devices (nfc_context *context, nfc_connstring connstrings[] , size_t szDevices)
281281 *
282282 * @see nfc_property enum values
283283 */
284 int
284 int
285285 nfc_device_set_property_int (nfc_device *pnd, const nfc_property property, const int value)
286286 {
287287 HAL (device_set_property_int, pnd, property, value);
384384 *
385385 * @param[out] pnt \a nfc_target struct pointer which will filled if available
386386 *
387 * The NFC device will try to find one available passive tag or emulated tag.
387 * The NFC device will try to find one available passive tag or emulated tag.
388388 *
389389 * The chip needs to know with what kind of tag it is dealing with, therefore
390390 * the initial modulation and speed (106, 212 or 424 kbps) should be supplied.
518518 * The NFC device will try to find an available D.E.P. target. The standards
519519 * (ISO18092 and ECMA-340) describe the modulation that can be used for reader
520520 * to passive communications.
521 *
521 *
522522 * @note \a nfc_dep_info will be returned when the target was acquired successfully.
523523 */
524524 int
525 nfc_initiator_select_dep_target (nfc_device *pnd,
525 nfc_initiator_select_dep_target (nfc_device *pnd,
526526 const nfc_dep_mode ndm, const nfc_baud_rate nbr,
527527 const nfc_dep_info *pndiInitiator, nfc_target *pnt, const int timeout)
528528 {
543543 * The NFC device will try to find an available D.E.P. target. The standards
544544 * (ISO18092 and ECMA-340) describe the modulation that can be used for reader
545545 * to passive communications.
546 *
546 *
547547 * @note \a nfc_dep_info will be returned when the target was acquired successfully.
548548 */
549549 int
598598 * @param[out] pbtRx response from the tags
599599 * @param szRx size of \a pbtRx (Will return NFC_EOVFLOW if RX exceeds this size)
600600 * @param timeout in milliseconds
601 *
601 *
602602 * The NFC device (configured as initiator) will transmit the supplied bytes (\a pbtTx) to the target.
603603 * It waits for the response and stores the received bytes in the \a pbtRx byte array.
604604 *
645645 * explain how it works, if you just are sending two bytes with ISO14443-A
646646 * compliant parity bits you better can use the
647647 * nfc_initiator_transceive_bytes() function.
648 *
648 *
649649 * @param[out] pbtRx response from the tag
650650 * @param[out] pbtRxPar parameter contains a byte array of the corresponding parity bits
651651 *
849849 /** @ingroup target
850850 * @brief Receive bytes and APDU frames
851851 * @return Returns received bytes count on success, otherwise returns libnfc's error code
852 *
852 *
853853 * @param pnd \a nfc_device struct pointer that represent currently used device
854854 * @param pbtRx pointer to Rx buffer
855855 * @param szRx size of Rx buffer
927927 /** @ingroup error
928928 * @brief Return the last error string
929929 * @return Returns a string
930 *
930 *
931931 * @param pnd \a nfc_device struct pointer that represent currently used device
932932 */
933933 const char *
934934 nfc_strerror (const nfc_device *pnd)
935 {
935 {
936936 const char *pcRes = "Unknown error";
937937 size_t i;
938938 for (i = 0; i < (sizeof (sErrorMessages) / sizeof (struct sErrorMessage)); i++) {
948948 /** @ingroup error
949949 * @brief Renders the last error in pcStrErrBuf for a maximum size of szBufLen chars
950950 * @return Returns 0 upon success
951 *
951 *
952952 * @param pnd \a nfc_device struct pointer that represent currently used device
953953 * @param pcStrErrBuf a string that contains the last error.
954954 * @param szBufLen size of buffer
961961
962962 /** @ingroup error
963963 * @brief Display the last error occured on a nfc_device
964 *
965 * @param pnd \a nfc_device struct pointer that represent currently used device
966 * @param pcString a string
964 *
965 * @param pnd \a nfc_device struct pointer that represent currently used device
966 * @param pcString a string
967967 */
968968 void
969969 nfc_perror (const nfc_device *pnd, const char *pcString)
974974 /** @ingroup error
975975 * @brief Returns last error occured on a nfc_device
976976 * @return Returns an integer that represents to libnfc's error code.
977 *
977 *
978978 * @param pnd \a nfc_device struct pointer that represent currently used device
979979 */
980980 int
988988 /** @ingroup data
989989 * @brief Returns the device name
990990 * @return Returns a string with the device name
991 *
991 *
992992 * @param pnd \a nfc_device struct pointer that represent currently used device
993993 */
994994 const char *
10001000 /** @ingroup data
10011001 * @brief Returns the device connection string
10021002 * @return Returns a string with the device connstring
1003 *
1003 *
10041004 * @param pnd \a nfc_device struct pointer that represent currently used device
10051005 */
10061006 const char *
10151015 * @param pnd \a nfc_device struct pointer that represent currently used device
10161016 * @param mode \a nfc_mode.
10171017 * @param supported_mt pointer of \a nfc_modulation_type array.
1018 *
1019 */
1020 int
1018 *
1019 */
1020 int
10211021 nfc_device_get_supported_modulation (nfc_device *pnd, const nfc_mode mode, const nfc_modulation_type **const supported_mt)
10221022 {
10231023 HAL (get_supported_modulation, pnd, mode, supported_mt);
10291029 * @param pnd \a nfc_device struct pointer that represent currently used device
10301030 * @param nmt \a nfc_modulation_type.
10311031 * @param supported_br pointer of \a nfc_baud_rate array.
1032 *
1033 */
1034 int
1032 *
1033 */
1034 int
10351035 nfc_device_get_supported_baud_rate (nfc_device *pnd, const nfc_modulation_type nmt, const nfc_baud_rate **const supported_br)
10361036 {
10371037 HAL (get_supported_baud_rate, pnd, nmt, supported_br);
10421042 /** @ingroup misc
10431043 * @brief Returns the library version
10441044 * @return Returns a string with the library version
1045 *
1045 *
10461046 * @param pnd \a nfc_device struct pointer that represent currently used device
10471047 */
10481048 const char *
10621062 * @param buf string to print information
10631063 * @param buflen buf length
10641064 */
1065 int
1065 int
10661066 nfc_device_get_information_about (nfc_device *pnd, char *buf, size_t buflen)
10671067 {
10681068 HAL (device_get_information_about, pnd, buf, buflen);
1717 int res = 0;
1818
1919 nfc_init (NULL);
20
20
2121 size_t ref_device_count = nfc_list_devices (NULL, connstrings, MAX_DEVICE_COUNT);
2222 if (!ref_device_count)
2323 cut_omit ("No NFC device found");
9292 const uint8_t abtAttRx[] = "Hello DEP target!";
9393 cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data"));
9494 if (res <= 0) { thread_res = -1; return (void*) thread_res; }
95
95
9696 const uint8_t abtTx[] = "Hello DEP initiator!";
9797 res = nfc_target_send_bytes (device, abtTx, sizeof(abtTx), 500);
9898 cut_assert_operator_int (res, >, 0, cut_message ("Can't send bytes to initiator: %s", nfc_strerror (device)));
120120
121121 nfc_target nt;
122122
123 // Active mode
123 // Active mode
124124 printf ("=========== INITIATOR %s (Active mode / %s Kbps) =========\n", nfc_device_get_name (device), str_nfc_baud_rate(nbr));
125125 res = nfc_initiator_select_dep_target (device, NDM_ACTIVE, nbr, NULL, &nt, 1000);
126126 cut_assert_operator_int (res, >, 0, cut_message ("Can't select any DEP target: %s", nfc_strerror (device)));
158158 .device = devices[TARGET],
159159 .cut_test_context = test_context,
160160 };
161
161
162162 struct thread_data initiator_data = {
163163 .device = devices[INITIATOR],
164164 .cut_test_context = test_context,
165165 };
166
166
167167 for (int i = 0; i < 3; i++) {
168168 initiator_data.nbr = nbrs[i];
169
169
170170 if ((res = pthread_create (&(threads[TARGET]), NULL, target_thread, &target_data)))
171171 cut_fail ("pthread_create() returned %d", res);
172172 if ((res = pthread_create (&(threads[INITIATOR]), NULL, initiator_thread, &initiator_data)))
180180 cut_assert_equal_int (0, result[INITIATOR], cut_message ("Unexpected initiator return code"));
181181 cut_assert_equal_int (0, result[TARGET], cut_message ("Unexpected target return code"));
182182 }
183
183
184184 }
2929 if (n < 2) {
3030 cut_omit ("At least two NFC devices must be plugged-in to run this test");
3131 }
32
32
3333 nfc_init (NULL);
3434 devices[TARGET] = nfc_open (NULL, connstrings[TARGET]);
3535 devices[INITIATOR] = nfc_open (NULL, connstrings[INITIATOR]);
8989 res = nfc_target_receive_bytes (device, abtRx, sizeof (abtRx), 500);
9090 cut_assert_operator_int (res, >, 0, cut_message ("Can't receive bytes from initiator: %s", nfc_strerror (device)));
9191 szRx = (size_t) res;
92
92
9393 const uint8_t abtAttRx[] = "Hello DEP target!";
9494 cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data"));
9595 if (res <= 0) { thread_res = -1; return (void*) thread_res; }
96
96
9797 const uint8_t abtTx[] = "Hello DEP initiator!";
9898 res = nfc_target_send_bytes (device, abtTx, sizeof(abtTx), 500);
9999 cut_assert_operator_int (res, >, 0, cut_message ("Can't send bytes to initiator: %s", nfc_strerror (device)));
106106
107107 cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data"));
108108 if (res <= 0) { thread_res = -1; return (void*) thread_res; }
109
109
110110 res = nfc_target_send_bytes (device, abtTx, sizeof(abtTx), 500);
111111 cut_assert_operator_int (res, >, 0, cut_message ("Can't send bytes to initiator: %s", nfc_strerror (device)));
112112 if (res <= 0) { thread_res = -1; return (void*) thread_res; }
118118
119119 cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data"));
120120 if (res <= 0) { thread_res = -1; return (void*) thread_res; }
121
122 res = nfc_target_send_bytes (device, abtTx, sizeof(abtTx), 500);
123 cut_assert_operator_int (res, >, 0, cut_message ("Can't send bytes to initiator: %s", nfc_strerror (device)));
124 if (res <= 0) { thread_res = -1; return (void*) thread_res; }
125
121
122 res = nfc_target_send_bytes (device, abtTx, sizeof(abtTx), 500);
123 cut_assert_operator_int (res, >, 0, cut_message ("Can't send bytes to initiator: %s", nfc_strerror (device)));
124 if (res <= 0) { thread_res = -1; return (void*) thread_res; }
125
126126 // Fourth pass
127127 res = nfc_target_receive_bytes (device, abtRx, sizeof (abtRx), 500);
128128 cut_assert_operator_int (res, >, 0, cut_message ("Can't receive bytes from initiator: %s", nfc_strerror (device)));
130130
131131 cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data"));
132132 if (res <= 0) { thread_res = -1; return (void*) thread_res; }
133
133
134134 res = nfc_target_send_bytes (device, abtTx, sizeof(abtTx), 500);
135135 cut_assert_operator_int (res, >, 0, cut_message ("Can't send bytes to initiator: %s", nfc_strerror (device)));
136136 if (res <= 0) { thread_res = -1; return (void*) thread_res; }
225225 res = nfc_initiator_deselect_target (device);
226226 cut_assert_operator_int (res, >=, 0, cut_message ("Can't deselect target: %s", nfc_strerror (device)));
227227 if (res < 0) { thread_res = -1; return (void*) thread_res; }
228
228
229229 // Passive mode / 424Kbps
230230 printf ("=========== INITIATOR %s (Passive mode / 424Kbps) =========\n", nfc_device_get_name (device));
231231 res = nfc_initiator_select_dep_target (device, NDM_PASSIVE, NBR_424, NULL, &nt, 1000);
5656 cut_set_current_test_context (((struct thread_data *) arg)->cut_test_context);
5757
5858 printf ("=========== TARGET %s =========\n", nfc_device_get_name (device));
59 nfc_target nt;
59 nfc_target nt;
6060
6161 uint8_t abtRx[1024];
6262 size_t szRx = sizeof (abtRx);
6565 int res = nfc_target_init (device, &nt, abtRx, szRx, 500);
6666 cut_assert_operator_int (res, >=, 0, cut_message ("Can't initialize NFC device as target: %s", nfc_strerror (device)));
6767 if (res < 0) { thread_res = -1; return (void*) thread_res; }
68
68
6969 // 2) act as target
7070 nfc_target nt1 = {
7171 .nm = {
9595 res = nfc_target_receive_bytes (device, abtRx, sizeof (abtRx), 500);
9696 cut_assert_operator_int (res, >, 0, cut_message ("Can't receive bytes from initiator: %s", nfc_strerror (device)));
9797 szRx = (size_t) res;
98
98
9999 const uint8_t abtAttRx[] = "Hello DEP target!";
100100 cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data"));
101101 if (res <= 0) { thread_res = -1; return (void*) thread_res; }
102
102
103103 const uint8_t abtTx[] = "Hello DEP initiator!";
104104 res = nfc_target_send_bytes (device, abtTx, sizeof(abtTx), 500);
105105 cut_assert_operator_int (res, >, 0, cut_message ("Can't send bytes to initiator: %s", nfc_strerror (device)));
129129 cut_assert_equal_int (0, res, cut_message ("Can't initialize NFC device as initiator: %s", nfc_strerror (device)));
130130 if (res < 0) { thread_res = -1; return (void*) thread_res; }
131131
132 // 1) As other device should be in idle mode, nfc_initiator_poll_dep_target should return 0
132 // 1) As other device should be in idle mode, nfc_initiator_poll_dep_target should return 0
133133 nfc_target nt;
134134 res = nfc_initiator_poll_dep_target (device, NDM_PASSIVE, NBR_106, NULL, &nt, 1000);
135135 cut_assert_equal_int (0, res, cut_message ("Problem with nfc_idle"));
136136 if (res != 0) { thread_res = -1; return (void*) thread_res; }
137137
138
138
139139 // 2 As other device should be in target mode, nfc_initiator_poll_dep_target should be positive.
140140 nfc_target nt1;
141141
164164 cut_assert_operator_int (res, >=, 0, cut_message ("Can't deselect target: %s", nfc_strerror (device)));
165165 if (res < 0) { thread_res = -1; return (void*) thread_res; }
166166
167 // 3) As other device should be in idle mode, nfc_initiator_poll_dep_target should return 0
167 // 3) As other device should be in idle mode, nfc_initiator_poll_dep_target should return 0
168168 nfc_target nt2;
169169 res = nfc_initiator_poll_dep_target (device, NDM_PASSIVE, NBR_106, NULL, &nt2, 1000);
170170 cut_assert_equal_int (0, res, cut_message ("Problem with nfc_idle"));
171171 if (res != 0) { thread_res = -1; return (void*) thread_res; }
172
172
173173 return (void *) thread_res;
174174 }
175175
183183 .device = first_device,
184184 .cut_test_context = test_context,
185185 };
186
186
187187 struct thread_data initiator_data = {
188188 .device = second_device,
189189 .cut_test_context = test_context,
190190 };
191
191
192192 for (int i = 0; i < 2; i++) {
193193 if ((res = pthread_create (&(threads[1]), NULL, target_thread, &target_data)))
194194 cut_fail ("pthread_create() returned %d", res);
203203
204204 cut_assert_equal_int (0, result[0], cut_message ("Unexpected initiator return code"));
205205 cut_assert_equal_int (0, result[1], cut_message ("Unexpected target return code"));
206
206
207207 // initiator --> target, target --> initiator
208208 target_data.device = second_device;
209209 initiator_data.device = first_device;
1010 {
1111 nfc_connstring connstrings[MAX_DEVICE_COUNT];
1212 int res = 0;
13
13
1414 nfc_init (NULL);
1515
1616 size_t device_count = nfc_list_devices (NULL, connstrings, MAX_DEVICE_COUNT);
1111 {
1212 nfc_connstring connstrings[MAX_DEVICE_COUNT];
1313 int res = 0;
14
14
1515 nfc_init (NULL);
1616
1717 size_t device_count = nfc_list_devices (NULL, connstrings, MAX_DEVICE_COUNT);
00 /*-
11 * Public platform independent Near Field Communication (NFC) library examples
2 *
2 *
33 * Copyright (C) 2009, Roel Verdult
44 * Copyright (C) 2010, Romuald Conty, Romain Tartière
5 *
5 *
66 * Redistribution and use in source and binary forms, with or without
77 * modification, are permitted provided that the following conditions are met:
88 * 1) Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
9 * this list of conditions and the following disclaimer.
1010 * 2 )Redistributions in binary form must reproduce the above copyright
1111 * notice, this list of conditions and the following disclaimer in the
1212 * documentation and/or other materials provided with the distribution.
2222 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2323 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2424 * POSSIBILITY OF SUCH DAMAGE.
25 *
25 *
2626 * Note that this license only applies on the examples, NFC library itself is under LGPL
2727 *
2828 */
4444 * The specified MIFARE command will be executed on the tag. There are different commands possible, they all require the destination block number.
4545 * @note There are three different types of information (Authenticate, Data and Value).
4646 *
47 * First an authentication must take place using Key A or B. It requires a 48 bit Key (6 bytes) and the UID.
47 * First an authentication must take place using Key A or B. It requires a 48 bit Key (6 bytes) and the UID.
4848 * They are both used to initialize the internal cipher-state of the PN53X chip (http://libnfc.org/hardware/pn53x-chip).
49 * After a successful authentication it will be possible to execute other commands (e.g. Read/Write).
49 * After a successful authentication it will be possible to execute other commands (e.g. Read/Write).
5050 * The MIFARE Classic Specification (http://www.nxp.com/acrobat/other/identification/M001053_MF1ICS50_rev5_3.pdf) explains more about this process.
5151 */
5252 bool
00 /*-
11 * Public platform independent Near Field Communication (NFC) library examples
2 *
2 *
33 * Copyright (C) 2009, Roel Verdult
44 * Copyright (C) 2010, Romuald Conty, Romain Tartière
5 *
5 *
66 * Redistribution and use in source and binary forms, with or without
77 * modification, are permitted provided that the following conditions are met:
88 * 1) Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
9 * this list of conditions and the following disclaimer.
1010 * 2 )Redistributions in binary form must reproduce the above copyright
1111 * notice, this list of conditions and the following disclaimer in the
1212 * documentation and/or other materials provided with the distribution.
2222 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2323 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2424 * POSSIBILITY OF SUCH DAMAGE.
25 *
25 *
2626 * Note that this license only applies on the examples, NFC library itself is under LGPL
2727 *
2828 */
00 /*-
11 * Public platform independent Near Field Communication (NFC) library examples
2 *
2 *
33 * Copyright (C) 2010, Roel Verdult, Romuald Conty
44 * Copyright (C) 2011, Romain Tartière, Romuald Conty
5 *
5 *
66 * Redistribution and use in source and binary forms, with or without
77 * modification, are permitted provided that the following conditions are met:
88 * 1) Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
9 * this list of conditions and the following disclaimer.
1010 * 2 )Redistributions in binary form must reproduce the above copyright
1111 * notice, this list of conditions and the following disclaimer in the
1212 * documentation and/or other materials provided with the distribution.
2222 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2323 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2424 * POSSIBILITY OF SUCH DAMAGE.
25 *
25 *
2626 * Note that this license only applies on the examples, NFC library itself is under LGPL
2727 *
2828 */
9090 0x00, 0x0F, /* CCLEN 15 bytes */
9191 0x20, /* Mapping version 2.0, use option -1 to force v1.0 */
9292 0x00, 0x54, /* MLe Maximum R-ADPU data size */
93 // Notes:
93 // Notes:
9494 // - I (Romuald) don't know why Nokia 6212 Classic refuses the NDEF message if MLe is more than 0xFD (any suggests are welcome);
9595 // - ARYGON devices doesn't support extended frame sending, consequently these devices can't sent more than 0xFE bytes as APDU, so 0xFB APDU data bytes.
9696 // - I (Romuald) don't know why ARYGON device doesn't ACK when MLe > 0x54 (ARYGON frame length = 0xC2 (192 bytes))
363363 err (EXIT_FAILURE, "Can't load NDEF file '%s'", argv[1 + options]);
364364 }
365365 }
366
366
367367 nfc_init (NULL);
368368
369369 // Try to open the NFC reader
390390 err (EXIT_FAILURE, "Can't save NDEF file '%s'", argv[2 + options]);
391391 }
392392 }
393
393
394394 nfc_exit (NULL);
395395 exit (EXIT_SUCCESS);
396396 }
00 /*-
11 * Public platform independent Near Field Communication (NFC) library examples
2 *
2 *
33 * Copyright (C) 2009, Roel Verdult
44 * Copyright (C) 2010, Romuald Conty, Romain Tartière
5 *
5 *
66 * Redistribution and use in source and binary forms, with or without
77 * modification, are permitted provided that the following conditions are met:
88 * 1) Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
9 * this list of conditions and the following disclaimer.
1010 * 2 )Redistributions in binary form must reproduce the above copyright
1111 * notice, this list of conditions and the following disclaimer in the
1212 * documentation and/or other materials provided with the distribution.
2222 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2323 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2424 * POSSIBILITY OF SUCH DAMAGE.
25 *
25 *
2626 * Note that this license only applies on the examples, NFC library itself is under LGPL
2727 *
2828 */
7474 int res = 0;
7575
7676 nfc_init (NULL);
77
77
7878 // Display libnfc version
7979 acLibnfcVersion = nfc_version ();
8080 printf ("%s uses libnfc %s\n", argv[0], acLibnfcVersion);
131131 }
132132 if (nfc_initiator_init (pnd) < 0) {
133133 nfc_perror (pnd, "nfc_initiator_init");
134 exit (EXIT_FAILURE);
134 exit (EXIT_FAILURE);
135135 }
136136
137137 printf ("NFC device: %s opened\n", nfc_device_get_name (pnd));
00 /*-
11 * Public platform independent Near Field Communication (NFC) library examples
2 *
2 *
33 * Copyright (C) 2009, Roel Verdult
44 * Copyright (C) 2010, Romuald Conty, Romain Tartière
55 * Copyright (C) 2011, Adam Laurie
6 *
6 *
77 * Redistribution and use in source and binary forms, with or without
88 * modification, are permitted provided that the following conditions are met:
99 * 1) Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
10 * this list of conditions and the following disclaimer.
1111 * 2 )Redistributions in binary form must reproduce the above copyright
1212 * notice, this list of conditions and the following disclaimer in the
1313 * documentation and/or other materials provided with the distribution.
2323 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2424 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2525 * POSSIBILITY OF SUCH DAMAGE.
26 *
26 *
2727 * Note that this license only applies on the examples, NFC library itself is under LGPL
2828 *
2929 */
507507 // printf("Successfully opened required files\n");
508508
509509 nfc_init (NULL);
510
510
511511 // Try to open the NFC reader
512512 pnd = nfc_open (NULL, NULL);
513513 if (pnd == NULL) {
517517
518518 if (nfc_initiator_init (pnd) < 0) {
519519 nfc_perror (pnd, "nfc_initiator_init");
520 exit (EXIT_FAILURE);
520 exit (EXIT_FAILURE);
521521 };
522522
523523 // Let the reader only try once to find a tag
593593 nfc_close (pnd);
594594 break;
595595 };
596
596
597597 nfc_exit (NULL);
598598 exit (EXIT_SUCCESS);
599599 }
00 /*-
11 * Public platform independent Near Field Communication (NFC) library examples
2 *
2 *
33 * Copyright (C) 2009, Roel Verdult
44 * Copyright (C) 2010, Romuald Conty
5 *
5 *
66 * Redistribution and use in source and binary forms, with or without
77 * modification, are permitted provided that the following conditions are met:
88 * 1) Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
9 * this list of conditions and the following disclaimer.
1010 * 2 )Redistributions in binary form must reproduce the above copyright
1111 * notice, this list of conditions and the following disclaimer in the
1212 * documentation and/or other materials provided with the distribution.
2222 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2323 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2424 * POSSIBILITY OF SUCH DAMAGE.
25 *
25 *
2626 * Note that this license only applies on the examples, NFC library itself is under LGPL
2727 *
2828 */
148148 bFailure = false;
149149 }
150150 // For the Mifare Ultralight, this write command can be used
151 // in compatibility mode, which only actually writes the first
151 // in compatibility mode, which only actually writes the first
152152 // page (4 bytes). The Ultralight-specific Write command only
153153 // writes one page at a time.
154154 uiBlock = page / 4;
204204 DBG ("Successfully opened the dump file\n");
205205
206206 nfc_init (NULL);
207
207
208208 // Try to open the NFC device
209209 pnd = nfc_open (NULL, NULL);
210210 if (pnd == NULL) {
214214
215215 if (nfc_initiator_init (pnd) < 0) {
216216 nfc_perror (pnd, "nfc_initiator_init");
217 exit (EXIT_FAILURE);
217 exit (EXIT_FAILURE);
218218 }
219219
220220 // Let the device only try once to find a tag
00 /*-
11 * Public platform independent Near Field Communication (NFC) library examples
2 *
2 *
33 * Copyright (C) 2009, Roel Verdult
44 * Copyright (C) 2010, Romuald Conty, Romain Tartière
55 * Copyright (C) 2011-2012, Romuald Conty
6 *
6 *
77 * Redistribution and use in source and binary forms, with or without
88 * modification, are permitted provided that the following conditions are met:
99 * 1) Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
10 * this list of conditions and the following disclaimer.
1111 * 2 )Redistributions in binary form must reproduce the above copyright
1212 * notice, this list of conditions and the following disclaimer in the
1313 * documentation and/or other materials provided with the distribution.
2323 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2424 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2525 * POSSIBILITY OF SUCH DAMAGE.
26 *
26 *
2727 * Note that this license only applies on the examples, NFC library itself is under LGPL
2828 *
2929 */
7474 bool verbose = false;
7575
7676 nfc_init (NULL);
77
77
7878 // Display libnfc version
7979 acLibnfcVersion = nfc_version ();
8080 printf ("%s uses libnfc %s\n", argv[0], acLibnfcVersion);
00 /*-
11 * Public platform independent Near Field Communication (NFC) library examples
2 *
2 *
33 * Copyright (C) 2011, Romuald Conty
4 *
4 *
55 * Redistribution and use in source and binary forms, with or without
66 * modification, are permitted provided that the following conditions are met:
77 * 1) Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
8 * this list of conditions and the following disclaimer.
99 * 2 )Redistributions in binary form must reproduce the above copyright
1010 * notice, this list of conditions and the following disclaimer in the
1111 * documentation and/or other materials provided with the distribution.
2121 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2222 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2323 * POSSIBILITY OF SUCH DAMAGE.
24 *
24 *
2525 * Note that this license only applies on the examples, NFC library itself is under LGPL
2626 *
2727 */
8484 }
8585
8686 #define CHECK 0x06
87 static int
87 static int
8888 nfc_forum_tag_type3_check (nfc_device *dev, const nfc_target nt, const uint16_t block, const uint8_t block_count, uint8_t *data, size_t *data_len)
8989 {
9090 uint8_t payload[1024] = {
9393 block_count,
9494 0x80, block, // block 0
9595 };
96
96
9797 size_t payload_len = 1 + 2 + 1;
9898 for (uint8_t b = 0; b < block_count; b++) {
9999 if (block < 0x100) {
103103 payload[payload_len++] = 0x00;
104104 payload[payload_len++] = (block + b) >> 8;
105105 payload[payload_len++] = (block + b) & 0xff;
106 }
106 }
107107 }
108108
109109 uint8_t frame[1024];
116116 return res;
117117 }
118118 const int res_overhead = 1 + 1 + 8 + 2; // 1+1+8+2: LEN + CMD + NFCID2 + STATUS
119 if (res < res_overhead) {
119 if (res < res_overhead) {
120120 // Not enough data
121121 return -1;
122122 }
153153 (void)argv;
154154
155155 int ch;
156 char *ndef_output = NULL;
157 while ((ch = getopt (argc, argv, "ho:")) != -1) {
158 switch (ch) {
159 case 'h':
160 print_usage(argv[0]);
161 exit (EXIT_SUCCESS);
162 break;
163 case 'o':
164 ndef_output = optarg;
165 break;
166 case '?':
167 if (optopt == 'o')
168 fprintf (stderr, "Option -%c requires an argument.\n", optopt);
169 default:
170 print_usage (argv[0]);
171 exit (EXIT_FAILURE);
172 }
173 }
174
175 if (ndef_output == NULL) {
176 print_usage (argv[0]);
177 exit (EXIT_FAILURE);
178 }
179 FILE* message_stream = NULL;
180 FILE* ndef_stream = NULL;
181
182 if ((strlen (ndef_output) == 1) && (ndef_output[0] == '-')) {
183 message_stream = stderr;
184 ndef_stream = stdout;
185 } else {
186 message_stream = stdout;
187 ndef_stream = fopen(ndef_output, "wb");
188 if (!ndef_stream) {
189 fprintf (stderr, "Could not open file %s.\n", ndef_output);
190 exit (EXIT_FAILURE);
191 }
192 }
193
156 char *ndef_output = NULL;
157 while ((ch = getopt (argc, argv, "ho:")) != -1) {
158 switch (ch) {
159 case 'h':
160 print_usage(argv[0]);
161 exit (EXIT_SUCCESS);
162 break;
163 case 'o':
164 ndef_output = optarg;
165 break;
166 case '?':
167 if (optopt == 'o')
168 fprintf (stderr, "Option -%c requires an argument.\n", optopt);
169 default:
170 print_usage (argv[0]);
171 exit (EXIT_FAILURE);
172 }
173 }
174
175 if (ndef_output == NULL) {
176 print_usage (argv[0]);
177 exit (EXIT_FAILURE);
178 }
179 FILE* message_stream = NULL;
180 FILE* ndef_stream = NULL;
181
182 if ((strlen (ndef_output) == 1) && (ndef_output[0] == '-')) {
183 message_stream = stderr;
184 ndef_stream = stdout;
185 } else {
186 message_stream = stdout;
187 ndef_stream = fopen(ndef_output, "wb");
188 if (!ndef_stream) {
189 fprintf (stderr, "Could not open file %s.\n", ndef_output);
190 exit (EXIT_FAILURE);
191 }
192 }
193
194194 nfc_init (NULL);
195195
196196 pnd = nfc_open (NULL, NULL);
213213
214214 if (nfc_initiator_init (pnd) < 0) {
215215 nfc_perror (pnd, "nfc_initiator_init");
216 exit (EXIT_FAILURE);
216 exit (EXIT_FAILURE);
217217 }
218218 fprintf (message_stream, "Place your NFC Forum Tag Type 3 in the field...\n");
219219
226226 goto error;
227227 }
228228
229 // Check if System Code equals 0x12fc
229 // Check if System Code equals 0x12fc
230230 const uint8_t abtNfcForumSysCode[] = { 0x12, 0xfc };
231231 if (0 != memcmp (nt.nti.nfi.abtSysCode, abtNfcForumSysCode, 2)) {
232232 // Retry with special polling
236236 error = EXIT_FAILURE;
237237 goto error;
238238 }
239 // Check again if System Code equals 0x12fc
239 // Check again if System Code equals 0x12fc
240240 if (0 != memcmp (nt.nti.nfi.abtSysCode, abtNfcForumSysCode, 2)) {
241241 fprintf (stderr, "Tag is not NFC Forum Tag Type 3 compliant.\n");
242242 error = EXIT_FAILURE;
00 /*-
11 * Public platform independent Near Field Communication (NFC) library examples
2 *
2 *
33 * Copyright (C) 2010, Romuald Conty
4 *
4 *
55 * Redistribution and use in source and binary forms, with or without
66 * modification, are permitted provided that the following conditions are met:
77 * 1) Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
8 * this list of conditions and the following disclaimer.
99 * 2 )Redistributions in binary form must reproduce the above copyright
1010 * notice, this list of conditions and the following disclaimer in the
1111 * documentation and/or other materials provided with the distribution.
2121 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2222 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2323 * POSSIBILITY OF SUCH DAMAGE.
24 *
24 *
2525 * Note that this license only applies on the examples, NFC library itself is under LGPL
2626 *
2727 */
191191 #endif
192192
193193 nfc_init (NULL);
194
194
195195 nfc_connstring connstrings[MAX_DEVICE_COUNT];
196196 // List available devices
197197 size_t szFound = nfc_list_devices (NULL, connstrings, MAX_DEVICE_COUNT);
276276 nfc_exit (NULL);
277277 exit(EXIT_FAILURE);
278278 }
279 }
279 }
280280 }
281281 if (initiator_only_mode) {
282282 printf ("Hint: tag <---> *INITIATOR* (relay) <-FD3/FD4-> target (relay) <---> original reader\n\n");
351351
352352 printf("We will emulate:\n");
353353 print_nfc_iso14443a_info (ntEmulatedTarget.nti.nai, false);
354
354
355355 // Try to open the NFC emulator device
356356 pndTarget = nfc_open (NULL, connstrings[0]);
357357 if (pndTarget == NULL) {
00 /*-
11 * Public platform independent Near Field Communication (NFC) library examples
2 *
2 *
33 * Copyright (C) 2009, Roel Verdult
44 * Copyright (C) 2010, Romuald Conty, Romain Tartière
5 *
5 *
66 * Redistribution and use in source and binary forms, with or without
77 * modification, are permitted provided that the following conditions are met:
88 * 1) Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
9 * this list of conditions and the following disclaimer.
1010 * 2 )Redistributions in binary form must reproduce the above copyright
1111 * notice, this list of conditions and the following disclaimer in the
1212 * documentation and/or other materials provided with the distribution.
2222 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2323 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2424 * POSSIBILITY OF SUCH DAMAGE.
25 *
25 *
2626 * Note that this license only applies on the examples, NFC library itself is under LGPL
2727 *
2828 */
00 /*-
11 * Public platform independent Near Field Communication (NFC) library examples
2 *
2 *
33 * Copyright (C) 2009, Roel Verdult
44 * Copyright (C) 2010, Romuald Conty, Romain Tartière
5 *
5 *
66 * Redistribution and use in source and binary forms, with or without
77 * modification, are permitted provided that the following conditions are met:
88 * 1) Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
9 * this list of conditions and the following disclaimer.
1010 * 2 )Redistributions in binary form must reproduce the above copyright
1111 * notice, this list of conditions and the following disclaimer in the
1212 * documentation and/or other materials provided with the distribution.
2222 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2323 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2424 * POSSIBILITY OF SUCH DAMAGE.
25 *
25 *
2626 * Note that this license only applies on the examples, NFC library itself is under LGPL
2727 *
2828 */
66 *
77 */
88
9 /*
9 /*
1010 * $Id: usb.h 1220 2010-05-04 03:14:56Z roger.brown $
1111 */
1212
1717 #include <stdlib.h>
1818 #include <windows.h>
1919
20 /*
21 * 'interface' is defined somewhere in the Windows header files. This macro
20 /*
21 * 'interface' is defined somewhere in the Windows header files. This macro
2222 * is deleted here to avoid conflicts and compile errors.
2323 */
2424
2828
2929 /*
3030 * PATH_MAX from limits.h can't be used on Windows if the dll and
31 * import libraries are build/used by different compilers
31 * import libraries are build/used by different compilers
3232 */
3333
3434 #define LIBUSB_PATH_MAX 512
8080
8181
8282 /* ensure byte-packed structures */
83 #include <pshpack1.h>
83 #include <pshpack1.h>
8484
8585
8686 /* All standard descriptors have these 2 fields in common */
338338 int usb_interrupt_read(usb_dev_handle *dev, int ep, char *bytes, int size,
339339 int timeout);
340340 int usb_control_msg(usb_dev_handle *dev, int requesttype, int request,
341 int value, int index, char *bytes, int size,
341 int value, int index, char *bytes, int size,
342342 int timeout);
343343 int usb_set_configuration(usb_dev_handle *dev, int configuration);
344344 int usb_claim_interface(usb_dev_handle *dev, int interface);
364364 int usb_install_service_np(void);
365365 void CALLBACK usb_install_service_np_rundll(HWND wnd, HINSTANCE instance,
366366 LPSTR cmd_line, int cmd_show);
367
367
368368 #define LIBUSB_HAS_UNINSTALL_SERVICE_NP 1
369369 int usb_uninstall_service_np(void);
370370 void CALLBACK usb_uninstall_service_np_rundll(HWND wnd, HINSTANCE instance,