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.

MainClass.cpp 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. //
  2. // Created by robin on 8/8/15.
  3. //
  4. #include <iostream>
  5. #include <sysexits.h>
  6. #include <DBO/StringUtils.h>
  7. #include <Business/FreeFareDeviceBusiness.h>
  8. #include "DBO/Result.h"
  9. #include "Business/LibNfcBusiness.h"
  10. #include "Business/FreeFareDeviceBusiness.h"
  11. #include "CommandLineParser.h"
  12. #include "MainClass.h"
  13. MainClass::MainClass(int argc, char *argv[])
  14. : _argc(argc)
  15. , _argv(argv)
  16. {
  17. }
  18. int MainClass::main()
  19. {
  20. std::cout << "LibNfc version: " << LibNfcBusiness::getVersion() << std::endl;
  21. LibNfcBusiness libNfc;
  22. auto init = libNfc.init();
  23. if (!init) {
  24. init.print();
  25. return 1;
  26. }
  27. auto devicesResult = libNfc.getDevices();
  28. if (!devicesResult) {
  29. devicesResult.print();
  30. return 2;
  31. }
  32. auto devices = devicesResult.getData();
  33. if (devices.size() == 0) {
  34. std::cerr << "No NFC device found" << std::endl;
  35. return 3;
  36. }
  37. std::cout << "Found " << devices.size() << " devices: " << std::endl;
  38. for (size_t i = 0; i < devices.size(); ++i) {
  39. std::cout << devices[i]->getConnStr() << std::endl;
  40. }
  41. auto device = devices[0];
  42. auto open = device->open();
  43. if (!open) {
  44. open.print();
  45. return 4;
  46. }
  47. FreeFareDeviceBusiness freeFareDevice(device);
  48. auto tags = freeFareDevice.getTags();
  49. if (!tags) {
  50. tags.print();
  51. return 5;
  52. }
  53. std::cout << "Found " << tags.getData().size() << " tags:" << std::endl;
  54. for (size_t i = 0; i < tags.getData().size(); ++i) {
  55. auto tag = tags.getData()[i];
  56. std::cout << "UID: " << tag->getUid() << std::endl;
  57. std::cout << "Type: " << tag->getType() << std::endl;
  58. for(int s = 0; s < 16; ++s) {
  59. std::cout << "+Sector: " << s << std::endl;
  60. auto sectorResult = tag->readSector(s, StringUtils::humanToRaw("8829da9daf76").getData(), MFC_KEY_A);
  61. if (!sectorResult) {
  62. sectorResult.print();
  63. }
  64. else {
  65. auto sector = sectorResult.getData();
  66. for (int b = 0; b < 3; ++b) {
  67. std::cout << StringUtils::rawToHuman(sector.getBlock(b)) << std::endl;
  68. }
  69. std::cout << StringUtils::rawToHuman(sector.getKeyA()) << " "
  70. << StringUtils::rawToHuman(sector.getAccessBits()) << " "
  71. << StringUtils::rawToHuman(sector.getKeyB()) << std::endl;
  72. }
  73. }
  74. }
  75. device->close();
  76. libNfc.clean();
  77. return 0;
  78. }