libnfc 1.8.0
nfc-utils.h
Go to the documentation of this file.
1/*-
2 * Free/Libre Near Field Communication (NFC) library
3 *
4 * Libnfc historical contributors:
5 * Copyright (C) 2009 Roel Verdult
6 * Copyright (C) 2009-2013 Romuald Conty
7 * Copyright (C) 2010-2012 Romain Tartière
8 * Copyright (C) 2010-2013 Philippe Teuwen
9 * Copyright (C) 2012-2013 Ludovic Rousseau
10 * See AUTHORS file for a more comprehensive list of contributors.
11 * Additional contributors of this file:
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions are met:
15 * 1) Redistributions of source code must retain the above copyright notice,
16 * this list of conditions and the following disclaimer.
17 * 2 )Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 *
33 * Note that this license only applies on the examples, NFC library itself is under LGPL
34 *
35 */
36
42#ifndef _EXAMPLES_NFC_UTILS_H_
43# define _EXAMPLES_NFC_UTILS_H_
44
45# include <stdlib.h>
46# include <string.h>
47# include <err.h>
48
53#ifdef DEBUG
54# define DBG(...) do { \
55 warnx ("DBG %s:%d", __FILE__, __LINE__); \
56 warnx (" " __VA_ARGS__ ); \
57 } while (0)
58#else
59# define DBG(...) {}
60#endif
61
66#ifdef DEBUG
67# define WARN(...) do { \
68 warnx ("WARNING %s:%d", __FILE__, __LINE__); \
69 warnx (" " __VA_ARGS__ ); \
70 } while (0)
71#else
72# define WARN(...) warnx ("WARNING: " __VA_ARGS__ )
73#endif
74
79#ifdef DEBUG
80# define ERR(...) do { \
81 warnx ("ERROR %s:%d", __FILE__, __LINE__); \
82 warnx (" " __VA_ARGS__ ); \
83 } while (0)
84#else
85# define ERR(...) warnx ("ERROR: " __VA_ARGS__ )
86#endif
87
88#ifndef MIN
89#define MIN(a,b) (((a) < (b)) ? (a) : (b))
90#endif
91#ifndef MAX
92#define MAX(a,b) (((a) > (b)) ? (a) : (b))
93#endif
94
95uint8_t oddparity(const uint8_t bt);
96void oddparity_bytes_ts(const uint8_t *pbtData, const size_t szLen, uint8_t *pbtPar);
97
98void print_hex(const uint8_t *pbtData, const size_t szLen);
99void print_hex_bits(const uint8_t *pbtData, const size_t szBits);
100void print_hex_par(const uint8_t *pbtData, const size_t szBits, const uint8_t *pbtDataPar);
101
102void print_nfc_target(const nfc_target *pnt, bool verbose);
103
104#endif
NFC target structure.
Definition: nfc-types.h:351