You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

nfc-utils.h 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. /**
  36. * @file nfc-utils.h
  37. * @brief Provide some examples shared functions like print, parity calculation, options parsing.
  38. */
  39. #ifndef _EXAMPLES_NFC_UTILS_H_
  40. # define _EXAMPLES_NFC_UTILS_H_
  41. # include <stdlib.h>
  42. # include <string.h>
  43. # include <err.h>
  44. /**
  45. * @macro DBG
  46. * @brief Print a message of standard output only in DEBUG mode
  47. */
  48. #ifdef DEBUG
  49. # define DBG(...) do { \
  50. warnx ("DBG %s:%d", __FILE__, __LINE__); \
  51. warnx (" " __VA_ARGS__ ); \
  52. } while (0)
  53. #else
  54. # define DBG(...) {}
  55. #endif
  56. /**
  57. * @macro WARN
  58. * @brief Print a warn message
  59. */
  60. #ifdef DEBUG
  61. # define WARN(...) do { \
  62. warnx ("WARNING %s:%d", __FILE__, __LINE__); \
  63. warnx (" " __VA_ARGS__ ); \
  64. } while (0)
  65. #else
  66. # define WARN(...) warnx ("WARNING: " __VA_ARGS__ )
  67. #endif
  68. /**
  69. * @macro ERR
  70. * @brief Print a error message
  71. */
  72. #ifdef DEBUG
  73. # define ERR(...) do { \
  74. warnx ("ERROR %s:%d", __FILE__, __LINE__); \
  75. warnx (" " __VA_ARGS__ ); \
  76. } while (0)
  77. #else
  78. # define ERR(...) warnx ("ERROR: " __VA_ARGS__ )
  79. #endif
  80. #ifndef MIN
  81. #define MIN(a,b) (((a) < (b)) ? (a) : (b))
  82. #endif
  83. #ifndef MAX
  84. #define MAX(a,b) (((a) > (b)) ? (a) : (b))
  85. #endif
  86. uint8_t oddparity(const uint8_t bt);
  87. void oddparity_bytes_ts(const uint8_t *pbtData, const size_t szLen, uint8_t *pbtPar);
  88. void print_hex(const uint8_t *pbtData, const size_t szLen);
  89. void print_hex_bits(const uint8_t *pbtData, const size_t szBits);
  90. void print_hex_par(const uint8_t *pbtData, const size_t szBits, const uint8_t *pbtDataPar);
  91. void print_nfc_target(const nfc_target *pnt, bool verbose);
  92. #endif