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