Remove extra whitespaces/tabs before EOL.
find . -name '*.[ch]' | xargs perl -pi -e 's/\t+$//; s/ +$//'
Thanks to Ludovic.
Romuald Conty
11 years ago
0 | 0 | /*- |
1 | 1 | * Public platform independent Near Field Communication (NFC) library |
2 | * | |
2 | * | |
3 | 3 | * Copyright (C) 2011, Romuald Conty |
4 | * | |
4 | * | |
5 | 5 | * This program is free software: you can redistribute it and/or modify it |
6 | 6 | * under the terms of the GNU Lesser General Public License as published by the |
7 | 7 | * Free Software Foundation, either version 3 of the License, or (at your |
8 | 8 | * option) any later version. |
9 | * | |
9 | * | |
10 | 10 | * This program is distributed in the hope that it will be useful, but WITHOUT |
11 | 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
12 | 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
0 | 0 | /*- |
1 | 1 | * Public platform independent Near Field Communication (NFC) library |
2 | * | |
2 | * | |
3 | 3 | * Copyright (C) 2011, Romuald Conty |
4 | * | |
4 | * | |
5 | 5 | * This program is free software: you can redistribute it and/or modify it |
6 | 6 | * under the terms of the GNU Lesser General Public License as published by the |
7 | 7 | * Free Software Foundation, either version 3 of the License, or (at your |
8 | 8 | * option) any later version. |
9 | * | |
9 | * | |
10 | 10 | * This program is distributed in the hope that it will be useful, but WITHOUT |
11 | 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
12 | 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
0 | 0 | /*- |
1 | 1 | * Public platform independent Near Field Communication (NFC) library |
2 | * | |
2 | * | |
3 | 3 | * Copyright (C) 2010, Romuald Conty |
4 | 4 | * Copyright (C) 2011, Glenn Ergeerts |
5 | * | |
5 | * | |
6 | 6 | * This program is free software: you can redistribute it and/or modify it |
7 | 7 | * under the terms of the GNU Lesser General Public License as published by the |
8 | 8 | * Free Software Foundation, either version 3 of the License, or (at your |
9 | 9 | * option) any later version. |
10 | * | |
10 | * | |
11 | 11 | * This program is distributed in the hope that it will be useful, but WITHOUT |
12 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
13 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
17 | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/> |
18 | 18 | */ |
19 | 19 | |
20 | /** | |
20 | /** | |
21 | 21 | * @file windows.h |
22 | 22 | * @brief Provide some windows related hacks due to lack of POSIX compat |
23 | 23 | */ |
0 | /** | |
0 | /** | |
1 | 1 | * @file quick_start_example1.c |
2 | 2 | * @brief Quick start example that presents how to use libnfc |
3 | 3 | */ |
17 | 17 | { |
18 | 18 | nfc_device *pnd; |
19 | 19 | nfc_target nt; |
20 | ||
20 | ||
21 | 21 | nfc_init (NULL); |
22 | 22 | |
23 | 23 | // Display libnfc version |
34 | 34 | // Set opened NFC device to initiator mode |
35 | 35 | if (nfc_initiator_init (pnd) < 0) { |
36 | 36 | nfc_perror (pnd, "nfc_initiator_init"); |
37 | exit (EXIT_FAILURE); | |
37 | exit (EXIT_FAILURE); | |
38 | 38 | } |
39 | 39 | |
40 | 40 | printf ("NFC reader: %s opened\n", nfc_device_get_name (pnd)); |
0 | 0 | /*- |
1 | 1 | * Public platform independent Near Field Communication (NFC) library examples |
2 | * | |
2 | * | |
3 | 3 | * Copyright (C) 2009, Roel Verdult |
4 | * | |
4 | * | |
5 | 5 | * Redistribution and use in source and binary forms, with or without |
6 | 6 | * modification, are permitted provided that the following conditions are met: |
7 | 7 | * 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. | |
9 | 9 | * 2 )Redistributions in binary form must reproduce the above copyright |
10 | 10 | * notice, this list of conditions and the following disclaimer in the |
11 | 11 | * documentation and/or other materials provided with the distribution. |
21 | 21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
22 | 22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
23 | 23 | * POSSIBILITY OF SUCH DAMAGE. |
24 | * | |
24 | * | |
25 | 25 | * Note that this license only applies on the examples, NFC library itself is under LGPL |
26 | 26 | * |
27 | 27 | */ |
28 | 28 | |
29 | /** | |
29 | /** | |
30 | 30 | * @file nfc-anticol.c |
31 | 31 | * @brief Generates one ISO14443-A anti-collision process "by-hand" |
32 | 32 | */ |
149 | 149 | } |
150 | 150 | |
151 | 151 | nfc_init (NULL); |
152 | ||
152 | ||
153 | 153 | // Try to open the NFC reader |
154 | 154 | pnd = nfc_open (NULL, NULL); |
155 | 155 | |
161 | 161 | // Initialise NFC device as "initiator" |
162 | 162 | if (nfc_initiator_init (pnd) < 0) { |
163 | 163 | nfc_perror (pnd, "nfc_initiator_init"); |
164 | exit (EXIT_FAILURE); | |
164 | exit (EXIT_FAILURE); | |
165 | 165 | } |
166 | 166 | |
167 | 167 | // Configure the CRC |
0 | 0 | /*- |
1 | 1 | * Public platform independent Near Field Communication (NFC) library examples |
2 | * | |
2 | * | |
3 | 3 | * Copyright (C) 2009, Roel Verdult |
4 | 4 | * Copyright (C) 2010, Romuald Conty |
5 | * | |
5 | * | |
6 | 6 | * Redistribution and use in source and binary forms, with or without |
7 | 7 | * modification, are permitted provided that the following conditions are met: |
8 | 8 | * 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. | |
10 | 10 | * 2 )Redistributions in binary form must reproduce the above copyright |
11 | 11 | * notice, this list of conditions and the following disclaimer in the |
12 | 12 | * documentation and/or other materials provided with the distribution. |
22 | 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
23 | 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
24 | 24 | * POSSIBILITY OF SUCH DAMAGE. |
25 | * | |
25 | * | |
26 | 26 | * Note that this license only applies on the examples, NFC library itself is under LGPL |
27 | 27 | * |
28 | 28 | */ |
69 | 69 | printf ("Usage: %s\n", argv[0]); |
70 | 70 | return EXIT_FAILURE; |
71 | 71 | } |
72 | ||
72 | ||
73 | 73 | nfc_init (NULL); |
74 | 74 | |
75 | 75 | pnd = nfc_open (NULL, NULL); |
0 | 0 | /*- |
1 | 1 | * Public platform independent Near Field Communication (NFC) library examples |
2 | * | |
2 | * | |
3 | 3 | * Copyright (C) 2009, Roel Verdult |
4 | 4 | * Copyright (C) 2010, Romuald Conty |
5 | * | |
5 | * | |
6 | 6 | * Redistribution and use in source and binary forms, with or without |
7 | 7 | * modification, are permitted provided that the following conditions are met: |
8 | 8 | * 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. | |
10 | 10 | * 2 )Redistributions in binary form must reproduce the above copyright |
11 | 11 | * notice, this list of conditions and the following disclaimer in the |
12 | 12 | * documentation and/or other materials provided with the distribution. |
22 | 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
23 | 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
24 | 24 | * POSSIBILITY OF SUCH DAMAGE. |
25 | * | |
25 | * | |
26 | 26 | * Note that this license only applies on the examples, NFC library itself is under LGPL |
27 | 27 | * |
28 | 28 | */ |
0 | 0 | /*- |
1 | 1 | * Public platform independent Near Field Communication (NFC) library examples |
2 | * | |
2 | * | |
3 | 3 | * Copyright (C) 2011, Romuald Conty |
4 | * | |
4 | * | |
5 | 5 | * Redistribution and use in source and binary forms, with or without |
6 | 6 | * modification, are permitted provided that the following conditions are met: |
7 | 7 | * 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. | |
9 | 9 | * 2 )Redistributions in binary form must reproduce the above copyright |
10 | 10 | * notice, this list of conditions and the following disclaimer in the |
11 | 11 | * documentation and/or other materials provided with the distribution. |
21 | 21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
22 | 22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
23 | 23 | * POSSIBILITY OF SUCH DAMAGE. |
24 | * | |
24 | * | |
25 | 25 | * Note that this license only applies on the examples, NFC library itself is under LGPL |
26 | 26 | * |
27 | 27 | */ |
30 | 30 | * @file nfc-emulate-forum-tag2.c |
31 | 31 | * @brief Emulates a NFC Forum Tag Type 2 with a NDEF message |
32 | 32 | * This example allow to emulate an NFC Forum Tag Type 2 that contains a read-only NDEF message. |
33 | * | |
33 | * | |
34 | 34 | * It have been developed using PN533 USB hardware as target and Google Nexus S phone as initiator. |
35 | 35 | * |
36 | 36 | * This is know to NOT work with Nokia 6212 Classic and could not work with |
50 | 50 | * NFC Forum Type 2 Tag Operation |
51 | 51 | * Technical Specification |
52 | 52 | * NFCForum-TS-Type-2-Tag_1.0 - 2007-07-09 |
53 | * | |
54 | * ISO/IEC 14443-3 | |
53 | * | |
54 | * ISO/IEC 14443-3 | |
55 | 55 | * First edition - 2001-02-01 |
56 | 56 | * Identification cards — Contactless integrated circuit(s) cards — Proximity cards |
57 | 57 | * Part 3: Initialization and anticollision |
85 | 85 | |
86 | 86 | static uint8_t __nfcforum_tag2_memory_area[] = { |
87 | 87 | 0x00, 0x00, 0x00, 0x00, // Block 0 |
88 | 0x00, 0x00, 0x00, 0x00, | |
88 | 0x00, 0x00, 0x00, 0x00, | |
89 | 89 | 0x00, 0x00, 0xFF, 0xFF, // Block 2 (Static lock bytes: CC area and data area are read-only locked) |
90 | 90 | 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) |
91 | 91 | |
181 | 181 | }; |
182 | 182 | |
183 | 183 | signal (SIGINT, stop_emulation); |
184 | nfc_init (NULL); | |
184 | nfc_init (NULL); | |
185 | 185 | pnd = nfc_open (NULL, NULL); |
186 | 186 | |
187 | 187 | if (pnd == NULL) { |
0 | 0 | /*- |
1 | 1 | * Public platform independent Near Field Communication (NFC) library examples |
2 | * | |
2 | * | |
3 | 3 | * Copyright (C) 2010, Romuald Conty |
4 | * | |
4 | * | |
5 | 5 | * Redistribution and use in source and binary forms, with or without |
6 | 6 | * modification, are permitted provided that the following conditions are met: |
7 | 7 | * 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. | |
9 | 9 | * 2 )Redistributions in binary form must reproduce the above copyright |
10 | 10 | * notice, this list of conditions and the following disclaimer in the |
11 | 11 | * documentation and/or other materials provided with the distribution. |
21 | 21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
22 | 22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
23 | 23 | * POSSIBILITY OF SUCH DAMAGE. |
24 | * | |
24 | * | |
25 | 25 | * Note that this license only applies on the examples, NFC library itself is under LGPL |
26 | 26 | * |
27 | 27 | */ |
65 | 65 | (void) sig; |
66 | 66 | printf ("\nQuitting...\n"); |
67 | 67 | if (pnd != NULL) { |
68 | nfc_close(pnd); | |
68 | nfc_close(pnd); | |
69 | 69 | } |
70 | 70 | nfc_exit (NULL); |
71 | 71 | exit (EXIT_FAILURE); |
72 | 72 | } |
73 | 73 | |
74 | static bool | |
74 | static bool | |
75 | 75 | target_io( nfc_target *pnt, const uint8_t *pbtInput, const size_t szInput, uint8_t *pbtOutput, size_t *pszOutput ) |
76 | 76 | { |
77 | 77 | bool loop = true; |
181 | 181 | #endif |
182 | 182 | |
183 | 183 | nfc_init (NULL); |
184 | ||
184 | ||
185 | 185 | // Try to open the NFC reader |
186 | 186 | pnd = nfc_open (NULL, NULL); |
187 | 187 |
0 | 0 | /*- |
1 | 1 | * Public platform independent Near Field Communication (NFC) library examples |
2 | * | |
2 | * | |
3 | 3 | * Copyright (C) 2009, Roel Verdult |
4 | 4 | * Copyright (C) 2010, Romuald Conty |
5 | * | |
5 | * | |
6 | 6 | * Redistribution and use in source and binary forms, with or without |
7 | 7 | * modification, are permitted provided that the following conditions are met: |
8 | 8 | * 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. | |
10 | 10 | * 2 )Redistributions in binary form must reproduce the above copyright |
11 | 11 | * notice, this list of conditions and the following disclaimer in the |
12 | 12 | * documentation and/or other materials provided with the distribution. |
22 | 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
23 | 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
24 | 24 | * POSSIBILITY OF SUCH DAMAGE. |
25 | * | |
25 | * | |
26 | 26 | * Note that this license only applies on the examples, NFC library itself is under LGPL |
27 | 27 | * |
28 | 28 | */ |
30 | 30 | /** |
31 | 31 | * @file nfc-emulate-uid.c |
32 | 32 | * @brief Emulates a tag which which have a "really" custom UID |
33 | * | |
33 | * | |
34 | 34 | * NFC devices are able to emulate passive tags but manufacturers restrict the |
35 | 35 | * customization of UID. With PN53x, UID is only 4-byte long and the first |
36 | 36 | * byte of emulated UID is hard-wired to 0x08 which is the standard way to say |
126 | 126 | #endif |
127 | 127 | |
128 | 128 | nfc_init (NULL); |
129 | ||
129 | ||
130 | 130 | // Try to open the NFC device |
131 | 131 | pnd = nfc_open (NULL, NULL); |
132 | 132 |
0 | 0 | /*- |
1 | 1 | * Public platform independent Near Field Communication (NFC) library examples |
2 | * | |
2 | * | |
3 | 3 | * Copyright (C) 2009, Roel Verdult |
4 | 4 | * Copyright (C) 2011, Adam Laurie |
5 | * | |
5 | * | |
6 | 6 | * Redistribution and use in source and binary forms, with or without |
7 | 7 | * modification, are permitted provided that the following conditions are met: |
8 | 8 | * 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. | |
10 | 10 | * 2 )Redistributions in binary form must reproduce the above copyright |
11 | 11 | * notice, this list of conditions and the following disclaimer in the |
12 | 12 | * documentation and/or other materials provided with the distribution. |
22 | 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
23 | 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
24 | 24 | * POSSIBILITY OF SUCH DAMAGE. |
25 | * | |
25 | * | |
26 | 26 | * Note that this license only applies on the examples, NFC library itself is under LGPL |
27 | 27 | * |
28 | 28 | */ |
29 | 29 | |
30 | /** | |
30 | /** | |
31 | 31 | * @file nfc-mfsetuid.c |
32 | 32 | * @brief Set UID of special Mifare cards |
33 | 33 | */ |
177 | 177 | } |
178 | 178 | |
179 | 179 | nfc_init (NULL); |
180 | ||
180 | ||
181 | 181 | // Try to open the NFC reader |
182 | 182 | pnd = nfc_open (NULL, NULL); |
183 | 183 | |
189 | 189 | // Initialise NFC device as "initiator" |
190 | 190 | if (nfc_initiator_init (pnd) < 0) { |
191 | 191 | nfc_perror (pnd, "nfc_initiator_init"); |
192 | exit (EXIT_FAILURE); | |
192 | exit (EXIT_FAILURE); | |
193 | 193 | } |
194 | 194 | |
195 | 195 | // Configure the CRC |
0 | 0 | /*- |
1 | 1 | * Public platform independent Near Field Communication (NFC) library examples |
2 | * | |
2 | * | |
3 | 3 | * Copyright (C) 2010, Romuald Conty |
4 | 4 | * Copyright (C) 2011, Romain Tartiere, Romuald Conty |
5 | * | |
5 | * | |
6 | 6 | * Redistribution and use in source and binary forms, with or without |
7 | 7 | * modification, are permitted provided that the following conditions are met: |
8 | 8 | * 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. | |
10 | 10 | * 2 )Redistributions in binary form must reproduce the above copyright |
11 | 11 | * notice, this list of conditions and the following disclaimer in the |
12 | 12 | * documentation and/or other materials provided with the distribution. |
22 | 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
23 | 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
24 | 24 | * POSSIBILITY OF SUCH DAMAGE. |
25 | * | |
25 | * | |
26 | 26 | * Note that this license only applies on the examples, NFC library itself is under LGPL |
27 | 27 | * |
28 | 28 | */ |
101 | 101 | |
102 | 102 | nfc_target nt; |
103 | 103 | int res = 0; |
104 | ||
104 | ||
105 | 105 | nfc_init (NULL); |
106 | 106 | |
107 | 107 | pnd = nfc_open (NULL, NULL); |
113 | 113 | |
114 | 114 | if (nfc_initiator_init (pnd) < 0) { |
115 | 115 | nfc_perror (pnd, "nfc_initiator_init"); |
116 | exit (EXIT_FAILURE); | |
116 | exit (EXIT_FAILURE); | |
117 | 117 | } |
118 | 118 | |
119 | 119 | printf ("NFC reader: %s opened\n", nfc_device_get_name (pnd)); |
0 | 0 | /*- |
1 | 1 | * Public platform independent Near Field Communication (NFC) library examples |
2 | * | |
2 | * | |
3 | 3 | * Copyright (C) 2009, Roel Verdult |
4 | 4 | * Copyright (C) 2010, Romuald Conty |
5 | * | |
5 | * | |
6 | 6 | * Redistribution and use in source and binary forms, with or without |
7 | 7 | * modification, are permitted provided that the following conditions are met: |
8 | 8 | * 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. | |
10 | 10 | * 2 )Redistributions in binary form must reproduce the above copyright |
11 | 11 | * notice, this list of conditions and the following disclaimer in the |
12 | 12 | * documentation and/or other materials provided with the distribution. |
22 | 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
23 | 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
24 | 24 | * POSSIBILITY OF SUCH DAMAGE. |
25 | * | |
25 | * | |
26 | 26 | * Note that this license only applies on the examples, NFC library itself is under LGPL |
27 | 27 | * |
28 | 28 | */ |
115 | 115 | ERR ("%zd device found but two opened devices are needed to relay NFC.", szFound); |
116 | 116 | return EXIT_FAILURE; |
117 | 117 | } |
118 | ||
118 | ||
119 | 119 | nfc_init (NULL); |
120 | ||
120 | ||
121 | 121 | // Try to open the NFC emulator device |
122 | 122 | pndTag = nfc_open (NULL, connstrings[0]); |
123 | 123 | if (pndTag == NULL) { |
167 | 167 | |
168 | 168 | printf ("NFC reader device: %s opened", nfc_device_get_name (pndReader)); |
169 | 169 | printf ("%s", "Configuring NFC reader settings..."); |
170 | ||
170 | ||
171 | 171 | if (nfc_initiator_init (pndReader) < 0) { |
172 | 172 | nfc_perror (pndReader, "nfc_initiator_init"); |
173 | exit (EXIT_FAILURE); | |
173 | exit (EXIT_FAILURE); | |
174 | 174 | } |
175 | 175 | if ((nfc_device_set_property_bool (pndReader, NP_HANDLE_CRC, false) < 0) || |
176 | 176 | (nfc_device_set_property_bool (pndReader, NP_HANDLE_PARITY, false) < 0) || |
219 | 219 | } |
220 | 220 | } |
221 | 221 | |
222 | nfc_close (pndTag); | |
222 | nfc_close (pndTag); | |
223 | 223 | nfc_close (pndReader); |
224 | 224 | nfc_exit (NULL); |
225 | 225 | exit (EXIT_SUCCESS); |
0 | 0 | /*- |
1 | 1 | * Public platform independent Near Field Communication (NFC) library examples |
2 | * | |
2 | * | |
3 | 3 | * Copyright (C) 2010, Romuald Conty |
4 | * | |
4 | * | |
5 | 5 | * Redistribution and use in source and binary forms, with or without |
6 | 6 | * modification, are permitted provided that the following conditions are met: |
7 | 7 | * 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. | |
9 | 9 | * 2 )Redistributions in binary form must reproduce the above copyright |
10 | 10 | * notice, this list of conditions and the following disclaimer in the |
11 | 11 | * documentation and/or other materials provided with the distribution. |
21 | 21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
22 | 22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
23 | 23 | * POSSIBILITY OF SUCH DAMAGE. |
24 | * | |
24 | * | |
25 | 25 | * Note that this license only applies on the examples, NFC library itself is under LGPL |
26 | 26 | * |
27 | 27 | */ |
28 | 28 | |
29 | /** | |
29 | /** | |
30 | 30 | * @file pn53x-diagnose.c |
31 | 31 | * @brief Small application to diagnose PN53x using dedicated commands |
32 | 32 | */ |
66 | 66 | if (argc > 1) { |
67 | 67 | errx (1, "usage: %s", argv[0]); |
68 | 68 | } |
69 | ||
69 | ||
70 | 70 | nfc_init (NULL); |
71 | ||
71 | ||
72 | 72 | // Display libnfc version |
73 | 73 | acLibnfcVersion = nfc_version (); |
74 | 74 | printf ("%s uses libnfc %s\n", argv[0], acLibnfcVersion); |
0 | 0 | /*- |
1 | 1 | * Public platform independent Near Field Communication (NFC) library examples |
2 | * | |
2 | * | |
3 | 3 | * Copyright (C) 2010, Emanuele Bertoldi |
4 | * | |
4 | * | |
5 | 5 | * Redistribution and use in source and binary forms, with or without |
6 | 6 | * modification, are permitted provided that the following conditions are met: |
7 | 7 | * 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. | |
9 | 9 | * 2 )Redistributions in binary form must reproduce the above copyright |
10 | 10 | * notice, this list of conditions and the following disclaimer in the |
11 | 11 | * documentation and/or other materials provided with the distribution. |
21 | 21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
22 | 22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
23 | 23 | * POSSIBILITY OF SUCH DAMAGE. |
24 | * | |
24 | * | |
25 | 25 | * Note that this license only applies on the examples, NFC library itself is under LGPL |
26 | 26 | * |
27 | 27 | */ |
73 | 73 | { |
74 | 74 | (void) argc; |
75 | 75 | (void) argv; |
76 | ||
76 | ||
77 | 77 | int ret = EXIT_FAILURE; |
78 | 78 | |
79 | 79 | nfc_init (NULL); |
80 | ||
80 | ||
81 | 81 | // Display libnfc version |
82 | 82 | const char *acLibnfcVersion = nfc_version (); |
83 | 83 | printf ("%s uses libnfc %s\n", argv[0], acLibnfcVersion); |
0 | 0 | /*- |
1 | 1 | * Public platform independent Near Field Communication (NFC) library examples |
2 | * | |
2 | * | |
3 | 3 | * Copyright (C) 2010, Romuald Conty |
4 | * | |
4 | * | |
5 | 5 | * Redistribution and use in source and binary forms, with or without |
6 | 6 | * modification, are permitted provided that the following conditions are met: |
7 | 7 | * 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. | |
9 | 9 | * 2 )Redistributions in binary form must reproduce the above copyright |
10 | 10 | * notice, this list of conditions and the following disclaimer in the |
11 | 11 | * documentation and/or other materials provided with the distribution. |
21 | 21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
22 | 22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
23 | 23 | * POSSIBILITY OF SUCH DAMAGE. |
24 | * | |
24 | * | |
25 | 25 | * Note that this license only applies on the examples, NFC library itself is under LGPL |
26 | 26 | * |
27 | 27 | */ |
83 | 83 | } |
84 | 84 | |
85 | 85 | nfc_init (NULL); |
86 | ||
86 | ||
87 | 87 | // Try to open the NFC reader |
88 | 88 | pnd = nfc_open(NULL, NULL); |
89 | 89 | |
95 | 95 | printf ("NFC reader: %s opened\n", nfc_device_get_name (pnd)); |
96 | 96 | if (nfc_initiator_init (pnd) < 0) { |
97 | 97 | nfc_perror (pnd, "nfc_initiator_init"); |
98 | exit (EXIT_FAILURE); | |
98 | exit (EXIT_FAILURE); | |
99 | 99 | } |
100 | 100 | |
101 | 101 | char *cmd; |
0 | 0 | /*- |
1 | 1 | * Public platform independent Near Field Communication (NFC) library |
2 | * | |
2 | * | |
3 | 3 | * Copyright (C) 2011, Romuald Conty, Romain Tartière |
4 | * | |
4 | * | |
5 | 5 | * This program is free software: you can redistribute it and/or modify it |
6 | 6 | * under the terms of the GNU Lesser General Public License as published by the |
7 | 7 | * Free Software Foundation, either version 3 of the License, or (at your |
8 | 8 | * option) any later version. |
9 | * | |
9 | * | |
10 | 10 | * This program is distributed in the hope that it will be useful, but WITHOUT |
11 | 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
12 | 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
16 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/> |
17 | 17 | */ |
18 | 18 | |
19 | /** | |
19 | /** | |
20 | 20 | * @file nfc-emulation.h |
21 | 21 | * @brief Provide a small API to ease emulation in libnfc |
22 | 22 | */ |
0 | 0 | /** |
1 | 1 | * Public platform independent Near Field Communication (NFC) library |
2 | * | |
2 | * | |
3 | 3 | * Copyright (C) 2009, Roel Verdult |
4 | 4 | * Copyright (C) 2010, Romain Tartière, Romuald Conty |
5 | 5 | * Copyright (C) 2011, Romain Tartière, Romuald Conty |
6 | * | |
6 | * | |
7 | 7 | * This program is free software: you can redistribute it and/or modify it |
8 | 8 | * under the terms of the GNU Lesser General Public License as published by the |
9 | 9 | * Free Software Foundation, either version 3 of the License, or (at your |
10 | 10 | * option) any later version. |
11 | * | |
11 | * | |
12 | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT |
13 | 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
14 | 14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
18 | 18 | * along with this program. If not, see <http://www.gnu.org/licenses/> |
19 | 19 | */ |
20 | 20 | |
21 | /** | |
21 | /** | |
22 | 22 | * @file nfc-types.h |
23 | 23 | * @brief Define NFC types |
24 | 24 | */ |
47 | 47 | * Properties |
48 | 48 | */ |
49 | 49 | typedef enum { |
50 | /** | |
50 | /** | |
51 | 51 | * Default command processing timeout |
52 | 52 | * Property value's (duration) unit is ms and 0 means no timeout (infinite). |
53 | 53 | * Default value is set by driver layer |
54 | 54 | */ |
55 | 55 | NP_TIMEOUT_COMMAND, |
56 | /** | |
56 | /** | |
57 | 57 | * Timeout between ATR_REQ and ATR_RES |
58 | 58 | * When the device is in initiator mode, a target is considered as mute if no |
59 | 59 | * valid ATR_RES is received within this timeout value. |
0 | 0 | /*- |
1 | 1 | * Public platform independent Near Field Communication (NFC) library |
2 | * | |
2 | * | |
3 | 3 | * Copyright (C) 2009, Roel Verdult |
4 | 4 | * Copyright (C) 2010, Romuald Conty |
5 | * | |
5 | * | |
6 | 6 | * This program is free software: you can redistribute it and/or modify it |
7 | 7 | * under the terms of the GNU Lesser General Public License as published by the |
8 | 8 | * Free Software Foundation, either version 3 of the License, or (at your |
9 | 9 | * option) any later version. |
10 | * | |
10 | * | |
11 | 11 | * This program is distributed in the hope that it will be useful, but WITHOUT |
12 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
13 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
136 | 136 | #define NFC_EIO -1 |
137 | 137 | /** @ingroup error |
138 | 138 | * @hideinitializer |
139 | * Invalid argument(s) | |
139 | * Invalid argument(s) | |
140 | 140 | */ |
141 | 141 | #define NFC_EINVARG -2 |
142 | 142 | /** @ingroup error |
143 | 143 | * @hideinitializer |
144 | * Operation not supported by device | |
144 | * Operation not supported by device | |
145 | 145 | */ |
146 | 146 | #define NFC_EDEVNOTSUPP -3 |
147 | 147 | /** @ingroup error |
148 | 148 | * @hideinitializer |
149 | * No such device | |
149 | * No such device | |
150 | 150 | */ |
151 | 151 | #define NFC_ENOTSUCHDEV -4 |
152 | 152 | /** @ingroup error |
153 | 153 | * @hideinitializer |
154 | * Buffer overflow | |
154 | * Buffer overflow | |
155 | 155 | */ |
156 | 156 | #define NFC_EOVFLOW -5 |
157 | 157 | /** @ingroup error |
158 | 158 | * @hideinitializer |
159 | * Operation timed out | |
159 | * Operation timed out | |
160 | 160 | */ |
161 | 161 | #define NFC_ETIMEOUT -6 |
162 | 162 | /** @ingroup error |
163 | 163 | * @hideinitializer |
164 | * Operation aborted (by user) | |
164 | * Operation aborted (by user) | |
165 | 165 | */ |
166 | 166 | #define NFC_EOPABORTED -7 |
167 | 167 | /** @ingroup error |
168 | 168 | * @hideinitializer |
169 | * Not (yet) implemented | |
169 | * Not (yet) implemented | |
170 | 170 | */ |
171 | 171 | #define NFC_ENOTIMPL -8 |
172 | 172 | /** @ingroup error |
173 | 173 | * @hideinitializer |
174 | * Target released | |
174 | * Target released | |
175 | 175 | */ |
176 | #define NFC_ETGRELEASED -10 | |
176 | #define NFC_ETGRELEASED -10 | |
177 | 177 | /** @ingroup error |
178 | 178 | * @hideinitializer |
179 | * Error while RF transmission | |
179 | * Error while RF transmission | |
180 | 180 | */ |
181 | 181 | #define NFC_ERFTRANS -20 |
182 | 182 | /** @ingroup error |
186 | 186 | #define NFC_ESOFT -80 |
187 | 187 | /** @ingroup error |
188 | 188 | * @hideinitializer |
189 | * Device's internal chip error | |
189 | * Device's internal chip error | |
190 | 190 | */ |
191 | 191 | #define NFC_ECHIP -90 |
192 | 192 |
0 | 0 | /*- |
1 | 1 | * Public platform independent Near Field Communication (NFC) library |
2 | * | |
2 | * | |
3 | 3 | * Copyright (C) 2009, 2010, Roel Verdult, Romuald Conty |
4 | * | |
4 | * | |
5 | 5 | * This program is free software: you can redistribute it and/or modify it |
6 | 6 | * under the terms of the GNU Lesser General Public License as published by the |
7 | 7 | * Free Software Foundation, either version 3 of the License, or (at your |
8 | 8 | * option) any later version. |
9 | * | |
9 | * | |
10 | 10 | * This program is distributed in the hope that it will be useful, but WITHOUT |
11 | 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
12 | 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
0 | 0 | /*- |
1 | 1 | * Public platform independent Near Field Communication (NFC) library |
2 | * | |
2 | * | |
3 | 3 | * Copyright (C) 2009, Roel Verdult, Romuald Conty |
4 | 4 | * Copyright (C) 2010, Roel Verdult, Romuald Conty |
5 | 5 | * Copyright (C) 2011, Romuald Conty, Romain Tartière |
6 | * | |
6 | * | |
7 | 7 | * This program is free software: you can redistribute it and/or modify it |
8 | 8 | * under the terms of the GNU Lesser General Public License as published by the |
9 | 9 | * Free Software Foundation, either version 3 of the License, or (at your |
10 | 10 | * option) any later version. |
11 | * | |
11 | * | |
12 | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT |
13 | 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
14 | 14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
0 | 0 | /*- |
1 | 1 | * Public platform independent Near Field Communication (NFC) library |
2 | * | |
2 | * | |
3 | 3 | * Copyright (C) 2009, 2010, Roel Verdult, Romuald Conty |
4 | 4 | * Copyright (C) 2010, Roel Verdult, Romuald Conty |
5 | 5 | * Copyright (C) 2011, Romuald Conty, Romain Tartière |
6 | * | |
6 | * | |
7 | 7 | * This program is free software: you can redistribute it and/or modify it |
8 | 8 | * under the terms of the GNU Lesser General Public License as published by the |
9 | 9 | * Free Software Foundation, either version 3 of the License, or (at your |
10 | 10 | * option) any later version. |
11 | * | |
11 | * | |
12 | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT |
13 | 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
14 | 14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
137 | 137 | uart_set_speed (serial_port sp, const uint32_t uiPortSpeed) |
138 | 138 | { |
139 | 139 | log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "Serial port speed requested to be set to %d bauds.", uiPortSpeed); |
140 | ||
140 | ||
141 | 141 | // Portability note: on some systems, B9600 != 9600 so we have to do |
142 | 142 | // uint32_t <=> speed_t associations by hand. |
143 | 143 | speed_t stPortSpeed = B9600; |
351 | 351 | char **res2 = realloc (res, (szRes+1) * sizeof (char *)); |
352 | 352 | if (!res2) |
353 | 353 | goto oom; |
354 | ||
354 | ||
355 | 355 | res = res2; |
356 | 356 | if (!(res[szRes-1] = malloc (6 + strlen (pdDirEnt->d_name)))) |
357 | 357 | goto oom; |
358 | 358 | |
359 | 359 | sprintf (res[szRes-1], "/dev/%s", pdDirEnt->d_name); |
360 | ||
360 | ||
361 | 361 | szRes++; |
362 | 362 | res[szRes-1] = NULL; |
363 | 363 | } |
0 | 0 | /*- |
1 | 1 | * Public platform independent Near Field Communication (NFC) library |
2 | * | |
2 | * | |
3 | 3 | * Copyright (C) 2009, 2010, Roel Verdult, Romuald Conty |
4 | * | |
4 | * | |
5 | 5 | * This program is free software: you can redistribute it and/or modify it |
6 | 6 | * under the terms of the GNU Lesser General Public License as published by the |
7 | 7 | * Free Software Foundation, either version 3 of the License, or (at your |
8 | 8 | * option) any later version. |
9 | * | |
9 | * | |
10 | 10 | * This program is distributed in the hope that it will be useful, but WITHOUT |
11 | 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
12 | 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
166 | 166 | do { |
167 | 167 | log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "ReadFile"); |
168 | 168 | res = ReadFile (((struct serial_port_windows *) sp)->hPort, pbtRx + dwTotalBytesReceived, |
169 | dwBytesToGet, | |
169 | dwBytesToGet, | |
170 | 170 | &dwBytesReceived, NULL); |
171 | 171 | |
172 | 172 | dwTotalBytesReceived += dwBytesReceived; |
178 | 178 | } else if (dwBytesReceived == 0) { |
179 | 179 | return NFC_ETIMEOUT; |
180 | 180 | } |
181 | ||
181 | ||
182 | 182 | if (((DWORD)szRx) > dwTotalBytesReceived) { |
183 | 183 | dwBytesToGet -= dwBytesReceived; |
184 | 184 | } |
0 | 0 | /*- |
1 | 1 | * Public platform independent Near Field Communication (NFC) library |
2 | * | |
2 | * | |
3 | 3 | * Copyright (C) 2011, Romuald Conty, Romain Tartière |
4 | * | |
4 | * | |
5 | 5 | * This program is free software: you can redistribute it and/or modify it |
6 | 6 | * under the terms of the GNU Lesser General Public License as published by the |
7 | 7 | * Free Software Foundation, either version 3 of the License, or (at your |
8 | 8 | * option) any later version. |
9 | * | |
9 | * | |
10 | 10 | * This program is distributed in the hope that it will be useful, but WITHOUT |
11 | 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
12 | 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
73 | 73 | #define TgGetTargetStatus 0x8A |
74 | 74 | |
75 | 75 | /** @note PN53x's normal frame: |
76 | * | |
76 | * | |
77 | 77 | * .-- Start |
78 | 78 | * | .-- Packet length |
79 | 79 | * | | .-- Length checksum |
80 | 80 | * | | | .-- Direction (D4 Host to PN, D5 PN to Host) |
81 | 81 | * | | | | .-- Code |
82 | 82 | * | | | | | .-- Packet checksum |
83 | * | | | | | | .-- Postamble | |
83 | * | | | | | | .-- Postamble | |
84 | 84 | * V | | | | | | |
85 | 85 | * ----- V V V V V V |
86 | 86 | * 00 FF 02 FE D4 02 2A 00 |
87 | 87 | */ |
88 | 88 | |
89 | 89 | /** @note PN53x's extended frame: |
90 | * | |
90 | * | |
91 | 91 | * .-- Start |
92 | 92 | * | .-- Fixed to FF to enable extended frame |
93 | 93 | * | | .-- Packet length |
95 | 95 | * | | | | .-- Direction (D4 Host to PN, D5 PN to Host) |
96 | 96 | * | | | | | .-- Code |
97 | 97 | * | | | | | | .-- Packet checksum |
98 | * | | | | | | | .-- Postamble | |
98 | * | | | | | | | .-- Postamble | |
99 | 99 | * V V V | | | | | |
100 | 100 | * ----- ----- ----- V V V V V |
101 | 101 | * 00 FF FF FF 00 02 FE D4 02 2A 00 |
102 | 102 | */ |
103 | 103 | |
104 | /** | |
104 | /** | |
105 | 105 | * Start bytes, packet length, length checksum, direction, packet checksum and postamble are overhead |
106 | 106 | */ |
107 | 107 | // The TFI is considered part of the overhead |
155 | 155 | PNCMD( SAMConfiguration, PN531|PN532 ), |
156 | 156 | PNCMD( PowerDown, PN531|PN532 ), |
157 | 157 | PNCMD( AlparCommandForTDA, PN533|RCS360 ), // Has another usage on RC-S360... |
158 | ||
158 | ||
159 | 159 | // RF communication |
160 | 160 | PNCMD( RFConfiguration, PN531|PN532|PN533|RCS360 ), |
161 | 161 | PNCMD( RFRegulationTest, PN531|PN532|PN533 ), |
0 | 0 | /*- |
1 | 1 | * Public platform independent Near Field Communication (NFC) library |
2 | * | |
2 | * | |
3 | 3 | * Copyright (C) 2009, Roel Verdult, Romuald Conty |
4 | 4 | * Copyright (C) 2010, Roel Verdult, Romuald Conty, Romain Tartière |
5 | 5 | * Copyright (C) 2011, Romuald Conty, Romain Tartière |
6 | * | |
6 | * | |
7 | 7 | * This program is free software: you can redistribute it and/or modify it |
8 | 8 | * under the terms of the GNU Lesser General Public License as published by the |
9 | 9 | * Free Software Foundation, either version 3 of the License, or (at your |
10 | 10 | * option) any later version. |
11 | * | |
11 | * | |
12 | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT |
13 | 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
14 | 14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
79 | 79 | nbSupportedModulation++; |
80 | 80 | CHIP_DATA(pnd)->supported_modulation_as_initiator[nbSupportedModulation] = NMT_FELICA; |
81 | 81 | nbSupportedModulation++; |
82 | } | |
82 | } | |
83 | 83 | if (pnd->btSupportByte & SUPPORT_ISO14443B) { |
84 | 84 | CHIP_DATA(pnd)->supported_modulation_as_initiator[nbSupportedModulation] = NMT_ISO14443B; |
85 | 85 | nbSupportedModulation++; |
86 | } | |
86 | } | |
87 | 87 | if(CHIP_DATA(pnd)->type != PN531) { |
88 | 88 | CHIP_DATA(pnd)->supported_modulation_as_initiator[nbSupportedModulation] = NMT_JEWEL; |
89 | 89 | nbSupportedModulation++; |
92 | 92 | nbSupportedModulation++; |
93 | 93 | CHIP_DATA(pnd)->supported_modulation_as_initiator[nbSupportedModulation] = 0; |
94 | 94 | } |
95 | ||
95 | ||
96 | 96 | if (!CHIP_DATA(pnd)->supported_modulation_as_target) { |
97 | 97 | CHIP_DATA(pnd)->supported_modulation_as_target = (nfc_modulation_type*) pn53x_supported_modulation_as_target; |
98 | 98 | } |
99 | ||
99 | ||
100 | 100 | // CRC handling should be enabled by default as declared in nfc_device_new |
101 | 101 | // which is the case by default for pn53x, so nothing to do here |
102 | 102 | // Parity handling should be enabled by default as declared in nfc_device_new |
487 | 487 | case NMT_ISO14443BI: |
488 | 488 | // Skip V & T Addresses |
489 | 489 | pbtRawData++; |
490 | if (*pbtRawData != 0x07) { // 0x07 = REPGEN | |
490 | if (*pbtRawData != 0x07) { // 0x07 = REPGEN | |
491 | 491 | return NFC_ECHIP; |
492 | 492 | } |
493 | 493 | pbtRawData++; |
756 | 756 | return res; |
757 | 757 | } |
758 | 758 | |
759 | int | |
759 | int | |
760 | 760 | pn53x_set_property_int (struct nfc_device *pnd, const nfc_property property, const int value) |
761 | 761 | { |
762 | 762 | switch (property) { |
845 | 845 | // TODO Made some research around this point: |
846 | 846 | // timings could be tweak better than this, and maybe we can tweak timings |
847 | 847 | // to "gain" a sort-of hardware polling (ie. like PN532 does) |
848 | if (pn53x_RFConfiguration__MaxRetries (pnd, | |
848 | if (pn53x_RFConfiguration__MaxRetries (pnd, | |
849 | 849 | (bEnable) ? 0xff : 0x00, // MxRtyATR, default: active = 0xff, passive = 0x02 |
850 | 850 | (bEnable) ? 0xff : 0x01, // MxRtyPSL, default: 0x01 |
851 | 851 | (bEnable) ? 0xff : 0x02 // MxRtyPassiveActivation, default: 0xff (0x00 leads to problems with PN531) |
983 | 983 | szRx = (size_t) res; |
984 | 984 | if ((sizeof(abtExpectedRx) == szRx) && (0 == memcmp (abtRx, abtExpectedRx, sizeof(abtExpectedRx)))) |
985 | 985 | return NFC_SUCCESS; |
986 | ||
986 | ||
987 | 987 | return NFC_EIO; |
988 | 988 | } |
989 | 989 | |
1050 | 1050 | const uint8_t abtReqt[]= { 0x10 }; |
1051 | 1051 | // Getting product code / fab code & store it in output buffer after the serial nr we'll obtain later |
1052 | 1052 | if ((res = pn53x_initiator_transceive_bytes (pnd, abtReqt, sizeof(abtReqt), abtTargetsData+2, sizeof(abtTargetsData)-2, timeout)) < 0) { |
1053 | return res; | |
1053 | return res; | |
1054 | 1054 | } |
1055 | 1055 | szTargetsData = (size_t)res; |
1056 | 1056 | } |
1122 | 1122 | nfc_target *pnt) |
1123 | 1123 | { |
1124 | 1124 | int res = 0; |
1125 | ||
1125 | ||
1126 | 1126 | if (CHIP_DATA(pnd)->type == PN532) { |
1127 | 1127 | size_t szTargetTypes = 0; |
1128 | 1128 | pn53x_target_type apttTargetTypes[32]; |
1166 | 1166 | size_t szInitiatorData; |
1167 | 1167 | prepare_initiator_data (pnmModulations[n], &pbtInitiatorData, &szInitiatorData); |
1168 | 1168 | const int timeout_ms = uiPeriod * 150; |
1169 | ||
1169 | ||
1170 | 1170 | if ((res = pn53x_initiator_select_passive_target_ext (pnd, pnmModulations[n], pbtInitiatorData, szInitiatorData, pnt, timeout_ms)) < 0) { |
1171 | 1171 | if (pnd->last_error != NFC_ETIMEOUT) { |
1172 | 1172 | return pnd->last_error; |
1630 | 1630 | return pn53x_InDeselect (pnd, 0); // 0 mean deselect all selected targets |
1631 | 1631 | } |
1632 | 1632 | |
1633 | int | |
1633 | int | |
1634 | 1634 | pn53x_initiator_target_is_present (struct nfc_device *pnd, const nfc_target nt) |
1635 | 1635 | { |
1636 | 1636 | // TODO Check if nt is equal to current target |
1785 | 1785 | // Set System Code |
1786 | 1786 | abtFeliCaParams[16] = 0x0f; |
1787 | 1787 | abtFeliCaParams[17] = 0xab; |
1788 | ||
1788 | ||
1789 | 1789 | pbtFeliCaParams = abtFeliCaParams; |
1790 | 1790 | break; |
1791 | 1791 | case NMT_ISO14443B: |
1883 | 1883 | uint8_t abtRx[PN53x_EXTENDED_FRAME__DATA_MAX_LEN]; |
1884 | 1884 | size_t szRx = sizeof (abtRx); |
1885 | 1885 | int res = 0; |
1886 | ||
1886 | ||
1887 | 1887 | // Try to gather a received frame from the reader |
1888 | 1888 | if ((res = pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), abtRx, szRx, -1)) < 0) |
1889 | 1889 | return res; |
2047 | 2047 | return pnd->last_error; |
2048 | 2048 | } |
2049 | 2049 | } |
2050 | // NO BREAK | |
2050 | // NO BREAK | |
2051 | 2051 | case NMT_JEWEL: |
2052 | 2052 | case NMT_ISO14443B: |
2053 | 2053 | case NMT_ISO14443BI: |
2063 | 2063 | |
2064 | 2064 | // Copy the data into the command frame |
2065 | 2065 | memcpy (abtCmd + 1, pbtTx, szTx); |
2066 | ||
2066 | ||
2067 | 2067 | // Try to send the bits to the reader |
2068 | 2068 | if ((res = pn53x_transceive (pnd, abtCmd, szTx + 1, NULL, 0, timeout)) < 0) |
2069 | 2069 | return res; |
2564 | 2564 | return res; |
2565 | 2565 | szRx = (size_t) res; |
2566 | 2566 | |
2567 | // Note: the first byte is skip: | |
2567 | // Note: the first byte is skip: | |
2568 | 2568 | // its the "mode" byte which contains baudrate, DEP and Framing type (Mifare, active or FeliCa) datas. |
2569 | 2569 | if(pbtModeByte) { |
2570 | 2570 | *pbtModeByte = abtRx[0]; |
2572 | 2572 | |
2573 | 2573 | // Save the received byte count |
2574 | 2574 | szRx -= 1; |
2575 | ||
2575 | ||
2576 | 2576 | if ((szRx - 1) > szRxLen) |
2577 | 2577 | return NFC_EOVFLOW; |
2578 | 2578 | // Copy the received bytes |
2830 | 2830 | return PTT_UNDEFINED; |
2831 | 2831 | } |
2832 | 2832 | |
2833 | int | |
2833 | int | |
2834 | 2834 | pn53x_get_supported_modulation(nfc_device *pnd, const nfc_mode mode, const nfc_modulation_type * *const supported_mt) |
2835 | 2835 | { |
2836 | 2836 | switch (mode) { |
2840 | 2840 | case N_INITIATOR: |
2841 | 2841 | *supported_mt = CHIP_DATA(pnd)->supported_modulation_as_initiator; |
2842 | 2842 | break; |
2843 | default: | |
2843 | default: | |
2844 | 2844 | return NFC_EINVARG; |
2845 | 2845 | } |
2846 | 2846 | return NFC_SUCCESS; |
2848 | 2848 | |
2849 | 2849 | int |
2850 | 2850 | pn53x_get_supported_baud_rate (nfc_device *pnd, const nfc_modulation_type nmt, const nfc_baud_rate * *const supported_br) |
2851 | { | |
2851 | { | |
2852 | 2852 | switch (nmt) { |
2853 | case NMT_FELICA: | |
2853 | case NMT_FELICA: | |
2854 | 2854 | *supported_br = (nfc_baud_rate*)pn53x_felica_supported_baud_rates; |
2855 | 2855 | break; |
2856 | case NMT_ISO14443A: | |
2856 | case NMT_ISO14443A: | |
2857 | 2857 | *supported_br = (nfc_baud_rate*)pn53x_iso14443a_supported_baud_rates; |
2858 | 2858 | break; |
2859 | 2859 | case NMT_ISO14443B: |
2871 | 2871 | case NMT_JEWEL: |
2872 | 2872 | *supported_br = (nfc_baud_rate*)pn53x_jewel_supported_baud_rates; |
2873 | 2873 | break; |
2874 | case NMT_DEP: | |
2874 | case NMT_DEP: | |
2875 | 2875 | *supported_br = (nfc_baud_rate*)pn53x_dep_supported_baud_rates; |
2876 | 2876 | break; |
2877 | 2877 | default: |
2905 | 2905 | if ((res = nfc_device_get_supported_modulation(pnd, N_INITIATOR, &nmt)) < 0) { |
2906 | 2906 | return res; |
2907 | 2907 | } |
2908 | ||
2908 | ||
2909 | 2909 | for (int i=0; nmt[i]; i++) { |
2910 | 2910 | if ((res = snprintf (buf, buflen, "%s%s (", (i==0)?"":", ", str_nfc_modulation_type (nmt[i]))) < 0) { |
2911 | 2911 | return NFC_ESOFT; |
2919 | 2919 | if ((res = nfc_device_get_supported_baud_rate (pnd, nmt[i], &nbr)) < 0) { |
2920 | 2920 | return res; |
2921 | 2921 | } |
2922 | ||
2922 | ||
2923 | 2923 | for (int j=0; nbr[j]; j++) { |
2924 | 2924 | if ((res = snprintf (buf, buflen, "%s%s", (j==0)?"":", ", str_nfc_baud_rate (nbr[j]))) < 0) { |
2925 | 2925 | return NFC_ESOFT; |
2959 | 2959 | if ((res = nfc_device_get_supported_modulation(pnd, N_TARGET, &nmt)) < 0) { |
2960 | 2960 | return res; |
2961 | 2961 | } |
2962 | ||
2962 | ||
2963 | 2963 | for (int i=0; nmt[i]; i++) { |
2964 | 2964 | if ((res = snprintf (buf, buflen, "%s%s (", (i==0)?"":", ", str_nfc_modulation_type (nmt[i]))) < 0) { |
2965 | 2965 | return NFC_ESOFT; |
2973 | 2973 | if ((res = nfc_device_get_supported_baud_rate (pnd, nmt[i], &nbr)) < 0) { |
2974 | 2974 | return res; |
2975 | 2975 | } |
2976 | ||
2976 | ||
2977 | 2977 | for (int j=0; nbr[j]; j++) { |
2978 | 2978 | if ((res = snprintf (buf, buflen, "%s%s", (j==0)?"":", ", str_nfc_baud_rate (nbr[j]))) < 0) { |
2979 | 2979 | return NFC_ESOFT; |
3042 | 3042 | |
3043 | 3043 | // Set default communication timeout (52 ms) |
3044 | 3044 | CHIP_DATA (pnd)->timeout_communication = 52; |
3045 | ||
3045 | ||
3046 | 3046 | 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; | |
3049 | 3049 | } |
3050 | 3050 | |
3051 | 3051 | void |
0 | 0 | /*- |
1 | 1 | * Public platform independent Near Field Communication (NFC) library |
2 | * | |
2 | * | |
3 | 3 | * Copyright (C) 2009, Roel Verdult, Romuald Conty |
4 | 4 | * Copyright (C) 2010, Roel Verdult, Romuald Conty, Romain Tartière |
5 | 5 | * Copyright (C) 2011, Romuald Conty, Romain Tartière |
6 | * | |
6 | * | |
7 | 7 | * This program is free software: you can redistribute it and/or modify it |
8 | 8 | * under the terms of the GNU Lesser General Public License as published by the |
9 | 9 | * Free Software Foundation, either version 3 of the License, or (at your |
10 | 10 | * option) any later version. |
11 | * | |
11 | * | |
12 | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT |
13 | 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
14 | 14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
18 | 18 | * along with this program. If not, see <http://www.gnu.org/licenses/> |
19 | 19 | */ |
20 | 20 | |
21 | /** | |
21 | /** | |
22 | 22 | * @file pn53x.h |
23 | 23 | * @brief PN531, PN532 and PN533 common functions |
24 | 24 | */ |
188 | 188 | int timeout_atr; |
189 | 189 | /** Communication timeout */ |
190 | 190 | 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; | |
193 | 193 | nfc_modulation_type *supported_modulation_as_target; |
194 | 194 | }; |
195 | 195 | |
209 | 209 | /** JIS X 6319-4 (Sony Felica) http://en.wikipedia.org/wiki/FeliCa */ |
210 | 210 | PM_FELICA_424 = 0x02, |
211 | 211 | /** ISO14443-B http://en.wikipedia.org/wiki/ISO/IEC_14443 (Not supported by PN531) */ |
212 | PM_ISO14443B_106 = 0x03, | |
212 | PM_ISO14443B_106 = 0x03, | |
213 | 213 | /** Jewel Topaz (Innovision Research & Development) (Not supported by PN531) */ |
214 | 214 | PM_JEWEL_106 = 0x04, |
215 | 215 | /** ISO14443-B http://en.wikipedia.org/wiki/ISO/IEC_14443 (Not supported by PN531 nor PN532) */ |
321 | 321 | nfc_target *pnt); |
322 | 322 | int pn53x_initiator_select_dep_target (struct nfc_device *pnd, |
323 | 323 | const nfc_dep_mode ndm, const nfc_baud_rate nbr, |
324 | const nfc_dep_info *pndiInitiator, | |
324 | const nfc_dep_info *pndiInitiator, | |
325 | 325 | nfc_target *pnt, |
326 | 326 | const int timeout); |
327 | 327 | int pn53x_initiator_transceive_bits (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, |
0 | 0 | /*- |
1 | 1 | * Public platform independent Near Field Communication (NFC) library |
2 | * | |
2 | * | |
3 | 3 | * Copyright (C) 2009, Roel Verdult |
4 | 4 | * Copyright (C) 2011, Romain Tartiere, Romuald Conty |
5 | 5 | * Copyright (C) 2012, Romuald Conty |
6 | * | |
6 | * | |
7 | 7 | * This program is free software: you can redistribute it and/or modify it |
8 | 8 | * under the terms of the GNU Lesser General Public License as published by the |
9 | 9 | * Free Software Foundation, either version 3 of the License, or (at your |
10 | 10 | * option) any later version. |
11 | * | |
11 | * | |
12 | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT |
13 | 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
14 | 14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
281 | 281 | pn53x_data_new (pnd, &acr122_pcsc_io); |
282 | 282 | |
283 | 283 | SCARDCONTEXT *pscc; |
284 | ||
284 | ||
285 | 285 | log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "Attempt to open %s", ndd.pcsc_device_name); |
286 | 286 | // Test if context succeeded |
287 | 287 | if (!(pscc = acr122_pcsc_get_scardcontext ())) |
0 | 0 | /** |
1 | 1 | * Public platform independent Near Field Communication (NFC) library |
2 | * | |
2 | * | |
3 | 3 | * Copyright (C) 2009, Roel Verdult |
4 | 4 | * Copyright (C) 2011, Romain Tartiere, Romuald Conty |
5 | 5 | * Copyright (C) 2012, Romuald Conty |
6 | * | |
6 | * | |
7 | 7 | * This program is free software: you can redistribute it and/or modify it |
8 | 8 | * under the terms of the GNU Lesser General Public License as published by the |
9 | 9 | * Free Software Foundation, either version 3 of the License, or (at your |
10 | 10 | * option) any later version. |
11 | * | |
11 | * | |
12 | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT |
13 | 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
14 | 14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
16 | 16 | * |
17 | 17 | * You should have received a copy of the GNU Lesser General Public License |
18 | 18 | * along with this program. If not, see <http://www.gnu.org/licenses/> |
19 | * | |
20 | * | |
19 | * | |
20 | * | |
21 | 21 | * @file acr122_pcsc.h |
22 | 22 | * @brief Driver for ACR122 devices (behind PC/SC daemon) |
23 | 23 | */ |
0 | 0 | /*- |
1 | 1 | * Public platform independent Near Field Communication (NFC) library |
2 | * | |
2 | * | |
3 | 3 | * Copyright (C) 2009, Roel Verdult |
4 | 4 | * Copyright (C) 2010, Romain Tartière, Romuald Conty |
5 | 5 | * Copyright (C) 2011, Romain Tartière, Romuald Conty |
6 | * | |
6 | * | |
7 | 7 | * This program is free software: you can redistribute it and/or modify it |
8 | 8 | * under the terms of the GNU Lesser General Public License as published by the |
9 | 9 | * Free Software Foundation, either version 3 of the License, or (at your |
10 | 10 | * option) any later version. |
11 | * | |
11 | * | |
12 | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT |
13 | 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
14 | 14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
32 | 32 | * Revision 1.1 |
33 | 33 | * April 22rd, 2005 |
34 | 34 | * http://www.usb.org/developers/devclass_docs/DWG_Smart-Card_CCID_Rev110.pdf |
35 | * | |
35 | * | |
36 | 36 | * ACR122U NFC Reader |
37 | 37 | * Application Programming Interface |
38 | 38 | * Revision 1.2 |
683 | 683 | |
684 | 684 | /* |
685 | 685 | // 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[] = { | |
687 | 687 | 0x6b, // CCID |
688 | 688 | 0x09, // lenght of frame |
689 | 689 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // padding |
0 | 0 | /** |
1 | 1 | * Public platform independent Near Field Communication (NFC) library |
2 | * | |
2 | * | |
3 | 3 | * Copyright (C) 2009, Roel Verdult |
4 | 4 | * Copyright (C) 2011, Romain Tartière |
5 | * | |
5 | * | |
6 | 6 | * This program is free software: you can redistribute it and/or modify it |
7 | 7 | * under the terms of the GNU Lesser General Public License as published by the |
8 | 8 | * Free Software Foundation, either version 3 of the License, or (at your |
9 | 9 | * option) any later version. |
10 | * | |
10 | * | |
11 | 11 | * This program is distributed in the hope that it will be useful, but WITHOUT |
12 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
13 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
15 | 15 | * |
16 | 16 | * You should have received a copy of the GNU Lesser General Public License |
17 | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/> |
18 | * | |
19 | * | |
18 | * | |
19 | * | |
20 | 20 | * @file acr122_usb.h |
21 | 21 | * @brief Driver for ACR122 devices using direct USB connection (without PCSC) |
22 | 22 | */ |
478 | 478 | return false; |
479 | 479 | #else /* SERIAL_AUTOPROBE_ENABLED */ |
480 | 480 | *pszDeviceFound = 0; |
481 | ||
481 | ||
482 | 482 | serial_port sp; |
483 | 483 | char **acPorts = uart_list_ports (); |
484 | 484 | const char *acPort; |
487 | 487 | while ((acPort = acPorts[iDevice++])) { |
488 | 488 | sp = uart_open (acPort); |
489 | 489 | 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 | ||
491 | 491 | if ((sp != INVALID_SERIAL_PORT) && (sp != CLAIMED_SERIAL_PORT)) { |
492 | 492 | // We need to flush input to be sure first reply does not comes from older byte transceive |
493 | 493 | uart_flush_input (sp); |
511 | 511 | pn53x_data_new(pnd, &acr122s_io); |
512 | 512 | CHIP_DATA(pnd)->type = PN532; |
513 | 513 | CHIP_DATA(pnd)->power_mode = NORMAL; |
514 | ||
514 | ||
515 | 515 | char version[32]; |
516 | 516 | int ret = acr122s_get_firmware_version(pnd, version, sizeof(version)); |
517 | 517 | if (ret == 0 && strncmp("ACR122S", version, 7) != 0) { |
524 | 524 | |
525 | 525 | if (ret != 0) |
526 | 526 | continue; |
527 | ||
527 | ||
528 | 528 | // ACR122S reader is found |
529 | 529 | memcpy (connstrings[*pszDeviceFound], connstring, sizeof(nfc_connstring)); |
530 | 530 | (*pszDeviceFound)++; |
531 | ||
531 | ||
532 | 532 | // Test if we reach the maximum "wanted" devices |
533 | 533 | if (*pszDeviceFound >= connstrings_len) |
534 | 534 | break; |
550 | 550 | nfc_device *pnd; |
551 | 551 | struct acr122s_descriptor ndd; |
552 | 552 | int connstring_decode_level = acr122s_connstring_decode (connstring, &ndd); |
553 | ||
553 | ||
554 | 554 | if (connstring_decode_level < 2) { |
555 | 555 | return NULL; |
556 | 556 | } |
0 | 0 | /*- |
1 | 1 | * Public platform independent Near Field Communication (NFC) library |
2 | * | |
2 | * | |
3 | 3 | * Copyright (C) 2009, Roel Verdult |
4 | 4 | * Copyright (C) 2010, Romuald Conty |
5 | 5 | * Copyright (C) 2011, Romain Tartière, Romuald Conty |
6 | * | |
6 | * | |
7 | 7 | * This program is free software: you can redistribute it and/or modify it |
8 | 8 | * under the terms of the GNU Lesser General Public License as published by the |
9 | 9 | * Free Software Foundation, either version 3 of the License, or (at your |
10 | 10 | * option) any later version. |
11 | * | |
11 | * | |
12 | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT |
13 | 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
14 | 14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
21 | 21 | /** |
22 | 22 | * @file arygon.c |
23 | 23 | * @brief ARYGON readers driver |
24 | * | |
24 | * | |
25 | 25 | * This driver can handle ARYGON readers that use UART as bus. |
26 | 26 | * 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) |
27 | 27 | */ |
49 | 49 | #include "uart.h" |
50 | 50 | |
51 | 51 | /** @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) | |
53 | 53 | */ |
54 | 54 | #define DEV_ARYGON_PROTOCOL_ARYGON_ASCII '0' |
55 | 55 | /** @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) | |
57 | 57 | */ |
58 | 58 | #define DEV_ARYGON_PROTOCOL_ARYGON_BINARY_WAB '1' |
59 | 59 | /** @def DEV_ARYGON_PROTOCOL_TAMA |
540 | 540 | return NFC_SUCCESS; |
541 | 541 | } |
542 | 542 | |
543 | static int | |
543 | static int | |
544 | 544 | arygon_abort_command (nfc_device *pnd) |
545 | 545 | { |
546 | 546 | if (pnd) { |
0 | 0 | /** |
1 | 1 | * Public platform independent Near Field Communication (NFC) library |
2 | * | |
2 | * | |
3 | 3 | * Copyright (C) 2009, Roel Verdult |
4 | 4 | * Copyright (C) 2010, Romuald Conty |
5 | 5 | * Copyright (C) 2011, Romuald Conty, Romain Tartière |
6 | * | |
6 | * | |
7 | 7 | * This program is free software: you can redistribute it and/or modify it |
8 | 8 | * under the terms of the GNU Lesser General Public License as published by the |
9 | 9 | * Free Software Foundation, either version 3 of the License, or (at your |
10 | 10 | * option) any later version. |
11 | * | |
11 | * | |
12 | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT |
13 | 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
14 | 14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
16 | 16 | * |
17 | 17 | * You should have received a copy of the GNU Lesser General Public License |
18 | 18 | * along with this program. If not, see <http://www.gnu.org/licenses/> |
19 | * | |
20 | * | |
19 | * | |
20 | * | |
21 | 21 | * @file arygon.h |
22 | 22 | * @brief Driver for PN53x-equipped ARYGON device connected using UART |
23 | 23 | */ |
0 | 0 | /*- |
1 | 1 | * Public platform independent Near Field Communication (NFC) library |
2 | * | |
2 | * | |
3 | 3 | * Copyright (C) 2010, Roel Verdult, Romuald Conty |
4 | 4 | * Copyright (C) 2011, Romuald Conty, Romain Tartière |
5 | * | |
5 | * | |
6 | 6 | * This program is free software: you can redistribute it and/or modify it |
7 | 7 | * under the terms of the GNU Lesser General Public License as published by the |
8 | 8 | * Free Software Foundation, either version 3 of the License, or (at your |
9 | 9 | * option) any later version. |
10 | * | |
10 | * | |
11 | 11 | * This program is distributed in the hope that it will be useful, but WITHOUT |
12 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
13 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
60 | 60 | volatile bool abort_flag; |
61 | 61 | #endif |
62 | 62 | }; |
63 | ||
63 | ||
64 | 64 | #define DRIVER_DATA(pnd) ((struct pn532_uart_data*)(pnd->driver_data)) |
65 | 65 | |
66 | 66 | bool |
0 | 0 | /** |
1 | 1 | * Public platform independent Near Field Communication (NFC) library |
2 | * | |
2 | * | |
3 | 3 | * Copyright (C) 2010, Roel Verdult, Romuald Conty |
4 | 4 | * Copyright (C) 2011, Romuald Conty, Romain Tartière |
5 | * | |
5 | * | |
6 | 6 | * This program is free software: you can redistribute it and/or modify it |
7 | 7 | * under the terms of the GNU Lesser General Public License as published by the |
8 | 8 | * Free Software Foundation, either version 3 of the License, or (at your |
9 | 9 | * option) any later version. |
10 | * | |
10 | * | |
11 | 11 | * This program is distributed in the hope that it will be useful, but WITHOUT |
12 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
13 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
15 | 15 | * |
16 | 16 | * You should have received a copy of the GNU Lesser General Public License |
17 | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/> |
18 | * | |
19 | * | |
18 | * | |
19 | * | |
20 | 20 | * @file pn532_uart.h |
21 | 21 | * @brief Driver for PN532 connected in UART (HSU) |
22 | 22 | */ |
0 | 0 | /*- |
1 | 1 | * Public platform independent Near Field Communication (NFC) library |
2 | * | |
2 | * | |
3 | 3 | * Copyright (C) 2009, Roel Verdult |
4 | 4 | * Copyright (C) 2010, Romain Tartière, Romuald Conty |
5 | 5 | * Copyright (C) 2011, Romain Tartière, Romuald Conty |
6 | * | |
6 | * | |
7 | 7 | * This program is free software: you can redistribute it and/or modify it |
8 | 8 | * under the terms of the GNU Lesser General Public License as published by the |
9 | 9 | * Free Software Foundation, either version 3 of the License, or (at your |
10 | 10 | * option) any later version. |
11 | * | |
11 | * | |
12 | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT |
13 | 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
14 | 14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
685 | 685 | |
686 | 686 | /* |
687 | 687 | On ASK LoGO hardware: |
688 | LEDs port bits definition: | |
688 | LEDs port bits definition: | |
689 | 689 | * LED 1: bit 2 (P32) |
690 | 690 | * LED 2: bit 1 (P31) |
691 | 691 | * LED 3: bit 0 or 3 (depending of hardware revision) (P30 or P33) |
692 | 692 | * 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. | |
695 | 695 | * Bit 4 should be maintained at 1 to keep RF field on. |
696 | 696 | |
697 | 697 | Progressive field activation: |
698 | 698 | The ASK LoGO hardware can progressively power-up the antenna. |
699 | 699 | 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 | |
701 | 701 | field by switching off the field on PN533 then set P34 to '0'. |
702 | 702 | */ |
703 | 703 |
0 | 0 | /** |
1 | 1 | * Public platform independent Near Field Communication (NFC) library |
2 | * | |
2 | * | |
3 | 3 | * Copyright (C) 2009, Roel Verdult |
4 | 4 | * Copyright (C) 2011, Romain Tartière |
5 | * | |
5 | * | |
6 | 6 | * This program is free software: you can redistribute it and/or modify it |
7 | 7 | * under the terms of the GNU Lesser General Public License as published by the |
8 | 8 | * Free Software Foundation, either version 3 of the License, or (at your |
9 | 9 | * option) any later version. |
10 | * | |
10 | * | |
11 | 11 | * This program is distributed in the hope that it will be useful, but WITHOUT |
12 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
13 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
15 | 15 | * |
16 | 16 | * You should have received a copy of the GNU Lesser General Public License |
17 | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/> |
18 | * | |
19 | * | |
18 | * | |
19 | * | |
20 | 20 | * @file pn53x_usb.h |
21 | 21 | * @brief Drive for PN53x USB devices |
22 | 22 | */ |
0 | 0 | /*- |
1 | 1 | * Public platform independent Near Field Communication (NFC) library |
2 | * | |
2 | * | |
3 | 3 | * Copyright (C) 2009, Roel Verdult |
4 | 4 | * Copyright (C) 2011, Romuald Conty, Romain Tartière |
5 | * | |
5 | * | |
6 | 6 | * This program is free software: you can redistribute it and/or modify it |
7 | 7 | * under the terms of the GNU Lesser General Public License as published by the |
8 | 8 | * Free Software Foundation, either version 3 of the License, or (at your |
9 | 9 | * option) any later version. |
10 | * | |
10 | * | |
11 | 11 | * This program is distributed in the hope that it will be useful, but WITHOUT |
12 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
13 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
0 | 0 | /*- |
1 | 1 | * Public platform independent Near Field Communication (NFC) library |
2 | * | |
2 | * | |
3 | 3 | * Copyright (C) 2009, Roel Verdult |
4 | * | |
4 | * | |
5 | 5 | * This program is free software: you can redistribute it and/or modify it |
6 | 6 | * under the terms of the GNU Lesser General Public License as published by the |
7 | 7 | * Free Software Foundation, either version 3 of the License, or (at your |
8 | 8 | * option) any later version. |
9 | * | |
9 | * | |
10 | 10 | * This program is distributed in the hope that it will be useful, but WITHOUT |
11 | 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
12 | 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
94 | 94 | * @brief Add cascade tags (0x88) in UID |
95 | 95 | * @see ISO/IEC 14443-3 (6.4.4 UID contents and cascade levels) |
96 | 96 | */ |
97 | void | |
97 | void | |
98 | 98 | iso14443_cascade_uid (const uint8_t abtUID[], const size_t szUID, uint8_t *pbtCascadedUID, size_t *pszCascadedUID) |
99 | 99 | { |
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 | } | |
121 | 121 | } |
0 | 0 | /*- |
1 | 1 | * Public platform independent Near Field Communication (NFC) library |
2 | * | |
2 | * | |
3 | 3 | * Copyright (C) 2011, Romuald Conty, Romain Tartière |
4 | * | |
4 | * | |
5 | 5 | * This program is free software: you can redistribute it and/or modify it |
6 | 6 | * under the terms of the GNU Lesser General Public License as published by the |
7 | 7 | * Free Software Foundation, either version 3 of the License, or (at your |
8 | 8 | * option) any later version. |
9 | * | |
9 | * | |
10 | 10 | * This program is distributed in the hope that it will be useful, but WITHOUT |
11 | 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
12 | 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
40 | 40 | __attribute__((format(printf, 3, 4))) |
41 | 41 | # endif |
42 | 42 | ; |
43 | ||
44 | ||
43 | ||
44 | ||
45 | 45 | #define NFC_PRIORITY_FATAL "fatal" |
46 | 46 | #define NFC_PRIORITY_ALERT "alert" |
47 | 47 | #define NFC_PRIORITY_CRIT "critical" |
58 | 58 | #define log_msg(category, priority, message) do {} while (0) |
59 | 59 | #define log_set_appender(category, appender) do {} while (0) |
60 | 60 | #define log_put(category, priority, format, ...) do {} while (0) |
61 | ||
61 | ||
62 | 62 | #define NFC_PRIORITY_FATAL 8 |
63 | 63 | #define NFC_PRIORITY_ALERT 7 |
64 | 64 | #define NFC_PRIORITY_CRIT 6 |
0 | 0 | /*- |
1 | 1 | * Public platform independent Near Field Communication (NFC) library |
2 | * | |
2 | * | |
3 | 3 | * Copyright (C) 2009, Roel Verdult |
4 | * | |
4 | * | |
5 | 5 | * This program is free software: you can redistribute it and/or modify it |
6 | 6 | * under the terms of the GNU Lesser General Public License as published by the |
7 | 7 | * Free Software Foundation, either version 3 of the License, or (at your |
8 | 8 | * option) any later version. |
9 | * | |
9 | * | |
10 | 10 | * This program is distributed in the hope that it will be useful, but WITHOUT |
11 | 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
12 | 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
0 | 0 | /** |
1 | 1 | * Public platform independent Near Field Communication (NFC) library |
2 | * | |
2 | * | |
3 | 3 | * Copyright (C) 2009, Roel Verdult |
4 | * | |
4 | * | |
5 | 5 | * This program is free software: you can redistribute it and/or modify it |
6 | 6 | * under the terms of the GNU Lesser General Public License as published by the |
7 | 7 | * Free Software Foundation, either version 3 of the License, or (at your |
8 | 8 | * option) any later version. |
9 | * | |
9 | * | |
10 | 10 | * This program is distributed in the hope that it will be useful, but WITHOUT |
11 | 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
12 | 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
14 | 14 | * |
15 | 15 | * You should have received a copy of the GNU Lesser General Public License |
16 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/> |
17 | * | |
18 | * | |
17 | * | |
18 | * | |
19 | 19 | * @file mirror-subr.h |
20 | 20 | * @brief Mirror bytes |
21 | 21 | */ |
0 | 0 | /*- |
1 | 1 | * Public platform independent Near Field Communication (NFC) library |
2 | * | |
2 | * | |
3 | 3 | * Copyright (C) 2011, Romain Tartière, Romuald Conty |
4 | * | |
4 | * | |
5 | 5 | * This program is free software: you can redistribute it and/or modify it |
6 | 6 | * under the terms of the GNU Lesser General Public License as published by the |
7 | 7 | * Free Software Foundation, either version 3 of the License, or (at your |
8 | 8 | * option) any later version. |
9 | * | |
9 | * | |
10 | 10 | * This program is distributed in the hope that it will be useful, but WITHOUT |
11 | 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
12 | 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
0 | 0 | /*- |
1 | 1 | * Public platform independent Near Field Communication (NFC) library |
2 | * | |
2 | * | |
3 | 3 | * Copyright (C) 2011, Romuald Conty, Romain Tartière |
4 | * | |
4 | * | |
5 | 5 | * This program is free software: you can redistribute it and/or modify it |
6 | 6 | * under the terms of the GNU Lesser General Public License as published by the |
7 | 7 | * Free Software Foundation, either version 3 of the License, or (at your |
8 | 8 | * option) any later version. |
9 | * | |
9 | * | |
10 | 10 | * This program is distributed in the hope that it will be useful, but WITHOUT |
11 | 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
12 | 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
0 | 0 | /*- |
1 | 1 | * Public platform independent Near Field Communication (NFC) library |
2 | * | |
2 | * | |
3 | 3 | * Copyright (C) 2011, Romuald Conty |
4 | * | |
4 | * | |
5 | 5 | * This program is free software: you can redistribute it and/or modify it |
6 | 6 | * under the terms of the GNU Lesser General Public License as published by the |
7 | 7 | * Free Software Foundation, either version 3 of the License, or (at your |
8 | 8 | * option) any later version. |
9 | * | |
9 | * | |
10 | 10 | * This program is distributed in the hope that it will be useful, but WITHOUT |
11 | 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
12 | 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
24 | 24 | #include <nfc/nfc.h> |
25 | 25 | #include "nfc-internal.h" |
26 | 26 | |
27 | void | |
27 | void | |
28 | 28 | prepare_initiator_data (const nfc_modulation nm, uint8_t **ppbtInitiatorData, size_t * pszInitiatorData) |
29 | 29 | { |
30 | 30 | switch (nm.nmt) { |
0 | 0 | /*- |
1 | 1 | * Public platform independent Near Field Communication (NFC) library |
2 | * | |
2 | * | |
3 | 3 | * Copyright (C) 2011, Romain Tartière, Romuald Conty |
4 | * | |
4 | * | |
5 | 5 | * This program is free software: you can redistribute it and/or modify it |
6 | 6 | * under the terms of the GNU Lesser General Public License as published by the |
7 | 7 | * Free Software Foundation, either version 3 of the License, or (at your |
8 | 8 | * option) any later version. |
9 | * | |
9 | * | |
10 | 10 | * This program is distributed in the hope that it will be useful, but WITHOUT |
11 | 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
12 | 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
53 | 53 | |
54 | 54 | /* |
55 | 55 | * Buffer management macros. |
56 | * | |
56 | * | |
57 | 57 | * The following macros ease setting-up and using buffers: |
58 | 58 | * BUFFER_INIT (data, 5); // data -> [ xx, xx, xx, xx, xx ] |
59 | 59 | * BUFFER_SIZE (data); // size -> 0 |
0 | 0 | /*- |
1 | 1 | * Public platform independent Near Field Communication (NFC) library |
2 | * | |
2 | * | |
3 | 3 | * Copyright (C) 2009, Roel Verdult, Romuald Conty |
4 | 4 | * Copyright (C) 2010, Roel Verdult, Romuald Conty, Romain Tartière |
5 | 5 | * Copyright (C) 2011, Romuald Conty, Romain Tartière |
6 | * | |
6 | * | |
7 | 7 | * This program is free software: you can redistribute it and/or modify it |
8 | 8 | * under the terms of the GNU Lesser General Public License as published by the |
9 | 9 | * Free Software Foundation, either version 3 of the License, or (at your |
10 | 10 | * option) any later version. |
11 | * | |
11 | * | |
12 | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT |
13 | 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
14 | 14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
18 | 18 | * along with this program. If not, see <http://www.gnu.org/licenses/> |
19 | 19 | */ |
20 | 20 | |
21 | /** | |
21 | /** | |
22 | 22 | * @file nfc.c |
23 | 23 | * @brief NFC library implementation |
24 | 24 | */ |
29 | 29 | * must not call any libnfc functions after deinitialization. |
30 | 30 | */ |
31 | 31 | /** |
32 | * @defgroup dev NFC Device/Hardware manipulation | |
32 | * @defgroup dev NFC Device/Hardware manipulation | |
33 | 33 | * The functionality documented below is designed to help with the following |
34 | 34 | * operations: |
35 | 35 | * - Enumerating the NFC devices currently attached to the system |
36 | 36 | * - Opening and closing the chosen device |
37 | */ | |
37 | */ | |
38 | 38 | /** |
39 | 39 | * @defgroup initiator NFC initiator |
40 | 40 | * This page details how to act as "reader". |
41 | */ | |
41 | */ | |
42 | 42 | /** |
43 | 43 | * @defgroup target NFC target |
44 | 44 | * This page details how to act as tag (i.e. MIFARE Classic) or NFC target device. |
45 | */ | |
45 | */ | |
46 | 46 | /** |
47 | 47 | * @defgroup error Error reporting |
48 | 48 | * Most libnfc functions return 0 on success or one of error codes defined on failure. |
49 | */ | |
49 | */ | |
50 | 50 | /** |
51 | 51 | * @defgroup data Special data accessors |
52 | 52 | * The functionnality documented below allow to access to special data as device name or device connstring. |
53 | */ | |
53 | */ | |
54 | 54 | /** |
55 | 55 | * @defgroup properties Properties accessors |
56 | 56 | * The functionnality documented below allow to configure parameters and registers. |
57 | */ | |
57 | */ | |
58 | 58 | /** |
59 | 59 | * @defgroup misc Miscellaneous |
60 | * | |
61 | */ | |
60 | * | |
61 | */ | |
62 | 62 | |
63 | 63 | /* vim:set ts=2 sw=2 et: */ |
64 | 64 | |
127 | 127 | |
128 | 128 | /** @ingroup dev |
129 | 129 | * @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 | |
131 | 131 | * @return \e true on success |
132 | 132 | * |
133 | 133 | * This function fill \e connstring with the LIBNFC_DEFAULT_DEVICE environment variable content |
135 | 135 | * \e connstring with the corresponding \a nfc_connstring value. |
136 | 136 | * |
137 | 137 | * This function returns true when LIBNFC_DEFAULT_DEVICE is set or an available device is found. |
138 | * | |
138 | * | |
139 | 139 | * @note The \e connstring content can be invalid if LIBNFC_DEFAULT_DEVICE is |
140 | 140 | * set with incorrect value. |
141 | 141 | */ |
142 | bool | |
142 | bool | |
143 | 143 | nfc_get_default_device (nfc_connstring *connstring) |
144 | 144 | { |
145 | 145 | char *env_default_connstring = getenv ("LIBNFC_DEFAULT_DEVICE"); |
165 | 165 | * @return Returns pointer to a \a nfc_device struct if successfull; otherwise returns \c NULL value. |
166 | 166 | * |
167 | 167 | * If \e connstring is \c NULL, the \a nfc_get_default_device() function is used. |
168 | * | |
168 | * | |
169 | 169 | * If \e connstring is set, this function will try to claim the right device using information provided by \e connstring. |
170 | 170 | * |
171 | 171 | * When it has successfully claimed a NFC device, memory is allocated to save the device information. |
172 | 172 | * It will return a pointer to a \a nfc_device struct. |
173 | 173 | * This pointer should be supplied by every next functions of libnfc that should perform an action with this device. |
174 | 174 | * |
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(), | |
176 | 176 | * optionally followed by manual tuning of the parameters if the default parameters are not suiting your goals. |
177 | 177 | */ |
178 | 178 | nfc_device * |
190 | 190 | } else { |
191 | 191 | strncpy (ncs, connstring, sizeof (nfc_connstring)); |
192 | 192 | } |
193 | ||
193 | ||
194 | 194 | // Search through the device list for an available device |
195 | 195 | const struct nfc_driver *ndr; |
196 | 196 | const struct nfc_driver **pndr = nfc_drivers; |
197 | 197 | while ((ndr = *pndr)) { |
198 | // Specific device is requested: using device description | |
198 | // Specific device is requested: using device description | |
199 | 199 | if (0 != strncmp (ndr->name, ncs, strlen(ndr->name))) { |
200 | 200 | pndr++; |
201 | 201 | continue; |
208 | 208 | log_fini (); |
209 | 209 | return pnd; |
210 | 210 | } |
211 | ||
211 | ||
212 | 212 | log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "\"%s\" (%s) has been claimed.", pnd->name, pnd->connstring); |
213 | 213 | log_fini (); |
214 | 214 | return pnd; |
232 | 232 | if (pnd) { |
233 | 233 | // Go in idle mode |
234 | 234 | nfc_idle (pnd); |
235 | // Close, clean up and release the device | |
235 | // Close, clean up and release the device | |
236 | 236 | pnd->driver->close (pnd); |
237 | 237 | |
238 | 238 | } |
244 | 244 | * @param context The context to operate on, or NULL for the default context. |
245 | 245 | * @param connstrings array of \a nfc_connstring. |
246 | 246 | * @param szDevices size of the \a connstrings array. |
247 | * | |
247 | * | |
248 | 248 | */ |
249 | 249 | size_t |
250 | 250 | nfc_list_devices (nfc_context *context, nfc_connstring connstrings[] , size_t szDevices) |
281 | 281 | * |
282 | 282 | * @see nfc_property enum values |
283 | 283 | */ |
284 | int | |
284 | int | |
285 | 285 | nfc_device_set_property_int (nfc_device *pnd, const nfc_property property, const int value) |
286 | 286 | { |
287 | 287 | HAL (device_set_property_int, pnd, property, value); |
384 | 384 | * |
385 | 385 | * @param[out] pnt \a nfc_target struct pointer which will filled if available |
386 | 386 | * |
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. | |
388 | 388 | * |
389 | 389 | * The chip needs to know with what kind of tag it is dealing with, therefore |
390 | 390 | * the initial modulation and speed (106, 212 or 424 kbps) should be supplied. |
518 | 518 | * The NFC device will try to find an available D.E.P. target. The standards |
519 | 519 | * (ISO18092 and ECMA-340) describe the modulation that can be used for reader |
520 | 520 | * to passive communications. |
521 | * | |
521 | * | |
522 | 522 | * @note \a nfc_dep_info will be returned when the target was acquired successfully. |
523 | 523 | */ |
524 | 524 | int |
525 | nfc_initiator_select_dep_target (nfc_device *pnd, | |
525 | nfc_initiator_select_dep_target (nfc_device *pnd, | |
526 | 526 | const nfc_dep_mode ndm, const nfc_baud_rate nbr, |
527 | 527 | const nfc_dep_info *pndiInitiator, nfc_target *pnt, const int timeout) |
528 | 528 | { |
543 | 543 | * The NFC device will try to find an available D.E.P. target. The standards |
544 | 544 | * (ISO18092 and ECMA-340) describe the modulation that can be used for reader |
545 | 545 | * to passive communications. |
546 | * | |
546 | * | |
547 | 547 | * @note \a nfc_dep_info will be returned when the target was acquired successfully. |
548 | 548 | */ |
549 | 549 | int |
598 | 598 | * @param[out] pbtRx response from the tags |
599 | 599 | * @param szRx size of \a pbtRx (Will return NFC_EOVFLOW if RX exceeds this size) |
600 | 600 | * @param timeout in milliseconds |
601 | * | |
601 | * | |
602 | 602 | * The NFC device (configured as initiator) will transmit the supplied bytes (\a pbtTx) to the target. |
603 | 603 | * It waits for the response and stores the received bytes in the \a pbtRx byte array. |
604 | 604 | * |
645 | 645 | * explain how it works, if you just are sending two bytes with ISO14443-A |
646 | 646 | * compliant parity bits you better can use the |
647 | 647 | * nfc_initiator_transceive_bytes() function. |
648 | * | |
648 | * | |
649 | 649 | * @param[out] pbtRx response from the tag |
650 | 650 | * @param[out] pbtRxPar parameter contains a byte array of the corresponding parity bits |
651 | 651 | * |
849 | 849 | /** @ingroup target |
850 | 850 | * @brief Receive bytes and APDU frames |
851 | 851 | * @return Returns received bytes count on success, otherwise returns libnfc's error code |
852 | * | |
852 | * | |
853 | 853 | * @param pnd \a nfc_device struct pointer that represent currently used device |
854 | 854 | * @param pbtRx pointer to Rx buffer |
855 | 855 | * @param szRx size of Rx buffer |
927 | 927 | /** @ingroup error |
928 | 928 | * @brief Return the last error string |
929 | 929 | * @return Returns a string |
930 | * | |
930 | * | |
931 | 931 | * @param pnd \a nfc_device struct pointer that represent currently used device |
932 | 932 | */ |
933 | 933 | const char * |
934 | 934 | nfc_strerror (const nfc_device *pnd) |
935 | { | |
935 | { | |
936 | 936 | const char *pcRes = "Unknown error"; |
937 | 937 | size_t i; |
938 | 938 | for (i = 0; i < (sizeof (sErrorMessages) / sizeof (struct sErrorMessage)); i++) { |
948 | 948 | /** @ingroup error |
949 | 949 | * @brief Renders the last error in pcStrErrBuf for a maximum size of szBufLen chars |
950 | 950 | * @return Returns 0 upon success |
951 | * | |
951 | * | |
952 | 952 | * @param pnd \a nfc_device struct pointer that represent currently used device |
953 | 953 | * @param pcStrErrBuf a string that contains the last error. |
954 | 954 | * @param szBufLen size of buffer |
961 | 961 | |
962 | 962 | /** @ingroup error |
963 | 963 | * @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 | |
967 | 967 | */ |
968 | 968 | void |
969 | 969 | nfc_perror (const nfc_device *pnd, const char *pcString) |
974 | 974 | /** @ingroup error |
975 | 975 | * @brief Returns last error occured on a nfc_device |
976 | 976 | * @return Returns an integer that represents to libnfc's error code. |
977 | * | |
977 | * | |
978 | 978 | * @param pnd \a nfc_device struct pointer that represent currently used device |
979 | 979 | */ |
980 | 980 | int |
988 | 988 | /** @ingroup data |
989 | 989 | * @brief Returns the device name |
990 | 990 | * @return Returns a string with the device name |
991 | * | |
991 | * | |
992 | 992 | * @param pnd \a nfc_device struct pointer that represent currently used device |
993 | 993 | */ |
994 | 994 | const char * |
1000 | 1000 | /** @ingroup data |
1001 | 1001 | * @brief Returns the device connection string |
1002 | 1002 | * @return Returns a string with the device connstring |
1003 | * | |
1003 | * | |
1004 | 1004 | * @param pnd \a nfc_device struct pointer that represent currently used device |
1005 | 1005 | */ |
1006 | 1006 | const char * |
1015 | 1015 | * @param pnd \a nfc_device struct pointer that represent currently used device |
1016 | 1016 | * @param mode \a nfc_mode. |
1017 | 1017 | * @param supported_mt pointer of \a nfc_modulation_type array. |
1018 | * | |
1019 | */ | |
1020 | int | |
1018 | * | |
1019 | */ | |
1020 | int | |
1021 | 1021 | nfc_device_get_supported_modulation (nfc_device *pnd, const nfc_mode mode, const nfc_modulation_type **const supported_mt) |
1022 | 1022 | { |
1023 | 1023 | HAL (get_supported_modulation, pnd, mode, supported_mt); |
1029 | 1029 | * @param pnd \a nfc_device struct pointer that represent currently used device |
1030 | 1030 | * @param nmt \a nfc_modulation_type. |
1031 | 1031 | * @param supported_br pointer of \a nfc_baud_rate array. |
1032 | * | |
1033 | */ | |
1034 | int | |
1032 | * | |
1033 | */ | |
1034 | int | |
1035 | 1035 | nfc_device_get_supported_baud_rate (nfc_device *pnd, const nfc_modulation_type nmt, const nfc_baud_rate **const supported_br) |
1036 | 1036 | { |
1037 | 1037 | HAL (get_supported_baud_rate, pnd, nmt, supported_br); |
1042 | 1042 | /** @ingroup misc |
1043 | 1043 | * @brief Returns the library version |
1044 | 1044 | * @return Returns a string with the library version |
1045 | * | |
1045 | * | |
1046 | 1046 | * @param pnd \a nfc_device struct pointer that represent currently used device |
1047 | 1047 | */ |
1048 | 1048 | const char * |
1062 | 1062 | * @param buf string to print information |
1063 | 1063 | * @param buflen buf length |
1064 | 1064 | */ |
1065 | int | |
1065 | int | |
1066 | 1066 | nfc_device_get_information_about (nfc_device *pnd, char *buf, size_t buflen) |
1067 | 1067 | { |
1068 | 1068 | HAL (device_get_information_about, pnd, buf, buflen); |
17 | 17 | int res = 0; |
18 | 18 | |
19 | 19 | nfc_init (NULL); |
20 | ||
20 | ||
21 | 21 | size_t ref_device_count = nfc_list_devices (NULL, connstrings, MAX_DEVICE_COUNT); |
22 | 22 | if (!ref_device_count) |
23 | 23 | cut_omit ("No NFC device found"); |
92 | 92 | const uint8_t abtAttRx[] = "Hello DEP target!"; |
93 | 93 | cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data")); |
94 | 94 | if (res <= 0) { thread_res = -1; return (void*) thread_res; } |
95 | ||
95 | ||
96 | 96 | const uint8_t abtTx[] = "Hello DEP initiator!"; |
97 | 97 | res = nfc_target_send_bytes (device, abtTx, sizeof(abtTx), 500); |
98 | 98 | cut_assert_operator_int (res, >, 0, cut_message ("Can't send bytes to initiator: %s", nfc_strerror (device))); |
120 | 120 | |
121 | 121 | nfc_target nt; |
122 | 122 | |
123 | // Active mode | |
123 | // Active mode | |
124 | 124 | printf ("=========== INITIATOR %s (Active mode / %s Kbps) =========\n", nfc_device_get_name (device), str_nfc_baud_rate(nbr)); |
125 | 125 | res = nfc_initiator_select_dep_target (device, NDM_ACTIVE, nbr, NULL, &nt, 1000); |
126 | 126 | cut_assert_operator_int (res, >, 0, cut_message ("Can't select any DEP target: %s", nfc_strerror (device))); |
158 | 158 | .device = devices[TARGET], |
159 | 159 | .cut_test_context = test_context, |
160 | 160 | }; |
161 | ||
161 | ||
162 | 162 | struct thread_data initiator_data = { |
163 | 163 | .device = devices[INITIATOR], |
164 | 164 | .cut_test_context = test_context, |
165 | 165 | }; |
166 | ||
166 | ||
167 | 167 | for (int i = 0; i < 3; i++) { |
168 | 168 | initiator_data.nbr = nbrs[i]; |
169 | ||
169 | ||
170 | 170 | if ((res = pthread_create (&(threads[TARGET]), NULL, target_thread, &target_data))) |
171 | 171 | cut_fail ("pthread_create() returned %d", res); |
172 | 172 | if ((res = pthread_create (&(threads[INITIATOR]), NULL, initiator_thread, &initiator_data))) |
180 | 180 | cut_assert_equal_int (0, result[INITIATOR], cut_message ("Unexpected initiator return code")); |
181 | 181 | cut_assert_equal_int (0, result[TARGET], cut_message ("Unexpected target return code")); |
182 | 182 | } |
183 | ||
183 | ||
184 | 184 | } |
29 | 29 | if (n < 2) { |
30 | 30 | cut_omit ("At least two NFC devices must be plugged-in to run this test"); |
31 | 31 | } |
32 | ||
32 | ||
33 | 33 | nfc_init (NULL); |
34 | 34 | devices[TARGET] = nfc_open (NULL, connstrings[TARGET]); |
35 | 35 | devices[INITIATOR] = nfc_open (NULL, connstrings[INITIATOR]); |
89 | 89 | res = nfc_target_receive_bytes (device, abtRx, sizeof (abtRx), 500); |
90 | 90 | cut_assert_operator_int (res, >, 0, cut_message ("Can't receive bytes from initiator: %s", nfc_strerror (device))); |
91 | 91 | szRx = (size_t) res; |
92 | ||
92 | ||
93 | 93 | const uint8_t abtAttRx[] = "Hello DEP target!"; |
94 | 94 | cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data")); |
95 | 95 | if (res <= 0) { thread_res = -1; return (void*) thread_res; } |
96 | ||
96 | ||
97 | 97 | const uint8_t abtTx[] = "Hello DEP initiator!"; |
98 | 98 | res = nfc_target_send_bytes (device, abtTx, sizeof(abtTx), 500); |
99 | 99 | cut_assert_operator_int (res, >, 0, cut_message ("Can't send bytes to initiator: %s", nfc_strerror (device))); |
106 | 106 | |
107 | 107 | cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data")); |
108 | 108 | if (res <= 0) { thread_res = -1; return (void*) thread_res; } |
109 | ||
109 | ||
110 | 110 | res = nfc_target_send_bytes (device, abtTx, sizeof(abtTx), 500); |
111 | 111 | cut_assert_operator_int (res, >, 0, cut_message ("Can't send bytes to initiator: %s", nfc_strerror (device))); |
112 | 112 | if (res <= 0) { thread_res = -1; return (void*) thread_res; } |
118 | 118 | |
119 | 119 | cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data")); |
120 | 120 | 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 | ||
126 | 126 | // Fourth pass |
127 | 127 | res = nfc_target_receive_bytes (device, abtRx, sizeof (abtRx), 500); |
128 | 128 | cut_assert_operator_int (res, >, 0, cut_message ("Can't receive bytes from initiator: %s", nfc_strerror (device))); |
130 | 130 | |
131 | 131 | cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data")); |
132 | 132 | if (res <= 0) { thread_res = -1; return (void*) thread_res; } |
133 | ||
133 | ||
134 | 134 | res = nfc_target_send_bytes (device, abtTx, sizeof(abtTx), 500); |
135 | 135 | cut_assert_operator_int (res, >, 0, cut_message ("Can't send bytes to initiator: %s", nfc_strerror (device))); |
136 | 136 | if (res <= 0) { thread_res = -1; return (void*) thread_res; } |
225 | 225 | res = nfc_initiator_deselect_target (device); |
226 | 226 | cut_assert_operator_int (res, >=, 0, cut_message ("Can't deselect target: %s", nfc_strerror (device))); |
227 | 227 | if (res < 0) { thread_res = -1; return (void*) thread_res; } |
228 | ||
228 | ||
229 | 229 | // Passive mode / 424Kbps |
230 | 230 | printf ("=========== INITIATOR %s (Passive mode / 424Kbps) =========\n", nfc_device_get_name (device)); |
231 | 231 | res = nfc_initiator_select_dep_target (device, NDM_PASSIVE, NBR_424, NULL, &nt, 1000); |
56 | 56 | cut_set_current_test_context (((struct thread_data *) arg)->cut_test_context); |
57 | 57 | |
58 | 58 | printf ("=========== TARGET %s =========\n", nfc_device_get_name (device)); |
59 | nfc_target nt; | |
59 | nfc_target nt; | |
60 | 60 | |
61 | 61 | uint8_t abtRx[1024]; |
62 | 62 | size_t szRx = sizeof (abtRx); |
65 | 65 | int res = nfc_target_init (device, &nt, abtRx, szRx, 500); |
66 | 66 | cut_assert_operator_int (res, >=, 0, cut_message ("Can't initialize NFC device as target: %s", nfc_strerror (device))); |
67 | 67 | if (res < 0) { thread_res = -1; return (void*) thread_res; } |
68 | ||
68 | ||
69 | 69 | // 2) act as target |
70 | 70 | nfc_target nt1 = { |
71 | 71 | .nm = { |
95 | 95 | res = nfc_target_receive_bytes (device, abtRx, sizeof (abtRx), 500); |
96 | 96 | cut_assert_operator_int (res, >, 0, cut_message ("Can't receive bytes from initiator: %s", nfc_strerror (device))); |
97 | 97 | szRx = (size_t) res; |
98 | ||
98 | ||
99 | 99 | const uint8_t abtAttRx[] = "Hello DEP target!"; |
100 | 100 | cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data")); |
101 | 101 | if (res <= 0) { thread_res = -1; return (void*) thread_res; } |
102 | ||
102 | ||
103 | 103 | const uint8_t abtTx[] = "Hello DEP initiator!"; |
104 | 104 | res = nfc_target_send_bytes (device, abtTx, sizeof(abtTx), 500); |
105 | 105 | cut_assert_operator_int (res, >, 0, cut_message ("Can't send bytes to initiator: %s", nfc_strerror (device))); |
129 | 129 | cut_assert_equal_int (0, res, cut_message ("Can't initialize NFC device as initiator: %s", nfc_strerror (device))); |
130 | 130 | if (res < 0) { thread_res = -1; return (void*) thread_res; } |
131 | 131 | |
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 | |
133 | 133 | nfc_target nt; |
134 | 134 | res = nfc_initiator_poll_dep_target (device, NDM_PASSIVE, NBR_106, NULL, &nt, 1000); |
135 | 135 | cut_assert_equal_int (0, res, cut_message ("Problem with nfc_idle")); |
136 | 136 | if (res != 0) { thread_res = -1; return (void*) thread_res; } |
137 | 137 | |
138 | ||
138 | ||
139 | 139 | // 2 As other device should be in target mode, nfc_initiator_poll_dep_target should be positive. |
140 | 140 | nfc_target nt1; |
141 | 141 | |
164 | 164 | cut_assert_operator_int (res, >=, 0, cut_message ("Can't deselect target: %s", nfc_strerror (device))); |
165 | 165 | if (res < 0) { thread_res = -1; return (void*) thread_res; } |
166 | 166 | |
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 | |
168 | 168 | nfc_target nt2; |
169 | 169 | res = nfc_initiator_poll_dep_target (device, NDM_PASSIVE, NBR_106, NULL, &nt2, 1000); |
170 | 170 | cut_assert_equal_int (0, res, cut_message ("Problem with nfc_idle")); |
171 | 171 | if (res != 0) { thread_res = -1; return (void*) thread_res; } |
172 | ||
172 | ||
173 | 173 | return (void *) thread_res; |
174 | 174 | } |
175 | 175 | |
183 | 183 | .device = first_device, |
184 | 184 | .cut_test_context = test_context, |
185 | 185 | }; |
186 | ||
186 | ||
187 | 187 | struct thread_data initiator_data = { |
188 | 188 | .device = second_device, |
189 | 189 | .cut_test_context = test_context, |
190 | 190 | }; |
191 | ||
191 | ||
192 | 192 | for (int i = 0; i < 2; i++) { |
193 | 193 | if ((res = pthread_create (&(threads[1]), NULL, target_thread, &target_data))) |
194 | 194 | cut_fail ("pthread_create() returned %d", res); |
203 | 203 | |
204 | 204 | cut_assert_equal_int (0, result[0], cut_message ("Unexpected initiator return code")); |
205 | 205 | cut_assert_equal_int (0, result[1], cut_message ("Unexpected target return code")); |
206 | ||
206 | ||
207 | 207 | // initiator --> target, target --> initiator |
208 | 208 | target_data.device = second_device; |
209 | 209 | initiator_data.device = first_device; |
10 | 10 | { |
11 | 11 | nfc_connstring connstrings[MAX_DEVICE_COUNT]; |
12 | 12 | int res = 0; |
13 | ||
13 | ||
14 | 14 | nfc_init (NULL); |
15 | 15 | |
16 | 16 | size_t device_count = nfc_list_devices (NULL, connstrings, MAX_DEVICE_COUNT); |
11 | 11 | { |
12 | 12 | nfc_connstring connstrings[MAX_DEVICE_COUNT]; |
13 | 13 | int res = 0; |
14 | ||
14 | ||
15 | 15 | nfc_init (NULL); |
16 | 16 | |
17 | 17 | size_t device_count = nfc_list_devices (NULL, connstrings, MAX_DEVICE_COUNT); |
0 | 0 | /*- |
1 | 1 | * Public platform independent Near Field Communication (NFC) library examples |
2 | * | |
2 | * | |
3 | 3 | * Copyright (C) 2009, Roel Verdult |
4 | 4 | * Copyright (C) 2010, Romuald Conty, Romain Tartière |
5 | * | |
5 | * | |
6 | 6 | * Redistribution and use in source and binary forms, with or without |
7 | 7 | * modification, are permitted provided that the following conditions are met: |
8 | 8 | * 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. | |
10 | 10 | * 2 )Redistributions in binary form must reproduce the above copyright |
11 | 11 | * notice, this list of conditions and the following disclaimer in the |
12 | 12 | * documentation and/or other materials provided with the distribution. |
22 | 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
23 | 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
24 | 24 | * POSSIBILITY OF SUCH DAMAGE. |
25 | * | |
25 | * | |
26 | 26 | * Note that this license only applies on the examples, NFC library itself is under LGPL |
27 | 27 | * |
28 | 28 | */ |
44 | 44 | * The specified MIFARE command will be executed on the tag. There are different commands possible, they all require the destination block number. |
45 | 45 | * @note There are three different types of information (Authenticate, Data and Value). |
46 | 46 | * |
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. | |
48 | 48 | * 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). | |
50 | 50 | * The MIFARE Classic Specification (http://www.nxp.com/acrobat/other/identification/M001053_MF1ICS50_rev5_3.pdf) explains more about this process. |
51 | 51 | */ |
52 | 52 | bool |
0 | 0 | /*- |
1 | 1 | * Public platform independent Near Field Communication (NFC) library examples |
2 | * | |
2 | * | |
3 | 3 | * Copyright (C) 2009, Roel Verdult |
4 | 4 | * Copyright (C) 2010, Romuald Conty, Romain Tartière |
5 | * | |
5 | * | |
6 | 6 | * Redistribution and use in source and binary forms, with or without |
7 | 7 | * modification, are permitted provided that the following conditions are met: |
8 | 8 | * 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. | |
10 | 10 | * 2 )Redistributions in binary form must reproduce the above copyright |
11 | 11 | * notice, this list of conditions and the following disclaimer in the |
12 | 12 | * documentation and/or other materials provided with the distribution. |
22 | 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
23 | 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
24 | 24 | * POSSIBILITY OF SUCH DAMAGE. |
25 | * | |
25 | * | |
26 | 26 | * Note that this license only applies on the examples, NFC library itself is under LGPL |
27 | 27 | * |
28 | 28 | */ |
0 | 0 | /*- |
1 | 1 | * Public platform independent Near Field Communication (NFC) library examples |
2 | * | |
2 | * | |
3 | 3 | * Copyright (C) 2010, Roel Verdult, Romuald Conty |
4 | 4 | * Copyright (C) 2011, Romain Tartière, Romuald Conty |
5 | * | |
5 | * | |
6 | 6 | * Redistribution and use in source and binary forms, with or without |
7 | 7 | * modification, are permitted provided that the following conditions are met: |
8 | 8 | * 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. | |
10 | 10 | * 2 )Redistributions in binary form must reproduce the above copyright |
11 | 11 | * notice, this list of conditions and the following disclaimer in the |
12 | 12 | * documentation and/or other materials provided with the distribution. |
22 | 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
23 | 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
24 | 24 | * POSSIBILITY OF SUCH DAMAGE. |
25 | * | |
25 | * | |
26 | 26 | * Note that this license only applies on the examples, NFC library itself is under LGPL |
27 | 27 | * |
28 | 28 | */ |
90 | 90 | 0x00, 0x0F, /* CCLEN 15 bytes */ |
91 | 91 | 0x20, /* Mapping version 2.0, use option -1 to force v1.0 */ |
92 | 92 | 0x00, 0x54, /* MLe Maximum R-ADPU data size */ |
93 | // Notes: | |
93 | // Notes: | |
94 | 94 | // - I (Romuald) don't know why Nokia 6212 Classic refuses the NDEF message if MLe is more than 0xFD (any suggests are welcome); |
95 | 95 | // - 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. |
96 | 96 | // - I (Romuald) don't know why ARYGON device doesn't ACK when MLe > 0x54 (ARYGON frame length = 0xC2 (192 bytes)) |
363 | 363 | err (EXIT_FAILURE, "Can't load NDEF file '%s'", argv[1 + options]); |
364 | 364 | } |
365 | 365 | } |
366 | ||
366 | ||
367 | 367 | nfc_init (NULL); |
368 | 368 | |
369 | 369 | // Try to open the NFC reader |
390 | 390 | err (EXIT_FAILURE, "Can't save NDEF file '%s'", argv[2 + options]); |
391 | 391 | } |
392 | 392 | } |
393 | ||
393 | ||
394 | 394 | nfc_exit (NULL); |
395 | 395 | exit (EXIT_SUCCESS); |
396 | 396 | } |
0 | 0 | /*- |
1 | 1 | * Public platform independent Near Field Communication (NFC) library examples |
2 | * | |
2 | * | |
3 | 3 | * Copyright (C) 2009, Roel Verdult |
4 | 4 | * Copyright (C) 2010, Romuald Conty, Romain Tartière |
5 | * | |
5 | * | |
6 | 6 | * Redistribution and use in source and binary forms, with or without |
7 | 7 | * modification, are permitted provided that the following conditions are met: |
8 | 8 | * 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. | |
10 | 10 | * 2 )Redistributions in binary form must reproduce the above copyright |
11 | 11 | * notice, this list of conditions and the following disclaimer in the |
12 | 12 | * documentation and/or other materials provided with the distribution. |
22 | 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
23 | 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
24 | 24 | * POSSIBILITY OF SUCH DAMAGE. |
25 | * | |
25 | * | |
26 | 26 | * Note that this license only applies on the examples, NFC library itself is under LGPL |
27 | 27 | * |
28 | 28 | */ |
74 | 74 | int res = 0; |
75 | 75 | |
76 | 76 | nfc_init (NULL); |
77 | ||
77 | ||
78 | 78 | // Display libnfc version |
79 | 79 | acLibnfcVersion = nfc_version (); |
80 | 80 | printf ("%s uses libnfc %s\n", argv[0], acLibnfcVersion); |
131 | 131 | } |
132 | 132 | if (nfc_initiator_init (pnd) < 0) { |
133 | 133 | nfc_perror (pnd, "nfc_initiator_init"); |
134 | exit (EXIT_FAILURE); | |
134 | exit (EXIT_FAILURE); | |
135 | 135 | } |
136 | 136 | |
137 | 137 | printf ("NFC device: %s opened\n", nfc_device_get_name (pnd)); |
0 | 0 | /*- |
1 | 1 | * Public platform independent Near Field Communication (NFC) library examples |
2 | * | |
2 | * | |
3 | 3 | * Copyright (C) 2009, Roel Verdult |
4 | 4 | * Copyright (C) 2010, Romuald Conty, Romain Tartière |
5 | 5 | * Copyright (C) 2011, Adam Laurie |
6 | * | |
6 | * | |
7 | 7 | * Redistribution and use in source and binary forms, with or without |
8 | 8 | * modification, are permitted provided that the following conditions are met: |
9 | 9 | * 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. | |
11 | 11 | * 2 )Redistributions in binary form must reproduce the above copyright |
12 | 12 | * notice, this list of conditions and the following disclaimer in the |
13 | 13 | * documentation and/or other materials provided with the distribution. |
23 | 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
24 | 24 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
25 | 25 | * POSSIBILITY OF SUCH DAMAGE. |
26 | * | |
26 | * | |
27 | 27 | * Note that this license only applies on the examples, NFC library itself is under LGPL |
28 | 28 | * |
29 | 29 | */ |
507 | 507 | // printf("Successfully opened required files\n"); |
508 | 508 | |
509 | 509 | nfc_init (NULL); |
510 | ||
510 | ||
511 | 511 | // Try to open the NFC reader |
512 | 512 | pnd = nfc_open (NULL, NULL); |
513 | 513 | if (pnd == NULL) { |
517 | 517 | |
518 | 518 | if (nfc_initiator_init (pnd) < 0) { |
519 | 519 | nfc_perror (pnd, "nfc_initiator_init"); |
520 | exit (EXIT_FAILURE); | |
520 | exit (EXIT_FAILURE); | |
521 | 521 | }; |
522 | 522 | |
523 | 523 | // Let the reader only try once to find a tag |
593 | 593 | nfc_close (pnd); |
594 | 594 | break; |
595 | 595 | }; |
596 | ||
596 | ||
597 | 597 | nfc_exit (NULL); |
598 | 598 | exit (EXIT_SUCCESS); |
599 | 599 | } |
0 | 0 | /*- |
1 | 1 | * Public platform independent Near Field Communication (NFC) library examples |
2 | * | |
2 | * | |
3 | 3 | * Copyright (C) 2009, Roel Verdult |
4 | 4 | * Copyright (C) 2010, Romuald Conty |
5 | * | |
5 | * | |
6 | 6 | * Redistribution and use in source and binary forms, with or without |
7 | 7 | * modification, are permitted provided that the following conditions are met: |
8 | 8 | * 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. | |
10 | 10 | * 2 )Redistributions in binary form must reproduce the above copyright |
11 | 11 | * notice, this list of conditions and the following disclaimer in the |
12 | 12 | * documentation and/or other materials provided with the distribution. |
22 | 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
23 | 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
24 | 24 | * POSSIBILITY OF SUCH DAMAGE. |
25 | * | |
25 | * | |
26 | 26 | * Note that this license only applies on the examples, NFC library itself is under LGPL |
27 | 27 | * |
28 | 28 | */ |
148 | 148 | bFailure = false; |
149 | 149 | } |
150 | 150 | // 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 | |
152 | 152 | // page (4 bytes). The Ultralight-specific Write command only |
153 | 153 | // writes one page at a time. |
154 | 154 | uiBlock = page / 4; |
204 | 204 | DBG ("Successfully opened the dump file\n"); |
205 | 205 | |
206 | 206 | nfc_init (NULL); |
207 | ||
207 | ||
208 | 208 | // Try to open the NFC device |
209 | 209 | pnd = nfc_open (NULL, NULL); |
210 | 210 | if (pnd == NULL) { |
214 | 214 | |
215 | 215 | if (nfc_initiator_init (pnd) < 0) { |
216 | 216 | nfc_perror (pnd, "nfc_initiator_init"); |
217 | exit (EXIT_FAILURE); | |
217 | exit (EXIT_FAILURE); | |
218 | 218 | } |
219 | 219 | |
220 | 220 | // Let the device only try once to find a tag |
0 | 0 | /*- |
1 | 1 | * Public platform independent Near Field Communication (NFC) library examples |
2 | * | |
2 | * | |
3 | 3 | * Copyright (C) 2009, Roel Verdult |
4 | 4 | * Copyright (C) 2010, Romuald Conty, Romain Tartière |
5 | 5 | * Copyright (C) 2011-2012, Romuald Conty |
6 | * | |
6 | * | |
7 | 7 | * Redistribution and use in source and binary forms, with or without |
8 | 8 | * modification, are permitted provided that the following conditions are met: |
9 | 9 | * 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. | |
11 | 11 | * 2 )Redistributions in binary form must reproduce the above copyright |
12 | 12 | * notice, this list of conditions and the following disclaimer in the |
13 | 13 | * documentation and/or other materials provided with the distribution. |
23 | 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
24 | 24 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
25 | 25 | * POSSIBILITY OF SUCH DAMAGE. |
26 | * | |
26 | * | |
27 | 27 | * Note that this license only applies on the examples, NFC library itself is under LGPL |
28 | 28 | * |
29 | 29 | */ |
74 | 74 | bool verbose = false; |
75 | 75 | |
76 | 76 | nfc_init (NULL); |
77 | ||
77 | ||
78 | 78 | // Display libnfc version |
79 | 79 | acLibnfcVersion = nfc_version (); |
80 | 80 | printf ("%s uses libnfc %s\n", argv[0], acLibnfcVersion); |
0 | 0 | /*- |
1 | 1 | * Public platform independent Near Field Communication (NFC) library examples |
2 | * | |
2 | * | |
3 | 3 | * Copyright (C) 2011, Romuald Conty |
4 | * | |
4 | * | |
5 | 5 | * Redistribution and use in source and binary forms, with or without |
6 | 6 | * modification, are permitted provided that the following conditions are met: |
7 | 7 | * 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. | |
9 | 9 | * 2 )Redistributions in binary form must reproduce the above copyright |
10 | 10 | * notice, this list of conditions and the following disclaimer in the |
11 | 11 | * documentation and/or other materials provided with the distribution. |
21 | 21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
22 | 22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
23 | 23 | * POSSIBILITY OF SUCH DAMAGE. |
24 | * | |
24 | * | |
25 | 25 | * Note that this license only applies on the examples, NFC library itself is under LGPL |
26 | 26 | * |
27 | 27 | */ |
84 | 84 | } |
85 | 85 | |
86 | 86 | #define CHECK 0x06 |
87 | static int | |
87 | static int | |
88 | 88 | 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) |
89 | 89 | { |
90 | 90 | uint8_t payload[1024] = { |
93 | 93 | block_count, |
94 | 94 | 0x80, block, // block 0 |
95 | 95 | }; |
96 | ||
96 | ||
97 | 97 | size_t payload_len = 1 + 2 + 1; |
98 | 98 | for (uint8_t b = 0; b < block_count; b++) { |
99 | 99 | if (block < 0x100) { |
103 | 103 | payload[payload_len++] = 0x00; |
104 | 104 | payload[payload_len++] = (block + b) >> 8; |
105 | 105 | payload[payload_len++] = (block + b) & 0xff; |
106 | } | |
106 | } | |
107 | 107 | } |
108 | 108 | |
109 | 109 | uint8_t frame[1024]; |
116 | 116 | return res; |
117 | 117 | } |
118 | 118 | 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) { | |
120 | 120 | // Not enough data |
121 | 121 | return -1; |
122 | 122 | } |
153 | 153 | (void)argv; |
154 | 154 | |
155 | 155 | 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 | ||
194 | 194 | nfc_init (NULL); |
195 | 195 | |
196 | 196 | pnd = nfc_open (NULL, NULL); |
213 | 213 | |
214 | 214 | if (nfc_initiator_init (pnd) < 0) { |
215 | 215 | nfc_perror (pnd, "nfc_initiator_init"); |
216 | exit (EXIT_FAILURE); | |
216 | exit (EXIT_FAILURE); | |
217 | 217 | } |
218 | 218 | fprintf (message_stream, "Place your NFC Forum Tag Type 3 in the field...\n"); |
219 | 219 | |
226 | 226 | goto error; |
227 | 227 | } |
228 | 228 | |
229 | // Check if System Code equals 0x12fc | |
229 | // Check if System Code equals 0x12fc | |
230 | 230 | const uint8_t abtNfcForumSysCode[] = { 0x12, 0xfc }; |
231 | 231 | if (0 != memcmp (nt.nti.nfi.abtSysCode, abtNfcForumSysCode, 2)) { |
232 | 232 | // Retry with special polling |
236 | 236 | error = EXIT_FAILURE; |
237 | 237 | goto error; |
238 | 238 | } |
239 | // Check again if System Code equals 0x12fc | |
239 | // Check again if System Code equals 0x12fc | |
240 | 240 | if (0 != memcmp (nt.nti.nfi.abtSysCode, abtNfcForumSysCode, 2)) { |
241 | 241 | fprintf (stderr, "Tag is not NFC Forum Tag Type 3 compliant.\n"); |
242 | 242 | error = EXIT_FAILURE; |
0 | 0 | /*- |
1 | 1 | * Public platform independent Near Field Communication (NFC) library examples |
2 | * | |
2 | * | |
3 | 3 | * Copyright (C) 2010, Romuald Conty |
4 | * | |
4 | * | |
5 | 5 | * Redistribution and use in source and binary forms, with or without |
6 | 6 | * modification, are permitted provided that the following conditions are met: |
7 | 7 | * 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. | |
9 | 9 | * 2 )Redistributions in binary form must reproduce the above copyright |
10 | 10 | * notice, this list of conditions and the following disclaimer in the |
11 | 11 | * documentation and/or other materials provided with the distribution. |
21 | 21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
22 | 22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
23 | 23 | * POSSIBILITY OF SUCH DAMAGE. |
24 | * | |
24 | * | |
25 | 25 | * Note that this license only applies on the examples, NFC library itself is under LGPL |
26 | 26 | * |
27 | 27 | */ |
191 | 191 | #endif |
192 | 192 | |
193 | 193 | nfc_init (NULL); |
194 | ||
194 | ||
195 | 195 | nfc_connstring connstrings[MAX_DEVICE_COUNT]; |
196 | 196 | // List available devices |
197 | 197 | size_t szFound = nfc_list_devices (NULL, connstrings, MAX_DEVICE_COUNT); |
276 | 276 | nfc_exit (NULL); |
277 | 277 | exit(EXIT_FAILURE); |
278 | 278 | } |
279 | } | |
279 | } | |
280 | 280 | } |
281 | 281 | if (initiator_only_mode) { |
282 | 282 | printf ("Hint: tag <---> *INITIATOR* (relay) <-FD3/FD4-> target (relay) <---> original reader\n\n"); |
351 | 351 | |
352 | 352 | printf("We will emulate:\n"); |
353 | 353 | print_nfc_iso14443a_info (ntEmulatedTarget.nti.nai, false); |
354 | ||
354 | ||
355 | 355 | // Try to open the NFC emulator device |
356 | 356 | pndTarget = nfc_open (NULL, connstrings[0]); |
357 | 357 | if (pndTarget == NULL) { |
0 | 0 | /*- |
1 | 1 | * Public platform independent Near Field Communication (NFC) library examples |
2 | * | |
2 | * | |
3 | 3 | * Copyright (C) 2009, Roel Verdult |
4 | 4 | * Copyright (C) 2010, Romuald Conty, Romain Tartière |
5 | * | |
5 | * | |
6 | 6 | * Redistribution and use in source and binary forms, with or without |
7 | 7 | * modification, are permitted provided that the following conditions are met: |
8 | 8 | * 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. | |
10 | 10 | * 2 )Redistributions in binary form must reproduce the above copyright |
11 | 11 | * notice, this list of conditions and the following disclaimer in the |
12 | 12 | * documentation and/or other materials provided with the distribution. |
22 | 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
23 | 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
24 | 24 | * POSSIBILITY OF SUCH DAMAGE. |
25 | * | |
25 | * | |
26 | 26 | * Note that this license only applies on the examples, NFC library itself is under LGPL |
27 | 27 | * |
28 | 28 | */ |
0 | 0 | /*- |
1 | 1 | * Public platform independent Near Field Communication (NFC) library examples |
2 | * | |
2 | * | |
3 | 3 | * Copyright (C) 2009, Roel Verdult |
4 | 4 | * Copyright (C) 2010, Romuald Conty, Romain Tartière |
5 | * | |
5 | * | |
6 | 6 | * Redistribution and use in source and binary forms, with or without |
7 | 7 | * modification, are permitted provided that the following conditions are met: |
8 | 8 | * 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. | |
10 | 10 | * 2 )Redistributions in binary form must reproduce the above copyright |
11 | 11 | * notice, this list of conditions and the following disclaimer in the |
12 | 12 | * documentation and/or other materials provided with the distribution. |
22 | 22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
23 | 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
24 | 24 | * POSSIBILITY OF SUCH DAMAGE. |
25 | * | |
25 | * | |
26 | 26 | * Note that this license only applies on the examples, NFC library itself is under LGPL |
27 | 27 | * |
28 | 28 | */ |
6 | 6 | * |
7 | 7 | */ |
8 | 8 | |
9 | /* | |
9 | /* | |
10 | 10 | * $Id: usb.h 1220 2010-05-04 03:14:56Z roger.brown $ |
11 | 11 | */ |
12 | 12 | |
17 | 17 | #include <stdlib.h> |
18 | 18 | #include <windows.h> |
19 | 19 | |
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 | |
22 | 22 | * is deleted here to avoid conflicts and compile errors. |
23 | 23 | */ |
24 | 24 | |
28 | 28 | |
29 | 29 | /* |
30 | 30 | * 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 | |
32 | 32 | */ |
33 | 33 | |
34 | 34 | #define LIBUSB_PATH_MAX 512 |
80 | 80 | |
81 | 81 | |
82 | 82 | /* ensure byte-packed structures */ |
83 | #include <pshpack1.h> | |
83 | #include <pshpack1.h> | |
84 | 84 | |
85 | 85 | |
86 | 86 | /* All standard descriptors have these 2 fields in common */ |
338 | 338 | int usb_interrupt_read(usb_dev_handle *dev, int ep, char *bytes, int size, |
339 | 339 | int timeout); |
340 | 340 | 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, | |
342 | 342 | int timeout); |
343 | 343 | int usb_set_configuration(usb_dev_handle *dev, int configuration); |
344 | 344 | int usb_claim_interface(usb_dev_handle *dev, int interface); |
364 | 364 | int usb_install_service_np(void); |
365 | 365 | void CALLBACK usb_install_service_np_rundll(HWND wnd, HINSTANCE instance, |
366 | 366 | LPSTR cmd_line, int cmd_show); |
367 | ||
367 | ||
368 | 368 | #define LIBUSB_HAS_UNINSTALL_SERVICE_NP 1 |
369 | 369 | int usb_uninstall_service_np(void); |
370 | 370 | void CALLBACK usb_uninstall_service_np_rundll(HWND wnd, HINSTANCE instance, |